From 82e9f4ca03fdc32ebcdea763d2958448d6e2ce77 Mon Sep 17 00:00:00 2001 From: Wunkolo Date: Fri, 10 Nov 2023 17:48:51 -0800 Subject: [PATCH] rasterizer: Add multi-sampled framebuffers Vulkan implementation only --- .../rasterizer_cache/framebuffer_base.h | 3 ++- .../rasterizer_cache/rasterizer_cache.h | 1 + .../renderer_vulkan/vk_texture_runtime.cpp | 21 ++++++++++++++----- .../renderer_vulkan/vk_texture_runtime.h | 11 +++++++--- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/video_core/rasterizer_cache/framebuffer_base.h b/src/video_core/rasterizer_cache/framebuffer_base.h index 9a1123270..f7a889e30 100644 --- a/src/video_core/rasterizer_cache/framebuffer_base.h +++ b/src/video_core/rasterizer_cache/framebuffer_base.h @@ -27,7 +27,8 @@ struct FramebufferParams { u32 color_level; u32 depth_level; bool shadow_rendering; - INSERT_PADDING_BYTES(3); + u8 sample_count; + INSERT_PADDING_BYTES(2); bool operator==(const FramebufferParams& params) const noexcept { return std::memcmp(this, ¶ms, sizeof(FramebufferParams)) == 0; diff --git a/src/video_core/rasterizer_cache/rasterizer_cache.h b/src/video_core/rasterizer_cache/rasterizer_cache.h index 25ea05c6e..b935ed0f4 100644 --- a/src/video_core/rasterizer_cache/rasterizer_cache.h +++ b/src/video_core/rasterizer_cache/rasterizer_cache.h @@ -748,6 +748,7 @@ FramebufferHelper RasterizerCache::GetFramebufferSurfaces(bool using_color .color_level = color_level, .depth_level = depth_level, .shadow_rendering = regs.framebuffer.IsShadowRendering(), + .sample_count = sample_count, }; auto [it, new_framebuffer] = framebuffers.try_emplace(fb_params); diff --git a/src/video_core/renderer_vulkan/vk_texture_runtime.cpp b/src/video_core/renderer_vulkan/vk_texture_runtime.cpp index 2db1a9c39..11ae2e9f2 100644 --- a/src/video_core/renderer_vulkan/vk_texture_runtime.cpp +++ b/src/video_core/renderer_vulkan/vk_texture_runtime.cpp @@ -1458,8 +1458,9 @@ void Surface::BlitScale(const VideoCore::TextureBlit& blit, bool up_scale) { Framebuffer::Framebuffer(TextureRuntime& runtime, const VideoCore::FramebufferParams& params, Surface* color, Surface* depth) - : VideoCore::FramebufferParams{params}, res_scale{color ? color->res_scale - : (depth ? depth->res_scale : 1u)} { + : VideoCore::FramebufferParams{params}, + res_scale{color ? color->res_scale : (depth ? depth->res_scale : 1u)}, + sample_count{params.sample_count} { auto& renderpass_cache = runtime.GetRenderpassCache(); if (shadow_rendering && !color) { return; @@ -1474,12 +1475,12 @@ Framebuffer::Framebuffer(TextureRuntime& runtime, const VideoCore::FramebufferPa if (!shadow_rendering) { formats[index] = surface->pixel_format; } - images[index] = surface->Image(); aspects[index] = surface->Aspect(); + images[index] = surface->Image(); image_views[index] = shadow_rendering ? surface->StorageView() : surface->FramebufferView(); }; - boost::container::static_vector attachments; + boost::container::static_vector attachments; if (color) { prepare(0, color); @@ -1491,6 +1492,16 @@ Framebuffer::Framebuffer(TextureRuntime& runtime, const VideoCore::FramebufferPa attachments.emplace_back(image_views[1]); } + if (sample_count > 1) { + if (color) { + attachments.emplace_back(color->ImageView(3)); + } + + if (depth) { + attachments.emplace_back(depth->ImageView(3)); + } + } + const vk::Device device = runtime.GetInstance().GetDevice(); if (shadow_rendering) { render_pass = @@ -1498,7 +1509,7 @@ Framebuffer::Framebuffer(TextureRuntime& runtime, const VideoCore::FramebufferPa framebuffer = MakeFramebuffer(device, render_pass, color->GetScaledWidth(), color->GetScaledHeight(), {}); } else { - render_pass = renderpass_cache.GetRenderpass(formats[0], formats[1], false); + render_pass = renderpass_cache.GetRenderpass(formats[0], formats[1], false, sample_count); framebuffer = MakeFramebuffer(device, render_pass, width, height, attachments); } } diff --git a/src/video_core/renderer_vulkan/vk_texture_runtime.h b/src/video_core/renderer_vulkan/vk_texture_runtime.h index 2bef63dab..eeede2f0a 100644 --- a/src/video_core/renderer_vulkan/vk_texture_runtime.h +++ b/src/video_core/renderer_vulkan/vk_texture_runtime.h @@ -215,7 +215,7 @@ public: return framebuffer.get(); } - [[nodiscard]] std::array Images() const noexcept { + [[nodiscard]] std::array Images() const noexcept { return images; } @@ -227,6 +227,10 @@ public: return render_pass; } + u8 Samples() const noexcept { + return sample_count; + } + u32 Scale() const noexcept { return res_scale; } @@ -240,8 +244,8 @@ public: } private: - std::array images{}; - std::array image_views{}; + std::array images{}; + std::array image_views{}; vk::UniqueFramebuffer framebuffer; vk::RenderPass render_pass; std::array aspects{}; @@ -250,6 +254,7 @@ private: u32 width{}; u32 height{}; u32 res_scale{1}; + u8 sample_count{1}; }; class Sampler {