Repository navigation
d3d12-shader: preserve non-EXEC writelanes and full/exempt LDS in paired Wave64 form (D3D12-SHADER-PAIRED-MULTI-BARRIER-EXACTNESS) - #3262
Open
zmasi wants to merge 3 commits into
Conversation
…face programs' LDS (D3D12-SHADER-PAIRED-MULTI-BARRIER-EXACTNESS)
The paired form (one host thread runs console lanes n and n + 32) ran beside the split form
on an RTX 3090 (driver 610.88), both against a 64-lane model of the console's wave: hand-
written programs and seeded random ones. Three things it did not keep, each failing before
and passing now:
- v_writelane_b32 to a lane outside EXEC was lost: the form guarded it like a lane's own
write. It now writes the lane its select names (S1[5:0]) whatever EXEC is, as the "Lane
select" row of docs/design.md says.
- A program named in LEONIDA_LDS_BOUNDS_EXEMPT (the face programs) was held to its header's
LDS all the same, since the form bounds every access: past the header a read gave 0 and a
write was dropped. It now has the group's 32 KiB; a header that gives more is refused, as
before.
- A group of several waves using all 32 KiB of LDS was refused for a counter dword the form
no longer keeps.
Tests: emit/paired/{lane,barrier,fuzz,differential}_tests.rs, each form from its own entry
point, against the model; the random programs are shrunk when one goes wrong. d3d12/docs/
findings.md: what the runs showed, with what is not the paired form's, left as it is (the
split form's lane writes, lane selects past 63 and per-lane scalars; in both forms a mask
made of two 32-bit writes and the host's order of f32 sums).
AI-assisted: GPT-6.2 Astra (author; the LaneGpu tests), GPT-6.2 Sol (LaneAudit, read-only),
Claude Fable 5.2 (ControlAudit, read-only; the BarrierGpu tests), Claude Opus 5.5 (separate
read-only reviewer, two passes).
… it is judged first (D3D12-SHADER-PAIRED-MULTI-BARRIER-EXACTNESS) Hand-written programs, each form against the console's model (rules of tools/crosslane_fuzz.py, measured on RDNA 2), for the cross-lane reads the audit had only read in the code: - Exact in both forms, now tests: s_bcnt1_i32_b64 and s_ff1_i32_b64 of EXEC with its SCC through s_cselect_b32 and s_cbranch_scc0; v_permlane16_b32 and v_permlanex16_b32 with sources outside EXEC (FI 0 keeps the lane's value, FI 1 reads the source); a DPP row mask over both halves. - Forward ds_permute_b32 is refused by both forms, with LDS or without. - Not exact in either form, recorded in d3d12/docs/findings.md and left as it is (emit/lower.rs): s_wqm_b64 gives every lane; a DPP16 source lane outside EXEC with fi 0, and a ds_swizzle_b32 source lane outside EXEC, are read as they are. findings.md also says now that a lane mask made of two separately written dwords is wrong in lanes 32-63 in the paired form, where the split form refuses the program; and that the split form's lane writes, lane selects past 63, per-lane scalars and prefix sums were each run against the model on the card (the paired form exact for every one of them). differential_tests::forms puts the paired form first, so a form stopping at its first fault never leaves the paired form unjudged for one of the split form's. AI-assisted: GPT-6.2 Astra (author). Prompted by review notes from other models.
…ed-multi-barrier-exactness
merzleckeier
reviewed
Dec 2, 2026
merzleckeier
left a comment
Contributor
There was a problem hiding this comment.
Independent translation check on 3643c2879 with Rust 1.98.1 on Linux. I reused the PR’s synthetic two-wave fixture and called the paired emitter directly with a 32-lane host selection.
- The two-wave shader with the full 32 KiB of LDS now translates in the paired form.
- A shader with a 512-byte header and
lds_unbounded=trueemits byte-identical DXIL to the same shader with an explicit 32 KiB header. The ordinary 512-byte translation emits different DXIL, so the comparison exercises the allocation change.
Both probes fail with only emit/mod.rs restored from main (ef35d683e). The Linux shader unit suite plus the two probes passed 256, with two ignored. The checks were limited to translation and emitted bytes. The paired dispatch results, including the EXEC-disabled v_writelane_b32 case, remain GPU coverage. git diff --check passed and the PR also merges cleanly with #3215. AI-assisted.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Claimed in the coordination issue as:
D3D12-SHADER-PAIRED-MULTI-BARRIER-EXACTNESS(#2570 (comment))
What and why
@enlight3d found that naming six heavy compute programs in
LEONIDA_PAIRED_FORchanges the picture, although thepaired form is described as exact (#2570, #issuecomment-7352754262). The paired form runs console lanes
nandn + 32in host threadn. I ran it beside the split form on an RTX 3090, each form from its own entry point, againsta 64-lane model of the console's wave. The programs were hand-written ones and 300 seeded random ones: ballots as
numbers and through the 64-bit scalar operations, counts, ranks, first-lane and lane reads and writes, the compiler's
DPP reductions and prefix sums, permlanes, a DPP row mask, and EXEC counted with its SCC. They ran under lane branches,
scalar branches and loops that lanes leave apart, in groups of one to sixteen console waves, with multi-barrier LDS
rounds. Three things the paired form did not keep. Each test fails before its fix and passes now:
v_writelane_b32to a lane outside EXEC was lost. The instruction writes the lane it names whatever EXEC is(
docs/design.md, "Lane select"). The form guarded it like a lane's own write. It is now lowered for both lanes ofthe thread without the guard (
paired_cross).LEONIDA_LDS_BOUNDS_EXEMPT, by default the face programs) were held to theirheader's LDS in the paired form. That form checks every access against the group's own array: past the header a
read gave 0 and a write was dropped. That is what left the faces undrawn before the exemption. Such a program now
has the group's 32 KiB in this form. A header that gives more than 32 KiB is still refused, named or not.
With these fixes, all 300 random programs match the model in the paired form. Half of them use everything the
generator has. The other half are held to what the split form keeps; 141 of those 150 also match in the split form,
which refuses the other 9.
Recorded in
d3d12/docs/findings.mdand left as it is, since all of it is outsidepaired.rs:s_mov_b32, as a64-bit constant is loaded) is wrong in lanes 32–63 (
structure.rs'smaskshortcut). The split form refuses thesame program.
s_wqm_b64gives every lane.fi0, and ads_swizzle_b32source lane outside EXEC, are read as theyare.
The paired form is exact for every one of the split form's programs.
Not measured in the game. The six programs of the report are not named by hash there, so which of these each one hit
is open. Naming them in
LEONIDA_PAIRED_FORagain on this change, at the same shot, is the check.Tested
d3d12/crates/leonida-shader/src/emit/paired/:lane_tests.rs:barrier_tests.rs:fuzz_tests.rs: 36 seeded programs in the suite (300 in a sweep), shrunk when one goes wrong.differential_tests.rs: the shared harness. The paired form is judged first, so a split-form fault never leavesit unjudged.
main, green here: the writelane, full-32-KiB and named-LDS tests, and the fuzz test. Checked by hand (thechange's production files reverted) and with
python -I scripts/red_green.py: verdict "red then green", those 4tests red then green. The other new tests pass on
maintoo: they check behaviour this change keeps.cargo test --locked -p leonida-shader(x86_64-pc-windows-msvc): 440 passed, 0 failed, 6 ignored.cargo clippy --locked -p leonida-shader --all-targets --no-deps: no warning in the touched files.cargo xtask policy: no violation in the touched files (the three it reports are onmain).python -I scripts/check_no_game_data.py,python -I tests/test_text_write_line_endings.py,python -I tests/test_docs_design_rows.py,python -m unittest discover -s tests -p "test_docs_*.py": pass.GPUs tested: NVIDIA GeForce RTX 3090 24 GB, driver 610.88, Windows 11 Pro 10.0.26200 (Microsoft WARP has no 32-lane
waves, so it skips these tests).
AI-assisted: yes.
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (No new rule:the writelane fix applies the existing "Lane select" row.)