From 65dd6c5aa598653cf6b828efd51fc359fc758b36 Mon Sep 17 00:00:00 2001 From: azhirnov Date: Thu, 25 Feb 2021 21:00:12 +0300 Subject: some fixes and improvements for D3D12 & Vulkan --- .../include/PipelineResourceSignatureVkImpl.hpp | 7 +++-- .../include/PipelineStateVkImpl.hpp | 1 - .../include/ShaderResourceBindingVkImpl.hpp | 2 +- .../src/DeviceContextVkImpl.cpp | 21 ++++++++++---- .../GraphicsEngineVulkan/src/PipelineLayoutVk.cpp | 32 ++-------------------- .../src/PipelineStateVkImpl.cpp | 2 +- .../src/ShaderResourceBindingVkImpl.cpp | 1 + 7 files changed, 25 insertions(+), 41 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/include/PipelineResourceSignatureVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/PipelineResourceSignatureVkImpl.hpp index f8215d49..e1dd094d 100644 --- a/Graphics/GraphicsEngineVulkan/include/PipelineResourceSignatureVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/PipelineResourceSignatureVkImpl.hpp @@ -224,7 +224,10 @@ public: /// Implementation of IPipelineResourceSignature::IsCompatibleWith. virtual bool DILIGENT_CALL_TYPE IsCompatibleWith(const IPipelineResourceSignature* pPRS) const override final { - VERIFY_EXPR(pPRS != nullptr); + if (pPRS == nullptr) + { + return GetHash() == 0; + } return IsCompatibleWith(*ValidatedCast(pPRS)); } @@ -329,7 +332,7 @@ private: // Static resource cache for all static resources ShaderResourceCacheVk* m_pStaticResCache = nullptr; // Static variables manager for every shader stage - ShaderVariableManagerVk* m_StaticVarsMgrs = nullptr; // [m_NumShaderStages] + ShaderVariableManagerVk* m_StaticVarsMgrs = nullptr; // [GetNumStaticResStages()] ImmutableSamplerAttribs* m_ImmutableSamplers = nullptr; // [m_Desc.NumImmutableSamplers] diff --git a/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.hpp index a37638dd..16206349 100644 --- a/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/PipelineStateVkImpl.hpp @@ -92,7 +92,6 @@ public: SubpassDesc& SubpassDesc); - void InitializeStaticSRBResources(ShaderResourceCacheVk& ResourceCache) const; struct ShaderStageInfo { diff --git a/Graphics/GraphicsEngineVulkan/include/ShaderResourceBindingVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/ShaderResourceBindingVkImpl.hpp index 54cd3b3a..c0e012a2 100644 --- a/Graphics/GraphicsEngineVulkan/include/ShaderResourceBindingVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/ShaderResourceBindingVkImpl.hpp @@ -74,7 +74,7 @@ private: void Destruct(); ShaderResourceCacheVk m_ShaderResourceCache; - ShaderVariableManagerVk* m_pShaderVarMgrs = nullptr; + ShaderVariableManagerVk* m_pShaderVarMgrs = nullptr; // [m_NumShaders] }; } // namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index 2ae180e7..27cdfbee 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -326,7 +326,7 @@ void DeviceContextVkImpl::SetPipelineState(IPipelineState* pPipelineState) for (Uint32 i = 0; i < SignCount; ++i) { auto* pSignature = Layout.GetSignature(i); - if (pSignature == nullptr) + if (pSignature == nullptr || pSignature->GetNumDescriptorSets() == 0) continue; BindInfo.ActiveSRBMask |= 1u << i; @@ -349,13 +349,20 @@ void DeviceContextVkImpl::SetPipelineState(IPipelineState* pPipelineState) Uint32 sign = 0; for (; sign < SignCount; ++sign) { - const auto* LayoutSign = Layout.GetSignature(sign); - if (LayoutSign == nullptr) - continue; + const auto* pLayoutSign = Layout.GetSignature(sign); + const auto* pSRBSign = BindInfo.SRBs[sign] != nullptr ? BindInfo.SRBs[sign]->GetSignature() : nullptr; - auto* pSRB = BindInfo.SRBs[sign]; - if (pSRB == nullptr || LayoutSign->IsIncompatibleWith(*pSRB->GetSignature())) + if ((pLayoutSign == nullptr || pLayoutSign->GetNumDescriptorSets() == 0) != (pSRBSign == nullptr || pSRBSign->GetNumDescriptorSets() == 0)) + { + // One signature is null or empty while the other is not - SRB is not compatible with the layout. break; + } + + if (pLayoutSign != nullptr && pSRBSign != nullptr && pLayoutSign->IsIncompatibleWith(*pSRBSign)) + { + // Signatures are incompatible + break; + } } // Unbind incompatible shader resources @@ -375,6 +382,8 @@ void DeviceContextVkImpl::SetPipelineState(IPipelineState* pPipelineState) BindInfo.ClearDynamicBufferBit(sign); } #endif + + m_State.CommittedResourcesValidated = false; } DeviceContextVkImpl::DescriptorSetBindInfo& DeviceContextVkImpl::GetDescriptorSetBindInfo(PIPELINE_TYPE Type) diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineLayoutVk.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineLayoutVk.cpp index b7aaaa26..febc0002 100644 --- a/Graphics/GraphicsEngineVulkan/src/PipelineLayoutVk.cpp +++ b/Graphics/GraphicsEngineVulkan/src/PipelineLayoutVk.cpp @@ -61,36 +61,8 @@ void PipelineLayoutVk::Create(RenderDeviceVkImpl* pDeviceVk, PIPELINE_TYPE Pipel VERIFY(m_SignatureCount == 0 && m_DescrSetCount == 0 && !m_VkPipelineLayout, "This pipeline layout is already initialized"); - for (Uint32 i = 0; i < SignatureCount; ++i) - { - auto* pSignature = ValidatedCast(ppSignatures[i]); - VERIFY(pSignature != nullptr, "Pipeline resource signature at index ", i, " is null. This error should've been caught by ValidatePipelineResourceSignatures."); - - const Uint8 Index = pSignature->GetDesc().BindingIndex; - -#ifdef DILIGENT_DEBUG - VERIFY(Index < m_Signatures.size(), - "Pipeline resource signature specifies binding index ", Uint32{Index}, " that exceeds the limit (", m_Signatures.size() - 1, - "). This error should've been caught by ValidatePipelineResourceSignatureDesc."); - - VERIFY(m_Signatures[Index] == nullptr, - "Pipeline resource signature '", pSignature->GetDesc().Name, "' at index ", Uint32{Index}, - " conflicts with another resource signature '", m_Signatures[Index]->GetDesc().Name, - "' that uses the same index. This error should've been caught by ValidatePipelineResourceSignatures."); - - for (Uint32 s = 0, StageCount = pSignature->GetNumActiveShaderStages(); s < StageCount; ++s) - { - const auto ShaderType = pSignature->GetActiveShaderStageType(s); - VERIFY(IsConsistentShaderType(ShaderType, PipelineType), - "Pipeline resource signature '", pSignature->GetDesc().Name, "' at index ", Uint32{Index}, - " has shader stage '", GetShaderTypeLiteralName(ShaderType), "' that is not compatible with pipeline type '", - GetPipelineTypeString(PipelineType), "'."); - } -#endif - - m_SignatureCount = std::max(m_SignatureCount, Index + 1); - m_Signatures[Index] = pSignature; - } + PipelineResourceSignatureVkImpl::CopyResourceSignatures(PipelineType, SignatureCount, ppSignatures, + m_Signatures.data(), m_Signatures.size(), m_SignatureCount); std::array DescSetLayouts; diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp index 93262266..14417af0 100644 --- a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp @@ -1114,7 +1114,7 @@ void PipelineStateVkImpl::DvpVerifySRBResources(SRBArray& SRBs) const } else { - LOG_ERROR_MESSAGE("No SRB is bound to binding index ", SignBindIndex, " for signature '", SignDesc.Name, '\''); + LOG_ERROR_MESSAGE("No SRB is bound to binding index ", Uint32{SignBindIndex}, " for signature '", SignDesc.Name, '\''); } } ++res_info; diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp index 7456e66c..e0d0d39f 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderResourceBindingVkImpl.cpp @@ -110,6 +110,7 @@ void ShaderResourceBindingVkImpl::Destruct() } GetRawAllocator().Free(m_pShaderVarMgrs); + m_pShaderVarMgrs = nullptr; } } -- cgit v1.2.3