summaryrefslogtreecommitdiffstats
path: root/Graphics
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2021-02-20 04:01:22 +0000
committerassiduous <assiduous@diligentgraphics.com>2021-03-19 00:38:09 +0000
commitb9c44f8f6e98ff7a9cbeeb0d82ecbd41afae563d (patch)
treeb9e3f4a7e3d7436e2219c03d2a27930b15589ede /Graphics
parentUpdated accessing static variables through PSO (diff)
downloadDiligentCore-b9c44f8f6e98ff7a9cbeeb0d82ecbd41afae563d.tar.gz
DiligentCore-b9c44f8f6e98ff7a9cbeeb0d82ecbd41afae563d.zip
PipelineResourceSignatureD3D12Impl and PipelineResourceSignatureVkImpl: removed duplicate logic for hash calculation and compatiblitiy tests
Diffstat (limited to 'Graphics')
-rw-r--r--Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp18
-rw-r--r--Graphics/GraphicsEngine/src/PipelineResourceSignatureBase.cpp64
-rw-r--r--Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp47
-rw-r--r--Graphics/GraphicsEngineVulkan/src/PipelineResourceSignatureVkImpl.cpp54
4 files changed, 93 insertions, 90 deletions
diff --git a/Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp b/Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp
index b748df22..93659fa7 100644
--- a/Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp
+++ b/Graphics/GraphicsEngine/include/PipelineResourceSignatureBase.hpp
@@ -58,18 +58,12 @@ Int32 FindImmutableSampler(const ImmutableSamplerDesc* ImtblSamplers,
const char* ResourceName,
const char* SamplerSuffix);
-/// Returns true if two pipeline resources are compatible
-inline bool PipelineResourcesCompatible(const PipelineResourceDesc& lhs, const PipelineResourceDesc& rhs)
-{
- // Ignore resource names.
- // clang-format off
- return lhs.ShaderStages == rhs.ShaderStages &&
- lhs.ArraySize == rhs.ArraySize &&
- lhs.ResourceType == rhs.ResourceType &&
- lhs.VarType == rhs.VarType &&
- lhs.Flags == rhs.Flags;
- // clang-format on
-}
+/// Returns true if two pipeline resource signature descriptions are compatible, and false otherwise
+bool PipelineResourceSignaturesCompatible(const PipelineResourceSignatureDesc& Desc0,
+ const PipelineResourceSignatureDesc& Desc1) noexcept;
+
+/// Calculates hash of the pipeline resource signature description.
+size_t CalculatePipelineResourceSignatureDescHash(const PipelineResourceSignatureDesc& Desc) noexcept;
/// Template class implementing base functionality of the pipeline resource signature object.
diff --git a/Graphics/GraphicsEngine/src/PipelineResourceSignatureBase.cpp b/Graphics/GraphicsEngine/src/PipelineResourceSignatureBase.cpp
index cd7e048c..29c069de 100644
--- a/Graphics/GraphicsEngine/src/PipelineResourceSignatureBase.cpp
+++ b/Graphics/GraphicsEngine/src/PipelineResourceSignatureBase.cpp
@@ -245,5 +245,69 @@ Int32 FindImmutableSampler(const ImmutableSamplerDesc* ImtblSamplers,
return -1;
}
+/// Returns true if two pipeline resources are compatible
+inline bool PipelineResourcesCompatible(const PipelineResourceDesc& lhs, const PipelineResourceDesc& rhs)
+{
+ // Ignore resource names.
+ // clang-format off
+ return lhs.ShaderStages == rhs.ShaderStages &&
+ lhs.ArraySize == rhs.ArraySize &&
+ lhs.ResourceType == rhs.ResourceType &&
+ lhs.VarType == rhs.VarType &&
+ lhs.Flags == rhs.Flags;
+ // clang-format on
+}
+
+bool PipelineResourceSignaturesCompatible(const PipelineResourceSignatureDesc& Desc0,
+ const PipelineResourceSignatureDesc& Desc1) noexcept
+{
+ if (Desc0.BindingIndex != Desc1.BindingIndex)
+ return false;
+
+ if (Desc0.NumResources != Desc1.NumResources)
+ return false;
+
+ for (Uint32 r = 0; r < Desc0.NumResources; ++r)
+ {
+ if (!PipelineResourcesCompatible(Desc0.Resources[r], Desc1.Resources[r]))
+ return false;
+ }
+
+ if (Desc0.NumImmutableSamplers != Desc1.NumImmutableSamplers)
+ return false;
+
+ for (Uint32 s = 0; s < Desc0.NumImmutableSamplers; ++s)
+ {
+ const auto& Samp0 = Desc0.ImmutableSamplers[s];
+ const auto& Samp1 = Desc1.ImmutableSamplers[s];
+
+ if (Samp0.ShaderStages != Samp1.ShaderStages ||
+ !(Samp0.Desc == Samp1.Desc))
+ return false;
+ }
+
+ return true;
+}
+
+size_t CalculatePipelineResourceSignatureDescHash(const PipelineResourceSignatureDesc& Desc) noexcept
+{
+ if (Desc.NumResources == 0 && Desc.NumImmutableSamplers == 0)
+ return 0;
+
+ size_t Hash = ComputeHash(Desc.NumResources, Desc.NumImmutableSamplers, Desc.BindingIndex);
+
+ for (Uint32 i = 0; i < Desc.NumResources; ++i)
+ {
+ const auto& Res = Desc.Resources[i];
+ HashCombine(Hash, Uint32{Res.ShaderStages}, Res.ArraySize, Uint32{Res.ResourceType}, Uint32{Res.VarType}, Uint32{Res.Flags});
+ }
+
+ for (Uint32 i = 0; i < Desc.NumImmutableSamplers; ++i)
+ {
+ HashCombine(Hash, Uint32{Desc.ImmutableSamplers[i].ShaderStages}, Desc.ImmutableSamplers[i].Desc);
+ }
+
+ return Hash;
+}
} // namespace Diligent
diff --git a/Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp
index e61dd9fd..bba1d296 100644
--- a/Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/PipelineResourceSignatureD3D12Impl.cpp
@@ -121,7 +121,7 @@ PipelineResourceSignatureD3D12Impl::PipelineResourceSignatureD3D12Impl(IReferenc
constexpr SHADER_RESOURCE_VARIABLE_TYPE AllowedVarTypes[] = {SHADER_RESOURCE_VARIABLE_TYPE_STATIC};
for (Uint32 i = 0; i < m_StaticResStageIndex.size(); ++i)
{
- Int8 Idx = m_StaticResStageIndex[i];
+ auto Idx = m_StaticResStageIndex[i];
if (Idx >= 0)
{
VERIFY_EXPR(static_cast<Uint32>(Idx) < NumStaticResStages);
@@ -381,35 +381,14 @@ bool PipelineResourceSignatureD3D12Impl::IsCompatibleWith(const PipelineResource
if (GetHash() != Other.GetHash())
return false;
- if (GetDesc().BindingIndex != Other.GetDesc().BindingIndex)
+ if (!PipelineResourceSignaturesCompatible(GetDesc(), Other.GetDesc()))
return false;
- const Uint32 LResCount = GetTotalResourceCount();
- const Uint32 RResCount = Other.GetTotalResourceCount();
-
- if (LResCount != RResCount)
- return false;
-
- for (Uint32 r = 0; r < LResCount; ++r)
+ const auto ResCount = GetTotalResourceCount();
+ VERIFY_EXPR(ResCount == Other.GetTotalResourceCount());
+ for (Uint32 r = 0; r < ResCount; ++r)
{
- if (!ResourcesCompatible(GetResourceAttribs(r), Other.GetResourceAttribs(r)) ||
- !PipelineResourcesCompatible(GetResourceDesc(r), Other.GetResourceDesc(r)))
- return false;
- }
-
- const Uint32 LSampCount = GetDesc().NumImmutableSamplers;
- const Uint32 RSampCount = Other.GetDesc().NumImmutableSamplers;
-
- if (LSampCount != RSampCount)
- return false;
-
- for (Uint32 s = 0; s < LSampCount; ++s)
- {
- const auto& LSamp = GetDesc().ImmutableSamplers[s];
- const auto& RSamp = Other.GetDesc().ImmutableSamplers[s];
-
- if (LSamp.ShaderStages != RSamp.ShaderStages ||
- !(LSamp.Desc == RSamp.Desc))
+ if (!ResourcesCompatible(GetResourceAttribs(r), Other.GetResourceAttribs(r)))
return false;
}
@@ -453,20 +432,12 @@ size_t PipelineResourceSignatureD3D12Impl::CalculateHash() const
if (m_Desc.NumResources == 0 && m_Desc.NumImmutableSamplers == 0)
return 0;
- size_t Hash = ComputeHash(m_Desc.NumResources, m_Desc.NumImmutableSamplers, m_Desc.BindingIndex);
-
+ auto Hash = CalculatePipelineResourceSignatureDescHash(m_Desc);
for (Uint32 i = 0; i < m_Desc.NumResources; ++i)
{
- const auto& Res = m_Desc.Resources[i];
const auto& Attr = m_pResourceAttribs[i];
-
- HashCombine(Hash, Res.ArraySize, Uint32{Res.ShaderStages}, Uint32{Res.VarType}, Uint32{Res.Flags},
- Attr.Register, Attr.Space, Attr.SRBRootIndex, Attr.SRBOffsetFromTableStart, Attr.IsImmutableSamplerAssigned());
- }
-
- for (Uint32 i = 0; i < m_Desc.NumImmutableSamplers; ++i)
- {
- HashCombine(Hash, Uint32{m_Desc.ImmutableSamplers[i].ShaderStages}, m_Desc.ImmutableSamplers[i].Desc);
+ HashCombine(Hash, Attr.Register, Attr.Space, Attr.SRBRootIndex, Attr.SRBOffsetFromTableStart,
+ Attr.RootParamType, Attr.IsImmutableSamplerAssigned());
}
return Hash;
diff --git a/Graphics/GraphicsEngineVulkan/src/PipelineResourceSignatureVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/PipelineResourceSignatureVkImpl.cpp
index 9bff0621..ddd59ae1 100644
--- a/Graphics/GraphicsEngineVulkan/src/PipelineResourceSignatureVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/PipelineResourceSignatureVkImpl.cpp
@@ -624,20 +624,12 @@ size_t PipelineResourceSignatureVkImpl::CalculateHash() const
if (m_Desc.NumResources == 0 && m_Desc.NumImmutableSamplers == 0)
return 0;
- size_t Hash = ComputeHash(m_Desc.NumResources, m_Desc.NumImmutableSamplers, m_Desc.BindingIndex);
-
+ auto Hash = CalculatePipelineResourceSignatureDescHash(m_Desc);
for (Uint32 i = 0; i < m_Desc.NumResources; ++i)
{
- const auto& Res = m_Desc.Resources[i];
const auto& Attr = m_pResourceAttribs[i];
-
- HashCombine(Hash, Res.ArraySize, Uint32{Res.ShaderStages}, Uint32{Res.VarType}, static_cast<Uint32>(Attr.GetDescriptorType()),
- Attr.BindingIndex, Attr.DescrSet, Attr.IsImmutableSamplerAssigned());
- }
-
- for (Uint32 i = 0; i < m_Desc.NumImmutableSamplers; ++i)
- {
- HashCombine(Hash, Uint32{m_Desc.ImmutableSamplers[i].ShaderStages}, m_Desc.ImmutableSamplers[i].Desc);
+ HashCombine(Hash, static_cast<Uint32>(Attr.GetDescriptorType()), Attr.BindingIndex, Attr.DescrType,
+ Attr.DescrSet, Attr.IsImmutableSamplerAssigned(), Attr.SRBCacheOffset);
}
return Hash;
@@ -677,11 +669,14 @@ void PipelineResourceSignatureVkImpl::Destruct()
m_pStaticResCache = nullptr;
}
- for (Uint32 i = 0; i < m_Desc.NumImmutableSamplers; ++i)
+ if (m_ImmutableSamplers != nullptr)
{
- m_ImmutableSamplers[i].~ImmutableSamplerAttribs();
+ for (Uint32 i = 0; i < m_Desc.NumImmutableSamplers; ++i)
+ {
+ m_ImmutableSamplers[i].~ImmutableSamplerAttribs();
+ }
+ m_ImmutableSamplers = nullptr;
}
- m_ImmutableSamplers = nullptr;
if (void* pRawMem = m_pResourceAttribs)
{
@@ -700,35 +695,14 @@ bool PipelineResourceSignatureVkImpl::IsCompatibleWith(const PipelineResourceSig
if (GetHash() != Other.GetHash())
return false;
- if (GetDesc().BindingIndex != Other.GetDesc().BindingIndex)
- return false;
-
- const Uint32 LResCount = GetTotalResourceCount();
- const Uint32 RResCount = Other.GetTotalResourceCount();
-
- if (LResCount != RResCount)
- return false;
-
- for (Uint32 r = 0; r < LResCount; ++r)
- {
- if (!ResourcesCompatible(GetResourceAttribs(r), Other.GetResourceAttribs(r)) ||
- !PipelineResourcesCompatible(GetResourceDesc(r), Other.GetResourceDesc(r)))
- return false;
- }
-
- const Uint32 LSampCount = GetDesc().NumImmutableSamplers;
- const Uint32 RSampCount = Other.GetDesc().NumImmutableSamplers;
-
- if (LSampCount != RSampCount)
+ if (!PipelineResourceSignaturesCompatible(GetDesc(), Other.GetDesc()))
return false;
- for (Uint32 s = 0; s < LSampCount; ++s)
+ const auto ResCount = GetTotalResourceCount();
+ VERIFY_EXPR(ResCount == Other.GetTotalResourceCount());
+ for (Uint32 r = 0; r < ResCount; ++r)
{
- const auto& LSamp = GetDesc().ImmutableSamplers[s];
- const auto& RSamp = Other.GetDesc().ImmutableSamplers[s];
-
- if (LSamp.ShaderStages != RSamp.ShaderStages ||
- !(LSamp.Desc == RSamp.Desc))
+ if (!ResourcesCompatible(GetResourceAttribs(r), Other.GetResourceAttribs(r)))
return false;
}