diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2019-03-05 16:04:52 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2019-03-05 16:04:52 +0000 |
| commit | 0220c1820c60d08c71dcfa3db1a7e9ddc93eddc6 (patch) | |
| tree | c39d7143d4757e6c3aebf0ea9a35bbc7d99732fd /Graphics/GraphicsEngineOpenGL | |
| parent | Updated QueryInterface declaration in GL backend (diff) | |
| download | DiligentCore-0220c1820c60d08c71dcfa3db1a7e9ddc93eddc6.tar.gz DiligentCore-0220c1820c60d08c71dcfa3db1a7e9ddc93eddc6.zip | |
Reworked GLProgramResources & GLProgram
Diffstat (limited to 'Graphics/GraphicsEngineOpenGL')
8 files changed, 152 insertions, 280 deletions
diff --git a/Graphics/GraphicsEngineOpenGL/include/GLProgram.h b/Graphics/GraphicsEngineOpenGL/include/GLProgram.h index 96729fed..617cf5f9 100644 --- a/Graphics/GraphicsEngineOpenGL/include/GLProgram.h +++ b/Graphics/GraphicsEngineOpenGL/include/GLProgram.h @@ -37,30 +37,16 @@ namespace Diligent GLProgram& operator = (const GLProgram&) = delete; GLProgram& operator = ( GLProgram&&) = delete; - void InitResources(RenderDeviceGLImpl* pDeviceGLImpl, - SHADER_RESOURCE_VARIABLE_TYPE DefaultVariableType, - const ShaderResourceVariableDesc* VariableDesc, - Uint32 NumVars, - const StaticSamplerDesc* StaticSamplers, - Uint32 NumStaticSamplers, - IObject& Owner); + void InitResources(RenderDeviceGLImpl* pDeviceGLImpl, + SHADER_TYPE ShaderStage, + IObject& Owner); void BindConstantResources(IResourceMapping* pResourceMapping, Uint32 Flags); - const GLProgramResources& GetAllResources() const{return m_AllResources;} - GLProgramResources& GetConstantResources() {return m_ConstantResources;} - const GLProgramResources& GetConstantResources()const{return m_ConstantResources;} - - -#ifdef VERIFY_RESOURCE_BINDINGS - template<typename TResArrayType> - void dbgVerifyBindingCompletenessHelper(TResArrayType& ResArr, GLProgramResources* pDynamicResources); - void dbgVerifyBindingCompleteness(GLProgramResources* pDynamicResources, class PipelineStateGLImpl* pPSO); -#endif + const GLProgramResources& GetResources() const { return m_AllResources; } private: GLProgramResources m_AllResources; - GLProgramResources m_ConstantResources; // When adding new member DO NOT FORGET TO UPDATE GLProgram( GLProgram&& Program )!!! }; } diff --git a/Graphics/GraphicsEngineOpenGL/include/GLProgramResources.h b/Graphics/GraphicsEngineOpenGL/include/GLProgramResources.h index 85651833..d3d25eb3 100644 --- a/Graphics/GraphicsEngineOpenGL/include/GLProgramResources.h +++ b/Graphics/GraphicsEngineOpenGL/include/GLProgramResources.h @@ -45,27 +45,23 @@ namespace Diligent GLProgramResources& operator = (const GLProgramResources&) = delete; GLProgramResources& operator = ( GLProgramResources&&) = delete; - void LoadUniforms(class RenderDeviceGLImpl* pDeviceGLImpl, - GLuint GLProgram, - const SHADER_RESOURCE_VARIABLE_TYPE DefaultVariableType, - const ShaderResourceVariableDesc* VariableDesc, - Uint32 NumVars, - const StaticSamplerDesc* StaticSamplers, - Uint32 NumStaticSamplers); - - void Clone(const GLProgramResources& SrcLayout, - SHADER_RESOURCE_VARIABLE_TYPE* VarTypes, - Uint32 NumVarTypes, - IObject& Owner); + void LoadUniforms(class RenderDeviceGLImpl* pDeviceGLImpl, + SHADER_TYPE ShaderStage, + GLuint GLProgram, + const PipelineResourceLayoutDesc* pResourceLayout, + const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, + Uint32 NumAllowedTypes); struct GLProgramVariableBase { - GLProgramVariableBase(String _Name, - size_t _ArraySize, - SHADER_RESOURCE_VARIABLE_TYPE _VarType) : - Name ( std::move(_Name) ), - pResources(_ArraySize), - VarType (_VarType) + GLProgramVariableBase(String _Name, + size_t _ArraySize, + SHADER_RESOURCE_VARIABLE_TYPE _VarType, + SHADER_RESOURCE_TYPE _ResourceType) : + Name ( std::move(_Name) ), + pResources (_ArraySize), + VarType (_VarType), + ResourceType(_ResourceType) { VERIFY_EXPR(_ArraySize >= 1); } @@ -81,18 +77,29 @@ namespace Diligent return ComputeHash(static_cast<Int32>(VarType), pResources.size()); } + ShaderResourceDesc GetResourceDesc()const + { + ShaderResourceDesc ResourceDesc; + ResourceDesc.Name = Name.c_str(); + ResourceDesc.ArraySize = static_cast<Uint32>(pResources.size()); + ResourceDesc.Type = ResourceType; + return ResourceDesc; + } + String Name; std::vector< RefCntAutoPtr<IDeviceObject> > pResources; - const SHADER_RESOURCE_VARIABLE_TYPE VarType; + const SHADER_RESOURCE_VARIABLE_TYPE VarType; + const SHADER_RESOURCE_TYPE ResourceType; }; struct UniformBufferInfo : GLProgramVariableBase { - UniformBufferInfo(String _Name, - size_t _ArraySize, + UniformBufferInfo(String _Name, + size_t _ArraySize, SHADER_RESOURCE_VARIABLE_TYPE _VarType, - GLint _Index) : - GLProgramVariableBase(std::move(_Name), _ArraySize, _VarType), + SHADER_RESOURCE_TYPE _ResourceType, + GLint _Index) : + GLProgramVariableBase(std::move(_Name), _ArraySize, _VarType, _ResourceType), Index(_Index) {} @@ -113,13 +120,14 @@ namespace Diligent struct SamplerInfo : GLProgramVariableBase { - SamplerInfo(String _Name, - size_t _ArraySize, + SamplerInfo(String _Name, + size_t _ArraySize, SHADER_RESOURCE_VARIABLE_TYPE _VarType, - GLint _Location, - GLenum _Type, - class SamplerGLImpl* _pStaticSampler) : - GLProgramVariableBase(std::move(_Name), _ArraySize, _VarType), + SHADER_RESOURCE_TYPE _ResourceType, + GLint _Location, + GLenum _Type, + class SamplerGLImpl* _pStaticSampler) : + GLProgramVariableBase(std::move(_Name), _ArraySize, _VarType, _ResourceType), Location (_Location), Type (_Type), pStaticSampler(_pStaticSampler) @@ -145,12 +153,13 @@ namespace Diligent struct ImageInfo : GLProgramVariableBase { - ImageInfo(String _Name, - size_t _ArraySize, + ImageInfo(String _Name, + size_t _ArraySize, SHADER_RESOURCE_VARIABLE_TYPE _VarType, - GLint _BindingPoint, - GLenum _Type) : - GLProgramVariableBase(std::move(_Name), _ArraySize, _VarType), + SHADER_RESOURCE_TYPE _ResourceType, + GLint _BindingPoint, + GLenum _Type) : + GLProgramVariableBase(std::move(_Name), _ArraySize, _VarType, _ResourceType), BindingPoint(_BindingPoint), Type (_Type) {} @@ -174,11 +183,12 @@ namespace Diligent struct StorageBlockInfo : GLProgramVariableBase { - StorageBlockInfo(String _Name, - size_t _ArraySize, + StorageBlockInfo(String _Name, + size_t _ArraySize, SHADER_RESOURCE_VARIABLE_TYPE _VarType, - GLint _Binding) : - GLProgramVariableBase(std::move(_Name), _ArraySize, _VarType), + SHADER_RESOURCE_TYPE _ResourceType, + GLint _Binding) : + GLProgramVariableBase(std::move(_Name), _ArraySize, _VarType, _ResourceType), Binding(_Binding) {} @@ -237,6 +247,10 @@ namespace Diligent return VariableIndex; } + ShaderResourceDesc GetResourceDesc() const + { + return ProgramVar.GetResourceDesc(); + } private: GLProgramVariableBase& ProgramVar; const Uint32 VariableIndex; @@ -248,8 +262,12 @@ namespace Diligent void dbgVerifyResourceBindings(); #endif - IShaderResourceVariable* GetShaderVariable(const Char* Name); - IShaderResourceVariable* GetShaderVariable(Uint32 Index) + CGLShaderVariable* GetShaderVariable(const Char* Name); + CGLShaderVariable* GetShaderVariable(Uint32 Index) + { + return Index < m_VariablesByIndex.size() ? m_VariablesByIndex[Index] : nullptr; + } + const CGLShaderVariable* GetShaderVariable(Uint32 Index)const { return Index < m_VariablesByIndex.size() ? m_VariablesByIndex[Index] : nullptr; } @@ -264,9 +282,9 @@ namespace Diligent bool IsCompatibleWith(const GLProgramResources& Res)const; size_t GetHash()const; - private: void InitVariables(IObject &Owner); + private: std::vector<UniformBufferInfo> m_UniformBlocks; std::vector<SamplerInfo> m_Samplers; std::vector<ImageInfo> m_Images; diff --git a/Graphics/GraphicsEngineOpenGL/include/PipelineStateGLImpl.h b/Graphics/GraphicsEngineOpenGL/include/PipelineStateGLImpl.h index dbf2b07b..fd42adf2 100644 --- a/Graphics/GraphicsEngineOpenGL/include/PipelineStateGLImpl.h +++ b/Graphics/GraphicsEngineOpenGL/include/PipelineStateGLImpl.h @@ -49,10 +49,16 @@ public: ~PipelineStateGLImpl(); /// Queries the specific interface, see IObject::QueryInterface() for details - virtual void QueryInterface( const INTERFACE_ID& IID, IObject** ppInterface )override; + virtual void QueryInterface(const INTERFACE_ID& IID, IObject** ppInterface)override; virtual void BindStaticResources(Uint32 ShaderFlags, IResourceMapping* pResourceMapping, Uint32 Flags)override final; + virtual Uint32 GetStaticVariableCount(SHADER_TYPE ShaderType) const override final; + + virtual IShaderResourceVariable* GetStaticShaderVariable(SHADER_TYPE ShaderType, const Char* Name) override final; + + virtual IShaderResourceVariable* GetStaticShaderVariable(SHADER_TYPE ShaderType, Uint32 Index) override final; + virtual void CreateShaderResourceBinding( IShaderResourceBinding** ppShaderResourceBinding, bool InitStaticResources )override final; virtual bool IsCompatibleWith(const IPipelineState* pPSO)const override final; diff --git a/Graphics/GraphicsEngineOpenGL/include/ShaderGLImpl.h b/Graphics/GraphicsEngineOpenGL/include/ShaderGLImpl.h index b8d607ea..d579ef46 100644 --- a/Graphics/GraphicsEngineOpenGL/include/ShaderGLImpl.h +++ b/Graphics/GraphicsEngineOpenGL/include/ShaderGLImpl.h @@ -73,67 +73,14 @@ public: ShaderGLImpl( IReferenceCounters *pRefCounters, RenderDeviceGLImpl *pDeviceGL, const ShaderCreateInfo &ShaderCreateInfo, bool bIsDeviceInternal = false ); ~ShaderGLImpl(); - virtual void BindResources( IResourceMapping* pResourceMapping, Uint32 Flags )override final; + virtual Uint32 GetResourceCount()const override final; + virtual ShaderResourceDesc GetResource(Uint32 Index)const override final; virtual void QueryInterface( const INTERFACE_ID &IID, IObject **ppInterface )override final; - // If separate shaders are not available, the method can optionally create - // a placeholder for static resource variable - IShaderResourceVariable* GetShaderVariable(const Char* Name, bool CreatePlaceholder); - virtual IShaderResourceVariable* GetShaderVariable(const Char* Name)override final; - - virtual Uint32 GetVariableCount() const override final; - - virtual IShaderResourceVariable* GetShaderVariable(Uint32 Index) override final; GLProgram& GetGlProgram(){return m_GlProgObj;} - // This class is used to keep references to static resources when separate shaders are not available - class StaticVarPlaceholder final : public ObjectBase<IShaderResourceVariable> - { - public: - StaticVarPlaceholder(IReferenceCounters* pRefCounters, String Name, Uint32 Index) : - ObjectBase<IShaderResourceVariable>(pRefCounters), - m_Name (std::move(Name)), - m_Index (Index) - {} - - virtual void Set(IDeviceObject* pObject)override final - { - SetArray(&pObject, 0, 1); - } - virtual void SetArray(IDeviceObject* const* ppObjects, Uint32 FirstElement, Uint32 NumElements)override final - { - if (m_Objects.size() < FirstElement + NumElements) - m_Objects.resize(FirstElement + NumElements); - for (Uint32 i=0; i < NumElements; ++i) - m_Objects[FirstElement + i] = ppObjects[i]; - } - virtual SHADER_RESOURCE_VARIABLE_TYPE GetType()const override final - { - return SHADER_RESOURCE_VARIABLE_TYPE_STATIC; - } - virtual Uint32 GetArraySize()const override final - { - return static_cast<Uint32>(m_Objects.size()); - } - virtual const Char* GetName()const override final - { - return m_Name.c_str(); - } - virtual Uint32 GetIndex()const override final - { - return m_Index; - } - IDeviceObject* Get(Uint32 ArrayIndex) - { - return ArrayIndex < m_Objects.size() ? m_Objects[ArrayIndex].RawPtr() : nullptr; - } - private: - const String m_Name; - const Uint32 m_Index; - std::vector<RefCntAutoPtr<IDeviceObject>> m_Objects; - }; private: friend class PipelineStateGLImpl; @@ -141,9 +88,6 @@ private: GLProgram m_GlProgObj; // Used if program pipeline supported GLObjectWrappers::GLShaderObj m_GLShaderObj; // Used if program pipelines are not supported - - std::vector<RefCntAutoPtr<StaticVarPlaceholder>> m_StaticResources; // Used only if program pipelines are not supported to - // hold static resources. }; } diff --git a/Graphics/GraphicsEngineOpenGL/src/GLProgram.cpp b/Graphics/GraphicsEngineOpenGL/src/GLProgram.cpp index 07c2117c..cd3e01fa 100644 --- a/Graphics/GraphicsEngineOpenGL/src/GLProgram.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/GLProgram.cpp @@ -33,67 +33,18 @@ namespace Diligent {} GLProgram::GLProgram( GLProgram&& Program ): - GLObjectWrappers::GLProgramObj(std::move(Program ) ), - m_AllResources (std::move(Program.m_AllResources) ), - m_ConstantResources (std::move(Program.m_ConstantResources)) + GLObjectWrappers::GLProgramObj(std::move(Program ) ), + m_AllResources (std::move(Program.m_AllResources)) {} - void GLProgram::InitResources(RenderDeviceGLImpl* pDeviceGLImpl, - const SHADER_RESOURCE_VARIABLE_TYPE DefaultVariableType, - const ShaderResourceVariableDesc *VariableDesc, - Uint32 NumVars, - const StaticSamplerDesc *StaticSamplers, - Uint32 NumStaticSamplers, - IObject &Owner) + void GLProgram::InitResources(RenderDeviceGLImpl* pDeviceGLImpl, + SHADER_TYPE ShaderStage, + IObject& Owner) { GLuint GLProgram = static_cast<GLuint>(*this); - m_AllResources.LoadUniforms(pDeviceGLImpl, GLProgram, DefaultVariableType, VariableDesc, NumVars, StaticSamplers, NumStaticSamplers); - - SHADER_RESOURCE_VARIABLE_TYPE VarTypes[] = {SHADER_RESOURCE_VARIABLE_TYPE_STATIC}; - m_ConstantResources.Clone(m_AllResources, VarTypes, _countof(VarTypes), Owner); - } - - void GLProgram::BindConstantResources( IResourceMapping *pResourceMapping, Uint32 Flags ) - { - if( !pResourceMapping ) - return; - - m_ConstantResources.BindResources(pResourceMapping, Flags); + m_AllResources.LoadUniforms(pDeviceGLImpl, ShaderStage, GLProgram, nullptr, nullptr, 0); + m_AllResources.InitVariables(Owner); } -#ifdef VERIFY_RESOURCE_BINDINGS - template<typename TResArrayType> - void GLProgram::dbgVerifyBindingCompletenessHelper(TResArrayType &ResArr, GLProgramResources *pDynamicResources) - { - const auto &ConstVariables = m_ConstantResources.GetVariables(); - for( auto res = ResArr.begin(); res != ResArr.end(); ++res ) - { - auto ConstRes = ConstVariables.find(HashMapStringKey(res->Name.c_str())); - if (ConstRes == ConstVariables.end()) - { - bool bVarFound = false; - if( pDynamicResources) - { - const auto &DynamicVariables = pDynamicResources->GetVariables(); - auto DynRes = DynamicVariables.find(HashMapStringKey(res->Name.c_str())); - bVarFound = (DynRes != DynamicVariables.end()); - } - - if(!bVarFound) - { - LOG_ERROR_MESSAGE( "Incomplete binding: non-static shader variable \"", res->Name, "\" not found" ); - } - } - } - } - - void GLProgram::dbgVerifyBindingCompleteness(GLProgramResources *pDynamicResources, PipelineStateGLImpl *pPSO) - { - dbgVerifyBindingCompletenessHelper(m_AllResources.GetUniformBlocks(), pDynamicResources); - dbgVerifyBindingCompletenessHelper(m_AllResources.GetSamplers(), pDynamicResources); - dbgVerifyBindingCompletenessHelper(m_AllResources.GetImages(), pDynamicResources); - dbgVerifyBindingCompletenessHelper(m_AllResources.GetStorageBlocks(), pDynamicResources); - } -#endif } diff --git a/Graphics/GraphicsEngineOpenGL/src/GLProgramResources.cpp b/Graphics/GraphicsEngineOpenGL/src/GLProgramResources.cpp index 34529cbf..a9d8538f 100644 --- a/Graphics/GraphicsEngineOpenGL/src/GLProgramResources.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/GLProgramResources.cpp @@ -24,6 +24,7 @@ #include "pch.h" #include "GLProgramResources.h" #include "RenderDeviceGLImpl.h" +#include "ShaderResourceBindingBase.h" namespace Diligent { @@ -44,16 +45,17 @@ namespace Diligent *OpenBacketPtr = 0; } - void GLProgramResources::LoadUniforms(RenderDeviceGLImpl *pDeviceGLImpl, - GLuint GLProgram, - const SHADER_RESOURCE_VARIABLE_TYPE DefaultVariableType, - const ShaderResourceVariableDesc *VariableDesc, - Uint32 NumVars, - const StaticSamplerDesc *StaticSamplers, - Uint32 NumStaticSamplers) + void GLProgramResources::LoadUniforms(RenderDeviceGLImpl* pDeviceGLImpl, + SHADER_TYPE ShaderStage, + GLuint GLProgram, + const PipelineResourceLayoutDesc* pResourceLayout, + const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, + Uint32 NumAllowedTypes) { VERIFY(GLProgram != 0, "Null GL program"); + const Uint32 AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes); + GLint numActiveUniforms = 0; glGetProgramiv( GLProgram, GL_ACTIVE_UNIFORMS, &numActiveUniforms ); CHECK_GL_ERROR_AND_THROW( "Unable to get number of active uniforms\n" ); @@ -176,18 +178,23 @@ namespace Diligent // The latter is only available in GL 4.4 and GLES 3.1 RemoveArrayBrackets(Name.data()); - auto VarType = GetShaderVariableType(Name.data(), DefaultVariableType, VariableDesc, NumVars); + SHADER_RESOURCE_VARIABLE_TYPE VarType = SHADER_RESOURCE_VARIABLE_TYPE_STATIC; RefCntAutoPtr<SamplerGLImpl> pStaticSampler; - for (Uint32 s = 0; s < NumStaticSamplers; ++s) + if (pResourceLayout != nullptr) { - if (strcmp(Name.data(), StaticSamplers[s].SamplerOrTextureName) == 0) + VarType = GetShaderVariableType(ShaderStage, Name.data(), *pResourceLayout); + for (Uint32 s = 0; s < pResourceLayout->NumStaticSamplers; ++s) { - pDeviceGLImpl->CreateSampler(StaticSamplers[s].Desc, reinterpret_cast<ISampler**>(static_cast<SamplerGLImpl**>(&pStaticSampler)) ); - break; + const auto& StSam = pResourceLayout->StaticSamplers[s]; + if (strcmp(Name.data(), StSam.SamplerOrTextureName) == 0) + { + pDeviceGLImpl->CreateSampler(StSam.Desc, reinterpret_cast<ISampler**>(static_cast<SamplerGLImpl**>(&pStaticSampler)) ); + break; + } } } - m_Samplers.emplace_back( Name.data(), size, VarType, UniformLocation, dataType, pStaticSampler ); + m_Samplers.emplace_back( Name.data(), size, VarType, SHADER_RESOURCE_TYPE_TEXTURE_SRV, UniformLocation, dataType, pStaticSampler ); break; } @@ -235,8 +242,10 @@ namespace Diligent VERIFY( BindingPoint >= 0, "Incorrect binding point" ); RemoveArrayBrackets(Name.data()); - auto VarType = GetShaderVariableType(Name.data(), DefaultVariableType, VariableDesc, NumVars); - m_Images.emplace_back( Name.data(), size, VarType, BindingPoint, dataType ); + SHADER_RESOURCE_VARIABLE_TYPE VarType = (pResourceLayout != nullptr) ? + GetShaderVariableType(ShaderStage, Name.data(), *pResourceLayout) : + SHADER_RESOURCE_VARIABLE_TYPE_STATIC; + m_Images.emplace_back( Name.data(), size, VarType, SHADER_RESOURCE_TYPE_TEXTURE_UAV, BindingPoint, dataType ); break; } #endif @@ -293,8 +302,10 @@ namespace Diligent } - auto VarType = GetShaderVariableType(Name.data(), DefaultVariableType, VariableDesc, NumVars); - m_UniformBlocks.emplace_back( Name.data(), ArraySize, VarType, UniformBlockIndex ); + SHADER_RESOURCE_VARIABLE_TYPE VarType = (pResourceLayout != nullptr) ? + GetShaderVariableType(ShaderStage, Name.data(), *pResourceLayout) : + SHADER_RESOURCE_VARIABLE_TYPE_STATIC; + m_UniformBlocks.emplace_back( Name.data(), ArraySize, VarType, SHADER_RESOURCE_TYPE_CONSTANT_BUFFER, UniformBlockIndex ); } #if GL_ARB_shader_storage_buffer_object @@ -341,8 +352,10 @@ namespace Diligent } } - auto VarType = GetShaderVariableType(Name.data(), DefaultVariableType, VariableDesc, NumVars); - m_StorageBlocks.emplace_back( Name.data(), ArraySize, VarType, Binding ); + SHADER_RESOURCE_VARIABLE_TYPE VarType = (pResourceLayout != nullptr) ? + GetShaderVariableType(ShaderStage, Name.data(), *pResourceLayout) : + SHADER_RESOURCE_VARIABLE_TYPE_STATIC; + m_StorageBlocks.emplace_back( Name.data(), ArraySize, VarType, SHADER_RESOURCE_TYPE_BUFFER_UAV, Binding ); } #endif @@ -357,39 +370,7 @@ namespace Diligent return false; } - void GLProgramResources::Clone(const GLProgramResources& SrcLayout, - SHADER_RESOURCE_VARIABLE_TYPE* VarTypes, - Uint32 NumVarTypes, - IObject& Owner) - { - for (auto& ub : SrcLayout.m_UniformBlocks) - { - if(CheckType(ub.VarType, VarTypes, NumVarTypes)) - m_UniformBlocks.emplace_back( ub.Name, ub.pResources.size(), ub.VarType, ub.Index ); - } - - for (auto& sam : SrcLayout.m_Samplers) - { - if(CheckType(sam.VarType, VarTypes, NumVarTypes)) - m_Samplers.emplace_back( sam.Name, sam.pResources.size(), sam.VarType, sam.Location, sam.Type, const_cast<SamplerGLImpl*>(sam.pStaticSampler.RawPtr()) ); - } - - for (auto& img : SrcLayout.m_Images) - { - if(CheckType(img.VarType, VarTypes, NumVarTypes)) - m_Images.emplace_back( img.Name, img.pResources.size(), img.VarType, img.BindingPoint, img.Type ); - } - - for (auto& sb : SrcLayout.m_StorageBlocks) - { - if(CheckType(sb.VarType, VarTypes, NumVarTypes)) - m_StorageBlocks.emplace_back( sb.Name, sb.pResources.size(), sb.VarType, sb.Binding ); - } - - InitVariables(Owner); - } - - void GLProgramResources::InitVariables(IObject &Owner) + void GLProgramResources::InitVariables(IObject& Owner) { // After all program resources are loaded, we can populate shader variable hash map. // The map contains raw pointers, but none of the arrays will ever change. @@ -414,7 +395,7 @@ namespace Diligent #undef STORE_SHADER_VARIABLES } - IShaderResourceVariable* GLProgramResources::GetShaderVariable( const Char* Name ) + GLProgramResources::CGLShaderVariable* GLProgramResources::GetShaderVariable( const Char* Name ) { // Name will be implicitly converted to HashMapStringKey without making a copy auto it = m_VariableHash.find( Name ); diff --git a/Graphics/GraphicsEngineOpenGL/src/PipelineStateGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/PipelineStateGLImpl.cpp index 9071b815..d26fa887 100644 --- a/Graphics/GraphicsEngineOpenGL/src/PipelineStateGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/PipelineStateGLImpl.cpp @@ -247,4 +247,25 @@ GLObjectWrappers::GLPipelineObj& PipelineStateGLImpl::GetGLProgramPipeline(GLCon } } + +void PipelineStateGLImpl::BindStaticResources(Uint32 ShaderFlags, IResourceMapping* pResourceMapping, Uint32 Flags) +{ + +} + +Uint32 PipelineStateGLImpl::GetStaticVariableCount(SHADER_TYPE ShaderType) const +{ + +} + +IShaderResourceVariable* PipelineStateGLImpl::GetStaticShaderVariable(SHADER_TYPE ShaderType, const Char* Name) +{ + +} + +IShaderResourceVariable* GetStaticShaderVariable(SHADER_TYPE ShaderType, Uint32 Index) +{ + +} + } diff --git a/Graphics/GraphicsEngineOpenGL/src/ShaderGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/ShaderGLImpl.cpp index 7e6340dc..b155a373 100644 --- a/Graphics/GraphicsEngineOpenGL/src/ShaderGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/ShaderGLImpl.cpp @@ -33,10 +33,10 @@ using namespace Diligent; namespace Diligent { -ShaderGLImpl::ShaderGLImpl(IReferenceCounters* pRefCounters, - RenderDeviceGLImpl* pDeviceGL, - const ShaderCreateInfo& CreationAttribs, - bool bIsDeviceInternal) : +ShaderGLImpl::ShaderGLImpl(IReferenceCounters* pRefCounters, + RenderDeviceGLImpl* pDeviceGL, + const ShaderCreateInfo& CreationAttribs, + bool bIsDeviceInternal) : TShaderBase( pRefCounters, pDeviceGL, CreationAttribs.Desc, bIsDeviceInternal ), m_GlProgObj(false), m_GLShaderObj( false, GLObjectWrappers::GLShaderObjCreateReleaseHelper( GetGLShaderType( m_Desc.ShaderType ) ) ) @@ -160,7 +160,7 @@ ShaderGLImpl::ShaderGLImpl(IReferenceCounters* pRefCounters, // boolean status bit DELETE_STATUS is set to true ShaderObj.Release(); - m_GlProgObj.InitResources(pDeviceGL, m_Desc.DefaultVariableType, m_Desc.VariableDesc, m_Desc.NumVariables, m_Desc.StaticSamplers, m_Desc.NumStaticSamplers, *this); + m_GlProgObj.InitResources(pDeviceGL, m_Desc.ShaderType, *this); } else { @@ -174,68 +174,33 @@ ShaderGLImpl::~ShaderGLImpl() IMPLEMENT_QUERY_INTERFACE( ShaderGLImpl, IID_ShaderGL, TShaderBase ) -void ShaderGLImpl::BindResources( IResourceMapping* pResourceMapping, Uint32 Flags ) +Uint32 ShaderGLImpl::GetResourceCount()const { - if( static_cast<GLuint>(m_GlProgObj) ) + Uint32 ResCount = 0; + if (m_GlProgObj) { - m_GlProgObj.BindConstantResources( pResourceMapping, Flags ); + return m_GlProgObj.GetResources().GetVariableCount(); } else { - LOG_WARNING_MESSAGE_ONCE( "IShader::BindResources() effectively does nothing when separable programs are not supported by the device." ); + LOG_WARNING_MESSAGE("Shader resource queries are not available when separate shader objects are unsupported"); } + return ResCount; } -IShaderResourceVariable* ShaderGLImpl::GetShaderVariable(const Char* Name) +ShaderResourceDesc ShaderGLImpl::GetResource(Uint32 Index)const { - return GetShaderVariable(Name, true); -} - -IShaderResourceVariable* ShaderGLImpl::GetShaderVariable(const Char* Name, bool CreatePlaceholder) -{ - if( m_GlProgObj ) - return m_GlProgObj.GetConstantResources().GetShaderVariable(Name); - else + ShaderResourceDesc ResourceDesc; + if (m_GlProgObj) { - for (auto& Res : m_StaticResources) - { - if( strcmp(Res->GetName(), Name) == 0) - return Res; - } - - if (CreatePlaceholder) - { - auto* pNewVar = MakeNewRCObj<StaticVarPlaceholder>()(Name, static_cast<Uint32>(m_StaticResources.size())); - m_StaticResources.emplace_back(pNewVar); - return pNewVar; - } - else - { - return nullptr; - } - } -} - -Uint32 ShaderGLImpl::GetVariableCount() const -{ - if( m_GlProgObj ) - return m_GlProgObj.GetConstantResources().GetVariableCount(); - else - { - LOG_WARNING_MESSAGE("When separate shader objects are unavailable, GetVariableCount() returns the number of resources being set so far " - "rather than the total number of static shader resources."); - return static_cast<Uint32>(m_StaticResources.size()); + DEV_CHECK_ERR(Index < GetResourceCount(), "Index is out of range"); + ResourceDesc = m_GlProgObj.GetResources().GetShaderVariable(Index)->GetResourceDesc(); } -} - -IShaderResourceVariable* ShaderGLImpl::GetShaderVariable(Uint32 Index) -{ - if( m_GlProgObj ) - return m_GlProgObj.GetConstantResources().GetShaderVariable(Index); else { - return Index < m_StaticResources.size() ? m_StaticResources[Index].RawPtr() : nullptr; + LOG_WARNING_MESSAGE("Shader resource queries are not available when separate shader objects are unsupported"); } + return ResourceDesc; } } |
