diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2019-03-04 04:50:04 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2019-03-04 04:50:04 +0000 |
| commit | c3ce1b6cc0214c0c67ac6c75b742b92b18af30d8 (patch) | |
| tree | 7afef7d7245fdd226b8d0f440f8042739599cb47 /Graphics/GraphicsEngineD3D11 | |
| parent | Almost completed refactoring d3d11 backend to comply with the new API (diff) | |
| download | DiligentCore-c3ce1b6cc0214c0c67ac6c75b742b92b18af30d8.tar.gz DiligentCore-c3ce1b6cc0214c0c67ac6c75b742b92b18af30d8.zip | |
Final changes to complete d3d11 backend refactor
Diffstat (limited to 'Graphics/GraphicsEngineD3D11')
5 files changed, 110 insertions, 74 deletions
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<ID3D11BlendState> m_pd3d11BlendState; CComPtr<ID3D11RasterizerState> m_pd3d11RasterizerState; CComPtr<ID3D11DepthStencilState> 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<ISampler> > > 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<const ShaderResourcesD3D11> 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<ISampler> _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<ISampler> 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<ShaderResourceCacheD3D11*>(pResCacheRawMem); const auto& ResourceLayout = PipelineDesc.ResourceLayout; + +#ifdef DEVELOPMENT + { + const ShaderResources* pResources[MaxShadersInPipeline] = {}; + for (Uint32 s = 0; s < m_NumShaders; ++s) + { + auto* pShader = GetShader<const ShaderD3D11Impl>(s); + pResources[s] = &(*pShader->GetD3D11Resources()); + } + ShaderResources::DvpVerifyResourceLayout(ResourceLayout, pResources, m_NumShaders); + } +#endif + + decltype(m_StaticSamplers) StaticSamplers; std::array<size_t, MaxShadersInPipeline> ShaderResLayoutDataSizes = {}; std::array<size_t, MaxShadersInPipeline> 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<ISampler> pStaticSampler; + pRenderDeviceD3D11->CreateSampler(SrcStaticSamplerInfo.Desc, &pStaticSampler); + StaticSamplers.emplace_back(SamplerAttribs, std::move(pStaticSampler)); + } + } + m_StaticSamplerOffsets[s + 1] = static_cast<Uint16>(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<Int8>(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<SamplerD3D11Impl>(); + // Limiting EndBindPoint is required when initializing static samplers in a Shader's static cache + auto EndBindPoint = std::min( static_cast<Uint32>(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<ShaderResourceCacheD3D11*>(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<Int8>(ShaderInd); } @@ -163,7 +158,7 @@ void ShaderResourceBindingD3D11Impl::InitializeStaticResources(const IPipelineSt VERIFY_EXPR(ResourceLayoutInd == static_cast<Int8>(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<const ShaderResourcesD3D11> 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<ISampler> 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<SamplerBindInfo>(sam++)) SamplerBindInfo(Sampler, *this, VarType, std::move(pStaticSampler));
+ new (&GetResource<SamplerBindInfo>(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<SamplerBindInfo>(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<SamplerBindInfo>(); ++s)
- {
- auto& Sampler = GetConstResource<SamplerBindInfo>(s);
- if (Sampler.pStaticSampler)
- {
- const auto& SamAttribs = Sampler.m_Attribs;
- auto* pSamplerD3D11Impl = const_cast<SamplerD3D11Impl*>(Sampler.pStaticSampler.RawPtr<SamplerD3D11Impl>());
- // Limiting EndBindPoint is required when initializing static samplers in a Shader's static cache
- auto EndBindPoint = std::min( static_cast<Uint32>(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<SamplerBindInfo>(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<ConstBuffBindInfo>(Name))
+ if (auto* pCB = GetResourceByName<ConstBuffBindInfo>(Name))
return pCB;
- if(auto* pTexSRV = GetResourceByName<TexSRVBindInfo>(Name))
+ if (auto* pTexSRV = GetResourceByName<TexSRVBindInfo>(Name))
return pTexSRV;
- if(auto* pTexUAV = GetResourceByName<TexUAVBindInfo>(Name))
+ if (auto* pTexUAV = GetResourceByName<TexUAVBindInfo>(Name))
return pTexUAV;
- if(auto* pBuffSRV = GetResourceByName<BuffSRVBindInfo>(Name))
+ if (auto* pBuffSRV = GetResourceByName<BuffSRVBindInfo>(Name))
return pBuffSRV;
- if(auto* pBuffUAV = GetResourceByName<BuffUAVBindInfo>(Name))
+ if (auto* pBuffUAV = GetResourceByName<BuffUAVBindInfo>(Name))
return pBuffUAV;
if (!m_pResources->IsUsingCombinedTextureSamplers())
{
- auto NumSamplers = GetNumResources<SamplerBindInfo>();
- for (Uint32 s = 0; s < NumSamplers; ++s)
- {
- auto& Sampler = GetResource<SamplerBindInfo>(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<SamplerBindInfo>(Name))
+ return pSampler;
}
return nullptr;
|
