diff options
| author | sds-228 <329233051+sds-228@users.noreply.github.com> | 2026-11-23 04:28:47 +0300 |
|---|---|---|
| committer | sds-228 <329233051+sds-228@users.noreply.github.com> | 2026-11-23 04:28:47 +0300 |
| commit | 7d71e8328ad6c3b41fa9ac47ea4eb27fdd3afa8a (patch) | |
| tree | 52f7119acdd5ebffecf88c4fd805be7587159081 /runtime/src/vulkan_backend.h | |
| parent | 03b09a086592a197db64d91655c6e65c30764d96 (diff) | |
vulkan: retain prepared-list storage across smaller submissions
resize() down destroyed the per-list vectors that prepare refills, so a queue alternating 8 lists and 1 list rebuilt them every frame. Grow the vector only, and iterate the current list count in the query and emit loops so retained entries are never replayed. Registers the existing vk_queue_test with CTest and adds an 8-then-1 GPU regression with a negative control.
AI-assisted (OpenCode)
Diffstat (limited to 'runtime/src/vulkan_backend.h')
| -rw-r--r-- | runtime/src/vulkan_backend.h | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/runtime/src/vulkan_backend.h b/runtime/src/vulkan_backend.h index 03ab7ba26..97959be69 100644 --- a/runtime/src/vulkan_backend.h +++ b/runtime/src/vulkan_backend.h | |||
| @@ -1500,6 +1500,10 @@ public: | |||
| 1500 | 1500 | ||
| 1501 | bool ok() const { return ok_; } | 1501 | bool ok() const { return ok_; } |
| 1502 | 1502 | ||
| 1503 | // Entries kept between executions. Execute only uses the first lists.size(); a larger count is retained storage, | ||
| 1504 | // not work the next submission will replay (vk_queue_test checks both halves of that contract). | ||
| 1505 | std::size_t prepared_entries() const { return prepared_.size(); } | ||
| 1506 | |||
| 1503 | template<typename GetHeap> | 1507 | template<typename GetHeap> |
| 1504 | bool update_tiles(ResourceId id, std::span<const BufferTileRegion> regions, | 1508 | bool update_tiles(ResourceId id, std::span<const BufferTileRegion> regions, |
| 1505 | std::span<const BufferTileRange> ranges, GetHeap&& get_heap) { | 1509 | std::span<const BufferTileRange> ranges, GetHeap&& get_heap) { |
| @@ -1679,7 +1683,10 @@ private: | |||
| 1679 | // Kept between executions: prepare refills each list's entries in the storage the last execution left, where | 1683 | // Kept between executions: prepare refills each list's entries in the storage the last execution left, where |
| 1680 | // making them fresh for every command was about half the layer's CPU cost per command (replay_cpu_bench). | 1684 | // making them fresh for every command was about half the layer's CPU cost per command (replay_cpu_bench). |
| 1681 | auto& prepared = prepared_; | 1685 | auto& prepared = prepared_; |
| 1682 | prepared.resize(lists.size()); | 1686 | // Keep the storage from a larger batch. resize() down would destroy the unused entries and their vectors, so |
| 1687 | // a queue that sees 8 lists and then 1 in every frame would rebuild them on each execution. The loops below | ||
| 1688 | // use only the first lists.size() entries, so stale entries are never prepared, queried or emitted. | ||
| 1689 | if (prepared.size() < lists.size()) prepared.resize(lists.size()); | ||
| 1683 | ReplayFunctions replay = context_.replay_; | 1690 | ReplayFunctions replay = context_.replay_; |
| 1684 | replay.queue_stages = kind_ == QueueKind::copy ? detail::queue_stages_copy | 1691 | replay.queue_stages = kind_ == QueueKind::copy ? detail::queue_stages_copy |
| 1685 | : kind_ == QueueKind::compute ? detail::queue_stages_compute | 1692 | : kind_ == QueueKind::compute ? detail::queue_stages_compute |
| @@ -1797,7 +1804,8 @@ private: | |||
| 1797 | if (has_queries && !tracker_lock.owns_lock()) tracker_lock.lock(); | 1804 | if (has_queries && !tracker_lock.owns_lock()) tracker_lock.lock(); |
| 1798 | QueryReplay queries; | 1805 | QueryReplay queries; |
| 1799 | std::uint32_t base = 0, statistics_base = 0; | 1806 | std::uint32_t base = 0, statistics_base = 0; |
| 1800 | for (auto& list : prepared) { | 1807 | for (std::size_t i = 0; i < lists.size(); ++i) { |
| 1808 | auto& list = prepared[i]; | ||
| 1801 | const auto result = queries.plan(list, physical, base, can_resolve_occlusion, statistics, statistics_base); | 1809 | const auto result = queries.plan(list, physical, base, can_resolve_occlusion, statistics, statistics_base); |
| 1802 | if (result != ReplayResult::success) return result; | 1810 | if (result != ReplayResult::success) return result; |
| 1803 | base += list.segment_count; | 1811 | base += list.segment_count; |
| @@ -1893,7 +1901,8 @@ private: | |||
| 1893 | bool wrote_readback = false; | 1901 | bool wrote_readback = false; |
| 1894 | VkPipelineStageFlags2 readback_stages = 0; | 1902 | VkPipelineStageFlags2 readback_stages = 0; |
| 1895 | std::uint32_t open_labels = 0; // events may span the lists of one ExecuteCommandLists | 1903 | std::uint32_t open_labels = 0; // events may span the lists of one ExecuteCommandLists |
| 1896 | for (const auto& list : prepared) { | 1904 | for (std::size_t i = 0; i < lists.size(); ++i) { |
| 1905 | const auto& list = prepared[i]; | ||
| 1897 | emit(list, command_buffer, replay, &next_tracker, &open_labels); | 1906 | emit(list, command_buffer, replay, &next_tracker, &open_labels); |
| 1898 | wrote_readback |= list.wrote_readback; | 1907 | wrote_readback |= list.wrote_readback; |
| 1899 | readback_stages |= list.readback_src_stages; | 1908 | readback_stages |= list.readback_src_stages; |