From c8bdcc78df5434b4d53bd1f955d851e2983f9960 Mon Sep 17 00:00:00 2001 From: assiduous Date: Tue, 31 Mar 2020 22:42:18 -0700 Subject: Enabled using PSO_CREATE_FLAGS flags in D3D11, D3D12 and Vk backends. --- Graphics/GraphicsEngine/interface/PipelineState.h | 11 +- .../src/PipelineStateD3D11Impl.cpp | 4 +- .../src/PipelineStateD3D12Impl.cpp | 4 +- .../include/ShaderResources.hpp | 4 +- .../GraphicsEngineD3DBase/src/ShaderResources.cpp | 114 ++++++++++--------- .../include/ShaderResourceLayoutVk.hpp | 8 +- .../src/PipelineStateVkImpl.cpp | 4 +- .../src/ShaderResourceLayoutVk.cpp | 122 +++++++++++---------- 8 files changed, 151 insertions(+), 120 deletions(-) (limited to 'Graphics') diff --git a/Graphics/GraphicsEngine/interface/PipelineState.h b/Graphics/GraphicsEngine/interface/PipelineState.h index 913f557c..5e99a392 100644 --- a/Graphics/GraphicsEngine/interface/PipelineState.h +++ b/Graphics/GraphicsEngine/interface/PipelineState.h @@ -255,24 +255,25 @@ typedef struct PipelineStateDesc PipelineStateDesc; DILIGENT_TYPED_ENUM(PSO_CREATE_FLAGS, Uint32) { /// Null flag. - PSO_CREATE_FLAG_NONE = 0x00, + PSO_CREATE_FLAG_NONE = 0x00, - /// Silence missing variable warnings. + /// Ignore missing variables. /// By default, the engine outputs a warning for every variable /// provided as part of the pipeline resource layout description /// that is not found in any of the designated shader stages. /// Use this flag to silence these warnings. - PSO_CREATE_FLAG_SILENCE_MISSING_VARIABLE_WARNINGS = 0x01, + PSO_CREATE_FLAG_IGNORE_MISSING_VARIABLES = 0x01, - /// Silence missing static sampler warnings. + /// Ignore missing static samplers. /// By default, the engine outputs a warning for every static sampler /// provided as part of the pipeline resource layout description /// that is not found in any of the designated shader stages. /// Use this flag to silence these warnings. - PSO_CREATE_FLAG_SILENCE_MISSING_STATIC_SAMPLER_WARNINGS = 0x02, + PSO_CREATE_FLAG_IGNORE_MISSING_STATIC_SAMPLERS = 0x02, }; +DEFINE_FLAG_ENUM_OPERATORS(PSO_CREATE_FLAGS); /// Pipeline state creation attributes diff --git a/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp index 0f5f6e07..3b787039 100644 --- a/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp @@ -139,7 +139,9 @@ PipelineStateD3D11Impl::PipelineStateD3D11Impl(IReferenceCounters* pR auto* pShader = GetShader(s); pResources[s] = &(*pShader->GetD3D11Resources()); } - ShaderResources::DvpVerifyResourceLayout(ResourceLayout, pResources, m_NumShaders); + ShaderResources::DvpVerifyResourceLayout(ResourceLayout, pResources, m_NumShaders, + (CreateInfo.Flags & PSO_CREATE_FLAG_IGNORE_MISSING_VARIABLES) == 0, + (CreateInfo.Flags & PSO_CREATE_FLAG_IGNORE_MISSING_STATIC_SAMPLERS) == 0); } #endif diff --git a/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp index 7e864b67..168736a0 100644 --- a/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp @@ -100,7 +100,9 @@ PipelineStateD3D12Impl::PipelineStateD3D12Impl(IReferenceCounters* pR const auto* pShader = GetShader(s); pResources[s] = &(*pShader->GetShaderResources()); } - ShaderResources::DvpVerifyResourceLayout(ResourceLayout, pResources, m_NumShaders); + ShaderResources::DvpVerifyResourceLayout(ResourceLayout, pResources, m_NumShaders, + (CreateInfo.Flags & PSO_CREATE_FLAG_IGNORE_MISSING_VARIABLES) == 0, + (CreateInfo.Flags & PSO_CREATE_FLAG_IGNORE_MISSING_STATIC_SAMPLERS) == 0); } #endif diff --git a/Graphics/GraphicsEngineD3DBase/include/ShaderResources.hpp b/Graphics/GraphicsEngineD3DBase/include/ShaderResources.hpp index e12d094e..5765e20a 100644 --- a/Graphics/GraphicsEngineD3DBase/include/ShaderResources.hpp +++ b/Graphics/GraphicsEngineD3DBase/include/ShaderResources.hpp @@ -379,7 +379,9 @@ public: #ifdef DILIGENT_DEVELOPMENT static void DvpVerifyResourceLayout(const PipelineResourceLayoutDesc& ResourceLayout, const ShaderResources* const pShaderResources[], - Uint32 NumShaders); + Uint32 NumShaders, + bool VerifyVariables, + bool VerifyStaticSamplers); #endif void GetShaderModel(Uint32& Major, Uint32& Minor) const diff --git a/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp b/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp index 0482ee5a..2f23c4ba 100644 --- a/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp +++ b/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp @@ -216,7 +216,9 @@ D3DShaderResourceCounters ShaderResources::CountResources(const PipelineResource #ifdef DILIGENT_DEVELOPMENT void ShaderResources::DvpVerifyResourceLayout(const PipelineResourceLayoutDesc& ResourceLayout, const ShaderResources* const pShaderResources[], - Uint32 NumShaders) + Uint32 NumShaders, + bool VerifyVariables, + bool VerifyStaticSamplers) { auto GetAllowedShadersString = [&](SHADER_TYPE ShaderStages) // { @@ -256,77 +258,83 @@ void ShaderResources::DvpVerifyResourceLayout(const PipelineResourceLayoutDesc& return ShadersStr; }; - for (Uint32 v = 0; v < ResourceLayout.NumVariables; ++v) + if (VerifyVariables) { - const auto& VarDesc = ResourceLayout.Variables[v]; - if (VarDesc.ShaderStages == SHADER_TYPE_UNKNOWN) + for (Uint32 v = 0; v < ResourceLayout.NumVariables; ++v) { - LOG_WARNING_MESSAGE("No allowed shader stages are specified for ", GetShaderVariableTypeLiteralName(VarDesc.Type), " variable '", VarDesc.Name, "'."); - continue; - } - - bool VariableFound = false; - for (Uint32 s = 0; s < NumShaders && !VariableFound; ++s) - { - const auto& Resources = *pShaderResources[s]; - if ((VarDesc.ShaderStages & Resources.GetShaderType()) == 0) + const auto& VarDesc = ResourceLayout.Variables[v]; + if (VarDesc.ShaderStages == SHADER_TYPE_UNKNOWN) + { + LOG_WARNING_MESSAGE("No allowed shader stages are specified for ", GetShaderVariableTypeLiteralName(VarDesc.Type), " variable '", VarDesc.Name, "'."); continue; + } - const auto UseCombinedTextureSamplers = Resources.IsUsingCombinedTextureSamplers(); - for (Uint32 n = 0; n < Resources.m_TotalResources && !VariableFound; ++n) + bool VariableFound = false; + for (Uint32 s = 0; s < NumShaders && !VariableFound; ++s) { - const auto& Res = Resources.GetResAttribs(n, Resources.m_TotalResources, 0); - - // Skip samplers if combined texture samplers are used as - // in this case they are not treated as independent variables - if (UseCombinedTextureSamplers && Res.GetInputType() == D3D_SIT_SAMPLER) + const auto& Resources = *pShaderResources[s]; + if ((VarDesc.ShaderStages & Resources.GetShaderType()) == 0) continue; - VariableFound = (strcmp(Res.Name, VarDesc.Name) == 0); + const auto UseCombinedTextureSamplers = Resources.IsUsingCombinedTextureSamplers(); + for (Uint32 n = 0; n < Resources.m_TotalResources && !VariableFound; ++n) + { + const auto& Res = Resources.GetResAttribs(n, Resources.m_TotalResources, 0); + + // Skip samplers if combined texture samplers are used as + // in this case they are not treated as independent variables + if (UseCombinedTextureSamplers && Res.GetInputType() == D3D_SIT_SAMPLER) + continue; + + VariableFound = (strcmp(Res.Name, VarDesc.Name) == 0); + } } - } - if (!VariableFound) - { - LOG_WARNING_MESSAGE(GetShaderVariableTypeLiteralName(VarDesc.Type), " variable '", VarDesc.Name, - "' is not found in any of the designated shader stages: ", - GetAllowedShadersString(VarDesc.ShaderStages)); + if (!VariableFound) + { + LOG_WARNING_MESSAGE(GetShaderVariableTypeLiteralName(VarDesc.Type), " variable '", VarDesc.Name, + "' is not found in any of the designated shader stages: ", + GetAllowedShadersString(VarDesc.ShaderStages)); + } } } - for (Uint32 sam = 0; sam < ResourceLayout.NumStaticSamplers; ++sam) + if (VerifyStaticSamplers) { - const auto& StSamDesc = ResourceLayout.StaticSamplers[sam]; - if (StSamDesc.ShaderStages == SHADER_TYPE_UNKNOWN) + for (Uint32 sam = 0; sam < ResourceLayout.NumStaticSamplers; ++sam) { - LOG_WARNING_MESSAGE("No allowed shader stages are specified for static sampler '", StSamDesc.SamplerOrTextureName, "'."); - continue; - } - - const auto* TexOrSamName = StSamDesc.SamplerOrTextureName; - - bool StaticSamplerFound = false; - for (Uint32 s = 0; s < NumShaders && !StaticSamplerFound; ++s) - { - const auto& Resources = *pShaderResources[s]; - if ((StSamDesc.ShaderStages & Resources.GetShaderType()) == 0) + const auto& StSamDesc = ResourceLayout.StaticSamplers[sam]; + if (StSamDesc.ShaderStages == SHADER_TYPE_UNKNOWN) + { + LOG_WARNING_MESSAGE("No allowed shader stages are specified for static sampler '", StSamDesc.SamplerOrTextureName, "'."); continue; + } + + const auto* TexOrSamName = StSamDesc.SamplerOrTextureName; - // Look for static sampler. - // In case HLSL-style combined image samplers are used, the condition is Sampler.Name == "g_Texture" + "_sampler". - // Otherwise the condition is Sampler.Name == "g_Texture_sampler" + "". - const auto* CombinedSamplerSuffix = Resources.GetCombinedSamplerSuffix(); - for (Uint32 n = 0; n < Resources.GetNumSamplers() && !StaticSamplerFound; ++n) + bool StaticSamplerFound = false; + for (Uint32 s = 0; s < NumShaders && !StaticSamplerFound; ++s) { - const auto& Sampler = Resources.GetSampler(n); - StaticSamplerFound = StreqSuff(Sampler.Name, TexOrSamName, CombinedSamplerSuffix); + const auto& Resources = *pShaderResources[s]; + if ((StSamDesc.ShaderStages & Resources.GetShaderType()) == 0) + continue; + + // Look for static sampler. + // In case HLSL-style combined image samplers are used, the condition is Sampler.Name == "g_Texture" + "_sampler". + // Otherwise the condition is Sampler.Name == "g_Texture_sampler" + "". + const auto* CombinedSamplerSuffix = Resources.GetCombinedSamplerSuffix(); + for (Uint32 n = 0; n < Resources.GetNumSamplers() && !StaticSamplerFound; ++n) + { + const auto& Sampler = Resources.GetSampler(n); + StaticSamplerFound = StreqSuff(Sampler.Name, TexOrSamName, CombinedSamplerSuffix); + } } - } - if (!StaticSamplerFound) - { - LOG_WARNING_MESSAGE("Static sampler '", TexOrSamName, "' is not found in any of the designated shader stages: ", - GetAllowedShadersString(StSamDesc.ShaderStages)); + if (!StaticSamplerFound) + { + LOG_WARNING_MESSAGE("Static sampler '", TexOrSamName, "' is not found in any of the designated shader stages: ", + GetAllowedShadersString(StSamDesc.ShaderStages)); + } } } } diff --git a/Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.hpp b/Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.hpp index 529255a0..07050821 100644 --- a/Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.hpp +++ b/Graphics/GraphicsEngineVulkan/include/ShaderResourceLayoutVk.hpp @@ -145,7 +145,9 @@ public: IMemoryAllocator& LayoutDataAllocator, const PipelineResourceLayoutDesc& ResourceLayoutDesc, std::vector SPIRVs[], - class PipelineLayout& PipelineLayout); + class PipelineLayout& PipelineLayout, + bool VerifyVariables, + bool VerifyStaticSamplers); // sizeof(VkResource) == 24 (x64) struct VkResource @@ -274,7 +276,9 @@ public: bool dvpVerifyBindings(const ShaderResourceCacheVk& ResourceCache) const; static void dvpVerifyResourceLayoutDesc(Uint32 NumShaders, const std::shared_ptr pShaderResources[], - const PipelineResourceLayoutDesc& ResourceLayoutDesc); + const PipelineResourceLayoutDesc& ResourceLayoutDesc, + bool VerifyVariables, + bool VerifyStaticSamplers); #endif Uint32 GetResourceCount(SHADER_RESOURCE_VARIABLE_TYPE VarType) const diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp index 33be3b8e..31888d8c 100644 --- a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp @@ -184,7 +184,9 @@ PipelineStateVkImpl::PipelineStateVkImpl(IReferenceCounters* pRefCoun new (m_StaticVarsMgrs + s) ShaderVariableManagerVk(*this, *pStaticResLayout, GetRawAllocator(), nullptr, 0, *pStaticResCache); } ShaderResourceLayoutVk::Initialize(pDeviceVk, m_NumShaders, m_ShaderResourceLayouts, ShaderResources.data(), GetRawAllocator(), - m_Desc.ResourceLayout, ShaderSPIRVs.data(), m_PipelineLayout); + m_Desc.ResourceLayout, ShaderSPIRVs.data(), m_PipelineLayout, + (CreateInfo.Flags & PSO_CREATE_FLAG_IGNORE_MISSING_VARIABLES) == 0, + (CreateInfo.Flags & PSO_CREATE_FLAG_IGNORE_MISSING_STATIC_SAMPLERS) == 0); m_PipelineLayout.Finalize(LogicalDevice); if (m_Desc.SRBAllocationGranularity > 1) diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp index 76c2692f..a02cd8bb 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp @@ -237,7 +237,9 @@ void ShaderResourceLayoutVk::InitializeStaticResourceLayout(std::shared_ptr pShaderResources[], - const PipelineResourceLayoutDesc& ResourceLayoutDesc) + const PipelineResourceLayoutDesc& ResourceLayoutDesc, + bool VerifyVariables, + bool VerifyStaticSamplers) { auto GetAllowedShadersString = [&](SHADER_TYPE ShaderStages) // { @@ -277,79 +279,85 @@ void ShaderResourceLayoutVk::dvpVerifyResourceLayoutDesc(Uint32 return ShadersStr; }; - for (Uint32 v = 0; v < ResourceLayoutDesc.NumVariables; ++v) + if (VerifyVariables) { - const auto& VarDesc = ResourceLayoutDesc.Variables[v]; - if (VarDesc.ShaderStages == SHADER_TYPE_UNKNOWN) + for (Uint32 v = 0; v < ResourceLayoutDesc.NumVariables; ++v) { - LOG_WARNING_MESSAGE("No allowed shader stages are specified for ", GetShaderVariableTypeLiteralName(VarDesc.Type), " variable '", VarDesc.Name, "'."); - continue; - } + const auto& VarDesc = ResourceLayoutDesc.Variables[v]; + if (VarDesc.ShaderStages == SHADER_TYPE_UNKNOWN) + { + LOG_WARNING_MESSAGE("No allowed shader stages are specified for ", GetShaderVariableTypeLiteralName(VarDesc.Type), " variable '", VarDesc.Name, "'."); + continue; + } - bool VariableFound = false; - for (Uint32 s = 0; s < NumShaders && !VariableFound; ++s) - { - const auto& Resources = *pShaderResources[s]; - if ((VarDesc.ShaderStages & Resources.GetShaderType()) != 0) + bool VariableFound = false; + for (Uint32 s = 0; s < NumShaders && !VariableFound; ++s) { - for (Uint32 res = 0; res < Resources.GetTotalResources() && !VariableFound; ++res) + const auto& Resources = *pShaderResources[s]; + if ((VarDesc.ShaderStages & Resources.GetShaderType()) != 0) { - const auto& ResAttribs = Resources.GetResource(res); - VariableFound = (strcmp(ResAttribs.Name, VarDesc.Name) == 0); + for (Uint32 res = 0; res < Resources.GetTotalResources() && !VariableFound; ++res) + { + const auto& ResAttribs = Resources.GetResource(res); + VariableFound = (strcmp(ResAttribs.Name, VarDesc.Name) == 0); + } } } - } - if (!VariableFound) - { - LOG_WARNING_MESSAGE(GetShaderVariableTypeLiteralName(VarDesc.Type), " variable '", VarDesc.Name, - "' is not found in any of the designated shader stages: ", - GetAllowedShadersString(VarDesc.ShaderStages)); + if (!VariableFound) + { + LOG_WARNING_MESSAGE(GetShaderVariableTypeLiteralName(VarDesc.Type), " variable '", VarDesc.Name, + "' is not found in any of the designated shader stages: ", + GetAllowedShadersString(VarDesc.ShaderStages)); + } } } - for (Uint32 sam = 0; sam < ResourceLayoutDesc.NumStaticSamplers; ++sam) + if (VerifyStaticSamplers) { - const auto& StSamDesc = ResourceLayoutDesc.StaticSamplers[sam]; - if (StSamDesc.ShaderStages == SHADER_TYPE_UNKNOWN) + for (Uint32 sam = 0; sam < ResourceLayoutDesc.NumStaticSamplers; ++sam) { - LOG_WARNING_MESSAGE("No allowed shader stages are specified for static sampler '", StSamDesc.SamplerOrTextureName, "'."); - continue; - } - - bool SamplerFound = false; - for (Uint32 s = 0; s < NumShaders && !SamplerFound; ++s) - { - const auto& Resources = *pShaderResources[s]; - if ((StSamDesc.ShaderStages & Resources.GetShaderType()) == 0) - continue; - - // Irrespective of whether HLSL-style combined image samplers are used, - // a static sampler can be assigned to GLSL sampled image (i.e. sampler2D g_tex) - for (Uint32 i = 0; i < Resources.GetNumSmpldImgs() && !SamplerFound; ++i) + const auto& StSamDesc = ResourceLayoutDesc.StaticSamplers[sam]; + if (StSamDesc.ShaderStages == SHADER_TYPE_UNKNOWN) { - const auto& SmplImg = Resources.GetSmpldImg(i); - SamplerFound = (strcmp(SmplImg.Name, StSamDesc.SamplerOrTextureName) == 0); + LOG_WARNING_MESSAGE("No allowed shader stages are specified for static sampler '", StSamDesc.SamplerOrTextureName, "'."); + continue; } - if (!SamplerFound) + bool SamplerFound = false; + for (Uint32 s = 0; s < NumShaders && !SamplerFound; ++s) { - // Check if static sampler is assigned to a separate sampler. - // In case HLSL-style combined image samplers are used, the condition is SepSmpl.Name == "g_Texture" + "_sampler". - // Otherwise the condition is SepSmpl.Name == "g_Texture_sampler" + "". - const auto* CombinedSamplerSuffix = Resources.GetCombinedSamplerSuffix(); - for (Uint32 i = 0; i < Resources.GetNumSepSmplrs() && !SamplerFound; ++i) + const auto& Resources = *pShaderResources[s]; + if ((StSamDesc.ShaderStages & Resources.GetShaderType()) == 0) + continue; + + // Irrespective of whether HLSL-style combined image samplers are used, + // a static sampler can be assigned to GLSL sampled image (i.e. sampler2D g_tex) + for (Uint32 i = 0; i < Resources.GetNumSmpldImgs() && !SamplerFound; ++i) { - const auto& SepSmpl = Resources.GetSepSmplr(i); - SamplerFound = StreqSuff(SepSmpl.Name, StSamDesc.SamplerOrTextureName, CombinedSamplerSuffix); + const auto& SmplImg = Resources.GetSmpldImg(i); + SamplerFound = (strcmp(SmplImg.Name, StSamDesc.SamplerOrTextureName) == 0); + } + + if (!SamplerFound) + { + // Check if static sampler is assigned to a separate sampler. + // In case HLSL-style combined image samplers are used, the condition is SepSmpl.Name == "g_Texture" + "_sampler". + // Otherwise the condition is SepSmpl.Name == "g_Texture_sampler" + "". + const auto* CombinedSamplerSuffix = Resources.GetCombinedSamplerSuffix(); + for (Uint32 i = 0; i < Resources.GetNumSepSmplrs() && !SamplerFound; ++i) + { + const auto& SepSmpl = Resources.GetSepSmplr(i); + SamplerFound = StreqSuff(SepSmpl.Name, StSamDesc.SamplerOrTextureName, CombinedSamplerSuffix); + } } } - } - if (!SamplerFound) - { - LOG_WARNING_MESSAGE("Static sampler '", StSamDesc.SamplerOrTextureName, - "' is not found in any of the designated shader stages: ", - GetAllowedShadersString(StSamDesc.ShaderStages)); + if (!SamplerFound) + { + LOG_WARNING_MESSAGE("Static sampler '", StSamDesc.SamplerOrTextureName, + "' is not found in any of the designated shader stages: ", + GetAllowedShadersString(StSamDesc.ShaderStages)); + } } } } @@ -362,10 +370,12 @@ void ShaderResourceLayoutVk::Initialize(IRenderDevice* IMemoryAllocator& LayoutDataAllocator, const PipelineResourceLayoutDesc& ResourceLayoutDesc, std::vector SPIRVs[], - class PipelineLayout& PipelineLayout) + class PipelineLayout& PipelineLayout, + bool VerifyVariables, + bool VerifyStaticSamplers) { #ifdef DILIGENT_DEVELOPMENT - dvpVerifyResourceLayoutDesc(NumShaders, pShaderResources, ResourceLayoutDesc); + dvpVerifyResourceLayoutDesc(NumShaders, pShaderResources, ResourceLayoutDesc, VerifyVariables, VerifyStaticSamplers); #endif const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes = nullptr; -- cgit v1.2.3