D3D12.X: Hash dirty chunks from the bytes staged for upload #3702
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3702"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T15:38:27Z.
What is in it
Load each complete dirty 64-byte chunk once during staging and use its words for both the upload and the submitted hash journal. Partial chunks retain their previous behavior. The initial dirty scan, GPU copy, and fence ownership remain in place.
Tested
cargo test --release --locked -p xcl --lib bench_upload_ab_sparse -- --ignored --nocapture --test-threads=1.Mapped D3D12 upload benchmark
The staged bytes and hash journal matched. This isolates one contiguous dirty span with warm source data and a reused allocation. Parallel jobs, dirty discovery, GPU copies, and fences are outside the timed region.
Release build on an i9-12900K and RTX 4090 (610.88). Each value is the median of five independent process medians, with 31 alternating timed batches of 128 operations per method and size in each run. XCL allocated a native D3D12 upload buffer. The device reported WRITE_COMBINE and Windows reported PAGE_READWRITE | PAGE_WRITECOMBINE (0x404). Both focused checks passed in each process on the combined development checkout. These are CPU staging times.
Reproduce with
cargo test --release --locked -p xcl --lib bench_upload_ab_sparse_mapped -- --ignored --test-threads=1 --nocapture.Regression run
Main
PR head
The journal records the hash of the same loaded words written to staging. This closes the interval in which a guest write between hashing and copying could previously leave a hash for different bytes. The tests cover writes after planning and verify staged bytes against the journal. Concurrent guest mutation during staging and AMD hardware remain untested.
Not tested
The full GPU workspace suite and a matched in-world frame-time comparison for this individual PR.
AI use
OpenAI Codex (GPT-6) implemented and reviewed the change, ran the focused tests and benchmark, and prepared this PR.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T18:31:19Z.
merge-check
base:
5eaadb54c1head:
77d276fa70merge: clean
build: ok
tests: 2975 passed, 0 failed, 53 ignored; 28 skipped, the same as on main
review: 1 high, 3 medium (below)
performance: 60 s smoke run: 1422 → 1670 frames (117 % of main), peak commit 17184 → 16928 MB, no device removal, no crash
title run: not run
verdict: not yet: it is a draft,
PR descriptionis red, and 1 high finding (below): the default dirty-upload copy into write-combined memory is measured only into an ordinary buffer, with no smoke runs and no suite run of this headhardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
In short: On the default (and only) dirty-upload path, each full 64-byte chunk is now read once from the title's memory, and that one read is both written to the upload ring and hashed; main reads twice (hash first, then a separate
memcpy:stage_copies/run_copiessparse.rs~7499-7557,submit_upload~4738). That also fixes a real race (finding 2). The suite and smoke run below are clean, but the speed-up was measured on the wrong kind of memory and the PR has no evidence of its own yet.High
run_copiesreplaces one bulkcopy_nonoverlappingper job with a 64-byte read/write loop into the write-combined upload heap (staging, ~4083), with no opt-out. The numbers come from aVectarget only, and there are no smoke blocks or suite run of this head (thePR descriptioncheck fails). Measure into the real upload heap and add the smoke pair.Medium
memcpyleft C on the GPU with H(B) stored, so the chunk was never sent again. The fused read closes that, but no test pins "stored hash = bytes uploaded" under a concurrent write (the edited test, ~10479, covers only a write after the copy). Say it in the description and add that test.mod testsas#[ignore].bench_upload_ab_sparse(~10495) is a benchmark, not a test, and its equivalence asserts duplicate the new test. Move it tobenches/or drop it.Checked and fine
Submitted(~4209), and the ring rolls back onNotSubmitted.hash_words(..from_le)equalschunk_hash.assert!(journal.is_empty())andset_lenafter the join are sound.How this was tested
5eaadb54, thencargo build --workspaceandcargo test --workspace --no-fail-fast -- --test-threads=4.scripts/smoke.ps1: 60 s of a retail title on main5eaadb54and on this merge; presents per 2 s at the end: 60 60 60.Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by capy-ai[bot] on 2026-12-02T20:10:08Z.
Code review (head
2fe4985512, diff read only — not built or tested on Windows/GPU, not a merge-check)No code or memory-safety bugs found; merges cleanly onto
origin/main(5ad98adb). This looks like a strong win.main: fusing each full 64-byte chunk load into[u64; 8]registers (stage_copies), writing unaligned 64-byte runs into the WC staging ring, and hashingwords.map(u64::from_le)matcheschunk_hash/read_chunk_wordsbyte-for-byte while guaranteeing the journaled hash matches the exact bytes uploaded (closing the concurrent guestB -> C -> Bmutation window between hashing andcopy_nonoverlappingonmain).UploadCopy::prefixavoids overflow on misaligned windows and sub-chunk spans, each worker piece gets a disjointMutex<&mut [MaybeUninit<HashUpdate>]>,assert!(journal.is_empty())confirms full initialization beforeupdates.set_len(old_len + chunks)after join, and hashes still publish only onSubmitResult::Submitted.#3701and#3702both add the identicalwith_upload_pairhelper atcrates/xcl/src/gpu/recomp/runner.rs:566(the second to merge will need to drop its duplicate).D3D12.X:/Memory:area prefix,AI usenamesOpenAI Codexwithout the exact model name, and the two#[ignore]timing tests sit inmod testsrather thancrates/xcl/benches/.gpu:both), and a real title run past loading on head2fe4985512.AI use: Capy, Google Gemini 4 Neon (static code review only; not built or tested on Windows/GPU).
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-12-02T20:42:31Z.
merge-check
base:
5ad98adbc3(current main)head:
2fe4985512merge: clean (8be3f02af; runner.rs auto-merged)
build: cargo check -p xcl --all-targets -> ok (39 lib / 19 lib-test warnings, same as main
5ad98adbc); git diff --check cleantests: cargo test -p xcl --lib -- --test-threads=1 on the touched sparse tests (staging_copies_and_hashes_cover_only_the_requested_ranges, hash_plan_is_published_only_when_applied, only_changed_chunks_are_sent, batch_hash_plan_is_bounded_by_staging, prepared_dirty_batch_keeps_exact_hash_plan_and_rollback_point, ring_planner_handles_wrap_and_large_chunks) -> 6 passed, 0 failed. Full workspace suite and GPU tests not run here; Foniass's full suite on
77d276fa7(this code without the bench commit) passed 2975/0.review:
main; the description should say so.main,submit_uploadhashes each full chunk from the title's memory first, thenrun_copiescopies it into the ring.sentholds H(B).changed_chunks(sparse.rs:2947onmain) sees B == H(B) and never sends the chunk again, so the GPU keeps stale bytes.stage_copies,sparse.rs:7498), the journal hash is always the hash of the exact words staged. A read torn by a concurrent write still leaves the page write-watched and the chunk different from its journal hash, so it goes up again.staging_copies_and_hashes_cover_only_the_requested_ranges(:10569, misaligned windows and the pool path) already pins "journal = hashes of the staged bytes", so only the description is missing.UPLOADheap (0x404). Each full chunk is one 64 B store.RING_ALIGN,plan_ring_chunk), and dirty runs fromchanged_chunksstart on chunk boundaries, so in practiceprefix() == 0and each store fills one WC line.prefixbytes into a line and straddles two lines. The new test exercises exactly that (windows+3,+19). Is it reachable at runtime?window % 64keeps the stores line-aligned. If not, adebug_assert!would document it.updates.set_len(old_len + chunks)(:7556) runs only after the worker-pool join, and theMaybeUninitslots are never read before then.runner::with_upload_pairis byte-identical in both PRs, and a trial merge of the two heads is clean.bench_upload_ab_sparse(ordinary RAM) is superseded bybench_upload_ab_sparse_mappedand could go.performance: not run here; no GPU work in this check. The description's smoke pair can't be read as evidence: a hash/copy fusion doesn't move peak commit from 23,474 to 14,909 MB, and the
mainblock (presents 51/16/48) is shared with #3701/#3703. Foniass's 5070 Ti pair on77d276fa7(the same code without the bench commit), 1,422 -> 1,670 frames, 0 removals, is the usable one.verdict: safe to merge: correct by reading and its tests pass on current main; please add the B-C-B race fix to the description, since it changes what the default upload path guarantees.
hardware / tool and model: NVIDIA GeForce RTX 5070 Ti, driver 32.0.16.1074, AMD Ryzen 9 9950X, Windows 11 Pro 26200 / Claude Code (claude-opus-5-5)
Imported from ivall/xcl. Originally posted by lucsoft on 2026-12-02T20:43:32Z.
merge-check claim
head:
2fe4985512Imported from ivall/xcl. Originally posted by lucsoft on 2026-12-02T23:13:24Z.
merge-check
base:
5ad98adbc3head:
2fe4985512merge: clean (merge commit 63760ca2, auto-merge in runner.rs, git diff --check clean)
build: cargo build --release -p xcl && cargo test --workspace --release --no-run (x86_64-pc-windows-gnu) -> ok
tests: lib 2798 passed, 17 failed, 15 ignored, 31 died; integration 137 passed, 6 failed, 20 ignored, 1 exe died (main
5ad98adb: lib 2797 / 17 / 13 / 31, integration identical; +1 passed = staging_copies_and_hashes_cover_only_the_requested_ranges, +2 ignored = the manual benches). Under Wine, one test module per process with --test-threads=2, not 4. Skipped: 8 tests, the same set as on main (no dxc.exe, no D3D12 debug layer, heap windows opt-in, driver cache cannot be disabled, stale-blob probe refused, Close does not refuse an open pipeline-statistics query x2, SetPredication ignored for copies). failing: every failure also fails on main5ad98adbin the same setup (suite-diff by test name: 0 only on this PR): 31 died = 29 split-wave/DXIL GPU tests that abort in dxil-spirv without #3707 (module::split 10, mask_exchange 5, lower_dxil 5, recomp 4, robustness 2, idioms 2, lower 1), hle::netoff 1, and the known serialize_root_signature hang (not run), 17 failed = Wine/RADV-specific (title_textures group 4, list_x 3, recomp 2, lower_dxil 2, and single ones in root_signature, driver_cache, descriptor_heap, device_x, round, fuzz); integration: gpu_compute_e2e died, e2e x2, frame_clock, gpu_two_pass_cache_e2e, pls_quota, tls_slot_zero fail on main tootitle run: retail title, RX 7800 XT (RADV, Wine), 480 s run, past the loading screen into the in-engine intro cutscenes / prologue (world rendering from 123 s: first 2 s window with >= 1000 draws), 358 s there, no crash, no device removal, 0 amdgpu page faults or ring timeouts, 0.88 presents/s there (2617 frames in total). Run on this merge result + #3707 (
912ff558) on top: main5ad98adbalone aborts ~3 s in under vkd3d-proton (dxil-spirv, the helper functions #3707 inlines), so did this merge without it (exit 0x3 at ~3.3 s). main5ad98adb+ #3707 the same way: 359 s there, no crash, 0.59 presents/s, 2182 frames.review: read the whole diff (+211/-61). Each full 64-byte chunk is now read once into [u64; 8], written to the ring and hashed from the same words; hash_words(words.map(u64::from_le)) equals chunk_hash of those bytes (read_chunk_words is from_le_bytes of the same unaligned words). This closes the window on main where the journal hashed one read of guest memory and the ring got a later read. prefix()/chunks() give the same full-chunk set as the old next_multiple_of/& !(CHUNK-1) loop (by window address; partial chunks still get no update). The parallel path splits the reserved journal by each piece's chunk count, the last piece is closed by k + 1 == len, stage_copies asserts its slice is used up, and set_len runs only after every slot was written (on unwind the old length stays). batch.updates stays within MAX_BATCH_HASH_UPDATES (= STAGING / CHUNK). with_upload_pair is #[cfg(test)]. Untested here: NVIDIA; the >= 512 KiB pool path ran only in the unit test, not separately measured in the title. No findings.
performance: one guest read per staged chunk instead of two (hash pass + copy pass), so less memory traffic by default; no new allocation (reserve on the existing Vec). Title run 0.88 presents/s vs 0.59 on the base (noise at this rate, not a measurement of the change).
verdict: safe to merge
hardware / tool and model: AMD Radeon RX 7800 XT (RADV NAVI32, Mesa 26.3.1), Ryzen 7 7800X3D, NixOS (Linux 7.3.5) with Wine staging 11.21 + vkd3d-proton 3.1 / Claude Code, claude-opus-5-5
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-03T02:29:01Z.
merge-check
base:
078358a058head:
2fe4985512merge: clean
build: ok
tests: 3007 passed, 0 failed, 54 ignored; 28 skipped, the same as on main
review: 3 medium, 1 nit (below)
performance: 60 s smoke run: 1669 → 1683 frames (100 % of main), peak commit 17577 → 17846 MB, no device removal, no crash
title run: retail title on the RTX 5070 Ti (driver 621.14), into the world by scripted presses: 227 s there, 0 device removals, 0 crashes, 3 presents/s; run with
XCL_SKIP_CS=95cc13288a27a96e(the NVIDIA hang at the end of loading, #3541) and NVIDIA's 2048 MB shader heap (#2590)verdict: safe to merge: no blocking finding (the points below are medium or nits), the suite passes and the smoke run is clean
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
In short: On the dirty-upload path, each full 64-byte chunk is now read once from the title's memory, and that one copy is both written to the upload ring and hashed; main hashed first and then ran a separate memcpy. Since the earlier merge-check it has added smoke blocks and a benchmark into a real write-combined upload heap, and the description now names the race it closes. Nothing blocks; still open are a test of that race, the benchmarks left in mod tests, and the description.
Medium
Nit
Checked and fine
How this was tested
078358a0, thencargo build --workspaceandcargo test --workspace --no-fail-fast -- --test-threads=4.scripts/smoke.ps1: 60 s of a retail title on main078358a0and on this merge; presents per 2 s at the end: 60 60 60.XCL_RUN_SECONDS=300and scripted A presses counted from the first frame (XCL_PRESS_BASE=frame, #3712) into the world from an existing save; time in the world is counted from the first in-world draw call to the end of the run.Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.