[Vulkan] Support usage of the primary queue in the swap chain

This commit is contained in:
DrChat 2017-12-19 23:08:27 -06:00
parent 0a75f68e88
commit 45846f25ac
2 changed files with 37 additions and 4 deletions

View File

@ -65,11 +65,18 @@ VkResult VulkanSwapChain::Initialize(VkSurfaceKHR surface) {
return VK_ERROR_INCOMPATIBLE_DRIVER; return VK_ERROR_INCOMPATIBLE_DRIVER;
} }
presentation_queue_family_ = queue_family_index;
presentation_queue_ = device_->AcquireQueue(queue_family_index); presentation_queue_ = device_->AcquireQueue(queue_family_index);
presentation_queue_family_ = queue_family_index;
if (!presentation_queue_) { if (!presentation_queue_) {
XELOGE("Failed to acquire swap chain presentation queue!"); // That's okay, use the primary queue.
return VK_ERROR_INITIALIZATION_FAILED; presentation_queue_ = device_->primary_queue();
presentation_queue_mutex_ = &device_->primary_queue_mutex();
presentation_queue_family_ = device_->queue_family_index();
if (!presentation_queue_) {
XELOGE("Failed to acquire swap chain presentation queue!");
return VK_ERROR_INITIALIZATION_FAILED;
}
} }
// Query supported target formats. // Query supported target formats.
@ -459,8 +466,12 @@ void VulkanSwapChain::Shutdown() {
cmd_pool_ = nullptr; cmd_pool_ = nullptr;
} }
if (presentation_queue_) { if (presentation_queue_) {
device_->ReleaseQueue(presentation_queue_, presentation_queue_family_); if (!presentation_queue_mutex_) {
// We own the queue and need to release it.
device_->ReleaseQueue(presentation_queue_, presentation_queue_family_);
}
presentation_queue_ = nullptr; presentation_queue_ = nullptr;
presentation_queue_mutex_ = nullptr;
presentation_queue_family_ = -1; presentation_queue_family_ = -1;
} }
// images_ doesn't need to be cleaned up as the swapchain does it implicitly. // images_ doesn't need to be cleaned up as the swapchain does it implicitly.
@ -502,7 +513,13 @@ VkResult VulkanSwapChain::Begin() {
wait_submit_info.pCommandBuffers = nullptr; wait_submit_info.pCommandBuffers = nullptr;
wait_submit_info.signalSemaphoreCount = 1; wait_submit_info.signalSemaphoreCount = 1;
wait_submit_info.pSignalSemaphores = &image_usage_semaphore_; wait_submit_info.pSignalSemaphores = &image_usage_semaphore_;
if (presentation_queue_mutex_) {
presentation_queue_mutex_->lock();
}
status = vkQueueSubmit(presentation_queue_, 1, &wait_submit_info, nullptr); status = vkQueueSubmit(presentation_queue_, 1, &wait_submit_info, nullptr);
if (presentation_queue_mutex_) {
presentation_queue_mutex_->unlock();
}
if (status != VK_SUCCESS) { if (status != VK_SUCCESS) {
return status; return status;
} }
@ -714,7 +731,14 @@ VkResult VulkanSwapChain::End() {
render_submit_info.pCommandBuffers = &cmd_buffer_; render_submit_info.pCommandBuffers = &cmd_buffer_;
render_submit_info.signalSemaphoreCount = uint32_t(semaphores.size()) - 1; render_submit_info.signalSemaphoreCount = uint32_t(semaphores.size()) - 1;
render_submit_info.pSignalSemaphores = semaphores.data(); render_submit_info.pSignalSemaphores = semaphores.data();
if (presentation_queue_mutex_) {
presentation_queue_mutex_->lock();
}
status = vkQueueSubmit(presentation_queue_, 1, &render_submit_info, nullptr); status = vkQueueSubmit(presentation_queue_, 1, &render_submit_info, nullptr);
if (presentation_queue_mutex_) {
presentation_queue_mutex_->unlock();
}
if (status != VK_SUCCESS) { if (status != VK_SUCCESS) {
return status; return status;
} }
@ -731,7 +755,14 @@ VkResult VulkanSwapChain::End() {
present_info.pSwapchains = swap_chains; present_info.pSwapchains = swap_chains;
present_info.pImageIndices = swap_chain_image_indices; present_info.pImageIndices = swap_chain_image_indices;
present_info.pResults = nullptr; present_info.pResults = nullptr;
if (presentation_queue_mutex_) {
presentation_queue_mutex_->lock();
}
status = vkQueuePresentKHR(presentation_queue_, &present_info); status = vkQueuePresentKHR(presentation_queue_, &present_info);
if (presentation_queue_mutex_) {
presentation_queue_mutex_->unlock();
}
switch (status) { switch (status) {
case VK_SUCCESS: case VK_SUCCESS:
break; break;

View File

@ -11,6 +11,7 @@
#define XENIA_UI_VULKAN_VULKAN_SWAP_CHAIN_H_ #define XENIA_UI_VULKAN_VULKAN_SWAP_CHAIN_H_
#include <memory> #include <memory>
#include <mutex>
#include <string> #include <string>
#include <vector> #include <vector>
@ -79,6 +80,7 @@ class VulkanSwapChain {
VulkanDevice* device_ = nullptr; VulkanDevice* device_ = nullptr;
VkQueue presentation_queue_ = nullptr; VkQueue presentation_queue_ = nullptr;
std::mutex* presentation_queue_mutex_ = nullptr;
uint32_t presentation_queue_family_ = -1; uint32_t presentation_queue_family_ = -1;
VkSurfaceKHR surface_ = nullptr; VkSurfaceKHR surface_ = nullptr;
uint32_t surface_width_ = 0; uint32_t surface_width_ = 0;