Browse Source

fixup sgsr for realsies

lizzie/sgsr
lizzie 2 weeks ago
parent
commit
c9669971f5
  1. 82
      .patch/sgsr/0001-fix-glsl.patch
  2. 97
      .patch/snapdragon_gsr/0001-fix-glsl.patch
  3. 2
      CMakeLists.txt
  4. 6
      src/video_core/host_shaders/CMakeLists.txt
  5. 10
      src/video_core/renderer_vulkan/present/sgsr.cpp

82
.patch/sgsr/0001-fix-glsl.patch

@ -0,0 +1,82 @@
diff --git a/sgsr/v1/include/glsl/sgsr1_shader_mobile.frag b/sgsr/v1/include/glsl/sgsr1_shader_mobile.frag
index 7074999..b465126 100644
--- a/sgsr/v1/include/glsl/sgsr1_shader_mobile.frag
+++ b/sgsr/v1/include/glsl/sgsr1_shader_mobile.frag
@@ -1,4 +1,4 @@
-#version 300 es
+#version 460 core
//============================================================================================================
//
@@ -34,11 +34,10 @@ precision highp int;
////////////////////////
#if defined(UseUniformBlock)
-layout (set=0, binding = 0) uniform UniformBlock
-{
- highp vec4 ViewportInfo[1];
+layout( push_constant ) uniform constants {
+ highp vec4 ViewportInfo[1];
};
-layout(set = 0, binding = 1) uniform mediump sampler2D ps0;
+layout(set = 0, binding = 0) uniform mediump sampler2D ps0;
#else
uniform highp vec4 ViewportInfo[1];
uniform mediump sampler2D ps0;
@@ -63,15 +62,19 @@ vec2 weightY(float dx, float dy,float c, float std)
void main()
{
- int mode = OperationMode;
- float edgeThreshold = EdgeThreshold;
- float edgeSharpness = EdgeSharpness;
+ 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;
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);
@@ -82,21 +85,24 @@ void main()
//if ( mode!=4 && xCenter*xCenter+yCenter*yCenter<=0.4 * 0.4)
if ( mode!=4)
{
- highp vec2 imgCoord = ((in_TEXCOORD0.xy*ViewportInfo[0].zw)+vec2(-0.5,0.5));
+ 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, mode);
+ highp vec2 coord = imgCoordPixel * ViewportInfo[0].xy;
+ vec2 pl = imgCoord - imgCoordPixel;
+ vec4 left = textureGather(ps0, coord * resize_factor, mode);
float edgeVote = abs(left.z - left.y) + abs(color[mode] - left.y) + abs(color[mode] - left.z) ;
if(edgeVote > edgeThreshold)
{
coord.x += ViewportInfo[0].x;
- 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 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;
+ 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;
float mean = (left.y+left.z+right.x+right.w)*0.25;
left = left - vec4(mean);

97
.patch/snapdragon_gsr/0001-fix-glsl.patch

@ -1,97 +0,0 @@
diff --git a/sgsr/v1/include/glsl/sgsr1_shader_mobile.frag b/sgsr/v1/include/glsl/sgsr1_shader_mobile.frag
index 7074999..cb1eea3 100644
--- a/sgsr/v1/include/glsl/sgsr1_shader_mobile.frag
+++ b/sgsr/v1/include/glsl/sgsr1_shader_mobile.frag
@@ -1,4 +1,4 @@
-#version 300 es
+#version 460 core
//============================================================================================================
//
@@ -34,11 +34,10 @@ precision highp int;
////////////////////////
#if defined(UseUniformBlock)
-layout (set=0, binding = 0) uniform UniformBlock
-{
- highp vec4 ViewportInfo[1];
+layout( push_constant ) uniform constants {
+ highp vec4 ViewportInfo[1];
};
-layout(set = 0, binding = 1) uniform mediump sampler2D ps0;
+layout(set = 0, binding = 0) uniform mediump sampler2D ps0;
#else
uniform highp vec4 ViewportInfo[1];
uniform mediump sampler2D ps0;
@@ -63,9 +62,9 @@ vec2 weightY(float dx, float dy,float c, float std)
void main()
{
- int mode = OperationMode;
- float edgeThreshold = EdgeThreshold;
- float edgeSharpness = EdgeSharpness;
+ const int mode = OperationMode;
+ const float edgeThreshold = EdgeThreshold;
+ const float edgeSharpness = EdgeSharpness;
vec4 color;
if(mode == 1)
@@ -93,10 +92,13 @@ void main()
{
coord.x += ViewportInfo[0].x;
- vec4 right = textureGather(ps0,coord + highp vec2(ViewportInfo[0].x, 0.0), mode);
+ highp vec2 IR_highp_vec2_0 = vec2(ViewportInfo[0].x, 0.0);
+ vec4 right = textureGather(ps0,coord + 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 = vec2(0.0, -ViewportInfo[0].y);
+ upDown.xy = textureGather(ps0,coord + IR_highp_vec2_1,mode).wz;
+ highp vec2 IR_highp_vec2_2 = vec2(0.0, ViewportInfo[0].y);
+ upDown.zw = textureGather(ps0,coord+ 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..95d09cf 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 @@
-#version 300 es
+#version 460 core
//============================================================================================================
//
@@ -40,11 +40,10 @@ precision highp int;
////////////////////////
#if defined(UseUniformBlock)
-layout (set=0, binding = 0) uniform UniformBlock
-{
- highp vec4 ViewportInfo[1];
+layout( push_constant ) uniform constants {
+ highp vec4 ViewportInfo[1];
};
-layout(set = 0, binding = 1) uniform mediump sampler2D ps0;
+layout(set = 0, binding = 0) uniform mediump sampler2D ps0;
#else
uniform highp vec4 ViewportInfo[1];
uniform mediump sampler2D ps0;
@@ -124,10 +123,13 @@ void main()
{
coord.x += ViewportInfo[0].x;
- vec4 right = textureGather(ps0,coord + highp vec2(ViewportInfo[0].x, 0.0), OperationMode);
+ highp vec2 IR_highp_vec2_0 = vec2(ViewportInfo[0].x, 0.0);
+ vec4 right = textureGather(ps0,coord + 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 = vec2(0.0, -ViewportInfo[0].y);
+ upDown.xy = textureGather(ps0,coord + IR_highp_vec2_1,OperationMode).wz;
+ highp vec2 IR_highp_vec2_2 = vec2(0.0, ViewportInfo[0].y);
+ upDown.zw = textureGather(ps0,coord+ IR_highp_vec2_2, OperationMode).yx;
float mean = (left.y+left.z+right.x+right.w)*0.25;
left = left - vec4(mean);

2
CMakeLists.txt

@ -270,7 +270,7 @@ endif()
cmake_dependent_option(YUZU_USE_BUNDLED_OPENSSL "Download bundled OpenSSL build" ${DEFAULT_YUZU_USE_BUNDLED_OPENSSL} "ENABLE_OPENSSL" OFF)
AddJsonPackage(snapdragon_gsr)
AddJsonPackage(sgsr)
# TODO(crueter): CPM this
if (ANDROID AND YUZU_DOWNLOAD_ANDROID_VVL)

6
src/video_core/host_shaders/CMakeLists.txt

@ -79,8 +79,8 @@ set(SHADER_FILES
# Snapdragon Game Super Resolution
${CMAKE_CURRENT_SOURCE_DIR}/sgsr1_shader.vert
${snapdragon_gsr_SOURCE_DIR}/sgsr/v1/include/glsl/sgsr1_shader_mobile.frag
${snapdragon_gsr_SOURCE_DIR}/sgsr/v1/include/glsl/sgsr1_shader_mobile_edge_direction.frag
${sgsr_SOURCE_DIR}/sgsr/v1/include/glsl/sgsr1_shader_mobile.frag
${sgsr_SOURCE_DIR}/sgsr/v1/include/glsl/sgsr1_shader_mobile_edge_direction.frag
)
if (PLATFORM_HAIKU)
@ -217,4 +217,4 @@ add_custom_target(host_shaders
SOURCES
${SHADER_SOURCES}
)
#add_dependencies(host_shaders snapdragon_gsr::snapdragon_gsr)
#add_dependencies(host_shaders sgsr::sgsr)

10
src/video_core/renderer_vulkan/present/sgsr.cpp

@ -116,11 +116,13 @@ VkImageView SGSR::Draw(Scheduler& scheduler, size_t image_index, VkImage source_
const f32 viewport_width = (crop_rect.right - crop_rect.left) * input_image_width;
const f32 viewport_height = (crop_rect.bottom - crop_rect.top) * input_image_height;
// p = (tex * viewport) / input = [0,n] (normalized texcoords)
// p * input = [0,1024], [0,768]
PushConstants viewport_con{};
viewport_con[0] = std::bit_cast<u32>(1.f / output_image_width);
viewport_con[1] = std::bit_cast<u32>(1.f / output_image_height);
viewport_con[2] = std::bit_cast<u32>(output_image_width);
viewport_con[3] = std::bit_cast<u32>(output_image_height);
viewport_con[0] = std::bit_cast<u32>(1.f / viewport_width);
viewport_con[1] = std::bit_cast<u32>(1.f / viewport_height);
viewport_con[2] = std::bit_cast<u32>(viewport_width);
viewport_con[3] = std::bit_cast<u32>(viewport_height);
UploadImages(scheduler);
UpdateDescriptorSets(source_image_view, image_index);

Loading…
Cancel
Save