From 74822d6ba364b0e23389fc2ba438adee2f324088 Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Sat, 11 Jun 2016 01:08:50 +0200 Subject: [PATCH] gsdx ogl: rework atst handling * Move the rounding operation in the constant buffer * Merge less with less equal. And merge greater with greater equal Need test --- plugins/GSdx/GSRendererOGL.cpp | 67 +++++++++++++++--------- plugins/GSdx/GSRendererOGL.h | 2 - plugins/GSdx/res/glsl/common_header.glsl | 3 +- plugins/GSdx/res/glsl/tfx_fs.glsl | 59 +++++++++++++-------- plugins/GSdx/res/glsl_source.h | 62 +++++++++++++--------- 5 files changed, 118 insertions(+), 75 deletions(-) diff --git a/plugins/GSdx/GSRendererOGL.cpp b/plugins/GSdx/GSRendererOGL.cpp index d4f37f3b7b..cd08ab519b 100644 --- a/plugins/GSdx/GSRendererOGL.cpp +++ b/plugins/GSdx/GSRendererOGL.cpp @@ -41,7 +41,6 @@ GSRendererOGL::GSRendererOGL() UserHacks_merge_sprite = theApp.GetConfigB("UserHacks_merge_pp_sprite"); m_prim_overlap = PRIM_OVERLAP_UNKNOW; - m_pass1_atst = 0; ResetStates(); if (!theApp.GetConfigB("UserHacks")) { @@ -171,29 +170,48 @@ void GSRendererOGL::SetupIA() void GSRendererOGL::EmulateAtst(const int pass, const GSTextureCache::Source* tex) { - if (pass == 1) { - if (m_context->TEST.ATE) - m_pass1_atst = m_context->TEST.ATST; - else - m_pass1_atst = ATST_ALWAYS; + static const uint32 inverted_atst[] = {ATST_ALWAYS, ATST_NEVER, ATST_GEQUAL, ATST_GREATER, ATST_NOTEQUAL, ATST_LESS, ATST_LEQUAL, ATST_EQUAL}; + int atst = (pass == 2) ? inverted_atst[m_context->TEST.ATST] : m_context->TEST.ATST; - if (m_context->TEST.ATE && m_context->TEST.ATST > 1) + if (!m_context->TEST.ATE) return; + + switch (atst) { + case ATST_LESS: + if (tex && tex->m_spritehack_t) { + m_ps_sel.atst = 0; + } else { + ps_cb.FogColor_AREF.a = (float)m_context->TEST.AREF - 0.1f; + m_ps_sel.atst = 1; + } + break; + case ATST_LEQUAL: + ps_cb.FogColor_AREF.a = (float)m_context->TEST.AREF - 0.1f + 1.0f; + m_ps_sel.atst = 1; + break; + case ATST_GEQUAL: + // Maybe a -1 trick multiplication factor could be used to merge with ATST_LEQUAL case + ps_cb.FogColor_AREF.a = (float)m_context->TEST.AREF - 0.1f; + m_ps_sel.atst = 2; + break; + case ATST_GREATER: + // Maybe a -1 trick multiplication factor could be used to merge with ATST_LESS case + ps_cb.FogColor_AREF.a = (float)m_context->TEST.AREF - 0.1f + 1.0f; + m_ps_sel.atst = 2; + break; + case ATST_EQUAL: ps_cb.FogColor_AREF.a = (float)m_context->TEST.AREF; + m_ps_sel.atst = 3; + break; + case ATST_NOTEQUAL: + ps_cb.FogColor_AREF.a = (float)m_context->TEST.AREF; + m_ps_sel.atst = 4; + break; - if (tex && tex->m_spritehack_t && (m_pass1_atst == 2)) { - m_ps_sel.atst = 1; - } else { - m_ps_sel.atst = m_pass1_atst; - } - - } else if (pass == 2) { - static const uint32 iatst[] = {1, 0, 5, 6, 7, 2, 3, 4}; - - m_ps_sel.atst = iatst[m_pass1_atst]; - - if (tex && tex->m_spritehack_t && (m_ps_sel.atst == 2)) { - m_ps_sel.atst = 1; - } + case ATST_NEVER: // Draw won't be done so no need to implement it in shader + case ATST_ALWAYS: + default: + m_ps_sel.atst = 0; + break; } } @@ -786,10 +804,6 @@ void GSRendererOGL::EmulateTextureSampler(const GSTextureCache::Source* tex) // Setup Texture ressources dev->SetupSampler(m_ps_ssel); dev->PSSetShaderResources(tex->m_texture, tex->m_palette); - - if (tex->m_spritehack_t && (m_ps_sel.atst == 2)) { - m_ps_sel.atst = 1; - } } GSRendererOGL::PRIM_OVERLAP GSRendererOGL::PrimitiveOverlap() @@ -1361,6 +1375,9 @@ void GSRendererOGL::DrawPrims(GSTexture* rt, GSTexture* ds, GSTextureCache::Sour EmulateAtst(2, tex); + // Potentially AREF was updated (hope perf impact will be limited) + dev->SetupCB(&vs_cb, &ps_cb); + dev->SetupPipeline(m_vs_sel, m_gs_sel, m_ps_sel); bool z = m_om_dssel.zwe; diff --git a/plugins/GSdx/GSRendererOGL.h b/plugins/GSdx/GSRendererOGL.h index 7652ab4334..fc524d4d34 100644 --- a/plugins/GSdx/GSRendererOGL.h +++ b/plugins/GSdx/GSRendererOGL.h @@ -71,8 +71,6 @@ class GSRendererOGL final : public GSRendererHW GSDeviceOGL::OMColorMaskSelector m_om_csel; GSDeviceOGL::OMDepthStencilSelector m_om_dssel; - int m_pass1_atst; - private: inline void ResetStates(); inline void Lines2Sprites(); diff --git a/plugins/GSdx/res/glsl/common_header.glsl b/plugins/GSdx/res/glsl/common_header.glsl index 3f56e15181..ad8c35e62f 100644 --- a/plugins/GSdx/res/glsl/common_header.glsl +++ b/plugins/GSdx/res/glsl/common_header.glsl @@ -72,7 +72,8 @@ layout(std140, binding = 21) uniform cb21 vec4 WH; vec2 TA; - float _pad0; + //float _pad0; + int Uber_ATST; float Af; uvec4 MskFix; diff --git a/plugins/GSdx/res/glsl/tfx_fs.glsl b/plugins/GSdx/res/glsl/tfx_fs.glsl index 6fe698249b..d5c77dcb55 100644 --- a/plugins/GSdx/res/glsl/tfx_fs.glsl +++ b/plugins/GSdx/res/glsl/tfx_fs.glsl @@ -478,32 +478,45 @@ vec4 tfx(vec4 T, vec4 C) void atst(vec4 C) { - // FIXME use integer cmp float a = C.a; -#if (PS_ATST == 0) // never - discard; -#elif (PS_ATST == 1) // always - // nothing to do -#elif (PS_ATST == 2) // l - if ((AREF - a - 0.5f) < 0.0f) - discard; -#elif (PS_ATST == 3 ) // le - if ((AREF - a + 0.5f) < 0.0f) - discard; -#elif (PS_ATST == 4) // e - if ((0.5f - abs(a - AREF)) < 0.0f) - discard; -#elif (PS_ATST == 5) // ge - if ((a-AREF + 0.5f) < 0.0f) - discard; -#elif (PS_ATST == 6) // g - if ((a-AREF - 0.5f) < 0.0f) - discard; -#elif (PS_ATST == 7) // ne - if ((abs(a - AREF) - 0.5f) < 0.0f) - discard; +#if 0 + switch(Uber_ATST) { + case 0: + break; + case 1: + if (a > AREF) discard; + break; + case 2: + if (a < AREF) discard; + break; + case 3: + if (abs(a - AREF) > 0.5f) discard; + break; + case 4: + if (abs(a - AREF) < 0.5f) discard; + break; + } + + #endif + +#if 1 + +#if (PS_ATST == 0) + // nothing to do +#elif (PS_ATST == 1) + if (a > AREF) discard; +#elif (PS_ATST == 2) + if (a < AREF) discard; +#elif (PS_ATST == 3) + if (abs(a - AREF) > 0.5f) discard; +#elif (PS_ATST == 4) + if (abs(a - AREF) < 0.5f) discard; +#endif + +#endif + } void fog(inout vec4 C, float f) diff --git a/plugins/GSdx/res/glsl_source.h b/plugins/GSdx/res/glsl_source.h index 05f32c5cdb..276a1b997a 100644 --- a/plugins/GSdx/res/glsl_source.h +++ b/plugins/GSdx/res/glsl_source.h @@ -97,7 +97,8 @@ static const char* const common_header_glsl = " vec4 WH;\n" "\n" " vec2 TA;\n" - " float _pad0;\n" + " //float _pad0;\n" + " int Uber_ATST;\n" " float Af;\n" "\n" " uvec4 MskFix;\n" @@ -1321,32 +1322,45 @@ static const char* const tfx_fs_all_glsl = "\n" "void atst(vec4 C)\n" "{\n" - " // FIXME use integer cmp\n" " float a = C.a;\n" "\n" - "#if (PS_ATST == 0) // never\n" - " discard;\n" - "#elif (PS_ATST == 1) // always\n" - " // nothing to do\n" - "#elif (PS_ATST == 2) // l\n" - " if ((AREF - a - 0.5f) < 0.0f)\n" - " discard;\n" - "#elif (PS_ATST == 3 ) // le\n" - " if ((AREF - a + 0.5f) < 0.0f)\n" - " discard;\n" - "#elif (PS_ATST == 4) // e\n" - " if ((0.5f - abs(a - AREF)) < 0.0f)\n" - " discard;\n" - "#elif (PS_ATST == 5) // ge\n" - " if ((a-AREF + 0.5f) < 0.0f)\n" - " discard;\n" - "#elif (PS_ATST == 6) // g\n" - " if ((a-AREF - 0.5f) < 0.0f)\n" - " discard;\n" - "#elif (PS_ATST == 7) // ne\n" - " if ((abs(a - AREF) - 0.5f) < 0.0f)\n" - " discard;\n" + "#if 0\n" + " switch(Uber_ATST) {\n" + " case 0:\n" + " break;\n" + " case 1:\n" + " if (a > AREF) discard;\n" + " break;\n" + " case 2:\n" + " if (a < AREF) discard;\n" + " break;\n" + " case 3:\n" + " if (abs(a - AREF) > 0.5f) discard;\n" + " break;\n" + " case 4:\n" + " if (abs(a - AREF) < 0.5f) discard;\n" + " break;\n" + " }\n" + "\n" + "\n" "#endif\n" + "\n" + "#if 1\n" + "\n" + "#if (PS_ATST == 0)\n" + " // nothing to do\n" + "#elif (PS_ATST == 1)\n" + " if (a > AREF) discard;\n" + "#elif (PS_ATST == 2)\n" + " if (a < AREF) discard;\n" + "#elif (PS_ATST == 3)\n" + " if (abs(a - AREF) > 0.5f) discard;\n" + "#elif (PS_ATST == 4)\n" + " if (abs(a - AREF) < 0.5f) discard;\n" + "#endif\n" + "\n" + "#endif\n" + "\n" "}\n" "\n" "void fog(inout vec4 C, float f)\n"