Skip to content

D3D12.X: the frame trace counts memory copies of views that went stale - #3178

Open
KOLESNiii wants to merge 1 commit into
xcl-dev:mainfrom
KOLESNiii:d3d12x-stale-descriptor-copy-census
Open

KOLESNiii wants to merge 1 commit into
xcl-dev:mainfrom
KOLESNiii:d3d12x-stale-descriptor-copy-census

Conversation

@KOLESNiii

@KOLESNiii KOLESNiii commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Help wanted: evidence. This PR only measures and changes no behaviour; it is the first step for the console-layout guesses. Please run a title on this head and post the frame trace: view heap ... census lines (their stale counts) and frame trace: ... stale copies seen in descriptor tables at draws, with XCL_TRACE_FRAME=1 for a short run here (not the whole log). It decides whether XCL's T# naming its slot's PC descriptor (instead of being a value) needs changing. The regression run below was without XCL_TRACE_FRAME, so it does not measure; not run with it on the retail game yet.

A console view descriptor is a value. A copy keeps the view it was copied from when the source slot later gets another view, even while the GPU has not yet run the work that reads the copy. XCL's T# names its slot's PC descriptor instead (word 0 = that slot's index in the PC heap). So a copy the title makes as memory follows the source slot: a view made there afterwards changes every earlier copy, in-flight work included, and the draw reads the wrong texture without any error. HANDOFF names this limitation, but nothing measured whether a title runs into it. This PR is the measurement. It changes no behaviour.

What is in it

  • console_heap.rs, under XCL_TRACE_FRAME:
    • The view-heap census line now reports, per heap, how many copies (images naming another slot's PC index) are stale: their words 1–7 differ from the image now in the slot that owns that index.
    • It also reports how many image views were written over with other words (rewritten), counted in write.
    • The owner is looked up in the shared heap for a heap that is in it, and in the heap itself otherwise. A copy whose owner slot now holds something else is not counted.
  • bind.rs: the descriptor-table slots that the frame trace samples at draws are marked (stale copy), and the census prints how many were seen.
  • Without XCL_TRACE_FRAME nothing changes: the only added work in write sits behind the cached trace_frame() check.

Tested

  • NVIDIA RTX 2070 SUPER (driver 32.0.16.2140), AMD Ryzen 5 3600XT, Windows 11 build 26300, Rust 1.100.0 MSVC; tests in debug

  • cargo test --workspace --no-fail-fast -- --test-threads=4 on a385e9a: 2139 passed, 4 failed, 48 ignored. SKIPPED: 15 (14 no wave64, 1 no heap windows).

    • The 4 failures are the e2e title tests incomplete_discovered_corpus_blocks_headless_title_entry, test_title_draws_with_a_root_signature_under_the_debug_layer, test_title_runs_and_game_folder_is_untouched and test_title_runs_under_the_debug_layer_with_dred.
    • They also fail on main 309c3ec. This branch's base, main bb9a6b4, has no suite run of its own.
  • New test console_heap::tests::a_memory_copy_whose_source_slot_is_rewritten_is_stale: ok. It makes view A in slot 0, copies it as memory to slot 2, then makes view B in slot 0.

    • Before B, the copy is not stale.
    • After B, it is, both in the census and at a bind.
    • With a buffer in the source slot, the copy is not counted.
  • Retail game, a385e9a release, one 60 s run with XCL_TRACE_FRAME=1 (XCL_PREPARE=0, XCL_PRESS_AT=25:A); census of the shader-visible view heap (1 245 184 slots):

    census at own index another stale rewritten buffers empty
    6.1 s 114 15 0 0 327 652 917 403
    28.4 s 6 101 1 962 109 11 382 956 854 165
    • The 11 CPU-only view heaps have no copies.
    • At draws, 0 sampled table slots were stale. The trace samples the first 4 slots of each table on traced draws only.
    • All 8 stale examples name PC index 218, at slots 4 096 apart (716 433, 720 529, …).
    • The heap also holds "copies" whose word 0 looks like a float (0x3F800000, 0x45700000). So not every image-typed slot is a real descriptor, and the 109 have not been checked one by one.

Regression run
RTX 2070 SUPER, the retail game, 60 s, XCL_PRESS_AT=25:A, XCL_PREPARE=0 (no startup shader preparation), release builds. main ran in an earlier queue job than this head; every run started from the same DXIL cache.

main:

xcl-smoke v1
commit: 309c3ec5a25ea231ddbe01f76748ab8ed3d9d953
gpu: NVIDIA GeForce RTX 2070 SUPER
title: retail game
seconds: 60
exit: 0x0
frames shown: 1297 (PresentX 1298)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 14701 MB

This PR's head:

xcl-smoke v1
commit: a385e9a47f0464556ac63116cf60a74a32df1311
gpu: NVIDIA GeForce RTX 2070 SUPER
title: retail game
seconds: 60
exit: 0x0
frames shown: 1293 (PresentX 1293)
presents per 2 s (last 3): 61 60 60
device removals: 0
crashes: 0
peak commit: 14782 MB

Not tested

  • Whether the 109 stale copies are read by a draw after the rewrite. The sampled tables saw none.
  • The regression runs skip startup shader preparation (XCL_PREPARE=0), on main and on this PR alike.
  • AMD GPUs.

AI use

  • Claude Code, Claude Opus 5.5: wrote the code, the test and this description; ran the tests and the traced run.

🤖 Generated with Claude Code

@KOLESNiii
KOLESNiii force-pushed the d3d12x-stale-descriptor-copy-census branch from a385e9a to 3c87803 Compare November 28, 2026 19:57
@KOLESNiii
KOLESNiii force-pushed the d3d12x-stale-descriptor-copy-census branch from 3c87803 to 7fae625 Compare November 29, 2026 20:55
@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:memory Virtual/physical memory, arenas, VRAM budget, UMA gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Nov 29, 2026
@KOLESNiii
KOLESNiii marked this pull request as ready for review November 29, 2026 21:00
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Triage (#1607) – head 7fae625

No open or merged PR makes the same change; #3313 clears stale PC views on CBV/BVH/buffer overwrites, a different (behaviour) change, while this only adds XCL_TRACE_FRAME counting.
In console_heap.rs the census loop is moved into view_census unchanged and extended with stale-copy detection; write reads the old slot words only under trace_frame(). stale_copy_at takes HEAPS on each slot of the root_args_summary trace, which is trace-only. No problems found in the diff.
Recommendation: keep open.

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

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Review (head 7fae625, diff read, not a merge-check; PR description red: no smoke block on this head):

  • Behind XCL_TRACE_FRAME it is heavy, but that's acceptable for a trace. write (console_heap.rs ~1346) reads the old 8 words and takes the global REWRITES mutex on every view write. stale_copy_at takes HEAPS per sampled slot, and owner_image scans every heap's page list for each copy (~1395). With a 1.2M-slot shader-visible heap, the census and the per-draw marks can slow a traced run noticeably; worth one line in the README entry so people don't read frame times from a traced run.
  • stale_copy_at takes HEAPS from inside root_args_summary (bind.rs ~4538). I found no caller that already holds HEAPS there (~4338, ~4410, ~4482 are trace log lines), so no self-deadlock, but it's a new lock on the draw path under trace.
  • The red CI run is the known access violation in gpu::agility::tests::create_device_sets_dred_first inside D3DSCache.dll (Intermittent access violations during parallel library tests on Windows 11 #1487), not this diff.

Fine: without XCL_TRACE_FRAME the only added work is the cached trace_frame() check in write. Buffer V#s are excluded (they carry their own address), and a copy whose owner slot now holds something else isn't counted. The owner is looked up in the shared heap or the heap's own PC heap as the T# names it. The new test covers before and after the source is rewritten and the buffer case. The question it measures (does a title read memory copies of views whose source changed?) is worth answering before changing how a T# names its descriptor.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

A console view descriptor is a value: a copy keeps the view it was
copied from when the source slot later gets another view. XCL's T#
names its slot's PC descriptor instead (word 0), so a title's memory
copy follows the source slot: a view made there afterwards changes the
copy, in-flight work included. Nothing measured whether a title does
this.

Under XCL_TRACE_FRAME, the view heap census now reports, per heap:
- copies (images naming another slot's PC index) whose other words
  differ from the image now in the slot owning that index: stale;
- image views written over with other words (a rewrite).
The descriptor tables sampled at draws mark a stale slot, and the census
prints how many were seen. Without XCL_TRACE_FRAME nothing changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@KOLESNiii
KOLESNiii force-pushed the d3d12x-stale-descriptor-copy-census branch from 7fae625 to 7e422de Compare December 2, 2026 15:05
@KOLESNiii

Copy link
Copy Markdown
Contributor Author

Thanks for both reviews. Rebased onto main df0cfef with no conflicts; new head 7e422de5. XCL_TRACE_FRAME has no README entry to add the warning to, so the warning that frame times from a traced run should not be read as normal is here in the thread instead. Suite and smoke are queued on the new head.

— Claude Code (Claude Opus 5.5), on behalf of the PR author

@Foniass

Foniass commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Follow-up review (head 7e422de, since 7fae625, diff read, not a merge-check; checks red):

  • Earlier points: unchanged; git range-diff shows the commit identical to 7fae625, so this push only rebases onto the current main.

New: none.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory area:memory Virtual/physical memory, arenas, VRAM budget, UMA gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants