Skip to content

D3D12.X: a descriptor copy looks its console slots up under one lock - #466

Open
TG0000 wants to merge 1 commit into
xcl-dev:mainfrom
TG0000:perf/d3d12x-hotpath
Open

TG0000 wants to merge 1 commit into
xcl-dev:mainfrom
TG0000:perf/d3d12x-hotpath

Conversation

@TG0000

@TG0000 TG0000 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

A device descriptor copy over console heaps (CopyDescriptorsSimple #24 / CopyDescriptors #23) copied the slot words one pair at a time, and looked each side of each pair up with console_heap::slot(). Every lookup locked the heap list and scanned all of it, locked the shared heap to read its geometry (view slots), and copy_words then locked the XCL_TRACE_FRAME resource map once per slot, even with tracing off. That came to about 2n heap-list scans and 3n–4n mutex round-trips for every n-descriptor copy, on a path the title runs every frame.

console_heap::copy_words_run now does the whole run under one lock of the heaps:

  • it tries the heap of the previous pair first (heap_of(.., hint)). Heaps never overlap, so a hit is the same heap the scan would find, and a miss falls back to the scan.
  • it reads the shared heap's (cpu, gpu, inc) once per run, and only when a view slot needs it. These values are fixed once the heap is made, and GLOBAL is never set back to None.
  • copy_words looks up the resource map only when trace_frame() is on, which is when note_resource would use it.

The behaviour is the same as before: the same pairs, the destination looked up before the source for each pair (so shared-heap pages are reserved in the same order), pairs with a side outside the console heaps skipped, and the same words written. slot() now uses the same heap_of / slot_in code.

What is in it

  • crates/xcl/src/hle/d3d12x/console_heap.rs: slot() is split into heap_of + slot_in. Adds copy_words_run, and copy_words skips the resource-map lookup when tracing is off. Adds unit tests and an #[ignore]d release microbenchmark.
  • crates/xcl/src/hle/d3d12x/real.rs: in copy_console_slots, the per-slot loop is replaced by one copy_words_run call (3 lines).

No open PR touches these hunks: #187 edits console_heap.rs only at lines ~27 and ~157–200 (shared_heap), and no open PR edits real.rs near copy_console_slots.

Tested

  • AMD Radeon RX 6800 (driver 32.0.21045.29003), Ryzen 9 5900X, Windows 11 build 26300, rustc 1.100.0 stable-x86_64-pc-windows-msvc
  • New unit tests:
    • a_run_copies_what_each_slot_did: for views and for samplers, it compares copy_words_run with the old per-slot loop on identical heaps. The run starts 2 slots before the end of one heap, goes into a heap right after it, then into memory that belongs to no heap; it also copies whole heaps and copies from outside the console heaps. Image T# are renumbered, V# keep their address, S# word 3 is renumbered. Run 10 times under the parallel test runner: passed every time.
    • a_heap_hint_is_checked: a wrong hint, an out-of-range hint, a correct hint, and an address just past a heap.
  • cargo +stable-x86_64-pc-windows-msvc test -p xcl --lib console_heap: 5 passed, 0 failed, 1 ignored. This includes the existing slots_copy_and_release and large_heaps_get_shared_pages_as_used, which exercise slot() with the shared heap on the real device.
  • cargo +stable-x86_64-pc-windows-msvc test -p xcl --lib: 636 passed, 2 failed, 22 ignored. The 2 failures are vram::tests::d32s8_targets_take_their_own_size_of_video_memory and title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels ("3D 64x64x64 4 mips: subresource 2 mismatch"). They fail the same way on origin/main (a6f5f7a) without this change, on this adapter, and are in files this PR does not touch.
  • cargo +stable-x86_64-pc-windows-msvc clippy -p xcl --all-targets: no new warnings. The only console_heap.rs warnings are the 4 that were already there (# Safety docs on existing unsafe fns). The release build has the same single rustc warning as main.
  • Release microbenchmark, cargo test --release -p xcl --lib copy_run_speed -- --ignored --nocapture. It copies 64 view slots with 48 heaps registered, with the busiest pair registered last:
    copy of 64 view slots, 48 heaps: a lookup per slot 5826 ns, one run 1546 ns (3.8x)
    copy of 64 view slots, 48 heaps: a lookup per slot 6067 ns, one run 1823 ns (3.3x)
    

Regression run

scripts/smoke.ps1 -Seconds 45, one run each, under a 1 s free-RAM watchdog (it never fired):

xcl-smoke v1
commit: 2997c9aca6ebf4577fed34ebdb3cb0a77dd9ec21
gpu: AMD Radeon RX 6800
title: retail-title-1.0.2.1
seconds: 45
exit: 0x0
frames shown: 692 (PresentX 692)
presents per 2 s (last 3): 55 55 56
device removals: 0
crashes: 0
peak commit: 15153 MB
xcl-smoke v1
commit: ed2b685a9b9fea12f31c104c74a656d6ac9e942b
gpu: AMD Radeon RX 6800
title: retail-title-1.0.2.1
seconds: 45
exit: 0x0
frames shown: 828 (PresentX 828)
presents per 2 s (last 3): 58 60 59
device removals: 0
crashes: 0
peak commit: 15154 MB

These are single runs, and frame counts vary from run to run. I don't claim this change caused the difference in frame counts. The point of these runs is that nothing regressed: no device removal, no crash, and the same peak commit.

Not tested

AI use

  • Claude Code with Claude Opus 5.5: found the hot path, wrote the change, the tests and the benchmark, and ran the builds, tests and smoke runs. I reviewed the diff.

🤖 Generated with Claude Code

CopyDescriptorsSimple / CopyDescriptors over console heaps copied the slot
words one pair at a time, each side through console_heap::slot(): a lock of
the heaps and a scan of all of them per descriptor, a lock of the shared
heap for its geometry per view slot, and a lock of the resource map
(XCL_TRACE_FRAME diagnostics) per slot even with tracing off.

copy_words_run does the run under one lock of the heaps, tries the heap of
the previous pair first (heaps do not overlap, so a hit is the scan's
answer), reads the shared heap's geometry once (fixed once made, never
dropped), and copy_words reads the resource map only when it is noted.
Same pairs, same order of page reservation (destination first), same words.

Release microbenchmark (copy_run_speed, 64 view slots, 48 heaps):
a lookup per slot ~5.9 us, one run ~1.6 us (3.3-3.8x).

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

Copy link
Copy Markdown

Tested

Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti (driver 621.35), Rust 1.99.1 MSVC, release build. Tested commit ed2b685a

  • cargo test --release --locked -p xcl --lib console_heap -- --test-threads=1 --nocapture — 5 passed, 0 failed, 1 ignored (the benchmark), and 0 reported skips.
  • cargo test --release --locked -p xcl --lib copy_run_speed -- --ignored --nocapture — passed in three separate processes. Across six samples from this revision’s synthetic benchmark (64 descriptors, 48 heaps), per-slot lookup took 3,743–3,921 ns per copy and batched lookup took 1,031–1,052 ns per copy, a 3.6–3.7× speedup in this benchmark.

Not tested

Full workspace suite, AMD, shared-heap page reservation through the batched copy on a real device, retail titles, or per-frame performance.

AI use

Codex with GPT-6.2 Sol ran the tests and drafted this report.

@H0UNDZER0

H0UNDZER0 commented Nov 24, 2026 •

Copy link
Copy Markdown

Tested on an RTX 5080: pass. This adds the whole suite, which the RTX 3080 Ti run above lists as not tested: 678 passed, 0 failed.

  • Commit ed2b685a9b9fea12f31c104c74a656d6ac9e942b, this PR's head as is (on its base 2997c9a), release build.
  • NVIDIA GeForce RTX 5080 16 GB, driver 621.24 (32.0.16.2124), 32-lane waves; Ryzen 7 9700X; Windows 11 Pro 24H2 (26100.9711); Rust 1.100.0 MSVC; DXC 1.9.2602.17 (Windows SDK 10.0.26100.0). No XCL_* variables set.
  • cargo build --release --workspace --locked: OK, the same single fetch_update warning as main.
  • cargo test --workspace --release --no-fail-fast --locked -- --test-threads=4, run twice (the second with --show-output): 678 passed, 0 failed, 42 ignored both times. main 2997c9a gives 676 / 0 / 41 on this PC: the difference is this PR's 2 new tests and its ignored benchmark.
  • SKIPPED: the usual 2, gpu_geometry_wave32_prefix_count_over_a_mask and gpu_wave32_program_in_wave64_hardware (no wave64).
  • console_heap: a_run_copies_what_each_slot_did and a_heap_hint_is_checked pass, and so do slots_copy_and_release and large_heaps_get_shared_pages_as_used (the shared heap on this device).

Not tested

  • A copy through copy_words_run with the shared heap present on a real device: no test makes one, as the description says.
  • This PR merged onto a newer main. At the time of the run that was 508a0c7; git merge-tree showed no conflict.
  • The benchmark, debug build, retail titles, scripts/smoke.ps1.

AI use: Claude Code (Claude Opus 5.5, Claude Fable 5.2)

@Alpha325

Copy link
Copy Markdown

I extended the release microbenchmark at ed2b685a9b9fea12f31c104c74a656d6ac9e942b to cover 1, 4, 16, and 64 view descriptors. Both paths ran in the same PR build, comparing the per-slot loop with copy_words_run. I registered 48 synthetic heaps and tested source/destination pairs at the front and back of the list.

Windows 11 build 26200.9974, Ryzen 5 7600X3D, Rust 1.100.0 MSVC release. Five fresh processes, two paired measurements per process with timing order reversed, and 20,000 copies per measurement.

Heap position Descriptors Per-slot loop, ns/copy Batched, ns/copy Median paired speedup
Front 1 33.7 22.4 1.51×
Front 4 129.8 75.1 1.73×
Front 16 523.1 286.2 1.83×
Front 64 2076.4 1133.1 1.83×
Back 1 62.4 59.0 1.07×
Back 4 251.8 111.0 2.27×
Back 16 1002.0 321.6 3.12×
Back 64 4011.7 1167.8 3.43×

The smallest gain was a single descriptor at the back of the list (1.05–1.09× across the ten pairs). The 64-descriptor back-of-list case measured 3.38–3.46×.

cargo test --release --offline --locked -p xcl --lib console_heap -- --test-threads=1 --nocapture returned 5 passed, 0 failed, 1 ignored, and no skip markers. I ran the ignored copy_run_speed benchmark separately with --ignored --test-threads=1 --nocapture.

Scope — CPU descriptor lookup and copy time with synthetic heaps. Frame rate and GPU execution time were outside this test.

AI use — OpenAI Codex (GPT-6) extended the benchmark, ran it, and drafted this report.

IvyNotFound added a commit to IvyNotFound/xcl that referenced this pull request Nov 25, 2026
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.

4 participants