gsdx ogl: extend shader to lookup a single channel

This commit is contained in:
Gregory Hainaut 2016-04-28 22:15:28 +02:00
parent eaa4fd41e2
commit c445a14c46
4 changed files with 114 additions and 32 deletions

View File

@ -778,6 +778,7 @@ GLuint GSDeviceOGL::CompilePS(PSSelector sel)
+ format("#define PS_TEX_FMT %d\n", sel.tex_fmt) + format("#define PS_TEX_FMT %d\n", sel.tex_fmt)
+ format("#define PS_DFMT %d\n", sel.dfmt) + format("#define PS_DFMT %d\n", sel.dfmt)
+ format("#define PS_DEPTH_FMT %d\n", sel.depth_fmt) + 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_AEM %d\n", sel.aem)
+ format("#define PS_TFX %d\n", sel.tfx) + format("#define PS_TFX %d\n", sel.tfx)
+ format("#define PS_TCC %d\n", sel.tcc) + format("#define PS_TCC %d\n", sel.tcc)
@ -920,42 +921,48 @@ void GSDeviceOGL::SelfShaderTest()
PRINT_TEST("Fst/Tc/IIp"); PRINT_TEST("Fst/Tc/IIp");
// Test: tfx/tcc // Test: tfx/tcc
for (int tfx = 0; tfx < 5; tfx++) { for (int channel = 0; channel < 5; channel++) {
for (int tcc = 0; tcc < 2; tcc++) { for (int tfx = 0; tfx < 5; tfx++) {
PSSelector sel; for (int tcc = 0; tcc < 2; tcc++) {
sel.atst = 1; PSSelector sel;
sel.fst = 1; sel.atst = 1;
sel.fst = 1;
sel.tfx = tfx; sel.channel = channel;
sel.tcc = tcc; sel.tfx = tfx;
std::string file = format("Shader_Tfx_%d__Tcc_%d.glsl.asm", tfx, tcc); sel.tcc = tcc;
RUN_TEST; 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 // Test: Texture Sampling
for (int fmt = 0; fmt < 16; fmt++) { for (int depth = 0; depth < 4; depth++) {
if ((fmt & 3) == 3) continue; for (int fmt = 0; fmt < 16; fmt++) {
if ((fmt & 3) == 3) continue;
for (int ltf = 0; ltf < 2; ltf++) { for (int ltf = 0; ltf < 2; ltf++) {
for (int aem = 0; aem < 2; aem++) { for (int aem = 0; aem < 2; aem++) {
for (int wms = 1; wms < 4; wms++) { for (int wms = 1; wms < 4; wms++) {
for (int wmt = 1; wmt < 4; wmt++) { for (int wmt = 1; wmt < 4; wmt++) {
PSSelector sel; PSSelector sel;
sel.atst = 1; sel.atst = 1;
sel.tfx = 1; sel.tfx = 1;
sel.tcc = 1; sel.tcc = 1;
sel.fst = 1; sel.fst = 1;
sel.ltf = ltf; sel.depth_fmt = depth;
sel.aem = aem; sel.ltf = ltf;
sel.tex_fmt = fmt; sel.aem = aem;
sel.wms = wms; sel.tex_fmt = fmt;
sel.wmt = wmt; sel.wms = wms;
std::string file = format("Shader_Ltf_%d__Aem_%d__TFmt_%d__Wms_%d__Wmt_%d.glsl.asm", sel.wmt = wmt;
ltf, aem, fmt, wms, wmt); std::string file = format("Shader_Ltf_%d__Aem_%d__TFmt_%d__Wms_%d__Wmt_%d__DepthFmt_%d.glsl.asm",
RUN_TEST; ltf, aem, fmt, wms, wmt, depth);
RUN_TEST;
}
} }
} }
} }

View File

@ -284,10 +284,13 @@ class GSDeviceOGL final : public GSDevice
uint32 hdr:1; uint32 hdr:1;
uint32 colclip:1; uint32 colclip:1;
// Others ways to fetch the texture
uint32 channel:3;
// Hack // Hack
uint32 tcoffsethack:1; uint32 tcoffsethack:1;
uint32 _free2:19; uint32 _free2:16;
}; };
uint64 key; uint64 key;

View File

@ -261,6 +261,34 @@ vec4 sample_depth(vec2 st)
return t; 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) vec4 sample_color(vec2 st)
@ -422,7 +450,15 @@ vec4 ps_color()
vec2 st = PSin.t_int.xy; vec2 st = PSin.t_int.xy;
#endif #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 // Integral coordinate
vec4 T = sample_depth(PSin.t_int.zw); vec4 T = sample_depth(PSin.t_int.zw);
#else #else

View File

@ -1105,6 +1105,34 @@ static const char* const tfx_fs_all_glsl =
"\n" "\n"
" return t;\n" " return t;\n"
"}\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"
"\n" "\n"
"vec4 sample_color(vec2 st)\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" " vec2 st = PSin.t_int.xy;\n"
"#endif\n" "#endif\n"
"\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" " // Integral coordinate\n"
" vec4 T = sample_depth(PSin.t_int.zw);\n" " vec4 T = sample_depth(PSin.t_int.zw);\n"
"#else\n" "#else\n"