diff --git a/rpcs3/Emu/RSX/Program/GLSLCommon.cpp b/rpcs3/Emu/RSX/Program/GLSLCommon.cpp index 280e4fdb74..c1d1930871 100644 --- a/rpcs3/Emu/RSX/Program/GLSLCommon.cpp +++ b/rpcs3/Emu/RSX/Program/GLSLCommon.cpp @@ -795,7 +795,7 @@ namespace glsl " {\n" " // Renormalize to 8-bit (PS3) accuracy\n" " rgba = floor(rgba * 255.);\n" - " rgba /= 255.;" + " rgba /= 255.;\n" " }\n" "\n" " uvec4 mask;\n" @@ -904,17 +904,42 @@ namespace glsl auto insert_msaa_sample_code = [&OS](const std::string_view& sampler_type) { OS << - "vec4 sampleTexture2DMS(in " << sampler_type << " tex, const in vec2 coords, const in int index)\n" + "vec4 texelFetch2DMS(in " << sampler_type << " tex, const in ivec2 sample_count, const in ivec2 icoords, const in int index, const in ivec2 offset)\n" "{\n" - " const uint flags = TEX_FLAGS(index);\n" - " const ivec2 sample_count = ivec2(2, textureSamples(tex) / 2);\n" - " const ivec2 icoords = ivec2(COORD_SCALE2(index, coords) * textureSize(tex) * sample_count);\n" - "\n" - " const ivec2 resolve_coords = icoords * ivec2(bvec2(texture_parameters[index].scale_bias.xy));\n" + " const ivec2 resolve_coords = (icoords + offset) * ivec2(bvec2(texture_parameters[index].scale_bias.xy));\n" " const ivec2 aa_coords = resolve_coords / sample_count;\n" " const ivec2 sample_loc = ivec2(resolve_coords % sample_count);\n" " const int sample_index = sample_loc.x + (sample_loc.y * sample_count.y);\n" " return texelFetch(tex, aa_coords, sample_index);\n" + "}\n\n" + + "vec4 sampleTexture2DMS(in " << sampler_type << " tex, const in vec2 coords, const in int index)\n" + "{\n" + " const uint flags = TEX_FLAGS(index);\n" + " const vec2 normalized_coords = COORD_SCALE2(index, coords);\n" + " const ivec2 sample_count = ivec2(2, textureSamples(tex) / 2);\n" + " const ivec2 image_size = textureSize(tex) * sample_count;" + " const ivec2 icoords = ivec2(normalized_coords * image_size);\n" + " const vec4 sample0 = texelFetch2DMS(tex, sample_count, icoords, index, ivec2(0));\n" + "\n" + " if (!_test_bit(flags, FILTERED_BIT))\n" + " {\n" + " return sample0;\n" + " }\n" + "\n" + " const vec2 uv_step = 1.0 / vec2(image_size);\n" + " const vec2 up_factor = normalized_coords - (vec2(icoords) * uv_step);\n" + " // Hacky downscaling for performance reasons. Simple weighted area, upto 2x2 down.\n" + " const vec2 actual_step = vec2(dFdx(normalized_coords.x), dFdy(normalized_coords.y));\n" + " const vec2 down_factor = min(actual_step / uv_step, 1.5) - 1.0;\n" + " const vec2 factor = _select(up_factor, down_factor, greaterThan(actual_step, uv_step));\n" + " // Do linear filter\n" + " const vec4 sample1 = texelFetch2DMS(tex, sample_count, icoords, index, ivec2(1, 0));\n" + " const vec4 sample2 = texelFetch2DMS(tex, sample_count, icoords, index, ivec2(0, 1));\n" + " const vec4 sample3 = texelFetch2DMS(tex, sample_count, icoords, index, ivec2(1, 1));\n" + " const vec4 a = mix(sample0, sample1, factor.x);\n" + " const vec4 b = mix(sample2, sample3, factor.x);\n" + " return mix(a, b, factor.y);\n" "}\n\n"; };