startup: check the cb_blend decoder without a device #1680

Merged
Asimmimx merged 1 commit from upstream-pr/1687 into main 2026-11-24 17:20:30 +00:00
Asimmimx commented 2026-11-24 17:05:11 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Asimmimx on 2026-11-24T17:05:11Z.


Refs #1149.

Change

src/startup_stubs/cb_blend.h decodes a CB_BLENDn_CONTROL word and a CB_TARGET_MASK nibble into a D3D12_RENDER_TARGET_BLEND_DESC. It refuses, with a reason, the forms D3D12 cannot express (BOTH_SRC_ALPHA/BOTH_INV_SRC_ALPHA, constant alpha without alpha blend factor support, unknown factors and combine functions, MIN/MAX with factors other than ONE). state_block_blend.h uses it for slot 57 pipelines and passes the reason on to the log.

Three tests reach the header without a hardware adapter today:

  • startup_cb_blend_warp (offscreen_check --startup-cb-blend) runs a decoder table and then 18 WARP draws compared with a CPU model. The table puts all 21 factor values in the colour source slot only. The destination and alpha slots get only the values used by a few fixed words.
  • startup_cb_blend_swapped_warp is the same run with source and destination exchanged, as its negative control.
  • startup_state_block_blend decodes the four words measured on #1216 and one refused word.

The device run needs a D3D12 device. Only the colour source slot sees the whole factor table, and no case checks a refusal reason. 15 of 23 single-point mutants of the header left all three tests passing (table below). One of them leaves a colour factor such as SRC_COLOR in its colour spelling in DestBlendAlpha. D3D12 accepts only the alpha spelling in that field, so a classic multiply blend (ZERO, SRC_COLOR) would produce a blend state D3D12 rejects. The existing draws cannot catch it because none of them has a colour factor in the destination alpha slot.

This PR adds tests/startup_cb_blend_check.cpp, a device-free check registered next to the existing cb_blend block in CMakeLists.txt:

Case What it pins
each 5-bit factor value (0-31) in each of the four slots, other slots at ONE/ZERO, with and without alpha blend factor support (256 decodes) the colour and alpha mapping of every factor in every slot, the full 5-bit field width of each slot, refusal of 11, 12, 21-31, and 19/20 without support, with the reason naming the cause
the same values through shared alpha (SEPARATE_ALPHA_BLEND clear) in the source and in the destination field, with refused values in every alpha field the colour fields fill both channels, alpha spelling in both alpha slots, alpha fields not read
every pair of colour and alpha CombFunc values 0-7 with separate alpha, plus shared alpha with an unknown alpha function each channel's function mapped and checked on its own
MIN and MAX on the colour and on the alpha channel, with ONE/ONE and with ZERO, SRC_ALPHA or INV_SRC1_COLOR in each of the two slots, the other channel adding with SRC_ALPHA/INV_SRC_ALPHA the MIN/MAX rule per slot and per channel, with the "MIN / MAX" reason
masks 0-15 on a blended word and on the same word with ENABLE clear; masks 0x10, 0x1F, 0x100, 0xFFFFFFFF the write mask on both paths and the refusal of masks wider than a nibble
control_word against four words written out by hand (one with a distinct value in each field, one with every field overfull); raw 0x74331291 decoded with and without alpha blend factor support the helper's field positions and masks, and a raw word with distinct factors and functions in all six fields

--mutate dest-alpha-colour expects the colour spelling in DestBlendAlpha. It is registered as startup_cb_blend_decode_dest_alpha_control with WILL_FAIL (24 of 526 cases fail).

docs/startup-runtime.md: the cb_blend paragraph now names the device-free check and its control. No existing test or case is changed.

Mutation probe

I applied each mutant to cb_blend.h alone, rebuilt offscreen_check, startup_state_block_blend_check and startup_cb_blend_check, and ran the four tests. Then I reverted it. "Before" is the three existing tests; "after" adds startup_cb_blend_decode.

