From 78dd9577174857f1218b2b87457fa1470a6d7140 Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Fri, 14 Aug 2015 17:53:41 +0200 Subject: [PATCH] gsdx-ogl: use normalized index coordinate for palette texture In palette mode, 90% of texture accesses are done in 8 bits. So let's keep this path as light as possible. It reduces GPU load. --- plugins/GSdx/res/glsl/tfx_fs.glsl | 18 +++++++++++------- plugins/GSdx/res/glsl_source.h | 18 +++++++++++------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/plugins/GSdx/res/glsl/tfx_fs.glsl b/plugins/GSdx/res/glsl/tfx_fs.glsl index af71932801..df482558ed 100644 --- a/plugins/GSdx/res/glsl/tfx_fs.glsl +++ b/plugins/GSdx/res/glsl/tfx_fs.glsl @@ -80,9 +80,9 @@ vec4 sample_c(vec2 uv) return texture(TextureSampler, uv); } -vec4 sample_p(uint idx) +vec4 sample_p(float idx) { - return texelFetch(PaletteSampler, ivec2(idx, 0u), 0); + return texture(PaletteSampler, vec2(idx, 0.0f)); } vec4 wrapuv(vec4 uv) @@ -149,7 +149,7 @@ mat4 sample_4c(vec4 uv) return c; } -uvec4 sample_4_index(vec4 uv) +vec4 sample_4_index(vec4 uv) { vec4 c; @@ -169,18 +169,22 @@ uvec4 sample_4_index(vec4 uv) #if PS_IFMT == 1 // 4HH - return i >> 4u; + return vec4(i >> 4u) / 255.0f; + #elif PS_IFMT == 2 // 4HL - return i & 0xFu; + return vec4(i & 0xFu) / 255.0f; + #else + // Most of texture will hit this code so keep normalized float value + // 8 bits - return i; + return c; #endif } -mat4 sample_4p(uvec4 u) +mat4 sample_4p(vec4 u) { mat4 c; diff --git a/plugins/GSdx/res/glsl_source.h b/plugins/GSdx/res/glsl_source.h index 27cb31c417..3139c86853 100644 --- a/plugins/GSdx/res/glsl_source.h +++ b/plugins/GSdx/res/glsl_source.h @@ -939,9 +939,9 @@ static const char* tfx_fs_all_glsl = " return texture(TextureSampler, uv);\n" "}\n" "\n" - "vec4 sample_p(uint idx)\n" + "vec4 sample_p(float idx)\n" "{\n" - " return texelFetch(PaletteSampler, ivec2(idx, 0u), 0);\n" + " return texture(PaletteSampler, vec2(idx, 0.0f));\n" "}\n" "\n" "vec4 wrapuv(vec4 uv)\n" @@ -1008,7 +1008,7 @@ static const char* tfx_fs_all_glsl = " return c;\n" "}\n" "\n" - "uvec4 sample_4_index(vec4 uv)\n" + "vec4 sample_4_index(vec4 uv)\n" "{\n" " vec4 c;\n" "\n" @@ -1028,18 +1028,22 @@ static const char* tfx_fs_all_glsl = "\n" "#if PS_IFMT == 1\n" " // 4HH\n" - " return i >> 4u;\n" + " return vec4(i >> 4u) / 255.0f;\n" + "\n" "#elif PS_IFMT == 2\n" " // 4HL\n" - " return i & 0xFu;\n" + " return vec4(i & 0xFu) / 255.0f;\n" + "\n" "#else\n" + " // Most of texture will hit this code so keep normalized float value\n" + "\n" " // 8 bits\n" - " return i;\n" + " return c;\n" "#endif\n" "\n" "}\n" "\n" - "mat4 sample_4p(uvec4 u)\n" + "mat4 sample_4p(vec4 u)\n" "{\n" " mat4 c;\n" "\n"