From c3ce1b6cc0214c0c67ac6c75b742b92b18af30d8 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Sun, 3 Mar 2019 20:50:04 -0800 Subject: Final changes to complete d3d11 backend refactor --- .../include/PipelineStateD3D11Impl.h | 5 + .../include/ShaderResourceLayoutD3D11.h | 11 +-- .../src/PipelineStateD3D11Impl.cpp | 58 +++++++++++- .../src/ShaderResourceBindingD3D11Impl.cpp | 7 +- .../src/ShaderResourceLayoutD3D11.cpp | 103 +++++++++------------ 5 files changed, 110 insertions(+), 74 deletions(-) (limited to 'Graphics/GraphicsEngineD3D11') diff --git a/Graphics/GraphicsEngineD3D11/include/PipelineStateD3D11Impl.h b/Graphics/GraphicsEngineD3D11/include/PipelineStateD3D11Impl.h index 583190aa..2cbe0ebc 100644 --- a/Graphics/GraphicsEngineD3D11/include/PipelineStateD3D11Impl.h +++ b/Graphics/GraphicsEngineD3D11/include/PipelineStateD3D11Impl.h @@ -97,8 +97,10 @@ public: return m_pStaticResourceCaches[s]; } + void SetStaticSamplers(ShaderResourceCacheD3D11& ResourceCache, Uint32 ShaderInd)const; private: + CComPtr m_pd3d11BlendState; CComPtr m_pd3d11RasterizerState; CComPtr m_pd3d11DepthStencilState; @@ -112,6 +114,9 @@ private: SRBMemoryAllocator m_SRBMemAllocator; Int8 m_ResourceLayoutIndex[6] = {-1, -1, -1, -1, -1, -1}; + + Uint16 m_StaticSamplerOffsets[MaxShadersInPipeline+1] = {}; + std::vector< std::pair< const D3DShaderResourceAttribs&, RefCntAutoPtr > > m_StaticSamplers; }; } diff --git a/Graphics/GraphicsEngineD3D11/include/ShaderResourceLayoutD3D11.h b/Graphics/GraphicsEngineD3D11/include/ShaderResourceLayoutD3D11.h index 6666777b..bfc39727 100644 --- a/Graphics/GraphicsEngineD3D11/include/ShaderResourceLayoutD3D11.h +++ b/Graphics/GraphicsEngineD3D11/include/ShaderResourceLayoutD3D11.h @@ -46,7 +46,6 @@ class ShaderResourceLayoutD3D11 { public: ShaderResourceLayoutD3D11(IObject& Owner, - IRenderDevice* pRenderDevice, std::shared_ptr pSrcResources, const PipelineResourceLayoutDesc& ResourceLayout, const SHADER_RESOURCE_VARIABLE_TYPE* VarTypes, @@ -186,10 +185,8 @@ public: { SamplerBindInfo( const D3DShaderResourceAttribs& ResourceAttribs, ShaderResourceLayoutD3D11& ParentResLayout, - SHADER_RESOURCE_VARIABLE_TYPE VariableType, - RefCntAutoPtr _pStaticSampler) : - ShaderVariableD3D11Base(ParentResLayout, ResourceAttribs, VariableType), - pStaticSampler(std::move(_pStaticSampler)) + SHADER_RESOURCE_VARIABLE_TYPE VariableType) : + ShaderVariableD3D11Base(ParentResLayout, ResourceAttribs, VariableType) {} // Non-virtual function @@ -203,16 +200,12 @@ public: } __forceinline bool IsBound(Uint32 ArrayIndex)const; - - RefCntAutoPtr pStaticSampler; }; // dbgResourceCache is only used for sanity check and as a remainder that the resource cache must be alive // while Layout is alive void BindResources( IResourceMapping* pResourceMapping, Uint32 Flags, const ShaderResourceCacheD3D11& dbgResourceCache ); - void SetStaticSamplers(ShaderResourceCacheD3D11& ResourceCache)const; - #ifdef DEVELOPMENT bool dvpVerifyBindings()const; #endif diff --git a/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp index eec91b20..09754861 100644 --- a/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/PipelineStateD3D11Impl.cpp @@ -118,6 +118,20 @@ PipelineStateD3D11Impl::PipelineStateD3D11Impl(IReferenceCounters* pRefCoun m_pStaticResourceCaches = reinterpret_cast(pResCacheRawMem); const auto& ResourceLayout = PipelineDesc.ResourceLayout; + +#ifdef DEVELOPMENT + { + const ShaderResources* pResources[MaxShadersInPipeline] = {}; + for (Uint32 s = 0; s < m_NumShaders; ++s) + { + auto* pShader = GetShader(s); + pResources[s] = &(*pShader->GetD3D11Resources()); + } + ShaderResources::DvpVerifyResourceLayout(ResourceLayout, pResources, m_NumShaders); + } +#endif + + decltype(m_StaticSamplers) StaticSamplers; std::array ShaderResLayoutDataSizes = {}; std::array ShaderResCacheDataSizes = {}; for (Uint32 s = 0; s < m_NumShaders; ++s) @@ -134,7 +148,6 @@ PipelineStateD3D11Impl::PipelineStateD3D11Impl(IReferenceCounters* pRefCoun ShaderResourceLayoutD3D11 { *this, - pRenderDeviceD3D11, pShader->GetD3D11Resources(), m_Desc.ResourceLayout, StaticVarTypes, @@ -144,7 +157,20 @@ PipelineStateD3D11Impl::PipelineStateD3D11Impl(IReferenceCounters* pRefCoun GetRawAllocator() }; - m_pStaticResourceLayouts[s].SetStaticSamplers(m_pStaticResourceCaches[s]); + // Initialize static samplers + for(Uint32 sam = 0; sam < ShaderResources.GetNumSamplers(); ++sam) + { + const auto& SamplerAttribs = ShaderResources.GetSampler(sam); + auto SrcStaticSamplerInd = ShaderResources.FindStaticSampler(SamplerAttribs, ResourceLayout); + if (SrcStaticSamplerInd >= 0) + { + const auto& SrcStaticSamplerInfo = ResourceLayout.StaticSamplers[SrcStaticSamplerInd]; + RefCntAutoPtr pStaticSampler; + pRenderDeviceD3D11->CreateSampler(SrcStaticSamplerInfo.Desc, &pStaticSampler); + StaticSamplers.emplace_back(SamplerAttribs, std::move(pStaticSampler)); + } + } + m_StaticSamplerOffsets[s + 1] = static_cast(StaticSamplers.size()); if (PipelineDesc.SRBAllocationGranularity > 1) { @@ -152,12 +178,25 @@ PipelineStateD3D11Impl::PipelineStateD3D11Impl(IReferenceCounters* pRefCoun ShaderResLayoutDataSizes[s] = ShaderResourceLayoutD3D11::GetRequiredMemorySize(ShaderResources, ResourceLayout, SRBVarTypes, _countof(SRBVarTypes)); ShaderResCacheDataSizes[s] = ShaderResourceCacheD3D11::GetRequriedMemorySize(ShaderResources); } + + auto ShaderInd = GetShaderTypeIndex(pShader->GetDesc().ShaderType); + m_ResourceLayoutIndex[ShaderInd] = static_cast(s); } if (PipelineDesc.SRBAllocationGranularity > 1) { m_SRBMemAllocator.Initialize(PipelineDesc.SRBAllocationGranularity, m_NumShaders, ShaderResLayoutDataSizes.data(), m_NumShaders, ShaderResCacheDataSizes.data()); } + + m_StaticSamplers.reserve(StaticSamplers.size()); + for(auto& Sam : StaticSamplers) + m_StaticSamplers.emplace_back(std::move(Sam)); + + for (Uint32 s = 0; s < m_NumShaders; ++s) + { + // Initialize static samplers in the static resource cache to avoid warning messages + SetStaticSamplers(m_pStaticResourceCaches[s], s); + } } @@ -317,4 +356,19 @@ IShaderResourceVariable* PipelineStateD3D11Impl::GetStaticShaderVariable(SHADER_ return m_pStaticResourceLayouts[LayoutInd].GetShaderVariable(Index); } +void PipelineStateD3D11Impl::SetStaticSamplers(ShaderResourceCacheD3D11& ResourceCache, Uint32 ShaderInd)const +{ + auto NumCachedSamplers = ResourceCache.GetSamplerCount(); + for (Uint32 s = m_StaticSamplerOffsets[ShaderInd]; s < m_StaticSamplerOffsets[ShaderInd+1]; ++s) + { + auto& SamplerInfo = m_StaticSamplers[s]; + const auto& SamAttribs = SamplerInfo.first; + auto* pSamplerD3D11Impl = SamplerInfo.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); + } +} + } diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp index 0091cc54..a99da5de 100644 --- a/Graphics/GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/ShaderResourceBindingD3D11Impl.cpp @@ -45,7 +45,6 @@ ShaderResourceBindingD3D11Impl::ShaderResourceBindingD3D11Impl( IReferenceCounte auto* pResCacheRawMem = ALLOCATE(GetRawAllocator(), "Raw memory for ShaderResourceCacheD3D11", m_NumActiveShaders * sizeof(ShaderResourceCacheD3D11)); m_pBoundResourceCaches = reinterpret_cast(pResCacheRawMem); - auto* pRenderDevice = pPSO->GetDevice(); const auto& PSODesc = pPSO->GetDesc(); // Reserve memory for resource layouts @@ -71,7 +70,6 @@ ShaderResourceBindingD3D11Impl::ShaderResourceBindingD3D11Impl( IReferenceCounte ShaderResourceLayoutD3D11 { *this, - pRenderDevice, pShaderD3D11->GetD3D11Resources(), PSODesc.ResourceLayout, VarTypes, @@ -81,9 +79,6 @@ ShaderResourceBindingD3D11Impl::ShaderResourceBindingD3D11Impl( IReferenceCounte ResLayoutDataAllocator }; - m_pResourceLayouts[s].SetStaticSamplers(m_pBoundResourceCaches[s]); - pPSO->GetStaticResourceLayout(s).SetStaticSamplers(m_pBoundResourceCaches[s]); - m_ResourceLayoutIndex[ShaderInd] = s; m_ShaderTypeIndex[s] = static_cast(ShaderInd); } @@ -163,7 +158,7 @@ void ShaderResourceBindingD3D11Impl::InitializeStaticResources(const IPipelineSt VERIFY_EXPR(ResourceLayoutInd == static_cast(shader) ); #endif StaticResLayout.CopyResources(m_pBoundResourceCaches[shader]); - //StaticResLayout.SetStaticSamplers(m_pBoundResourceCaches[shader]); + pPSOD3D11->SetStaticSamplers(m_pBoundResourceCaches[shader], shader); } m_bIsStaticResourcesBound = true; diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderResourceLayoutD3D11.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderResourceLayoutD3D11.cpp index 6839e29d..12ca400a 100755 --- a/Graphics/GraphicsEngineD3D11/src/ShaderResourceLayoutD3D11.cpp +++ b/Graphics/GraphicsEngineD3D11/src/ShaderResourceLayoutD3D11.cpp @@ -80,7 +80,9 @@ size_t ShaderResourceLayoutD3D11::GetRequiredMemorySize(const ShaderResourcesD3D const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, Uint32 NumAllowedTypes) { - auto ResCounters = SrcResources.CountResources(ResourceLayout, AllowedVarTypes, NumAllowedTypes); + // Skip static samplers as they are initialized directly in the resource cache by the PSO + constexpr bool CountStaticSamplers = false; + auto ResCounters = SrcResources.CountResources(ResourceLayout, AllowedVarTypes, NumAllowedTypes, CountStaticSamplers); auto MemSize = ResCounters.NumCBs * sizeof(ConstBuffBindInfo) + ResCounters.NumTexSRVs * sizeof(TexSRVBindInfo) + ResCounters.NumTexUAVs * sizeof(TexUAVBindInfo) + @@ -92,7 +94,6 @@ size_t ShaderResourceLayoutD3D11::GetRequiredMemorySize(const ShaderResourcesD3D ShaderResourceLayoutD3D11::ShaderResourceLayoutD3D11(IObject& Owner, - IRenderDevice* pRenderDevice, std::shared_ptr pSrcResources, const PipelineResourceLayoutDesc& ResourceLayout, const SHADER_RESOURCE_VARIABLE_TYPE* VarTypes, @@ -109,7 +110,9 @@ ShaderResourceLayoutD3D11::ShaderResourceLayoutD3D11(IObject& const auto AllowedTypeBits = GetAllowedTypeBits(VarTypes, NumVarTypes); // Count total number of resources of allowed types - auto ResCounters = m_pResources->CountResources(ResourceLayout, VarTypes, NumVarTypes); + // Skip static samplers as they are initialized directly in the resource cache by the PSO + constexpr bool CountStaticSamplers = false; + auto ResCounters = m_pResources->CountResources(ResourceLayout, VarTypes, NumVarTypes, CountStaticSamplers); // Initialize offsets size_t CurrentOffset = 0; @@ -175,14 +178,13 @@ ShaderResourceLayoutD3D11::ShaderResourceLayoutD3D11(IObject& if (IsAllowedType(VarType, AllowedTypeBits)) { auto StaticSamplerInd = m_pResources->FindStaticSampler(Sampler, ResourceLayout); - RefCntAutoPtr pStaticSampler; if (StaticSamplerInd >= 0) { - const auto& StaticSamplerDesc = ResourceLayout.StaticSamplers[StaticSamplerInd]; - pRenderDevice->CreateSampler(StaticSamplerDesc.Desc, &pStaticSampler); + // Skip static samplers as they are initialized directly in the resource cache by the PSO + return; } // Initialize current sampler in place, increment sampler counter - new (&GetResource(sam++)) SamplerBindInfo(Sampler, *this, VarType, std::move(pStaticSampler)); + new (&GetResource(sam++)) SamplerBindInfo(Sampler, *this, VarType); NumSamplerSlots = std::max(NumSamplerSlots, Uint32{Sampler.BindPoint} + Uint32{Sampler.BindCount}); } }, @@ -207,21 +209,33 @@ ShaderResourceLayoutD3D11::ShaderResourceLayoutD3D11(IObject& ") of the sampler '", AssignedSamplerAttribs.Name, "' that is assigned to it"); bool SamplerFound = false; - for (AssignedSamplerIndex = 0; AssignedSamplerIndex < NumSamplers && !SamplerFound; ++AssignedSamplerIndex) + for (AssignedSamplerIndex = 0; AssignedSamplerIndex < NumSamplers; ++AssignedSamplerIndex) { const auto& Sampler = GetResource(AssignedSamplerIndex); SamplerFound = strcmp(Sampler.m_Attribs.Name, AssignedSamplerAttribs.Name) == 0; if (SamplerFound) + break; // Otherwise AssignedSamplerIndex will be incremented + } + + if (!SamplerFound) + { + AssignedSamplerIndex = TexSRVBindInfo::InvalidSamplerIndex; +#ifdef _DEBUG + if (m_pResources->FindStaticSampler(AssignedSamplerAttribs, ResourceLayout) < 0) { - if (Sampler.pStaticSampler) - { - // Do not assign static samplers to texture SRV - AssignedSamplerIndex = TexSRVBindInfo::InvalidSamplerIndex; - break; - } + LOG_ERROR("Unable to find non-static sampler assigned to texture SRV '", TexSRV.Name, "'. This seems to be a bug."); + } +#endif + } + else + { +#ifdef _DEBUG + if (m_pResources->FindStaticSampler(AssignedSamplerAttribs, ResourceLayout) >= 0) + { + LOG_ERROR("Static sampler '", AssignedSamplerAttribs.Name, "' is assigned to texture SRV '", TexSRV.Name, "'. This seems to be a bug."); } +#endif } - VERIFY(SamplerFound, "Unable to find sampler assigned to texture SRV '", TexSRV.Name, "'"); } // Initialize tex SRV in place, increment counter of tex SRVs @@ -318,7 +332,7 @@ void ShaderResourceLayoutD3D11::CopyResources(ShaderResourceCacheD3D11& DstCache HandleConstResources( [&](const ConstBuffBindInfo& cb) { - for(auto CBSlot = cb.m_Attribs.BindPoint; CBSlot < cb.m_Attribs.BindPoint+cb.m_Attribs.BindCount; ++CBSlot) + for (auto CBSlot = cb.m_Attribs.BindPoint; CBSlot < cb.m_Attribs.BindPoint+cb.m_Attribs.BindCount; ++CBSlot) { VERIFY_EXPR(CBSlot < m_ResourceCache.GetCBCount() && CBSlot < DstCache.GetCBCount()); DstCBs [CBSlot] = CachedCBs[CBSlot]; @@ -328,7 +342,7 @@ void ShaderResourceLayoutD3D11::CopyResources(ShaderResourceCacheD3D11& DstCache [&](const TexSRVBindInfo& ts) { - for(auto SRVSlot = ts.m_Attribs.BindPoint; SRVSlot < ts.m_Attribs.BindPoint + ts.m_Attribs.BindCount; ++SRVSlot) + for (auto SRVSlot = ts.m_Attribs.BindPoint; SRVSlot < ts.m_Attribs.BindPoint + ts.m_Attribs.BindCount; ++SRVSlot) { VERIFY_EXPR(SRVSlot < m_ResourceCache.GetSRVCount() && SRVSlot < DstCache.GetSRVCount()); DstSRVResources[SRVSlot] = CachedSRVResources[SRVSlot]; @@ -338,7 +352,7 @@ void ShaderResourceLayoutD3D11::CopyResources(ShaderResourceCacheD3D11& DstCache [&](const TexUAVBindInfo& uav) { - for(auto UAVSlot = uav.m_Attribs.BindPoint; UAVSlot < uav.m_Attribs.BindPoint + uav.m_Attribs.BindCount; ++UAVSlot) + for (auto UAVSlot = uav.m_Attribs.BindPoint; UAVSlot < uav.m_Attribs.BindPoint + uav.m_Attribs.BindCount; ++UAVSlot) { VERIFY_EXPR(UAVSlot < m_ResourceCache.GetUAVCount() && UAVSlot < DstCache.GetUAVCount()); DstUAVResources[UAVSlot] = CachedUAVResources[UAVSlot]; @@ -348,7 +362,7 @@ void ShaderResourceLayoutD3D11::CopyResources(ShaderResourceCacheD3D11& DstCache [&](const BuffSRVBindInfo& srv) { - for(auto SRVSlot = srv.m_Attribs.BindPoint; SRVSlot < srv.m_Attribs.BindPoint + srv.m_Attribs.BindCount; ++SRVSlot) + for (auto SRVSlot = srv.m_Attribs.BindPoint; SRVSlot < srv.m_Attribs.BindPoint + srv.m_Attribs.BindCount; ++SRVSlot) { VERIFY_EXPR(SRVSlot < m_ResourceCache.GetSRVCount() && SRVSlot < DstCache.GetSRVCount()); DstSRVResources[SRVSlot] = CachedSRVResources[SRVSlot]; @@ -358,7 +372,7 @@ void ShaderResourceLayoutD3D11::CopyResources(ShaderResourceCacheD3D11& DstCache [&](const BuffUAVBindInfo& uav) { - for(auto UAVSlot = uav.m_Attribs.BindPoint; UAVSlot < uav.m_Attribs.BindPoint + uav.m_Attribs.BindCount; ++UAVSlot) + for (auto UAVSlot = uav.m_Attribs.BindPoint; UAVSlot < uav.m_Attribs.BindPoint + uav.m_Attribs.BindCount; ++UAVSlot) { VERIFY_EXPR(UAVSlot < m_ResourceCache.GetUAVCount() && UAVSlot < DstCache.GetUAVCount()); DstUAVResources[UAVSlot] = CachedUAVResources[UAVSlot]; @@ -368,8 +382,8 @@ void ShaderResourceLayoutD3D11::CopyResources(ShaderResourceCacheD3D11& DstCache [&](const SamplerBindInfo& sam) { - VERIFY(!sam.pStaticSampler, "Variables are not created for static samplers"); - for(auto SamSlot = sam.m_Attribs.BindPoint; SamSlot < sam.m_Attribs.BindPoint + sam.m_Attribs.BindCount; ++SamSlot) + //VERIFY(!sam.IsStaticSampler, "Variables are not created for static samplers"); + for (auto SamSlot = sam.m_Attribs.BindPoint; SamSlot < sam.m_Attribs.BindPoint + sam.m_Attribs.BindCount; ++SamSlot) { VERIFY_EXPR(SamSlot < m_ResourceCache.GetSamplerCount() && SamSlot < DstCache.GetSamplerCount()); DstSamplers [SamSlot] = CachedSamplers[SamSlot]; @@ -379,24 +393,6 @@ void ShaderResourceLayoutD3D11::CopyResources(ShaderResourceCacheD3D11& DstCache ); } -void ShaderResourceLayoutD3D11::SetStaticSamplers(ShaderResourceCacheD3D11& ResourceCache)const -{ - auto NumCachedSamplers = ResourceCache.GetSamplerCount(); - for (Uint32 s = 0; s < GetNumResources(); ++s) - { - auto& Sampler = GetConstResource(s); - if (Sampler.pStaticSampler) - { - const auto& SamAttribs = Sampler.m_Attribs; - auto* pSamplerD3D11Impl = const_cast(Sampler.pStaticSampler.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); - } - } -} - #define LOG_RESOURCE_BINDING_ERROR(ResType, pResource, Attribs, ArrayInd, ShaderName, ...)\ do{ \ const auto* ResName = pResource->GetDesc().Name; \ @@ -507,7 +503,7 @@ void ShaderResourceLayoutD3D11::TexSRVBindInfo::BindResource(IDeviceObject* pVie if (ValidSamplerAssigned()) { auto& Sampler = m_ParentResLayout.GetResource(SamplerIndex); - VERIFY(!Sampler.pStaticSampler, "Static samplers are not assigned to texture SRVs as they are initialized directly in the shader resource cache"); + //VERIFY(!Sampler.IsStaticSampler, "Static samplers are not assigned to texture SRVs as they are initialized directly in the shader resource cache"); VERIFY_EXPR(Sampler.m_Attribs.BindCount == m_Attribs.BindCount || Sampler.m_Attribs.BindCount == 1); auto SamplerBindPoint = Sampler.m_Attribs.BindPoint + (Sampler.m_Attribs.BindCount != 1 ? ArrayIndex : 0); @@ -547,7 +543,7 @@ void ShaderResourceLayoutD3D11::SamplerBindInfo::BindResource(IDeviceObject* pSa { DEV_CHECK_ERR(ArrayIndex < m_Attribs.BindCount, "Array index (", ArrayIndex, ") is out of range for variable '", m_Attribs.Name, "'. Max allowed index: ", m_Attribs.BindCount); auto& ResourceCache = m_ParentResLayout.m_ResourceCache; - VERIFY(!pStaticSampler, "Cannot bind sampler to a static sampler"); + //VERIFY(!IsStaticSampler, "Cannot bind sampler to a static sampler"); // We cannot use ValidatedCast<> here as the resource retrieved from the // resource mapping can be of wrong type @@ -807,33 +803,26 @@ IShaderResourceVariable* ShaderResourceLayoutD3D11::GetResourceByName( const Cha IShaderResourceVariable* ShaderResourceLayoutD3D11::GetShaderVariable(const Char* Name) { - if(auto* pCB = GetResourceByName(Name)) + if (auto* pCB = GetResourceByName(Name)) return pCB; - if(auto* pTexSRV = GetResourceByName(Name)) + if (auto* pTexSRV = GetResourceByName(Name)) return pTexSRV; - if(auto* pTexUAV = GetResourceByName(Name)) + if (auto* pTexUAV = GetResourceByName(Name)) return pTexUAV; - if(auto* pBuffSRV = GetResourceByName(Name)) + if (auto* pBuffSRV = GetResourceByName(Name)) return pBuffSRV; - if(auto* pBuffUAV = GetResourceByName(Name)) + if (auto* pBuffUAV = GetResourceByName(Name)) return pBuffUAV; if (!m_pResources->IsUsingCombinedTextureSamplers()) { - auto NumSamplers = GetNumResources(); - for (Uint32 s = 0; s < NumSamplers; ++s) - { - auto& Sampler = GetResource(s); - if (strcmp(Sampler.m_Attribs.Name, Name) == 0) - { - // Do not return static samplers - return Sampler.pStaticSampler ? nullptr : &Sampler; - } - } + // Static samplers are never created in the resource layout + if (auto* pSampler = GetResourceByName(Name)) + return pSampler; } return nullptr; -- cgit v1.2.3