summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngine
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2020-09-18 05:00:26 +0000
committerassiduous <assiduous@diligentgraphics.com>2020-09-18 05:00:26 +0000
commitce496ba73a61fe88db3d5c233dd920c2689d9e9b (patch)
tree107347e11c1a5a26199d1f8eb59bcec99763e703 /Graphics/GraphicsEngine
parentMerge branch 'mesh_shader_fix' of https://github.com/azhirnov/DiligentCore in... (diff)
downloadDiligentCore-ce496ba73a61fe88db3d5c233dd920c2689d9e9b.tar.gz
DiligentCore-ce496ba73a61fe88db3d5c233dd920c2689d9e9b.zip
Refactored internal shader resouce variable indexing
Diffstat (limited to 'Graphics/GraphicsEngine')
-rw-r--r--Graphics/GraphicsEngine/include/PipelineStateBase.hpp62
-rw-r--r--Graphics/GraphicsEngine/include/ShaderBase.hpp46
-rw-r--r--Graphics/GraphicsEngine/include/ShaderResourceBindingBase.hpp67
-rw-r--r--Graphics/GraphicsEngine/interface/Constants.h5
4 files changed, 130 insertions, 50 deletions
diff --git a/Graphics/GraphicsEngine/include/PipelineStateBase.hpp b/Graphics/GraphicsEngine/include/PipelineStateBase.hpp
index 4d2e408f..91cf912c 100644
--- a/Graphics/GraphicsEngine/include/PipelineStateBase.hpp
+++ b/Graphics/GraphicsEngine/include/PipelineStateBase.hpp
@@ -450,6 +450,68 @@ protected:
std::array<IShader*, MAX_SHADERS_IN_PIPELINE> m_ppShaders = {}; ///< Array of pointers to the shaders used by this PSO
size_t m_ShaderResourceLayoutHash = 0; ///< Hash computed from the shader resource layout
+
+protected:
+ Int8 GetStaticVariableCountHelper(SHADER_TYPE ShaderType, const std::array<Int8, MAX_SHADERS_IN_PIPELINE>& ResourceLayoutIndex) const
+ {
+ if (!IsConsistentShaderType(ShaderType, m_Desc.PipelineType))
+ {
+ LOG_WARNING_MESSAGE("Unable to get the number of static variables in shader stage ", GetShaderTypeLiteralName(ShaderType),
+ " as the stage is invalid for ", GetPipelineTypeString(m_Desc.PipelineType), " pipeline '", m_Desc.Name, "'");
+ return -1;
+ }
+
+ const auto ShaderTypeInd = GetShaderTypePipelineIndex(ShaderType, m_Desc.PipelineType);
+ const auto LayoutInd = ResourceLayoutIndex[ShaderTypeInd];
+ if (LayoutInd < 0)
+ {
+ LOG_WARNING_MESSAGE("Unable to get the number of static variables in shader stage ", GetShaderTypeLiteralName(ShaderType),
+ " as the stage is inactive in PSO '", m_Desc.Name, "'");
+ }
+
+ return LayoutInd;
+ }
+
+ Int8 GetStaticVariableByNameHelper(SHADER_TYPE ShaderType, const Char* Name, const std::array<Int8, MAX_SHADERS_IN_PIPELINE>& ResourceLayoutIndex) const
+ {
+ if (!IsConsistentShaderType(ShaderType, m_Desc.PipelineType))
+ {
+ LOG_WARNING_MESSAGE("Unable to find static variable '", Name, "' in shader stage ", GetShaderTypeLiteralName(ShaderType),
+ " as the stage is invalid for ", GetPipelineTypeString(m_Desc.PipelineType), " pipeline '", m_Desc.Name, "'");
+ return -1;
+ }
+
+ const auto ShaderTypeInd = GetShaderTypePipelineIndex(ShaderType, m_Desc.PipelineType);
+ const auto LayoutInd = ResourceLayoutIndex[ShaderTypeInd];
+ if (LayoutInd < 0)
+ {
+ LOG_WARNING_MESSAGE("Unable to find static variable '", Name, "' in shader stage ", GetShaderTypeLiteralName(ShaderType),
+ " as the stage is inactive in PSO '", m_Desc.Name, "'");
+ }
+
+ return LayoutInd;
+ }
+
+ Int8 GetStaticVariableByIndexHelper(SHADER_TYPE ShaderType, Uint32 Index, const std::array<Int8, MAX_SHADERS_IN_PIPELINE>& ResourceLayoutIndex) const
+ {
+ if (!IsConsistentShaderType(ShaderType, m_Desc.PipelineType))
+ {
+ LOG_WARNING_MESSAGE("Unable to get static variable at index ", Index, " in shader stage ", GetShaderTypeLiteralName(ShaderType),
+ " as the stage is invalid for ", GetPipelineTypeString(m_Desc.PipelineType), " pipeline '", m_Desc.Name, "'");
+ return -1;
+ }
+
+ const auto ShaderTypeInd = GetShaderTypePipelineIndex(ShaderType, m_Desc.PipelineType);
+ const auto LayoutInd = ResourceLayoutIndex[ShaderTypeInd];
+ if (LayoutInd < 0)
+ {
+ LOG_WARNING_MESSAGE("Unable to get static variable at index ", Index, " in shader stage ", GetShaderTypeLiteralName(ShaderType),
+ " as the stage is inactive in PSO '", m_Desc.Name, "'");
+ }
+
+ return LayoutInd;
+ }
+
private:
#define LOG_PSO_ERROR_AND_THROW(...) LOG_ERROR_AND_THROW("Description of ", GetPipelineTypeString(this->m_Desc.PipelineType), " PSO '", this->m_Desc.Name, "' is invalid: ", ##__VA_ARGS__)
diff --git a/Graphics/GraphicsEngine/include/ShaderBase.hpp b/Graphics/GraphicsEngine/include/ShaderBase.hpp
index 3beaa9c8..24ad92ee 100644
--- a/Graphics/GraphicsEngine/include/ShaderBase.hpp
+++ b/Graphics/GraphicsEngine/include/ShaderBase.hpp
@@ -38,56 +38,10 @@
#include "PlatformMisc.hpp"
#include "EngineMemory.h"
#include "Align.hpp"
-#include "Constants.h"
namespace Diligent
{
-static_assert((1u << (NUM_SHADER_TYPES - 1)) == SHADER_TYPE_LAST, "check shader type enum or shader count");
-
-inline SHADER_TYPE GetShaderTypeFromIndex(Int32 Index)
-{
- return static_cast<SHADER_TYPE>(1 << Index);
-}
-
-inline Int32 GetShaderTypeIndex(SHADER_TYPE Type)
-{
- VERIFY(IsPowerOfTwo(Uint32{Type}), "Only single shader stage should be provided");
-
- Int32 ShaderIndex = PlatformMisc::GetLSB(Type);
-
-#ifdef DILIGENT_DEBUG
- static_assert(SHADER_TYPE_LAST == 0x080, "Please update the switch below to handle the new shader type");
- switch (Type)
- {
- // clang-format off
- case SHADER_TYPE_UNKNOWN: VERIFY_EXPR(ShaderIndex == -1); break;
- case SHADER_TYPE_VERTEX: VERIFY_EXPR(ShaderIndex == 0); break;
- case SHADER_TYPE_PIXEL: VERIFY_EXPR(ShaderIndex == 1); break;
- case SHADER_TYPE_GEOMETRY: VERIFY_EXPR(ShaderIndex == 2); break;
- case SHADER_TYPE_HULL: VERIFY_EXPR(ShaderIndex == 3); break;
- case SHADER_TYPE_DOMAIN: VERIFY_EXPR(ShaderIndex == 4); break;
- case SHADER_TYPE_COMPUTE: VERIFY_EXPR(ShaderIndex == 5); break;
- case SHADER_TYPE_AMPLIFICATION: VERIFY_EXPR(ShaderIndex == 6); break;
- case SHADER_TYPE_MESH: VERIFY_EXPR(ShaderIndex == 7); break;
- // clang-format on
- default: UNEXPECTED("Unexpected shader type (", Type, ")"); break;
- }
- VERIFY(Type == GetShaderTypeFromIndex(ShaderIndex), "Incorrect shader type index");
-#endif
- return ShaderIndex;
-}
-
-static const int VSInd = GetShaderTypeIndex(SHADER_TYPE_VERTEX);
-static const int PSInd = GetShaderTypeIndex(SHADER_TYPE_PIXEL);
-static const int GSInd = GetShaderTypeIndex(SHADER_TYPE_GEOMETRY);
-static const int HSInd = GetShaderTypeIndex(SHADER_TYPE_HULL);
-static const int DSInd = GetShaderTypeIndex(SHADER_TYPE_DOMAIN);
-static const int CSInd = GetShaderTypeIndex(SHADER_TYPE_COMPUTE);
-static const int ASInd = GetShaderTypeIndex(SHADER_TYPE_AMPLIFICATION);
-static const int MSInd = GetShaderTypeIndex(SHADER_TYPE_MESH);
-
-
/// Template class implementing base functionality for a shader object
/// \tparam BaseInterface - base interface that this class will inheret
diff --git a/Graphics/GraphicsEngine/include/ShaderResourceBindingBase.hpp b/Graphics/GraphicsEngine/include/ShaderResourceBindingBase.hpp
index 60992189..30546842 100644
--- a/Graphics/GraphicsEngine/include/ShaderResourceBindingBase.hpp
+++ b/Graphics/GraphicsEngine/include/ShaderResourceBindingBase.hpp
@@ -30,10 +30,14 @@
/// \file
/// Implementation of the Diligent::ShaderResourceBindingBase template class
+#include <array>
+
#include "ShaderResourceBinding.h"
#include "ObjectBase.hpp"
#include "GraphicsTypes.h"
+#include "Constants.h"
#include "RefCntAutoPtr.hpp"
+#include "GraphicsAccessories.hpp"
namespace Diligent
{
@@ -80,6 +84,69 @@ public:
}
protected:
+ Int8 GetVariableByNameHelper(SHADER_TYPE ShaderType, const char* Name, const std::array<Int8, MAX_SHADERS_IN_PIPELINE>& ResourceLayoutIndex) const
+ {
+ const auto PipelineType = m_pPSO->GetDesc().PipelineType;
+ if (!IsConsistentShaderType(ShaderType, PipelineType))
+ {
+ LOG_WARNING_MESSAGE("Unable to find mutable/dynamic variable '", Name, "' in shader stage ", GetShaderTypeLiteralName(ShaderType),
+ " as the stage is invalid for ", GetPipelineTypeString(m_pPSO->GetDesc().PipelineType), " pipeline '", m_pPSO->GetDesc().Name, "'");
+ return -1;
+ }
+
+ const auto ShaderInd = GetShaderTypePipelineIndex(ShaderType, PipelineType);
+ const auto ResLayoutInd = ResourceLayoutIndex[ShaderInd];
+ if (ResLayoutInd < 0)
+ {
+ LOG_WARNING_MESSAGE("Unable to find mutable/dynamic variable '", Name, "' in shader stage ", GetShaderTypeLiteralName(ShaderType),
+ " as the stage is inactive in PSO '", m_pPSO->GetDesc().Name, "'");
+ }
+
+ return ResLayoutInd;
+ }
+
+ Int8 GetVariableCountHelper(SHADER_TYPE ShaderType, const std::array<Int8, MAX_SHADERS_IN_PIPELINE>& ResourceLayoutIndex) const
+ {
+ const auto PipelineType = m_pPSO->GetDesc().PipelineType;
+ if (!IsConsistentShaderType(ShaderType, PipelineType))
+ {
+ LOG_WARNING_MESSAGE("Unable to get the number of mutable/dynamic variables in shader stage ", GetShaderTypeLiteralName(ShaderType),
+ " as the stage is invalid for ", GetPipelineTypeString(m_pPSO->GetDesc().PipelineType), " pipeline '", m_pPSO->GetDesc().Name, "'");
+ return -1;
+ }
+
+ const auto ShaderInd = GetShaderTypePipelineIndex(ShaderType, PipelineType);
+ const auto ResLayoutInd = ResourceLayoutIndex[ShaderInd];
+ if (ResLayoutInd < 0)
+ {
+ LOG_WARNING_MESSAGE("Unable to get the number of mutable/dynamic variables in shader stage ", GetShaderTypeLiteralName(ShaderType),
+ " as the stage is inactive in PSO '", m_pPSO->GetDesc().Name, "'");
+ }
+
+ return ResLayoutInd;
+ }
+
+ Int8 GetVariableByIndexHelper(SHADER_TYPE ShaderType, Uint32 Index, const std::array<Int8, MAX_SHADERS_IN_PIPELINE>& ResourceLayoutIndex)
+ {
+ const auto PipelineType = m_pPSO->GetDesc().PipelineType;
+ if (!IsConsistentShaderType(ShaderType, PipelineType))
+ {
+ LOG_WARNING_MESSAGE("Unable to get mutable/dynamic variable at index ", Index, " in shader stage ", GetShaderTypeLiteralName(ShaderType),
+ " as the stage is invalid for ", GetPipelineTypeString(m_pPSO->GetDesc().PipelineType), " pipeline '", m_pPSO->GetDesc().Name, "'");
+ return -1;
+ }
+
+ const auto ShaderInd = GetShaderTypePipelineIndex(ShaderType, PipelineType);
+ const auto ResLayoutInd = ResourceLayoutIndex[ShaderInd];
+ if (ResLayoutInd < 0)
+ {
+ LOG_WARNING_MESSAGE("Unable to get mutable/dynamic variable at index ", Index, " in shader stage ", GetShaderTypeLiteralName(ShaderType),
+ " as the stage is inactive in PSO '", m_pPSO->GetDesc().Name, "'");
+ }
+
+ return ResLayoutInd;
+ }
+
/// Strong reference to PSO. We must use strong reference, because
/// shader resource binding uses PSO's memory allocator to allocate
/// memory for shader resource cache.
diff --git a/Graphics/GraphicsEngine/interface/Constants.h b/Graphics/GraphicsEngine/interface/Constants.h
index 419d6862..9cd45c4d 100644
--- a/Graphics/GraphicsEngine/interface/Constants.h
+++ b/Graphics/GraphicsEngine/interface/Constants.h
@@ -51,12 +51,9 @@ static const Uint32 MAX_RENDER_TARGETS = DILIGENT_MAX_RENDER_TARGETS;
static const Uint32 MAX_VIEWPORTS = DILIGENT_MAX_VIEWPORTS;
/// Maximum number of shader stages in a pipeline.
-/// (Vertex, Pixel, Geometry, Domain, Hull) or (Amplification, Mesh, Pixel)
+/// (Vertex, Hull, Domain, Geometry, Pixel) or (Amplification, Mesh, Pixel), or (Compute)
static const Uint32 MAX_SHADERS_IN_PIPELINE = 5;
-///// Number of different shader types (Vertex, Pixel, Geometry, Domain, Hull, Compute, Amplification, Mesh)
-static const Uint32 NUM_SHADER_TYPES = 8;
-
// clang-format on
DILIGENT_END_NAMESPACE // namespace Diligent