Skip to content

Dxil/guard wave64 graphics cache - #1

Open
mokkamokacaffe wants to merge 190 commits into
fixgep:mainfrom
mokkamokacaffe:dxil/guard-wave64-graphics-cache
Open

mokkamokacaffe wants to merge 190 commits into
fixgep:mainfrom
mokkamokacaffe:dxil/guard-wave64-graphics-cache

Conversation

@mokkamokacaffe

Copy link
Copy Markdown

What is in it

Fixes xcl-dev#1895.

  • Passes the adapter's wave32/split requirement into the Direct DXIL VS/PS route.
  • Falls back to the HLSL upper_lanes implementation when a wave64 graphics shader reads data from lanes 32-63 that Direct DXIL cannot represent in a 32-lane wave.
  • Applies the same refusal to xcl shaders --direct, keeping coverage results consistent with runtime routing.
  • Disables the translated shader caches while XCL_DXIL_NO_OPT is set, so diagnostic, deliberately unoptimized DXIL cannot poison later normal runs.
  • Adds focused unit coverage for upper-lane classification and the cache override.

Tested

  • git diff --check
  • Source-level call-site audit for direct_graphics and needs_upper_lanes.

The current Linux workspace does not contain Cargo/Rust or the Windows D3D12/DXIL toolchain, so Rust unit tests and DXIL validation were not run here.

Regression run

Not run: this change needs the maintainer's Windows/GPU smoke pass on both this exact head commit and its main base. Please apply test-only until those two matching xcl-smoke v1 blocks are available.

Not tested

  • Runtime smoke test in a retail title.
  • DXIL validator execution.
  • AMD and NVIDIA GPU execution of affected wave64 VS/PS shaders.

AI use

OpenAI Codex was used to inspect issue xcl-dev#1895 and current source, implement the routing/cache guard, add focused tests, and perform source-level validation. No generated test results or hardware claims are included.

sennecools and others added 30 commits November 24, 2026 00:52
…ther

gather4h, gather4h_pck and gather8h_pck fetch a horizontal row of texels,
but the prefix match on "gather4" sent them down the Gather path and
returned a 2x2 footprint. Report them as unsupported until the row's
position and rounding are measured.

AI-assisted (Claude Code)
…-dev#336)

Preparation for classifying wave64 VS / PS by whether their result depends
on how a 32-lane GPU cuts their waves: that needs to know which blocks run
because of a wave-wide vote. No behaviour change: nothing calls it yet.

cfg::Cfg builds a program's basic blocks from upper_lanes::successors (now
shared), and gives each block's immediate post-dominator (Cooper, Harvey
and Kennedy's iteration on the reversed graph, with one exit after every
block that ends the program) and the branches it is control-dependent on
(Ferrante, Ottenstein and Warren). A program with an indirect jump has no
graph; a block from which no path ends the program has no post-dominator.

Measured over all 26 698 programs of a retail shader pack (release, one
thread): no panic, 195 with an indirect jump, at most 15 995 blocks in one
program, at most 15 ms for one program's graph, post-dominators and
control dependence.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Channel::connect() left self.messages alone, so a MSG_DISCONNECTED (or
stale command acks) queued before a disconnect surfaced on the fresh
connection. Clear the queue on connect. Part of xcl-dev#329.

Assisted-by: Devin (SWE-2 Flash Medium)
…xcl-dev#476)

A destination page array entry that is 0 at EnqueueRequest is read again
at the request's turn (xcl-dev#289). That read checked `readable()` and then
dereferenced the title's memory: an array the title unmapped between the
two faulted in the xcl-dstorage worker and ended the process. It now reads
with `read_own` (ReadProcessMemory), as the snapshot at enqueue already
does: the request fails with E_ACCESS_VIOLATION instead.

An array the title frees and reuses before the request's turn cannot be
told from a late fill; the title keeps it until the request is done, as
the comment now says.

The test runs 20000 requests with a deferred entry while another thread
decommits and recommits the array's page: before, the test process ended
with 0xc0000005 (5 of 5 runs); after, it passes (10 of 10).

Fixes xcl-dev#476

Assisted-by: Claude Code (Claude Opus 5.5)
Inverse quantization computed the same exponential for each coded band. Cache the finite f32 gain range in the shared decoder tables and clamp exponents outside the range to the matching zero or infinity endpoint.

On MSVC, the synthetic gain benchmark went from 14.929 ns to 0.517 ns per band and the cross-packet decode went from 35.975 to 33.128 us, with bit-identical samples.