Mutant Before After
M1 colour destination factor not checked for "no D3D12 form" survived killed
M2 alpha source factor not checked survived killed
M3 alpha destination factor not checked survived killed
M4 reason of a bad destination factor taken from the source field survived killed
M5 BOTH_INV_SRC_ALPHA (12) reported as an unknown factor survived killed
M6 colour combine function not checked survived killed
M7 alpha combine function not checked survived killed
M8 colour MIN/MAX ignores the destination factor survived killed
M9 alpha MIN/MAX ignores the source factor survived killed
M10 MAX not treated as min/max killed killed
M11 DestBlendAlpha without the alpha form survived killed
M12 SrcBlendAlpha without the alpha form killed killed
M13 ALPHA_DESTBLEND read as [27:24] survived killed
M14 COLOR_DESTBLEND read as [11:8] survived killed
M15 ALPHA_SRCBLEND read as [19:16] killed killed
M16 ALPHA_COMB_FCN read as [22:21] killed killed
M17 alpha form of INV_SRC1_COLOR is SRC1_ALPHA killed killed
M18 MIN/MAX refusal labelled "unknown combine function" survived killed
M19 control_word keeps 4 bits of ALPHA_DESTBLEND survived killed
M20 mask limit > 0x1F killed killed
M21 factor 16 maps to SRC1_COLOR killed killed
M22 CONSTANT_ALPHA reason only for 19 survived killed
M23 alpha form of INV_DEST_COLOR dropped killed killed

M14 survived the WARP draws even though the "constant alpha" draw uses ONE_MINUS_CONSTANT_ALPHA (20) as the destination factor. Read as [11:8], 20 becomes 4 (SRC_ALPHA), and with the draw's constant alpha 0.25 and source alpha 0.75 both factors are 0.75, so the result is the same.

Not pinned: when more than one slot is refused, the reason names the first in the order colour source, colour destination, alpha source, alpha destination. That order looks like an implementation detail, so the new check puts only one bad value in each word. It also does not pin the factor fields of an unblended (ENABLE clear) target beyond SrcBlend; D3D12 ignores them.

Verification

Base c864f138 (main) plus commit 3c684a32, dev preset (Debug), Windows 11 Pro build 26300.9974, MSVC 19.51.36260 (Visual Studio), Windows SDK 10.0.26100.0, WARP 10.0.26100.9818. No _hardware test was run.

cmake --preset dev
cmake --build --preset dev --target startup_cb_blend_check offscreen_check startup_state_block_blend_check
ctest --preset dev --no-tests=error -R '^(startup_cb_blend_decode(_dest_alpha_control)?|startup_cb_blend_(swapped_)?warp|startup_state_block_blend)$' -V
#   5/5 passed
#   startup_cb_blend_decode: PASS (526 cases)
#   startup_cb_blend_decode_dest_alpha_control: "24 of 526 FAILED", exit 1 (WILL_FAIL)
#   startup_cb_blend_warp: swapped=0 drawn=18 skipped=0 mismatches=0
#   startup_cb_blend_swapped_warp: swapped=1 drawn=18 skipped=0 mismatches=14
#   startup_state_block_blend: PASS

