VERY experimental Nintendo Switch 2 emulator
C++
[vulkan, sgsr] Adjustments to SGSR implementation (#4293)
Samuel86ba79b1ba79
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SettingsItem.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SettingsItem.ktindex 0ca31062b3..c05539c306 100644--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SettingsItem.kt+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/view/SettingsItem.kt@@ -624,6 +624,7 @@ abstract class SettingsItem(IntSetting.FSR_SHARPENING_SLIDER,titleId = R.string.fsr_sharpness,descriptionId = R.string.fsr_sharpness_description,+ max = 200,units = "%"))diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.ktindex 5b93c88161..016ac57356 100644--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt@@ -1182,7 +1182,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {container,IntSetting.FSR_SHARPENING_SLIDER,minValue = 0,- maxValue = 100,+ maxValue = 200,units = "%")}diff --git a/src/video_core/host_shaders/sgsr1_shader.vert b/src/video_core/host_shaders/sgsr1_shader.vertindex 0d2a935a9d..e995997060 100644--- a/src/video_core/host_shaders/sgsr1_shader.vert+++ b/src/video_core/host_shaders/sgsr1_shader.vert@@ -7,6 +7,7 @@ layout(push_constant) uniform constants {vec2 scale;vec2 size;vec2 resize_factor;+ vec2 crop_offset;float edge_sharpness;};layout(location = 0) out highp vec2 texcoord;@@ -15,5 +16,5 @@ 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) * vec4(sign(resize_factor), 1.f, 1.f);- texcoord = vec2(x, y) * abs(resize_factor) * 0.5;+ texcoord = crop_offset + vec2(x, y) * abs(resize_factor) * 0.5;}diff --git a/src/video_core/host_shaders/sgsr1_shader_mobile.frag b/src/video_core/host_shaders/sgsr1_shader_mobile.fragindex 2e62d60af3..3453ca2cae 100644--- a/src/video_core/host_shaders/sgsr1_shader_mobile.frag+++ b/src/video_core/host_shaders/sgsr1_shader_mobile.frag@@ -14,6 +14,7 @@ layout(push_constant) uniform constants {vec2 scale;vec2 size;vec2 resize_factor;+ vec2 crop_offset;float edge_sharpness;};layout(set = 0, binding = 0) uniform sampler2D sampler0;diff --git a/src/video_core/host_shaders/sgsr1_shader_mobile_edge_direction.frag b/src/video_core/host_shaders/sgsr1_shader_mobile_edge_direction.fragindex 10a8ff8e00..66417e9c46 100644--- a/src/video_core/host_shaders/sgsr1_shader_mobile_edge_direction.frag+++ b/src/video_core/host_shaders/sgsr1_shader_mobile_edge_direction.frag@@ -13,6 +13,7 @@layout( push_constant ) uniform constants {vec4 ViewportInfo[1];vec2 ResizeFactor;+ vec2 CropOffset;float EdgeSharpness;};layout(set = 0, binding = 0) uniform sampler2D ps0;diff --git a/src/video_core/renderer_vulkan/present/sgsr.cpp b/src/video_core/renderer_vulkan/present/sgsr.cppindex 5fc746458d..fa37225e43 100644--- a/src/video_core/renderer_vulkan/present/sgsr.cpp+++ b/src/video_core/renderer_vulkan/present/sgsr.cpp@@ -1,6 +1,8 @@// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project// SPDX-License-Identifier: GPL-3.0-or-later+#include <algorithm>+#include "common/common_types.h"#include "common/div_ceil.h"#include "common/settings.h"@@ -17,7 +19,7 @@namespace Vulkan {-using PushConstants = std::array<u32, 4 + 2 + 1>;+using PushConstants = std::array<u32, 4 + 2 + 2 + 1>;SGSR::SGSR(const Device& device, MemoryAllocator& memory_allocator, size_t image_count, VkExtent2D extent, bool edge_dir): m_memory_allocator{memory_allocator}@@ -100,26 +102,28 @@ VkImageView SGSR::Draw(const Device& device, Scheduler& scheduler, size_t image_const f32 input_image_width = f32(input_image_extent.width);const f32 input_image_height = f32(input_image_extent.height);- 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;- // expected [0, 2]- const f32 sharpening = f32(Settings::values.fsr_sharpening_slider.GetValue()) / 100.0f;+ const f32 crop_width = (crop_rect.right - crop_rect.left) * input_image_width;+ const f32 crop_height = (crop_rect.bottom - crop_rect.top) * input_image_height;+ static constexpr f32 EDGE_SHARPNESS_MAX = 2.0f;+ const f32 edge_sharpness =+ EDGE_SHARPNESS_MAX - f32(Settings::values.fsr_sharpening_slider.GetValue()) / 200.0f;- // p = (tex * viewport) / input = [0,n] (normalized texcoords)- // p * input = [0,1024], [0,768]// layout( push_constant ) uniform constants {// highp vec4 ViewportInfo[1];// highp vec2 ResizeFactor;+ // highp vec2 CropOffset;// highp float EdgeSharpness;// };PushConstants viewport_con{};- viewport_con[0] = std::bit_cast<u32>(std::abs(1.f / viewport_width));- viewport_con[1] = std::bit_cast<u32>(std::abs(1.f / viewport_height));- viewport_con[2] = std::bit_cast<u32>(std::abs(viewport_width));- viewport_con[3] = std::bit_cast<u32>(std::abs(viewport_height));- viewport_con[4] = std::bit_cast<u32>(viewport_width / input_image_width);- viewport_con[5] = std::bit_cast<u32>(viewport_height / input_image_height);- viewport_con[6] = std::bit_cast<u32>(sharpening);+ viewport_con[0] = std::bit_cast<u32>(1.f / input_image_width);+ viewport_con[1] = std::bit_cast<u32>(1.f / input_image_height);+ viewport_con[2] = std::bit_cast<u32>(input_image_width);+ viewport_con[3] = std::bit_cast<u32>(input_image_height);+ viewport_con[4] = std::bit_cast<u32>(crop_width / input_image_width);+ viewport_con[5] = std::bit_cast<u32>(crop_height / input_image_height);+ viewport_con[6] = std::bit_cast<u32>((std::min)(crop_rect.left, crop_rect.right));+ viewport_con[7] = std::bit_cast<u32>((std::min)(crop_rect.top, crop_rect.bottom));+ viewport_con[8] = std::bit_cast<u32>(edge_sharpness);UploadImages(device, scheduler);UpdateDescriptorSets(device, source_image_view, image_index);