mirror of
https://git.eden-emu.dev/archive/citron
synced 2026-04-14 08:40:48 -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:
@@ -123,6 +123,8 @@ add_library(video_core STATIC
|
||||
renderer_opengl/present/filters.h
|
||||
renderer_opengl/present/fsr.cpp
|
||||
renderer_opengl/present/fsr.h
|
||||
renderer_opengl/present/fsr2.cpp
|
||||
renderer_opengl/present/fsr2.h
|
||||
renderer_opengl/present/fxaa.cpp
|
||||
renderer_opengl/present/fxaa.h
|
||||
renderer_opengl/present/layer.cpp
|
||||
@@ -178,6 +180,8 @@ add_library(video_core STATIC
|
||||
renderer_vulkan/present/filters.h
|
||||
renderer_vulkan/present/fsr.cpp
|
||||
renderer_vulkan/present/fsr.h
|
||||
renderer_vulkan/present/fsr2.cpp
|
||||
renderer_vulkan/present/fsr2.h
|
||||
renderer_vulkan/present/fxaa.cpp
|
||||
renderer_vulkan/present/fxaa.h
|
||||
renderer_vulkan/present/layer.cpp
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
240
src/video_core/renderer_vulkan/present/fsr2.cpp
Normal file
240
src/video_core/renderer_vulkan/present/fsr2.cpp
Normal file
@@ -0,0 +1,240 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2025 citron Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "common/div_ceil.h"
|
||||
#include "common/settings.h"
|
||||
|
||||
#include "video_core/fsr.h"
|
||||
#include "video_core/host_shaders/vulkan_fidelityfx_fsr_easu_fp16_frag_spv.h"
|
||||
#include "video_core/host_shaders/vulkan_fidelityfx_fsr_easu_fp32_frag_spv.h"
|
||||
#include "video_core/host_shaders/vulkan_fidelityfx_fsr_rcas_fp16_frag_spv.h"
|
||||
#include "video_core/host_shaders/vulkan_fidelityfx_fsr_rcas_fp32_frag_spv.h"
|
||||
#include "video_core/host_shaders/vulkan_fidelityfx_fsr_vert_spv.h"
|
||||
#include "video_core/renderer_vulkan/present/fsr2.h"
|
||||
#include "video_core/renderer_vulkan/present/util.h"
|
||||
#include "video_core/renderer_vulkan/vk_scheduler.h"
|
||||
#include "video_core/renderer_vulkan/vk_shader_util.h"
|
||||
#include "video_core/vulkan_common/vulkan_device.h"
|
||||
|
||||
namespace Vulkan {
|
||||
using namespace FSR;
|
||||
|
||||
using PushConstants = std::array<u32, 4 * 4>;
|
||||
|
||||
FSR2::FSR2(const Device& device, MemoryAllocator& memory_allocator, size_t image_count,
|
||||
VkExtent2D extent)
|
||||
: m_device{device}, m_memory_allocator{memory_allocator},
|
||||
m_image_count{image_count}, m_extent{extent} {
|
||||
|
||||
CreateImages();
|
||||
CreateRenderPasses();
|
||||
CreateSampler();
|
||||
CreateShaders();
|
||||
CreateDescriptorPool();
|
||||
CreateDescriptorSetLayout();
|
||||
CreateDescriptorSets();
|
||||
CreatePipelineLayouts();
|
||||
CreatePipelines();
|
||||
}
|
||||
|
||||
void FSR2::CreateImages() {
|
||||
m_dynamic_images.resize(m_image_count);
|
||||
for (auto& images : m_dynamic_images) {
|
||||
images.images[Easu] =
|
||||
CreateWrappedImage(m_memory_allocator, m_extent, VK_FORMAT_R16G16B16A16_SFLOAT);
|
||||
images.images[Rcas] =
|
||||
CreateWrappedImage(m_memory_allocator, m_extent, VK_FORMAT_R16G16B16A16_SFLOAT);
|
||||
images.image_views[Easu] =
|
||||
CreateWrappedImageView(m_device, images.images[Easu], VK_FORMAT_R16G16B16A16_SFLOAT);
|
||||
images.image_views[Rcas] =
|
||||
CreateWrappedImageView(m_device, images.images[Rcas], VK_FORMAT_R16G16B16A16_SFLOAT);
|
||||
}
|
||||
}
|
||||
|
||||
void FSR2::CreateRenderPasses() {
|
||||
m_renderpass = CreateWrappedRenderPass(m_device, VK_FORMAT_R16G16B16A16_SFLOAT);
|
||||
|
||||
for (auto& images : m_dynamic_images) {
|
||||
images.framebuffers[Easu] =
|
||||
CreateWrappedFramebuffer(m_device, m_renderpass, images.image_views[Easu], m_extent);
|
||||
images.framebuffers[Rcas] =
|
||||
CreateWrappedFramebuffer(m_device, m_renderpass, images.image_views[Rcas], m_extent);
|
||||
}
|
||||
}
|
||||
|
||||
void FSR2::CreateSampler() {
|
||||
m_sampler = CreateBilinearSampler(m_device);
|
||||
}
|
||||
|
||||
void FSR2::CreateShaders() {
|
||||
m_vert_shader = BuildShader(m_device, VULKAN_FIDELITYFX_FSR_VERT_SPV);
|
||||
|
||||
if (m_device.IsFloat16Supported()) {
|
||||
m_easu_shader = BuildShader(m_device, VULKAN_FIDELITYFX_FSR_EASU_FP16_FRAG_SPV);
|
||||
m_rcas_shader = BuildShader(m_device, VULKAN_FIDELITYFX_FSR_RCAS_FP16_FRAG_SPV);
|
||||
} else {
|
||||
m_easu_shader = BuildShader(m_device, VULKAN_FIDELITYFX_FSR_EASU_FP32_FRAG_SPV);
|
||||
m_rcas_shader = BuildShader(m_device, VULKAN_FIDELITYFX_FSR_RCAS_FP32_FRAG_SPV);
|
||||
}
|
||||
}
|
||||
|
||||
void FSR2::CreateDescriptorPool() {
|
||||
// EASU: 1 descriptor
|
||||
// RCAS: 1 descriptor
|
||||
// 2 descriptors, 2 descriptor sets per invocation
|
||||
m_descriptor_pool = CreateWrappedDescriptorPool(m_device, 2 * m_image_count, 2 * m_image_count);
|
||||
}
|
||||
|
||||
void FSR2::CreateDescriptorSetLayout() {
|
||||
m_descriptor_set_layout =
|
||||
CreateWrappedDescriptorSetLayout(m_device, {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER});
|
||||
}
|
||||
|
||||
void FSR2::CreateDescriptorSets() {
|
||||
std::vector<VkDescriptorSetLayout> layouts(MaxFsr2Stage, *m_descriptor_set_layout);
|
||||
|
||||
for (auto& images : m_dynamic_images) {
|
||||
images.descriptor_sets = CreateWrappedDescriptorSets(m_descriptor_pool, layouts);
|
||||
}
|
||||
}
|
||||
|
||||
void FSR2::CreatePipelineLayouts() {
|
||||
const VkPushConstantRange range{
|
||||
.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT,
|
||||
.offset = 0,
|
||||
.size = sizeof(PushConstants),
|
||||
};
|
||||
VkPipelineLayoutCreateInfo ci{
|
||||
.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
.flags = 0,
|
||||
.setLayoutCount = 1,
|
||||
.pSetLayouts = m_descriptor_set_layout.address(),
|
||||
.pushConstantRangeCount = 1,
|
||||
.pPushConstantRanges = &range,
|
||||
};
|
||||
|
||||
m_pipeline_layout = m_device.GetLogical().CreatePipelineLayout(ci);
|
||||
}
|
||||
|
||||
void FSR2::CreatePipelines() {
|
||||
m_easu_pipeline = CreateWrappedPipeline(m_device, m_renderpass, m_pipeline_layout,
|
||||
std::tie(m_vert_shader, m_easu_shader));
|
||||
m_rcas_pipeline = CreateWrappedPipeline(m_device, m_renderpass, m_pipeline_layout,
|
||||
std::tie(m_vert_shader, m_rcas_shader));
|
||||
}
|
||||
|
||||
void FSR2::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);
|
||||
|
||||
updates.push_back(CreateWriteDescriptorSet(image_infos, *m_sampler, image_view,
|
||||
images.descriptor_sets[Easu], 0));
|
||||
updates.push_back(CreateWriteDescriptorSet(image_infos, *m_sampler, *images.image_views[Easu],
|
||||
images.descriptor_sets[Rcas], 0));
|
||||
|
||||
m_device.GetLogical().UpdateDescriptorSets(updates, {});
|
||||
}
|
||||
|
||||
void FSR2::UploadImages(Scheduler& scheduler) {
|
||||
if (m_images_ready) {
|
||||
return;
|
||||
}
|
||||
|
||||
scheduler.Record([&](vk::CommandBuffer cmdbuf) {
|
||||
for (auto& image : m_dynamic_images) {
|
||||
ClearColorImage(cmdbuf, *image.images[Easu]);
|
||||
ClearColorImage(cmdbuf, *image.images[Rcas]);
|
||||
}
|
||||
});
|
||||
scheduler.Finish();
|
||||
|
||||
m_images_ready = true;
|
||||
}
|
||||
|
||||
VkImageView FSR2::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];
|
||||
|
||||
VkImage easu_image = *images.images[Easu];
|
||||
VkImage rcas_image = *images.images[Rcas];
|
||||
VkDescriptorSet easu_descriptor_set = images.descriptor_sets[Easu];
|
||||
VkDescriptorSet rcas_descriptor_set = images.descriptor_sets[Rcas];
|
||||
VkFramebuffer easu_framebuffer = *images.framebuffers[Easu];
|
||||
VkFramebuffer rcas_framebuffer = *images.framebuffers[Rcas];
|
||||
VkPipeline easu_pipeline = *m_easu_pipeline;
|
||||
VkPipeline rcas_pipeline = *m_rcas_pipeline;
|
||||
VkPipelineLayout pipeline_layout = *m_pipeline_layout;
|
||||
VkRenderPass renderpass = *m_renderpass;
|
||||
VkExtent2D extent = m_extent;
|
||||
|
||||
const f32 input_image_width = static_cast<f32>(input_image_extent.width);
|
||||
const f32 input_image_height = static_cast<f32>(input_image_extent.height);
|
||||
const f32 output_image_width = static_cast<f32>(extent.width);
|
||||
const f32 output_image_height = static_cast<f32>(extent.height);
|
||||
const f32 viewport_width = (crop_rect.right - crop_rect.left) * input_image_width;
|
||||
const f32 viewport_x = crop_rect.left * input_image_width;
|
||||
const f32 viewport_height = (crop_rect.bottom - crop_rect.top) * input_image_height;
|
||||
const f32 viewport_y = crop_rect.top * input_image_height;
|
||||
|
||||
PushConstants easu_con{};
|
||||
PushConstants rcas_con{};
|
||||
FsrEasuConOffset(easu_con.data() + 0, easu_con.data() + 4, easu_con.data() + 8,
|
||||
easu_con.data() + 12, viewport_width, viewport_height, input_image_width,
|
||||
input_image_height, output_image_width, output_image_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);
|
||||
|
||||
UploadImages(scheduler);
|
||||
UpdateDescriptorSets(source_image_view, image_index);
|
||||
|
||||
scheduler.RequestOutsideRenderPassOperationContext();
|
||||
scheduler.Record([=](vk::CommandBuffer cmdbuf) {
|
||||
TransitionImageLayout(cmdbuf, source_image, VK_IMAGE_LAYOUT_GENERAL);
|
||||
TransitionImageLayout(cmdbuf, easu_image, VK_IMAGE_LAYOUT_GENERAL);
|
||||
BeginRenderPass(cmdbuf, renderpass, easu_framebuffer, extent);
|
||||
cmdbuf.BindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, easu_pipeline);
|
||||
cmdbuf.BindDescriptorSets(VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
|
||||
easu_descriptor_set, {});
|
||||
cmdbuf.PushConstants(pipeline_layout, VK_SHADER_STAGE_FRAGMENT_BIT, easu_con);
|
||||
cmdbuf.Draw(3, 1, 0, 0);
|
||||
cmdbuf.EndRenderPass();
|
||||
|
||||
TransitionImageLayout(cmdbuf, easu_image, VK_IMAGE_LAYOUT_GENERAL);
|
||||
TransitionImageLayout(cmdbuf, rcas_image, VK_IMAGE_LAYOUT_GENERAL);
|
||||
BeginRenderPass(cmdbuf, renderpass, rcas_framebuffer, extent);
|
||||
cmdbuf.BindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, rcas_pipeline);
|
||||
cmdbuf.BindDescriptorSets(VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0,
|
||||
rcas_descriptor_set, {});
|
||||
cmdbuf.PushConstants(pipeline_layout, VK_SHADER_STAGE_FRAGMENT_BIT, rcas_con);
|
||||
cmdbuf.Draw(3, 1, 0, 0);
|
||||
cmdbuf.EndRenderPass();
|
||||
|
||||
TransitionImageLayout(cmdbuf, rcas_image, VK_IMAGE_LAYOUT_GENERAL);
|
||||
});
|
||||
|
||||
return *images.image_views[Rcas];
|
||||
}
|
||||
|
||||
} // namespace Vulkan
|
||||
69
src/video_core/renderer_vulkan/present/fsr2.h
Normal file
69
src/video_core/renderer_vulkan/present/fsr2.h
Normal file
@@ -0,0 +1,69 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2025 citron Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/math_util.h"
|
||||
#include "video_core/vulkan_common/vulkan_memory_allocator.h"
|
||||
#include "video_core/vulkan_common/vulkan_wrapper.h"
|
||||
|
||||
namespace Vulkan {
|
||||
|
||||
class Device;
|
||||
class Scheduler;
|
||||
|
||||
class FSR2 {
|
||||
public:
|
||||
explicit FSR2(const Device& device, MemoryAllocator& memory_allocator, size_t image_count,
|
||||
VkExtent2D extent);
|
||||
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 CreateImages();
|
||||
void CreateRenderPasses();
|
||||
void CreateSampler();
|
||||
void CreateShaders();
|
||||
void CreateDescriptorPool();
|
||||
void CreateDescriptorSetLayout();
|
||||
void CreateDescriptorSets();
|
||||
void CreatePipelineLayouts();
|
||||
void CreatePipelines();
|
||||
|
||||
void UploadImages(Scheduler& scheduler);
|
||||
void UpdateDescriptorSets(VkImageView image_view, size_t image_index);
|
||||
|
||||
const Device& m_device;
|
||||
MemoryAllocator& m_memory_allocator;
|
||||
const size_t m_image_count;
|
||||
const VkExtent2D m_extent;
|
||||
|
||||
enum Fsr2Stage {
|
||||
Easu,
|
||||
Rcas,
|
||||
MaxFsr2Stage,
|
||||
};
|
||||
|
||||
vk::DescriptorPool m_descriptor_pool;
|
||||
vk::DescriptorSetLayout m_descriptor_set_layout;
|
||||
vk::PipelineLayout m_pipeline_layout;
|
||||
vk::ShaderModule m_vert_shader;
|
||||
vk::ShaderModule m_easu_shader;
|
||||
vk::ShaderModule m_rcas_shader;
|
||||
vk::Pipeline m_easu_pipeline;
|
||||
vk::Pipeline m_rcas_pipeline;
|
||||
vk::RenderPass m_renderpass;
|
||||
vk::Sampler m_sampler;
|
||||
|
||||
struct Images {
|
||||
vk::DescriptorSets descriptor_sets;
|
||||
std::array<vk::Image, MaxFsr2Stage> images;
|
||||
std::array<vk::ImageView, MaxFsr2Stage> image_views;
|
||||
std::array<vk::Framebuffer, MaxFsr2Stage> framebuffers;
|
||||
};
|
||||
std::vector<Images> m_dynamic_images;
|
||||
bool m_images_ready{};
|
||||
};
|
||||
|
||||
} // namespace Vulkan
|
||||
@@ -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/present.h"
|
||||
@@ -7,6 +8,7 @@
|
||||
#include "common/settings.h"
|
||||
#include "video_core/framebuffer_config.h"
|
||||
#include "video_core/renderer_vulkan/present/fsr.h"
|
||||
#include "video_core/renderer_vulkan/present/fsr2.h"
|
||||
#include "video_core/renderer_vulkan/present/fxaa.h"
|
||||
#include "video_core/renderer_vulkan/present/layer.h"
|
||||
#include "video_core/renderer_vulkan/present/present_push_constants.h"
|
||||
@@ -57,6 +59,9 @@ Layer::Layer(const Device& device_, MemoryAllocator& memory_allocator_, Schedule
|
||||
if (filters.get_scaling_filter() == Settings::ScalingFilter::Fsr) {
|
||||
CreateFSR(output_size);
|
||||
}
|
||||
if (filters.get_scaling_filter() == Settings::ScalingFilter::Fsr2) {
|
||||
CreateFSR2(output_size);
|
||||
}
|
||||
}
|
||||
|
||||
Layer::~Layer() {
|
||||
@@ -107,6 +112,11 @@ void Layer::ConfigureDraw(PresentPushConstants* out_push_constants,
|
||||
render_extent, crop_rect);
|
||||
crop_rect = {0, 0, 1, 1};
|
||||
}
|
||||
if (fsr2) {
|
||||
source_image_view = fsr2->Draw(scheduler, image_index, source_image, source_image_view,
|
||||
render_extent, crop_rect);
|
||||
crop_rect = {0, 0, 1, 1};
|
||||
}
|
||||
|
||||
SetMatrixData(*out_push_constants, layout);
|
||||
SetVertexData(*out_push_constants, layout, crop_rect);
|
||||
@@ -157,6 +167,10 @@ void Layer::CreateFSR(VkExtent2D output_size) {
|
||||
fsr = std::make_unique<FSR>(device, memory_allocator, image_count, output_size);
|
||||
}
|
||||
|
||||
void Layer::CreateFSR2(VkExtent2D output_size) {
|
||||
fsr2 = std::make_unique<FSR2>(device, memory_allocator, image_count, output_size);
|
||||
}
|
||||
|
||||
void Layer::RefreshResources(const Tegra::FramebufferConfig& framebuffer) {
|
||||
if (framebuffer.width == raw_width && framebuffer.height == raw_height &&
|
||||
framebuffer.pixel_format == pixel_format && !raw_images.empty()) {
|
||||
|
||||
@@ -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
|
||||
@@ -30,6 +31,7 @@ namespace Vulkan {
|
||||
class AntiAliasPass;
|
||||
class Device;
|
||||
class FSR;
|
||||
class FSR2;
|
||||
class MemoryAllocator;
|
||||
struct PresentPushConstants;
|
||||
class RasterizerVulkan;
|
||||
@@ -55,6 +57,7 @@ private:
|
||||
void CreateStagingBuffer(const Tegra::FramebufferConfig& framebuffer);
|
||||
void CreateRawImages(const Tegra::FramebufferConfig& framebuffer);
|
||||
void CreateFSR(VkExtent2D output_size);
|
||||
void CreateFSR2(VkExtent2D output_size);
|
||||
|
||||
void RefreshResources(const Tegra::FramebufferConfig& framebuffer);
|
||||
void SetAntiAliasPass();
|
||||
@@ -90,6 +93,7 @@ private:
|
||||
std::unique_ptr<AntiAliasPass> anti_alias{};
|
||||
|
||||
std::unique_ptr<FSR> fsr{};
|
||||
std::unique_ptr<FSR2> fsr2{};
|
||||
std::vector<u64> resource_ticks{};
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
||||
// SPDX-FileCopyrightText: Copyright 2025 citron Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "video_core/framebuffer_config.h"
|
||||
@@ -44,6 +45,7 @@ void BlitScreen::SetWindowAdaptPass() {
|
||||
window_adapt = MakeScaleForce(device, swapchain_view_format);
|
||||
break;
|
||||
case Settings::ScalingFilter::Fsr:
|
||||
case Settings::ScalingFilter::Fsr2:
|
||||
case Settings::ScalingFilter::Bilinear:
|
||||
default:
|
||||
window_adapt = MakeBilinear(device, swapchain_view_format);
|
||||
|
||||
Reference in New Issue
Block a user