From ef42c5459abd4f0d7e438f90adcad8577c1a686e Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Mon, 18 Jun 2018 21:06:44 -0700 Subject: Cleaned D3D Shader Resource implementation --- .../src/ShaderResourceLayoutD3D11.cpp | 34 +-- .../src/ShaderResourcesD3D11.cpp | 4 +- Graphics/GraphicsEngineD3D12/src/RootSignature.cpp | 4 +- .../src/ShaderResourceLayoutD3D12.cpp | 80 +++---- .../include/D3DShaderResourceLoader.h | 10 +- .../include/ShaderResources.h | 244 ++++++++------------- .../GraphicsEngineD3DBase/src/ShaderResources.cpp | 14 +- 7 files changed, 170 insertions(+), 220 deletions(-) (limited to 'Graphics') diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderResourceLayoutD3D11.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderResourceLayoutD3D11.cpp index bc952619..db1d9c4b 100644 --- a/Graphics/GraphicsEngineD3D11/src/ShaderResourceLayoutD3D11.cpp +++ b/Graphics/GraphicsEngineD3D11/src/ShaderResourceLayoutD3D11.cpp @@ -145,7 +145,7 @@ void ShaderResourceLayoutD3D11::Initialize(const std::shared_ptr(CB.BindPoint + CB.BindCount)); @@ -153,7 +153,7 @@ void ShaderResourceLayoutD3D11::Initialize(const std::shared_ptrGetSamplerCount() && SamplerSlot < DstCache.GetSamplerCount() ); DstSamplers[SamplerSlot] = CachedSamplers[SamplerSlot]; @@ -385,12 +385,12 @@ void ShaderResourceLayoutD3D11::ConstBuffBindInfo::BindResource(IDeviceObject *p } #ifdef VERIFY_SHADER_BINDINGS - if( Attribs.GetVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC) + if( Attribs.VariableType != SHADER_VARIABLE_TYPE_DYNAMIC) { auto &CachedCB = pResourceCache->GetCB(Attribs.BindPoint + ArrayIndex); if( CachedCB.pBuff != nullptr && CachedCB.pBuff != pBuffD3D11Impl) { - auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.GetVariableType()); + auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.VariableType); LOG_ERROR_MESSAGE( "Non-null constant buffer is already bound to ", VarTypeStr, " shader variable \"", Attribs.GetPrintName(ArrayIndex), "\" in shader \"", m_ParentResLayout.GetShaderName(), "\". Attempting to bind another resource or null is an error and may cause unpredicted behavior. Use another shader resource binding instance or mark shader variable as dynamic." ); } } @@ -454,12 +454,12 @@ void ShaderResourceLayoutD3D11::TexAndSamplerBindInfo::BindResource( IDeviceObje if(pViewD3D11 && !dbgVerifyViewType("texture view", pViewD3D11.RawPtr(), Attribs, ArrayIndex, TEXTURE_VIEW_SHADER_RESOURCE, m_ParentResLayout.GetShaderName())) pViewD3D11.Release(); - if( Attribs.GetVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC) + if( Attribs.VariableType != SHADER_VARIABLE_TYPE_DYNAMIC) { auto &CachedSRV = pResourceCache->GetSRV(Attribs.BindPoint + ArrayIndex); if( CachedSRV.pView != nullptr && CachedSRV.pView != pViewD3D11) { - auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.GetVariableType()); + auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.VariableType); LOG_ERROR_MESSAGE( "Non-null texture SRV is already bound to ", VarTypeStr, " shader variable \"", Attribs.GetPrintName(ArrayIndex), "\" in shader \"", m_ParentResLayout.GetShaderName(), "\". Attempting to bind another resource or null is an error and may cause unpredicted behavior. Use another shader resource binding instance or mark shader variable as dynamic." ); } } @@ -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.IsStaticSampler() ) + if( !SamplerAttribs.GetIsStaticSampler() ) { SamplerD3D11Impl *pSamplerD3D11Impl = nullptr; if( pViewD3D11 ) @@ -515,12 +515,12 @@ void ShaderResourceLayoutD3D11::BuffSRVBindInfo::BindResource( IDeviceObject *pV if(pViewD3D11 && !dbgVerifyViewType("buffer view", pViewD3D11.RawPtr(), Attribs, ArrayIndex, BUFFER_VIEW_SHADER_RESOURCE, m_ParentResLayout.GetShaderName())) pViewD3D11.Release(); - if( Attribs.GetVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC) + if( Attribs.VariableType != SHADER_VARIABLE_TYPE_DYNAMIC) { auto &CachedSRV = pResourceCache->GetSRV(Attribs.BindPoint + ArrayIndex); if( CachedSRV.pView != nullptr && CachedSRV.pView != pViewD3D11) { - auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.GetVariableType()); + auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.VariableType); LOG_ERROR_MESSAGE( "Non-null buffer SRV is already bound to ", VarTypeStr, " shader variable \"", Attribs.GetPrintName(ArrayIndex), "\" in shader \"", m_ParentResLayout.GetShaderName(), "\". Attempting to bind another resource or null is an error and may cause unpredicted behavior. Use another shader resource binding instance or mark shader variable as dynamic." ); } } @@ -546,12 +546,12 @@ void ShaderResourceLayoutD3D11::TexUAVBindInfo::BindResource( IDeviceObject *pVi if(pViewD3D11 && !dbgVerifyViewType("texture view", pViewD3D11.RawPtr(), Attribs, ArrayIndex, TEXTURE_VIEW_UNORDERED_ACCESS, m_ParentResLayout.GetShaderName())) pViewD3D11.Release(); - if( Attribs.GetVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC) + if( Attribs.VariableType != SHADER_VARIABLE_TYPE_DYNAMIC) { auto &CachedUAV = pResourceCache->GetUAV(Attribs.BindPoint + ArrayIndex); if( CachedUAV.pView != nullptr && CachedUAV.pView != pViewD3D11) { - auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.GetVariableType()); + auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.VariableType); LOG_ERROR_MESSAGE( "Non-null texture UAV is already bound to ", VarTypeStr, " shader variable \"", Attribs.GetPrintName(ArrayIndex), "\" in shader \"", m_ParentResLayout.GetShaderName(), "\". Attempting to bind another resource or null is an error and may cause unpredicted behavior. Use another shader resource binding instance or mark shader variable as dynamic." ); } } @@ -577,12 +577,12 @@ void ShaderResourceLayoutD3D11::BuffUAVBindInfo::BindResource( IDeviceObject *pV if(pViewD3D11 && !dbgVerifyViewType("buffer view", pViewD3D11.RawPtr(), Attribs, ArrayIndex, BUFFER_VIEW_UNORDERED_ACCESS, m_ParentResLayout.GetShaderName()) ) pViewD3D11.Release(); - if( Attribs.GetVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC) + if( Attribs.VariableType != SHADER_VARIABLE_TYPE_DYNAMIC) { auto &CachedUAV = pResourceCache->GetUAV(Attribs.BindPoint + ArrayIndex); if( CachedUAV.pView != nullptr && CachedUAV.pView != pViewD3D11) { - auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.GetVariableType()); + auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.VariableType); LOG_ERROR_MESSAGE( "Non-null buffer UAV is already bound to ", VarTypeStr, " shader variable \"", Attribs.GetPrintName(ArrayIndex), "\" in shader \"", m_ParentResLayout.GetShaderName(), "\". Attempting to bind another resource or null is an error and may cause unpredicted behavior. Use another shader resource binding instance or mark shader variable as dynamic." ); } } diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderResourcesD3D11.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderResourcesD3D11.cpp index ffc3a963..1fec3454 100644 --- a/Graphics/GraphicsEngineD3D11/src/ShaderResourcesD3D11.cpp +++ b/Graphics/GraphicsEngineD3D11/src/ShaderResourcesD3D11.cpp @@ -84,7 +84,7 @@ ShaderResourcesD3D11::ShaderResourcesD3D11(RenderDeviceD3D11Impl *pDeviceD3D11Im { VERIFY( SamplerAttribs.BindPoint + SamplerAttribs.BindCount-1 <= MaxAllowedBindPoint, "Sampler bind point exceeds supported range" ); m_MaxSamplerBindPoint = std::max(m_MaxSamplerBindPoint, static_cast(SamplerAttribs.BindPoint + SamplerAttribs.BindCount-1)); - m_NumStaticSamplers += SamplerAttribs.IsStaticSampler() ? 1 : 0; + m_NumStaticSamplers += SamplerAttribs.GetIsStaticSampler() ? 1 : 0; new (&GetSampler(CurrSampler++)) D3DShaderResourceAttribs( std::move(SamplerAttribs) ); }, @@ -124,7 +124,7 @@ ShaderResourcesD3D11::ShaderResourcesD3D11(RenderDeviceD3D11Impl *pDeviceD3D11Im for (Uint32 s = 0; s < GetNumSamplers(); ++s) { const auto &Sam = GetSampler(s); - if (Sam.IsStaticSampler()) + if (Sam.GetIsStaticSampler()) { Uint32 ssd = 0; for (; ssd < ShdrDesc.NumStaticSamplers; ++ssd) diff --git a/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp b/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp index dbe18717..070c3c4e 100644 --- a/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp +++ b/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp @@ -292,12 +292,12 @@ void RootSignature::AllocateResourceSlot(SHADER_TYPE ShaderType, OffsetFromTableStart = 0; // Add new root view to existing root parameters - m_RootParams.AddRootView(D3D12_ROOT_PARAMETER_TYPE_CBV, RootIndex, ShaderResAttribs.BindPoint, ShaderVisibility, ShaderResAttribs.GetVariableType()); + m_RootParams.AddRootView(D3D12_ROOT_PARAMETER_TYPE_CBV, RootIndex, ShaderResAttribs.BindPoint, ShaderVisibility, ShaderResAttribs.VariableType); } else { // Use the same table for static and mutable resources. Treat both as static - auto RootTableType = (ShaderResAttribs.GetVariableType() == SHADER_VARIABLE_TYPE_DYNAMIC) ? SHADER_VARIABLE_TYPE_DYNAMIC : SHADER_VARIABLE_TYPE_STATIC; + auto RootTableType = (ShaderResAttribs.VariableType == SHADER_VARIABLE_TYPE_DYNAMIC) ? SHADER_VARIABLE_TYPE_DYNAMIC : SHADER_VARIABLE_TYPE_STATIC; auto TableIndKey = ShaderInd * SHADER_VARIABLE_TYPE_NUM_TYPES + RootTableType; // Get the table array index (this is not the root index!) auto &RootTableArrayInd = (( RangeType == D3D12_DESCRIPTOR_RANGE_TYPE_SAMPLER ) ? m_SamplerRootTablesMap : m_SrvCbvUavRootTablesMap)[ TableIndKey ]; diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp index 4cd3a639..367ff074 100644 --- a/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp +++ b/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp @@ -143,8 +143,8 @@ ShaderResourceLayoutD3D12::ShaderResourceLayoutD3D12(IObject &Owner, if (SrcRes.IsValidSampler()) { const auto &SrcSamplerAttribs = SrcLayout.GetSampler(VarType, SrcRes.GetSamplerId()); - VERIFY(!SrcSamplerAttribs.Attribs.IsStaticSampler(), "Only non-static samplers can be assigned space in shader cache"); - VERIFY(SrcSamplerAttribs.Attribs.GetVariableType() == SrcRes.Attribs.GetVariableType(), "Inconsistent texture and sampler variable types" ); + VERIFY(!SrcSamplerAttribs.Attribs.GetIsStaticSampler(), "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"); VERIFY_EXPR(SrcSamplerAttribs.Attribs.BindCount == SrcRes.Attribs.BindCount || SrcSamplerAttribs.Attribs.BindCount == 1); @@ -194,20 +194,20 @@ void ShaderResourceLayoutD3D12::Initialize(ID3D12Device *pd3d12Device, [&](const D3DShaderResourceAttribs &CB, Uint32) { - VERIFY_EXPR(IsAllowedType(CB.GetVariableType(), AllowedTypeBits)); - ++m_NumCbvSrvUav[CB.GetVariableType()]; + VERIFY_EXPR(IsAllowedType(CB.VariableType, AllowedTypeBits)); + ++m_NumCbvSrvUav[CB.VariableType]; }, [&](const D3DShaderResourceAttribs& TexSRV, Uint32) { - auto VarType = TexSRV.GetVariableType(); + auto VarType = TexSRV.VariableType; VERIFY_EXPR(IsAllowedType(VarType, AllowedTypeBits)); ++m_NumCbvSrvUav[VarType]; if(TexSRV.IsValidSampler()) { auto SamplerId = TexSRV.GetSamplerId(); const auto &SamplerAttribs = m_pResources->GetSampler(SamplerId); - VERIFY(SamplerAttribs.GetVariableType() == VarType, "Texture and sampler variable types are not conistent"); - if(!SamplerAttribs.IsStaticSampler()) + VERIFY(SamplerAttribs.VariableType == VarType, "Texture and sampler variable types are not conistent"); + if(!SamplerAttribs.GetIsStaticSampler()) { ++m_NumSamplers[VarType]; } @@ -215,18 +215,18 @@ void ShaderResourceLayoutD3D12::Initialize(ID3D12Device *pd3d12Device, }, [&](const D3DShaderResourceAttribs &TexUAV, Uint32) { - VERIFY_EXPR(IsAllowedType(TexUAV.GetVariableType(), AllowedTypeBits)); - ++m_NumCbvSrvUav[TexUAV.GetVariableType()]; + VERIFY_EXPR(IsAllowedType(TexUAV.VariableType, AllowedTypeBits)); + ++m_NumCbvSrvUav[TexUAV.VariableType]; }, [&](const D3DShaderResourceAttribs &BufSRV, Uint32) { - VERIFY_EXPR(IsAllowedType(BufSRV.GetVariableType(), AllowedTypeBits)); - ++m_NumCbvSrvUav[BufSRV.GetVariableType()]; + VERIFY_EXPR(IsAllowedType(BufSRV.VariableType, AllowedTypeBits)); + ++m_NumCbvSrvUav[BufSRV.VariableType]; }, [&](const D3DShaderResourceAttribs &BufUAV, Uint32) { - VERIFY_EXPR(IsAllowedType(BufUAV.GetVariableType(), AllowedTypeBits)); - ++m_NumCbvSrvUav[BufUAV.GetVariableType()]; + VERIFY_EXPR(IsAllowedType(BufUAV.VariableType, AllowedTypeBits)); + ++m_NumCbvSrvUav[BufUAV.VariableType]; } ); @@ -269,7 +269,7 @@ void ShaderResourceLayoutD3D12::Initialize(ID3D12Device *pd3d12Device, VERIFY(Offset != SRV_CBV_UAV::InvalidOffset, "Offset must be valid"); // Static samplers are never copied, and SamplerId == InvalidSamplerId - ::new (&GetSrvCbvUav(Attribs.GetVariableType(), CurrCbvSrvUav[Attribs.GetVariableType()]++)) SRV_CBV_UAV( *this, Attribs, ResType, RootIndex, Offset, SamplerId); + ::new (&GetSrvCbvUav(Attribs.VariableType, CurrCbvSrvUav[Attribs.VariableType]++)) SRV_CBV_UAV( *this, Attribs, ResType, RootIndex, Offset, SamplerId); }; @@ -279,21 +279,21 @@ void ShaderResourceLayoutD3D12::Initialize(ID3D12Device *pd3d12Device, [&](const D3DShaderResourceAttribs &CB, Uint32) { - VERIFY_EXPR( IsAllowedType(CB.GetVariableType(), AllowedTypeBits) ); + VERIFY_EXPR( IsAllowedType(CB.VariableType, AllowedTypeBits) ); AddResource(CB, CachedResourceType::CBV); }, [&](const D3DShaderResourceAttribs& TexSRV, Uint32) { - auto VarType = TexSRV.GetVariableType(); + auto VarType = TexSRV.VariableType; VERIFY_EXPR(IsAllowedType(VarType, AllowedTypeBits) ); Uint32 SamplerId = SRV_CBV_UAV::InvalidSamplerId; if(TexSRV.IsValidSampler()) { const auto &SrcSamplerAttribs = m_pResources->GetSampler(TexSRV.GetSamplerId()); - VERIFY(SrcSamplerAttribs.GetVariableType() == VarType, "Inconsistent texture and sampler variable types" ); + VERIFY(SrcSamplerAttribs.VariableType == VarType, "Inconsistent texture and sampler variable types" ); - if (SrcSamplerAttribs.IsStaticSampler()) + if (SrcSamplerAttribs.GetIsStaticSampler()) { if(pRootSig != nullptr) pRootSig->InitStaticSampler(m_pResources->GetShaderType(), TexSRV.Name, SrcSamplerAttribs); @@ -337,17 +337,17 @@ void ShaderResourceLayoutD3D12::Initialize(ID3D12Device *pd3d12Device, }, [&](const D3DShaderResourceAttribs &TexUAV, Uint32) { - VERIFY_EXPR( IsAllowedType(TexUAV.GetVariableType(), AllowedTypeBits) ); + VERIFY_EXPR( IsAllowedType(TexUAV.VariableType, AllowedTypeBits) ); AddResource(TexUAV, CachedResourceType::TexUAV); }, [&](const D3DShaderResourceAttribs &BufSRV, Uint32) { - VERIFY_EXPR( IsAllowedType(BufSRV.GetVariableType(), AllowedTypeBits) ); + VERIFY_EXPR( IsAllowedType(BufSRV.VariableType, AllowedTypeBits) ); AddResource(BufSRV, CachedResourceType::BufSRV); }, [&](const D3DShaderResourceAttribs &BufUAV, Uint32) { - VERIFY_EXPR( IsAllowedType(BufUAV.GetVariableType(), AllowedTypeBits) ); + VERIFY_EXPR( IsAllowedType(BufUAV.VariableType, AllowedTypeBits) ); AddResource(BufUAV, CachedResourceType::BufUAV); } ); @@ -413,11 +413,11 @@ void ShaderResourceLayoutD3D12::SRV_CBV_UAV::CacheCB(IDeviceObject *pBuffer, Sha { if( pBuffD3D12->GetDesc().BindFlags & BIND_UNIFORM_BUFFER ) { - if( Attribs.GetVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC && DstRes.pObject != nullptr ) + if( Attribs.VariableType != SHADER_VARIABLE_TYPE_DYNAMIC && DstRes.pObject != nullptr ) { if(DstRes.pObject != pBuffD3D12) { - auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.GetVariableType()); + auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.VariableType); LOG_ERROR_MESSAGE( "Non-null constant buffer is already bound to ", VarTypeStr, " shader variable \"", Attribs.GetPrintName(ArrayInd), "\" in shader \"", m_ParentResLayout.GetShaderName(), "\". Attempring to bind another constant buffer is an error and will be ignored. Use another shader resource binding instance or mark shader variable as dynamic." ); } @@ -502,11 +502,11 @@ void ShaderResourceLayoutD3D12::SRV_CBV_UAV::CacheResourceView(IDeviceObject *pV return; } #endif - if( Attribs.GetVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC && DstRes.pObject != nullptr ) + if( Attribs.VariableType != SHADER_VARIABLE_TYPE_DYNAMIC && DstRes.pObject != nullptr ) { if(DstRes.pObject != pViewD3D12) { - auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.GetVariableType()); + auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.VariableType); LOG_ERROR_MESSAGE( "Non-null resource is already bound to ", VarTypeStr, " shader variable \"", Attribs.GetPrintName(ArrayIndex), "\" in shader \"", m_ParentResLayout.GetShaderName(), "\". Attempting to bind another resource or null is an error and will be ignored. Use another shader resource binding instance or mark shader variable as dynamic." ); } @@ -555,7 +555,7 @@ void ShaderResourceLayoutD3D12::Sampler::CacheSampler(ITextureViewD3D12 *pTexVie } else if (pResourceCache->DbgGetContentType() == ShaderResourceCacheD3D12::DbgCacheContentType::SRBResources) { - if(Attribs.GetVariableType() == SHADER_VARIABLE_TYPE_DYNAMIC) + if(Attribs.VariableType == SHADER_VARIABLE_TYPE_DYNAMIC) VERIFY(ShdrVisibleHeapCPUDescriptorHandle.ptr == 0, "Dynamic resources of a shader resource binding should be assigned shader visible descriptor space at every draw call"); else VERIFY(ShdrVisibleHeapCPUDescriptorHandle.ptr != 0 || pTexViewD3D12 == nullptr, "Non-dynamics resources of a shader resource binding must be assigned shader visible descriptor space"); @@ -572,11 +572,11 @@ void ShaderResourceLayoutD3D12::Sampler::CacheSampler(ITextureViewD3D12 *pTexVie auto pSampler = pTexViewD3D12->GetSampler(); if( pSampler ) { - if( Attribs.GetVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC && DstSam.pObject != nullptr) + if( Attribs.VariableType != SHADER_VARIABLE_TYPE_DYNAMIC && DstSam.pObject != nullptr) { if(DstSam.pObject != pSampler) { - auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.GetVariableType()); + auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.VariableType); LOG_ERROR_MESSAGE( "Non-null sampler is already bound to ", VarTypeStr, " shader variable \"", Attribs.GetPrintName(ArrayIndex), "\" in shader \"", m_ParentResLayout.GetShaderName(), "\". Attempting to bind another sampler is an error and will be ignored. Use another shader resource binding instance or mark shader variable as dynamic." ); } @@ -619,8 +619,8 @@ ShaderResourceLayoutD3D12::Sampler &ShaderResourceLayoutD3D12::GetAssignedSample { VERIFY(TexSrv.GetResType() == CachedResourceType::TexSRV, "Unexpected resource type: texture SRV is expected"); VERIFY(TexSrv.IsValidSampler(), "Texture SRV has no associated sampler"); - auto &SamInfo = GetSampler(TexSrv.Attribs.GetVariableType(), TexSrv.GetSamplerId()); - VERIFY(SamInfo.Attribs.GetVariableType() == TexSrv.Attribs.GetVariableType(), "Inconsistent texture and sampler variable types"); + 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, '\"'); return SamInfo; } @@ -650,7 +650,7 @@ void ShaderResourceLayoutD3D12::SRV_CBV_UAV::BindResource(IDeviceObject *pObj, U } else { - if(Attribs.GetVariableType() == SHADER_VARIABLE_TYPE_DYNAMIC) + if(Attribs.VariableType == SHADER_VARIABLE_TYPE_DYNAMIC) VERIFY(ShdrVisibleHeapCPUDescriptorHandle.ptr == 0, "Dynamic resources of a shader resource binding should be assigned shader visible descriptor space at every draw call"); else VERIFY(ShdrVisibleHeapCPUDescriptorHandle.ptr != 0, "Non-dynamics resources of a shader resource binding must be assigned shader visible descriptor space"); @@ -677,7 +677,7 @@ void ShaderResourceLayoutD3D12::SRV_CBV_UAV::BindResource(IDeviceObject *pObj, U if(IsValidSampler()) { auto &Sam = m_ParentResLayout.GetAssignedSampler(*this); - VERIFY( !Sam.Attribs.IsStaticSampler(), "Static samplers should never be assigned space in the cache" ); + VERIFY( !Sam.Attribs.GetIsStaticSampler(), "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); @@ -703,7 +703,7 @@ void ShaderResourceLayoutD3D12::SRV_CBV_UAV::BindResource(IDeviceObject *pObj, U } else { - if (DstRes.pObject && Attribs.GetVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC) + if (DstRes.pObject && Attribs.VariableType != SHADER_VARIABLE_TYPE_DYNAMIC) { LOG_ERROR_MESSAGE( "Shader variable \"", Attribs.Name, "\" in shader \"", m_ParentResLayout.GetShaderName(), "\" is not dynamic but being unbound. This is an error and may cause unpredicted behavior. Use another shader resource binding instance or mark shader variable as dynamic if you need to bind another resource." ); } @@ -885,7 +885,7 @@ void ShaderResourceLayoutD3D12::CopyStaticResourceDesriptorHandles(const ShaderR { auto &SamInfo = GetAssignedSampler(res); - VERIFY(!SamInfo.Attribs.IsStaticSampler(), "Static samplers should never be assigned space in the cache"); + VERIFY(!SamInfo.Attribs.GetIsStaticSampler(), "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); @@ -937,7 +937,7 @@ void ShaderResourceLayoutD3D12::dbgVerifyBindings()const for(Uint32 r=0; r < m_NumCbvSrvUav[VarType]; ++r) { const auto &res = GetSrvCbvUav(VarType, r); - VERIFY(res.Attribs.GetVariableType() == VarType, "Unexpected variable type"); + VERIFY(res.Attribs.VariableType == VarType, "Unexpected variable type"); for(Uint32 ArrInd = 0; ArrInd < res.Attribs.BindCount; ++ArrInd) { @@ -950,7 +950,7 @@ void ShaderResourceLayoutD3D12::dbgVerifyBindings()const if( !CachedRes.pObject || // Dynamic buffers do not have CPU descriptor handle as they do not keep D3D12 buffer, and space is allocated from the GPU ring buffer CachedRes.CPUDescriptorHandle.ptr == 0 && !(CachedRes.Type==CachedResourceType::CBV && CachedRes.pObject.RawPtr()->GetDesc().Usage == USAGE_DYNAMIC) ) - LOG_ERROR_MESSAGE( "No resource is bound to ", GetShaderVariableTypeLiteralName(res.Attribs.GetVariableType()), " variable \"", res.Attribs.GetPrintName(ArrInd), "\" in shader \"", GetShaderName(), "\"" ); + LOG_ERROR_MESSAGE( "No resource is bound to ", GetShaderVariableTypeLiteralName(res.Attribs.VariableType), " variable \"", res.Attribs.GetPrintName(ArrInd), "\" in shader \"", GetShaderName(), "\"" ); if (res.Attribs.BindCount > 1 && res.IsValidSampler()) { @@ -983,7 +983,7 @@ void ShaderResourceLayoutD3D12::dbgVerifyBindings()const } else { - if(res.Attribs.GetVariableType() == SHADER_VARIABLE_TYPE_DYNAMIC) + if(res.Attribs.VariableType == SHADER_VARIABLE_TYPE_DYNAMIC) VERIFY(ShdrVisibleHeapCPUDescriptorHandle.ptr == 0, "Dynamic resources of a shader resource binding should be assigned shader visible descriptor space at every draw call"); else VERIFY(ShdrVisibleHeapCPUDescriptorHandle.ptr != 0, "Non-dynamics resources of a shader resource binding must be assigned shader visible descriptor space"); @@ -1001,7 +1001,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.IsStaticSampler(), "Static samplers should never be assigned space in the cache" ); + VERIFY( !SamInfo.Attribs.GetIsStaticSampler(), "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) @@ -1023,7 +1023,7 @@ void ShaderResourceLayoutD3D12::dbgVerifyBindings()const } else if (m_pResourceCache->DbgGetContentType() == ShaderResourceCacheD3D12::DbgCacheContentType::SRBResources) { - if(SamInfo.Attribs.GetVariableType() == SHADER_VARIABLE_TYPE_DYNAMIC) + if(SamInfo.Attribs.VariableType == SHADER_VARIABLE_TYPE_DYNAMIC) VERIFY(ShdrVisibleHeapCPUDescriptorHandle.ptr == 0, "Dynamic resources of a shader resource binding should be assigned shader visible descriptor space at every draw call"); else VERIFY(ShdrVisibleHeapCPUDescriptorHandle.ptr != 0, "Non-dynamics resources of a shader resource binding must be assigned shader visible descriptor space"); @@ -1041,7 +1041,7 @@ void ShaderResourceLayoutD3D12::dbgVerifyBindings()const for(Uint32 s=0; s < m_NumSamplers[VarType]; ++s) { const auto &sam = GetSampler(VarType, s); - VERIFY(sam.Attribs.GetVariableType() == VarType, "Unexpected sampler variable type"); + VERIFY(sam.Attribs.VariableType == VarType, "Unexpected sampler variable type"); for(Uint32 ArrInd = 0; ArrInd < sam.Attribs.BindCount; ++ArrInd) { diff --git a/Graphics/GraphicsEngineD3DBase/include/D3DShaderResourceLoader.h b/Graphics/GraphicsEngineD3DBase/include/D3DShaderResourceLoader.h index cb3650bb..937d6b30 100644 --- a/Graphics/GraphicsEngineD3DBase/include/D3DShaderResourceLoader.h +++ b/Graphics/GraphicsEngineD3DBase/include/D3DShaderResourceLoader.h @@ -196,7 +196,7 @@ namespace Diligent for (const auto& Res : Resources) { // Skip samplers as they are not handled as independent variables - if (Res.GetInputType() != D3D_SIT_SAMPLER && Res.Name.compare(VarName) == 0) + if (Res.InputType != D3D_SIT_SAMPLER && Res.Name.compare(VarName) == 0) { VariableFound = true; break; @@ -215,7 +215,7 @@ namespace Diligent for (const auto& Res : Resources) { - if ( Res.GetInputType() == D3D_SIT_TEXTURE && Res.GetSRVDimension() != D3D_SRV_DIMENSION_BUFFER && Res.Name.compare(TexName) == 0) + if ( Res.InputType == D3D_SIT_TEXTURE && Res.SRVDimension != D3D_SRV_DIMENSION_BUFFER && Res.Name.compare(TexName) == 0) { TextureFound = true; break; @@ -236,7 +236,7 @@ namespace Diligent for(auto &Res : Resources) { - switch( Res.GetInputType() ) + switch( Res.InputType ) { case D3D_SIT_CBUFFER: { @@ -252,7 +252,7 @@ namespace Diligent case D3D_SIT_TEXTURE: { - if( Res.GetSRVDimension() == D3D_SRV_DIMENSION_BUFFER ) + if( Res.SRVDimension == D3D_SRV_DIMENSION_BUFFER ) { OnNewBuffSRV( std::move(Res) ); } @@ -271,7 +271,7 @@ namespace Diligent case D3D_SIT_UAV_RWTYPED: { - if( Res.GetSRVDimension() == D3D_SRV_DIMENSION_BUFFER ) + if( Res.SRVDimension == D3D_SRV_DIMENSION_BUFFER ) { OnNewBuffUAV( std::move(Res) ); } diff --git a/Graphics/GraphicsEngineD3DBase/include/ShaderResources.h b/Graphics/GraphicsEngineD3DBase/include/ShaderResources.h index c44972f5..04ebeb51 100644 --- a/Graphics/GraphicsEngineD3DBase/include/ShaderResources.h +++ b/Graphics/GraphicsEngineD3DBase/include/ShaderResources.h @@ -84,119 +84,117 @@ inline Uint32 GetAllowedTypeBits(const SHADER_VARIABLE_TYPE *AllowedVarTypes, Ui struct D3DShaderResourceAttribs { - D3DShaderResourceAttribs(String &&_Name, - UINT _BindPoint, - UINT _BindCount, - D3D_SHADER_INPUT_TYPE _InputType, - SHADER_VARIABLE_TYPE _VariableType, - D3D_SRV_DIMENSION SRVDimension, - Uint32 SamplerId, - bool _IsStaticSampler) : + String Name; // Move ctor will not work if it is const + + const Uint16 BindPoint; + const Uint16 BindCount; + + // 4 3 4 20 1 + // 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"); + + 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; + + static constexpr const Uint32 InvalidSamplerId = (1 << SamplerIdBits) - 1; + static constexpr const Uint16 InvalidBindPoint = std::numeric_limits::max(); + static constexpr const Uint16 MaxBindPoint = InvalidBindPoint - 1; + static constexpr const Uint16 MaxBindCount = std::numeric_limits::max(); + + static_assert(D3D_SIT_UAV_RWSTRUCTURED_WITH_COUNTER < (1 << ShaderInputTypeBits), "Not enough bits to represent D3D_SHADER_INPUT_TYPE"); + 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, + UINT _BindPoint, + UINT _BindCount, + D3D_SHADER_INPUT_TYPE _InputType, + SHADER_VARIABLE_TYPE _VariableType, + D3D_SRV_DIMENSION _SRVDimension, + Uint32 _SamplerId, + bool _IsStaticSampler)noexcept : Name(std::move(_Name)), - BindPoint(static_cast(_BindPoint)), - BindCount(static_cast(_BindCount)), - PackedAttribs( PackAttribs(_InputType, _VariableType, SRVDimension, SamplerId, _IsStaticSampler) ) + BindPoint(static_cast(_BindPoint)), + BindCount(static_cast(_BindCount)), + InputType (_InputType), + VariableType (_VariableType), + SRVDimension (_SRVDimension), + SamplerId (_SamplerId), + IsStaticSampler(_IsStaticSampler) { - VERIFY( static_cast(_InputType) <= ShaderInputTypeMask, "Shader input type is out of expected range"); - VERIFY( static_cast(_VariableType) <= VariableTypeMask, "Variable type is out of expected range"); - VERIFY( static_cast(SRVDimension) <= SRVDimMask, "SRV dimensions is out of expected range"); - VERIFY(SamplerId <= SamplerIdMask, "Sampler Id is out of allowed range" ); - VERIFY_EXPR(GetInputType() == _InputType); - VERIFY_EXPR(GetVariableType() == _VariableType); - VERIFY(_BindPoint <= MaxBindPoint || _BindPoint == InvalidBindPoint, "Bind Point is out of allowed range" ); - VERIFY(_BindCount <= MaxBindCount, "Bind Count is out of allowed range" ); + VERIFY(_BindPoint <= MaxBindPoint || _BindPoint == InvalidBindPoint, "Bind Point is out of allowed range"); + VERIFY(_BindCount <= MaxBindCount, "Bind Count is out of allowed range"); + VERIFY(_InputType < (1 << ShaderInputTypeBits), "Shader input type is out of expected range"); + VERIFY(_VariableType < (1 << VariableTypeBits), "Variable type is out of expected range"); + VERIFY(_SRVDimension < (1 << SRVDimBits), "SRV dimensions is out of expected range"); + 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"); - } if (_InputType == D3D_SIT_TEXTURE) - { - VERIFY_EXPR(GetSamplerId() == SamplerId); - } + VERIFY_EXPR(SamplerId == _SamplerId); else - { - VERIFY(SamplerId == InvalidSamplerId, "Only textures can be assigned valid texture sampler"); - } + VERIFY(SamplerId == InvalidSamplerId, "Only textures can be assigned a valid texture sampler"); if(_IsStaticSampler) - { VERIFY( _InputType == D3D_SIT_SAMPLER, "Invalid input type: D3D_SIT_SAMPLER is expected" ); - } #endif } - D3DShaderResourceAttribs(const D3DShaderResourceAttribs& rhs) = default; + D3DShaderResourceAttribs(D3DShaderResourceAttribs&& rhs) = default; + D3DShaderResourceAttribs(const D3DShaderResourceAttribs& rhs) = delete; D3DShaderResourceAttribs(const D3DShaderResourceAttribs& rhs, Uint32 SamplerId)noexcept : - Name(rhs.Name), - BindPoint(rhs.BindPoint), - BindCount(rhs.BindCount), - PackedAttribs( PackAttribs(rhs.GetInputType(), rhs.GetVariableType(), rhs.GetSRVDimension(), SamplerId, false) ) - { - VERIFY(GetInputType() == D3D_SIT_TEXTURE, "Only textures can be assigned a texture sampler"); - - VERIFY_EXPR(GetInputType() == rhs.GetInputType()); - VERIFY_EXPR(GetVariableType() == rhs.GetVariableType()); - VERIFY_EXPR(GetSamplerId() == SamplerId); - } - - D3DShaderResourceAttribs(D3DShaderResourceAttribs&& rhs, Uint32 SamplerId)noexcept : - Name(std::move(rhs.Name)), - BindPoint(rhs.BindPoint), - BindCount(rhs.BindCount), - PackedAttribs( PackAttribs(rhs.GetInputType(), rhs.GetVariableType(), rhs.GetSRVDimension(), SamplerId, false) ) - { - VERIFY(GetInputType() == D3D_SIT_TEXTURE, "Only textures can be assigned a texture sampler"); - - VERIFY_EXPR(GetInputType() == rhs.GetInputType()); - VERIFY_EXPR(GetVariableType() == rhs.GetVariableType()); - VERIFY_EXPR(GetSamplerId() == SamplerId); - } - - D3DShaderResourceAttribs(D3DShaderResourceAttribs&& rhs)noexcept : - Name(std::move(rhs.Name)), - BindPoint(rhs.BindPoint), - BindCount(rhs.BindCount), - PackedAttribs( rhs.PackedAttribs ) - { - } - - D3D_SHADER_INPUT_TYPE GetInputType()const - { - return static_cast( (PackedAttribs >> ShaderInputTypeBitOffset) & ShaderInputTypeMask ); - } - - SHADER_VARIABLE_TYPE GetVariableType()const + D3DShaderResourceAttribs + { + rhs.Name, + rhs.BindPoint, + rhs.BindCount, + rhs.InputType, + rhs.VariableType, + rhs.SRVDimension, + SamplerId, + false + } { - return static_cast( (PackedAttribs >> VariableTypeBitOffset) & VariableTypeMask ); + VERIFY(InputType == D3D_SIT_TEXTURE, "Only textures can be assigned a texture sampler"); } - D3D_SRV_DIMENSION GetSRVDimension()const - { - return static_cast( (PackedAttribs >> SRVDimBitOffset) & SRVDimMask ); - } + //D3DShaderResourceAttribs(D3DShaderResourceAttribs&& rhs)noexcept : + // Name(std::move(rhs.Name)), + // BindPoint(rhs.BindPoint), + // BindCount(rhs.BindCount), + // PackedAttribs( rhs.PackedAttribs ) + //{ + //} Uint32 GetSamplerId()const { - VERIFY( GetInputType() == D3D_SIT_TEXTURE, "Invalid input type: D3D_SIT_TEXTURE is expected" ); - return (PackedAttribs >> SamplerIdBitOffset) & SamplerIdMask; + VERIFY( InputType == D3D_SIT_TEXTURE, "Invalid input type: D3D_SIT_TEXTURE is expected" ); + return SamplerId; } - bool IsStaticSampler()const + bool GetIsStaticSampler()const { - VERIFY( GetInputType() == D3D_SIT_SAMPLER, "Invalid input type: D3D_SIT_SAMPLER is expected" ); - return (PackedAttribs & (1 << IsStaticSamplerFlagBitOffset)) != 0; + VERIFY( InputType == D3D_SIT_SAMPLER, "Invalid input type: D3D_SIT_SAMPLER is expected" ); + return IsStaticSampler; } bool IsValidSampler()const { - VERIFY( GetInputType() == D3D_SIT_TEXTURE, "Invalid input type: D3D_SIT_TEXTURE is expected" ); return GetSamplerId() != InvalidSamplerId; } @@ -205,12 +203,6 @@ struct D3DShaderResourceAttribs return BindPoint != InvalidBindPoint; } - static constexpr Uint16 InvalidBindPoint = std::numeric_limits::max(); - - String Name; // Move ctor will not work if it is const - const Uint16 BindPoint; - const Uint16 BindCount; - String GetPrintName(Uint32 ArrayInd)const { VERIFY_EXPR(ArrayInd < BindCount); @@ -220,63 +212,21 @@ struct D3DShaderResourceAttribs return Name; } - bool IsCompatibleWith(const D3DShaderResourceAttribs& Attibs)const + bool IsCompatibleWith(const D3DShaderResourceAttribs& Attribs)const { - return BindPoint == Attibs.BindPoint && - BindCount == Attibs.BindCount && - PackedAttribs == Attibs.PackedAttribs; + return BindPoint == Attribs.BindPoint && + BindCount == Attribs.BindCount && + InputType == Attribs.InputType && + VariableType == Attribs.VariableType && + SRVDimension == Attribs.SRVDimension && + SamplerId == Attribs.SamplerId && + IsStaticSampler == Attribs.IsStaticSampler; } size_t GetHash()const { - return ComputeHash(BindPoint, BindCount, PackedAttribs); + return ComputeHash(BindPoint, BindCount, InputType, VariableType, SRVDimension, SamplerId, IsStaticSampler); } - -private: - static constexpr Uint16 MaxBindPoint = InvalidBindPoint-1; - static constexpr Uint16 MaxBindCount = std::numeric_limits::max(); - - static constexpr Uint32 ShaderInputTypeBits = 4; // Max value: D3D_SIT_UAV_RWSTRUCTURED_WITH_COUNTER==11 - static constexpr Uint32 ShaderInputTypeMask = (1 << ShaderInputTypeBits)-1; - static constexpr Uint32 ShaderInputTypeBitOffset = 0; - static_assert( D3D_SIT_UAV_RWSTRUCTURED_WITH_COUNTER <= ShaderInputTypeMask, "Not enough bits to represent D3D_SHADER_INPUT_TYPE" ); - - static constexpr Uint32 VariableTypeBits = 3; // Max value: SHADER_VARIABLE_TYPE_DYNAMIC == 2 - static constexpr Uint32 VariableTypeMask = (1<(_InputType) & ShaderInputTypeMask) << ShaderInputTypeBitOffset) | - ((static_cast(_VariableType) & VariableTypeMask) << VariableTypeBitOffset ) | - ((static_cast(SRVDimension) & SRVDimMask) << SRVDimBitOffset) | - ((SamplerId & SamplerIdMask) << SamplerIdBitOffset) | - ((_IsStaticSampler ? 1 : 0) << IsStaticSamplerFlagBitOffset); - } - - // 4 3 4 20 1 - // bit | 0 1 2 3 | 4 5 6 | 7 8 9 10 | 11 12 ... 30 | 31 | - // | | | | | | - // | InputType | VariableType | SRV Dim | SamplerId | StaticSamplerFlag | - const Uint32 PackedAttribs; }; @@ -333,35 +283,35 @@ public: for(Uint32 n=0; n < GetNumCBs(); ++n) { const auto& CB = GetCB(n); - if( IsAllowedType(CB.GetVariableType(), AllowedTypeBits) ) + if( IsAllowedType(CB.VariableType, AllowedTypeBits) ) HandleCB(CB, n); } for(Uint32 n=0; n < GetNumTexSRV(); ++n) { const auto &TexSRV = GetTexSRV(n); - if( IsAllowedType(TexSRV.GetVariableType(), AllowedTypeBits) ) + if( IsAllowedType(TexSRV.VariableType, AllowedTypeBits) ) HandleTexSRV(TexSRV, n); } for(Uint32 n=0; n < GetNumTexUAV(); ++n) { const auto &TexUAV = GetTexUAV(n); - if( IsAllowedType(TexUAV.GetVariableType(), AllowedTypeBits) ) + if( IsAllowedType(TexUAV.VariableType, AllowedTypeBits) ) HandleTexUAV(TexUAV, n); } for(Uint32 n=0; n < GetNumBufSRV(); ++n) { const auto &BufSRV = GetBufSRV(n); - if( IsAllowedType(BufSRV.GetVariableType(), AllowedTypeBits) ) + if( IsAllowedType(BufSRV.VariableType, AllowedTypeBits) ) HandleBufSRV(BufSRV, n); } for(Uint32 n=0; n < GetNumBufUAV(); ++n) { const auto& BufUAV = GetBufUAV(n); - if( IsAllowedType(BufUAV.GetVariableType(), AllowedTypeBits) ) + if( IsAllowedType(BufUAV.VariableType, AllowedTypeBits) ) HandleBufUAV(BufUAV, n); } } @@ -398,9 +348,9 @@ protected: private: // Memory buffer that holds all resources as continuous chunk of memory: - // | CBs | TexSRVs | TexUAVs | BufSRVs | BufUAVs | Samplers | + // | CBs | TexSRVs | TexUAVs | BufSRVs | BufUAVs | Samplers | Resource Names | std::unique_ptr< void, STDDeleterRawMem > m_MemoryBuffer; - + // 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 4abf2673..85cda16d 100644 --- a/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp +++ b/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp @@ -119,28 +119,28 @@ void ShaderResources::CountResources(const SHADER_VARIABLE_TYPE *AllowedVarTypes [&](const D3DShaderResourceAttribs &CB, Uint32) { - VERIFY_EXPR(IsAllowedType(CB.GetVariableType(), AllowedTypeBits)); + VERIFY_EXPR(IsAllowedType(CB.VariableType, AllowedTypeBits)); ++NumCBs; }, [&](const D3DShaderResourceAttribs& TexSRV, Uint32) { - VERIFY_EXPR(IsAllowedType(TexSRV.GetVariableType(), AllowedTypeBits)); + VERIFY_EXPR(IsAllowedType(TexSRV.VariableType, AllowedTypeBits)); ++NumTexSRVs; NumSamplers += TexSRV.IsValidSampler() ? 1 : 0; }, [&](const D3DShaderResourceAttribs &TexUAV, Uint32) { - VERIFY_EXPR(IsAllowedType(TexUAV.GetVariableType(), AllowedTypeBits)); + VERIFY_EXPR(IsAllowedType(TexUAV.VariableType, AllowedTypeBits)); ++NumTexUAVs; }, [&](const D3DShaderResourceAttribs &BufSRV, Uint32) { - VERIFY_EXPR(IsAllowedType(BufSRV.GetVariableType(), AllowedTypeBits)); + VERIFY_EXPR(IsAllowedType(BufSRV.VariableType, AllowedTypeBits)); ++NumBufSRVs; }, [&](const D3DShaderResourceAttribs &BufUAV, Uint32) { - VERIFY_EXPR(IsAllowedType(BufUAV.GetVariableType(), AllowedTypeBits)); + VERIFY_EXPR(IsAllowedType(BufUAV.VariableType, AllowedTypeBits)); ++NumBufUAVs; } ); @@ -149,14 +149,14 @@ void ShaderResources::CountResources(const SHADER_VARIABLE_TYPE *AllowedVarTypes Uint32 ShaderResources::FindAssignedSamplerId(const D3DShaderResourceAttribs& TexSRV)const { - VERIFY_EXPR(TexSRV.GetInputType() == D3D_SIT_TEXTURE); + VERIFY_EXPR(TexSRV.InputType == D3D_SIT_TEXTURE); auto NumSamplers = GetNumSamplers(); for (Uint32 s = 0; s < NumSamplers; ++s) { const auto &Sampler = GetSampler(s); if( StrCmpSuff(Sampler.Name.c_str(), TexSRV.Name.c_str(), D3DSamplerSuffix) ) { - VERIFY(Sampler.GetVariableType() == TexSRV.GetVariableType(), "Inconsistent texture and sampler variable types"); + 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); return s; } -- cgit v1.2.3