startup: read slot 57 mesh blend words at the shifted offset #3503

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

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


Refs #3416

state_block_blend.h read the eight CB_BLENDn_CONTROL words of a slot 57 state block A at +0xD0 without looking at the layout tag at +0x004. pipeline_state_decode.h already applies the mesh layout's +0x54 shift to the depth-stencil words. The blend reader now applies the same shift.

What changes

  • Tag 4 (vertex): words read at +0xD0, unchanged.
  • Tag 6 (mesh): words read at +0x124. All eight words are required, so the block must be at least 0x144 bytes.
  • Unknown tag or short block: refused through the existing refusal path. A tag-6 block is never read at +0xD0.
  • A refusal does not skip the draw. The pipeline falls back to find_blend on state block A, then B, else draws without blending. The reason is logged as before.
  • state_block_a_shift returns std::optional. The depth-stencil reader takes .value_or(0), so it still uses the vertex offsets for other tags.
  • The draw log records the offset actually read (+0xD0 or +0x124).
  • Untagged synthetic blocks are now refused and draw unblended. The two test fixtures that build slot 57 blocks (startup_stream_consumer.cpp, startup_slot57_depth.cpp) now write tag 4.
  • Behaviour note: on main a tag-6 block was read at +0xD0, found no enabled word and stayed unblended. If the decoder now refuses an enabled tag-6 word at +0x124, that pipeline takes the find_blend heuristic instead. Not measured.

Evidence

One long local run of the application, 134 slot-57 creation captures, all with layout tag 6:

Window Observation
A+0x124+4n 123 captures hold 0x80000000 in all 8 slots
A+0x124+4n 11 captures hold enabled words that decode with valid fields and differ per slot
A+0x124+4n all 35 captures without a pixel shader read 0x80000000 x8
A+0xD0 no word has bit 31, 30 or 29 set
A+0xD0 word 0 follows pixel-shader presence: 0x00CC0000 without, 0x00CC0010 with

This is consistency only: no single blend enable was toggled between two pipelines to confirm the mapping.

Tests

startup_state_block_blend gains a tag-6 block with distinct valid words at +0x124 and a valid decoy at +0xD0, the same block with tag 4, a tag-6 block one byte short of 0x144, and an unknown tag. The refusal cases check that the outputs stay untouched.

Base 77d63db8, dev preset, X2W_WITH_OPUS=OFF:

ctest --preset dev --no-tests=error --output-on-failure -R '^(startup_state_block_blend|startup_pipeline_state(_offset_control|_mesh_shift_control)?|startup_depth_state(_switch_control)?|startup_slot57_(blend_draw|depth)_(warp|hardware)|startup_indirect_requests_(warp|hardware))$'

12/12 passed, 0 skipped.

Mutations in state_block_blend.h, each restored afterwards:

Mutation startup_state_block_blend result
offset fixed at +0xD0 fails "mesh layout" and "short mesh block"
accept 0x143 bytes when the offset is +0x124 fails "short mesh block" only
accept tag 5 fails "unknown layout" only

Removing the tag write from the startup_stream_consumer.cpp fixture makes startup_slot57_blend_draw_warp fail: the blended draw reads (255,0,0,128) where (128,0,128,191) is expected.