Co-Authored-By: GPT 6.2 Sol <noreply@openai.com>
Windows gives PlayStation controllers to XInput only through extra
software (Steam Input, DS4Windows), so a player with one had no gamepad.
They are now read as HID devices (input report 0x01) on a thread of
their own, and used when no XInput controller answers: buttons, sticks
and triggers; no rumble or light bar. DualShock 4 over USB or Bluetooth
(the same first bytes), DualSense over USB. XCL_PLAYSTATION_PAD=0 turns
it off.
check_uma_import waits 2 s for its copy out of the coherent window. When the wait ran out it returned and dropped the queue, allocator, list, fence and readback buffer and freed the probe words, with the copy still on the GPU. vkd3d-proton releases them at once; on RADV the GPU then faults on the freed memory (GCVM_L2_PROTECTION_FAULT, client TCP) and the gfx ring times out: the title's device is removed within its first minute. Under Wine the first use of the 4 GiB imported window can take longer than 2 s (1.3 s when it does not), so this happened in some runs only. On a timeout, what the copy uses is now kept (forgotten, once).
…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.
A retail title's NGG transform programs (128 vertices / 128 primitives,
21 params + SV_ClipDistance0 = 352 B per vertex) all failed ms_6_6 with
"vertex plus primitive output size is greater than 32768": the split
budget divided 32768 by the stride, but DXC accounts whole chunks of 32
vertices even when fewer are declared - verts[78] at 352 B is accounted
as 96 (33792 B) and refused. Measured with dxc 1.8.2502 on this machine:
every boundary from 9 to 26 float4 rows agrees with the chunk model.

passthrough_split now floors the vertex budget to a multiple of 32
(capped at 256); the wide records go out in 7 groups of 19 triangles
instead of 5 groups of 26 that DXC refuses. Test: the wide record splits
and compiles, a 96-vertex group at 320 B compiles, a narrow record stays
whole; fails without the change (5 != 7).

Assisted-by: DSH (GPT-6.2 Astra)
The emitter picked the whole-record layout from passthrough_split == 1, but
that count is the dispatch's: a record of 80 vertices with 22 float4 rows
does not fit the mesh output budget as a whole (DXC accounts 96 vertices,
33792 B > 32768) while its single triangle's compact copies fit one group,
so the count is 1 and verts[80] was declared and refused. The declaration
now follows the vertex budget independently of the group count; the compact
form covers every record over the budget, including the one-group ones.

