summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineD3DBase
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2018-03-11 19:07:09 +0000
committerEgor Yusov <egor.yusov@gmail.com>2018-03-11 19:07:09 +0000
commitbbbf3434aefd105662f9efd4bf9e7d56f9e8170b (patch)
tree42806921a62dcc82b4925927d52e9f453048e959 /Graphics/GraphicsEngineD3DBase
parentEnabled full optimization (/Ox) for windows release builds (diff)
downloadDiligentCore-bbbf3434aefd105662f9efd4bf9e7d56f9e8170b.tar.gz
DiligentCore-bbbf3434aefd105662f9efd4bf9e7d56f9e8170b.zip
Implemented PSO compatibility in D3D11
Diffstat (limited to 'Graphics/GraphicsEngineD3DBase')
-rw-r--r--Graphics/GraphicsEngineD3DBase/include/ShaderResources.h49
-rw-r--r--Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp93
2 files changed, 127 insertions, 15 deletions
diff --git a/Graphics/GraphicsEngineD3DBase/include/ShaderResources.h b/Graphics/GraphicsEngineD3DBase/include/ShaderResources.h
index 8972e2be..57e395ed 100644
--- a/Graphics/GraphicsEngineD3DBase/include/ShaderResources.h
+++ b/Graphics/GraphicsEngineD3DBase/include/ShaderResources.h
@@ -58,6 +58,7 @@
#include "Shader.h"
#include "STDAllocator.h"
+#include "HashUtils.h"
namespace Diligent
{
@@ -218,6 +219,19 @@ struct D3DShaderResourceAttribs
else
return Name;
}
+
+ bool IsCompatibleWith(const D3DShaderResourceAttribs& Attibs)const
+ {
+ return BindPoint == Attibs.BindPoint &&
+ BindCount == Attibs.BindCount &&
+ PackedAttribs == Attibs.PackedAttribs;
+ }
+
+ size_t GetHash()const
+ {
+ return ComputeHash(BindPoint, BindCount, PackedAttribs);
+ }
+
private:
static constexpr Uint16 MaxBindPoint = InvalidBindPoint-1;
static constexpr Uint16 MaxBindCount = std::numeric_limits<Uint16>::max();
@@ -327,38 +341,42 @@ public:
{
const auto& CB = GetCB(n);
if( IsAllowedType(CB.GetVariableType(), AllowedTypeBits) )
- HandleCB(CB);
+ HandleCB(CB, n);
}
for(Uint32 n=0; n < GetNumTexSRV(); ++n)
{
const auto &TexSRV = GetTexSRV(n);
if( IsAllowedType(TexSRV.GetVariableType(), AllowedTypeBits) )
- HandleTexSRV(TexSRV);
+ HandleTexSRV(TexSRV, n);
}
for(Uint32 n=0; n < GetNumTexUAV(); ++n)
{
const auto &TexUAV = GetTexUAV(n);
if( IsAllowedType(TexUAV.GetVariableType(), AllowedTypeBits) )
- HandleTexUAV(TexUAV);
+ HandleTexUAV(TexUAV, n);
}
for(Uint32 n=0; n < GetNumBufSRV(); ++n)
{
const auto &BufSRV = GetBufSRV(n);
if( IsAllowedType(BufSRV.GetVariableType(), AllowedTypeBits) )
- HandleBufSRV(BufSRV);
+ HandleBufSRV(BufSRV, n);
}
for(Uint32 n=0; n < GetNumBufUAV(); ++n)
{
const auto& BufUAV = GetBufUAV(n);
if( IsAllowedType(BufUAV.GetVariableType(), AllowedTypeBits) )
- HandleBufUAV(BufUAV);
+ HandleBufUAV(BufUAV, n);
}
}
+ bool IsCompatibleWith(const ShaderResources &Resources)const;
+
+ size_t GetHash()const;
+
protected:
void Initialize(IMemoryAllocator &Allocator, Uint32 NumCBs, Uint32 NumTexSRVs, Uint32 NumTexUAVs, Uint32 NumBufSRVs, Uint32 NumBufUAVs, Uint32 NumSamplers);
@@ -403,3 +421,24 @@ private:
};
}
+
+namespace std
+{
+ template<>
+ struct hash<Diligent::D3DShaderResourceAttribs>
+ {
+ size_t operator()(const Diligent::D3DShaderResourceAttribs &Attribs) const
+ {
+ return Attribs.GetHash();
+ }
+ };
+
+ template<>
+ struct hash<Diligent::ShaderResources>
+ {
+ size_t operator()(const Diligent::ShaderResources &Res) const
+ {
+ return Res.GetHash();
+ }
+ };
+}
diff --git a/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp b/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp
index 6cedfa41..3d09b233 100644
--- a/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp
+++ b/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp
@@ -25,6 +25,7 @@
#include "EngineMemory.h"
#include "StringTools.h"
#include "ShaderResources.h"
+#include "HashUtils.h"
namespace Diligent
{
@@ -116,28 +117,28 @@ void ShaderResources::CountResources(const SHADER_VARIABLE_TYPE *AllowedVarTypes
ProcessResources(
AllowedVarTypes, NumAllowedTypes,
- [&](const D3DShaderResourceAttribs &CB)
+ [&](const D3DShaderResourceAttribs &CB, Uint32)
{
VERIFY_EXPR(IsAllowedType(CB.GetVariableType(), AllowedTypeBits));
++NumCBs;
},
- [&](const D3DShaderResourceAttribs& TexSRV)
+ [&](const D3DShaderResourceAttribs& TexSRV, Uint32)
{
VERIFY_EXPR(IsAllowedType(TexSRV.GetVariableType(), AllowedTypeBits));
++NumTexSRVs;
NumSamplers += TexSRV.IsValidSampler() ? 1 : 0;
},
- [&](const D3DShaderResourceAttribs &TexUAV)
+ [&](const D3DShaderResourceAttribs &TexUAV, Uint32)
{
VERIFY_EXPR(IsAllowedType(TexUAV.GetVariableType(), AllowedTypeBits));
++NumTexUAVs;
},
- [&](const D3DShaderResourceAttribs &BufSRV)
+ [&](const D3DShaderResourceAttribs &BufSRV, Uint32)
{
VERIFY_EXPR(IsAllowedType(BufSRV.GetVariableType(), AllowedTypeBits));
++NumBufSRVs;
},
- [&](const D3DShaderResourceAttribs &BufUAV)
+ [&](const D3DShaderResourceAttribs &BufUAV, Uint32)
{
VERIFY_EXPR(IsAllowedType(BufUAV.GetVariableType(), AllowedTypeBits));
++NumBufUAVs;
@@ -169,12 +170,12 @@ ShaderResources::ShaderResources(IMemoryAllocator &Allocator,
ProcessResources(
AllowedVarTypes, NumAllowedTypes,
- [&](const D3DShaderResourceAttribs &CB)
+ [&](const D3DShaderResourceAttribs &CB, Uint32)
{
VERIFY_EXPR( IsAllowedType(CB.GetVariableType(), AllowedTypeBits) );
new (&GetCB(CurrCB++)) D3DShaderResourceAttribs(CB);
},
- [&](const D3DShaderResourceAttribs& TexSRV)
+ [&](const D3DShaderResourceAttribs& TexSRV, Uint32)
{
VERIFY_EXPR(IsAllowedType(TexSRV.GetVariableType(), AllowedTypeBits));
@@ -187,17 +188,17 @@ ShaderResources::ShaderResources(IMemoryAllocator &Allocator,
new (&GetTexSRV(CurrTexSRV++)) D3DShaderResourceAttribs(TexSRV, SamplerId);
},
- [&](const D3DShaderResourceAttribs &TexUAV)
+ [&](const D3DShaderResourceAttribs &TexUAV, Uint32)
{
VERIFY_EXPR( IsAllowedType(TexUAV.GetVariableType(), AllowedTypeBits) );
new (&GetTexUAV(CurrTexUAV++)) D3DShaderResourceAttribs(TexUAV);
},
- [&](const D3DShaderResourceAttribs &BufSRV)
+ [&](const D3DShaderResourceAttribs &BufSRV, Uint32)
{
VERIFY_EXPR( IsAllowedType(BufSRV.GetVariableType(), AllowedTypeBits) );
new (&GetBufSRV(CurrBufSRV++)) D3DShaderResourceAttribs(BufSRV);
},
- [&](const D3DShaderResourceAttribs &BufUAV)
+ [&](const D3DShaderResourceAttribs &BufUAV, Uint32)
{
VERIFY_EXPR( IsAllowedType(BufUAV.GetVariableType(), AllowedTypeBits) );
new (&GetBufUAV(CurrBufUAV++)) D3DShaderResourceAttribs(BufUAV);
@@ -229,4 +230,76 @@ Uint32 ShaderResources::FindAssignedSamplerId(const D3DShaderResourceAttribs& Te
return D3DShaderResourceAttribs::InvalidSamplerId;
}
+bool ShaderResources::IsCompatibleWith(const ShaderResources &Res)const
+{
+ if (GetNumCBs() != Res.GetNumCBs() ||
+ GetNumTexSRV() != Res.GetNumTexSRV() ||
+ GetNumTexUAV() != Res.GetNumTexUAV() ||
+ GetNumBufSRV() != Res.GetNumBufSRV() ||
+ GetNumBufUAV() != Res.GetNumBufUAV())
+ return false;
+
+ bool IsCompatible = true;
+ ProcessResources(
+ nullptr, 0,
+
+ [&](const D3DShaderResourceAttribs &CB, Uint32 n)
+ {
+ if(!CB.IsCompatibleWith(Res.GetCB(n)))
+ IsCompatible = false;
+ },
+ [&](const D3DShaderResourceAttribs& TexSRV, Uint32 n)
+ {
+ if(!TexSRV.IsCompatibleWith(Res.GetTexSRV(n)))
+ IsCompatible = false;
+ },
+ [&](const D3DShaderResourceAttribs &TexUAV, Uint32 n)
+ {
+ if(!TexUAV.IsCompatibleWith(Res.GetTexUAV(n)))
+ IsCompatible = false;
+ },
+ [&](const D3DShaderResourceAttribs &BufSRV, Uint32 n)
+ {
+ if(!BufSRV.IsCompatibleWith(Res.GetBufSRV(n)))
+ IsCompatible = false;
+ },
+ [&](const D3DShaderResourceAttribs &BufUAV, Uint32 n)
+ {
+ if(!BufUAV.IsCompatibleWith(Res.GetBufUAV(n)))
+ IsCompatible = false;
+ }
+ );
+ return IsCompatible;
+}
+
+size_t ShaderResources::GetHash()const
+{
+ size_t hash = ComputeHash(GetNumCBs(), GetNumTexSRV(), GetNumTexUAV(), GetNumBufSRV(), GetNumBufUAV());
+ ProcessResources(
+ nullptr, 0,
+ [&](const D3DShaderResourceAttribs &CB, Uint32 n)
+ {
+ HashCombine(hash, CB);
+ },
+ [&](const D3DShaderResourceAttribs& TexSRV, Uint32 n)
+ {
+ HashCombine(hash, TexSRV);
+ },
+ [&](const D3DShaderResourceAttribs &TexUAV, Uint32 n)
+ {
+ HashCombine(hash, TexUAV);
+ },
+ [&](const D3DShaderResourceAttribs &BufSRV, Uint32 n)
+ {
+ HashCombine(hash, BufSRV);
+ },
+ [&](const D3DShaderResourceAttribs &BufUAV, Uint32 n)
+ {
+ HashCombine(hash, BufUAV);
+ }
+ );
+
+ return hash;
+}
+
}