From d40df7d9e6b15c3aac87fe78d2bafd3f868c5352 Mon Sep 17 00:00:00 2001 From: assiduous Date: Wed, 24 Feb 2021 19:23:36 -0800 Subject: Reworked ShaderVariableVkImpl and ShaderVariableD3D12Impl: removed some duplicate code --- .../include/ShaderResourceVariableBase.hpp | 63 +++++++++++++++------- 1 file changed, 44 insertions(+), 19 deletions(-) (limited to 'Graphics/GraphicsEngine') diff --git a/Graphics/GraphicsEngine/include/ShaderResourceVariableBase.hpp b/Graphics/GraphicsEngine/include/ShaderResourceVariableBase.hpp index edd850d1..7b8115a9 100644 --- a/Graphics/GraphicsEngine/include/ShaderResourceVariableBase.hpp +++ b/Graphics/GraphicsEngine/include/ShaderResourceVariableBase.hpp @@ -492,32 +492,23 @@ std::string GetShaderGroupName(const ShaderVectorType& Shaders) return Name; } -struct DefaultShaderVariableIDComparator -{ - bool operator()(const INTERFACE_ID& IID) const - { - return IID == IID_ShaderResourceVariable || IID == IID_Unknown; - } // namespace Diligent -}; - /// Base implementation of a shader variable -template +template struct ShaderVariableBase : public ResourceVariableBaseInterface { - ShaderVariableBase(ResourceLayoutType& ParentResLayout) : - m_ParentResLayout{ParentResLayout} + ShaderVariableBase(VarManagerType& ParentManager) : + m_ParentManager{ParentManager} { } - virtual void DILIGENT_CALL_TYPE QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override final + virtual void DILIGENT_CALL_TYPE QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface) override { if (ppInterface == nullptr) return; *ppInterface = nullptr; - if (VariableIDComparator{}(IID)) + if (IID == IID_ShaderResourceVariable || IID == IID_Unknown) { *ppInterface = this; (*ppInterface)->AddRef(); @@ -526,21 +517,55 @@ struct ShaderVariableBase : public ResourceVariableBaseInterface virtual Atomics::Long DILIGENT_CALL_TYPE AddRef() override final { - return m_ParentResLayout.GetOwner().AddRef(); + return m_ParentManager.GetOwner().AddRef(); } virtual Atomics::Long DILIGENT_CALL_TYPE Release() override final { - return m_ParentResLayout.GetOwner().Release(); + return m_ParentManager.GetOwner().Release(); } virtual IReferenceCounters* DILIGENT_CALL_TYPE GetReferenceCounters() const override final { - return m_ParentResLayout.GetOwner().GetReferenceCounters(); + return m_ParentManager.GetOwner().GetReferenceCounters(); + } + + template + void BindResources(IResourceMapping* pResourceMapping, Uint32 Flags) + { + auto* const pThis = static_cast(this); + + const auto& ResDesc = pThis->GetDesc(); + + if ((Flags & (1u << ResDesc.VarType)) == 0) + return; + + for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd) + { + if ((Flags & BIND_SHADER_RESOURCES_KEEP_EXISTING) != 0 && pThis->IsBound(ArrInd)) + continue; + + RefCntAutoPtr pObj; + pResourceMapping->GetResource(ResDesc.Name, &pObj, ArrInd); + if (pObj) + { + pThis->BindResource(pObj, ArrInd); + } + else + { + if ((Flags & BIND_SHADER_RESOURCES_VERIFY_ALL_RESOLVED) && !pThis->IsBound(ArrInd)) + { + LOG_ERROR_MESSAGE("Unable to bind resource to shader variable '", + GetShaderResourcePrintName(ResDesc, ArrInd), + "': resource is not found in the resource mapping. " + "Do not use BIND_SHADER_RESOURCES_VERIFY_ALL_RESOLVED flag to suppress the message if this is not an issue."); + } + } + } } protected: - ResourceLayoutType& m_ParentResLayout; + VarManagerType& m_ParentManager; }; } // namespace Diligent -- cgit v1.2.3