Repository navigation
D3D12.X: pipeline library blob has a readable dword after its end - #2859
bobosneefdev wants to merge 259 commits into
Conversation
…s mapped at Without it XCL keeps a physical page at one address at a time and copies it when the title maps it elsewhere; the console shows the page at every address it is mapped at. A retail title maps its streamed pages into a pool, into the CPU view of a 24 GB reservation and into that reservation's GPU view (xcl-dev#1031). With `XCL_PAGE_ALIAS=1` (`kernelx::alias`): - a block of physical pages is a section (`kernelx::sections`) with a view of its own, through which XCL reads and writes pages by number (DirectStorage); the title never maps a page there; - the title's reservations of 64 KiB pages with no commit (its CPU view, GPU view and pool) are placeholders, and a page mapped there is a view of its slice, guarded (`kernelx::guards`) so that a write through one view is uploaded at all of them; `title_textures` adds those pages to what the write watch found; - a page mapped anywhere else (a placeholder region the title made in a sparse window) is moved there and back with its bytes, as before. Pages are committed on first use as before (`kernelx::lazy`); whether a page is committed is a bit per page: asking Windows walked the rest of a fresh block, and a title mapping 100 000 new pages one at a time took 20 s longer to its first frame. Measured in a traced run of a retail title: 3 blocks (11 360, 2 960 and 99 776 pages), 131 072 map calls in 150 s, nearly all single pages into its plain reservations, none at a page's home, no commit inside them.
…GPU-view page shows Queue method xcl-dev#31 (xcl-dev#29 of the older layout) maps pages of the title's memory into GPU views; it was a stub. Its batches are now decoded and checked against the batch count and the pool, and each 64 KiB page of a GPU view records the pool page it was given and the physical page the title had mapped there (kernelx::mirrors). A bad call records nothing; releasing a view drops its pages. XCL keeps a physical page's data where it was mapped last, and the title maps most streamed pages into the CPU view behind the GPU view too, so `mapped_source` answers where that page is now (`page_now`), else the pool page itself. Each title mapping is remembered per address (Away::title), written once the page is in place and forgotten when the reservation goes; a page freed while its allocation lives is no longer looked for (Away::freed). Nothing reads the record yet: textures are unchanged; the queue logs its counts. (xcl-dev#1031) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`mirrors::decode_batches` checks and decodes one call of the queue's CopyPageMappingsBatchX into (GPU-view page, pool page or unmapped) pairs; `apply_batches` records them as before. No change in behaviour: the next commit maps the decoded pages for real when physical pages alias.
The queue's CopyPageMappingsBatchX maps pool pages into GPU views; on the console a GPU-view page then shows the physical page mapped at its pool page at the time of the call. xcl-dev#1055 decodes the calls and keeps a record of them; with physical pages aliasing (`kernelx::alias`) the GPU view is a reservation of views, so the decoded mappings are made for real: each GPU-view page becomes a view of the physical page mapped at its pool page now, or is unmapped (kind 2, or nothing mapped at the pool page). Textures in the GPU view then read the page at their own address (`title_textures` prefers an address with a physical page mapped), and a write through any view of the page is uploaded at all of them. Without the switch nothing changes: the call is recorded as in xcl-dev#1055.
Each chained dispatch made a scratch buffer for all its groups and kept it until the allocator's reset. A retail title's 176 split programs need 187 KB a group (median), 3 GB for 960x540 pixels in groups of 8x4. At most XCL_SPLIT_SCRATCH_MB (256) of groups now run at once, each piece adding the slab's origin to the group ids, and the chains recorded on one list share the buffer.
In a pixel shader EXEC holds helper lanes (s_wqm), and on a primitive's edge the first lane of EXEC is often one. v_readfirstlane read that lane. An RDNA2 driver (RX 6700 XT, 32.0.21045) gives 0 for everything a helper lane holds once a WaveReadLaneAt ran inside a loop, quad reads included. A loop whose state the console's compiler carries in a vector register (v_mov v, s ... v_readfirstlane s, v) then read 0 back on each pass and ran to the loop budget: a retail title's volumetric light pass took seconds per draw at its world start and Windows reset the GPU (xcl-dev#675). v_readfirstlane now reads the first lane of EXEC that is live (ballot(true), per half in the wave32-in-64 form) when EXEC has one, and the first lane of EXEC as before when it has none. The value is the same: the console's compiler reads the first lane of a value equal in every lane, or of a lane it then removes from EXEC (a waterfall loop). The new GPU test draws that title's list-loop shape on two triangles sharing a diagonal. Without the change, on the RX 6700 XT, 69 of 1024 pixels run the loop 65 536 times (the budget) with wrong results; with it, none, and at most 16 passes. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…esent in flight)
A retail game unmaps addresses while it streams its world with
XMemMapPhysicalPagesScatter(addresses, n, NULL); it checks the result
and runs into its own int3 when the call fails (+0xb18de7, then its
crash reporter). XCL refused a NULL page array with
ERROR_INVALID_PARAMETER. Page 0 already means "unmap this address" in a
scatter, so no array is taken as page 0 for every address.
Test scatter_without_pages_unmaps: two pages mapped and written, unmapped
with no array (the call succeeds, the addresses are no longer committed),
mapped again they read what was written. It fails without the change
("refused").
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The driver builds about two pipelines at a time for one process, so the preparation before a title (xcl-dev#2555) stood for minutes on each stretch of large compute programs. The stages are still translated in the host; the compute pipelines are built by worker processes of the same program, each on its own slice of the records: the processors less two, 16 at most, 3 GB of the commit left for each (XCL_PREPARE_WORKERS; 1: as before). With a list of the pipelines an earlier run used, only those are built before the title starts. A worker that fails is logged and the title starts; a worker ends when the host does. A worker reports every record while a title waits on it, and the host logs its progress every 5 s. Measured on a retail title, RTX 5090, 32 threads: the first 92 % of the steps in 85 s (one process: 84 % of one pass after several minutes). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… record The two passes were added up (twice the records), and a worker's count moved every 200 records, so the screen stood on one number for many minutes. The workers' pass has its own heading and count, a worker reports every record, and the line under the bar says a large pipeline is compiling. Workers: the logical processors less four. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A run keeps the shaders of the pipelines it uses, each by its own key (used-shaders.txt beside the DXIL cache). With that list the preparation before a title translates only those records; the title translates another when it first uses it. XCL_PREPARE_ALL=1: every record, as without the list. XCL_PREPARE=0: no preparation, the title builds what it uses as it goes. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Records with the same program are in several workers' slices. Each worker found no driver blob and built the pipeline: the driver's compile of one took about twice as long in each of four workers that built it at once, and a worker that had waited for its turn built what another had written to the cache meanwhile. A worker claims a pipeline with a file beside the blob it will write (<blob>.claim) and removes it when the build ends; a worker that finds the claim leaves the pipeline, and the cache is read again after the wait. A claim left by a process that died is taken over after 30 minutes. The count of pipelines left to another process is printed with the others. Reported by a tester who logged what each worker compiled. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The shader preparation before a title starts builds the compute pipelines earlier runs used, but no graphics pipeline: what is kept between runs is not enough to make one again. used-pipelines.txt holds only the key of a pipeline's shader set, and the driver cache holds blobs named after the translated DXIL and the description's hash. A retail title then builds ~6 000 graphics pipelines in its first minutes, with thousands of stand-ins that draw nothing meanwhile. A lazy graphics pipeline's description is now written down at its first use in a run (pso_async::on_first_use, told once, as used::note is): every field of the description but its pointers, its input layout, and the keys of its console shaders, ~200 bytes, under the key used-pipelines.txt has. The entry is made when the pipeline is (no shader copy is kept for it after its build) and written by a thread of its own, each description once, to used-graphics-pipelines.bin beside the DXIL cache (gfx_records: the format is in the module's comment). The file is versioned (another version reads as none and is started again), an entry cut short or damaged ends it, and it stops at XCL_GFX_RECORDS_MB (64) with a line in the log. No shader code is kept: the preparation finds the shaders in the title's shader files by key, as it does for used-shaders.txt. Mesh pipeline streams are not recorded. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
After the compute pass, the shader preparation now reads the graphics pipeline records of earlier runs (used-graphics-pipelines.bin), finds their console shaders in the title's shader files by key, and builds each pipeline in worker processes, the way the title's background build makes it (real::prepare_graphics calls translated_graphics_pso, as build_graphics does): the translation, DXC and driver blob caches on disk then hold exactly what the title asks for, and the title makes these pipelines from the kept blob in milliseconds instead of compiling them while it draws stand-ins. Worker processes, as for the compute pipelines: the driver builds about two pipelines at a time for one process, and a driver that ends a worker ends no title. Nothing of the title's device is needed: a translated pipeline gets XCL's root signature, and what else its build reads of the process is the title's memory windows (given with --windows, no memory reserved: uma::leave_out, pso::set_title_windows) and the adapter (XCL_ADAPTER from the title's setting). Each worker gets a file of its part with the shaders it needs (gfx_records' format) in the temporary folder, removed after. The title did not keep the blob of most graphics pipelines: none of under 16 KB of DXIL and none built in under 250 ms (XCL_PSO_DISK_CACHE_MIN_MS), so most were compiled again in every run. A preparation worker keeps every blob, on disk only. The blob's file name is made of the description's state, the DXIL, the adapter and driver and the window count, no address, so the title's lookup finds the worker's file. The screen shows "Building graphics pipelines" with its own count, the 5 s line counts graphics pipelines, a failure is logged and skipped and the title starts regardless. XCL_PREPARE=0 skips it with the rest, XCL_PREPARE_GRAPHICS=0 skips this pass only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…fter prebuilder merge
Ray tracing programs held back (XCL_RT_GATE=hold, the default) left a retail title's world dark: its lighting passes never ran. With XCL_RT_GATE=miss they run, and every BVH intersection reports a miss (dxil::kernel::rt_all_miss), so lighting, reflections and shadows take their no-hit path. Their traversal loops get a budget (RT_LOOP_BUDGET) so a loop the misses would not end stops. The title's BVH builder (DispatchX with USE_THREAD_DIMENSIONS from XboxBvhBuilder.dll) is left out unless XCL_BVH_BUILDER=1: while its 52 pipelines are built one by one, some passes ran and others did not, and the half-built structures in the title's memory crashed or hung the world load 2-100 s after the first pass in nine runs of nine. Without it the structures stay unbuilt and rays miss anyway. Measured on an AMD RX 9070 (16 GB): the world is lit with XCL_RT_GATE=miss, where it was dark with the default.
…load Fixes, each run in a retail title's world on an AMD RX 9070 (16 GB): - list_x: a wait an earlier signal of the same cell or fence already satisfies is not part of a cycle (nvidia-dev 4cdb71f, f98a1d6). Every pipelined frame (wait N armed, signal N+1 next) counted as one: 16 false cycle breaks a run before, none after. - dispatch_chain: whole_in_cooldown takes CHAINS with try_lock, and a replaced chain is dropped after the lock: title threads blocked there. - bind: prelude job tables live in pooled 1 MiB persistently mapped blocks (64 kept) instead of a committed buffer per use: ~1 250 CreateCommittedResource a second during the world load before. XCL_TWO_PASS_LIST_MB sizes a list's two-pass record buffer (32 MiB, as before). - title_textures: a submit whose lists were all closed before the last write-watch look began, in the same frame, takes no look of its own (XCL_LOOK_SKIP=0: off). A quarter of the world's submits skip it. - sparse, vram: a submit waits on the CPU (XCL_SPARSE_CPU_WAIT_MS, 1 s) for the tile mappings its queue needs, then on the GPU only if they are late; placements no longer signal the sparse queue one by one. - pso_async: workers are throttled by the system's free commit, not its free RAM: the world load dropped free RAM to 1.3 GB with 12 GB of commit free, every worker idled and a bind waited 14 s for a compute pipeline. - real: pipelines waiting to be built (pso_async::lazy) share their copies of console shaders (same address, same bytes): ~80 000 of them in the first minute held 318 MB of copies after this. Diagnostics (XCL_ACTIVITY): - prof: a "profile (2 s)" line, where the title's threads waited in XCL: pipeline waits, submits (write-watch, sparse copies, texture uploads, list segments, driver), placements, frame events, presents. - flight: every queue XCL signals, with a stall warning after 1 s and, at a device removal or crash, the queues (the first stopped first) and the last 400 events; tile mappings and creations a line. After 3 s without GPU progress its thread reports the GPU culprit (XCL_GPU_CULPRIT=1) and after 8 s dumps the threads (XCL_STALL_DUMP=1): in the activity thread they never came, its DXGI query blocked in the hung driver. - memory_report (xcl-dev#2697): "memory by owner" against DXGI's budget, the title's committed resources alive by kind, and every 10 s the address space walked. - eh: thread dumps go 40 frames deep. Not fixed: the device is still removed 60-110 s into the world. The culprit report named an indirect compute dispatch in one run; in the others no dispatch was in flight and every queue waited.
|
Same card, different driver. On an RX 6800 with driver 32.0.21045.5002 (yours is 32.0.21045.29003), a pipeline library that ends 2 bytes before a page boundary does not crash without the fix. Both builds open it as a file mapping and use it. This fills in one line of Not tested ("Other AMD driver versions"): the read past the end, or the fault from it, seems to depend on the driver version. The fix does no harm on this driver either. Repro (retail title, release builds,
So on this driver the 4-byte read past the view, if it happens at all, does not fault. One run per remainder: I did not try 4093, 4095 or 0 mod 4096. Small note on the log. With the fix, a file in the copy path still logs Diff review. I read the whole diff. The length check Tested
Not tested: the crash itself (it does not reproduce on this driver); the AI use: Claude Code (Claude Opus 5.5) read the diff, built the trees, made the padded library, ran the tests and game runs, and wrote this comment. Every number comes from those runs on the hardware above. Update for head |
AMD's driver reads a dword at blob + length in CreatePipelineLibrary (amdxc64.dll+0x176cd5, `cmp dword ptr [r14], eax` with r14 = the view's address + the file's length). MappedBlob hands it a file mapping, which ends with the file's last page: a file that ends less than 4 bytes before a page boundary has that dword in the unmapped page after it, and the process dies at startup with 0xc0000005 until the file is removed. Seen on an RX 6800 (driver 32.0.21045.29003) with two libraries, both of a length of 4094 mod 4096 (1933310 and 3252222 bytes); the faulting address was the first byte after the view in every one of 3 starts. Such a file (4 lengths in 4096) is now read into memory with 4 zero bytes after it instead of being mapped. With the fix the 1933310-byte library opens and serves pipelines. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
83b95c4 to
78795c7
Compare
|
Thanks for the run on 32.0.21045.5002 and for reading the diff. Good to know the fault depends on the driver version; I will add your result to the description. The log note is fixed in Written with Claude Code (Claude Fable 5.2). |
|
Ran the pipeline-library blob tests at Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, wave32 only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09), MSVC 14.44.35207, DXC 1.9.2609.5, debug build. All four tests pass, including Not tested: the AMD AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used. |
Port #2859. Keep a readable dword beyond the logical blob length for the driver. Assisted-by: Claude (exact model unknown), Codex (GPT-6 family, exact model unknown)
…triaged SKIP, probe past xcl-dev#2860)
|
The padded-copy branch at The tested replacement for the copy setup was: use std::io::Read;
use std::os::windows::io::FromRawHandle;
let mut file = std::fs::File::from_raw_handle(file);
let padded_len = len.checked_add(4)?;
let mut copy = Vec::new();
copy.try_reserve_exact(padded_len).ok()?;
copy.resize(padded_len, 0);
file.read_exact(&mut copy[..len]).ok()?;
if file.read(&mut [0]).ok()? != 0 {
return None;
}All 15 lengths per run preserved the logical size and last payload byte, exposed four zero bytes at the end, and kept the same mapped-vs-copied split. The odd lengths also keep the original handle through the read. This is a source-extracted Windows file/memory test using synthetic payloads, with no D3D12 driver or title run. OpenAI Codex assisted with verification. |
|
merge-check |
|
merge-check claim |
|
merge-check |
|
This PR's own change is only the top commit 78795c7 ( AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human. |
On AMD, XCL can crash at every start with
0xc0000005inamdxc64.dll+0x176cd5until the saved pipeline library is deleted. The driver reads a dword at blob + length inCreatePipelineLibrary(cmp dword ptr [r14], eax, withr14= the view's address + the file's length).MappedBlobhands it a file mapping, which ends with the file's last page, so a file that ends less than 4 bytes before a page boundary has that dword in the unmapped page after it.Seen with two libraries, 1933310 and 3252222 bytes, both 4094 mod 4096. In 3 of 3 crashing starts the faulting address was the first byte after the view. Such a file (4 lengths in 4096) is now read into memory with 4 zero bytes after it instead of being mapped.
This corrects my earlier reading in #2619, where I put the crash down to the memory-window layout.
What is in it
crates/xcl/src/hle/d3d12x/pso_library.rs:MappedBlob::openreads a file of such a length into memory with room after it; unit testmapped_blob_has_a_readable_dword_after_its_end(fails without the fix).Tested
cargo test --release -p xcl --lib pso_library: 4 passed, 0 failed. With the new branch disabled, the new test fails.cargo test --workspace -- --test-threads=4(debug) on this PR's head78795c74: 1642 passed, 12 failed, 27 ignored. On the unmodified base71b8e6e0: 1640 passed, 13 failed, 27 ignored. All 12 that fail here also fail on the base; none is inpso_library.rs.SKIPPED:gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu, 4 forms (f16 arithmetic and f16 packed, wave32 and wave64, per-lane form: refused as unsupported).c32c91a3plus local logging: the 1933310-byte library that crashed 3 starts opened, served over 1000 pipelines, and 7 newer generations were saved.Regression run
scripts/smoke.ps1 -Game <retail title> -Seconds 120, same title, same machine,XCL_PREPARE=0in the environment for both.main(e120925e):This PR's head (
78795c74):mainrun is one120925e, the commit before the tip. On the tip8b957becthe pre-launch shader preparation (xcl run: prepare shaders in the game window before title execution #2555) stopped at 23097 of 26503 records for over 26 minutes with four threads busy inamdxc64.dll, andmainhas no switch to leave it out, so no run of the tip finished.XCL_PREPARE=0leaves that preparation out on this PR's build;e120925epredates it and does not read the variable.Not tested
c32c91a3with local logging in the tree, not on this exact head.AI use
🤖 Generated with Claude Code