diff --git a/Graphics/GraphicsEngine/include/PipelineStateBase.hpp b/Graphics/GraphicsEngine/include/PipelineStateBase.hpp index 3682bf97c..529e25443 100644 --- a/Graphics/GraphicsEngine/include/PipelineStateBase.hpp +++ b/Graphics/GraphicsEngine/include/PipelineStateBase.hpp @@ -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"); @@ -113,7 +113,7 @@ void CopyRTShaderGroupNames(std::unordered_map& 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' @@ -784,7 +784,7 @@ class PipelineStateBase : public DeviceObjectBasem_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); diff --git a/Graphics/GraphicsEngine/src/PipelineStateBase.cpp b/Graphics/GraphicsEngine/src/PipelineStateBase.cpp index 9cf75e65e..016c116fd 100644 --- a/Graphics/GraphicsEngine/src/PipelineStateBase.cpp +++ b/Graphics/GraphicsEngine/src/PipelineStateBase.cpp @@ -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) @@ -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) @@ -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); @@ -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); }