summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineD3D11
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2018-06-19 15:52:15 +0000
committerEgor Yusov <egor.yusov@gmail.com>2018-06-19 15:52:15 +0000
commitf345a63c047c7760cb5c5fe70f72a075b4f3a7df (patch)
tree95d9ec41ff14a8b52326e9f80c807365b767c05a /Graphics/GraphicsEngineD3D11
parentCleaned D3D Shader Resource implementation (diff)
downloadDiligentCore-f345a63c047c7760cb5c5fe70f72a075b4f3a7df.tar.gz
DiligentCore-f345a63c047c7760cb5c5fe70f72a075b4f3a7df.zip
Implemented resource names string pool for D3D backends
Diffstat (limited to 'Graphics/GraphicsEngineD3D11')
-rw-r--r--Graphics/GraphicsEngineD3D11/src/ShaderResourceLayoutD3D11.cpp32
-rw-r--r--Graphics/GraphicsEngineD3D11/src/ShaderResourcesD3D11.cpp35
2 files changed, 34 insertions, 33 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;