summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineD3DBase
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2018-10-18 15:38:21 +0000
committerEgor Yusov <egor.yusov@gmail.com>2018-10-18 15:38:21 +0000
commitc2a6a2c4b716d45ddc92ed04bb0ac7fb7200e548 (patch)
tree243f85bb150b677e5ed07532731fc30de88b0ee7 /Graphics/GraphicsEngineD3DBase
parentImplemented separate samplers in D3D11 (diff)
downloadDiligentCore-c2a6a2c4b716d45ddc92ed04bb0ac7fb7200e548.tar.gz
DiligentCore-c2a6a2c4b716d45ddc92ed04bb0ac7fb7200e548.zip
Implemented separate samplers in D3D12
Diffstat (limited to 'Graphics/GraphicsEngineD3DBase')
-rw-r--r--Graphics/GraphicsEngineD3DBase/include/D3DShaderResourceLoader.h4
-rw-r--r--Graphics/GraphicsEngineD3DBase/include/ShaderResources.h23
-rw-r--r--Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp2
3 files changed, 16 insertions, 13 deletions
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<D3DShaderResourceAttribs*>(m_MemoryBuffer.get())[Offset + n];
+ return reinterpret_cast<const D3DShaderResourceAttribs*>(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<void> > 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<D3D_SHADER_DESC, D3D_SHADER_INPUT_BIND_DESC, TShaderReflection>(
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);