Skip to content

Commit e3a9cab

Browse files
Use vkQueueSubmit2()
1 parent e258c67 commit e3a9cab

File tree

2 files changed

+32
-23
lines changed

2 files changed

+32
-23
lines changed

lvk/vulkan/VulkanClasses.cpp

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,36 +1515,43 @@ lvk::SubmitHandle lvk::VulkanImmediateCommands::submit(const CommandBufferWrappe
15151515
LVK_ASSERT(wrapper.isEncoding_);
15161516
VK_ASSERT(vkEndCommandBuffer(wrapper.cmdBuf_));
15171517

1518-
const VkPipelineStageFlags waitStageMasks[] = {VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
1519-
VkSemaphore waitSemaphores[] = {VK_NULL_HANDLE, VK_NULL_HANDLE};
1518+
VkSemaphoreSubmitInfo waitSemaphores[] = {{}, {}};
15201519
uint32_t numWaitSemaphores = 0;
1521-
if (waitSemaphore_) {
1520+
if (waitSemaphore_.semaphore) {
15221521
waitSemaphores[numWaitSemaphores++] = waitSemaphore_;
15231522
}
1524-
if (lastSubmitSemaphore_) {
1523+
if (lastSubmitSemaphore_.semaphore) {
15251524
waitSemaphores[numWaitSemaphores++] = lastSubmitSemaphore_;
15261525
}
1526+
VkSemaphoreSubmitInfo signalSemaphores[] = {
1527+
VkSemaphoreSubmitInfo{.sType = VK_STRUCTURE_TYPE_SEMAPHORE_SUBMIT_INFO,
1528+
.semaphore = wrapper.semaphore_,
1529+
.stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT},
1530+
};
15271531

1528-
LVK_PROFILER_ZONE("vkQueueSubmit()", LVK_PROFILER_COLOR_SUBMIT);
1532+
LVK_PROFILER_ZONE("vkQueueSubmit2()", LVK_PROFILER_COLOR_SUBMIT);
15291533
#if LVK_VULKAN_PRINT_COMMANDS
1530-
LLOGL("%p vkQueueSubmit()\n\n", wrapper.cmdBuf_);
1534+
LLOGL("%p vkQueueSubmit2()\n\n", wrapper.cmdBuf_);
15311535
#endif // LVK_VULKAN_PRINT_COMMANDS
1532-
const VkSubmitInfo si = {
1533-
.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
1534-
.waitSemaphoreCount = numWaitSemaphores,
1535-
.pWaitSemaphores = numWaitSemaphores ? waitSemaphores : nullptr,
1536-
.pWaitDstStageMask = waitStageMasks,
1537-
.commandBufferCount = 1u,
1538-
.pCommandBuffers = &wrapper.cmdBuf_,
1539-
.signalSemaphoreCount = 1u,
1540-
.pSignalSemaphores = &wrapper.semaphore_,
1536+
const VkCommandBufferSubmitInfo bufferSI = {
1537+
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_SUBMIT_INFO,
1538+
.commandBuffer = wrapper.cmdBuf_,
1539+
};
1540+
const VkSubmitInfo2 si = {
1541+
.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO_2,
1542+
.waitSemaphoreInfoCount = numWaitSemaphores,
1543+
.pWaitSemaphoreInfos = waitSemaphores,
1544+
.commandBufferInfoCount = 1u,
1545+
.pCommandBufferInfos = &bufferSI,
1546+
.signalSemaphoreInfoCount = 1u,
1547+
.pSignalSemaphoreInfos = signalSemaphores,
15411548
};
1542-
VK_ASSERT(vkQueueSubmit(queue_, 1u, &si, wrapper.fence_));
1549+
VK_ASSERT(vkQueueSubmit2(queue_, 1u, &si,wrapper.fence_));
15431550
LVK_PROFILER_ZONE_END();
15441551

1545-
lastSubmitSemaphore_ = wrapper.semaphore_;
1552+
lastSubmitSemaphore_.semaphore = wrapper.semaphore_;
15461553
lastSubmitHandle_ = wrapper.handle_;
1547-
waitSemaphore_ = VK_NULL_HANDLE;
1554+
waitSemaphore_.semaphore = VK_NULL_HANDLE;
15481555

15491556
// reset
15501557
const_cast<CommandBufferWrapper&>(wrapper).isEncoding_ = false;
@@ -1559,13 +1566,13 @@ lvk::SubmitHandle lvk::VulkanImmediateCommands::submit(const CommandBufferWrappe
15591566
}
15601567

15611568
void lvk::VulkanImmediateCommands::waitSemaphore(VkSemaphore semaphore) {
1562-
LVK_ASSERT(waitSemaphore_ == VK_NULL_HANDLE);
1569+
LVK_ASSERT(waitSemaphore_.semaphore == VK_NULL_HANDLE);
15631570

1564-
waitSemaphore_ = semaphore;
1571+
waitSemaphore_.semaphore = semaphore;
15651572
}
15661573

15671574
VkSemaphore lvk::VulkanImmediateCommands::acquireLastSubmitSemaphore() {
1568-
return std::exchange(lastSubmitSemaphore_, VK_NULL_HANDLE);
1575+
return std::exchange(lastSubmitSemaphore_.semaphore, VK_NULL_HANDLE);
15691576
}
15701577

15711578
VkFence lvk::VulkanImmediateCommands::getVkFence(lvk::SubmitHandle handle) const {

lvk/vulkan/VulkanClasses.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,10 @@ class VulkanImmediateCommands final {
193193
CommandBufferWrapper buffers_[kMaxCommandBuffers];
194194
SubmitHandle lastSubmitHandle_ = SubmitHandle();
195195
SubmitHandle nextSubmitHandle_ = SubmitHandle();
196-
VkSemaphore lastSubmitSemaphore_ = VK_NULL_HANDLE;
197-
VkSemaphore waitSemaphore_ = VK_NULL_HANDLE;
196+
VkSemaphoreSubmitInfo lastSubmitSemaphore_ = {.sType = VK_STRUCTURE_TYPE_SEMAPHORE_SUBMIT_INFO,
197+
.stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT};
198+
VkSemaphoreSubmitInfo waitSemaphore_ = {.sType = VK_STRUCTURE_TYPE_SEMAPHORE_SUBMIT_INFO,
199+
.stageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT}; // extra "wait" semaphore
198200
uint32_t numAvailableCommandBuffers_ = kMaxCommandBuffers;
199201
uint32_t submitCounter_ = 1;
200202
};

0 commit comments

Comments
 (0)