Not covered

  • Tags other than 4 and 6: none has been measured, they are refused.
  • CB_TARGET_MASK is still not located.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5553805370 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3503). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-29T18:34:35Z. --- Refs #3416 `state_block_blend.h` read the eight `CB_BLENDn_CONTROL` words of a slot 57 state block A at +0xD0 without looking at the layout tag at +0x004. `pipeline_state_decode.h` already applies the mesh layout's +0x54 shift to the depth-stencil words. The blend reader now applies the same shift. ## What changes - Tag 4 (vertex): words read at +0xD0, unchanged. - Tag 6 (mesh): words read at +0x124. All eight words are required, so the block must be at least 0x144 bytes. - Unknown tag or short block: refused through the existing refusal path. A tag-6 block is never read at +0xD0. - A refusal does not skip the draw. The pipeline falls back to `find_blend` on state block A, then B, else draws without blending. The reason is logged as before. - `state_block_a_shift` returns `std::optional`. The depth-stencil reader takes `.value_or(0)`, so it still uses the vertex offsets for other tags. - The draw log records the offset actually read (+0xD0 or +0x124). - Untagged synthetic blocks are now refused and draw unblended. The two test fixtures that build slot 57 blocks (`startup_stream_consumer.cpp`, `startup_slot57_depth.cpp`) now write tag 4. - Behaviour note: on main a tag-6 block was read at +0xD0, found no enabled word and stayed unblended. If the decoder now refuses an enabled tag-6 word at +0x124, that pipeline takes the `find_blend` heuristic instead. Not measured. ## Evidence One long local run of the application, 134 slot-57 creation captures, all with layout tag 6: | Window | Observation | |---|---| | A+0x124+4n | 123 captures hold 0x80000000 in all 8 slots | | A+0x124+4n | 11 captures hold enabled words that decode with valid fields and differ per slot | | A+0x124+4n | all 35 captures without a pixel shader read 0x80000000 x8 | | A+0xD0 | no word has bit 31, 30 or 29 set | | A+0xD0 | word 0 follows pixel-shader presence: 0x00CC0000 without, 0x00CC0010 with | This is consistency only: no single blend enable was toggled between two pipelines to confirm the mapping. ## Tests `startup_state_block_blend` gains a tag-6 block with distinct valid words at +0x124 and a valid decoy at +0xD0, the same block with tag 4, a tag-6 block one byte short of 0x144, and an unknown tag. The refusal cases check that the outputs stay untouched. Base 77d63db8, `dev` preset, `X2W_WITH_OPUS=OFF`: ``` ctest --preset dev --no-tests=error --output-on-failure -R '^(startup_state_block_blend|startup_pipeline_state(_offset_control|_mesh_shift_control)?|startup_depth_state(_switch_control)?|startup_slot57_(blend_draw|depth)_(warp|hardware)|startup_indirect_requests_(warp|hardware))$' ``` 12/12 passed, 0 skipped. Mutations in `state_block_blend.h`, each restored afterwards: | Mutation | `startup_state_block_blend` result | |---|---| | offset fixed at +0xD0 | fails "mesh layout" and "short mesh block" | | accept 0x143 bytes when the offset is +0x124 | fails "short mesh block" only | | accept tag 5 | fails "unknown layout" only | Removing the tag write from the `startup_stream_consumer.cpp` fixture makes `startup_slot57_blend_draw_warp` fail: the blended draw reads (255,0,0,128) where (128,0,128,191) is expected. ## Not covered - Tags other than 4 and 6: none has been measured, they are refused. - `CB_TARGET_MASK` is still not located.
Not-Saii commented 2026-11-29 22:02:52 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Not-Saii on 2026-11-29T22:02:52Z.

Review: APPROVED


I reviewed head ea3a90c20885f465d056c0053434c3cf2292fb0f: a static read, then a build and test run in an isolated Windows Sandbox (networking disabled, PR tree mapped read-only). The decoder change is correct and well tested. The vertex layout keeps +0xD0, the mesh layout reads +0x124, and short blocks and unknown tags are refused without touching the outputs. Nothing below blocks the merge.

I found no downloads, network calls, CMake/CI changes or agent-config changes.

SHOULD

  1. The mesh-layout result doesn't reach a mesh draw yet. Please say so in the PR body and at docs/startup-runtime.md:3200-3206.

    • bound->blend has one consumer: effective_blend_state → pipeline_for, which builds a VS/PS D3D12_GRAPHICS_PIPELINE_STATE_DESC (src/startup_stubs/d3d12_draw.inl:1399-1402, 1505-1532).
    • The native slot 57 mesh PSO takes its blend from the reviewed profile (src/startup_stubs/native_mesh57.inl:417).
    • So for tag-6 pipelines this PR changes the decoder result and the blend from … at +0x124 log line, not what a mesh draw blends. The same applies to the behaviour note about the find_blend fallback.
    • As written, the doc line reads as if mesh draws now blend.
  2. No draw-level test reads at +0x124. The sandbox mutation below confirms it: with the shift dropped, startup_slot57_blend_draw_{warp,hardware} still pass, because the fixture now writes tag 4 and the check asserts at +0xd0. The &where plumbing in d3d12_draw.inl:1129-1130 is therefore covered for tag 4 only. The fixture's spec string can already write the tag, so one more case in startup_slot57_blend_draw_check.py would cover it: spec 4:6,124:<BLEND>,d0:<another valid word>, asserting the blended colour and at +0x124.

  3. Evidence fields (AGENTS.md "Evidence"). The _hardware results in the PR body don't give the adapter, driver, Windows build or debug-layer status, and they name the base, not the head, as the build under test.

