Skip to content

D3D12.X: command list #142 applies the quad sample mask (XCL_SAMPLE_MASK=1) - #3076

Draft
CharlyRien wants to merge 1 commit into
xcl-dev:mainfrom
CharlyRien:pr/quad-sample-mask
Draft

CharlyRien wants to merge 1 commit into
xcl-dev:mainfrom
CharlyRien:pr/quad-sample-mask

Conversation

@CharlyRien

@CharlyRien CharlyRien commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Command list #142 of the newer console layout, SetQuadSampleMaskX(u64), is a stub on main: every pixel is drawn. The u64 is the two PA_SC_AA_MASK registers, 16 sample bits for each pixel of a 2×2 quad. A retail title sets it per draw from dithered fade tables (0 to 4 pixels of the quad, each 0 or 0xFFFF, and the complement for the other side of a cross-fade), so LOD cross-fades draw both levels whole instead of a dither pattern. This applies the mask in the translated pixel shaders, behind XCL_SAMPLE_MASK=1 (off by default). The slot's name is the one #1274 gives it (a no-op there).

What is in it (one commit)

  • crates/xcl/src/hle/d3d12x/quad_mask.rs (new): the Pr/newer title startup #142 handler (newer layout only; on the older one Pr/newer title startup #142 is another method, answered as before), the mask kept per list as the samples it takes away, the switch, a log line at the first call and counts at powers of two from 1024.
  • crates/xcl/src/hle/d3d12x/bind.rs: the list's mask; reset and ClearState go back to all ones, a mid-list split inherits it; bind_abi writes it into io slots 117 / 118 of graphics draws only when it is partial. real.rs: the slot.
  • crates/xcl/src/gpu/recomp/mod.rs: IO_QUAD_KILL = [117, 118] (trap-temp SGPR slots; 113 is left for D3D12.X: dispatches of more than 65 535 groups in X are folded into Y #1428, 114..116 are main's DispatchX thread limits).
  • crates/xcl/src/gpu/recomp/emit.rs (HLSL) and crates/xcl/src/gpu/dxil/lower_gfx.rs (direct DXIL): every pixel shader starts, before its EXEC is taken, with the test: HLSL one uniform branch on the two io words, then a discard of the pixel whose 16 bits are all taken away; direct DXIL the same straight-line with one conditional discard. With the switch off the io words are 0 and nothing is discarded, but the text of every pixel shader changes, so the translator identity changes.
  • No pixel shader on main has early depth. One that gets it (Recompiler: console pixel shaders tested depth-first keep early depth #2181) must not get this test: the depth of the discarded pixels would still be written. The comment at the test says so.
  • Tests: mask decoding and the title's masks with their complements; the slot; the io wiring across reset / ClearState / split; the HLSL text and the direct path's discards (dxil::core_tests); a GPU draw through both paths with each kind of mask, 16×16 pixels compared (recomp::tests::gpu_quad_sample_mask_discards_the_quad_pixels_it_takes_away).

346 added lines, 3 removed, about 150 of them tests.

Tested

  • Head 0bab2ef (rebased onto main e429936). RTX 3090 24 GB (Resizable BAR off), driver 616.56, Ryzen 9 5950X, 32 GB RAM, Windows 11 22631, Rust 1.100.0, debug for the suite, release for the smoke runs.
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 2133 passed, 9 failed, 48 ignored. The 9 are the 9 tests main e429936 itself fails on a GPU since the last merges, the same names as in this report on an RTX 4080 (2126 passed there; this PR adds 7 tests): three gpu::dxil::module::split dispatch-chain tests, gpu_heap_flat_reads_match_guarded_and_root_output, gpu_compute_mode_dispatch_abi, gpu_float_cas_uses_ieee_equality, and three e2e test-title runs. The 7 tests of this PR passed, among them the GPU one, recomp::tests::gpu_quad_sample_mask_discards_the_quad_pixels_it_takes_away (both paths, each kind of mask, 16×16 pixels compared).
    • SKIPPED on this adapter: 25 lines. 21 are "no wave64" (8 with that reason alone, 13 in lower_dxil::tests with the part named, e.g. "f32 arithmetic, wave64: no wave64"); 3 are the per-lane form refusing f16 / packed f16 / f32-to-f16 conversions ("its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's"); 1 is heap_window_out_of_memory_falls_back_to_the_switch_form ("no heap windows"). None is a test of this PR.
  • CI: the Build and test failure on this head is main's own build error (E0451, a private field of Config used by a test), the same on main e429936; the earlier failure on 4c6207d was the known flaky fine_timer_makes_short_sleeps_short.
  • Before the rebase (head 4c6207d on main 2c717a0): the suite gave 1473 passed, 0 failed, 47 ignored, and a run with XCL_SAMPLE_MASK=1 had no device removal and no crash; in it the title only set an all-ones mask (1024 calls, 0 partial, no count line at 2048), so nothing was discarded: that run checks that the switch is harmless, not that the fades are right.
xcl-smoke block of the XCL_SAMPLE_MASK=1 run (4c6207d)
xcl-smoke v1
commit: 4c6207dfb0f75c36d4534a9e7bb4bede8532735d
gpu: NVIDIA GeForce RTX 3090
title: 16b5e5d4
seconds: 200
exit: 0x0
frames shown: 1621 (PresentX 1621)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 35492 MB

Regression run
main e429936 and this PR's head 0bab2ef, same machine, same title, 200 s, the same scripted A presses (XCL_PRESS_A_AT), XCL_PREPARE=0, XCL_SAMPLE_MASK unset, both through main's scripts/smoke.ps1, each starting from its own copy of the same shader cache (made by another main commit, so cold for both).

main:

xcl-smoke v1
commit: e429936c10a5b8aa09470ff99dfc8c8d3d8c56fd
gpu: NVIDIA GeForce RTX 3090
title: 16b5e5d4
seconds: 200
exit: 0x0
frames shown: 2442 (PresentX 2442)
presents per 2 s (last 3): 1 1 1
device removals: 0
crashes: 0
peak commit: 31737 MB

this PR's head:

xcl-smoke v1
commit: 0bab2ef0d7a17ac8ba592f39c51baaf65c5dbd36
gpu: NVIDIA GeForce RTX 3090
title: 16b5e5d4
seconds: 200
exit: 0x0
frames shown: 1852 (PresentX 1853)
presents per 2 s (last 3): 3 22 3
device removals: 0
crashes: 0
peak commit: 31534 MB

No device removal and no crash on the head. Its frames are 75.8 % of main's, under the 80 % of CONTRIBUTING, so this stays a draft. The whole difference is in the first 25 s: main presented 603 frames there, the head none. After 25 s the two runs are within about 2 % (1,795 frames against 1,838).

What the logs show about those 25 s: at start the background pipeline builders spent 21 to 24 s each in the driver on a few large compute pipelines ("slow driver compile" lines), and the first frame came at about 28 s. That is not specific to this PR: main's own first run of this build (below, 116g1) shows the same slow driver compiles at 25.7 s and its first frame at 28.2 s. Only main's second run (the pair above) started fast: its third run, with the cache the second one filled, had the slow start again (2 presents in the first 25 s, 1,744 frames in all, 71 % of the second). A second run of the head with the cache its first run filled (below) had the slow start too (1,751 frames). Why one run starts fast and another does not is not known; on this machine it moves main's own 200 s total between 1,744 and 2,442 frames. This PR changes only pixel shaders (and the translator identity); the slow pipelines are compute pipelines.

The other runs (same setup)

main e429936, its first run (frames 1908; a compile of another branch ran on the same machine during its first 95 s, so it is not a clean reference):

xcl-smoke v1
commit: e429936c10a5b8aa09470ff99dfc8c8d3d8c56fd
gpu: NVIDIA GeForce RTX 3090
title: 16b5e5d4
seconds: 200
exit: 0x0
frames shown: 1908 (PresentX 1908)
presents per 2 s (last 3): 0 0 1
device removals: 0
crashes: 0
peak commit: 31509 MB

this PR's head, second run, with the cache its first run filled:

xcl-smoke v1
commit: 0bab2ef0d7a17ac8ba592f39c51baaf65c5dbd36
gpu: NVIDIA GeForce RTX 3090
title: 16b5e5d4
seconds: 200
exit: 0x0
frames shown: 1751 (PresentX 1752)
presents per 2 s (last 3): 4 7 3
device removals: 0
crashes: 0
peak commit: 32587 MB

main e429936, third run, with the cache its second run filled:

xcl-smoke v1
commit: e429936c10a5b8aa09470ff99dfc8c8d3d8c56fd
gpu: NVIDIA GeForce RTX 3090
title: 16b5e5d4
seconds: 200
exit: 0x0
frames shown: 1744 (PresentX 1744)
presents per 2 s (last 3): 3 2 0
device removals: 0
crashes: 0
peak commit: 32562 MB

Not tested

  • The image: no capture was compared, and the run with the switch never got a partial mask, so whether the dithered fades now look as on the console is not shown.
  • The order of the 16-bit words (pixel (x, y) = word x + 2y) is taken from the register names; the title's tables are symmetric under swapping x and y, so they cannot tell the two orders apart (a wrong order would transpose the pattern, with the same coverage).
  • Masks that keep part of a pixel's samples (MSAA): the pixel is kept whole; the title only sets 0 or 0xFFFF per pixel.
  • Draws with no pixel shader, the older layout's Pr/newer title startup #142, AMD and Intel GPUs.

AI use

  • Claude Code, model Claude Opus 5.5: worked out the call's meaning from the values the title passes, wrote the code, the tests and this description, and ran the suite and the runs above on the hardware named. Opened as a draft at the request of the person running these tests, who will review the diff before marking it ready.

🤖 Generated with Claude Code

@JJAutoCompare

Copy link
Copy Markdown

Tested

Clean detached 4c6207dfb0f75c36d4534a9e7bb4bede8532735d on Windows 11 build 26200, Ryzen 7 3800X, Intel Arc A770 (8086:56a0, driver 32.0.101.9175), Rust 1.100.1 MSVC, and DXC/DXIL 1.9.2602.17. I reran the pinned stock test executable with --exact --nocapture --test-threads=1.

  • Arc (1 passed): gpu::recomp::tests::gpu_quad_sample_mask_discards_the_quad_pixels_it_takes_away passed six masks per path on HLSL-to-DXIL and direct DXIL, for 12 single-sample draws and 3,072 RGBA pixel comparisons. The fixture injected the mask words into shader I/O and checked expected white or clear-blue output. The Arc probe identified the A770 and the stock runner used XCL_ADAPTER=A770 through its hardware-only named selector.
  • Host (6 passed): same-binary controls covered mask decoding, pixel retention, draw I/O and command-list state, handler 142 routing, and code generation for both paths.

7 passed, 0 failed, 0 ignored, 0 skips. All native processes and the Arc wrapper exited 0. The executable SHA-256 held before, under, and after the lock.

Not tested

Hardware MSAA, end-to-end command-list-to-GPU wiring, the runtime enable switch, retail smoke, and the full suite.

AI use

T3 Code / Codex (gpt-6.2-sol) independently reran the stock fixtures and wrote this report.

Kalmarv added a commit to Kalmarv/xcl that referenced this pull request Nov 28, 2026
Command list xcl-dev#142 of the newer layout (SetQuadSampleMaskX, a stub so far)
gets a handler that only counts: its calls, those with a mask other than
all ones, and the title's graphics work recorded while such a mask is
current on its list (direct draws, DispatchMesh, and graphics
ExecuteIndirect calls by kind, each once at the title's call). One tally
line every ten seconds of graphics work, so a window without use reads as
zeros. Nothing is applied: no shader, io or state change.

It answers whether xcl-dev#3076 has anything to act on in a title
before that PR's shader change is tried.

Co-Authored-By: Claude Fable 5 <[email protected]>
…AMPLE_MASK=1)

The newer layout's command list xcl-dev#142, SetQuadSampleMaskX(u64), takes the two
PA_SC_AA_MASK registers: 16 sample bits for each pixel of a 2x2 quad (X0Y0, X1Y0,
X0Y1, X1Y1 from bit 0). A retail title sets it per draw from dithered fade tables
(0 to 4 pixels of the quad, each 0 or 0xFFFF, and the complement for the other
side of a cross-fade). As a stub every pixel is drawn, so LOD cross-fades draw
both levels whole. The name is the one xcl-dev#1274 gives the slot (a no-op there).

Host (hle/d3d12x/quad_mask.rs, bind.rs): the handler keeps the mask per list as
the samples it takes away; bind_abi writes them into io slots 117 / 118
(recomp::IO_QUAD_KILL) of graphics draws, only when the mask is partial; reset and
ClearState go back to all ones, a mid-list split inherits it. Older layout: xcl-dev#142
is another method, answered as the stub did. Off unless XCL_SAMPLE_MASK=1: off,
the io slots stay 0 and nothing is discarded.

Translator: every pixel shader starts (before its EXEC is taken) with the test.
HLSL: one uniform branch on the two io words, then a discard of the pixel whose
quad word is all ones. Direct DXIL: the same straight-line, one conditional
discard. No pixel shader on main has early depth; one that gets it must not get
this test (the discarded pixels' depth would still be written).

Tests: mask decoding and the title's masks, the slot, the io wiring across
reset / ClearState / split, the HLSL text and the direct path's discards, and a
GPU draw through both paths with each kind of mask.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants