Vulkan/Context: Pass swap chain through to submission

Simplifies things a bit.
This commit is contained in:
Stenzek 2023-01-06 21:44:49 +10:00 committed by refractionpcsx2
parent 7d572ff794
commit 93bd95f4bd
4 changed files with 37 additions and 45 deletions

View File

@ -1129,9 +1129,7 @@ namespace Vulkan
m_completed_fence_counter = now_completed_counter;
}
void Context::SubmitCommandBuffer(VkSemaphore wait_semaphore /* = VK_NULL_HANDLE */,
VkSemaphore signal_semaphore /* = VK_NULL_HANDLE */, VkSwapchainKHR present_swap_chain /* = VK_NULL_HANDLE */,
uint32_t present_image_index /* = 0xFFFFFFFF */, bool submit_on_thread /* = false */)
void Context::SubmitCommandBuffer(SwapChain* present_swap_chain /* = nullptr */, bool submit_on_thread /* = false */)
{
FrameResources& resources = m_frame_resources[m_current_frame];
@ -1204,23 +1202,20 @@ namespace Vulkan
if (!submit_on_thread || !m_present_thread.joinable())
{
DoSubmitCommandBuffer(m_current_frame, wait_semaphore, signal_semaphore, spin_cycles);
if (present_swap_chain != VK_NULL_HANDLE)
DoPresent(signal_semaphore, present_swap_chain, present_image_index);
DoSubmitCommandBuffer(m_current_frame, present_swap_chain, spin_cycles);
if (present_swap_chain)
DoPresent(present_swap_chain);
return;
}
m_queued_present.command_buffer_index = m_current_frame;
m_queued_present.present_swap_chain = present_swap_chain;
m_queued_present.present_image_index = present_image_index;
m_queued_present.wait_semaphore = wait_semaphore;
m_queued_present.signal_semaphore = signal_semaphore;
m_queued_present.swap_chain = present_swap_chain;
m_queued_present.spin_cycles = spin_cycles;
m_present_done.store(false);
m_present_queued_cv.notify_one();
}
void Context::DoSubmitCommandBuffer(u32 index, VkSemaphore wait_semaphore, VkSemaphore signal_semaphore, u32 spin_cycles)
void Context::DoSubmitCommandBuffer(u32 index, SwapChain* present_swap_chain, u32 spin_cycles)
{
FrameResources& resources = m_frame_resources[index];
@ -1230,24 +1225,24 @@ namespace Vulkan
submit_info.commandBufferCount = resources.init_buffer_used ? 2u : 1u;
submit_info.pCommandBuffers = resources.init_buffer_used ? resources.command_buffers.data() : &resources.command_buffers[1];
if (wait_semaphore != VK_NULL_HANDLE)
if (present_swap_chain)
{
submit_info.pWaitSemaphores = &wait_semaphore;
submit_info.pWaitSemaphores = present_swap_chain->GetImageAvailableSemaphorePtr();
submit_info.waitSemaphoreCount = 1;
submit_info.pWaitDstStageMask = &wait_bits;
}
if (signal_semaphore != VK_NULL_HANDLE && spin_cycles != 0)
{
semas[0] = signal_semaphore;
semas[1] = m_spin_resources[index].semaphore;
submit_info.signalSemaphoreCount = 2;
submit_info.pSignalSemaphores = semas;
}
else if (signal_semaphore != VK_NULL_HANDLE)
{
submit_info.signalSemaphoreCount = 1;
submit_info.pSignalSemaphores = &signal_semaphore;
if (spin_cycles != 0)
{
semas[0] = present_swap_chain->GetRenderingFinishedSemaphore();
semas[1] = m_spin_resources[index].semaphore;
submit_info.signalSemaphoreCount = 2;
submit_info.pSignalSemaphores = semas;
}
else
{
submit_info.pSignalSemaphores = present_swap_chain->GetRenderingFinishedSemaphorePtr();
submit_info.signalSemaphoreCount = 1;
}
}
else if (spin_cycles != 0)
{
@ -1266,12 +1261,12 @@ namespace Vulkan
SubmitSpinCommand(index, spin_cycles);
}
void Context::DoPresent(VkSemaphore wait_semaphore, VkSwapchainKHR present_swap_chain, uint32_t present_image_index)
void Context::DoPresent(SwapChain* present_swap_chain)
{
// Should have a signal semaphore.
pxAssert(wait_semaphore != VK_NULL_HANDLE);
VkPresentInfoKHR present_info = {VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, nullptr, 1, &wait_semaphore, 1,
&present_swap_chain, &present_image_index, nullptr};
const VkPresentInfoKHR present_info = {VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, nullptr,
1, present_swap_chain->GetRenderingFinishedSemaphorePtr(),
1, present_swap_chain->GetSwapChainPtr(), present_swap_chain->GetCurrentImageIndexPtr(),
nullptr};
VkResult res = vkQueuePresentKHR(m_present_queue, &present_info);
if (res != VK_SUCCESS)
@ -1311,10 +1306,9 @@ namespace Vulkan
if (m_present_done.load())
continue;
DoSubmitCommandBuffer(m_queued_present.command_buffer_index, m_queued_present.wait_semaphore,
m_queued_present.signal_semaphore, m_queued_present.spin_cycles);
DoPresent(m_queued_present.signal_semaphore, m_queued_present.present_swap_chain,
m_queued_present.present_image_index);
DoSubmitCommandBuffer(m_queued_present.command_buffer_index, m_queued_present.swap_chain, m_queued_present.spin_cycles);
if (m_queued_present.swap_chain)
DoPresent(m_queued_present.swap_chain);
m_present_done.store(true);
m_present_done_cv.notify_one();
}

View File

@ -193,9 +193,7 @@ namespace Vulkan
// queued and executed. Do not wait for this fence before the buffer is executed.
u64 GetCurrentFenceCounter() const { return m_frame_resources[m_current_frame].fence_counter; }
void SubmitCommandBuffer(VkSemaphore wait_semaphore = VK_NULL_HANDLE,
VkSemaphore signal_semaphore = VK_NULL_HANDLE, VkSwapchainKHR present_swap_chain = VK_NULL_HANDLE,
uint32_t present_image_index = 0xFFFFFFFF, bool submit_on_thread = false);
void SubmitCommandBuffer(SwapChain* present_swap_chain = nullptr, bool submit_on_thread = false);
void MoveToNextCommandBuffer();
enum class WaitType
@ -283,8 +281,8 @@ namespace Vulkan
void ScanForCommandBufferCompletion();
void WaitForCommandBufferCompletion(u32 index);
void DoSubmitCommandBuffer(u32 index, VkSemaphore wait_semaphore, VkSemaphore signal_semaphore, u32 spin_cycles);
void DoPresent(VkSemaphore wait_semaphore, VkSwapchainKHR present_swap_chain, uint32_t present_image_index);
void DoSubmitCommandBuffer(u32 index, SwapChain* present_swap_chain, u32 spin_cycles);
void DoPresent(SwapChain* present_swap_chain);
void WaitForPresentComplete(std::unique_lock<std::mutex>& lock);
void PresentThread();
void StartPresentThread();
@ -384,11 +382,8 @@ namespace Vulkan
struct QueuedPresent
{
VkSemaphore wait_semaphore;
VkSemaphore signal_semaphore;
VkSwapchainKHR present_swap_chain;
SwapChain* swap_chain;
u32 command_buffer_index;
u32 present_image_index;
u32 spin_cycles;
};

View File

@ -55,11 +55,13 @@ namespace Vulkan
__fi VkFormat GetTextureFormat() const { return m_surface_format.format; }
__fi VkPresentModeKHR GetPreferredPresentMode() const { return m_preferred_present_mode; }
__fi VkSwapchainKHR GetSwapChain() const { return m_swap_chain; }
__fi const VkSwapchainKHR* GetSwapChainPtr() const { return &m_swap_chain; }
__fi const WindowInfo& GetWindowInfo() const { return m_window_info; }
__fi u32 GetWidth() const { return m_window_info.surface_width; }
__fi u32 GetHeight() const { return m_window_info.surface_height; }
__fi float GetScale() const { return m_window_info.surface_scale; }
__fi u32 GetCurrentImageIndex() const { return m_current_image; }
__fi const u32* GetCurrentImageIndexPtr() const { return &m_current_image; }
__fi u32 GetImageCount() const { return static_cast<u32>(m_images.size()); }
__fi VkImage GetCurrentImage() const { return m_images[m_current_image].image; }
__fi const Texture& GetCurrentTexture() const { return m_images[m_current_image].texture; }
@ -68,7 +70,9 @@ namespace Vulkan
__fi VkRenderPass GetLoadRenderPass() const { return m_load_render_pass; }
__fi VkRenderPass GetClearRenderPass() const { return m_clear_render_pass; }
__fi VkSemaphore GetImageAvailableSemaphore() const { return m_images[m_current_image].available_semaphore; }
__fi const VkSemaphore* GetImageAvailableSemaphorePtr() const { return &m_images[m_current_image].available_semaphore; }
__fi VkSemaphore GetRenderingFinishedSemaphore() const { return m_images[m_current_image].rendering_finished_semaphore; }
__fi const VkSemaphore* GetRenderingFinishedSemaphorePtr() const { return &m_images[m_current_image].rendering_finished_semaphore; }
VkResult AcquireNextImage();
bool RecreateSurface(const WindowInfo& new_wi);

View File

@ -411,8 +411,7 @@ void VulkanHostDisplay::EndPresent()
vkCmdEndRenderPass(g_vulkan_context->GetCurrentCommandBuffer());
m_swap_chain->GetCurrentTexture().TransitionToLayout(cmdbuffer, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
g_vulkan_context->SubmitCommandBuffer(m_swap_chain->GetImageAvailableSemaphore(), m_swap_chain->GetRenderingFinishedSemaphore(),
m_swap_chain->GetSwapChain(), m_swap_chain->GetCurrentImageIndex(), !m_swap_chain->IsPresentModeSynchronizing());
g_vulkan_context->SubmitCommandBuffer(m_swap_chain.get(), !m_swap_chain->IsPresentModeSynchronizing());
g_vulkan_context->MoveToNextCommandBuffer();
}