diff options
-rw-r--r-- | src/video_core/renderer_vulkan/vk_blit_screen.cpp | 19 | ||||
-rw-r--r-- | src/video_core/renderer_vulkan/vk_blit_screen.h | 2 | ||||
-rw-r--r-- | src/video_core/renderer_vulkan/vk_fsr.cpp | 72 |
3 files changed, 50 insertions, 43 deletions
diff --git a/src/video_core/renderer_vulkan/vk_blit_screen.cpp b/src/video_core/renderer_vulkan/vk_blit_screen.cpp index 9dfc508bc..1e447e621 100644 --- a/src/video_core/renderer_vulkan/vk_blit_screen.cpp +++ b/src/video_core/renderer_vulkan/vk_blit_screen.cpp @@ -468,20 +468,14 @@ void VKBlitScreen::CreateDynamicResources() { CreateGraphicsPipeline(); fsr.reset(); if (Settings::values.scaling_filter.GetValue() == Settings::ScalingFilter::Fsr) { - const auto& layout = render_window.GetFramebufferLayout(); - fsr = std::make_unique<FSR>( - device, memory_allocator, image_count, - VkExtent2D{.width = layout.screen.GetWidth(), .height = layout.screen.GetHeight()}); + CreateFSR(); } } void VKBlitScreen::RefreshResources(const Tegra::FramebufferConfig& framebuffer) { if (Settings::values.scaling_filter.GetValue() == Settings::ScalingFilter::Fsr) { if (!fsr) { - const auto& layout = render_window.GetFramebufferLayout(); - fsr = std::make_unique<FSR>( - device, memory_allocator, image_count, - VkExtent2D{.width = layout.screen.GetWidth(), .height = layout.screen.GetHeight()}); + CreateFSR(); } } else { fsr.reset(); @@ -1443,6 +1437,15 @@ void VKBlitScreen::SetVertexData(BufferData& data, const Tegra::FramebufferConfi data.vertices[3] = ScreenRectVertex(x + w, y + h, texcoords.bottom * scale_u, right * scale_v); } +void VKBlitScreen::CreateFSR() { + const auto& layout = render_window.GetFramebufferLayout(); + const VkExtent2D fsr_size{ + .width = layout.screen.GetWidth(), + .height = layout.screen.GetHeight(), + }; + fsr = std::make_unique<FSR>(device, memory_allocator, image_count, fsr_size); +} + u64 VKBlitScreen::CalculateBufferSize(const Tegra::FramebufferConfig& framebuffer) const { return sizeof(BufferData) + GetSizeInBytes(framebuffer) * image_count; } diff --git a/src/video_core/renderer_vulkan/vk_blit_screen.h b/src/video_core/renderer_vulkan/vk_blit_screen.h index ad0cd8ee1..bbca71af3 100644 --- a/src/video_core/renderer_vulkan/vk_blit_screen.h +++ b/src/video_core/renderer_vulkan/vk_blit_screen.h @@ -99,6 +99,8 @@ private: void SetVertexData(BufferData& data, const Tegra::FramebufferConfig& framebuffer, const Layout::FramebufferLayout layout) const; + void CreateFSR(); + u64 CalculateBufferSize(const Tegra::FramebufferConfig& framebuffer) const; u64 GetRawImageOffset(const Tegra::FramebufferConfig& framebuffer, std::size_t image_index) const; diff --git a/src/video_core/renderer_vulkan/vk_fsr.cpp b/src/video_core/renderer_vulkan/vk_fsr.cpp index 2feaa9d37..73629d229 100644 --- a/src/video_core/renderer_vulkan/vk_fsr.cpp +++ b/src/video_core/renderer_vulkan/vk_fsr.cpp @@ -2,8 +2,11 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include <cmath> +#include "common/bit_cast.h" #include "common/common_types.h" #include "common/div_ceil.h" + #include "video_core/host_shaders/vulkan_fidelityfx_fsr_easu_fp16_comp_spv.h" #include "video_core/host_shaders/vulkan_fidelityfx_fsr_easu_fp32_comp_spv.h" #include "video_core/host_shaders/vulkan_fidelityfx_fsr_rcas_fp16_comp_spv.h" @@ -13,9 +16,11 @@ #include "video_core/renderer_vulkan/vk_shader_util.h" #include "video_core/vulkan_common/vulkan_device.h" +namespace Vulkan { +namespace { // Reimplementations of the constant generating functions in ffx_fsr1.h // GCC generated a lot of warnings when using the official header. -static u32 AU1_AH1_AF1(f32 f) { +u32 AU1_AH1_AF1(f32 f) { static constexpr u32 base[512]{ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, @@ -102,59 +107,56 @@ static u32 AU1_AH1_AF1(f32 f) { 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, }; - auto u = std::bit_cast<u32>(f); - u32 i = u >> 23; + const u32 u = Common::BitCast<u32>(f); + const u32 i = u >> 23; return base[i] + ((u & 0x7fffff) >> shift[i]); } -static u32 AU1_AH2_AF2(f32 a[2]) { +u32 AU1_AH2_AF2(f32 a[2]) { return AU1_AH1_AF1(a[0]) + (AU1_AH1_AF1(a[1]) << 16); } -static void FsrEasuCon(u32 con0[4], u32 con1[4], u32 con2[4], u32 con3[4], - f32 inputViewportInPixelsX, f32 inputViewportInPixelsY, - f32 inputSizeInPixelsX, f32 inputSizeInPixelsY, f32 outputSizeInPixelsX, - f32 outputSizeInPixelsY) { - con0[0] = std::bit_cast<u32>(inputViewportInPixelsX / outputSizeInPixelsX); - con0[1] = std::bit_cast<u32>(inputViewportInPixelsY / outputSizeInPixelsY); - con0[2] = std::bit_cast<u32>(0.5f * inputViewportInPixelsX / outputSizeInPixelsX - 0.5f); - con0[3] = std::bit_cast<u32>(0.5f * inputViewportInPixelsY / outputSizeInPixelsY - 0.5f); - con1[0] = std::bit_cast<u32>(1.0f / inputSizeInPixelsX); - con1[1] = std::bit_cast<u32>(1.0f / inputSizeInPixelsY); - con1[2] = std::bit_cast<u32>(1.0f / inputSizeInPixelsX); - con1[3] = std::bit_cast<u32>(-1.0f / inputSizeInPixelsY); - con2[0] = std::bit_cast<u32>(-1.0f / inputSizeInPixelsX); - con2[1] = std::bit_cast<u32>(2.0f / inputSizeInPixelsY); - con2[2] = std::bit_cast<u32>(1.0f / inputSizeInPixelsX); - con2[3] = std::bit_cast<u32>(2.0f / inputSizeInPixelsY); - con3[0] = std::bit_cast<u32>(0.0f / inputSizeInPixelsX); - con3[1] = std::bit_cast<u32>(4.0f / inputSizeInPixelsY); +void FsrEasuCon(u32 con0[4], u32 con1[4], u32 con2[4], u32 con3[4], f32 inputViewportInPixelsX, + f32 inputViewportInPixelsY, f32 inputSizeInPixelsX, f32 inputSizeInPixelsY, + f32 outputSizeInPixelsX, f32 outputSizeInPixelsY) { + con0[0] = Common::BitCast<u32>(inputViewportInPixelsX / outputSizeInPixelsX); + con0[1] = Common::BitCast<u32>(inputViewportInPixelsY / outputSizeInPixelsY); + con0[2] = Common::BitCast<u32>(0.5f * inputViewportInPixelsX / outputSizeInPixelsX - 0.5f); + con0[3] = Common::BitCast<u32>(0.5f * inputViewportInPixelsY / outputSizeInPixelsY - 0.5f); + con1[0] = Common::BitCast<u32>(1.0f / inputSizeInPixelsX); + con1[1] = Common::BitCast<u32>(1.0f / inputSizeInPixelsY); + con1[2] = Common::BitCast<u32>(1.0f / inputSizeInPixelsX); + con1[3] = Common::BitCast<u32>(-1.0f / inputSizeInPixelsY); + con2[0] = Common::BitCast<u32>(-1.0f / inputSizeInPixelsX); + con2[1] = Common::BitCast<u32>(2.0f / inputSizeInPixelsY); + con2[2] = Common::BitCast<u32>(1.0f / inputSizeInPixelsX); + con2[3] = Common::BitCast<u32>(2.0f / inputSizeInPixelsY); + con3[0] = Common::BitCast<u32>(0.0f / inputSizeInPixelsX); + con3[1] = Common::BitCast<u32>(4.0f / inputSizeInPixelsY); con3[2] = con3[3] = 0; } -static void FsrEasuConOffset(u32 con0[4], u32 con1[4], u32 con2[4], u32 con3[4], - f32 inputViewportInPixelsX, f32 inputViewportInPixelsY, - f32 inputSizeInPixelsX, f32 inputSizeInPixelsY, - f32 outputSizeInPixelsX, f32 outputSizeInPixelsY, - f32 inputOffsetInPixelsX, f32 inputOffsetInPixelsY) { +void FsrEasuConOffset(u32 con0[4], u32 con1[4], u32 con2[4], u32 con3[4], + f32 inputViewportInPixelsX, f32 inputViewportInPixelsY, + f32 inputSizeInPixelsX, f32 inputSizeInPixelsY, f32 outputSizeInPixelsX, + f32 outputSizeInPixelsY, f32 inputOffsetInPixelsX, f32 inputOffsetInPixelsY) { FsrEasuCon(con0, con1, con2, con3, inputViewportInPixelsX, inputViewportInPixelsY, inputSizeInPixelsX, inputSizeInPixelsY, outputSizeInPixelsX, outputSizeInPixelsY); - con0[2] = std::bit_cast<u32>(0.5f * inputViewportInPixelsX / outputSizeInPixelsX - 0.5f + - inputOffsetInPixelsX); - con0[3] = std::bit_cast<u32>(0.5f * inputViewportInPixelsY / outputSizeInPixelsY - 0.5f + - inputOffsetInPixelsY); + con0[2] = Common::BitCast<u32>(0.5f * inputViewportInPixelsX / outputSizeInPixelsX - 0.5f + + inputOffsetInPixelsX); + con0[3] = Common::BitCast<u32>(0.5f * inputViewportInPixelsY / outputSizeInPixelsY - 0.5f + + inputOffsetInPixelsY); } -static void FsrRcasCon(u32* con, f32 sharpness) { +void FsrRcasCon(u32* con, f32 sharpness) { sharpness = std::exp2f(-sharpness); f32 hSharp[2]{sharpness, sharpness}; - con[0] = std::bit_cast<u32>(sharpness); + con[0] = Common::BitCast<u32>(sharpness); con[1] = AU1_AH2_AF2(hSharp); con[2] = 0; con[3] = 0; } - -namespace Vulkan { +} // Anonymous namespace FSR::FSR(const Device& device_, MemoryAllocator& memory_allocator_, size_t image_count_, VkExtent2D output_size_) |