mirror of https://github.com/PCSX2/pcsx2.git
Vulkan/Context: Pass swap chain through to submission
Simplifies things a bit.
This commit is contained in:
parent
7d572ff794
commit
93bd95f4bd
|
@ -1129,9 +1129,7 @@ namespace Vulkan
|
||||||
m_completed_fence_counter = now_completed_counter;
|
m_completed_fence_counter = now_completed_counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Context::SubmitCommandBuffer(VkSemaphore wait_semaphore /* = VK_NULL_HANDLE */,
|
void Context::SubmitCommandBuffer(SwapChain* present_swap_chain /* = nullptr */, bool submit_on_thread /* = false */)
|
||||||
VkSemaphore signal_semaphore /* = VK_NULL_HANDLE */, VkSwapchainKHR present_swap_chain /* = VK_NULL_HANDLE */,
|
|
||||||
uint32_t present_image_index /* = 0xFFFFFFFF */, bool submit_on_thread /* = false */)
|
|
||||||
{
|
{
|
||||||
FrameResources& resources = m_frame_resources[m_current_frame];
|
FrameResources& resources = m_frame_resources[m_current_frame];
|
||||||
|
|
||||||
|
@ -1204,23 +1202,20 @@ namespace Vulkan
|
||||||
|
|
||||||
if (!submit_on_thread || !m_present_thread.joinable())
|
if (!submit_on_thread || !m_present_thread.joinable())
|
||||||
{
|
{
|
||||||
DoSubmitCommandBuffer(m_current_frame, wait_semaphore, signal_semaphore, spin_cycles);
|
DoSubmitCommandBuffer(m_current_frame, present_swap_chain, spin_cycles);
|
||||||
if (present_swap_chain != VK_NULL_HANDLE)
|
if (present_swap_chain)
|
||||||
DoPresent(signal_semaphore, present_swap_chain, present_image_index);
|
DoPresent(present_swap_chain);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_queued_present.command_buffer_index = m_current_frame;
|
m_queued_present.command_buffer_index = m_current_frame;
|
||||||
m_queued_present.present_swap_chain = present_swap_chain;
|
m_queued_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.spin_cycles = spin_cycles;
|
m_queued_present.spin_cycles = spin_cycles;
|
||||||
m_present_done.store(false);
|
m_present_done.store(false);
|
||||||
m_present_queued_cv.notify_one();
|
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];
|
FrameResources& resources = m_frame_resources[index];
|
||||||
|
|
||||||
|
@ -1230,24 +1225,24 @@ namespace Vulkan
|
||||||
submit_info.commandBufferCount = resources.init_buffer_used ? 2u : 1u;
|
submit_info.commandBufferCount = resources.init_buffer_used ? 2u : 1u;
|
||||||
submit_info.pCommandBuffers = resources.init_buffer_used ? resources.command_buffers.data() : &resources.command_buffers[1];
|
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.waitSemaphoreCount = 1;
|
||||||
submit_info.pWaitDstStageMask = &wait_bits;
|
submit_info.pWaitDstStageMask = &wait_bits;
|
||||||
}
|
|
||||||
|
|
||||||
if (signal_semaphore != VK_NULL_HANDLE && spin_cycles != 0)
|
if (spin_cycles != 0)
|
||||||
{
|
{
|
||||||
semas[0] = signal_semaphore;
|
semas[0] = present_swap_chain->GetRenderingFinishedSemaphore();
|
||||||
semas[1] = m_spin_resources[index].semaphore;
|
semas[1] = m_spin_resources[index].semaphore;
|
||||||
submit_info.signalSemaphoreCount = 2;
|
submit_info.signalSemaphoreCount = 2;
|
||||||
submit_info.pSignalSemaphores = semas;
|
submit_info.pSignalSemaphores = semas;
|
||||||
}
|
}
|
||||||
else if (signal_semaphore != VK_NULL_HANDLE)
|
else
|
||||||
{
|
{
|
||||||
|
submit_info.pSignalSemaphores = present_swap_chain->GetRenderingFinishedSemaphorePtr();
|
||||||
submit_info.signalSemaphoreCount = 1;
|
submit_info.signalSemaphoreCount = 1;
|
||||||
submit_info.pSignalSemaphores = &signal_semaphore;
|
}
|
||||||
}
|
}
|
||||||
else if (spin_cycles != 0)
|
else if (spin_cycles != 0)
|
||||||
{
|
{
|
||||||
|
@ -1266,12 +1261,12 @@ namespace Vulkan
|
||||||
SubmitSpinCommand(index, spin_cycles);
|
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.
|
const VkPresentInfoKHR present_info = {VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, nullptr,
|
||||||
pxAssert(wait_semaphore != VK_NULL_HANDLE);
|
1, present_swap_chain->GetRenderingFinishedSemaphorePtr(),
|
||||||
VkPresentInfoKHR present_info = {VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, nullptr, 1, &wait_semaphore, 1,
|
1, present_swap_chain->GetSwapChainPtr(), present_swap_chain->GetCurrentImageIndexPtr(),
|
||||||
&present_swap_chain, &present_image_index, nullptr};
|
nullptr};
|
||||||
|
|
||||||
VkResult res = vkQueuePresentKHR(m_present_queue, &present_info);
|
VkResult res = vkQueuePresentKHR(m_present_queue, &present_info);
|
||||||
if (res != VK_SUCCESS)
|
if (res != VK_SUCCESS)
|
||||||
|
@ -1311,10 +1306,9 @@ namespace Vulkan
|
||||||
if (m_present_done.load())
|
if (m_present_done.load())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
DoSubmitCommandBuffer(m_queued_present.command_buffer_index, m_queued_present.wait_semaphore,
|
DoSubmitCommandBuffer(m_queued_present.command_buffer_index, m_queued_present.swap_chain, m_queued_present.spin_cycles);
|
||||||
m_queued_present.signal_semaphore, m_queued_present.spin_cycles);
|
if (m_queued_present.swap_chain)
|
||||||
DoPresent(m_queued_present.signal_semaphore, m_queued_present.present_swap_chain,
|
DoPresent(m_queued_present.swap_chain);
|
||||||
m_queued_present.present_image_index);
|
|
||||||
m_present_done.store(true);
|
m_present_done.store(true);
|
||||||
m_present_done_cv.notify_one();
|
m_present_done_cv.notify_one();
|
||||||
}
|
}
|
||||||
|
|
|
@ -193,9 +193,7 @@ namespace Vulkan
|
||||||
// queued and executed. Do not wait for this fence before the buffer is executed.
|
// 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; }
|
u64 GetCurrentFenceCounter() const { return m_frame_resources[m_current_frame].fence_counter; }
|
||||||
|
|
||||||
void SubmitCommandBuffer(VkSemaphore wait_semaphore = VK_NULL_HANDLE,
|
void SubmitCommandBuffer(SwapChain* present_swap_chain = nullptr, bool submit_on_thread = false);
|
||||||
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 MoveToNextCommandBuffer();
|
void MoveToNextCommandBuffer();
|
||||||
|
|
||||||
enum class WaitType
|
enum class WaitType
|
||||||
|
@ -283,8 +281,8 @@ namespace Vulkan
|
||||||
void ScanForCommandBufferCompletion();
|
void ScanForCommandBufferCompletion();
|
||||||
void WaitForCommandBufferCompletion(u32 index);
|
void WaitForCommandBufferCompletion(u32 index);
|
||||||
|
|
||||||
void DoSubmitCommandBuffer(u32 index, VkSemaphore wait_semaphore, VkSemaphore signal_semaphore, u32 spin_cycles);
|
void DoSubmitCommandBuffer(u32 index, SwapChain* present_swap_chain, u32 spin_cycles);
|
||||||
void DoPresent(VkSemaphore wait_semaphore, VkSwapchainKHR present_swap_chain, uint32_t present_image_index);
|
void DoPresent(SwapChain* present_swap_chain);
|
||||||
void WaitForPresentComplete(std::unique_lock<std::mutex>& lock);
|
void WaitForPresentComplete(std::unique_lock<std::mutex>& lock);
|
||||||
void PresentThread();
|
void PresentThread();
|
||||||
void StartPresentThread();
|
void StartPresentThread();
|
||||||
|
@ -384,11 +382,8 @@ namespace Vulkan
|
||||||
|
|
||||||
struct QueuedPresent
|
struct QueuedPresent
|
||||||
{
|
{
|
||||||
VkSemaphore wait_semaphore;
|
SwapChain* swap_chain;
|
||||||
VkSemaphore signal_semaphore;
|
|
||||||
VkSwapchainKHR present_swap_chain;
|
|
||||||
u32 command_buffer_index;
|
u32 command_buffer_index;
|
||||||
u32 present_image_index;
|
|
||||||
u32 spin_cycles;
|
u32 spin_cycles;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -55,11 +55,13 @@ namespace Vulkan
|
||||||
__fi VkFormat GetTextureFormat() const { return m_surface_format.format; }
|
__fi VkFormat GetTextureFormat() const { return m_surface_format.format; }
|
||||||
__fi VkPresentModeKHR GetPreferredPresentMode() const { return m_preferred_present_mode; }
|
__fi VkPresentModeKHR GetPreferredPresentMode() const { return m_preferred_present_mode; }
|
||||||
__fi VkSwapchainKHR GetSwapChain() const { return m_swap_chain; }
|
__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 const WindowInfo& GetWindowInfo() const { return m_window_info; }
|
||||||
__fi u32 GetWidth() const { return m_window_info.surface_width; }
|
__fi u32 GetWidth() const { return m_window_info.surface_width; }
|
||||||
__fi u32 GetHeight() const { return m_window_info.surface_height; }
|
__fi u32 GetHeight() const { return m_window_info.surface_height; }
|
||||||
__fi float GetScale() const { return m_window_info.surface_scale; }
|
__fi float GetScale() const { return m_window_info.surface_scale; }
|
||||||
__fi u32 GetCurrentImageIndex() const { return m_current_image; }
|
__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 u32 GetImageCount() const { return static_cast<u32>(m_images.size()); }
|
||||||
__fi VkImage GetCurrentImage() const { return m_images[m_current_image].image; }
|
__fi VkImage GetCurrentImage() const { return m_images[m_current_image].image; }
|
||||||
__fi const Texture& GetCurrentTexture() const { return m_images[m_current_image].texture; }
|
__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 GetLoadRenderPass() const { return m_load_render_pass; }
|
||||||
__fi VkRenderPass GetClearRenderPass() const { return m_clear_render_pass; }
|
__fi VkRenderPass GetClearRenderPass() const { return m_clear_render_pass; }
|
||||||
__fi VkSemaphore GetImageAvailableSemaphore() const { return m_images[m_current_image].available_semaphore; }
|
__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 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();
|
VkResult AcquireNextImage();
|
||||||
|
|
||||||
bool RecreateSurface(const WindowInfo& new_wi);
|
bool RecreateSurface(const WindowInfo& new_wi);
|
||||||
|
|
|
@ -411,8 +411,7 @@ void VulkanHostDisplay::EndPresent()
|
||||||
vkCmdEndRenderPass(g_vulkan_context->GetCurrentCommandBuffer());
|
vkCmdEndRenderPass(g_vulkan_context->GetCurrentCommandBuffer());
|
||||||
m_swap_chain->GetCurrentTexture().TransitionToLayout(cmdbuffer, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
|
m_swap_chain->GetCurrentTexture().TransitionToLayout(cmdbuffer, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
|
||||||
|
|
||||||
g_vulkan_context->SubmitCommandBuffer(m_swap_chain->GetImageAvailableSemaphore(), m_swap_chain->GetRenderingFinishedSemaphore(),
|
g_vulkan_context->SubmitCommandBuffer(m_swap_chain.get(), !m_swap_chain->IsPresentModeSynchronizing());
|
||||||
m_swap_chain->GetSwapChain(), m_swap_chain->GetCurrentImageIndex(), !m_swap_chain->IsPresentModeSynchronizing());
|
|
||||||
g_vulkan_context->MoveToNextCommandBuffer();
|
g_vulkan_context->MoveToNextCommandBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue