diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2019-03-06 03:31:09 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2019-03-06 03:31:09 +0000 |
| commit | 36c9ca813faf49dbb73f6774f298ebdd55d88459 (patch) | |
| tree | 939c156ec17774d02e742b8d9f67f6ea06297b22 /Graphics/GraphicsEngineOpenGL | |
| parent | Reworked GLProgramResources & GLProgram (diff) | |
| download | DiligentCore-36c9ca813faf49dbb73f6774f298ebdd55d88459.tar.gz DiligentCore-36c9ca813faf49dbb73f6774f298ebdd55d88459.zip | |
Final changes to make GL backend compile
Diffstat (limited to 'Graphics/GraphicsEngineOpenGL')
10 files changed, 190 insertions, 209 deletions
diff --git a/Graphics/GraphicsEngineOpenGL/include/GLProgram.h b/Graphics/GraphicsEngineOpenGL/include/GLProgram.h index 617cf5f9..dbc0c6c8 100644 --- a/Graphics/GraphicsEngineOpenGL/include/GLProgram.h +++ b/Graphics/GraphicsEngineOpenGL/include/GLProgram.h @@ -37,9 +37,12 @@ namespace Diligent GLProgram& operator = (const GLProgram&) = delete; GLProgram& operator = ( GLProgram&&) = delete; - void InitResources(RenderDeviceGLImpl* pDeviceGLImpl, - SHADER_TYPE ShaderStage, - IObject& Owner); + void InitResources(RenderDeviceGLImpl* pDeviceGLImpl, + SHADER_TYPE ShaderStage, + IObject& Owner, + const PipelineResourceLayoutDesc* pResourceLayout, + const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, + Uint32 NumAllowedTypes); void BindConstantResources(IResourceMapping* pResourceMapping, Uint32 Flags); diff --git a/Graphics/GraphicsEngineOpenGL/include/GLProgramResources.h b/Graphics/GraphicsEngineOpenGL/include/GLProgramResources.h index d3d25eb3..d75bb2a5 100644 --- a/Graphics/GraphicsEngineOpenGL/include/GLProgramResources.h +++ b/Graphics/GraphicsEngineOpenGL/include/GLProgramResources.h @@ -46,12 +46,20 @@ namespace Diligent GLProgramResources& operator = ( GLProgramResources&&) = delete; void LoadUniforms(class RenderDeviceGLImpl* pDeviceGLImpl, - SHADER_TYPE ShaderStage, + SHADER_TYPE ShaderStages, GLuint GLProgram, const PipelineResourceLayoutDesc* pResourceLayout, const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, Uint32 NumAllowedTypes); + + void Clone(class RenderDeviceGLImpl* pDeviceGLImpl, + IObject& Owner, + const GLProgramResources& SrcResources, + const PipelineResourceLayoutDesc& ResourceLayout, + const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, + Uint32 NumAllowedTypes); + struct GLProgramVariableBase { GLProgramVariableBase(String _Name, @@ -284,7 +292,12 @@ namespace Diligent void InitVariables(IObject &Owner); + SHADER_TYPE GetShaderStages() const {return m_ShaderStages;} + private: + // There could be more than one stage is using non-separable programs + SHADER_TYPE m_ShaderStages = SHADER_TYPE_UNKNOWN; + 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 fd42adf2..0c98d838 100644 --- a/Graphics/GraphicsEngineOpenGL/include/PipelineStateGLImpl.h +++ b/Graphics/GraphicsEngineOpenGL/include/PipelineStateGLImpl.h @@ -23,6 +23,7 @@ #pragma once +#include <vector> #include "PipelineStateGL.h" #include "PipelineStateBase.h" #include "RenderDevice.h" @@ -66,12 +67,19 @@ public: GLProgram& GetGLProgram(){return m_GLProgram;} GLObjectWrappers::GLPipelineObj& GetGLProgramPipeline(GLContext::NativeGLContextType Context); + GLProgramResources& GetStaticResources(Uint32 s) + { + return m_StaticResources[s]; + } + private: void LinkGLProgram(bool bIsProgramPipelineSupported); GLProgram m_GLProgram; ThreadingTools::LockFlag m_ProgPipelineLockFlag; - std::unordered_map<GLContext::NativeGLContextType, GLObjectWrappers::GLPipelineObj> m_GLProgPipelines; + std::vector< std::pair<GLContext::NativeGLContextType, GLObjectWrappers::GLPipelineObj > > m_GLProgPipelines; + std::vector<GLProgramResources> m_StaticResources; + Int8 m_ResourceLayoutIndex[6] = {-1, -1, -1, -1, -1, -1}; }; } diff --git a/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp index d7ff2b32..cddce1ea 100644 --- a/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp @@ -385,13 +385,13 @@ namespace Diligent GLProgramResources* pDynamicResources = pShaderResBindingGL ? &pShaderResBindingGL->GetProgramResources(pShaderGL->GetDesc().ShaderType, m_pPipelineState) : nullptr; #ifdef VERIFY_RESOURCE_BINDINGS - GLProgramObj.dbgVerifyBindingCompleteness(pDynamicResources, m_pPipelineState); + //GLProgramObj.dbgVerifyBindingCompleteness(pDynamicResources, m_pPipelineState); #endif // When program pipelines are not supported, all resources are dynamic resources for (int BindDynamicResources = (ProgramPipelineSupported ? 0 : 1); BindDynamicResources < (pShaderResBindingGL ? 2 : 1); ++BindDynamicResources) { - GLProgramResources& ProgResources = BindDynamicResources ? *pDynamicResources : GLProgramObj.GetConstantResources(); + GLProgramResources& ProgResources = BindDynamicResources ? *pDynamicResources : m_pPipelineState->GetStaticResources(ProgNum); #ifdef VERIFY_RESOURCE_BINDINGS ProgResources.dbgVerifyResourceBindings(); diff --git a/Graphics/GraphicsEngineOpenGL/src/GLProgram.cpp b/Graphics/GraphicsEngineOpenGL/src/GLProgram.cpp index cd3e01fa..f4650151 100644 --- a/Graphics/GraphicsEngineOpenGL/src/GLProgram.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/GLProgram.cpp @@ -37,14 +37,15 @@ namespace Diligent m_AllResources (std::move(Program.m_AllResources)) {} - void GLProgram::InitResources(RenderDeviceGLImpl* pDeviceGLImpl, - SHADER_TYPE ShaderStage, - IObject& Owner) + void GLProgram::InitResources(RenderDeviceGLImpl* pDeviceGLImpl, + SHADER_TYPE ShaderStage, + IObject& Owner, + const PipelineResourceLayoutDesc* pResourceLayout, + const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, + Uint32 NumAllowedTypes) { GLuint GLProgram = static_cast<GLuint>(*this); - m_AllResources.LoadUniforms(pDeviceGLImpl, ShaderStage, GLProgram, nullptr, nullptr, 0); + m_AllResources.LoadUniforms(pDeviceGLImpl, ShaderStage, GLProgram, pResourceLayout, AllowedVarTypes, NumAllowedTypes); m_AllResources.InitVariables(Owner); } - - } diff --git a/Graphics/GraphicsEngineOpenGL/src/GLProgramResources.cpp b/Graphics/GraphicsEngineOpenGL/src/GLProgramResources.cpp index a9d8538f..42dbf43f 100644 --- a/Graphics/GraphicsEngineOpenGL/src/GLProgramResources.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/GLProgramResources.cpp @@ -46,7 +46,7 @@ namespace Diligent } void GLProgramResources::LoadUniforms(RenderDeviceGLImpl* pDeviceGLImpl, - SHADER_TYPE ShaderStage, + SHADER_TYPE ShaderStages, GLuint GLProgram, const PipelineResourceLayoutDesc* pResourceLayout, const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, @@ -54,6 +54,7 @@ namespace Diligent { VERIFY(GLProgram != 0, "Null GL program"); + m_ShaderStages = ShaderStages; const Uint32 AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes); GLint numActiveUniforms = 0; @@ -183,7 +184,7 @@ namespace Diligent RefCntAutoPtr<SamplerGLImpl> pStaticSampler; if (pResourceLayout != nullptr) { - VarType = GetShaderVariableType(ShaderStage, Name.data(), *pResourceLayout); + VarType = GetShaderVariableType(ShaderStages, Name.data(), *pResourceLayout); for (Uint32 s = 0; s < pResourceLayout->NumStaticSamplers; ++s) { const auto& StSam = pResourceLayout->StaticSamplers[s]; @@ -243,7 +244,7 @@ namespace Diligent RemoveArrayBrackets(Name.data()); SHADER_RESOURCE_VARIABLE_TYPE VarType = (pResourceLayout != nullptr) ? - GetShaderVariableType(ShaderStage, Name.data(), *pResourceLayout) : + GetShaderVariableType(ShaderStages, Name.data(), *pResourceLayout) : SHADER_RESOURCE_VARIABLE_TYPE_STATIC; m_Images.emplace_back( Name.data(), size, VarType, SHADER_RESOURCE_TYPE_TEXTURE_UAV, BindingPoint, dataType ); break; @@ -301,9 +302,9 @@ namespace Diligent } } - + SHADER_RESOURCE_VARIABLE_TYPE VarType = (pResourceLayout != nullptr) ? - GetShaderVariableType(ShaderStage, Name.data(), *pResourceLayout) : + GetShaderVariableType(ShaderStages, Name.data(), *pResourceLayout) : SHADER_RESOURCE_VARIABLE_TYPE_STATIC; m_UniformBlocks.emplace_back( Name.data(), ArraySize, VarType, SHADER_RESOURCE_TYPE_CONSTANT_BUFFER, UniformBlockIndex ); } @@ -353,21 +354,71 @@ namespace Diligent } SHADER_RESOURCE_VARIABLE_TYPE VarType = (pResourceLayout != nullptr) ? - GetShaderVariableType(ShaderStage, Name.data(), *pResourceLayout) : + GetShaderVariableType(ShaderStages, Name.data(), *pResourceLayout) : SHADER_RESOURCE_VARIABLE_TYPE_STATIC; m_StorageBlocks.emplace_back( Name.data(), ArraySize, VarType, SHADER_RESOURCE_TYPE_BUFFER_UAV, Binding ); } #endif - } - static bool CheckType(SHADER_RESOURCE_VARIABLE_TYPE Type, SHADER_RESOURCE_VARIABLE_TYPE* AllowedTypes, Uint32 NumAllowedTypes) + + void GLProgramResources::Clone(RenderDeviceGLImpl* pDeviceGLImpl, + IObject& Owner, + const GLProgramResources& SrcResources, + const PipelineResourceLayoutDesc& ResourceLayout, + const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, + Uint32 NumAllowedTypes) { - for(Uint32 i=0; i < NumAllowedTypes; ++i) - if(Type == AllowedTypes[i]) - return true; - - return false; + m_ShaderStages = SrcResources.m_ShaderStages; + const Uint32 AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes); + + for (auto& ub : SrcResources.m_UniformBlocks) + { + auto VarType = GetShaderVariableType(m_ShaderStages, ub.Name.data(), ResourceLayout); + if (IsAllowedType(VarType, VarType)) + { + m_UniformBlocks.emplace_back(ub.Name, ub.pResources.size(), ub.VarType, ub.ResourceType, ub.Index); + } + } + + for (auto& sam : SrcResources.m_Samplers) + { + auto VarType = GetShaderVariableType(m_ShaderStages, sam.Name.data(), ResourceLayout); + if (IsAllowedType(VarType, VarType)) + { + RefCntAutoPtr<ISampler> pStaticSampler; + for (Uint32 s = 0; s < ResourceLayout.NumStaticSamplers; ++s) + { + const auto& StSam = ResourceLayout.StaticSamplers[s]; + if (strcmp(sam.Name.data(), StSam.SamplerOrTextureName) == 0) + { + pDeviceGLImpl->CreateSampler(StSam.Desc, &pStaticSampler); + break; + } + } + m_Samplers.emplace_back(sam.Name, sam.pResources.size(), sam.VarType, sam.ResourceType, sam.Location, sam.Type, pStaticSampler.RawPtr<SamplerGLImpl>()); + } + } + + for (auto& img : SrcResources.m_Images) + { + auto VarType = GetShaderVariableType(m_ShaderStages, img.Name.data(), ResourceLayout); + if (IsAllowedType(VarType, VarType)) + { + m_Images.emplace_back(img.Name, img.pResources.size(), img.VarType, img.ResourceType, img.BindingPoint, img.Type); + } + } + + for (auto& sb : SrcResources.m_StorageBlocks) + { + auto VarType = GetShaderVariableType(m_ShaderStages, sb.Name.data(), ResourceLayout); + if (IsAllowedType(VarType, VarType)) + { + m_StorageBlocks.emplace_back(sb.Name, sb.pResources.size(), sb.VarType, sb.ResourceType, sb.Binding); + } + } + + InitVariables(Owner); } void GLProgramResources::InitVariables(IObject& Owner) diff --git a/Graphics/GraphicsEngineOpenGL/src/PipelineStateGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/PipelineStateGLImpl.cpp index d26fa887..25ee1d17 100644 --- a/Graphics/GraphicsEngineOpenGL/src/PipelineStateGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/PipelineStateGLImpl.cpp @@ -53,10 +53,18 @@ void PipelineStateGLImpl::LinkGLProgram(bool bIsProgramPipelineSupported) // Program pipelines are not shared between GL contexts, so we cannot create // it now m_ShaderResourceLayoutHash = 0; + m_StaticResources.resize(m_NumShaders); for (Uint32 Shader = 0; Shader < m_NumShaders; ++Shader) { auto* pShaderGL = GetShader<ShaderGLImpl>(Shader); - HashCombine(m_ShaderResourceLayoutHash, pShaderGL->m_GlProgObj.GetAllResources().GetHash()); + const SHADER_RESOURCE_VARIABLE_TYPE StaticVars[] = {SHADER_RESOURCE_VARIABLE_TYPE_STATIC}; + m_StaticResources[Shader].Clone(GetDevice(), *this, pShaderGL->GetGlProgram().GetResources(), m_Desc.ResourceLayout, StaticVars, _countof(StaticVars)); + + const auto ShaderType = pShaderGL->GetDesc().ShaderType; + const auto ShaderTypeInd = GetShaderTypeIndex(ShaderType); + m_ResourceLayoutIndex[ShaderTypeInd] = static_cast<Int8>(Shader); + + HashCombine(m_ShaderResourceLayoutHash, pShaderGL->m_GlProgObj.GetResources().GetHash()); } } else @@ -99,81 +107,22 @@ void PipelineStateGLImpl::LinkGLProgram(bool bIsProgramPipelineSupported) CHECK_GL_ERROR("glDetachShader() failed"); } - std::vector<ShaderResourceVariableDesc> MergedVarTypesArray; - std::vector<StaticSamplerDesc> MergedStSamArray; - SHADER_RESOURCE_VARIABLE_TYPE DefaultVarType = SHADER_RESOURCE_VARIABLE_TYPE_STATIC; + SHADER_TYPE ShaderStages = SHADER_TYPE_UNKNOWN; for (Uint32 Shader = 0; Shader < m_NumShaders; ++Shader) { auto* pCurrShader = GetShader<ShaderGLImpl>(Shader); const auto& Desc = pCurrShader->GetDesc(); - if (Shader == 0) - { - DefaultVarType = Desc.DefaultVariableType; - } - else - { - if (DefaultVarType != Desc.DefaultVariableType) - { - LOG_ERROR_MESSAGE("When separate shader programs are not available, all shaders linked into a program " - "must use the same default variable type."); - } - } - - for (Uint32 v = 0; v < Desc.NumVariables; ++v) - { - const auto& NewVar = Desc.VariableDesc[v]; - bool VarExists = false; - for (const auto& Var : MergedVarTypesArray) - { - if (strcmp(Var.Name, NewVar.Name) == 0) - { - VarExists = true; - if (Var.Type != NewVar.Type) - { - LOG_ERROR_MESSAGE("The type of variable '", Var.Name, "' is not consistent between shader stages. " - "When separate shader programs are not available, all shaders must use the same " - "type for identically named shader variables."); - } - break; - } - } - - if (!VarExists) - { - MergedVarTypesArray.push_back(NewVar); - } - } - - for (Uint32 s = 0; s < Desc.NumStaticSamplers; ++s) - { - const auto& NewSampler = Desc.StaticSamplers[s]; - bool SamplerExists = false; - for (const auto& Sampler : MergedStSamArray) - { - if (strcmp(Sampler.SamplerOrTextureName, NewSampler.SamplerOrTextureName) == 0) - { - SamplerExists = true; - if ( !(Sampler.Desc == NewSampler.Desc) ) - { - LOG_ERROR_MESSAGE("Static sampler defined for texture '", NewSampler.SamplerOrTextureName, "' is not consistent between shader stages. " - "When separate shader programs are not available, all shaders must use the same " - "static samplers for identically named shader variables."); - } - break; - } - } - - if (!SamplerExists) - { - MergedStSamArray.push_back(NewSampler); - } - } + ShaderStages |= Desc.ShaderType; } auto pDeviceGL = GetDevice(); - m_GLProgram.InitResources(pDeviceGL, DefaultVarType, MergedVarTypesArray.data(), static_cast<Uint32>(MergedVarTypesArray.size()), MergedStSamArray.data(), static_cast<Uint32>(MergedStSamArray.size()), *this); + m_GLProgram.InitResources(pDeviceGL, ShaderStages, *this, &m_Desc.ResourceLayout, nullptr, 0); + + m_StaticResources.resize(1); + const SHADER_RESOURCE_VARIABLE_TYPE StaticVars[] = {SHADER_RESOURCE_VARIABLE_TYPE_STATIC}; + m_StaticResources[0].Clone(GetDevice(), *this, m_GLProgram.GetResources(), m_Desc.ResourceLayout, StaticVars, _countof(StaticVars)); - m_ShaderResourceLayoutHash = m_GLProgram.GetAllResources().GetHash(); + m_ShaderResourceLayoutHash = m_GLProgram.GetResources().GetHash(); } } @@ -185,18 +134,6 @@ PipelineStateGLImpl::~PipelineStateGLImpl() IMPLEMENT_QUERY_INTERFACE( PipelineStateGLImpl, IID_PipelineStateGL, TPipelineStateBase ) -void PipelineStateGLImpl::BindShaderResources(IResourceMapping* pResourceMapping, Uint32 Flags) -{ - if (GetDevice()->GetDeviceCaps().bSeparableProgramSupported) - { - TPipelineStateBase::BindShaderResources(pResourceMapping, Flags); - } - else - { - if (m_GLProgram) - m_GLProgram.BindConstantResources(pResourceMapping, Flags); - } -} void PipelineStateGLImpl::CreateShaderResourceBinding(IShaderResourceBinding** ppShaderResourceBinding, bool InitStaticResources) { @@ -219,53 +156,82 @@ bool PipelineStateGLImpl::IsCompatibleWith(const IPipelineState* pPSO)const if (m_ShaderResourceLayoutHash != pPSOGL->m_ShaderResourceLayoutHash) return false; - return m_GLProgram.GetAllResources().IsCompatibleWith(pPSOGL->m_GLProgram.GetAllResources()); + return m_GLProgram.GetResources().IsCompatibleWith(pPSOGL->m_GLProgram.GetResources()); } GLObjectWrappers::GLPipelineObj& PipelineStateGLImpl::GetGLProgramPipeline(GLContext::NativeGLContextType Context) { ThreadingTools::LockHelper Lock(m_ProgPipelineLockFlag); - auto it = m_GLProgPipelines.find(Context); - if (it != m_GLProgPipelines.end()) - return it->second; - else + for(auto& ctx_pipeline : m_GLProgPipelines) { - // Create new progam pipeline - it = m_GLProgPipelines.emplace(Context, true).first; - GLuint Pipeline = it->second; - for (Uint32 Shader = 0; Shader < m_NumShaders; ++Shader) - { - auto* pCurrShader = GetShader<ShaderGLImpl>(Shader); - auto GLShaderBit = ShaderTypeToGLShaderBit(pCurrShader->GetDesc().ShaderType); - // If the program has an active code for each stage mentioned in set flags, - // then that code will be used by the pipeline. If program is 0, then the given - // stages are cleared from the pipeline. - glUseProgramStages(Pipeline, GLShaderBit, pCurrShader->m_GlProgObj); - CHECK_GL_ERROR("glUseProgramStages() failed"); - } - return it->second; + if (ctx_pipeline.first == Context) + return ctx_pipeline.second; + } + + // Create new progam pipeline + m_GLProgPipelines.emplace_back(Context, true); + auto& ctx_pipeline = m_GLProgPipelines.back(); + GLuint Pipeline = ctx_pipeline.second; + for (Uint32 Shader = 0; Shader < m_NumShaders; ++Shader) + { + auto* pCurrShader = GetShader<ShaderGLImpl>(Shader); + auto GLShaderBit = ShaderTypeToGLShaderBit(pCurrShader->GetDesc().ShaderType); + // If the program has an active code for each stage mentioned in set flags, + // then that code will be used by the pipeline. If program is 0, then the given + // stages are cleared from the pipeline. + glUseProgramStages(Pipeline, GLShaderBit, pCurrShader->m_GlProgObj); + CHECK_GL_ERROR("glUseProgramStages() failed"); } + return ctx_pipeline.second; } void PipelineStateGLImpl::BindStaticResources(Uint32 ShaderFlags, IResourceMapping* pResourceMapping, Uint32 Flags) { - + for(auto& StaticRes : m_StaticResources) + { + if ((StaticRes.GetShaderStages() & ShaderFlags)!=0) + StaticRes.BindResources(pResourceMapping, Flags); + } } Uint32 PipelineStateGLImpl::GetStaticVariableCount(SHADER_TYPE ShaderType) const { - + if (m_GLProgram) + { + return m_StaticResources[0].GetVariableCount(); + } + else + { + const auto LayoutInd = m_ResourceLayoutIndex[GetShaderTypeIndex(ShaderType)]; + return LayoutInd >= 0 ? m_StaticResources[LayoutInd].GetVariableCount() : 0; + } } IShaderResourceVariable* PipelineStateGLImpl::GetStaticShaderVariable(SHADER_TYPE ShaderType, const Char* Name) { - + if (m_GLProgram) + { + return m_StaticResources[0].GetShaderVariable(Name); + } + else + { + const auto LayoutInd = m_ResourceLayoutIndex[GetShaderTypeIndex(ShaderType)]; + return LayoutInd >= 0 ? m_StaticResources[LayoutInd].GetShaderVariable(Name) : nullptr; + } } -IShaderResourceVariable* GetStaticShaderVariable(SHADER_TYPE ShaderType, Uint32 Index) +IShaderResourceVariable* PipelineStateGLImpl::GetStaticShaderVariable(SHADER_TYPE ShaderType, Uint32 Index) { - + if (m_GLProgram) + { + return m_StaticResources[0].GetShaderVariable(Index); + } + else + { + const auto LayoutInd = m_ResourceLayoutIndex[GetShaderTypeIndex(ShaderType)]; + return LayoutInd >= 0 ? m_StaticResources[LayoutInd].GetShaderVariable(Index) : nullptr; + } } } diff --git a/Graphics/GraphicsEngineOpenGL/src/ShaderGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/ShaderGLImpl.cpp index b155a373..278f79de 100644 --- a/Graphics/GraphicsEngineOpenGL/src/ShaderGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/ShaderGLImpl.cpp @@ -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.ShaderType, *this); + m_GlProgObj.InitResources(pDeviceGL, m_Desc.ShaderType, *this, nullptr, nullptr, 0); } else { diff --git a/Graphics/GraphicsEngineOpenGL/src/ShaderResourceBindingGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/ShaderResourceBindingGLImpl.cpp index 5930f0a6..15086b05 100644 --- a/Graphics/GraphicsEngineOpenGL/src/ShaderResourceBindingGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/ShaderResourceBindingGLImpl.cpp @@ -40,7 +40,7 @@ ShaderResourceBindingGLImpl::ShaderResourceBindingGLImpl(IReferenceCounters* pRe if(auto p##SN = ValidatedCast<ShaderGLImpl>( pPSO->Get##SN() )) \ { \ auto &GLProg = p##SN->GetGlProgram(); \ - m_DynamicProgResources[SN##Ind].Clone(GLProg.GetAllResources(), VarTypes, _countof(VarTypes), *this); \ + m_DynamicProgResources[SN##Ind].Clone(pPSO->GetDevice(), *this, GLProg.GetResources(), pPSO->GetDesc().ResourceLayout, VarTypes, _countof(VarTypes)); \ } INIT_SHADER(VS) @@ -55,7 +55,7 @@ ShaderResourceBindingGLImpl::ShaderResourceBindingGLImpl(IReferenceCounters* pRe { // Clone all variable types SHADER_RESOURCE_VARIABLE_TYPE VarTypes[] = {SHADER_RESOURCE_VARIABLE_TYPE_STATIC, SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE, SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC}; - m_DynamicProgResources[0].Clone(pPSO->GetGLProgram().GetAllResources(), VarTypes, _countof(VarTypes), *this); + m_DynamicProgResources[0].Clone(pPSO->GetDevice(), *this, pPSO->GetGLProgram().GetResources(), pPSO->GetDesc().ResourceLayout, VarTypes, _countof(VarTypes)); } } @@ -129,75 +129,12 @@ void ShaderResourceBindingGLImpl::InitializeStaticResources(const IPipelineState { if (!IsUsingSeparatePrograms()) { - class ResourceMappingProxy final : public IResourceMapping - { - public: - ResourceMappingProxy(const PipelineStateGLImpl& PSO) : - m_PSO(PSO) - { - } - virtual void QueryInterface (const INTERFACE_ID& IID, IObject** ppInterface)override final - { - UNEXPECTED("This method should never be called"); - } - virtual CounterValueType AddRef()override final - { - UNEXPECTED("This method should never be called"); - return 0; - } - virtual CounterValueType Release()override final - { - UNEXPECTED("This method should never be called"); - return 0; - } - virtual IReferenceCounters* GetReferenceCounters()const override final - { - UNEXPECTED("This method should never be called"); - return nullptr; - } - virtual void AddResource (const Char* Name, IDeviceObject* pObject, bool bIsUnique)override final - { - UNEXPECTED("This method should never be called"); - } - virtual void AddResourceArray (const Char* Name, Uint32 StartIndex, IDeviceObject* const* ppObjects, Uint32 NumElements, bool bIsUnique)override final - { - UNEXPECTED("This method should never be called"); - } - virtual void RemoveResourceByName (const Char* Name, Uint32 ArrayIndex = 0) - { - UNEXPECTED("This method should never be called"); - } - virtual void GetResource (const Char* Name, IDeviceObject** ppResource, Uint32 ArrayIndex = 0) - { - auto NumShaders = m_PSO.GetNumShaders(); - for (Uint32 s=0; s < NumShaders; ++s) - { - auto* pShader = m_PSO.GetShader<ShaderGLImpl>(s); - auto* pVar = pShader->GetShaderVariable(Name, false); - if (pVar != nullptr) - { - auto* pStaticVarPlaceholder = ValidatedCast<ShaderGLImpl::StaticVarPlaceholder>(pVar); - *ppResource = pStaticVarPlaceholder->Get(ArrayIndex); - if (*ppResource != nullptr) - (*ppResource)->AddRef(); - } - } - } - virtual size_t GetSize() - { - UNEXPECTED("This method should never be called"); - return 0; - } - private: - const PipelineStateGLImpl& m_PSO; - }; - - if (pPipelineState != nullptr) - { - const auto* PSOGL = ValidatedCast<const PipelineStateGLImpl>(pPipelineState); - ResourceMappingProxy StaticResMapping(*PSOGL); - m_DynamicProgResources[0].BindResources(&StaticResMapping, 0); - } + //if (pPipelineState != nullptr) + //{ + // const auto* PSOGL = ValidatedCast<const PipelineStateGLImpl>(pPipelineState); + // ResourceMappingProxy StaticResMapping(*PSOGL); + // m_DynamicProgResources[0].BindResources(&StaticResMapping, 0); + //} } } diff --git a/Graphics/GraphicsEngineOpenGL/src/TexRegionRender.cpp b/Graphics/GraphicsEngineOpenGL/src/TexRegionRender.cpp index 9bbb9c89..abd5c9f2 100644 --- a/Graphics/GraphicsEngineOpenGL/src/TexRegionRender.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/TexRegionRender.cpp @@ -61,7 +61,6 @@ namespace Diligent ShaderCreateInfo ShaderAttrs; ShaderAttrs.Desc.Name = "TexRegionRender : Vertex shader"; ShaderAttrs.Desc.ShaderType = SHADER_TYPE_VERTEX; - ShaderAttrs.Desc.DefaultVariableType = SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC; ShaderAttrs.Source = VertexShaderSource; constexpr bool IsInternalDeviceObject = true; pDeviceGL->CreateShader(ShaderAttrs, &m_pVertexShader, IsInternalDeviceObject); @@ -117,12 +116,6 @@ namespace Diligent Name.append(SamplerDim); ShaderAttrs.Desc.Name = Name.c_str(); ShaderAttrs.Desc.ShaderType = SHADER_TYPE_PIXEL; - ShaderResourceVariableDesc Vars[] = - { - {"cbConstants", SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE} - }; - ShaderAttrs.Desc.NumVariables = _countof(Vars); - ShaderAttrs.Desc.VariableDesc = Vars; std::stringstream SourceSS; SourceSS << "uniform " << Prefix << SamplerDim << " gSourceTex;\n" @@ -141,6 +134,15 @@ namespace Diligent auto &FragmetShader = m_pFragmentShaders[Dim*3 + Fmt]; pDeviceGL->CreateShader(ShaderAttrs, &FragmetShader, IsInternalDeviceObject); GraphicsPipeline.pPS = FragmetShader; + + PSODesc.ResourceLayout.DefaultVariableType = SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC; + ShaderResourceVariableDesc Vars[] = + { + {SHADER_TYPE_PIXEL, "cbConstants", SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE} + }; + PSODesc.ResourceLayout.NumVariables = _countof(Vars); + PSODesc.ResourceLayout.Variables = Vars; + pDeviceGL->CreatePipelineState(PSODesc, &m_pPSO[Dim*3 + Fmt], IsInternalDeviceObject); } m_pPSO[RESOURCE_DIM_TEX_2D*3]->CreateShaderResourceBinding(&m_pSRB); |
