A lazy pipeline is built at its first use: until then a graphics one
draws nothing and a compute one is waited for on the title's thread. A
retail title's first frames of its world use hundreds of pipelines for
the first time at once.
The pipelines a title uses are now kept by a hash of their shaders
(used-pipelines.txt beside the DXIL cache), and a lazy pipeline of
shaders an earlier run used is sent to workers of its own when it is
made: two to four threads at the lowest priority, apart from the ones a
bind sends to, so a pipeline that is bound is not held up by the ones
made ahead. XCL_PSO_PRELOAD=0 turns it off. Pipelines no run used stay
lazy, as before (the memory of ~51 000 built pipelines was the reason
for making them lazy).
Measured on an RTX 5090 with a build that skips a dispatch instead of
waiting for its pipeline: ~2 170 dispatches skipped in the title's first
world frames without this, 94 - 150 with it.
Assisted-by: Claude Code (Claude Fable 5.2)
#636 keeps the driver's blob of a translated compute program in memory:
its second build in one run is made from it. The first build of every
run still goes through the driver's compiler. On an NVIDIA GPU (RTX
5090) that is 5 - 27 s for each of a retail title's larger compute
programs when its world loads: the title dispatches without them
meanwhile and is ended by its watchdog before all are built, so the
next run starts the same compiles again.
A blob whose build took 250 ms or longer is also written to the DXIL
cache directory (driver\, under the hash of the DXIL and the flags),
and a build that finds none in memory reads it from there. A blob the
driver refuses (another driver, adapter or root signature) is dropped
and the program compiled as before. XCL_PSO_DISK_CACHE=0 turns it off.
Assisted-by: Claude Code (Claude Fable 5.2)
A retail title creates some of its big compute pipelines more than once while loading (14 programs
of 105 - 222 KB DXIL, each twice). Every creation went through the driver's compiler again: 3 - 6 s
the first time, 13 - 30 s the second, with the title's thread waiting. After a translated compute
PSO of 16 KB of DXIL or more is built, its GetCachedBlob is kept (by DXIL hash, root signature and
flags; 512 MB at most) and passed as CachedPSO when the same program is built again. A blob the
driver does not take is dropped and the program is compiled as before. The PSO log line now says
how long the build took and whether a blob was used.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Before each upload of a title texture, and before hashing it to see whether
it changed, its memory was copied into a new zeroed buffer of its size
(read_committed). The copy, a fresh allocation and its page faults every
time, cost as much as the detile itself: GTA VI's intro video re-uploads
its 3840x2160 and 1920x1080 R8 planes several times a frame.
title_bytes now hands out the title's memory where it is when the whole
range is readable (gpu::shader::readable), and the page-by-page copy as
before when it is not. The 2D slices, 3D textures and the unchanged-content
hash take it.
Measured on an RX 5700 XT / Ryzen 5 2600 during the video (release, a
local counter around the upload batches, with a row-at-a-time detile like
the one #451 merged): reading and detiling 0.9 -> 0.4 s of every 2 s,
36 -> 54 presents per 2 s.
Assisted-by: Claude Code (Claude Opus 5.5)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Use the maintainer label event for the checked PR snapshot and verify it against live metadata. Keep the regular smoke requirement for later revisions and preserve the description and asset checks.
With the limit on waits for a background pipeline, ExecuteIndirect could reach the PC call with the pipeline's stand-in while the list held XCL's ABI root signature from a translated draw: debug layer 953 (root signature does not match the pipeline state), six times as a retail title's world started, and then the device hung (0x887a0006). Such a call is skipped like a draw or dispatch of that pipeline; a PC pipeline gets the title's root signature first, as graphics_bound does. With it the same run shows no 953 and no device removal.
Assisted-by: Claude Code (Claude Fable 5.2)
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
sparse::init installed its state with *STATE.lock() = Some(s): the
state it replaced was dropped while the guard was held. Once used, that
state holds the last references to buffers of its own (readback,
staging, zeros), all made through the adopted device; their release goes
through real::res_release, which calls sparse::forget_buffer, which
locks STATE again - the thread waited for itself, and every later user
of the sparse windows behind it. The windows are set up again when two
first real::init calls overlap, as GPU tests starting together do: a
suite run hung in four GPU tests until it was killed.
The old state is now taken out under the lock and dropped after it.
Fixes#344
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Sample successfully presented frames over at least one second using the existing window timer. Keep FPS visible alongside shader compilation progress and report zero when presentation stops. Cover irregular sampling, sample intervals, stalls and recovery with unit tests.
The write watch is per page, and a title writes next to its textures and rewrites what it wrote: every texture with a written page was detiled and uploaded again before each submit. With a retail title's intro video that was about 25 MB a presented frame where about 3 MB had changed, and the title's submits spent their time in the refresh. The texture's memory is hashed first (four multiply-rotate lanes over 8-byte words, ~4.5 GB/s measured); the same hash as at the last upload of that texture object leaves it out. A texture that is released, or whose address is registered again, starts over. XCL_TEXTURE_SKIP_UNCHANGED=0 turns it off.
Assisted-by: Claude Code (Claude Fable 5.2)
read_committed previously called VirtualQuery followed by std::ptr::copy_nonoverlapping. When a title streaming thread concurrently decommits or unmaps a page in a GPU-viewed CPU memory pool between VirtualQuery and memcpy, the submit thread hits an unhandled 0xC0000005 read access violation (observed at ~462 s / 7500 frames on a retail title).
Copy committed regions via ReadProcessMemory(GetCurrentProcess(), ...) instead. Because Windows can return 0 with bytes_read == 0 when a later page in the span faults, binary-split failed multi-page spans at 4 KiB boundaries so still-committed pages are copied intact in O(log N) calls and only unreadable pages stay zeroed. Also guard against at + len overflow and zero-sized VirtualQuery regions.
Assisted-by: Antigravity (Gemini 4 Neon)
Chain::detile_level computed the address of every element and copied it
on its own. A linear level (mode 0) keeps each row's elements contiguous,
so its rows are now copied whole; which elements are copied when the
source is cut short is unchanged. Swizzled modes, a base swizzle and
levels in a mip tail keep the per-row form of the previous commit.
A retail title's intro video is three linear R8 planes per frame
(3840x2160 and two 1920x1080), uploaded on every frame through the
kept-in-step title textures: release, one plane 56.9 ms -> 1.2 ms and
14.4 ms -> 0.3 ms, about 85 ms -> 2 ms a frame. The video played at
3.5 fps on an RX 9060 XT with the element-by-element form.
Test: linear levels give the same bytes by rows as by elements, for
every element size, padded rows, every mip and a cut-short source.
From #440 (be722a7), placed in front of the per-row loop of this PR.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every placement of a texture on the title's pages of video memory
(Pages::bind) looked at every page of both maps for the ones idle for 2 s.
A retail game streaming its world places textures by the ten thousand over
more than 100 000 pages: on an i7-7700K, by its 36 864th placement (213 s
into the run, 113 460 + 17 088 pages) the sweeps had looked at
2 922 636 089 page entries and taken 14.5 s of the title's thread that
creates its resources - with PAGES held, which the title's queues wait for
before their work (before_execute).
The pages whose last user went are queued with that moment, oldest first,
and a sweep takes the ones idle for IDLE from the front (sweep_idle); an
entry whose page was used again since is dropped. The same run with it:
3 ms in the sweeps by the 36 864th placement, 38 067 queue entries looked
at. Which pages go back, and when, is unchanged.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
`title_textures::upload_all` read and detiled each texture of a batch
one after another, inside the title's own submit and present. Batches of
1 MB or more are now detiled on up to 8 threads (half the cores), each
taking the next texture; the results keep the batch's order. Smaller
batches stay on the calling thread.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`Chain::detile_level` called `element_at` / `Layout::offset_z` for every
element: a `div_ceil`, several divisions and modulos and six table
lookups each. Once the upload buffers were reused, it was most of a
retail title's render thread while the title streamed textures the CPU
writes (thread samples, frames named from a symbol build).
The parts of the offset that depend on x alone (block column and the
x and high-x pattern bits) are now computed once per level, those that
depend on y and the slice once per row, leaving two lookups and an XOR
per element. The result is the same: a new test compares it with
`element_at` for every mode, element size, pipe configuration and level
(mip tails too), with a base swizzle, two slices and a source cut short.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`gpu::texture::upload_batch` made a new upload buffer for every texture
and a new command allocator, command list and fence for every batch,
and released them all again. Each of these D3D12 calls waits for the
video memory manager. While a retail title streamed textures the CPU
writes, they took 200 - 650 ms apiece (timed in the title's runs), and
its frames fell to 1 - 3 a second.
Each upload queue now keeps an `Uploader`: one persistently mapped
upload buffer that the batch's textures share (each at a 512-byte
aligned offset; it grows only when a batch needs more room), an
allocator and list that are reset, and a fence whose value counts up.
When the wait for a batch times out, the uploader is retired and kept
alive instead of released: the GPU may still read the buffer and run
the list, and releasing them under it removed the device.
`record_upload_states` is split into `layout` and `record_into`; it
keeps its behaviour (a buffer of its own) for its other callers.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Layout::from_bits built the tables for the coordinates above a block (hx, hy,
hz) over the whole 16-bit range. For a 2D surface the z table alone is
65536 u32 entries – 256 KiB – and every xg::Texture builds its own Layout,
so each live tiled title texture carried about 256 KiB of CPU memory.
The entries depend only on the coordinate bits the block's pattern masks use.
Each table now covers the power of two above the highest such bit (one
entry when no bit is used); offset_z already indexes the tables modulo their
length, so every offset is unchanged.
The test compares every 2D and thick 3D mode, element size and pipe
configuration against the full-range tables, for coordinates up to and past
16 bits, and fails before the change (a 2D z table of 65536 entries).
GitHub's runner adapter reports tiled resources tier 2 but refuses a reserved 256x256x6
cube with 9 mips, and further steps of placed_title_textures_share_vram_and_preserve_pixels
(PR #288) then expected shared pages it never got. The test now probes that one resource
and is SKIPPED, like the other GPU tests the runner cannot run; on a GPU it runs whole.
gpu::shader::readable checked title pointers with VirtualQuery, which sizes the whole region
around the address by walking it, so its cost follows the region, not the range. In a retail
game's world load the page arrays of its DirectStorage requests (8-32 bytes, checked at
enqueue and again at execute) live in a 2 GB block of committed memory: each check took
20-25 ms. readable now asks K32QueryWorkingSetEx about up to 16 pages first, in one call; only
a page not valid in the working set falls back to the walk.
The gpu line took the first Win32_VideoController that is not the basic
display adapter. On a machine with an iGPU and a discrete GPU that is often
the iGPU: on an RTX 3080 + AMD RDNA2 iGPU machine the block said
"AMD Radeon(TM) Graphics" while XCL ran on the RTX 3080.
The line now comes from d3d12.adapter in the run's report.json (next to the
log; XCL removes the previous run's report at start), without the VRAM
suffix. The Win32 query stays as the fallback when the report or the field
is missing.
(cherry picked from commit c756051df6)
placed_title_textures_share_vram_and_preserve_pixels (PR #288) asserted every shape went to
shared video-memory pages. GitHub's runner adapter refuses the 256x256x6 cube with 9 mips as a
reserved resource (arrays with packed mips are a lower tiled tier's limit); the texture is
then committed, which is correct - the test failed and its panic poisoned the lock two other
tests share. Arrays and cubes now note the fallback; their pixels are checked either way.
Exercise the merged GPU-view mirror path end to end on a synthetic R8 texture. Force watched Windows reservations outside the UMA windows, verify CPU rewrites reach the GPU, then verify a later lazy physical mapping overrides the mirror and unmapping restores it. Keep the GPU-view title address throughout and clean up reservations, physical pages and texture registration on failure. No retail data or runtime changes.
A retail game is mute under XCL: it does not use XAudio2 but sends its sound to the
console's audio decoder (xapu), and XCL answered every xapu command with silence. Everything
goes to stream 0 through XApuEnqueueCommand: Activate (kind 1) with the channel count and
48 kHz, Process (kind 3) with one raw Opus packet (CELT fullband 20 ms) and a float output
buffer, Deactivate (kind 2). The title reads the decoded PCM back, mixes it and plays its
mix itself through Windows Spatial Audio, so XCL only decodes into its buffer.
- hle/acphal.rs: the first Activate of a stream makes its decoder, a later one with the same
layout resets it; Process decodes into the title's output and returns the frames written;
a packet that does not decode, or a stream not connected, still gets silence. report.json
gets xapu counters, the log a summary every 5 s; XCL_TRACE_APU=1 traces the commands.
- hle/opus.rs: when Media Foundation has no Opus decoder (Wine), libopus is loaded at run
time from %XCL_OPUS_DIR% or next to xcl.exe (not distributed; THIRD_PARTY.md); Windows
keeps its own decoder.
Write64BitValueBottomOfPipeX and Write64BitValueTopOfPipeX with timestamp flags previously rejected any target address outside unified memory (for example, a title's own VirtualAlloc memory on a first run before the coherent window grows), even though non-timestamp writes already fall back to cpu_writes after the queue fence completes.
Resolve non-UMA timestamp queries into a lazily allocated, persistently mapped READBACK buffer per device (4096 slots, 32 KiB) and copy the 64-bit GPU tick atomically to the title's address in the cpu_writes worker once the submission's fence completes. Also separate the 8-byte alignment check from the unified-memory check so warnings report the actual reason.
Assisted-by: Antigravity (Gemini 4 Neon)