tooling: draft reviewed slot 57 profiles from captures #3505

Closed
Leyukaka wants to merge 13 commits from upstream-pr/3505 into main
Leyukaka commented 2026-11-29 18:47:35 +00:00 (Migrated from github.com)

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


Refs #3416

Stacked on #3493, #3497 and #3503. Until they merge, this PR also shows their commits (including 1014e85f and ea3a90c2) and the merges 196adf8c, 5a5df32c and 2ca22af6. Its own commits are 527ee33a, d8af54b7, 243d7e4a and 5b05bac2.

Why

A reviewed slot 57 profile needs the desktop state of the pipeline. Writing that by hand for 100+ pipelines is not practical. The capture and the .t57 sidecar from #3502 already hold most of it, so the tool can prefill what it can decode exactly and leave the rest to the reviewer.

What

Depth-only profiles (527ee33a, d8af54b7). mesh57_profile.py accepts a capture with a zero-length .ps57:

  • rt_formats and blend.targets must be empty.
  • Depth must be enabled with depth_write_mask 1.
  • depth_format must be a typed DSV format (20, 40, 45 or 55).
  • Version 1 has no pixel field. Versions 2–5 need all three pixel fields zero. Version 6 is refused.
  • Blend RT0 is filled with a fixed disabled entry (ONE/ZERO, ADD, NOOP, all channels). The runtime leaves it unchecked for zero RTVs.

d8af54b7 fixes the padding added in 527ee33a, which produced a 564-byte header instead of 532. The padding is now computed from the rasterizer offset (384) minus the 32-byte prefix. The test asserts a 532-byte header on every successful write and adds a refusal case for a depth-only capture with one RTV format and a matching blend target.

Draft mode (243d7e4a, 5b05bac2). --draft ARCHIVE DRAFT_JSON writes a JSON in the reviewed schema to a new path:

  • Depth and stencil are decoded from block A, tag 6, words at A+0x10C, 0x110, 0x114 and 0x118, with the rules of pipeline_state_decode.h.
  • Blend is decoded from the eight words at A+0x124+4n with the word rules of cb_blend.h and state_block_blend.h: factor table, bit 29 shared or separate alpha, combine mapping, MIN/MAX needing ONE/ONE, alpha forms and dual-source restrictions. All eight words are validated. The draft keeps one target per RTV.
  • RTV formats, DSV format and sample settings come from the .t57 sidecar when it holds exactly one distinct tuple. Several tuples or an overflow line are refused, and the refusal lists them. Without a tuple these fields and blend stay null.
  • A depth-only tuple with an empty .ps57 gives an empty target list.
  • Every other field is null. Each field carries its provenance, and the draft has review_required: true. The stencil reference and DSV writability appear in provenance only, because the profile has no field for them.

The profile writer refuses a draft that still has a null anywhere or still has the review_required key. For a tag 6 capture it also reruns the decoder refusals.

Intentional differences from the C++

  • A tag other than 6 is refused. The C++ falls back to the vertex offsets.
  • Depth bounds, and a back face whose masks or reference differ from the front, are refused. The C++ only flags them.
  • independent is derived from differences between the selected targets. The C++ always sets it. With identical targets the result is the same, since RT0 then applies to all.

Not covered

  • write_mask, logic_op, logic_op_enable and alpha_to_coverage are not located in the capture and stay null.
  • After the reviewer edits the draft, the decoded values are not compared with the capture again.
  • The .t57 sidecar is written by #3502.

Tests

Dev preset, X2W_WITH_OPUS=OFF.

  • At d8af54b7, ctest -R '^(native_direct_mesh|native_fixed_mesh57_depth_only_)': 3/3 passed (native_direct_mesh, native_fixed_mesh57_depth_only_warp, native_fixed_mesh57_depth_only_hardware).
  • At 243d7e4a, ctest -R '^(mesh57_profile_draft|native_direct_mesh|startup_pipeline_state(_offset_control|_mesh_shift_control)?)$': 5/5 passed.
  • At 5b05bac2, ctest -R '^(mesh57_profile_draft|native_direct_mesh|startup_state_block_blend|startup_cb_blend_decode)': 5/5 passed (mesh57_profile_draft, native_direct_mesh, startup_state_block_blend, startup_cb_blend_decode, startup_cb_blend_decode_dest_alpha_control).

Mutations, each caught and then restored:

Mutation Failing test
Padding without the 32-byte prefix native_direct_mesh (the writer's 532 assert fires first)
Depth-only RTV-count check removed native_direct_mesh
Depth write no longer gated by depth enable mesh57_profile_draft
Two .t57 tuples accepted mesh57_profile_draft
Writer review_required check removed mesh57_profile_draft
Blend offset 0x124 changed to 0xD0 mesh57_profile_draft
Bit 29 ignored (alpha always separate) mesh57_profile_draft
Legacy paired factor BOTH_SRC_ALPHA accepted mesh57_profile_draft
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5553917886 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3505). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-29T18:47:35Z. --- Refs #3416 Stacked on #3493, #3497 and #3503. Until they merge, this PR also shows their commits (including 1014e85f and ea3a90c2) and the merges 196adf8c, 5a5df32c and 2ca22af6. Its own commits are 527ee33a, d8af54b7, 243d7e4a and 5b05bac2. ## Why A reviewed slot 57 profile needs the desktop state of the pipeline. Writing that by hand for 100+ pipelines is not practical. The capture and the `.t57` sidecar from #3502 already hold most of it, so the tool can prefill what it can decode exactly and leave the rest to the reviewer. ## What **Depth-only profiles (527ee33a, d8af54b7).** `mesh57_profile.py` accepts a capture with a zero-length `.ps57`: - `rt_formats` and `blend.targets` must be empty. - Depth must be enabled with `depth_write_mask` 1. - `depth_format` must be a typed DSV format (20, 40, 45 or 55). - Version 1 has no `pixel` field. Versions 2–5 need all three `pixel` fields zero. Version 6 is refused. - Blend RT0 is filled with a fixed disabled entry (ONE/ZERO, ADD, NOOP, all channels). The runtime leaves it unchecked for zero RTVs. d8af54b7 fixes the padding added in 527ee33a, which produced a 564-byte header instead of 532. The padding is now computed from the rasterizer offset (384) minus the 32-byte prefix. The test asserts a 532-byte header on every successful write and adds a refusal case for a depth-only capture with one RTV format and a matching blend target. **Draft mode (243d7e4a, 5b05bac2).** `--draft ARCHIVE DRAFT_JSON` writes a JSON in the reviewed schema to a new path: - Depth and stencil are decoded from block A, tag 6, words at A+0x10C, 0x110, 0x114 and 0x118, with the rules of `pipeline_state_decode.h`. - Blend is decoded from the eight words at A+0x124+4n with the word rules of `cb_blend.h` and `state_block_blend.h`: factor table, bit 29 shared or separate alpha, combine mapping, MIN/MAX needing ONE/ONE, alpha forms and dual-source restrictions. All eight words are validated. The draft keeps one target per RTV. - RTV formats, DSV format and sample settings come from the `.t57` sidecar when it holds exactly one distinct tuple. Several tuples or an overflow line are refused, and the refusal lists them. Without a tuple these fields and blend stay null. - A depth-only tuple with an empty `.ps57` gives an empty target list. - Every other field is null. Each field carries its provenance, and the draft has `review_required: true`. The stencil reference and DSV writability appear in provenance only, because the profile has no field for them. The profile writer refuses a draft that still has a null anywhere or still has the `review_required` key. For a tag 6 capture it also reruns the decoder refusals. ## Intentional differences from the C++ - A tag other than 6 is refused. The C++ falls back to the vertex offsets. - Depth bounds, and a back face whose masks or reference differ from the front, are refused. The C++ only flags them. - `independent` is derived from differences between the selected targets. The C++ always sets it. With identical targets the result is the same, since RT0 then applies to all. ## Not covered - `write_mask`, `logic_op`, `logic_op_enable` and `alpha_to_coverage` are not located in the capture and stay null. - After the reviewer edits the draft, the decoded values are not compared with the capture again. - The `.t57` sidecar is written by #3502. ## Tests Dev preset, `X2W_WITH_OPUS=OFF`. - At d8af54b7, `ctest -R '^(native_direct_mesh|native_fixed_mesh57_depth_only_)'`: 3/3 passed (`native_direct_mesh`, `native_fixed_mesh57_depth_only_warp`, `native_fixed_mesh57_depth_only_hardware`). - At 243d7e4a, `ctest -R '^(mesh57_profile_draft|native_direct_mesh|startup_pipeline_state(_offset_control|_mesh_shift_control)?)$'`: 5/5 passed. - At 5b05bac2, `ctest -R '^(mesh57_profile_draft|native_direct_mesh|startup_state_block_blend|startup_cb_blend_decode)'`: 5/5 passed (`mesh57_profile_draft`, `native_direct_mesh`, `startup_state_block_blend`, `startup_cb_blend_decode`, `startup_cb_blend_decode_dest_alpha_control`). Mutations, each caught and then restored: | Mutation | Failing test | |---|---| | Padding without the 32-byte prefix | `native_direct_mesh` (the writer's 532 assert fires first) | | Depth-only RTV-count check removed | `native_direct_mesh` | | Depth write no longer gated by depth enable | `mesh57_profile_draft` | | Two `.t57` tuples accepted | `mesh57_profile_draft` | | Writer `review_required` check removed | `mesh57_profile_draft` | | Blend offset 0x124 changed to 0xD0 | `mesh57_profile_draft` | | Bit 29 ignored (alpha always separate) | `mesh57_profile_draft` | | Legacy paired factor BOTH_SRC_ALPHA accepted | `mesh57_profile_draft` |
Leyukaka commented 2026-11-29 19:01:44 +00:00 (Migrated from github.com)

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


