Skip to content

shader: accept the slot 57 heap descriptor load form - #3754

Open
lambirou wants to merge 1 commit into
R0Y00:mainfrom
lambirou:codex/mesh-heap-descriptor
Open

lambirou wants to merge 1 commit into
R0Y00:mainfrom
lambirou:codex/mesh-heap-descriptor

Conversation

@lambirou

@lambirou lambirou commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

The fixed slot 57 mesh shader for req_72e1909e13df6f66 loads a 32-byte
texture descriptor with s_load_dwordx8 s[56:63], s[12:13], s22 (SMEM op 3)
from a resource-heap table and then reads s57, s58 and s59 as numeric
descriptor fields. The mesh frontend only accepted the four-dword op 2 form, so
the request stopped at +0x614: unsupported mesh heap descriptor address;
after op 3 alone, it stopped at +0x69c: unbound numeric SGPR s57 because the
eight words stayed indexed descriptors.

The heap descriptor branch now accepts op 3 with the same checks (zero
immediate offset, constant high word, destination bounds, proven 32-byte
selector). A GPU-proven selector materializes all eight words as the heap slot
(bytes >> 5) with projected_numeric, so a guest numeric read sees a
defined value; the texture slot map keeps priority and keeps words 1..3 as the
guest descriptor metadata. Consumers still require heap_fetches,
token_fetches or texture_heap_fetches.

Validation (Windows, Release):

  • The real MS with the v5 profile layout now reaches
    +0x700: unsupported mesh instruction or EXEC state: image_load; the next
    chain is the texture heap slot map, not the descriptor address.
  • python -B tests/native_direct_mesh_check.py out\\build\\release\\compile_dxil.exe "<DXC dir>"
    — pass, including the x8 fetch, x16 refusal and unaligned-offset control.
  • ctest --preset release --no-tests=error -R '^native_direct' — 2/2 pass.
  • ctest --preset release --no-tests=error -R '^native_fixed_mesh57_warp$'
    — pass.

Refs #3497

R0Y00 commented Dec 1, 2026

Copy link
Copy Markdown
Owner

Review blocker in lower_mesh: the new descriptor_words[j] read runs for all SMEM table-load paths with i.op < 8. memory_count(i) is 1u << (i.op & 7), so a valid non-global 16-dword table load (op == 4) can read beyond the eight-element array. The new x16 refusal covers only the validated global heap branch. Please bound the lookup by descriptor_words.size() and add a source-built non-global wide table control. Also please identify which descriptor bits are actually consumed numerically in the unmapped path so the synthetic slot value does not silently stand in for unrelated guest metadata.

@Leyukaka Leyukaka left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepting s_load_dwordx8 (op 3) on the validated heap branch with the same address checks looks right, and the x16 and unaligned refusals are useful. The problem is the second half of the change: it turns the descriptor words into numeric values that the guest never wrote.

MUST: the eight words get a made-up numeric value (src/gfx1013_direct_mesh.inl:1475-1485, 1505)

For every op 3 fetch on this branch, whether the selector comes from the root or from the GPU, all eight destination words are written as bytes >> 5 and marked projected_numeric. require_numeric (src/gfx1013_compute_native.cpp:1382-1384) checks only Symbol::numeric(), so any later numeric read of s[dst+0..7] now compiles to the heap slot index. On hardware these words hold the image base address, width/height, mip and format fields, and words 4..7 hold depth/pitch/array state. No mapping supplies those values here. The slot-map branch (:1424-1449) is the only place on main that sets projected_numeric on heap words, and it sets it only on words 1..3, which it loads from the remap record. The pixel/compute heap path keeps the slot as the register's identity, but numeric() stays false there ("Numeric consumption still requires real bits", src/gfx1013_compute_native.cpp:730-731). So the code comment's and doc's "as the pixel heap path does" does not match the code on main.

This is the same concern as the last point of the maintainer's comment above. The first option below also removes descriptor_words, and with it the out-of-bounds read reported there.

