Skip to content

Commit

Permalink
rename IFramebufferLayout::Desc -> FramebufferLayoutDesc (#22)
Browse files Browse the repository at this point in the history
* rename IFramebufferLayout::Desc -> FramebufferLayoutDesc

* fixed size render target array

* store desc

* remove BlendDesc::targetCount

* formatting
  • Loading branch information
skallweitNV authored Sep 5, 2024
1 parent b1a52c9 commit db1adf3
Show file tree
Hide file tree
Showing 31 changed files with 94 additions and 165 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- rename IFramebufferLayout::Desc -> FramebufferLayoutDesc
- rename IInputLayout::Desc -> InputLayoutDesc
- introduce ICommandEncoder, which is the new base interface for all command encoders (encoders don't inherit the IResourceCommandEncoder anymore)
- remove IDevice::createProgram2
Expand Down
32 changes: 15 additions & 17 deletions include/slang-rhi.h
Original file line number Diff line number Diff line change
Expand Up @@ -1167,27 +1167,25 @@ struct TargetBlendDesc
struct BlendDesc
{
TargetBlendDesc targets[kMaxRenderTargetCount];
GfxCount targetCount = 0;

bool alphaToCoverageEnable = false;
};

struct TargetLayoutDesc
{
Format format = Format::Unknown;
GfxCount sampleCount = 1;
};

struct FramebufferLayoutDesc
{
GfxCount renderTargetCount;
TargetLayoutDesc renderTargets[kMaxRenderTargetCount];
TargetLayoutDesc depthStencil;
};

class IFramebufferLayout : public ISlangUnknown
{
SLANG_COM_INTERFACE(0xe5facc0a, 0x3d48, 0x4459, {0x8e, 0xa5, 0x7d, 0xbe, 0x81, 0xba, 0x91, 0xc2});

public:
struct TargetLayout
{
Format format;
GfxCount sampleCount;
};
struct Desc
{
GfxCount renderTargetCount;
TargetLayout* renderTargets = nullptr;
TargetLayout* depthStencil = nullptr;
};
};

struct RenderPipelineDesc
Expand Down Expand Up @@ -2253,8 +2251,8 @@ class IDevice : public ISlangUnknown
}

virtual SLANG_NO_THROW Result SLANG_MCALL
createFramebufferLayout(IFramebufferLayout::Desc const& desc, IFramebufferLayout** outFrameBuffer) = 0;
inline ComPtr<IFramebufferLayout> createFramebufferLayout(IFramebufferLayout::Desc const& desc)
createFramebufferLayout(FramebufferLayoutDesc const& desc, IFramebufferLayout** outFrameBuffer) = 0;
inline ComPtr<IFramebufferLayout> createFramebufferLayout(FramebufferLayoutDesc const& desc)
{
ComPtr<IFramebufferLayout> fb;
SLANG_RETURN_NULL_ON_FAIL(createFramebufferLayout(desc, fb.writeRef()));
Expand Down
2 changes: 1 addition & 1 deletion src/cuda/cuda-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,7 @@ DeviceImpl::createSwapchain(const ISwapchain::Desc& desc, WindowHandle window, I
}

SLANG_NO_THROW Result SLANG_MCALL
DeviceImpl::createFramebufferLayout(const IFramebufferLayout::Desc& desc, IFramebufferLayout** outLayout)
DeviceImpl::createFramebufferLayout(const FramebufferLayoutDesc& desc, IFramebufferLayout** outLayout)
{
SLANG_UNUSED(desc);
SLANG_UNUSED(outLayout);
Expand Down
2 changes: 1 addition & 1 deletion src/cuda/cuda-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class DeviceImpl : public RendererBase
createSwapchain(const ISwapchain::Desc& desc, WindowHandle window, ISwapchain** outSwapchain) override;

virtual SLANG_NO_THROW Result SLANG_MCALL
createFramebufferLayout(const IFramebufferLayout::Desc& desc, IFramebufferLayout** outLayout) override;
createFramebufferLayout(const FramebufferLayoutDesc& desc, IFramebufferLayout** outLayout) override;

virtual SLANG_NO_THROW Result SLANG_MCALL
createFramebuffer(const IFramebuffer::Desc& desc, IFramebuffer** outFramebuffer) override;
Expand Down
31 changes: 9 additions & 22 deletions src/d3d11/d3d11-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,24 +366,10 @@ Result DeviceImpl::createSwapchain(const ISwapchain::Desc& desc, WindowHandle wi
return SLANG_OK;
}

Result DeviceImpl::createFramebufferLayout(const IFramebufferLayout::Desc& desc, IFramebufferLayout** outLayout)
Result DeviceImpl::createFramebufferLayout(const FramebufferLayoutDesc& desc, IFramebufferLayout** outLayout)
{
RefPtr<FramebufferLayoutImpl> layout = new FramebufferLayoutImpl();
layout->m_renderTargets.resize(desc.renderTargetCount);
for (GfxIndex i = 0; i < desc.renderTargetCount; i++)
{
layout->m_renderTargets[i] = desc.renderTargets[i];
}

if (desc.depthStencil)
{
layout->m_hasDepthStencil = true;
layout->m_depthStencil = *desc.depthStencil;
}
else
{
layout->m_hasDepthStencil = false;
}
layout->m_desc = desc;
returnComPtr(outLayout, layout);
return SLANG_OK;
}
Expand Down Expand Up @@ -1624,23 +1610,24 @@ Result DeviceImpl::createRenderPipeline(const RenderPipelineDesc& inDesc, IPipel
TargetBlendDesc defaultTargetBlendDesc;

static const UInt kMaxTargets = D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT;
if (srcDesc.targetCount > kMaxTargets)
int targetCount = static_cast<FramebufferLayoutImpl*>(inDesc.framebufferLayout)->m_desc.renderTargetCount;
if (targetCount > kMaxTargets)
return SLANG_FAIL;

for (GfxIndex ii = 0; ii < kMaxTargets; ++ii)
{
TargetBlendDesc const* srcTargetBlendDescPtr = nullptr;
if (ii < srcDesc.targetCount)
if (ii < targetCount)
{
srcTargetBlendDescPtr = &srcDesc.targets[ii];
}
else if (srcDesc.targetCount == 0)
else if (targetCount == 0)
{
srcTargetBlendDescPtr = &defaultTargetBlendDesc;
}
else
{
srcTargetBlendDescPtr = &srcDesc.targets[srcDesc.targetCount - 1];
srcTargetBlendDescPtr = &srcDesc.targets[targetCount - 1];
}

auto& srcTargetBlendDesc = *srcTargetBlendDescPtr;
Expand Down Expand Up @@ -1670,7 +1657,7 @@ Result DeviceImpl::createRenderPipeline(const RenderPipelineDesc& inDesc, IPipel
dstTargetBlendDesc.RenderTargetWriteMask = translateRenderTargetWriteMask(srcTargetBlendDesc.writeMask);
}

dstDesc.IndependentBlendEnable = srcDesc.targetCount > 1;
dstDesc.IndependentBlendEnable = targetCount > 1;
dstDesc.AlphaToCoverageEnable = srcDesc.alphaToCoverageEnable;

SLANG_RETURN_ON_FAIL(m_device->CreateBlendState(&dstDesc, blendState.writeRef()));
Expand All @@ -1681,7 +1668,7 @@ Result DeviceImpl::createRenderPipeline(const RenderPipelineDesc& inDesc, IPipel
pipeline->m_rasterizerState = rasterizerState;
pipeline->m_blendState = blendState;
pipeline->m_inputLayout = static_cast<InputLayoutImpl*>(desc.inputLayout);
pipeline->m_rtvCount = (UINT) static_cast<FramebufferLayoutImpl*>(desc.framebufferLayout)->m_renderTargets.size();
pipeline->m_rtvCount = (UINT) static_cast<FramebufferLayoutImpl*>(desc.framebufferLayout)->m_desc.renderTargetCount;
pipeline->m_blendColor[0] = 0;
pipeline->m_blendColor[1] = 0;
pipeline->m_blendColor[2] = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/d3d11/d3d11-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DeviceImpl : public ImmediateRendererBase
virtual SLANG_NO_THROW Result SLANG_MCALL
createSwapchain(const ISwapchain::Desc& desc, WindowHandle window, ISwapchain** outSwapchain) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
createFramebufferLayout(const IFramebufferLayout::Desc& desc, IFramebufferLayout** outLayout) override;
createFramebufferLayout(const FramebufferLayoutDesc& desc, IFramebufferLayout** outLayout) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
createFramebuffer(const IFramebuffer::Desc& desc, IFramebuffer** outFramebuffer) override;
virtual void setFramebuffer(IFramebuffer* frameBuffer) override;
Expand Down
4 changes: 1 addition & 3 deletions src/d3d11/d3d11-framebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ enum
class FramebufferLayoutImpl : public FramebufferLayoutBase
{
public:
short_vector<IFramebufferLayout::TargetLayout> m_renderTargets;
bool m_hasDepthStencil = false;
IFramebufferLayout::TargetLayout m_depthStencil;
FramebufferLayoutDesc m_desc;
};

class FramebufferImpl : public FramebufferBase
Expand Down
18 changes: 2 additions & 16 deletions src/d3d12/d3d12-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1706,24 +1706,10 @@ Result DeviceImpl::createFramebuffer(IFramebuffer::Desc const& desc, IFramebuffe
return SLANG_OK;
}

Result DeviceImpl::createFramebufferLayout(IFramebufferLayout::Desc const& desc, IFramebufferLayout** outLayout)
Result DeviceImpl::createFramebufferLayout(FramebufferLayoutDesc const& desc, IFramebufferLayout** outLayout)
{
RefPtr<FramebufferLayoutImpl> layout = new FramebufferLayoutImpl();
layout->m_renderTargets.resize(desc.renderTargetCount);
for (GfxIndex i = 0; i < desc.renderTargetCount; i++)
{
layout->m_renderTargets[i] = desc.renderTargets[i];
}

if (desc.depthStencil)
{
layout->m_hasDepthStencil = true;
layout->m_depthStencil = *desc.depthStencil;
}
else
{
layout->m_hasDepthStencil = false;
}
layout->m_desc = desc;
returnComPtr(outLayout, layout);
return SLANG_OK;
}
Expand Down
2 changes: 1 addition & 1 deletion src/d3d12/d3d12-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class DeviceImpl : public RendererBase
createFramebuffer(IFramebuffer::Desc const& desc, IFramebuffer** outFrameBuffer) override;

virtual SLANG_NO_THROW Result SLANG_MCALL
createFramebufferLayout(IFramebufferLayout::Desc const& desc, IFramebufferLayout** outLayout) override;
createFramebufferLayout(FramebufferLayoutDesc const& desc, IFramebufferLayout** outLayout) override;

virtual SLANG_NO_THROW Result SLANG_MCALL
createRenderPassLayout(const IRenderPassLayout::Desc& desc, IRenderPassLayout** outRenderPassLayout) override;
Expand Down
4 changes: 1 addition & 3 deletions src/d3d12/d3d12-framebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ namespace rhi::d3d12 {
class FramebufferLayoutImpl : public FramebufferLayoutBase
{
public:
short_vector<IFramebufferLayout::TargetLayout> m_renderTargets;
bool m_hasDepthStencil = false;
IFramebufferLayout::TargetLayout m_depthStencil;
FramebufferLayoutDesc m_desc;
};

class FramebufferImpl : public FramebufferBase
Expand Down
25 changes: 12 additions & 13 deletions src/d3d12/d3d12-pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,27 +66,27 @@ Result PipelineImpl::ensureAPIPipelineCreated()

psoDesc.PrimitiveTopologyType = D3DUtil::getPrimitiveType(desc.graphics.primitiveType);

{
auto framebufferLayout = static_cast<FramebufferLayoutImpl*>(desc.graphics.framebufferLayout);
const int numRenderTargets = int(framebufferLayout->m_renderTargets.size());
auto framebufferLayout = static_cast<FramebufferLayoutImpl*>(desc.graphics.framebufferLayout);
const int numRenderTargets = int(framebufferLayout->m_desc.renderTargetCount);

if (framebufferLayout->m_hasDepthStencil)
{
if (framebufferLayout->m_desc.depthStencil.format != Format::Unknown)
{
psoDesc.DSVFormat = D3DUtil::getMapFormat(framebufferLayout->m_depthStencil.format);
psoDesc.SampleDesc.Count = framebufferLayout->m_depthStencil.sampleCount;
psoDesc.DSVFormat = D3DUtil::getMapFormat(framebufferLayout->m_desc.depthStencil.format);
psoDesc.SampleDesc.Count = framebufferLayout->m_desc.depthStencil.sampleCount;
}
else
{
psoDesc.DSVFormat = DXGI_FORMAT_UNKNOWN;
if (framebufferLayout->m_renderTargets.size())
if (numRenderTargets > 0)
{
psoDesc.SampleDesc.Count = framebufferLayout->m_renderTargets[0].sampleCount;
psoDesc.SampleDesc.Count = framebufferLayout->m_desc.renderTargets[0].sampleCount;
}
}
psoDesc.NumRenderTargets = numRenderTargets;
for (Int i = 0; i < numRenderTargets; i++)
{
psoDesc.RTVFormats[i] = D3DUtil::getMapFormat(framebufferLayout->m_renderTargets[i].format);
psoDesc.RTVFormats[i] = D3DUtil::getMapFormat(framebufferLayout->m_desc.renderTargets[0].format);
}

psoDesc.SampleDesc.Quality = 0;
Expand Down Expand Up @@ -116,7 +116,7 @@ Result PipelineImpl::ensureAPIPipelineCreated()
blend.IndependentBlendEnable = FALSE;
blend.AlphaToCoverageEnable = desc.graphics.blend.alphaToCoverageEnable ? TRUE : FALSE;
blend.RenderTarget[0].RenderTargetWriteMask = (uint8_t)RenderTargetWriteMask::EnableAll;
for (GfxIndex i = 0; i < desc.graphics.blend.targetCount; i++)
for (GfxIndex i = 0; i < numRenderTargets; i++)
{
auto& d3dDesc = blend.RenderTarget[i];
d3dDesc.BlendEnable = desc.graphics.blend.targets[i].enableBlend ? TRUE : FALSE;
Expand All @@ -130,7 +130,7 @@ Result PipelineImpl::ensureAPIPipelineCreated()
d3dDesc.SrcBlend = D3DUtil::getBlendFactor(desc.graphics.blend.targets[i].color.srcFactor);
d3dDesc.SrcBlendAlpha = D3DUtil::getBlendFactor(desc.graphics.blend.targets[i].alpha.srcFactor);
}
for (GfxIndex i = 1; i < desc.graphics.blend.targetCount; i++)
for (GfxIndex i = 1; i < numRenderTargets; i++)
{
if (memcmp(
&desc.graphics.blend.targets[i],
Expand All @@ -142,8 +142,7 @@ Result PipelineImpl::ensureAPIPipelineCreated()
break;
}
}
for (uint32_t i = (uint32_t)desc.graphics.blend.targetCount; i < D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT;
++i)
for (uint32_t i = (uint32_t)numRenderTargets; i < D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
{
blend.RenderTarget[i] = blend.RenderTarget[0];
}
Expand Down
2 changes: 1 addition & 1 deletion src/d3d12/d3d12-render-pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ void RenderPassLayoutImpl::init(const IRenderPassLayout::Desc& desc)
{
SimpleRenderPassLayout::init(desc);
m_framebufferLayout = static_cast<FramebufferLayoutImpl*>(desc.framebufferLayout);
m_hasDepthStencil = m_framebufferLayout->m_hasDepthStencil;
m_hasDepthStencil = m_framebufferLayout->m_desc.depthStencil.format != Format::Unknown;
}

} // namespace rhi::d3d12
2 changes: 1 addition & 1 deletion src/debug-layer/debug-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ Result DebugDevice::createAccelerationStructure(
return SLANG_OK;
}

Result DebugDevice::createFramebufferLayout(IFramebufferLayout::Desc const& desc, IFramebufferLayout** outFrameBuffer)
Result DebugDevice::createFramebufferLayout(FramebufferLayoutDesc const& desc, IFramebufferLayout** outFrameBuffer)
{
SLANG_RHI_API_FUNC;

Expand Down
2 changes: 1 addition & 1 deletion src/debug-layer/debug-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class DebugDevice : public DebugObject<IDevice>
IAccelerationStructure** outView
) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
createFramebufferLayout(IFramebufferLayout::Desc const& desc, IFramebufferLayout** outFrameBuffer) override;
createFramebufferLayout(FramebufferLayoutDesc const& desc, IFramebufferLayout** outFrameBuffer) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
createFramebuffer(IFramebuffer::Desc const& desc, IFramebuffer** outFrameBuffer) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
Expand Down
2 changes: 1 addition & 1 deletion src/immediate-renderer-base.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class ImmediateComputeDeviceBase : public ImmediateRendererBase
return SLANG_FAIL;
}
virtual SLANG_NO_THROW Result SLANG_MCALL
createFramebufferLayout(const IFramebufferLayout::Desc& desc, IFramebufferLayout** outLayout) override
createFramebufferLayout(const FramebufferLayoutDesc& desc, IFramebufferLayout** outLayout) override
{
SLANG_UNUSED(desc);
SLANG_UNUSED(outLayout);
Expand Down
2 changes: 1 addition & 1 deletion src/metal/metal-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ Result DeviceImpl::createSwapchain(const ISwapchain::Desc& desc, WindowHandle wi
return SLANG_OK;
}

Result DeviceImpl::createFramebufferLayout(const IFramebufferLayout::Desc& desc, IFramebufferLayout** outLayout)
Result DeviceImpl::createFramebufferLayout(const FramebufferLayoutDesc& desc, IFramebufferLayout** outLayout)
{
AUTORELEASEPOOL

Expand Down
2 changes: 1 addition & 1 deletion src/metal/metal-device.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class DeviceImpl : public RendererBase
virtual SLANG_NO_THROW Result SLANG_MCALL
createSwapchain(const ISwapchain::Desc& desc, WindowHandle window, ISwapchain** outSwapchain) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
createFramebufferLayout(const IFramebufferLayout::Desc& desc, IFramebufferLayout** outLayout) override;
createFramebufferLayout(const FramebufferLayoutDesc& desc, IFramebufferLayout** outLayout) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
createFramebuffer(const IFramebuffer::Desc& desc, IFramebuffer** outFramebuffer) override;
virtual SLANG_NO_THROW Result SLANG_MCALL
Expand Down
15 changes: 2 additions & 13 deletions src/metal/metal-framebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,9 @@

namespace rhi::metal {

Result FramebufferLayoutImpl::init(const IFramebufferLayout::Desc& desc)
Result FramebufferLayoutImpl::init(const FramebufferLayoutDesc& desc)
{
for (Index i = 0; i < desc.renderTargetCount; ++i)
{
m_renderTargets.push_back(desc.renderTargets[i]);
}
if (desc.depthStencil)
{
m_depthStencil = *desc.depthStencil;
}
else
{
m_depthStencil = {};
}
m_desc = desc;
return SLANG_OK;
}

Expand Down
5 changes: 2 additions & 3 deletions src/metal/metal-framebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ enum
class FramebufferLayoutImpl : public FramebufferLayoutBase
{
public:
std::vector<IFramebufferLayout::TargetLayout> m_renderTargets;
IFramebufferLayout::TargetLayout m_depthStencil;
FramebufferLayoutDesc m_desc;

public:
Result init(const IFramebufferLayout::Desc& desc);
Result init(const FramebufferLayoutDesc& desc);
};

class FramebufferImpl : public FramebufferBase
Expand Down
Loading

0 comments on commit db1adf3

Please sign in to comment.