From 3b019d0c699fbb224fd00cbfcfb1e0598a44b7ba Mon Sep 17 00:00:00 2001 From: azhirnov Date: Fri, 26 Feb 2021 22:02:04 +0300 Subject: Vulkan: added validation for DescriptorSetBaseInd, optimized field packing --- .../include/DeviceContextVkImpl.hpp | 12 +++++++++--- .../GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp | 17 ++++++++++++++--- 2 files changed, 23 insertions(+), 6 deletions(-) (limited to 'Graphics/GraphicsEngineVulkan') diff --git a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp index eb298fb1..e32405a9 100644 --- a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp @@ -479,11 +479,11 @@ private: /// Flag indicating if currently committed index buffer is up to date bool CommittedIBUpToDate = false; + bool CommittedResourcesValidated = false; + Uint32 NumCommands = 0; VkPipelineBindPoint vkPipelineBindPoint = VK_PIPELINE_BIND_POINT_MAX_ENUM; - - bool CommittedResourcesValidated = false; } m_State; // Graphics/mesh, compute, ray tracing @@ -507,12 +507,18 @@ private: // The total number of descriptors with dynamic offset, given by pSignature->GetDynamicOffsetCount(). // Note that this is not the actual number of dynamic buffers in the resource cache. Uint32 DynamicOffsetCount = 0; + +#ifdef DILIGENT_DEVELOPMENT + // The DescriptorSetBaseInd that was used in the last BindDescriptorSets() call + Uint32 LastBoundDSBaseInd = ~0u; +#endif }; std::array Resources; +#ifdef DILIGENT_DEVELOPMENT // Do not use strong references! std::array SRBs = {}; - +#endif using Bitfield = Uint8; static_assert(sizeof(Bitfield) * 8 >= MAX_RESOURCE_SIGNATURES, "not enought space to store MAX_RESOURCE_SIGNATURES bits"); diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index 27cdfbee..0e9610c6 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -445,6 +445,10 @@ void DeviceContextVkImpl::CommitDescriptorSets(DescriptorSetBindInfo& BindInfo) VERIFY_EXPR(m_State.vkPipelineBindPoint != VK_PIPELINE_BIND_POINT_MAX_ENUM); m_CommandBuffer.BindDescriptorSets(m_State.vkPipelineBindPoint, BindInfo.vkPipelineLayout, ResInfo.DescriptorSetBaseInd, SetCount, ResInfo.vkSets.data(), ResInfo.DynamicOffsetCount, m_DynamicBufferOffsets.data()); + +#ifdef DILIGENT_DEVELOPMENT + ResInfo.LastBoundDSBaseInd = ResInfo.DescriptorSetBaseInd; +#endif } VERIFY_EXPR((StaleSRBFlags & BindInfo.ActiveSRBMask) == 0); @@ -481,15 +485,15 @@ void DeviceContextVkImpl::DvpValidateCommittedShaderResources() } auto* pSRBSign = pSRB->GetSignature(); - VERIFY_EXPR(pSRBSign != nullptr); + DEV_CHECK_ERR(pSRBSign != nullptr, "SRB must not be null"); if (!pLayoutSign->IsCompatibleWith(*pSRBSign)) { - LOG_ERROR_MESSAGE("Shader resource binding at index ", i, " with signature '", pSRBSign->GetDesc().Name, + LOG_ERROR_MESSAGE("Shader resource binding at index (", i, ") with signature '", pSRBSign->GetDesc().Name, "' is not compatible with pipeline layout in current pipeline '", m_pPipelineState->GetDesc().Name, "'."); } - VERIFY((BindInfo.StaleSRBMask & BindInfo.ActiveSRBMask) == 0, "CommitDescriptorSets() must be called before validation."); + DEV_CHECK_ERR((BindInfo.StaleSRBMask & BindInfo.ActiveSRBMask) == 0, "CommitDescriptorSets() must be called before validation."); const auto& ResInfo = BindInfo.Resources[i]; const auto DSCount = pLayoutSign->GetNumDescriptorSets(); @@ -499,6 +503,11 @@ void DeviceContextVkImpl::DvpValidateCommittedShaderResources() "descriptor set with index ", s, " is not bound for resource signature '", pLayoutSign->GetDesc().Name, "', binding index ", i, "."); } + + DEV_CHECK_ERR(ResInfo.LastBoundDSBaseInd == ResInfo.DescriptorSetBaseInd, + "Shader resource binding at index ", i, " has descriptor set base offset ", ResInfo.DescriptorSetBaseInd, + ", but currently bound descriptor sets have base offset ", ResInfo.LastBoundDSBaseInd, + "; one of the resource signatures with lower binding index is not compatible."); } m_pPipelineState->DvpVerifySRBResources(BindInfo.SRBs); @@ -607,7 +616,9 @@ void DeviceContextVkImpl::CommitShaderResources(IShaderResourceBinding* pShaderR VERIFY_EXPR(DSIndex == ResourceCache.GetNumDescriptorSets()); +#ifdef DILIGENT_DEVELOPMENT BindInfo.SRBs[SRBIndex] = pResBindingVkImpl; +#endif m_DynamicBufferOffsets.resize(std::max(m_DynamicBufferOffsets.size(), pSignature->GetDynamicOffsetCount())); -- cgit v1.2.3