tests/docs_links_check.py, tests/bidi_controls_check.py and git diff --check passed.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6587191351 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1687). Originally posted by [Asimmimx](https://github.com/Asimmimx) on 2026-11-24T17:05:11Z. --- Refs #1149. ## Change `src/startup_stubs/cb_blend.h` decodes a `CB_BLENDn_CONTROL` word and a `CB_TARGET_MASK` nibble into a `D3D12_RENDER_TARGET_BLEND_DESC`. It refuses, with a reason, the forms D3D12 cannot express (`BOTH_SRC_ALPHA`/`BOTH_INV_SRC_ALPHA`, constant alpha without alpha blend factor support, unknown factors and combine functions, MIN/MAX with factors other than ONE). `state_block_blend.h` uses it for slot 57 pipelines and passes the reason on to the log. Three tests reach the header without a hardware adapter today: - `startup_cb_blend_warp` (`offscreen_check --startup-cb-blend`) runs a decoder table and then 18 WARP draws compared with a CPU model. The table puts all 21 factor values in the **colour source slot only**. The destination and alpha slots get only the values used by a few fixed words. - `startup_cb_blend_swapped_warp` is the same run with source and destination exchanged, as its negative control. - `startup_state_block_blend` decodes the four words measured on #1216 and one refused word. The device run needs a D3D12 device. Only the colour source slot sees the whole factor table, and no case checks a refusal reason. 15 of 23 single-point mutants of the header left all three tests passing (table below). One of them leaves a colour factor such as `SRC_COLOR` in its colour spelling in `DestBlendAlpha`. D3D12 accepts only the alpha spelling in that field, so a classic multiply blend (`ZERO`, `SRC_COLOR`) would produce a blend state D3D12 rejects. The existing draws cannot catch it because none of them has a colour factor in the destination alpha slot. This PR adds `tests/startup_cb_blend_check.cpp`, a device-free check registered next to the existing cb_blend block in `CMakeLists.txt`: | Case | What it pins | |---|---| | each 5-bit factor value (0-31) in each of the four slots, other slots at ONE/ZERO, with and without alpha blend factor support (256 decodes) | the colour and alpha mapping of every factor in every slot, the full 5-bit field width of each slot, refusal of 11, 12, 21-31, and 19/20 without support, with the reason naming the cause | | the same values through shared alpha (`SEPARATE_ALPHA_BLEND` clear) in the source and in the destination field, with refused values in every alpha field | the colour fields fill both channels, alpha spelling in both alpha slots, alpha fields not read | | every pair of colour and alpha CombFunc values 0-7 with separate alpha, plus shared alpha with an unknown alpha function | each channel's function mapped and checked on its own | | MIN and MAX on the colour and on the alpha channel, with ONE/ONE and with ZERO, SRC_ALPHA or INV_SRC1_COLOR in each of the two slots, the other channel adding with SRC_ALPHA/INV_SRC_ALPHA | the MIN/MAX rule per slot and per channel, with the "MIN / MAX" reason | | masks 0-15 on a blended word and on the same word with ENABLE clear; masks 0x10, 0x1F, 0x100, 0xFFFFFFFF | the write mask on both paths and the refusal of masks wider than a nibble | | `control_word` against four words written out by hand (one with a distinct value in each field, one with every field overfull); raw `0x74331291` decoded with and without alpha blend factor support | the helper's field positions and masks, and a raw word with distinct factors and functions in all six fields | `--mutate dest-alpha-colour` expects the colour spelling in `DestBlendAlpha`. It is registered as `startup_cb_blend_decode_dest_alpha_control` with `WILL_FAIL` (24 of 526 cases fail). `docs/startup-runtime.md`: the cb_blend paragraph now names the device-free check and its control. No existing test or case is changed. ## Mutation probe I applied each mutant to `cb_blend.h` alone, rebuilt `offscreen_check`, `startup_state_block_blend_check` and `startup_cb_blend_check`, and ran the four tests. Then I reverted it. "Before" is the three existing tests; "after" adds `startup_cb_blend_decode`. | Mutant | Before | After | |---|---|---| | M1 colour destination factor not checked for "no D3D12 form" | **survived** | killed | | M2 alpha source factor not checked | **survived** | killed | | M3 alpha destination factor not checked | **survived** | killed | | M4 reason of a bad destination factor taken from the source field | **survived** | killed | | M5 `BOTH_INV_SRC_ALPHA` (12) reported as an unknown factor | **survived** | killed | | M6 colour combine function not checked | **survived** | killed | | M7 alpha combine function not checked | **survived** | killed | | M8 colour MIN/MAX ignores the destination factor | **survived** | killed | | M9 alpha MIN/MAX ignores the source factor | **survived** | killed | | M10 MAX not treated as min/max | killed | killed | | M11 `DestBlendAlpha` without the alpha form | **survived** | killed | | M12 `SrcBlendAlpha` without the alpha form | killed | killed | | M13 `ALPHA_DESTBLEND` read as [27:24] | **survived** | killed | | M14 `COLOR_DESTBLEND` read as [11:8] | **survived** | killed | | M15 `ALPHA_SRCBLEND` read as [19:16] | killed | killed | | M16 `ALPHA_COMB_FCN` read as [22:21] | killed | killed | | M17 alpha form of `INV_SRC1_COLOR` is `SRC1_ALPHA` | killed | killed | | M18 MIN/MAX refusal labelled "unknown combine function" | **survived** | killed | | M19 `control_word` keeps 4 bits of `ALPHA_DESTBLEND` | **survived** | killed | | M20 mask limit `> 0x1F` | killed | killed | | M21 factor 16 maps to `SRC1_COLOR` | killed | killed | | M22 `CONSTANT_ALPHA` reason only for 19 | **survived** | killed | | M23 alpha form of `INV_DEST_COLOR` dropped | killed | killed | M14 survived the WARP draws even though the "constant alpha" draw uses `ONE_MINUS_CONSTANT_ALPHA` (20) as the destination factor. Read as [11:8], 20 becomes 4 (`SRC_ALPHA`), and with the draw's constant alpha 0.25 and source alpha 0.75 both factors are 0.75, so the result is the same. Not pinned: when more than one slot is refused, the reason names the first in the order colour source, colour destination, alpha source, alpha destination. That order looks like an implementation detail, so the new check puts only one bad value in each word. It also does not pin the factor fields of an unblended (`ENABLE` clear) target beyond `SrcBlend`; D3D12 ignores them. ## Verification Base `c864f138` (`main`) plus commit `3c684a32`, `dev` preset (Debug), Windows 11 Pro build 26300.9974, MSVC 19.51.36260 (Visual Studio), Windows SDK 10.0.26100.0, WARP 10.0.26100.9818. No `_hardware` test was run. ```powershell cmake --preset dev cmake --build --preset dev --target startup_cb_blend_check offscreen_check startup_state_block_blend_check ctest --preset dev --no-tests=error -R '^(startup_cb_blend_decode(_dest_alpha_control)?|startup_cb_blend_(swapped_)?warp|startup_state_block_blend)$' -V # 5/5 passed # startup_cb_blend_decode: PASS (526 cases) # startup_cb_blend_decode_dest_alpha_control: "24 of 526 FAILED", exit 1 (WILL_FAIL) # startup_cb_blend_warp: swapped=0 drawn=18 skipped=0 mismatches=0 # startup_cb_blend_swapped_warp: swapped=1 drawn=18 skipped=0 mismatches=14 # startup_state_block_blend: PASS ``` `tests/docs_links_check.py`, `tests/bidi_controls_check.py` and `git diff --check` passed. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-24 18:02:31 +00:00
tedin7 commented 2026-11-24 18:02:32 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T17:15:07Z.

Review: COMMENTED


Verified at commit 3c684a32dc0745f74f54fbc13d45f4eaff01f76b:

  • Diff & scope audit: test-only + docs + test-only CMakeLists.txt registration (startup_cb_blend_check, startup_cb_blend_decode, and startup_cb_blend_decode_dest_alpha_control with WILL_FAIL TRUE). Zero production code changes, zero weakened assertions, no temporary files or subprocesses, clean-room/title-neutral.
  • Linux checks:
    • git diff --check origin/main...HEAD — clean
    • python3 tests/docs_links_check.py — self-test passed, 16 Markdown files, 350 links
    • python3 tests/bidi_controls_check.py — self-test passed, 1278 files, no bidirectional controls
  • Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP):
    • Debug (--preset dev):
      • cmake --build --preset dev --target startup_cb_blend_check startup_stream_consumer -- -j 6 (3.94s)
      • ctest --preset dev -R '^(startup_cb_blend_decode|startup_cb_blend_decode_dest_alpha_control)$' --parallel 4 --no-tests=error --output-on-failure — 2/2 passed (0.09s)
    • Release /O2 (--preset release):
      • cmake --build --preset release --target startup_cb_blend_check startup_stream_consumer -- -j 6 (1.77s)
      • ctest --preset release -R '^(startup_cb_blend_decode|startup_cb_blend_decode_dest_alpha_control)$' --parallel 4 --no-tests=error --output-on-failure — 2/2 passed (0.12s)
  • Mutation checks (Windows Server 2025, --preset dev, patched src/startup_stubs/cb_blend.h):
    1. Dropped alpha_form() on d.DestBlendAlpha (d.DestBlendAlpha = dst_a;): ctest --preset dev -R '^startup_cb_blend_decode$' --output-on-failure FAILED as expected (24 of 526 FAILED across separate and shared destination alpha slots).
    2. Dropped dst_a != D3D12_BLEND_ONE in the alpha MIN / MAX guard: ctest --preset dev -R '^startup_cb_blend_decode$' --output-on-failure FAILED as expected (6 of 526 FAILED on alpha MIN/MAX with non-ONE destination factors).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6043980644 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1687#pullrequestreview-6043980644). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T17:15:07Z. **Review:** COMMENTED --- Verified at commit `3c684a32dc0745f74f54fbc13d45f4eaff01f76b`: - **Diff & scope audit**: test-only + docs + test-only `CMakeLists.txt` registration (`startup_cb_blend_check`, `startup_cb_blend_decode`, and `startup_cb_blend_decode_dest_alpha_control` with `WILL_FAIL TRUE`). Zero production code changes, zero weakened assertions, no temporary files or subprocesses, clean-room/title-neutral. - **Linux checks**: - `git diff --check origin/main...HEAD` — clean - `python3 tests/docs_links_check.py` — self-test passed, 16 Markdown files, 350 links - `python3 tests/bidi_controls_check.py` — self-test passed, 1278 files, no bidirectional controls - **Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP)**: - **Debug (`--preset dev`)**: - `cmake --build --preset dev --target startup_cb_blend_check startup_stream_consumer -- -j 6` (`3.94s`) - `ctest --preset dev -R '^(startup_cb_blend_decode|startup_cb_blend_decode_dest_alpha_control)$' --parallel 4 --no-tests=error --output-on-failure` — **2/2 passed** (`0.09s`) - **Release `/O2` (`--preset release`)**: - `cmake --build --preset release --target startup_cb_blend_check startup_stream_consumer -- -j 6` (`1.77s`) - `ctest --preset release -R '^(startup_cb_blend_decode|startup_cb_blend_decode_dest_alpha_control)$' --parallel 4 --no-tests=error --output-on-failure` — **2/2 passed** (`0.12s`) - **Mutation checks (Windows Server 2025, `--preset dev`, patched `src/startup_stubs/cb_blend.h`)**: 1. Dropped `alpha_form()` on `d.DestBlendAlpha` (`d.DestBlendAlpha = dst_a;`): `ctest --preset dev -R '^startup_cb_blend_decode$' --output-on-failure` **FAILED** as expected (`24 of 526 FAILED` across separate and shared destination alpha slots). 2. Dropped `dst_a != D3D12_BLEND_ONE` in the alpha `MIN / MAX` guard: `ctest --preset dev -R '^startup_cb_blend_decode$' --output-on-failure` **FAILED** as expected (`6 of 526 FAILED` on alpha `MIN`/`MAX` with non-`ONE` destination factors). 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!1680
No description provided.