Skip to content

Commit

Permalink
store desc
Browse files Browse the repository at this point in the history
  • Loading branch information
skallweitNV committed Sep 5, 2024
1 parent 5db64ae commit 3e71790
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 63 deletions.
18 changes: 2 additions & 16 deletions src/d3d11/d3d11-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,21 +369,7 @@ Result DeviceImpl::createSwapchain(const ISwapchain::Desc& desc, WindowHandle wi
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.format != Format::Unknown)
{
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 @@ -1681,7 +1667,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
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<TargetLayoutDesc> m_renderTargets;
bool m_hasDepthStencil = false;
TargetLayoutDesc m_depthStencil;
FramebufferLayoutDesc m_desc;
};

class FramebufferImpl : public FramebufferBase
Expand Down
16 changes: 1 addition & 15 deletions src/d3d12/d3d12-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1709,21 +1709,7 @@ Result DeviceImpl::createFramebuffer(IFramebuffer::Desc const& desc, IFramebuffe
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.format != Format::Unknown)
{
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
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<TargetLayoutDesc> m_renderTargets;
bool m_hasDepthStencil = false;
TargetLayoutDesc m_depthStencil;
FramebufferLayoutDesc m_desc;
};

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

{
auto framebufferLayout = static_cast<FramebufferLayoutImpl*>(desc.graphics.framebufferLayout);
const int numRenderTargets = int(framebufferLayout->m_renderTargets.size());
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
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
13 changes: 1 addition & 12 deletions src/metal/metal-framebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,7 @@ namespace rhi::metal {

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

Expand Down
3 changes: 1 addition & 2 deletions src/metal/metal-framebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ enum
class FramebufferLayoutImpl : public FramebufferLayoutBase
{
public:
std::vector<TargetLayoutDesc> m_renderTargets;
TargetLayoutDesc m_depthStencil;
FramebufferLayoutDesc m_desc;

public:
Result init(const FramebufferLayoutDesc& desc);
Expand Down
8 changes: 4 additions & 4 deletions src/metal/metal-pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ Result PipelineImpl::createMetalRenderPipelineState()
// pd->setAlphaToOneEnabled(); // Currently not supported by rhi
// pd->setRasterizationEnabled(true); // Enabled by default

for (Index i = 0; i < framebufferLayoutImpl->m_renderTargets.size(); ++i)
for (Index i = 0; i < framebufferLayoutImpl->m_desc.renderTargetCount; ++i)
{
const TargetLayoutDesc& targetLayout = framebufferLayoutImpl->m_renderTargets[i];
const TargetLayoutDesc& targetLayout = framebufferLayoutImpl->m_desc.renderTargets[i];
MTL::RenderPipelineColorAttachmentDescriptor* colorAttachment = pd->colorAttachments()->object(i);
colorAttachment->setPixelFormat(MetalUtil::translatePixelFormat(targetLayout.format));
if (i < blend.targetCount)
Expand All @@ -109,9 +109,9 @@ Result PipelineImpl::createMetalRenderPipelineState()
}
sampleCount = std::max(sampleCount, targetLayout.sampleCount);
}
if (framebufferLayoutImpl->m_depthStencil.format != Format::Unknown)
if (framebufferLayoutImpl->m_desc.depthStencil.format != Format::Unknown)
{
const TargetLayoutDesc& depthStencil = framebufferLayoutImpl->m_depthStencil;
const TargetLayoutDesc& depthStencil = framebufferLayoutImpl->m_desc.depthStencil;
MTL::PixelFormat pixelFormat = MetalUtil::translatePixelFormat(depthStencil.format);
if (MetalUtil::isDepthFormat(pixelFormat))
{
Expand Down

0 comments on commit 3e71790

Please sign in to comment.