Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions docs/experiments/native-mesh-heap-descriptor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Slot 57 mesh heap descriptor load

The stable slot 57 profile `9482ea4411e1e03f` (version 5, heap SGPR 23,
`validate_uint_heap_reads`, views s16..s19 for roots 0..3) reaches the mesh
frontend with `req_72e1909e13df6f66.m57`. The captured MS is the exact part
the profile carries, so `compile_dxil gfx1013-raw-ms` reproduces the run's
refusal byte for byte.

## Decoded form

At code offset `+0x614` the program issues

s_load_dwordx8 s[56:63], s[12:13], s22

SMEM op 3 (eight dwords), immediate offset 0, SGPR offset s22, base s12:s13
where s12 was copied from the heap SGPR s23 and s13 is the constant 0. The
preceding `s_lshl_b32 s22, s22, 5` proves the byte offset is a multiple of 32,
and the result feeds `image_load v[19:21], v11, s[56:63] dmask:0x7
dim:SQ_RSRC_IMG_1D unorm` at `+0x700`.

## Contract

The mesh heap branch behind `validate_uint_heap_reads` accepted only
`i.op == 2` (one four-dword typed-buffer descriptor). It now also accepts
`i.op == 3`, the eight-dword texture descriptor, with the same address rules:
no immediate offset, an SGPR offset inside the SGPR range, a constant zero high
word and the destination range check. A root-provided selector still records
`heap_fetches`; a GPU-selected selector that is a proven multiple of 32 keeps
the fetch opaque and records only the heap slot:

- the fetch records `bytes >> 5` by its pc for a consumer that brings its own
descriptor contract. The eight destination words stay symbolic; none of
their field bits are available, so a numeric read keeps refusing (for
example `unbound numeric SGPR s33` for word 1 and `s37` for word 5);
- with `texture_heap_slot_map` the texture branch keeps priority and words 1..3
stay the guest descriptor metadata from the remap record;
- the consumers still need their own proof: a buffer load needs
`heap_fetches`/`token_fetches` and an image needs
`texture_heap_fetches`, so an unmapped selection still refuses.

## Observed

Before this change the request refused at `+0x614: unsupported mesh heap
descriptor address`. After accepting the eight-dword form it refused at
`+0x69c: unbound numeric SGPR s57` because the eight words stayed
`indexed_descriptor`. That refusal is the correct one here: the fetch has
recorded the slot, but the image still needs a consumer that can name the V#
fields. The slot-57 image change supplies that consumer separately; it must
use the recorded slot and keep the words symbolic.

## Fixture

[tests/native_direct_mesh_check.py](../../tests/native_direct_mesh_check.py)
adds the eight-dword heap fetch feeding a typed load (`typed-heap-descriptor-x8`),
a sixteen-dword refusal (`typed-heap-descriptor-x16`) and an unaligned-offset
refusal (`typed-heap-descriptor-unproven`). The GPU-selected form is covered by
`gpu-heap-descriptor-x8-typed`, `-x8-image`, `-word-1` and `-word-5`, all of
which keep refusing. `mesh-table-wide-load` and `mesh-heap-wide-load` cover a
sixteen-dword write loop against the eight-word record. The texture fixture has
a masked and an unmasked selector; only the slot-map form reads descriptor
word 1 (`s33`) numerically.

**Reproduce** with
`ctest --preset release --no-tests=error -R '^native_direct'` and
`ctest --preset release --no-tests=error -R '^native_fixed_mesh57_warp$'`.

