Skip to content

Commit

Permalink
remove BlendDesc::targetCount
Browse files Browse the repository at this point in the history
  • Loading branch information
skallweitNV committed Sep 5, 2024
1 parent 3e71790 commit 1d5a572
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 31 deletions.
2 changes: 0 additions & 2 deletions include/slang-rhi.h
Original file line number Diff line number Diff line change
Expand Up @@ -1167,8 +1167,6 @@ struct TargetBlendDesc
struct BlendDesc
{
TargetBlendDesc targets[kMaxRenderTargetCount];
GfxCount targetCount = 0;

bool alphaToCoverageEnable = false;
};

Expand Down
11 changes: 6 additions & 5 deletions src/d3d11/d3d11-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1610,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 @@ -1656,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 Down
12 changes: 6 additions & 6 deletions src/d3d12/d3d12-pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ Result PipelineImpl::ensureAPIPipelineCreated()

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

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

{
if (framebufferLayout->m_desc.depthStencil.format != Format::Unknown)
{
psoDesc.DSVFormat = D3DUtil::getMapFormat(framebufferLayout->m_desc.depthStencil.format);
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,7 +142,7 @@ Result PipelineImpl::ensureAPIPipelineCreated()
break;
}
}
for (uint32_t i = (uint32_t)desc.graphics.blend.targetCount; i < D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT;
for (uint32_t i = (uint32_t)numRenderTargets; i < D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT;
++i)
{
blend.RenderTarget[i] = blend.RenderTarget[0];
Expand Down
33 changes: 16 additions & 17 deletions src/metal/metal-pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,23 +90,22 @@ Result PipelineImpl::createMetalRenderPipelineState()
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)
{
const TargetBlendDesc& targetBlendDesc = blend.targets[i];
colorAttachment->setBlendingEnabled(targetBlendDesc.enableBlend);
colorAttachment->setSourceRGBBlendFactor(MetalUtil::translateBlendFactor(targetBlendDesc.color.srcFactor));
colorAttachment->setDestinationRGBBlendFactor(
MetalUtil::translateBlendFactor(targetBlendDesc.color.dstFactor)
);
colorAttachment->setRgbBlendOperation(MetalUtil::translateBlendOperation(targetBlendDesc.color.op));
colorAttachment->setSourceAlphaBlendFactor(MetalUtil::translateBlendFactor(targetBlendDesc.alpha.srcFactor)
);
colorAttachment->setDestinationAlphaBlendFactor(
MetalUtil::translateBlendFactor(targetBlendDesc.alpha.dstFactor)
);
colorAttachment->setAlphaBlendOperation(MetalUtil::translateBlendOperation(targetBlendDesc.alpha.op));
colorAttachment->setWriteMask(MetalUtil::translateColorWriteMask(targetBlendDesc.writeMask));
}

const TargetBlendDesc& targetBlendDesc = blend.targets[i];
colorAttachment->setBlendingEnabled(targetBlendDesc.enableBlend);
colorAttachment->setSourceRGBBlendFactor(MetalUtil::translateBlendFactor(targetBlendDesc.color.srcFactor));
colorAttachment->setDestinationRGBBlendFactor(
MetalUtil::translateBlendFactor(targetBlendDesc.color.dstFactor)
);
colorAttachment->setRgbBlendOperation(MetalUtil::translateBlendOperation(targetBlendDesc.color.op));
colorAttachment->setSourceAlphaBlendFactor(MetalUtil::translateBlendFactor(targetBlendDesc.alpha.srcFactor)
);
colorAttachment->setDestinationAlphaBlendFactor(
MetalUtil::translateBlendFactor(targetBlendDesc.alpha.dstFactor)
);
colorAttachment->setAlphaBlendOperation(MetalUtil::translateBlendOperation(targetBlendDesc.alpha.op));
colorAttachment->setWriteMask(MetalUtil::translateColorWriteMask(targetBlendDesc.writeMask));

sampleCount = std::max(sampleCount, targetLayout.sampleCount);
}
if (framebufferLayoutImpl->m_desc.depthStencil.format != Format::Unknown)
Expand Down
2 changes: 1 addition & 1 deletion src/vulkan/vk-pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ Result PipelineImpl::createVKGraphicsPipeline()
multisampling.alphaToCoverageEnable = blendDesc.alphaToCoverageEnable;
multisampling.alphaToOneEnable = VK_FALSE;

auto targetCount = GfxCount(std::min(framebufferLayoutImpl->m_renderTargetCount, (uint32_t)blendDesc.targetCount));
auto targetCount = framebufferLayoutImpl->m_renderTargetCount;
std::vector<VkPipelineColorBlendAttachmentState> colorBlendTargets;

// Regardless of whether blending is enabled, Vulkan always applies the color write mask
Expand Down

0 comments on commit 1d5a572

Please sign in to comment.