diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-06-19 15:52:15 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-06-19 15:52:15 +0000 |
| commit | f345a63c047c7760cb5c5fe70f72a075b4f3a7df (patch) | |
| tree | 95d9ec41ff14a8b52326e9f80c807365b767c05a /Graphics | |
| parent | Cleaned D3D Shader Resource implementation (diff) | |
| download | DiligentCore-f345a63c047c7760cb5c5fe70f72a075b4f3a7df.tar.gz DiligentCore-f345a63c047c7760cb5c5fe70f72a075b4f3a7df.zip | |
Implemented resource names string pool for D3D backends
Diffstat (limited to 'Graphics')
7 files changed, 193 insertions, 142 deletions
diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderResourceLayoutD3D11.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderResourceLayoutD3D11.cpp index db1d9c4b..14ef0e84 100644 --- a/Graphics/GraphicsEngineD3D11/src/ShaderResourceLayoutD3D11.cpp +++ b/Graphics/GraphicsEngineD3D11/src/ShaderResourceLayoutD3D11.cpp @@ -77,7 +77,7 @@ ShaderResourceLayoutD3D11::~ShaderResourceLayoutD3D11() ); } -const D3DShaderResourceAttribs ShaderResourceLayoutD3D11::TexAndSamplerBindInfo::InvalidSamplerAttribs(String("Invalid sampler"), D3DShaderResourceAttribs::InvalidBindPoint, 0, D3D_SIT_SAMPLER, SHADER_VARIABLE_TYPE_NUM_TYPES, D3D_SRV_DIMENSION_UNKNOWN, D3DShaderResourceAttribs::InvalidSamplerId, false); +const D3DShaderResourceAttribs ShaderResourceLayoutD3D11::TexAndSamplerBindInfo::InvalidSamplerAttribs("Invalid sampler", D3DShaderResourceAttribs::InvalidBindPoint, 0, D3D_SIT_SAMPLER, SHADER_VARIABLE_TYPE_NUM_TYPES, D3D_SRV_DIMENSION_UNKNOWN, D3DShaderResourceAttribs::InvalidSamplerId, false); void ShaderResourceLayoutD3D11::Initialize(const std::shared_ptr<const ShaderResourcesD3D11>& pSrcResources, const SHADER_VARIABLE_TYPE *VarTypes, @@ -264,7 +264,7 @@ void ShaderResourceLayoutD3D11::CopyResources(ShaderResourceCacheD3D11 &DstCache { VERIFY_EXPR(ts.SamplerAttribs.BindCount == ts.Attribs.BindCount || ts.SamplerAttribs.BindCount == 1); Uint32 SamplerSlot = ts.SamplerAttribs.BindPoint + (ts.SamplerAttribs.BindCount == 1 ? 0 : (SRVSlot - ts.Attribs.BindPoint)); - if( !ts.SamplerAttribs.GetIsStaticSampler() ) + if( !ts.SamplerAttribs.IsStaticSampler() ) { VERIFY_EXPR( SamplerSlot < m_pResourceCache->GetSamplerCount() && SamplerSlot < DstCache.GetSamplerCount() ); DstSamplers[SamplerSlot] = CachedSamplers[SamplerSlot]; @@ -318,27 +318,27 @@ void ShaderResourceLayoutD3D11::InitVariablesHashMap() HandleResources( [&](ConstBuffBindInfo&cb) { - m_VariableHash.insert( std::make_pair( Diligent::HashMapStringKey(cb.Attribs.Name), &cb ) ); + m_VariableHash.insert( std::make_pair( Diligent::HashMapStringKey(cb.Attribs.Name, true), &cb ) ); }, [&](TexAndSamplerBindInfo& ts) { - m_VariableHash.insert( std::make_pair( Diligent::HashMapStringKey(ts.Attribs.Name), &ts ) ); + m_VariableHash.insert( std::make_pair( Diligent::HashMapStringKey(ts.Attribs.Name, true), &ts ) ); }, [&](TexUAVBindInfo& uav) { - m_VariableHash.insert( std::make_pair( Diligent::HashMapStringKey(uav.Attribs.Name), &uav ) ); + m_VariableHash.insert( std::make_pair( Diligent::HashMapStringKey(uav.Attribs.Name, true), &uav ) ); }, [&](BuffSRVBindInfo& srv) { - m_VariableHash.insert( std::make_pair( Diligent::HashMapStringKey(srv.Attribs.Name), &srv ) ); + m_VariableHash.insert( std::make_pair( Diligent::HashMapStringKey(srv.Attribs.Name, true), &srv ) ); }, [&](BuffUAVBindInfo& uav) { - m_VariableHash.insert( std::make_pair( Diligent::HashMapStringKey(uav.Attribs.Name), &uav ) ); + m_VariableHash.insert( std::make_pair( Diligent::HashMapStringKey(uav.Attribs.Name, true), &uav ) ); } ); #endif @@ -346,7 +346,7 @@ void ShaderResourceLayoutD3D11::InitVariablesHashMap() #define LOG_RESOURCE_BINDING_ERROR(ResType, pResource, Attribs, ArrayInd, ShaderName, ...)\ do{ \ - const auto &ResName = pResource->GetDesc().Name; \ + 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__ ); \ @@ -469,7 +469,7 @@ void ShaderResourceLayoutD3D11::TexAndSamplerBindInfo::BindResource( IDeviceObje { VERIFY_EXPR(SamplerAttribs.BindCount == Attribs.BindCount || SamplerAttribs.BindCount == 1); auto SamplerBindPoint = SamplerAttribs.BindPoint + (SamplerAttribs.BindCount != 1 ? ArrayIndex : 0); - if( !SamplerAttribs.GetIsStaticSampler() ) + if( !SamplerAttribs.IsStaticSampler() ) { SamplerD3D11Impl *pSamplerD3D11Impl = nullptr; if( pViewD3D11 ) @@ -655,10 +655,10 @@ public: if( (Flags & BIND_SHADER_RESOURCES_UPDATE_UNRESOLVED) && Res.IsBound(elem) ) return; - const auto& VarName = Res.Attribs.Name; + const auto* VarName = Res.Attribs.Name; RefCntAutoPtr<IDeviceObject> pRes; VERIFY_EXPR(pResourceMapping != nullptr); - pResourceMapping->GetResource( VarName.c_str(), &pRes, elem ); + pResourceMapping->GetResource( VarName, &pRes, elem ); if( pRes ) { // Call non-virtual function @@ -728,19 +728,19 @@ IShaderVariable* ShaderResourceLayoutD3D11::GetShaderVariable(const Char* Name) pVar = it->second; #else for (Uint32 cb = 0; cb < m_NumCBs; ++cb) - if(GetCB(cb).Attribs.Name.compare(Name) == 0) + if (strcmp(GetCB(cb).Attribs.Name, Name) == 0) return &GetCB(cb); for (Uint32 t = 0; t < m_NumTexSRVs; ++t) - if(GetTexSRV(t).Attribs.Name.compare(Name) == 0 ) + if (strcmp(GetTexSRV(t).Attribs.Name, Name) == 0 ) return &GetTexSRV(t); for (Uint32 u = 0; u < m_NumTexUAVs; ++u) - if(GetTexUAV(u).Attribs.Name.compare(Name) == 0 ) + if (strcmp(GetTexUAV(u).Attribs.Name, Name) == 0 ) return &GetTexUAV(u); for (Uint32 s = 0; s < m_NumBufSRVs; ++s) - if(GetBufSRV(s).Attribs.Name.compare(Name) == 0 ) + if (strcmp(GetBufSRV(s).Attribs.Name, Name) == 0 ) return &GetBufSRV(s); for (Uint32 u = 0; u < m_NumBufUAVs; ++u) - if(GetBufUAV(u).Attribs.Name.compare(Name) == 0 ) + if (strcmp(GetBufUAV(u).Attribs.Name, Name) == 0 ) return &GetBufUAV(u); #endif if(pVar == nullptr) diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderResourcesD3D11.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderResourcesD3D11.cpp index 1fec3454..d8532762 100644 --- a/Graphics/GraphicsEngineD3D11/src/ShaderResourcesD3D11.cpp +++ b/Graphics/GraphicsEngineD3D11/src/ShaderResourcesD3D11.cpp @@ -43,53 +43,53 @@ ShaderResourcesD3D11::ShaderResourcesD3D11(RenderDeviceD3D11Impl *pDeviceD3D11Im LoadD3DShaderResources<D3D11_SHADER_DESC, D3D11_SHADER_INPUT_BIND_DESC, ID3D11ShaderReflection>( pShaderBytecode, - [&](Uint32 NumCBs, Uint32 NumTexSRVs, Uint32 NumTexUAVs, Uint32 NumBufSRVs, Uint32 NumBufUAVs, Uint32 NumSamplers) + [&](Uint32 NumCBs, Uint32 NumTexSRVs, Uint32 NumTexUAVs, Uint32 NumBufSRVs, Uint32 NumBufUAVs, Uint32 NumSamplers, size_t ResourceNamesPoolSize) { - Initialize(GetRawAllocator(), NumCBs, NumTexSRVs, NumTexUAVs, NumBufSRVs, NumBufUAVs, NumSamplers); + Initialize(GetRawAllocator(), NumCBs, NumTexSRVs, NumTexUAVs, NumBufSRVs, NumBufUAVs, NumSamplers, ResourceNamesPoolSize); }, - [&](D3DShaderResourceAttribs&& CBAttribs) + [&](const D3DShaderResourceAttribs& CBAttribs) { VERIFY( CBAttribs.BindPoint + CBAttribs.BindCount-1 <= MaxAllowedBindPoint, "CB bind point exceeds supported range" ); m_MaxCBBindPoint = std::max(m_MaxCBBindPoint, static_cast<MaxBindPointType>(CBAttribs.BindPoint + CBAttribs.BindCount-1)); - new (&GetCB(CurrCB++)) D3DShaderResourceAttribs(std::move(CBAttribs)); + new (&GetCB(CurrCB++)) D3DShaderResourceAttribs(m_ResourceNames, CBAttribs); }, - [&](D3DShaderResourceAttribs &&TexUAV) + [&](const D3DShaderResourceAttribs& TexUAV) { VERIFY( TexUAV.BindPoint + TexUAV.BindCount-1 <= MaxAllowedBindPoint, "Tex UAV bind point exceeds supported range" ); m_MaxUAVBindPoint = std::max(m_MaxUAVBindPoint, static_cast<MaxBindPointType>(TexUAV.BindPoint + TexUAV.BindCount-1)); - new (&GetTexUAV(CurrTexUAV++)) D3DShaderResourceAttribs( std::move(TexUAV) ); + new (&GetTexUAV(CurrTexUAV++)) D3DShaderResourceAttribs(m_ResourceNames, TexUAV); }, - [&](D3DShaderResourceAttribs &&BuffUAV) + [&](const D3DShaderResourceAttribs& BuffUAV) { VERIFY( BuffUAV.BindPoint + BuffUAV.BindCount-1 <= MaxAllowedBindPoint, "Buff UAV bind point exceeds supported range" ); m_MaxUAVBindPoint = std::max(m_MaxUAVBindPoint, static_cast<MaxBindPointType>(BuffUAV.BindPoint + BuffUAV.BindCount-1)); - new (&GetBufUAV(CurrBufUAV++)) D3DShaderResourceAttribs( std::move(BuffUAV) ); + new (&GetBufUAV(CurrBufUAV++)) D3DShaderResourceAttribs(m_ResourceNames, BuffUAV); }, - [&](D3DShaderResourceAttribs &&BuffSRV) + [&](const D3DShaderResourceAttribs& BuffSRV) { VERIFY( BuffSRV.BindPoint + BuffSRV.BindCount-1 <= MaxAllowedBindPoint, "Buff SRV bind point exceeds supported range" ); m_MaxSRVBindPoint = std::max(m_MaxSRVBindPoint, static_cast<MaxBindPointType>(BuffSRV.BindPoint + BuffSRV.BindCount-1)); - new (&GetBufSRV(CurrBufSRV++)) D3DShaderResourceAttribs( std::move(BuffSRV) ); + new (&GetBufSRV(CurrBufSRV++)) D3DShaderResourceAttribs(m_ResourceNames, BuffSRV); }, - [&](D3DShaderResourceAttribs &&SamplerAttribs) + [&](const D3DShaderResourceAttribs& SamplerAttribs) { VERIFY( SamplerAttribs.BindPoint + SamplerAttribs.BindCount-1 <= MaxAllowedBindPoint, "Sampler bind point exceeds supported range" ); m_MaxSamplerBindPoint = std::max(m_MaxSamplerBindPoint, static_cast<MaxBindPointType>(SamplerAttribs.BindPoint + SamplerAttribs.BindCount-1)); - m_NumStaticSamplers += SamplerAttribs.GetIsStaticSampler() ? 1 : 0; + m_NumStaticSamplers += SamplerAttribs.IsStaticSampler() ? 1 : 0; - new (&GetSampler(CurrSampler++)) D3DShaderResourceAttribs( std::move(SamplerAttribs) ); + new (&GetSampler(CurrSampler++)) D3DShaderResourceAttribs(m_ResourceNames, SamplerAttribs); }, - [&](D3DShaderResourceAttribs &&TexAttribs) + [&](const D3DShaderResourceAttribs& TexAttribs) { VERIFY(CurrSampler == GetNumSamplers(), "All samplers must be initialized before texture SRVs" ); @@ -97,12 +97,13 @@ ShaderResourcesD3D11::ShaderResourcesD3D11(RenderDeviceD3D11Impl *pDeviceD3D11Im m_MaxSRVBindPoint = std::max(m_MaxSRVBindPoint, static_cast<MaxBindPointType>(TexAttribs.BindPoint + TexAttribs.BindCount-1)); auto SamplerId = FindAssignedSamplerId(TexAttribs); - new (&GetTexSRV(CurrTexSRV++)) D3DShaderResourceAttribs( std::move(TexAttribs), SamplerId); + new (&GetTexSRV(CurrTexSRV++)) D3DShaderResourceAttribs(m_ResourceNames, TexAttribs, SamplerId); }, ShdrDesc, D3DSamplerSuffix); + VERIFY_EXPR(m_ResourceNames.GetRemainingSize() == 0); VERIFY(CurrCB == GetNumCBs(), "Not all CBs are initialized, which will result in a crash when ~D3DShaderResourceAttribs() is called"); VERIFY(CurrTexSRV == GetNumTexSRV(), "Not all Tex SRVs are initialized, which will result in a crash when ~D3DShaderResourceAttribs() is called" ); VERIFY(CurrTexUAV == GetNumTexUAV(), "Not all Tex UAVs are initialized, which will result in a crash when ~D3DShaderResourceAttribs() is called" ); @@ -124,13 +125,13 @@ ShaderResourcesD3D11::ShaderResourcesD3D11(RenderDeviceD3D11Impl *pDeviceD3D11Im for (Uint32 s = 0; s < GetNumSamplers(); ++s) { const auto &Sam = GetSampler(s); - if (Sam.GetIsStaticSampler()) + if (Sam.IsStaticSampler()) { Uint32 ssd = 0; for (; ssd < ShdrDesc.NumStaticSamplers; ++ssd) { const auto& StaticSamplerDesc = ShdrDesc.StaticSamplers[ssd]; - if ( StrCmpSuff(Sam.Name.c_str(), StaticSamplerDesc.TextureName, D3DSamplerSuffix)) + if (StrCmpSuff(Sam.Name, StaticSamplerDesc.TextureName, D3DSamplerSuffix)) { auto &StaticSamplerAttrs = GetStaticSampler(CurrStaticSam++); StaticSamplerAttrs.first = &Sam; diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp index 367ff074..c020197f 100644 --- a/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp +++ b/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp @@ -143,7 +143,7 @@ ShaderResourceLayoutD3D12::ShaderResourceLayoutD3D12(IObject &Owner, if (SrcRes.IsValidSampler()) { const auto &SrcSamplerAttribs = SrcLayout.GetSampler(VarType, SrcRes.GetSamplerId()); - VERIFY(!SrcSamplerAttribs.Attribs.GetIsStaticSampler(), "Only non-static samplers can be assigned space in shader cache"); + VERIFY(!SrcSamplerAttribs.Attribs.IsStaticSampler(), "Only non-static samplers can be assigned space in shader cache"); VERIFY(SrcSamplerAttribs.Attribs.VariableType == SrcRes.Attribs.VariableType, "Inconsistent texture and sampler variable types" ); VERIFY(SrcSamplerAttribs.IsValidRootIndex(), "Root index must be valid"); VERIFY(SrcSamplerAttribs.IsValidOffset(), "Offset must be valid"); @@ -207,7 +207,7 @@ void ShaderResourceLayoutD3D12::Initialize(ID3D12Device *pd3d12Device, auto SamplerId = TexSRV.GetSamplerId(); const auto &SamplerAttribs = m_pResources->GetSampler(SamplerId); VERIFY(SamplerAttribs.VariableType == VarType, "Texture and sampler variable types are not conistent"); - if(!SamplerAttribs.GetIsStaticSampler()) + if(!SamplerAttribs.IsStaticSampler()) { ++m_NumSamplers[VarType]; } @@ -293,7 +293,7 @@ void ShaderResourceLayoutD3D12::Initialize(ID3D12Device *pd3d12Device, const auto &SrcSamplerAttribs = m_pResources->GetSampler(TexSRV.GetSamplerId()); VERIFY(SrcSamplerAttribs.VariableType == VarType, "Inconsistent texture and sampler variable types" ); - if (SrcSamplerAttribs.GetIsStaticSampler()) + if (SrcSamplerAttribs.IsStaticSampler()) { if(pRootSig != nullptr) pRootSig->InitStaticSampler(m_pResources->GetShaderType(), TexSRV.Name, SrcSamplerAttribs); @@ -387,7 +387,7 @@ void ShaderResourceLayoutD3D12::InitVariablesHashMap() { auto &Res = GetSrvCbvUav(r); /* HashMapStringKey will make a copy of the string*/ - m_VariableHash.insert( std::make_pair( Diligent::HashMapStringKey(Res.Name), &Res ) ); + m_VariableHash.insert( std::make_pair( Diligent::HashMapStringKey(Res.Name, true), &Res ) ); } #endif } @@ -621,7 +621,7 @@ ShaderResourceLayoutD3D12::Sampler &ShaderResourceLayoutD3D12::GetAssignedSample VERIFY(TexSrv.IsValidSampler(), "Texture SRV has no associated sampler"); auto &SamInfo = GetSampler(TexSrv.Attribs.VariableType, TexSrv.GetSamplerId()); VERIFY(SamInfo.Attribs.VariableType == TexSrv.Attribs.VariableType, "Inconsistent texture and sampler variable types"); - VERIFY(SamInfo.Attribs.Name == TexSrv.Attribs.Name + D3DSamplerSuffix, "Sampler name \"", SamInfo.Attribs.Name, "\" does not match texture name \"", TexSrv.Attribs.Name, '\"'); + VERIFY(StrCmpSuff(SamInfo.Attribs.Name, TexSrv.Attribs.Name, D3DSamplerSuffix), "Sampler name \"", SamInfo.Attribs.Name, "\" does not match texture name \"", TexSrv.Attribs.Name, '\"'); return SamInfo; } @@ -677,7 +677,7 @@ void ShaderResourceLayoutD3D12::SRV_CBV_UAV::BindResource(IDeviceObject *pObj, U if(IsValidSampler()) { auto &Sam = m_ParentResLayout.GetAssignedSampler(*this); - VERIFY( !Sam.Attribs.GetIsStaticSampler(), "Static samplers should never be assigned space in the cache" ); + VERIFY( !Sam.Attribs.IsStaticSampler(), "Static samplers should never be assigned space in the cache" ); VERIFY_EXPR(Attribs.BindCount == Sam.Attribs.BindCount || Sam.Attribs.BindCount == 1); auto SamplerArrInd = Sam.Attribs.BindCount > 1 ? ArrayIndex : 0; auto ShdrVisibleSamplerHeapCPUDescriptorHandle = pResourceCache->GetShaderVisibleTableCPUDescriptorHandle<D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER>(Sam.RootIndex, Sam.OffsetFromTableStart + SamplerArrInd); @@ -767,10 +767,9 @@ void ShaderResourceLayoutD3D12::BindResources( IResourceMapping* pResourceMappin if( (Flags & BIND_SHADER_RESOURCES_UPDATE_UNRESOLVED) && Res.IsBound(ArrInd) ) return; - const auto& VarName = Res.Attribs.Name; RefCntAutoPtr<IDeviceObject> pObj; VERIFY_EXPR(pResourceMapping != nullptr); - pResourceMapping->GetResource( VarName.c_str(), &pObj, ArrInd ); + pResourceMapping->GetResource( Res.Attribs.Name, &pObj, ArrInd ); if( pObj ) { // Call non-virtual function @@ -799,7 +798,7 @@ IShaderVariable* ShaderResourceLayoutD3D12::GetShaderVariable(const Char* Name) for(Uint32 r=0; r < TotalResources; ++r) { auto &Res = GetSrvCbvUav(r); - if(Res.Attribs.Name.compare(Name) == 0) + if (strcmp(Res.Attribs.Name, Name) == 0) { pVar = &Res; break; @@ -885,7 +884,7 @@ void ShaderResourceLayoutD3D12::CopyStaticResourceDesriptorHandles(const ShaderR { auto &SamInfo = GetAssignedSampler(res); - VERIFY(!SamInfo.Attribs.GetIsStaticSampler(), "Static samplers should never be assigned space in the cache"); + VERIFY(!SamInfo.Attribs.IsStaticSampler(), "Static samplers should never be assigned space in the cache"); VERIFY(SamInfo.Attribs.IsValidBindPoint(), "Sampler bind point must be valid"); VERIFY_EXPR(SamInfo.Attribs.BindCount == res.Attribs.BindCount || SamInfo.Attribs.BindCount == 1); @@ -1001,7 +1000,7 @@ void ShaderResourceLayoutD3D12::dbgVerifyBindings()const { VERIFY(res.GetResType() == CachedResourceType::TexSRV, "Sampler can only be assigned to a texture SRV" ); const auto &SamInfo = const_cast<ShaderResourceLayoutD3D12*>(this)->GetAssignedSampler(res); - VERIFY( !SamInfo.Attribs.GetIsStaticSampler(), "Static samplers should never be assigned space in the cache" ); + VERIFY(!SamInfo.Attribs.IsStaticSampler(), "Static samplers should never be assigned space in the cache" ); VERIFY(SamInfo.Attribs.IsValidBindPoint(), "Sampler bind point must be valid"); for(Uint32 ArrInd = 0; ArrInd < SamInfo.Attribs.BindCount; ++ArrInd) diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderResourcesD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderResourcesD3D12.cpp index 1127d03d..2a06fd03 100644 --- a/Graphics/GraphicsEngineD3D12/src/ShaderResourcesD3D12.cpp +++ b/Graphics/GraphicsEngineD3D12/src/ShaderResourcesD3D12.cpp @@ -41,47 +41,48 @@ ShaderResourcesD3D12::ShaderResourcesD3D12(ID3DBlob *pShaderBytecode, const Shad LoadD3DShaderResources<D3D12_SHADER_DESC, D3D12_SHADER_INPUT_BIND_DESC, ID3D12ShaderReflection>( pShaderBytecode, - [&](Uint32 NumCBs, Uint32 NumTexSRVs, Uint32 NumTexUAVs, Uint32 NumBufSRVs, Uint32 NumBufUAVs, Uint32 NumSamplers) + [&](Uint32 NumCBs, Uint32 NumTexSRVs, Uint32 NumTexUAVs, Uint32 NumBufSRVs, Uint32 NumBufUAVs, Uint32 NumSamplers, size_t ResourceNamesPoolSize) { - Initialize(GetRawAllocator(), NumCBs, NumTexSRVs, NumTexUAVs, NumBufSRVs, NumBufUAVs, NumSamplers); + Initialize(GetRawAllocator(), NumCBs, NumTexSRVs, NumTexUAVs, NumBufSRVs, NumBufUAVs, NumSamplers, ResourceNamesPoolSize); }, - [&](D3DShaderResourceAttribs&& CBAttribs) + [&](const D3DShaderResourceAttribs& CBAttribs) { - new (&GetCB(CurrCB++)) D3DShaderResourceAttribs(std::move(CBAttribs)); + new (&GetCB(CurrCB++)) D3DShaderResourceAttribs(m_ResourceNames, CBAttribs); }, - [&](D3DShaderResourceAttribs &&TexUAV) + [&](const D3DShaderResourceAttribs& TexUAV) { - new (&GetTexUAV(CurrTexUAV++)) D3DShaderResourceAttribs( std::move(TexUAV) ); + new (&GetTexUAV(CurrTexUAV++)) D3DShaderResourceAttribs(m_ResourceNames, TexUAV); }, - [&](D3DShaderResourceAttribs &&BuffUAV) + [&](const D3DShaderResourceAttribs& BuffUAV) { - new (&GetBufUAV(CurrBufUAV++)) D3DShaderResourceAttribs( std::move(BuffUAV) ); + new (&GetBufUAV(CurrBufUAV++)) D3DShaderResourceAttribs(m_ResourceNames, BuffUAV); }, - [&](D3DShaderResourceAttribs &&BuffSRV) + [&](const D3DShaderResourceAttribs& BuffSRV) { - new (&GetBufSRV(CurrBufSRV++)) D3DShaderResourceAttribs( std::move(BuffSRV) ); + new (&GetBufSRV(CurrBufSRV++)) D3DShaderResourceAttribs(m_ResourceNames, BuffSRV); }, - [&](D3DShaderResourceAttribs &&SamplerAttribs) + [&](const D3DShaderResourceAttribs& SamplerAttribs) { - new (&GetSampler(CurrSampler++)) D3DShaderResourceAttribs( std::move(SamplerAttribs) ); + new (&GetSampler(CurrSampler++)) D3DShaderResourceAttribs(m_ResourceNames, SamplerAttribs); }, - [&](D3DShaderResourceAttribs &&TexAttribs) + [&](const D3DShaderResourceAttribs& TexAttribs) { VERIFY(CurrSampler == GetNumSamplers(), "All samplers must be initialized before texture SRVs" ); auto SamplerId = FindAssignedSamplerId(TexAttribs); - new (&GetTexSRV(CurrTexSRV++)) D3DShaderResourceAttribs( std::move(TexAttribs), SamplerId); + new (&GetTexSRV(CurrTexSRV++)) D3DShaderResourceAttribs(m_ResourceNames, TexAttribs, SamplerId); }, ShdrDesc, D3DSamplerSuffix); + VERIFY_EXPR(m_ResourceNames.GetRemainingSize() == 0); VERIFY(CurrCB == GetNumCBs(), "Not all CBs are initialized, which will result in a crash when ~D3DShaderResourceAttribs() is called"); VERIFY(CurrTexSRV == GetNumTexSRV(), "Not all Tex SRVs are initialized, which will result in a crash when ~D3DShaderResourceAttribs() is called" ); VERIFY(CurrTexUAV == GetNumTexUAV(), "Not all Tex UAVs are initialized, which will result in a crash when ~D3DShaderResourceAttribs() is called" ); diff --git a/Graphics/GraphicsEngineD3DBase/include/D3DShaderResourceLoader.h b/Graphics/GraphicsEngineD3DBase/include/D3DShaderResourceLoader.h index 937d6b30..db2bd897 100644 --- a/Graphics/GraphicsEngineD3DBase/include/D3DShaderResourceLoader.h +++ b/Graphics/GraphicsEngineD3DBase/include/D3DShaderResourceLoader.h @@ -23,6 +23,10 @@ #pragma once +#include <string> +#include <vector> +#include <unordered_set> + #include "Shader.h" #include "StringTools.h" @@ -42,30 +46,32 @@ namespace Diligent typename TOnNewBuffSRV, typename TOnNewSampler, typename TOnNewTexSRV> - void LoadD3DShaderResources(ID3DBlob *pShaderByteCode, + void LoadD3DShaderResources(ID3DBlob* pShaderByteCode, TOnResourcesCounted OnResourcesCounted, - TOnNewCB OnNewCB, - TOnNewTexUAV OnNewTexUAV, - TOnNewBuffUAV OnNewBuffUAV, - TOnNewBuffSRV OnNewBuffSRV, - TOnNewSampler OnNewSampler, - TOnNewTexSRV OnNewTexSRV, - - const ShaderDesc &ShdrDesc, - const Char *SamplerSuffix) + TOnNewCB OnNewCB, + TOnNewTexUAV OnNewTexUAV, + TOnNewBuffUAV OnNewBuffUAV, + TOnNewBuffSRV OnNewBuffSRV, + TOnNewSampler OnNewSampler, + TOnNewTexSRV OnNewTexSRV, + + const ShaderDesc& ShdrDesc, + const Char* SamplerSuffix) { CComPtr<TShaderReflection> pShaderReflection; - CHECK_D3D_RESULT_THROW( D3DReflect( pShaderByteCode->GetBufferPointer(), pShaderByteCode->GetBufferSize(), __uuidof(pShaderReflection), reinterpret_cast<void**>(static_cast<TShaderReflection**>(&pShaderReflection)) ), - "Failed to get the shader reflection" ); + auto hr = D3DReflect( pShaderByteCode->GetBufferPointer(), pShaderByteCode->GetBufferSize(), __uuidof(pShaderReflection), reinterpret_cast<void**>(static_cast<TShaderReflection**>(&pShaderReflection))); + CHECK_D3D_RESULT_THROW(hr, "Failed to get the shader reflection" ); D3D_SHADER_DESC shaderDesc = {}; pShaderReflection->GetDesc( &shaderDesc ); std::vector<D3DShaderResourceAttribs, STDAllocatorRawMem<D3DShaderResourceAttribs> > Resources( STD_ALLOCATOR_RAW_MEM(D3DShaderResourceAttribs, GetRawAllocator(), "Allocator for vector<D3DShaderResourceAttribs>") ); Resources.reserve(shaderDesc.BoundResources); - + std::unordered_set<std::string> ResourceNamesTmpPool; + Uint32 NumCBs = 0, NumTexSRVs = 0, NumTexUAVs = 0, NumBufSRVs = 0, NumBufUAVs = 0, NumSamplers = 0; + size_t ResourceNamesPoolSize = 0; // Number of resources to skip (used for array resources) UINT SkipCount = 1; for( UINT Res = 0; Res < shaderDesc.BoundResources; Res += SkipCount ) @@ -73,7 +79,7 @@ namespace Diligent D3D_SHADER_INPUT_BIND_DESC BindingDesc = {}; pShaderReflection->GetResourceBindingDesc( Res, &BindingDesc ); - String Name(BindingDesc.Name); + std::string Name(BindingDesc.Name); SkipCount = 1; @@ -107,7 +113,7 @@ namespace Diligent #ifdef _DEBUG for (const auto &ExistingRes : Resources) { - VERIFY(ExistingRes.Name != Name, "Resource with the same name has already been enumerated. All array elements are expected to be enumerated one after another"); + VERIFY(Name.compare(ExistingRes.Name) != 0, "Resource with the same name has already been enumerated. All array elements are expected to be enumerated one after another"); } #endif for( UINT ArrElem = Res+1; ArrElem < shaderDesc.BoundResources; ++ArrElem) @@ -153,15 +159,14 @@ namespace Diligent } // Use texture name to derive sampler type VarType = GetShaderVariableType(ShdrDesc.DefaultVariableType, ShdrDesc.VariableDesc, ShdrDesc.NumVariables, - [&](const char *TexName) - { - return StrCmpSuff(Name.c_str(), TexName, SamplerSuffix); - } - ); + [&](const char *TexName) + { + return StrCmpSuff(Name.c_str(), TexName, SamplerSuffix); + }); } else { - VarType = GetShaderVariableType(Name.c_str(), ShdrDesc.DefaultVariableType, ShdrDesc.VariableDesc, ShdrDesc.NumVariables); + VarType = GetShaderVariableType(Name, ShdrDesc.DefaultVariableType, ShdrDesc.VariableDesc, ShdrDesc.NumVariables); } @@ -181,7 +186,18 @@ namespace Diligent case D3D_SIT_UAV_RWSTRUCTURED_WITH_COUNTER: UNSUPPORTED( "RW structured buffers with counter are not supported" ); break; default: UNEXPECTED("Unexpected resource type"); } - Resources.emplace_back(std::move(Name), BindingDesc.BindPoint, BindCount, BindingDesc.Type, VarType, BindingDesc.Dimension, D3DShaderResourceAttribs::InvalidSamplerId, IsStaticSampler); + ResourceNamesPoolSize += Name.length() + 1; + auto it = ResourceNamesTmpPool.emplace(std::move(Name)); + Resources.emplace_back( + it.first->c_str(), + BindingDesc.BindPoint, + BindCount, + BindingDesc.Type, + VarType, + BindingDesc.Dimension, + D3DShaderResourceAttribs::InvalidSamplerId, + IsStaticSampler + ); } @@ -191,12 +207,12 @@ namespace Diligent for (Uint32 v = 0; v < ShdrDesc.NumVariables; ++v) { bool VariableFound = false; - const auto *VarName = ShdrDesc.VariableDesc[v].Name; + const auto* VarName = ShdrDesc.VariableDesc[v].Name; for (const auto& Res : Resources) { // Skip samplers as they are not handled as independent variables - if (Res.InputType != D3D_SIT_SAMPLER && Res.Name.compare(VarName) == 0) + if (Res.InputType != D3D_SIT_SAMPLER && strcmp(Res.Name, VarName) == 0) { VariableFound = true; break; @@ -215,7 +231,7 @@ namespace Diligent for (const auto& Res : Resources) { - if ( Res.InputType == D3D_SIT_TEXTURE && Res.SRVDimension != D3D_SRV_DIMENSION_BUFFER && Res.Name.compare(TexName) == 0) + if ( Res.InputType == D3D_SIT_TEXTURE && Res.SRVDimension != D3D_SRV_DIMENSION_BUFFER && strcmp(Res.Name, TexName) == 0) { TextureFound = true; break; @@ -229,18 +245,19 @@ namespace Diligent } #endif - OnResourcesCounted(NumCBs, NumTexSRVs, NumTexUAVs, NumBufSRVs, NumBufUAVs, NumSamplers); + OnResourcesCounted(NumCBs, NumTexSRVs, NumTexUAVs, NumBufSRVs, NumBufUAVs, NumSamplers, ResourceNamesPoolSize); - std::vector<D3DShaderResourceAttribs, STDAllocatorRawMem<D3DShaderResourceAttribs> > TextureSRVs( STD_ALLOCATOR_RAW_MEM(D3DShaderResourceAttribs, GetRawAllocator(), "Allocator for vector<D3DShaderResourceAttribs>") ); - TextureSRVs.reserve(NumTexSRVs); + std::vector<size_t, STDAllocatorRawMem<size_t> > TexSRVInds( STD_ALLOCATOR_RAW_MEM(size_t, GetRawAllocator(), "Allocator for vector<size_t>") ); + TexSRVInds.reserve(NumTexSRVs); - for(auto &Res : Resources) + for(size_t ResInd = 0; ResInd < Resources.size(); ++ResInd) { + const auto& Res = Resources[ResInd]; switch( Res.InputType ) { case D3D_SIT_CBUFFER: { - OnNewCB( std::move(Res) ); + OnNewCB( Res ); break; } @@ -254,18 +271,19 @@ namespace Diligent { if( Res.SRVDimension == D3D_SRV_DIMENSION_BUFFER ) { - OnNewBuffSRV( std::move(Res) ); + OnNewBuffSRV( Res ); } else { - TextureSRVs.emplace_back( std::move(Res) ); + // Texture SRVs must be processed all samplers are initialized + TexSRVInds.push_back(ResInd); } break; } case D3D_SIT_SAMPLER: { - OnNewSampler( std::move(Res) ); + OnNewSampler( Res ); break; } @@ -273,24 +291,24 @@ namespace Diligent { if( Res.SRVDimension == D3D_SRV_DIMENSION_BUFFER ) { - OnNewBuffUAV( std::move(Res) ); + OnNewBuffUAV( Res ); } else { - OnNewTexUAV( std::move(Res) ); + OnNewTexUAV( Res ); } break; } case D3D_SIT_STRUCTURED: { - OnNewBuffSRV( std::move(Res) ); + OnNewBuffSRV( Res ); break; } case D3D_SIT_UAV_RWSTRUCTURED: { - OnNewBuffUAV( std::move(Res) ); + OnNewBuffUAV( Res ); break; } @@ -302,7 +320,7 @@ namespace Diligent case D3D_SIT_UAV_RWBYTEADDRESS: { - OnNewBuffUAV( std::move(Res) ); + OnNewBuffUAV( Res ); break; } @@ -327,9 +345,9 @@ namespace Diligent } // Process texture SRVs. We need to do this after all samplers are initialized - for( auto &Tex : TextureSRVs ) + for( auto TexSRVInd : TexSRVInds ) { - OnNewTexSRV( std::move(Tex) ); + OnNewTexSRV( Resources[TexSRVInd] ); } } } diff --git a/Graphics/GraphicsEngineD3DBase/include/ShaderResources.h b/Graphics/GraphicsEngineD3DBase/include/ShaderResources.h index 04ebeb51..a8e9e46a 100644 --- a/Graphics/GraphicsEngineD3DBase/include/ShaderResources.h +++ b/Graphics/GraphicsEngineD3DBase/include/ShaderResources.h @@ -59,6 +59,7 @@ #include "Shader.h" #include "STDAllocator.h" #include "HashUtils.h" +#include "StringPool.h" namespace Diligent { @@ -84,7 +85,7 @@ inline Uint32 GetAllowedTypeBits(const SHADER_VARIABLE_TYPE *AllowedVarTypes, Ui struct D3DShaderResourceAttribs { - String Name; // Move ctor will not work if it is const + const char* const Name; const Uint16 BindPoint; const Uint16 BindCount; @@ -93,18 +94,19 @@ struct D3DShaderResourceAttribs // bit | 0 1 2 3 | 4 5 6 | 7 8 9 10 | 11 12 ... 30 | 31 | // | | | | | | // | InputType | VariableType | SRV Dim | SamplerId | StaticSamplerFlag | - static constexpr const Uint32 ShaderInputTypeBits = 4; - static constexpr const Uint32 VariableTypeBits = 3; - static constexpr const Uint32 SRVDimBits = 4; - static constexpr const Uint32 SamplerIdBits = 20; - static constexpr const Uint32 IsStaticSamplerFlagBits = 1; - static_assert(ShaderInputTypeBits + VariableTypeBits + SRVDimBits + SamplerIdBits + IsStaticSamplerFlagBits == 32, "Attributes are better be packed into 32 bits"); + static constexpr const Uint32 ShaderInputTypeBits = 4; + static constexpr const Uint32 VariableTypeBits = 3; + static constexpr const Uint32 SRVDimBits = 4; + static constexpr const Uint32 SamplerIdBits = 20; + static constexpr const Uint32 StaticSamplerFlagBits = 1; + static_assert(ShaderInputTypeBits + VariableTypeBits + SRVDimBits + SamplerIdBits + StaticSamplerFlagBits == 32, "Attributes are better be packed into 32 bits"); const D3D_SHADER_INPUT_TYPE InputType : ShaderInputTypeBits; // Max value: D3D_SIT_UAV_RWSTRUCTURED_WITH_COUNTER == 11 const SHADER_VARIABLE_TYPE VariableType : VariableTypeBits; // Max value: SHADER_VARIABLE_TYPE_DYNAMIC == 2 const D3D_SRV_DIMENSION SRVDimension : SRVDimBits; // Max value: D3D_SRV_DIMENSION_BUFFEREX == 11 const Uint32 SamplerId : SamplerIdBits; // Max value: 1048575 - const bool IsStaticSampler : IsStaticSamplerFlagBits; + const Uint32 StaticSamplerFlag : StaticSamplerFlagBits; // Needs to be Uint32, otherwise sizeof(D3DShaderResourceAttribs)==24 + // (https://stackoverflow.com/questions/308364/c-bitfield-packing-with-bools) static constexpr const Uint32 InvalidSamplerId = (1 << SamplerIdBits) - 1; static constexpr const Uint16 InvalidBindPoint = std::numeric_limits<Uint16>::max(); @@ -115,7 +117,7 @@ struct D3DShaderResourceAttribs static_assert(SHADER_VARIABLE_TYPE_NUM_TYPES < (1 << VariableTypeBits), "Not enough bits to represent SHADER_VARIABLE_TYPE"); static_assert(D3D_SRV_DIMENSION_BUFFEREX < (1 << SRVDimBits), "Not enough bits to represent D3D_SRV_DIMENSION"); - D3DShaderResourceAttribs(String _Name, + D3DShaderResourceAttribs(const char* _Name, UINT _BindPoint, UINT _BindCount, D3D_SHADER_INPUT_TYPE _InputType, @@ -123,14 +125,14 @@ struct D3DShaderResourceAttribs D3D_SRV_DIMENSION _SRVDimension, Uint32 _SamplerId, bool _IsStaticSampler)noexcept : - Name(std::move(_Name)), - BindPoint(static_cast<decltype(BindPoint)>(_BindPoint)), - BindCount(static_cast<decltype(BindCount)>(_BindCount)), - InputType (_InputType), - VariableType (_VariableType), - SRVDimension (_SRVDimension), - SamplerId (_SamplerId), - IsStaticSampler(_IsStaticSampler) + Name (_Name), + BindPoint (static_cast<decltype(BindPoint)>(_BindPoint)), + BindCount (static_cast<decltype(BindCount)>(_BindCount)), + InputType (_InputType), + VariableType (_VariableType), + SRVDimension (_SRVDimension), + SamplerId (_SamplerId), + StaticSamplerFlag(_IsStaticSampler ? 1 : 0) { VERIFY(_BindPoint <= MaxBindPoint || _BindPoint == InvalidBindPoint, "Bind Point is out of allowed range"); VERIFY(_BindCount <= MaxBindCount, "Bind Count is out of allowed range"); @@ -140,7 +142,7 @@ struct D3DShaderResourceAttribs VERIFY(_SamplerId < (1 << SamplerIdBits), "SamplerId is out of representable range"); #ifdef _DEBUG if(_InputType==D3D_SIT_SAMPLER) - VERIFY_EXPR(IsStaticSampler == _IsStaticSampler); + VERIFY_EXPR(IsStaticSampler() == _IsStaticSampler); else VERIFY(!_IsStaticSampler, "Only samplers can be marked as static"); @@ -154,13 +156,10 @@ struct D3DShaderResourceAttribs #endif } - D3DShaderResourceAttribs(D3DShaderResourceAttribs&& rhs) = default; - D3DShaderResourceAttribs(const D3DShaderResourceAttribs& rhs) = delete; - - D3DShaderResourceAttribs(const D3DShaderResourceAttribs& rhs, Uint32 SamplerId)noexcept : + D3DShaderResourceAttribs(StringPool& NamesPool, const D3DShaderResourceAttribs& rhs, Uint32 SamplerId)noexcept : D3DShaderResourceAttribs { - rhs.Name, + NamesPool.CopyString(rhs.Name), rhs.BindPoint, rhs.BindCount, rhs.InputType, @@ -173,24 +172,36 @@ struct D3DShaderResourceAttribs VERIFY(InputType == D3D_SIT_TEXTURE, "Only textures can be assigned a texture sampler"); } - //D3DShaderResourceAttribs(D3DShaderResourceAttribs&& rhs)noexcept : - // Name(std::move(rhs.Name)), - // BindPoint(rhs.BindPoint), - // BindCount(rhs.BindCount), - // PackedAttribs( rhs.PackedAttribs ) - //{ - //} + D3DShaderResourceAttribs(StringPool& NamesPool, const D3DShaderResourceAttribs& rhs)noexcept : + D3DShaderResourceAttribs + { + NamesPool.CopyString(rhs.Name), + rhs.BindPoint, + rhs.BindCount, + rhs.InputType, + rhs.VariableType, + rhs.SRVDimension, + rhs.SamplerId, + rhs.StaticSamplerFlag !=0 ? true : false + } + { + } + D3DShaderResourceAttribs (const D3DShaderResourceAttribs& rhs) = delete; + D3DShaderResourceAttribs ( D3DShaderResourceAttribs&& rhs) = default; // Required for vector<D3DShaderResourceAttribs> + D3DShaderResourceAttribs& operator = (const D3DShaderResourceAttribs& rhs) = delete; + D3DShaderResourceAttribs& operator = ( D3DShaderResourceAttribs&& rhs) = delete; + Uint32 GetSamplerId()const { VERIFY( InputType == D3D_SIT_TEXTURE, "Invalid input type: D3D_SIT_TEXTURE is expected" ); return SamplerId; } - bool GetIsStaticSampler()const + bool IsStaticSampler()const { VERIFY( InputType == D3D_SIT_SAMPLER, "Invalid input type: D3D_SIT_SAMPLER is expected" ); - return IsStaticSampler; + return StaticSamplerFlag != 0; } bool IsValidSampler()const @@ -214,20 +225,21 @@ struct D3DShaderResourceAttribs bool IsCompatibleWith(const D3DShaderResourceAttribs& Attribs)const { - return BindPoint == Attribs.BindPoint && - BindCount == Attribs.BindCount && - InputType == Attribs.InputType && - VariableType == Attribs.VariableType && - SRVDimension == Attribs.SRVDimension && - SamplerId == Attribs.SamplerId && - IsStaticSampler == Attribs.IsStaticSampler; + return BindPoint == Attribs.BindPoint && + BindCount == Attribs.BindCount && + InputType == Attribs.InputType && + VariableType == Attribs.VariableType && + SRVDimension == Attribs.SRVDimension && + SamplerId == Attribs.SamplerId && + StaticSamplerFlag == Attribs.StaticSamplerFlag; } size_t GetHash()const { - return ComputeHash(BindPoint, BindCount, InputType, VariableType, SRVDimension, SamplerId, IsStaticSampler); + return ComputeHash(BindPoint, BindCount, InputType, VariableType, SRVDimension, SamplerId, StaticSamplerFlag); } }; +static_assert(sizeof(D3DShaderResourceAttribs) == sizeof(void*) + sizeof(Uint32)*2, "Unexpected sizeof(D3DShaderResourceAttribs)"); /// Diligent::ShaderResources class @@ -321,7 +333,14 @@ public: size_t GetHash()const; protected: - void Initialize(IMemoryAllocator &Allocator, Uint32 NumCBs, Uint32 NumTexSRVs, Uint32 NumTexUAVs, Uint32 NumBufSRVs, Uint32 NumBufUAVs, Uint32 NumSamplers); + void Initialize(IMemoryAllocator& Allocator, + Uint32 NumCBs, + Uint32 NumTexSRVs, + Uint32 NumTexUAVs, + Uint32 NumBufSRVs, + Uint32 NumBufUAVs, + Uint32 NumSamplers, + size_t ResourceNamesPoolSize); __forceinline D3DShaderResourceAttribs& GetResAttribs(Uint32 n, Uint32 NumResources, Uint32 Offset)noexcept { @@ -351,6 +370,10 @@ private: // | CBs | TexSRVs | TexUAVs | BufSRVs | BufUAVs | Samplers | Resource Names | std::unique_ptr< void, STDDeleterRawMem<void> > m_MemoryBuffer; +protected: + StringPool m_ResourceNames; + +private: // Offsets in elements of D3DShaderResourceAttribs typedef Uint16 OffsetType; OffsetType m_TexSRVOffset = 0; diff --git a/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp b/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp index 85cda16d..d2489ef2 100644 --- a/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp +++ b/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp @@ -51,7 +51,14 @@ ShaderResources::~ShaderResources() GetSampler(n).~D3DShaderResourceAttribs(); } -void ShaderResources::Initialize(IMemoryAllocator &Allocator, Uint32 NumCBs, Uint32 NumTexSRVs, Uint32 NumTexUAVs, Uint32 NumBufSRVs, Uint32 NumBufUAVs, Uint32 NumSamplers) +void ShaderResources::Initialize(IMemoryAllocator& Allocator, + Uint32 NumCBs, + Uint32 NumTexSRVs, + Uint32 NumTexUAVs, + Uint32 NumBufSRVs, + Uint32 NumBufUAVs, + Uint32 NumSamplers, + size_t ResourceNamesPoolSize) { VERIFY( &m_MemoryBuffer.get_deleter().m_Allocator == &Allocator, "Incosistent allocators provided"); @@ -74,7 +81,7 @@ void ShaderResources::Initialize(IMemoryAllocator &Allocator, Uint32 NumCBs, Uin VERIFY(m_SamplersOffset + NumSamplers<= MaxOffset, "Max offset exceeded"); m_TotalResources = m_SamplersOffset + static_cast<OffsetType>(NumSamplers); - auto MemorySize = m_TotalResources * sizeof(D3DShaderResourceAttribs); + auto MemorySize = m_TotalResources * sizeof(D3DShaderResourceAttribs) + ResourceNamesPoolSize * sizeof(char); VERIFY_EXPR(GetNumCBs() == NumCBs); VERIFY_EXPR(GetNumTexSRV() == NumTexSRVs); @@ -87,6 +94,8 @@ void ShaderResources::Initialize(IMemoryAllocator &Allocator, Uint32 NumCBs, Uin { auto *pRawMem = ALLOCATE(Allocator, "Allocator for shader resources", MemorySize ); m_MemoryBuffer.reset(pRawMem); + char* NamesPool = reinterpret_cast<char*>(reinterpret_cast<D3DShaderResourceAttribs*>(pRawMem) + m_TotalResources); + m_ResourceNames.AssignMemory(NamesPool, ResourceNamesPoolSize); } } @@ -154,7 +163,7 @@ Uint32 ShaderResources::FindAssignedSamplerId(const D3DShaderResourceAttribs& Te for (Uint32 s = 0; s < NumSamplers; ++s) { const auto &Sampler = GetSampler(s); - if( StrCmpSuff(Sampler.Name.c_str(), TexSRV.Name.c_str(), D3DSamplerSuffix) ) + if( StrCmpSuff(Sampler.Name, TexSRV.Name, D3DSamplerSuffix) ) { VERIFY(Sampler.VariableType == TexSRV.VariableType, "Inconsistent texture and sampler variable types"); VERIFY(Sampler.BindCount == TexSRV.BindCount || Sampler.BindCount == 1, "Sampler assigned to array \"", TexSRV.Name, "\" is expected to be scalar or have the same dimension (",TexSRV.BindCount,"). Actual sampler array dimension : ", Sampler.BindCount); |
