upleb.uk

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

summaryrefslogtreecommitdiff
path: root/runtime/src/vulkan_backend.h
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/src/vulkan_backend.h')
-rw-r--r--runtime/src/vulkan_backend.h35
1 files changed, 27 insertions, 8 deletions
diff --git a/runtime/src/vulkan_backend.h b/runtime/src/vulkan_backend.h
index d4b6b00a7..e577e6af0 100644
--- a/runtime/src/vulkan_backend.h
+++ b/runtime/src/vulkan_backend.h
@@ -732,13 +732,16 @@ public:
732 const std::uint64_t base = replay_.heap_base; 732 const std::uint64_t base = replay_.heap_base;
733 XdxrLayout layout; 733 XdxrLayout layout;
734 layout.compute(xdxr_elements(b), b.is_tlas); 734 layout.compute(xdxr_elements(b), b.is_tlas);
735 // PERFORM_UPDATE refits the source (the destination itself when no source is given, as D3D12
736 // allows for an in-place update); a full build otherwise.
737 const std::uint64_t from = b.update ? base + (b.src_va ? b.src_va : b.dst_va) : 0;
735 if (b.is_tlas) { 738 if (b.is_tlas) {
736 xdxr_->record_tlas(cb, layout, b.instances_va ? base + b.instances_va : 0, base + b.dst_va, 739 xdxr_->record_tlas(cb, layout, b.instances_va ? base + b.instances_va : 0, base + b.dst_va,
737 base + b.scratch_va, base); 740 base + b.scratch_va, base, from);
738 } else { 741 } else {
739 std::vector<XdxrTriangles> geometries; 742 std::vector<XdxrTriangles> geometries;
740 xdxr_inputs(b, &geometries, base); 743 xdxr_inputs(b, &geometries, base);
741 xdxr_->record_blas(cb, layout, geometries, base + b.dst_va, base + b.scratch_va); 744 xdxr_->record_blas(cb, layout, geometries, base + b.dst_va, base + b.scratch_va, from);
742 } 745 }
743 }; 746 };
744 } else { 747 } else {
@@ -845,7 +848,10 @@ public:
845 query_pools_[id] = pool; 848 query_pools_[id] = pool;
846 } 849 }
847 void remove_query_pool(QueryHeapId id) { 850 void remove_query_pool(QueryHeapId id) {
851 // Lock hierarchy: resource_mutex_ -> tracker_mutex_. Holding tracker_mutex_ before erasing keeps the
852 // QueryPool node alive until any in-flight execute() that unlocked resource_mutex_ finishes QueryReplay::commit().
848 std::unique_lock lock(resource_mutex_); 853 std::unique_lock lock(resource_mutex_);
854 std::lock_guard tlock(tracker_mutex_);
849 query_pools_.erase(id); 855 query_pools_.erase(id);
850 } 856 }
851 // The heap's d3d12_query_heap type, or ~0u for a heap that is not registered. 857 // The heap's d3d12_query_heap type, or ~0u for a heap that is not registered.
@@ -1024,6 +1030,7 @@ public:
1024 1030
1025 std::uint64_t completed_retire_ticket() { 1031 std::uint64_t completed_retire_ticket() {
1026 std::lock_guard lock(submit_mutex_); 1032 std::lock_guard lock(submit_mutex_);
1033 if (is_device_lost()) return 0;
1027 return retire_tickets_.completed([this](VkSemaphore semaphore, std::uint64_t value) { 1034 return retire_tickets_.completed([this](VkSemaphore semaphore, std::uint64_t value) {
1028 std::uint64_t done = 0; 1035 std::uint64_t done = 0;
1029 return vk.vkGetSemaphoreCounterValue(device_, semaphore, &done) == VK_SUCCESS && done >= value; 1036 return vk.vkGetSemaphoreCounterValue(device_, semaphore, &done) == VK_SUCCESS && done >= value;
@@ -1220,8 +1227,12 @@ public:
1220 if (queue_) { 1227 if (queue_) {
1221 std::lock_guard lock(context_.submit_mutex()); 1228 std::lock_guard lock(context_.submit_mutex());
1222 for (; open_labels_; --open_labels_) context_.labels_.queue_end(queue_); 1229 for (; open_labels_; --open_labels_) context_.labels_.queue_end(queue_);
1223 vk.vkQueueWaitIdle(queue_); 1230 const VkResult idle_result = vk.vkQueueWaitIdle(queue_);
1224 if (progress_) context_.retire_queue_idle_locked(progress_); 1231 if (idle_result == VK_SUCCESS) {
1232 if (progress_) context_.retire_queue_idle_locked(progress_);
1233 } else {
1234 context_.mark_device_lost();
1235 }
1225 } 1236 }
1226 if (progress_) { 1237 if (progress_) {
1227 std::lock_guard lock(context_.tracker_mutex_); 1238 std::lock_guard lock(context_.tracker_mutex_);
@@ -1342,6 +1353,7 @@ public:
1342 } 1353 }
1343 const auto resolve = [this](ResourceId id) { return context_.resolve(id); }; 1354 const auto resolve = [this](ResourceId id) { return context_.resolve(id); };
1344 std::uint32_t segments = 0, statistics_segments = 0; 1355 std::uint32_t segments = 0, statistics_segments = 0;
1356 bool has_queries = false;
1345 for (std::size_t i = 0; i < lists.size(); ++i) { 1357 for (std::size_t i = 0; i < lists.size(); ++i) {
1346 const auto result = prepare(*lists[i], resolve, replay, prepared[i]); 1358 const auto result = prepare(*lists[i], resolve, replay, prepared[i]);
1347 if (result != ReplayResult::success) return result; 1359 if (result != ReplayResult::success) return result;
@@ -1350,6 +1362,7 @@ public:
1350 return ReplayResult::unsupported; 1362 return ReplayResult::unsupported;
1351 segments += prepared[i].segment_count; 1363 segments += prepared[i].segment_count;
1352 statistics_segments += prepared[i].statistics_segment_count; 1364 statistics_segments += prepared[i].statistics_segment_count;
1365 has_queries = has_queries || !prepared[i].queries.empty();
1353 } 1366 }
1354 const auto segment_pool = [this](VkQueryType type, std::uint32_t count, 1367 const auto segment_pool = [this](VkQueryType type, std::uint32_t count,
1355 std::shared_ptr<OcclusionSegmentPool>& out) { 1368 std::shared_ptr<OcclusionSegmentPool>& out) {
@@ -1371,6 +1384,10 @@ public:
1371 if (statistics_segments && can_resolve_occlusion && 1384 if (statistics_segments && can_resolve_occlusion &&
1372 !segment_pool(VK_QUERY_TYPE_PIPELINE_STATISTICS, statistics_segments, statistics)) 1385 !segment_pool(VK_QUERY_TYPE_PIPELINE_STATISTICS, statistics_segments, statistics))
1373 return ReplayResult::unsupported; 1386 return ReplayResult::unsupported;
1387 // QueryReplay::plan() reads QueryPool::ended / occlusion and QueryReplay::commit() writes them after
1388 // resource_lock is unlocked. Hold tracker_mutex_ across plan -> emit -> submit -> commit so concurrent queues
1389 // see submission-order query state and remove_query_pool() waits until commit finishes.
1390 if (has_queries && !tracker_lock.owns_lock()) tracker_lock.lock();
1374 QueryReplay queries; 1391 QueryReplay queries;
1375 std::uint32_t base = 0, statistics_base = 0; 1392 std::uint32_t base = 0, statistics_base = 0;
1376 for (auto& list : prepared) { 1393 for (auto& list : prepared) {
@@ -1595,10 +1612,12 @@ private:
1595 return false; 1612 return false;
1596 } 1613 }
1597 const bool ok = (res == VK_SUCCESS); 1614 const bool ok = (res == VK_SUCCESS);
1598 waits_.clear(); 1615 if (ok) {
1599 wait_values_.clear(); 1616 waits_.clear();
1600 for (auto& slot : buffers_) 1617 wait_values_.clear();
1601 if (slot.buffer == command_buffer) slot.ticket = ticket; 1618 for (auto& slot : buffers_)
1619 if (slot.buffer == command_buffer) slot.ticket = ticket;
1620 }
1602 return ok; 1621 return ok;
1603 } 1622 }
1604 1623