Skip to content

tooling: build slot 57 mesh profiles from runtime captures - #3497

Merged
R0Y00 merged 1 commit into
R0Y00:mainfrom
Leyukaka:tooling-mesh57-profile-from-capture
Nov 30, 2026
Merged

R0Y00 merged 1 commit into
R0Y00:mainfrom
Leyukaka:tooling-mesh57-profile-from-capture

Conversation

@Leyukaka

Copy link
Copy Markdown
Collaborator

Refs #3416

Why

The native slot 57 path only builds a PSO from a reviewed <variant>.mesh57-state profile, and so far only the test fixtures wrote such profiles. X2W_MESH57_CAPTURE_STATE=1 already writes capture sets (134 in one long local run of the application). This tool turns one capture set plus reviewed desktop state into a profile.

What changes

  • tools/startup/mesh57_profile.py (new): reads a capture archive (.s57) with its three request companions (.m57, .ps57, .root) and a JSON record of the reviewed desktop and entry state, then writes <variant>.mesh57-state.
  • tools/startup/mesh57_pixel_entry.py: capture validation moved into a shared read_creation. Behaviour is unchanged except for error texts and check order (the length check now runs before the key check). No test or caller matches the old strings.
  • tests/native_direct_mesh_check.py: check_profile_writer adds a version 2 byte round-trip and refusal controls.
  • docs/experiments/native-fixed-mesh57.md: invocation.
python -B tools/startup/mesh57_profile.py ARCHIVE REVIEWED.json OUTPUT_DIR

Keep the three request companions beside the archive. check_profile_writer shows a complete version 2 record.

Behaviour

  • The 532-byte header matches Mesh57Profile (src/startup_stubs/mesh57_profile.h) byte for byte: magic 0, lengths 8, mesh 32, blend 56, rasterizer 384, depth-stencil 428, render target formats 480, depth format 516, sample desc 520, sample mask 528. The tool asserts 532.
  • Extensions follow the runtime reader order in native_mesh57.inl: pixel entry (v2+), constant (v3+), view list (v4+), heap_sgpr (v5+), then the six spans (descriptor, two state blocks, root, MS, PS), with no trailing bytes.
  • The v1-v6 and root-flag rules match native_mesh57.inl: v1/v2 refuse heap flags or root parameters, v3+ need a heap flag, v5+ need the view heap flag.
  • Missing, unexpected or duplicate fields are refused. Nothing is defaulted.
  • Capture checks match the runtime: descriptor size and words, state block sizes, exact total length, companions found by the stored request key, key recomputed from MS, PS and root, variant recomputed from the descriptor and state blocks, archive name.
  • Output goes to a staging directory inside the output directory, then one atomic replace. A failure leaves nothing behind and exits 1 with a message.
  • No network, subprocess or dynamic evaluation.

Verification

On 1014e85 (base 1b8e2fe), X2W_WITH_OPUS=OFF:

cmake --preset dev -DX2W_WITH_OPUS:BOOL=OFF
cmake --build --preset dev --target compile_dxil
ctest --preset dev --no-tests=error --output-on-failure -R '^native_direct_mesh$'

1/1 passed. Only compile_dxil has to be built; llvm-mc is not needed.

Mutations, each reverted afterwards:

Mutation Result
blend target packing 9IB3x -> 9I3xB (write_mask moved 3 bytes) caught by the byte round-trip
a missing field accepted with a default instead of refused caught by the refusal control (tool returned 0 and wrote a profile)

Not covered

@Not-Saii Not-Saii left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed at head 1014e85f37416174e6523c2dffef2658c33f81a1 (base 1b8e2fee). I read the diff statically and ran the PR's tests in an isolated, network-disabled Windows Sandbox. Approve. There are no blocking findings. The two SHOULDs are about how much the byte round-trip actually proves, and a mutation confirmed the first one.

