From f1dbc752658cff61f95172fa1fad57f7bb17372c Mon Sep 17 00:00:00 2001 From: assiduous Date: Tue, 26 Jan 2021 21:58:44 -0800 Subject: Resource signature: added validation that texture and assigned samplers are compatible; some code cleanup. --- .../include/DeviceContextVkImpl.hpp | 4 ++- .../src/DeviceContextVkImpl.cpp | 39 ++++++++++++---------- .../src/PipelineStateVkImpl.cpp | 15 +++++---- 3 files changed, 32 insertions(+), 26 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp index 00ca6f64..6d7e355e 100644 --- a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp @@ -524,7 +524,9 @@ private: void BindShaderResources(PipelineStateVkImpl* pPipelineStateVk); void BindDescriptorSetsWithDynamicOffsets(DescriptorSetBindInfo& DescrSetBindInfo); - void ValidateShaderResources(); +#ifdef DILIGENT_DEVELOPMENT + void DvpValidateShaderResources(); +#endif /// Descriptor set binding information for each pipeline type (graphics/mesh, compute, ray tracing) std::array m_DescrSetBindInfo; diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index 315ffeae..eb90bd69 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -366,7 +366,6 @@ __forceinline void DeviceContextVkImpl::BindShaderResources(PipelineStateVkImpl* // (14.2.2. Pipeline Layouts, clause 'Pipeline Layout Compatibility') // https://www.khronos.org/registry/vulkan/specs/1.2-extensions/html/vkspec.html#descriptorsets-compatibility -#ifdef DILIGENT_DEBUG auto& Resources = BindInfo.Resources; Uint32 CompatSignCount = SignCount; @@ -395,7 +394,6 @@ __forceinline void DeviceContextVkImpl::BindShaderResources(PipelineStateVkImpl* BindInfo.vkSets[i * MAX_DESCR_SET_PER_SIGNATURE + 0] = VK_NULL_HANDLE; BindInfo.vkSets[i * MAX_DESCR_SET_PER_SIGNATURE + 1] = VK_NULL_HANDLE; } -#endif } void DeviceContextVkImpl::BindDescriptorSetsWithDynamicOffsets(DescriptorSetBindInfo& BindInfo) @@ -456,14 +454,13 @@ void DeviceContextVkImpl::BindDescriptorSetsWithDynamicOffsets(DescriptorSetBind VERIFY_EXPR(!(BindInfo.PendingSRB & BindInfo.ActiveSRBMask)); } -void DeviceContextVkImpl::ValidateShaderResources() +#ifdef DILIGENT_DEVELOPMENT +void DeviceContextVkImpl::DvpValidateShaderResources() { -#ifdef DILIGENT_DEBUG - auto* pPipelineStateVk = ValidatedCast(m_pPipelineState.RawPtr()); - const auto& Layout = pPipelineStateVk->GetPipelineLayout(); - const auto BindIndex = PipelineTypeToBindPointIndex(pPipelineStateVk->GetDesc().PipelineType); - auto& BindInfo = m_DescrSetBindInfo[BindIndex]; - const auto SignCount = Layout.GetSignatureCount(); + const auto& Layout = m_pPipelineState->GetPipelineLayout(); + const auto BindIndex = PipelineTypeToBindPointIndex(m_pPipelineState->GetDesc().PipelineType); + auto& BindInfo = m_DescrSetBindInfo[BindIndex]; + const auto SignCount = Layout.GetSignatureCount(); for (Uint32 i = 0; i < SignCount; ++i) { @@ -483,7 +480,7 @@ void DeviceContextVkImpl::ValidateShaderResources() if (!LayoutSign->IsCompatibleWith(*ResSign)) { LOG_ERROR_MESSAGE("Shader resource binding with signature '", ResSign->GetDesc().Name, - "' is not compatible with pipeline layout in current pipeline '", pPipelineStateVk->GetDesc().Name, "'."); + "' is not compatible with pipeline layout in current pipeline '", m_pPipelineState->GetDesc().Name, "'."); } // You must call BindDescriptorSetsWithDynamicOffsets() before validation. @@ -499,8 +496,8 @@ void DeviceContextVkImpl::ValidateShaderResources() LayoutSign->GetDesc().Name, "' binding index (", i, ")."); } } -#endif } +#endif void DeviceContextVkImpl::TransitionShaderResources(IPipelineState*, IShaderResourceBinding* pShaderResourceBinding) { @@ -521,7 +518,6 @@ void DeviceContextVkImpl::TransitionShaderResources(IPipelineState*, IShaderReso auto* pResBindingVkImpl = ValidatedCast(pShaderResourceBinding); auto& ResourceCache = pResBindingVkImpl->GetResourceCache(); - // AZ TODO: exclude stages that is not supported by pipeline ResourceCache.TransitionResources(this); } @@ -539,7 +535,6 @@ void DeviceContextVkImpl::CommitShaderResources(IShaderResourceBinding* pShaderR if (StateTransitionMode == RESOURCE_STATE_TRANSITION_MODE_TRANSITION) { - // AZ TODO: exclude stages that is not supported by pipeline ResourceCache.TransitionResources(this); } #ifdef DILIGENT_DEVELOPMENT @@ -579,8 +574,10 @@ void DeviceContextVkImpl::CommitShaderResources(IShaderResourceBinding* pShaderR VkDescriptorSet DynamicDescrSet = VK_NULL_HANDLE; const char* DynamicDescrSetName = "Dynamic Descriptor Set"; #ifdef DILIGENT_DEVELOPMENT - String _DynamicDescrSetName("AZ TODO"); - _DynamicDescrSetName.append(" - dynamic set"); + String _DynamicDescrSetName{DynamicDescrSetName}; + _DynamicDescrSetName.append(" ("); + _DynamicDescrSetName.append(pSignature->GetDesc().Name); + _DynamicDescrSetName += ')'; DynamicDescrSetName = _DynamicDescrSetName.c_str(); #endif // Allocate vulkan descriptor set for dynamic resources @@ -768,7 +765,9 @@ void DeviceContextVkImpl::PrepareForDraw(DRAW_FLAGS Flags) CommitRenderPassAndFramebuffer((Flags & DRAW_FLAG_VERIFY_STATES) != 0); } - ValidateShaderResources(); +#ifdef DILIGENT_DEVELOPMENT + DvpValidateShaderResources(); +#endif } BufferVkImpl* DeviceContextVkImpl::PrepareIndirectDrawAttribsBuffer(IBuffer* pAttribsBuffer, RESOURCE_STATE_TRANSITION_MODE TransitonMode) @@ -904,7 +903,9 @@ void DeviceContextVkImpl::PrepareForDispatchCompute() # endif #endif - ValidateShaderResources(); +#ifdef DILIGENT_DEVELOPMENT + DvpValidateShaderResources(); +#endif } void DeviceContextVkImpl::PrepareForRayTracing() @@ -918,7 +919,9 @@ void DeviceContextVkImpl::PrepareForRayTracing() BindDescriptorSetsWithDynamicOffsets(DescrSetBindInfo); } - ValidateShaderResources(); +#ifdef DILIGENT_DEVELOPMENT + DvpValidateShaderResources(); +#endif } void DeviceContextVkImpl::DispatchCompute(const DispatchComputeAttribs& Attribs) diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp index 06388005..9e3bafe4 100644 --- a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp @@ -720,7 +720,7 @@ void PipelineStateVkImpl::InitPipelineLayout(const PipelineStateCreateInfo& Crea TShaderStages& ShaderStages) { std::array Signatures; - RefCntAutoPtr TempSignature; + RefCntAutoPtr pImplicitSignature; Uint32 SignatureCount = CreateInfo.ResourceSignaturesCount; @@ -745,6 +745,7 @@ void PipelineStateVkImpl::InitPipelineLayout(const PipelineStateCreateInfo& Crea for (auto& Stage : ShaderStages) { + // Variables in all shader stages are separate in implicit layout UniqueNames.clear(); for (auto* pShader : Stage.Shaders) { @@ -794,7 +795,7 @@ void PipelineStateVkImpl::InitPipelineLayout(const PipelineStateCreateInfo& Crea auto& Res = Resources[Iter->second.DescIndex]; Res.VarType = Var.Type; - // apply new variable type to sampler too + // Apply new variable type to sampler too if (ShaderResources.IsUsingCombinedSamplers() && Res.ResourceType == SHADER_RESOURCE_TYPE_TEXTURE_SRV) { String SampName = String{Var.Name} + ShaderResources.GetCombinedSamplerSuffix(); @@ -820,20 +821,20 @@ void PipelineStateVkImpl::InitPipelineLayout(const PipelineStateCreateInfo& Crea ResSignDesc.UseCombinedTextureSamplers = pCombinedSamplerSuffix != nullptr; ResSignDesc.CombinedSamplerSuffix = pCombinedSamplerSuffix; - GetDevice()->CreatePipelineResourceSignature(ResSignDesc, &TempSignature, true); + GetDevice()->CreatePipelineResourceSignature(ResSignDesc, &pImplicitSignature, true); - if (TempSignature == nullptr) + if (pImplicitSignature == nullptr) LOG_ERROR_AND_THROW("Failed to create resource signature for pipeline state"); - Signatures[0] = TempSignature; + Signatures[0] = pImplicitSignature; SignatureCount = 1; } } m_PipelineLayout.Create(GetDevice(), CreateInfo.PSODesc.PipelineType, Signatures.data(), SignatureCount); - // verify that pipeline layout is compatible with shader resources and - // remap resource bindings + // Verify that pipeline layout is compatible with shader resources and + // remap resource bindings. for (size_t s = 0; s < ShaderStages.size(); ++s) { const auto& Shaders = ShaderStages[s].Shaders; -- cgit v1.2.3