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

Closed
safesearch77 wants to merge 1 commit from upstream-pr/2358 into main
safesearch77 commented 2026-11-25 16:30:00 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by safesearch77 on 2026-11-25T16:30:00Z.


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). With XCL_DIRECT_DXIL=all, a console PS that writes a sample mask through exp mrtz currently loses it: every covered sample is written. This PR keeps the mask and matches the HLSL recompiler's OSG1 signature.

Part of #1269

What is in it

  • crates/xcl/src/gpu/dxil/lower_gfx.rs:
    • When PsInterface::outputs declares SV_Coverage (system value 66), a sample-mask temporary is initialised to 0xFFFFFFFF. export_gfx writes channel 2 of exp mrtz to it (VSRC2 for the 32-bit Z formats, VSRC1 [15:0] when compressed).
    • finish_gfx declares the PS outputs in ps.outputs order and declares SV_Coverage only if an export wrote it.
    • Coverage-only pixel shaders skip the dummy SV_Target7 fallback; when a pixel shader declares no outputs at all, an undeclared exp mrt7 is now ignored rather than written to the dummy fallback, and the dummy SV_Target7 stores constant 0.0 (matching recomp/emit.rs:5273-5277's (XclOut)0).
  • crates/xcl/src/gpu/dxil/graphics_tests.rs:
    • ps_mrtz_sample_mask_writes_sv_coverage (CPU): OSG1 declarations and the dx.op.storeOutput.i32 value for 5 cases: uncompressed, compressed under a divergent EXEC + s_cbranch_execz phi, depth-only, coverage-only, and no SV_Coverage in the signature.
    • gpu_ps_mrtz_sample_mask_covers_only_its_samples (GPU): draws both wave64: false and wave64: true console PS translations into a 4x MSAA target and checks every sample (mask 0b0101 uncompressed, 0b1010 compressed with the other mask in VSRC2, and the all-samples default where EXEC skips the export).
  • crates/xcl/src/gpu/recomp/runner.rs: draw_msaa, the existing VS/PS draw path into a target with N samples. It returns every sample, read back by a compute pass (Texture2DMS::Load). The 1-sample path is unchanged.

The diff is ~660 changed lines. Most of it is the two tests and the readback; the lowering change is +115 / -49. The GPU test stays in this PR because the review asked for it before the PR is marked ready.

Tested

  • Linux x86_64 host, Rust stable (repo toolchain), cross-checked for x86_64-pc-windows-gnu: cargo check --offline --workspace --tests gave 0 errors. Its 3 warnings (d3d12x/real.rs:3804, xgameruntime/mod.rs:547, d3d12x/vram.rs:1110) are the same 3 that b49be183 gives. None are in the files changed here.
  • Linux x86_64 host, the CPU tests of gpu::dxil::graphics::tests built with plain rustc --edition 2021 --test from git archive of this head. Only Windows plumbing is stubbed (windows names, the validator and disassembler, the GPU runner, DXC). No test or lowering code is changed. Results:
    • ps_mrtz_sample_mask_writes_sv_coverage passes on this head.
    • It fails with lower_gfx.rs from b49be183, at graphics_tests.rs:1380 (left: 0, right: 1): main emits no SV_Coverage store.
    • With the stub validator returning Ok, the whole module gives 25 passed; 2 failed here and 24 passed; 3 failed with main's lower_gfx.rs. The 2 failures in both runs are cs_static_resources_match_dxc and ps_early_depth_matches_dxc, which unwrap the DXC disassembler that is stubbed on Linux.
    • The new GPU test reports SKIPPED …: no GPU on this host.

Regression run

  • None yet. Direct DXIL graphics lowering is opt-in (XCL_DIRECT_DXIL=all). The xcl-smoke pair (main b49be183 and this head) has to come from a Windows run with a retail title before this leaves draft.

Not tested

  • The Windows GPU suite (cargo test --workspace -- --test-threads=4), including gpu_ps_mrtz_sample_mask_covers_only_its_samples (both wave64: false and wave64: true cases; draw_ready gates on wave64_programs_supported, i.e. wave64 || wave32, so software adapters without wave32/wave64 such as WARP skip with no wave64) and the DXC validator run of the CPU test. I have no Windows GPU machine, so I make no claim that the GPU test passes on wave32-only (NVIDIA) or wave64 (AMD) hardware.
  • Any retail title, xcl-smoke, AMD / NVIDIA / Intel adapters, Proton.

AI use

  • Antigravity (Gemini 4 Carbon): the original fix and the CPU test (517a26d), and the wave64: true GPU test loop.
  • Antigravity (Claude Opus 5.5): the rebase, the MSAA GPU test and runner::draw_msaa, the line wrapping of the changed lines, and this description.
<!-- greyfinch-sync:ivall/xcl:issue:5495135907 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2358). Originally posted by [safesearch77](https://github.com/safesearch77) on 2026-11-25T16:30:00Z. --- 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`). With `XCL_DIRECT_DXIL=all`, a console PS that writes a sample mask through `exp mrtz` currently loses it: every covered sample is written. This PR keeps the mask and matches the HLSL recompiler's `OSG1` signature. Part of #1269 **What is in it** - `crates/xcl/src/gpu/dxil/lower_gfx.rs`: - When `PsInterface::outputs` declares `SV_Coverage` (system value 66), a sample-mask temporary is initialised to `0xFFFFFFFF`. `export_gfx` writes channel 2 of `exp mrtz` to it (`VSRC2` for the 32-bit Z formats, `VSRC1 [15:0]` when compressed). - `finish_gfx` declares the PS outputs in `ps.outputs` order and declares `SV_Coverage` only if an export wrote it. - Coverage-only pixel shaders skip the dummy `SV_Target7` fallback; when a pixel shader declares no outputs at all, an undeclared `exp mrt7` is now ignored rather than written to the dummy fallback, and the dummy `SV_Target7` stores constant `0.0` (matching `recomp/emit.rs:5273-5277`'s `(XclOut)0`). - `crates/xcl/src/gpu/dxil/graphics_tests.rs`: - `ps_mrtz_sample_mask_writes_sv_coverage` (CPU): `OSG1` declarations and the `dx.op.storeOutput.i32` value for 5 cases: uncompressed, compressed under a divergent EXEC + `s_cbranch_execz` phi, depth-only, coverage-only, and no `SV_Coverage` in the signature. - `gpu_ps_mrtz_sample_mask_covers_only_its_samples` (GPU): draws both `wave64: false` and `wave64: true` console PS translations into a 4x MSAA target and checks every sample (mask `0b0101` uncompressed, `0b1010` compressed with the other mask in `VSRC2`, and the all-samples default where EXEC skips the export). - `crates/xcl/src/gpu/recomp/runner.rs`: `draw_msaa`, the existing VS/PS draw path into a target with N samples. It returns every sample, read back by a compute pass (`Texture2DMS::Load`). The 1-sample path is unchanged. The diff is ~660 changed lines. Most of it is the two tests and the readback; the lowering change is +115 / -49. The GPU test stays in this PR because the review asked for it before the PR is marked ready. **Tested** - Linux x86_64 host, Rust stable (repo toolchain), cross-checked for `x86_64-pc-windows-gnu`: `cargo check --offline --workspace --tests` gave 0 errors. Its 3 warnings (`d3d12x/real.rs:3804`, `xgameruntime/mod.rs:547`, `d3d12x/vram.rs:1110`) are the same 3 that `b49be183` gives. None are in the files changed here. - Linux x86_64 host, the CPU tests of `gpu::dxil::graphics::tests` built with plain `rustc --edition 2021 --test` from `git archive` of this head. Only Windows plumbing is stubbed (`windows` names, the validator and disassembler, the GPU runner, DXC). No test or lowering code is changed. Results: - `ps_mrtz_sample_mask_writes_sv_coverage` passes on this head. - It fails with `lower_gfx.rs` from `b49be183`, at `graphics_tests.rs:1380` (`left: 0, right: 1`): main emits no `SV_Coverage` store. - With the stub validator returning Ok, the whole module gives `25 passed; 2 failed` here and `24 passed; 3 failed` with main's `lower_gfx.rs`. The 2 failures in both runs are `cs_static_resources_match_dxc` and `ps_early_depth_matches_dxc`, which unwrap the DXC disassembler that is stubbed on Linux. - The new GPU test reports `SKIPPED …: no GPU` on this host. **Regression run** - None yet. Direct DXIL graphics lowering is opt-in (`XCL_DIRECT_DXIL=all`). The `xcl-smoke` pair (main `b49be183` and this head) has to come from a Windows run with a retail title before this leaves draft. **Not tested** - The Windows GPU suite (`cargo test --workspace -- --test-threads=4`), including `gpu_ps_mrtz_sample_mask_covers_only_its_samples` (both `wave64: false` and `wave64: true` cases; `draw_ready` gates on `wave64_programs_supported`, i.e. `wave64 || wave32`, so software adapters without wave32/wave64 such as WARP skip with `no wave64`) and the DXC validator run of the CPU test. I have no Windows GPU machine, so I make no claim that the GPU test passes on wave32-only (NVIDIA) or wave64 (AMD) hardware. - Any retail title, `xcl-smoke`, AMD / NVIDIA / Intel adapters, Proton. **AI use** - Antigravity (Gemini 4 Carbon): the original fix and the CPU test (`517a26d`), and the `wave64: true` GPU test loop. - Antigravity (Claude Opus 5.5): the rebase, the MSAA GPU test and `runner::draw_msaa`, the line wrapping of the changed lines, and this description.
DavidM1911 commented 2026-11-25 19:09:09 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T18:37:34Z.


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!

<!-- greyfinch-sync:ivall/xcl:comment:7171168251 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2358#issuecomment-7171168251). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T18:37:34Z. --- 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!
SlopTart commented 2026-11-25 19:09:20 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by SlopTart on 2026-11-25T19:06:03Z.


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.

<!-- greyfinch-sync:ivall/xcl:comment:7171819003 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2358#issuecomment-7171819003). Originally posted by [SlopTart](https://github.com/SlopTart) on 2026-11-25T19:06:03Z. --- **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.
bmjask commented 2026-11-25 20:26:21 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by bmjask on 2026-11-25T20:26:21Z.

Review: COMMENTED


No source-level defect found: the MRTZ-to-SV_Coverage mapping and default-mask flow are internally consistent. Material validation gap: this has no GPU-rendered output test for the newly emitted coverage path, only IR/container/validator checks. Please add an observable MSAA/sample-mask GPU test and provide current completed Windows CI; the visible current status is pending with no completed Windows build/test.

<!-- greyfinch-sync:ivall/xcl:review:6064470117 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2358#pullrequestreview-6064470117). Originally posted by [bmjask](https://github.com/bmjask) on 2026-11-25T20:26:21Z. **Review:** COMMENTED --- No source-level defect found: the MRTZ-to-SV_Coverage mapping and default-mask flow are internally consistent. Material validation gap: this has no GPU-rendered output test for the newly emitted coverage path, only IR/container/validator checks. Please add an observable MSAA/sample-mask GPU test and provide current completed Windows CI; the visible current status is pending with no completed Windows build/test.
safesearch77 commented 2026-11-26 15:03:41 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by safesearch77 on 2026-11-26T14:07:11Z.


Thanks for the review. Added the GPU test, rebased onto b49be183 and force-pushed as one commit (7dda9dfb).

gpu_ps_mrtz_sample_mask_covers_only_its_samples (gpu/dxil/graphics_tests.rs) translates both wave32 (wave64: false) and wave64 (wave64: true) console PS programs with translate_pixel and draws each with one full-target triangle into a 4x MSAA R32G32B32A32_FLOAT target. It then reads back every sample of every pixel and compares it with the expected value:

  • Pixels with x >= 4: exp mrtz writes the mask (EN = 0x4, VSRC2 = 0b0101). Only samples 0 and 2 get the colour; samples 1 and 3 keep the clear value.
  • Same, compressed: COMPR = 1, EN = 0xC, VSRC1 = 0b1010. VSRC2 holds 0b0101 in this case, so reading the wrong source gives the wrong samples.
  • Pixels with x < 4: EXEC is off for those lanes (v_cmp + s_and_saveexec_b32/b64 + s_cbranch_execz around the export). All 4 samples must be written, which checks the default 0xFFFFFFFF mask.

The readback is runner::draw_msaa (gpu/recomp/runner.rs). It is the existing VS/PS draw path with a sample count. A copy cannot read the samples of a multisampled resource, so a compute pass loads each one (Texture2DMS::Load, SM 6.6 ResourceDescriptorHeap) into a buffer and copies that to readback. I compare samples one by one, not a ResolveSubresource average, so the test checks which samples are covered, not only how many. The test skips with no wave64 / no GPU (through draw_ready, as emitted_vs_ps_draw_a_triangle does) and with no DXC (the VS and the readback pass are compiled with DXC).

I could not run it: I have no Windows GPU machine. The Windows suite and xcl-smoke runs are still open (see Not tested). The PR stays a draft until someone posts them.

<!-- greyfinch-sync:ivall/xcl:comment:7194304032 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2358#issuecomment-7194304032). Originally posted by [safesearch77](https://github.com/safesearch77) on 2026-11-26T14:07:11Z. --- Thanks for the review. Added the GPU test, rebased onto `b49be183` and force-pushed as one commit (`7dda9dfb`). `gpu_ps_mrtz_sample_mask_covers_only_its_samples` (`gpu/dxil/graphics_tests.rs`) translates both wave32 (`wave64: false`) and wave64 (`wave64: true`) console PS programs with `translate_pixel` and draws each with one full-target triangle into a 4x MSAA `R32G32B32A32_FLOAT` target. It then reads back every sample of every pixel and compares it with the expected value: - Pixels with `x >= 4`: `exp mrtz` writes the mask (`EN = 0x4`, `VSRC2 = 0b0101`). Only samples 0 and 2 get the colour; samples 1 and 3 keep the clear value. - Same, compressed: `COMPR = 1`, `EN = 0xC`, `VSRC1 = 0b1010`. `VSRC2` holds `0b0101` in this case, so reading the wrong source gives the wrong samples. - Pixels with `x < 4`: EXEC is off for those lanes (`v_cmp` + `s_and_saveexec_b32`/`b64` + `s_cbranch_execz` around the export). All 4 samples must be written, which checks the default `0xFFFFFFFF` mask. The readback is `runner::draw_msaa` (`gpu/recomp/runner.rs`). It is the existing VS/PS draw path with a sample count. A copy cannot read the samples of a multisampled resource, so a compute pass loads each one (`Texture2DMS::Load`, SM 6.6 `ResourceDescriptorHeap`) into a buffer and copies that to readback. I compare samples one by one, not a `ResolveSubresource` average, so the test checks *which* samples are covered, not only how many. The test skips with `no wave64` / `no GPU` (through `draw_ready`, as `emitted_vs_ps_draw_a_triangle` does) and with `no DXC` (the VS and the readback pass are compiled with DXC). I could not run it: I have no Windows GPU machine. The Windows suite and `xcl-smoke` runs are still open (see **Not tested**). The PR stays a draft until someone posts them.
github-actions[bot] commented 2026-12-01 02:34:35 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-12-01T02:34:35Z.


Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

<!-- greyfinch-sync:ivall/xcl:comment:7298763851 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2358#issuecomment-7298763851). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-12-01T02:34:35Z. --- Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
Foniass commented 2026-12-01 07:55:00 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T07:55:00Z.


Triage (#1607) – head 7dda9df

#3252 makes the same change in lower_gfx.rs:

  • exp mrtz channel 2 (or VSRC1[15:0] when compressed) goes to a mask variable initialised to 0xFFFFFFFF.
  • SV_Coverage is declared at finish only when the shader writes the mask.
  • A coverage-only PS no longer gets the dummy SV_Target7.
    #3252 has a DXC-validated GPU test against the HLSL path, green checks and a smoke pair, and it merges cleanly. This PR is a draft, its PR description check fails, and it conflicts. Its extra runner::draw_msaa / read_samples per-sample readback is the one thing #3252 lacks, and it could be proposed as a follow-up test.
    Recommendation: close (duplicate of #3252).

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7304642553 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2358#issuecomment-7304642553). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T07:55:00Z. --- **Triage (#1607)** – head 7dda9df #3252 makes the same change in `lower_gfx.rs`: - `exp mrtz` channel 2 (or VSRC1[15:0] when compressed) goes to a mask variable initialised to `0xFFFFFFFF`. - `SV_Coverage` is declared at finish only when the shader writes the mask. - A coverage-only PS no longer gets the dummy `SV_Target7`. #3252 has a DXC-validated GPU test against the HLSL path, green checks and a smoke pair, and it merges cleanly. This PR is a draft, its PR description check fails, and it conflicts. Its extra `runner::draw_msaa` / `read_samples` per-sample readback is the one thing #3252 lacks, and it could be proposed as a follow-up test. Recommendation: close (duplicate of #3252). AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
throny commented 2026-12-01 15:58:47 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-12-01T15:58:47Z.


Closing as superseded: the same change is in #3252 (open, mergeable, required checks green). From Foniass's rechecked close list on #1607, checked again by script just now. If something here is still missing, say so and reopen it, or ask and I will.

AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:ivall/xcl:comment:7316833855 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/2358#issuecomment-7316833855). Originally posted by [throny](https://github.com/throny) on 2026-12-01T15:58:47Z. --- Closing as superseded: the same change is in #3252 (open, mergeable, required checks green). From Foniass's rechecked close list on #1607, checked again by script just now. If something here is still missing, say so and reopen it, or ask and I will. AI use: Claude Code (Claude Opus 5.5).

Pull request closed

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
xcl-dev/xcl!2348
No description provided.