New head cf40d844: the writer now re-derives from the capture the fields the draft decoded exactly (depth/stencil, blend words, RT/DSV formats and samples) and refuses a reviewed state that contradicts them, naming the fields. Fields left null in the draft stay reviewer-supplied. It also refuses a malformed .t57; without a .t57, only depth/stencil is checked.

Test: tests/mesh57_profile_draft_check.py edits depth function, blend source, RTV format, and DSV + sample fields, and expects each refusal to name the fields and leave the output directory empty; a valid review is compared byte-for-byte. ctest --preset dev -R '^(native_direct_mesh|mesh57_profile_draft)': 2/2 passed.
Mutation: with if mismatches: disabled in the writer, the edited depth_func is accepted and the test fails.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7260948745 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3505#issuecomment-7260948745). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-29T19:01:44Z. --- New head cf40d844: the writer now re-derives from the capture the fields the draft decoded exactly (depth/stencil, blend words, RT/DSV formats and samples) and refuses a reviewed state that contradicts them, naming the fields. Fields left null in the draft stay reviewer-supplied. It also refuses a malformed `.t57`; without a `.t57`, only depth/stencil is checked. Test: `tests/mesh57_profile_draft_check.py` edits depth function, blend source, RTV format, and DSV + sample fields, and expects each refusal to name the fields and leave the output directory empty; a valid review is compared byte-for-byte. `ctest --preset dev -R '^(native_direct_mesh|mesh57_profile_draft)'`: 2/2 passed. Mutation: with `if mismatches:` disabled in the writer, the edited `depth_func` is accepted and the test fails.
lukaslw-lab commented 2026-11-30 07:13:12 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-30T07:13:12Z.

Review: APPROVED


