startup: read mesh pipeline state blocks at their shifted layout #2298

Merged
denn0x merged 1 commit from upstream-pr/2306 into main 2026-11-25 11:35:27 +00:00
denn0x commented 2026-11-25 11:28:57 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by denn0x on 2026-11-25T11:28:57Z.


Refs #1999 (item A)

What

State block A of a slot 57 pipeline comes in two layouts. Vertex pipelines carry 4 in the word at +0x004, and the depth-stencil words sit where #2124 reads them (+0xB8 to +0xC4). Mesh pipelines carry 6 there, and every field from +0x058 on sits 0x54 bytes later, so DB_DEPTH_CONTROL is at +0x10C. Both layouts were measured locally. Before this change, a mesh pipeline's block was read at the vertex offsets, so its depth-stencil state came from unrelated words.

  • src/startup_stubs/pipeline_state_decode.h:
    • state_block_a_shift() returns 0 or 0x54 from the word at +0x004.
    • read_depth_stencil_words applies the shift, reports mesh_layout, and refuses a mesh block too short for the shifted words.
    • A block with any other value at +0x004 is read at the vertex offsets, as before.
  • state_block_blend.h (the +0xD0 blend words) is not changed here. The docs say so.

Test

tests/startup_pipeline_state_check.cpp adds layout_cases:

  • Blocks with +0x004 = 4, 6 and 5. Each holds a different decodable depth state at the other layout's offsets, so a wrong offset decodes to the wrong state rather than to zeros.
  • A short mesh block, which must be refused.

The new startup_pipeline_state_mesh_shift_control run moves the mesh words to the vertex offsets and must fail. It fails 3 of 39 checks.

ctest --test-dir out/build/split --no-tests=error -R "^startup_(pipeline_state|depth_state|slot57_depth|state_block_blend)"
100% tests passed, 0 tests failed out of 6

The six tests are startup_state_block_blend, startup_pipeline_state, _offset_control, _mesh_shift_control, startup_depth_state and _switch_control.