mesh_layout_independent_of_group_count covers the asymmetric limits (80
vertices, 1 triangle, 22 rows): compact declaration, count 1, DXC accepts.
Found in review by shdann (PR xcl-dev#304).

Assisted-by: DSH (GPT-6.2 Astra)
A retail title streams thousands of 64 KiB zlib blocks during startup. Enable the existing checksum backend to validate them using SIMD on supported CPUs.

Assisted-by: Codex (GPT-6.2 Astra)
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
Review nits (Parakeet-Wheat): mesh_layout_independent_of_group_count ended with a block that rebuilt the same MsInterface and asserted verts[3] again; it now compiles the whole-record declaration (verts[80], accounted as 96: 33792 B) and asserts DXC refuses it. passthrough_split's doc claimed a comparison of the two forms it does not make; the doc now states what it does. Tests only plus a doc line; no behaviour change.

Assisted-by: DSH (GPT-6.2 Astra)
…them

Part of xcl-dev#336. A GPU that runs a console wave64 VS / PS in 32-lane waves runs
each half of the console wave on its own. upper_lanes follows what lanes >= 32
hold when they are read; this follows the other ways the cut shows: wave-wide
votes are taken per half, and lane counts, ranks, first-lane indices, masks
used as numbers and other lanes' values differ in a half. Classification
only: nothing translates by it yet.

partition::classify runs a forward data-flow pass over the program's blocks
(cfg) with taint bits per register and reports Exact / MayDiffer with the
reasons:
- a tainted value reaching an export, a store (LDS / GDS ones included), a
  branch or EXEC; one word of EXEC or a number written to EXEC;
- a vote (vccz/vccnz, execz/execnz, scc on a mask) unless the side taken
  with the mask empty is the join or ends the program writing nothing, and
  the other side starts by narrowing EXEC to the mask (for a mask other
  than EXEC) and does not widen it again before the join (a restore of a
  mask saved inside, an if/else flip, a restore right before the join are
  fine) – or the mask is all or none of the active lanes;
- a scalar written in the blocks a vote decides and read after the join
  (a half that took the other side never wrote it).
Values every lane has are followed (written under the launch EXEC by plain
VALU ops of such values, through all-or-none selectors, or loaded at such
addresses), so reading one from the first lane is exact. Register uses
come from x64_masks::uses (read-modify-write destinations, SDWA scalar
sources, SMEM offsets, src_vccz / src_execz) plus src_scc, NSA addresses
and image loads by their DMASK (upper_lanes::vgpr_writes, now shared).

Tests include the review's counter-examples (values written under a
narrowed EXEC or selected per lane, a vote read as a number, mask words
moved, read-modify-write taint, a side that widens EXEC again, an SCC vote
whose mask is rewritten, EXEC's high word, image DMASK, DS writes) and one
for every reason.

Over the 13 210 wave64 VS / PS of a retail shader pack (local run): 7 208
Exact (5 118 of 10 974 PS, 2 090 of 2 236 VS), at most 159 ms a program.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An SDWA instruction's text stopped at its registers: which byte or word
each source is read from and the result written to, sext / neg / abs on
the sources, clamp and the output modifier were left out, a second
source with its S bit set was printed as a VGPR, and a compare that
writes an SGPR instead of VCC did not show it. The decoder and the
recompiler have all of these; only the printed line dropped them (the
same gap as xcl-dev#664, in the encodings that issue does not list).

The text follows LLVM's: all 2816 lines of its gfx10 SDWA tests in
tests/data/llvm-amdgpu now read the same (none did), apart from the
implicit vcc operands that the plain forms leave out too.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
An image (MIMG) instruction was printed with the widest registers its
opcode can take and nothing else: `image_load v[16:19], v[8:11],
s[96:103]` for every DMASK, dimension and flag, and an NSA form's
address registers were not listed at all. Now, as LLVM writes it: the
data registers DMASK selects (four for a gather, halved by D16, one
more with TFE), the address registers the opcode and the dimension take
(a list when NSA dwords name them), then dmask, dim and unorm / glc /
slc / dlc / r128 / a16 / tfe / lwe / d16. The recompiler reads all of
these; only the printed line dropped them (the gap of xcl-dev#664, in an
encoding that issue does not list).

All 265 image lines of LLVM's gfx10 tests in tests/data/llvm-amdgpu now
read the same (2 did).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
NathanTheophile bisected DXC's ms_6_6 acceptance boundary over 96 cases (1-32 float4 rows, up to 256 primitives): the formula matches exactly everywhere, not only rows 9-26. Doc-only; narrower clip/cull rows count as full rows (overestimate only).

Assisted-by: DSH (GPT-6.2 Astra)
…cl-dev#336)

The partition classifier accepted a mask vote only if the side the wave
runs starts with an instruction that narrows EXEC by the vote's mask. The
console compiler's pixel-shader discard early-out narrows it one step
later: `s_wqm_b64 s, live; s_and_b64 exec, exec, s`, often with scalar
loads in between. Such votes were reported as `vote-branch`.

The side now only has to turn EXEC off, in a half whose mask is empty,
before its first lane instruction. The zero flow of the vote's side checks
it: wqm(0) and x & 0 are zero there. Before that only scalar ALU ops, scalar
loads, s_waitcnt and s_nop are allowed; their writes are the wave's and are
followed as stale where the sides join. s_setreg, s_sendmsg, PC writes and
any lane instruction end the search. Every shape the old first-instruction
check accepted passes the new one.

Over the 13 210 wave64 VS / PS of a retail shader pack: 7 015 Exact
instead of 6 057 (PS 4 912 of 10 974, from 3 954), `vote-branch` 5 186
programs instead of 6 375. A reference interpreter of a 64-lane wave and
its two 32-lane halves (from the review of xcl-dev#517) shows no difference for
the new exact form over 5 000 random cuts, and differs for an export
placed before the narrowing, which stays `vote-branch`.

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

A kernel VirtualQuery on a 4 GiB OpenExistingHeapFromAddress coherent UMA window walks the entire region (~75-80 ms) while holding MmLockAddressSpace, stalling GetWriteWatch on other threads.

eh::is_writable already checks uma.in_committed_window() first; extend the same fast path to cpu_writes (write_now, write_u64_now, writable), kernelx (VirtualQuery, VirtualQueryEx, XMemVirtualQuery, committed_range, committed_page_in), and list_x frame-trace diagnostics.
…computed operand plans

Co-Authored-By: Gemini 4 Neon <noreply@google.com>
Only ds_write_addtid_b32 / ds_read_addtid_b32 checked the GDS bit (xcl-dev#79).
Every other DS instruction with GDS=1 (plain and read2/write2 forms,
d16 and 8/16-bit forms, wrxchg2, the read-modify-write atomics) was
translated as an access to the group's LDS (xcl_lds): it overwrote the
title's groupshared data, read LDS instead of the global data share,
and nothing was recorded as unsupported.

The GDS check now runs for every DS instruction that reaches LDS
memory, after the "LDS outside compute" check, so the ADDTID forms
behave exactly as before. ds_swizzle_b32 / ds_bpermute_b32 use no
memory and are left as they were.

ds_gds_plain_forms_are_unsupported translates DS_ADD_U32, DS_WRITE_B32
and DS_READ_B32 with GDS=1; before the change none was recorded as
unsupported and each declared groupshared xcl_lds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
image_get_resinfo with DIM = 1D_ARRAY wrote the layer count into z and
1 into y, so a 1D array read back (width, 1, layers, mips). On RDNA
(GFX10+) the hardware returns the layers in y.

Mesa's AMD backend (ac_nir_to_llvm.c, read in Mesa 21.3.9) uses the
hardware result's .xy directly for textureSize(sampler1DArray) and only
moves z into y on GFX9: visit_image_size and the txs path both guard
the move with `chip_class == GFX9 && dim == GLSL_SAMPLER_DIM_1D &&
is_array`, because ac_get_sampler_dim (ac_shader_util.c) maps a 1D
array to ac_image_2darray on GFX9 alone and to ac_image_1darray on
the others.

GetDimensions now writes the element count into y; z keeps the layer
count it had before (no source found for z on a 1D array), so only y
changes.

Tests: a translation test of the HLSL (fails before the change), and a
GPU test with a 4-wide, 3-layer 1D array expecting (4, 3, _, 1); the
test runner gains a TexDim::D1Array for it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ine is skipped, as Dispatch is

Dispatch skips a console compute pipeline without a translation (a build that failed). ExecuteIndirect sent the same pipeline to the PC call after setting only the graphics root signature, so the dispatch ran with the list's compute root signature, which can still be XCL's ABI one from a translated dispatch before it. The D3D12 debug layer reports that pair as error 953 during a retail title's world load.

Command signatures with a Dispatch argument are now noted when they are made (and forgotten when a signature without one is made at the same address). Compute pipelines made from a console shader that runs untranslated (a background build's stand-in, the fallback of a console shader that failed) are noted too, and dropped with the pipeline. ExecuteIndirect skips a Dispatch signature only for those; a native PC compute pipeline still goes to the PC call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
After s_wqm the helper pixels of a quad an edge splits are in EXEC, but
ballot() took masks with WaveActiveBallot alone, which leaves helper
lanes out before SM 6.7: v_cndmask gave them the false value,
s_and_saveexec dropped them, derivatives taken across the quad by hand
were wrong along every edge, and a waterfall loop over v_readfirstlane
never removed a helper lane from EXEC (ran into the loop budget).

ballot_px gets each quad's four bits through quad reads and collects
them with four ballots (a helper lane gets the wave's result of a
ballot, but not of WaveActiveBitOr on an RTX 5070 Ti, and it holds its
own copy of EXEC). Masks only read lane by lane (x64_masks liveness, now
also for pixel shaders) take ballot_px_local: one ballot plus the lane's
own bit. The entry EXEC stays the live lanes. HLSL of every other stage
is byte-identical.

Tests: gpu_ps_masks_hold_helper_lanes_on_triangle_edges (384 / 1024
pixels wrong before, 0 after, wave64 and wave32 programs),
gpu_ps_helper_lanes_see_ballots_and_quads_are_lanes_4k.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…xcl-dev#134)

ballot_px quad-reads a compare's result for the helper lanes' bits. AMD's
compilers crash in CreateGraphicsPipelineState on two shapes of that: RDNA2
on quad reads of a value computed from a WaveReadLaneAt in a loop
(WarmMilkCodes, RX 6600 XT), RDNA3 on a WaveReadLaneAt whose lane comes from
such a mask, with no loop (srcamarda, RX 7800 XT; RDNA4 too per the
maintainer's run). Every mask quad_bits can express now reads the compare's
vector operands through quad reads and evaluates the compare per member
(ballot_px_quad); the others keep ballot_px. The loop ranges this first
needed are gone.

The change outside loops is srcamarda's, from their review of this PR.

Co-Authored-By: srcamarda <5217213+srcamarda@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A bind of a pipeline still being built holds the title's thread until the build is
done (pso_async::resolve_wait): a console title never waits there. A retail title's
own stall check is a thread that ticks once a second with Sleep and ends the process
after 30 ticks without a sign of its main thread. While the driver built the compute
pipelines of its world the main thread was held in binds, and the title ended itself
about 30 s after the world's set-up began (xcl-dev#505, xcl-dev#232).

XCL now takes the title's Sleep (it comes in through api-ms-win-core-synch): a sleep
of 100 ms or more returns after its time has gone by in which no bind was waiting for
a build (pso_async::title_held), taken in steps of 20 ms. A shorter sleep is a poll
and is passed on as it is, like a yield and an endless sleep: a thread that paces
streaming or sound with short sleeps goes on while a bind waits. XCL_SLEEP_HOLD=<ms>
sets that length; 0 leaves the PC's Sleep as it is.

Nothing of the title is changed and no dispatch is skipped; a title that is not held
sleeps as before.

Tests: a_sleep_does_not_count_the_time_the_title_is_held,
a_sleep_stops_counting_when_the_title_gets_held,
a_short_sleep_is_passed_on_while_the_title_is_held,
a_sleep_of_a_title_not_held_takes_its_time,
a_bind_waiting_for_a_build_holds_the_title.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Runtime-indexed uint4 values became local arrays in DXIL and made large NVIDIA pipeline compiles substantially slower. Select components explicitly in format helpers and BVH barycentric selection instead.\n\nOn a 579 KB translated compute program this removed 101 local arrays; five cache-disabled driver runs improved from a 24.2 s median to 18.6 s. GPU tests cover packed formats, all four 32-bit components, selectors 0/1/4/7, stores, and BVH intersections.\n\nAssisted-by: OpenAI Codex (GPT-5)
raylitebull and others added 29 commits November 25, 2026 01:49
…al-wave

Direct DXIL: TG_SIZE counts a partial last wave
…nd-oob

dxil: lower 64-bit icmp via 32-bit dwords and guard MIMG heap indices
Shaders: size-based admission for big compute driver compiles
Pixel shaders: masks hold the helper lanes (xcl-dev#105 item 1)
Recompiler: classify wave64 VS / PS by whether a 32-lane cut changes them (xcl-dev#336)
Recompiler: a vote's side may narrow EXEC through a whole-quad copy (xcl-dev#336)
Recompiler: the mesh pass-through budget accounts DXC’s vertex chunks
…at-rtz-unorm

Recompiler: saturate UINT/SINT and use RTZ in fmt_encode
…e-bitcode-operands-1269

Recompiler: reuse operands when writing DXIL instruction records
…rray-layers

Recompiler: image_get_resinfo on a 1D array gives the layers in y
Recompiler: direct DXIL cache entries change when its sources do
…ge-array-read

DirectStorage: a deferred page-array entry is reread without faulting (xcl-dev#476)
kernelx: implement XMemIsToolsMemAvailable and route xmem.dll
…light

D3D12.X: a timed-out UMA import check keeps what the GPU still uses
Recompiler: reject image_gather4h/8h instead of translating as 2x2 Gather
Shaders: xcl disasm prints SDWA selectors, modifiers and scalar sources
…ness

Recompiler: solve split-wave64 mask liveness per basic block with precomputed operand plans
GameInput: a DualShock 4 or DualSense is the gamepad without XInput
acphal: a reconnect drops messages queued for the old channel
Recompiler: fold split-wave64 reduction tail v_readlane exchanges
XAudio2: precompute XMA inverse quantizer gains
…ib-checksum

DirectStorage: use SIMD for zlib checksums
Shaders: xcl disasm prints image operands, dmask, dim and flags
Recompiler: honor pixel shader EXP VM valid-mask bit in HLSL and DXIL
Scripts: fail a shader coverage regression against a committed baseline
Recompiler: use IEEE-754 equality for float compare-and-swap atomics
…ported

Recompiler: report every DS instruction with GDS=1 as unsupported
…deadlock

D3D12.X: a buffer's last release does not wait for the sparse state's lock
@mokkamokacaffe
mokkamokacaffe force-pushed the dxil/guard-wave64-graphics-cache branch from 51738bb to cf70b66 Compare November 25, 2026 01:16
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.

Shaders: XCL_DIRECT_DXIL=all ignores split_wave64 / upper_lanes for wave64 VS/PS (poisoning split=1 cache), and XCL_DXIL_NO_OPT bypasses cache_allowed()