From 61de98d651d36235c238f24d9c45dc541697b076 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sat, 22 Oct 2022 21:16:12 +1000 Subject: [PATCH] Vulkan: Support running surfaceless --- common/Vulkan/Context.cpp | 7 +++---- pcsx2/Frontend/VulkanHostDisplay.cpp | 7 ++++++- pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp | 12 +++++------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/common/Vulkan/Context.cpp b/common/Vulkan/Context.cpp index 33ee58321b..db275d09ba 100644 --- a/common/Vulkan/Context.cpp +++ b/common/Vulkan/Context.cpp @@ -536,7 +536,7 @@ namespace Vulkan Console.Error("Vulkan: Failed to find an acceptable graphics queue."); return false; } - if (surface && m_present_queue_family_index == queue_family_count) + if (surface != VK_NULL_HANDLE && m_present_queue_family_index == queue_family_count) { Console.Error("Vulkan: Failed to find an acceptable present queue."); return false; @@ -570,7 +570,7 @@ namespace Vulkan }}; device_info.queueCreateInfoCount = 1; - if (m_graphics_queue_family_index != m_present_queue_family_index) + if (surface != VK_NULL_HANDLE && m_graphics_queue_family_index != m_present_queue_family_index) { device_info.queueCreateInfoCount = 2; } @@ -1445,8 +1445,7 @@ namespace Vulkan } const VkSubpassDescriptionFlags subpass_flags = - (key.color_feedback_loop && g_vulkan_context->GetOptionalExtensions().vk_arm_rasterization_order_attachment_access) - ? VK_SUBPASS_DESCRIPTION_RASTERIZATION_ORDER_ATTACHMENT_COLOR_ACCESS_BIT_ARM : 0; + (key.color_feedback_loop && g_vulkan_context->GetOptionalExtensions().vk_arm_rasterization_order_attachment_access) ? VK_SUBPASS_DESCRIPTION_RASTERIZATION_ORDER_ATTACHMENT_COLOR_ACCESS_BIT_ARM : 0; const VkSubpassDescription subpass = {subpass_flags, VK_PIPELINE_BIND_POINT_GRAPHICS, input_reference_ptr ? 1u : 0u, input_reference_ptr ? input_reference_ptr : nullptr, color_reference_ptr ? 1u : 0u, color_reference_ptr ? color_reference_ptr : nullptr, nullptr, depth_reference_ptr, 0, nullptr}; diff --git a/pcsx2/Frontend/VulkanHostDisplay.cpp b/pcsx2/Frontend/VulkanHostDisplay.cpp index 2cefb50225..aee303647c 100644 --- a/pcsx2/Frontend/VulkanHostDisplay.cpp +++ b/pcsx2/Frontend/VulkanHostDisplay.cpp @@ -311,7 +311,12 @@ bool VulkanHostDisplay::HasSurface() const bool VulkanHostDisplay::CreateImGuiContext() { - return ImGui_ImplVulkan_Init(m_swap_chain->GetClearRenderPass()); + const VkRenderPass render_pass = + m_swap_chain ? m_swap_chain->GetClearRenderPass() : g_vulkan_context->GetRenderPass(VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_UNDEFINED); + if (render_pass == VK_NULL_HANDLE) + return false; + + return ImGui_ImplVulkan_Init(render_pass); } void VulkanHostDisplay::DestroyImGuiContext() diff --git a/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp b/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp index db5b4cccb0..ed8c2f74f7 100644 --- a/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp +++ b/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp @@ -1513,13 +1513,11 @@ bool GSDeviceVK::CompilePresentPipelines() { // we may not have a swap chain if running in headless mode. Vulkan::SwapChain* swapchain = static_cast(g_host_display->GetSurface()); - if (swapchain) - { - m_swap_chain_render_pass = - g_vulkan_context->GetRenderPass(swapchain->GetSurfaceFormat().format, VK_FORMAT_UNDEFINED); - if (!m_swap_chain_render_pass) - return false; - } + m_swap_chain_render_pass = swapchain ? + swapchain->GetClearRenderPass() : + g_vulkan_context->GetRenderPass(VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_UNDEFINED); + if (!m_swap_chain_render_pass) + return false; std::optional shader = Host::ReadResourceFileToString("shaders/vulkan/present.glsl"); if (!shader)