25 changes: 23 additions & 2 deletions src/gfx1013_direct_mesh.inl
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ NativeComputeShader lower_mesh(const string &code, const MeshStageLayout &layout
std::map<unsigned,RootBits> heap_fetches;
std::set<string> heap_entry_offsets;
std::map<unsigned,string> texture_heap_fetches;
// The heap slot an eight-dword descriptor fetch read, by the pc of that fetch.
std::map<unsigned,string> heap_descriptor_slots;
// heap_tokens: the heap descriptor loads at a byte offset in heap_entry_offsets (a multiple of the 32-byte
// descriptor size), by pc, with that offset.
if (layout.heap_tokens && !layout.validate_uint_heap_reads)
Expand Down Expand Up @@ -1447,19 +1449,38 @@ NativeComputeShader lower_mesh(const string &code, const MeshStageLayout &layout
ir.features|=16;
emitter.result.mesh_texture_heap_slot_map=true;
} else if (global && layout.validate_uint_heap_reads) {
if (i.op!=2 || offset_reg>=106 || (i.b&0xfffff) ||
// A typed-buffer descriptor is one s_load_dwordx4 (op 2) and a
// texture descriptor is one s_load_dwordx8 (op 3); both take
// the same resource-heap address.
if ((i.op!=2 && i.op!=3) || offset_reg>=106 || (i.b&0xfffff) ||
!(state[i.src[0]+1]==Symbol{Symbol::Type::constant,0}))
refuse(pc,"unsupported mesh heap descriptor address");
const auto bytes=alu.operand32(i,offset_reg);
bool heap_descriptor=false;
const auto bits=root_values.find(bytes);
if (bits!=root_values.end() && bits->second.shift==5)
if (bits!=root_values.end() && bits->second.shift==5) {
heap_fetches[pc]=bits->second;
heap_descriptor=true;
}
else if (layout.heap_tokens && heap_entry_offsets.count(bytes))
token_fetches[pc]=bytes;
else if (layout.heap_tokens)
refuse(pc,"mesh heap token byte offset is not a proven multiple of 32");
else if (i.op==3 && heap_entry_offsets.count(bytes))
// A 32-byte-aligned eight-dword fetch whose slot comes from GPU data
// stays opaque. It records only the slot for a consumer that brings its
// own descriptor contract; it adds no heap_fetches, token_fetches or
// mesh_heap_reads entry and leaves the eight words symbolic.
heap_descriptor=true;
else
refuse(pc,"mesh heap slot lacks masked root constant provenance");
if (i.op==3 && heap_descriptor) {
// The eight words are a whole guest V# whose field bits are not
// available here. Record only the heap slot; a consumer that can
// name the fields supplies its own contract, and a numeric read
// keeps refusing until then.
heap_descriptor_slots[pc]=ir.binary("lshr",bytes,"5");
}
} else {
const auto offset=alu.graphics_registers.find(offset_reg);
const bool uniform_load=i.op>=8 && whole_wave_execution() && !branch && forward.empty() &&
Expand Down
92 changes: 80 additions & 12 deletions tests/native_direct_mesh_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,19 @@ def run(name, words, expected=None):
assert marker in text, marker
overwritten = typed[:7] + [0xbea10380] + typed[7:]
run('overwritten-heap-word',overwritten+exported,'overwritten mesh heap descriptor')
# The slot 57 descriptor load may be eight dwords wide: the same heap
# address and proven selector fetch one 32-byte descriptor, and the
# first four words stay the V# a typed load consumes.
x8_fetch = [0xf40c080f, 0x2a000000] # s_load_dwordx8 s[32:39], s[30:31], s21
x8_load = [0x7e020280,0xe0002000,0x80080a01] # v1 = 0; buffer_load_format_x v10, v1, s[32:35] idxen
text = run('typed-heap-descriptor-x8', typed[:5] + x8_fetch + x8_load + exported)
for marker in ('createHandleFromHeap', 'bufferLoad.i32', 'i32 261'):
assert marker in text, marker
run('typed-heap-descriptor-x16', typed[:5] + [0xf410080f, 0x2a000000] + x8_load + exported,
'+0x14: unsupported mesh heap descriptor address')
run('typed-heap-descriptor-unproven',
[0xbe9e0317,0xbe9f0380,0x8f148415] + [0xf40c080f, 0x28000000] + x8_load + exported,
'+0xc: mesh heap slot lacks masked root constant provenance')
# Unindexed buffer_load_format_x reads element 0 without touching vaddr, and its result is uniform under full EXEC.
heap_setup = typed[:7]
load_idxen = [0xe0002000, 0x80080a01] # buffer_load_format_x v10, v1, s[32:35], 0 idxen
Expand Down Expand Up @@ -710,28 +723,57 @@ def skip_load(body, seed=True):
]
text = run('typed-heap-saveexec-then', skip_load(saveexec_load))
assert 'bufferLoad.i32' in text and 'mesh_then' in text and 'phi i32' in text, text
texture = [
texture_fetch = [
0xbe9e0317, 0xbe9f0380, # heap base and zero high word
0x8f148515, # s20 = s21 << 5
0x8715ff15, 31, # mask the root selector
0x8f148515, # s20 = s21 << 5
0xf40c080f, 0x28000000, # s_load_dwordx8 s[32:39], s[30:31], s20
0x9394ff23, 0x4000c, 0x7e020214, # v1 = base mip from descriptor word 3
0xf0001f00, 0x00080a01, # image_load 1D v[10:13] at v1
]
texture_zero = [0x7e020280] # v1 = 0
texture_load = [0xf0001f00, 0x00080a01] # image_load 1D v[10:13] at v1
texture_numeric = [0x9394ff21, 0x4000c, 0x7e020214] # v1 = field from word 1
texture_export = program.copy()
texture_export[7] = 0x7e02030a # pass the red float to POS0.x
run('mesh-texture-heap-without-map',texture+texture_export,'unsupported mesh heap descriptor address')
# The eight words stay symbolic: without a contract a descriptor word
# has no numeric value, for word 1 and word 5 alike.
run('mesh-descriptor-word-1', texture_fetch + texture_numeric + texture_export,
'unbound numeric SGPR s33')
run('mesh-descriptor-word-5',
texture_fetch + [0x9394ff25, 0x4000c, 0x7e020214] + texture_export,
'unbound numeric SGPR s37')
# An image consumer needs the slot map even with a zero coordinate, so
# the descriptor-word read cannot refuse before the image does.
run('mesh-texture-heap-without-map',
texture_fetch + texture_zero + texture_load + texture_export,
'unsupported mesh instruction or EXEC state: image_load')
# The unmasked selector reaches the GPU-selected branch through the
# proven 32-byte shift; it still needs the remapped view.
texture_gpu = [
0xbe9e0317, 0xbe9f0380,
0x8f148515,
0xf40c080f, 0x28000000,
]
run('mesh-texture-heap-gpu-without-map',
texture_gpu + texture_zero + texture_load + texture_export,
'unsupported mesh instruction or EXEC state: image_load')
with layout.open('a') as meta:
meta.write('\ntexture_heap_slot_map')
text = run('mesh-texture-heap-slot-map',texture+texture_export)
texture_mapped = texture_fetch + texture_numeric + texture_load
text = run('mesh-texture-heap-slot-map', texture_mapped + texture_export)
for marker in ('t0,space1', 'RawBuffer', 'createHandleFromHeap', 'textureLoad.f32', 'texture1d'):
assert marker.lower() in text.lower(), marker
bad_shift = texture.copy()
bad_shift[2] = 0x8f148415
run('mesh-texture-heap-unaligned',bad_shift+texture_export,'32-byte alignment proof')
bad_dim = texture.copy()
text = run('mesh-texture-heap-gpu-slot-map',
texture_gpu + texture_zero + texture_load + texture_export)
assert 'textureLoad.f32' in text and 'createHandleFromHeap' in text, text
bad_shift = texture_mapped.copy()
bad_shift[4] = 0x8f148415
run('mesh-texture-heap-unaligned', bad_shift + texture_export, '32-byte alignment proof')
bad_dim = texture_mapped.copy()
bad_dim[-2] |= 8
run('mesh-texture-heap-wrong-dimension',bad_dim+texture_export,'remapped Texture1D heap contract')
run('mesh-texture-heap-overwritten',texture[:5]+[0xbea70380]+texture[5:]+texture_export,
run('mesh-texture-heap-wrong-dimension', bad_dim + texture_export,
'remapped Texture1D heap contract')
run('mesh-texture-heap-overwritten',
texture_mapped[:7] + [0xbea70380] + texture_mapped[7:] + texture_export,
'overwritten mesh texture heap descriptor')
half_frontend = [0xcc210014, 242 | (242 << 9) | (242 << 18)] # v_fma_mixlo_f16 v20, 1, 1, 1
half_pack = [0xd711001a, 276 | (276 << 9)] # pack the defined low half of v20 twice
Expand All @@ -754,6 +796,32 @@ def skip_load(body, seed=True):
gpu_layout = 'mesh1 128 3 1 2 128 64\ntable 16 1\nresource_heap 23\nvalidate_uint_heap_reads'
layout.write_text(gpu_layout)
run('token-no-contract',selected+exported,'mesh heap slot lacks masked root constant provenance')
# A GPU-selected eight-dword descriptor fetch records only its slot.
# The typed consumer has no heap or token fetch, an image needs the
# slot map, and numeric reads of words 1 and 5 stay unbound.
selected_x8 = select_word + times_32 + heap_base + [0xf40c080f, 0x48000000]
run('gpu-heap-descriptor-x8-typed', selected_x8 + formatted + exported,
'formatted mesh load lacks an R32_UINT resource heap contract')
run('gpu-heap-descriptor-x8-image',
selected_x8 + [0x7e020280, 0xf0001f00, 0x00080a01] + texture_export,
'unsupported mesh instruction or EXEC state: image_load')
run('gpu-heap-descriptor-word-1',
selected_x8 + [0x9394ff21, 0x4000c, 0x7e020214] + exported,
'unbound numeric SGPR s33')
run('gpu-heap-descriptor-word-5',
selected_x8 + [0x9394ff25, 0x4000c, 0x7e020214] + exported,
'unbound numeric SGPR s37')
# A sixteen-dword table fetch is refused by the shared table bounds;
# a sixteen-dword heap fetch without the validated branch still reaches
# the write loop, which must stay inside the eight-word record.
wide_table = [0xf4100808, 0xfa000000]
run('mesh-table-wide-load', program[:5] + wide_table + [0x7e020220] + program[6:],
'direct descriptor address outside bound table')
layout.write_text('mesh1 128 3 1 2 128 64\nresource_heap 23')
run('mesh-heap-wide-load',
program[:5] + [0xbe9e0317, 0xbe9f0380, 0xf410080f, 0xfa000000] +
[0x7e020220] + program[6:],
'direct resource-heap load requires the selected GPU slot and its view type')
layout.write_text('mesh1 128 3 1 2 128 64\ntable 16 1\nresource_heap 23\nheap_tokens')
run('token-unvalidated',selected+exported,'mesh heap tokens require validated heap reads')
token_layout = gpu_layout + '\nheap_tokens'
Expand Down
Loading