diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2021-03-06 07:00:47 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2021-03-19 00:38:16 +0000 |
| commit | 72d2e4a6482150ee61b3124de546af1ec5a0bf38 (patch) | |
| tree | f33e4b9bc627519b0d6e9755c902e6945a4a93b6 /Graphics/GraphicsEngineOpenGL | |
| parent | Reworked FenceGLImpl to use std::atomic (diff) | |
| download | DiligentCore-72d2e4a6482150ee61b3124de546af1ec5a0bf38.tar.gz DiligentCore-72d2e4a6482150ee61b3124de546af1ec5a0bf38.zip | |
Moved GetResourceAttribution() function to PipelineStateBase to eliminate duplication
Diffstat (limited to 'Graphics/GraphicsEngineOpenGL')
5 files changed, 50 insertions, 111 deletions
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<Uint32, BINDING_RANGE_COUNT>; + // 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<IPipelineResourceSignature>(); + return m_Signatures[Index].RawPtr<PipelineResourceSignatureGLImpl>(); } /// 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<PipelineResourceSignatureGLImpl>(); - } - #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<const ShaderResourcesGL> 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<Uint32>(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<IBufferView>(), 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<IBufferView>(), 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<const ShaderResourcesGL> pShaderResources, const char* ShaderName, SHADER_TYPE ShaderStages) { @@ -559,7 +543,7 @@ void PipelineStateGLImpl::ValidateShaderResources(std::shared_ptr<const ShaderRe #ifdef DILIGENT_DEVELOPMENT void PipelineStateGLImpl::DvpVerifySRBResources(ShaderResourceBindingGLImpl* pSRBs[], - const TBindings BoundResOffsets[], + const TBindings BaseBindings[], Uint32 NumSRBs) const { // Verify SRB compatibility with this pipeline @@ -568,7 +552,7 @@ void PipelineStateGLImpl::DvpVerifySRBResources(ShaderResourceBindingGLImpl* pSR for (Uint32 sign = 0; sign < SignCount; ++sign) { // Get resource signature from the root signature - const auto& pSignature = GetSignature(sign); + const auto& pSignature = GetResourceSignature(sign); if (pSignature == nullptr || pSignature->GetTotalResourceCount() == 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); |
