Skip to content

Merge amd-dev into main - #3547

Open
lucsoft wants to merge 188 commits into
xcl-dev:mainfrom
lucsoft:merge/amd-dev-into-main
Open

lucsoft wants to merge 188 commits into
xcl-dev:mainfrom
lucsoft:merge/amd-dev-into-main

Conversation

@lucsoft

@lucsoft lucsoft commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

Moves amd-dev into main: 176 commits, +26.4k/−1.0k in 103 files against current main (1c8b551). Ready for testing on other GPUs; the defaults below decide what changes for everyone.

amd-dev's memory switches (XCL_TEXTURE_LEVEL_PAGES, XCL_SMALL_TEXTURES, XCL_VRAM_SMALL, XCL_ZERO_TARGET_PAGES, XCL_FORMAT_ALIAS) are off by default here, as on main: with them on, the retail title hung in the load in 5 of 6 runs on an RX 7800 XT; with all five off it ran 600 s clean. Translator defaults (XCL_DECLARED_LDS, XCL_PS_MASKS, …) and the NVIDIA-facing knobs are left as amd-dev has them and need a non-AMD test pass.

What is in it

Tested

  • AMD Radeon RX 7800 XT (RADV NAVI32), AMD Ryzen 7 7800X3D, NixOS with Wine 11.21 (Staging) + vkd3d-proton, rustc 1.95.0, release build, x86_64-pc-windows-gnu
  • whole suite, one module per process, 2 threads (--test-threads=2, not 4: under Wine one very heavy test ran the machine out of memory with more threads), 30ca950 against main 1c8b551 on the same machine:
    • lib: 2943 passed, 17 failed, 31 ignored, 1 died (serialize_root_signature_*, hangs under Wine); main: 2735 passed, 17 failed, 31 ignored, 1 died – 16 of them fail on both; the 17th is title_textures below on the PR and gpu_ps_readfirstlane_loop_on_a_primitive_edge_ends on main
    • integration: 144 passed, 5 failed, 20 ignored; main: 143 passed, 5 failed, 20 ignored – the same 5 on both (e2e ×2, gpu_two_pass_cache_e2e, pls_quota, tls_slot_zero)
    • title_textures::remapped_pages_are_compared_with_what_they_held failed once in the suite run (that group fails together under Wine when one test panics) and passed alone 2/2; it is not on main
    • uma_driver not run (~32 GB under Wine)
    • SKIPPED: no D3D12 debug layer / d3d12SDKLayers.dll, no dxc.exe, no Developer Mode (driver cache), heap windows opt-in (XCL_HEAP_WINDOWS), Close does not refuse an open pipeline-statistics query (2), host ignores SetPredication for copies, no successful stale-blob probe
  • Windows CI's failure on dd6cec7 (vram_small::gpu_small_textures_pack_at_4k_granularity_and_preserve_pixels, the switch now off) is fixed in 30ca950: vram_small 5 passed, 0 failed here

Regression run

main 1c8b551 did not reach the end of a 600 s run on this machine in two tries (device removal after GPU page faults both times), so its block has no frame count. The PR ran 600 s clean twice: 2615 frames at dd6cec7 (the same tree without the test fix 30ca950), 2114 at the head below; 0 page faults and 0 ring timeouts in the kernel log both times.

Both runs below were made with -Title <game name>; after the runs that flag was dropped from our wrapper, and the title: line of both blocks now shows smoke.ps1's default label instead (f651e787, the hash of the game folder's name). Nothing else in the blocks was changed; the runs are the same.

main:

xcl-smoke v1
commit: 1c8b551475e1e7bfe48f94448492a4c3544a2e0f
gpu: AMD Radeon RX 7800 XT (RADV NAVI32)
title: f651e787
seconds: 600
exit: 0x5
frames shown: none logged (the run did not reach its end)
presents per 2 s (last 3): 0 0 0
device removals: 1
crashes: 1
peak commit: 0 MB

PR:

xcl-smoke v1
commit: 30ca950e78cc7758044640a9d46a59f4559c8cf0
gpu: AMD Radeon RX 7800 XT (RADV NAVI32)
title: f651e787
seconds: 600
exit: 0x0
frames shown: 2114 (PresentX 2114)
presents per 2 s (last 3): 0 2 1
device removals: 0
crashes: 0
peak commit: 0 MB

Not tested

  • NVIDIA, Intel and Windows: only RADV under Wine was run
  • the five memory switches turned back on (they hang the load here)
  • uma_driver tests

AI use

  • Claude Code (Claude Opus 5.5): merged main into the branch and resolved the conflicts, the vram_small test fix (30ca950), the test and game runs above, this description
  • the fixes brought over on 2026-12-01 (c909fb8 – 1bb6108) were ported by Codex (gpt-6.2-sol) and pi (gpt-5.3-codex) agents and finished and checked in Claude Code

🤖 Generated with Claude Code

raylitebull and others added 30 commits November 27, 2026 22:23
…ave64 masks

Bring Direct DXIL pixel shaders and wave64 HLSL pixel shaders in line with
6ec402b (first_lane_live) and 8fcc111 (mask_live):
- Direct DXIL v_readfirstlane_b32 now calls Lw::first_lane_live, intersecting
  EXEC with ballot(true) in pixel shaders when any live lane is active so
  helper-lane zeroing inside loops on AMD drivers cannot spin to LOOP_BUDGET.