NIT

  • state_block_blend.h:41-49: the length check runs before the layout check. An unknown-tag block that is also shorter than +0xF0 logs "shorter than the blend words", not "unknown state block A layout". The behaviour is the same.
  • The two readers now treat unknown tags differently. Blend refuses them; depth reads them at the vertex offsets (pipeline_state_decode.h:61, .value_or(0)). This is documented and covered by startup_pipeline_state for tag 5. Refusing in the depth reader too could be a follow-up.
  • PR body: "Untagged synthetic blocks are now refused and draw unblended". A refused block falls through to find_blend on state block A, then B (d3d12_draw.inl:1133-1134), so the "unblended" part depends on that heuristic finding nothing.
  • startup_state_block_blend_check.cpp has no case for a tag-6 block whose eight words are all present but disabled. That should succeed unblended with offset 0x124.
  • pipeline_state_decode.h:20 still says "not used by the draw path yet". That was stale before this PR, and the header now also feeds the blend reader.

What the tests prove

  • startup_state_block_blend:
    • "mesh layout" (a 0x144-byte tag-6 block, distinct words at +0x124, a valid decoy at +0xD0) proves the shifted window is read and +0xD0 is ignored.
    • "vertex layout" proves tag 4 still reads +0xD0.
    • "short mesh block" and "unknown layout" prove the refusals, with sentinel checks on all outputs.
    • The edited offset control is stricter than before: it now requires a successful unblended read instead of accepting a refusal.
  • startup_pipeline_state (+ _offset_control, _mesh_shift_control): the std::optional refactor leaves the depth reader unchanged for tags 4, 6 and 5.
  • startup_depth_state (+ _switch_control): the depth path through depth_state_apply.h is unchanged.
  • startup_slot57_blend_draw_*: end to end through translation_for for tag 4, including the new offset reporting.
  • startup_slot57_depth_*, startup_indirect_requests_*, native_startup_request_cache_*: the retagged startup_slot57_depth / startup_stream_consumer fixtures still create and draw slot 57 pipelines, with exact pixel comparisons in the last test.
  • The other slot 57 fixtures in startup_indirect_draw_indexed.cpp pass an empty or 8-byte state block A, so they are refused before and after this change.

Sandbox run

  • Commit: ea3a90c20885f465d056c0053434c3cf2292fb0f, exported tree, dev preset (Debug).
  • Command: cmake --preset dev -DX2W_WITH_OPUS=OFF. I built only the targets these tests need, then:
    ctest --preset dev --no-tests=error --output-on-failure -R '^(startup_state_block_blend|startup_pipeline_state(_offset_control|_mesh_shift_control)?|startup_depth_state(_switch_control)?|startup_slot57_(blend_draw|depth)_(warp|hardware)|startup_indirect_requests_(warp|hardware)|native_startup_request_cache_(warp|hardware))$'
    
  • Passed (14): startup_state_block_blend, startup_pipeline_state, startup_pipeline_state_offset_control, startup_pipeline_state_mesh_shift_control, startup_depth_state, startup_depth_state_switch_control, startup_slot57_depth_warp, startup_slot57_blend_draw_warp, startup_indirect_requests_warp, startup_slot57_depth_hardware, startup_slot57_blend_draw_hardware, startup_indirect_requests_hardware, native_startup_request_cache_warp, native_startup_request_cache_hardware.
  • Failed: none. Skipped (77): none.
  • Environment:
    • Adapter: NVIDIA GeForce RTX 4090 through the Windows Sandbox vGPU, driver 10.0.26100.1150 as reported inside the sandbox.
    • OS: Windows 11 Enterprise 10.0.26100 (build 26100), the sandbox image.
    • Debug layer: off. X2W_D3D12_DEBUG was unset, so the checks used their default of 0, and d3d12SDKLayers.dll isn't present in the sandbox image.

