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

Merged
Leyukaka merged 1 commit from upstream-pr/3497 into main 2026-11-30 02:24:16 +00:00
Leyukaka commented 2026-11-29 18:01:53 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-29T18:01:53Z.


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 1014e85f (base 1b8e2fee), 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

  • v3-v6 are exercised by refusal controls only, with no byte round-trip.
  • Replacing an existing same-named profile is not exercised.
  • Captures with an empty PS are refused for now. Depth-only profiles come in a follow-up after #3493.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5553524380 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3497). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-29T18:01:53Z. --- 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 1014e85f (base 1b8e2fee), `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 - v3-v6 are exercised by refusal controls only, with no byte round-trip. - Replacing an existing same-named profile is not exercised. - Captures with an empty PS are refused for now. Depth-only profiles come in a follow-up after #3493.
Not-Saii commented 2026-11-29 23:05:36 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Not-Saii on 2026-11-29T23:05:36Z.

Review: APPROVED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6105275632 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3497#pullrequestreview-6105275632). Originally posted by [Not-Saii](https://github.com/Not-Saii) on 2026-11-29T23:05:36Z. **Review:** APPROVED --- 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 3. 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`. 4. 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". 5. The tool does not check `rt_formats` entries for `DXGI_FORMAT_UNKNOWN`. The runtime doesn't check this either, so it's optional. 6. 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.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!3497
No description provided.