upleb.uk

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

summaryrefslogtreecommitdiff
path: root/runtime/src/root_signature.cpp
diff options
context:
space:
mode:
authorbennymxckz <133025973+bennymxckz@users.noreply.github.com>2026-11-22 12:29:35 +1000
committerbennymxckz <133025973+bennymxckz@users.noreply.github.com>2026-11-22 12:29:35 +1000
commit14668c62d8ad8b4f9e96e8dba7886efd48749b3b (patch)
tree4a901e0e40165403ba7c923f5b38ad8574963a88 /runtime/src/root_signature.cpp
parent67204bf8c0471335d9046890288b33e8d5e2875b (diff)
Runtime: RTS0 descriptor ranges read Flags before the table offset
parse_rts0 read 1.1/1.2 descriptor-range records with Flags and OffsetInDescriptorsFromTableStart swapped (offset at +16, flags at +20). The PC serializer writes D3D12_DESCRIPTOR_RANGE1 order: type, count, base register, space, Flags, then the offset. Both values were discarded, so nothing broke yet, but the descriptor-table layout would have read flags as offsets. DescriptorRange now keeps all six fields; the canonical codec stores them (codec version 2; nothing persists version 1 blobs). The hand-built 1.1 fixture in root_signature_test had the same swap and is corrected; a 1.0 fixture is added, and root_signature_oracle_test checks every range field against the host serializer for 1.0, 1.1 and 1.2. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/src/root_signature.cpp')
-rw-r--r--runtime/src/root_signature.cpp26
1 files changed, 15 insertions, 11 deletions
diff --git a/runtime/src/root_signature.cpp b/runtime/src/root_signature.cpp
index bdd181f08..8aac0f554 100644
--- a/runtime/src/root_signature.cpp
+++ b/runtime/src/root_signature.cpp
@@ -90,7 +90,9 @@ private:
90}; 90};
91 91
92constexpr uint32_t kCanonicalMagic = 0x3153524Cu; // "LRS1" little-endian 92constexpr uint32_t kCanonicalMagic = 0x3153524Cu; // "LRS1" little-endian
93constexpr uint32_t kCanonicalVersion = 1; 93// 2: ranges store all six D3D12_DESCRIPTOR_RANGE1 fields (1 stored only type and count). Nothing persists these
94// blobs across builds, so version 1 is simply refused.
95constexpr uint32_t kCanonicalVersion = 2;
94 96
95// D3D_ROOT_SIGNATURE_VERSION 1 (1.0), 2 (1.1), 3 (1.2): the numbering RTS0 and the canonical codec both store. 97// D3D_ROOT_SIGNATURE_VERSION 1 (1.0), 2 (1.1), 3 (1.2): the numbering RTS0 and the canonical codec both store.
96bool known_version(uint32_t v, Version& out) { 98bool known_version(uint32_t v, Version& out) {
@@ -121,6 +123,10 @@ std::vector<uint8_t> encode_canonical(const RootSignature& sig) {
121 for (const DescriptorRange& r : p.ranges) { 123 for (const DescriptorRange& r : p.ranges) {
122 put_u32(out, r.range_type); 124 put_u32(out, r.range_type);
123 put_u32(out, r.num_descriptors); 125 put_u32(out, r.num_descriptors);
126 put_u32(out, r.base_shader_register);
127 put_u32(out, r.register_space);
128 put_u32(out, r.flags);
129 put_u32(out, r.offset_in_table);
124 } 130 }
125 } 131 }
126 for (const StaticSampler& s : sig.static_samplers) { 132 for (const StaticSampler& s : sig.static_samplers) {
@@ -198,7 +204,8 @@ DecodeResult decode_canonical(const uint8_t* data, size_t size) {
198 p.ranges.reserve(nranges); 204 p.ranges.reserve(nranges);
199 for (uint32_t j = 0; j < nranges; ++j) { 205 for (uint32_t j = 0; j < nranges; ++j) {
200 DescriptorRange range; 206 DescriptorRange range;
201 if (!r.u32(range.range_type) || !r.u32(range.num_descriptors)) { 207 if (!r.u32(range.range_type) || !r.u32(range.num_descriptors) || !r.u32(range.base_shader_register) ||
208 !r.u32(range.register_space) || !r.u32(range.flags) || !r.u32(range.offset_in_table)) {
202 out.error = "truncated canonical range"; 209 out.error = "truncated canonical range";
203 return out; 210 return out;
204 } 211 }
@@ -344,7 +351,9 @@ static DecodeResult parse_rts0_payload(const uint8_t* data, size_t size) {
344 out.error = "absurd RTS0 range count"; 351 out.error = "absurd RTS0 range count";
345 return out; 352 return out;
346 } 353 }
347 // Range record: {type, num, base_reg, space, offset} (+ flags on 1.1 and 1.2). 354 // Range record, in D3D12_DESCRIPTOR_RANGE(1) order: {type, num, base_reg, space, offset} in 1.0, and
355 // {type, num, base_reg, space, flags, offset} in 1.1 and 1.2: the flags come BEFORE the table offset
356 // (measured against the PC serializer in root_signature_oracle_test).
348 const size_t stride = flags_v11 ? 24 : 20; 357 const size_t stride = flags_v11 ? 24 : 20;
349 if (nranges > 0 && (ranges_off > size || nranges > (size - ranges_off) / stride)) { 358 if (nranges > 0 && (ranges_off > size || nranges > (size - ranges_off) / stride)) {
350 out.error = "RTS0 ranges overrun their payload"; 359 out.error = "RTS0 ranges overrun their payload";
@@ -354,18 +363,13 @@ static DecodeResult parse_rts0_payload(const uint8_t* data, size_t size) {
354 for (uint32_t j = 0; j < nranges; ++j) { 363 for (uint32_t j = 0; j < nranges; ++j) {
355 const size_t roff = static_cast<size_t>(ranges_off) + j * stride; 364 const size_t roff = static_cast<size_t>(ranges_off) + j * stride;
356 DescriptorRange range; 365 DescriptorRange range;
357 uint32_t base_reg = 0, space = 0, disp_off = 0, rflags = 0; 366 const size_t offset_at = roff + (flags_v11 ? 20 : 16);
358 if (!u32_at(roff, range.range_type) || !u32_at(roff + 4, range.num_descriptors) || 367 if (!u32_at(roff, range.range_type) || !u32_at(roff + 4, range.num_descriptors) ||
359 !u32_at(roff + 8, base_reg) || !u32_at(roff + 12, space) || 368 !u32_at(roff + 8, range.base_shader_register) || !u32_at(roff + 12, range.register_space) ||
360 !u32_at(roff + 16, disp_off) || 369 (flags_v11 && !u32_at(roff + 16, range.flags)) || !u32_at(offset_at, range.offset_in_table)) {
361 (flags_v11 && !u32_at(roff + 20, rflags))) {
362 out.error = "truncated RTS0 range"; 370 out.error = "truncated RTS0 range";
363 return out; 371 return out;
364 } 372 }
365 (void)base_reg;
366 (void)space;
367 (void)disp_off;
368 (void)rflags;
369 p.ranges.push_back(range); 373 p.ranges.push_back(range);
370 } 374 }
371 } else { 375 } else {