mirror of
https://git.eden-emu.dev/archive/citron
synced 2026-04-18 18:50:50 -04:00
feat: Add FSR 2.0 scaling filter option
- Add FSR2 to ScalingFilter enum alongside existing FSR - Implement FSR2 classes for both Vulkan and OpenGL renderers - Add fsr2_quality_mode setting with 4 quality levels (Quality, Balanced, Performance, Ultra Performance) - Integrate FSR2 into present pipeline for both renderers - Add UI support for FSR2 option in scaling filter dropdown - Add FSR2 quality mode setting with dropdown selection - Update translations and Android strings for new options - Default to Performance mode for optimal balance This provides users with FSR 2.0 as a scaling option, offering different quality/performance characteristics compared to FSR 1.0. The implementation uses quality-based sharpening values and integrates seamlessly with the existing rendering pipeline. Signed-off-by: Zephyron <zephyron@citron-emu.org>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-FileCopyrightText: Copyright 2025 citron Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "common/settings.h"
|
||||
@@ -87,6 +88,7 @@ void BlitScreen::CreateWindowAdapt() {
|
||||
window_adapt = MakeScaleForce(device);
|
||||
break;
|
||||
case Settings::ScalingFilter::Fsr:
|
||||
case Settings::ScalingFilter::Fsr2:
|
||||
case Settings::ScalingFilter::Bilinear:
|
||||
default:
|
||||
window_adapt = MakeBilinear(device);
|
||||
|
||||
109
src/video_core/renderer_opengl/present/fsr2.cpp
Normal file
109
src/video_core/renderer_opengl/present/fsr2.cpp
Normal file
@@ -0,0 +1,109 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2025 citron Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "common/settings.h"
|
||||
#include "video_core/fsr.h"
|
||||
#include "video_core/host_shaders/ffx_a_h.h"
|
||||
#include "video_core/host_shaders/ffx_fsr1_h.h"
|
||||
#include "video_core/host_shaders/full_screen_triangle_vert.h"
|
||||
#include "video_core/host_shaders/opengl_fidelityfx_fsr_easu_frag.h"
|
||||
#include "video_core/host_shaders/opengl_fidelityfx_fsr_frag.h"
|
||||
#include "video_core/host_shaders/opengl_fidelityfx_fsr_rcas_frag.h"
|
||||
#include "video_core/renderer_opengl/gl_shader_manager.h"
|
||||
#include "video_core/renderer_opengl/gl_shader_util.h"
|
||||
#include "video_core/renderer_opengl/present/fsr2.h"
|
||||
#include "video_core/renderer_opengl/present/util.h"
|
||||
|
||||
namespace OpenGL {
|
||||
using namespace FSR;
|
||||
|
||||
using FsrConstants = std::array<u32, 4 * 4>;
|
||||
|
||||
FSR2::FSR2(u32 output_width_, u32 output_height_) : width(output_width_), height(output_height_) {
|
||||
std::string fsr_source{HostShaders::OPENGL_FIDELITYFX_FSR_FRAG};
|
||||
ReplaceInclude(fsr_source, "ffx_a.h", HostShaders::FFX_A_H);
|
||||
ReplaceInclude(fsr_source, "ffx_fsr1.h", HostShaders::FFX_FSR1_H);
|
||||
|
||||
std::string fsr_easu_source{HostShaders::OPENGL_FIDELITYFX_FSR_EASU_FRAG};
|
||||
std::string fsr_rcas_source{HostShaders::OPENGL_FIDELITYFX_FSR_RCAS_FRAG};
|
||||
ReplaceInclude(fsr_easu_source, "opengl_fidelityfx_fsr.frag", fsr_source);
|
||||
ReplaceInclude(fsr_rcas_source, "opengl_fidelityfx_fsr.frag", fsr_source);
|
||||
|
||||
vert = CreateProgram(HostShaders::FULL_SCREEN_TRIANGLE_VERT, GL_VERTEX_SHADER);
|
||||
easu_frag = CreateProgram(fsr_easu_source, GL_FRAGMENT_SHADER);
|
||||
rcas_frag = CreateProgram(fsr_rcas_source, GL_FRAGMENT_SHADER);
|
||||
|
||||
glProgramUniform2f(vert.handle, 0, 1.0f, -1.0f);
|
||||
glProgramUniform2f(vert.handle, 1, 0.0f, 1.0f);
|
||||
|
||||
sampler = CreateBilinearSampler();
|
||||
framebuffer.Create();
|
||||
|
||||
easu_tex.Create(GL_TEXTURE_2D);
|
||||
glTextureStorage2D(easu_tex.handle, 1, GL_RGBA16F, width, height);
|
||||
|
||||
rcas_tex.Create(GL_TEXTURE_2D);
|
||||
glTextureStorage2D(rcas_tex.handle, 1, GL_RGBA16F, width, height);
|
||||
}
|
||||
|
||||
FSR2::~FSR2() = default;
|
||||
|
||||
GLuint FSR2::Draw(ProgramManager& program_manager, GLuint texture, u32 input_image_width,
|
||||
u32 input_image_height, const Common::Rectangle<f32>& crop_rect) {
|
||||
const f32 input_width = static_cast<f32>(input_image_width);
|
||||
const f32 input_height = static_cast<f32>(input_image_height);
|
||||
const f32 output_width = static_cast<f32>(width);
|
||||
const f32 output_height = static_cast<f32>(height);
|
||||
const f32 viewport_width = (crop_rect.right - crop_rect.left) * input_width;
|
||||
const f32 viewport_x = crop_rect.left * input_width;
|
||||
const f32 viewport_height = (crop_rect.bottom - crop_rect.top) * input_height;
|
||||
const f32 viewport_y = crop_rect.top * input_height;
|
||||
|
||||
FsrConstants easu_con{};
|
||||
FsrConstants rcas_con{};
|
||||
|
||||
FsrEasuConOffset(easu_con.data() + 0, easu_con.data() + 4, easu_con.data() + 8,
|
||||
easu_con.data() + 12, viewport_width, viewport_height, input_width,
|
||||
input_height, output_width, output_height, viewport_x, viewport_y);
|
||||
|
||||
// FSR 2.0 uses a different sharpening calculation based on quality mode
|
||||
const int quality_mode = Settings::values.fsr2_quality_mode.GetValue();
|
||||
const float sharpening = [quality_mode]() {
|
||||
switch (quality_mode) {
|
||||
case 0: // Quality
|
||||
return 0.2f;
|
||||
case 1: // Balanced
|
||||
return 0.4f;
|
||||
case 2: // Performance
|
||||
return 0.6f;
|
||||
case 3: // Ultra Performance
|
||||
return 0.8f;
|
||||
default:
|
||||
return 0.4f;
|
||||
}
|
||||
}();
|
||||
|
||||
FsrRcasCon(rcas_con.data(), sharpening);
|
||||
|
||||
glProgramUniform4uiv(easu_frag.handle, 0, sizeof(easu_con), easu_con.data());
|
||||
glProgramUniform4uiv(rcas_frag.handle, 0, sizeof(rcas_con), rcas_con.data());
|
||||
|
||||
glFrontFace(GL_CW);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, framebuffer.handle);
|
||||
glNamedFramebufferTexture(framebuffer.handle, GL_COLOR_ATTACHMENT0, easu_tex.handle, 0);
|
||||
glViewportIndexedf(0, 0.0f, 0.0f, output_width, output_height);
|
||||
program_manager.BindPresentPrograms(vert.handle, easu_frag.handle);
|
||||
glBindTextureUnit(0, texture);
|
||||
glBindSampler(0, sampler.handle);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||
|
||||
glNamedFramebufferTexture(framebuffer.handle, GL_COLOR_ATTACHMENT0, rcas_tex.handle, 0);
|
||||
program_manager.BindPresentPrograms(vert.handle, rcas_frag.handle);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||
|
||||
glFrontFace(GL_CCW);
|
||||
return rcas_tex.handle;
|
||||
}
|
||||
|
||||
} // namespace OpenGL
|
||||
39
src/video_core/renderer_opengl/present/fsr2.h
Normal file
39
src/video_core/renderer_opengl/present/fsr2.h
Normal file
@@ -0,0 +1,39 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2025 citron Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "common/math_util.h"
|
||||
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
||||
|
||||
namespace OpenGL {
|
||||
|
||||
class ProgramManager;
|
||||
|
||||
class FSR2 {
|
||||
public:
|
||||
explicit FSR2(u32 output_width_, u32 output_height_);
|
||||
~FSR2();
|
||||
|
||||
GLuint Draw(ProgramManager& program_manager, GLuint texture, u32 input_image_width,
|
||||
u32 input_image_height, const Common::Rectangle<f32>& crop_rect);
|
||||
|
||||
bool NeedsRecreation(const Common::Rectangle<u32>& screen) const {
|
||||
return screen.GetWidth() != width || screen.GetHeight() != height;
|
||||
}
|
||||
|
||||
private:
|
||||
const u32 width;
|
||||
const u32 height;
|
||||
|
||||
OGLProgram vert;
|
||||
OGLProgram easu_frag;
|
||||
OGLProgram rcas_frag;
|
||||
OGLSampler sampler;
|
||||
OGLFramebuffer framebuffer;
|
||||
OGLTexture easu_tex;
|
||||
OGLTexture rcas_tex;
|
||||
};
|
||||
|
||||
} // namespace OpenGL
|
||||
@@ -1,4 +1,5 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-FileCopyrightText: Copyright 2025 citron Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "video_core/framebuffer_config.h"
|
||||
@@ -6,6 +7,7 @@
|
||||
#include "video_core/renderer_opengl/gl_blit_screen.h"
|
||||
#include "video_core/renderer_opengl/gl_rasterizer.h"
|
||||
#include "video_core/renderer_opengl/present/fsr.h"
|
||||
#include "video_core/renderer_opengl/present/fsr2.h"
|
||||
#include "video_core/renderer_opengl/present/fxaa.h"
|
||||
#include "video_core/renderer_opengl/present/layer.h"
|
||||
#include "video_core/renderer_opengl/present/present_uniforms.h"
|
||||
@@ -74,6 +76,14 @@ GLuint Layer::ConfigureDraw(std::array<GLfloat, 3 * 2>& out_matrix,
|
||||
texture = fsr->Draw(program_manager, texture, info.scaled_width, info.scaled_height, crop);
|
||||
crop = {0, 0, 1, 1};
|
||||
}
|
||||
if (filters.get_scaling_filter() == Settings::ScalingFilter::Fsr2) {
|
||||
if (!fsr2 || fsr2->NeedsRecreation(layout.screen)) {
|
||||
fsr2 = std::make_unique<FSR2>(layout.screen.GetWidth(), layout.screen.GetHeight());
|
||||
}
|
||||
|
||||
texture = fsr2->Draw(program_manager, texture, info.scaled_width, info.scaled_height, crop);
|
||||
crop = {0, 0, 1, 1};
|
||||
}
|
||||
|
||||
out_matrix =
|
||||
MakeOrthographicMatrix(static_cast<float>(layout.width), static_cast<float>(layout.height));
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||
// SPDX-FileCopyrightText: Copyright 2025 citron Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
@@ -27,6 +28,7 @@ namespace OpenGL {
|
||||
|
||||
struct FramebufferTextureInfo;
|
||||
class FSR;
|
||||
class FSR2;
|
||||
class FXAA;
|
||||
class ProgramManager;
|
||||
class RasterizerOpenGL;
|
||||
@@ -77,6 +79,7 @@ private:
|
||||
TextureInfo framebuffer_texture;
|
||||
|
||||
std::unique_ptr<FSR> fsr;
|
||||
std::unique_ptr<FSR2> fsr2;
|
||||
std::unique_ptr<FXAA> fxaa;
|
||||
std::unique_ptr<SMAA> smaa;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user