startup: check the cb_blend decoder without a device #1687

Manually merged
github merged 1 commit from gh-pr/1687/head into gh-pr/1687/base 2026-11-26 23:26:06 +00:00
Owner

@⁠Asimmimx on GitHub · 2026-11-24 17:05 UTC · original
Asimmimx:tests/cb-blend-check → main · +273 −1 · 3 files · 1 commits · merged 2026-11-24 17:20 UTC

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).

**@⁠Asimmimx** on GitHub · 2026-11-24 17:05 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1687) `Asimmimx:tests/cb-blend-check` → `main` · +273 −1 · 3 files · 1 commits · merged 2026-11-24 17:20 UTC 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).
Add startup_cb_blend_check, a device-free check of src/startup_stubs/cb_blend.h
next to the existing decoder table and draws in offscreen_check. The existing
table puts every factor in the colour source slot only, and the draws use a
fixed set of words, so 15 of 23 single-point mutants of the header left
startup_cb_blend_warp, startup_cb_blend_swapped_warp and
startup_state_block_blend passing. Among them: a colour or alpha destination
factor left in its colour spelling in DestBlendAlpha (an invalid D3D12 blend
state), COLOR_DESTBLEND or ALPHA_DESTBLEND read one bit short, the factor
refusal dropped for the destination or alpha slots, either combine function
check dropped, the MIN / MAX rule losing one factor, and wrong refusal reasons.

The new check decodes each 5-bit factor value in each of the four factor
slots (and through shared alpha), every pair of colour and alpha CombFunc
values, MIN and MAX with a non-ONE factor on each slot, the write mask of
blended and unblended targets, and control_word against hand-built words. It
kills all 23 mutants. The --mutate dest-alpha-colour run expects the colour
spelling in DestBlendAlpha and is registered with WILL_FAIL as the negative
control.

Refs #1149.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:26:05 +00:00
github manually merged commit 3c684a32dc into gh-pr/1687/base 2026-11-26 23:26:06 +00:00
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 17:15 UTC · original · reviewed

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.

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