Direct DXIL: write PS exp mrtz sample mask to SV_Coverage #2358

Open
github-bot wants to merge 1 commit from github-bot/gh-2358 into main AGit
Owner

@⁠safesearch77 on GitHub · 2026-11-25 16:30 UTC · original
safesearch77:fix/dxil-ps-mrtz-sv-coverage → main · +286 −49 · 2 files · 1 commits · draft

Port 6dbae61 (Recompiler: a PS sample mask from exp mrtz is written to SV_Coverage) to the Direct DXIL pixel-shader backend (crates/xcl/src/gpu/dxil/lower_gfx.rs) so XCL_DIRECT_DXIL=all preserves custom pixel sample masks and matches the HLSL recompiler's OSG1 signature.

Part of #1269

What is in it

  • crates/xcl/src/gpu/dxil/lower_gfx.rs:
    • Allocate a 0xFFFF_FFFF-initialised sample-mask temporary when PsInterface::outputs declares SV_Coverage (system_value == 66).
    • Write comp(self, 2) in export_gfx (tgt == 8, covering VSRC2 for 32-bit Z exports with EN & 0x4 != 0 and VSRC1[15:0] for compressed UINT16_ABGR exports with COMPR = 1, EN & 0xC != 0) and record ps_writes_mask.
    • Declare PS OSG1 outputs in finish_gfx in ps.outputs order, emitting SV_Coverage iff ps_writes_mask holds and skipping the dummy SV_Target7 fallback on coverage-only pixel shaders.
  • crates/xcl/src/gpu/dxil/graphics_tests.rs:
    • ps_mrtz_sample_mask_writes_sv_coverage: verifies OSG1 declarations, emitted DXIL bitcode parsing, and dx.op.storeOutput.i32 IR value provenance across uncompressed EN = 0x4, compressed COMPR = 1, EN = 0xC under a lane-divergent EXEC + S_CBRANCH_EXECZ bypass phi, depth-only EN = 0x1 with SV_Coverage in signature, coverage-only PS without dummy SV_Target7, and mrtz mask export without SV_Coverage in signature.

Tested

  • Linux x86_64 host native unit test execution (rustc --edition 2021 --test harness over gpu::dxil::graphics::tests, base 0829441, head 517a26d): verified ps_mrtz_sample_mask_writes_sv_coverage fails (0 passed; 1 failed) against main lower_gfx.rs and passes (9 passed; 0 failed across all graphics::tests) with the fix applied.
  • Offline cross-target check: cargo check --offline --target x86_64-pc-windows-gnu --workspace --tests (0 errors, 0 new warnings).

Not tested

  • Windows cargo test --workspace -- --test-threads=4 GPU suite (dxcompiler.dll validation) and paired Windows scripts/smoke.ps1 runs (opened as Draft from Linux; note Direct DXIL pixel shaders require XCL_DIRECT_DXIL=all).

AI use

  • Antigravity (Gemini 4 Carbon) identified the 6dbae61 Direct-DXIL parity gap, implemented the fix and 5-case unit test, and verified RED-to-GREEN execution on host CPU; reviewed with Claude Opus 5.5.
