fix: refuse dual-source blend factors on render targets other than 0 #1504

Merged
tedin7 merged 2 commits from upstream-pr/1511 into main 2026-11-25 05:22:52 +00:00
tedin7 commented 2026-11-24 13:24:15 +00:00 (Migrated from github.com)

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


Change

Refs #1216. state_block_blend decoded all eight CB_BLENDn_CONTROL words and accepted a SRC1_* (dual-source) factor on any target, as well as blending on targets 1-7 alongside a dual-source target 0. Dual-source blending reads the pixel shader's second output, which exists for render target 0 only, and D3D12 forbids blending on targets 1-7 when target 0 uses dual-source factors (OM_DUAL_SOURCE_BLENDING_CAN_ONLY_HAVE_RENDER_TARGET_0). Both invalid cases are now refused ("dual-source factor on a target other than 0" / "dual-source blend on target 0 with another blending target"), each offending target is set in refused_targets, and the output is left alone (the caller keeps its previous path, as for any refused word). Target 0 with targets 1-7 disabled (ENABLE clear) is accepted, and a target with ENABLE clear uses no factor and is not refused.

Audit result for the other points of the blend headers (no change needed): a 40-million-word sweep of cb_blend::decode (every field value including undefined factors 21-31 and combine functions 5-7, words with all bits set, with and without alpha-factor support) never produced an out-of-range D3D12_BLEND/D3D12_BLEND_OP, a colour-only factor in an alpha slot, BlendEnable together with LogicOpEnable, a write mask above 0xF, or a refusal without a reason.

Verification

  • MinGW + Wine check: x86_64-w64-mingw32-g++ -std=c++17 -Wall -Wextra -Werror -static -Isrc -o sbb.exe tests/startup_state_block_blend_check.cpp && wine sbb.exe -> startup_state_block_blend: PASS (4 measured words, enable clear, 5 controls, dual source)
  • Same test against the unmodified state_block_blend.h from origin/main: fails on dual source on target > 0 and dual source on target 0 with blending target > 0, exit 1.
  • git diff --check origin/main...HEAD, tests/docs_links_check.py, tests/bidi_controls_check.py: clean.
  • Windows Server 2025 Debug (--preset dev) and Release /O2 (--preset release): ctest --preset <preset> -R '^startup_state_block_blend' --no-tests=error --output-on-failure -> 1/1 passed (details in PR comment).

Evidence and follow-up

