From f345a63c047c7760cb5c5fe70f72a075b4f3a7df Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Tue, 19 Jun 2018 08:52:15 -0700 Subject: Implemented resource names string pool for D3D backends --- .../src/ShaderResourceLayoutD3D12.cpp | 21 ++++++++-------- .../src/ShaderResourcesD3D12.cpp | 29 +++++++++++----------- 2 files changed, 25 insertions(+), 25 deletions(-) (limited to 'Graphics/GraphicsEngineD3D12') 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(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 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(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( 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" ); -- cgit v1.2.3