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

Manually merged
github merged 1 commit from gh-pr/2306/head into gh-pr/2306/base 2026-11-27 00:14:17 +00:00
Owner

@⁠denn0x on GitHub · 2026-11-25 11:28 UTC · original
denn0x:startup/mesh-state-layout → main · +82 −11 · 4 files · 1 commits · merged 2026-11-25 11:35 UTC

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.

**@⁠denn0x** on GitHub · 2026-11-25 11:28 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2306) `denn0x:startup/mesh-state-layout` → `main` · +82 −11 · 4 files · 1 commits · merged 2026-11-25 11:35 UTC 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.
State block A of a slot 57 pipeline has a second layout for mesh pipelines: the word at +0x004 is 6
there (4 for vertex pipelines), and every field from +0x058 on sits 0x54 bytes later, so
DB_DEPTH_CONTROL is at +0x10C instead of +0xB8. Both layouts were measured locally.

read_depth_stencil_words now applies that shift (state_block_a_shift) and reports which layout it read.
A block with any other value at +0x004 keeps the vertex offsets, as before. The blend reader
(state_block_blend.h) is unchanged.

Test: startup_pipeline_state gains vertex, mesh and other-value blocks that each hold a different
decodable state at the other layout's offsets, and a short mesh block that must be refused.
startup_pipeline_state_mesh_shift_control (the mesh words at the vertex offsets) must fail.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 00:14:16 +00:00
github manually merged commit 8c6af1b3b0 into gh-pr/2306/base 2026-11-27 00:14:17 +00:00
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 11:32 UTC · original · reviewed

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.

**@⁠tedin7** on GitHub · 2026-11-25 11:32 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2306#pullrequestreview-6056832251) · **reviewed** 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.
This discussion has been locked. Commenting is limited to contributors.
No description provided.