Skip to content

Commit

Permalink
Pipeline state base: set format of unused render targets to UNKNOWN; …
Browse files Browse the repository at this point in the history
…validate DepthClipEnable member
  • Loading branch information
TheMostDiligent committed Aug 23, 2023
1 parent 8dc5852 commit 624d9ff
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
6 changes: 3 additions & 3 deletions Graphics/GraphicsEngine/include/PipelineStateBase.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 Diligent Graphics LLC
* Copyright 2019-2023 Diligent Graphics LLC
* Copyright 2015-2019 Egor Yusov
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -113,7 +113,7 @@ void CopyRTShaderGroupNames(std::unordered_map<HashMapStringKey, Uint32>& NameTo
const RayTracingPipelineStateCreateInfo& CreateInfo,
FixedLinearAllocator& MemPool) noexcept;

void CorrectGraphicsPipelineDesc(GraphicsPipelineDesc& GraphicsPipeline) noexcept;
void CorrectGraphicsPipelineDesc(GraphicsPipelineDesc& GraphicsPipeline, const DeviceFeatures& Features) noexcept;


/// Finds a pipeline resource layout variable with the name 'Name' in shader stage 'ShaderStage'
Expand Down Expand Up @@ -784,7 +784,7 @@ class PipelineStateBase : public DeviceObjectBase<typename EngineImplTraits::Pip
auto& pStrides = this->m_pGraphicsPipelineData->pStrides;

GraphicsPipeline = CreateInfo.GraphicsPipeline;
CorrectGraphicsPipelineDesc(GraphicsPipeline);
CorrectGraphicsPipelineDesc(GraphicsPipeline, this->GetDevice()->GetDeviceInfo().Features);

CopyResourceLayout(CreateInfo.PSODesc.ResourceLayout, this->m_Desc.ResourceLayout, MemPool);
CopyResourceSignatures(CreateInfo, MemPool);
Expand Down
21 changes: 18 additions & 3 deletions Graphics/GraphicsEngine/src/PipelineStateBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ namespace Diligent
namespace
{

void ValidateRasterizerStateDesc(const PipelineStateDesc& PSODesc, const GraphicsPipelineDesc& GraphicsPipeline) noexcept(false)
void ValidateRasterizerStateDesc(const PipelineStateDesc& PSODesc, const GraphicsPipelineDesc& GraphicsPipeline, const DeviceFeatures& Features) noexcept(false)
{
const auto& RSDesc = GraphicsPipeline.RasterizerDesc;
if (RSDesc.FillMode == FILL_MODE_UNDEFINED)
LOG_PSO_ERROR_AND_THROW("RasterizerDesc.FillMode must not be FILL_MODE_UNDEFINED.");
if (RSDesc.CullMode == CULL_MODE_UNDEFINED)
LOG_PSO_ERROR_AND_THROW("RasterizerDesc.CullMode must not be CULL_MODE_UNDEFINED.");
if (!RSDesc.DepthClipEnable && Features.DepthClamp == DEVICE_FEATURE_STATE_DISABLED)
LOG_ERROR_MESSAGE("Disabling depth clip is not supported by this device. Check the value of the DepthClamp device feature.");
}

void ValidateDepthStencilDesc(const PipelineStateDesc& PSODesc, const GraphicsPipelineDesc& GraphicsPipeline) noexcept(false)
Expand Down Expand Up @@ -182,6 +184,15 @@ void CorrectBlendStateDesc(GraphicsPipelineDesc& GraphicsPipeline) noexcept
}
}

void CorrectRasterizerStateDesc(GraphicsPipelineDesc& GraphicsPipeline, const DeviceFeatures& Features) noexcept
{
auto& RSDesc = GraphicsPipeline.RasterizerDesc;
if (!RSDesc.DepthClipEnable && Features.DepthClamp == DEVICE_FEATURE_STATE_DISABLED)
{
// The error message is printed by ValidateRasterizerStateDesc
RSDesc.DepthClipEnable = True;
}
}

void ValidatePipelineResourceSignatures(const PipelineStateCreateInfo& CreateInfo,
const IRenderDevice* pDevice) noexcept(false)
Expand Down Expand Up @@ -542,7 +553,7 @@ void ValidateGraphicsPipelineCreateInfo(const GraphicsPipelineStateCreateInfo& C
const auto& GraphicsPipeline = CreateInfo.GraphicsPipeline;

ValidateBlendStateDesc(PSODesc, GraphicsPipeline);
ValidateRasterizerStateDesc(PSODesc, GraphicsPipeline);
ValidateRasterizerStateDesc(PSODesc, GraphicsPipeline, Features);
ValidateDepthStencilDesc(PSODesc, GraphicsPipeline);
ValidateGraphicsPipelineDesc(PSODesc, GraphicsPipeline, AdapterInfo.ShadingRate);
ValidatePipelineResourceLayoutDesc(PSODesc, Features);
Expand Down Expand Up @@ -872,9 +883,13 @@ void ValidatePipelineResourceCompatibility(const PipelineResourceDesc& ResDesc,
}
}

void CorrectGraphicsPipelineDesc(GraphicsPipelineDesc& GraphicsPipeline) noexcept
void CorrectGraphicsPipelineDesc(GraphicsPipelineDesc& GraphicsPipeline, const DeviceFeatures& Features) noexcept
{
for (size_t rt = GraphicsPipeline.NumRenderTargets; rt < _countof(GraphicsPipeline.RTVFormats); ++rt)
GraphicsPipeline.RTVFormats[rt] = TEX_FORMAT_UNKNOWN;

CorrectBlendStateDesc(GraphicsPipeline);
CorrectRasterizerStateDesc(GraphicsPipeline, Features);
CorrectDepthStencilDesc(GraphicsPipeline);
}

Expand Down

0 comments on commit 624d9ff

Please sign in to comment.