Skip to content
Draft
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$'`.

65 changes: 65 additions & 0 deletions docs/experiments/native-mesh-image-load.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Mesh image_load through a full table descriptor

The slot 57 capture `req_72e1909e13df6f66.m57` reaches `+0x700` after the
eight-dword heap descriptor load of
[native-mesh-heap-descriptor.md](native-mesh-heap-descriptor.md):

image_load v[19:21], v11, s[56:63] dmask:0x7 dim:SQ_RSRC_IMG_1D unorm

The descriptor is a complete guest V# read from the resource heap, not a
texture heap slot-map record, so the existing image branch (which requires
`layout.texture_heap_slot_map`) refused it.

## Lowering

A mesh image branch now handles the full-V# form when
`!layout.texture_heap_slot_map`:

- the instruction must be an `image_load` (op 0) with `dim 1D` (0),
`dmask 0x7`, `unorm` set, no LWE/TFE/R128/reserved bits, no cache-policy
or descriptor base bits in word 1, a destination inside the VGPR range and
eight descriptor words in range;
- the descriptor symbol must be an `indexed_descriptor` of the resource heap at
offset 0 whose eight words share its fetch pc and offsets 0, 4, ..., 28. The
fetch must be recorded by `heap_fetches` or `heap_descriptor_slots`; the
words stay symbolic and an overwritten word keeps refusing;
- the slot comes from the fetch: a root-proven selector uses the same
`heap_fetches` guard as the typed path, records a
`mesh_heap_reads` entry and takes `and(root, mask)`; a GPU-selected fetch
uses the `bytes >> 5` slot recorded by the eight-dword load;
- the load binds `createHandleFromHeap(slot)` as a Texture1D
(`annotateHandle { 1, 1033 }`) and issues `textureLoad.f32` at mip 0 with
the VGPR coordinate, writing the three integer channels.

Four-channel loads, other dimensions, missing UNORM, a mismatched coordinate or
an unmatched descriptor still refuse with `unsupported mesh image load or
descriptor`.

## Observed

With #3754's corrected head the capture refuses at `+0x69c: unbound numeric
SGPR s57`: `s_bfe_u32 s22, s57, 0x2001e` reads descriptor word 1 to build the
image coordinate. The full-V# branch is covered by source-built fixtures with
a constant coordinate; reaching `+0x700` needs a contract that supplies the
real V# field bits.

## Fixture

[tests/native_direct_mesh_check.py](../../tests/native_direct_mesh_check.py)
adds `mesh-image-full-descriptor`: an eight-dword heap fetch behind a masked
root selector drives the 1D UNORM load, and the IR must hold
`createHandleFromHeap`, one `textureLoad.f32` at mip 0 and the three
extracted channels exported through POS0.x. `mesh-image-full-descriptor-root`
and `-gpu` cover the root-proven and GPU-selected fetch paths without a slot
map. `mesh-image-unsupported-dimension` flips the dimension to 2D and must
refuse; `mesh-image-four-channel-without-map` is the dmask-15 control.

Observed on the captured MS with the v5 profile layout: the `+0x700`
`image_load` refusal is gone. The next refusal is
`+0x7c0: unproven mesh entry register 287`, the full `v31` read after the
`v_fma_mixlo_f16` / `v_fma_mixhi_f16` pair.

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

4 changes: 3 additions & 1 deletion src/dxil_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ class DxilModule {
resources.push_back(r);
if (offset.empty() && !static_handles.insert(h).second)
return h;
Text index = reg;
// A root SRV in space 2 is one descriptor, not an array starting at its register number:
// createHandleFromBinding takes the descriptor index inside the binding, which is zero.
Text index = r.space == 2 ? "0" : reg;
auto &out = offset.empty() ? setup : body;
if (!offset.empty()) {
index = r.reg ? binary("add", reg, offset) : offset;
Expand Down
3 changes: 3 additions & 0 deletions src/gfx1013_compute_native.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ struct NativeComputeShader {
std::vector<unsigned> pixel_descriptor_word_tables;
// Pair of guest root parameter and byte offset of a numerically read image descriptor.
std::vector<std::pair<unsigned, unsigned>> pixel_descriptor_records;
// A mesh stage reads guest V# words numerically. The runtime binds a 1024-entry table of eight-dword
// descriptors as a root SRV at this guest root parameter's register number in space 2.
unsigned mesh_descriptor_word_table = ~0u;
std::optional<MeshHeapTokens> mesh_heap_tokens;
std::vector<GraphicsLinkage> inputs, outputs;
std::vector<ComputeConstants> constants;
Expand Down
Loading
Loading