upleb.uk

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

summaryrefslogtreecommitdiff
path: root/runtime/src
diff options
context:
space:
mode:
authorItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com>2026-11-22 05:37:48 -0500
committerItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com>2026-11-22 05:37:48 -0500
commit41dccfb3e45a6b5b997bf5dc3fe9381a271adeb2 (patch)
tree26d7624af0a1878166230a2871f1732bab2a528d /runtime/src
parent59c34bdc914711ec52a02459f537ed953b37ec0a (diff)
parent3b7cbf46c78e8373b0cfb5aeea2dddd5103dc54f (diff)
Merge pull request #1339 from mrb-eel
Diffstat (limited to 'runtime/src')
-rw-r--r--runtime/src/vulkan_replay.h42
1 files changed, 33 insertions, 9 deletions
diff --git a/runtime/src/vulkan_replay.h b/runtime/src/vulkan_replay.h
index f966fa420..c8ce03c69 100644
--- a/runtime/src/vulkan_replay.h
+++ b/runtime/src/vulkan_replay.h
@@ -716,6 +716,7 @@ enum class ReplayResult {
716 invalid_copy, 716 invalid_copy,
717 invalid_predication, 717 invalid_predication,
718 invalid_query, 718 invalid_query,
719 invalid_indirect_arguments,
719 unsupported 720 unsupported
720}; 721};
721 722
@@ -960,6 +961,21 @@ inline bool within(std::uint64_t offset, std::uint64_t size, std::uint64_t total
960 return offset <= total && size <= total - offset; 961 return offset <= total && size <= total - offset;
961} 962}
962 963
964inline VkDeviceSize indirect_record_size(IndirectKind kind) {
965 switch (kind) {
966 case IndirectKind::draw: return sizeof(VkDrawIndirectCommand);
967 case IndirectKind::draw_indexed: return sizeof(VkDrawIndexedIndirectCommand);
968 case IndirectKind::dispatch: return sizeof(VkDispatchIndirectCommand);
969 }
970 return 0;
971}
972
973inline bool indirect_range(const ResourceBinding& binding, VkDeviceSize offset, VkDeviceSize bytes) {
974 return (binding.buffer_offset | offset) % sizeof(std::uint32_t) == 0 &&
975 within(offset, bytes, binding.size) &&
976 within(binding.buffer_offset, offset + bytes, UINT64_MAX);
977}
978
963// The bytes of a buffer UAV clear, and whether the transfer commands can write them. Elements of up to 4 bytes 979// The bytes of a buffer UAV clear, and whether the transfer commands can write them. Elements of up to 4 bytes
964// repeat in every aligned word, so vkCmdFillBuffer writes the aligned middle and copies from it the unaligned ends 980// repeat in every aligned word, so vkCmdFillBuffer writes the aligned middle and copies from it the unaligned ends
965// (vkCmdCopyBuffer has no alignment rule); that needs one whole word in the middle. Wider elements are written 981// (vkCmdCopyBuffer has no alignment rule); that needs one whole word in the middle. Wider elements are written
@@ -1802,9 +1818,17 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun
1802 out.queries.push_back({i, heap, statistics_active}); 1818 out.queries.push_back({i, heap, statistics_active});
1803 } else if (const auto* ind = std::get_if<ExecuteIndirect>(&command)) { 1819 } else if (const auto* ind = std::get_if<ExecuteIndirect>(&command)) {
1804 if (!bind(ind->argument_buffer) || !p.binding.buffer) return ReplayResult::unresolved_resource; 1820 if (!bind(ind->argument_buffer) || !p.binding.buffer) return ReplayResult::unresolved_resource;
1821 const VkDeviceSize record_size = detail::indirect_record_size(ind->kind);
1822 if (!record_size || ind->stride < record_size || ind->stride % sizeof(std::uint32_t))
1823 return ReplayResult::invalid_indirect_arguments;
1824 const VkDeviceSize bytes = VkDeviceSize(ind->max_count - 1) * ind->stride + record_size;
1825 if (!detail::indirect_range(p.binding, ind->argument_offset, bytes))
1826 return ReplayResult::invalid_indirect_arguments;
1805 if (ind->count_buffer) { 1827 if (ind->count_buffer) {
1806 const ResourceBinding* cnt = resolve(ind->count_buffer); 1828 const ResourceBinding* cnt = resolve(ind->count_buffer);
1807 if (!cnt || !cnt->buffer) return ReplayResult::unresolved_resource; 1829 if (!cnt || !cnt->buffer) return ReplayResult::unresolved_resource;
1830 if (!detail::indirect_range(*cnt, ind->count_offset, sizeof(std::uint32_t)))
1831 return ReplayResult::invalid_indirect_arguments;
1808 p.source = *cnt; 1832 p.source = *cnt;
1809 if ((ind->kind == IndirectKind::draw && !vk.draw_indirect_count) || 1833 if ((ind->kind == IndirectKind::draw && !vk.draw_indirect_count) ||
1810 (ind->kind == IndirectKind::draw_indexed && !vk.draw_indexed_indirect_count) || 1834 (ind->kind == IndirectKind::draw_indexed && !vk.draw_indexed_indirect_count) ||
@@ -2427,25 +2451,25 @@ inline void emit(const PreparedList& prepared, VkCommandBuffer command_buffer, c
2427 VK_PIPELINE_STAGE_TRANSFER_BIT); 2451 VK_PIPELINE_STAGE_TRANSFER_BIT);
2428 vk.copy_buffer(command_buffer, p.source.buffer, p.binding.buffer, 1, p.buffer_copies.data()); 2452 vk.copy_buffer(command_buffer, p.source.buffer, p.binding.buffer, 1, p.buffer_copies.data());
2429 } else if (const auto* ind = std::get_if<ExecuteIndirect>(&command)) { 2453 } else if (const auto* ind = std::get_if<ExecuteIndirect>(&command)) {
2454 const VkDeviceSize arguments = p.binding.buffer_offset + ind->argument_offset;
2430 if (ind->count_buffer) { 2455 if (ind->count_buffer) {
2456 const VkDeviceSize count = p.source.buffer_offset + ind->count_offset;
2431 if (ind->kind == IndirectKind::draw) { 2457 if (ind->kind == IndirectKind::draw) {
2432 vk.draw_indirect_count(command_buffer, p.binding.buffer, ind->argument_offset, p.source.buffer, 2458 vk.draw_indirect_count(command_buffer, p.binding.buffer, arguments, p.source.buffer,
2433 ind->count_offset, ind->max_count, ind->stride); 2459 count, ind->max_count, ind->stride);
2434 } else if (ind->kind == IndirectKind::draw_indexed) { 2460 } else if (ind->kind == IndirectKind::draw_indexed) {
2435 vk.draw_indexed_indirect_count(command_buffer, p.binding.buffer, ind->argument_offset, 2461 vk.draw_indexed_indirect_count(command_buffer, p.binding.buffer, arguments,
2436 p.source.buffer, ind->count_offset, ind->max_count, ind->stride); 2462 p.source.buffer, count, ind->max_count, ind->stride);
2437 } 2463 }
2438 } else { 2464 } else {
2439 if (ind->kind == IndirectKind::draw) { 2465 if (ind->kind == IndirectKind::draw) {
2440 vk.draw_indirect(command_buffer, p.binding.buffer, ind->argument_offset, ind->max_count, 2466 vk.draw_indirect(command_buffer, p.binding.buffer, arguments, ind->max_count, ind->stride);
2441 ind->stride);
2442 } else if (ind->kind == IndirectKind::draw_indexed) { 2467 } else if (ind->kind == IndirectKind::draw_indexed) {
2443 vk.draw_indexed_indirect(command_buffer, p.binding.buffer, ind->argument_offset, ind->max_count, 2468 vk.draw_indexed_indirect(command_buffer, p.binding.buffer, arguments, ind->max_count, ind->stride);
2444 ind->stride);
2445 } else if (ind->kind == IndirectKind::dispatch) { 2469 } else if (ind->kind == IndirectKind::dispatch) {
2446 for (std::uint32_t k = 0; k < ind->max_count; ++k) { 2470 for (std::uint32_t k = 0; k < ind->max_count; ++k) {
2447 vk.dispatch_indirect(command_buffer, p.binding.buffer, 2471 vk.dispatch_indirect(command_buffer, p.binding.buffer,
2448 ind->argument_offset + std::uint64_t(k) * ind->stride); 2472 arguments + VkDeviceSize(k) * ind->stride);
2449 } 2473 }
2450 } 2474 }
2451 } 2475 }