rsx: Improvements to the video out passes

- Use shared VS for vulkan as well as GL
- Simplify binding model and give control back to the cpp side
This commit is contained in:
kd-11 2024-02-01 03:47:02 +03:00 committed by Megamouse
parent bb22afb7f1
commit 1808a4373b
4 changed files with 48 additions and 37 deletions

View File

@ -464,6 +464,13 @@ namespace gl
#include "../Program/GLSLSnippets/VideoOutCalibrationPass.glsl"
;
std::pair<std::string_view, std::string> repl_list[] =
{
{ "%sampler_binding", fmt::format("(%d - x)", GL_TEMP_IMAGE_SLOT(0)) },
{ "%set_decorator, ", "" },
};
fs_src = fmt::replace_all(fs_src, repl_list);
m_input_filter = gl::filter::linear;
}
@ -480,11 +487,11 @@ namespace gl
program_handle.uniforms["stereo_display_mode"] = static_cast<u8>(stereo_mode);
program_handle.uniforms["stereo_image_count"] = (source[1] == GL_NONE? 1 : 2);
saved_sampler_state saved(31, m_sampler);
cmd->bind_texture(31, GL_TEXTURE_2D, source[0]);
saved_sampler_state saved(GL_TEMP_IMAGE_SLOT(0), m_sampler);
cmd->bind_texture(GL_TEMP_IMAGE_SLOT(0), GL_TEXTURE_2D, source[0]);
saved_sampler_state saved2(30, m_sampler);
cmd->bind_texture(30, GL_TEXTURE_2D, source[1]);
saved_sampler_state saved2(GL_TEMP_IMAGE_SLOT(1), m_sampler);
cmd->bind_texture(GL_TEMP_IMAGE_SLOT(1), GL_TEXTURE_2D, source[1]);
overlay_pass::run(cmd, viewport, GL_NONE, gl::image_aspect::color, false);
}

View File

@ -2,10 +2,21 @@ R"(
#version 420
layout(location=0) out vec2 tc0;
#ifdef VULKAN
#define gl_VertexID gl_VertexIndex
#endif
void main()
{
vec2 positions[] = {vec2(-1., -1.), vec2(1., -1.), vec2(-1., 1.), vec2(1., 1.)};
#ifdef VULKAN
// Origin at top left
vec2 coords[] = {vec2(0., 0.), vec2(1., 0.), vec2(0., 1.), vec2(1., 1.)};
#else
// Origin at bottom left. Flip Y coordinate.
vec2 coords[] = {vec2(0., 1.), vec2(1., 1.), vec2(0., 0.), vec2(1., 0.)};
#endif
tc0 = coords[gl_VertexID % 4];
vec2 pos = positions[gl_VertexID % 4];
gl_Position = vec4(pos, 0., 1.);

View File

@ -1,13 +1,10 @@
R"(
#version 420
#version 440
#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
#define SAMPLER_BINDING(x) %sampler_binding
layout(%set_decorator, binding=SAMPLER_BINDING(0)) uniform sampler2D fs0;
layout(%set_decorator, binding=SAMPLER_BINDING(1)) uniform sampler2D fs1;
layout(location=0) in vec2 tc0;
layout(location=0) out vec4 ocol;
@ -77,7 +74,10 @@ vec4 anaglyph_stereo_image()
vec4 read_source()
{
if (stereo_display_mode == STEREO_MODE_DISABLED) return texture(fs0, tc0);
if (stereo_display_mode == STEREO_MODE_DISABLED)
{
return texture(fs0, tc0);
}
if (stereo_image_count == 1)
{
@ -106,7 +106,8 @@ vec4 read_source()
return texture(fs0, tc0);
}
}
else if (stereo_image_count == 2)
if (stereo_image_count == 2)
{
switch (stereo_display_mode)
{
@ -133,23 +134,17 @@ vec4 read_source()
return texture(fs0, tc0);
}
}
else
{
vec2 coord_left = tc0 * left_single_matrix;
vec2 coord_right = coord_left + right_single_matrix;
vec4 left = texture(fs0, coord_left);
vec4 right = texture(fs0, coord_right);
return vec4(left.r, right.g, right.b, 1.);
}
// Unreachable. Return debug color fill
return vec4(1., 0., 0., 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;
ocol = (limit_range == 0)
? ocol = color
: ((color * 220.) + 16.) / 255.;
}
)"

View File

@ -857,22 +857,20 @@ namespace vk
video_out_calibration_pass::video_out_calibration_pass()
{
vs_src =
"#version 450\n\n"
"layout(location=0) out vec2 tc0;\n"
"\n"
"void main()\n"
"{\n"
" vec2 positions[] = {vec2(-1., -1.), vec2(1., -1.), vec2(-1., 1.), vec2(1., 1.)};\n"
" vec2 coords[] = {vec2(0., 0.), vec2(1., 0.), vec2(0., 1.), vec2(1., 1.)};\n"
" tc0 = coords[gl_VertexIndex % 4];\n"
" vec2 pos = positions[gl_VertexIndex % 4];\n"
" gl_Position = vec4(pos, 0., 1.);\n"
"}\n";
#include "../Program/GLSLSnippets/GenericVSPassthrough.glsl"
;
fs_src =
#include "../Program/GLSLSnippets/VideoOutCalibrationPass.glsl"
;
std::pair<std::string_view, std::string> repl_list[] =
{
{ "%sampler_binding", fmt::format("(%d + x)", sampler_location(0)) },
{ "%set_decorator", "set=0" },
};
fs_src = fmt::replace_all(fs_src, repl_list);
renderpass_config.set_depth_mask(false);
renderpass_config.set_color_mask(0, true, true, true, true);
renderpass_config.set_attachment_count(1);