diff --git a/plugins/GSdx/GSDeviceOGL.cpp b/plugins/GSdx/GSDeviceOGL.cpp index 0e9c921561..10745619b8 100644 --- a/plugins/GSdx/GSDeviceOGL.cpp +++ b/plugins/GSdx/GSDeviceOGL.cpp @@ -778,6 +778,7 @@ GLuint GSDeviceOGL::CompilePS(PSSelector sel) + format("#define PS_TEX_FMT %d\n", sel.tex_fmt) + format("#define PS_DFMT %d\n", sel.dfmt) + format("#define PS_DEPTH_FMT %d\n", sel.depth_fmt) + + format("#define PS_CHANNEL_FETCH %d\n", sel.channel) + format("#define PS_AEM %d\n", sel.aem) + format("#define PS_TFX %d\n", sel.tfx) + format("#define PS_TCC %d\n", sel.tcc) @@ -920,42 +921,48 @@ void GSDeviceOGL::SelfShaderTest() PRINT_TEST("Fst/Tc/IIp"); // Test: tfx/tcc - for (int tfx = 0; tfx < 5; tfx++) { - for (int tcc = 0; tcc < 2; tcc++) { - PSSelector sel; - sel.atst = 1; - sel.fst = 1; + for (int channel = 0; channel < 5; channel++) { + for (int tfx = 0; tfx < 5; tfx++) { + for (int tcc = 0; tcc < 2; tcc++) { + PSSelector sel; + sel.atst = 1; + sel.fst = 1; - sel.tfx = tfx; - sel.tcc = tcc; - std::string file = format("Shader_Tfx_%d__Tcc_%d.glsl.asm", tfx, tcc); - RUN_TEST; + sel.channel = channel; + sel.tfx = tfx; + sel.tcc = tcc; + std::string file = format("Shader_Tfx_%d__Tcc_%d__Channel_%d.glsl.asm", tfx, tcc, channel); + RUN_TEST; + } } } - PRINT_TEST("Tfx/Tcc"); + PRINT_TEST("Tfx/Tcc/Channel"); // Test: Texture Sampling - for (int fmt = 0; fmt < 16; fmt++) { - if ((fmt & 3) == 3) continue; + for (int depth = 0; depth < 4; depth++) { + for (int fmt = 0; fmt < 16; fmt++) { + if ((fmt & 3) == 3) continue; - for (int ltf = 0; ltf < 2; ltf++) { - for (int aem = 0; aem < 2; aem++) { - for (int wms = 1; wms < 4; wms++) { - for (int wmt = 1; wmt < 4; wmt++) { - PSSelector sel; - sel.atst = 1; - sel.tfx = 1; - sel.tcc = 1; - sel.fst = 1; + for (int ltf = 0; ltf < 2; ltf++) { + for (int aem = 0; aem < 2; aem++) { + for (int wms = 1; wms < 4; wms++) { + for (int wmt = 1; wmt < 4; wmt++) { + PSSelector sel; + sel.atst = 1; + sel.tfx = 1; + sel.tcc = 1; + sel.fst = 1; - sel.ltf = ltf; - sel.aem = aem; - sel.tex_fmt = fmt; - sel.wms = wms; - sel.wmt = wmt; - std::string file = format("Shader_Ltf_%d__Aem_%d__TFmt_%d__Wms_%d__Wmt_%d.glsl.asm", - ltf, aem, fmt, wms, wmt); - RUN_TEST; + sel.depth_fmt = depth; + sel.ltf = ltf; + sel.aem = aem; + sel.tex_fmt = fmt; + sel.wms = wms; + sel.wmt = wmt; + std::string file = format("Shader_Ltf_%d__Aem_%d__TFmt_%d__Wms_%d__Wmt_%d__DepthFmt_%d.glsl.asm", + ltf, aem, fmt, wms, wmt, depth); + RUN_TEST; + } } } } diff --git a/plugins/GSdx/GSDeviceOGL.h b/plugins/GSdx/GSDeviceOGL.h index 962b4c282e..47d1bb87f7 100644 --- a/plugins/GSdx/GSDeviceOGL.h +++ b/plugins/GSdx/GSDeviceOGL.h @@ -284,10 +284,13 @@ class GSDeviceOGL final : public GSDevice uint32 hdr:1; uint32 colclip:1; + // Others ways to fetch the texture + uint32 channel:3; + // Hack uint32 tcoffsethack:1; - uint32 _free2:19; + uint32 _free2:16; }; uint64 key; diff --git a/plugins/GSdx/res/glsl/tfx_fs.glsl b/plugins/GSdx/res/glsl/tfx_fs.glsl index 9d81c22559..65439c9376 100644 --- a/plugins/GSdx/res/glsl/tfx_fs.glsl +++ b/plugins/GSdx/res/glsl/tfx_fs.glsl @@ -261,6 +261,34 @@ vec4 sample_depth(vec2 st) return t; } + +////////////////////////////////////////////////////////////////////// +// Fetch a Single Channel +////////////////////////////////////////////////////////////////////// +vec4 fetch_red() +{ + vec4 rt = texelFetch(RtSampler, ivec2(gl_FragCoord.xy), 0); + return sample_p(rt.r) * 255.0f; +} + +vec4 fetch_blue() +{ + vec4 rt = texelFetch(RtSampler, ivec2(gl_FragCoord.xy), 0); + return sample_p(rt.b) * 255.0f; +} + +vec4 fetch_green() +{ + vec4 rt = texelFetch(RtSampler, ivec2(gl_FragCoord.xy), 0); + return sample_p(rt.g) * 255.0f; +} + +vec4 fetch_alpha() +{ + vec4 rt = texelFetch(RtSampler, ivec2(gl_FragCoord.xy), 0); + return sample_p(rt.a) * 255.0f; +} + ////////////////////////////////////////////////////////////////////// vec4 sample_color(vec2 st) @@ -422,7 +450,15 @@ vec4 ps_color() vec2 st = PSin.t_int.xy; #endif -#if (PS_DEPTH_FMT > 0) +#if PS_CHANNEL_FETCH == 1 + vec4 T = fetch_red(); +#elif PS_CHANNEL_FETCH == 2 + vec4 T = fetch_green(); +#elif PS_CHANNEL_FETCH == 3 + vec4 T = fetch_blue(); +#elif PS_CHANNEL_FETCH == 4 + vec4 T = fetch_alpha(); +#elif PS_DEPTH_FMT > 0 // Integral coordinate vec4 T = sample_depth(PSin.t_int.zw); #else diff --git a/plugins/GSdx/res/glsl_source.h b/plugins/GSdx/res/glsl_source.h index 3ed2b1b442..2ad233ea4e 100644 --- a/plugins/GSdx/res/glsl_source.h +++ b/plugins/GSdx/res/glsl_source.h @@ -1105,6 +1105,34 @@ static const char* const tfx_fs_all_glsl = "\n" " return t;\n" "}\n" + "\n" + "//////////////////////////////////////////////////////////////////////\n" + "// Fetch a Single Channel\n" + "//////////////////////////////////////////////////////////////////////\n" + "vec4 fetch_red()\n" + "{\n" + " vec4 rt = texelFetch(RtSampler, ivec2(gl_FragCoord.xy), 0);\n" + " return sample_p(rt.r) * 255.0f;\n" + "}\n" + "\n" + "vec4 fetch_blue()\n" + "{\n" + " vec4 rt = texelFetch(RtSampler, ivec2(gl_FragCoord.xy), 0);\n" + " return sample_p(rt.b) * 255.0f;\n" + "}\n" + "\n" + "vec4 fetch_green()\n" + "{\n" + " vec4 rt = texelFetch(RtSampler, ivec2(gl_FragCoord.xy), 0);\n" + " return sample_p(rt.g) * 255.0f;\n" + "}\n" + "\n" + "vec4 fetch_alpha()\n" + "{\n" + " vec4 rt = texelFetch(RtSampler, ivec2(gl_FragCoord.xy), 0);\n" + " return sample_p(rt.a) * 255.0f;\n" + "}\n" + "\n" "//////////////////////////////////////////////////////////////////////\n" "\n" "vec4 sample_color(vec2 st)\n" @@ -1266,7 +1294,15 @@ static const char* const tfx_fs_all_glsl = " vec2 st = PSin.t_int.xy;\n" "#endif\n" "\n" - "#if (PS_DEPTH_FMT > 0)\n" + "#if PS_CHANNEL_FETCH == 1\n" + " vec4 T = fetch_red();\n" + "#elif PS_CHANNEL_FETCH == 2\n" + " vec4 T = fetch_green();\n" + "#elif PS_CHANNEL_FETCH == 3\n" + " vec4 T = fetch_blue();\n" + "#elif PS_CHANNEL_FETCH == 4\n" + " vec4 T = fetch_alpha();\n" + "#elif PS_DEPTH_FMT > 0\n" " // Integral coordinate\n" " vec4 T = sample_depth(PSin.t_int.zw);\n" "#else\n"