From 72d2e4a6482150ee61b3124de546af1ec5a0bf38 Mon Sep 17 00:00:00 2001 From: assiduous Date: Fri, 5 Mar 2021 23:00:47 -0800 Subject: Moved GetResourceAttribution() function to PipelineStateBase to eliminate duplication --- .../GraphicsEngine/include/PipelineStateBase.hpp | 71 ++++++++++++++++++++++ .../include/PipelineStateD3D12Impl.hpp | 50 ++------------- .../src/DeviceContextD3D12Impl.cpp | 2 +- .../src/PipelineStateD3D12Impl.cpp | 23 ------- .../include/PipelineResourceSignatureGLImpl.hpp | 12 ++-- .../include/PipelineStateGLImpl.hpp | 51 +--------------- .../src/DeviceContextGLImpl.cpp | 4 +- .../src/PipelineResourceSignatureGLImpl.cpp | 60 +++++++++--------- .../src/PipelineStateGLImpl.cpp | 34 +++-------- 9 files changed, 127 insertions(+), 180 deletions(-) (limited to 'Graphics') diff --git a/Graphics/GraphicsEngine/include/PipelineStateBase.hpp b/Graphics/GraphicsEngine/include/PipelineStateBase.hpp index 558daf29..f831f4ea 100644 --- a/Graphics/GraphicsEngine/include/PipelineStateBase.hpp +++ b/Graphics/GraphicsEngine/include/PipelineStateBase.hpp @@ -43,6 +43,7 @@ #include "GraphicsAccessories.hpp" #include "FixedLinearAllocator.hpp" #include "HashUtils.hpp" +#include "PipelineResourceSignatureBase.hpp" namespace Diligent { @@ -94,6 +95,12 @@ private: // Render device implementation type (RenderDeviceD3D12Impl, RenderDeviceVkImpl, etc.). using RenderDeviceImplType = typename EngineImplTraits::RenderDeviceImplType; + // Pipeline state implementation type (PipelineStateD3D12Impl, PipelineStateVkImpl, etc.). + using PipelineStateImplType = typename EngineImplTraits::PipelineStateImplType; + + // Pipeline resource signature implementation type (PipelineResourceSignatureD3D12Impl, PipelineResourceSignatureVkImpl, etc.). + using PipelineResourceSignatureImplType = typename EngineImplTraits::PipelineResourceSignatureImplType; + using TDeviceObjectBase = DeviceObjectBase; /// \param pRefCounters - Reference counters object that controls the lifetime of this PSO @@ -751,6 +758,70 @@ protected: CopyResourceLayout(CreateInfo.PSODesc.ResourceLayout, this->m_Desc.ResourceLayout, MemPool); } + + // Resource attribution properties + struct ResourceAttribution + { + static constexpr Uint32 InvalidSignatureIndex = ~0u; + static constexpr Uint32 InvalidResourceIndex = PipelineResourceSignatureImplType::InvalidResourceIndex; + static constexpr Uint32 InvalidSamplerIndex = InvalidImmutableSamplerIndex; + + const PipelineResourceSignatureImplType* pSignature = nullptr; + + Uint32 SignatureIndex = InvalidSignatureIndex; + Uint32 ResourceIndex = InvalidResourceIndex; + Uint32 ImmutableSamplerIndex = InvalidSamplerIndex; + + ResourceAttribution() noexcept {} + ResourceAttribution(const PipelineResourceSignatureImplType* _pSignature, + Uint32 _SignatureIndex, + Uint32 _ResourceIndex, + Uint32 _ImmutableSamplerIndex = InvalidResourceIndex) noexcept : + pSignature{_pSignature}, + SignatureIndex{_SignatureIndex}, + ResourceIndex{_ResourceIndex}, + ImmutableSamplerIndex{_ImmutableSamplerIndex} + { + VERIFY_EXPR(pSignature == nullptr || pSignature->GetDesc().BindingIndex == SignatureIndex); + VERIFY_EXPR((ResourceIndex == InvalidResourceIndex) || (ImmutableSamplerIndex == InvalidSamplerIndex)); + } + + explicit operator bool() const + { + return ((SignatureIndex != InvalidSignatureIndex) && + (ResourceIndex != InvalidResourceIndex || ImmutableSamplerIndex != InvalidSamplerIndex)); + } + + bool IsImmutableSampler() const + { + return operator bool() && ImmutableSamplerIndex != InvalidSamplerIndex; + } + }; + + ResourceAttribution GetResourceAttribution(const char* Name, SHADER_TYPE Stage) const + { + const auto* const pThis = static_cast(this); + + const auto SignCount = pThis->GetResourceSignatureCount(); + for (Uint32 sign = 0; sign < SignCount; ++sign) + { + const PipelineResourceSignatureImplType* const pSignature = pThis->GetResourceSignature(sign); + if (pSignature == nullptr) + continue; + + const auto ResIndex = pSignature->FindResource(Stage, Name); + if (ResIndex != ResourceAttribution::InvalidResourceIndex) + return ResourceAttribution{pSignature, sign, ResIndex}; + else + { + const auto ImtblSamIndex = pSignature->FindImmutableSampler(Stage, Name); + if (ImtblSamIndex != ResourceAttribution::InvalidSamplerIndex) + return ResourceAttribution{pSignature, sign, ResourceAttribution::InvalidResourceIndex, ImtblSamIndex}; + } + } + return ResourceAttribution{}; + } + private: static void ReserveResourceLayout(const PipelineResourceLayoutDesc& SrcLayout, FixedLinearAllocator& MemPool) noexcept { diff --git a/Graphics/GraphicsEngineD3D12/include/PipelineStateD3D12Impl.hpp b/Graphics/GraphicsEngineD3D12/include/PipelineStateD3D12Impl.hpp index 84d9dccd..4c0f954b 100644 --- a/Graphics/GraphicsEngineD3D12/include/PipelineStateD3D12Impl.hpp +++ b/Graphics/GraphicsEngineD3D12/include/PipelineStateD3D12Impl.hpp @@ -64,7 +64,11 @@ public: virtual Uint32 DILIGENT_CALL_TYPE GetResourceSignatureCount() const override final { return m_RootSig->GetSignatureCount(); } /// Implementation of IPipelineState::GetResourceSignature() in Direct3D12 backend. - virtual IPipelineResourceSignature* DILIGENT_CALL_TYPE GetResourceSignature(Uint32 Index) const override final { return GetSignature(Index); } + virtual PipelineResourceSignatureD3D12Impl* DILIGENT_CALL_TYPE GetResourceSignature(Uint32 Index) const override final + { + VERIFY_EXPR(Index < GetResourceSignatureCount()); + return m_ResourceSignatures[Index]; + } /// Implementation of IPipelineStateD3D12::GetD3D12PipelineState(). virtual ID3D12PipelineState* DILIGENT_CALL_TYPE GetD3D12PipelineState() const override final { return static_cast(m_pd3d12PSO.p); } @@ -77,12 +81,6 @@ public: const RootSignatureD3D12& GetRootSignature() const { return *m_RootSig; } - PipelineResourceSignatureD3D12Impl* GetSignature(Uint32 index) const - { - VERIFY_EXPR(index < GetResourceSignatureCount()); - return m_ResourceSignatures[index]; - } - #ifdef DILIGENT_DEVELOPMENT void DvpVerifySRBResources(ShaderResourceBindingD3D12Impl* pSRBs[], Uint32 NumSRBs) const; #endif @@ -121,44 +119,6 @@ private: void Destruct(); - struct ResourceAttribution - { - static constexpr Uint32 InvalidSignatureIndex = ~0u; - static constexpr Uint32 InvalidResourceIndex = PipelineResourceSignatureD3D12Impl::InvalidResourceIndex; - static constexpr Uint32 InvalidSamplerIndex = InvalidImmutableSamplerIndex; - - const PipelineResourceSignatureD3D12Impl* pSignature = nullptr; - - Uint32 SignatureIndex = InvalidSignatureIndex; - Uint32 ResourceIndex = InvalidResourceIndex; - Uint32 ImmutableSamplerIndex = InvalidSamplerIndex; - - ResourceAttribution() noexcept {} - ResourceAttribution(const PipelineResourceSignatureD3D12Impl* _pSignature, - Uint32 _SignatureIndex, - Uint32 _ResourceIndex, - Uint32 _ImmutableSamplerIndex = InvalidResourceIndex) noexcept : - pSignature{_pSignature}, - SignatureIndex{_SignatureIndex}, - ResourceIndex{_ResourceIndex}, - ImmutableSamplerIndex{_ImmutableSamplerIndex} - { - VERIFY_EXPR(pSignature == nullptr || pSignature->GetDesc().BindingIndex == SignatureIndex); - VERIFY_EXPR((ResourceIndex == InvalidResourceIndex) || (ImmutableSamplerIndex == InvalidSamplerIndex)); - } - - explicit operator bool() const - { - return SignatureIndex != InvalidSignatureIndex && (ResourceIndex != InvalidResourceIndex || ImmutableSamplerIndex != InvalidSamplerIndex); - } - - bool IsImmutableSampler() const - { - return operator bool() && ImmutableSamplerIndex != InvalidSamplerIndex; - } - }; - ResourceAttribution GetResourceAttribution(const char* Name, SHADER_TYPE Stage) const; - void ValidateShaderResources(const ShaderD3D12Impl* pShader, const LocalRootSignatureD3D12* pLocalRootSig); private: diff --git a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp index b9a0f91e..864919d2 100644 --- a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp @@ -240,7 +240,7 @@ void DeviceContextD3D12Impl::SetPipelineState(IPipelineState* pPipelineState) for (Uint32 i = 0, SignCount = pPipelineStateD3D12->GetResourceSignatureCount(); i < SignCount; ++i) { - const auto* pSignature = pPipelineStateD3D12->GetSignature(i); + const auto* pSignature = pPipelineStateD3D12->GetResourceSignature(i); if (pSignature != nullptr) RootInfo.ActiveSRBMask |= 1u << i; } diff --git a/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp index fa70ddc6..f27d39dc 100644 --- a/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/PipelineStateD3D12Impl.cpp @@ -660,29 +660,6 @@ void PipelineStateD3D12Impl::InitRootSignature(const PipelineStateCreateInfo& Cr } } - -PipelineStateD3D12Impl::ResourceAttribution PipelineStateD3D12Impl::GetResourceAttribution(const char* Name, SHADER_TYPE Stage) const -{ - const auto SignCount = GetResourceSignatureCount(); - for (Uint32 sign = 0; sign < SignCount; ++sign) - { - const auto* const pSignature = GetSignature(sign); - if (pSignature == nullptr) - continue; - - const auto ResIndex = pSignature->FindResource(Stage, Name); - if (ResIndex != ResourceAttribution::InvalidResourceIndex) - return ResourceAttribution{pSignature, sign, ResIndex}; - else - { - const auto ImtblSamIndex = pSignature->FindImmutableSampler(Stage, Name); - if (ImtblSamIndex != ResourceAttribution::InvalidSamplerIndex) - return ResourceAttribution{pSignature, sign, ResourceAttribution::InvalidResourceIndex, ImtblSamIndex}; - } - } - return ResourceAttribution{}; -} - void PipelineStateD3D12Impl::ValidateShaderResources(const ShaderD3D12Impl* pShader, const LocalRootSignatureD3D12* pLocalRootSig) { const auto& pShaderResources = pShader->GetShaderResources(); diff --git a/Graphics/GraphicsEngineOpenGL/include/PipelineResourceSignatureGLImpl.hpp b/Graphics/GraphicsEngineOpenGL/include/PipelineResourceSignatureGLImpl.hpp index 3c2ad8ee..f4a4cefb 100644 --- a/Graphics/GraphicsEngineOpenGL/include/PipelineResourceSignatureGLImpl.hpp +++ b/Graphics/GraphicsEngineOpenGL/include/PipelineResourceSignatureGLImpl.hpp @@ -81,7 +81,7 @@ public: // clang-format off const Uint32 CacheOffset; // SRB and Signature use the same cache offsets for static resources. - // Binding = m_FirstBinding[Range] + CacheOffset + // Binding == BaseBinding[Range] + CacheOffset const Uint32 SamplerInd : _SamplerIndBits; // ImtblSamplerAssigned == true: index of the immutable sampler in m_ImmutableSamplers. // ImtblSamplerAssigned == false: index of the assigned sampler in m_Desc.Resources. const Uint32 ImtblSamplerAssigned : _SamplerAssignedBits; // Immutable sampler flag @@ -110,12 +110,6 @@ public: return m_pResourceAttribs[ResIndex]; } - const PipelineResourceDesc& GetResourceDesc(Uint32 ResIndex) const - { - VERIFY_EXPR(ResIndex < m_Desc.NumResources); - return m_Desc.Resources[ResIndex]; - } - bool HasDynamicResources() const { const auto IndexRange = GetResourceIndexRange(SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC); @@ -124,10 +118,12 @@ public: using TBindings = std::array; + // Applies bindings for resources in this signature to GLProgram. + // The bindings are biased by BaseBindings. void ApplyBindings(GLObjectWrappers::GLProgramObj& GLProgram, class GLContextState& State, SHADER_TYPE Stages, - const TBindings& Bindings) const; + const TBindings& BaseBindings) const; __forceinline void ShiftBindings(TBindings& Bindings) const { diff --git a/Graphics/GraphicsEngineOpenGL/include/PipelineStateGLImpl.hpp b/Graphics/GraphicsEngineOpenGL/include/PipelineStateGLImpl.hpp index 8b4b1e57..20f1965a 100644 --- a/Graphics/GraphicsEngineOpenGL/include/PipelineStateGLImpl.hpp +++ b/Graphics/GraphicsEngineOpenGL/include/PipelineStateGLImpl.hpp @@ -64,10 +64,10 @@ public: virtual Uint32 DILIGENT_CALL_TYPE GetResourceSignatureCount() const override final { return m_SignatureCount; } /// Implementation of IPipelineState::GetResourceSignature() in OpenGL backend. - virtual IPipelineResourceSignature* DILIGENT_CALL_TYPE GetResourceSignature(Uint32 Index) const override final + virtual PipelineResourceSignatureGLImpl* DILIGENT_CALL_TYPE GetResourceSignature(Uint32 Index) const override final { VERIFY_EXPR(Index < m_SignatureCount); - return m_Signatures[Index].RawPtr(); + return m_Signatures[Index].RawPtr(); } /// Implementation of IPipelineState::IsCompatibleWith() in OpenGL backend. @@ -75,15 +75,9 @@ public: void CommitProgram(GLContextState& State); - PipelineResourceSignatureGLImpl* GetSignature(Uint32 index) const - { - VERIFY_EXPR(index < m_SignatureCount); - return m_Signatures[index].RawPtr(); - } - #ifdef DILIGENT_DEVELOPMENT using TBindings = PipelineResourceSignatureGLImpl::TBindings; - void DvpVerifySRBResources(class ShaderResourceBindingGLImpl* pSRBs[], const TBindings BoundResOffsets[], Uint32 NumSRBs) const; + void DvpVerifySRBResources(class ShaderResourceBindingGLImpl* pSRBs[], const TBindings BaseBindings[], Uint32 NumSRBs) const; #endif private: @@ -108,45 +102,6 @@ private: SHADER_TYPE GetShaderStageType(Uint32 Index) const; Uint32 GetNumShaderStages() const { return m_NumPrograms; } - - struct ResourceAttribution - { - static constexpr Uint32 InvalidSignatureIndex = ~0u; - static constexpr Uint32 InvalidResourceIndex = PipelineResourceSignatureGLImpl::InvalidResourceIndex; - static constexpr Uint32 InvalidSamplerIndex = InvalidImmutableSamplerIndex; - - const PipelineResourceSignatureGLImpl* pSignature = nullptr; - - Uint32 SignatureIndex = InvalidSignatureIndex; - Uint32 ResourceIndex = InvalidResourceIndex; - Uint32 ImmutableSamplerIndex = InvalidSamplerIndex; - - ResourceAttribution() noexcept {} - ResourceAttribution(const PipelineResourceSignatureGLImpl* _pSignature, - Uint32 _SignatureIndex, - Uint32 _ResourceIndex, - Uint32 _ImmutableSamplerIndex = InvalidResourceIndex) noexcept : - pSignature{_pSignature}, - SignatureIndex{_SignatureIndex}, - ResourceIndex{_ResourceIndex}, - ImmutableSamplerIndex{_ImmutableSamplerIndex} - { - VERIFY_EXPR(pSignature == nullptr || pSignature->GetDesc().BindingIndex == SignatureIndex); - VERIFY_EXPR((ResourceIndex == InvalidResourceIndex) || (ImmutableSamplerIndex == InvalidSamplerIndex)); - } - - explicit operator bool() const - { - return SignatureIndex != InvalidSignatureIndex && (ResourceIndex != InvalidResourceIndex || ImmutableSamplerIndex != InvalidSamplerIndex); - } - - bool IsImmutableSampler() const - { - return operator bool() && ImmutableSamplerIndex != InvalidSamplerIndex; - } - }; - ResourceAttribution GetResourceAttribution(const char* Name, SHADER_TYPE Stage) const; - void ValidateShaderResources(std::shared_ptr pShaderResources, const char* ShaderName, SHADER_TYPE ShaderStages); private: diff --git a/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp index 36b6df70..d57de1f7 100644 --- a/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp @@ -159,7 +159,7 @@ void DeviceContextGLImpl::SetPipelineState(IPipelineState* pPipelineState) m_BindInfo.ActiveSRBMask = 0; for (Uint32 s = 0; s < SignCount; ++s) { - const auto* pLayoutSign = m_pPipelineState->GetSignature(s); + const auto* pLayoutSign = m_pPipelineState->GetResourceSignature(s); if (pLayoutSign == nullptr || pLayoutSign->GetTotalResourceCount() == 0) continue; @@ -171,7 +171,7 @@ void DeviceContextGLImpl::SetPipelineState(IPipelineState* pPipelineState) Uint32 sign = 0; for (; sign < SignCount; ++sign) { - const auto* pLayoutSign = m_pPipelineState->GetSignature(sign); + const auto* pLayoutSign = m_pPipelineState->GetResourceSignature(sign); const auto* pSRBSign = m_BindInfo.SRBs[sign] != nullptr ? m_BindInfo.SRBs[sign]->GetSignature() : nullptr; if ((pLayoutSign == nullptr || pLayoutSign->GetTotalResourceCount() == 0) != (pSRBSign == nullptr || pSRBSign->GetTotalResourceCount() == 0)) diff --git a/Graphics/GraphicsEngineOpenGL/src/PipelineResourceSignatureGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/PipelineResourceSignatureGLImpl.cpp index f853252c..60cae558 100644 --- a/Graphics/GraphicsEngineOpenGL/src/PipelineResourceSignatureGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/PipelineResourceSignatureGLImpl.cpp @@ -103,7 +103,7 @@ BINDING_RANGE PipelineResourceToBindingRange(const PipelineResourceDesc& Desc) case SHADER_RESOURCE_TYPE_TEXTURE_UAV: return BINDING_RANGE_IMAGE; case SHADER_RESOURCE_TYPE_BUFFER_UAV: return (Desc.Flags & PIPELINE_RESOURCE_FLAG_FORMATTED_BUFFER) ? BINDING_RANGE_IMAGE : BINDING_RANGE_STORAGE_BUFFER; case SHADER_RESOURCE_TYPE_INPUT_ATTACHMENT: return BINDING_RANGE_TEXTURE; - // clang-format on + // clang-format on case SHADER_RESOURCE_TYPE_SAMPLER: case SHADER_RESOURCE_TYPE_ACCEL_STRUCT: default: @@ -205,11 +205,6 @@ void PipelineResourceSignatureGLImpl::CreateLayouts() if (ResDesc.ResourceType == SHADER_RESOURCE_TYPE_SAMPLER) { Int32 ImtblSamplerIdx = FindImmutableSampler(ResDesc.ShaderStages, ResDesc.Name); - if (ImtblSamplerIdx < 0) - { - LOG_WARNING_MESSAGE("Pipeline resource signature '", m_Desc.Name, "' has separate sampler with name '", ResDesc.Name, "' that is not supported in OpenGL."); - } - new (m_pResourceAttribs + i) ResourceAttribs // { ResourceAttribs::InvalidCacheOffset, @@ -222,27 +217,27 @@ void PipelineResourceSignatureGLImpl::CreateLayouts() const auto Range = PipelineResourceToBindingRange(ResDesc); VERIFY_EXPR(Range != BINDING_RANGE_UNKNOWN); - const Uint32 CacheOffset = m_BindingCount[Range]; - Uint32 SamplerIdx = ResourceAttribs::InvalidSamplerInd; - Int32 ImtblSamplerIdx = -1; + Uint32& CacheOffset = m_BindingCount[Range]; + Uint32 SamplerIdx = ResourceAttribs::InvalidSamplerInd; + Int32 ImtblSamplerIdx = -1; if (ResDesc.ResourceType == SHADER_RESOURCE_TYPE_TEXTURE_SRV) { ImtblSamplerIdx = FindImmutableSampler(ResDesc.ShaderStages, ResDesc.Name); - if (ImtblSamplerIdx < 0) - SamplerIdx = FindAssignedSampler(ResDesc, ResourceAttribs::InvalidSamplerInd); - else + if (ImtblSamplerIdx >= 0) SamplerIdx = static_cast(ImtblSamplerIdx); + else + SamplerIdx = FindAssignedSampler(ResDesc, ResourceAttribs::InvalidSamplerInd); } new (m_pResourceAttribs + i) ResourceAttribs // { CacheOffset, SamplerIdx, - ImtblSamplerIdx >= 0 // + ImtblSamplerIdx >= 0 // _ImtblSamplerAssigned }; - m_BindingCount[Range] += ResDesc.ArraySize; + CacheOffset += ResDesc.ArraySize; if (ResDesc.VarType == SHADER_RESOURCE_VARIABLE_TYPE_STATIC) StaticCounter[Range] += ResDesc.ArraySize; @@ -263,12 +258,12 @@ void PipelineResourceSignatureGLImpl::CreateLayouts() if (ResDesc.ResourceType != SHADER_RESOURCE_TYPE_TEXTURE_SRV || !ResAttr.IsSamplerAssigned()) continue; - ISampler* Sampler = nullptr; + ISampler* pSampler = nullptr; if (ResAttr.IsImmutableSamplerAssigned()) { VERIFY_EXPR(ResAttr.SamplerInd < GetImmutableSamplerCount()); - Sampler = m_ImmutableSamplers[ResAttr.SamplerInd].RawPtr(); + pSampler = m_ImmutableSamplers[ResAttr.SamplerInd].RawPtr(); } else { @@ -276,11 +271,14 @@ void PipelineResourceSignatureGLImpl::CreateLayouts() if (!SampAttr.IsImmutableSamplerAssigned()) continue; - Sampler = m_ImmutableSamplers[SampAttr.SamplerInd].RawPtr(); + pSampler = m_ImmutableSamplers[SampAttr.SamplerInd].RawPtr(); } - for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd) - m_pStaticResCache->SetSampler(ResAttr.CacheOffset + ArrInd, Sampler); + if (pSampler != nullptr) + { + for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd) + m_pStaticResCache->SetSampler(ResAttr.CacheOffset + ArrInd, pSampler); + } } #ifdef DILIGENT_DEVELOPMENT m_pStaticResCache->SetStaticResourcesInitialized(); @@ -326,7 +324,7 @@ void PipelineResourceSignatureGLImpl::Destruct() void PipelineResourceSignatureGLImpl::ApplyBindings(GLObjectWrappers::GLProgramObj& GLProgram, GLContextState& State, SHADER_TYPE Stages, - const TBindings& Bindings) const + const TBindings& BaseBindings) const { VERIFY(GLProgram != 0, "Null GL program"); State.SetProgram(GLProgram); @@ -343,7 +341,7 @@ void PipelineResourceSignatureGLImpl::ApplyBindings(GLObjectWrappers::GLProgramO continue; const auto Range = PipelineResourceToBindingRange(ResDesc); - const Uint32 BindingIndex = Bindings[Range] + ResAttr.CacheOffset; + const Uint32 BindingIndex = BaseBindings[Range] + ResAttr.CacheOffset; static_assert(BINDING_RANGE_COUNT == 4, "Please update the switch below to handle the new shader resource range"); switch (Range) @@ -577,12 +575,12 @@ void PipelineResourceSignatureGLImpl::CopyStaticResources(ShaderResourceCacheGL& if (!ResAttr.IsSamplerAssigned()) continue; - ISampler* Sampler = nullptr; + ISampler* pSampler = nullptr; if (ResAttr.IsImmutableSamplerAssigned()) { VERIFY_EXPR(ResAttr.SamplerInd < GetImmutableSamplerCount()); - Sampler = m_ImmutableSamplers[ResAttr.SamplerInd].RawPtr(); + pSampler = m_ImmutableSamplers[ResAttr.SamplerInd].RawPtr(); } else { @@ -590,11 +588,14 @@ void PipelineResourceSignatureGLImpl::CopyStaticResources(ShaderResourceCacheGL& if (!SampAttr.IsImmutableSamplerAssigned()) continue; - Sampler = m_ImmutableSamplers[SampAttr.SamplerInd].RawPtr(); + pSampler = m_ImmutableSamplers[SampAttr.SamplerInd].RawPtr(); } - for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd) - DstResourceCache.SetSampler(ResAttr.CacheOffset + ArrInd, Sampler); + if (pSampler != nullptr) + { + for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd) + DstResourceCache.SetSampler(ResAttr.CacheOffset + ArrInd, pSampler); + } } #ifdef DILIGENT_DEVELOPMENT @@ -664,10 +665,10 @@ bool PipelineResourceSignatureGLImpl::DvpValidateCommittedResource(const ShaderR LOG_ERROR_MESSAGE("No resource is bound to variable '", GetShaderResourcePrintName(GLAttribs, ArrInd), "' in shader '", ShaderName, "' of PSO '", PSOName, "'"); BindingsOK = false; - continue; } } break; + case BINDING_RANGE_STORAGE_BUFFER: for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd) { @@ -676,10 +677,10 @@ bool PipelineResourceSignatureGLImpl::DvpValidateCommittedResource(const ShaderR LOG_ERROR_MESSAGE("No resource is bound to variable '", GetShaderResourcePrintName(GLAttribs, ArrInd), "' in shader '", ShaderName, "' of PSO '", PSOName, "'"); BindingsOK = false; - continue; } } break; + case BINDING_RANGE_TEXTURE: for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd) { @@ -699,6 +700,7 @@ bool PipelineResourceSignatureGLImpl::DvpValidateCommittedResource(const ShaderR ValidateResourceViewDimension(ResDesc.Name, ResDesc.ArraySize, ArrInd, Tex.pView.RawPtr(), ResourceDim, IsMultisample); } break; + case BINDING_RANGE_IMAGE: for (Uint32 ArrInd = 0; ArrInd < ResDesc.ArraySize; ++ArrInd) { @@ -718,9 +720,11 @@ bool PipelineResourceSignatureGLImpl::DvpValidateCommittedResource(const ShaderR ValidateResourceViewDimension(ResDesc.Name, ResDesc.ArraySize, ArrInd, Img.pView.RawPtr(), ResourceDim, IsMultisample); } break; + default: UNEXPECTED("Unsupported shader resource range type."); } + return BindingsOK; } #endif // DILIGENT_DEVELOPMENT diff --git a/Graphics/GraphicsEngineOpenGL/src/PipelineStateGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/PipelineStateGLImpl.cpp index b787fd38..693c0d1a 100644 --- a/Graphics/GraphicsEngineOpenGL/src/PipelineStateGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/PipelineStateGLImpl.cpp @@ -26,6 +26,11 @@ */ #include "pch.h" + +#ifdef FindResource +# undef FindResource +#endif + #include "PipelineStateGLImpl.hpp" #include "RenderDeviceGLImpl.hpp" #include "ShaderGLImpl.hpp" @@ -419,7 +424,7 @@ bool PipelineStateGLImpl::IsCompatibleWith(const IPipelineState* pPSO) const for (Uint32 s = 0, SigCount = lhs.GetResourceSignatureCount(); s < SigCount; ++s) { - if (!lhs.GetSignature(s)->IsCompatibleWith(*rhs.GetSignature(s))) + if (!lhs.GetResourceSignature(s)->IsCompatibleWith(*rhs.GetResourceSignature(s))) return false; } return true; @@ -469,27 +474,6 @@ GLObjectWrappers::GLPipelineObj& PipelineStateGLImpl::GetGLProgramPipeline(GLCon return ctx_pipeline.second; } -PipelineStateGLImpl::ResourceAttribution PipelineStateGLImpl::GetResourceAttribution(const char* Name, SHADER_TYPE Stage) const -{ - const auto SignCount = GetResourceSignatureCount(); - for (Uint32 sign = 0; sign < SignCount; ++sign) - { - const auto* const pSignature = GetSignature(sign); - if (pSignature == nullptr) - continue; - - const auto ResIndex = pSignature->FindResource(Stage, Name); - if (ResIndex != ResourceAttribution::InvalidResourceIndex) - return ResourceAttribution{pSignature, sign, ResIndex}; - else - { - const auto ImtblSamIndex = pSignature->FindImmutableSampler(Stage, Name); - if (ImtblSamIndex != ResourceAttribution::InvalidSamplerIndex) - return ResourceAttribution{pSignature, sign, ResourceAttribution::InvalidResourceIndex, ImtblSamIndex}; - } - } - return ResourceAttribution{}; -} void PipelineStateGLImpl::ValidateShaderResources(std::shared_ptr pShaderResources, const char* ShaderName, SHADER_TYPE ShaderStages) { @@ -559,7 +543,7 @@ void PipelineStateGLImpl::ValidateShaderResources(std::shared_ptrGetTotalResourceCount() == 0) continue; // Skip null and empty signatures @@ -587,7 +571,7 @@ void PipelineStateGLImpl::DvpVerifySRBResources(ShaderResourceBindingGLImpl* pSR "' is not compatible with pipeline layout in current pipeline '", m_Desc.Name, "'."); } - DEV_CHECK_ERR(Bindings == BoundResOffsets[sign], + DEV_CHECK_ERR(Bindings == BaseBindings[sign], "Bound resources has incorrect base binding indices, this may indicate a bug in resource signature compatibility comparison."); pSignature->ShiftBindings(Bindings); -- cgit v1.2.3