In the slot 57 MS this is hidden only because the image_load at +0x700 still refuses. A shader that uses s57..s59 (or any of words 0..7) for an address, a bound or a branch, without reaching a refusing consumer, would now produce valid DXIL with wrong values instead of refusing at unbound numeric SGPR. Two options:

  • Accept op 3 but leave the words unmaterialised, so the refusal stays at +0x69c: unbound numeric SGPR s57. That refusal is accurate: the next requirement is the slot map either way.
  • Or materialise them only when a contract supplies the actual field values.

MUST: no fixture covers the new GPU-selected branch (src/gfx1013_direct_mesh.inl:1468-1472, tests/native_direct_mesh_check.py:728)

The real MS takes i.op==3 && heap_entry_offsets.count(bytes) with heap_tokens off. No test reaches that branch:

  • typed-heap-descriptor-x8 (:659) uses typed[:5], a masked root selector, so it records heap_fetches.
  • typed-heap-descriptor-unproven (:664) shifts by 4, so it never enters heap_entry_offsets.
  • mesh-texture-heap-without-map would reach this branch through its former unmasked s21 << 5. The new mask at :728 moves it onto the root branch.

As a result, deleting lines 1468-1472 or changing it to accept any offset would probably still pass. Please add GPU-selected op 3 cases in the style of token-no-contract (gpu_layout, selector from table 16 1, no heap_tokens):

  1. A buffer_load_format through the eight words must still refuse with formatted mesh load lacks an R32_UINT resource heap contract.
  2. The image_load must still refuse without the slot map.
  3. A numeric read of a descriptor word must refuse, for example s_bfe_u32 on word 1 and on word 5 feeding an export (assuming the first finding is fixed).

Keep one unmasked texture fixture so the old path stays covered.

SHOULD: alignment proof and scope of the opaque branch (:1468)

heap_entry_offsets gets an entry from any s_lshl_b32 by an immediate of 5 or more (:2070-2071), so it does prove that the offset is a multiple of 32. The branch records nothing: no heap_fetches, no token_fetches, no mesh_heap_reads. Its only effect is to let the destination words exist. That holds only while no consumer accepts an indexed_descriptor without a fetch record. Please say this in the comment at :1469-1471, so that a later consumer change cannot pick up these words by accident. As written, the comment says the words feed only a descriptor consumer, and the numeric marking makes that untrue.

Note: interaction with #3712

#3712 changes lower_mesh near line 1295 and the test file near line 439. Those are different hunks from this PR, so I expect no textual conflict. Its new image path requires Symbol::Type::descriptor (table words). Heap words here are indexed_descriptor, so mesh-texture-heap-without-map should keep its unsupported mesh instruction or EXEC state: image_load refusal after both PRs merge. Whichever PR merges second should rerun native_direct_mesh on the combined tree.

The doc (docs/experiments/native-mesh-heap-descriptor.md:31-33) repeats the "as the pixel heap path already does" claim. It needs updating together with the first finding.

Verdict: changes requested (the two MUST items).

Reviewed 4dd116c by reading the diff; not built or run.

The stable slot 57 profile 9482ea4411e1e03f reaches the mesh frontend with
req_72e1909e13df6f66.m57 and refused at +0x614. The decoded instruction there
is s_load_dwordx8 s[56:63], s[12:13], s22: SMEM op 3, immediate offset 0, an
SGPR offset proven as a multiple of 32, and the base copied from heap SGPR 23
with a constant zero high word. It feeds image_load v[19:21], v11, s[56:63]
at +0x700.

- The mesh heap branch behind validate_uint_heap_reads accepted only op 2
  (s_load_dwordx4); it now also accepts op 3 (s_load_dwordx8) with the same
  immediate-offset, high-word, destination-range and provenance rules.