Environment: Windows 11, MSVC Build Tools (VS 18), Ninja Release build of the whole tree (all) on this branch. The tests are device-free, so there were no GPU runs and no capability skips.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6603466013 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2306). Originally posted by [denn0x](https://github.com/denn0x) on 2026-11-25T11:28:57Z. --- Refs #1999 (item A) ## What State block A of a slot 57 pipeline comes in two layouts. Vertex pipelines carry 4 in the word at +0x004, and the depth-stencil words sit where #2124 reads them (+0xB8 to +0xC4). Mesh pipelines carry 6 there, and every field from +0x058 on sits 0x54 bytes later, so `DB_DEPTH_CONTROL` is at +0x10C. Both layouts were measured locally. Before this change, a mesh pipeline's block was read at the vertex offsets, so its depth-stencil state came from unrelated words. - `src/startup_stubs/pipeline_state_decode.h`: - `state_block_a_shift()` returns 0 or 0x54 from the word at +0x004. - `read_depth_stencil_words` applies the shift, reports `mesh_layout`, and refuses a mesh block too short for the shifted words. - A block with any other value at +0x004 is read at the vertex offsets, as before. - `state_block_blend.h` (the +0xD0 blend words) is not changed here. The docs say so. ## Test `tests/startup_pipeline_state_check.cpp` adds `layout_cases`: - Blocks with +0x004 = 4, 6 and 5. Each holds a different decodable depth state at the other layout's offsets, so a wrong offset decodes to the wrong state rather than to zeros. - A short mesh block, which must be refused. The new `startup_pipeline_state_mesh_shift_control` run moves the mesh words to the vertex offsets and must fail. It fails 3 of 39 checks. ``` ctest --test-dir out/build/split --no-tests=error -R "^startup_(pipeline_state|depth_state|slot57_depth|state_block_blend)" 100% tests passed, 0 tests failed out of 6 ``` The six tests are `startup_state_block_blend`, `startup_pipeline_state`, `_offset_control`, `_mesh_shift_control`, `startup_depth_state` and `_switch_control`. Environment: Windows 11, MSVC Build Tools (VS 18), Ninja Release build of the whole tree (`all`) on this branch. The tests are device-free, so there were no GPU runs and no capability skips.
upstream-sync closed this pull request 2026-11-25 12:01:45 +00:00
tedin7 commented 2026-11-25 12:01:46 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T11:32:05Z.

Review: COMMENTED


Review of head 8c6af1b3b0537523f5c2e99cf07e384cb897bc8f (comment only, no approval).

Result: no P1, no P2. Two nits.

Scope: pipeline_state_decode.h (+0x004 layout word, 0x54 shift from +0x058, shifted length check), tests/startup_pipeline_state_check.cpp (layout_cases, --mutate mesh-shift), CMake control test, docs. Title and body are neutral. Mergeable. CI was still pending when I looked (Linux Python checks, Windows build, gfx1013 fixtures).

Logic read

  • state_block_a_shift returns 0 for a null or tiny block, 0x54 only when the word at +0x004 is exactly 6. Any other value keeps the old vertex offsets, so existing callers behave as before.
  • read_depth_stencil_words checks a_refmask_bf + s + 4, so a mesh block cut short is refused instead of read out of bounds. memcpy at off + s stays inside that bound.
  • The only production caller is depth_state_apply.h:27. It is unchanged and gets the right words for both layouts.

Commands executed locally (Linux, mingw-w64 cross build plus wine, since the header needs d3d12.h)

  • git diff --check origin/main...HEAD: clean.
  • python3 tests/docs_links_check.py: 18 files, 446 links, ok.
  • python3 tests/bidi_controls_check.py: 1593 files, ok.
  • x86_64-w64-mingw32-g++ -std=c++17 -static -Isrc tests/startup_pipeline_state_check.cpp, run under wine: 0 of 39 checks failed.
  • Same binary with --mutate mesh-shift: 3 of 39 checks failed, exit 1 (the WILL_FAIL control works).
  • tests/startup_depth_state_check.cpp built and run: 0 of 10 checks failed.

Mutations of the new logic (each reverted with git checkout -- .)

  • Shift always 0: test fails (other layout values..., short mesh block refused and the mesh case), killed.
  • Length check without + s: short mesh block refused fails, killed.

Nits

  • nit: state_block_blend.h (+0xD0 blend words) is still read at the vertex offsets for mesh pipelines. The docs say so, but a mesh pipeline's blend state will be wrong until a follow-up. Worth a tracking line on #1999.
  • nit: the "measured locally" claim for the mesh layout cannot be checked from the repo. A fixture-derived block in the tests would make the 0x54 shift reproducible.

I did not run the Windows WARP pipeline: the change is pure header and CPU-side parsing, with no shader or GPU path.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6056832251 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2306#pullrequestreview-6056832251). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T11:32:05Z. **Review:** COMMENTED --- Review of head `8c6af1b3b0537523f5c2e99cf07e384cb897bc8f` (comment only, no approval). **Result: no P1, no P2. Two nits.** Scope: `pipeline_state_decode.h` (+0x004 layout word, 0x54 shift from +0x058, shifted length check), `tests/startup_pipeline_state_check.cpp` (`layout_cases`, `--mutate mesh-shift`), CMake control test, docs. Title and body are neutral. Mergeable. CI was still pending when I looked (Linux Python checks, Windows build, gfx1013 fixtures). **Logic read** - `state_block_a_shift` returns 0 for a null or tiny block, 0x54 only when the word at +0x004 is exactly 6. Any other value keeps the old vertex offsets, so existing callers behave as before. - `read_depth_stencil_words` checks `a_refmask_bf + s + 4`, so a mesh block cut short is refused instead of read out of bounds. `memcpy` at `off + s` stays inside that bound. - The only production caller is `depth_state_apply.h:27`. It is unchanged and gets the right words for both layouts. **Commands executed locally** (Linux, mingw-w64 cross build plus wine, since the header needs `d3d12.h`) - `git diff --check origin/main...HEAD`: clean. - `python3 tests/docs_links_check.py`: 18 files, 446 links, ok. - `python3 tests/bidi_controls_check.py`: 1593 files, ok. - `x86_64-w64-mingw32-g++ -std=c++17 -static -Isrc tests/startup_pipeline_state_check.cpp`, run under wine: `0 of 39 checks failed`. - Same binary with `--mutate mesh-shift`: `3 of 39 checks failed`, exit 1 (the WILL_FAIL control works). - `tests/startup_depth_state_check.cpp` built and run: `0 of 10 checks failed`. **Mutations of the new logic** (each reverted with `git checkout -- .`) - Shift always 0: test fails (`other layout values...`, `short mesh block refused` and the mesh case), killed. - Length check without `+ s`: `short mesh block refused` fails, killed. **Nits** - nit: `state_block_blend.h` (+0xD0 blend words) is still read at the vertex offsets for mesh pipelines. The docs say so, but a mesh pipeline's blend state will be wrong until a follow-up. Worth a tracking line on #1999. - nit: the "measured locally" claim for the mesh layout cannot be checked from the repo. A fixture-derived block in the tests would make the 0x54 shift reproducible. I did not run the Windows WARP pipeline: the change is pure header and CPU-side parsing, with no shader or GPU path. AI-assisted; commands listed were executed locally.
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!2298
No description provided.