**@⁠safesearch77** on GitHub · 2026-11-25 16:30 UTC · [original](https://github.com/xcl-dev/xcl/pull/2358) `safesearch77:fix/dxil-ps-mrtz-sv-coverage` → `main` · +286 −49 · 2 files · 1 commits · draft Port `6dbae61` (`Recompiler: a PS sample mask from exp mrtz is written to SV_Coverage`) to the Direct DXIL pixel-shader backend (`crates/xcl/src/gpu/dxil/lower_gfx.rs`) so `XCL_DIRECT_DXIL=all` preserves custom pixel sample masks and matches the HLSL recompiler's `OSG1` signature. Part of #1269 **What is in it** - `crates/xcl/src/gpu/dxil/lower_gfx.rs`: - Allocate a `0xFFFF_FFFF`-initialised sample-mask temporary when `PsInterface::outputs` declares `SV_Coverage` (`system_value == 66`). - Write `comp(self, 2)` in `export_gfx` (`tgt == 8`, covering `VSRC2` for 32-bit Z exports with `EN & 0x4 != 0` and `VSRC1[15:0]` for compressed `UINT16_ABGR` exports with `COMPR = 1, EN & 0xC != 0`) and record `ps_writes_mask`. - Declare PS `OSG1` outputs in `finish_gfx` in `ps.outputs` order, emitting `SV_Coverage` iff `ps_writes_mask` holds and skipping the dummy `SV_Target7` fallback on coverage-only pixel shaders. - `crates/xcl/src/gpu/dxil/graphics_tests.rs`: - `ps_mrtz_sample_mask_writes_sv_coverage`: verifies `OSG1` declarations, emitted `DXIL` bitcode parsing, and `dx.op.storeOutput.i32` IR value provenance across uncompressed `EN = 0x4`, compressed `COMPR = 1, EN = 0xC` under a lane-divergent `EXEC` + `S_CBRANCH_EXECZ` bypass `phi`, depth-only `EN = 0x1` with `SV_Coverage` in signature, coverage-only PS without dummy `SV_Target7`, and `mrtz` mask export without `SV_Coverage` in signature. **Tested** - Linux x86_64 host native unit test execution (`rustc --edition 2021 --test` harness over `gpu::dxil::graphics::tests`, base `0829441`, head `517a26d`): verified `ps_mrtz_sample_mask_writes_sv_coverage` fails (`0 passed; 1 failed`) against `main` `lower_gfx.rs` and passes (`9 passed; 0 failed` across all `graphics::tests`) with the fix applied. - Offline cross-target check: `cargo check --offline --target x86_64-pc-windows-gnu --workspace --tests` (`0` errors, `0` new warnings). **Not tested** - Windows `cargo test --workspace -- --test-threads=4` GPU suite (`dxcompiler.dll` validation) and paired Windows `scripts/smoke.ps1` runs (opened as Draft from Linux; note Direct DXIL pixel shaders require `XCL_DIRECT_DXIL=all`). **AI use** - Antigravity (Gemini 4 Carbon) identified the `6dbae61` Direct-DXIL parity gap, implemented the fix and 5-case unit test, and verified RED-to-GREEN execution on host CPU; reviewed with Claude Opus 5.5.
Port 6dbae61 to lower_gfx.rs: initialise an SV_Coverage temporary to
0xFFFFFFFF when declared in PsInterface::outputs, write channel 2 of
exp mrtz (32-bit VSRC2 or compressed VSRC1[15:0]) to it, and emit PS
OSG1 outputs in finish_gfx so SV_Coverage is declared iff written and
coverage-only shaders skip the dummy SV_Target7 fallback.

An undeclared exp mrt7 in a pixel shader with no declared outputs is now
ignored rather than routed to the dummy fallback, matching recomp/emit.

Assisted-by: Antigravity (Gemini 4 Carbon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:28:49 +00:00
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 18:37 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-25 18:37 UTC · [original](https://github.com/xcl-dev/xcl/pull/2358#issuecomment-7171168251) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
Author
Owner

@⁠SlopTart on GitHub · 2026-11-25 19:06 UTC · original

Tested: current PR head merged onto current origin/main (clean), Linux (Arch, kernel 7.2.15), Mesa 26.2.5 RADV, Radeon RX 7900 XT (NAVI31), cargo target x86_64-pc-windows-gnu run under wine-11.0 (Proton), rustc 1.94.0, vkd3d-proton 3.1 with the XCL patch, official MS DXC (binaries 2026-09-29).
suite: 144/3 = the three known baseline failures on this lane (fuzz_validate_and_gpu_2 seed 1003, gpu_nonfused_mad_and_mac_prevent_fma_contraction, gpu_depth_buffer_created_for_unordered_access_is_placed). Targeted run of the new ps_mrtz_sample_mask test: 2 passed.

Not tested: retail titles (no title data on this lane, counts only).

AI use: Hermes agent (local Qwen-class) ran both machines and drafted this; I checked it before posting.

**@⁠SlopTart** on GitHub · 2026-11-25 19:06 UTC · [original](https://github.com/xcl-dev/xcl/pull/2358#issuecomment-7171819003) **Tested**: current PR head merged onto current `origin/main` (clean), Linux (Arch, kernel 7.2.15), Mesa 26.2.5 RADV, Radeon RX 7900 XT (NAVI31), cargo target `x86_64-pc-windows-gnu` run under wine-11.0 (Proton), rustc 1.94.0, vkd3d-proton 3.1 with the XCL patch, official MS DXC (binaries 2026-09-29). suite: 144/3 = the three known baseline failures on this lane (`fuzz_validate_and_gpu_2` seed 1003, `gpu_nonfused_mad_and_mac_prevent_fma_contraction`, `gpu_depth_buffer_created_for_unordered_access_is_placed`). Targeted run of the new `ps_mrtz_sample_mask` test: 2 passed. **Not tested**: retail titles (no title data on this lane, counts only). **AI use**: Hermes agent (local Qwen-class) ran both machines and drafted this; I checked it before posting.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2358/head:github-bot/gh-2358'
git switch 'github-bot/gh-2358'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2358'
git switch 'github-bot/gh-2358'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2358'
git switch 'github-bot/gh-2358'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2358'
git switch 'main'
git merge --squash 'github-bot/gh-2358'
git switch 'main'
git merge --ff-only 'github-bot/gh-2358'
git switch 'main'
git merge 'github-bot/gh-2358'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.