From 3f404c8edbc7148c3e8ce3efccc82777b9ca6fef Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Sun, 10 Apr 2016 14:14:30 +0200 Subject: [PATCH] gsdx-ogl: update shader pipeline intertace to use vs/gs/ps triplet Better to have 1 function calls with 3 parameters rather 3 functions call with 1 parameter. --- plugins/GSdx/GSDeviceOGL.cpp | 8 ++------ plugins/GSdx/GSDeviceOGL.h | 10 ++++------ plugins/GSdx/GSRendererOGL.cpp | 8 +++----- plugins/GSdx/GSShaderOGL.cpp | 32 ++++++++++++-------------------- plugins/GSdx/GSShaderOGL.h | 4 +--- plugins/GSdx/GSTextureFXOGL.cpp | 20 +++++--------------- 6 files changed, 27 insertions(+), 55 deletions(-) diff --git a/plugins/GSdx/GSDeviceOGL.cpp b/plugins/GSdx/GSDeviceOGL.cpp index c1084cae32..cae77454fb 100644 --- a/plugins/GSdx/GSDeviceOGL.cpp +++ b/plugins/GSdx/GSDeviceOGL.cpp @@ -1025,9 +1025,7 @@ void GSDeviceOGL::StretchRect(GSTexture* sTex, const GSVector4& sRect, GSTexture GSVector2i ds = dTex->GetSize(); - m_shader->VS(m_convert.vs); - m_shader->GS(0); - m_shader->PS(ps); + m_shader->Pipeline(m_convert.vs, 0, ps); // ************************************ // om @@ -1265,9 +1263,7 @@ void GSDeviceOGL::SetupDATE(GSTexture* rt, GSTexture* ds, const GSVertexPT1* ver ClearStencil(ds, 0); - m_shader->VS(m_convert.vs); - m_shader->GS(0); - m_shader->PS(m_convert.ps[datm ? ShaderConvert_DATM_1 : ShaderConvert_DATM_0]); + m_shader->Pipeline(m_convert.vs, 0, m_convert.ps[datm ? ShaderConvert_DATM_1 : ShaderConvert_DATM_0]); // om diff --git a/plugins/GSdx/GSDeviceOGL.h b/plugins/GSdx/GSDeviceOGL.h index 2d1756e924..4701f9439b 100644 --- a/plugins/GSdx/GSDeviceOGL.h +++ b/plugins/GSdx/GSDeviceOGL.h @@ -160,7 +160,7 @@ class GSDeviceOGL final : public GSDevice uint32 key; }; - operator uint32() {return key;} + operator uint32() const {return key;} VSSelector() : key(0) {} VSSelector(uint32 k) : key(k) {} @@ -181,7 +181,7 @@ class GSDeviceOGL final : public GSDevice uint32 key; }; - operator uint32() {return key;} + operator uint32() const {return key;} GSSelector() : key(0) {} GSSelector(uint32 k) : key(k) {} @@ -293,7 +293,7 @@ class GSDeviceOGL final : public GSDevice }; // FIXME is the & useful ? - operator uint64() {return key;} + operator uint64() const {return key;} PSSelector() : key(0) {} }; @@ -538,9 +538,7 @@ class GSDeviceOGL final : public GSDevice void SetupIA(const void* vertex, int vertex_count, const uint32* index, int index_count, int prim); - void SetupVS(VSSelector sel); - void SetupGS(GSSelector sel); - void SetupPS(PSSelector sel); + void SetupPipeline(const VSSelector& vsel, const GSSelector& gsel, const PSSelector& psel); void SetupCB(const VSConstantBuffer* vs_cb, const PSConstantBuffer* ps_cb); void SetupSampler(PSSamplerSelector ssel); void SetupOM(OMDepthStencilSelector dssel); diff --git a/plugins/GSdx/GSRendererOGL.cpp b/plugins/GSdx/GSRendererOGL.cpp index 7880b49153..e59bc26d4b 100644 --- a/plugins/GSdx/GSRendererOGL.cpp +++ b/plugins/GSdx/GSRendererOGL.cpp @@ -1022,9 +1022,7 @@ void GSRendererOGL::DrawPrims(GSTexture* rt, GSTexture* ds, GSTextureCache::Sour #endif gs_sel.sprite = m_vt.m_primclass == GS_SPRITE_CLASS; - dev->SetupVS(vs_sel); - dev->SetupGS(gs_sel); - dev->SetupPS(ps_sel); + dev->SetupPipeline(vs_sel, gs_sel, ps_sel); // rs @@ -1062,7 +1060,7 @@ void GSRendererOGL::DrawPrims(GSTexture* rt, GSTexture* ds, GSTextureCache::Sour glDepthMask(GLState::depth_mask); ps_sel.date = 3; - dev->SetupPS(ps_sel); + dev->SetupPipeline(vs_sel, gs_sel, ps_sel); // Be sure that first pass is finished ! dev->Barrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT); @@ -1096,7 +1094,7 @@ void GSRendererOGL::DrawPrims(GSTexture* rt, GSTexture* ds, GSTextureCache::Sour ps_sel.atst = 1; } - dev->SetupPS(ps_sel); + dev->SetupPipeline(vs_sel, gs_sel, ps_sel); bool z = om_dssel.zwe; bool r = om_csel.wr; diff --git a/plugins/GSdx/GSShaderOGL.cpp b/plugins/GSdx/GSShaderOGL.cpp index 46660ca72c..6bf504ce41 100644 --- a/plugins/GSdx/GSShaderOGL.cpp +++ b/plugins/GSdx/GSShaderOGL.cpp @@ -40,35 +40,27 @@ GSShaderOGL::~GSShaderOGL() m_single_prog.clear(); } -void GSShaderOGL::VS(GLuint s) +void GSShaderOGL::Pipeline(GLuint vs, GLuint gs, GLuint ps) { - if (GLState::vs != s) + if (GLState::vs != vs) { - GLState::vs = s; - glUseProgramStages(m_pipeline, GL_VERTEX_SHADER_BIT, s); + GLState::vs = vs; + glUseProgramStages(m_pipeline, GL_VERTEX_SHADER_BIT, vs); + } + if (GLState::gs != gs) + { + GLState::gs = gs; + glUseProgramStages(m_pipeline, GL_GEOMETRY_SHADER_BIT, gs); } -} - -void GSShaderOGL::PS(GLuint s) -{ #ifdef _DEBUG if (true) #else - if (GLState::ps != s) + if (GLState::ps != ps) #endif { // In debug always sets the program. It allow to replace the program in apitrace easily. - GLState::ps = s; - glUseProgramStages(m_pipeline, GL_FRAGMENT_SHADER_BIT, s); - } -} - -void GSShaderOGL::GS(GLuint s) -{ - if (GLState::gs != s) - { - GLState::gs = s; - glUseProgramStages(m_pipeline, GL_GEOMETRY_SHADER_BIT, s); + GLState::ps = ps; + glUseProgramStages(m_pipeline, GL_FRAGMENT_SHADER_BIT, ps); } } diff --git a/plugins/GSdx/GSShaderOGL.h b/plugins/GSdx/GSShaderOGL.h index 376285bb11..7538124417 100644 --- a/plugins/GSdx/GSShaderOGL.h +++ b/plugins/GSdx/GSShaderOGL.h @@ -35,9 +35,7 @@ class GSShaderOGL { GSShaderOGL(bool debug); ~GSShaderOGL(); - void GS(GLuint s); - void PS(GLuint s); - void VS(GLuint s); + void Pipeline(GLuint vs, GLuint gs, GLuint ps); GLuint Compile(const std::string& glsl_file, const std::string& entry, GLenum type, const char* glsl_h_code, const std::string& macro_sel = ""); diff --git a/plugins/GSdx/GSTextureFXOGL.cpp b/plugins/GSdx/GSTextureFXOGL.cpp index c6552953c4..03fff8f318 100644 --- a/plugins/GSdx/GSTextureFXOGL.cpp +++ b/plugins/GSdx/GSTextureFXOGL.cpp @@ -110,27 +110,17 @@ void GSDeviceOGL::SetupCB(const VSConstantBuffer* vs_cb, const PSConstantBuffer* GL_POP(); } -void GSDeviceOGL::SetupVS(VSSelector sel) -{ - m_shader->VS(m_vs[sel]); -} - -void GSDeviceOGL::SetupGS(GSSelector sel) -{ - m_shader->GS(m_gs[sel]); -} - -void GSDeviceOGL::SetupPS(PSSelector sel) +void GSDeviceOGL::SetupPipeline(const VSSelector& vsel, const GSSelector& gsel, const PSSelector& psel) { // ************************************************************* // Static // ************************************************************* GLuint ps; - auto i = m_ps.find(sel); + auto i = m_ps.find(psel); if (i == m_ps.end()) { - ps = CompilePS(sel); - m_ps[sel] = ps; + ps = CompilePS(psel); + m_ps[psel] = ps; } else { ps = i->second; } @@ -138,7 +128,7 @@ void GSDeviceOGL::SetupPS(PSSelector sel) // ************************************************************* // Dynamic // ************************************************************* - m_shader->PS(ps); + m_shader->Pipeline(m_vs[vsel], m_gs[gsel], ps); } void GSDeviceOGL::SetupSampler(PSSamplerSelector ssel)