Add SGSR edge variant

This commit is contained in:
lizzie
2026-01-24 08:46:36 +00:00
committed by Caio Oliveira
parent ecb22c1bb0
commit 95fff10d3a
13 changed files with 97 additions and 33 deletions

View File

@@ -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..b465126 100644
index 7074999..9e2122e 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..b465126 100644
//============================================================================================================
//
@@ -34,11 +34,10 @@ precision highp int;
@@ -34,17 +34,16 @@ precision highp int;
////////////////////////
#if defined(UseUniformBlock)
@@ -23,6 +23,13 @@ index 7074999..b465126 100644
#else
uniform highp vec4 ViewportInfo[1];
uniform mediump sampler2D ps0;
#endif
-layout(location=0) in highp vec4 in_TEXCOORD0;
+layout(location=0) in highp vec2 in_TEXCOORD0;
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)
void main()
@@ -80,3 +87,67 @@ index 7074999..b465126 100644
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..91a8d4d 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
//============================================================================================================
//
@@ -50,7 +50,7 @@ uniform highp vec4 ViewportInfo[1];
uniform mediump sampler2D ps0;
#endif
-layout(location=0) in highp vec4 in_TEXCOORD0;
+layout(location=0) in highp vec2 in_TEXCOORD0;
layout(location=0) out vec4 out_Target0;
float fastLanczos2(float x)
@@ -98,11 +98,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 +120,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);
float edgeVote = abs(left.z - left.y) + abs(color[OperationMode] - left.y) + abs(color[OperationMode] - left.z) ;
if(edgeVote > EdgeThreshold)
{
coord.x += ViewportInfo[0].x;
- 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 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;
+ 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;
float mean = (left.y+left.z+right.x+right.w)*0.25;
left = left - vec4(mean);

View File

@@ -45,6 +45,7 @@ Various graphical filters exist - each of them aimed at a specific target/image
- **SGSR**: Uses Snapdragon Studios Game Super Resolution to enhance image quality (similar to FSR, but for Adreno devices).
- **Pros**: Optimized for Adreno devices.
- **Cons**: Doesn't play nicely with non-Adreno devices.
- **SGSR Edge**: Almost the same pipeline as SGSR, but with improved edge detection.
### Anisotropy values

View File

@@ -254,6 +254,7 @@
<item>@string/scaling_filter_mitchell</item>
<item>@string/scaling_filter_spline1</item>
<item>@string/scaling_filter_sgsr</item>
<item>@string/scaling_filter_sgsr_edge</item>
</string-array>
<integer-array name="rendererScalingFilterValues">

View File

@@ -1069,7 +1069,8 @@
<string name="scaling_filter_bspline" translatable="false">B-Spline</string>
<string name="scaling_filter_mitchell" translatable="false">Mitchell</string>
<string name="scaling_filter_mmpx" translatable="false">MMPX</string>
<string name="scaling_filter_sgsr" translatable="false">Snapdragon Game Super Resolution</string>
<string name="scaling_filter_sgsr" translatable="false">Snapdragon GSR</string>
<string name="scaling_filter_sgsr_edge" translatable="false">Snapdragon GSR EdgeDir</string>
<!-- Anti-Aliasing -->
<string name="anti_aliasing_none">None</string>

View File

@@ -142,7 +142,7 @@ ENUM(ConfirmStop, Ask_Always, Ask_Based_On_Game, Ask_Never);
ENUM(FullscreenMode, Borderless, Exclusive);
ENUM(NvdecEmulation, Off, Cpu, Gpu);
ENUM(ResolutionSetup, Res1_4X, Res1_2X, Res3_4X, Res1X, Res5_4X, Res3_2X, Res2X, Res3X, Res4X, Res5X, Res6X, Res7X, Res8X);
ENUM(ScalingFilter, NearestNeighbor, Bilinear, Bicubic, Gaussian, Lanczos, ScaleForce, Fsr, Area, ZeroTangent, BSpline, Mitchell, Spline1, Mmpx, Sgsr, MaxEnum);
ENUM(ScalingFilter, NearestNeighbor, Bilinear, Bicubic, Gaussian, Lanczos, ScaleForce, Fsr, Area, ZeroTangent, BSpline, Mitchell, Spline1, Mmpx, Sgsr, SgsrEdge, MaxEnum);
ENUM(AntiAliasing, None, Fxaa, Smaa, MaxEnum);
ENUM(AspectRatio, R16_9, R4_3, R21_9, R16_10, Stretch);
ENUM(ConsoleMode, Handheld, Docked);

View File

@@ -577,6 +577,7 @@ std::unique_ptr<ComboboxTranslationMap> ComboboxEnumeration(QObject* parent)
PAIR(ScalingFilter, Mitchell, tr("Mitchell")),
PAIR(ScalingFilter, Spline1, tr("Spline-1")),
PAIR(ScalingFilter, Sgsr, tr("Snapdragon Game Super Resolution")),
PAIR(ScalingFilter, SgsrEdge, tr("Snapdragon Game Super Resolution EdgeDir")),
}});
translations->insert({Settings::EnumMetadata<Settings::AntiAliasing>::Index(),
{

View File

@@ -54,6 +54,7 @@ static const std::map<Settings::ScalingFilter, QString> scaling_filter_texts_map
{Settings::ScalingFilter::Area, QStringLiteral(QT_TRANSLATE_NOOP("MainWindow", "Area"))},
{Settings::ScalingFilter::Mmpx, QStringLiteral(QT_TRANSLATE_NOOP("MainWindow", "MMPX"))},
{Settings::ScalingFilter::Sgsr, QStringLiteral(QT_TRANSLATE_NOOP("MainWindow", "SGSR"))},
{Settings::ScalingFilter::SgsrEdge, QStringLiteral(QT_TRANSLATE_NOOP("MainWindow", "SGSR EdgeDir"))},
};
static const std::map<Settings::ConsoleMode, QString> use_docked_mode_texts_map = {

View File

@@ -3,11 +3,11 @@
#version 450
layout(location = 0) out highp vec4 texcoord;
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 = vec4(x, y, 0.f, 0.f) / 2.0;
texcoord = vec2(x, y) / 2.0;
}

View File

@@ -116,6 +116,7 @@ void BlitScreen::CreateWindowAdapt() {
break;
case Settings::ScalingFilter::Fsr:
case Settings::ScalingFilter::Sgsr:
case Settings::ScalingFilter::SgsrEdge:
case Settings::ScalingFilter::Bilinear:
default:
window_adapt = MakeBilinear(device);

View File

@@ -66,7 +66,9 @@ Layer::Layer(const Device& device_, MemoryAllocator& memory_allocator_, Schedule
if (filters.get_scaling_filter() == Settings::ScalingFilter::Fsr) {
sr_filter.emplace<FSR>(device, memory_allocator, image_count, output_size);
} else if (filters.get_scaling_filter() == Settings::ScalingFilter::Sgsr) {
sr_filter.emplace<SGSR>(device, memory_allocator, image_count, output_size);
sr_filter.emplace<SGSR>(device, memory_allocator, image_count, output_size, false);
} else if (filters.get_scaling_filter() == Settings::ScalingFilter::SgsrEdge) {
sr_filter.emplace<SGSR>(device, memory_allocator, image_count, output_size, true);
}
}

View File

@@ -19,29 +19,27 @@ namespace Vulkan {
using PushConstants = std::array<u32, 4>;
SGSR::SGSR(const Device& device, MemoryAllocator& memory_allocator, size_t image_count, VkExtent2D extent)
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}
, m_image_count{image_count}, m_extent{extent}
, m_edge_dir{edge_dir}
{
// Not finished yet initializing at ctor time?
m_dynamic_images.resize(m_image_count);
for (auto& images : m_dynamic_images) {
images.images[0] = CreateWrappedImage(m_memory_allocator, m_extent, VK_FORMAT_R16G16B16A16_SFLOAT);
images.images[1] = CreateWrappedImage(m_memory_allocator, m_extent, VK_FORMAT_R16G16B16A16_SFLOAT);
images.image_views[0] = CreateWrappedImageView(m_device, images.images[0], VK_FORMAT_R16G16B16A16_SFLOAT);
images.image_views[1] = CreateWrappedImageView(m_device, images.images[1], VK_FORMAT_R16G16B16A16_SFLOAT);
}
m_renderpass = CreateWrappedRenderPass(m_device, VK_FORMAT_R16G16B16A16_SFLOAT);
for (auto& images : m_dynamic_images) {
for (auto& images : m_dynamic_images)
images.framebuffers[0] = CreateWrappedFramebuffer(m_device, m_renderpass, images.image_views[0], m_extent);
images.framebuffers[1] = CreateWrappedFramebuffer(m_device, m_renderpass, images.image_views[1], m_extent);
}
m_sampler = CreateBilinearSampler(m_device);
m_vert_shader = BuildShader(m_device, SGSR1_SHADER_VERT_SPV);
m_stage_shader[0] = BuildShader(m_device, SGSR1_SHADER_MOBILE_FRAG_SPV);
m_stage_shader[1] = BuildShader(m_device, SGSR1_SHADER_MOBILE_EDGE_DIRECTION_FRAG_SPV);
m_stage_shader[0] = m_edge_dir
? BuildShader(m_device, SGSR1_SHADER_MOBILE_EDGE_DIRECTION_FRAG_SPV)
: BuildShader(m_device, SGSR1_SHADER_MOBILE_FRAG_SPV);
// 2 descriptors, 2 descriptor sets per invocation
m_descriptor_pool = CreateWrappedDescriptorPool(m_device, 2 * m_image_count, 2 * m_image_count);
m_descriptor_set_layout = CreateWrappedDescriptorSetLayout(m_device, {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER});
@@ -66,14 +64,13 @@ SGSR::SGSR(const Device& device, MemoryAllocator& memory_allocator, size_t image
};
m_pipeline_layout = m_device.GetLogical().CreatePipelineLayout(ci);
m_stage_pipeline[0] = CreateWrappedPipeline(m_device, m_renderpass, m_pipeline_layout, std::tie(m_vert_shader, m_stage_shader[0]));
m_stage_pipeline[1] = CreateWrappedPipeline(m_device, m_renderpass, m_pipeline_layout, std::tie(m_vert_shader, m_stage_shader[1]));
}
void SGSR::UpdateDescriptorSets(VkImageView image_view, size_t image_index) {
Images& images = m_dynamic_images[image_index];
std::vector<VkDescriptorImageInfo> image_infos;
std::vector<VkWriteDescriptorSet> updates;
image_infos.reserve(2);
image_infos.reserve(1);
updates.push_back(CreateWriteDescriptorSet(image_infos, *m_sampler, image_view, images.descriptor_sets[0], 0));
updates.push_back(CreateWriteDescriptorSet(image_infos, *m_sampler, *images.image_views[0], images.descriptor_sets[1], 0));
m_device.GetLogical().UpdateDescriptorSets(updates, {});
@@ -84,7 +81,6 @@ void SGSR::UploadImages(Scheduler& scheduler) {
scheduler.Record([&](vk::CommandBuffer cmdbuf) {
for (auto& image : m_dynamic_images) {
ClearColorImage(cmdbuf, *image.images[0]);
ClearColorImage(cmdbuf, *image.images[1]);
}
});
scheduler.Finish();
@@ -95,13 +91,9 @@ void SGSR::UploadImages(Scheduler& scheduler) {
VkImageView SGSR::Draw(Scheduler& scheduler, size_t image_index, VkImage source_image, VkImageView source_image_view, VkExtent2D input_image_extent, const Common::Rectangle<f32>& crop_rect) {
Images& images = m_dynamic_images[image_index];
auto const stage0_image = *images.images[0];
//auto const stage1_image = *images.images[1];
auto const stage0_descriptor_set = images.descriptor_sets[0];
//auto const stage1_descriptor_set = images.descriptor_sets[1];
auto const stage0_framebuffer = *images.framebuffers[0];
//auto const stage1_framebuffer = *images.framebuffers[1];
auto const stage0_pipeline = *m_stage_pipeline[0];
//auto const stage1_pipeline = *m_stage_pipeline[1];
VkPipelineLayout pipeline_layout = *m_pipeline_layout;
VkRenderPass renderpass = *m_renderpass;
@@ -138,16 +130,7 @@ VkImageView SGSR::Draw(Scheduler& scheduler, size_t image_index, VkImage source_
cmdbuf.Draw(3, 1, 0, 0);
cmdbuf.EndRenderPass();
TransitionImageLayout(cmdbuf, stage0_image, VK_IMAGE_LAYOUT_GENERAL);
// TransitionImageLayout(cmdbuf, stage1_image, VK_IMAGE_LAYOUT_GENERAL);
// BeginRenderPass(cmdbuf, renderpass, stage1_framebuffer, extent);
// cmdbuf.BindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, stage1_pipeline);
// cmdbuf.BindDescriptorSets(VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, stage1_descriptor_set, {});
// cmdbuf.PushConstants(pipeline_layout, VK_SHADER_STAGE_FRAGMENT_BIT, viewport_con);
// cmdbuf.Draw(3, 1, 0, 0);
// cmdbuf.EndRenderPass();
// TransitionImageLayout(cmdbuf, stage1_image, VK_IMAGE_LAYOUT_GENERAL);
});
//return *images.image_views[1];
return *images.image_views[0];
}

View File

@@ -14,8 +14,8 @@ class Scheduler;
class SGSR {
public:
static constexpr size_t SGSR_STAGE_COUNT = 2;
explicit SGSR(const Device& device, MemoryAllocator& memory_allocator, size_t image_count, VkExtent2D extent);
static constexpr size_t SGSR_STAGE_COUNT = 1;
explicit SGSR(const Device& device, MemoryAllocator& memory_allocator, size_t image_count, VkExtent2D extent, bool edge_dir);
VkImageView Draw(Scheduler& scheduler, size_t image_index, VkImage source_image, VkImageView source_image_view, VkExtent2D input_image_extent, const Common::Rectangle<f32>& crop_rect);
private:
void Initialize();
@@ -44,6 +44,7 @@ private:
};
std::vector<Images> m_dynamic_images;
bool m_images_ready{};
bool m_edge_dir{};
};
} // namespace Vulkan

View File

@@ -73,6 +73,7 @@ void BlitScreen::SetWindowAdaptPass() {
break;
case Settings::ScalingFilter::Fsr:
case Settings::ScalingFilter::Sgsr:
case Settings::ScalingFilter::SgsrEdge:
case Settings::ScalingFilter::Bilinear:
default:
window_adapt = MakeBilinear(device, swapchain_view_format);