From 3dac7d16e7ca89c0533bd532325ad20245478609 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Mon, 29 Jan 2024 22:09:48 +0100 Subject: [PATCH] vk/gl: unite video_out_calibration_pass fragment shader to new glsl --- rpcs3/Emu/RSX/GL/GLOverlays.cpp | 83 +-------------- .../GLSLSnippets/VideoOutCalibrationPass.glsl | 100 ++++++++++++++++++ rpcs3/Emu/RSX/VK/VKOverlays.cpp | 86 +-------------- rpcs3/Emu/RSX/VK/VKOverlays.h | 2 +- rpcs3/emucore.vcxproj | 1 + rpcs3/emucore.vcxproj.filters | 3 + 6 files changed, 109 insertions(+), 166 deletions(-) create mode 100644 rpcs3/Emu/RSX/Program/GLSLSnippets/VideoOutCalibrationPass.glsl diff --git a/rpcs3/Emu/RSX/GL/GLOverlays.cpp b/rpcs3/Emu/RSX/GL/GLOverlays.cpp index ea2ce7bffe..0cfa40ca35 100644 --- a/rpcs3/Emu/RSX/GL/GLOverlays.cpp +++ b/rpcs3/Emu/RSX/GL/GLOverlays.cpp @@ -461,87 +461,8 @@ namespace gl ; fs_src = - "#version 420\n\n" - "layout(binding=31) uniform sampler2D fs0;\n" - "layout(binding=30) uniform sampler2D fs1;\n" - "layout(location=0) in vec2 tc0;\n" - "layout(location=0) out vec4 ocol;\n" - "\n" - "#define STEREO_MODE_DISABLED 0\n" - "#define STEREO_MODE_ANAGLYPH 1\n" - "#define STEREO_MODE_SIDE_BY_SIDE 2\n" - "#define STEREO_MODE_OVER_UNDER 3\n" - "\n" - "vec2 sbs_single_matrix = vec2(2.0,0.4898f);\n" - "vec2 sbs_multi_matrix = vec2(2.0,1.0);\n" - "vec2 ou_single_matrix = vec2(1.0,0.9796f);\n" - "vec2 ou_multi_matrix = vec2(1.0,2.0);\n" - "\n" - "uniform float gamma;\n" - "uniform int limit_range;\n" - "uniform int stereo_display_mode;\n" - "uniform int stereo_image_count;\n" - "\n" - "vec4 read_source()\n" - "{\n" - " if (stereo_display_mode == STEREO_MODE_DISABLED) return texture(fs0, tc0);\n" - "\n" - " vec4 left, right;\n" - " if (stereo_image_count == 1)\n" - " {\n" - " switch (stereo_display_mode)\n" - " {\n" - " case STEREO_MODE_ANAGLYPH:\n" - " left = texture(fs0, tc0 * vec2(1.f, 0.4898f));\n" - " right = texture(fs0, (tc0 * vec2(1.f, 0.4898f)) + vec2(0.f, 0.510204f));\n" - " return vec4(left.r, right.g, right.b, 1.f);\n" - " case STEREO_MODE_SIDE_BY_SIDE:\n" - " if (tc0.x < 0.5) return texture(fs0, tc0* sbs_single_matrix);\n" - " else return texture(fs0, (tc0* sbs_single_matrix) + vec2(-1.f, 0.510204f));\n" - " case STEREO_MODE_OVER_UNDER:\n" - " if (tc0.y < 0.5) return texture(fs0, tc0* ou_single_matrix);\n" - " else return texture(fs0, (tc0* ou_single_matrix) + vec2(0.f, 0.020408f) );\n" - " default:\n" // undefined behavior - " return texture(fs0,tc0);\n" - " }\n" - " }\n" - " else if (stereo_image_count == 2)\n" - " {\n" - " switch (stereo_display_mode)\n" - " {\n" - " case STEREO_MODE_ANAGLYPH:\n" - " left = texture(fs0, tc0);\n" - " right = texture(fs1, tc0);\n" - " return vec4(left.r, right.g, right.b, 1.f);\n" - " case STEREO_MODE_SIDE_BY_SIDE:\n" - " if (tc0.x < 0.5) return texture(fs0,(tc0 * sbs_multi_matrix));\n" - " else return texture(fs1,(tc0 * sbs_multi_matrix) + vec2(-1.f,0.f));\n" - " case STEREO_MODE_OVER_UNDER:\n" - " if (tc0.y < 0.5) return texture(fs0,(tc0 * ou_multi_matrix));\n" - " else return texture(fs1,(tc0 * ou_multi_matrix) + vec2(0.f,-1.f));\n" - " default:\n" // undefined behavior - " return texture(fs0,tc0);\n" - " }\n" - " }\n" - " else\n" - " {\n" - " vec2 coord_left = tc0 * vec2(1.f, 0.4898f);\n" - " vec2 coord_right = coord_left + vec2(0.f, 0.510204f);\n" - " left = texture(fs0, coord_left);\n" - " right = texture(fs0, coord_right);\n" - " return vec4(left.r, right.g, right.b, 1.);\n" - " }\n" - "}\n" - "\n" - "void main()\n" - "{\n" - " vec4 color = read_source();\n" - " color.rgb = pow(color.rgb, vec3(gamma));\n" - " if (limit_range > 0)\n" - " ocol = ((color * 220.) + 16.) / 255.;\n" - " else\n" - " ocol = color;\n" - "}\n"; + #include "../Program/GLSLSnippets/VideoOutCalibrationPass.glsl" + ; m_input_filter = gl::filter::linear; } diff --git a/rpcs3/Emu/RSX/Program/GLSLSnippets/VideoOutCalibrationPass.glsl b/rpcs3/Emu/RSX/Program/GLSLSnippets/VideoOutCalibrationPass.glsl new file mode 100644 index 0000000000..a620c6f948 --- /dev/null +++ b/rpcs3/Emu/RSX/Program/GLSLSnippets/VideoOutCalibrationPass.glsl @@ -0,0 +1,100 @@ +R"( +#version 420 + +#ifdef VULKAN +layout(set=0, binding=1) uniform sampler2D fs0; +layout(set=0, binding=2) uniform sampler2D fs1; +#else +layout(binding=31) uniform sampler2D fs0; +layout(binding=30) uniform sampler2D fs1; +#endif + +layout(location=0) in vec2 tc0; +layout(location=0) out vec4 ocol; + +#define STEREO_MODE_DISABLED 0 +#define STEREO_MODE_ANAGLYPH 1 +#define STEREO_MODE_SIDE_BY_SIDE 2 +#define STEREO_MODE_OVER_UNDER 3 + +vec2 sbs_single_matrix = vec2(2.0,0.4898f); +vec2 sbs_multi_matrix = vec2(2.0,1.0); +vec2 ou_single_matrix = vec2(1.0,0.9796f); +vec2 ou_multi_matrix = vec2(1.0,2.0); + +#ifdef VULKAN +layout(push_constant) uniform static_data +{ + float gamma; + int limit_range; + int stereo_display_mode; + int stereo_image_count; +}; +#else +uniform float gamma; +uniform int limit_range; +uniform int stereo_display_mode; +uniform int stereo_image_count; +#endif + +vec4 read_source() +{ + if (stereo_display_mode == STEREO_MODE_DISABLED) return texture(fs0, tc0); + + vec4 left, right; + if (stereo_image_count == 1) + { + switch (stereo_display_mode) + { + case STEREO_MODE_ANAGLYPH: + left = texture(fs0, tc0 * vec2(1.f, 0.4898f)); + right = texture(fs0, (tc0 * vec2(1.f, 0.4898f)) + vec2(0.f, 0.510204f)); + return vec4(left.r, right.g, right.b, 1.f); + case STEREO_MODE_SIDE_BY_SIDE: + if (tc0.x < 0.5) return texture(fs0, tc0* sbs_single_matrix); + else return texture(fs0, (tc0* sbs_single_matrix) + vec2(-1.f, 0.510204f)); + case STEREO_MODE_OVER_UNDER: + if (tc0.y < 0.5) return texture(fs0, tc0* ou_single_matrix); + else return texture(fs0, (tc0* ou_single_matrix) + vec2(0.f, 0.020408f) ); + default: // undefined behavior + return texture(fs0,tc0); + } + } + else if (stereo_image_count == 2) + { + switch (stereo_display_mode) + { + case STEREO_MODE_ANAGLYPH: + left = texture(fs0, tc0); + right = texture(fs1, tc0); + return vec4(left.r, right.g, right.b, 1.f); + case STEREO_MODE_SIDE_BY_SIDE: + if (tc0.x < 0.5) return texture(fs0,(tc0 * sbs_multi_matrix)); + else return texture(fs1,(tc0 * sbs_multi_matrix) + vec2(-1.f,0.f)); + case STEREO_MODE_OVER_UNDER: + if (tc0.y < 0.5) return texture(fs0,(tc0 * ou_multi_matrix)); + else return texture(fs1,(tc0 * ou_multi_matrix) + vec2(0.f,-1.f)); + default: // undefined behavior + return texture(fs0,tc0); + } + } + else + { + vec2 coord_left = tc0 * vec2(1.f, 0.4898f); + vec2 coord_right = coord_left + vec2(0.f, 0.510204f); + left = texture(fs0, coord_left); + right = texture(fs0, coord_right); + return vec4(left.r, right.g, right.b, 1.); + } +} + +void main() +{ + vec4 color = read_source(); + color.rgb = pow(color.rgb, vec3(gamma)); + if (limit_range > 0) + ocol = ((color * 220.) + 16.) / 255.; + else + ocol = color; +} +)" diff --git a/rpcs3/Emu/RSX/VK/VKOverlays.cpp b/rpcs3/Emu/RSX/VK/VKOverlays.cpp index b0c17a789a..02eb03ddae 100644 --- a/rpcs3/Emu/RSX/VK/VKOverlays.cpp +++ b/rpcs3/Emu/RSX/VK/VKOverlays.cpp @@ -870,90 +870,8 @@ namespace vk "}\n"; fs_src = - "#version 420\n\n" - "layout(set=0, binding=1) uniform sampler2D fs0;\n" - "layout(set=0, binding=2) uniform sampler2D fs1;\n" - "layout(location=0) in vec2 tc0;\n" - "layout(location=0) out vec4 ocol;\n" - "\n" - "#define STEREO_MODE_DISABLED 0\n" - "#define STEREO_MODE_ANAGLYPH 1\n" - "#define STEREO_MODE_SIDE_BY_SIDE 2\n" - "#define STEREO_MODE_OVER_UNDER 3\n" - "\n" - "vec2 sbs_single_matrix = vec2(2.0,0.4898f);\n" - "vec2 sbs_multi_matrix = vec2(2.0,1.0);\n" - "vec2 ou_single_matrix = vec2(1.0,0.9796f);\n" - "vec2 ou_multi_matrix = vec2(1.0,2.0);\n" - "\n" - "layout(push_constant) uniform static_data\n" - "{\n" - " float gamma;\n" - " int limit_range;\n" - " int stereo_display_mode;\n" - " int stereo_image_count;\n" - "};\n" - "\n" - "vec4 read_source()\n" - "{\n" - " if (stereo_display_mode == STEREO_MODE_DISABLED) return texture(fs0, tc0);\n" - "\n" - " vec4 left, right;\n" - " if (stereo_image_count == 1)\n" - " {\n" - " switch (stereo_display_mode)\n" - " {\n" - " case STEREO_MODE_ANAGLYPH:\n" - " left = texture(fs0, tc0 * vec2(1.f, 0.4898f));\n" - " right = texture(fs0, (tc0 * vec2(1.f, 0.4898f)) + vec2(0.f, 0.510204f));\n" - " return vec4(left.r, right.g, right.b, 1.f);\n" - " case STEREO_MODE_SIDE_BY_SIDE:\n" - " if (tc0.x < 0.5) return texture(fs0, tc0* sbs_single_matrix);\n" - " else return texture(fs0, (tc0* sbs_single_matrix) + vec2(-1.f, 0.510204f));\n" - " case STEREO_MODE_OVER_UNDER:\n" - " if (tc0.y < 0.5) return texture(fs0, tc0* ou_single_matrix);\n" - " else return texture(fs0, (tc0* ou_single_matrix) + vec2(0.f, 0.020408f) );\n" - " default:\n" // undefined behavior - " return texture(fs0,tc0);\n" - " }\n" - " }\n" - " else if (stereo_image_count == 2)\n" - " {\n" - " switch (stereo_display_mode)\n" - " {\n" - " case STEREO_MODE_ANAGLYPH:\n" - " left = texture(fs0, tc0);\n" - " right = texture(fs1, tc0);\n" - " return vec4(left.r, right.g, right.b, 1.f);\n" - " case STEREO_MODE_SIDE_BY_SIDE:\n" - " if (tc0.x < 0.5) return texture(fs0,(tc0 * sbs_multi_matrix));\n" - " else return texture(fs1,(tc0 * sbs_multi_matrix) + vec2(-1.f,0.f));\n" - " case STEREO_MODE_OVER_UNDER:\n" - " if (tc0.y < 0.5) return texture(fs0,(tc0 * ou_multi_matrix));\n" - " else return texture(fs1,(tc0 * ou_multi_matrix) + vec2(0.f,-1.f));\n" - " default:\n" // undefined behavior - " return texture(fs0,tc0);\n" - " }\n" - " }\n" - " else\n" - " {\n" - " vec2 coord_left = tc0 * vec2(1.f, 0.4898f);\n" - " vec2 coord_right = coord_left + vec2(0.f, 0.510204f);\n" - " left = texture(fs0, coord_left);\n" - " right = texture(fs0, coord_right);\n" - " return vec4(left.r, right.g, right.b, 1.);\n" - " }\n" - "}\n" - "\n" - "void main()\n" - "{\n" - " vec4 color = read_source();\n" - " color.rgb = pow(color.rgb, vec3(gamma));\n" - " if (limit_range > 0)\n" - " ocol = ((color * 220.) + 16.) / 255.;\n" - " else\n" - " ocol = color;\n" - "}\n"; + #include "../Program/GLSLSnippets/VideoOutCalibrationPass.glsl" + ; renderpass_config.set_depth_mask(false); renderpass_config.set_color_mask(0, true, true, true, true); diff --git a/rpcs3/Emu/RSX/VK/VKOverlays.h b/rpcs3/Emu/RSX/VK/VKOverlays.h index 7b6efc7f68..9da4202372 100644 --- a/rpcs3/Emu/RSX/VK/VKOverlays.h +++ b/rpcs3/Emu/RSX/VK/VKOverlays.h @@ -137,7 +137,7 @@ namespace vk bool m_pulse_glow = false; bool m_clip_enabled = false; bool m_disable_vertex_snap = false; - rsx::overlays::texture_sampling_mode m_texture_type; + rsx::overlays::texture_sampling_mode m_texture_type = rsx::overlays::texture_sampling_mode::none; areaf m_clip_region; coordf m_viewport; diff --git a/rpcs3/emucore.vcxproj b/rpcs3/emucore.vcxproj index de159e10df..77390d7c33 100644 --- a/rpcs3/emucore.vcxproj +++ b/rpcs3/emucore.vcxproj @@ -938,6 +938,7 @@ + diff --git a/rpcs3/emucore.vcxproj.filters b/rpcs3/emucore.vcxproj.filters index 066d4b7cf9..88805a21fe 100644 --- a/rpcs3/emucore.vcxproj.filters +++ b/rpcs3/emucore.vcxproj.filters @@ -2496,5 +2496,8 @@ Emu\GPU\RSX\Program\Snippets\RSXProg + + Emu\GPU\RSX\Program\Snippets + \ No newline at end of file