Mutation

  • In a scratch copy, I changed state_block_blend.h:42 to const std::size_t offset = state_block_blend_offset + 0;. This reverts the fix and still compiles.
  • Result: the rebuild succeeded, and startup_state_block_blend failed with FAIL mesh layout and FAIL short mesh block (2 FAILED).
  • The other 13 tests passed, including both startup_slot57_blend_draw backends; that is SHOULD 2.
  • After restoring the file (hash matches the head), startup_state_block_blend passes again.

CI

Run 46296026189 passed, but the Windows job builds and runs only the pr preset (82 smoke tests, fixed targets). It compiled the stand-in that includes both changed headers. It did not build startup_state_block_blend_check, startup_slot57_depth or startup_stream_consumer, and it ran none of the tests above.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6105034637 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3503#pullrequestreview-6105034637). Originally posted by [Not-Saii](https://github.com/Not-Saii) on 2026-11-29T22:02:52Z. **Review:** APPROVED --- I reviewed head `ea3a90c20885f465d056c0053434c3cf2292fb0f`: a static read, then a build and test run in an isolated Windows Sandbox (networking disabled, PR tree mapped read-only). The decoder change is correct and well tested. The vertex layout keeps +0xD0, the mesh layout reads +0x124, and short blocks and unknown tags are refused without touching the outputs. Nothing below blocks the merge. I found no downloads, network calls, CMake/CI changes or agent-config changes. ## SHOULD 1. **The mesh-layout result doesn't reach a mesh draw yet. Please say so in the PR body and at `docs/startup-runtime.md:3200-3206`.** - `bound->blend` has one consumer: `effective_blend_state` → `pipeline_for`, which builds a VS/PS `D3D12_GRAPHICS_PIPELINE_STATE_DESC` (`src/startup_stubs/d3d12_draw.inl:1399-1402, 1505-1532`). - The native slot 57 mesh PSO takes its blend from the reviewed profile (`src/startup_stubs/native_mesh57.inl:417`). - So for tag-6 pipelines this PR changes the decoder result and the `blend from … at +0x124` log line, not what a mesh draw blends. The same applies to the behaviour note about the `find_blend` fallback. - As written, the doc line reads as if mesh draws now blend. 2. **No draw-level test reads at +0x124.** The sandbox mutation below confirms it: with the shift dropped, `startup_slot57_blend_draw_{warp,hardware}` still pass, because the fixture now writes tag 4 and the check asserts `at +0xd0`. The `&where` plumbing in `d3d12_draw.inl:1129-1130` is therefore covered for tag 4 only. The fixture's spec string can already write the tag, so one more case in `startup_slot57_blend_draw_check.py` would cover it: spec `4:6,124:<BLEND>,d0:<another valid word>`, asserting the blended colour and `at +0x124`. 3. **Evidence fields (AGENTS.md "Evidence").** The `_hardware` results in the PR body don't give the adapter, driver, Windows build or debug-layer status, and they name the base, not the head, as the build under test. ## NIT - `state_block_blend.h:41-49`: the length check runs before the layout check. An unknown-tag block that is also shorter than +0xF0 logs "shorter than the blend words", not "unknown state block A layout". The behaviour is the same. - The two readers now treat unknown tags differently. Blend refuses them; depth reads them at the vertex offsets (`pipeline_state_decode.h:61`, `.value_or(0)`). This is documented and covered by `startup_pipeline_state` for tag 5. Refusing in the depth reader too could be a follow-up. - PR body: "Untagged synthetic blocks are now refused and draw unblended". A refused block falls through to `find_blend` on state block A, then B (`d3d12_draw.inl:1133-1134`), so the "unblended" part depends on that heuristic finding nothing. - `startup_state_block_blend_check.cpp` has no case for a tag-6 block whose eight words are all present but disabled. That should succeed unblended with offset 0x124. - `pipeline_state_decode.h:20` still says "not used by the draw path yet". That was stale before this PR, and the header now also feeds the blend reader. ## What the tests prove - `startup_state_block_blend`: - "mesh layout" (a 0x144-byte tag-6 block, distinct words at +0x124, a valid decoy at +0xD0) proves the shifted window is read and +0xD0 is ignored. - "vertex layout" proves tag 4 still reads +0xD0. - "short mesh block" and "unknown layout" prove the refusals, with sentinel checks on all outputs. - The edited offset control is stricter than before: it now requires a successful unblended read instead of accepting a refusal. - `startup_pipeline_state` (+ `_offset_control`, `_mesh_shift_control`): the `std::optional` refactor leaves the depth reader unchanged for tags 4, 6 and 5. - `startup_depth_state` (+ `_switch_control`): the depth path through `depth_state_apply.h` is unchanged. - `startup_slot57_blend_draw_*`: end to end through `translation_for` for tag 4, including the new offset reporting. - `startup_slot57_depth_*`, `startup_indirect_requests_*`, `native_startup_request_cache_*`: the retagged `startup_slot57_depth` / `startup_stream_consumer` fixtures still create and draw slot 57 pipelines, with exact pixel comparisons in the last test. - The other slot 57 fixtures in `startup_indirect_draw_indexed.cpp` pass an empty or 8-byte state block A, so they are refused before and after this change. ## Sandbox run - Commit: `ea3a90c20885f465d056c0053434c3cf2292fb0f`, exported tree, `dev` preset (Debug). - Command: `cmake --preset dev -DX2W_WITH_OPUS=OFF`. I built only the targets these tests need, then: ``` ctest --preset dev --no-tests=error --output-on-failure -R '^(startup_state_block_blend|startup_pipeline_state(_offset_control|_mesh_shift_control)?|startup_depth_state(_switch_control)?|startup_slot57_(blend_draw|depth)_(warp|hardware)|startup_indirect_requests_(warp|hardware)|native_startup_request_cache_(warp|hardware))$' ``` - Passed (14): `startup_state_block_blend`, `startup_pipeline_state`, `startup_pipeline_state_offset_control`, `startup_pipeline_state_mesh_shift_control`, `startup_depth_state`, `startup_depth_state_switch_control`, `startup_slot57_depth_warp`, `startup_slot57_blend_draw_warp`, `startup_indirect_requests_warp`, `startup_slot57_depth_hardware`, `startup_slot57_blend_draw_hardware`, `startup_indirect_requests_hardware`, `native_startup_request_cache_warp`, `native_startup_request_cache_hardware`. - Failed: none. Skipped (77): none. - Environment: - Adapter: NVIDIA GeForce RTX 4090 through the Windows Sandbox vGPU, driver 10.0.26100.1150 as reported inside the sandbox. - OS: Windows 11 Enterprise 10.0.26100 (build 26100), the sandbox image. - Debug layer: off. `X2W_D3D12_DEBUG` was unset, so the checks used their default of 0, and `d3d12SDKLayers.dll` isn't present in the sandbox image. ## Mutation - In a scratch copy, I changed `state_block_blend.h:42` to `const std::size_t offset = state_block_blend_offset + 0;`. This reverts the fix and still compiles. - Result: the rebuild succeeded, and `startup_state_block_blend` failed with `FAIL mesh layout` and `FAIL short mesh block` (2 FAILED). - The other 13 tests passed, including both `startup_slot57_blend_draw` backends; that is SHOULD 2. - After restoring the file (hash matches the head), `startup_state_block_blend` passes again. ## CI Run 46296026189 passed, but the Windows job builds and runs only the `pr` preset (82 smoke tests, fixed targets). It compiled the stand-in that includes both changed headers. It did not build `startup_state_block_blend_check`, `startup_slot57_depth` or `startup_stream_consumer`, and it ran none of the tests above.
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!3503
No description provided.