From ecd151d725ec446be7718995ed110de1678d7d8f Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Tue, 26 Jun 2018 21:14:20 -0700 Subject: Reworked shader memory alloction for resource layouts in D3D12 pipeline implementation --- Graphics/GraphicsEngine/include/PipelineStateBase.h | 21 ++++++++++++++++----- Graphics/GraphicsEngine/interface/PipelineState.h | 15 ++++++--------- 2 files changed, 22 insertions(+), 14 deletions(-) (limited to 'Graphics/GraphicsEngine') diff --git a/Graphics/GraphicsEngine/include/PipelineStateBase.h b/Graphics/GraphicsEngine/include/PipelineStateBase.h index 77c82cf5..80813fba 100644 --- a/Graphics/GraphicsEngine/include/PipelineStateBase.h +++ b/Graphics/GraphicsEngine/include/PipelineStateBase.h @@ -60,8 +60,6 @@ public: m_LayoutElements( PSODesc.GraphicsPipeline.InputLayout.NumElements, LayoutElement(), STD_ALLOCATOR_RAW_MEM(LayoutElement, GetRawAllocator(), "Allocator for vector" ) ), m_NumShaders(0) { - memset(m_ppShaders, 0, sizeof(m_ppShaders)); - if (this->m_Desc.IsComputePipeline) { const auto &ComputePipeline = PSODesc.ComputePipeline; @@ -73,7 +71,7 @@ public: #define VALIDATE_SHADER_TYPE(Shader, ExpectedType, ShaderName)\ if (Shader && Shader->GetDesc().ShaderType != ExpectedType) \ { \ - LOG_ERROR_AND_THROW( GetShaderTypeLiteralName(Shader->GetDesc().ShaderType), " is not valid type for ", ShaderName, " shader" );\ + LOG_ERROR_AND_THROW( GetShaderTypeLiteralName(Shader->GetDesc().ShaderType), " is not a valid type for ", ShaderName, " shader" );\ } VALIDATE_SHADER_TYPE(ComputePipeline.pCS, SHADER_TYPE_COMPUTE, "compute") @@ -208,6 +206,19 @@ public: IShader* const* GetShaders()const{return m_ppShaders;} Uint32 GetNumShaders()const{return m_NumShaders;} + template + ShaderType* GetShader(Uint32 ShaderInd) + { + VERIFY_EXPR(ShaderInd < m_NumShaders); + return ValidatedCast(m_ppShaders[ShaderInd]); + } + template + ShaderType* GetShader(Uint32 ShaderInd)const + { + VERIFY_EXPR(ShaderInd < m_NumShaders); + return ValidatedCast(m_ppShaders[ShaderInd]); + } + // This function only compares shader resource layout hashes, so // it can potentially give false negatives bool IsIncompatibleWith(IPipelineState *pPSO)const @@ -230,8 +241,8 @@ protected: RefCntAutoPtr m_pDS; ///< Strong reference to the domain shader RefCntAutoPtr m_pHS; ///< Strong reference to the hull shader RefCntAutoPtr m_pCS; ///< Strong reference to the compute shader - IShader *m_ppShaders[5]; ///< Array of pointers to shaders that this PSO uses - Uint32 m_NumShaders; ///< Number of shaders that this PSO uses + IShader* m_ppShaders[5] = {}; ///< Array of pointers to the shaders used by this PSO + Uint32 m_NumShaders = 0; ///< Number of shaders that this PSO uses size_t m_ShaderResourceLayoutHash = 0;///< Hash computed from the shader resource layout }; diff --git a/Graphics/GraphicsEngine/interface/PipelineState.h b/Graphics/GraphicsEngine/interface/PipelineState.h index 34962f2e..0c642f3f 100644 --- a/Graphics/GraphicsEngine/interface/PipelineState.h +++ b/Graphics/GraphicsEngine/interface/PipelineState.h @@ -62,19 +62,19 @@ struct SampleDesc struct GraphicsPipelineDesc { /// Vertex shader to be used with the pipeline - IShader *pVS = nullptr; + IShader* pVS = nullptr; /// Pixel shader to be used with the pipeline - IShader *pPS = nullptr; + IShader* pPS = nullptr; /// Domain shader to be used with the pipeline - IShader *pDS = nullptr; + IShader* pDS = nullptr; /// Hull shader to be used with the pipeline - IShader *pHS = nullptr; + IShader* pHS = nullptr; /// Geometry shader to be used with the pipeline - IShader *pGS = nullptr; + IShader* pGS = nullptr; //D3D12_STREAM_OUTPUT_DESC StreamOutput; @@ -136,10 +136,7 @@ struct GraphicsPipelineDesc struct ComputePipelineDesc { /// Compute shader to be used with the pipeline - IShader *pCS; - ComputePipelineDesc() : - pCS(nullptr) - {} + IShader* pCS = nullptr; }; /// Pipeline state description -- cgit v1.2.3