From ea481a2db85aca1c0ed18ff46caea090ef0a80d3 Mon Sep 17 00:00:00 2001 From: lizzie Date: Sat, 24 Jan 2026 11:35:51 +0000 Subject: [PATCH] dont multiply shit randomly, just premult the texcoord to scale :) --- .patch/sgsr/0001-fix-glsl.patch | 58 ++++++------------- src/video_core/host_shaders/sgsr1_shader.vert | 6 +- .../renderer_vulkan/present/sgsr.cpp | 4 +- 3 files changed, 27 insertions(+), 41 deletions(-) diff --git a/.patch/sgsr/0001-fix-glsl.patch b/.patch/sgsr/0001-fix-glsl.patch index 3fd8c531a1..7f50bc210b 100644 --- a/.patch/sgsr/0001-fix-glsl.patch +++ b/.patch/sgsr/0001-fix-glsl.patch @@ -1,5 +1,5 @@ diff --git a/sgsr/v1/include/glsl/sgsr1_shader_mobile.frag b/sgsr/v1/include/glsl/sgsr1_shader_mobile.frag -index 7074999..9e2122e 100644 +index 7074999..c23aae4 100644 --- a/sgsr/v1/include/glsl/sgsr1_shader_mobile.frag +++ b/sgsr/v1/include/glsl/sgsr1_shader_mobile.frag @@ -1,4 +1,4 @@ @@ -8,7 +8,7 @@ index 7074999..9e2122e 100644 //============================================================================================================ // -@@ -34,17 +34,16 @@ precision highp int; +@@ -34,17 +34,17 @@ precision highp int; //////////////////////// #if defined(UseUniformBlock) @@ -17,6 +17,7 @@ index 7074999..9e2122e 100644 - highp vec4 ViewportInfo[1]; +layout( push_constant ) uniform constants { + highp vec4 ViewportInfo[1]; ++ highp vec2 ResizeFactor; }; -layout(set = 0, binding = 1) uniform mediump sampler2D ps0; +layout(set = 0, binding = 0) uniform mediump sampler2D ps0; @@ -30,7 +31,7 @@ index 7074999..9e2122e 100644 layout(location=0) out vec4 out_Target0; float fastLanczos2(float x) -@@ -63,15 +62,19 @@ vec2 weightY(float dx, float dy,float c, float std) +@@ -63,15 +63,15 @@ vec2 weightY(float dx, float dy,float c, float std) void main() { @@ -40,22 +41,18 @@ index 7074999..9e2122e 100644 + const int mode = OperationMode; + const float edgeThreshold = EdgeThreshold; + const float edgeSharpness = EdgeSharpness; -+ -+ vec2 full_texsize = textureSize(ps0, 0); -+ vec2 recp_texsize = 1.0 / full_texsize; -+ vec2 resize_factor = ViewportInfo[0].zw / full_texsize; vec4 color; if(mode == 1) - color.xyz = textureLod(ps0,in_TEXCOORD0.xy,0.0).xyz; -+ color.xyz = textureLod(ps0, in_TEXCOORD0.xy * resize_factor, 0.0).xyz; ++ color.xyz = textureLod(ps0, in_TEXCOORD0.xy, 0.0).xyz; else - color.xyzw = textureLod(ps0,in_TEXCOORD0.xy,0.0).xyzw; -+ color.xyzw = textureLod(ps0, in_TEXCOORD0.xy * resize_factor, 0.0).xyzw; ++ color.xyzw = textureLod(ps0, in_TEXCOORD0.xy, 0.0).xyzw; highp float xCenter; xCenter = abs(in_TEXCOORD0.x+-0.5); -@@ -82,21 +85,24 @@ void main() +@@ -82,21 +82,24 @@ void main() //if ( mode!=4 && xCenter*xCenter+yCenter*yCenter<=0.4 * 0.4) if ( mode!=4) { @@ -67,7 +64,7 @@ index 7074999..9e2122e 100644 - vec4 left = textureGather(ps0,coord, mode); + highp vec2 coord = imgCoordPixel * ViewportInfo[0].xy; + vec2 pl = imgCoord - imgCoordPixel; -+ vec4 left = textureGather(ps0, coord * resize_factor, mode); ++ vec4 left = textureGather(ps0, coord, mode); float edgeVote = abs(left.z - left.y) + abs(color[mode] - left.y) + abs(color[mode] - left.z) ; if(edgeVote > edgeThreshold) @@ -76,19 +73,19 @@ index 7074999..9e2122e 100644 - vec4 right = textureGather(ps0,coord + highp vec2(ViewportInfo[0].x, 0.0), mode); + highp vec2 IR_highp_vec2_0 = coord + vec2(ViewportInfo[0].x, 0.0); -+ vec4 right = textureGather(ps0, IR_highp_vec2_0 * resize_factor, mode); ++ vec4 right = textureGather(ps0, IR_highp_vec2_0, mode); vec4 upDown; - upDown.xy = textureGather(ps0,coord + highp vec2(0.0, -ViewportInfo[0].y),mode).wz; - upDown.zw = textureGather(ps0,coord+ highp vec2(0.0, ViewportInfo[0].y), mode).yx; + highp vec2 IR_highp_vec2_1 = coord + vec2(0.0, -ViewportInfo[0].y); -+ upDown.xy = textureGather(ps0, IR_highp_vec2_1 * resize_factor, mode).wz; ++ upDown.xy = textureGather(ps0, IR_highp_vec2_1, mode).wz; + highp vec2 IR_highp_vec2_2 = coord + vec2(0.0, ViewportInfo[0].y); -+ upDown.zw = textureGather(ps0, IR_highp_vec2_2 * resize_factor, mode).yx; ++ upDown.zw = textureGather(ps0, IR_highp_vec2_2, mode).yx; float mean = (left.y+left.z+right.x+right.w)*0.25; left = left - vec4(mean); diff --git a/sgsr/v1/include/glsl/sgsr1_shader_mobile_edge_direction.frag b/sgsr/v1/include/glsl/sgsr1_shader_mobile_edge_direction.frag -index d2df646..3e4f5cd 100644 +index d2df646..8b64497 100644 --- a/sgsr/v1/include/glsl/sgsr1_shader_mobile_edge_direction.frag +++ b/sgsr/v1/include/glsl/sgsr1_shader_mobile_edge_direction.frag @@ -1,4 +1,4 @@ @@ -97,7 +94,7 @@ index d2df646..3e4f5cd 100644 //============================================================================================================ // -@@ -40,17 +40,16 @@ precision highp int; +@@ -40,17 +40,17 @@ precision highp int; //////////////////////// #if defined(UseUniformBlock) @@ -106,6 +103,7 @@ index d2df646..3e4f5cd 100644 - highp vec4 ViewportInfo[1]; +layout( push_constant ) uniform constants { + highp vec4 ViewportInfo[1]; ++ highp vec2 ResizeFactor; }; -layout(set = 0, binding = 1) uniform mediump sampler2D ps0; +layout(set = 0, binding = 0) uniform mediump sampler2D ps0; @@ -119,32 +117,14 @@ index d2df646..3e4f5cd 100644 layout(location=0) out vec4 out_Target0; float fastLanczos2(float x) -@@ -98,11 +97,15 @@ vec2 edgeDirection(vec4 left, vec4 right) - - void main() - { -+ vec2 full_texsize = textureSize(ps0, 0); -+ vec2 recp_texsize = 1.0 / full_texsize; -+ vec2 resize_factor = ViewportInfo[0].zw / full_texsize; -+ - vec4 color; - if(OperationMode == 1) -- color.xyz = textureLod(ps0,in_TEXCOORD0.xy,0.0).xyz; -+ color.xyz = textureLod(ps0,in_TEXCOORD0.xy * resize_factor,0.0).xyz; - else -- color.xyzw = textureLod(ps0,in_TEXCOORD0.xy,0.0).xyzw; -+ color.xyzw = textureLod(ps0,in_TEXCOORD0.xy * resize_factor,0.0).xyzw; - - highp float xCenter; - xCenter = abs(in_TEXCOORD0.x+-0.5); -@@ -116,18 +119,21 @@ void main() +@@ -116,18 +116,21 @@ void main() highp vec2 imgCoord = ((in_TEXCOORD0.xy*ViewportInfo[0].zw)+vec2(-0.5,0.5)); highp vec2 imgCoordPixel = floor(imgCoord); highp vec2 coord = (imgCoordPixel*ViewportInfo[0].xy); - vec2 pl = (imgCoord+(-imgCoordPixel)); - vec4 left = textureGather(ps0,coord, OperationMode); + vec2 pl = imgCoord - imgCoordPixel; -+ vec4 left = textureGather(ps0, coord * resize_factor, OperationMode); ++ vec4 left = textureGather(ps0, coord, OperationMode); float edgeVote = abs(left.z - left.y) + abs(color[OperationMode] - left.y) + abs(color[OperationMode] - left.z) ; if(edgeVote > EdgeThreshold) @@ -153,14 +133,14 @@ index d2df646..3e4f5cd 100644 - vec4 right = textureGather(ps0,coord + highp vec2(ViewportInfo[0].x, 0.0), OperationMode); + highp vec2 IR_highp_vec2_0 = coord + vec2(ViewportInfo[0].x, 0.0); -+ vec4 right = textureGather(ps0, IR_highp_vec2_0 * resize_factor, OperationMode); ++ vec4 right = textureGather(ps0, IR_highp_vec2_0, OperationMode); vec4 upDown; - upDown.xy = textureGather(ps0,coord + highp vec2(0.0, -ViewportInfo[0].y),OperationMode).wz; - upDown.zw = textureGather(ps0,coord+ highp vec2(0.0, ViewportInfo[0].y), OperationMode).yx; + highp vec2 IR_highp_vec2_1 = coord + vec2(0.0, -ViewportInfo[0].y); -+ upDown.xy = textureGather(ps0, IR_highp_vec2_1 * resize_factor, OperationMode).wz; ++ upDown.xy = textureGather(ps0, IR_highp_vec2_1, OperationMode).wz; + highp vec2 IR_highp_vec2_2 = coord + vec2(0.0, ViewportInfo[0].y); -+ upDown.zw = textureGather(ps0, IR_highp_vec2_2 * resize_factor, OperationMode).yx; ++ upDown.zw = textureGather(ps0, IR_highp_vec2_2, OperationMode).yx; float mean = (left.y+left.z+right.x+right.w)*0.25; left = left - vec4(mean); diff --git a/src/video_core/host_shaders/sgsr1_shader.vert b/src/video_core/host_shaders/sgsr1_shader.vert index 00649312fb..1a07242fd6 100644 --- a/src/video_core/host_shaders/sgsr1_shader.vert +++ b/src/video_core/host_shaders/sgsr1_shader.vert @@ -3,11 +3,15 @@ #version 450 +layout( push_constant ) uniform constants { + highp vec4 ViewportInfo[1]; + highp vec2 ResizeFactor; +}; layout(location = 0) out highp vec2 texcoord; void main() { float x = float((gl_VertexIndex & 1) << 2); float y = float((gl_VertexIndex & 2) << 1); gl_Position = vec4(x - 1.0f, y - 1.0f, 0.0, 1.0f); - texcoord = vec2(x, y) / 2.0; + texcoord = vec2(x, y) * ResizeFactor * 0.5; } diff --git a/src/video_core/renderer_vulkan/present/sgsr.cpp b/src/video_core/renderer_vulkan/present/sgsr.cpp index 1991684920..9442d81630 100644 --- a/src/video_core/renderer_vulkan/present/sgsr.cpp +++ b/src/video_core/renderer_vulkan/present/sgsr.cpp @@ -17,7 +17,7 @@ namespace Vulkan { -using PushConstants = std::array; +using PushConstants = std::array; SGSR::SGSR(const Device& device, MemoryAllocator& memory_allocator, size_t image_count, VkExtent2D extent, bool edge_dir) : m_device{device}, m_memory_allocator{memory_allocator} @@ -110,6 +110,8 @@ VkImageView SGSR::Draw(Scheduler& scheduler, size_t image_index, VkImage source_ viewport_con[1] = std::bit_cast(1.f / viewport_height); viewport_con[2] = std::bit_cast(viewport_width); viewport_con[3] = std::bit_cast(viewport_height); + viewport_con[4] = std::bit_cast(viewport_width / input_image_width); + viewport_con[5] = std::bit_cast(viewport_height / input_image_height); UploadImages(scheduler); UpdateDescriptorSets(source_image_view, image_index);