Skip to content

D3D12.X: pipeline library blob has a readable dword after its end - #2859

Open
bobosneefdev wants to merge 259 commits into
xcl-dev:amd-devfrom
bobosneefdev:pso-library-blob-end
Open

bobosneefdev wants to merge 259 commits into
xcl-dev:amd-devfrom
bobosneefdev:pso-library-blob-end

Conversation

@bobosneefdev

@bobosneefdev bobosneefdev commented Nov 26, 2026 •

Copy link
Copy Markdown

On AMD, XCL can crash at every start with 0xc0000005 in amdxc64.dll+0x176cd5 until the saved pipeline library is deleted. The driver reads a dword at blob + length in CreatePipelineLibrary (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, 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::open reads a file of such a length into memory with room after it; unit test mapped_blob_has_a_readable_dword_after_its_end (fails without the fix).

Tested

  • RX 6800 16 GB (driver 32.0.21045.29003), Ryzen 5 5600X3D, Windows 11 Pro 26200, Rust 1.98.1 MSVC.
  • 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 head 78795c74: 1642 passed, 12 failed, 27 ignored. On the unmodified base 71b8e6e0: 1640 passed, 13 failed, 27 ignored. All 12 that fail here also fail on the base; none is in pso_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).
  • Retail title, with the fix applied on c32c91a3 plus 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=0 in the environment for both.

main (e120925e):

xcl-smoke v1
commit: e120925e3abc9956a8b9bae631969d32e8ccd43c
gpu: AMD Radeon RX 6800
title: 9cc6a39e
seconds: 120
exit: 0x0
frames shown: 3284 (PresentX 3284)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 28469 MB

This PR's head (78795c74):

xcl-smoke v1
commit: 78795c7438b07e02651ff9ecefaaa5841a2935bd
gpu: AMD Radeon RX 6800
title: 9cc6a39e
seconds: 120
exit: 0x0
frames shown: 3232 (PresentX 3232)
presents per 2 s (last 3): 60 60 63
device removals: 0
crashes: 0
peak commit: 13359 MB
  • The main run is on e120925e, the commit before the tip. On the tip 8b957bec the 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 in amdxc64.dll, and main has no switch to leave it out, so no run of the tip finished.
  • XCL_PREPARE=0 leaves that preparation out on this PR's build; e120925e predates it and does not read the variable.

Not tested

  • NVIDIA and Intel. Whether their drivers read past the blob is unknown; the copy path is taken on any adapter.
  • Other AMD driver versions. A reviewer's RX 6800 on driver 32.0.21045.5002 does not crash with or without the fix (comment below), so the read depends on the driver version.
  • The regression run opened a 2.3 MiB library whose length is not near a page boundary, so it took the file-backed path (as its log says); it reached the title screen and does not cover the copy path. That path is covered by the unit test and the retail check above.
  • The retail check above ran on c32c91a3 with local logging in the tree, not on this exact head.

AI use

  • Claude Code with Claude Fable 5.2: found the cause, wrote the fix, the test and this description, and ran the tests.

🤖 Generated with Claude Code

ivall and others added 30 commits November 25, 2026 13:02
…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>
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>
theaustinayers and others added 9 commits November 26, 2026 18:31
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>
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.
@vibryxcx

vibryxcx commented Nov 26, 2026 •

Copy link
Copy Markdown

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, scripts/smoke.ps1 60 s; pso_library.rs is the same on c32c91a3 and on this PR's base 71b8e6e0)

  • I took the newest generation of my library (gen-0000005b.plib, 319,420 bytes, 4028 mod 4096) and saved a copy with 66 zero bytes added as gen-0000005c.plib: 319,486 bytes, 4094 mod 4096, the same remainder as your two crashing files.
  • I ran c32c91a3 without the fix and c32c91a3 with this PR's commit cherry-picked on top (no conflict), twice each and alternating, restoring the padded file before every run. On this head's own base 71b8e6e0 the title first recompiles all 26,503 shaders, about an hour here, so I used c32c91a3, whose shader cache was warm.
build run frames crash log
without the fix 1 1358 no opened memory-mapped pipeline library gen-0000005c (0.3 MiB file-backed), then 1000+ library hits
with the fix 1 1367 no same
without the fix 2 1382 no same
with the fix 2 1293 no same

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 opened memory-mapped pipeline library … file-backed, because that message is printed by the caller in pso_library.rs, which does not know which path MappedBlob::open took. A user reading a log to tell whether the workaround was used cannot tell from this line. It is a message only, with no behaviour change.

Diff review. I read the whole diff. The length check (4096 - len % 4096) % 4096 < 4 takes exactly the four remainders 4093, 4094, 4095 and 0, where the dword at blob + len would cross into the next page. view points into copy after the extend_from_slice, so it stays valid when the struct moves, and Drop skips UnmapViewOfFile for the copy path. I found no defect.

Tested

Not tested: the crash itself (it does not reproduce on this driver); the xcl-smoke pair on this exact head and its base (both need the full shader recompile first); NVIDIA / Intel; other remainders.

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 78795c74: the log line now reads read into memory: the file ends at a page boundary when the copy path is taken, which settles the note above. cargo test -p xcl --lib -- pso_library --test-threads=1 on this head, same RX 6800: 4 passed, 0 failed. I did not rerun the title, because the code path is unchanged apart from the message. Also, amd-dev bf7c82ee already has its own version of this change as 39440cd ("give mapped pipeline library blobs a readable tail").

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>
@bobosneefdev

Copy link
Copy Markdown
Author

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 78795c74 (amended, force-pushed): a library taken through the copy path now logs read into memory: the file ends at a page boundary in place of file-backed. Message only, no other change. cargo test --release -p xcl --lib pso_library on 78795c74: 4 passed, 0 failed. The full suite and the regression runs on the new head are running; I will update the description with them.

Written with Claude Code (Claude Fable 5.2).

@bobosneefdev
bobosneefdev marked this pull request as ready for review November 26, 2026 21:26
@Aniseto

Aniseto commented Nov 26, 2026

Copy link
Copy Markdown

Ran the pipeline-library blob tests at 78795c74 on an NVIDIA Blackwell desktop part:

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.

XCL_ADAPTER=NVIDIA cargo test -p xcl --lib pso_library -- --test-threads=1
4 passed; 0 failed; 0 ignored; 0 measured; 1677 filtered out      (exit 0)

All four tests pass, including mapped_blob_has_a_readable_dword_after_its_end. They are CPU-side file/mapping tests; no AMD driver is involved and no D3D12 pipeline library was created on this adapter. The thread's runs are on RX 6800 with two driver versions, where the crash is driver-specific; this adds a Windows MSVC run on an NVIDIA card, with no claim that the AMD fault path was exercised here.

Not tested: the AMD amdxc64.dll crash path, a paired smoke run, the full workspace suite, release profile, AMD and Intel GPUs, native wave64 hosts, Wine, game data.

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.

ivall added a commit that referenced this pull request Nov 26, 2026
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)
rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
@ettehn

ettehn commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

The padded-copy branch at 78795c74 has the same MappedBlob implementation as current amd-dev bf7c82ee (the port in 39440cd). On Windows 11 build 26200 / Rust 1.97.1 MSVC, I checked the private memory it retains while the blob is live. fs::read fills the vector, then appending four bytes doubles its capacity. For synthetic files of 64 MiB minus 0, 1, 2, or 3 bytes, opening the blob increased process private bytes by 128.26 MiB. Reserving exactly len+4 up front and reading from the already-open handle reduced that to 64.13 MiB. Three fresh processes per variant reproduced those values. The -4 file stayed mapped in both (~0.125 MiB private delta).

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.