- Wave64 HLSL pixel shader s_and_b64 / s_andn2_b64 with EXEC or VCC now tests
  live lanes only via mask_live64, matching mask_live for wave32 pixel loops.

Assisted-by: Antigravity (Gemini 4 Neon High)
…)) wrong)

amdxc64 on RDNA4 folds Bfrev(Countbits(K)) for a constant K to
Bfrev(n) | n (0x80000001 for K = 2). Fold Countbits of constants in
bit_count so the driver never sees that pattern. Fixes fuzz seed 1599
on the RX 9070 XT (xcl-dev#2115).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
In a Wave32 pixel shader a VALU mask write (a carry or compare SDST) and
a scalar SAVEEXEC / WREXEC write one dword: write_mask calls write32
when the program is not wave64. The liveness that decides whether a
mask needs the helper lanes' quad reads (x64_masks) took its kill sets
from the ISA tables, which describe the wave64 pair. So
`v_add_co_u32 v3, s20, ...` was taken to overwrite s21 as well; an
earlier carry into s21 that `v_bcnt_u32_b32 v4, s21, 0` reads later was
taken for a lane-local mask and built with ballot_px_local, and with
WQM on its helper lanes' bits were missing at triangle edges (xcl-dev#2584).

For Wave32 pixel shaders those writes now kill one dword, and a mask
write takes the full ballot when either this liveness or the existing
pair rule says its destination can be read whole, so no mask that took
the full ballot before loses it. Split wave64 and wave64 pixel shaders
keep the pair rule; the direct DXIL path (by_pc) is unchanged.

Tests: x64_masks::tests::wave32_carry_into_s20_preserves_a_whole_read_of_s21
and gpu_wave32_pixel_carry_preserves_adjacent_mask_at_triangle_edges,
which draws the issue's program on two triangles.

Fix and tests by akimfomin (akimfomin/xcl@d3e7725), carried onto main
without its README line.

Refs xcl-dev#2584

Co-authored-by: akimfomin <akim.fomin@mail.ru>
Assisted-by: Google Antigravity CLI (Claude Opus 5.5 (High))
This takes out e964ad2, which kept the table limit of 8,192 words on a
GPU with 64-lane waves. It was added after a run on an RX 9070 XT at
cbc296a, where neither form of the program it let in built within
24 GB and the compact form reached that sooner. Since xcl-dev#2174 the compact
form nests its dispatch by default, and on the same card model with
64 GB that program's nested compact form built in 159 to 203 s at about
34 GB with heap memory windows, where its plain form, which the guard
kept, passed 48 GB (komglebissarov on xcl-dev#2088, 1 run per form). With the
default switch windows both forms passed 48 GB, so that path does not
change.

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

(cherry picked from commit b6df9a7)

Port onto nvidia-dev: the table limit lives in automatic_plan (this
branch's form of `wanted`, which also takes split-wave atomic programs),
so its `tables` argument goes and it checks MAX_TABLE_WORDS; the
`wave32_only` argument of translate_compute_rodata goes the same way.
In Direct DXIL mubuf and buffer_atomic (stride == 0), off = voff + OFFSET
and e = off + bytes were compared against d2 without checking for 32-bit
unsigned wraparound (xcl-dev#1893). A large voff near 2^32 wrapped below d2 and
passed the OOB guard while 64-bit buffer_window() carried into the adjacent
4 GiB UMA window.

Check unsigned carry in pure 32-bit arithmetic (off >= voff when OFFSET != 0,
and e >= off) before comparing e <= d2, avoiding i64 promotion while closing
the wraparound bypass.

Assisted-by: Antigravity (Gemini 4 Neon High)
(cherry picked from commit 70e600d)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fixes two Direct DXIL correctness bugs (xcl-dev#1894, xcl-dev#1890):
- Module::uses_double_extensions now iterates live instructions in self.blocks
  (matching insts_use_type) instead of all self.insts, preventing DCE-removed
  f64 ops from spuriously setting DoubleExtensions shader flags.
- Lw::top_vgpr now incorporates Lw::max_vgpr precomputed across all decoded
  instructions (init.touched is empty outside Entry::Kernel), and v_movrels /
  v_movreld / v_movrelsd mask M0 to M0[7:0] (& 0xFF) per RDNA2 ISA.

Assisted-by: Antigravity (Gemini 4 Neon High)

(cherry picked from commit 2c33f9f)

Port onto nvidia-dev: only `max_vgpr` is added to Lw; the
`barrier_uav_fence` field next to it upstream belongs to 85a9480,
which this branch does not have.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Port xcl-dev#1818's constant-CFG terminator and path-fact folding onto Direct DXIL
and fix the stale shader-flag validation gap that blocked it:
1. Resolve CSE and trivial-PHI replacements before CFG folding, propagate
   dominating branch/switch path facts (bounded to 16 RPO passes so large
   shaders stay linear), fold constant CondBr/Switch terminators, drop newly
   unreachable blocks and obsolete PHI edges (preserving loop backedges), and
   rerun trivial-PHI simplification (opt-out via XCL_DXIL_NO_OPT=cfg).
2. Reconcile Int64Ops, Doubles, DoubleExtensions (including f64 FMA),
   ResourceHeapIndexing, SamplerHeapIndexing, AtomicInt64*, and
   TypedUavLoadAdditionalFormats in Shader::infer_type_features() against
   surviving reachable instructions after optimize(), preventing stale shader
   flags when dead branches are pruned.

Adds unit tests covering constant branches/switches, dominated branch facts,
reconvergence, loop PHI backedges, and pruned i64/heap shader flags.

Assisted-by: Antigravity (Gemini 4 Neon High)
(cherry picked from commit f4b0706)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cks, and IR opts

Large console compute shaders previously exceeded 1 MB of DXIL bitcode
(>136k instructions, 15k interned table constants, 84 switches) and stalled
or OOM-spiked amdxc64 during pipeline creation on AMD RDNA4.

- Bitcode encoding (bitstream.rs, module.rs, bitreader_tests.rs): emit
  LLVM DEFINE_ABBREV records for hot instruction/constant opcodes, emit
  compact lookup tables via CST_CODE_DATA (ConstDef::DataI32), and prune
  dead constants in write_bitcode (~6.88 -> 4.31 B/inst).
- Compact form (compact.rs, lower.rs, kernel.rs): isolate repeated heavy
  memory ops (ENC_MUBUF/MTBUF/SMEM/MIMG/FLAT) into standalone micro-blocks,
  run backward SGPR+SCC liveness to strip dead far-jump veneers and dead
  SCC/SGPR slot stores, strip pure no-ops and bypass empty non-header jump
  blocks while preserving fallthroughs, add TargetPool successor encoding,
  and support single-literal / S_GETPC_B64 parameterization on large shaders.
- IR optimization (opt.rs, lanes.rs, prelude.rs, lower_valu.rs, pso.rs):
  multi-iteration fixed-point optimize() with intra-block scalar alloca
  store->load forwarding + DSE, entry hoisting of repeated ReadNone system
  intrinsics (keeping createHandleFromHeap unshared and annotateHandle /
  getDimensions block-local for AMD RDNA4 amdxc64 stability), dominator
  branch-fact propagation, adjacent redundant barrier elimination, chained
  select collapse, constant EXEC lanebit folding, single-instruction f32
  IEEE-754 fcmp predicates, XCL_RDNA_FLOAT native op::FRC + mul/fma_legacy
  constant fast-paths, and XCL_HEAP_WINDOWS default ON.

Verified: 201/201 gpu::dxil + gpu_bvh unit/validator/GPU tests pass with 0
dxcompiler 1.8.2502.11 errors; 95cc13288a27a96e shrinks from 1,238 KB
(1,036.8 KB w/ heap windows) -> 230.8 KB (236,320 B DXBC, 37.6s amdxc64
compile) and 958400d2caf07244 -> 139.4 KB (142,740 B DXBC, 9.86s compile).

Assisted-by: Antigravity (Gemini 4 Neon High)

(cherry picked from commit 46aecbf)

Port onto nvidia-dev:
- XCL_HEAP_WINDOWS stays opt-in (`=1`), as on this branch: the default
  flip is not part of the size work, and two NVIDIA setups failed with
  heap windows on.
- compact.rs: this branch's automatic_plan (which also takes split-wave
  atomic programs) counts the micro-blocks the same way `wanted` does
  upstream, against the new MAX_TABLE_WORDS.
- lanes.rs keeps the launch-EXEC shortcut (`live_exec`) before the new
  constant-mask folds; lower.rs keeps the code region's high word
  (`code_hi`, constant data after the program) for s_getpc_b64.
- opt.rs keeps the test-only XCL_SAMPLE_PHI_CSE arm.
- Left out: the test edits for 9c4a921 (split.rs) and 324193c
  (heap_window_tests.rs), commits this branch does not have.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
inst_sreg_scc_use_def now treats all S_CMOV* as conditional writes and
S_ADDK_I32/S_MULK_I32/S_BITSET* as read-modify-write on SDST, and clamps
Wave32 VALU 64-bit mask defs to 1 SGPR so live s[v+1] slots are not killed.

Assisted-by: Antigravity (Gemini 4 Neon)
(cherry picked from commit a523305)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…compile commit spikes

compact::large() previously only checked reachable non-terminator instruction count
(>= 20_000), ignoring both terminating branches and basic-block count. Branch-heavy
unrolled compute shaders just below 20k non-terminator instructions (for example,
cs 56c0cd3b82a00c6e) skipped compact lowering and emitted >2.6 MiB monolithic DXIL
(~588k IR lines, ~32k blocks, ~36k PHIs), causing the driver compiler to commit >36 GiB
of virtual memory and stall compilation. In compact form the same shader shrinks to
~160 KiB (~975 blocks, 108 PHIs).

Lower the non-terminator threshold to 10_000 and add a reachable basic-block threshold
(>= 2_000) in compact::large(); compact::wanted() still gates adoption on >70%
deduplication and bounded table size.

(cherry picked from commit 5399542)

Port onto nvidia-dev: `large` is asked by automatic_plan here (this
branch's form of `wanted`); its doc says so instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Snapshot of uncommitted work inherited from the previous agent session:
ps_masks, rt_leave_out, ambient, format_alias, gpu_awake, vram_small and
related d3d12x/dxil/recomp changes. Local safety commit, not for review.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
Work in progress from the 2026-11-27/28 sessions on an RX 9070 XT (one
retail title), saved as one commit. Not split into PRs, not rebased:
origin/main has moved on (31 commits, the shader preparation and
pipeline library work) and origin/nvidia-dev / origin/amd-dev differ.

What was wrong and what changed:
- The title makes every state transition through command list xcl-dev#146,
  Barrier(groups) (enhanced barriers). XCL answered it with a UAV
  barrier only, so no PC texture left the state it was made in and the
  world was dark. New hle/d3d12x/barrier_groups.rs turns the groups'
  texture barriers into legacy transitions through resource_barrier_x
  (depth twins and format aliases see them); `legal` drops what the PC
  would refuse (an illegal one fails Close with E_INVALIDARG and the
  title stops). XCL_BARRIER_GROUPS=0 off, XCL_BARRIER_LOG=1 logs kinds.
- Tiled lighting tests depth EQUAL against a class buffer (console
  D16S8, PC R24G8) that only compute writes through a UAV. Depth UAV
  twins are on by default (depth_uav DEFAULT_ON), and the stencil
  plane's twin is now copied to and from the plane through a buffer
  (StencilCopy, list_x::stencil_copies_on).
- ambient.rs: the stand-in no longer keeps the title's own probe
  resolve while XCL_RT_LEAVE_OUT leaves out the programs that feed it
  (that kept garbage: a flat green wash and bright bands);
  XCL_AMBIENT_KEEP overrides. A frame-based estimate from
  CS_CacheScreenSpaceRadiance (64x36 cells, slow mean; credit in THIRD_PARTY.md) raises the fill:
  XCL_AMBIENT_FRAME (default 0.8, 0 off).
- sRGB textures with unordered access made typeless (opt-in,
  XCL_SRGB_UAV=1); XCL_DUMP_TARGETS also writes each depth twin as a
  picture of its raw bytes; XCL_RAM_MB=auto (ram_budget.rs),
  XCL_MEM_MAP=1 (mem_map.rs), lazy-level texture uploads.

Measured (guarded runs, 200 s, intro to the first world scenes): exit
0x0, no device removal, no crash, no TDR; the world is lit; 5-7
presents per 2 s in the world; peak commit about 21 GB.

Still wrong: round hard-edged patches where one lamp lights everything
inside a screen circle (made inside the class-0 tiled lighting
shaders; the class buffer itself is right), characters lit only inside
such patches, dark scenes, small dark triangles on diagonals. Most
likely cause: the title ray-traces lamp shadows and bounce light, and
CS_RaytracingResolve / CS_ScreenProbes_ActivateRays are left out here
(XCL_RT_LEAVE_OUT); with them allowed, world entry compiles push title
commit from about 10 to 21 GB and a 32 GB PC runs out (the shader
preparation work on origin/main targets this).

Tests: cargo test --release -p xcl --lib -- --test-threads=4 ambient
barrier_groups depth_uav format_alias: 42 passed, 0 failed. Whole suite
not run.

Written with Claude Code (Claude Mythos 5.2, then Claude Opus 5.5).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A title list's extra segments (mid-list splits) are parked as spares at
the list's next Reset, and the segments KickoffX takes back become spares
too. A spare records again only after its own later Reset, but alloc_pool
still counted it as a user of the PC allocator it last recorded on, so that
allocator was never free: each later Reset of the title's allocator while
those were "in use" put another PC allocator aside, and none was ever
reused or released. The previous recording a stand-in replaces at Reset
pinned its allocator the same way.

alloc_pool::park_list drops the list from its allocator's users (its
submit marks stay, so the allocator is reused only once the GPU is past
them). title_list::reset parks the moved segments and the replaced
recording; KickoffX parks its reclaimed segments after both submits.

Measured on the title (RTX 5070 Ti, Series X profile, 240 s untimed runs,
object counts from 100 to 240 s): PC allocators 1,137 -> 1,928 without,
728-753 -> 862-897 with; non-local video memory 6.2 -> 9.6 GB without,
5.0 -> 5.4-5.5 GB with (about 4 GB less at 240 s). Timed pairs showed no
frame-rate cost (late window 11.99 / 10.76 fps without, 10.76 / 11.76 with;
run-to-run spread ~10 %).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit bf42a6e)
…acements

A sampled texture the shared 64 KiB pages do not take (vram::place_pages refuses it; a 1D
texture cannot be a reserved resource) was a committed resource, which takes at least 64 KiB
of video memory. On the title the committed fallback held 8,361 x 64 KiB = 523 MiB
(XCL_COMMITTED_AUDIT), mostly ~5k Texture1D RGBA8_SRGB textures of 4 KiB or less.

With the switch, such a texture goes on a 4 KiB placement in a 4 MiB DEFAULT heap of XCL's own
(ALLOW_ONLY_NON_RT_DS_TEXTURES), made through the adopting CreatePlacedResource. Only when
the PC allows it: no RT/DS/UAV flags, one sample, and GetResourceAllocationInfo returning
4 KiB alignment for the description asking for it (most detailed level within 64 KiB).
Otherwise, and when no heap can take it, it is committed as before. Its units are free again
where late_release lets its last reference go (the queues are past the work before it); with
XCL_LATE_RELEASE=0 the switch does nothing (logged once), as uploads of XCL's into a texture
could still be in flight at the title's release. XCL asks no residency priority for the heaps,
as for a committed texture (logged per heap).

Measured on the title (RTX 5070 Ti, one 480 s run per arm, same base and env, with and
without the switch): 8,192 small textures live in 58 MiB of 15 heaps, against at least 512 MiB as committed
resources; local video memory over 250-310 s 18,332 vs 18,793 MB (-461 MB) with equal sparse
pools and target pages. Still 3.1 GB over the budget there, and the frame rate did not move.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 24fdb7b)
NVIDIA adaptation of CallMeBrado's xcl-dev#1916 at e2aa856. Keep storage-only homes CPU-backed until explicitly mapped, then replay preserved bytes even when ordinary storage write hints are disabled.

Based directly on nvidia-dev 54225f5, without the separate physical-page liveness, alias-identity or owner-sampler integration. Preserves NVIDIA's existing free/title mapping behavior. Prepared from integration abc027544; source-reviewed independently. Added fixtures are unrun, no native or build results claimed.

Assisted-by: Codex (GPT-6)
(cherry picked from commit 6330fba)
Correct PageSize=2 rounding while preserving explicit alignment, checked sizes, and recorded allocation/free accounting. Update the test title's alignment and zeroing-tail probes to the same 2 MiB contract, keeping the tail read inside its allocation.

Three focused tests passed on the earlier preserved patch; restoring the old 4 MiB grain failed all three controls. The new squashed head has not been run individually. Full-suite and retail merge checks remain pending.

Assisted-by: Codex (GPT-6)
(cherry picked from commit f00e1c4)
…roll

`ballot_px_quad` took its quad's four members in an `[unroll]` loop. It
is called in most translated pixel shaders, often hundreds of times, and
DXC unrolls every inlined copy: on a 395 KB one with 84 calls,
`-ftime-report` put 22 % of its pass time in "Dxil Loop Unroll" and 9 %
more in "Unroll loops" and LCSSA. The four members are now written out,
in the form thehollowedone gave in review.

On a retail pack, 282 pixel shaders compiled in-process on 8 threads
took 72.1 s instead of 125.1 s on Windows (Ryzen 7 5700X3D). 980 of them
through dxc.exe took 505 s instead of 854 s with DXC 1.9 and 575 s
instead of 961 s with DXC 1.8. Under Wine, XCL's own pass over the 980
took 59 s instead of 116 s with xcl-dev#688's private DXC heaps; without them
it was slower (428 s against 387 s).

Co-authored-by: thehollowedone <36892342+thehollowedone@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 2dad32e)
sparse.rs previously stored free pool tiles in a flat Vec and popped the
oldest cooled tile from cooling in FIFO order before checking free. When
tiles freed across multiple 64 MiB pools cooled, reuse_tile handed out
tiles from nearly-empty draining pools instead of packing fuller ones,
keeping sparse pools pinned so retire_free_pools could not reclaim them
and splitting UpdateTileMappings calls across more heaps.

Partition free sparse pool tiles by heap in FreePools. reuse_tile drains
cooled tiles into their heaps and takes from the fullest partially-used
heap (fewest free tiles in 1..POOL_TILES, lowest heap index on ties),
leaving nearly-empty and all-free heaps untouched for retirement unless
no partially-used heap has a free tile. retire_free_pools drains cooling
and checks heap counts in O(pools) instead of scanning all free tiles,
and before_execute_on passes free.has_empty_heap() to retire_due so an
all-free heap completed by take_tile's drain_cooling still retires even
when cooling is empty.

Measured on RTX 5080 (180 s Series S XCL_DEVICE_TYPE=lockhart A/B vs
nvidia-dev af2cecc): peak commit 22042 -> 21818 MB (-224 MB), steady
sparse pools 5440 -> 5376 MB (-64 MB), UpdateTileMappings calls 891 ->
736 (-17.4%) for 120k mapped tiles, 0 device removals, 0 crashes.
sparse::tests: 61 passed, 0 failed, 1 ignored.

Assisted-by: Antigravity (Gemini 4 Neon (High))
(cherry picked from commit 8cf249e)
…d textures drawn again

Work in progress on the visual defects of a retail title on an RX 9070 XT
(direct DXIL), not split into single changes yet:

- ambient: the resolve's light and depth are taken from their own slots; the
  estimate is made in space from the depth (cells placed, gathered at 160x90
  points, raised along a normal rebuilt from the depth), the air's light is
  held to the light around, magenta is rejected in the reflection clamps.
  Switches: XCL_AMBIENT_SPACE, XCL_AMBIENT_SPLIT, XCL_AMBIENT_MOST,
  XCL_AMBIENT_SKY. Credit in THIRD_PARTY.md.
- shadowed textures a draw's tables name are made active again (after open
  PR xcl-dev#2956): video frames no longer come up green.
- draws of bake pipelines (drawn once and kept) wait for their pipeline and
  make the shadowed textures they pick by index active again
  (XCL_KEPT_DRAWS, XCL_BAKE_SOURCES).
- diagnostics: XCL_TRACE_LATE, XCL_TRACE_SLOT.
- earlier fixes of this branch: vertex buffers kept out of the alias space,
  the PS export patch table for all pixel shaders, ambient levels.

Tested: cargo test -p xcl --lib -- ambient stage_name placements
title_textures pso_async bcpack rt_leave_out: 117 passed, 0 failed
(RX 9070 XT, release build runs of 300 s without device removal).
Not tested: the whole suite, scripts/smoke.ps1, other GPUs. Open: black
heads at a distance, dotted diagonals, 3-5 fps in the world.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
The existing row-factorized detiler still visited swizzled textures one element at a time and recalculated block placement for every element. Large CPU-written textures therefore consumed milliseconds on the submit path even after persistent detile workers.

Adapt raylitebull's 032c661 block-slab algorithm: cache the largest provably contiguous horizontal run for each immutable GFX10 layout, keep one 4 KiB/64 KiB block hot at a time, bulk-copy complete runs, and retain element-wise bounds checks for a truncated source. Low-bit base swizzles shorten runs safely; thick 3D single-slice helpers retain their former path.

On this AMD EPYC 7R13 Linux host, an isolated release benchmark against 032c661's parent reduced 1920x1080 R8 mode-5 detile from 8.8-10.3 ms to 0.76-0.87 ms and tile from 28-31 ms to 0.64-0.78 ms. A 2048x2048 RGBA8 mode-10 detile fell from 28-31 ms to 9.7-11.8 ms and tile from 59-67 ms to 5.8-6.9 ms.

All 17 isolated pure tiling tests passed. The Windows GNU library/test cross-check passed with the existing warnings; Windows MSVC, GPU, and smoke tests were unavailable.

Source algorithm: 032c661 by raylitebull, assisted by Antigravity (Gemini 4 Neon High).

Assisted-by: Codex (GPT-5.6-sol)
(cherry picked from commit 95f12a0)
Every mirrored vertex or index bind and draw searched the append-only mirror table behind one global mutex. Once a title created a mirror, repeated hot-path lookups serialized even though existing entries never change.

Keep a complete ordered mirror snapshot per thread and answer positive lookups locally. Misses still lock and refresh from the authoritative table, preserving first-match range selection and immediate discovery before creating a mirror; the no-mirror case rejects from the existing byte counter.

Assisted-by: Codex (GPT-5.6-sol)
(cherry picked from commit 66f0ea5)
…ault

Four alias tests rely on the first write through a view of a page
never used faulting into `lazy`, which commits the page and sets its
commit bit; the guards, reads by number and moves all key off that bit.

Under Wine 11.21 that write does not fault: it lands in the section,
`VirtualQuery` still reports the view as MEM_RESERVE, the lazy mark
stays, and the bit is never set. So the views are never guarded and a
read by number or a move sees zeros. The code is right on Windows,
where these tests pass; the building blocks (sections, guards, lazy)
pass under Wine too.

Probe the behaviour itself rather than sniffing for Wine, and skip with
the reason when it does not hold.
The slicer moved its commands to INDIRECT_ARGUMENT |
VERTEX_AND_CONSTANT_BUFFER. vkd3d-proton only counts a transition to
exactly INDIRECT_ARGUMENT as a write to indirect arguments; without one
it hoists an ExecuteIndirect's preprocessing to the start of its
command buffer, or of the whole submit. So the pieces' ExecuteIndirects
read the commands before the slicer wrote them: zeros, or the groups
and slab origins of an earlier split dispatch recorded with the same
storage, run with this program's pieces. On RADV that is a TCP page
fault and a gfx ring timeout where the world finishes loading, the
removal seen at about 170 s on main and on the guard branch alike.

The commands now go to INDIRECT_ARGUMENT alone (the root-constant
chain ABI needs no constant buffer state). The split-chain test now
also counts the groups the pieces run: 0 before this, 6, 0 and 2 now.

(cherry picked from commit 373e22e)
Assisted-by: Codex (gpt-6.2-sol)
Wine's D3DCompile cannot compile the guard's Load3 on a raw UAV. Cache the DXC shader before taking GUARD and fall back to D3DCompile if the device rejects DXIL. Keep the existing DRED label and the inline root-SRV path, which now gets checked counts under Wine.

Port the guard's DXC tests. Run a split chain against the guard's root SRV in the slicer test and assert that out-of-range counts produce zero groups and that the pieces run the valid groups.

(adapted from 9181dd3)

Assisted-by: Codex (gpt-6.2-sol)
vram's mapping queue raised its value and then signalled it, ignoring
the result. When that Signal failed, the value was one no Signal would
reach: every queue's next submit waited for it (before_execute) and a
retired texture's NULL unmap counted as done although nothing marked
it.

The value now moves only when the Signal was queued. A mapping or
unmapping whose Signal failed is marked, and gets a later Signal before
anything counts on it: before_execute queues one and has the title's
queue wait for it, and a retired texture stays out of the pool until
one completes. When none can be queued either, before_execute says so,
and the submission stops with that cause (MappingUnmarked) instead of
going out with mappings nothing covers.

Tests: a failed Signal leaves the value a Signal reached; with the
mapping queue held behind a test fence, a bind, a held unmap released
inside before_execute and a retired texture's unmap whose Signals fail
each get a later mark, and the work waits for it or does not go.

(cherry picked from commit 6970034)

On amd-dev, flush recycled zero-fill tiles before marking. A failed zero-fill Signal also leaves its ring slot unmarked. Keep the allocator and alias buffers in use until a later Signal covers the copy.

Assisted-by: Codex (gpt-6.2-sol)
amdgpu, the Linux kernel driver, runs a process's page-table updates in
order on one queue, and every unmap and every sparse rebind (REPLACE
frees the old range) waits for all command submissions of the VM
first. While a frame is in flight, a reserved texture made after its
submit has no page-table entries, not even the PRT ones, until that
frame is done. A console title may write a descriptor of a texture it
has just placed that work it already submitted reads; on the console
the memory is there, here the read is a GPU page fault (TCP,
PERMISSION_FAULTS 0x3) and the device is lost. RADV_DEBUG=bo_history
and the kernel log put the faulting virtual BO 32-38 ms after its
creation, by a new placement, with the hung IB older than the texture.

A texture from the pool has had its entries since before: its rebind
still lands late, but the work in flight reads a NULL tile meanwhile.
So:

- the pool also takes render targets, depth and UAV textures and those
  with a clear value, keyed by its meaningful bytes;
- every placement tops its description up to XCL_RESERVED_SPARES
  (default 2) spares made ahead, reserved under the pages lock and
  pooled only once a Signal of the mapping queue after them completes;
- a placement that still has to make a new texture waits up to
  XCL_PLACE_MAP_WAIT_MS (default 1000) for such a Signal, polling the
  fence; when no Signal can be queued for it, the placement fails as a
  failed creation does.

It is one change because the parts only work together: without the
wait a burst of new textures outruns the spares and faults; without
the spares every new placement waits a frame. It builds on the marks
for mappings whose Signal failed (the commit before): spares and new
placements count on a Signal reaching their mappings.

On by default only under Wine with an AMD GPU, judged by the Vulkan
physical device vkd3d-proton drives (DXVK's DXGI may report an NVIDIA
GPU as AMD), else by the DXGI adapter: Windows drivers do not order
page-table updates like this, and the extra creations and waits cost
time on the title's thread (the log says how much: the placements,
the spares made and the time spent making them, and the waits).
XCL_LIVE_RESERVED=1/0 forces it either way.

