diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2020-10-11 02:28:54 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2020-10-11 02:28:54 +0000 |
| commit | 91aac63f651da1079be93d2fe722cd10e4e15570 (patch) | |
| tree | a342deebcf83a91fac3b35587860e2f2017c1637 /Graphics/GraphicsEngineOpenGL | |
| parent | formating (diff) | |
| download | DiligentCore-91aac63f651da1079be93d2fe722cd10e4e15570.tar.gz DiligentCore-91aac63f651da1079be93d2fe722cd10e4e15570.zip | |
A number of corrections for PSO refactoring
Diffstat (limited to 'Graphics/GraphicsEngineOpenGL')
| -rw-r--r-- | Graphics/GraphicsEngineOpenGL/include/ShaderGLImpl.hpp | 2 | ||||
| -rw-r--r-- | Graphics/GraphicsEngineOpenGL/src/PipelineStateGLImpl.cpp | 46 | ||||
| -rw-r--r-- | Graphics/GraphicsEngineOpenGL/src/ShaderGLImpl.cpp | 6 |
3 files changed, 30 insertions, 24 deletions
diff --git a/Graphics/GraphicsEngineOpenGL/include/ShaderGLImpl.hpp b/Graphics/GraphicsEngineOpenGL/include/ShaderGLImpl.hpp index bc0f32e6..d4c4b87e 100644 --- a/Graphics/GraphicsEngineOpenGL/include/ShaderGLImpl.hpp +++ b/Graphics/GraphicsEngineOpenGL/include/ShaderGLImpl.hpp @@ -92,7 +92,7 @@ public: /// Implementation of IShader::GetResource() in OpenGL backend. virtual void DILIGENT_CALL_TYPE GetResourceDesc(Uint32 Index, ShaderResourceDesc& ResourceDesc) const override final; - static GLObjectWrappers::GLProgramObj LinkProgram(IShader** ppShaders, Uint32 NumShaders, bool IsSeparableProgram); + static GLObjectWrappers::GLProgramObj LinkProgram(ShaderGLImpl** ppShaders, Uint32 NumShaders, bool IsSeparableProgram); private: GLObjectWrappers::GLShaderObj m_GLShaderObj; diff --git a/Graphics/GraphicsEngineOpenGL/src/PipelineStateGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/PipelineStateGLImpl.cpp index e6e6a84f..8590e203 100644 --- a/Graphics/GraphicsEngineOpenGL/src/PipelineStateGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/PipelineStateGLImpl.cpp @@ -52,8 +52,7 @@ PipelineStateGLImpl::PipelineStateGLImpl(IReferenceCounters* pRefCoun m_StaticResourceLayout{*this} // clang-format on { - RefCntAutoPtr<IShader> pTempPS; - + RefCntAutoPtr<ShaderGLImpl> pTempPS; if (m_Desc.IsAnyGraphicsPipeline() && m_Desc.GraphicsPipeline.pPS == nullptr) { // Some OpenGL implementations fail if fragment shader is not present, so @@ -63,17 +62,23 @@ PipelineStateGLImpl::PipelineStateGLImpl(IReferenceCounters* pRefCoun ShaderCI.Source = "void main(){}"; ShaderCI.Desc.ShaderType = SHADER_TYPE_PIXEL; ShaderCI.Desc.Name = "Dummy fragment shader"; - pDeviceGL->CreateShader(ShaderCI, &pTempPS); - } + pDeviceGL->CreateShader(ShaderCI, reinterpret_cast<IShader**>(static_cast<ShaderGLImpl**>(&pTempPS))); - ShaderStages_t ShaderStages; - ExtractShaders(ShaderStages); + m_Desc.GraphicsPipeline.pPS = pTempPS; + } - if (pTempPS) + struct GLPipelineShaderStageInfo { - m_pShaderTypes[m_NumShaderTypes++] = SHADER_TYPE_PIXEL; - ShaderStages.push_back({SHADER_TYPE_PIXEL, pTempPS}); - } + const SHADER_TYPE Type; + ShaderGLImpl* const pShader; + GLPipelineShaderStageInfo(SHADER_TYPE _Type, + ShaderGLImpl* _pShader) : + Type{_Type}, + pShader{_pShader} + {} + }; + std::vector<GLPipelineShaderStageInfo> ShaderStages; + ExtractShaders<ShaderGLImpl>(ShaderStages); auto& DeviceCaps = pDeviceGL->GetDeviceCaps(); VERIFY(DeviceCaps.DevType != RENDER_DEVICE_TYPE_UNDEFINED, "Device caps are not initialized"); @@ -96,10 +101,9 @@ PipelineStateGLImpl::PipelineStateGLImpl(IReferenceCounters* pRefCoun m_GLPrograms.reserve(ShaderStages.size()); for (size_t i = 0; i < ShaderStages.size(); ++i) { - auto* pShader = ShaderStages[i].second; - auto* pShaderGL = ValidatedCast<ShaderGLImpl>(pShader); + auto* pShaderGL = ShaderStages[i].pShader; const auto& ShaderDesc = pShaderGL->GetDesc(); - m_GLPrograms.emplace_back(ShaderGLImpl::LinkProgram(&pShader, 1, true)); + m_GLPrograms.emplace_back(ShaderGLImpl::LinkProgram(&pShaderGL, 1, true)); // Load uniforms and assign bindings m_ProgramResources[i].LoadUniforms(ShaderDesc.ShaderType, m_GLPrograms[i], GLState, m_TotalUniformBufferBindings, @@ -112,12 +116,14 @@ PipelineStateGLImpl::PipelineStateGLImpl(IReferenceCounters* pRefCoun } else { - std::vector<IShader*> Shaders; - SHADER_TYPE ActiveStages = SHADER_TYPE_UNKNOWN; - for (size_t i = 0; i < ShaderStages.size(); ++i) + std::vector<ShaderGLImpl*> Shaders; + + SHADER_TYPE ActiveStages = SHADER_TYPE_UNKNOWN; + for (const auto& Stage : ShaderStages) { - Shaders.push_back(ShaderStages[i].second); - ActiveStages |= ShaderStages[i].first; + Shaders.push_back(Stage.pShader); + VERIFY((ActiveStages & Stage.Type) == 0, "Shader stage ", GetShaderTypeLiteralName(Stage.Type), " is already active"); + ActiveStages |= Stage.Type; } m_GLPrograms.emplace_back(ShaderGLImpl::LinkProgram(Shaders.data(), static_cast<Uint32>(ShaderStages.size()), false)); @@ -226,9 +232,9 @@ GLObjectWrappers::GLPipelineObj& PipelineStateGLImpl::GetGLProgramPipeline(GLCon m_GLProgPipelines.emplace_back(Context, true); auto& ctx_pipeline = m_GLProgPipelines.back(); GLuint Pipeline = ctx_pipeline.second; - for (Uint32 i = 0; i < GetNumShaderTypes(); ++i) + for (Uint32 i = 0; i < GetNumShaderStages(); ++i) { - auto GLShaderBit = ShaderTypeToGLShaderBit(GetShaderTypes()[i]); + auto GLShaderBit = ShaderTypeToGLShaderBit(GetShaderStageType(i)); // 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. diff --git a/Graphics/GraphicsEngineOpenGL/src/ShaderGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/ShaderGLImpl.cpp index c7a493cd..e27a8a4c 100644 --- a/Graphics/GraphicsEngineOpenGL/src/ShaderGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/ShaderGLImpl.cpp @@ -158,7 +158,7 @@ ShaderGLImpl::ShaderGLImpl(IReferenceCounters* pRefCounters, if (deviceCaps.Features.SeparablePrograms) { - IShader* ThisShader[] = {this}; + ShaderGLImpl* ThisShader[] = {this}; GLObjectWrappers::GLProgramObj Program = LinkProgram(ThisShader, 1, true); Uint32 UniformBufferBinding = 0; Uint32 SamplerBinding = 0; @@ -178,7 +178,7 @@ ShaderGLImpl::~ShaderGLImpl() IMPLEMENT_QUERY_INTERFACE(ShaderGLImpl, IID_ShaderGL, TShaderBase) -GLObjectWrappers::GLProgramObj ShaderGLImpl::LinkProgram(IShader** ppShaders, Uint32 NumShaders, bool IsSeparableProgram) +GLObjectWrappers::GLProgramObj ShaderGLImpl::LinkProgram(ShaderGLImpl** ppShaders, Uint32 NumShaders, bool IsSeparableProgram) { VERIFY(!IsSeparableProgram || NumShaders == 1, "Number of shaders must be 1 when separable program is created"); @@ -190,7 +190,7 @@ GLObjectWrappers::GLProgramObj ShaderGLImpl::LinkProgram(IShader** ppShaders, Ui for (Uint32 i = 0; i < NumShaders; ++i) { - auto* pCurrShader = ValidatedCast<ShaderGLImpl>(ppShaders[i]); + auto* pCurrShader = ppShaders[i]; glAttachShader(GLProg, pCurrShader->m_GLShaderObj); CHECK_GL_ERROR("glAttachShader() failed"); } |
