diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2021-03-11 04:58:49 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2021-03-19 00:38:20 +0000 |
| commit | 6e54a0840da780c3b208bc72294aa33eecc64738 (patch) | |
| tree | 2b3cd3d88cf89a3fb7e16a73692c25af15f2273a /Graphics/GraphicsEngine | |
| parent | Vk backend: moved resource binding logic to variable manager and cache (diff) | |
| download | DiligentCore-6e54a0840da780c3b208bc72294aa33eecc64738.tar.gz DiligentCore-6e54a0840da780c3b208bc72294aa33eecc64738.zip | |
Moved duplicate shader variable functionality to ShaderVariableBase
Diffstat (limited to 'Graphics/GraphicsEngine')
| -rw-r--r-- | Graphics/GraphicsEngine/include/ShaderResourceVariableBase.hpp | 48 |
1 files changed, 44 insertions, 4 deletions
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 <typename VarManagerType, +template <typename ThisImplType, + typename VarManagerType, typename ResourceVariableBaseInterface = IShaderResourceVariable> 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 <typename ThisImplType> + virtual void DILIGENT_CALL_TYPE Set(IDeviceObject* pObject) override final + { + static_cast<ThisImplType*>(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<ThisImplType*>(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<const ThisImplType*>(this)); + } + void BindResources(IResourceMapping* pResourceMapping, Uint32 Flags) { auto* const pThis = static_cast<ThisImplType*>(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 |