Tests: the gate and the vendor source, clear keys, the fence wait,
placements with the gate on and off, concurrent placements and their
spares, spares and a cold lazy placement whose Signal fails, and spares
kept out of dump tracking.

(cherry picked from commit ee13d5a)
vkd3d-proton keeps every command buffer an allocator needed in one
cycle (recycled up to 256 per pool, never freed by a Reset), and RADV
keeps each one's IB (80 KiB, growing to 640 KiB) and 16 KiB upload
buffer in host-visible VRAM. GTA VI records 40-110 lists on one
allocator in a world frame (4 while loading). alloc_pool's swaps
spread those frames over hundreds of PC allocators, and every one that
hosted a heavy frame kept its ~80 command buffers for good. That is
the world's growing "other" video memory.

Evidence (RADV uprobes via bpftrace plus amdgpu_gem_info):
- live VkCommandBuffers 3016 vs 80K+160K+320K+640K USWC BOs 2989,
  16 KiB upload BOs the same count; vkFreeCommandBuffers was never
  called.
- ~1000 new command buffers a minute in the world, 5.0k of 5.25k in
  title-namespace pools. Each pool sat at ~6, took one burst of ~80
  within 30 s while still being reset, and kept them.
- every heavy cycle (42-112 recordings between two driver Resets of
  one PC allocator) is title list Resets; 39 of the first 66 were on
  the title's own allocators, 27 on ones alloc_pool made.

