Skip to content

[upstream #1732] D3D12.X: run sparse::readback_after_execute asynchronously per queue - #396

Open
ufoptg wants to merge 84 commits into
mainfrom
upstream-pr/1732
Open

ufoptg wants to merge 84 commits into
mainfrom
upstream-pr/1732

Conversation

@ufoptg

@ufoptg ufoptg commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Move sparse::readback_after_execute off sparse::State::queue and out from under STATE.lock() into per-queue FIFO background workers, completing asynchronously when the queue has an unsatisfied GPU queue.Wait (avoiding CPU/GPU deadlocks on wait-before-signal Wait64BitValueX) and synchronously when no unsatisfied queue.Wait is active (preserving immediate CPU visibility after a GPU fence wait). Part of xcl-dev#1452.

Stacked on xcl-dev#877; only the top commit (e4d8229) belongs here.

Previously, sparse::readback_after_execute locked STATE, called s.queue.Wait(&s.rb_fence, v), and synchronously executed s.readback_ranges(&merged) (s.wait_for(s.value) with a 5,000 ms timeout) inside ExecuteCommandLists. When an async compute queue carried both a sparse memory write and a wait-before-signal Wait64BitValueX whose producer direct queue had not yet been submitted on the same thread, this deadlocked both the submitter thread (preventing submission of the producer queue) and sparse::State::queue for 5,000 ms per submit, triggering repeated xcl-sync-watchdog timeouts and causing a retail title's stall watchdog to abort after 5–6 consecutive submits.

With per-queue FIFO workers waiting on a raw per-queue fence outside STATE.lock() before invoking readback_ranges, sparse::State::queue is never stalled behind a blocked title queue (sparse readback timeouts dropped to 0 across >500 s gameplay runs). Active unsatisfied queue.Wait calls are tracked via sparse::note_queue_wait (hooked in q_wait_pc and the Wait64BitValueX GPU bridge, cleaned up in q_release via sparse::forget_queue): when queue has an unsatisfied wait, readback_after_execute returns immediately; when queue is unstalled, readback_after_execute waits on the worker's completion condvar outside STATE.lock() so CPU reads immediately after a GPU fence wait (such as Write32BitValueBottomOfPipeX in testtitle) always see the read-back bytes.

What is in it

  • crates/xcl/src/hle/d3d12x/sparse.rs:
    • Add per-queue RB_QUEUES map (RbQueueState holding a raw ID3D12Fence via super::real::create_raw_fence, monotonic fence value, and channel sender to a dedicated xcl-sparse-rb-<queue> FIFO worker thread) and QUEUE_WAITS tracking (note_queue_wait, queue_has_unsatisfied_wait, forget_queue).
    • Have readback_after_execute filter/merge sparse ranges using uma::get(), signal the queue's fence, and enqueue an RbJob without acquiring STATE or calling s.queue.Wait — returning immediately if queue_has_unsatisfied_wait is true, or waiting on the job's completion condvar outside STATE.lock() otherwise.
    • Have each worker wait on its fence outside STATE.lock() (5,000 ms timeout with power-of-two warning logging on late queues) before locking STATE and running s.readback_ranges(&job.ranges).
    • Add unit test readback_after_execute_does_not_block_on_stalled_queue verifying on a real mapped sparse tile that readback_after_execute returns in < 1 s and leaves STATE unlocked while a compute queue is blocked on an unsignaled fence, and completes synchronously once the gate fence is signaled.
  • crates/xcl/src/hle/d3d12x/real.rs & crates/xcl/src/hle/d3d12x/list_x.rs:
    • Record active unsatisfied queue.Wait calls via sparse::note_queue_wait in q_wait_pc and try_gpu_wait, and clean up per-queue state in q_release via sparse::forget_queue.

Tested

  • Hardware / OS: AMD Radeon RX 9060 XT (16 GiB VRAM, RADV Mesa 26.2.7), Fedora Linux, GE-Proton11-14-x86_64, vkd3d-proton master ec20719452e916b (-Db_ndebug=true), DXC 1.9.2609.5, cross-compiled x86_64-pc-windows-msvc (clang-cl + lld-link).
  • Rebased onto main 689f2db + D3D12.X: preserve native vtables and wrap fences for vkd3d-proton under Wine (#175) xcl-dev/xcl#867 (a4c5a82) + Memory: avoid amdgpu userptr stalls under Wine (#175) xcl-dev/xcl#871 (b3f2f7c) + Memory: lazily map sparse VRAM tiles for Wine graphics heaps (#175) xcl-dev/xcl#877 (b112fe7) and verified under Proton (--test-threads=1, XCL_DXC_DIR set for GPU tests):
    • --exact hle::d3d12x::sparse::tests::readback_after_execute_does_not_block_on_stalled_queue: 1 passed, 0 failed, 0 ignored, 0 skipped
    • hle::d3d12x::sparse::tests: 16 passed, 0 failed, 1 ignored (pre-existing #[ignore] early_commit_timing)
    • hle::d3d12x::list_x::: 27 passed, 0 failed, 0 ignored
    • --exact gpu::recomp::tests::gpu_sparse_vram_descriptors_buffers_and_xmem gpu::recomp::tests::gpu_valu_float_and_int: 2 passed, 0 failed, 0 ignored, 0 skipped
  • Retail title 60 s smoke run under GE-Proton11-14 (XCL_NETWORK=0 XCL_PSO_PRELOAD=0 XCL_RUN_SECONDS=60 XCL_ACTIVITY=1, VKD3D_CONFIG=""): 1079 frames shown (1079 PresentX, 0 0 0 presents/2 s) with 0 crashes and 0 device removals.

Regression run
Produced under Wine (GE-Proton11-14, AMD Radeon RX 9060 XT, vkd3d-proton ec20719452e916b, XCL_NETWORK=0 XCL_PSO_PRELOAD=0 XCL_RUN_SECONDS=60 XCL_ACTIVITY=1, VKD3D_CONFIG="") using the xcl-smoke v1 log extraction format (Linux environment; native Windows scripts/smoke.ps1 could not be run; peak commit: 0 MB is what 689f2db logs under Wine before xcl-dev#1097).

main (689f2db):

xcl-smoke v1
commit: 689f2db477c3c062cf162649781640ef8a977c18
gpu: AMD Radeon RX 9060 XT
title: retail-title
seconds: 60
exit: 0x3
frames shown: 0 (did not reach end)
presents per 2 s (last 3): 0 0
device removals: 0
crashes: 2
peak commit: 0 MB

This PR (e4d8229, stacked on xcl-dev#877):

xcl-smoke v1
commit: e4d8229650344e003513bd3775eb90502854c96b
gpu: AMD Radeon RX 9060 XT
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1079 (PresentX 1079)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 0 MB

Not tested

  • Native Windows (test_title_runs_and_game_folder_is_untouched e2e needs re-check on Windows after e4d8229).
  • NVIDIA Linux GPUs.

AI use

  • Antigravity (Google DeepMind, exact model name not exposed to the agent) assisted with root-cause analysis, implementation, rebase, unit test design, and running the Wine test/smoke verification on this machine.

Mirror of xcl-dev#1732 (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.
gefydev and others added 30 commits November 24, 2026 18:00
…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
…er Wine (#175)

vkd3d-proton validates iface->lpVtbl on adopted D3D12 objects passed back into d3d12core.dll (command allocators, lists, heaps, resources, PSOs, and fences). On unmodified assertion-free vkd3d-proton (such as GE-Proton or -Db_ndebug=true builds), XCL's in-place vtable adoption causes CreateCommandList/Reset to fail with E_INVALIDARG and fence waits to reject adopted fences.

Under Wine (gated behind util::under_wine(), native Windows unchanged):
- UnadoptGuard temporarily restores the native vtable on adopted command allocators (including alloc_pool backings and reset_pc_allocator), command lists, heaps (CreatePlacedResource/CreatePlacedResource1), RTV resources, and PSOs around calls into d3d12core.dll.
- FenceProxy wraps title ID3D12Fence1 objects so the underlying PC fence keeps its native lpVtbl, unwrapping in queue Signal/Wait while preserving Fence::#12 completed_value_address and freeing on final Release.
- real::create_raw_fence creates un-proxied native ID3D12Fence objects for XCL's own internal queue tracking (late_release, alloc_pool, list_x, cpu_writes, present, vram, drain_gpu) so un-adopted internal queues like sparse::queue() never receive a FenceProxy.

Note: assert-enabled vkd3d-proton builds (such as stock Proton Experimental) still validate iface->lpVtbl inside an adopted object's own methods, so an assertion-free build (-Db_ndebug=true / GE-Proton) remains required for in-place adoption.

Assisted-by: Antigravity (Google DeepMind)
On Linux with amdgpu, a multi-GiB coherent UMA window imported via OpenExistingHeapFromAddress (VK_EXT_external_memory_host userptr) causes two severe stalls:
1. GetWriteWatch(WRITE_WATCH_FLAG_RESET) on the userptr range triggers amdgpu MMU-notifier evictions (~100-200 ms/submit).
2. A multi-GiB userptr BO stalls every Vulkan GPU submission (~150 ms/frame, dropping PresentX frames).

Under Wine (native Windows unchanged):
- Key the default 512 MiB coherent_hint() cap on AMD GPUs (DXGI VendorId 0x1002) under Wine so NVIDIA Linux keeps a full-size coherent window (unless XCL_COHERENT_MB is set).
- Allocate the coherent window without MEM_WRITE_WATCH and exclude it from watch_regions(), notifying title_textures on DirectStorage writes into it and hashing small/dynamic coherent textures with a 1/16 round-robin sweep for large ones.
- Route overflow PAGE_GRAPHICS_* title GPU heaps into the sparse VRAM windows so shaders still read them directly.

Assisted-by: Antigravity (Google DeepMind)
Under Wine, overflow PAGE_GRAPHICS_* title heaps are routed to sparse VRAM
windows (xcl-dev#871). Eagerly mapping 64 KiB VRAM tiles for the full reserved
heap up front consumes ~3.2 GiB of local VRAM for zero-filled or never-
written pages before the title even leaves the menus.

Add sparse::alloc_lazy (used under util::under_wine() only; native Windows
unchanged):
- Commits CPU pages up front so host accesses never fault, while deferring
  64 KiB VRAM tile allocation until the first non-zero CPU write or GPU
  write target registration (placed buffers, buffer UAVs, and command-list
  memory writes via sparse::ensure_lazy_mapped).
- Unit tests cover lazy-range overlap, hole masks, non-zero page detection,
  and coalesced lazy tile allocation.

Assisted-by: Antigravity (Google DeepMind)
…g STATE or sparse::State::queue

sparse::readback_after_execute previously stalled sparse::State::queue
behind the title queue (s.queue.Wait) and synchronously blocked the
submitter thread inside STATE.lock() for up to 5000 ms (s.wait_for).
When an async compute queue carried both a sparse write and a
wait-before-signal Wait64BitValueX whose producer direct queue had not
yet been submitted on the same thread, this deadlocked both the
submitter thread (blocking submission of the producer queue) and
sparse::State::queue for 5000 ms per submit, triggering xcl-sync-watchdog
timeouts and the title's stall watchdog after 5-6 consecutive submits.

Dispatch sparse readbacks through per-queue FIFO background workers that
wait on a raw per-queue fence outside STATE.lock() before invoking
readback_ranges, never stalling sparse::State::queue. Track active
unsatisfied queue.Wait calls via note_queue_wait (in q_wait_pc and the
Wait64BitValueX GPU bridge, cleaned up in q_release via forget_queue):
when the queue has an unsatisfied Wait, readback_after_execute returns
immediately while the worker finishes asynchronously; when no
unsatisfied Wait is active, readback_after_execute waits on the worker's
completion condvar outside STATE.lock() so CPU reads immediately after a
GPU fence wait (such as Write32BitValueBottomOfPipeX in testtitle)
always observe the updated bytes.
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.