From a0488c54c6c5017c71198d8b13c9ed75894791de Mon Sep 17 00:00:00 2001 From: azhirnov Date: Wed, 16 Sep 2020 22:41:57 +0300 Subject: use NUM_SHADER_TYPES constant instead of magic number, use std::array instead of c-style array. --- Graphics/GraphicsEngine/include/PipelineStateBase.hpp | 6 +++--- Graphics/GraphicsEngine/include/ShaderBase.hpp | 3 +++ Graphics/GraphicsEngine/interface/Constants.h | 4 ++++ 3 files changed, 10 insertions(+), 3 deletions(-) (limited to 'Graphics/GraphicsEngine') diff --git a/Graphics/GraphicsEngine/include/PipelineStateBase.hpp b/Graphics/GraphicsEngine/include/PipelineStateBase.hpp index 02a74f85..4d2e408f 100644 --- a/Graphics/GraphicsEngine/include/PipelineStateBase.hpp +++ b/Graphics/GraphicsEngine/include/PipelineStateBase.hpp @@ -406,7 +406,7 @@ public: IShader* GetHS() { return m_pHS; } IShader* GetCS() { return m_pCS; } - IShader* const* GetShaders() const { return m_ppShaders; } + IShader* const* GetShaders() const { return m_ppShaders.data(); } Uint32 GetNumShaders() const { return m_NumShaders; } template @@ -447,8 +447,8 @@ protected: RefCntAutoPtr m_pRenderPass; ///< Strong reference to the render pass object - IShader* m_ppShaders[MAX_SHADERS_IN_PIPELINE] = {}; ///< Array of pointers to the shaders used by this PSO - size_t m_ShaderResourceLayoutHash = 0; ///< Hash computed from the shader resource layout + std::array m_ppShaders = {}; ///< Array of pointers to the shaders used by this PSO + size_t m_ShaderResourceLayoutHash = 0; ///< Hash computed from the shader resource layout 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 5b39da79..3beaa9c8 100644 --- a/Graphics/GraphicsEngine/include/ShaderBase.hpp +++ b/Graphics/GraphicsEngine/include/ShaderBase.hpp @@ -38,10 +38,13 @@ #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(1 << Index); diff --git a/Graphics/GraphicsEngine/interface/Constants.h b/Graphics/GraphicsEngine/interface/Constants.h index dfd17c45..419d6862 100644 --- a/Graphics/GraphicsEngine/interface/Constants.h +++ b/Graphics/GraphicsEngine/interface/Constants.h @@ -51,8 +51,12 @@ 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) 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 -- cgit v1.2.3