upleb.uk

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

summaryrefslogtreecommitdiff
path: root/runtime/shims/d3d12_com.cpp
diff options
context:
space:
mode:
authorbailu12300 <bailu12300@users.noreply.github.com>2026-11-24 03:55:56 +0800
committerbailu12300 <bailu12300@users.noreply.github.com>2026-11-24 03:55:56 +0800
commite1ec785b2ddda4a00f7996951d4cc344fc9e7574 (patch)
tree15a2ecb309a4e8b2db140ef4227a99b3554dcdc5 /runtime/shims/d3d12_com.cpp
parent9cf192d92667103b9c7507a8631603d121962c08 (diff)
d3d12: ExecuteIndirect bounds the span max_count * stride, and checks the offset at max_count 0
d3d12_execute_indirect_validation reports five host-parity mismatches on the RTX 5060 and on WARP: the layer accepts an argument buffer range the host refuses. Both live hosts bound the bytes the signature can walk, max_count * stride, so a record that fits at the end of the buffer while its stride runs past it is refused (offset 240 with stride 20 in a 256-byte buffer), and both check the offset itself when max_count is 0, which the layer skipped entirely. The layer validated with (max_count - 1) * stride + record_size and only when max_count was non-zero. It now uses the same span as the host and validates every call, in d3d12_com.cpp (recording, so Close fails as the host's does) and in vulkan_replay.h (replay, which had its own copy of the old arithmetic). The test's positive GPU path recorded the same out-of-range calls the parity table marks as refused, so it moves to an exact-fit range (244 + 12 == 256) and a max_count 0 no-op at the buffer's end (offset 256), and the five parity rows take the verdict both hosts give here.
Diffstat (limited to 'runtime/shims/d3d12_com.cpp')
-rw-r--r--runtime/shims/d3d12_com.cpp25
1 files changed, 13 insertions, 12 deletions
diff --git a/runtime/shims/d3d12_com.cpp b/runtime/shims/d3d12_com.cpp
index f25168a2a..c89aecc86 100644
--- a/runtime/shims/d3d12_com.cpp
+++ b/runtime/shims/d3d12_com.cpp
@@ -834,18 +834,19 @@ public:
834 } else if (count_buffer_offset != 0) { 834 } else if (count_buffer_offset != 0) {
835 return check(false); 835 return check(false);
836 } 836 }
837 if (max_command_count) { 837 // The record size is checked for every call: D3D12 rejects a signature whose stride cannot hold a record
838 const UINT64 record_size = 838 // even when no command runs. The argument span is what the signature can walk, max_command_count * stride:
839 kind == leonida::IndirectKind::draw ? sizeof(D3D12_DRAW_ARGUMENTS) 839 // the host refuses a range that ends past the buffer (`240` with stride `20` in a `256`-byte buffer), and
840 : kind == leonida::IndirectKind::draw_indexed ? sizeof(D3D12_DRAW_INDEXED_ARGUMENTS) 840 // it checks the offset itself when max_command_count is 0, where the required bytes are none.
841 : kind == leonida::IndirectKind::dispatch ? sizeof(D3D12_DISPATCH_ARGUMENTS) 841 const UINT64 record_size =
842 : 0; 842 kind == leonida::IndirectKind::draw ? sizeof(D3D12_DRAW_ARGUMENTS)
843 if (!record_size || stride < record_size || stride % 4 != 0) 843 : kind == leonida::IndirectKind::draw_indexed ? sizeof(D3D12_DRAW_INDEXED_ARGUMENTS)
844 return check(false); 844 : kind == leonida::IndirectKind::dispatch ? sizeof(D3D12_DISPATCH_ARGUMENTS)
845 const UINT64 required = UINT64(max_command_count - 1) * stride + record_size; 845 : 0;
846 if (argument_buffer_offset > arg_desc.Width || arg_desc.Width - argument_buffer_offset < required) 846 if (!record_size || stride < record_size || stride % 4 != 0) return check(false);
847 return check(false); 847 if (argument_buffer_offset > arg_desc.Width ||
848 } 848 UINT64(max_command_count) > (arg_desc.Width - argument_buffer_offset) / stride)
849 return check(false);
849 leonida::ExecuteIndirect cmd{}; 850 leonida::ExecuteIndirect cmd{};
850 cmd.kind = kind; 851 cmd.kind = kind;
851 cmd.stride = stride; 852 cmd.stride = stride;