Synthetic state blocks built in the test; no captured data. Assumption: the dual-source rules (target 0 only, and no other blending target alongside dual-source target 0) follow the D3D12/Vulkan blend rules and the hardware's single second export. Not changed, candidates for separate work: the stream and derived-patch blend descriptors are copied without range checks; find_blend accepts factors up to 19 only (misses ALPHA_FACTOR/INV_ALPHA_FACTOR); blending on integer render target formats is not checked in pipeline_for.

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; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6582785314 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1511). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T13:24:15Z. --- ## Change Refs #1216. `state_block_blend` decoded all eight `CB_BLENDn_CONTROL` words and accepted a `SRC1_*` (dual-source) factor on any target, as well as blending on targets 1-7 alongside a dual-source target 0. Dual-source blending reads the pixel shader's second output, which exists for render target 0 only, and D3D12 forbids blending on targets 1-7 when target 0 uses dual-source factors (`OM_DUAL_SOURCE_BLENDING_CAN_ONLY_HAVE_RENDER_TARGET_0`). Both invalid cases are now refused ("dual-source factor on a target other than 0" / "dual-source blend on target 0 with another blending target"), each offending target is set in `refused_targets`, and the output is left alone (the caller keeps its previous path, as for any refused word). Target 0 with targets 1-7 disabled (`ENABLE` clear) is accepted, and a target with `ENABLE` clear uses no factor and is not refused. Audit result for the other points of the blend headers (no change needed): a 40-million-word sweep of `cb_blend::decode` (every field value including undefined factors 21-31 and combine functions 5-7, words with all bits set, with and without alpha-factor support) never produced an out-of-range `D3D12_BLEND`/`D3D12_BLEND_OP`, a colour-only factor in an alpha slot, `BlendEnable` together with `LogicOpEnable`, a write mask above 0xF, or a refusal without a reason. ## Verification - MinGW + Wine check: `x86_64-w64-mingw32-g++ -std=c++17 -Wall -Wextra -Werror -static -Isrc -o sbb.exe tests/startup_state_block_blend_check.cpp && wine sbb.exe` -> `startup_state_block_blend: PASS (4 measured words, enable clear, 5 controls, dual source)` - Same test against the unmodified `state_block_blend.h` from `origin/main`: fails on `dual source on target > 0` and `dual source on target 0 with blending target > 0`, exit 1. - `git diff --check origin/main...HEAD`, `tests/docs_links_check.py`, `tests/bidi_controls_check.py`: clean. - Windows Server 2025 Debug (`--preset dev`) and Release `/O2` (`--preset release`): `ctest --preset <preset> -R '^startup_state_block_blend' --no-tests=error --output-on-failure` -> 1/1 passed (details in PR comment). ## Evidence and follow-up Synthetic state blocks built in the test; no captured data. Assumption: the dual-source rules (target 0 only, and no other blending target alongside dual-source target 0) follow the D3D12/Vulkan blend rules and the hardware's single second export. Not changed, candidates for separate work: the stream and derived-patch blend descriptors are copied without range checks; `find_blend` accepts factors up to 19 only (misses `ALPHA_FACTOR`/`INV_ALPHA_FACTOR`); blending on integer render target formats is not checked in `pipeline_for`. ## 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; commands listed were executed locally.
tedin7 commented 2026-11-24 15:02:21 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T14:09:17Z.


Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit ae2fe983aa3e7fb670bfc3ec0456de0d7dbd79f9:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target startup_state_block_blend_check -- -j 6): 4.00s (configure 1.81s)
    • Test (ctest --preset dev -R '^startup_state_block_blend' --parallel 4 --no-tests=error --output-on-failure): 1/1 passed (0.08s: startup_state_block_blend 0.01s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target startup_state_block_blend_check -- -j 6): 1.50s (configure 1.82s)
    • Test (ctest --preset release -R '^startup_state_block_blend' --parallel 4 --no-tests=error --output-on-failure): 1/1 passed (0.08s: startup_state_block_blend 0.01s)
  • sccache: 0/2 hits; wall 14.9s

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7133924365 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1511#issuecomment-7133924365). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T14:09:17Z. --- Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `ae2fe983aa3e7fb670bfc3ec0456de0d7dbd79f9`: - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev --target startup_state_block_blend_check -- -j 6`): `4.00s` (configure `1.81s`) - Test (`ctest --preset dev -R '^startup_state_block_blend' --parallel 4 --no-tests=error --output-on-failure`): **1/1 passed** (`0.08s`: `startup_state_block_blend` `0.01s`) - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release --target startup_state_block_blend_check -- -j 6`): `1.50s` (configure `1.82s`) - Test (`ctest --preset release -R '^startup_state_block_blend' --parallel 4 --no-tests=error --output-on-failure`): **1/1 passed** (`0.08s`: `startup_state_block_blend` `0.01s`) - `sccache`: 0/2 hits; wall `14.9s` AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot commented 2026-11-24 15:02:21 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T14:09:29Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T14:13:01.908854Z ae2fe98 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7133929269 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1511#issuecomment-7133929269). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T14:09:29Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"ae2fe983aa3e7fb670bfc3ec0456de0d7dbd79f9","has_any_findings":false,"has_unresolved_findings":false,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-24T14:13:01.908854Z">2026-11-24T14:13:01.908854Z</relative-time> | `ae2fe98` | Draft marked ready | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
ChazY11 commented 2026-11-24 15:02:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-24T14:50:16Z.


Both halves of the dual-source rule are covered

