From 6e54a0840da780c3b208bc72294aa33eecc64738 Mon Sep 17 00:00:00 2001 From: assiduous Date: Wed, 10 Mar 2021 20:58:49 -0800 Subject: Moved duplicate shader variable functionality to ShaderVariableBase --- .../include/ShaderResourceVariableBase.hpp | 48 ++++++++++++++++++++-- 1 file changed, 44 insertions(+), 4 deletions(-) (limited to 'Graphics/GraphicsEngine') diff --git a/Graphics/GraphicsEngine/include/ShaderResourceVariableBase.hpp b/Graphics/GraphicsEngine/include/ShaderResourceVariableBase.hpp index 7b8115a9..e35cdb96 100644 --- a/Graphics/GraphicsEngine/include/ShaderResourceVariableBase.hpp +++ b/Graphics/GraphicsEngine/include/ShaderResourceVariableBase.hpp @@ -493,12 +493,14 @@ std::string GetShaderGroupName(const ShaderVectorType& Shaders) } /// Base implementation of a shader variable -template struct ShaderVariableBase : public ResourceVariableBaseInterface { - ShaderVariableBase(VarManagerType& ParentManager) : - m_ParentManager{ParentManager} + ShaderVariableBase(VarManagerType& ParentManager, Uint32 ResIndex) : + m_ParentManager{ParentManager}, + m_ResIndex{ResIndex} { } @@ -530,7 +532,39 @@ struct ShaderVariableBase : public ResourceVariableBaseInterface return m_ParentManager.GetOwner().GetReferenceCounters(); } - template + virtual void DILIGENT_CALL_TYPE Set(IDeviceObject* pObject) override final + { + static_cast(this)->BindResource(pObject, 0); + } + + virtual void DILIGENT_CALL_TYPE SetArray(IDeviceObject* const* ppObjects, + Uint32 FirstElement, + Uint32 NumElements) override final + { + const auto& Desc = GetDesc(); + VerifyAndCorrectSetArrayArguments(Desc.Name, Desc.ArraySize, FirstElement, NumElements); + for (Uint32 elem = 0; elem < NumElements; ++elem) + static_cast(this)->BindResource(ppObjects[elem], FirstElement + elem); + } + + virtual SHADER_RESOURCE_VARIABLE_TYPE DILIGENT_CALL_TYPE GetType() const override final + { + return GetDesc().VarType; + } + + virtual void DILIGENT_CALL_TYPE GetResourceDesc(ShaderResourceDesc& ResourceDesc) const override final + { + const auto& Desc = GetDesc(); + ResourceDesc.Name = Desc.Name; + ResourceDesc.Type = Desc.ResourceType; + ResourceDesc.ArraySize = Desc.ArraySize; + } + + virtual Uint32 DILIGENT_CALL_TYPE GetIndex() const override final + { + return m_ParentManager.GetVariableIndex(*static_cast(this)); + } + void BindResources(IResourceMapping* pResourceMapping, Uint32 Flags) { auto* const pThis = static_cast(this); @@ -564,8 +598,14 @@ struct ShaderVariableBase : public ResourceVariableBaseInterface } } + const PipelineResourceDesc& GetDesc() const { return m_ParentManager.GetResourceDesc(m_ResIndex); } + protected: + // Variable manager that owns this variable VarManagerType& m_ParentManager; + + // Resource index in pipeline resource signature m_Desc.Resources[] + const Uint32 m_ResIndex; }; } // namespace Diligent -- cgit v1.2.3