From c2a6a2c4b716d45ddc92ed04bb0ac7fb7200e548 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Thu, 18 Oct 2018 08:38:21 -0700 Subject: Implemented separate samplers in D3D12 --- .../include/ShaderResourceLayoutD3D11.h | 12 +++++----- .../src/ShaderResourceLayoutD3D11.cpp | 28 ++++++++++++---------- .../src/ShaderResourcesD3D11.cpp | 2 +- 3 files changed, 23 insertions(+), 19 deletions(-) (limited to 'Graphics/GraphicsEngineD3D11') diff --git a/Graphics/GraphicsEngineD3D11/include/ShaderResourceLayoutD3D11.h b/Graphics/GraphicsEngineD3D11/include/ShaderResourceLayoutD3D11.h index 24284cec..274c0e28 100644 --- a/Graphics/GraphicsEngineD3D11/include/ShaderResourceLayoutD3D11.h +++ b/Graphics/GraphicsEngineD3D11/include/ShaderResourceLayoutD3D11.h @@ -250,7 +250,7 @@ private: const ConstBuffBindInfo& GetCB(Uint32 cb)const { VERIFY_EXPR(cb(m_ResourceBuffer.get())[cb]; + return reinterpret_cast(m_ResourceBuffer.get())[cb]; } TexSRVBindInfo& GetTexSRV(Uint32 t) @@ -261,7 +261,7 @@ private: const TexSRVBindInfo& GetTexSRV(Uint32 t)const { VERIFY_EXPR(t( reinterpret_cast(m_ResourceBuffer.get()) + m_TexSRVsOffset)[t]; + return reinterpret_cast( reinterpret_cast(m_ResourceBuffer.get()) + m_TexSRVsOffset)[t]; } TexUAVBindInfo& GetTexUAV(Uint32 u) @@ -272,7 +272,7 @@ private: const TexUAVBindInfo& GetTexUAV(Uint32 u)const { VERIFY_EXPR(u < m_NumTexUAVs); - return reinterpret_cast( reinterpret_cast(m_ResourceBuffer.get()) + m_TexUAVsOffset)[u]; + return reinterpret_cast( reinterpret_cast(m_ResourceBuffer.get()) + m_TexUAVsOffset)[u]; } BuffUAVBindInfo& GetBufUAV(Uint32 u) @@ -283,7 +283,7 @@ private: const BuffUAVBindInfo& GetBufUAV(Uint32 u)const { VERIFY_EXPR(u < m_NumBufUAVs); - return reinterpret_cast( reinterpret_cast(m_ResourceBuffer.get()) + m_BuffUAVsOffset)[u]; + return reinterpret_cast( reinterpret_cast(m_ResourceBuffer.get()) + m_BuffUAVsOffset)[u]; } BuffSRVBindInfo& GetBufSRV(Uint32 s) @@ -294,7 +294,7 @@ private: const BuffSRVBindInfo& GetBufSRV(Uint32 s)const { VERIFY_EXPR(s < m_NumBufSRVs); - return reinterpret_cast( reinterpret_cast(m_ResourceBuffer.get()) + m_BuffSRVsOffset)[s]; + return reinterpret_cast( reinterpret_cast(m_ResourceBuffer.get()) + m_BuffSRVsOffset)[s]; } SamplerBindInfo& GetSampler(Uint32 s) @@ -305,7 +305,7 @@ private: const SamplerBindInfo& GetSampler(Uint32 s)const { VERIFY_EXPR(s < m_NumSamplers); - return reinterpret_cast( reinterpret_cast(m_ResourceBuffer.get()) + m_SamplerOffset)[s]; + return reinterpret_cast( reinterpret_cast(m_ResourceBuffer.get()) + m_SamplerOffset)[s]; } templateGetSampler(TexSRV.GetSamplerId()); + DEV_CHECK_ERR(AssignedSamplerAttribs.GetVariableType() == TexSRV.GetVariableType(), + "The type (", GetShaderVariableTypeLiteralName(TexSRV.GetVariableType()),") of texture SRV variable '", TexSRV.Name, + "' is not consistent with the type (", GetShaderVariableTypeLiteralName(AssignedSamplerAttribs.GetVariableType()), + ") of the sampler '", AssignedSamplerAttribs.Name, "' that is assigned to it"); // Do not assign static sampler to texture SRV as it is initialized directly in the shader resource cache if (!AssignedSamplerAttribs.IsStaticSampler()) { @@ -366,7 +370,7 @@ void ShaderResourceLayoutD3D11::ConstBuffBindInfo::BindResource(IDeviceObject* p { auto &pResourceCache = m_ParentResLayout.m_pResourceCache; VERIFY(pResourceCache, "Resource cache is null"); - VERIFY_EXPR(ArrayIndex < Attribs.BindCount); + DEV_CHECK_ERR(ArrayIndex < Attribs.BindCount, "Array index (", ArrayIndex, ") is out of range for variable '", Attribs.Name, "'. Max allowed index: ", Attribs.BindCount); RefCntAutoPtr pBuffD3D11Impl; if( pBuffer ) @@ -448,7 +452,7 @@ void ShaderResourceLayoutD3D11::TexSRVBindInfo::BindResource(IDeviceObject* pVie Uint32 ArrayIndex) { VERIFY(m_ParentResLayout.m_pResourceCache, "Resource cache is null"); - VERIFY_EXPR(ArrayIndex < Attribs.BindCount); + DEV_CHECK_ERR(ArrayIndex < Attribs.BindCount, "Array index (", ArrayIndex, ") is out of range for variable '", Attribs.Name, "'. Max allowed index: ", Attribs.BindCount); auto& ResourceCache = *m_ParentResLayout.m_pResourceCache; // We cannot use ValidatedCast<> here as the resource retrieved from the @@ -502,7 +506,7 @@ void ShaderResourceLayoutD3D11::SamplerBindInfo::BindResource(IDeviceObject* pSa Uint32 ArrayIndex) { VERIFY(m_ParentResLayout.m_pResourceCache != nullptr, "Resource cache is null"); - VERIFY_EXPR(ArrayIndex < Attribs.BindCount); + DEV_CHECK_ERR(ArrayIndex < Attribs.BindCount, "Array index (", ArrayIndex, ") is out of range for variable '", Attribs.Name, "'. Max allowed index: ", Attribs.BindCount); auto& ResourceCache = *m_ParentResLayout.m_pResourceCache; VERIFY(!Attribs.IsStaticSampler(), "Cannot bind sampler to a static sampler"); @@ -538,7 +542,7 @@ void ShaderResourceLayoutD3D11::BuffSRVBindInfo::BindResource(IDeviceObject* pVi Uint32 ArrayIndex) { VERIFY(m_ParentResLayout.m_pResourceCache != nullptr, "Resource cache is null"); - VERIFY(ArrayIndex < Attribs.BindCount, "Array index is out of range"); + DEV_CHECK_ERR(ArrayIndex < Attribs.BindCount, "Array index (", ArrayIndex, ") is out of range for variable '", Attribs.Name, "'. Max allowed index: ", Attribs.BindCount); auto& ResourceCache = *m_ParentResLayout.m_pResourceCache; // We cannot use ValidatedCast<> here as the resource retrieved from the @@ -569,7 +573,7 @@ void ShaderResourceLayoutD3D11::TexUAVBindInfo::BindResource(IDeviceObject* pVie Uint32 ArrayIndex) { VERIFY(m_ParentResLayout.m_pResourceCache != nullptr, "Resource cache is null"); - VERIFY(ArrayIndex < Attribs.BindCount, "Array index is out of range"); + DEV_CHECK_ERR(ArrayIndex < Attribs.BindCount, "Array index (", ArrayIndex, ") is out of range for variable '", Attribs.Name, "'. Max allowed index: ", Attribs.BindCount); auto& ResourceCache = *m_ParentResLayout.m_pResourceCache; // We cannot use ValidatedCast<> here as the resource retrieved from the @@ -600,7 +604,7 @@ void ShaderResourceLayoutD3D11::BuffUAVBindInfo::BindResource(IDeviceObject* pVi Uint32 ArrayIndex) { VERIFY(m_ParentResLayout.m_pResourceCache != nullptr, "Resource cache is null"); - VERIFY(ArrayIndex < Attribs.BindCount, "Array index is out of range"); + DEV_CHECK_ERR(ArrayIndex < Attribs.BindCount, "Array index (", ArrayIndex, ") is out of range for variable '", Attribs.Name, "'. Max allowed index: ", Attribs.BindCount); auto& ResourceCache = *m_ParentResLayout.m_pResourceCache; // We cannot use ValidatedCast<> here as the resource retrieved from the @@ -799,7 +803,7 @@ Uint32 ShaderResourceLayoutD3D11::GetVariableIndex(const ShaderVariableD3D11Base Uint32 Index = 0; if (Offset < m_TexSRVsOffset) { - VERIFY(Offset % sizeof(ConstBuffBindInfo) == 0, "Offset is not multiple of sizeof(ConstBuffBindInfo)"); + DEV_CHECK_ERR(Offset % sizeof(ConstBuffBindInfo) == 0, "Offset is not multiple of sizeof(ConstBuffBindInfo)"); return Index + static_cast(Offset / sizeof(ConstBuffBindInfo)); } else @@ -807,7 +811,7 @@ Uint32 ShaderResourceLayoutD3D11::GetVariableIndex(const ShaderVariableD3D11Base if (Offset < m_TexUAVsOffset) { - VERIFY( (Offset - m_TexSRVsOffset) % sizeof(TexSRVBindInfo) == 0, "Offset is not multiple of sizeof(TexSRVBindInfo)"); + DEV_CHECK_ERR( (Offset - m_TexSRVsOffset) % sizeof(TexSRVBindInfo) == 0, "Offset is not multiple of sizeof(TexSRVBindInfo)"); return Index + static_cast((Offset - m_TexSRVsOffset) / sizeof(TexSRVBindInfo)); } else @@ -815,7 +819,7 @@ Uint32 ShaderResourceLayoutD3D11::GetVariableIndex(const ShaderVariableD3D11Base if (Offset < m_BuffUAVsOffset) { - VERIFY( (Offset - m_TexUAVsOffset) % sizeof(TexUAVBindInfo) == 0, "Offset is not multiple of sizeof(TexUAVBindInfo)"); + DEV_CHECK_ERR( (Offset - m_TexUAVsOffset) % sizeof(TexUAVBindInfo) == 0, "Offset is not multiple of sizeof(TexUAVBindInfo)"); return Index + static_cast((Offset - m_TexUAVsOffset) / sizeof(TexUAVBindInfo)); } else @@ -823,7 +827,7 @@ Uint32 ShaderResourceLayoutD3D11::GetVariableIndex(const ShaderVariableD3D11Base if (Offset < m_BuffSRVsOffset) { - VERIFY( (Offset - m_BuffUAVsOffset) % sizeof(BuffUAVBindInfo) == 0, "Offset is not multiple of sizeof(BuffUAVBindInfo)" ); + DEV_CHECK_ERR( (Offset - m_BuffUAVsOffset) % sizeof(BuffUAVBindInfo) == 0, "Offset is not multiple of sizeof(BuffUAVBindInfo)" ); return Index + static_cast((Offset - m_BuffUAVsOffset) / sizeof(BuffUAVBindInfo)); } else @@ -831,7 +835,7 @@ Uint32 ShaderResourceLayoutD3D11::GetVariableIndex(const ShaderVariableD3D11Base if (Offset < static_cast(m_BuffSRVsOffset + m_NumBufSRVs * sizeof(BuffSRVBindInfo))) { - VERIFY( (Offset - m_BuffSRVsOffset) % sizeof(BuffSRVBindInfo) == 0, "Offset is not multiple of sizeof(BuffSRVBindInfo)" ); + DEV_CHECK_ERR( (Offset - m_BuffSRVsOffset) % sizeof(BuffSRVBindInfo) == 0, "Offset is not multiple of sizeof(BuffSRVBindInfo)" ); return Index + static_cast((Offset - m_BuffSRVsOffset) / sizeof(BuffSRVBindInfo)); } else @@ -839,7 +843,7 @@ Uint32 ShaderResourceLayoutD3D11::GetVariableIndex(const ShaderVariableD3D11Base if (Offset < static_cast(m_SamplerOffset + m_NumSamplers * sizeof(SamplerBindInfo))) { - VERIFY( (Offset - m_SamplerOffset) % sizeof(SamplerBindInfo) == 0, "Offset is not multiple of sizeof(SamplerBindInfo)" ); + DEV_CHECK_ERR( (Offset - m_SamplerOffset) % sizeof(SamplerBindInfo) == 0, "Offset is not multiple of sizeof(SamplerBindInfo)" ); return Index + static_cast((Offset - m_SamplerOffset) / sizeof(SamplerBindInfo)); } else diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderResourcesD3D11.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderResourcesD3D11.cpp index b92c16fe..544d9088 100755 --- a/Graphics/GraphicsEngineD3D11/src/ShaderResourcesD3D11.cpp +++ b/Graphics/GraphicsEngineD3D11/src/ShaderResourcesD3D11.cpp @@ -116,7 +116,7 @@ ShaderResourcesD3D11::ShaderResourcesD3D11(RenderDeviceD3D11Impl* pDeviceD3D11Im for (; ssd < ShdrDesc.NumStaticSamplers; ++ssd) { const auto& StaticSamplerDesc = ShdrDesc.StaticSamplers[ssd]; - if (StrCmpSuff(Sam.Name, StaticSamplerDesc.SamplerOrTextureName, CombinedSamplerSuffix)) + if (StreqSuff(Sam.Name, StaticSamplerDesc.SamplerOrTextureName, CombinedSamplerSuffix)) { auto &StaticSamplerAttrs = GetStaticSampler(CurrStaticSam++); StaticSamplerAttrs.first = &Sam; -- cgit v1.2.3