- A root-provided selector still records heap_fetches. A GPU-selected selector
  that is a proven multiple of 32 keeps the fetch opaque: it records the heap
  slot (bytes >> 5) by pc, but leaves all eight destination words symbolic.
  Their field bits are not available here, so a numeric read keeps refusing
  (unbound numeric SGPR s33 or s37) until a consumer supplies the fields.
- With texture_heap_slot_map the texture branch keeps priority and words 1..3
  remain the guest descriptor metadata from the remap record.
- The write loop no longer indexes a fixed eight-word array for wider loads;
  it writes texture metadata only, so a sixteen-dword table or heap load
  cannot read past the record.

Observed on the captured MS with the exact profile layout:
- before: native compute +0x614: unsupported mesh heap descriptor address
- now:    native compute +0x69c: unbound numeric SGPR s57

That refusal is the intended boundary: the image consumer and its V# fields
belong to the separate image-load change.

tests/native_direct_mesh_check.py adds the eight-dword heap fetch feeding a
typed load, a sixteen-dword table refusal, a sixteen-dword heap write-loop
control, the GPU-selected typed/image/numeric refusals, and the texture
fixture's masked and unmasked selectors. The slot-map form is the only one
that reads descriptor word 1 numerically.

Verified:
- cmake --build --preset release --target compile_dxil
- python -B tests/native_direct_mesh_check.py <compile_dxil.exe> <dxc dir>:
  exit 0, "mesh allocation, indexed outputs, group exchange and negative
  controls passed"
- ctest --preset release --no-tests=error -R '^native_direct': 2/2 passed

Refs R0Y00#3497
@lambirou
lambirou force-pushed the codex/mesh-heap-descriptor branch from 4dd116c to 6102db8 Compare December 1, 2026 22:36
@lambirou

lambirou commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks — both MUSTs are addressed in 6102db88.

The eight words are no longer materialised. An op 3 fetch records only bytes >> 5 by its pc; the destination words stay indexed_descriptor with no projected_numeric flag. A numeric read now keeps the accurate refusal (unbound numeric SGPR s33 for word 1, s37 for word 5). The slot-map branch is unchanged and still fills words 1..3 from the remap record.

The write loop no longer indexes a fixed array: it writes only texture_metadata, so a 16-dword load (op 4) cannot run past the eight-word record. mesh-table-wide-load covers a non-global table x16 and mesh-heap-wide-load covers a heap x16 that reaches the write loop.

GPU-selected op 3 is now covered in the gpu_layout/token-no-contract style:

  • gpu-heap-descriptor-x8-typed refuses formatted mesh load lacks an R32_UINT resource heap contract;
  • gpu-heap-descriptor-x8-image refuses unsupported mesh instruction or EXEC state: image_load;
  • gpu-heap-descriptor-word-1 and -word-5 refuse unbound numeric SGPR s33 / s37.

The texture fixture keeps both a masked and an unmasked selector; only the slot-map form reads descriptor word 1 numerically. The alignment/opaque comment now says the fetch records only the slot and adds no heap_fetches, token_fetches or mesh_heap_reads entry.

Mutation check: restoring 4dd116c4:src/gfx1013_direct_mesh.inl makes mesh-descriptor-word-1 fail.

Validation on the pushed head:

  • python -B tests/native_direct_mesh_check.py ... — pass.
  • ctest --preset release --no-tests=error -R '^native_direct' — 2/2 passed.
  • git diff --check clean.

The image consumer is the separate #3758 stack; I'll rebase it to use the recorded slot and drop its projected_numeric requirement. The observed refusal for this PR alone is +0x69c: unbound numeric SGPR s57, which is the intended boundary.

AI-assisted.

lambirou added a commit to lambirou/Xbox2Windows that referenced this pull request Dec 1, 2026
The slot 57 capture req_72e1909e13df6f66.m57 contains
  image_load v[19:21], v11, s[56:63] dmask:0x7 dim:SQ_RSRC_IMG_1D unorm
at +0x700, fed by the eight-dword resource-heap fetch at +0x614. This is a
complete guest V#, not a texture heap slot-map record, so the slot-map branch
refuses it.

