upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/src/vulkan_present.h
diff options
context:
space:
mode:
authorJan Trencansky <jan.trencansky@protonmail.com>2026-11-25 19:04:24 -0500
committerJan Trencansky <jan.trencansky@protonmail.com>2026-11-25 19:04:24 -0500
commit8d832fd10913064e1c8aec74191e3ba8f70211c8 (patch)
treee365199d7d86ebf592a5a0dc2f07cda4b74b58a7 /runtime/src/vulkan_present.h
parent5da3b6be3cefc1499452ba8c8370a50092674d61 (diff)
parentc50ed94b35b37b697ab9c5fd176f3738480b4db5 (diff)
Merge main into rt-title-every-budget (#2122)
#2098 split the every-pass loop of refresh_title_textures by mode: with LEONIDA_TEXTURE_REFRESH_ASYNC every persistent mapping is polled each pass and only stale unmapped textures are visited, without it all mapped or stale ones are. The async branch is kept as main has it. LEONIDA_TITLE_EVERY_BUDGET_US applies to the synchronous pass, the one before a submission on the submitting thread; under async the pass runs on the refresh worker and the limit does not apply (README says so). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/src/vulkan_present.h')
-rw-r--r--runtime/src/vulkan_present.h91
1 files changed, 56 insertions, 35 deletions
diff --git a/runtime/src/vulkan_present.h b/runtime/src/vulkan_present.h
index d494233d3..81f3b57e1 100644
--- a/runtime/src/vulkan_present.h
+++ b/runtime/src/vulkan_present.h
@@ -183,7 +183,7 @@ public:
183 std::error_code created; 183 std::error_code created;
184 std::filesystem::create_directories(capture_dir_, created); 184 std::filesystem::create_directories(capture_dir_, created);
185 capture_to_disk_ = true; 185 capture_to_disk_ = true;
186 capture_ = true; // the swapchain needs TRANSFER_SRC, and every frame copies into a staging buffer 186 capture_ = true; // provision TRANSFER_SRC and staging; disk-only copies follow the requested cadence
187 if (const char* every = std::getenv("LEONIDA_CAPTURE_EVERY")) capture_every_ = std::max(1, std::atoi(every)); 187 if (const char* every = std::getenv("LEONIDA_CAPTURE_EVERY")) capture_every_ = std::max(1, std::atoi(every));
188 if (const char* limit = std::getenv("LEONIDA_CAPTURE_LIMIT")) capture_limit_ = std::max(1, std::atoi(limit)); 188 if (const char* limit = std::getenv("LEONIDA_CAPTURE_LIMIT")) capture_limit_ = std::max(1, std::atoi(limit));
189 std::fprintf(stderr, "[rt] present: capture on: every %d presented frame(s), at most %d, into %s\n", 189 std::fprintf(stderr, "[rt] present: capture on: every %d presented frame(s), at most %d, into %s\n",
@@ -212,6 +212,7 @@ public:
212 const VkDevice device = context_.device(); 212 const VkDevice device = context_.device();
213 { 213 {
214 std::lock_guard lock(context_.submit_mutex()); 214 std::lock_guard lock(context_.submit_mutex());
215 const SubmitMutex::SubmitTurn turn(context_.submit_mutex()); // a queue operation: the compile gate
215 context_.observe_result(vk.vkQueueWaitIdle(queue_), "vkQueueWaitIdle (present)"); 216 context_.observe_result(vk.vkQueueWaitIdle(queue_), "vkQueueWaitIdle (present)");
216 // A WSI layer may perform a device-wide idle while destroying the swapchain. 217 // A WSI layer may perform a device-wide idle while destroying the swapchain.
217 // Keep that implicit idle serialized with submits from every context queue. 218 // Keep that implicit idle serialized with submits from every context queue.
@@ -348,15 +349,9 @@ public:
348 // Call before the first present. 349 // Call before the first present.
349 bool enable_capture() { 350 bool enable_capture() {
350 std::lock_guard lock(present_mutex_); 351 std::lock_guard lock(present_mutex_);
351 if (!ok_) return false;
352 splash_capture_only_ = false; 352 splash_capture_only_ = false;
353 capture_ = true; 353 continuous_readback_ = enable_capture_storage();
354 stale_ = true; 354 return continuous_readback_;
355 if (!recreate(vsync_, swapchain_srgb_, swapchain_hdr_req_) || (swapchain_ && !capture_buffer_)) {
356 capture_ = false;
357 return false;
358 }
359 return true;
360 } 355 }
361 356
362 // Present the shell image immediately. Keep it on screen until the window has a non-black title frame. 357 // Present the shell image immediately. Keep it on screen until the window has a non-black title frame.
@@ -365,7 +360,7 @@ public:
365 // The last presented frame as the swapchain stores it (4 bytes a texel, rows tightly packed, format() order). 360 // The last presented frame as the swapchain stores it (4 bytes a texel, rows tightly packed, format() order).
366 // Waits for the frame to finish. False when nothing was presented since enable_capture(), after a present 361 // Waits for the frame to finish. False when nothing was presented since enable_capture(), after a present
367 // that was skipped because the window is minimised (it returned VK_SUCCESS but showed nothing), until the next 362 // that was skipped because the window is minimised (it returned VK_SUCCESS but showed nothing), until the next
368 // frame that is shown (the frame before it is not what the window was last asked to show), or when the wait fails. 363 // frame that is shown, on an unsampled disk-only present, or when the wait fails.
369 bool read_back(std::vector<std::uint8_t>& pixels, VkExtent2D* extent, VkFormat* format) { 364 bool read_back(std::vector<std::uint8_t>& pixels, VkExtent2D* extent, VkFormat* format) {
370 std::lock_guard lock(present_mutex_); 365 std::lock_guard lock(present_mutex_);
371 if (!capture_ || !capture_ptr_ || !captured_) return false; 366 if (!capture_ || !capture_ptr_ || !captured_) return false;
@@ -416,6 +411,19 @@ public:
416 } 411 }
417 412
418private: 413private:
414 // Called with present_mutex_ held. Reserving staging for the splash or rare disk samples
415 // is distinct from promising the caller a copy of every frame through read_back().
416 bool enable_capture_storage() {
417 if (!ok_) return false;
418 capture_ = true;
419 stale_ = true;
420 if (!recreate(vsync_, swapchain_srgb_, swapchain_hdr_req_) || (swapchain_ && !capture_buffer_)) {
421 capture_ = false;
422 return false;
423 }
424 return true;
425 }
426
419 bool should_abort() { 427 bool should_abort() {
420 std::function<bool()> abort; 428 std::function<bool()> abort;
421 { 429 {
@@ -507,14 +515,13 @@ private:
507 if ((binding || planes) && !(format_features(format_) & VK_FORMAT_FEATURE_BLIT_DST_BIT)) 515 if ((binding || planes) && !(format_features(format_) & VK_FORMAT_FEATURE_BLIT_DST_BIT))
508 return VK_ERROR_FORMAT_NOT_SUPPORTED; 516 return VK_ERROR_FORMAT_NOT_SUPPORTED;
509 if (planes && !prepare_compose()) return VK_ERROR_FORMAT_NOT_SUPPORTED; 517 if (planes && !prepare_compose()) return VK_ERROR_FORMAT_NOT_SUPPORTED;
510 auto& vk = context_.vk;
511 const VkDevice device = context_.device(); 518 const VkDevice device = context_.device();
512 Frame& frame = frames_[frame_index_ % frames_.size()]; 519 Frame& frame = frames_[frame_index_ % frames_.size()];
513 if (const VkResult waited = context_.observe_result( 520 if (const VkResult waited = context_.observe_result(
514 vkWaitForFences_(device, 1, &frame.done, VK_TRUE, UINT64_MAX), "vkWaitForFences (present)"); 521 vkWaitForFences_(device, 1, &frame.done, VK_TRUE, UINT64_MAX), "vkWaitForFences (present)");
515 waited != VK_SUCCESS) 522 waited != VK_SUCCESS)
516 return stop(waited); 523 return stop(waited);
517 // Every submit copies into the same mapped buffer, even if its frame is outside the disk capture stride. 524 // Drain the preceding disk sample before reusing its fence or advancing its metadata.
518 if (const VkResult r = finish_pending_capture(); r != VK_SUCCESS) return stop(r); 525 if (const VkResult r = finish_pending_capture(); r != VK_SUCCESS) return stop(r);
519 526
520 std::uint32_t image = 0; 527 std::uint32_t image = 0;
@@ -537,6 +544,15 @@ private:
537 // An out-of-date retry above may have given the swapchain another extent: the compose target follows it. 544 // An out-of-date retry above may have given the swapchain another extent: the compose target follows it.
538 if (planes && !prepare_compose()) return give_back(frame, VK_ERROR_FORMAT_NOT_SUPPORTED); 545 if (planes && !prepare_compose()) return give_back(frame, VK_ERROR_FORMAT_NOT_SUPPORTED);
539 546
547 // The ordinal counts accepted presents, not submissions or deferred requests. Decide after
548 // draining the previous disk sample and any acquire/recreate retry; an unshown attempt consumes no slot.
549 const bool disk_sample = capture_to_disk_ && capture_written_ < capture_limit_ &&
550 presented_ % std::uint64_t(capture_every_) == 0;
551 const bool inspect = splash_owner_ && capture_ptr_;
552 // Merely allocating a temporary splash buffer does not require a copy. In particular, a minimized
553 // initial splash can return before taking ownership; later ordinary frames must not become continuous.
554 const bool copy_frame = capture_buffer_ && ((capture_ && (disk_sample || continuous_readback_ || inspect)) || dump_.due(presented_));
555 captured_ = false; // never expose a stale sample after an unsampled or unshown frame
540 bool recorded = false; 556 bool recorded = false;
541 std::unique_lock tracker_lock(context_.tracker_mutex_, std::defer_lock); 557 std::unique_lock tracker_lock(context_.tracker_mutex_, std::defer_lock);
542 bool rollback_source = false; 558 bool rollback_source = false;
@@ -561,7 +577,8 @@ private:
561 plane_rollbacks[i].tracked = context_.tracker_.tracked(plane_rollbacks[i].id); 577 plane_rollbacks[i].tracked = context_.tracker_.tracked(plane_rollbacks[i].id);
562 if (plane_rollbacks[i].tracked) plane_rollbacks[i].layout = context_.tracker_.layout(plane_rollbacks[i].id, 0); 578 if (plane_rollbacks[i].tracked) plane_rollbacks[i].layout = context_.tracker_.layout(plane_rollbacks[i].id, 0);
563 } 579 }
564 recorded = record_planes(frame, std::uint32_t(frame_index_ % frames_.size()), current, *planes, image); 580 recorded = record_planes(frame, std::uint32_t(frame_index_ % frames_.size()), current, *planes,
581 image, copy_frame);
565 } 582 }
566 } 583 }
567 } else if (binding) { 584 } else if (binding) {
@@ -574,11 +591,11 @@ private:
574 tracker_lock.lock(); 591 tracker_lock.lock();
575 rollback_source = context_.tracker_.tracked(source); 592 rollback_source = context_.tracker_.tracked(source);
576 if (rollback_source) prev_layout = context_.tracker_.layout(source, 0); 593 if (rollback_source) prev_layout = context_.tracker_.layout(source, 0);
577 record(frame.commands, *current, source, image, source_rect); 594 record(frame.commands, *current, source, image, source_rect, copy_frame);
578 recorded = true; 595 recorded = true;
579 } 596 }
580 } else { 597 } else {
581 record_blank(frame.commands, image); 598 record_blank(frame.commands, image, copy_frame);
582 recorded = true; 599 recorded = true;
583 } 600 }
584 const auto rollback = [&] { 601 const auto rollback = [&] {
@@ -624,7 +641,6 @@ private:
624 const bool tearing = false; 641 const bool tearing = false;
625 (void)tear; 642 (void)tear;
626#endif 643#endif
627 const bool inspect = splash_owner_ && capture_ptr_;
628 bool show_title = false; 644 bool show_title = false;
629 if (inspect) { 645 if (inspect) {
630 submit_info.signalSemaphoreCount = 0; // signal ready only after choosing the image the window will show 646 submit_info.signalSemaphoreCount = 0; // signal ready only after choosing the image the window will show
@@ -633,7 +649,10 @@ private:
633 VkResult submitted, result = VK_SUCCESS; 649 VkResult submitted, result = VK_SUCCESS;
634 { 650 {
635 std::lock_guard lock(context_.submit_mutex()); 651 std::lock_guard lock(context_.submit_mutex());
636 submitted = context_.observe_result(vk.vkQueueSubmit(queue_, 1, &submit_info, frame.done), 652 // One turn of the compile gate for the submit and the present after it: no pipeline create enters the
653 // driver between the two (queue_submit's own turn nests inside this one).
654 const SubmitMutex::SubmitTurn turn(context_.submit_mutex()); // a queue operation: the compile gate
655 submitted = context_.observe_result(context_.queue_submit(queue_, 1, &submit_info, frame.done),
637 "vkQueueSubmit (present)"); 656 "vkQueueSubmit (present)");
638 if (submitted == VK_SUCCESS) context_.note_image_work_locked(); 657 if (submitted == VK_SUCCESS) context_.note_image_work_locked();
639 if (submitted != VK_SUCCESS) rollback(); 658 if (submitted != VK_SUCCESS) rollback();
@@ -674,14 +693,12 @@ private:
674 last_tore_ = true; 693 last_tore_ = true;
675 ++tear_presents_; 694 ++tear_presents_;
676 } 695 }
677 if (capture_to_disk_ && capture_ && capture_ptr_ && capture_written_ < capture_limit_ && 696 if (copy_frame && capture_ptr_) { // a temporary splash-only allocation may have just been released
678 (presented_ - 1) % std::uint64_t(capture_every_) == 0) 697 captured_ = true;
679 pending_capture_ = frame.done; 698 captured_extent_ = extent_;
680 } 699 captured_format_ = format_;
681 if (capture_ && capture_ptr_) { 700 if (disk_sample) pending_capture_ = frame.done;
682 captured_ = true; 701 }
683 captured_extent_ = extent_;
684 captured_format_ = format_;
685 } 702 }
686 if (result == VK_ERROR_SURFACE_LOST_KHR) { 703 if (result == VK_ERROR_SURFACE_LOST_KHR) {
687 // The surface was lost during the present (display disconnected, a driver reset of the window's 704 // The surface was lost during the present (display disconnected, a driver reset of the window's
@@ -913,7 +930,7 @@ private:
913 VkResult submitted; 930 VkResult submitted;
914 { 931 {
915 std::lock_guard lock(context_.submit_mutex()); 932 std::lock_guard lock(context_.submit_mutex());
916 submitted = context_.observe_result(vk.vkQueueSubmit(queue_, 1, &submit_info, probe_fence_), 933 submitted = context_.observe_result(context_.queue_submit(queue_, 1, &submit_info, probe_fence_),
917 "vkQueueSubmit (present probe)"); 934 "vkQueueSubmit (present probe)");
918 if (submitted == VK_SUCCESS) context_.note_image_work_locked(); 935 if (submitted == VK_SUCCESS) context_.note_image_work_locked();
919 } 936 }
@@ -1034,7 +1051,7 @@ private:
1034 VkResult submitted; 1051 VkResult submitted;
1035 { 1052 {
1036 std::lock_guard lock(context_.submit_mutex()); 1053 std::lock_guard lock(context_.submit_mutex());
1037 submitted = context_.observe_result(context_.vk.vkQueueSubmit(queue_, 1, &submit_info, frame.done), 1054 submitted = context_.observe_result(context_.queue_submit(queue_, 1, &submit_info, frame.done),
1038 "vkQueueSubmit (return present image)"); 1055 "vkQueueSubmit (return present image)");
1039 } 1056 }
1040 if (submitted != VK_SUCCESS) return stop(failure); 1057 if (submitted != VK_SUCCESS) return stop(failure);
@@ -1066,6 +1083,7 @@ private:
1066 const VkDevice device = context_.device(); 1083 const VkDevice device = context_.device();
1067 { 1084 {
1068 std::lock_guard lock(context_.submit_mutex()); 1085 std::lock_guard lock(context_.submit_mutex());
1086 const SubmitMutex::SubmitTurn turn(context_.submit_mutex()); // a queue operation: the compile gate
1069 // The old swapchain's images and semaphores may still be in use. 1087 // The old swapchain's images and semaphores may still be in use.
1070 context_.observe_result(vk.vkQueueWaitIdle(queue_), "vkQueueWaitIdle (present)"); 1088 context_.observe_result(vk.vkQueueWaitIdle(queue_), "vkQueueWaitIdle (present)");
1071 release(swapchain_); 1089 release(swapchain_);
@@ -1079,7 +1097,7 @@ private:
1079 } 1097 }
1080 1098
1081 void record(VkCommandBuffer commands, const ResourceBinding& binding, ResourceId source, std::uint32_t image, 1099 void record(VkCommandBuffer commands, const ResourceBinding& binding, ResourceId source, std::uint32_t image,
1082 const PresentRect* source_rect) { 1100 const PresentRect* source_rect, bool copy_frame) {
1083 auto& vk = context_.vk; 1101 auto& vk = context_.vk;
1084 const ReplayFunctions& fn = context_.replay_; 1102 const ReplayFunctions& fn = context_.replay_;
1085 vk.vkResetCommandBuffer(commands, 0); 1103 vk.vkResetCommandBuffer(commands, 0);
@@ -1122,7 +1140,7 @@ private:
1122 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &blit, 1140 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &blit,
1123 sw == dw && sh == dh ? VK_FILTER_NEAREST : blit_filter(binding.format)); 1141 sw == dw && sh == dh ? VK_FILTER_NEAREST : blit_filter(binding.format));
1124 1142
1125 finish_image(commands, image); 1143 finish_image(commands, image, copy_frame);
1126 for (const auto& piece : pieces) 1144 for (const auto& piece : pieces)
1127 detail::image_barrier(fn, commands, binding, piece.range, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, 1145 detail::image_barrier(fn, commands, binding, piece.range, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
1128 piece.layout, VK_ACCESS_TRANSFER_READ_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, any, 1146 piece.layout, VK_ACCESS_TRANSFER_READ_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, any,
@@ -1156,6 +1174,7 @@ private:
1156 return true; 1174 return true;
1157 { 1175 {
1158 std::lock_guard lock(context_.submit_mutex()); 1176 std::lock_guard lock(context_.submit_mutex());
1177 const SubmitMutex::SubmitTurn turn(context_.submit_mutex()); // a queue operation: the compile gate
1159 // The old target may still be in use. 1178 // The old target may still be in use.
1160 context_.observe_result(context_.vk.vkQueueWaitIdle(queue_), "vkQueueWaitIdle (present)"); 1179 context_.observe_result(context_.vk.vkQueueWaitIdle(queue_), "vkQueueWaitIdle (present)");
1161 } 1180 }
@@ -1166,7 +1185,7 @@ private:
1166 // Records the composition of `planes` and its copy to swapchain image `image`. False, with nothing recorded and the 1185 // Records the composition of `planes` and its copy to swapchain image `image`. False, with nothing recorded and the
1167 // tracker untouched, when a view cannot be made. The caller holds the resource and tracker locks. 1186 // tracker untouched, when a view cannot be made. The caller holds the resource and tracker locks.
1168 bool record_planes(Frame& frame, std::uint32_t slot, const std::array<ResourceBinding, 2>& current, 1187 bool record_planes(Frame& frame, std::uint32_t slot, const std::array<ResourceBinding, 2>& current,
1169 const PresentPlanes& planes, std::uint32_t image) { 1188 const PresentPlanes& planes, std::uint32_t image, bool copy_frame) {
1170 auto& vk = context_.vk; 1189 auto& vk = context_.vk;
1171 const ReplayFunctions& fn = context_.replay_; 1190 const ReplayFunctions& fn = context_.replay_;
1172 if (composer_->target() == VK_NULL_HANDLE || composer_->extent().width != extent_.width || 1191 if (composer_->target() == VK_NULL_HANDLE || composer_->extent().width != extent_.width ||
@@ -1254,7 +1273,7 @@ private:
1254 blit.dstOffsets[1] = {std::int32_t(extent_.width), std::int32_t(extent_.height), 1}; 1273 blit.dstOffsets[1] = {std::int32_t(extent_.width), std::int32_t(extent_.height), 1};
1255 vkCmdBlitImage_(commands, composer_->target(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, images_[image], 1274 vkCmdBlitImage_(commands, composer_->target(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, images_[image],
1256 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &blit, VK_FILTER_NEAREST); 1275 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &blit, VK_FILTER_NEAREST);
1257 finish_image(commands, image); 1276 finish_image(commands, image, copy_frame);
1258 for (std::uint32_t i = 0; i < planes.count; ++i) { 1277 for (std::uint32_t i = 0; i < planes.count; ++i) {
1259 if (i == 1 && same) continue; 1278 if (i == 1 && same) continue;
1260 for (const auto& piece : pieces[i]) 1279 for (const auto& piece : pieces[i])
@@ -1291,7 +1310,7 @@ private:
1291 } 1310 }
1292 1311
1293 // Clears the swapchain image to opaque black. 1312 // Clears the swapchain image to opaque black.
1294 void record_blank(VkCommandBuffer commands, std::uint32_t image) { 1313 void record_blank(VkCommandBuffer commands, std::uint32_t image, bool copy_frame) {
1295 auto& vk = context_.vk; 1314 auto& vk = context_.vk;
1296 const ReplayFunctions& fn = context_.replay_; 1315 const ReplayFunctions& fn = context_.replay_;
1297 vk.vkResetCommandBuffer(commands, 0); 1316 vk.vkResetCommandBuffer(commands, 0);
@@ -1304,18 +1323,18 @@ private:
1304 VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT); 1323 VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT);
1305 const VkClearColorValue black{{0.0f, 0.0f, 0.0f, 1.0f}}; 1324 const VkClearColorValue black{{0.0f, 0.0f, 0.0f, 1.0f}};
1306 vkCmdClearColorImage_(commands, images_[image], VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &black, 1, &range); 1325 vkCmdClearColorImage_(commands, images_[image], VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &black, 1, &range);
1307 finish_image(commands, image); 1326 finish_image(commands, image, copy_frame);
1308 vk.vkEndCommandBuffer(commands); 1327 vk.vkEndCommandBuffer(commands);
1309 } 1328 }
1310 1329
1311 // The swapchain image is written (TRANSFER_DST): optionally copy it to the capture buffer, then hand it to 1330 // The swapchain image is written (TRANSFER_DST): optionally copy it to the capture buffer, then hand it to
1312 // the presentation engine. 1331 // the presentation engine.
1313 void finish_image(VkCommandBuffer commands, std::uint32_t image) { 1332 void finish_image(VkCommandBuffer commands, std::uint32_t image, bool copy_frame) {
1314 const ReplayFunctions& fn = context_.replay_; 1333 const ReplayFunctions& fn = context_.replay_;
1315 const VkImageSubresourceRange range{VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; 1334 const VkImageSubresourceRange range{VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
1316 VkImageLayout layout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; 1335 VkImageLayout layout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
1317 VkAccessFlags access = VK_ACCESS_TRANSFER_WRITE_BIT; 1336 VkAccessFlags access = VK_ACCESS_TRANSFER_WRITE_BIT;
1318 if (capture_buffer_ && (capture_ || dump_.due(presented_))) { 1337 if (copy_frame) {
1319 // Two frames may be in flight and share `capture_buffer_`: serialize the prior frame's capture copy 1338 // Two frames may be in flight and share `capture_buffer_`: serialize the prior frame's capture copy
1320 // before overwriting it, while moving this frame's swapchain image to TRANSFER_SRC. 1339 // before overwriting it, while moving this frame's swapchain image to TRANSFER_SRC.
1321 VkBufferMemoryBarrier capture_waw{VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER}; 1340 VkBufferMemoryBarrier capture_waw{VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER};
@@ -1512,6 +1531,7 @@ private:
1512 const VkDevice device = context_.device(); 1531 const VkDevice device = context_.device();
1513 { 1532 {
1514 std::lock_guard lock(context_.submit_mutex()); 1533 std::lock_guard lock(context_.submit_mutex());
1534 const SubmitMutex::SubmitTurn turn(context_.submit_mutex()); // a queue operation: the compile gate
1515 // The old swapchain's images and semaphores may still be in use. 1535 // The old swapchain's images and semaphores may still be in use.
1516 context_.observe_result(vk.vkQueueWaitIdle(queue_), "vkQueueWaitIdle (present)"); 1536 context_.observe_result(vk.vkQueueWaitIdle(queue_), "vkQueueWaitIdle (present)");
1517 } 1537 }
@@ -1819,6 +1839,7 @@ private:
1819 bool capture_ = false; 1839 bool capture_ = false;
1820 present_dump::PresentDump dump_; 1840 present_dump::PresentDump dump_;
1821 bool dump_pq_ = false; 1841 bool dump_pq_ = false;
1842 bool continuous_readback_ = false; // explicit enable_capture(), independent of disk sampling
1822 VkBuffer capture_buffer_ = VK_NULL_HANDLE; 1843 VkBuffer capture_buffer_ = VK_NULL_HANDLE;
1823 VkDeviceMemory capture_memory_ = VK_NULL_HANDLE; 1844 VkDeviceMemory capture_memory_ = VK_NULL_HANDLE;
1824 VkDeviceSize capture_size_ = 0; 1845 VkDeviceSize capture_size_ = 0;