diff options
| author | Ash Hopkins <ashleighhopkins87@gmail.com> | 2026-11-22 14:21:37 +0000 |
|---|---|---|
| committer | Ash Hopkins <ashleighhopkins87@gmail.com> | 2026-11-22 14:21:37 +0000 |
| commit | eebf85b60f021ce567427ce766f4ec1c88b0f13a (patch) | |
| tree | f8ee32c3f47c57a6beae5705b35c97cd69b44afe /runtime/src/vulkan_backend.h | |
| parent | 19b261bb99735ceb33dd2daaefe31ac9ef9ed26a (diff) | |
| parent | 003e78129303643a3fdc9e5f0e31a01b09759236 (diff) | |
Merge remote-tracking branch 'origin/main' into runtime-vulkan12-khr
# Conflicts:
# runtime/shims/d3d12_vulkan_device.cpp
# runtime/test/vk_test_device.h
Diffstat (limited to 'runtime/src/vulkan_backend.h')
| -rw-r--r-- | runtime/src/vulkan_backend.h | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/runtime/src/vulkan_backend.h b/runtime/src/vulkan_backend.h index 95803fe34..2ddd8be74 100644 --- a/runtime/src/vulkan_backend.h +++ b/runtime/src/vulkan_backend.h | |||
| @@ -847,7 +847,10 @@ public: | |||
| 847 | query_pools_[id] = pool; | 847 | query_pools_[id] = pool; |
| 848 | } | 848 | } |
| 849 | void remove_query_pool(QueryHeapId id) { | 849 | void remove_query_pool(QueryHeapId id) { |
| 850 | // Lock hierarchy: resource_mutex_ -> tracker_mutex_. Holding tracker_mutex_ before erasing keeps the | ||
| 851 | // QueryPool node alive until any in-flight execute() that unlocked resource_mutex_ finishes QueryReplay::commit(). | ||
| 850 | std::unique_lock lock(resource_mutex_); | 852 | std::unique_lock lock(resource_mutex_); |
| 853 | std::lock_guard tlock(tracker_mutex_); | ||
| 851 | query_pools_.erase(id); | 854 | query_pools_.erase(id); |
| 852 | } | 855 | } |
| 853 | // The heap's d3d12_query_heap type, or ~0u for a heap that is not registered. | 856 | // The heap's d3d12_query_heap type, or ~0u for a heap that is not registered. |
| @@ -1026,6 +1029,7 @@ public: | |||
| 1026 | 1029 | ||
| 1027 | std::uint64_t completed_retire_ticket() { | 1030 | std::uint64_t completed_retire_ticket() { |
| 1028 | std::lock_guard lock(submit_mutex_); | 1031 | std::lock_guard lock(submit_mutex_); |
| 1032 | if (is_device_lost()) return 0; | ||
| 1029 | return retire_tickets_.completed([this](VkSemaphore semaphore, std::uint64_t value) { | 1033 | return retire_tickets_.completed([this](VkSemaphore semaphore, std::uint64_t value) { |
| 1030 | std::uint64_t done = 0; | 1034 | std::uint64_t done = 0; |
| 1031 | return vk.vkGetSemaphoreCounterValue(device_, semaphore, &done) == VK_SUCCESS && done >= value; | 1035 | return vk.vkGetSemaphoreCounterValue(device_, semaphore, &done) == VK_SUCCESS && done >= value; |
| @@ -1222,8 +1226,12 @@ public: | |||
| 1222 | if (queue_) { | 1226 | if (queue_) { |
| 1223 | std::lock_guard lock(context_.submit_mutex()); | 1227 | std::lock_guard lock(context_.submit_mutex()); |
| 1224 | for (; open_labels_; --open_labels_) context_.labels_.queue_end(queue_); | 1228 | for (; open_labels_; --open_labels_) context_.labels_.queue_end(queue_); |
| 1225 | vk.vkQueueWaitIdle(queue_); | 1229 | const VkResult idle_result = vk.vkQueueWaitIdle(queue_); |
| 1226 | if (progress_) context_.retire_queue_idle_locked(progress_); | 1230 | if (idle_result == VK_SUCCESS) { |
| 1231 | if (progress_) context_.retire_queue_idle_locked(progress_); | ||
| 1232 | } else { | ||
| 1233 | context_.mark_device_lost(); | ||
| 1234 | } | ||
| 1227 | } | 1235 | } |
| 1228 | if (progress_) { | 1236 | if (progress_) { |
| 1229 | std::lock_guard lock(context_.tracker_mutex_); | 1237 | std::lock_guard lock(context_.tracker_mutex_); |
| @@ -1344,6 +1352,7 @@ public: | |||
| 1344 | } | 1352 | } |
| 1345 | const auto resolve = [this](ResourceId id) { return context_.resolve(id); }; | 1353 | const auto resolve = [this](ResourceId id) { return context_.resolve(id); }; |
| 1346 | std::uint32_t segments = 0, statistics_segments = 0; | 1354 | std::uint32_t segments = 0, statistics_segments = 0; |
| 1355 | bool has_queries = false; | ||
| 1347 | for (std::size_t i = 0; i < lists.size(); ++i) { | 1356 | for (std::size_t i = 0; i < lists.size(); ++i) { |
| 1348 | const auto result = prepare(*lists[i], resolve, replay, prepared[i]); | 1357 | const auto result = prepare(*lists[i], resolve, replay, prepared[i]); |
| 1349 | if (result != ReplayResult::success) return result; | 1358 | if (result != ReplayResult::success) return result; |
| @@ -1352,6 +1361,7 @@ public: | |||
| 1352 | return ReplayResult::unsupported; | 1361 | return ReplayResult::unsupported; |
| 1353 | segments += prepared[i].segment_count; | 1362 | segments += prepared[i].segment_count; |
| 1354 | statistics_segments += prepared[i].statistics_segment_count; | 1363 | statistics_segments += prepared[i].statistics_segment_count; |
| 1364 | has_queries = has_queries || !prepared[i].queries.empty(); | ||
| 1355 | } | 1365 | } |
| 1356 | const auto segment_pool = [this](VkQueryType type, std::uint32_t count, | 1366 | const auto segment_pool = [this](VkQueryType type, std::uint32_t count, |
| 1357 | std::shared_ptr<OcclusionSegmentPool>& out) { | 1367 | std::shared_ptr<OcclusionSegmentPool>& out) { |
| @@ -1373,6 +1383,10 @@ public: | |||
| 1373 | if (statistics_segments && can_resolve_occlusion && | 1383 | if (statistics_segments && can_resolve_occlusion && |
| 1374 | !segment_pool(VK_QUERY_TYPE_PIPELINE_STATISTICS, statistics_segments, statistics)) | 1384 | !segment_pool(VK_QUERY_TYPE_PIPELINE_STATISTICS, statistics_segments, statistics)) |
| 1375 | return ReplayResult::unsupported; | 1385 | return ReplayResult::unsupported; |
| 1386 | // QueryReplay::plan() reads QueryPool::ended / occlusion and QueryReplay::commit() writes them after | ||
| 1387 | // resource_lock is unlocked. Hold tracker_mutex_ across plan -> emit -> submit -> commit so concurrent queues | ||
| 1388 | // see submission-order query state and remove_query_pool() waits until commit finishes. | ||
| 1389 | if (has_queries && !tracker_lock.owns_lock()) tracker_lock.lock(); | ||
| 1376 | QueryReplay queries; | 1390 | QueryReplay queries; |
| 1377 | std::uint32_t base = 0, statistics_base = 0; | 1391 | std::uint32_t base = 0, statistics_base = 0; |
| 1378 | for (auto& list : prepared) { | 1392 | for (auto& list : prepared) { |
| @@ -1597,10 +1611,12 @@ private: | |||
| 1597 | return false; | 1611 | return false; |
| 1598 | } | 1612 | } |
| 1599 | const bool ok = (res == VK_SUCCESS); | 1613 | const bool ok = (res == VK_SUCCESS); |
| 1600 | waits_.clear(); | 1614 | if (ok) { |
| 1601 | wait_values_.clear(); | 1615 | waits_.clear(); |
| 1602 | for (auto& slot : buffers_) | 1616 | wait_values_.clear(); |
| 1603 | if (slot.buffer == command_buffer) slot.ticket = ticket; | 1617 | for (auto& slot : buffers_) |
| 1618 | if (slot.buffer == command_buffer) slot.ticket = ticket; | ||
| 1619 | } | ||
| 1604 | return ok; | 1620 | return ok; |
| 1605 | } | 1621 | } |
| 1606 | 1622 | ||