- A mesh image branch handles the full-V# form when
  !layout.texture_heap_slot_map: image_load (op 0), dim 1D, dmask 0x7, UNORM,
  no LWE/TFE/R128/reserved bits, eight contiguous descriptor words sharing one
  fetch pc and a destination inside the VGPR range.
- The eight words stay symbolic. The fetch is identified by heap_fetches (a
  root-proven selector) or heap_descriptor_slots (a GPU-selected selector);
  no projected_numeric flag is needed.
- createHandleFromHeap(slot) is annotated Texture1D { 1, 1033 } and
  textureLoad.f32 reads mip 0 at the VGPR coordinate, writing the three
  integer channels.
- Four-channel loads, other dimensions, missing UNORM or an unmatched
  descriptor keep refusing.

Observed on the captured MS with the exact profile layout:
- before: native compute +0x700: unsupported mesh instruction or EXEC state: image_load
- now:    native compute +0x69c: unbound numeric SGPR s57

The capture reads descriptor word 1 numerically at +0x69c
(s_bfe_u32 s22, s57, 0x2001e) to build the image coordinate. After R0Y00#3754's
correction the words stay symbolic, which is the accurate refusal: this
branch needs a contract that supplies the real V# field bits before the
+0x700 image is reachable. The source-built fixtures use a constant
coordinate and cover the translation itself; the earlier +0x7c0 observation
belonged to the slot-materialising draft and no longer applies.

tests/native_direct_mesh_check.py adds mesh-image-full-descriptor (root
selector), mesh-image-full-descriptor-root/-gpu, the four-channel and 2D
controls, and keeps the symbolic descriptor-word refusals.

Verified:
- cmake --build --preset release --target compile_dxil
- python -B tests/native_direct_mesh_check.py <compile_dxil.exe> <dxc dir>:
  exit 0, "mesh allocation, indexed outputs, group exchange and negative
  controls passed"
- ctest --preset release --no-tests=error -R '^native_direct': 2/2 passed
- real capture: native compute +0x69c: unbound numeric SGPR s57

Refs R0Y00#3497

@Leyukaka Leyukaka left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review of 6102db88. Read the diff; not built or run.

Both MUST items from my earlier review are addressed:

  • Descriptor words. The op 3 heap branch no longer sets projected_numeric, and descriptor_words is gone. The write loop now fills only words 1..3 from texture_metadata, which stays empty outside the slot-map branch. A numeric read of any of the eight words therefore still refuses at unbound numeric SGPR, and a 16-dword load can no longer index past the record (the maintainer's bounds point). mesh-descriptor-word-1 / -word-5 cover the root-selected case, and the doc no longer claims parity with the pixel heap path.
  • GPU-selected branch coverage. gpu-heap-descriptor-x8-typed, -x8-image, -word-1 and -word-5 reach i.op==3 && heap_entry_offsets.count(bytes) without heap_tokens. Removing that branch would change all four refusals to mesh heap slot lacks masked root constant provenance. Accepting any offset would make typed-heap-descriptor-unproven translate. Both mutations are now caught. mesh-texture-heap-gpu-without-map / -gpu-slot-map keep the unmasked texture path covered.

The SHOULD item is handled too. The comment at the opaque branch now says it adds no heap_fetches, token_fetches or mesh_heap_reads entry.

Two small points:

  1. heap_descriptor_slots (src/gfx1013_direct_mesh.inl:100, written at :1482) is never read in this PR, so each accepted op 3 fetch emits an unused lshr. That is harmless. If #3758 is the consumer, keeping it is fine; otherwise the map could be dropped until something reads it.
  2. The branch now conflicts with main in src/gfx1013_direct_mesh.inl and tests/native_direct_mesh_check.py. Please rebase it, rerun native_direct_mesh and native_direct_container, and check that the GPU-selected cases still produce the same refusals.

I'll approve once the rebased head is up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants