From cb0d14258bddee2ccddf5c49bb3661d002214ff6 Mon Sep 17 00:00:00 2001 From: KojoZero Date: Mon, 25 May 2026 08:40:34 -0700 Subject: [PATCH] refactored vulkan shaders --- .../antialiasing/Vulkan/vulkan_fxaa.frag | 10 ++------- .../antialiasing/Vulkan/vulkan_fxaa.vert | 8 +------ .../Vulkan/vulkan_smaa_pass0_post.frag | 4 ++-- .../Vulkan/vulkan_smaa_pass0_pre.frag | 9 ++------ .../Vulkan/vulkan_smaa_pass0_pre.vert | 3 --- .../Vulkan/vulkan_smaa_pass1_post.frag | 2 +- .../Vulkan/vulkan_smaa_pass1_pre.frag | 13 ++++------- .../Vulkan/vulkan_smaa_pass1_pre.vert | 3 --- .../Vulkan/vulkan_smaa_pass2_post.frag | 2 +- .../Vulkan/vulkan_smaa_pass2_pre.frag | 11 +++------- .../Vulkan/vulkan_smaa_pass2_pre.vert | 3 --- .../scaling/vulkan_area_sampling.frag | 11 +++------- .../scaling/vulkan_area_sampling.vert | 3 --- .../host_shaders/vulkan_present.frag | 19 ++-------------- .../host_shaders/vulkan_present_anaglyph.frag | 22 ++++--------------- .../vulkan_present_interlaced.frag | 22 ++++--------------- .../host_shaders/vulkan_simple_present.frag | 18 ++------------- .../renderer_vulkan/renderer_vulkan.h | 5 +---- 18 files changed, 32 insertions(+), 136 deletions(-) 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 ef2898d5d..cbc3b4eda 100644 --- a/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_fxaa.frag +++ b/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_fxaa.frag @@ -53,7 +53,7 @@ FXAA_SUBPIX_CAP - Insures fine detail is not completely removed. layout(location = 0) in vec2 frag_tex_coord; layout(location = 0) out vec4 color; -layout (set = 0, binding = 0) uniform sampler2D screen_textures[3]; +layout (set = 0, binding = 0) uniform sampler2D color_texture; layout (push_constant, std140) uniform DrawInfo { mat4 modelview_matrix; @@ -64,14 +64,8 @@ layout (push_constant, std140) uniform DrawInfo { 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 @@ -263,7 +257,7 @@ vec3 sRGBToLinear(vec3 c) { void main() { - vec4 pixel = vec4(FxaaPixelShader(frag_tex_coord, screen_textures[0], vec2(i_resolution.z, i_resolution.w)), 1.0) * 1.0; + vec4 pixel = vec4(FxaaPixelShader(frag_tex_coord, color_texture, 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 60dac6302..66591424e 100644 --- a/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_fxaa.vert +++ b/src/video_core/host_shaders/antialiasing/Vulkan/vulkan_fxaa.vert @@ -10,18 +10,12 @@ layout (push_constant, std140) uniform DrawInfo { 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; -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 b80add9d6..722a27b36 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, screen_textures[0]), 0.0, 0.0); + color = vec4(SMAALumaEdgeDetectionPS(frag_tex_coord, offset, color_texture), 0.0, 0.0); } else if (SMAA_EDT <= 1.0) { - color = vec4(SMAAColorEdgeDetectionPS(frag_tex_coord, offset, screen_textures[0]), 0.0, 0.0); + color = vec4(SMAAColorEdgeDetectionPS(frag_tex_coord, offset, color_texture), 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 c239c1322..8953a0169 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 @@ -13,9 +13,6 @@ layout (push_constant, std140) uniform DrawInfo { int layer; int reverse_interlaced; int convert_colors; - int areatex; - int searchtex; - int smaa_input; }; #define SMAA_RT_METRICS vec4(i_resolution.z, i_resolution.w, i_resolution.x, i_resolution.y) @@ -27,9 +24,7 @@ layout (push_constant, std140) uniform DrawInfo { layout(location = 0) in vec2 frag_tex_coord; layout(location = 1) in vec4 offset[3]; layout(location = 0) out vec4 color; -layout (set = 0, binding = 0) uniform sampler2D screen_textures[3]; -/* -screen_textures[0] = color_texture -*/ +layout (set = 0, binding = 0) uniform sampler2D 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 698c0e8b0..8244c35b4 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 @@ -13,9 +13,6 @@ layout (push_constant, std140) uniform DrawInfo { int layer; int reverse_interlaced; int convert_colors; - int areatex; - int searchtex; - int smaa_input; }; #define SMAA_RT_METRICS vec4(i_resolution.z, i_resolution.w, i_resolution.x, i_resolution.y) 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 441eff0ef..d407fa1a1 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, screen_textures[0], screen_textures[1], screen_textures[2], subsampleIndices); + color = SMAABlendingWeightCalculationPS(frag_tex_coord, pixcoord, offset, color_texture, areaTex, searchTex, 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 a0ad791cf..225a7382f 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 @@ -13,9 +13,6 @@ layout (push_constant, std140) uniform DrawInfo { int layer; int reverse_interlaced; int convert_colors; - int areatex; - int searchtex; - int smaa_input; }; #define SMAA_RT_METRICS vec4(i_resolution.z, i_resolution.w, i_resolution.x, i_resolution.y) @@ -28,11 +25,9 @@ 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 (set = 0, binding = 0) uniform sampler2D screen_textures[3]; -/* -screen_textures[0] = color_texture -screen_textures[1] = areaTex; -screen_textures[2] = searchTex; -*/ +layout (set = 0, binding = 0) uniform sampler2D color_texture; +layout (set = 0, binding = 1) uniform sampler2D areaTex; +layout (set = 0, binding = 2) uniform sampler2D 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 f07f7e373..7e752e755 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 @@ -13,9 +13,6 @@ layout (push_constant, std140) uniform DrawInfo { int layer; int reverse_interlaced; int convert_colors; - int areatex; - int searchtex; - int smaa_input; }; #define SMAA_RT_METRICS vec4(i_resolution.z, i_resolution.w, i_resolution.x, i_resolution.y) 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 728ce4682..8341214c5 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, screen_textures[1], screen_textures[0]); + vec4 pixel = SMAANeighborhoodBlendingPS(frag_tex_coord, offset, SMAA_Input, color_texture); 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 bf9374d39..017eca16e 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 @@ -13,9 +13,6 @@ layout (push_constant, std140) uniform DrawInfo { int layer; int reverse_interlaced; int convert_colors; - int areatex; - int searchtex; - int smaa_input; }; #define SMAA_RT_METRICS vec4(i_resolution.z, i_resolution.w, i_resolution.x, i_resolution.y) @@ -25,10 +22,8 @@ layout (push_constant, std140) uniform DrawInfo { layout(location = 0) in vec2 frag_tex_coord; layout(location = 1) in vec4 offset; layout(location = 0) out vec4 color; -layout (set = 0, binding = 0) uniform sampler2D screen_textures[3]; -/* -screen_textures[0] = color_texture -screen_textures[1] = SMAA_Input; -*/ +layout (set = 0, binding = 0) uniform sampler2D color_texture; +layout (set = 0, binding = 1) uniform sampler2D 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 2e9f89b47..7c0ea802e 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 @@ -13,9 +13,6 @@ layout (push_constant, std140) uniform DrawInfo { int layer; int reverse_interlaced; int convert_colors; - int areatex; - int searchtex; - int smaa_input; }; #define SMAA_RT_METRICS vec4(i_resolution.z, i_resolution.w, i_resolution.x, i_resolution.y) diff --git a/src/video_core/host_shaders/scaling/vulkan_area_sampling.frag b/src/video_core/host_shaders/scaling/vulkan_area_sampling.frag index fc551ce90..347bc8af0 100644 --- a/src/video_core/host_shaders/scaling/vulkan_area_sampling.frag +++ b/src/video_core/host_shaders/scaling/vulkan_area_sampling.frag @@ -2,10 +2,8 @@ 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 (set = 0, binding = 0) uniform sampler2D color_texture; + layout (push_constant, std140) uniform DrawInfo { mat4 modelview_matrix; vec4 i_resolution; @@ -15,9 +13,6 @@ layout (push_constant, std140) uniform DrawInfo { int layer; int reverse_interlaced; int convert_colors; - int areatex; - int searchtex; - int smaa_input; }; /***** Area Sampling *****/ @@ -97,7 +92,7 @@ vec3 LinearTosRGB(vec3 c) { } void main() { - vec4 pixel = AreaSampling(screen_textures[0], 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.vert b/src/video_core/host_shaders/scaling/vulkan_area_sampling.vert index cfaadad1e..2117c62fc 100644 --- a/src/video_core/host_shaders/scaling/vulkan_area_sampling.vert +++ b/src/video_core/host_shaders/scaling/vulkan_area_sampling.vert @@ -11,9 +11,6 @@ layout (push_constant, std140) uniform DrawInfo { int layer; int reverse_interlaced; int convert_colors; - int areatex; - int searchtex; - int smaa_input; }; void main() { diff --git a/src/video_core/host_shaders/vulkan_present.frag b/src/video_core/host_shaders/vulkan_present.frag index 41c0916bd..dfb75b9ef 100644 --- a/src/video_core/host_shaders/vulkan_present.frag +++ b/src/video_core/host_shaders/vulkan_present.frag @@ -18,23 +18,8 @@ layout (push_constant, std140) uniform DrawInfo { 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 -} +layout (set = 0, binding = 0) uniform sampler2D color_texture; void main() { - color = GetScreen(screen_id_l); + color = texture(color_texture, frag_tex_coord); } diff --git a/src/video_core/host_shaders/vulkan_present_anaglyph.frag b/src/video_core/host_shaders/vulkan_present_anaglyph.frag index a01ce63f6..20d64605e 100644 --- a/src/video_core/host_shaders/vulkan_present_anaglyph.frag +++ b/src/video_core/host_shaders/vulkan_present_anaglyph.frag @@ -30,25 +30,11 @@ layout (push_constant, std140) uniform DrawInfo { 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 -} +layout (set = 0, binding = 0) uniform sampler2D color_texture_l; +layout (set = 0, binding = 1) uniform sampler2D color_texture_r; void main() { - vec4 color_tex_l = GetScreen(screen_id_l); - vec4 color_tex_r = GetScreen(screen_id_r); + vec4 color_tex_l = texture(color_texture_l, frag_tex_coord); + vec4 color_tex_r = texture(color_texture_r, frag_tex_coord); color = vec4(color_tex_l.rgb*l+color_tex_r.rgb*r, color_tex_l.a); } diff --git a/src/video_core/host_shaders/vulkan_present_interlaced.frag b/src/video_core/host_shaders/vulkan_present_interlaced.frag index b033a9dec..cf9af8477 100644 --- a/src/video_core/host_shaders/vulkan_present_interlaced.frag +++ b/src/video_core/host_shaders/vulkan_present_interlaced.frag @@ -18,27 +18,13 @@ layout (push_constant, std140) uniform DrawInfo { 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 -} +layout (set = 0, binding = 0) uniform sampler2D color_texture_l; +layout (set = 0, binding = 1) uniform sampler2D color_texture_r; void main() { float screen_row = o_resolution.x * frag_tex_coord.x; if (int(screen_row) % 2 == reverse_interlaced) - color = GetScreen(screen_id_l); + color = texture(color_texture_l, frag_tex_coord); else - color = GetScreen(screen_id_r); + color = texture(color_texture_r, frag_tex_coord); } diff --git a/src/video_core/host_shaders/vulkan_simple_present.frag b/src/video_core/host_shaders/vulkan_simple_present.frag index 04ab1d8bc..c9f86c37f 100644 --- a/src/video_core/host_shaders/vulkan_simple_present.frag +++ b/src/video_core/host_shaders/vulkan_simple_present.frag @@ -19,22 +19,8 @@ layout (push_constant, std140) uniform DrawInfo { int convert_colors; }; -layout (set = 0, binding = 0) uniform sampler2D screen_textures[3]; +layout (set = 0, binding = 0) uniform sampler2D color_texture; -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)); @@ -45,7 +31,7 @@ vec3 LinearTosRGB(vec3 c) { } void main() { - vec4 pixel = GetScreen(screen_id_l); + vec4 pixel = texture(color_texture, frag_tex_coord); if (convert_colors == 2){ pixel = vec4(LinearTosRGB(pixel.rgb), pixel.a); } else if (convert_colors == 1){ diff --git a/src/video_core/renderer_vulkan/renderer_vulkan.h b/src/video_core/renderer_vulkan/renderer_vulkan.h index 122e8c7f3..6e0a07906 100644 --- a/src/video_core/renderer_vulkan/renderer_vulkan.h +++ b/src/video_core/renderer_vulkan/renderer_vulkan.h @@ -63,11 +63,8 @@ struct PresentUniformData { int layer = 0; int reverse_interlaced = 0; int convert_colors; - int areatex; - int searchtex; - int smaa_input; }; -static_assert(sizeof(PresentUniformData) == 128, +static_assert(sizeof(PresentUniformData) == 116, "PresentUniformData does not structure in shader!"); class RendererVulkan : public VideoCore::RendererBase {