What I checked against the runtime

  • Header layout. It matches Mesh57Profile (src/startup_stubs/mesh57_profile.h) field by field: D3D12_BLEND_DESC at 56 (9IB3x per target, 40 bytes), D3D12_RASTERIZER_DESC at 384 (44 bytes), D3D12_DEPTH_STENCIL_DESC at 428 (4I2B2x plus two faces in fail/depth-fail/pass/func order, 52 bytes), D3D12_RT_FORMAT_ARRAY at 480, depth format 516, sample desc 520, sample mask 528, total 532. X2WM57<n> is NUL-padded to 8 bytes, which is what the memcmp in native_mesh57.inl:266-275 expects.
  • Extensions and root rules. These match native_mesh57.inl:271-299. The 0xc00 mask equals root_flags_heap_indexed (src/startup_stubs/heap_indexed_root.h:17-19), and v5+ requires 0x400. The runtime reads no extra fields for v6, and the tool treats v6 like v5.
  • Attachment and sample refusal. It matches native_mesh57.inl:320-325.
  • The read_creation refactor. It keeps every check the old pixel_entry made. Only the messages and the order change, as the body says.
  • Input handling. Bad JSON, wrong types, out-of-range integers, missing, extra or duplicate keys, and NaN/Infinity all end in exit 1 with no output. Publishing is a same-volume staged replace.
  • Downloads and agent config. No downloads, network calls, subprocesses, new build commands or agent-config changes.
  • Fixture content. The fixture is source-built and synthetic.

Findings

MUST

None.

SHOULD

  1. The round-trip does not check where zero-valued fields go (tests/native_direct_mesh_check.py:36-56, :113-118). Many fields in the reviewed record are 0: front_ccw, the three depth-bias fields, multisample, antialiased_line, forced_sample_count, conservative_raster, depth_enable, depth_write_mask, stencil_enable, both stencil masks, every front_face/back_face field, alpha_to_coverage, independent, blend_enable, logic_op_enable and quality. Any reordering among them gives the same bytes. I confirmed this with a mutation (below): swapping the face loop in fixed_state still passes. A fix: add a second record that only goes through the tool, with a distinct nonzero value in every field, and compare it with an expected header packed at absolute offsets. The tool only enforces the sample and attachment rules, so such a record is accepted as long as it keeps count 1, quality 0, mask all ones, and a depth format when depth is enabled.
  2. Nothing tests a correct version 3-6 profile (tools/startup/mesh57_profile.py:103-131). The body notes this. The constant, view-list and heap_sgpr encoding is only reached through the v3 refusal, and that refusal stops earlier, at the root flags. So a field-order slip in sgpr root_parameter root_address, or a missing view count, would go unnoticed. The test already compiles a root with DXC. A second capture set with RootFlags(CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED) would allow a v6 round-trip against the v6 layout that checked_pixel_entry already builds at :130-133.

NIT

  1. Several refusals have no control: a duplicate JSON key (unique_fields), a request key or companion mismatch, a variant/archive-name mismatch, an empty PS, and non-finite floats. The duplicate check is what backs the "duplicates refused" claim in the body. Each needs about one run(...) line; the duplicate key needs raw JSON text instead of json.dumps.
  2. Every refusal in the test fires before the staging directory exists. So not list(output.iterdir()) never exercises staging cleanup. This could go under "Not covered".
  3. The tool does not check rt_formats entries for DXGI_FORMAT_UNKNOWN. The runtime doesn't check this either, so it's optional.
  4. The PR body has no environment. No GPU is involved, but the DXC version matters because the fixture compiles a root signature with it.

What each test proves

  • native_direct_mesh (check_profile_writer, called from checked_pixel_entry):
    • The tool's v2 output equals an independently packed Mesh57Profile header plus the pixel entry and the six spans, for every field with a nonzero value.
    • These are refused with exit 1 and no output: a missing nested field, version 7, an extra section in a v1 record, a v3 record whose root has no heap flags, and an archive one byte short.
    • The existing pixel_entry and compile path still accept the v2 and v6 fixture profiles and reject a changed byte, which exercises the read_creation refactor.
  • startup_tools_lint lints both changed Python files.

Sandbox run

  • Commit: 1014e85f37, exported with git archive, built from a scratch copy.
  • Environment: Windows Sandbox, Windows 11 Enterprise 10.0.26100 build 26100, networking disabled (checked: unreachable), 8 GB. Adapter NVIDIA GeForce RTX 4090 via vGPU, driver 10.0.26100.1150. MSVC 14.44.35207, CMake 3.31.6, Python 3.14.8, DXC from Windows SDK 10.0.26100.
  • Debug layer: unavailable (no d3d12SDKLayers.dll in the sandbox). Neither test uses D3D12.
  • Commands:
    cmake --preset dev -DX2W_WITH_OPUS=OFF
    cmake --build --preset dev --target compile_dxil -j 8
    ctest --preset dev --no-tests=error --output-on-failure -V -R '^(native_direct_mesh|startup_tools_lint)$'
    
  • Results:
    • Passed: native_direct_mesh, startup_tools_lint (2/2).
    • Failed: none.
    • Skipped (77): none.
    • The PR adds no _hardware or _warp tests.

Mutations

