Skip to content

Commit a8e98ec

Browse files
Fix different queue support in offscreen swapchain
Make the command buffer submission that denotes the end of a frame be on the queue family which is being presented, rather than the default queue family. Previously, the command buffer/pool was used invalidly if the vkQueuePresentKHR call occured on a different queue family than the default.
1 parent 4626159 commit a8e98ec

File tree

2 files changed

+47
-38
lines changed

2 files changed

+47
-38
lines changed

framework/decode/vulkan_offscreen_swapchain.cpp

+45-36
Original file line numberDiff line numberDiff line change
@@ -103,38 +103,45 @@ VkResult VulkanOffscreenSwapchain::CreateSwapchainKHR(VkResult
103103
if (insert_frame_boundary_)
104104
{
105105
VkResult result;
106-
107-
VkCommandPoolCreateInfo commandPoolCreateInfo;
108-
commandPoolCreateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
109-
commandPoolCreateInfo.pNext = nullptr;
110-
commandPoolCreateInfo.queueFamilyIndex = default_queue_family_index_;
111-
commandPoolCreateInfo.flags = 0;
112-
113-
result = device_table_->CreateCommandPool(device, &commandPoolCreateInfo, nullptr, &command_pool_);
114-
GFXRECON_ASSERT(result == VK_SUCCESS);
115-
116-
VkCommandBufferAllocateInfo commandBufferAllocateInfo;
117-
commandBufferAllocateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
118-
commandBufferAllocateInfo.pNext = nullptr;
119-
commandBufferAllocateInfo.commandPool = command_pool_;
120-
commandBufferAllocateInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
121-
commandBufferAllocateInfo.commandBufferCount = 1;
122-
123-
result = device_table_->AllocateCommandBuffers(device, &commandBufferAllocateInfo, &command_buffer_);
124-
GFXRECON_ASSERT(result == VK_SUCCESS);
125-
126-
VkCommandBufferBeginInfo commandBufferBeginInfo;
127-
commandBufferBeginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
128-
commandBufferBeginInfo.pNext = nullptr;
129-
commandBufferBeginInfo.flags = 0;
130-
commandBufferBeginInfo.pInheritanceInfo = nullptr;
131-
132-
result = device_table_->BeginCommandBuffer(command_buffer_, &commandBufferBeginInfo);
133-
GFXRECON_ASSERT(result == VK_SUCCESS);
134-
135-
result = device_table_->EndCommandBuffer(command_buffer_);
136-
GFXRECON_ASSERT(result == VK_SUCCESS);
137-
106+
command_pools_.resize(device_info->queue_family_index_enabled.size());
107+
command_buffers_.resize(device_info->queue_family_index_enabled.size());
108+
109+
for (uint32_t family_index = 0; family_index < device_info->queue_family_index_enabled.size(); family_index++) {
110+
if (!device_info->queue_family_index_enabled.at(family_index)) {
111+
continue;
112+
}
113+
114+
VkCommandPoolCreateInfo commandPoolCreateInfo;
115+
commandPoolCreateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
116+
commandPoolCreateInfo.pNext = nullptr;
117+
commandPoolCreateInfo.queueFamilyIndex = family_index;
118+
commandPoolCreateInfo.flags = 0;
119+
120+
result = device_table_->CreateCommandPool(device, &commandPoolCreateInfo, nullptr, &command_pools_.at(family_index));
121+
GFXRECON_ASSERT(result == VK_SUCCESS);
122+
123+
VkCommandBufferAllocateInfo commandBufferAllocateInfo;
124+
commandBufferAllocateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
125+
commandBufferAllocateInfo.pNext = nullptr;
126+
commandBufferAllocateInfo.commandPool = command_pools_.at(family_index);
127+
commandBufferAllocateInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
128+
commandBufferAllocateInfo.commandBufferCount = 1;
129+
130+
result = device_table_->AllocateCommandBuffers(device, &commandBufferAllocateInfo, &command_buffers_.at(family_index));
131+
GFXRECON_ASSERT(result == VK_SUCCESS);
132+
133+
VkCommandBufferBeginInfo commandBufferBeginInfo;
134+
commandBufferBeginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
135+
commandBufferBeginInfo.pNext = nullptr;
136+
commandBufferBeginInfo.flags = 0;
137+
commandBufferBeginInfo.pInheritanceInfo = nullptr;
138+
139+
result = device_table_->BeginCommandBuffer(command_buffers_.at(family_index), &commandBufferBeginInfo);
140+
GFXRECON_ASSERT(result == VK_SUCCESS);
141+
142+
result = device_table_->EndCommandBuffer(command_buffers_.at(family_index));
143+
GFXRECON_ASSERT(result == VK_SUCCESS);
144+
}
138145
frame_boundary_.sType = VK_STRUCTURE_TYPE_FRAME_BOUNDARY_EXT;
139146
frame_boundary_.pNext = nullptr;
140147
frame_boundary_.flags = VK_FRAME_BOUNDARY_FRAME_END_BIT_EXT;
@@ -161,9 +168,11 @@ void VulkanOffscreenSwapchain::DestroySwapchainKHR(PFN_vkDestroySwapchainKHR
161168
CleanSwapchainResourceData(device_info, swapchain_info);
162169
}
163170

164-
if (insert_frame_boundary_ && command_pool_ != VK_NULL_HANDLE)
171+
if (insert_frame_boundary_ && command_pools_.size() > 0)
165172
{
166-
device_table_->DestroyCommandPool(device_info->handle, command_pool_, nullptr);
173+
for (const auto& command_pool : command_pools_){
174+
device_table_->DestroyCommandPool(device_info->handle, command_pool, nullptr);
175+
}
167176
}
168177
}
169178

@@ -276,7 +285,7 @@ VkResult VulkanOffscreenSwapchain::QueuePresentKHR(VkResult
276285
const QueueInfo* queue_info,
277286
const VkPresentInfoKHR* present_info)
278287
{
279-
if (insert_frame_boundary_ && command_buffer_ != VK_NULL_HANDLE)
288+
if (insert_frame_boundary_ && command_buffers_.size() > 0)
280289
{
281290
std::vector<VkImage> images(present_info->swapchainCount);
282291
for (uint32_t i = 0; i < images.size(); ++i)
@@ -299,7 +308,7 @@ VkResult VulkanOffscreenSwapchain::QueuePresentKHR(VkResult
299308
submitInfo.pWaitSemaphores = present_info->pWaitSemaphores;
300309
submitInfo.pWaitDstStageMask = dstStageFlags.data();
301310
submitInfo.commandBufferCount = 1;
302-
submitInfo.pCommandBuffers = &command_buffer_;
311+
submitInfo.pCommandBuffers = &command_buffers_.at(queue_info->family_index);
303312
submitInfo.signalSemaphoreCount = 0;
304313
submitInfo.pSignalSemaphores = nullptr;
305314

framework/decode/vulkan_offscreen_swapchain.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ class VulkanOffscreenSwapchain : public VulkanVirtualSwapchain
107107
VkFence fence);
108108

109109
bool insert_frame_boundary_{ false };
110-
VkCommandPool command_pool_{ VK_NULL_HANDLE };
111-
VkCommandBuffer command_buffer_{ VK_NULL_HANDLE };
110+
std::vector<VkCommandPool> command_pools_{ VK_NULL_HANDLE };
111+
std::vector<VkCommandBuffer> command_buffers_{ VK_NULL_HANDLE };
112112
VkFrameBoundaryEXT frame_boundary_;
113113
};
114114

0 commit comments

Comments
 (0)