@oni-swr

oni-swr commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

merge-check
base: 7c795f5 (amd-dev)
head: 78795c7
merge: clean, but empty: the merge tree is byte-identical to amd-dev (git diff of the merge against its first parent is empty)
build: cargo build --workspace -> ok (on the base, whose tree the merge equals)
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> on the base (= the merge tree): 1802 passed, 18 failed, 48 ignored, 4 tests printed SKIPPED; failing: 18 failures on the base itself, none touch pso_library.rs (e.g. gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1, the e2e test_title_* tests, list_x / title_textures tests); the merge tree is the base, so no separate run
review: read the whole diff (+39/-3, pso_library.rs). amd-dev already carries the same MappedBlob padded-copy branch (copy: Vec<u8>, PAGE - len % PAGE < 4, the read into memory log text) and the same test mapped_blob_has_a_readable_dword_after_its_end via 39440cd, so merging changes nothing. ettehn's finding on this PR's fs::read + extend_from_slice (capacity doubles, ~2x private memory for the copied file) is therefore already in amd-dev; a fix for it would be a new change on amd-dev, not this PR.
performance: none from this merge (no change to the tree). The existing 2x retention for the rare page-boundary files is as ettehn measured; not re-measured here.
verdict: not yet: nothing left to merge (tree equals amd-dev 7c795f5; 39440cd already carries the same MappedBlob padding and test)
hardware / tool and model: AMD Radeon RX 7800 XT (RDNA3), driver 32.0.31035.1003, Windows 11 Pro build 26200, Rust 1.100.0 MSVC, debug build; tool and model: Claude Code (Claude Sonnet 5.5)

@throny

throny commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

merge-check claim
head: 78795c7

@throny

throny commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

merge-check
base: 7c795f5 (amd-dev)
head: 78795c7
merge: clean
build: cargo build --workspace ->
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> nothing to compare: the merge changes no file (this identical-to-base tree gave 1802 passed, 18 failed, the base's 16 plus the two tests that come and go). On this NVIDIA card the amd-dev suite is noisy: the base alone gives 1804 passed, 16 failed, 48 ignored, two tests (list_x the_mirror_sync_copies_only_the_pages_the_title_wrote, present compositor_releases_root_sig_and_rejects_invalid_planes) fail in some runs and not in others, and in 2 of 5 runs today the library test binary ended with 0xc0000409, one of them a tree identical to the base.
review: the whole change is already on amd-dev: commit 39440cd is an ancestor of 7c795f5, the PR's diff reverses cleanly, and a trial merge changes nothing. The memory point of the first check still holds on the branch and would need a new PR: the file is read into a buffer of exactly its length and then extended by four bytes, which reallocates to about double, for the lengths that take the copy path. A file that changes between the size query and the read is refused; a hostile file's bytes reach CreatePipelineLibrary as before; there is no size cap.
performance: none from merging.
verdict: not yet: nothing to merge; already in amd-dev through 39440cd. The reallocation fix belongs in a new PR.
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read). An NVIDIA card: it says nothing about AMD driver behaviour, so a check from an AMD tester is the one that counts for that.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head 78795c7

This PR's own change is only the top commit 78795c7 (MappedBlob::open in hle/d3d12x/pso_library.rs). The other ~258 commits are the old amd-dev base it sits on, and #2891, #2912, #2913 and the other large amd-dev PRs share that base. They do not make this change themselves.
The fix was ported to amd-dev as 39440cd ("D3D12.X: give mapped pipeline library blobs a readable tail", "Port #2859"), with the same diff. #2912, #2913, #2981, #3079 and the others carry it.
Current amd-dev was rebuilt and has no pso_library.rs or MappedBlob any more: shaders/pipeline_library.rs reads the library into an in-memory Arc<[u8]>, so there is no mapped view to overrun.
Recommendation: close (superseded by amd-dev commit 39440cd).

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

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.