diff options
| author | Nicolas James <nj3ahxac@gmail.com> | 2026-04-07 01:43:56 +1000 |
|---|---|---|
| committer | Nicolas James <nj3ahxac@gmail.com> | 2026-04-07 01:43:56 +1000 |
| commit | 341b9b65a57dee1d4d16ec0994fe9a414b542ba5 (patch) | |
| tree | 882c7600607daf6e885024929c9cd5bcfb4e4459 /src/layer.cc | |
| parent | b725e39d1a38e018e72389de7d72d7db351a8ccb (diff) | |
Fix rare race when timestamps are returned to the pool and reused before their work completes
Diffstat (limited to 'src/layer.cc')
| -rw-r--r-- | src/layer.cc | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/src/layer.cc b/src/layer.cc index b8a2bd0..a4759fa 100644 --- a/src/layer.cc +++ b/src/layer.cc @@ -399,24 +399,20 @@ vkQueueSubmit(VkQueue queue, std::uint32_t submit_count, std::ranges::transform( submit_span, std::back_inserter(next_submits), [&](const auto& submit) { - const auto head_handle = context->timestamp_pool->acquire(); - head_handle->write_command(VK_PIPELINE_STAGE_2_TOP_OF_PIPE_BIT); - const auto tail_handle = context->timestamp_pool->acquire(); - tail_handle->write_command(VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT); + const auto handle = context->timestamp_pool->acquire(); submissions.push_back(std::make_unique<Submission>(Submission{ - .start = head_handle, - .end = tail_handle, + .handle = handle, .time = now, })); next_cbs.emplace_back([&]() -> auto { auto cbs = std::make_unique<cbs_t>(); - cbs->push_back(head_handle->command_buffer); + cbs->push_back(handle->get_start_buffer()); std::ranges::copy(std::span{submit.pCommandBuffers, submit.commandBufferCount}, std::back_inserter(*cbs)); - cbs->push_back(tail_handle->command_buffer); + cbs->push_back(handle->get_end_buffer()); return cbs; }()); @@ -464,14 +460,10 @@ vkQueueSubmit2(VkQueue queue, std::uint32_t submit_count, std::ranges::transform( submit_span, std::back_inserter(next_submits), [&](const auto& submit) { - const auto head_handle = context->timestamp_pool->acquire(); - head_handle->write_command(VK_PIPELINE_STAGE_2_TOP_OF_PIPE_BIT); - const auto tail_handle = context->timestamp_pool->acquire(); - tail_handle->write_command(VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT); + const auto handle = context->timestamp_pool->acquire(); submissions.push_back(std::make_unique<Submission>(Submission{ - .start = head_handle, - .end = tail_handle, + .handle = handle, .time = now, })); @@ -479,14 +471,14 @@ vkQueueSubmit2(VkQueue queue, std::uint32_t submit_count, auto cbs = std::make_unique<cbs_t>(); cbs->push_back(VkCommandBufferSubmitInfo{ .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_SUBMIT_INFO, - .commandBuffer = head_handle->command_buffer, + .commandBuffer = handle->get_start_buffer(), }); std::ranges::copy(std::span{submit.pCommandBufferInfos, submit.commandBufferInfoCount}, std::back_inserter(*cbs)); cbs->push_back(VkCommandBufferSubmitInfo{ .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_SUBMIT_INFO, - .commandBuffer = tail_handle->command_buffer, + .commandBuffer = handle->get_end_buffer(), }); return cbs; }()); |
