Direct DXIL: write PS exp mrtz sample mask to SV_Coverage #2348
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2358"
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 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). WithXCL_DIRECT_DXIL=all, a console PS that writes a sample mask throughexp mrtzcurrently loses it: every covered sample is written. This PR keeps the mask and matches the HLSL recompiler'sOSG1signature.Part of #1269
What is in it
crates/xcl/src/gpu/dxil/lower_gfx.rs:PsInterface::outputsdeclaresSV_Coverage(system value 66), a sample-mask temporary is initialised to0xFFFFFFFF.export_gfxwrites channel 2 ofexp mrtzto it (VSRC2for the 32-bit Z formats,VSRC1 [15:0]when compressed).finish_gfxdeclares the PS outputs inps.outputsorder and declaresSV_Coverageonly if an export wrote it.SV_Target7fallback; when a pixel shader declares no outputs at all, an undeclaredexp mrt7is now ignored rather than written to the dummy fallback, and the dummySV_Target7stores constant0.0(matchingrecomp/emit.rs:5273-5277's(XclOut)0).crates/xcl/src/gpu/dxil/graphics_tests.rs:ps_mrtz_sample_mask_writes_sv_coverage(CPU):OSG1declarations and thedx.op.storeOutput.i32value for 5 cases: uncompressed, compressed under a divergent EXEC +s_cbranch_execzphi, depth-only, coverage-only, and noSV_Coveragein the signature.gpu_ps_mrtz_sample_mask_covers_only_its_samples(GPU): draws bothwave64: falseandwave64: trueconsole PS translations into a 4x MSAA target and checks every sample (mask0b0101uncompressed,0b1010compressed with the other mask inVSRC2, 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
x86_64-pc-windows-gnu:cargo check --offline --workspace --testsgave 0 errors. Its 3 warnings (d3d12x/real.rs:3804,xgameruntime/mod.rs:547,d3d12x/vram.rs:1110) are the same 3 thatb49be183gives. None are in the files changed here.gpu::dxil::graphics::testsbuilt with plainrustc --edition 2021 --testfromgit archiveof this head. Only Windows plumbing is stubbed (windowsnames, the validator and disassembler, the GPU runner, DXC). No test or lowering code is changed. Results:ps_mrtz_sample_mask_writes_sv_coveragepasses on this head.lower_gfx.rsfromb49be183, atgraphics_tests.rs:1380(left: 0, right: 1): main emits noSV_Coveragestore.25 passed; 2 failedhere and24 passed; 3 failedwith main'slower_gfx.rs. The 2 failures in both runs arecs_static_resources_match_dxcandps_early_depth_matches_dxc, which unwrap the DXC disassembler that is stubbed on Linux.SKIPPED …: no GPUon this host.Regression run
XCL_DIRECT_DXIL=all). Thexcl-smokepair (mainb49be183and this head) has to come from a Windows run with a retail title before this leaves draft.Not tested
cargo test --workspace -- --test-threads=4), includinggpu_ps_mrtz_sample_mask_covers_only_its_samples(bothwave64: falseandwave64: truecases;draw_readygates onwave64_programs_supported, i.e.wave64 || wave32, so software adapters without wave32/wave64 such as WARP skip withno 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.xcl-smoke, AMD / NVIDIA / Intel adapters, Proton.AI use
517a26d), and thewave64: trueGPU test loop.runner::draw_msaa, the line wrapping of the changed lines, and this description.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!
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 targetx86_64-pc-windows-gnurun 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_2seed 1003,gpu_nonfused_mad_and_mac_prevent_fma_contraction,gpu_depth_buffer_created_for_unordered_access_is_placed). Targeted run of the newps_mrtz_sample_masktest: 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.
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.
Imported from ivall/xcl. Originally posted by safesearch77 on 2026-11-26T14:07:11Z.
Thanks for the review. Added the GPU test, rebased onto
b49be183and 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 withtranslate_pixeland draws each with one full-target triangle into a 4x MSAAR32G32B32A32_FLOATtarget. It then reads back every sample of every pixel and compares it with the expected value:x >= 4:exp mrtzwrites the mask (EN = 0x4,VSRC2 = 0b0101). Only samples 0 and 2 get the colour; samples 1 and 3 keep the clear value.COMPR = 1,EN = 0xC,VSRC1 = 0b1010.VSRC2holds0b0101in this case, so reading the wrong source gives the wrong samples.x < 4: EXEC is off for those lanes (v_cmp+s_and_saveexec_b32/b64+s_cbranch_execzaround the export). All 4 samples must be written, which checks the default0xFFFFFFFFmask.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.6ResourceDescriptorHeap) into a buffer and copies that to readback. I compare samples one by one, not aResolveSubresourceaverage, so the test checks which samples are covered, not only how many. The test skips withno wave64/no GPU(throughdraw_ready, asemitted_vs_ps_draw_a_triangledoes) and withno 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-smokeruns are still open (see Not tested). The PR stays a draft until someone posts them.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
staleand will be closed in 4 days. A push or a comment takes the mark off: rebase it ontomainif it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.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 mrtzchannel 2 (or VSRC1[15:0] when compressed) goes to a mask variable initialised to0xFFFFFFFF.SV_Coverageis declared at finish only when the shader writes the mask.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_samplesper-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.
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).
Pull request closed