So the title's own allocator now records only until its first Reset;
after that alloc_pool records on allocators it made. Up to
XCL_ALLOC_HEAVY_KEEP (16) allocators made here whose cycle reached
XCL_ALLOC_HEAVY (16) recordings stay alive as spares, and a swap in a
heavy namespace prefers one of them, so it does not grow a fresh
allocator to ~80 command buffers again. An idle heavy allocator above
that budget is released, and its command buffers go with it.

reset_list pins the backing across the unlocked native list Reset, so
a concurrent reclaim of the namespace can neither Reset nor release it
under the recording that starts. Bundle allocators are left alone:
vkd3d-proton keeps no command buffers for them. XCL_ALLOC_RETIRE=0
restores the old behaviour.
A GPU queue wait that outlasts the watchdog stops the title, and on
RADV the kernel's ring timeout and a full GPU reset follow, with no
page fault to point at the work. Only the device-removed path printed
the ring of recorded draws and dispatches, so these stops named no
pipeline. Print it here too, before the stop (and with
XCL_WAIT_TIMEOUT_CONTINUE=1).
The amd-dev merge only reached stable 600 s runs when level pages, small
textures, vram-small placements, zero-target-page fills and format aliasing
were all turned off. Keep the merge head on main's opt-in defaults for these
five switches so milestone-1 stability does not depend on per-user ENV edits.

