diff options
Diffstat (limited to 'runtime/src/vulkan_present.h')
| -rw-r--r-- | runtime/src/vulkan_present.h | 93 |
1 files changed, 58 insertions, 35 deletions
diff --git a/runtime/src/vulkan_present.h b/runtime/src/vulkan_present.h index f01167cf4..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 | ||
| 418 | private: | 413 | private: |
| 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(); |
| @@ -659,6 +678,8 @@ private: | |||
| 659 | // is recreated next time, and the caller sees VK_SUCCESS, since its work was submitted. | 678 | // is recreated next time, and the caller sees VK_SUCCESS, since its work was submitted. |
| 660 | if (result == VK_SUCCESS || result == VK_SUBOPTIMAL_KHR) { | 679 | if (result == VK_SUCCESS || result == VK_SUBOPTIMAL_KHR) { |
| 661 | const auto shown = ++presented_; | 680 | const auto shown = ++presented_; |
| 681 | submit_phases::totals().presents.fetch_add(1, std::memory_order_relaxed); // frames a second, phase line | ||
| 682 | submit_phases::totals().present_serial.fetch_add(1, std::memory_order_relaxed); | ||
| 662 | if (dump_.due(shown - 1)) { | 683 | if (dump_.due(shown - 1)) { |
| 663 | // Presentation is already queued and the queue/tracker locks are released. A sampled frame | 684 | // Presentation is already queued and the queue/tracker locks are released. A sampled frame |
| 664 | // may stall here for its transfer fence and a private CPU copy. PNG and disk I/O run on a worker. | 685 | // may stall here for its transfer fence and a private CPU copy. PNG and disk I/O run on a worker. |
| @@ -672,14 +693,12 @@ private: | |||
| 672 | last_tore_ = true; | 693 | last_tore_ = true; |
| 673 | ++tear_presents_; | 694 | ++tear_presents_; |
| 674 | } | 695 | } |
| 675 | 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 |
| 676 | (presented_ - 1) % std::uint64_t(capture_every_) == 0) | 697 | captured_ = true; |
| 677 | pending_capture_ = frame.done; | 698 | captured_extent_ = extent_; |
| 678 | } | 699 | captured_format_ = format_; |
| 679 | if (capture_ && capture_ptr_) { | 700 | if (disk_sample) pending_capture_ = frame.done; |
| 680 | captured_ = true; | 701 | } |
| 681 | captured_extent_ = extent_; | ||
| 682 | captured_format_ = format_; | ||
| 683 | } | 702 | } |
| 684 | if (result == VK_ERROR_SURFACE_LOST_KHR) { | 703 | if (result == VK_ERROR_SURFACE_LOST_KHR) { |
| 685 | // 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 |
| @@ -911,7 +930,7 @@ private: | |||
| 911 | VkResult submitted; | 930 | VkResult submitted; |
| 912 | { | 931 | { |
| 913 | std::lock_guard lock(context_.submit_mutex()); | 932 | std::lock_guard lock(context_.submit_mutex()); |
| 914 | 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_), |
| 915 | "vkQueueSubmit (present probe)"); | 934 | "vkQueueSubmit (present probe)"); |
| 916 | if (submitted == VK_SUCCESS) context_.note_image_work_locked(); | 935 | if (submitted == VK_SUCCESS) context_.note_image_work_locked(); |
| 917 | } | 936 | } |
| @@ -1032,7 +1051,7 @@ private: | |||
| 1032 | VkResult submitted; | 1051 | VkResult submitted; |
| 1033 | { | 1052 | { |
| 1034 | std::lock_guard lock(context_.submit_mutex()); | 1053 | std::lock_guard lock(context_.submit_mutex()); |
| 1035 | 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), |
| 1036 | "vkQueueSubmit (return present image)"); | 1055 | "vkQueueSubmit (return present image)"); |
| 1037 | } | 1056 | } |
| 1038 | if (submitted != VK_SUCCESS) return stop(failure); | 1057 | if (submitted != VK_SUCCESS) return stop(failure); |
| @@ -1064,6 +1083,7 @@ private: | |||
| 1064 | const VkDevice device = context_.device(); | 1083 | const VkDevice device = context_.device(); |
| 1065 | { | 1084 | { |
| 1066 | 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 | ||
| 1067 | // 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. |
| 1068 | context_.observe_result(vk.vkQueueWaitIdle(queue_), "vkQueueWaitIdle (present)"); | 1088 | context_.observe_result(vk.vkQueueWaitIdle(queue_), "vkQueueWaitIdle (present)"); |
| 1069 | release(swapchain_); | 1089 | release(swapchain_); |
| @@ -1077,7 +1097,7 @@ private: | |||
| 1077 | } | 1097 | } |
| 1078 | 1098 | ||
| 1079 | 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, |
| 1080 | const PresentRect* source_rect) { | 1100 | const PresentRect* source_rect, bool copy_frame) { |
| 1081 | auto& vk = context_.vk; | 1101 | auto& vk = context_.vk; |
| 1082 | const ReplayFunctions& fn = context_.replay_; | 1102 | const ReplayFunctions& fn = context_.replay_; |
| 1083 | vk.vkResetCommandBuffer(commands, 0); | 1103 | vk.vkResetCommandBuffer(commands, 0); |
| @@ -1120,7 +1140,7 @@ private: | |||
| 1120 | VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &blit, | 1140 | VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &blit, |
| 1121 | sw == dw && sh == dh ? VK_FILTER_NEAREST : blit_filter(binding.format)); | 1141 | sw == dw && sh == dh ? VK_FILTER_NEAREST : blit_filter(binding.format)); |
| 1122 | 1142 | ||
| 1123 | finish_image(commands, image); | 1143 | finish_image(commands, image, copy_frame); |
| 1124 | for (const auto& piece : pieces) | 1144 | for (const auto& piece : pieces) |
| 1125 | 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, |
| 1126 | 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, |
| @@ -1154,6 +1174,7 @@ private: | |||
| 1154 | return true; | 1174 | return true; |
| 1155 | { | 1175 | { |
| 1156 | 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 | ||
| 1157 | // The old target may still be in use. | 1178 | // The old target may still be in use. |
| 1158 | context_.observe_result(context_.vk.vkQueueWaitIdle(queue_), "vkQueueWaitIdle (present)"); | 1179 | context_.observe_result(context_.vk.vkQueueWaitIdle(queue_), "vkQueueWaitIdle (present)"); |
| 1159 | } | 1180 | } |
| @@ -1164,7 +1185,7 @@ private: | |||
| 1164 | // 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 |
| 1165 | // 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. |
| 1166 | 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, |
| 1167 | const PresentPlanes& planes, std::uint32_t image) { | 1188 | const PresentPlanes& planes, std::uint32_t image, bool copy_frame) { |
| 1168 | auto& vk = context_.vk; | 1189 | auto& vk = context_.vk; |
| 1169 | const ReplayFunctions& fn = context_.replay_; | 1190 | const ReplayFunctions& fn = context_.replay_; |
| 1170 | if (composer_->target() == VK_NULL_HANDLE || composer_->extent().width != extent_.width || | 1191 | if (composer_->target() == VK_NULL_HANDLE || composer_->extent().width != extent_.width || |
| @@ -1252,7 +1273,7 @@ private: | |||
| 1252 | 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}; |
| 1253 | 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], |
| 1254 | VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &blit, VK_FILTER_NEAREST); | 1275 | VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &blit, VK_FILTER_NEAREST); |
| 1255 | finish_image(commands, image); | 1276 | finish_image(commands, image, copy_frame); |
| 1256 | for (std::uint32_t i = 0; i < planes.count; ++i) { | 1277 | for (std::uint32_t i = 0; i < planes.count; ++i) { |
| 1257 | if (i == 1 && same) continue; | 1278 | if (i == 1 && same) continue; |
| 1258 | for (const auto& piece : pieces[i]) | 1279 | for (const auto& piece : pieces[i]) |
| @@ -1289,7 +1310,7 @@ private: | |||
| 1289 | } | 1310 | } |
| 1290 | 1311 | ||
| 1291 | // Clears the swapchain image to opaque black. | 1312 | // Clears the swapchain image to opaque black. |
| 1292 | void record_blank(VkCommandBuffer commands, std::uint32_t image) { | 1313 | void record_blank(VkCommandBuffer commands, std::uint32_t image, bool copy_frame) { |
| 1293 | auto& vk = context_.vk; | 1314 | auto& vk = context_.vk; |
| 1294 | const ReplayFunctions& fn = context_.replay_; | 1315 | const ReplayFunctions& fn = context_.replay_; |
| 1295 | vk.vkResetCommandBuffer(commands, 0); | 1316 | vk.vkResetCommandBuffer(commands, 0); |
| @@ -1302,18 +1323,18 @@ private: | |||
| 1302 | VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT); | 1323 | VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT); |
| 1303 | const VkClearColorValue black{{0.0f, 0.0f, 0.0f, 1.0f}}; | 1324 | const VkClearColorValue black{{0.0f, 0.0f, 0.0f, 1.0f}}; |
| 1304 | 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); |
| 1305 | finish_image(commands, image); | 1326 | finish_image(commands, image, copy_frame); |
| 1306 | vk.vkEndCommandBuffer(commands); | 1327 | vk.vkEndCommandBuffer(commands); |
| 1307 | } | 1328 | } |
| 1308 | 1329 | ||
| 1309 | // 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 |
| 1310 | // the presentation engine. | 1331 | // the presentation engine. |
| 1311 | void finish_image(VkCommandBuffer commands, std::uint32_t image) { | 1332 | void finish_image(VkCommandBuffer commands, std::uint32_t image, bool copy_frame) { |
| 1312 | const ReplayFunctions& fn = context_.replay_; | 1333 | const ReplayFunctions& fn = context_.replay_; |
| 1313 | 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}; |
| 1314 | VkImageLayout layout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; | 1335 | VkImageLayout layout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; |
| 1315 | VkAccessFlags access = VK_ACCESS_TRANSFER_WRITE_BIT; | 1336 | VkAccessFlags access = VK_ACCESS_TRANSFER_WRITE_BIT; |
| 1316 | if (capture_buffer_ && (capture_ || dump_.due(presented_))) { | 1337 | if (copy_frame) { |
| 1317 | // 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 |
| 1318 | // 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. |
| 1319 | VkBufferMemoryBarrier capture_waw{VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER}; | 1340 | VkBufferMemoryBarrier capture_waw{VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER}; |
| @@ -1510,6 +1531,7 @@ private: | |||
| 1510 | const VkDevice device = context_.device(); | 1531 | const VkDevice device = context_.device(); |
| 1511 | { | 1532 | { |
| 1512 | 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 | ||
| 1513 | // 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. |
| 1514 | context_.observe_result(vk.vkQueueWaitIdle(queue_), "vkQueueWaitIdle (present)"); | 1536 | context_.observe_result(vk.vkQueueWaitIdle(queue_), "vkQueueWaitIdle (present)"); |
| 1515 | } | 1537 | } |
| @@ -1817,6 +1839,7 @@ private: | |||
| 1817 | bool capture_ = false; | 1839 | bool capture_ = false; |
| 1818 | present_dump::PresentDump dump_; | 1840 | present_dump::PresentDump dump_; |
| 1819 | bool dump_pq_ = false; | 1841 | bool dump_pq_ = false; |
| 1842 | bool continuous_readback_ = false; // explicit enable_capture(), independent of disk sampling | ||
| 1820 | VkBuffer capture_buffer_ = VK_NULL_HANDLE; | 1843 | VkBuffer capture_buffer_ = VK_NULL_HANDLE; |
| 1821 | VkDeviceMemory capture_memory_ = VK_NULL_HANDLE; | 1844 | VkDeviceMemory capture_memory_ = VK_NULL_HANDLE; |
| 1822 | VkDeviceSize capture_size_ = 0; | 1845 | VkDeviceSize capture_size_ = 0; |