Skip to content

[upstream #1926] D3D12.X: the GPU wait watchdog starts after its wake pair is set - #235

Open
ufoptg wants to merge 81 commits into
mainfrom
upstream-pr/1926
Open

ufoptg wants to merge 81 commits into
mainfrom
upstream-pr/1926

Conversation

@ufoptg

@ufoptg ufoptg commented Nov 24, 2026

Copy link
Copy Markdown
Owner

The xcl-sync-watchdog thread, which releases a GPU wait that has not completed after 5 s, could panic as it started. wake_sync_watchdog spawned it inside the OnceLock's initializer, and the thread's first line unwraps that OnceLock. If the thread ran before the initializer returned, it panicked on None and was not started again. The code is from 8a5643f (xcl-dev#795).

Seen once, on main 4178e88 in a retail title run (stderr): thread 'xcl-sync-watchdog' (3856) panicked at crates\xcl\src\hle\d3d12x\list_x.rs:1364:55:, called `Option::unwrap()` on a `None` value. It was 1 of the 12 local title runs without this fix (stderr kept) that bridged GPU waits; with the initializer delayed so that the thread runs first, it happened in both runs (one unit-test run, one title run; below). I don't claim that this fixes a stall.

What is in it

  • hle/d3d12x/list_x.rs: the wake pair is set first, then the thread is started by the call that set it (sync_watchdog_pair, which takes the spawn as a closure so that the order can be tested). The thread's body is unchanged. If the spawn fails, nothing retries it, as before.
  • a unit test whose thread starts before the spawn returns: fails on the old order ([false], expected [true]), passes with the fix

Tested

  • RTX 3060 12 GB (driver 617.14), Ryzen 9 5900XT, 32 GB, Windows 11 (26300), Rust 1.100.0, debug
  • cargo test --workspace --locked --no-fail-fast -- --test-threads=4: 976 passed, 0 failed, 45 ignored on 2448457c's tree, run just before it was committed (22 SKIPPED lines: 18 no wave64, 3 wave32 per-lane forms refused, 1 no heap windows)
  • unit tests of main's code with a 300 ms sleep added after the spawn, so that the thread always runs first: the same panic (list_x.rs:1370:55 at 1d027e5); with the fix: none
  • retail title, 140 s, XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1 XCL_NETWORK=0, A pressed every 4 s from 20 s, one run per line:
    • main 689f2db + that sleep: the watchdog panics, 3 waits bridged (logged), 0 timed-out releases in the 27 s to the end of the process (17 s of the run, 10 s of drain)
    • this commit + that sleep: no panic, 4 timed-out releases
    • this commit: two runs, no panic, 4 timed-out releases each; a third crashed at 53 s (0xC0000005 read) in title_textures::content_hash (the read that D3D12.X: title texture reads outside the coherent window use the safe copy xcl-dev/xcl#751 replaces), before any wait was bridged
    • no device removal, no crash in the others. Presents stopped at 84 to 92 s in every full run, so these runs don't show that the panic or the fix changes the stall

Regression run

main:

xcl-smoke v1
commit: 689f2db477c3c062cf162649781640ef8a977c18
gpu: NVIDIA GeForce RTX 3060
title: b6ca0868
seconds: 60
exit: 0x0
frames shown: 1491 (PresentX 1491)
presents per 2 s (last 3): 60 60 52
device removals: 0
crashes: 0
peak commit: 21974 MB

PR:

xcl-smoke v1
commit: 2448457c985eb6f09ba7c7a42c7ea9504590b632
gpu: NVIDIA GeForce RTX 3060
title: b6ca0868
seconds: 60
exit: 0x0
frames shown: 1479 (PresentX 1479)
presents per 2 s (last 3): 60 60 37
device removals: 0
crashes: 0
peak commit: 22378 MB

(the second of two pairs, run main, PR, main, PR; the first: main 1436 frames, peak 21110 MB; PR 1502 frames, 21521 MB; no removal or crash in either)

Not tested

  • AMD; an un-forced panic in the title (it happened once, on 4178e88, and did not repeat)
  • other builds ran on this machine during some of the title runs; one run per arm is not a rate
  • the 60 s smoke runs end before the title's first bridged GPU wait (0 in all four), so they don't reach wake_sync_watchdog; the title runs above do
  • the watchdog's other known problem, a wakeup lost between its check and its wait (akimfomin's comment on D3D12.X: bridge Wait64BitValueX to GPU fences with exact cycle breaking xcl-dev/xcl#795), is not touched here

Related to xcl-dev#1452 (the watchdog that releases those waits; not a fix for it). If goal:world-load fits, please set it.

Overlaps: xcl-dev#1123, xcl-dev#1045, xcl-dev#1046, xcl-dev#1429, xcl-dev#1580, xcl-dev#1732 and xcl-dev#1323 edit the same function or nearby lines; none fixes this.

AI use

  • Claude Code (Claude Opus 5.5) found it in a log, wrote the fix and the test, ran the tests and the title, and drafted this; Claude Fable 5.2 reviewed it. I have read the diff and the text.

🤖 Generated with Claude Code


Mirror of xcl-dev#1926 (auto-synced, do not edit).

0x6461726B and others added 30 commits November 24, 2026 04:14
…LOAT

PC D3D12 rejects ALLOW_RENDER_TARGET and ALLOW_UNORDERED_ACCESS on DXGI_FORMAT_R9G9B9E5_SHAREDEXP (67) with E_INVALIDARG (0x80070057). In Series S (Lockhart) mode, a retail title creates a 1920x1080 format-67 target with flags 0x300005 during startup and aborts on the error.

Promote format-67 resources with RT/UAV flags and their RTV/UAV/SRV views to DXGI_FORMAT_R11G11B10_FLOAT (26, same 32 bpp unsigned HDR float with full PC RTV/UAV/SRV support), while keeping sampled-only format-67 textures unchanged.
The `title:` line of an xcl-smoke block printed the game folder's name,
and folder names are whatever people called their copy, so PR
descriptions ended up naming specific copies of a commercial game
(xcl-dev#677). It now prints the first 8 hex digits of the SHA-256 of the
folder name (trimmed, UTF-8). pr_check.py only compares the main and PR
blocks' titles for equality, so the check is unchanged, and two
different folders still get different titles. Existing blocks can be
converted with the same function (Python:
hashlib.sha256(name.strip().encode()).hexdigest()[:8]).

-Title <label> prints a label of your choice instead. Control, format
and line/paragraph separator characters and backticks are refused:
pr_check.py splits lines with str.splitlines(), so a U+2028 in a label
would otherwise add keys such as `commit:` to the block.

scripts/smoke-title.tests.ps1 checks hashes of ASCII, accented, CJK and
emoji names against Python's, a trailing backslash, -Title, and the
refused labels, with a stand-in for xcl.exe.

Fixes xcl-dev#677
The recompiler's Mode::Geometry as a direct compute pass: the ES for the
three vertices of 21 triangles per group (pre-fetched inputs), s_setpc_b64
into the GS, s_sendmsg GS emit / cut building strip triangles per lane, and
the mesh record (vertex / triangle counts, vertices copied from the GS
output area in LDS, triangles) written after wave prefix sums. The split
wave64 form runs the ES in both hardware waves, then a group barrier and the
GS in the lower wave with fresh registers, as the HLSL kernel does.
cfg::Cfg::build_geometry, lower_geom.rs; pso::console_geometry tries it
under XCL_DIRECT_DXIL=1 (HLSL fallback); coverage routes Mode::Geometry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ect translator

ops.rs: TexKind::D2MS / D2MSArray, texture_load_sample, Texture2DMSGetSamplePosition,
RenderTargetGetSampleCount / SamplePosition. lower_image.rs: image_load and
image_msaa_load (one component of four samples) on 2D MSAA (array) T#s, the fragment
index as sample index (no FMASK in D3D12), samples past the count read 0;
image_get_resinfo (one level). Stores / atomics (RWTexture2DMS, SM 6.7) and sampling
stay translation errors. runner.rs (test only): TexDim::D2Ms / D2MsArray filled
sample by sample with a per-sample draw.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Programs writing a non-default MODE[1:0] track MODE[1:0] / FP_DENORM single in an SSA
variable; f32 add/sub/mul/fma/mad/fmac/fmamk/fmaak/div_fmas, int and f64 conversions,
ldexp and sqrt compute exactly (f64 products, TwoSum) and round on the bits by the
mode, denormals flushed as FP_DENORM says. Constant modes fold, run-time modes
select per instruction. Direct-only (DXIL has no directed rounding). Tests against an
integer CPU reference; docs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Restores fuzz_tests.rs, left out of xcl-dev#1426 only for the diff-size limit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ed FUZZ_WATCH

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…copies, TRANSLATOR_VERSION 5

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…v#1307)

The structured form wraps the items that follow a forward jump in a guard
that lists every pending skip flag, and reopens it whenever the set
changes. With many flags pending at once that grows with the square of
the flags. Since b8b1f49 one compute program of the retail pack reaches
it: 148 MB of HLSL from 334 KB of code (3 861 flags, guards of up to 597
terms, 99 MB in guard lines), against 14 MB as pc blocks. DXC on that
fits the host's commit growing about 1 GB/s until it runs out, seen with
b8b1f49 and not without it.

Structured code longer than 128 bytes per byte of program is now
translated as pc blocks. Over the whole pack (CPU-side translation of
every program, macOS), only that program changes, to 13.8 MB. The next
largest structured program is at 61 bytes per byte. Every other program
comes out as it does on main, so b8b1f49's gain stays (1 670 -> 170
programs as pc blocks).

oversized_structured_code_falls_back_to_pc_blocks: 200 conditional
forward jumps whose targets all follow them, in order, cross the bound;
50 do not.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…SLATOR_VERSION 6

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-oom

dxil: eliminate giant-shader IR and CFG blowup in FormatLoad and multi-window memory
… the sweep report

image_get_lod rejected MIMGs whose S# the console built from constants (79 PS
of the GTA VI pack, the only non-geometry gap of a full sweep). The static/heap
sampler choice moves into Lw::mimg_sampler, shared by sample/gather and get_lod.
The coverage report also keeps the 10 slowest programs (text output), to chase
the translation-time tail.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The console orders a dispatch that writes indirect arguments before the
ExecuteIndirect that reads them with a barrier that reaches the PC as a
UAV barrier. NVIDIA's driver (RTX 5090) fetches the arguments without
waiting for it: the ExecuteIndirect ran the count the memory held before
the list, also when the dispatch wrote it through another resource over
the same memory, as translated shaders do through the memory windows.
A transition to INDIRECT_ARGUMENT makes the driver wait - of any buffer,
as measured - so each ExecuteIndirect is now recorded between two
transitions of a buffer of XCL's own (the title's buffer is in the
title's state).

Only lists XCL made (list_x::on_create) get the transitions, and not
bundles; the type comes from list_x's state (list_x::tracked_list_type),
not a call to the list, so a list XCL does not track gets no calls.

Test: execute_indirect_reads_the_arguments_written_before_it (GPU):
40 of 40 tries ran the old count without the transitions, 0 with them.

Assisted-by: omp (Claude Opus 5.5)
A backend that writes DXIL itself keeps the console CFG, so each lane can
branch on its own EXEC bit instead of every vector write being guarded and
branchy programs going through the `pc` dispatcher. This is the analysis it
needs: every lane mask is followed as a per-lane boolean function (a BDD
over the lanes' compare / carry results, uniform SCCs and unresolved
joins), mask branches are taken lane by lane, and a forward dataflow gives
what holds in each lane reaching a block. A vector instruction keeps its
guard only where reaching it does not imply the lane's EXEC bit.

Loop heads are guessed from their forward edges and checked against the
back edges; a wrong guess becomes an atom and only that head recomputes.
Results too large for a per-step node budget are weakened to atoms, which
only costs precision. Indirect jumps and irreducible loops are refused.

Nothing translates with it yet: `xcl shaders --recomp` prints its counts.
On the retail pack: 25 695 of 26 698 programs analysed (983 indirect
jumps, 20 irreducible), 10.65 M of 28.71 M vector instructions still
guarded (37.1 %), 9 015 programs with no guard at all, 700 CPU-s for the
whole pack (slowest program 1.5 s).
`dxil::assemble::assemble` turns a module written as LLVM IR text (or
bitcode) into a signed container: dxcompiler.dll's assembler builds the
container from the module's `dx.*` metadata, dxil.dll's validator checks and
signs it. No HLSL front end and no optimiser: a retail compute program's
module (8.6 MB of IR, 1 MB of DXIL) takes 0.75 s, its HLSL 25 s through DXC.

This is the text path under the module builder (`to_text()`), so the
lowering can run real programs on the GPU before the binary writer is done.

The test assembles a hand-written CS of the ABI root signature, runs it on
the GPU and checks its output, and checks that a use before its definition
is refused by the validator. A module needs an `!llvm.ident`: without one
it validates but the AMD driver faults in CreateComputePipelineState.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XTYmP5ub3Zjdi8PYaDNwsV
The direct backend's lowering, for kernel mode first. The console CFG is
kept and every register dword is an SSA value, built on the fly while the
blocks are lowered (`ssa.rs`). EXEC is each lane's own bit: mask branches
are per-lane branches and a vector write keeps `select(bit, new, old)` only
where the lane-mask analysis could not prove the bit set. An SGPR has a
number view and, when it holds a mask, a lane-bit view; a number read where
a mask was written (or the reverse across a join) is refused once every phi
is complete, and the program stays on the HLSL path. At the end, where every
lane is back, a mask stored as a number is the wave's ballot.

A mask written in a block some lanes skip (a loop lanes leave one by one,
an arm some lanes jump over) and read after they meet again differs from
the console, whose whole-wave write left the absent lanes' bits 0. Those
blocks are found from the post-dominators of the lane branches; such reads
are refused, and kernel mode's final store reports those registers.

The IR goes through an `Ir` trait, the part of the DXIL module builder the
lowering needs. The tests run it lane by lane on a CPU interpreter, and run
the same programs through the HLSL path on the GPU: every register agrees
(GTX 1650, wave32). The analysis now exports its CFG for the lowering.
`s_load_dword{,x2,x4,x8,x16}` and `global_` / `flat_` `load` / `store_dword
{,x2,x3,x4}` on the flat memory, with the addressing of the HLSL path's
single-window form. A guarded load runs in every lane and keeps the old
register where the lane's EXEC bit is clear (a raw buffer read out of range
is 0, so an inactive lane's address can't fault). A guarded store gets a
block of its own that only the lanes with their bit enter, and the rest of
the console block continues after it; the blocks are reserved before the
SSA form is built, so the predecessor lists stay exact.

The CPU interpreter in the tests gets the memory too, and the comparison
with the HLSL path on the GPU now also checks the memory after the run: a
program with an SMEM load, a per-lane load, a guarded store and an
unguarded one agrees word for word (GTX 1650, wave32).
The lowering takes a stage: kernel (the runner's ABI, as before) or a
compute program. In compute mode the user SGPRs come from `io`, then the
group ids and TG_SIZE the program enables, the thread ids go into v0–v2,
EXEC starts as every lane that runs, and the program ends without storing
registers (so kernel mode's report of stale masks does not apply).

One-dimensional groups only for now: in a 2-D / 3-D group the PC driver
need not give a wave consecutive threads, which the console does; the HLSL
path reorders them and those programs stay on it here.

A compute program with user SGPRs and the group id, over three groups of
64 threads, writes the same memory through the HLSL path on the GPU and
through the lowering on the CPU (GTX 1650, wave32).
`lower_dxil` implements the lowering's `Ir` trait on xcl-dev#1426's `Shader` /
`Module`: blocks, phis, integer ops, compares, `select`, the lane / thread
/ group ids, `waveActiveBallot`, and raw buffer access on the ABI's root
UAVs. A phi the SSA construction finds trivial keeps its identical incoming
values (the builder has no use replacement; the driver folds them).

Kernel and compute programs in their per-lane form now become signed DXIL
containers with no HLSL and no DXC, and run on the GPU: the lowering's test
programs agree with the CPU interpreter and with the HLSL path, registers
and memory (GTX 1650, wave32). The lowering's test programs are visible to
the crate's tests for this.
…kipped

An SGPR number or SCC written in a block that lanes leave one by one (a
waterfall loop's key, a counter of the passes) and read after they meet
again is each lane's own value in the per-lane form, where the console has
the last pass's. Such reads are refused like the stale masks, so those
programs fall back; kernel mode's final store reports the registers.
Taking the last-leaving lane's value is left for later. Reported by Sr-0w
on xcl-dev#1269 while putting wave operations on top of the lowering.

Two fixes on the way: a VOP3 instruction's op_sel was never refused (the
field is `OP_SEL`, not `OPSEL`), and an SOP1 mask-width op counted s0 as a
second source because `SSRC1`, which SOP1 lacks, defaulted to 0. The
assemble test declares validator 1.6, the oldest that knows SM 6.6.
At the kernel exit, lower_kernel pushes only r to `stale` for a mask some
lanes kept their own older bits of. In wave64, r + 1 is stored from the
upper half of the same ballot, so it carries the stale bits too, but it
was not reported: VCC after a loop that lanes leave one by one gave
[106] instead of [106, 107].

Found by a wave64 version of the GPU comparison with the HLSL path (the
existing one runs only wave32 programs): on an RX 7800 XT (native
wave64), `leaving loop` differed in s107, 0xFFFFFFFF in the lowering
against 0x80000000 on the GPU, where only lane 63 was active in the
last v_cmp.

Tests: the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu (the
five programs with _B64 mask operations and lane thresholds past 32,
native wave64 form, skipped without wave64) and
a_wave64_mask_left_behind_is_reported_in_both_halves (CPU only). Both
fail without the fix.

Assisted-by: Claude Code (Claude Opus 5.5)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The lowering now takes v_readfirstlane, v_readlane, v_writelane, DPP16 and
DPP8 sources, v_permlane16 / v_permlanex16, ds_swizzle_b32, v_mbcnt and
s_bcnt0 / s_bcnt1 / s_ff1 of a mask, in wave32 and wave64 (lower/wave.rs).
`Ir` gains `read_lane` (WaveReadLaneAt) and `count_bits`.

A lane reads another through `read_lane`, which needs that lane to be at
the same instruction. Lanes are where the console has them, except those
that went the other way at a lane branch. So a read of a lane in EXEC is
always defined (readfirstlane, and DPP / permlane / swizzle without
fetch-inactive, whose source outside EXEC gives 0 or keeps the
destination). A read of any lane (readlane, writelane, fetch-inactive) is
refused in a block not every lane reaches, and the program stays on HLSL.
A mask read as a number is the ballot of its bits: exact for EXEC (a lane
elsewhere is outside it), and for any mask where every lane is here.

The CPU interpreter runs a wave operation over the lanes waiting at it
(the first such point in block order), instead of requiring every lane
there; a waterfall loop's readfirstlane needs this.

Tests: the operations on the CPU in wave32 and wave64 with expected
values; a waterfall loop; a readlane in that loop is refused; and both
programs agree with the HLSL path on the GPU, register by register, in
wave32 and wave64 (RX 7800 XT). Registers the waterfall loop writes and
the program reads after it (an SGPR, the saved EXEC) are left out of the
comparison: each lane keeps its own last pass's value there, which the
lowering does not refuse yet. A stale wave64 mask's second register is
treated as stale too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XTYmP5ub3Zjdi8PYaDNwsV
… lowering

Sr-0w's cross-lane operations add Ir::read_lane and Ir::count_bits; on xcl-dev#1426's builder they are waveReadLaneAt and countbits.
`xcl shaders --recomp` now builds every compute program of the pack both
ways: in its per-lane form (`lower_dxil::compute_code`) and in xcl-dev#1426's
per-instruction form (`gpu::dxil::kernel::translate_compute`), and prints
how many each covers, the DXIL size where both do, and why the per-lane
form refused the rest.

The first pass: per-instruction 2 689 of 2 689, per-lane 4. The commonest
refusals were `v_nop` (now nothing), `s_setreg*` of MODE (now nothing: only
float instructions read it, and the lowering refuses every float
instruction so far), 2-D / 3-D groups, and the three-source integer ops,
now lowered (`v_lshl_add_u32`, `v_add_lshl_u32`, `v_lshl_or_b32`,
`v_and_or_b32`, `v_or3_b32`, `v_xor3_b32`, `v_add3_u32`).
`Ir` gains `ballot_half` and `read_lane_half`: a ballot of which only the
word of the lane's own 32-lane half is used, and a read of a lane in the
same half. A wave64 split into two 32-lane hardware waves can do these
without an exchange between the halves; `ballot` and `read_lane` keep
their names and stay whole-wave, so existing callers are right by default.

`lower/wave.rs` uses the half-local forms for DPP16 / DPP8, permlane(x)16
and ds_swizzle (their source lane and its EXEC bit are in the reader's
half), and for a mask operand of `v_mbcnt_hi` (lanes below 32 add 0). The
rest stays whole-wave: readfirstlane, readlane, writelane, `v_mbcnt_lo`,
a mask as a number, and the kernel exit's ballot of masks.

The DXIL adapter maps both forms to the same operations (one hardware
wave per console wave). The CPU interpreter gives lanes of the other half
a garbage word from `ballot_half` and asserts that `read_lane_half` stays
in the half, so a call that needs the whole wave but uses a half-local
form fails the tests: switching readfirstlane to the half-local ballot
fails two of them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XTYmP5ub3Zjdi8PYaDNwsV
…overage survey

The 1 134 compute programs refused for s_setreg_imm32_b32 write hwreg 20 (FLAT_SCR_LO, the scratch base), not MODE.
vladbondarenko97 and others added 30 commits November 24, 2026 18:00
…er lane

One program in the shape of the f32 ones (`f64_programs_on_the_gpu`) on
x = 1 + lane / 32 + lane * 2^-52: x + 2^-53 (ties to even), x * 2^-1040
(a denormal in and out), x * f64::MAX (infinity from lane 1),
fma(x, x, -x * x) (the product's rounding error: nonzero only when
fused), NaN into min / max, VOP3 abs / neg / omod / clamp, floor / ceil /
trunc / rndne / fract / frexp_mant / frexp_exp of (lane - 16) / 4 (ties,
-0 at lane 15), f64 <-> f32 / i32 / u32 (a tie, overflow, saturation,
NaN) and rcp / rsq / sqrt (within 1e-12). The HLSL path's registers are
checked against values computed in Rust (`check_f64`), and the per-lane
DXIL is compared with the HLSL path register for register, as for f32.
The GPU loop of `f32_programs_on_the_gpu` is now `programs_on_the_gpu`.

Not in it: v_trig_preop_f64 and v_div_*_f64, which the HLSL path does not
translate, and a non-default MODE.FP_ROUND for f64, which it refuses.

On 3511bb9 (RTX 3080 Ti, wave32) the HLSL path passes every check, and
the per-lane form takes the program and agrees with it register for
register. The wave64 half is SKIPPED (no 64-lane waves).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nd per lane

Two programs in the shape of the f32 ones (`integer_programs_on_the_gpu`)
on a = lane * 0x9E3779B9, b = lane - (a >> 13) and c = 0x7FFFFFF0 + lane:
- VOP3-only and VOP2 integer ops: mul_hi u32 / i32, the 24-bit multiplies
  and mads, bfe u32 / i32 with offset + width past 32 and width 0, bfi,
  bfm, alignbit / alignbyte, xad, sad_u8 / sad_hi_u8 / sad_u16 / sad_u32 /
  msad_u8, min3 / max3 / med3 u32 / i32, clamped (saturating) add3 / add /
  sub u32 and add / sub i32, bcnt, ffbh / ffbl / ffbh_i32 of 0 and -1,
  bfrev, not, xnor, cvt_pk_u16_u32 / cvt_pk_i16_i32 (saturating), and
  mad_u32_u16 / mad_i32_i16 with OP_SEL halves;
- carries: VOP3 carry-outs into s20..s30 and carry-ins from them, a VOP2
  chain through VCC, a VOP3 cndmask on s22, v_mad_u64_u32 /
  v_mad_i64_i32 with their carry-outs, and the 64-bit shifts (by 65 at
  lane 31).
The HLSL path's registers and carry masks are checked against values
computed in Rust (`check_int_*`; v_mad_i64_i32's carry-out is left to
the per-lane comparison), and the per-lane DXIL is compared with the
HLSL path register for register, as for f32. The GPU loop of
`f32_programs_on_the_gpu` is now `programs_on_the_gpu`.

On 3511bb9 (RTX 3080 Ti, wave32) the HLSL path passes every check; the
per-lane form takes the arithmetic and agrees with the HLSL path, and
refuses the carries (`V_ADD_CO_CI_U32`: "it reads register 21 the
per-lane form did not pass": xcl-dev#1426 reads a carry-in as the SGPR pair,
the bridge passes only its low SGPR in wave32), so that half is
SKIPPED. On 56102c5, before that check, the carries ran and every
carry-in read 0 per lane (v11, v13, v17, v18 one less, lanes 1-31): the
kernel form never sets up xcl-dev#1426's lanes (`DxilIr::new` with
`Entry::Kernel` calls no `Lw::setup_lanes*`), so `Lw::lane31` stays 0
and `Lw::lane_of` takes every lane's carry-in from bit 0. That is still
so on 3511bb9, so this half fails again once the pair is passed unless
the kernel form sets up the lanes. The wave64 halves are SKIPPED (no
64-lane waves).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ht lane bit

vladbondarenko97's integer programs found that in the kernel form every
carry-in read 0: `DxilIr` never called `Lw::setup_lanes` for a kernel
outside the split form, so `Lw::lane31` stayed the constant 0 and xcl-dev#1426's
lowering read bit 0 of the mask for every lane. The kernel entry now sets
up its lanes. xcl-dev#1426 also reads the mask as an SGPR pair in wave32, so the
bridge passes the upper SGPR (0) with this lane's bit in the lower; the
"register not passed" check had refused those instructions until now.

The integer carry program now runs per lane and agrees with the HLSL
path on the GPU (GTX 1650, wave32).
…ds them

vladbondarenko97's f16 programs show xcl-dev#1426's v_mul_f16 / v_pk_mul_f16
rounding toward zero (LegacyF32ToF16): x * 65504 gives 0x7BFF where the
console and the HLSL path give 0x7C00, and denormal ties round down. They
join V_CVT_F16_F32 on DIFFERS_ON_1426 until itsSio's fix on main lands.
… path and per lane

Two programs in the shape of the f32 ones (`f16_programs_on_the_gpu`):
- f16 VOP1 / VOP2 / VOP3: ties to even, denormal results and their
  ties, overflow to infinity, a fused fma just below a tie (lane 1:
  double rounding through f32 lands on the tie), NaN into min / max /
  med3, OP_SEL source and destination halves, omod and clamp, ldexp into
  denormals, rndne (-0 at lane 15), f16 <-> i16 / u16;
- VOP3P packed math: OP_SEL / OP_SEL_HI swapped and broadcast halves,
  NEG / NEG_HI, f16 clamp, saturating u16 / i16 (clamp), wrapping
  sub / mul_lo / mad, and v_cvt_pkrtz_f16_f32 (65504 for the out-of-range
  values).
The HLSL path's registers are checked against values computed in Rust
(`check_f16_*`, `f16_bits` rounding to nearest even), and the per-lane
DXIL is compared with the HLSL path register for register, as for f32.
The GPU loop of `f32_programs_on_the_gpu` is now `programs_on_the_gpu`.

Left out of the Rust checks: the f16 results the HLSL path rounds with
`f32tof16` (v_add/sub/fma/fmac/ldexp/cvt_f16_u16, v_pk_add/fma). Their
rounding is the driver's: on NVIDIA it rounds toward zero, where the
console rounds to nearest even (MODE.FP_ROUND = 0), e.g. 0x3C01 + 2^-11
gives 0x3C01 for 0x3C02. The per-lane comparison still covers them.

On 3511bb9 (RTX 3080 Ti, wave32) the HLSL path passes every check and
the per-lane form takes both programs, but it gives v_mul_f16 and
v_pk_mul_f16 rounded toward zero (xcl-dev#1426 writes them through
LegacyF32ToF16, the HLSL path through `f32_to_f16_rm`): x * 65504 is
0x7BFF for infinity (lanes 1-31) and the denormal ties of x * 2^-15 go
down (lanes 3, 7, ..., 31), so the per-lane half fails there. The wave64
halves are SKIPPED (no 64-lane waves).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Coalesce maximal straight-line runs of guarded vector instructions under
an unchanged EXEC mask (absorbing pure no-ops like s_waitcnt) into a
single per-lane EXEC branch lowered unguarded, merging updated registers
with SSA phis at the continuation block. Runs are emitted when they
contain a side-effecting instruction (stores, atomics, non-read DS, EXP)
or at least two guarded instructions; standalone guarded VALU/loads keep
a select. Runs stop at scalar/mask/SCC writes (including V_CMPX and
VOP3_SDST_ENC), cross-lane ops, and implicit-derivative image ops.

Track block def/use ownership in stale() so splitting a partial console
block into multiple runs keeps earlier definitions in the same console
block non-stale while keeping definitions inside a run block partial.

Assisted-by: Antigravity (Gemini 4 Neon)
Reviewed-by: Claude Code (Claude Opus 5.5, xhigh)
…ck's write

`stale()` keys each scalar value by the block that made it. A write in
a block some lanes skip of a value made elsewhere (an older mask copied
with `s_mov s4, s0`, a constant the builder shares) kept the older
block, so a read after the lanes meet was not refused although the
console's write reached every lane and each lane here kept its own.
Such a write now gets a copy of its own (`or v, 0`) defined in the
partial block.

Found by MiguelMachado-dev while writing guard coalescing.
`mask_reg` built its upper-dword answer with `then_some((r - 1, true))`,
which evaluates `r - 1` even when the condition is false, so a
cross-lane scalar op on s0 overflowed in debug builds
(`xcl shaders --recomp` panicked). It is lazy now (`then`).

Found and fixed by nobodyttk (xcl-dev#1269).
A few large programs kept the sweep running for over an hour (the
adapter's trivial-phi replacement walks the whole module each time).
They now count as "timeout: over N s" refusals, as the direct form's do.
`compute_with` passed `WaveSize(64)` to `Lw::finish` for a wave64 program
in the split form, so on a GPU with 32-lane waves only (the runtime's
split path) `CreateComputePipelineState` refused it (0x80070057 on a
GTX 1650): no split program reached the GPU through the runtime. The
split form now asks for 32-lane waves, as `compute_split` does. Test:
the 2-D / 3-D id programs in the split form through `compute_with`,
against the CPU lowering's wave64 run.

Also: `can_coalesce` uses `whole_quad` instead of its own copy of it.

Both found by MiguelMachado-dev, reading the code.
Each D3D vertex invocation is one lane, so no lane of a VS is outside
EXEC at launch (gefydev's answer in xcl-dev#1269). The lane-mask analysis now
takes a VS's launch EXEC as every lane (`LaunchExec::All`, as for
compute), and the lowering sets each lane's EXEC bit at the program's
first block, so a VS that never writes EXEC keeps no guard. Only a PS
takes the launch EXEC as unknown.

Tested on an RTX 4090 (Windows 10 22H2, DXC 1.8.2502):
- cargo test -p xcl --lib -- recomp::lower recomp::lane_masks gpu::dxil
  --test-threads=4: 133 passed, 0 failed, 1 ignored;
- cargo test --workspace --no-fail-fast -- --test-threads=4: lib 869
  passed, 0 failed, 22 ignored; every other test binary passed;
- with the VS's launch EXEC taken as unknown again,
  a_ps_helper_lane_runs_the_program_but_does_not_store fails (the VS's
  store keeps its guard).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DxilIr's Sink::replace called Module::replace_all_uses for every trivial
phi the SSA construction drops, and each call walks every instruction and
metadata entry of the module, so the per-lane lowering took time
(trivial phis) x (module size), about quadratic in the program's size.
A CPU profile (WPR) of one 80 KB retail compute program put
replace_all_uses and the heap at the top: survey_compute_code took 18.5 s
of the program's 19.3 s, and the CS + MS per-lane survey
(XCL_RECOMP_STAGES=CS,MS XCL_RECOMP_NO_HLSL=1) did not finish in 10
minutes on a 12-thread i5-11600. The runtime's per-lane form
(XCL_PER_LANE=1) goes through the same adapter.

replace now records old -> new, and DxilIr::finish makes all of them in
one pass (Module::replace_uses, which follows a chain a -> b -> c as the
calls one at a time in order did) before xcl-dev#1426's Lw seals its blocks.
Nothing reads an instruction's operands back before then: the SSA
construction resolves a replaced phi through its own forward map, and
Lw's SSA only compares the values it holds. replace_all_uses stays and
goes through replace_uses.

Test: a batched map with a chain gives the same container as
replace_all_uses one at a time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
xcl-dev#1693 put memory windows through the descriptor heap in xcl-dev#1426's lowering
(XCL_HEAP_WINDOWS), so compute_with no longer refuses them: with several
windows the per-lane form's memory instructions go through Lw, which
now reads the window from the heap.
Extend coalesced_foreign_runs_agree_on_the_gpu to also run coalesced_run(true)
through compute_with with wave64=true, split=true and 4 memory windows
(cut = 40, spanning both wave32 halves) so wave64 coalesced runs are checked
on 32-lane hardware too.

Assisted-by: Antigravity (Gemini 4 Neon)
On CI the adapter is WARP, which has neither 32- nor 64-lane waves, and
every per-lane GPU test failed there in CreateComputePipelineState
(0x80070057) instead of skipping. They now require a GPU that runs
`[WaveSize(32)]` programs, as `recomp::tests::gpu_ready` does, and skip
with "no GPU with 32-lane waves" otherwise. With XCL_ADAPTER=warp the
lib runs 876 passed, 0 failed, 22 ignored.
…odes it drops

Two correctness gaps on programs the per-lane form took, found by
Kalmarv's review of xcl-dev#1745 with GPU programs against the HLSL path:

- A branch on whether any lane of a mask is set (`s_cbranch_vccz` /
  `vccnz`, `s_cbranch_scc*` after a mask op or `s_cmp_lg` of a mask) and
  a scalar read of such an SCC (`s_cselect`, `s_cmov`, `s_addc`,
  `s_subb`) decide for the whole wave on the console. The analysis took
  each lane's own bit, which differs in the lanes in EXEC that lack the
  bit (VCC = lanes 0-15, EXEC = all 32: 7 where the console gives 0). They
  are now taken only where the condition is the same in every lane that
  reaches with its EXEC bit (`s_and_saveexec` then `s_cbranch_execz`, or
  VCC equal to EXEC), and refused otherwise. The analysis test that
  stated the old assumption (a vccz branch is a lane branch) now states
  the rule.
- `s_setreg` of MODE was a no-op, so a non-default rounding mode was
  dropped where xcl-dev#1426 and the HLSL path refuse the program. MODE writes
  now go to xcl-dev#1426's lowering, and the adapter sets `dyn_rm` /
  `has_f64_round_op` as xcl-dev#1426's translator does, so `s_round_mode` and
  `s_setreg` refuse what they cannot honour. Denormal-only writes are
  still taken.

Tests: Kalmarv's five branch / select programs are refused, and a
uniform one is taken; f32 by `s_setreg` and f64 by `s_round_mode` /
`s_setreg` are refused (the f32 one was taken before the fix), and a
denormal-only write is taken.
thehollowedone's program on xcl-dev#1745: `s_and_b32 s0, vcc, exec` sets SCC
in a loop's body and the next iteration's `s_cselect_b32` reads it. The
loop head's join counted only the edges whose masks it uses, and back
edges do not count there, so the SCC came out a uniform value and the
per-lane form selected by each lane's bit: 7 where the console gives 5
in lanes 16-31. The mask-op flag now comes from every incoming edge,
back edges included, and an unknown SCC that is a lane's on some edge is
an unknown lane condition, so the whole-wave rule refuses it.

Test: his program is refused (it was taken before the fix).
Pipodi's review of xcl-dev#1745: the translated-cache identity of `XCL_PER_LANE`
entries did not include the per-lane form's sources, so a cached
container outlived a change to the lowering. build.rs hashes them into
XCL_PER_LANE_SOURCE_ID, which only the per-lane entries' identity
includes (the HLSL path's entries keep theirs).
Recompiler: a per-lane form for the direct DXIL backend (XCL_PER_LANE)
Direct DXIL: image_get_lod accepts static samplers
D3D12.X: promote R9G9B9E5_SHAREDEXP render/UAV targets to R11G11B10_FLOAT
D3D12.X: an ExecuteIndirect reads the arguments written before it
D3D12.X: eliminate multi-heap UpdateTileMappings and per-texture Signal stalls in vram::Pages
Resolve kernel.rs against main's Lw::new refactor: the geometry entry's
res buffer, LDS, 64-thread groups and f32_rm/geom fields move into
Lw::new. TRANSLATOR_VERSION 7 (main's 6 + 1).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Nearly 1000 PRs are open. actions/stale (pinned to v11.0.0's commit) labels a PR without activity
for 3 days `stale`, says what to do about it, and closes it 4 days later if nothing happens.
Issues are left alone; PRs labelled `goal:world-load` or `keep-open` are exempt. A manual run is a
dry run unless told otherwise.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Direct DXIL: geometry mode, MSAA loads and directed f32 rounding
wake_sync_watchdog spawned the xcl-sync-watchdog thread inside the
OnceLock's initializer, and the thread's first line unwraps that
OnceLock. If the thread ran before the initializer returned, it panicked
on None.
The initializer has run by then and does not run again, so no timed-out
GPU wait was released on the CPU for the rest of the process.

Seen once on main 4178e88 in a retail title run:
"thread 'xcl-sync-watchdog' (3856) panicked at
crates\xcl\src\hle\d3d12x\list_x.rs:1364:55: called `Option::unwrap()`
on a `None` value".

The pair is set first and the thread is started after it, by the call
that set it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.