gpu: read slot 57 blend state from the colour-blend register words #1287
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1294"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-24T07:01:49Z.
Refs #1216, #1150.
This is the draw-path hookup #1216 lists as open: the decoder is on
mainthrough #1226 and the register location was measured there by @rasptum. @rasptum was invited to do the wiring, and main development has a local integration; if either is about to land, close this in favour of it. I am posting it because I needed it for a run and no PR had it.Problem
Translated pipelines created through device slot 57 get no blend state.
find_blendlooks for a desktopD3D12_BLEND_DESCin the captured blocks; state block A holdsCB_BLENDn_CONTROLwords instead. Glyph quads and other alpha-blended UI are drawn opaque.Change
src/startup_stubs/state_block_blend.h:state_block_blendreads the eight words at state block A+0xD0, decodes each withx2w_cb_blend::decode(word, 0xF, false)and fills aD3D12_BLEND_DESCwith independent blend.CB_TARGET_MASKis not located.refused_targets, which is logged.d3d12_draw.inlcalls it for a base pipeline of path 57, after the derived description and the stream subobject and before thefind_blendscans. The log line names the source ascolour-blend registers at +0xd0.Alpha blend factor support is passed as false, so the constant-alpha factors are refused rather than queried.
Evidence
Commit under test: the head of this branch, on
mainat93cb6a2a.Device-free check (
tests/startup_state_block_blend_check.cpp, registered asstartup_state_block_blend):It builds synthetic 388-byte state blocks filled with unrelated bytes, with the words at
+0xD0:0xE5040504,0xE5010504,0xE5010501,0xE1000104) give straight alpha, straight colour with ONE alpha, premultiplied and additive on target 0, with targets 1-7 unblended and unmasked;BOTH_SRC_ALPHAon target 0 is refused with a reason; the same form on targets 1-7 keeps target 0 and reports0xFE.Whole-program run. One console executable under the startup debugger, offline; Linux host, Wine with vkd3d-proton, NVIDIA RTX 4070 Ti SUPER. Measured with a local build that has the same hookup inline (not this branch's header):
blend from colour-blend registers, with source/destination factorsSRC_ALPHA / INV_SRC_ALPHAorONE / INV_SRC_ALPHA.Also ran
python -B tests/docs_links_check.py(pass) andgit diff --check(clean).Not included
startup_cb_blend_*) already cover the register fields against a CPU model; what is missing is the creation path. I do not have a Windows host to build and run a D3D12 fixture on, so I have left it out rather than submit one I could only run through a translation layer. If that makes this unmergeable as it stands, the header and its check can be folded into whichever PR adds the draw.d3d12_draw.inl; this will need a rebase after it.Not measured
d3d12_xs_device.cppwas syntax-checked the same way. CI is the first MSVC build.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T07:15:40Z.
Review: COMMENTED
Reviewed at commit
e0b2e8678aebd7e0f5aec8900a009df08e16003d.Linux Checks
git diff --check origin/main...HEAD: passed (no whitespace/conflict-marker issues)./root/.local/share/x2w-rev-venv/bin/python -B tests/docs_links_check.py: passed (Checked 16 Markdown files and 286 links.)./root/.local/share/x2w-rev-venv/bin/python -B tests/bidi_controls_check.py: passed (Checked 1081 tracked source, script and build/CI files: no bidirectional controls.).Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP)
--preset dev):cmake --build --preset dev --target startup_state_block_blend_check -- -j 6(3.94s, configure1.51s)ctest --preset dev -R '^startup_state_block_blend$' --parallel 4 --no-tests=error --output-on-failure: 1/1 passed (0.09s:startup_state_block_blend0.02s)/O2(--preset release):cmake --build --preset release --target startup_state_block_blend_check -- -j 6(1.43s, configure1.48s)ctest --preset release -R '^startup_state_block_blend$' --parallel 4 --no-tests=error --output-on-failure: 1/1 passed (0.09s:startup_state_block_blend0.02s)Code Review Notes
src/startup_stubs/state_block_blend.h: bounds check (bytes < state_block_blend_offset + 8 * sizeof(std::uint32_t)),std::memcpyword reads, and leaving*outuntouched on target-0/short-block refusal are clean and avoid unaligned access UB.src/startup_stubs/d3d12_draw.inl: slot 57state_block_blendsits cleanly betweenhas_stream_blendand thefind_blendfallbacks, and logs refusals on target 0 or secondary targets (refused_targets). Note thatalpha_factor_supportedis passed asfalse(conservative unlessD3D12_FEATURE_DATA_D3D12_OPTIONS13::AlphaBlendFactorSupportedis queried later), and as documented indocs/startup-runtime.md, a live draw through a slot 57 pipeline remains open.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T08:07:54Z.
Review: CHANGES_REQUESTED
The state-block decoder checks are useful. Please add a source-built slot 57 draw before landing the production hookup: read back a known background plus a translucent source, and confirm that the same draw with the blend word disabled or read from the adjacent offset produces a different pixel. Keep the write-mask limitation explicit. Please also exercise a bound secondary target with an unsupported factor; a log plus opaque rendering would silently change that target's output, so the fixture should show that the unsupported state is rejected or stays on an already verified path.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T08:42:54Z.
Review: COMMENTED
Retested at commit
b1382a66f62025829bb4fb0fd048e95e6516d3e3(4 new commits sincee0b2e867).Linux Checks
git diff --check origin/main...HEAD: passed (no whitespace/conflict-marker issues)./root/.local/share/x2w-rev-venv/bin/python -B tests/docs_links_check.py: passed (Checked 16 Markdown files and 294 links.)./root/.local/share/x2w-rev-venv/bin/python -B tests/bidi_controls_check.py: passed (Checked 1111 tracked source, script and build/CI files: no bidirectional controls.).Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP)
--preset dev):startup_state_block_blend_check,startup_stream_consumer):24.80s(configure1.46s)ctest --preset dev -R '^(startup_state_block_blend|startup_slot57_blend_draw_warp)$' --parallel 4 --no-tests=error --output-on-failure: 2/2 passed (startup_state_block_blend0.01s,startup_slot57_blend_draw_warp1.15s)/O2(--preset release):36.45s(configure1.56s)ctest --preset release -R '^(startup_state_block_blend|startup_slot57_blend_draw_warp)$' --parallel 4 --no-tests=error --output-on-failure: 2/2 passed (startup_state_block_blend0.01s,startup_slot57_blend_draw_warp1.26s)Retest Findings
src/startup_stubs/state_block_blend.h: now refuses the entire block when any of the eight targets is refused (if (refused) return false;), leaving*outuntouched sod3d12_draw.inlkeeps its prior path and logscolour-blend registers not used: ...; refused targets 0x....tests/startup_slot57_blend_draw_check.py(startup_slot57_blend_draw_warp): verified on WARP — exercises a source-built slot 57 draw reading back 8x4 RGBA8 pixels ((128, 0, 128, 191)blended vs(255, 0, 0, 128)unblended,(0, 0, 255, 255)background),ENABLEclear and+0xCC/+0xD4offset controls, two-target MRT per-target words, and a refused secondary target (BOTH_SRC_ALPHA,0x4000050b) leaving both targets unblended and loggingrefused targets 0x2.docs/startup-runtime.md: keeps theCB_TARGET_MASKwrite-mask limitation explicit.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T08:57:05Z.
Review: APPROVED
Release passed seven tests on RTX 4060 Laptop and WARP with no skips. The source-built slot 57 draw distinguishes the blended, opaque and shifted controls. Refused secondary state keeps the existing pipeline path. The independent write-mask work stays open.
Imported from R0Y00/Xbox2Windows. Originally posted by JohnConnorNPC on 2026-11-24T08:30:12Z.
Both done in
b1382a66.Draw fixture.
tests/startup_slot57_blend_draw_check.py(registered asstartup_slot57_blend_draw_warp/_hardware) creates a pipeline through device slot 57 from source-built gfx1013 shaders and a synthetic state block A, clears an 8x4 RGBA8 target to opaque blue, draws red with alpha 0.5 over the left half and reads every pixel back. The right half must still be the background in every case.0x40000504at +0xD0 (SRC_ALPHA / INV_SRC_ALPHA)0x00000504at +0xD00x40000504at +0xCC0x40000504at +0xD4Each control is also asserted to differ from the blended pixel. The one-step tolerance is for alpha 0.5, which lands between two UNORM values.
Secondary target with an unsupported factor. You were right that a log plus an opaque target changes that target's output.
state_block_blendnow refuses the whole block when the decoder refuses the word of any target, reports every refused target, and substitutes nothing. The pipeline then stays on the path it had before this PR. The fixture binds a second RGBA8 target and exports to both:0x400005040x4000050B(BOTH_SRC_ALPHA)The refused case asserts that the registers did not supply the blend state, that the log names the reason and
refused targets 0x2, and that both targets read the unblended source, so target 0 is not blended next to an opaque target 1. The unit test's "refused other targets" case is changed to match: refused, output untouched,refused == 0xFE.Write mask. Still not located and not covered; the header, the docs, and the fixture's docstring and PASS line all say so.
Results here at
b1382a66(clang-cl build under Wine 11.0 with vkd3d-proton, RTX 4070 Ti SUPER; translation-layer,hardwareonly):startup_stream_draw_check.py hardwarestill passes unchanged (the consumer gained a mode and the harness an optional second target).Not verified: Windows and WARP for the new fixture; CI will be its first WARP run. The fixture does not show which path a real slot 57 pipeline takes when a block is refused, only that the registers are then left unused.