From 4b193c8d6ba8e76e1fd4b9a545b8d786019edb8a Mon Sep 17 00:00:00 2001 From: Wunkolo Date: Sun, 20 Aug 2023 00:26:27 -0700 Subject: [PATCH] Add general purpose vulkan render cache Takes in a general `vk::Format` rather than PICA-types --- include/renderer_vk/renderer_vk.hpp | 3 ++- src/core/renderer_vk/renderer_vk.cpp | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/include/renderer_vk/renderer_vk.hpp b/include/renderer_vk/renderer_vk.hpp index e0d932a9..98e00c53 100644 --- a/include/renderer_vk/renderer_vk.hpp +++ b/include/renderer_vk/renderer_vk.hpp @@ -83,8 +83,9 @@ class RendererVK final : public Renderer { std::vector screenTexture = {}; vk::UniqueDeviceMemory framebufferMemory = {}; - std::map renderPassCache; + std::map renderPassCache; + vk::RenderPass getRenderPass(vk::Format colorFormat, std::optional depthFormat); vk::RenderPass getRenderPass(PICA::ColorFmt colorFormat, std::optional depthFormat); // Recreate the swapchain, possibly re-using the old one in the case of a resize diff --git a/src/core/renderer_vk/renderer_vk.cpp b/src/core/renderer_vk/renderer_vk.cpp index f4dadf8f..c53d820d 100644 --- a/src/core/renderer_vk/renderer_vk.cpp +++ b/src/core/renderer_vk/renderer_vk.cpp @@ -151,11 +151,11 @@ RendererVK::Texture& RendererVK::getDepthRenderTexture(u32 addr, PICA::DepthFmt return newTexture; } -vk::RenderPass RendererVK::getRenderPass(PICA::ColorFmt colorFormat, std::optional depthFormat) { - u32 renderPassHash = static_cast(colorFormat); +vk::RenderPass RendererVK::getRenderPass(vk::Format colorFormat, std::optional depthFormat) { + u64 renderPassHash = static_cast(colorFormat); if (depthFormat.has_value()) { - renderPassHash |= (static_cast(depthFormat.value()) << 8); + renderPassHash |= (static_cast(depthFormat.value()) << 32); } // Cache hit @@ -170,7 +170,7 @@ vk::RenderPass RendererVK::getRenderPass(PICA::ColorFmt colorFormat, std::option std::vector renderPassAttachments = {}; vk::AttachmentDescription colorAttachment = {}; - colorAttachment.format = Vulkan::colorFormatToVulkan(colorFormat); + colorAttachment.format = colorFormat; colorAttachment.samples = vk::SampleCountFlagBits::e1; colorAttachment.loadOp = vk::AttachmentLoadOp::eLoad; colorAttachment.storeOp = vk::AttachmentStoreOp::eStore; @@ -182,7 +182,7 @@ vk::RenderPass RendererVK::getRenderPass(PICA::ColorFmt colorFormat, std::option if (depthFormat.has_value()) { vk::AttachmentDescription depthAttachment = {}; - depthAttachment.format = Vulkan::depthFormatToVulkan(depthFormat.value()); + depthAttachment.format = depthFormat.value(); depthAttachment.samples = vk::SampleCountFlagBits::e1; depthAttachment.loadOp = vk::AttachmentLoadOp::eLoad; depthAttachment.storeOp = vk::AttachmentStoreOp::eStore; @@ -229,6 +229,14 @@ vk::RenderPass RendererVK::getRenderPass(PICA::ColorFmt colorFormat, std::option return {}; } +vk::RenderPass RendererVK::getRenderPass(PICA::ColorFmt colorFormat, std::optional depthFormat) { + if (depthFormat.has_value()) { + return getRenderPass(Vulkan::colorFormatToVulkan(colorFormat), Vulkan::depthFormatToVulkan(depthFormat.value())); + } else { + return getRenderPass(Vulkan::colorFormatToVulkan(colorFormat), {}); + } +} + vk::Result RendererVK::recreateSwapchain(vk::SurfaceKHR surface, vk::Extent2D swapchainExtent) { static constexpr u32 screenTextureWidth = 400; // Top screen is 400 pixels wide, bottom is 320 static constexpr u32 screenTextureHeight = 2 * 240; // Both screens are 240 pixels tall