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:
authorChatGPT (AI-assisted) <chatgpt@local.invalid>2026-11-22 15:34:34 -0500
committerChatGPT (AI-assisted) <chatgpt@local.invalid>2026-11-22 15:34:34 -0500
commitc262fb7b3c2e3e5c30279eed7bca0e85148e202f (patch)
treeed25d1bb58466c12766dcdb68379587f01b278af /runtime/src/vulkan_backend.h
parentf847748cc76bd3777f9c070c4034eb2fc1c04e64 (diff)
Runtime: gate counted indirect compute dispatches on GPU
Diffstat (limited to 'runtime/src/vulkan_backend.h')
-rw-r--r--runtime/src/vulkan_backend.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/runtime/src/vulkan_backend.h b/runtime/src/vulkan_backend.h
index 1be77a0ca..562e528a7 100644
--- a/runtime/src/vulkan_backend.h
+++ b/runtime/src/vulkan_backend.h
@@ -15,6 +15,7 @@
15#include "statistics_sum_spirv.h" 15#include "statistics_sum_spirv.h"
16#include "vulkan13_features.h" 16#include "vulkan13_features.h"
17#include "vulkan_depth24.h" 17#include "vulkan_depth24.h"
18#include "vulkan_indirect_dispatch_count.h"
18#include "vulkan_scratch.h" 19#include "vulkan_scratch.h"
19#include "vulkan_replay.h" 20#include "vulkan_replay.h"
20#include "queue_families.h" 21#include "queue_families.h"
@@ -941,6 +942,13 @@ public:
941 std::unique_lock lock(resource_mutex_); 942 std::unique_lock lock(resource_mutex_);
942 predicated_copier_ = std::make_unique<PredicatedBufferCopier>(get, device_, limits); 943 predicated_copier_ = std::make_unique<PredicatedBufferCopier>(get, device_, limits);
943 } 944 }
945 // Counts for DISPATCH-only ExecuteIndirect are read by a helper compute shader from GPU memory.
946 // Requires Vulkan bufferDeviceAddress, already enabled for the D3D12 address arena.
947 void configure_counted_dispatch(PFN_vkGetDeviceProcAddr get, const VkPhysicalDeviceMemoryProperties& memory,
948 const VkPhysicalDeviceLimits& limits) {
949 std::unique_lock lock(resource_mutex_);
950 counted_dispatch_ = std::make_unique<IndirectDispatchCounter>(get, device_, memory, limits);
951 }
944 VkDevice device() const { return device_; } 952 VkDevice device() const { return device_; }
945 953
946 // Debug markers become labels from here on; call before any queue or list uses the context. Incomplete sets 954 // Debug markers become labels from here on; call before any queue or list uses the context. Incomplete sets
@@ -1331,6 +1339,7 @@ private:
1331 ReplayFunctions replay_; 1339 ReplayFunctions replay_;
1332 std::unique_ptr<PredicateReducer> predicate_reducer_; 1340 std::unique_ptr<PredicateReducer> predicate_reducer_;
1333 std::unique_ptr<PredicatedBufferCopier> predicated_copier_; 1341 std::unique_ptr<PredicatedBufferCopier> predicated_copier_;
1342 std::unique_ptr<IndirectDispatchCounter> counted_dispatch_;
1334 std::uint32_t predicate_family_ = UINT32_MAX; 1343 std::uint32_t predicate_family_ = UINT32_MAX;
1335 std::uint32_t transfer_only_family_ = UINT32_MAX; 1344 std::uint32_t transfer_only_family_ = UINT32_MAX;
1336 DebugLabelFunctions labels_; 1345 DebugLabelFunctions labels_;
@@ -1563,6 +1572,7 @@ public:
1563 if (const auto* p = std::get_if<Predication>(&command); p && p->buffer) ++captures; 1572 if (const auto* p = std::get_if<Predication>(&command); p && p->buffer) ++captures;
1564 std::unique_ptr<PredicateReducer::Batch> batch; 1573 std::unique_ptr<PredicateReducer::Batch> batch;
1565 std::unique_ptr<PredicatedBufferCopier::Batch> copy_batch; 1574 std::unique_ptr<PredicatedBufferCopier::Batch> copy_batch;
1575 std::unique_ptr<IndirectDispatchCounter::Batch> counted_batch;
1566 if (captures) { 1576 if (captures) {
1567 if (kind_ == QueueKind::copy || !context_.predicate_reducer_ || family_ != context_.predicate_family_) 1577 if (kind_ == QueueKind::copy || !context_.predicate_reducer_ || family_ != context_.predicate_family_)
1568 return ReplayResult::unsupported; 1578 return ReplayResult::unsupported;
@@ -1600,6 +1610,19 @@ public:
1600 return context_.scratch_->get(bytes, buffer, offset); 1610 return context_.scratch_->get(bytes, buffer, offset);
1601 }; 1611 };
1602 } 1612 }
1613 if (kind_ != QueueKind::copy && context_.counted_dispatch_) {
1614 replay.prepare_counted_dispatch = [this, &tracker_lock, &counted_batch](
1615 VkBuffer args, VkDeviceSize args_offset, VkBuffer count, VkDeviceSize count_offset,
1616 std::uint32_t stride, std::uint32_t maximum, CountedDispatch& out) {
1617 // Pipeline creation is lazy and shared across queues; serialize it with other replay preparation.
1618 if (!tracker_lock.owns_lock()) tracker_lock.lock();
1619 if (!counted_batch) counted_batch = context_.counted_dispatch_->batch();
1620 return counted_batch->prepare(args, args_offset, count, count_offset, stride, maximum, out);
1621 };
1622 replay.emit_counted_dispatch = [this](VkCommandBuffer cb, const CountedDispatch& job) {
1623 context_.counted_dispatch_->emit(cb, job);
1624 };
1625 }
1603 if (context_.depth24_ && !transfer_only) { 1626 if (context_.depth24_ && !transfer_only) {
1604 replay.depth24_prepare = [this, &tracker_lock, &depth24_guard](Depth24Job& job, 1627 replay.depth24_prepare = [this, &tracker_lock, &depth24_guard](Depth24Job& job,
1605 std::vector<Depth24Job>& parts) { 1628 std::vector<Depth24Job>& parts) {
@@ -1829,6 +1852,7 @@ public:
1829 context_.tracker_ = std::move(next_tracker); 1852 context_.tracker_ = std::move(next_tracker);
1830 slot->predicate = std::move(batch); 1853 slot->predicate = std::move(batch);
1831 slot->predicated_copy = std::move(copy_batch); 1854 slot->predicated_copy = std::move(copy_batch);
1855 slot->counted_dispatch = std::move(counted_batch);
1832 queries.commit(); 1856 queries.commit();
1833 slot->segments = std::move(queries.retained); 1857 slot->segments = std::move(queries.retained);
1834 } else { 1858 } else {
@@ -1889,6 +1913,7 @@ private:
1889 std::vector<std::shared_ptr<const OcclusionSegmentPool>> segments; 1913 std::vector<std::shared_ptr<const OcclusionSegmentPool>> segments;
1890 std::vector<VkEvent> events; // order_timestamp_copy's, reset and reused once the slot completes 1914 std::vector<VkEvent> events; // order_timestamp_copy's, reset and reused once the slot completes
1891 std::unique_ptr<PredicatedBufferCopier::Batch> predicated_copy; 1915 std::unique_ptr<PredicatedBufferCopier::Batch> predicated_copy;
1916 std::unique_ptr<IndirectDispatchCounter::Batch> counted_dispatch;
1892 std::unique_ptr<PredicateReducer::Batch> predicate; // retained until this slot completes 1917 std::unique_ptr<PredicateReducer::Batch> predicate; // retained until this slot completes
1893 }; 1918 };
1894 1919
@@ -2007,6 +2032,7 @@ private:
2007 if (context_.vk.vkResetCommandBuffer(reuse->buffer, 0) != VK_SUCCESS) return nullptr; 2032 if (context_.vk.vkResetCommandBuffer(reuse->buffer, 0) != VK_SUCCESS) return nullptr;
2008 reuse->predicate.reset(); 2033 reuse->predicate.reset();
2009 reuse->predicated_copy.reset(); 2034 reuse->predicated_copy.reset();
2035 reuse->counted_dispatch.reset();
2010 reuse->ticket = UINT64_MAX; // in use until submitted 2036 reuse->ticket = UINT64_MAX; // in use until submitted
2011 return reuse; 2037 return reuse;
2012 } 2038 }