Independent reviewer, not the author. Reviewed ae2fe983; nothing pushed to the branch. Mutations were made locally in
src/startup_stubs/state_block_blend.h, rebuilt, reverted; working tree is clean.

Environment: Windows 11 build 26300.9974, MSVC 14.44.35207, SDK 10.0.26100.

cmake --preset dev
cmake --build --preset dev
ctest --preset dev --no-tests=error -R '^startup_state_block_blend' -V

startup_state_block_blend: PASS (4 measured words, enable clear, 5 controls, dual source) as submitted.

The rule under test

if (target == 0) {
    target0_dual_source = dual;
} else if (dual || target0_dual_source) {
    ...
    refused |= 1u << target;
    continue;
}

Mutation 1 — only refuse a dual factor on a non-zero target

-        } else if (dual || target0_dual_source) {
+        } else if (dual) {
startup_state_block_blend: 32 FAILED

So the "target 0 is dual-source and another target also blends" half is genuinely exercised, not just described.

Mutation 2 — refuse but do not report which target

-            refused |= 1u << target;
+            ;
startup_state_block_blend: 62 FAILED

refused_targets is asserted per bit, so the caller can tell which target was rejected rather than only that something
was.

Worth knowing

The two failures report 32 FAILED and 62 FAILED with no per-case name in the summary line, so from ctest output alone
it is not obvious which control broke. The count is enough to see a regression landed, and the test prints per-case
detail under -V; I mention it only because a one-line "first failing control: …" would make a future bisect faster.
Not a request.

Verdict

Reviewed ae2fe983. Builds clean, the fixture passes, and both halves of the rule plus the per-target reporting are each
caught when removed. No objection from me.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7135030547 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1511#issuecomment-7135030547). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-24T14:50:16Z. --- ## Both halves of the dual-source rule are covered Independent reviewer, not the author. Reviewed `ae2fe983`; nothing pushed to the branch. Mutations were made locally in `src/startup_stubs/state_block_blend.h`, rebuilt, reverted; working tree is clean. Environment: Windows 11 build 26300.9974, MSVC 14.44.35207, SDK 10.0.26100. ```powershell cmake --preset dev cmake --build --preset dev ctest --preset dev --no-tests=error -R '^startup_state_block_blend' -V ``` `startup_state_block_blend: PASS (4 measured words, enable clear, 5 controls, dual source)` as submitted. ### The rule under test ```cpp if (target == 0) { target0_dual_source = dual; } else if (dual || target0_dual_source) { ... refused |= 1u << target; continue; } ``` ### Mutation 1 — only refuse a dual factor on a non-zero target ```diff - } else if (dual || target0_dual_source) { + } else if (dual) { ``` ```text startup_state_block_blend: 32 FAILED ``` So the "target 0 is dual-source and another target also blends" half is genuinely exercised, not just described. ### Mutation 2 — refuse but do not report which target ```diff - refused |= 1u << target; + ; ``` ```text startup_state_block_blend: 62 FAILED ``` `refused_targets` is asserted per bit, so the caller can tell which target was rejected rather than only that something was. ### Worth knowing The two failures report `32 FAILED` and `62 FAILED` with no per-case name in the summary line, so from ctest output alone it is not obvious which control broke. The count is enough to see a regression landed, and the test prints per-case detail under `-V`; I mention it only because a one-line "first failing control: …" would make a future bisect faster. Not a request. ### Verdict Reviewed `ae2fe983`. Builds clean, the fixture passes, and both halves of the rule plus the per-target reporting are each caught when removed. No objection from me.
tedin7 commented 2026-11-24 15:02:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T14:55:55Z.


Thanks for the independent review and local mutation verification on Windows 11 26300, @ChazY11.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7135182487 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1511#issuecomment-7135182487). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T14:55:55Z. --- Thanks for the independent review and local mutation verification on Windows 11 26300, @ChazY11.
upstream-sync closed this pull request 2026-11-25 06:01:00 +00:00
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!1504
No description provided.