From 15ae9996bbfbf9a5dc9af7541954ef9e272e97a5 Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Sat, 25 Apr 2015 12:46:59 +0200 Subject: [PATCH] glsl: format white space + comment --- plugins/GSdx/res/glsl/tfx_fs.glsl | 388 +++++++++++++++--------------- plugins/GSdx/res/glsl_source.h | 388 +++++++++++++++--------------- 2 files changed, 386 insertions(+), 390 deletions(-) diff --git a/plugins/GSdx/res/glsl/tfx_fs.glsl b/plugins/GSdx/res/glsl/tfx_fs.glsl index 3ecdb53c81..51eb214a69 100644 --- a/plugins/GSdx/res/glsl/tfx_fs.glsl +++ b/plugins/GSdx/res/glsl/tfx_fs.glsl @@ -45,13 +45,13 @@ in SHADER { - vec4 t; - vec4 c; - flat vec4 fc; + vec4 t; + vec4 c; + flat vec4 fc; #if PS_SPRITE == 1 - flat vec4 flat_T; - flat vec2 flat_P; - vec2 alpha; + flat vec4 flat_T; + flat vec2 flat_P; + vec2 alpha; #endif } PSin; @@ -80,30 +80,26 @@ layout(binding = 3) uniform sampler2D RtSampler; // note 2 already use by the im #if PS_DATE > 0 // FIXME how to declare memory access layout(r32i, binding = 2) coherent uniform iimage2D img_prim_min; +layout(early_fragment_tests) in; +// origin_upper_left +layout(pixel_center_integer) in vec4 gl_FragCoord; #endif #else // use basic stencil #endif -#ifndef DISABLE_GL42_image -#if PS_DATE > 0 -// origin_upper_left -layout(pixel_center_integer) in vec4 gl_FragCoord; -//in int gl_PrimitiveID; -#endif -#endif layout(std140, binding = 21) uniform cb21 { - vec3 FogColor; - float AREF; - vec4 WH; - vec2 MinF; - vec2 TA; - uvec4 MskFix; - vec4 HalfTexel; - vec4 MinMax; - vec4 TC_OffsetHack; + vec3 FogColor; + float AREF; + vec4 WH; + vec2 MinF; + vec2 TA; + uvec4 MskFix; + vec4 HalfTexel; + vec4 MinMax; + vec4 TC_OffsetHack; }; #ifdef SUBROUTINE_GL40 @@ -121,242 +117,242 @@ layout(location = 1) subroutine uniform ColClipType colclip; vec4 sample_c(vec2 uv) { - // FIXME: check the issue on openGL + // FIXME: check the issue on openGL #if (ATI_SUCKS == 1) && (PS_POINT_SAMPLER == 1) - // 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; + // 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 - return texture(TextureSampler, uv); + return texture(TextureSampler, uv); } vec4 sample_p(float u) { - //FIXME do we need a 1D sampler. Big impact on opengl to find 1 dim - // So for the moment cheat with 0.0f dunno if it work - return texture(PaletteSampler, vec2(u, 0.0f)); + //FIXME do we need a 1D sampler. Big impact on opengl to find 1 dim + // So for the moment cheat with 0.0f dunno if it work + return texture(PaletteSampler, vec2(u, 0.0f)); } vec4 wrapuv(vec4 uv) { - vec4 uv_out = uv; + vec4 uv_out = uv; #if PS_WMS == PS_WMT #if PS_WMS == 2 - uv_out = clamp(uv, MinMax.xyxy, MinMax.zwzw); + uv_out = clamp(uv, MinMax.xyxy, MinMax.zwzw); #elif PS_WMS == 3 - uv_out = vec4((ivec4(uv * WH.xyxy) & ivec4(MskFix.xyxy)) | ivec4(MskFix.zwzw)) / WH.xyxy; + uv_out = vec4((ivec4(uv * WH.xyxy) & ivec4(MskFix.xyxy)) | ivec4(MskFix.zwzw)) / WH.xyxy; #endif #else // PS_WMS != PS_WMT #if PS_WMS == 2 - uv_out.xz = clamp(uv.xz, MinMax.xx, MinMax.zz); + uv_out.xz = clamp(uv.xz, MinMax.xx, MinMax.zz); #elif PS_WMS == 3 - uv_out.xz = vec2((ivec2(uv.xz * WH.xx) & ivec2(MskFix.xx)) | ivec2(MskFix.zz)) / WH.xx; + uv_out.xz = vec2((ivec2(uv.xz * WH.xx) & ivec2(MskFix.xx)) | ivec2(MskFix.zz)) / WH.xx; #endif #if PS_WMT == 2 - uv_out.yw = clamp(uv.yw, MinMax.yy, MinMax.ww); + uv_out.yw = clamp(uv.yw, MinMax.yy, MinMax.ww); #elif PS_WMT == 3 - uv_out.yw = vec2((ivec2(uv.yw * WH.yy) & ivec2(MskFix.yy)) | ivec2(MskFix.ww)) / WH.yy; + uv_out.yw = vec2((ivec2(uv.yw * WH.yy) & ivec2(MskFix.yy)) | ivec2(MskFix.ww)) / WH.yy; #endif #endif - return uv_out; + return uv_out; } vec2 clampuv(vec2 uv) { - vec2 uv_out = uv; + vec2 uv_out = uv; -#if (PS_WMS == 2) && (PS_WMT == 2) - uv_out = clamp(uv, MinF, MinMax.zw); +#if (PS_WMS == 2) && (PS_WMT == 2) + uv_out = clamp(uv, MinF, MinMax.zw); #elif PS_WMS == 2 - uv_out.x = clamp(uv.x, MinF.x, MinMax.z); + uv_out.x = clamp(uv.x, MinF.x, MinMax.z); #elif PS_WMT == 2 - uv_out.y = clamp(uv.y, MinF.y, MinMax.w); + uv_out.y = clamp(uv.y, MinF.y, MinMax.w); #endif - return uv_out; + return uv_out; } mat4 sample_4c(vec4 uv) { - mat4 c; + mat4 c; - c[0] = sample_c(uv.xy); - c[1] = sample_c(uv.zy); - c[2] = sample_c(uv.xw); - c[3] = sample_c(uv.zw); + c[0] = sample_c(uv.xy); + c[1] = sample_c(uv.zy); + c[2] = sample_c(uv.xw); + c[3] = sample_c(uv.zw); - return c; + return c; } vec4 sample_4a(vec4 uv) { - vec4 c; + vec4 c; - // Dx used the alpha channel. - // Opengl is only 8 bits on red channel. - c.x = sample_c(uv.xy).r; - c.y = sample_c(uv.zy).r; - c.z = sample_c(uv.xw).r; - c.w = sample_c(uv.zw).r; + // Dx used the alpha channel. + // Opengl is only 8 bits on red channel. + c.x = sample_c(uv.xy).r; + c.y = sample_c(uv.zy).r; + c.z = sample_c(uv.xw).r; + c.w = sample_c(uv.zw).r; return c * 255.0/256.0 + 0.5/256.0; } mat4 sample_4p(vec4 u) { - mat4 c; + mat4 c; - c[0] = sample_p(u.x); - c[1] = sample_p(u.y); - c[2] = sample_p(u.z); - c[3] = sample_p(u.w); + c[0] = sample_p(u.x); + c[1] = sample_p(u.y); + c[2] = sample_p(u.z); + c[3] = sample_p(u.w); - return c; + return c; } vec4 sample_color(vec2 st, float q) { #if (PS_FST == 0) - st /= q; + st /= q; #endif #if (PS_TCOFFSETHACK == 1) - st += TC_OffsetHack.xy; + st += TC_OffsetHack.xy; #endif - vec4 t; - mat4 c; - vec2 dd; + vec4 t; + mat4 c; + vec2 dd; #if (PS_LTF == 0 && PS_FMT <= FMT_16 && PS_WMS < 3 && PS_WMT < 3) - c[0] = sample_c(clampuv(st)); + c[0] = sample_c(clampuv(st)); #ifdef TEX_COORD_DEBUG - c[0].rg = clampuv(st).xy; + c[0].rg = clampuv(st).xy; #endif #else - vec4 uv; + vec4 uv; - if(PS_LTF != 0) - { - uv = st.xyxy + HalfTexel; - dd = fract(uv.xy * WH.zw); - } - else - { - uv = st.xyxy; - } + if(PS_LTF != 0) + { + uv = st.xyxy + HalfTexel; + dd = fract(uv.xy * WH.zw); + } + else + { + uv = st.xyxy; + } - uv = wrapuv(uv); + uv = wrapuv(uv); - if((PS_FMT & FMT_PAL) != 0) - { - c = sample_4p(sample_4a(uv)); - } - else - { - c = sample_4c(uv); - } + if((PS_FMT & FMT_PAL) != 0) + { + c = sample_4p(sample_4a(uv)); + } + else + { + c = sample_4c(uv); + } #ifdef TEX_COORD_DEBUG - c[0].rg = uv.xy; - c[1].rg = uv.xy; - c[2].rg = uv.xy; - c[3].rg = uv.xy; + c[0].rg = uv.xy; + c[1].rg = uv.xy; + c[2].rg = uv.xy; + c[3].rg = uv.xy; #endif #endif - // PERF: see the impact of the exansion before/after the interpolation - for (int i = 0; i < 4; i++) - { + // PERF: see the impact of the exansion before/after the interpolation + for (int i = 0; i < 4; i++) + { #if ((PS_FMT & ~FMT_PAL) == FMT_24) - c[i].a = ( (PS_AEM == 0) || any(bvec3(c[i].rgb)) ) ? TA.x : 0.0f; + c[i].a = ( (PS_AEM == 0) || any(bvec3(c[i].rgb)) ) ? TA.x : 0.0f; #elif ((PS_FMT & ~FMT_PAL) == FMT_16) - c[i].a = c[i].a >= 0.5 ? TA.y : ( (PS_AEM == 0) || any(bvec3(c[i].rgb)) ) ? TA.x : 0.0f; + c[i].a = c[i].a >= 0.5 ? TA.y : ( (PS_AEM == 0) || any(bvec3(c[i].rgb)) ) ? TA.x : 0.0f; #endif - } + } #if(PS_LTF != 0) - t = mix(mix(c[0], c[1], dd.x), mix(c[2], c[3], dd.x), dd.y); + t = mix(mix(c[0], c[1], dd.x), mix(c[2], c[3], dd.x), dd.y); #else - t = c[0]; + t = c[0]; #endif - return t; + return t; } #ifndef SUBROUTINE_GL40 vec4 tfx(vec4 t, vec4 c) { - vec4 c_out = c; + vec4 c_out = c; #if (PS_TFX == 0) - if(PS_TCC != 0) - c_out = c * t * 255.0f / 128.0f; - else - c_out.rgb = c.rgb * t.rgb * 255.0f / 128.0f; + if(PS_TCC != 0) + c_out = c * t * 255.0f / 128.0f; + else + c_out.rgb = c.rgb * t.rgb * 255.0f / 128.0f; #elif (PS_TFX == 1) - if(PS_TCC != 0) - c_out = t; - else - c_out.rgb = t.rgb; + if(PS_TCC != 0) + c_out = t; + else + c_out.rgb = t.rgb; #elif (PS_TFX == 2) - c_out.rgb = c.rgb * t.rgb * 255.0f / 128.0f + c.a; + c_out.rgb = c.rgb * t.rgb * 255.0f / 128.0f + c.a; - if(PS_TCC != 0) - c_out.a += t.a; + if(PS_TCC != 0) + c_out.a += t.a; #elif (PS_TFX == 3) - c_out.rgb = c.rgb * t.rgb * 255.0f / 128.0f + c.a; + c_out.rgb = c.rgb * t.rgb * 255.0f / 128.0f + c.a; - if(PS_TCC != 0) - c_out.a = t.a; + if(PS_TCC != 0) + c_out.a = t.a; #endif - return c_out; + return c_out; } #endif #ifndef SUBROUTINE_GL40 void atst(vec4 c) { - float a = trunc(c.a * 255.0 + 0.01); + float a = trunc(c.a * 255.0 + 0.01); #if (PS_ATST == 0) // never - discard; + discard; #elif (PS_ATST == 1) // always - // nothing to do + // nothing to do #elif (PS_ATST == 2) && (PS_SPRITEHACK == 0) // l - if ((AREF - a - 0.5f) < 0.0f) - discard; + if ((AREF - a - 0.5f) < 0.0f) + discard; #elif (PS_ATST == 3 ) // le - if ((AREF - a + 0.5f) < 0.0f) - discard; + if ((AREF - a + 0.5f) < 0.0f) + discard; #elif (PS_ATST == 4) // e - if ((0.5f - abs(a - AREF)) < 0.0f) - discard; + if ((0.5f - abs(a - AREF)) < 0.0f) + discard; #elif (PS_ATST == 5) // ge - if ((a-AREF + 0.5f) < 0.0f) - discard; + if ((a-AREF + 0.5f) < 0.0f) + discard; #elif (PS_ATST == 6) // g - if ((a-AREF - 0.5f) < 0.0f) - discard; + if ((a-AREF - 0.5f) < 0.0f) + discard; #elif (PS_ATST == 7) // ne - if ((abs(a - AREF) - 0.5f) < 0.0f) - discard; + if ((abs(a - AREF) - 0.5f) < 0.0f) + discard; #endif } #endif @@ -366,12 +362,12 @@ void atst(vec4 c) void colclip(inout vec4 c) { #if (PS_COLCLIP == 2) - c.rgb = 256.0f/255.0f - c.rgb; + c.rgb = 256.0f/255.0f - c.rgb; #elif (PS_COLCLIP > 0) - // FIXME !!!! - //c.rgb *= c.rgb < 128./255; - bvec3 factor = bvec3(128.0f/255.0f, 128.0f/255.0f, 128.0f/255.0f); - c.rgb *= vec3(factor); + // FIXME !!!! + //c.rgb *= c.rgb < 128./255; + bvec3 factor = bvec3(128.0f/255.0f, 128.0f/255.0f, 128.0f/255.0f); + c.rgb *= vec3(factor); #endif } #endif @@ -379,59 +375,59 @@ void colclip(inout vec4 c) void fog(inout vec4 c, float f) { #if PS_FOG != 0 - c.rgb = mix(FogColor, c.rgb, f); + c.rgb = mix(FogColor, c.rgb, f); #endif } vec4 ps_color() { #if PS_SPRITE == 1 - // Reinterpolate manually the texture coordinate. - // trunc => native resolution. Maybe we can add an option to choose a value between - // trunc and current. - vec2 factor = vec2(trunc(PSin.alpha.x), floor(PSin.alpha.y)); - //vec2 factor = trunc(PSin.alpha); - factor *= PSin.flat_P; - vec2 txy; - txy.x = mix(PSin.flat_T.x, PSin.flat_T.y, factor.x); - txy.y = mix(PSin.flat_T.z, PSin.flat_T.w, factor.y); + // Reinterpolate manually the texture coordinate. + // trunc => native resolution. Maybe we can add an option to choose a value between + // trunc and current. + vec2 factor = vec2(trunc(PSin.alpha.x), floor(PSin.alpha.y)); + //vec2 factor = trunc(PSin.alpha); + factor *= PSin.flat_P; + vec2 txy; + txy.x = mix(PSin.flat_T.x, PSin.flat_T.y, factor.x); + txy.y = mix(PSin.flat_T.z, PSin.flat_T.w, factor.y); #else - vec2 txy = PSin_t.xy; + vec2 txy = PSin_t.xy; #endif - vec4 t = sample_color(txy, PSin_t.w); + vec4 t = sample_color(txy, PSin_t.w); - vec4 zero = vec4(0.0f, 0.0f, 0.0f, 0.0f); - vec4 one = vec4(1.0f, 1.0f, 1.0f, 1.0f); + vec4 zero = vec4(0.0f, 0.0f, 0.0f, 0.0f); + vec4 one = vec4(1.0f, 1.0f, 1.0f, 1.0f); #ifdef TEX_COORD_DEBUG - vec4 c = clamp(t, zero, one); + vec4 c = clamp(t, zero, one); #else #if PS_IIP == 1 - vec4 c = clamp(tfx(t, PSin_c), zero, one); + vec4 c = clamp(tfx(t, PSin_c), zero, one); #else - vec4 c = clamp(tfx(t, PSin_fc), zero, one); + vec4 c = clamp(tfx(t, PSin_fc), zero, one); #endif #endif - atst(c); + atst(c); - fog(c, PSin_t.z); + fog(c, PSin_t.z); colclip(c); #if (PS_CLR1 != 0) // needed for Cd * (As/Ad/F + 1) blending modes - c.rgb = vec3(1.0f, 1.0f, 1.0f); + c.rgb = vec3(1.0f, 1.0f, 1.0f); #endif - return c; + return c; } #if pGL_ES void ps_main() { - vec4 c = ps_color(); - c.a *= 2.0; - SV_Target0 = c; + vec4 c = ps_color(); + c.a *= 2.0; + SV_Target0 = c; } #endif @@ -439,30 +435,32 @@ void ps_main() void ps_main() { #if (PS_DATE & 3) == 1 && !defined(DISABLE_GL42_image) - // DATM == 0 - // Pixel with alpha equal to 1 will failed + // DATM == 0 + // Pixel with alpha equal to 1 will failed float rt_a = texelFetch(RtSampler, ivec2(gl_FragCoord.xy), 0).a; - if ((127.5f / 255.0f) < rt_a) // < 0x80 pass (== 0x80 should not pass) + if ((127.5f / 255.0f) < rt_a) { // < 0x80 pass (== 0x80 should not pass) discard; + } #elif (PS_DATE & 3) == 2 && !defined(DISABLE_GL42_image) - // DATM == 1 - // Pixel with alpha equal to 0 will failed + // DATM == 1 + // Pixel with alpha equal to 0 will failed float rt_a = texelFetch(RtSampler, ivec2(gl_FragCoord.xy), 0).a; - if(rt_a < (127.5f / 255.0f)) // >= 0x80 pass + if(rt_a < (127.5f / 255.0f)) { // >= 0x80 pass discard; + } #endif #if PS_DATE == 3 && !defined(DISABLE_GL42_image) - int stencil_ceil = imageLoad(img_prim_min, ivec2(gl_FragCoord.xy)); - // Note gl_PrimitiveID == stencil_ceil will be the primitive that will update - // the bad alpha value so we must keep it. + int stencil_ceil = imageLoad(img_prim_min, ivec2(gl_FragCoord.xy)); + // Note gl_PrimitiveID == stencil_ceil will be the primitive that will update + // the bad alpha value so we must keep it. if (gl_PrimitiveID > stencil_ceil) { discard; } #endif - vec4 c = ps_color(); + vec4 c = ps_color(); #if (APITRACE_DEBUG & 1) == 1 c.r = 1.0f; #endif @@ -476,39 +474,39 @@ void ps_main() c.a = 0.5f; #endif - float alpha = c.a * 2.0; + float alpha = c.a * 2.0; #if (PS_AOUT != 0) // 16 bit output - float a = 128.0f / 255.0; // alpha output will be 0x80 + float a = 128.0f / 255.0; // alpha output will be 0x80 - c.a = (PS_FBA != 0) ? a : step(0.5, c.a) * a; + c.a = (PS_FBA != 0) ? a : step(0.5, c.a) * a; #elif (PS_FBA != 0) - if(c.a < 0.5) c.a += 0.5; + if(c.a < 0.5) c.a += 0.5; #endif - // Get first primitive that will write a failling alpha value + // Get first primitive that will write a failling alpha value #if PS_DATE == 1 && !defined(DISABLE_GL42_image) - // DATM == 0 - // Pixel with alpha equal to 1 will failed - if (c.a > 127.5f / 255.0f) { - imageAtomicMin(img_prim_min, ivec2(gl_FragCoord.xy), gl_PrimitiveID); - } + // DATM == 0 + // Pixel with alpha equal to 1 will failed (128-255) + if (c.a > 127.5f / 255.0f) { + imageAtomicMin(img_prim_min, ivec2(gl_FragCoord.xy), gl_PrimitiveID); + } #elif PS_DATE == 2 && !defined(DISABLE_GL42_image) - // DATM == 1 - // Pixel with alpha equal to 0 will failed - if (c.a < 127.5f / 255.0f) { - imageAtomicMin(img_prim_min, ivec2(gl_FragCoord.xy), gl_PrimitiveID); - } + // DATM == 1 + // Pixel with alpha equal to 0 will failed (0-127) + if (c.a < 127.5f / 255.0f) { + imageAtomicMin(img_prim_min, ivec2(gl_FragCoord.xy), gl_PrimitiveID); + } #endif #if (PS_DATE == 2 || PS_DATE == 1) && !defined(DISABLE_GL42_image) - // Don't write anything on the framebuffer - // Note: you can't use discard because it will also drop - // image operation + // Don't write anything on the framebuffer + // Note: you can't use discard because it will also drop + // image operation #else - SV_Target0 = c; - SV_Target1 = vec4(alpha, alpha, alpha, alpha); + SV_Target0 = c; + SV_Target1 = vec4(alpha, alpha, alpha, alpha); #endif } diff --git a/plugins/GSdx/res/glsl_source.h b/plugins/GSdx/res/glsl_source.h index 5ceec51bed..335fa60315 100644 --- a/plugins/GSdx/res/glsl_source.h +++ b/plugins/GSdx/res/glsl_source.h @@ -794,13 +794,13 @@ static const char* tfx_fs_all_glsl = "\n" "in SHADER\n" "{\n" - " vec4 t;\n" - " vec4 c;\n" - " flat vec4 fc;\n" + " vec4 t;\n" + " vec4 c;\n" + " flat vec4 fc;\n" "#if PS_SPRITE == 1\n" - " flat vec4 flat_T;\n" - " flat vec2 flat_P;\n" - " vec2 alpha;\n" + " flat vec4 flat_T;\n" + " flat vec2 flat_P;\n" + " vec2 alpha;\n" "#endif\n" "} PSin;\n" "\n" @@ -829,30 +829,26 @@ static const char* tfx_fs_all_glsl = "#if PS_DATE > 0\n" "// FIXME how to declare memory access\n" "layout(r32i, binding = 2) coherent uniform iimage2D img_prim_min;\n" + "layout(early_fragment_tests) in;\n" + "// origin_upper_left\n" + "layout(pixel_center_integer) in vec4 gl_FragCoord;\n" "#endif\n" "#else\n" "// use basic stencil\n" "#endif\n" "\n" - "#ifndef DISABLE_GL42_image\n" - "#if PS_DATE > 0\n" - "// origin_upper_left\n" - "layout(pixel_center_integer) in vec4 gl_FragCoord;\n" - "//in int gl_PrimitiveID;\n" - "#endif\n" - "#endif\n" "\n" "layout(std140, binding = 21) uniform cb21\n" "{\n" - " vec3 FogColor;\n" - " float AREF;\n" - " vec4 WH;\n" - " vec2 MinF;\n" - " vec2 TA;\n" - " uvec4 MskFix;\n" - " vec4 HalfTexel;\n" - " vec4 MinMax;\n" - " vec4 TC_OffsetHack;\n" + " vec3 FogColor;\n" + " float AREF;\n" + " vec4 WH;\n" + " vec2 MinF;\n" + " vec2 TA;\n" + " uvec4 MskFix;\n" + " vec4 HalfTexel;\n" + " vec4 MinMax;\n" + " vec4 TC_OffsetHack;\n" "};\n" "\n" "#ifdef SUBROUTINE_GL40\n" @@ -870,242 +866,242 @@ static const char* tfx_fs_all_glsl = "\n" "vec4 sample_c(vec2 uv)\n" "{\n" - " // FIXME: check the issue on openGL\n" + " // FIXME: check the issue on openGL\n" "#if (ATI_SUCKS == 1) && (PS_POINT_SAMPLER == 1)\n" - " // Weird issue with ATI cards (happens on at least HD 4xxx and 5xxx),\n" - " // it looks like they add 127/128 of a texel to sampling coordinates\n" - " // occasionally causing point sampling to erroneously round up.\n" - " // I'm manually adjusting coordinates to the centre of texels here,\n" - " // though the centre is just paranoia, the top left corner works fine.\n" - " uv = (trunc(uv * WH.zw) + vec2(0.5, 0.5)) / WH.zw;\n" + " // Weird issue with ATI cards (happens on at least HD 4xxx and 5xxx),\n" + " // it looks like they add 127/128 of a texel to sampling coordinates\n" + " // occasionally causing point sampling to erroneously round up.\n" + " // I'm manually adjusting coordinates to the centre of texels here,\n" + " // though the centre is just paranoia, the top left corner works fine.\n" + " uv = (trunc(uv * WH.zw) + vec2(0.5, 0.5)) / WH.zw;\n" "#endif\n" "\n" - " return texture(TextureSampler, uv);\n" + " return texture(TextureSampler, uv);\n" "}\n" "\n" "vec4 sample_p(float u)\n" "{\n" - " //FIXME do we need a 1D sampler. Big impact on opengl to find 1 dim\n" - " // So for the moment cheat with 0.0f dunno if it work\n" - " return texture(PaletteSampler, vec2(u, 0.0f));\n" + " //FIXME do we need a 1D sampler. Big impact on opengl to find 1 dim\n" + " // So for the moment cheat with 0.0f dunno if it work\n" + " return texture(PaletteSampler, vec2(u, 0.0f));\n" "}\n" "\n" "vec4 wrapuv(vec4 uv)\n" "{\n" - " vec4 uv_out = uv;\n" + " vec4 uv_out = uv;\n" "\n" "#if PS_WMS == PS_WMT\n" "\n" "#if PS_WMS == 2\n" - " uv_out = clamp(uv, MinMax.xyxy, MinMax.zwzw);\n" + " uv_out = clamp(uv, MinMax.xyxy, MinMax.zwzw);\n" "#elif PS_WMS == 3\n" - " uv_out = vec4((ivec4(uv * WH.xyxy) & ivec4(MskFix.xyxy)) | ivec4(MskFix.zwzw)) / WH.xyxy;\n" + " uv_out = vec4((ivec4(uv * WH.xyxy) & ivec4(MskFix.xyxy)) | ivec4(MskFix.zwzw)) / WH.xyxy;\n" "#endif\n" "\n" "#else // PS_WMS != PS_WMT\n" "\n" "#if PS_WMS == 2\n" - " uv_out.xz = clamp(uv.xz, MinMax.xx, MinMax.zz);\n" + " uv_out.xz = clamp(uv.xz, MinMax.xx, MinMax.zz);\n" "\n" "#elif PS_WMS == 3\n" - " uv_out.xz = vec2((ivec2(uv.xz * WH.xx) & ivec2(MskFix.xx)) | ivec2(MskFix.zz)) / WH.xx;\n" + " uv_out.xz = vec2((ivec2(uv.xz * WH.xx) & ivec2(MskFix.xx)) | ivec2(MskFix.zz)) / WH.xx;\n" "\n" "#endif\n" "\n" "#if PS_WMT == 2\n" - " uv_out.yw = clamp(uv.yw, MinMax.yy, MinMax.ww);\n" + " uv_out.yw = clamp(uv.yw, MinMax.yy, MinMax.ww);\n" "\n" "#elif PS_WMT == 3\n" "\n" - " uv_out.yw = vec2((ivec2(uv.yw * WH.yy) & ivec2(MskFix.yy)) | ivec2(MskFix.ww)) / WH.yy;\n" + " uv_out.yw = vec2((ivec2(uv.yw * WH.yy) & ivec2(MskFix.yy)) | ivec2(MskFix.ww)) / WH.yy;\n" "#endif\n" "\n" "#endif\n" "\n" - " return uv_out;\n" + " return uv_out;\n" "}\n" "\n" "vec2 clampuv(vec2 uv)\n" "{\n" - " vec2 uv_out = uv;\n" + " vec2 uv_out = uv;\n" "\n" - "#if (PS_WMS == 2) && (PS_WMT == 2) \n" - " uv_out = clamp(uv, MinF, MinMax.zw);\n" + "#if (PS_WMS == 2) && (PS_WMT == 2)\n" + " uv_out = clamp(uv, MinF, MinMax.zw);\n" "#elif PS_WMS == 2\n" - " uv_out.x = clamp(uv.x, MinF.x, MinMax.z);\n" + " uv_out.x = clamp(uv.x, MinF.x, MinMax.z);\n" "#elif PS_WMT == 2\n" - " uv_out.y = clamp(uv.y, MinF.y, MinMax.w);\n" + " uv_out.y = clamp(uv.y, MinF.y, MinMax.w);\n" "#endif\n" "\n" - " return uv_out;\n" + " return uv_out;\n" "}\n" "\n" "mat4 sample_4c(vec4 uv)\n" "{\n" - " mat4 c;\n" + " mat4 c;\n" "\n" - " c[0] = sample_c(uv.xy);\n" - " c[1] = sample_c(uv.zy);\n" - " c[2] = sample_c(uv.xw);\n" - " c[3] = sample_c(uv.zw);\n" + " c[0] = sample_c(uv.xy);\n" + " c[1] = sample_c(uv.zy);\n" + " c[2] = sample_c(uv.xw);\n" + " c[3] = sample_c(uv.zw);\n" "\n" - " return c;\n" + " return c;\n" "}\n" "\n" "vec4 sample_4a(vec4 uv)\n" "{\n" - " vec4 c;\n" + " vec4 c;\n" "\n" - " // Dx used the alpha channel.\n" - " // Opengl is only 8 bits on red channel.\n" - " c.x = sample_c(uv.xy).r;\n" - " c.y = sample_c(uv.zy).r;\n" - " c.z = sample_c(uv.xw).r;\n" - " c.w = sample_c(uv.zw).r;\n" + " // Dx used the alpha channel.\n" + " // Opengl is only 8 bits on red channel.\n" + " c.x = sample_c(uv.xy).r;\n" + " c.y = sample_c(uv.zy).r;\n" + " c.z = sample_c(uv.xw).r;\n" + " c.w = sample_c(uv.zw).r;\n" "\n" " return c * 255.0/256.0 + 0.5/256.0;\n" "}\n" "\n" "mat4 sample_4p(vec4 u)\n" "{\n" - " mat4 c;\n" + " mat4 c;\n" "\n" - " c[0] = sample_p(u.x);\n" - " c[1] = sample_p(u.y);\n" - " c[2] = sample_p(u.z);\n" - " c[3] = sample_p(u.w);\n" + " c[0] = sample_p(u.x);\n" + " c[1] = sample_p(u.y);\n" + " c[2] = sample_p(u.z);\n" + " c[3] = sample_p(u.w);\n" "\n" - " return c;\n" + " return c;\n" "}\n" "\n" "vec4 sample_color(vec2 st, float q)\n" "{\n" "#if (PS_FST == 0)\n" - " st /= q;\n" + " st /= q;\n" "#endif\n" "\n" "#if (PS_TCOFFSETHACK == 1)\n" - " st += TC_OffsetHack.xy;\n" + " st += TC_OffsetHack.xy;\n" "#endif\n" "\n" - " vec4 t;\n" - " mat4 c;\n" - " vec2 dd;\n" + " vec4 t;\n" + " mat4 c;\n" + " vec2 dd;\n" "\n" "#if (PS_LTF == 0 && PS_FMT <= FMT_16 && PS_WMS < 3 && PS_WMT < 3)\n" - " c[0] = sample_c(clampuv(st));\n" + " c[0] = sample_c(clampuv(st));\n" "#ifdef TEX_COORD_DEBUG\n" - " c[0].rg = clampuv(st).xy;\n" + " c[0].rg = clampuv(st).xy;\n" "#endif\n" "\n" "#else\n" - " vec4 uv;\n" + " vec4 uv;\n" "\n" - " if(PS_LTF != 0)\n" - " {\n" - " uv = st.xyxy + HalfTexel;\n" - " dd = fract(uv.xy * WH.zw);\n" - " }\n" - " else\n" - " {\n" - " uv = st.xyxy;\n" - " }\n" + " if(PS_LTF != 0)\n" + " {\n" + " uv = st.xyxy + HalfTexel;\n" + " dd = fract(uv.xy * WH.zw);\n" + " }\n" + " else\n" + " {\n" + " uv = st.xyxy;\n" + " }\n" "\n" - " uv = wrapuv(uv);\n" + " uv = wrapuv(uv);\n" "\n" - " if((PS_FMT & FMT_PAL) != 0)\n" - " {\n" - " c = sample_4p(sample_4a(uv));\n" - " }\n" - " else\n" - " {\n" - " c = sample_4c(uv);\n" - " }\n" + " if((PS_FMT & FMT_PAL) != 0)\n" + " {\n" + " c = sample_4p(sample_4a(uv));\n" + " }\n" + " else\n" + " {\n" + " c = sample_4c(uv);\n" + " }\n" "#ifdef TEX_COORD_DEBUG\n" - " c[0].rg = uv.xy;\n" - " c[1].rg = uv.xy;\n" - " c[2].rg = uv.xy;\n" - " c[3].rg = uv.xy;\n" + " c[0].rg = uv.xy;\n" + " c[1].rg = uv.xy;\n" + " c[2].rg = uv.xy;\n" + " c[3].rg = uv.xy;\n" "#endif\n" "\n" "#endif\n" "\n" - " // PERF: see the impact of the exansion before/after the interpolation\n" - " for (int i = 0; i < 4; i++)\n" - " {\n" + " // PERF: see the impact of the exansion before/after the interpolation\n" + " for (int i = 0; i < 4; i++)\n" + " {\n" "#if ((PS_FMT & ~FMT_PAL) == FMT_24)\n" - " c[i].a = ( (PS_AEM == 0) || any(bvec3(c[i].rgb)) ) ? TA.x : 0.0f;\n" + " c[i].a = ( (PS_AEM == 0) || any(bvec3(c[i].rgb)) ) ? TA.x : 0.0f;\n" "#elif ((PS_FMT & ~FMT_PAL) == FMT_16)\n" - " c[i].a = c[i].a >= 0.5 ? TA.y : ( (PS_AEM == 0) || any(bvec3(c[i].rgb)) ) ? TA.x : 0.0f;\n" + " c[i].a = c[i].a >= 0.5 ? TA.y : ( (PS_AEM == 0) || any(bvec3(c[i].rgb)) ) ? TA.x : 0.0f;\n" "#endif\n" - " }\n" + " }\n" "\n" "#if(PS_LTF != 0)\n" - " t = mix(mix(c[0], c[1], dd.x), mix(c[2], c[3], dd.x), dd.y);\n" + " t = mix(mix(c[0], c[1], dd.x), mix(c[2], c[3], dd.x), dd.y);\n" "#else\n" - " t = c[0];\n" + " t = c[0];\n" "#endif\n" "\n" - " return t;\n" + " return t;\n" "}\n" "\n" "#ifndef SUBROUTINE_GL40\n" "vec4 tfx(vec4 t, vec4 c)\n" "{\n" - " vec4 c_out = c;\n" + " vec4 c_out = c;\n" "#if (PS_TFX == 0)\n" - " if(PS_TCC != 0) \n" - " c_out = c * t * 255.0f / 128.0f;\n" - " else\n" - " c_out.rgb = c.rgb * t.rgb * 255.0f / 128.0f;\n" + " if(PS_TCC != 0)\n" + " c_out = c * t * 255.0f / 128.0f;\n" + " else\n" + " c_out.rgb = c.rgb * t.rgb * 255.0f / 128.0f;\n" "#elif (PS_TFX == 1)\n" - " if(PS_TCC != 0) \n" - " c_out = t;\n" - " else\n" - " c_out.rgb = t.rgb;\n" + " if(PS_TCC != 0)\n" + " c_out = t;\n" + " else\n" + " c_out.rgb = t.rgb;\n" "#elif (PS_TFX == 2)\n" - " c_out.rgb = c.rgb * t.rgb * 255.0f / 128.0f + c.a;\n" + " c_out.rgb = c.rgb * t.rgb * 255.0f / 128.0f + c.a;\n" "\n" - " if(PS_TCC != 0) \n" - " c_out.a += t.a;\n" + " if(PS_TCC != 0)\n" + " c_out.a += t.a;\n" "#elif (PS_TFX == 3)\n" - " c_out.rgb = c.rgb * t.rgb * 255.0f / 128.0f + c.a;\n" + " c_out.rgb = c.rgb * t.rgb * 255.0f / 128.0f + c.a;\n" "\n" - " if(PS_TCC != 0) \n" - " c_out.a = t.a;\n" + " if(PS_TCC != 0)\n" + " c_out.a = t.a;\n" "#endif\n" "\n" - " return c_out;\n" + " return c_out;\n" "}\n" "#endif\n" "\n" "#ifndef SUBROUTINE_GL40\n" "void atst(vec4 c)\n" "{\n" - " float a = trunc(c.a * 255.0 + 0.01);\n" + " float a = trunc(c.a * 255.0 + 0.01);\n" "\n" "#if (PS_ATST == 0) // never\n" - " discard;\n" + " discard;\n" "#elif (PS_ATST == 1) // always\n" - " // nothing to do\n" + " // nothing to do\n" "#elif (PS_ATST == 2) && (PS_SPRITEHACK == 0) // l\n" - " if ((AREF - a - 0.5f) < 0.0f)\n" - " discard;\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" + " 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" + " 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" + " 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" + " 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 ((abs(a - AREF) - 0.5f) < 0.0f)\n" + " discard;\n" "#endif\n" "}\n" "#endif\n" @@ -1115,12 +1111,12 @@ static const char* tfx_fs_all_glsl = "void colclip(inout vec4 c)\n" "{\n" "#if (PS_COLCLIP == 2)\n" - " c.rgb = 256.0f/255.0f - c.rgb;\n" + " c.rgb = 256.0f/255.0f - c.rgb;\n" "#elif (PS_COLCLIP > 0)\n" - " // FIXME !!!!\n" - " //c.rgb *= c.rgb < 128./255;\n" - " bvec3 factor = bvec3(128.0f/255.0f, 128.0f/255.0f, 128.0f/255.0f);\n" - " c.rgb *= vec3(factor);\n" + " // FIXME !!!!\n" + " //c.rgb *= c.rgb < 128./255;\n" + " bvec3 factor = bvec3(128.0f/255.0f, 128.0f/255.0f, 128.0f/255.0f);\n" + " c.rgb *= vec3(factor);\n" "#endif\n" "}\n" "#endif\n" @@ -1128,59 +1124,59 @@ static const char* tfx_fs_all_glsl = "void fog(inout vec4 c, float f)\n" "{\n" "#if PS_FOG != 0\n" - " c.rgb = mix(FogColor, c.rgb, f);\n" + " c.rgb = mix(FogColor, c.rgb, f);\n" "#endif\n" "}\n" "\n" "vec4 ps_color()\n" "{\n" "#if PS_SPRITE == 1\n" - " // Reinterpolate manually the texture coordinate.\n" - " // trunc => native resolution. Maybe we can add an option to choose a value between\n" - " // trunc and current.\n" - " vec2 factor = vec2(trunc(PSin.alpha.x), floor(PSin.alpha.y));\n" - " //vec2 factor = trunc(PSin.alpha);\n" - " factor *= PSin.flat_P;\n" - " vec2 txy;\n" - " txy.x = mix(PSin.flat_T.x, PSin.flat_T.y, factor.x);\n" - " txy.y = mix(PSin.flat_T.z, PSin.flat_T.w, factor.y);\n" + " // Reinterpolate manually the texture coordinate.\n" + " // trunc => native resolution. Maybe we can add an option to choose a value between\n" + " // trunc and current.\n" + " vec2 factor = vec2(trunc(PSin.alpha.x), floor(PSin.alpha.y));\n" + " //vec2 factor = trunc(PSin.alpha);\n" + " factor *= PSin.flat_P;\n" + " vec2 txy;\n" + " txy.x = mix(PSin.flat_T.x, PSin.flat_T.y, factor.x);\n" + " txy.y = mix(PSin.flat_T.z, PSin.flat_T.w, factor.y);\n" "\n" "#else\n" - " vec2 txy = PSin_t.xy;\n" + " vec2 txy = PSin_t.xy;\n" "#endif\n" - " vec4 t = sample_color(txy, PSin_t.w);\n" + " vec4 t = sample_color(txy, PSin_t.w);\n" "\n" - " vec4 zero = vec4(0.0f, 0.0f, 0.0f, 0.0f);\n" - " vec4 one = vec4(1.0f, 1.0f, 1.0f, 1.0f);\n" + " vec4 zero = vec4(0.0f, 0.0f, 0.0f, 0.0f);\n" + " vec4 one = vec4(1.0f, 1.0f, 1.0f, 1.0f);\n" "#ifdef TEX_COORD_DEBUG\n" - " vec4 c = clamp(t, zero, one);\n" + " vec4 c = clamp(t, zero, one);\n" "#else\n" "#if PS_IIP == 1\n" - " vec4 c = clamp(tfx(t, PSin_c), zero, one);\n" + " vec4 c = clamp(tfx(t, PSin_c), zero, one);\n" "#else\n" - " vec4 c = clamp(tfx(t, PSin_fc), zero, one);\n" + " vec4 c = clamp(tfx(t, PSin_fc), zero, one);\n" "#endif\n" "#endif\n" "\n" - " atst(c);\n" + " atst(c);\n" "\n" - " fog(c, PSin_t.z);\n" + " fog(c, PSin_t.z);\n" "\n" " colclip(c);\n" "\n" "#if (PS_CLR1 != 0) // needed for Cd * (As/Ad/F + 1) blending modes\n" - " c.rgb = vec3(1.0f, 1.0f, 1.0f); \n" + " c.rgb = vec3(1.0f, 1.0f, 1.0f);\n" "#endif\n" "\n" - " return c;\n" + " return c;\n" "}\n" "\n" "#if pGL_ES\n" "void ps_main()\n" "{\n" - " vec4 c = ps_color();\n" - " c.a *= 2.0;\n" - " SV_Target0 = c;\n" + " vec4 c = ps_color();\n" + " c.a *= 2.0;\n" + " SV_Target0 = c;\n" "}\n" "#endif\n" "\n" @@ -1188,30 +1184,32 @@ static const char* tfx_fs_all_glsl = "void ps_main()\n" "{\n" "#if (PS_DATE & 3) == 1 && !defined(DISABLE_GL42_image)\n" - " // DATM == 0\n" - " // Pixel with alpha equal to 1 will failed\n" + " // DATM == 0\n" + " // Pixel with alpha equal to 1 will failed\n" " float rt_a = texelFetch(RtSampler, ivec2(gl_FragCoord.xy), 0).a;\n" - " if ((127.5f / 255.0f) < rt_a) // < 0x80 pass (== 0x80 should not pass)\n" + " if ((127.5f / 255.0f) < rt_a) { // < 0x80 pass (== 0x80 should not pass)\n" " discard;\n" + " }\n" "#elif (PS_DATE & 3) == 2 && !defined(DISABLE_GL42_image)\n" - " // DATM == 1\n" - " // Pixel with alpha equal to 0 will failed\n" + " // DATM == 1\n" + " // Pixel with alpha equal to 0 will failed\n" " float rt_a = texelFetch(RtSampler, ivec2(gl_FragCoord.xy), 0).a;\n" - " if(rt_a < (127.5f / 255.0f)) // >= 0x80 pass\n" + " if(rt_a < (127.5f / 255.0f)) { // >= 0x80 pass\n" " discard;\n" + " }\n" "#endif\n" "\n" "#if PS_DATE == 3 && !defined(DISABLE_GL42_image)\n" - " int stencil_ceil = imageLoad(img_prim_min, ivec2(gl_FragCoord.xy));\n" - " // Note gl_PrimitiveID == stencil_ceil will be the primitive that will update\n" - " // the bad alpha value so we must keep it.\n" + " int stencil_ceil = imageLoad(img_prim_min, ivec2(gl_FragCoord.xy));\n" + " // Note gl_PrimitiveID == stencil_ceil will be the primitive that will update\n" + " // the bad alpha value so we must keep it.\n" "\n" " if (gl_PrimitiveID > stencil_ceil) {\n" " discard;\n" " }\n" "#endif\n" "\n" - " vec4 c = ps_color();\n" + " vec4 c = ps_color();\n" "#if (APITRACE_DEBUG & 1) == 1\n" " c.r = 1.0f;\n" "#endif\n" @@ -1225,39 +1223,39 @@ static const char* tfx_fs_all_glsl = " c.a = 0.5f;\n" "#endif\n" "\n" - " float alpha = c.a * 2.0;\n" + " float alpha = c.a * 2.0;\n" "\n" "#if (PS_AOUT != 0) // 16 bit output\n" - " float a = 128.0f / 255.0; // alpha output will be 0x80\n" + " float a = 128.0f / 255.0; // alpha output will be 0x80\n" "\n" - " c.a = (PS_FBA != 0) ? a : step(0.5, c.a) * a;\n" + " c.a = (PS_FBA != 0) ? a : step(0.5, c.a) * a;\n" "#elif (PS_FBA != 0)\n" - " if(c.a < 0.5) c.a += 0.5;\n" + " if(c.a < 0.5) c.a += 0.5;\n" "#endif\n" "\n" - " // Get first primitive that will write a failling alpha value\n" + " // Get first primitive that will write a failling alpha value\n" "#if PS_DATE == 1 && !defined(DISABLE_GL42_image)\n" - " // DATM == 0\n" - " // Pixel with alpha equal to 1 will failed\n" - " if (c.a > 127.5f / 255.0f) {\n" - " imageAtomicMin(img_prim_min, ivec2(gl_FragCoord.xy), gl_PrimitiveID);\n" - " }\n" + " // DATM == 0\n" + " // Pixel with alpha equal to 1 will failed (128-255)\n" + " if (c.a > 127.5f / 255.0f) {\n" + " imageAtomicMin(img_prim_min, ivec2(gl_FragCoord.xy), gl_PrimitiveID);\n" + " }\n" "#elif PS_DATE == 2 && !defined(DISABLE_GL42_image)\n" - " // DATM == 1\n" - " // Pixel with alpha equal to 0 will failed\n" - " if (c.a < 127.5f / 255.0f) {\n" - " imageAtomicMin(img_prim_min, ivec2(gl_FragCoord.xy), gl_PrimitiveID);\n" - " }\n" + " // DATM == 1\n" + " // Pixel with alpha equal to 0 will failed (0-127)\n" + " if (c.a < 127.5f / 255.0f) {\n" + " imageAtomicMin(img_prim_min, ivec2(gl_FragCoord.xy), gl_PrimitiveID);\n" + " }\n" "#endif\n" "\n" "\n" "#if (PS_DATE == 2 || PS_DATE == 1) && !defined(DISABLE_GL42_image)\n" - " // Don't write anything on the framebuffer\n" - " // Note: you can't use discard because it will also drop\n" - " // image operation\n" + " // Don't write anything on the framebuffer\n" + " // Note: you can't use discard because it will also drop\n" + " // image operation\n" "#else\n" - " SV_Target0 = c;\n" - " SV_Target1 = vec4(alpha, alpha, alpha, alpha);\n" + " SV_Target0 = c;\n" + " SV_Target1 = vec4(alpha, alpha, alpha, alpha);\n" "#endif\n" "\n" "}\n"