From d3bba829acfb2eabce748220eff045ef0c6f7880 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Sat, 20 Oct 2018 14:16:56 -0700 Subject: Multiple improvements to shader resource binding in D3D11 and D3D12 --- .../include/ShaderResourceCacheD3D11.h | 2 +- .../include/ShaderResourceLayoutD3D11.h | 19 +- .../include/ShaderResourcesD3D11.h | 39 ++-- .../src/DeviceContextD3D11Impl.cpp | 2 +- .../GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp | 2 +- .../src/ShaderResourceBindingD3D11Impl.cpp | 2 +- .../src/ShaderResourceLayoutD3D11.cpp | 240 +++++++++---------- .../src/ShaderResourcesD3D11.cpp | 254 +++++++++++---------- 8 files changed, 286 insertions(+), 274 deletions(-) (limited to 'Graphics/GraphicsEngineD3D11') diff --git a/Graphics/GraphicsEngineD3D11/include/ShaderResourceCacheD3D11.h b/Graphics/GraphicsEngineD3D11/include/ShaderResourceCacheD3D11.h index 70370ec2..95ca9378 100755 --- a/Graphics/GraphicsEngineD3D11/include/ShaderResourceCacheD3D11.h +++ b/Graphics/GraphicsEngineD3D11/include/ShaderResourceCacheD3D11.h @@ -152,7 +152,7 @@ public: SetD3D11ResourceInternal(Slot, GetUAVCount(), &ShaderResourceCacheD3D11::GetUAVArrays, std::move(pBuffView), pd3d11UAV); } - __forceinline void SetSampler(Uint32 Slot, SamplerD3D11Impl *pSampler) + __forceinline void SetSampler(Uint32 Slot, SamplerD3D11Impl* pSampler) { auto *pd3d11Sampler = pSampler ? pSampler->SamplerD3D11Impl::GetD3D11SamplerState() : nullptr; SetD3D11ResourceInternal(Slot, GetSamplerCount(), &ShaderResourceCacheD3D11::GetSamplerArrays, pSampler, pd3d11Sampler); diff --git a/Graphics/GraphicsEngineD3D11/include/ShaderResourceLayoutD3D11.h b/Graphics/GraphicsEngineD3D11/include/ShaderResourceLayoutD3D11.h index 274c0e28..937a992d 100644 --- a/Graphics/GraphicsEngineD3D11/include/ShaderResourceLayoutD3D11.h +++ b/Graphics/GraphicsEngineD3D11/include/ShaderResourceLayoutD3D11.h @@ -47,7 +47,7 @@ public: ShaderResourceLayoutD3D11(IObject& Owner); ~ShaderResourceLayoutD3D11(); - // No copies or moves + // No copies, only moves are allowed ShaderResourceLayoutD3D11 (const ShaderResourceLayoutD3D11&) = delete; ShaderResourceLayoutD3D11& operator = (const ShaderResourceLayoutD3D11&) = delete; ShaderResourceLayoutD3D11 ( ShaderResourceLayoutD3D11&&) = default; @@ -57,12 +57,12 @@ public: const SHADER_VARIABLE_TYPE* VarTypes, Uint32 NumVarTypes); - void Initialize(const std::shared_ptr& pSrcResources, - const SHADER_VARIABLE_TYPE* VarTypes, - Uint32 NumVarTypes, - ShaderResourceCacheD3D11& ResourceCache, - IMemoryAllocator& ResCacheDataAllocator, - IMemoryAllocator& ResLayoutDataAllocator); + void Initialize(std::shared_ptr pSrcResources, + const SHADER_VARIABLE_TYPE* VarTypes, + Uint32 NumVarTypes, + ShaderResourceCacheD3D11& ResourceCache, + IMemoryAllocator& ResCacheDataAllocator, + IMemoryAllocator& ResLayoutDataAllocator); void CopyResources(ShaderResourceCacheD3D11& DstCache); @@ -220,7 +220,10 @@ public: private: - const Char* GetShaderName()const; + const Char* GetShaderName()const + { + return m_pResources->GetShaderName(); + } // No need to use shared pointer, as the resource cache is either part of the same // ShaderD3D11Impl object, or ShaderResourceBindingD3D11Impl object diff --git a/Graphics/GraphicsEngineD3D11/include/ShaderResourcesD3D11.h b/Graphics/GraphicsEngineD3D11/include/ShaderResourcesD3D11.h index 7aee3bb9..c6bbcea4 100644 --- a/Graphics/GraphicsEngineD3D11/include/ShaderResourcesD3D11.h +++ b/Graphics/GraphicsEngineD3D11/include/ShaderResourcesD3D11.h @@ -51,7 +51,7 @@ // |_________________SamplerIndex_________________| // // -// One ShaderResources instance can be referenced by multiple objects +// One ShaderResourcesD3D11 instance can be referenced by multiple objects // // // _______ ________________________________ @@ -73,13 +73,14 @@ // // +#include #include "ShaderResources.h" namespace Diligent { -/// Diligent::ShaderResources class +/// Diligent::ShaderResourcesD3D11 class class ShaderResourcesD3D11 : public ShaderResources { public: @@ -90,10 +91,15 @@ public: const char* CombinedSamplerSuffix); ~ShaderResourcesD3D11(); - __forceinline Int32 GetMaxCBBindPoint() const{return m_MaxCBBindPoint; } - __forceinline Int32 GetMaxSRVBindPoint() const{return m_MaxSRVBindPoint; } - __forceinline Int32 GetMaxSamplerBindPoint()const{return m_MaxSamplerBindPoint; } - __forceinline Int32 GetMaxUAVBindPoint() const{return m_MaxUAVBindPoint; } + ShaderResourcesD3D11 (const ShaderResourcesD3D11&) = delete; + ShaderResourcesD3D11 ( ShaderResourcesD3D11&&) = delete; + ShaderResourcesD3D11& operator = (const ShaderResourcesD3D11&) = delete; + ShaderResourcesD3D11& operator = ( ShaderResourcesD3D11&&) = delete; + + __forceinline Int32 GetMaxCBBindPoint() const { return m_MaxCBBindPoint; } + __forceinline Int32 GetMaxSRVBindPoint() const { return m_MaxSRVBindPoint; } + __forceinline Int32 GetMaxSamplerBindPoint()const { return m_MaxSamplerBindPoint; } + __forceinline Int32 GetMaxUAVBindPoint() const { return m_MaxUAVBindPoint; } #ifdef DEVELOPMENT void dvpVerifyCommittedResources(ID3D11Buffer* CommittedD3D11CBs[], @@ -105,18 +111,17 @@ public: class ShaderResourceCacheD3D11& ResourceCache)const; #endif - const Char *GetShaderName()const{return m_ShaderName;} + const Char* GetShaderName() const { return m_ShaderName; } - void InitStaticSamplers(class ShaderResourceCacheD3D11& ResourceCache)const; + void SetStaticSamplers(class ShaderResourceCacheD3D11& ResourceCache)const; private: - typedef Int8 MaxBindPointType; + using MaxBindPointType = Int8; MaxBindPointType m_MaxCBBindPoint = -1; // Max == 13 MaxBindPointType m_MaxSRVBindPoint = -1; // Max == 127 MaxBindPointType m_MaxSamplerBindPoint = -1; // Max == 15 MaxBindPointType m_MaxUAVBindPoint = -1; // Max == 7 - Uint8 m_NumStaticSamplers = 0; // Max == 16 static constexpr UINT MaxAllowedBindPoint = std::numeric_limits::max(); static_assert(D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT-1 <= MaxAllowedBindPoint, "Not enough bits to represent max CB slot" ); @@ -126,17 +131,13 @@ private: // ShaderResourcesD3D11 is part of the ShaderD3D11Impl object, so we can simply // reference shader name without the need to copy it - const Char* m_ShaderName; + const Char* const m_ShaderName; - typedef std::pair > StaticSamplerAttribs; - StaticSamplerAttribs& GetStaticSampler(Uint32 n) - { - VERIFY_EXPR(n < m_NumStaticSamplers); - return reinterpret_cast< StaticSamplerAttribs* >(m_StaticSamplers.get())[n]; - } + using StaticSamplerAttribs = std::pair>; + using StaticSamplerVector = std::vector>; + void InitStaticSamplers(StaticSamplerVector&& StaticSamplers); - // We have to use void, because we will be calling destructors manually - std::unique_ptr< void, STDDeleterRawMem > m_StaticSamplers; + StaticSamplerVector m_StaticSamplers; }; } diff --git a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp index ee1e5f2d..6aa3665a 100755 --- a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp @@ -594,7 +594,7 @@ namespace Diligent #ifdef DEVELOPMENT - if( CommitResources && m_DebugFlags & (Uint32)EngineD3D11DebugFlags::VerifyCommittedShaderResources ) + if( CommitResources && (m_DebugFlags & (Uint32)EngineD3D11DebugFlags::VerifyCommittedShaderResources) != 0 ) { // Use full resource layout to verify that all required resources are committed pShaderD3D11->GetResources()->dvpVerifyCommittedResources( diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp index e8e9d8fd..0b128cd9 100644 --- a/Graphics/GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp @@ -87,7 +87,7 @@ ShaderD3D11Impl::ShaderD3D11Impl(IReferenceCounters* pRefCounters, m_StaticResLayout.Initialize(m_pShaderResources, VarTypes, _countof(VarTypes), m_StaticResCache, GetRawAllocator(), GetRawAllocator()); // This is not required, but still... - m_pShaderResources->InitStaticSamplers(m_StaticResCache); + m_pShaderResources->SetStaticSamplers(m_StaticResCache); // Byte code is only required for the vertex shader to create input layout if( CreationAttribs.Desc.ShaderType != SHADER_TYPE_VERTEX ) diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp index 021743e4..83f0dac1 100644 --- a/Graphics/GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp @@ -72,7 +72,7 @@ ShaderResourceBindingD3D11Impl::ShaderResourceBindingD3D11Impl( IReferenceCounte new (m_pResourceLayouts + s) ShaderResourceLayoutD3D11(*this); m_pResourceLayouts[s].Initialize(pShaderD3D11->GetResources(), VarTypes, _countof(VarTypes), m_pBoundResourceCaches[s], ResCacheDataAllocator, ResLayoutDataAllocator); - Resources.InitStaticSamplers(m_pBoundResourceCaches[s]); + Resources.SetStaticSamplers(m_pBoundResourceCaches[s]); m_ResourceLayoutIndex[ShaderInd] = s; m_ShaderTypeIndex[s] = static_cast(ShaderInd); diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderResourceLayoutD3D11.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderResourceLayoutD3D11.cpp index 22580688..1a175e38 100755 --- a/Graphics/GraphicsEngineD3D11/src/ShaderResourceLayoutD3D11.cpp +++ b/Graphics/GraphicsEngineD3D11/src/ShaderResourceLayoutD3D11.cpp @@ -32,7 +32,6 @@ #include "TextureBaseD3D11.h" #include "TextureViewD3D11.h" #include "SamplerD3D11Impl.h" -#include "D3DShaderResourceLoader.h" #include "ShaderD3D11Impl.h" namespace Diligent @@ -46,7 +45,7 @@ ShaderResourceLayoutD3D11::ShaderResourceLayoutD3D11(IObject& Owner) : ShaderResourceLayoutD3D11::~ShaderResourceLayoutD3D11() { HandleResources( - [&](ConstBuffBindInfo&cb) + [&](ConstBuffBindInfo& cb) { cb.~ConstBuffBindInfo(); }, @@ -93,23 +92,23 @@ size_t ShaderResourceLayoutD3D11::GetRequiredMemorySize(const ShaderResourcesD3D return MemSize; } -void ShaderResourceLayoutD3D11::Initialize(const std::shared_ptr& pSrcResources, - const SHADER_VARIABLE_TYPE* VarTypes, - Uint32 NumVarTypes, - ShaderResourceCacheD3D11& ResourceCache, - IMemoryAllocator& ResCacheDataAllocator, - IMemoryAllocator& ResLayoutDataAllocator) +void ShaderResourceLayoutD3D11::Initialize(std::shared_ptr pSrcResources, + const SHADER_VARIABLE_TYPE* VarTypes, + Uint32 NumVarTypes, + ShaderResourceCacheD3D11& ResourceCache, + IMemoryAllocator& ResCacheDataAllocator, + IMemoryAllocator& ResLayoutDataAllocator) { // http://diligentgraphics.com/diligent-engine/architecture/d3d11/shader-resource-layout#Shader-Resource-Layout-Initialization - m_pResources = pSrcResources; + m_pResources = std::move(pSrcResources); m_pResourceCache = &ResourceCache; auto AllowedTypeBits = GetAllowedTypeBits(VarTypes, NumVarTypes); // Count total number of resources of allowed types Uint32 NumCBs, NumTexSRVs, NumTexUAVs, NumBufSRVs, NumBufUAVs, NumSamplers; - pSrcResources->CountResources(VarTypes, NumVarTypes, NumCBs, NumTexSRVs, NumTexUAVs, NumBufSRVs, NumBufUAVs, NumSamplers); + m_pResources->CountResources(VarTypes, NumVarTypes, NumCBs, NumTexSRVs, NumTexUAVs, NumBufSRVs, NumBufUAVs, NumSamplers); // Initialize offsets m_TexSRVsOffset = 0 + static_cast( NumCBs * sizeof(ConstBuffBindInfo)); @@ -119,7 +118,7 @@ void ShaderResourceLayoutD3D11::Initialize(const std::shared_ptr( NumBufSRVs * sizeof(BuffSRVBindInfo) ); auto MemorySize = m_SamplerOffset + NumSamplers * sizeof(SamplerBindInfo) ; - VERIFY_EXPR(MemorySize == GetRequiredMemorySize(*pSrcResources, VarTypes, NumVarTypes)); + VERIFY_EXPR(MemorySize == GetRequiredMemorySize(*m_pResources, VarTypes, NumVarTypes)); if( MemorySize ) { @@ -152,7 +151,7 @@ void ShaderResourceLayoutD3D11::Initialize(const std::shared_ptrProcessResources( + m_pResources->ProcessResources( VarTypes, NumVarTypes, [&](const D3DShaderResourceAttribs& CB, Uint32) @@ -161,7 +160,7 @@ void ShaderResourceLayoutD3D11::Initialize(const std::shared_ptr(CB.BindPoint + CB.BindCount)); + NumCBSlots = std::max(NumCBSlots, Uint32{CB.BindPoint} + Uint32{CB.BindCount}); }, [&](const D3DShaderResourceAttribs& Sampler, Uint32) @@ -173,7 +172,7 @@ void ShaderResourceLayoutD3D11::Initialize(const std::shared_ptr(Sampler.BindPoint + Sampler.BindCount)); + NumSamplerSlots = std::max(NumSamplerSlots, Uint32{Sampler.BindPoint} + Uint32{Sampler.BindCount}); } }, @@ -205,7 +204,7 @@ void ShaderResourceLayoutD3D11::Initialize(const std::shared_ptr(TexSRV.BindPoint + TexSRV.BindCount)); + NumSRVSlots = std::max(NumSRVSlots, Uint32{TexSRV.BindPoint} + Uint32{TexSRV.BindCount}); }, [&](const D3DShaderResourceAttribs& TexUAV, Uint32) @@ -214,7 +213,7 @@ void ShaderResourceLayoutD3D11::Initialize(const std::shared_ptr(TexUAV.BindPoint + TexUAV.BindCount)); + NumUAVSlots = std::max(NumUAVSlots, Uint32{TexUAV.BindPoint} + Uint32{TexUAV.BindCount}); }, [&](const D3DShaderResourceAttribs& BuffSRV, Uint32) @@ -223,7 +222,7 @@ void ShaderResourceLayoutD3D11::Initialize(const std::shared_ptr(BuffSRV.BindPoint + BuffSRV.BindCount)); + NumSRVSlots = std::max(NumSRVSlots, Uint32{BuffSRV.BindPoint} + Uint32{BuffSRV.BindCount}); }, [&](const D3DShaderResourceAttribs& BuffUAV, Uint32) @@ -232,10 +231,17 @@ void ShaderResourceLayoutD3D11::Initialize(const std::shared_ptr(BuffUAV.BindPoint + BuffUAV.BindCount)); + NumUAVSlots = std::max(NumUAVSlots, Uint32{BuffUAV.BindPoint} + Uint32{BuffUAV.BindCount}); } ); + VERIFY(cb == m_NumCBs, "Not all CBs are initialized which will cause a crash when dtor is called"); + VERIFY(texSrv == m_NumTexSRVs, "Not all Tex SRVs are initialized which will cause a crash when dtor is called"); + VERIFY(texUav == m_NumTexUAVs, "Not all Tex UAVs are initialized which will cause a crash when dtor is called"); + VERIFY(bufSrv == m_NumBufSRVs, "Not all Buf SRVs are initialized which will cause a crash when dtor is called"); + VERIFY(bufUav == m_NumBufUAVs, "Not all Buf UAVs are initialized which will cause a crash when dtor is called"); + VERIFY(sam == m_NumSamplers, "Not all samplers are initialized which will cause a crash when dtor is called"); + // Shader resource cache in the SRB is initialized by the constructor of ShaderResourceBindingD3D11Impl to // hold all variable types. The corresponding layout in the SRB is initialized to keep mutable and dynamic // variables only @@ -245,23 +251,16 @@ void ShaderResourceLayoutD3D11::Initialize(const std::shared_ptrInitialize(NumCBSlots, NumSRVSlots, NumSamplerSlots, NumUAVSlots, ResCacheDataAllocator); } - - VERIFY(cb == m_NumCBs, "Not all CBs are initialized which will cause a crash when dtor is called"); - VERIFY(texSrv == m_NumTexSRVs, "Not all Tex SRVs are initialized which will cause a crash when dtor is called"); - VERIFY(texUav == m_NumTexUAVs, "Not all Tex UAVs are initialized which will cause a crash when dtor is called"); - VERIFY(bufSrv == m_NumBufSRVs, "Not all Buf SRVs are initialized which will cause a crash when dtor is called"); - VERIFY(bufUav == m_NumBufUAVs, "Not all Buf UAVs are initialized which will cause a crash when dtor is called"); - VERIFY(sam == m_NumSamplers, "Not all samplers are initialized which will cause a crash when dtor is called"); } void ShaderResourceLayoutD3D11::CopyResources(ShaderResourceCacheD3D11& DstCache) { VERIFY(m_pResourceCache, "Resource cache must not be null"); - VERIFY( DstCache.GetCBCount() >= m_pResourceCache->GetCBCount(), "Dst cache is not large enough to contain all CBs" ); - VERIFY( DstCache.GetSRVCount() >= m_pResourceCache->GetSRVCount(), "Dst cache is not large enough to contain all SRVs" ); + VERIFY( DstCache.GetCBCount() >= m_pResourceCache->GetCBCount(), "Dst cache is not large enough to contain all CBs" ); + VERIFY( DstCache.GetSRVCount() >= m_pResourceCache->GetSRVCount(), "Dst cache is not large enough to contain all SRVs" ); VERIFY( DstCache.GetSamplerCount() >= m_pResourceCache->GetSamplerCount(), "Dst cache is not large enough to contain all samplers" ); - VERIFY( DstCache.GetUAVCount() >= m_pResourceCache->GetUAVCount(), "Dst cache is not large enough to contain all UAVs" ); + VERIFY( DstCache.GetUAVCount() >= m_pResourceCache->GetUAVCount(), "Dst cache is not large enough to contain all UAVs" ); ShaderResourceCacheD3D11::CachedCB* CachedCBs = nullptr; ID3D11Buffer** d3d11CBs = nullptr; @@ -358,61 +357,52 @@ void ShaderResourceLayoutD3D11::CopyResources(ShaderResourceCacheD3D11& DstCache do{ \ const auto* ResName = pResource->GetDesc().Name; \ if(Attribs.BindCount>1) \ - LOG_ERROR_MESSAGE( "Failed to bind ", ResType, " \"", ResName, "\" to variable \"", Attribs.Name,\ - "[", ArrayInd, "]\" in shader \"", ShaderName, "\". ", __VA_ARGS__ ); \ + LOG_ERROR_MESSAGE( "Failed to bind ", ResType, " '", ResName, "' to variable '", Attribs.Name,\ + "[", ArrayInd, "]' in shader '", ShaderName, "'. ", __VA_ARGS__ ); \ else \ - LOG_ERROR_MESSAGE( "Failed to bind ", ResType, " \"", ResName, "\" to variable \"", Attribs.Name,\ - "\" in shader \"", ShaderName, "\". ", __VA_ARGS__ ); \ + LOG_ERROR_MESSAGE( "Failed to bind ", ResType, " '", ResName, "' to variable '", Attribs.Name,\ + "' in shader '", ShaderName, "'. ", __VA_ARGS__ ); \ }while(false) void ShaderResourceLayoutD3D11::ConstBuffBindInfo::BindResource(IDeviceObject* pBuffer, Uint32 ArrayIndex) { - auto &pResourceCache = m_ParentResLayout.m_pResourceCache; - VERIFY(pResourceCache, "Resource cache is null"); + VERIFY(m_ParentResLayout.m_pResourceCache != nullptr, "Resource cache is null"); DEV_CHECK_ERR(ArrayIndex < Attribs.BindCount, "Array index (", ArrayIndex, ") is out of range for variable '", Attribs.Name, "'. Max allowed index: ", Attribs.BindCount); + auto& ResourceCache = *m_ParentResLayout.m_pResourceCache; + + // We cannot use ValidatedCast<> here as the resource retrieved from the + // resource mapping can be of wrong type + RefCntAutoPtr pBuffD3D11Impl(pBuffer, IID_BufferD3D11); +#ifdef DEVELOPMENT + if (pBuffer && !pBuffD3D11Impl) + LOG_RESOURCE_BINDING_ERROR("buffer", pBuffer, Attribs, ArrayIndex, m_ParentResLayout.GetShaderName(), "Incorrect resource type: buffer is expected."); - RefCntAutoPtr pBuffD3D11Impl; - if( pBuffer ) + if (pBuffD3D11Impl && (pBuffD3D11Impl->GetDesc().BindFlags & BIND_UNIFORM_BUFFER) == 0) { - // We cannot use ValidatedCast<> here as the resource retrieved from the - // resource mapping can be of wrong type - IBufferD3D11 *pBuffD3D11 = nullptr; - pBuffer->QueryInterface(IID_BufferD3D11, reinterpret_cast(&pBuffD3D11)); - if( pBuffD3D11 ) - { - pBuffD3D11Impl.Attach(ValidatedCast(pBuffD3D11)); - if( !(pBuffD3D11Impl->GetDesc().BindFlags & BIND_UNIFORM_BUFFER) ) - { - pBuffD3D11Impl.Release(); - LOG_RESOURCE_BINDING_ERROR("buffer", pBuffer, Attribs, ArrayIndex, m_ParentResLayout.GetShaderName(), "Buffer was not created with BIND_UNIFORM_BUFFER flag."); - } - } - else - { - LOG_RESOURCE_BINDING_ERROR("buffer", pBuffer, Attribs, ArrayIndex, m_ParentResLayout.GetShaderName(), "Incorrect resource type: buffer is expected."); - } + LOG_RESOURCE_BINDING_ERROR("buffer", pBuffer, Attribs, ArrayIndex, m_ParentResLayout.GetShaderName(), "Buffer was not created with BIND_UNIFORM_BUFFER flag."); + pBuffD3D11Impl.Release(); } - -#ifdef DEVELOPMENT - if( Attribs.GetVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC) + + if (Attribs.GetVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC) { - auto &CachedCB = pResourceCache->GetCB(Attribs.BindPoint + ArrayIndex); - if( CachedCB.pBuff != nullptr && CachedCB.pBuff != pBuffD3D11Impl) + auto& CachedCB = ResourceCache.GetCB(Attribs.BindPoint + ArrayIndex); + if (CachedCB.pBuff != nullptr && CachedCB.pBuff != pBuffD3D11Impl) { auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.GetVariableType()); - LOG_ERROR_MESSAGE( "Non-null constant buffer is already bound to ", VarTypeStr, " shader variable \"", Attribs.GetPrintName(ArrayIndex), "\" in shader \"", m_ParentResLayout.GetShaderName(), "\". Attempting to bind another resource or null is an error and may cause unpredicted behavior. Use another shader resource binding instance or label the variable as dynamic." ); + LOG_ERROR_MESSAGE( "Non-null constant buffer is already bound to ", VarTypeStr, " shader variable '", Attribs.GetPrintName(ArrayIndex), "' in shader '", m_ParentResLayout.GetShaderName(), "'. Attempting to bind another resource or null is an error and may cause unpredicted behavior. Use another shader resource binding instance or label the variable as dynamic." ); } } #endif - pResourceCache->SetCB(Attribs.BindPoint + ArrayIndex, std::move(pBuffD3D11Impl) ); + + ResourceCache.SetCB(Attribs.BindPoint + ArrayIndex, std::move(pBuffD3D11Impl) ); } bool ShaderResourceLayoutD3D11::ConstBuffBindInfo::IsBound(Uint32 ArrayIndex) { - auto &pResourceCache = m_ParentResLayout.m_pResourceCache; + auto* pResourceCache = m_ParentResLayout.m_pResourceCache; VERIFY(pResourceCache, "Resource cache is null"); VERIFY_EXPR(ArrayIndex < Attribs.BindCount); @@ -424,12 +414,12 @@ bool ShaderResourceLayoutD3D11::ConstBuffBindInfo::IsBound(Uint32 ArrayIndex) #ifdef DEVELOPMENT template ///< Type of the expected view enum -bool dbgVerifyViewType( const char *ViewTypeName, - TResourceViewType pViewD3D11, +bool dbgVerifyViewType( const char* ViewTypeName, + TResourceViewType pViewD3D11, const D3DShaderResourceAttribs& Attribs, - Uint32 ArrayIndex, - TViewTypeEnum dbgExpectedViewType, - const String &ShaderName ) + Uint32 ArrayIndex, + TViewTypeEnum dbgExpectedViewType, + const Char* ShaderName ) { const auto& ViewDesc = pViewD3D11->GetDesc(); auto ViewType = ViewDesc.ViewType; @@ -442,7 +432,7 @@ bool dbgVerifyViewType( const char *ViewTypeName, const auto *ExpectedViewTypeName = GetViewTypeLiteralName( dbgExpectedViewType ); const auto *ActualViewTypeName = GetViewTypeLiteralName( ViewType ); LOG_RESOURCE_BINDING_ERROR(ViewTypeName, pViewD3D11, Attribs, ArrayIndex, ShaderName, - "Incorrect view type: ", ExpectedViewTypeName, " is expected, ", ActualViewTypeName, " provided." ); + "Incorrect view type: ", ExpectedViewTypeName, " is expected, ", ActualViewTypeName, " is provided." ); return false; } } @@ -460,17 +450,17 @@ void ShaderResourceLayoutD3D11::TexSRVBindInfo::BindResource(IDeviceObject* pVie RefCntAutoPtr pViewD3D11(pView, IID_TextureViewD3D11); #ifdef DEVELOPMENT if (pView && !pViewD3D11) - LOG_RESOURCE_BINDING_ERROR("resource", pView, Attribs, ArrayIndex, "", "Incorect resource type: texture view is expected."); + LOG_RESOURCE_BINDING_ERROR("resource", pView, Attribs, ArrayIndex, m_ParentResLayout.GetShaderName(), "Incorect resource type: texture view is expected."); if (pViewD3D11 && !dbgVerifyViewType("texture view", pViewD3D11.RawPtr(), Attribs, ArrayIndex, TEXTURE_VIEW_SHADER_RESOURCE, m_ParentResLayout.GetShaderName())) pViewD3D11.Release(); if( Attribs.GetVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC) { - auto &CachedSRV = ResourceCache.GetSRV(Attribs.BindPoint + ArrayIndex); - if( CachedSRV.pView != nullptr && CachedSRV.pView != pViewD3D11) + auto& CachedSRV = ResourceCache.GetSRV(Attribs.BindPoint + ArrayIndex); + if (CachedSRV.pView != nullptr && CachedSRV.pView != pViewD3D11) { auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.GetVariableType()); - LOG_ERROR_MESSAGE( "Non-null texture SRV is already bound to ", VarTypeStr, " shader variable \"", Attribs.GetPrintName(ArrayIndex), "\" in shader \"", m_ParentResLayout.GetShaderName(), "\". Attempting to bind another resource or null is an error and may cause unpredicted behavior. Use another shader resource binding instance or label the variable as dynamic." ); + LOG_ERROR_MESSAGE( "Non-null texture SRV is already bound to ", VarTypeStr, " shader variable '", Attribs.GetPrintName(ArrayIndex), "' in shader '", m_ParentResLayout.GetShaderName(), "'. Attempting to bind another resource or null is an error and may cause unpredicted behavior. Use another shader resource binding instance or label the variable as dynamic." ); } } #endif @@ -482,20 +472,31 @@ void ShaderResourceLayoutD3D11::TexSRVBindInfo::BindResource(IDeviceObject* pVie VERIFY_EXPR(Sampler.Attribs.BindCount == Attribs.BindCount || Sampler.Attribs.BindCount == 1); auto SamplerBindPoint = Sampler.Attribs.BindPoint + (Sampler.Attribs.BindCount != 1 ? ArrayIndex : 0); - SamplerD3D11Impl *pSamplerD3D11Impl = nullptr; - if( pViewD3D11 ) + SamplerD3D11Impl* pSamplerD3D11Impl = nullptr; + if (pViewD3D11) { pSamplerD3D11Impl = ValidatedCast(pViewD3D11->GetSampler()); #ifdef DEVELOPMENT if (pSamplerD3D11Impl == nullptr) { if(Sampler.Attribs.BindCount > 1) - LOG_ERROR_MESSAGE( "Failed to bind sampler to variable \"", Sampler.Attribs.Name, "[", ArrayIndex,"]\". Sampler is not set in the texture view \"", pViewD3D11->GetDesc().Name, "\"" ); + LOG_ERROR_MESSAGE( "Failed to bind sampler to variable '", Sampler.Attribs.Name, "[", ArrayIndex,"]'. Sampler is not set in the texture view '", pViewD3D11->GetDesc().Name, "'" ); else - LOG_ERROR_MESSAGE( "Failed to bind sampler to variable \"", Sampler.Attribs.Name, "\". Sampler is not set in the texture view \"", pViewD3D11->GetDesc().Name, "\"" ); + LOG_ERROR_MESSAGE( "Failed to bind sampler to variable '", Sampler.Attribs.Name, "'. Sampler is not set in the texture view '", pViewD3D11->GetDesc().Name, "'" ); } #endif } +#ifdef DEVELOPMENT + if (Sampler.Attribs.GetVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC) + { + auto& CachedSampler = ResourceCache.GetSampler(SamplerBindPoint); + if (CachedSampler.pSampler != nullptr && CachedSampler.pSampler != pSamplerD3D11Impl) + { + auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.GetVariableType()); + LOG_ERROR_MESSAGE( "Non-null sampler is already bound to ", VarTypeStr, " shader variable '", Sampler.Attribs.GetPrintName(ArrayIndex), "' in shader '", m_ParentResLayout.GetShaderName(), "'. Attempting to bind another sampler or null is an error and may cause unpredicted behavior. Use another shader resource binding instance or label the variable as dynamic." ); + } + } +#endif ResourceCache.SetSampler(SamplerBindPoint, pSamplerD3D11Impl); } @@ -516,7 +517,7 @@ void ShaderResourceLayoutD3D11::SamplerBindInfo::BindResource(IDeviceObject* pSa #ifdef DEVELOPMENT if (pSampler && !pSamplerD3D11) - LOG_RESOURCE_BINDING_ERROR("sampler", pSampler, Attribs, ArrayIndex, "", "Incorect resource type: sampler is expected."); + LOG_RESOURCE_BINDING_ERROR("sampler", pSampler, Attribs, ArrayIndex, m_ParentResLayout.GetShaderName(), "Incorect resource type: sampler is expected."); if (Attribs.ValidTexSRVAssigned()) { @@ -524,13 +525,13 @@ void ShaderResourceLayoutD3D11::SamplerBindInfo::BindResource(IDeviceObject* pSa LOG_WARNING_MESSAGE("Texture sampler sampler '", Attribs.Name, "' is assigned to texture SRV '", TexSRVName, "' and should not be accessed directly. The sampler is initialized when texture SRV is set to '", TexSRVName, "' variable."); } - if( Attribs.GetVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC) + if (Attribs.GetVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC) { - auto &CachedSampler = ResourceCache.GetSampler(Attribs.BindPoint + ArrayIndex); + auto& CachedSampler = ResourceCache.GetSampler(Attribs.BindPoint + ArrayIndex); if( CachedSampler.pSampler != nullptr && CachedSampler.pSampler != pSamplerD3D11) { auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.GetVariableType()); - LOG_ERROR_MESSAGE( "Non-null sampler is already bound to ", VarTypeStr, " shader variable \"", Attribs.GetPrintName(ArrayIndex), "\" in shader \"", m_ParentResLayout.GetShaderName(), "\". Attempting to bind another sampler or null is an error and may cause unpredicted behavior. Use another shader resource binding instance or label the variable as dynamic." ); + LOG_ERROR_MESSAGE( "Non-null sampler is already bound to ", VarTypeStr, " shader variable '", Attribs.GetPrintName(ArrayIndex), "' in shader '", m_ParentResLayout.GetShaderName(), "'. Attempting to bind another sampler or null is an error and may cause unpredicted behavior. Use another shader resource binding instance or label the variable as dynamic." ); } } #endif @@ -550,17 +551,17 @@ void ShaderResourceLayoutD3D11::BuffSRVBindInfo::BindResource(IDeviceObject* pVi RefCntAutoPtr pViewD3D11(pView, IID_BufferViewD3D11); #ifdef DEVELOPMENT if (pView && !pViewD3D11) - LOG_RESOURCE_BINDING_ERROR("resource", pView, Attribs, ArrayIndex, "", "Incorect resource type: buffer view is expected."); + LOG_RESOURCE_BINDING_ERROR("resource", pView, Attribs, ArrayIndex, m_ParentResLayout.GetShaderName(), "Incorect resource type: buffer view is expected."); if (pViewD3D11 && !dbgVerifyViewType("buffer view", pViewD3D11.RawPtr(), Attribs, ArrayIndex, BUFFER_VIEW_SHADER_RESOURCE, m_ParentResLayout.GetShaderName())) pViewD3D11.Release(); if (Attribs.GetVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC) { - auto &CachedSRV = ResourceCache.GetSRV(Attribs.BindPoint + ArrayIndex); - if( CachedSRV.pView != nullptr && CachedSRV.pView != pViewD3D11) + auto& CachedSRV = ResourceCache.GetSRV(Attribs.BindPoint + ArrayIndex); + if (CachedSRV.pView != nullptr && CachedSRV.pView != pViewD3D11) { auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.GetVariableType()); - LOG_ERROR_MESSAGE( "Non-null buffer SRV is already bound to ", VarTypeStr, " shader variable \"", Attribs.GetPrintName(ArrayIndex), "\" in shader \"", m_ParentResLayout.GetShaderName(), "\". Attempting to bind another resource or null is an error and may cause unpredicted behavior. Use another shader resource binding instance or label the variable as dynamic." ); + LOG_ERROR_MESSAGE( "Non-null buffer SRV is already bound to ", VarTypeStr, " shader variable '", Attribs.GetPrintName(ArrayIndex), "' in shader '", m_ParentResLayout.GetShaderName(), "'. Attempting to bind another resource or null is an error and may cause unpredicted behavior. Use another shader resource binding instance or label the variable as dynamic." ); } } #endif @@ -581,17 +582,17 @@ void ShaderResourceLayoutD3D11::TexUAVBindInfo::BindResource(IDeviceObject* pVie RefCntAutoPtr pViewD3D11(pView, IID_TextureViewD3D11); #ifdef DEVELOPMENT if (pView && !pViewD3D11) - LOG_RESOURCE_BINDING_ERROR("resource", pView, Attribs, ArrayIndex, "", "Incorect resource type: texture view is expected."); + LOG_RESOURCE_BINDING_ERROR("resource", pView, Attribs, ArrayIndex, m_ParentResLayout.GetShaderName(), "Incorect resource type: texture view is expected."); if (pViewD3D11 && !dbgVerifyViewType("texture view", pViewD3D11.RawPtr(), Attribs, ArrayIndex, TEXTURE_VIEW_UNORDERED_ACCESS, m_ParentResLayout.GetShaderName())) pViewD3D11.Release(); if (Attribs.GetVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC) { - auto &CachedUAV = ResourceCache.GetUAV(Attribs.BindPoint + ArrayIndex); - if( CachedUAV.pView != nullptr && CachedUAV.pView != pViewD3D11) + auto& CachedUAV = ResourceCache.GetUAV(Attribs.BindPoint + ArrayIndex); + if (CachedUAV.pView != nullptr && CachedUAV.pView != pViewD3D11) { auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.GetVariableType()); - LOG_ERROR_MESSAGE( "Non-null texture UAV is already bound to ", VarTypeStr, " shader variable \"", Attribs.GetPrintName(ArrayIndex), "\" in shader \"", m_ParentResLayout.GetShaderName(), "\". Attempting to bind another resource or null is an error and may cause unpredicted behavior. Use another shader resource binding instance or label the variable as dynamic." ); + LOG_ERROR_MESSAGE( "Non-null texture UAV is already bound to ", VarTypeStr, " shader variable '", Attribs.GetPrintName(ArrayIndex), "' in shader '", m_ParentResLayout.GetShaderName(), "'. Attempting to bind another resource or null is an error and may cause unpredicted behavior. Use another shader resource binding instance or label the variable as dynamic." ); } } #endif @@ -612,17 +613,17 @@ void ShaderResourceLayoutD3D11::BuffUAVBindInfo::BindResource(IDeviceObject* pVi RefCntAutoPtr pViewD3D11(pView, IID_BufferViewD3D11); #ifdef DEVELOPMENT if (pView && !pViewD3D11) - LOG_RESOURCE_BINDING_ERROR("resource", pView, Attribs, ArrayIndex, "", "Incorect resource type: buffer view is expected."); + LOG_RESOURCE_BINDING_ERROR("resource", pView, Attribs, ArrayIndex, m_ParentResLayout.GetShaderName(), "Incorect resource type: buffer view is expected."); if (pViewD3D11 && !dbgVerifyViewType("buffer view", pViewD3D11.RawPtr(), Attribs, ArrayIndex, BUFFER_VIEW_UNORDERED_ACCESS, m_ParentResLayout.GetShaderName()) ) pViewD3D11.Release(); if (Attribs.GetVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC) { - auto &CachedUAV = ResourceCache.GetUAV(Attribs.BindPoint + ArrayIndex); - if( CachedUAV.pView != nullptr && CachedUAV.pView != pViewD3D11) + auto& CachedUAV = ResourceCache.GetUAV(Attribs.BindPoint + ArrayIndex); + if (CachedUAV.pView != nullptr && CachedUAV.pView != pViewD3D11) { auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.GetVariableType()); - LOG_ERROR_MESSAGE( "Non-null buffer UAV is already bound to ", VarTypeStr, " shader variable \"", Attribs.GetPrintName(ArrayIndex), "\" in shader \"", m_ParentResLayout.GetShaderName(), "\". Attempting to bind another resource or null is an error and may cause unpredicted behavior. Use another shader resource binding instance or label the variable as dynamic." ); + LOG_ERROR_MESSAGE( "Non-null buffer UAV is already bound to ", VarTypeStr, " shader variable '", Attribs.GetPrintName(ArrayIndex), "' in shader '", m_ParentResLayout.GetShaderName(), "'. Attempting to bind another resource or null is an error and may cause unpredicted behavior. Use another shader resource binding instance or label the variable as dynamic." ); } } #endif @@ -711,7 +712,7 @@ public: else { if ( (Flags & BIND_SHADER_RESOURCES_VERIFY_ALL_RESOLVED) && !Res.IsBound(elem) ) - LOG_ERROR_MESSAGE( "Cannot bind resource to shader variable \"", VarName, "\": resource view not found in the resource mapping" ); + LOG_ERROR_MESSAGE( "Cannot bind resource to shader variable '", VarName, "': resource view not found in the resource mapping" ); } } } @@ -727,7 +728,7 @@ void ShaderResourceLayoutD3D11::BindResources( IResourceMapping* pResourceMappin if (pResourceMapping == nullptr) { - LOG_ERROR_MESSAGE( "Failed to bind resources in shader \"", GetShaderName(), "\": resource mapping is null" ); + LOG_ERROR_MESSAGE( "Failed to bind resources in shader '", GetShaderName(), "': resource mapping is null" ); return; } @@ -787,9 +788,13 @@ IShaderVariable* ShaderResourceLayoutD3D11::GetShaderVariable(const Char* Name) for (Uint32 u = 0; u < m_NumBufUAVs; ++u) if (strcmp(GetBufUAV(u).Attribs.Name, Name) == 0 ) return &GetBufUAV(u); - for (Uint32 s = 0; s < m_NumSamplers; ++s) - if (strcmp(GetSampler(s).Attribs.Name, Name) == 0 ) - return &GetSampler(s); + + if (!m_pResources->IsUsingCombinedTextureSamplers()) + { + for (Uint32 s = 0; s < m_NumSamplers; ++s) + if (strcmp(GetSampler(s).Attribs.Name, Name) == 0 ) + return &GetSampler(s); + } return nullptr; } @@ -844,7 +849,8 @@ Uint32 ShaderResourceLayoutD3D11::GetVariableIndex(const ShaderVariableD3D11Base else Index += m_NumBufSRVs; - if (Offset < static_cast(m_SamplerOffset + m_NumSamplers * sizeof(SamplerBindInfo))) + if (!m_pResources->IsUsingCombinedTextureSamplers() && + Offset < static_cast(m_SamplerOffset + m_NumSamplers * sizeof(SamplerBindInfo))) { DEV_CHECK_ERR( (Offset - m_SamplerOffset) % sizeof(SamplerBindInfo) == 0, "Offset is not multiple of sizeof(SamplerBindInfo)" ); return Index + static_cast((Offset - m_SamplerOffset) / sizeof(SamplerBindInfo)); @@ -858,7 +864,7 @@ Uint32 ShaderResourceLayoutD3D11::GetVariableIndex(const ShaderVariableD3D11Base IShaderVariable* ShaderResourceLayoutD3D11::GetShaderVariable( Uint32 Index ) { - if(Index >= GetTotalResourceCount()) + if (Index >= GetTotalResourceCount()) { LOG_ERROR("Invalid resource index ", Index); return nullptr; @@ -902,10 +908,6 @@ IShaderVariable* ShaderResourceLayoutD3D11::GetShaderVariable( Uint32 Index ) return nullptr; } -const Char* ShaderResourceLayoutD3D11::GetShaderName()const -{ - return m_pResources->GetShaderName(); -} #ifdef DEVELOPMENT void ShaderResourceLayoutD3D11::dvpVerifyBindings()const @@ -913,10 +915,10 @@ void ShaderResourceLayoutD3D11::dvpVerifyBindings()const #define LOG_MISSING_BINDING(VarType, Attrs, BindPt)\ do{ \ - if(Attrs.BindCount == 1) \ - LOG_ERROR_MESSAGE( "No resource is bound to ", VarType, " variable \"", Attrs.Name, "\" in shader \"", GetShaderName(), "\"" ); \ + if (Attrs.BindCount == 1) \ + LOG_ERROR_MESSAGE( "No resource is bound to ", VarType, " variable '", Attrs.Name, "' in shader '", GetShaderName(), "'" ); \ else \ - LOG_ERROR_MESSAGE( "No resource is bound to ", VarType, " variable \"", Attrs.Name, "[", BindPt-Attrs.BindPoint, "]\" in shader \"", GetShaderName(), "\"" );\ + LOG_ERROR_MESSAGE( "No resource is bound to ", VarType, " variable '", Attrs.Name, "[", BindPt-Attrs.BindPoint, "]' in shader '", GetShaderName(), "'" );\ }while(false) m_pResourceCache->dbgVerifyCacheConsistency(); @@ -924,9 +926,9 @@ do{ \ // Use const_cast to avoid duplication of the HandleResources() function // The function actually changes nothing const_cast(this)->HandleResources( - [&](const ConstBuffBindInfo&cb) + [&](const ConstBuffBindInfo& cb) { - for (auto BindPoint = cb.Attribs.BindPoint; BindPoint < cb.Attribs.BindPoint + cb.Attribs.BindCount; ++BindPoint) + for (Uint32 BindPoint = cb.Attribs.BindPoint; BindPoint < Uint32{cb.Attribs.BindPoint} + cb.Attribs.BindCount; ++BindPoint) { if (!m_pResourceCache->IsCBBound(BindPoint)) LOG_MISSING_BINDING("constant buffer", cb.Attribs, BindPoint); @@ -935,7 +937,7 @@ do{ \ [&](const TexSRVBindInfo& ts) { - for (auto BindPoint = ts.Attribs.BindPoint; BindPoint < ts.Attribs.BindPoint + ts.Attribs.BindCount; ++BindPoint) + for (Uint32 BindPoint = ts.Attribs.BindPoint; BindPoint < Uint32{ts.Attribs.BindPoint} + ts.Attribs.BindCount; ++BindPoint) { if (!m_pResourceCache->IsSRVBound(BindPoint, true)) LOG_MISSING_BINDING("texture", ts.Attribs, BindPoint); @@ -948,23 +950,23 @@ do{ \ // Verify that if single sampler is used for all texture array elements, all samplers set in the resource views are consistent if (ts.Attribs.BindCount > 1 && Sampler.Attribs.BindCount == 1) { - ShaderResourceCacheD3D11::CachedSampler *pCachedSamplers = nullptr; - ID3D11SamplerState **ppCachedD3D11Samplers = nullptr; + ShaderResourceCacheD3D11::CachedSampler* pCachedSamplers = nullptr; + ID3D11SamplerState** ppCachedD3D11Samplers = nullptr; m_pResourceCache->GetSamplerArrays(pCachedSamplers, ppCachedD3D11Samplers); VERIFY_EXPR(Sampler.Attribs.BindPoint < m_pResourceCache->GetSamplerCount()); const auto& CachedSampler = pCachedSamplers[Sampler.Attribs.BindPoint]; - ShaderResourceCacheD3D11::CachedResource *pCachedResources = nullptr; - ID3D11ShaderResourceView **ppCachedD3D11Resources = nullptr; + ShaderResourceCacheD3D11::CachedResource* pCachedResources = nullptr; + ID3D11ShaderResourceView** ppCachedD3D11Resources = nullptr; m_pResourceCache->GetSRVArrays(pCachedResources, ppCachedD3D11Resources); VERIFY_EXPR(BindPoint < m_pResourceCache->GetSRVCount()); auto& CachedResource = pCachedResources[BindPoint]; - if(CachedResource.pView) + if (CachedResource.pView) { auto* pTexView = CachedResource.pView.RawPtr(); auto* pSampler = pTexView->GetSampler(); - if(pSampler != nullptr && pSampler != CachedSampler.pSampler.RawPtr()) - LOG_ERROR_MESSAGE( "All elements of texture array \"", ts.Attribs.Name, "\" in shader \"", GetShaderName(), "\" share the same sampler. However, the sampler set in view for element ", BindPoint - ts.Attribs.BindPoint, " does not match bound sampler. This may cause incorrect behavior on GL platform." ); + if (pSampler != nullptr && pSampler != CachedSampler.pSampler.RawPtr()) + LOG_ERROR_MESSAGE( "All elements of texture array '", ts.Attribs.Name, "' in shader '", GetShaderName(), "' share the same sampler. However, the sampler set in view for element ", BindPoint - ts.Attribs.BindPoint, " does not match bound sampler. This may cause incorrect behavior on GL platform." ); } } } @@ -973,7 +975,7 @@ do{ \ [&](const TexUAVBindInfo& uav) { - for (auto BindPoint = uav.Attribs.BindPoint; BindPoint < uav.Attribs.BindPoint + uav.Attribs.BindCount; ++BindPoint) + for (Uint32 BindPoint = uav.Attribs.BindPoint; BindPoint < Uint32{uav.Attribs.BindPoint} + uav.Attribs.BindCount; ++BindPoint) { if (!m_pResourceCache->IsUAVBound(BindPoint, true)) LOG_MISSING_BINDING("texture UAV", uav.Attribs, BindPoint); @@ -982,7 +984,7 @@ do{ \ [&](const BuffSRVBindInfo& buf) { - for (auto BindPoint = buf.Attribs.BindPoint; BindPoint < buf.Attribs.BindPoint + buf.Attribs.BindCount; ++BindPoint) + for (Uint32 BindPoint = buf.Attribs.BindPoint; BindPoint < Uint32{buf.Attribs.BindPoint} + buf.Attribs.BindCount; ++BindPoint) { if (!m_pResourceCache->IsSRVBound(BindPoint, false)) LOG_MISSING_BINDING("buffer", buf.Attribs, BindPoint); @@ -991,7 +993,7 @@ do{ \ [&](const BuffUAVBindInfo& uav) { - for (auto BindPoint = uav.Attribs.BindPoint; BindPoint < uav.Attribs.BindPoint + uav.Attribs.BindCount; ++BindPoint) + for (Uint32 BindPoint = uav.Attribs.BindPoint; BindPoint < Uint32{uav.Attribs.BindPoint} + uav.Attribs.BindCount; ++BindPoint) { if (!m_pResourceCache->IsUAVBound(BindPoint, false)) LOG_MISSING_BINDING("buffer UAV", uav.Attribs, BindPoint); @@ -1000,7 +1002,7 @@ do{ \ [&](const SamplerBindInfo& sam) { - for (auto BindPoint = sam.Attribs.BindPoint; BindPoint < sam.Attribs.BindPoint + sam.Attribs.BindCount; ++BindPoint) + for (Uint32 BindPoint = sam.Attribs.BindPoint; BindPoint < Uint32{sam.Attribs.BindPoint} + sam.Attribs.BindCount; ++BindPoint) { if (!m_pResourceCache->IsSamplerBound(BindPoint)) LOG_MISSING_BINDING("sampler", sam.Attribs, BindPoint); diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderResourcesD3D11.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderResourcesD3D11.cpp index 544d9088..bdee52a0 100755 --- a/Graphics/GraphicsEngineD3D11/src/ShaderResourcesD3D11.cpp +++ b/Graphics/GraphicsEngineD3D11/src/ShaderResourcesD3D11.cpp @@ -26,7 +26,6 @@ #include #include "ShaderResourcesD3D11.h" #include "ShaderBase.h" -#include "D3DShaderResourceLoader.h" #include "ShaderResourceCacheD3D11.h" #include "RenderDeviceD3D11Impl.h" @@ -40,118 +39,125 @@ ShaderResourcesD3D11::ShaderResourcesD3D11(RenderDeviceD3D11Impl* pDeviceD3D11Im const char* CombinedSamplerSuffix) : ShaderResources(ShdrDesc.ShaderType), m_ShaderName(ShdrDesc.Name), - m_StaticSamplers(nullptr, STDDeleterRawMem< void >(GetRawAllocator())) + m_StaticSamplers(STD_ALLOCATOR_RAW_MEM(StaticSamplerAttribs, GetRawAllocator(), "Allocator for vector")) { class NewResourceHandler { public: - NewResourceHandler(ShaderResourcesD3D11& ResourcesD3D11) : - Res(ResourcesD3D11) + NewResourceHandler(RenderDeviceD3D11Impl* const _pDeviceD3D11Impl, + const ShaderDesc& _ShdrDesc, + const char* _CombinedSamplerSuffix, + ShaderResourcesD3D11& _Resources) : + pDeviceD3D11Impl (_pDeviceD3D11Impl), + ShdrDesc (_ShdrDesc), + CombinedSamplerSuffix(_CombinedSamplerSuffix), + Resources (_Resources), + m_StaticSamplers (STD_ALLOCATOR_RAW_MEM(StaticSamplerAttribs, GetRawAllocator(), "Allocator for vector")) {} void OnNewCB(const D3DShaderResourceAttribs& CBAttribs) { VERIFY( CBAttribs.BindPoint + CBAttribs.BindCount-1 <= MaxAllowedBindPoint, "CB bind point exceeds supported range" ); - Res.m_MaxCBBindPoint = std::max(Res.m_MaxCBBindPoint, static_cast(CBAttribs.BindPoint + CBAttribs.BindCount-1)); + Resources.m_MaxCBBindPoint = std::max(Resources.m_MaxCBBindPoint, static_cast(CBAttribs.BindPoint + CBAttribs.BindCount-1)); } void OnNewTexUAV (const D3DShaderResourceAttribs& TexUAV) { VERIFY( TexUAV.BindPoint + TexUAV.BindCount-1 <= MaxAllowedBindPoint, "Tex UAV bind point exceeds supported range" ); - Res.m_MaxUAVBindPoint = std::max(Res.m_MaxUAVBindPoint, static_cast(TexUAV.BindPoint + TexUAV.BindCount-1)); + Resources.m_MaxUAVBindPoint = std::max(Resources.m_MaxUAVBindPoint, static_cast(TexUAV.BindPoint + TexUAV.BindCount-1)); } void OnNewBuffUAV(const D3DShaderResourceAttribs& BuffUAV) { VERIFY( BuffUAV.BindPoint + BuffUAV.BindCount-1 <= MaxAllowedBindPoint, "Buff UAV bind point exceeds supported range" ); - Res.m_MaxUAVBindPoint = std::max(Res.m_MaxUAVBindPoint, static_cast(BuffUAV.BindPoint + BuffUAV.BindCount-1)); + Resources.m_MaxUAVBindPoint = std::max(Resources.m_MaxUAVBindPoint, static_cast(BuffUAV.BindPoint + BuffUAV.BindCount-1)); } void OnNewBuffSRV(const D3DShaderResourceAttribs& BuffSRV) { VERIFY( BuffSRV.BindPoint + BuffSRV.BindCount-1 <= MaxAllowedBindPoint, "Buff SRV bind point exceeds supported range" ); - Res.m_MaxSRVBindPoint = std::max(Res.m_MaxSRVBindPoint, static_cast(BuffSRV.BindPoint + BuffSRV.BindCount-1)); + Resources.m_MaxSRVBindPoint = std::max(Resources.m_MaxSRVBindPoint, static_cast(BuffSRV.BindPoint + BuffSRV.BindCount-1)); } void OnNewSampler(const D3DShaderResourceAttribs& SamplerAttribs) { VERIFY( SamplerAttribs.BindPoint + SamplerAttribs.BindCount-1 <= MaxAllowedBindPoint, "Sampler bind point exceeds supported range" ); - Res.m_MaxSamplerBindPoint = std::max(Res.m_MaxSamplerBindPoint, static_cast(SamplerAttribs.BindPoint + SamplerAttribs.BindCount-1)); - Res.m_NumStaticSamplers += SamplerAttribs.IsStaticSampler() ? 1 : 0; + Resources.m_MaxSamplerBindPoint = std::max(Resources.m_MaxSamplerBindPoint, static_cast(SamplerAttribs.BindPoint + SamplerAttribs.BindCount-1)); + + if (SamplerAttribs.IsStaticSampler()) + { + // Find attributes of this static sampler + Uint32 ssd = 0; + for (; ssd < ShdrDesc.NumStaticSamplers; ++ssd) + { + const auto& StaticSamplerDesc = ShdrDesc.StaticSamplers[ssd]; + if (StreqSuff(SamplerAttribs.Name, StaticSamplerDesc.SamplerOrTextureName, CombinedSamplerSuffix)) + { + RefCntAutoPtr pSampler; + pDeviceD3D11Impl->CreateSampler(StaticSamplerDesc.Desc, &pSampler); + m_StaticSamplers.emplace_back(SamplerAttribs, std::move(pSampler)); + break; + } + } + VERIFY(ssd < ShdrDesc.NumStaticSamplers, "Unable to find sampler '", SamplerAttribs.Name, "' in the list of static samplers. This should never happen and likely indicates a bug in static sampler enumeration code."); + } } void OnNewTexSRV(const D3DShaderResourceAttribs& TexAttribs) { VERIFY( TexAttribs.BindPoint + TexAttribs.BindCount-1 <= MaxAllowedBindPoint, "Tex SRV bind point exceeds supported range" ); - Res.m_MaxSRVBindPoint = std::max(Res.m_MaxSRVBindPoint, static_cast(TexAttribs.BindPoint + TexAttribs.BindCount-1)); + Resources.m_MaxSRVBindPoint = std::max(Resources.m_MaxSRVBindPoint, static_cast(TexAttribs.BindPoint + TexAttribs.BindCount-1)); + } + + ~NewResourceHandler() + { + Resources.InitStaticSamplers(std::move(m_StaticSamplers)); } private: - ShaderResourcesD3D11& Res; + RenderDeviceD3D11Impl* const pDeviceD3D11Impl; + const ShaderDesc& ShdrDesc; + const char* CombinedSamplerSuffix; + ShaderResourcesD3D11& Resources; + + StaticSamplerVector m_StaticSamplers; }; Initialize( pShaderBytecode, - NewResourceHandler{*this}, + NewResourceHandler{pDeviceD3D11Impl, ShdrDesc, CombinedSamplerSuffix, *this}, ShdrDesc, CombinedSamplerSuffix); +} - // Create static samplers - if (m_NumStaticSamplers > 0) - { - auto MemSize = m_NumStaticSamplers * sizeof(StaticSamplerAttribs); - auto *pRawMem = ALLOCATE(GetRawAllocator(), "Allocator for array of RefCntAutoPtr", MemSize); - m_StaticSamplers.reset( pRawMem ); - for (Uint32 i = 0; i < m_NumStaticSamplers; ++i) - { - new (&GetStaticSampler(i)) StaticSamplerAttribs; - } - Uint32 CurrStaticSam = 0; - for (Uint32 s = 0; s < GetNumSamplers(); ++s) - { - const auto &Sam = GetSampler(s); - if (Sam.IsStaticSampler()) - { - Uint32 ssd = 0; - for (; ssd < ShdrDesc.NumStaticSamplers; ++ssd) - { - const auto& StaticSamplerDesc = ShdrDesc.StaticSamplers[ssd]; - if (StreqSuff(Sam.Name, StaticSamplerDesc.SamplerOrTextureName, CombinedSamplerSuffix)) - { - auto &StaticSamplerAttrs = GetStaticSampler(CurrStaticSam++); - StaticSamplerAttrs.first = &Sam; - pDeviceD3D11Impl->CreateSampler(StaticSamplerDesc.Desc, &StaticSamplerAttrs.second); - break; - } - } - VERIFY(ssd < ShdrDesc.NumStaticSamplers, "Static sampler was not found!"); - } - } - VERIFY_EXPR(CurrStaticSam == m_NumStaticSamplers); - } +void ShaderResourcesD3D11::InitStaticSamplers(StaticSamplerVector&& StaticSamplers) +{ + m_StaticSamplers.reserve(StaticSamplers.size()); + for(auto& Sam : StaticSamplers) + m_StaticSamplers.emplace_back(std::move(Sam)); } ShaderResourcesD3D11::~ShaderResourcesD3D11() { - for(Uint32 ss=0; ss < m_NumStaticSamplers; ++ss) - GetStaticSampler(ss).~StaticSamplerAttribs(); } -void ShaderResourcesD3D11::InitStaticSamplers(ShaderResourceCacheD3D11 &ResourceCache)const +void ShaderResourcesD3D11::SetStaticSamplers(ShaderResourceCacheD3D11& ResourceCache)const { auto NumCachedSamplers = ResourceCache.GetSamplerCount(); - for(Uint32 ss=0; ss < m_NumStaticSamplers; ++ss) + for (const auto& SS : m_StaticSamplers) { - auto &StaticSampler = const_cast(this)->GetStaticSampler(ss); - const auto *pSamAttribs = StaticSampler.first; - auto EndBindPoint = std::min( static_cast(pSamAttribs->BindPoint) + pSamAttribs->BindCount, NumCachedSamplers); - for(Uint32 BindPoint = pSamAttribs->BindPoint; BindPoint < EndBindPoint; ++BindPoint ) - ResourceCache.SetSampler(BindPoint, StaticSampler.second.RawPtr() ); + const auto& SamAttribs = SS.first; + VERIFY_EXPR(SamAttribs.IsStaticSampler()); + auto* pSamplerD3D11Impl = const_cast(SS.second.RawPtr()); + // Limiting EndBindPoint is required when initializing static samplers in a Shader's static cache + auto EndBindPoint = std::min( static_cast(SamAttribs.BindPoint) + SamAttribs.BindCount, NumCachedSamplers); + for(Uint32 BindPoint = SamAttribs.BindPoint; BindPoint < EndBindPoint; ++BindPoint ) + ResourceCache.SetSampler(BindPoint, pSamplerD3D11Impl); } } #ifdef DEVELOPMENT -static String DbgMakeResourceName(const D3DShaderResourceAttribs &Attr, Uint32 BindPoint) +static String DbgMakeResourceName(const D3DShaderResourceAttribs& Attr, Uint32 BindPoint) { VERIFY( BindPoint >= (Uint32)Attr.BindPoint && BindPoint < (Uint32)Attr.BindPoint + Attr.BindCount, "Bind point is out of allowed range"); if(Attr.BindCount == 1) @@ -184,70 +190,70 @@ void ShaderResourcesD3D11::dvpVerifyCommittedResources(ID3D11Buffer* ProcessResources( nullptr, 0, - [&](const D3DShaderResourceAttribs &cb, Uint32) + [&](const D3DShaderResourceAttribs& cb, Uint32) { - for(auto BindPoint = cb.BindPoint; BindPoint < cb.BindPoint + cb.BindCount; ++BindPoint) + for (auto BindPoint = cb.BindPoint; BindPoint < cb.BindPoint + cb.BindCount; ++BindPoint) { if (BindPoint >= ResourceCache.GetCBCount()) { - LOG_ERROR_MESSAGE( "Unable to find constant buffer \"", DbgMakeResourceName(cb,BindPoint), "\" (slot ", BindPoint, ") in the resource cache: the cache reserves ", ResourceCache.GetCBCount()," CB slots only. This should never happen and may be the result of using wrong resource cache." ); + LOG_ERROR_MESSAGE( "Unable to find constant buffer '", DbgMakeResourceName(cb,BindPoint), "' (slot ", BindPoint, ") in the resource cache: the cache reserves ", ResourceCache.GetCBCount(), " CB slots only. This should never happen and may be the result of using wrong resource cache." ); continue; } - auto &CB = CachedCBs[BindPoint]; - if(CB.pBuff == nullptr) + auto& CB = CachedCBs[BindPoint]; + if (CB.pBuff == nullptr) { - LOG_ERROR_MESSAGE( "Constant buffer \"", DbgMakeResourceName(cb,BindPoint), "\" (slot ", BindPoint, ") is not initialized in the resource cache." ); + LOG_ERROR_MESSAGE( "Constant buffer '", DbgMakeResourceName(cb,BindPoint), "' (slot ", BindPoint, ") is not initialized in the resource cache." ); continue; } if (!(CB.pBuff->GetDesc().BindFlags & BIND_UNIFORM_BUFFER)) { - LOG_ERROR_MESSAGE( "Buffer \"", CB.pBuff->GetDesc().Name, "\" committed in the device context as constant buffer to variable \"", DbgMakeResourceName(cb,BindPoint), "\" (slot ", BindPoint, ") in shader \"", GetShaderName(), "\" does not have BIND_UNIFORM_BUFFER flag" ); + LOG_ERROR_MESSAGE( "Buffer '", CB.pBuff->GetDesc().Name, "' committed in the device context as constant buffer to variable '", DbgMakeResourceName(cb,BindPoint), "' (slot ", BindPoint, ") in shader '", GetShaderName(), "' was not created with BIND_UNIFORM_BUFFER flag" ); continue; } VERIFY_EXPR(d3d11CBs[BindPoint] == CB.pBuff->GetD3D11Buffer()); - if(CommittedD3D11CBs[BindPoint] == nullptr ) + if (CommittedD3D11CBs[BindPoint] == nullptr ) { - LOG_ERROR_MESSAGE( "No D3D11 resource committed to constant buffer \"", DbgMakeResourceName(cb,BindPoint), "\" (slot ", BindPoint ,") in shader \"", GetShaderName(), "\"" ); + LOG_ERROR_MESSAGE( "No D3D11 resource committed to constant buffer '", DbgMakeResourceName(cb,BindPoint), "' (slot ", BindPoint ,") in shader '", GetShaderName(), "'" ); continue; } - if(CommittedD3D11CBs[BindPoint] != d3d11CBs[BindPoint] ) + if (CommittedD3D11CBs[BindPoint] != d3d11CBs[BindPoint] ) { - LOG_ERROR_MESSAGE( "D3D11 resource committed to constant buffer \"", DbgMakeResourceName(cb,BindPoint), "\" (slot ", BindPoint ,") in shader \"", GetShaderName(), "\" does not match the resource in the resource cache" ); + LOG_ERROR_MESSAGE( "D3D11 resource committed to constant buffer '", DbgMakeResourceName(cb,BindPoint), "' (slot ", BindPoint ,") in shader '", GetShaderName(), "' does not match the resource in the resource cache" ); continue; } } }, - [&](const D3DShaderResourceAttribs &sam, Uint32) + [&](const D3DShaderResourceAttribs& sam, Uint32) { - for(auto BindPoint = sam.BindPoint; BindPoint < sam.BindPoint + sam.BindCount; ++BindPoint) + for (auto BindPoint = sam.BindPoint; BindPoint < sam.BindPoint + sam.BindCount; ++BindPoint) { if (BindPoint >= ResourceCache.GetSamplerCount()) { - LOG_ERROR_MESSAGE( "Unable to find sampler \"", DbgMakeResourceName(sam,BindPoint), "\" (slot ", BindPoint, ") in the resource cache: the cache reserves ", ResourceCache.GetSamplerCount()," Sampler slots only. This should never happen and may be the result of using wrong resource cache." ); + LOG_ERROR_MESSAGE( "Unable to find sampler '", DbgMakeResourceName(sam,BindPoint), "' (slot ", BindPoint, ") in the resource cache: the cache reserves ", ResourceCache.GetSamplerCount()," Sampler slots only. This should never happen and may be the result of using wrong resource cache." ); continue; } - auto &Sam = CachedSamplers[BindPoint]; - if(Sam.pSampler == nullptr) + auto& Sam = CachedSamplers[BindPoint]; + if (Sam.pSampler == nullptr) { - LOG_ERROR_MESSAGE( "Sampler \"", DbgMakeResourceName(sam,BindPoint), "\" (slot ", BindPoint, ") is not initialized in the resource cache." ); + LOG_ERROR_MESSAGE( "Sampler '", DbgMakeResourceName(sam,BindPoint), "' (slot ", BindPoint, ") is not initialized in the resource cache." ); continue; } VERIFY_EXPR(d3d11Samplers[BindPoint] == Sam.pSampler->GetD3D11SamplerState()); - if(CommittedD3D11Samplers[BindPoint] == nullptr ) + if (CommittedD3D11Samplers[BindPoint] == nullptr ) { - LOG_ERROR_MESSAGE( "No D3D11 sampler committed to variable \"", DbgMakeResourceName(sam,BindPoint), "\" (slot ", BindPoint ,") in shader \"", GetShaderName(), "\"" ); + LOG_ERROR_MESSAGE( "No D3D11 sampler committed to variable '", DbgMakeResourceName(sam,BindPoint), "' (slot ", BindPoint ,") in shader '", GetShaderName(), "'" ); continue; } - if(CommittedD3D11Samplers[BindPoint] != d3d11Samplers[BindPoint]) + if (CommittedD3D11Samplers[BindPoint] != d3d11Samplers[BindPoint]) { - LOG_ERROR_MESSAGE( "D3D11 sampler committed to variable \"", DbgMakeResourceName(sam,BindPoint), "\" (slot ", BindPoint ,") in shader \"", GetShaderName(), "\" does not match the resource in the resource cache" ); + LOG_ERROR_MESSAGE( "D3D11 sampler committed to variable '", DbgMakeResourceName(sam,BindPoint), "' (slot ", BindPoint ,") in shader '", GetShaderName(), "' does not match the resource in the resource cache" ); continue; } } @@ -259,40 +265,40 @@ void ShaderResourcesD3D11::dvpVerifyCommittedResources(ID3D11Buffer* { if (BindPoint >= ResourceCache.GetSRVCount()) { - LOG_ERROR_MESSAGE( "Unable to find texture SRV \"", DbgMakeResourceName(tex,BindPoint), "\" (slot ", BindPoint, ") in the resource cache: the cache reserves ", ResourceCache.GetSRVCount()," SRV slots only. This should never happen and may be the result of using wrong resource cache." ); + LOG_ERROR_MESSAGE( "Unable to find texture SRV '", DbgMakeResourceName(tex,BindPoint), "' (slot ", BindPoint, ") in the resource cache: the cache reserves ", ResourceCache.GetSRVCount()," SRV slots only. This should never happen and may be the result of using wrong resource cache." ); continue; } auto &SRVRes = CachedSRVResources[BindPoint]; - if(SRVRes.pBuffer != nullptr) + if (SRVRes.pBuffer != nullptr) { - LOG_ERROR_MESSAGE( "Unexpected buffer bound to variable \"", DbgMakeResourceName(tex,BindPoint), "\" (slot ", BindPoint, "). Texture is expected." ); + LOG_ERROR_MESSAGE( "Unexpected buffer bound to variable '", DbgMakeResourceName(tex,BindPoint), "' (slot ", BindPoint, "). Texture is expected." ); continue; } - if(SRVRes.pTexture == nullptr) + if (SRVRes.pTexture == nullptr) { - LOG_ERROR_MESSAGE( "Texture \"", DbgMakeResourceName(tex,BindPoint), "\" (slot ", BindPoint, ") is not initialized in the resource cache." ); + LOG_ERROR_MESSAGE( "Texture '", DbgMakeResourceName(tex,BindPoint), "' (slot ", BindPoint, ") is not initialized in the resource cache." ); continue; } if (!(SRVRes.pTexture->GetDesc().BindFlags & BIND_SHADER_RESOURCE)) { - LOG_ERROR_MESSAGE( "Texture \"", SRVRes.pTexture->GetDesc().Name, "\" committed in the device context as SRV to variable \"", DbgMakeResourceName(tex,BindPoint), "\" (slot ", BindPoint, ") in shader \"", GetShaderName(), "\" does not have BIND_SHADER_RESOURCE flag" ); + LOG_ERROR_MESSAGE( "Texture '", SRVRes.pTexture->GetDesc().Name, "' committed in the device context as SRV to variable '", DbgMakeResourceName(tex,BindPoint), "' (slot ", BindPoint, ") in shader '", GetShaderName(), "' was not created with BIND_SHADER_RESOURCE flag" ); } - if(CommittedD3D11SRVs[BindPoint] == nullptr ) + if (CommittedD3D11SRVs[BindPoint] == nullptr ) { - LOG_ERROR_MESSAGE( "No D3D11 resource committed to texture SRV \"", DbgMakeResourceName(tex,BindPoint), "\" (slot ", BindPoint ,") in shader \"", GetShaderName(), "\"" ); + LOG_ERROR_MESSAGE( "No D3D11 resource committed to texture SRV '", DbgMakeResourceName(tex,BindPoint), "' (slot ", BindPoint ,") in shader '", GetShaderName(), "'" ); continue; } - if(CommittedD3D11SRVs[BindPoint] != d3d11SRVs[BindPoint] ) + if (CommittedD3D11SRVs[BindPoint] != d3d11SRVs[BindPoint] ) { - LOG_ERROR_MESSAGE( "D3D11 resource committed to texture SRV \"", DbgMakeResourceName(tex,BindPoint), "\" (slot ", BindPoint ,") in shader \"", GetShaderName(), "\" does not match the resource in the resource cache" ); + LOG_ERROR_MESSAGE( "D3D11 resource committed to texture SRV '", DbgMakeResourceName(tex,BindPoint), "' (slot ", BindPoint ,") in shader '", GetShaderName(), "' does not match the resource in the resource cache" ); continue; } } - if( tex.ValidSamplerAssigned() ) + if (tex.ValidSamplerAssigned()) { const auto& SamAttribs = GetSampler( tex.GetSamplerId() ); VERIFY_EXPR(SamAttribs.IsValidBindPoint()); @@ -300,122 +306,122 @@ void ShaderResourcesD3D11::dvpVerifyCommittedResources(ID3D11Buffer* } }, - [&](const D3DShaderResourceAttribs &uav, Uint32) + [&](const D3DShaderResourceAttribs& uav, Uint32) { - for(auto BindPoint = uav.BindPoint; BindPoint < uav.BindPoint + uav.BindCount; ++BindPoint) + for (auto BindPoint = uav.BindPoint; BindPoint < uav.BindPoint + uav.BindCount; ++BindPoint) { if (BindPoint >= ResourceCache.GetUAVCount()) { - LOG_ERROR_MESSAGE( "Unable to find texture UAV \"", DbgMakeResourceName(uav,BindPoint), "\" (slot ", BindPoint, ") in the resource cache: the cache reserves ", ResourceCache.GetUAVCount()," UAV slots only. This should never happen and may be the result of using wrong resource cache." ); + LOG_ERROR_MESSAGE( "Unable to find texture UAV '", DbgMakeResourceName(uav,BindPoint), "' (slot ", BindPoint, ") in the resource cache: the cache reserves ", ResourceCache.GetUAVCount()," UAV slots only. This should never happen and may be the result of using wrong resource cache." ); continue; } auto &UAVRes = CachedUAVResources[BindPoint]; - if(UAVRes.pBuffer != nullptr) + if (UAVRes.pBuffer != nullptr) { - LOG_ERROR_MESSAGE( "Unexpected buffer bound to variable \"", DbgMakeResourceName(uav,BindPoint), "\" (slot ", BindPoint, "). Texture is expected." ); + LOG_ERROR_MESSAGE( "Unexpected buffer bound to variable '", DbgMakeResourceName(uav,BindPoint), "' (slot ", BindPoint, "). Texture is expected." ); continue; } - if(UAVRes.pTexture == nullptr) + if (UAVRes.pTexture == nullptr) { - LOG_ERROR_MESSAGE( "Texture \"", DbgMakeResourceName(uav,BindPoint), "\" (slot ", BindPoint, ") is not initialized in the resource cache." ); + LOG_ERROR_MESSAGE( "Texture '", DbgMakeResourceName(uav,BindPoint), "' (slot ", BindPoint, ") is not initialized in the resource cache." ); continue; } if (!(UAVRes.pTexture->GetDesc().BindFlags & BIND_UNORDERED_ACCESS)) { - LOG_ERROR_MESSAGE( "Texture \"", UAVRes.pTexture->GetDesc().Name, "\" committed in the device context as UAV to variable \"", DbgMakeResourceName(uav,BindPoint), "\" (slot ", BindPoint, ") in shader \"", GetShaderName(), "\" does not have BIND_UNORDERED_ACCESS flag" ); + LOG_ERROR_MESSAGE( "Texture '", UAVRes.pTexture->GetDesc().Name, "' committed in the device context as UAV to variable '", DbgMakeResourceName(uav,BindPoint), "' (slot ", BindPoint, ") in shader '", GetShaderName(), "' was not created with BIND_UNORDERED_ACCESS flag" ); } - if(CommittedD3D11UAVs[BindPoint] == nullptr ) + if (CommittedD3D11UAVs[BindPoint] == nullptr ) { - LOG_ERROR_MESSAGE( "No D3D11 resource committed to texture UAV \"", DbgMakeResourceName(uav,BindPoint), "\" (slot ", BindPoint ,") in shader \"", GetShaderName(), "\"" ); + LOG_ERROR_MESSAGE( "No D3D11 resource committed to texture UAV '", DbgMakeResourceName(uav,BindPoint), "' (slot ", BindPoint ,") in shader '", GetShaderName(), "'" ); continue; } - if(CommittedD3D11UAVs[BindPoint] != d3d11UAVs[BindPoint] ) + if (CommittedD3D11UAVs[BindPoint] != d3d11UAVs[BindPoint] ) { - LOG_ERROR_MESSAGE( "D3D11 resource committed to texture UAV \"", DbgMakeResourceName(uav,BindPoint), "\" (slot ", BindPoint ,") in shader \"", GetShaderName(), "\" does not match the resource in the resource cache" ); + LOG_ERROR_MESSAGE( "D3D11 resource committed to texture UAV '", DbgMakeResourceName(uav,BindPoint), "' (slot ", BindPoint ,") in shader '", GetShaderName(), "' does not match the resource in the resource cache" ); continue; } } }, - [&](const D3DShaderResourceAttribs &buf, Uint32) + [&](const D3DShaderResourceAttribs& buf, Uint32) { - for(auto BindPoint = buf.BindPoint; BindPoint < buf.BindPoint + buf.BindCount; ++BindPoint) + for (auto BindPoint = buf.BindPoint; BindPoint < buf.BindPoint + buf.BindCount; ++BindPoint) { if (BindPoint >= ResourceCache.GetSRVCount()) { - LOG_ERROR_MESSAGE( "Unable to find buffer SRV \"", DbgMakeResourceName(buf,BindPoint), "\" (slot ", BindPoint, ") in the resource cache: the cache reserves ", ResourceCache.GetSRVCount()," SRV slots only. This should never happen and may be the result of using wrong resource cache." ); + LOG_ERROR_MESSAGE( "Unable to find buffer SRV '", DbgMakeResourceName(buf,BindPoint), "' (slot ", BindPoint, ") in the resource cache: the cache reserves ", ResourceCache.GetSRVCount()," SRV slots only. This should never happen and may be the result of using wrong resource cache." ); continue; } - auto &SRVRes = CachedSRVResources[BindPoint]; - if(SRVRes.pTexture != nullptr) + auto& SRVRes = CachedSRVResources[BindPoint]; + if (SRVRes.pTexture != nullptr) { - LOG_ERROR_MESSAGE( "Unexpected texture bound to variable \"", DbgMakeResourceName(buf,BindPoint), "\" (slot ", BindPoint, "). Buffer is expected." ); + LOG_ERROR_MESSAGE( "Unexpected texture bound to variable '", DbgMakeResourceName(buf,BindPoint), "' (slot ", BindPoint, "). Buffer is expected." ); continue; } - if(SRVRes.pBuffer == nullptr) + if (SRVRes.pBuffer == nullptr) { - LOG_ERROR_MESSAGE( "Buffer \"", DbgMakeResourceName(buf,BindPoint), "\" (slot ", BindPoint ,") is not initialized in the resource cache." ); + LOG_ERROR_MESSAGE( "Buffer '", DbgMakeResourceName(buf,BindPoint), "' (slot ", BindPoint ,") is not initialized in the resource cache." ); continue; } if (!(SRVRes.pBuffer->GetDesc().BindFlags & BIND_SHADER_RESOURCE)) { - LOG_ERROR_MESSAGE( "Buffer \"", SRVRes.pBuffer->GetDesc().Name, "\" committed in the device context as SRV to variable \"", DbgMakeResourceName(buf,BindPoint), "\" (slot ", BindPoint, ") in shader \"", GetShaderName(), "\" does not have BIND_SHADER_RESOURCE flag" ); + LOG_ERROR_MESSAGE( "Buffer '", SRVRes.pBuffer->GetDesc().Name, "' committed in the device context as SRV to variable '", DbgMakeResourceName(buf,BindPoint), "' (slot ", BindPoint, ") in shader '", GetShaderName(), "' was not created with BIND_SHADER_RESOURCE flag" ); } - if(CommittedD3D11SRVs[BindPoint] == nullptr ) + if (CommittedD3D11SRVs[BindPoint] == nullptr ) { - LOG_ERROR_MESSAGE( "No D3D11 resource committed to buffer SRV \"", DbgMakeResourceName(buf,BindPoint), "\" (slot ", BindPoint ,") in shader \"", GetShaderName(), "\"" ); + LOG_ERROR_MESSAGE( "No D3D11 resource committed to buffer SRV '", DbgMakeResourceName(buf,BindPoint), "' (slot ", BindPoint ,") in shader '", GetShaderName(), "'" ); continue; } - if(CommittedD3D11SRVs[BindPoint] != d3d11SRVs[BindPoint] ) + if (CommittedD3D11SRVs[BindPoint] != d3d11SRVs[BindPoint] ) { - LOG_ERROR_MESSAGE( "D3D11 resource committed to buffer SRV \"", DbgMakeResourceName(buf,BindPoint), "\" (slot ", BindPoint ,") in shader \"", GetShaderName(), "\" does not match the resource in the resource cache" ); + LOG_ERROR_MESSAGE( "D3D11 resource committed to buffer SRV '", DbgMakeResourceName(buf,BindPoint), "' (slot ", BindPoint ,") in shader '", GetShaderName(), "' does not match the resource in the resource cache" ); continue; } } }, - [&](const D3DShaderResourceAttribs &uav, Uint32) + [&](const D3DShaderResourceAttribs& uav, Uint32) { for(auto BindPoint = uav.BindPoint; BindPoint < uav.BindPoint + uav.BindCount; ++BindPoint) { if (BindPoint >= ResourceCache.GetUAVCount()) { - LOG_ERROR_MESSAGE( "Unable to find buffer UAV \"", DbgMakeResourceName(uav,BindPoint), "\" (slot ", BindPoint, ") in the resource cache: the cache reserves ", ResourceCache.GetUAVCount()," UAV slots only. This should never happen and may be the result of using wrong resource cache." ); + LOG_ERROR_MESSAGE( "Unable to find buffer UAV '", DbgMakeResourceName(uav,BindPoint), "' (slot ", BindPoint, ") in the resource cache: the cache reserves ", ResourceCache.GetUAVCount()," UAV slots only. This should never happen and may be the result of using wrong resource cache." ); continue; } auto &UAVRes = CachedUAVResources[BindPoint]; - if(UAVRes.pTexture != nullptr) + if (UAVRes.pTexture != nullptr) { - LOG_ERROR_MESSAGE( "Unexpected texture bound to variable \"", DbgMakeResourceName(uav,BindPoint), "\" (slot ", BindPoint, "). Buffer is expected." ); + LOG_ERROR_MESSAGE( "Unexpected texture bound to variable '", DbgMakeResourceName(uav,BindPoint), "' (slot ", BindPoint, "). Buffer is expected." ); return; } - if(UAVRes.pBuffer == nullptr) + if (UAVRes.pBuffer == nullptr) { - LOG_ERROR_MESSAGE( "Buffer UAV \"", DbgMakeResourceName(uav,BindPoint), "\" (slot ", BindPoint, ") is not initialized in the resource cache." ); + LOG_ERROR_MESSAGE( "Buffer UAV '", DbgMakeResourceName(uav,BindPoint), "' (slot ", BindPoint, ") is not initialized in the resource cache." ); return; } if (!(UAVRes.pBuffer->GetDesc().BindFlags & BIND_UNORDERED_ACCESS)) { - LOG_ERROR_MESSAGE( "Buffer \"", UAVRes.pBuffer->GetDesc().Name, "\" committed in the device context as UAV to variable \"", DbgMakeResourceName(uav,BindPoint), "\" (slot ", BindPoint, ") in shader \"", GetShaderName(), "\" does not have BIND_UNORDERED_ACCESS flag" ); + LOG_ERROR_MESSAGE( "Buffer '", UAVRes.pBuffer->GetDesc().Name, "' committed in the device context as UAV to variable '", DbgMakeResourceName(uav,BindPoint), "' (slot ", BindPoint, ") in shader '", GetShaderName(), "' was not created with BIND_UNORDERED_ACCESS flag" ); } - if(CommittedD3D11UAVs[BindPoint] == nullptr ) + if (CommittedD3D11UAVs[BindPoint] == nullptr ) { - LOG_ERROR_MESSAGE( "No D3D11 resource committed to buffer UAV \"", DbgMakeResourceName(uav,BindPoint), "\" (slot ", BindPoint ,") in shader \"", GetShaderName(), "\"" ); + LOG_ERROR_MESSAGE( "No D3D11 resource committed to buffer UAV '", DbgMakeResourceName(uav,BindPoint), "' (slot ", BindPoint ,") in shader '", GetShaderName(), "'" ); return; } - if(CommittedD3D11UAVs[BindPoint] != d3d11UAVs[BindPoint] ) + if (CommittedD3D11UAVs[BindPoint] != d3d11UAVs[BindPoint] ) { - LOG_ERROR_MESSAGE( "D3D11 resource committed to buffer UAV \"", DbgMakeResourceName(uav,BindPoint), "\" (slot ", BindPoint ,") in shader \"", GetShaderName(), "\" does not match the resource in the resource cache" ); + LOG_ERROR_MESSAGE( "D3D11 resource committed to buffer UAV '", DbgMakeResourceName(uav,BindPoint), "' (slot ", BindPoint ,") in shader '", GetShaderName(), "' does not match the resource in the resource cache" ); return; } } -- cgit v1.2.3