From 756d73531ce1f37b4c6981fe562890f6ea37b5c5 Mon Sep 17 00:00:00 2001 From: KojoZero Date: Wed, 6 May 2026 17:53:27 -0700 Subject: [PATCH] setting up vulkan part 2 --- src/video_core/host_shaders/CMakeLists.txt | 19 ++++ .../antialiasing/Vulkan/vulkan_fxaa.frag | 25 ++++- .../antialiasing/Vulkan/vulkan_fxaa.vert | 25 ++++- .../Vulkan/vulkan_smaa_pass0_post.frag | 4 +- .../Vulkan/vulkan_smaa_pass0_pre.frag | 24 +++- .../Vulkan/vulkan_smaa_pass0_pre.vert | 18 ++- .../Vulkan/vulkan_smaa_pass1_post.frag | 2 +- .../Vulkan/vulkan_smaa_pass1_pre.frag | 28 ++++- .../Vulkan/vulkan_smaa_pass1_pre.vert | 18 ++- .../Vulkan/vulkan_smaa_pass2_post.frag | 2 +- .../Vulkan/vulkan_smaa_pass2_pre.frag | 27 ++++- .../Vulkan/vulkan_smaa_pass2_pre.vert | 18 ++- .../scaling/opengl_area_sampling.frag | 1 - .../scaling/vulkan_area_sampling.frag | 105 ++++++++++++++++++ .../scaling/vulkan_area_sampling.vert | 23 ++++ .../host_shaders/vulkan_present.vert | 1 - .../host_shaders/vulkan_simple_present.frag | 54 +++++++++ .../host_shaders/vulkan_simple_present.vert | 23 ++++ 18 files changed, 380 insertions(+), 37 deletions(-) create mode 100644 src/video_core/host_shaders/scaling/vulkan_area_sampling.frag create mode 100644 src/video_core/host_shaders/scaling/vulkan_area_sampling.vert create mode 100644 src/video_core/host_shaders/vulkan_simple_present.frag create mode 100644 src/video_core/host_shaders/vulkan_simple_present.vert diff --git a/src/video_core/host_shaders/CMakeLists.txt b/src/video_core/host_shaders/CMakeLists.txt index 40676999a..145dccb25 100644 --- a/src/video_core/host_shaders/CMakeLists.txt +++ b/src/video_core/host_shaders/CMakeLists.txt @@ -28,8 +28,25 @@ set(SHADER_FILES antialiasing/OpenGL/opengl_smaa_pass2_post.frag antialiasing/OpenGL/opengl_smaa_pass2_post.vert antialiasing/OpenGL/opengl_smaa.hlsl + antialiasing/Vulkan/vulkan_fxaa.frag + antialiasing/Vulkan/vulkan_fxaa.vert + antialiasing/Vulkan/vulkan_smaa_pass0_pre.frag + antialiasing/Vulkan/vulkan_smaa_pass0_pre.vert + antialiasing/Vulkan/vulkan_smaa_pass0_post.frag + antialiasing/Vulkan/vulkan_smaa_pass0_post.vert + antialiasing/Vulkan/vulkan_smaa_pass1_pre.frag + antialiasing/Vulkan/vulkan_smaa_pass1_pre.vert + antialiasing/Vulkan/vulkan_smaa_pass1_post.frag + antialiasing/Vulkan/vulkan_smaa_pass1_post.vert + antialiasing/Vulkan/vulkan_smaa_pass2_pre.frag + antialiasing/Vulkan/vulkan_smaa_pass2_pre.vert + antialiasing/Vulkan/vulkan_smaa_pass2_post.frag + antialiasing/Vulkan/vulkan_smaa_pass2_post.vert + antialiasing/Vulkan/vulkan_smaa.hlsl scaling/opengl_area_sampling.frag scaling/opengl_area_sampling.vert + scaling/vulkan_area_sampling.frag + scaling/vulkan_area_sampling.vert full_screen_triangle.vert opengl_present.frag opengl_present.vert @@ -43,6 +60,8 @@ set(SHADER_FILES vulkan_present_anaglyph.frag vulkan_present_interlaced.frag vulkan_blit_depth_stencil.frag + vulkan_simple_present.frag + vulkan_simple_present.vert vulkan_cursor.frag vulkan_cursor.vert ) diff --git a/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_fxaa.frag b/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_fxaa.frag index ac3d736cd..ef2898d5d 100644 --- a/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_fxaa.frag +++ b/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_fxaa.frag @@ -48,15 +48,30 @@ FXAA_SUBPIX_CAP - Insures fine detail is not completely removed. 7.0/8.0 - high amount of filtering 1.0 - no capping of sub-pixel aliasing removal */ -//? #version 450 +#version 450 core +#extension GL_ARB_separate_shader_objects : enable layout(location = 0) in vec2 frag_tex_coord; layout(location = 0) out vec4 color; -layout(binding = 0) uniform sampler2D color_texture; +layout (set = 0, binding = 0) uniform sampler2D screen_textures[3]; -uniform vec4 i_resolution; -uniform int convert_colors; +layout (push_constant, std140) uniform DrawInfo { + mat4 modelview_matrix; + vec4 i_resolution; + vec4 o_resolution; + int screen_id_l; + int screen_id_r; + int layer; + int reverse_interlaced; + int convert_colors; + int areatex; + int searchtex; + int smaa_input; +}; +/* +screen_textures[0] = color_texture +*/ #ifndef FXAA_PRESET #define FXAA_PRESET 5 #endif @@ -248,7 +263,7 @@ vec3 sRGBToLinear(vec3 c) { void main() { - vec4 pixel = vec4(FxaaPixelShader(frag_tex_coord, color_texture, vec2(i_resolution.z, i_resolution.w)), 1.0) * 1.0; + vec4 pixel = vec4(FxaaPixelShader(frag_tex_coord, screen_textures[0], vec2(i_resolution.z, i_resolution.w)), 1.0) * 1.0; if (convert_colors == 1){ pixel = vec4(sRGBToLinear(pixel.rgb), pixel.a); } diff --git a/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_fxaa.vert b/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_fxaa.vert index 793dcc580..60dac6302 100644 --- a/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_fxaa.vert +++ b/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_fxaa.vert @@ -1,10 +1,27 @@ -//? #version 450 +#version 450 core +#extension GL_ARB_separate_shader_objects : enable + +layout (push_constant, std140) uniform DrawInfo { + mat4 modelview_matrix; + vec4 i_resolution; + vec4 o_resolution; + int screen_id_l; + int screen_id_r; + int layer; + int reverse_interlaced; + int convert_colors; + int areatex; + int searchtex; + int smaa_input; +}; + layout(location = 0) in vec2 vert_position; layout(location = 1) in vec2 vert_tex_coord; layout(location = 0) out vec2 frag_tex_coord; - -uniform vec4 i_resolution; - +layout (set = 0, binding = 0) uniform sampler2D screen_textures[3]; +/* +screen_textures[0] = color_texture +*/ void main() { gl_Position = vec4(vert_position, 0.0, 1.0); diff --git a/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_smaa_pass0_post.frag b/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_smaa_pass0_post.frag index 722a27b36..b80add9d6 100644 --- a/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_smaa_pass0_post.frag +++ b/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_smaa_pass0_post.frag @@ -1,7 +1,7 @@ void main() { if (SMAA_EDT == 0.0) { - color = vec4(SMAALumaEdgeDetectionPS(frag_tex_coord, offset, color_texture), 0.0, 0.0); + color = vec4(SMAALumaEdgeDetectionPS(frag_tex_coord, offset, screen_textures[0]), 0.0, 0.0); } else if (SMAA_EDT <= 1.0) { - color = vec4(SMAAColorEdgeDetectionPS(frag_tex_coord, offset, color_texture), 0.0, 0.0); + color = vec4(SMAAColorEdgeDetectionPS(frag_tex_coord, offset, screen_textures[0]), 0.0, 0.0); } } diff --git a/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_smaa_pass0_pre.frag b/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_smaa_pass0_pre.frag index 51a1e2779..bca71c4b8 100644 --- a/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_smaa_pass0_pre.frag +++ b/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_smaa_pass0_pre.frag @@ -1,9 +1,23 @@ -//? #version 450 +#version 450 core +#extension GL_ARB_separate_shader_objects : enable + // SPDX-License-Identifier: Unlicense //----------------------------------------------------------------------------- // Edge Detection Shaders (First Pass) +layout (push_constant, std140) uniform DrawInfo { + mat4 modelview_matrix; + vec4 i_resolution; + vec4 o_resolution; + int screen_id_l; + int screen_id_r; + int layer; + int reverse_interlaced; + int convert_colors; + int areatex; + int searchtex; + int smaa_input; +}; -uniform vec4 i_resolution; #define SMAA_RT_METRICS vec4(i_resolution.z, i_resolution.w, i_resolution.x, i_resolution.y) #define SMAA_GLSL_4 #define SMAA_PRESET_ULTRA @@ -12,7 +26,9 @@ uniform vec4 i_resolution; layout(location = 0) in vec2 frag_tex_coord; layout(location = 1) in vec4 offset[3]; layout(location = 0) out vec4 color; -layout(binding = 0) uniform sampler2D color_texture; - +layout (set = 0, binding = 0) uniform sampler2D screen_textures[3]; +/* +screen_textures[0] = color_texture +*/ #define SMAA_INCLUDE_VS 0 //#include "SMAA.hlsl" \ No newline at end of file diff --git a/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_smaa_pass0_pre.vert b/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_smaa_pass0_pre.vert index 4bdce548b..1ed03a23a 100644 --- a/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_smaa_pass0_pre.vert +++ b/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_smaa_pass0_pre.vert @@ -1,9 +1,23 @@ -//? #version 450 +#version 450 core +#extension GL_ARB_separate_shader_objects : enable + // SPDX-License-Identifier: Unlicense //----------------------------------------------------------------------------- // Edge Detection Shaders (First Pass) +layout (push_constant, std140) uniform DrawInfo { + mat4 modelview_matrix; + vec4 i_resolution; + vec4 o_resolution; + int screen_id_l; + int screen_id_r; + int layer; + int reverse_interlaced; + int convert_colors; + int areatex; + int searchtex; + int smaa_input; +}; -uniform vec4 i_resolution; #define SMAA_RT_METRICS vec4(i_resolution.z, i_resolution.w, i_resolution.x, i_resolution.y) #define SMAA_GLSL_4 #define SMAA_PRESET_ULTRA diff --git a/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_smaa_pass1_post.frag b/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_smaa_pass1_post.frag index d407fa1a1..441eff0ef 100644 --- a/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_smaa_pass1_post.frag +++ b/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_smaa_pass1_post.frag @@ -1,4 +1,4 @@ void main() { vec4 subsampleIndices = vec4(0.0); - color = SMAABlendingWeightCalculationPS(frag_tex_coord, pixcoord, offset, color_texture, areaTex, searchTex, subsampleIndices); + color = SMAABlendingWeightCalculationPS(frag_tex_coord, pixcoord, offset, screen_textures[0], screen_textures[1], screen_textures[2], subsampleIndices); } diff --git a/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_smaa_pass1_pre.frag b/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_smaa_pass1_pre.frag index 279a85300..d41eae83c 100644 --- a/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_smaa_pass1_pre.frag +++ b/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_smaa_pass1_pre.frag @@ -1,9 +1,23 @@ -//? #version 450 +#version 450 core +#extension GL_ARB_separate_shader_objects : enable + // SPDX-License-Identifier: Unlicense //----------------------------------------------------------------------------- // Blending Weight Calculation Shader (Second Pass) +layout (push_constant, std140) uniform DrawInfo { + mat4 modelview_matrix; + vec4 i_resolution; + vec4 o_resolution; + int screen_id_l; + int screen_id_r; + int layer; + int reverse_interlaced; + int convert_colors; + int areatex; + int searchtex; + int smaa_input; +}; -uniform vec4 i_resolution; #define SMAA_RT_METRICS vec4(i_resolution.z, i_resolution.w, i_resolution.x, i_resolution.y) #define SMAA_GLSL_4 #define SMAA_PRESET_ULTRA @@ -13,9 +27,11 @@ layout(location = 0) in vec2 frag_tex_coord; layout(location = 1) in vec2 pixcoord; layout(location = 2) in vec4 offset[3]; layout(location = 0) out vec4 color; -layout(binding = 0) uniform sampler2D color_texture; -uniform sampler2D areaTex; -uniform sampler2D searchTex; - +layout (set = 0, binding = 0) uniform sampler2D screen_textures[3]; +/* +screen_textures[0] = color_texture +screen_textures[1] = areaTex; +screen_textures[2] = searchTex; +*/ #define SMAA_INCLUDE_VS 0 //#include "SMAA.hlsl" \ No newline at end of file diff --git a/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_smaa_pass1_pre.vert b/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_smaa_pass1_pre.vert index f75990c39..0b1a853c1 100644 --- a/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_smaa_pass1_pre.vert +++ b/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_smaa_pass1_pre.vert @@ -1,9 +1,23 @@ -//? #version 450 +#version 450 core +#extension GL_ARB_separate_shader_objects : enable + // SPDX-License-Identifier: Unlicense //----------------------------------------------------------------------------- // Blending Weight Calculation Shader (Second Pass) +layout (push_constant, std140) uniform DrawInfo { + mat4 modelview_matrix; + vec4 i_resolution; + vec4 o_resolution; + int screen_id_l; + int screen_id_r; + int layer; + int reverse_interlaced; + int convert_colors; + int areatex; + int searchtex; + int smaa_input; +}; -uniform vec4 i_resolution; #define SMAA_RT_METRICS vec4(i_resolution.z, i_resolution.w, i_resolution.x, i_resolution.y) #define SMAA_GLSL_4 #define SMAA_PRESET_ULTRA diff --git a/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_smaa_pass2_post.frag b/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_smaa_pass2_post.frag index 8341214c5..728ce4682 100644 --- a/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_smaa_pass2_post.frag +++ b/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_smaa_pass2_post.frag @@ -3,7 +3,7 @@ vec3 LinearTosRGB(vec3 c) { } void main() { - vec4 pixel = SMAANeighborhoodBlendingPS(frag_tex_coord, offset, SMAA_Input, color_texture); + vec4 pixel = SMAANeighborhoodBlendingPS(frag_tex_coord, offset, screen_textures[1], screen_textures[0]); if (convert_colors == 2){ pixel = vec4(LinearTosRGB(pixel.rgb), pixel.a); } diff --git a/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_smaa_pass2_pre.frag b/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_smaa_pass2_pre.frag index edd0d1137..37ca34c78 100644 --- a/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_smaa_pass2_pre.frag +++ b/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_smaa_pass2_pre.frag @@ -1,18 +1,33 @@ -//? #version 450 +#version 450 core +#extension GL_ARB_separate_shader_objects : enable + // SPDX-License-Identifier: Unlicense //----------------------------------------------------------------------------- // Neighborhood Blending Shader (Third Pass) +layout (push_constant, std140) uniform DrawInfo { + mat4 modelview_matrix; + vec4 i_resolution; + vec4 o_resolution; + int screen_id_l; + int screen_id_r; + int layer; + int reverse_interlaced; + int convert_colors; + int areatex; + int searchtex; + int smaa_input; +}; -uniform vec4 i_resolution; -uniform int convert_colors; #define SMAA_RT_METRICS vec4(i_resolution.z, i_resolution.w, i_resolution.x, i_resolution.y) #define SMAA_GLSL_4 layout(location = 0) in vec2 frag_tex_coord; layout(location = 1) in vec4 offset; layout(location = 0) out vec4 color; -layout(binding = 0) uniform sampler2D color_texture; -uniform sampler2D SMAA_Input; - +layout (set = 0, binding = 0) uniform sampler2D screen_textures[3]; +/* +screen_textures[0] = color_texture +screen_textures[1] = SMAA_Input; +*/ #define SMAA_INCLUDE_VS 0 //#include "SMAA.hlsl" \ No newline at end of file diff --git a/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_smaa_pass2_pre.vert b/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_smaa_pass2_pre.vert index 24baa2cc6..765a64e4d 100644 --- a/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_smaa_pass2_pre.vert +++ b/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_smaa_pass2_pre.vert @@ -1,9 +1,23 @@ -//? #version 450 +#version 450 core +#extension GL_ARB_separate_shader_objects : enable + // SPDX-License-Identifier: Unlicense //----------------------------------------------------------------------------- // Neighborhood Blending Shader (Third Pass) +layout (push_constant, std140) uniform DrawInfo { + mat4 modelview_matrix; + vec4 i_resolution; + vec4 o_resolution; + int screen_id_l; + int screen_id_r; + int layer; + int reverse_interlaced; + int convert_colors; + int areatex; + int searchtex; + int smaa_input; +}; -uniform vec4 i_resolution; #define SMAA_RT_METRICS vec4(i_resolution.z, i_resolution.w, i_resolution.x, i_resolution.y) #define SMAA_GLSL_4 diff --git a/src/video_core/host_shaders/scaling/opengl_area_sampling.frag b/src/video_core/host_shaders/scaling/opengl_area_sampling.frag index ccf9edd55..f1991de10 100644 --- a/src/video_core/host_shaders/scaling/opengl_area_sampling.frag +++ b/src/video_core/host_shaders/scaling/opengl_area_sampling.frag @@ -85,7 +85,6 @@ vec3 LinearTosRGB(vec3 c) { } void main() { - // vec4 pixel = texture(color_texture, frag_tex_coord); vec4 pixel = AreaSampling(color_texture, frag_tex_coord); if (convert_colors == 2){ pixel = vec4(LinearTosRGB(pixel.rgb), pixel.a); diff --git a/src/video_core/host_shaders/scaling/vulkan_area_sampling.frag b/src/video_core/host_shaders/scaling/vulkan_area_sampling.frag new file mode 100644 index 000000000..fc551ce90 --- /dev/null +++ b/src/video_core/host_shaders/scaling/vulkan_area_sampling.frag @@ -0,0 +1,105 @@ +//? #version 460 core + +layout(location = 0) in vec2 frag_tex_coord; +layout(location = 0) out vec4 color; +layout (set = 0, binding = 0) uniform sampler2D screen_textures[3]; +/* +screen_textures[0] = color_texture +*/ +layout (push_constant, std140) uniform DrawInfo { + mat4 modelview_matrix; + vec4 i_resolution; + vec4 o_resolution; + int screen_id_l; + int screen_id_r; + int layer; + int reverse_interlaced; + int convert_colors; + int areatex; + int searchtex; + int smaa_input; +}; + +/***** Area Sampling *****/ + +// By Sam Belliveau and Filippo Tarpini. Public Domain license. +// Effectively a more accurate sharp bilinear filter when upscaling, +// that also works as a mathematically perfect downscale filter. +// https://entropymine.com/imageworsener/pixelmixing/ +// https://github.com/obsproject/obs-studio/pull/1715 +// https://legacy.imagemagick.org/Usage/filter/ +vec4 AreaSampling(sampler2D textureSampler, vec2 texCoords) { + // Determine the sizes of the source and target images. + vec2 source_size = i_resolution.xy; + vec2 inverted_target_size = o_resolution.zw; + + // Determine the range of the source image that the target pixel will cover. + vec2 range = source_size * inverted_target_size; + vec2 beg = (texCoords.xy * source_size) - (range * 0.5); + vec2 end = beg + range; + + // Compute the top-left and bottom-right corners of the pixel box. + ivec2 f_beg = ivec2(floor(beg)); + ivec2 f_end = ivec2(floor(end)); + + // Compute how much of the start and end pixels are covered horizontally & vertically. + float area_w = 1.0 - fract(beg.x); + float area_n = 1.0 - fract(beg.y); + float area_e = fract(end.x); + float area_s = fract(end.y); + + // Compute the areas of the corner pixels in the pixel box. + float area_nw = area_n * area_w; + float area_ne = area_n * area_e; + float area_sw = area_s * area_w; + float area_se = area_s * area_e; + + // Initialize the color accumulator. + vec4 avg_color = vec4(0.0, 0.0, 0.0, 0.0); + + // Accumulate corner pixels. + avg_color += area_nw * texelFetch(textureSampler, ivec2(f_beg.x, f_beg.y), 0); + avg_color += area_ne * texelFetch(textureSampler, ivec2(f_end.x, f_beg.y), 0); + avg_color += area_sw * texelFetch(textureSampler, ivec2(f_beg.x, f_end.y), 0); + avg_color += area_se * texelFetch(textureSampler, ivec2(f_end.x, f_end.y), 0); + + // Determine the size of the pixel box. + int x_range = int(f_end.x - f_beg.x - 0.5); + int y_range = int(f_end.y - f_beg.y - 0.5); + + // Accumulate top and bottom edge pixels. + for (int x = f_beg.x + 1; x <= f_beg.x + x_range; ++x) { + avg_color += area_n * texelFetch(textureSampler, ivec2(x, f_beg.y), 0); + avg_color += area_s * texelFetch(textureSampler, ivec2(x, f_end.y), 0); + } + + // Accumulate left and right edge pixels and all the pixels in between. + for (int y = f_beg.y + 1; y <= f_beg.y + y_range; ++y) { + avg_color += area_w * texelFetch(textureSampler, ivec2(f_beg.x, y), 0); + avg_color += area_e * texelFetch(textureSampler, ivec2(f_end.x, y), 0); + + for (int x = f_beg.x + 1; x <= f_beg.x + x_range; ++x) { + avg_color += texelFetch(textureSampler, ivec2(x, y), 0); + } + } + + // Compute the area of the pixel box that was sampled. + float area_corners = area_nw + area_ne + area_sw + area_se; + float area_edges = float(x_range) * (area_n + area_s) + float(y_range) * (area_w + area_e); + float area_center = float(x_range) * float(y_range); + + // Return the normalized average color. + return avg_color / (area_corners + area_edges + area_center); +} + +vec3 LinearTosRGB(vec3 c) { + return mix(c * 12.92, 1.055 * pow(c, vec3(1.0/2.4)) - 0.055, step(0.0031308, c)); +} + +void main() { + vec4 pixel = AreaSampling(screen_textures[0], frag_tex_coord); + if (convert_colors == 2){ + pixel = vec4(LinearTosRGB(pixel.rgb), pixel.a); + } + color = pixel; +} \ No newline at end of file diff --git a/src/video_core/host_shaders/scaling/vulkan_area_sampling.vert b/src/video_core/host_shaders/scaling/vulkan_area_sampling.vert new file mode 100644 index 000000000..37c250acd --- /dev/null +++ b/src/video_core/host_shaders/scaling/vulkan_area_sampling.vert @@ -0,0 +1,23 @@ +//? #version 460 +layout(location = 0) in vec2 vert_position; +layout(location = 1) in vec2 vert_tex_coord; +layout(location = 0) out vec2 frag_tex_coord; +layout (push_constant, std140) uniform DrawInfo { + mat4 modelview_matrix; + vec4 i_resolution; + vec4 o_resolution; + int screen_id_l; + int screen_id_r; + int layer; + int reverse_interlaced; + int convert_colors; + int areatex; + int searchtex; + int smaa_input; +}; +void main() +{ + gl_Position = vec4(mat2(modelview_matrix) * vert_position + modelview_matrix[2], 0.0, 1.0); + frag_tex_coord = vert_tex_coord; +} + diff --git a/src/video_core/host_shaders/vulkan_present.vert b/src/video_core/host_shaders/vulkan_present.vert index 08b4d252c..30f671d4e 100644 --- a/src/video_core/host_shaders/vulkan_present.vert +++ b/src/video_core/host_shaders/vulkan_present.vert @@ -1,7 +1,6 @@ // Copyright 2022 Citra Emulator Project // Licensed under GPLv2 or any later version // Refer to the license.txt file included. - #version 450 core #extension GL_ARB_separate_shader_objects : enable diff --git a/src/video_core/host_shaders/vulkan_simple_present.frag b/src/video_core/host_shaders/vulkan_simple_present.frag new file mode 100644 index 000000000..14a3a0ad7 --- /dev/null +++ b/src/video_core/host_shaders/vulkan_simple_present.frag @@ -0,0 +1,54 @@ +// Copyright 2022 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#version 450 core +#extension GL_ARB_separate_shader_objects : enable + +layout (location = 0) in vec2 frag_tex_coord; +layout (location = 0) out vec4 color; + +layout (push_constant, std140) uniform DrawInfo { + mat4 modelview_matrix; + vec4 i_resolution; + vec4 o_resolution; + int screen_id_l; + int screen_id_r; + int layer; + int reverse_interlaced; +}; + +layout (set = 0, binding = 0) uniform sampler2D screen_textures[3]; + +vec4 GetScreen(int screen_id) { +#ifdef ARRAY_DYNAMIC_INDEX + return texture(screen_textures[screen_id], frag_tex_coord); +#else + switch (screen_id) { + case 0: + return texture(screen_textures[0], frag_tex_coord); + case 1: + return texture(screen_textures[1], frag_tex_coord); + case 2: + return texture(screen_textures[2], frag_tex_coord); + } +#endif +} + +vec3 sRGBToLinear(vec3 c) { + return mix(c / 12.92, pow((c + 0.055) / 1.055, vec3(2.4)), step(0.04045, c)); +} + +vec3 LinearTosRGB(vec3 c) { + return mix(c * 12.92, 1.055 * pow(c, vec3(1.0/2.4)) - 0.055, step(0.0031308, c)); +} + +void main() { + vec4 pixel = GetScreen(screen_id_l); + if (convert_colors == 2){ + pixel = vec4(LinearTosRGB(pixel.rgb), pixel.a); + } else if (convert_colors == 1){ + pixel = vec4(sRGBToLinear(pixel.rgb), pixel.a); + } + color = pixel; +} diff --git a/src/video_core/host_shaders/vulkan_simple_present.vert b/src/video_core/host_shaders/vulkan_simple_present.vert new file mode 100644 index 000000000..2e41fa548 --- /dev/null +++ b/src/video_core/host_shaders/vulkan_simple_present.vert @@ -0,0 +1,23 @@ +// Copyright 2022 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. +#version 450 core +#extension GL_ARB_separate_shader_objects : enable + +layout (location = 0) in vec2 vert_position; +layout (location = 1) in vec2 vert_tex_coord; +layout (location = 0) out vec2 frag_tex_coord; + +layout (push_constant, std140) uniform DrawInfo { + mat4 modelview_matrix; + vec4 i_resolution; + vec4 o_resolution; + int screen_id_l; + int screen_id_r; + int layer; +}; + +void main() { + gl_Position = vec4(vert_position, 0.0, 1.0); + frag_tex_coord = vert_tex_coord; +}