The feature code stays in place and can be re-enabled per run with =1 while the
A/B and vendor coverage catches up.
The merge keeps XCL_ZERO_TARGET_PAGES off by default to match main, but
`a_recycled_page_is_zeroed_before_a_new_texture_uses_it` validates the
zero-fill path itself.

Add a test-only AtomicBool override for `zero_target_pages()` and use a
restore guard in that test so it can enable the path without depending on
process env or leaking state to other tests.
lucsoft added a commit to lucsoft/xcl that referenced this pull request Dec 1, 2026
lucsoft added a commit to lucsoft/xcl that referenced this pull request Dec 1, 2026
…main-v3

# Conflicts:
#	crates/xcl/src/gpu/dxil/kernel.rs
#	crates/xcl/src/gpu/recomp/ps_masks.rs
#	crates/xcl/src/hle/d3d12x/bind.rs
#	crates/xcl/src/hle/d3d12x/indirect_guard.rs
#	crates/xcl/src/hle/d3d12x/real.rs
#	crates/xcl/src/hle/d3d12x/real/dispatch_chain.rs
#	crates/xcl/src/hle/d3d12x/vram.rs
#	crates/xcl/src/hle/kernelx.rs
@github-actions github-actions Bot added needs-pr-check Failing the PR description check (CONTRIBUTING.md) and removed needs-rebase Has merge conflicts with its base branch labels Dec 2, 2026
@lucsoft
lucsoft marked this pull request as ready for review December 2, 2026 08:49
@github-actions github-actions Bot removed the needs-pr-check Failing the PR description check (CONTRIBUTING.md) label Dec 2, 2026
b6aebe7 keeps XCL_VRAM_SMALL off by default to match main, but
`gpu_small_textures_pack_at_4k_granularity_and_preserve_pixels` tests
the packing path itself: with the path off nothing goes to the small
pools and its first assertion fails (0 B of 2 MiB), as on the Windows
CI run of dd6cec7.

