diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2021-03-11 19:36:13 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2021-03-19 00:38:20 +0000 |
| commit | 6949cdd0e957dd642e4ccf8d0e89673cd9d447d3 (patch) | |
| tree | b212126ea5cb6a38da496815af3f57885fdd8efc /Graphics | |
| parent | Moved duplicate buffer mode validation logic to ShaderResourceVariableBase.hpp (diff) | |
| download | DiligentCore-6949cdd0e957dd642e4ccf8d0e89673cd9d447d3.tar.gz DiligentCore-6949cdd0e957dd642e4ccf8d0e89673cd9d447d3.zip | |
Updated resource binding validation
Diffstat (limited to 'Graphics')
9 files changed, 131 insertions, 115 deletions
diff --git a/Graphics/GraphicsEngine/include/ShaderResourceVariableBase.hpp b/Graphics/GraphicsEngine/include/ShaderResourceVariableBase.hpp index 0a1ad9c1..e731d064 100644 --- a/Graphics/GraphicsEngine/include/ShaderResourceVariableBase.hpp +++ b/Graphics/GraphicsEngine/include/ShaderResourceVariableBase.hpp @@ -126,15 +126,15 @@ bool VerifyConstantBufferBinding(const PipelineResourceDesc& ResDesc, const IDeviceObject* pBuffer, const BufferImplType* pBufferImpl, const IDeviceObject* pCachedBuffer, - const char* ShaderName = nullptr) + const char* SignatureName) { if (pBuffer != nullptr && pBufferImpl == nullptr) { std::stringstream ss; ss << "Failed to bind resource '" << pBuffer->GetDesc().Name << "' to variable '" << GetShaderResourcePrintName(ResDesc, ArrayIndex) << '\''; - if (ShaderName != nullptr) + if (SignatureName != nullptr) { - ss << " in shader '" << ShaderName << '\''; + ss << " defined by signature '" << SignatureName << '\''; } ss << ". Invalid resource type: buffer is expected."; LOG_ERROR_MESSAGE(ss.str()); @@ -149,22 +149,22 @@ bool VerifyConstantBufferBinding(const PipelineResourceDesc& ResDesc, { std::stringstream ss; ss << "Error binding buffer '" << BuffDesc.Name << "' to variable '" << GetShaderResourcePrintName(ResDesc, ArrayIndex) << '\''; - if (ShaderName != nullptr) + if (SignatureName != nullptr) { - ss << " in shader '" << ShaderName << '\''; + ss << " defined by signature '" << SignatureName << '\''; } ss << ". The buffer was not created with BIND_UNIFORM_BUFFER flag."; LOG_ERROR_MESSAGE(ss.str()); BindingOK = false; } - if (BuffDesc.Usage == USAGE_DYNAMIC && (ResDesc.Flags & PIPELINE_RESOURCE_FLAG_NO_DYNAMIC_BUFFERS)) + if (BuffDesc.Usage == USAGE_DYNAMIC && (ResDesc.Flags & PIPELINE_RESOURCE_FLAG_NO_DYNAMIC_BUFFERS) != 0) { std::stringstream ss; ss << "Error binding USAGE_DYNAMIC buffer '" << BuffDesc.Name << "' to variable '" << GetShaderResourcePrintName(ResDesc, ArrayIndex) << '\''; - if (ShaderName != nullptr) + if (SignatureName != nullptr) { - ss << " in shader '" << ShaderName << '\''; + ss << " defined by signature '" << SignatureName << '\''; } ss << ". The variable was initialized with PIPELINE_RESOURCE_FLAG_NO_DYNAMIC_BUFFERS flag."; LOG_ERROR_MESSAGE(ss.str()); @@ -179,9 +179,9 @@ bool VerifyConstantBufferBinding(const PipelineResourceDesc& ResDesc, std::stringstream ss; ss << "Non-null constant (uniform) buffer '" << pCachedBuffer->GetDesc().Name << "' is already bound to " << VarTypeStr << " shader variable '" << GetShaderResourcePrintName(ResDesc, ArrayIndex) << '\''; - if (ShaderName != nullptr) + if (SignatureName != nullptr) { - ss << " in shader '" << ShaderName << '\''; + ss << " defined by signature '" << SignatureName << '\''; } ss << ". Attempting to bind "; if (pBufferImpl) @@ -296,7 +296,7 @@ bool VerifyResourceViewBinding(const PipelineResourceDesc& ResDesc, RESOURCE_DIMENSION ExpectedResourceDimension, bool IsMultisample, const IDeviceObject* pCachedView, - const char* ShaderName = nullptr) + const char* SignatureName) { const char* ExpectedResourceType = GetResourceTypeName<ViewTypeEnumType>(); @@ -304,9 +304,9 @@ bool VerifyResourceViewBinding(const PipelineResourceDesc& ResDesc, { std::stringstream ss; ss << "Failed to bind resource '" << pView->GetDesc().Name << "' to variable '" << GetShaderResourcePrintName(ResDesc, ArrayIndex) << '\''; - if (ShaderName != nullptr) + if (SignatureName != nullptr) { - ss << " in shader '" << ShaderName << '\''; + ss << " defined by signature '" << SignatureName << '\''; } ss << ". Invalid resource type: " << ExpectedResourceType << " is expected."; LOG_ERROR_MESSAGE(ss.str()); @@ -329,9 +329,9 @@ bool VerifyResourceViewBinding(const PipelineResourceDesc& ResDesc, std::stringstream ss; ss << "Error binding " << ExpectedResourceType << " '" << pViewImpl->GetDesc().Name << "' to variable '" << GetShaderResourcePrintName(ResDesc, ArrayIndex) << '\''; - if (ShaderName != nullptr) + if (SignatureName != nullptr) { - ss << " in shader '" << ShaderName << '\''; + ss << " defined by signature '" << SignatureName << '\''; } ss << ". Incorrect view type: "; bool IsFirstViewType = true; @@ -363,9 +363,9 @@ bool VerifyResourceViewBinding(const PipelineResourceDesc& ResDesc, std::stringstream ss; ss << "Non-null resource '" << pCachedView->GetDesc().Name << "' is already bound to " << VarTypeStr << " shader variable '" << GetShaderResourcePrintName(ResDesc, ArrayIndex) << '\''; - if (ShaderName != nullptr) + if (SignatureName != nullptr) { - ss << " in shader '" << ShaderName << '\''; + ss << " defined by signature '" << SignatureName << '\''; } ss << ". Attempting to bind "; if (pViewImpl) @@ -403,7 +403,7 @@ bool ValidateBufferMode(const PipelineResourceDesc& ResDesc, if (BuffDesc.Mode != BUFFER_MODE_FORMATTED) { LOG_ERROR_MESSAGE("Error binding buffer view '", pBufferView->GetDesc().Name, "' of buffer '", BuffDesc.Name, "' to shader variable '", - GetShaderResourcePrintName(ResDesc, ArrayIndex), ": formatted buffer view is expected."); + GetShaderResourcePrintName(ResDesc, ArrayIndex), "': formatted buffer view is expected."); BindingOK = false; } } @@ -412,7 +412,7 @@ bool ValidateBufferMode(const PipelineResourceDesc& ResDesc, if (BuffDesc.Mode != BUFFER_MODE_STRUCTURED && BuffDesc.Mode != BUFFER_MODE_RAW) { LOG_ERROR_MESSAGE("Error binding buffer view '", pBufferView->GetDesc().Name, "' of buffer '", BuffDesc.Name, "' to shader variable '", - GetShaderResourcePrintName(ResDesc, ArrayIndex), ": structured or raw buffer view is expected."); + GetShaderResourcePrintName(ResDesc, ArrayIndex), "': structured or raw buffer view is expected."); BindingOK = false; } } @@ -428,15 +428,15 @@ bool VerifyTLASResourceBinding(const PipelineResourceDesc& ResDesc, const IDeviceObject* pTLAS, const TLASImplType* pTLASImpl, const IDeviceObject* pCachedAS, - const char* ShaderName = nullptr) + const char* SignatureName) { if (pTLAS != nullptr && pTLASImpl == nullptr) { std::stringstream ss; ss << "Failed to bind resource '" << pCachedAS->GetDesc().Name << "' to variable '" << GetShaderResourcePrintName(ResDesc, ArrayIndex) << '\''; - if (ShaderName != nullptr) + if (SignatureName != nullptr) { - ss << " in shader '" << ShaderName << '\''; + ss << " defined by signature '" << SignatureName << '\''; } ss << ". Invalid resource type: TLAS is expected."; LOG_ERROR_MESSAGE(ss.str()); @@ -452,9 +452,9 @@ bool VerifyTLASResourceBinding(const PipelineResourceDesc& ResDesc, std::stringstream ss; ss << "Non-null resource '" << pCachedAS->GetDesc().Name << "' is already bound to " << VarTypeStr << " shader variable '" << GetShaderResourcePrintName(ResDesc, ArrayIndex) << '\''; - if (ShaderName != nullptr) + if (SignatureName != nullptr) { - ss << " in shader '" << ShaderName << '\''; + ss << " defined by signature '" << SignatureName << '\''; } ss << ". Attempting to bind "; if (pTLAS) diff --git a/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp index efd4b4e6..b03ceade 100644 --- a/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp @@ -518,7 +518,10 @@ RefCntAutoPtr<PipelineResourceSignatureD3D12Impl> PipelineStateD3D12Impl::Create RefCntAutoPtr<PipelineResourceSignatureD3D12Impl> pImplicitSignature; if (Resources.size()) { + String SignName = String{"Implicit signature of PSO '"} + (CreateInfo.PSODesc.Name ? CreateInfo.PSODesc.Name : "") + '\''; + PipelineResourceSignatureDesc ResSignDesc; + ResSignDesc.Name = SignName.c_str(); ResSignDesc.Resources = Resources.data(); ResSignDesc.NumResources = static_cast<Uint32>(Resources.size()); ResSignDesc.ImmutableSamplers = LayoutDesc.ImmutableSamplers; diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderVariableManagerD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderVariableManagerD3D12.cpp index a9fc128c..f130b628 100644 --- a/Graphics/GraphicsEngineD3D12/src/ShaderVariableManagerD3D12.cpp +++ b/Graphics/GraphicsEngineD3D12/src/ShaderVariableManagerD3D12.cpp @@ -93,7 +93,6 @@ void ShaderVariableManagerD3D12::Initialize(const PipelineResourceSignatureD3D12 m_pDbgAllocator = &Allocator; #endif - const Uint32 AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes); VERIFY_EXPR(m_NumVariables == 0); const auto MemSize = GetRequiredMemorySize(Signature, AllowedVarTypes, NumAllowedTypes, ShaderType, m_NumVariables); @@ -281,7 +280,7 @@ BindResourceHelper::BindResourceHelper(const PipelineResourceSignatureD3D12Impl& m_DstRes {const_cast<const ShaderResourceCacheD3D12&>(ResourceCache).GetRootTable(m_RootIndex).GetResource(m_OffsetFromTableStart)} // clang-format on { - VERIFY(ArrayIndex < m_ResDesc.ArraySize, "Array index is out of range"); + VERIFY(ArrayIndex < m_ResDesc.ArraySize, "Array index is out of range, but it should've been corrected by VerifyAndCorrectSetArrayArguments()"); if (m_CacheType != ResourceCacheContentType::Signature && !m_Attribs.IsRootView()) { @@ -324,11 +323,11 @@ BindResourceHelper::BindResourceHelper(const PipelineResourceSignatureD3D12Impl& void BindResourceHelper::CacheCB(IDeviceObject* pBuffer) const { - // We cannot use ValidatedCast<> here as the resource retrieved from the - // resource mapping can be of wrong type + // We cannot use ValidatedCast<> here as the resource can be of wrong type RefCntAutoPtr<BufferD3D12Impl> pBuffD3D12{pBuffer, IID_BufferD3D12}; #ifdef DILIGENT_DEVELOPMENT - VerifyConstantBufferBinding(m_ResDesc, m_ArrayIndex, pBuffer, pBuffD3D12.RawPtr(), m_DstRes.pObject.RawPtr()); + VerifyConstantBufferBinding(m_ResDesc, m_ArrayIndex, pBuffer, pBuffD3D12.RawPtr(), m_DstRes.pObject.RawPtr(), + m_Signature.GetDesc().Name); if (m_ResDesc.ArraySize != 1 && pBuffD3D12 && pBuffD3D12->GetDesc().Usage == USAGE_DYNAMIC && pBuffD3D12->GetD3D12Resource() == nullptr) { LOG_ERROR_MESSAGE("Attempting to bind dynamic buffer '", pBuffD3D12->GetDesc().Name, "' that doesn't have backing d3d12 resource to array variable '", m_ResDesc.Name, @@ -391,6 +390,10 @@ void BindResourceHelper::CacheSampler(IDeviceObject* pSampler) const void BindResourceHelper::CacheAccelStruct(IDeviceObject* pTLAS) const { RefCntAutoPtr<ITopLevelASD3D12> pTLASD3D12{pTLAS, IID_TopLevelASD3D12}; +#ifdef DILIGENT_DEVELOPMENT + VerifyTLASResourceBinding(m_ResDesc, m_ArrayIndex, pTLAS, pTLASD3D12.RawPtr(), m_DstRes.pObject.RawPtr(), + m_Signature.GetDesc().Name); +#endif if (pTLASD3D12) { if (m_ResDesc.VarType != SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC && m_DstRes.pObject != nullptr) @@ -460,8 +463,7 @@ template <typename TResourceViewType, void BindResourceHelper::CacheResourceView(IDeviceObject* pView, TViewTypeEnum dbgExpectedViewType) const { - // We cannot use ValidatedCast<> here as the resource retrieved from the - // resource mapping can be of wrong type + // We cannot use ValidatedCast<> here as the resource can be of wrong type RefCntAutoPtr<TResourceViewType> pViewD3D12{pView, ResourceViewTraits<TResourceViewType>::IID}; #ifdef DILIGENT_DEVELOPMENT VerifyResourceViewBinding(m_ResDesc, m_ArrayIndex, @@ -469,7 +471,8 @@ void BindResourceHelper::CacheResourceView(IDeviceObject* pView, {dbgExpectedViewType}, ResourceViewTraits<TResourceViewType>::ExpectedResDimension, false, // IsMultisample - m_DstRes.pObject.RawPtr()); + m_DstRes.pObject.RawPtr(), + m_Signature.GetDesc().Name); ResourceViewTraits<TResourceViewType>::VerifyView(pViewD3D12, m_ResDesc, m_ArrayIndex); #endif if (pViewD3D12) @@ -574,7 +577,7 @@ void BindResourceHelper::operator()(IDeviceObject* pObj) const { if (m_DstRes.pObject != nullptr && m_ResDesc.VarType != SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC) { - LOG_ERROR_MESSAGE("Shader variable '", m_ResDesc.Name, "' is not dynamic but is being reset to null. This is an error and may cause unpredicted behavior. ", + LOG_ERROR_MESSAGE("Shader variable '", m_ResDesc.Name, "' is not dynamic, but is being reset to null. This is an error and may cause unpredicted behavior. ", "Use another shader resource binding instance or label the variable as dynamic if you need to bind another resource."); } @@ -594,7 +597,7 @@ void BindResourceHelper::operator()(IDeviceObject* pObj) const if (DstSam.pObject != nullptr && SamplerResDesc.VarType != SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC) { - LOG_ERROR_MESSAGE("Sampler variable '", SamplerResDesc.Name, "' is not dynamic but is being reset to null. This is an error and may cause unpredicted behavior. ", + LOG_ERROR_MESSAGE("Sampler variable '", SamplerResDesc.Name, "' is not dynamic, but is being reset to null. This is an error and may cause unpredicted behavior. ", "Use another shader resource binding instance or label the variable as dynamic if you need to bind another sampler."); } diff --git a/Graphics/GraphicsEngineOpenGL/include/ShaderResourceCacheGL.hpp b/Graphics/GraphicsEngineOpenGL/include/ShaderResourceCacheGL.hpp index b099fb61..feecc187 100644 --- a/Graphics/GraphicsEngineOpenGL/include/ShaderResourceCacheGL.hpp +++ b/Graphics/GraphicsEngineOpenGL/include/ShaderResourceCacheGL.hpp @@ -93,21 +93,21 @@ public: // pSampler = nullptr; // Avoid unnecessary virtual function calls - pTexture = pTexView ? ValidatedCast<TextureBaseGL>(pTexView->TextureViewGLImpl::GetTexture()) : nullptr; + pTexture = pTexView ? pTexView->GetTexture<TextureBaseGL>() : nullptr; if (pTexView && SetSampler) { pSampler = ValidatedCast<SamplerGLImpl>(pTexView->GetSampler()); } - pView.Attach(pTexView.Detach()); + pView = std::move(pTexView); } void Set(RefCntAutoPtr<BufferViewGLImpl>&& pBufView) { pTexture = nullptr; // Avoid unnecessary virtual function calls - pBuffer = pBufView ? ValidatedCast<BufferGLImpl>(pBufView->BufferViewGLImpl::GetBuffer()) : nullptr; - pView.Attach(pBufView.Detach()); + pBuffer = pBufView ? pBufView->GetBuffer<BufferGLImpl>() : nullptr; + pView = std::move(pBufView); } }; diff --git a/Graphics/GraphicsEngineOpenGL/src/PipelineStateGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/PipelineStateGLImpl.cpp index 716626e7..57b925a4 100644 --- a/Graphics/GraphicsEngineOpenGL/src/PipelineStateGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/PipelineStateGLImpl.cpp @@ -155,7 +155,7 @@ RefCntAutoPtr<PipelineResourceSignatureGLImpl> PipelineStateGLImpl::CreateDefaul RefCntAutoPtr<PipelineResourceSignatureGLImpl> pSignature; if (Resources.size()) { - String SignName = String{"Implicit signature for PSO '"} + m_Desc.Name + '\''; + String SignName = String{"Implicit signature of PSO '"} + m_Desc.Name + '\''; PipelineResourceSignatureDesc ResSignDesc = {}; diff --git a/Graphics/GraphicsEngineOpenGL/src/ShaderVariableManagerGL.cpp b/Graphics/GraphicsEngineOpenGL/src/ShaderVariableManagerGL.cpp index 5b5a88e9..bfba532a 100644 --- a/Graphics/GraphicsEngineOpenGL/src/ShaderVariableManagerGL.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/ShaderVariableManagerGL.cpp @@ -107,7 +107,7 @@ void ShaderVariableManagerGL::Initialize(const PipelineResourceSignatureGLImpl& auto AdvanceOffset = [&CurrentOffset](size_t NumBytes) // { constexpr size_t MaxOffset = std::numeric_limits<OffsetType>::max(); - VERIFY(CurrentOffset <= MaxOffset, "Current offser (", CurrentOffset, ") exceeds max allowed value (", MaxOffset, ")"); + VERIFY(CurrentOffset <= MaxOffset, "Current offset (", CurrentOffset, ") exceeds max allowed value (", MaxOffset, ")"); (void)MaxOffset; auto Offset = static_cast<OffsetType>(CurrentOffset); CurrentOffset += NumBytes; @@ -210,17 +210,18 @@ void ShaderVariableManagerGL::UniformBuffBindInfo::BindResource(IDeviceObject* p const auto& Desc = GetDesc(); const auto& Attr = GetAttribs(); - DEV_CHECK_ERR(ArrayIndex < Desc.ArraySize, "Array index (", ArrayIndex, ") is out of range for variable '", Desc.Name, "'. Max allowed index: ", Desc.ArraySize - 1); - auto& ResourceCache = m_ParentManager.m_ResourceCache; - + VERIFY(ArrayIndex < Desc.ArraySize, "Index is out of range, but it should've been corrected by VerifyAndCorrectSetArrayArguments()"); VERIFY_EXPR(Desc.ResourceType == SHADER_RESOURCE_TYPE_CONSTANT_BUFFER); + auto& ResourceCache = m_ParentManager.m_ResourceCache; + // We cannot use ValidatedCast<> here as the resource can be of wrong type RefCntAutoPtr<BufferGLImpl> pBuffGLImpl{pBuffer, IID_BufferGL}; #ifdef DILIGENT_DEVELOPMENT { const auto& CachedUB = ResourceCache.GetConstUB(Attr.CacheOffset + ArrayIndex); - VerifyConstantBufferBinding(Desc, ArrayIndex, pBuffer, pBuffGLImpl.RawPtr(), CachedUB.pBuffer.RawPtr()); + VerifyConstantBufferBinding(Desc, ArrayIndex, pBuffer, pBuffGLImpl.RawPtr(), CachedUB.pBuffer.RawPtr(), + m_ParentManager.m_pSignature->GetDesc().Name); } #endif @@ -234,7 +235,7 @@ void ShaderVariableManagerGL::TextureBindInfo::BindResource(IDeviceObject* pView const auto& Desc = GetDesc(); const auto& Attr = GetAttribs(); - DEV_CHECK_ERR(ArrayIndex < Desc.ArraySize, "Array index (", ArrayIndex, ") is out of range for variable '", Desc.Name, "'. Max allowed index: ", Desc.ArraySize - 1); + VERIFY(ArrayIndex < Desc.ArraySize, "Index is out of range, but it should've been corrected by VerifyAndCorrectSetArrayArguments()"); auto& ResourceCache = m_ParentManager.m_ResourceCache; if (Desc.ResourceType == SHADER_RESOURCE_TYPE_TEXTURE_SRV || @@ -248,10 +249,11 @@ void ShaderVariableManagerGL::TextureBindInfo::BindResource(IDeviceObject* pView { const auto& CachedTexSampler = ResourceCache.GetConstTexture(Attr.CacheOffset + ArrayIndex); VerifyResourceViewBinding(Desc, ArrayIndex, pView, pViewGL.RawPtr(), - {TEXTURE_VIEW_SHADER_RESOURCE}, - RESOURCE_DIM_UNDEFINED, - false, // IsMultisample - CachedTexSampler.pView.RawPtr()); + {TEXTURE_VIEW_SHADER_RESOURCE}, // Expected view type + RESOURCE_DIM_UNDEFINED, // Expected resource dimension - unknown at this point + false, // IsMultisample (ignored when resource dim is undefined) + CachedTexSampler.pView.RawPtr(), + m_ParentManager.m_pSignature->GetDesc().Name); if (ImmutableSamplerAssigned && ResourceCache.GetContentType() == ResourceCacheContentType::SRB) { VERIFY(CachedTexSampler.pSampler != nullptr, "Immutable samplers must be initialized in the SRB cache by PipelineResourceSignatureGLImpl::InitSRBResourceCache!"); @@ -273,16 +275,17 @@ void ShaderVariableManagerGL::TextureBindInfo::BindResource(IDeviceObject* pView const auto& CachedBuffSampler = ResourceCache.GetConstTexture(Attr.CacheOffset + ArrayIndex); VerifyResourceViewBinding(Desc, ArrayIndex, pView, pViewGL.RawPtr(), - {BUFFER_VIEW_SHADER_RESOURCE}, - RESOURCE_DIM_BUFFER, - false, // IsMultisample - CachedBuffSampler.pView.RawPtr()); - - VERIFY_EXPR((Desc.Flags & PIPELINE_RESOURCE_FLAG_FORMATTED_BUFFER) != 0); + {BUFFER_VIEW_SHADER_RESOURCE}, // Expected view type + RESOURCE_DIM_BUFFER, // Expected resource dimension + false, // IsMultisample (ignored when resource dim is buffer) + CachedBuffSampler.pView.RawPtr(), + m_ParentManager.m_pSignature->GetDesc().Name); + + VERIFY((Desc.Flags & PIPELINE_RESOURCE_FLAG_FORMATTED_BUFFER) != 0, + "FORMATTED_BUFFER resource flag is not set for a texel buffer - this should've not happened."); ValidateBufferMode(Desc, ArrayIndex, pViewGL.RawPtr()); } #endif - VERIFY_EXPR((Desc.Flags & PIPELINE_RESOURCE_FLAG_FORMATTED_BUFFER) != 0); ResourceCache.SetTexelBuffer(Attr.CacheOffset + ArrayIndex, std::move(pViewGL)); } else @@ -297,43 +300,44 @@ void ShaderVariableManagerGL::ImageBindInfo::BindResource(IDeviceObject* pView, const auto& Desc = GetDesc(); const auto& Attr = GetAttribs(); - DEV_CHECK_ERR(ArrayIndex < Desc.ArraySize, "Array index (", ArrayIndex, ") is out of range for variable '", Desc.Name, "'. Max allowed index: ", Desc.ArraySize - 1); + VERIFY(ArrayIndex < Desc.ArraySize, "Index is out of range, but it should've been corrected by VerifyAndCorrectSetArrayArguments()"); auto& ResourceCache = m_ParentManager.m_ResourceCache; if (Desc.ResourceType == SHADER_RESOURCE_TYPE_TEXTURE_UAV) { - // We cannot use ValidatedCast<> here as the resource retrieved from the - // resource mapping can be of wrong type + // We cannot use ValidatedCast<> here as the resource can be of wrong type RefCntAutoPtr<TextureViewGLImpl> pViewGL{pView, IID_TextureViewGL}; #ifdef DILIGENT_DEVELOPMENT { const auto& CachedUAV = ResourceCache.GetConstImage(Attr.CacheOffset + ArrayIndex); VerifyResourceViewBinding(Desc, ArrayIndex, pView, pViewGL.RawPtr(), - {TEXTURE_VIEW_UNORDERED_ACCESS}, - RESOURCE_DIM_UNDEFINED, - false, // IsMultisample - CachedUAV.pView.RawPtr()); + {TEXTURE_VIEW_UNORDERED_ACCESS}, // Expected view type + RESOURCE_DIM_UNDEFINED, // Expected resource dimension - unknown at this point + false, // IsMultisample (ignored when resource dim is unknown) + CachedUAV.pView.RawPtr(), + m_ParentManager.m_pSignature->GetDesc().Name); } #endif ResourceCache.SetTexImage(Attr.CacheOffset + ArrayIndex, std::move(pViewGL)); } else if (Desc.ResourceType == SHADER_RESOURCE_TYPE_BUFFER_UAV) { - // We cannot use ValidatedCast<> here as the resource retrieved from the - // resource mapping can be of wrong type + // We cannot use ValidatedCast<> here as the resource can be of wrong type RefCntAutoPtr<BufferViewGLImpl> pViewGL{pView, IID_BufferViewGL}; #ifdef DILIGENT_DEVELOPMENT { - auto& CachedUAV = ResourceCache.GetConstImage(Attr.CacheOffset + ArrayIndex); + const auto& CachedUAV = ResourceCache.GetConstImage(Attr.CacheOffset + ArrayIndex); VerifyResourceViewBinding(Desc, ArrayIndex, pView, pViewGL.RawPtr(), - {BUFFER_VIEW_UNORDERED_ACCESS}, - RESOURCE_DIM_BUFFER, - false, // IsMultisample - CachedUAV.pView.RawPtr()); - - VERIFY_EXPR((Desc.Flags & PIPELINE_RESOURCE_FLAG_FORMATTED_BUFFER) != 0); + {BUFFER_VIEW_UNORDERED_ACCESS}, // Expected view type + RESOURCE_DIM_BUFFER, // Expected resource dimension + false, // IsMultisample (ignored when resource dim is buffer) + CachedUAV.pView.RawPtr(), + m_ParentManager.m_pSignature->GetDesc().Name); + + VERIFY((Desc.Flags & PIPELINE_RESOURCE_FLAG_FORMATTED_BUFFER) != 0, + "FORMATTED_BUFFER resource flag is not set for an image buffer - this should've not happened."); ValidateBufferMode(Desc, ArrayIndex, pViewGL.RawPtr()); } #endif @@ -352,14 +356,12 @@ void ShaderVariableManagerGL::StorageBufferBindInfo::BindResource(IDeviceObject* const auto& Desc = GetDesc(); const auto& Attr = GetAttribs(); - DEV_CHECK_ERR(ArrayIndex < Desc.ArraySize, "Array index (", ArrayIndex, ") is out of range for variable '", Desc.Name, "'. Max allowed index: ", Desc.ArraySize - 1); + VERIFY(ArrayIndex < Desc.ArraySize, "Index is out of range, but it should've been corrected by VerifyAndCorrectSetArrayArguments()"); auto& ResourceCache = m_ParentManager.m_ResourceCache; VERIFY_EXPR(Desc.ResourceType == SHADER_RESOURCE_TYPE_BUFFER_SRV || Desc.ResourceType == SHADER_RESOURCE_TYPE_BUFFER_UAV); - VERIFY_EXPR((Desc.Flags & PIPELINE_RESOURCE_FLAG_FORMATTED_BUFFER) == 0); - // We cannot use ValidatedCast<> here as the resource retrieved from the - // resource mapping can be of wrong type + // We cannot use ValidatedCast<> here as the resource can be of wrong type RefCntAutoPtr<BufferViewGLImpl> pViewGL{pView, IID_BufferViewGL}; #ifdef DILIGENT_DEVELOPMENT { @@ -367,10 +369,14 @@ void ShaderVariableManagerGL::StorageBufferBindInfo::BindResource(IDeviceObject* // HLSL structured buffers are mapped to SSBOs in GLSL VerifyResourceViewBinding(Desc, ArrayIndex, pView, pViewGL.RawPtr(), - {BUFFER_VIEW_SHADER_RESOURCE, BUFFER_VIEW_UNORDERED_ACCESS}, - RESOURCE_DIM_BUFFER, - false, // IsMultisample - CachedSSBO.pBufferView.RawPtr()); + {BUFFER_VIEW_SHADER_RESOURCE, BUFFER_VIEW_UNORDERED_ACCESS}, // Expected view types + RESOURCE_DIM_BUFFER, // Expected resource dimension + false, // IsMultisample (ignored when resource dim is buffer) + CachedSSBO.pBufferView.RawPtr(), + m_ParentManager.m_pSignature->GetDesc().Name); + + VERIFY((Desc.Flags & PIPELINE_RESOURCE_FLAG_FORMATTED_BUFFER) == 0, + "FORMATTED_BUFFER resource flag is set for a storage buffer - this should've not happened."); ValidateBufferMode(Desc, ArrayIndex, pViewGL.RawPtr()); } #endif @@ -440,11 +446,11 @@ IShaderResourceVariable* ShaderVariableManagerGL::GetVariable(const Char* Name) class ShaderVariableLocator { public: - ShaderVariableLocator(const ShaderVariableManagerGL& _Layout, + ShaderVariableLocator(const ShaderVariableManagerGL& _Mgr, Uint32 _Index) : // clang-format off - Layout {_Layout}, - Index {_Index} + Mgr {_Mgr}, + Index {_Index} // clang-format on { } @@ -453,7 +459,7 @@ public: IShaderResourceVariable* TryResource(Uint32 NumResources) { if (Index < NumResources) - return &Layout.GetResource<ResourceType>(Index); + return &Mgr.GetResource<ResourceType>(Index); else { Index -= NumResources; @@ -462,7 +468,7 @@ public: } private: - ShaderVariableManagerGL const& Layout; + ShaderVariableManagerGL const& Mgr; Uint32 Index; }; @@ -492,10 +498,10 @@ IShaderResourceVariable* ShaderVariableManagerGL::GetVariable(Uint32 Index) cons class ShaderVariableIndexLocator { public: - ShaderVariableIndexLocator(const ShaderVariableManagerGL& _Layout, const IShaderResourceVariable& Variable) : + ShaderVariableIndexLocator(const ShaderVariableManagerGL& _Mgr, const IShaderResourceVariable& Variable) : // clang-format off - Layout {_Layout}, - VarOffset(reinterpret_cast<const Uint8*>(&Variable) - reinterpret_cast<const Uint8*>(_Layout.m_ResourceBuffer)) + Mgr {_Mgr}, + VarOffset(reinterpret_cast<const Uint8*>(&Variable) - reinterpret_cast<const Uint8*>(_Mgr.m_ResourceBuffer)) // clang-format on {} @@ -504,7 +510,7 @@ public: { if (VarOffset < NextResourceTypeOffset) { - auto RelativeOffset = VarOffset - Layout.GetResourceOffset<ResourceType>(); + auto RelativeOffset = VarOffset - Mgr.GetResourceOffset<ResourceType>(); DEV_CHECK_ERR(RelativeOffset % sizeof(ResourceType) == 0, "Offset is not multiple of resource type (", sizeof(ResourceType), ")"); RelativeOffset /= sizeof(ResourceType); VERIFY(RelativeOffset >= 0 && RelativeOffset < VarCount, @@ -523,7 +529,7 @@ public: Uint32 GetIndex() const { return Index; } private: - const ShaderVariableManagerGL& Layout; + const ShaderVariableManagerGL& Mgr; const size_t VarOffset; Uint32 Index = 0; }; @@ -534,10 +540,10 @@ Uint32 ShaderVariableManagerGL::GetVariableIndex(const IShaderResourceVariable& if (!m_ResourceBuffer) { LOG_ERROR("This shader resource layout does not have resources"); - return static_cast<Uint32>(-1); + return ~0u; } - ShaderVariableIndexLocator IdxLocator(*this, Var); + ShaderVariableIndexLocator IdxLocator{*this, Var}; if (IdxLocator.TryResource<UniformBuffBindInfo>(m_TextureOffset, GetNumUBs())) return IdxLocator.GetIndex(); diff --git a/Graphics/GraphicsEngineVulkan/include/ShaderVariableManagerVk.hpp b/Graphics/GraphicsEngineVulkan/include/ShaderVariableManagerVk.hpp index 3869e64d..947abb3c 100644 --- a/Graphics/GraphicsEngineVulkan/include/ShaderVariableManagerVk.hpp +++ b/Graphics/GraphicsEngineVulkan/include/ShaderVariableManagerVk.hpp @@ -174,11 +174,6 @@ public: { return m_ParentManager.BindResource(pObj, ArrayIndex, m_ResIndex); } - -private: - using ResourceAttribs = PipelineResourceAttribsVk; - - const ResourceAttribs& GetAttribs() const { return m_ParentManager.GetAttribs(m_ResIndex); } }; } // namespace Diligent diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp index 5298d20d..49fd6d64 100644 --- a/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/PipelineStateVkImpl.cpp @@ -841,7 +841,7 @@ RefCntAutoPtr<PipelineResourceSignatureVkImpl> PipelineStateVkImpl::CreateDefaul RefCntAutoPtr<PipelineResourceSignatureVkImpl> pSignature; if (Resources.size()) { - String SignName = String{"Implicit signature for PSO '"} + m_Desc.Name + '\''; + String SignName = String{"Implicit signature of PSO '"} + m_Desc.Name + '\''; PipelineResourceSignatureDesc ResSignDesc; ResSignDesc.Name = SignName.c_str(); diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderVariableManagerVk.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderVariableManagerVk.cpp index dff52402..60855221 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderVariableManagerVk.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderVariableManagerVk.cpp @@ -89,7 +89,6 @@ void ShaderVariableManagerVk::Initialize(const PipelineResourceSignatureVkImpl& VERIFY_EXPR(m_pSignature == nullptr); - const Uint32 AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes); VERIFY_EXPR(m_NumVariables == 0); const auto MemSize = GetRequiredMemorySize(Signature, AllowedVarTypes, NumAllowedTypes, ShaderType, m_NumVariables); @@ -312,7 +311,7 @@ BindResourceHelper::BindResourceHelper(const PipelineResourceSignatureVkImpl& Si m_DstRes {m_CachedSet.GetResource(m_DstResCacheOffset)} // clang-format on { - VERIFY_EXPR(ArrayIndex < m_ResDesc.ArraySize); + VERIFY(ArrayIndex < m_ResDesc.ArraySize, "Array index is out of range, but it should've been corrected by VerifyAndCorrectSetArrayArguments()"); VERIFY(m_DstRes.Type == m_Attribs.GetDescriptorType(), "Inconsistent types"); #ifdef DILIGENT_DEBUG @@ -401,8 +400,8 @@ void BindResourceHelper::operator()(IDeviceObject* pObj) const { if (m_DstRes.pObject && m_ResDesc.VarType != SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC) { - LOG_ERROR_MESSAGE("Shader variable '", m_ResDesc.Name, "' is not dynamic but being unbound. This is an error and may cause unpredicted behavior. ", - "Use another shader resource binding instance or label shader variable as dynamic if you need to bind another resource."); + LOG_ERROR_MESSAGE("Shader variable '", m_ResDesc.Name, "' is not dynamic, but is being reset to null. This is an error and may cause unpredicted behavior. ", + "Use another shader resource binding instance or label the variable as dynamic if you need to bind another resource."); } m_ResourceCache.ResetResource(m_Attribs.DescrSet, m_DstResCacheOffset); @@ -442,7 +441,8 @@ void BindResourceHelper::CacheUniformBuffer(IDeviceObject* pBuffer) const // We cannot use ValidatedCast<> here as the resource can have wrong type RefCntAutoPtr<BufferVkImpl> pBufferVk{pBuffer, IID_BufferVk}; #ifdef DILIGENT_DEVELOPMENT - VerifyConstantBufferBinding(m_ResDesc, m_ArrayIndex, pBuffer, pBufferVk.RawPtr(), m_DstRes.pObject.RawPtr()); + VerifyConstantBufferBinding(m_ResDesc, m_ArrayIndex, pBuffer, pBufferVk.RawPtr(), m_DstRes.pObject.RawPtr(), + m_Signature.GetDesc().Name); #endif UpdateCachedResource(std::move(pBufferVk)); @@ -463,11 +463,14 @@ void BindResourceHelper::CacheStorageBuffer(IDeviceObject* pBufferView) const const auto RequiredViewType = DescriptorTypeToBufferView(m_DstRes.Type); VerifyResourceViewBinding(m_ResDesc, m_ArrayIndex, pBufferView, pBufferViewVk.RawPtr(), - {RequiredViewType}, RESOURCE_DIM_BUFFER, - false, // IsMultisample - m_DstRes.pObject.RawPtr()); + {RequiredViewType}, + RESOURCE_DIM_BUFFER, // Expected resource dim + false, // IsMultisample (ignored when resource dim is buffer) + m_DstRes.pObject.RawPtr(), + m_Signature.GetDesc().Name); - VERIFY_EXPR((m_ResDesc.Flags & PIPELINE_RESOURCE_FLAG_FORMATTED_BUFFER) == 0); + VERIFY((m_ResDesc.Flags & PIPELINE_RESOURCE_FLAG_FORMATTED_BUFFER) == 0, + "FORMATTED_BUFFER resource flag is set for a storage buffer - this should've not happened."); ValidateBufferMode(m_ResDesc, m_ArrayIndex, pBufferViewVk.RawPtr()); } #endif @@ -489,11 +492,14 @@ void BindResourceHelper::CacheTexelBuffer(IDeviceObject* pBufferView) const const auto RequiredViewType = DescriptorTypeToBufferView(m_DstRes.Type); VerifyResourceViewBinding(m_ResDesc, m_ArrayIndex, pBufferView, pBufferViewVk.RawPtr(), - {RequiredViewType}, RESOURCE_DIM_BUFFER, - false, // IsMultisample - m_DstRes.pObject.RawPtr()); + {RequiredViewType}, + RESOURCE_DIM_BUFFER, // Expected resource dim + false, // IsMultisample (ignored when resource dim is buffer) + m_DstRes.pObject.RawPtr(), + m_Signature.GetDesc().Name); - VERIFY_EXPR((m_ResDesc.Flags & PIPELINE_RESOURCE_FLAG_FORMATTED_BUFFER) != 0); + VERIFY((m_ResDesc.Flags & PIPELINE_RESOURCE_FLAG_FORMATTED_BUFFER) != 0, + "FORMATTED_BUFFER resource flag is not set for a texel buffer - this should've not happened."); ValidateBufferMode(m_ResDesc, m_ArrayIndex, pBufferViewVk.RawPtr()); } #endif @@ -517,8 +523,9 @@ void BindResourceHelper::CacheImage(IDeviceObject* pTexView) const pTexView, pTexViewVk0.RawPtr(), {RequiredViewType}, RESOURCE_DIM_UNDEFINED, // Required resource dimension is not known - false, // IsMultisample - m_DstRes.pObject.RawPtr()); + false, // IsMultisample (ignored when resource dim is unknown) + m_DstRes.pObject.RawPtr(), + m_Signature.GetDesc().Name); } #endif @@ -610,7 +617,8 @@ void BindResourceHelper::CacheInputAttachment(IDeviceObject* pTexView) const {TEXTURE_VIEW_SHADER_RESOURCE}, RESOURCE_DIM_UNDEFINED, false, // IsMultisample - m_DstRes.pObject.RawPtr()); + m_DstRes.pObject.RawPtr(), + m_Signature.GetDesc().Name); #endif UpdateCachedResource(std::move(pTexViewVk)); @@ -621,7 +629,8 @@ void BindResourceHelper::CacheAccelerationStructure(IDeviceObject* pTLAS) const VERIFY(m_DstRes.Type == DescriptorType::AccelerationStructure, "Acceleration Structure resource is expected"); RefCntAutoPtr<TopLevelASVkImpl> pTLASVk{pTLAS, IID_TopLevelASVk}; #ifdef DILIGENT_DEVELOPMENT - VerifyTLASResourceBinding(m_ResDesc, m_ArrayIndex, pTLAS, pTLASVk.RawPtr(), m_DstRes.pObject.RawPtr()); + VerifyTLASResourceBinding(m_ResDesc, m_ArrayIndex, pTLAS, pTLASVk.RawPtr(), m_DstRes.pObject.RawPtr(), + m_Signature.GetDesc().Name); #endif UpdateCachedResource(std::move(pTLASVk)); |