Reviewed cf40d844 (own commits 527ee33a..cf40d844; #3497 and #3503 are merged, #3493 is still below) by reading the diff; not built or run. Draft PR.

Verdict: approve. The draft path only fills what it can decode exactly, and since cf40d844 the writer re-checks those fields against the capture. One SHOULD can follow. No MUST.

  • SHOULD check DSV writability against depth writes. read_captured_state drops the .t57 writable bit (tools/startup/mesh57_profile.py:258-259). It reaches the draft only as provenance text (:343), and the writer never compares it. A capture that decodes depth_write_mask 1 but was only observed with a read-only DSV (writable 0) therefore builds a profile that writes depth through a read-only view. The fixture's alternate tuple (tests/mesh57_profile_draft_check.py:152) alone would make a refusal case. Refusing depth_write_mask 1 with writable 0 next to the mismatch check (:491) closes it.
  • NIT depth-only requires depth_write_mask 1 (:402), so a stencil-only pass (depth writes off, stencil writes on) is refused. That is fine for now; a line in the experiment note would say so.
  • Checked, no finding:
    • All eight blend words are validated, including unused ones. That matches the C++ (state_block_blend.h:55), so draft and runtime refuse the same captures.
    • capture_mismatches compares only the decoded keys. Lists of different lengths count as a mismatch. Fields left null in the draft stay reviewer-owned.
    • The header padding is now computed from the rasterizer offset, and the 532-byte assert guards it. --draft opens its output with "x", so it never overwrites a file.
    • read_targets accepts exactly what #3502's writer emits: format 0 RTVs, and writable 1 without a DSV, are refused.

Tests: mesh57_profile_draft proves the depth/stencil and blend decoding, the .t57 conflict and overflow refusals, review_required, and (cf40d844) refusals of edited fields with an empty output directory. CI ran it in the Linux Python job (green). native_direct_mesh (depth-only writer, 532-byte header) is not in the Windows pr filter or the Linux list, so only the author's local runs cover it.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6108148337 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3505#pullrequestreview-6108148337). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-11-30T07:13:12Z. **Review:** APPROVED --- Reviewed `cf40d844` (own commits 527ee33a..cf40d844; #3497 and #3503 are merged, #3493 is still below) by reading the diff; not built or run. Draft PR. **Verdict: approve.** The draft path only fills what it can decode exactly, and since cf40d844 the writer re-checks those fields against the capture. One SHOULD can follow. No MUST. - **SHOULD** check DSV writability against depth writes. `read_captured_state` drops the `.t57` `writable` bit (`tools/startup/mesh57_profile.py:258-259`). It reaches the draft only as provenance text (`:343`), and the writer never compares it. A capture that decodes `depth_write_mask 1` but was only observed with a read-only DSV (`writable 0`) therefore builds a profile that writes depth through a read-only view. The fixture's `alternate` tuple (`tests/mesh57_profile_draft_check.py:152`) alone would make a refusal case. Refusing `depth_write_mask 1` with `writable 0` next to the mismatch check (`:491`) closes it. - **NIT** depth-only requires `depth_write_mask 1` (`:402`), so a stencil-only pass (depth writes off, stencil writes on) is refused. That is fine for now; a line in the experiment note would say so. - Checked, no finding: - All eight blend words are validated, including unused ones. That matches the C++ (`state_block_blend.h:55`), so draft and runtime refuse the same captures. - `capture_mismatches` compares only the decoded keys. Lists of different lengths count as a mismatch. Fields left null in the draft stay reviewer-owned. - The header padding is now computed from the rasterizer offset, and the 532-byte assert guards it. `--draft` opens its output with `"x"`, so it never overwrites a file. - `read_targets` accepts exactly what #3502's writer emits: format 0 RTVs, and `writable 1` without a DSV, are refused. Tests: `mesh57_profile_draft` proves the depth/stencil and blend decoding, the `.t57` conflict and overflow refusals, `review_required`, and (cf40d844) refusals of edited fields with an empty output directory. CI ran it in the Linux Python job (green). `native_direct_mesh` (depth-only writer, 532-byte header) is not in the Windows `pr` filter or the Linux list, so only the author's local runs cover it.

Pull request closed

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!3505
No description provided.