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/D3DShaderResourceLoader.h | 4 ++-- .../include/ShaderResources.h | 23 ++++++++++++---------- .../GraphicsEngineD3DBase/src/ShaderResources.cpp | 2 +- 3 files changed, 16 insertions(+), 13 deletions(-) (limited to 'Graphics/GraphicsEngineD3DBase') diff --git a/Graphics/GraphicsEngineD3DBase/include/D3DShaderResourceLoader.h b/Graphics/GraphicsEngineD3DBase/include/D3DShaderResourceLoader.h index 1a256bce..bc6b19fe 100644 --- a/Graphics/GraphicsEngineD3DBase/include/D3DShaderResourceLoader.h +++ b/Graphics/GraphicsEngineD3DBase/include/D3DShaderResourceLoader.h @@ -153,7 +153,7 @@ namespace Diligent { for (Uint32 s = 0; s < ShdrDesc.NumStaticSamplers; ++s) { - if (StrCmpSuff(Name.c_str(), ShdrDesc.StaticSamplers[s].SamplerOrTextureName, SamplerSuffix)) + if (StreqSuff(Name.c_str(), ShdrDesc.StaticSamplers[s].SamplerOrTextureName, SamplerSuffix)) { IsStaticSampler = true; break; @@ -163,7 +163,7 @@ namespace Diligent VarType = GetShaderVariableType(ShdrDesc.DefaultVariableType, ShdrDesc.VariableDesc, ShdrDesc.NumVariables, [&](const char* VarName) { - return StrCmpSuff(Name.c_str(), VarName, SamplerSuffix); + return StreqSuff(Name.c_str(), VarName, SamplerSuffix); }); } else diff --git a/Graphics/GraphicsEngineD3DBase/include/ShaderResources.h b/Graphics/GraphicsEngineD3DBase/include/ShaderResources.h index 9c2278d4..6cc30b55 100644 --- a/Graphics/GraphicsEngineD3DBase/include/ShaderResources.h +++ b/Graphics/GraphicsEngineD3DBase/include/ShaderResources.h @@ -388,8 +388,9 @@ public: } } - bool IsCompatibleWith(const ShaderResources& Resources) const; - bool IsUsingCombinedTextureSamplers() const {return m_UseCombinedTextureSamplers;} + bool IsCompatibleWith(const ShaderResources& Resources) const; + bool IsUsingCombinedTextureSamplers() const { return m_SamplerSuffix != nullptr; } + const char* GetCombinedSamplerSuffix() const { return m_SamplerSuffix; } size_t GetHash()const; @@ -415,7 +416,7 @@ protected: { VERIFY(n < NumResources, "Resource index (", n, ") is out of range. Resource array size: ", NumResources); VERIFY_EXPR(Offset + n < m_TotalResources); - return reinterpret_cast(m_MemoryBuffer.get())[Offset + n]; + return reinterpret_cast(m_MemoryBuffer.get())[Offset + n]; } D3DShaderResourceAttribs& GetCB (Uint32 n)noexcept{ return GetResAttribs(n, GetNumCBs(), 0); } @@ -441,7 +442,8 @@ private: // | CBs | TexSRVs | TexUAVs | BufSRVs | BufUAVs | Samplers | Resource Names | std::unique_ptr< void, STDDeleterRawMem > m_MemoryBuffer; - StringPool m_ResourceNames; + StringPool m_ResourceNames; + const char* m_SamplerSuffix = nullptr; // The suffix is put into the m_ResourceNames // Offsets in elements of D3DShaderResourceAttribs typedef Uint16 OffsetType; @@ -452,8 +454,6 @@ private: OffsetType m_SamplersOffset = 0; OffsetType m_TotalResources = 0; - bool m_UseCombinedTextureSamplers = false; - SHADER_TYPE m_ShaderType = SHADER_TYPE_UNKNOWN; }; @@ -467,14 +467,15 @@ void ShaderResources::Initialize(ID3DBlob* pShaderByteCode, const ShaderDesc& ShdrDesc, const Char* CombinedSamplerSuffix) { - m_UseCombinedTextureSamplers = CombinedSamplerSuffix != nullptr; - Uint32 CurrCB = 0, CurrTexSRV = 0, CurrTexUAV = 0, CurrBufSRV = 0, CurrBufUAV = 0, CurrSampler = 0; LoadD3DShaderResources( pShaderByteCode, [&](Uint32 NumCBs, Uint32 NumTexSRVs, Uint32 NumTexUAVs, Uint32 NumBufSRVs, Uint32 NumBufUAVs, Uint32 NumSamplers, size_t ResourceNamesPoolSize) { + if (CombinedSamplerSuffix != nullptr) + ResourceNamesPoolSize += strlen(CombinedSamplerSuffix)+1; + AllocateMemory(GetRawAllocator(), NumCBs, NumTexSRVs, NumTexUAVs, NumBufSRVs, NumBufUAVs, NumSamplers, ResourceNamesPoolSize); }, @@ -531,17 +532,19 @@ void ShaderResources::Initialize(ID3DBlob* pShaderByteCode, ShdrDesc, CombinedSamplerSuffix); -#ifdef DEVELOPMENT if (CombinedSamplerSuffix != nullptr) { + m_SamplerSuffix = m_ResourceNames.CopyString(CombinedSamplerSuffix); + +#ifdef DEVELOPMENT for (Uint32 n=0; n < GetNumSamplers(); ++n) { const auto& Sampler = GetSampler(n); if (!Sampler.ValidTexSRVAssigned()) LOG_ERROR_MESSAGE("Shader '", ShdrDesc.Name, "' uses combined texture samplers, but sampler '", Sampler.Name, "' is not assigned to any texture"); } - } #endif + } VERIFY_EXPR(m_ResourceNames.GetRemainingSize() == 0); VERIFY(CurrCB == GetNumCBs(), "Not all CBs are initialized which will cause a crash when ~D3DShaderResourceAttribs() is called"); diff --git a/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp b/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp index 52fc96d9..f31da6a0 100644 --- a/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp +++ b/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp @@ -166,7 +166,7 @@ Uint32 ShaderResources::FindAssignedSamplerId(const D3DShaderResourceAttribs& Te for (Uint32 s = 0; s < NumSamplers; ++s) { const auto &Sampler = GetSampler(s); - if( StrCmpSuff(Sampler.Name, TexSRV.Name, SamplerSuffix) ) + if( StreqSuff(Sampler.Name, TexSRV.Name, SamplerSuffix) ) { VERIFY(Sampler.GetVariableType() == TexSRV.GetVariableType(), "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); -- cgit v1.2.3