Read a test-only AtomicBool in test builds, as 1bb6108 does for
zero_target_pages, and switch it on in that test under VRAM_TEST_LOCK
with a restore guard.
@throny

throny commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Testing this on an RTX 4080 16 GB now (head 30ca950e, plus our local input-timing patch): three 900 s world runs with XCL_RESIDENCY_PRIORITY=1, then the full suite merged on main. One reason it matters to us: amd-dev shows the outside through the start room's window where main shows it black (#3587's amd-dev build: window area 78–88 % bright vs 0–11 % on main 1c8b5514, same save and inputs). Results here when done.

AI use: Claude Code (Claude Opus 5.5).

@github-actions github-actions Bot added gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) and removed gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) labels Dec 2, 2026
@capy-ai

capy-ai Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

The red PR description check on 30ca950e isn't caused by binary files. GitHub stops sending per-file patches once a PR's diff gets past its size limit. For this PR, the files API reports 25,434 changed lines out of the real 27,457, and the last 15 files (kernelx/sections.rs, hle/mod.rs, host.rs, lib.rs, loader.rs, main.rs, mem_map.rs, resolver.rs, shaders.rs, …) come back with changes: 0 and no patch. pr-check.yml writes that as binary=true, so scripts/pr_check.py flags them as "a binary file outside tests/data/". In git they're ordinary text diffs (for example lib.rs +8/−1 and host.rs +12/−0 against main 1c8b5514), and git diff --summary shows no mode changes.

