From d7cdbf6f2718e817c77fed2495d1345b422c1218 Mon Sep 17 00:00:00 2001 From: lightningterror Date: Wed, 22 Aug 2018 00:51:19 +0200 Subject: [PATCH] Gsdx: Point Sampler changes. Re add point sampler to OpenGL. Fixes graphical issues when Allow 8-bit textures is enabled on AMD gpus. Issue: https://forums.pcsx2.net/Thread-GSDX-Hardware-mode-Bug-Report-Allow-8-bit-Texture Adjust the code to be easier to read, and execute the gl code only on amd - suggested by Gregory. Remove useless ATI_SUCKS define in tfx shader.It wasn't used anywhere outside of the shader. --- plugins/GSdx/GSDeviceOGL.cpp | 2 +- plugins/GSdx/GSDeviceOGL.h | 3 ++- plugins/GSdx/GSRendererDX.cpp | 2 +- plugins/GSdx/GSRendererOGL.cpp | 3 ++- plugins/GSdx/res/glsl/tfx_fs.glsl | 9 +++++++++ plugins/GSdx/res/tfx.fx | 5 +---- 6 files changed, 16 insertions(+), 8 deletions(-) diff --git a/plugins/GSdx/GSDeviceOGL.cpp b/plugins/GSdx/GSDeviceOGL.cpp index de5b023e4a..8003324ab3 100644 --- a/plugins/GSdx/GSDeviceOGL.cpp +++ b/plugins/GSdx/GSDeviceOGL.cpp @@ -961,7 +961,7 @@ GLuint GSDeviceOGL::CompilePS(PSSelector sel) + format("#define PS_COLCLIP %d\n", sel.colclip) + format("#define PS_DATE %d\n", sel.date) + format("#define PS_TCOFFSETHACK %d\n", sel.tcoffsethack) - //+ format("#define PS_POINT_SAMPLER %d\n", sel.point_sampler) + + format("#define PS_POINT_SAMPLER %d\n", sel.point_sampler) + format("#define PS_BLEND_A %d\n", sel.blend_a) + format("#define PS_BLEND_B %d\n", sel.blend_b) + format("#define PS_BLEND_C %d\n", sel.blend_c) diff --git a/plugins/GSdx/GSDeviceOGL.h b/plugins/GSdx/GSDeviceOGL.h index 8e1fccc883..d2ca94e036 100644 --- a/plugins/GSdx/GSDeviceOGL.h +++ b/plugins/GSdx/GSDeviceOGL.h @@ -301,8 +301,9 @@ public: uint32 tex_is_fb:1; // Jak Shadows uint32 automatic_lod:1; uint32 manual_lod:1; + uint32 point_sampler:1; - uint32 _free2:11; + uint32 _free2:10; }; uint64 key; diff --git a/plugins/GSdx/GSRendererDX.cpp b/plugins/GSdx/GSRendererDX.cpp index b10cab102b..9c413e2dc8 100644 --- a/plugins/GSdx/GSRendererDX.cpp +++ b/plugins/GSdx/GSRendererDX.cpp @@ -300,7 +300,7 @@ void GSRendererDX::EmulateTextureSampler(const GSTextureCache::Source* tex) m_ps_sel.rt = tex->m_target; m_ps_sel.spritehack = tex->m_spritehack_t; - m_ps_sel.point_sampler = !(bilinear && !shader_emulated_sampler); + m_ps_sel.point_sampler = !bilinear || shader_emulated_sampler; if (PRIM->FST) { diff --git a/plugins/GSdx/GSRendererOGL.cpp b/plugins/GSdx/GSRendererOGL.cpp index 92eadb4c7a..91cc02a8bc 100644 --- a/plugins/GSdx/GSRendererOGL.cpp +++ b/plugins/GSdx/GSRendererOGL.cpp @@ -391,7 +391,7 @@ void GSRendererOGL::EmulateTextureShuffleAndFbmask() // The safe and accurate path (but slow) GL_INS("FBMASK SW emulated fb_mask:%x on %d bits format", m_context->FRAME.FBMSK, (GSLocalMemory::m_psm[m_context->FRAME.PSM].fmt == 2) ? 16 : 32); - m_require_full_barrier = true;; + m_require_full_barrier = true; } } } @@ -816,6 +816,7 @@ void GSRendererOGL::EmulateTextureSampler(const GSTextureCache::Source* tex) m_ps_sel.tcc = m_context->TEX0.TCC; m_ps_sel.ltf = bilinear && shader_emulated_sampler; + m_ps_sel.point_sampler = GLLoader::vendor_id_amd && (!bilinear || shader_emulated_sampler); int w = tex->m_texture->GetWidth(); int h = tex->m_texture->GetHeight(); diff --git a/plugins/GSdx/res/glsl/tfx_fs.glsl b/plugins/GSdx/res/glsl/tfx_fs.glsl index 27b7e4f943..6adef160c9 100644 --- a/plugins/GSdx/res/glsl/tfx_fs.glsl +++ b/plugins/GSdx/res/glsl/tfx_fs.glsl @@ -82,6 +82,15 @@ vec4 sample_c(vec2 uv) return texelFetch(RtSampler, ivec2(gl_FragCoord.xy), 0); #else +#if PS_POINT_SAMPLER + // Weird issue with ATI cards (happens on at least HD 4xxx and 5xxx), + // it looks like they add 127/128 of a texel to sampling coordinates + // occasionally causing point sampling to erroneously round up. + // I'm manually adjusting coordinates to the centre of texels here, + // though the centre is just paranoia, the top left corner works fine. + uv = (trunc(uv * WH.zw) + vec2(0.5, 0.5)) / WH.zw; +#endif + #if PS_AUTOMATIC_LOD == 1 return texture(TextureSampler, uv); #elif PS_MANUAL_LOD == 1 diff --git a/plugins/GSdx/res/tfx.fx b/plugins/GSdx/res/tfx.fx index 0de2bbabf0..4ae3a4b148 100644 --- a/plugins/GSdx/res/tfx.fx +++ b/plugins/GSdx/res/tfx.fx @@ -3,9 +3,6 @@ #define FMT_24 1 #define FMT_16 2 -// And I say this as an ATI user. -#define ATI_SUCKS 1 - #if SHADER_MODEL >= 0x400 #ifndef VS_BPPZ @@ -116,7 +113,7 @@ cbuffer cb2 float4 sample_c(float2 uv) { - if (ATI_SUCKS && PS_POINT_SAMPLER) + if (PS_POINT_SAMPLER) { // Weird issue with ATI cards (happens on at least HD 4xxx and 5xxx), // it looks like they add 127/128 of a texel to sampling coordinates