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$'`.

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$'`.

74 changes: 72 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 Expand Up @@ -1545,6 +1566,55 @@ NativeComputeShader lower_mesh(const string &code, const MeshStageLayout &layout
alu.write(dst,ir.value("bitcast float "+value+" to i32"));
if (!full_exec) partial_writes.insert(dst);
}
} else if (i.enc==Encoding::Image && i.op==0 && !layout.texture_heap_slot_map &&
(full_exec || exec_skip)) {
// A full V# fetched from the resource heap drives one 1D UNORM load
// of three channels at a VGPR coordinate. The runtime descriptor
// heap slot holds the guest texture descriptor, so this needs no
// slot map; the eight-dword fetch above recorded the slot.
const unsigned dim=(i.a>>3)&7, mask=(i.a>>8)&15;
const auto base=((i.b>>16)&31)*4;
const auto sym=state[base];
if (dim!=0 || mask!=7 || !(i.a&0x1000) || (i.a&0x3c040) || (i.b&0xffe00000u) ||
(i.b&0x3c000000u) || base+8>106 || i.dst>252 ||
sym.type!=Symbol::Type::indexed_descriptor || sym.value!=compute_resource_heap ||
sym.offset ||
(!heap_fetches.count(sym.definition) && !heap_descriptor_slots.count(sym.definition)))
refuse(pc,"unsupported mesh image load or descriptor");
for (unsigned j=1;j<8;++j) {
auto expected=sym;
expected.offset=4*j;
if (!(expected==state[base+j])) refuse(pc,"overwritten mesh texture descriptor");
}
string slot;
const auto fetch=heap_fetches.find(sym.definition);
if (fetch!=heap_fetches.end()) {
const auto &guard=fetch->second;
const auto entry=std::find_if(root_values.begin(),root_values.end(),[&](const auto &x) {
return x.second.param==guard.param && x.second.dword==guard.dword &&
!x.second.shift && x.second.mask==~0u;
});
if (entry==root_values.end()) refuse(pc,"missing mesh heap selector");
emitter.result.mesh_heap_reads.push_back({guard.param,guard.dword,guard.mask});
slot=ir.binary("and",entry->first,to_string(guard.mask));
} else {
const auto stored=heap_descriptor_slots.find(sym.definition);
if (stored==heap_descriptor_slots.end())
refuse(pc,"mesh image load lacks a heap descriptor fetch");
slot=stored->second;
}
ir.features|=0x40000000;
const auto handle=ir.heap_handle(slot,1,1033);
const auto x=alu.read(256+(i.b&255));
const auto load=ir.invoke("%dx.types.ResRet.f32","textureLoad.f32",66,
{{"%dx.types.Handle",handle},{"i32","0"},{"i32",x},{"i32","undef"},{"i32","undef"},
{"i32","undef"},{"i32","undef"},{"i32","undef"}},"nounwind readonly");
for (unsigned j=0;j<3;++j) {
const auto value=ir.value("extractvalue %dx.types.ResRet.f32 "+load+", "+to_string(j));
const auto dst=256+i.dst+j;
alu.write(dst,ir.value("bitcast float "+value+" to i32"));
if (!full_exec) partial_writes.insert(dst);
}
} else if (op.form==gfx1013::Form::mtbuf && (full_exec || exec_skip)) {
const auto base=((i.b>>16)&31)*4;
const auto low=state[base];
Expand Down
Loading
Loading