So the check can't go green for a PR this size until the checker stops treating a missing patch as binary. Alternatively, split the PR below GitHub's diff limit. Since PR description is a required check in the main-required-checks ruleset, a maintainer will have to decide how to land it.

AI use: Capy (Claude Opus 5.5), posted on behalf of @macrophase-dev. The cause was checked with gh api repos/xcl-dev/xcl/pulls/3547/files and git diff. Nothing was built or run.

@throny

throny commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

Test report for #3547 at head 30ca950e7 (testing only, not a merge check).

Tested

  • RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0 release.
  • Trial merge into main 1c8b55147, cargo test --workspace -- --test-threads=4: 3118 passed, 0 failed, 51 ignored; 26 SKIPPED lines; no test binary ended abnormally.
  • Retail title, three 900 s world runs with XCL_RESIDENCY_PRIORITY=1, default two-pass reserve:
  • Picture: the start room window stays dark in 3 of 3 runs, the same as main. amd-dev + D3D12.X: XCL_VRAM_BUDGET keeps XCL's pools under the adapter's budget #3587 (2ddf82273) showed the outside there in 8 of 8 runs, and amd-dev without D3D12.X: XCL_VRAM_BUDGET keeps XCL's pools under the adapter's budget #3587 (41aa60ce8) in 2 of 2, so the difference comes from main's side of this merge. One of those two amd-dev runs lost the device at 138 s (GPU page fault on a texture read). I'm bisecting 41aa60ce8..30ca950e7 now and will add the commit here.

Not tested

  • AMD and wave32 GPUs.
  • Gameplay beyond the start room.

AI use

  • Claude Code with Claude Opus 5.5 ran the builds, runs and suite, and wrote this report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:directstorage DirectStorage queues, requests, decompression area:docs-ci Documentation, scripts, workflows, repo governance area:hle kernelx, XGameRuntime, XAudio2, VFS, PE loader, TLS, EH area:memory Virtual/physical memory, arenas, VRAM budget, UMA area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:shaders Shader cache, PSO compilation, pipeline libraries, precompilation area:tests Unit, integration, e2e tests, or testtitle gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks)

Projects

None yet

Development

Successfully merging this pull request may close these issues.