mirror of
https://git.eden-emu.dev/archive/citron
synced 2026-04-08 12:18:49 -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:
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{};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user