Each mutation was applied to a scratch copy of tools/startup/mesh57_profile.py, never to the PR branch. I checked the file hash after each change and restored the file afterwards. The test runs the tool straight from that source tree, so no rebuild was needed. A Python traceback, not a build error, shows each result.

Mutation Expected Observed
A: swap fill_mode cull_mode in the rasterizer field list fail native_direct_mesh failed at the byte round-trip assertion (read_bytes() == blob, line 70). Caught.
B: swap the face loop to ("back_face", "front_face") survive (SHOULD 1) native_direct_mesh passed. Not caught.
Restored (hash matches head) pass 2/2 passed

CI

Run 46292887497 at 1014e85f: the Windows PR job passed 82/82 (xmem_placeholder_split_{control,deployed,partial} skipped by design). It ran startup_tools_lint. It did not run native_direct_mesh, which is outside the pr test-preset filter. The Linux Python job and the gfx1013 assembly job also don't include it, because it needs compile_dxil and DXC. So CI covered only the lint; the run above is the only one of the behavioural test.

Overlap with #3505

Draft #3505 by the same author contains this PR's commit and rewrites the same tool, mesh57_pixel_entry.py, test and doc section. Suggest merging this PR first and rebasing #3505, then reviewing #3505 as a diff against this PR.

@R0Y00
R0Y00 merged commit 622dccf into R0Y00:main Nov 30, 2026
5 checks passed
lambirou added a commit to lambirou/Xbox2Windows that referenced this pull request Dec 1, 2026
lambirou added a commit to lambirou/Xbox2Windows that referenced this pull request Dec 1, 2026
lambirou added a commit to lambirou/Xbox2Windows that referenced this pull request Dec 1, 2026
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 added a commit to lambirou/Xbox2Windows that referenced this pull request Dec 1, 2026
The slot 57 capture req_72e1909e13df6f66.m57 reaches
  image_load v[19:21], v11, s[56:63] dmask:0x7 dim:SQ_RSRC_IMG_1D unorm
at +0x700. The descriptor is a complete guest V# read from the resource heap
by the eight-dword load at +0x614, not a texture heap slot-map record, so the
slot-map branch refused 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 +0x7c0: unproven mesh entry register 287

The next refusal is v_fma_mixlo_f16 reading its own destination to keep the
high half; that mixed-precision form stays outside this change.

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

Refs R0Y00#3497
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
lambirou added a commit to lambirou/Xbox2Windows that referenced this pull request Dec 2, 2026
The slot 57 shader already asked for t<guest>,space2, but the runtime did not
store the host root parameter and the draw path rebuilt the table without a
validated binding. The host root is now a versioned 1.1 signature with the
guest constants, the optional read table, and a root SRV in space 2. The
parameter is stored in IndirectGraphicsPipeline and checked at draw.

The numeric fetch also keeps the fetch's constant byte index so a fixed
s_load's destination symbols, whose offsets include that base, still resolve
to words 1..7. A token SRV projects its guest base address into words 4/5.

Adds a source-built runtime fixture with a Texture1D SRV in the title view
heap. Red exports word 1 and green is 64 only when word 5 is nonzero.

Build: compile_dxil, d3d12_xs_shim, startup_indirect_draw_indexed.
Tests: native_direct_mesh_check passes. Real MS still refuses at
+0x7c0: unproven mesh entry register 287. The new runtime case remains red:
pixel (2,2) expected 0xc04000ff, got 0x000000ff; the draw is forwarded and
the table has the expected V# words on the CPU side, so the remaining issue
is the root SRV read at draw.

Refs R0Y00#3497
lambirou added a commit to lambirou/Xbox2Windows that referenced this pull request Dec 2, 2026
The root-SRV form validated but read zero on WARP. Bind the 1024-entry
table as one R32_UINT SRV of 8192 dwords in a descriptor table at t0,space2
instead. The host root keeps the guest constants and the optional read table,
and the guest root parameter remains the validation key.

A descriptor-word-only stage no longer declares the resource-heap root flag:
the V# fetch is consumed to select the table entry and the module has no
createHandleFromHeap, so DXIL validation refused the unused flag.

The runtime fixture creates the Texture1D through slot 133 at guest address
0x100000000 so word 5 is nonzero and green proves it.

Build: compile_dxil, d3d12_xs_shim, startup_indirect_draw_indexed.
Tests: native_direct 2/2 passes. Real MS still refuses at +0x7c0: unproven
mesh entry register 287. The runtime descriptor-words case still reads zero:
pixel (2,2) expected 0xc04000ff, got 0x000000ff, with dispatchmesh 1.

Refs R0Y00#3497
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