Skip to content

d3d12: console heap slots record what their V#s resolved to; a release re-fixes only the slots naming it (RT-VSHARP-SLOT-RECORDS) - #2407

Merged
aslan2142 merged 1 commit into
ProjectLeonida:mainfrom
aslan2142:vsharp-slot-records
Nov 26, 2026
Merged

aslan2142 merged 1 commit into
ProjectLeonida:mainfrom
aslan2142:vsharp-slot-records

Conversation

@aslan2142

Copy link
Copy Markdown
Collaborator

A console heap's copy now keeps a record per V# of what it resolved to. A released buffer, a removed alias range or a
retired copy re-fixes only the slots that name it. Before this, every live slot of the heap was walked. Nothing walks
the heap any more.

Claimed in the coordination issue as: RT-VSHARP-SLOT-RECORDS

What was wrong

  • After any arena release, title-window or geometry block destroyed, or alias change, the next submission walked
    every live V# slot of the console heap: about 580,000 in our world runs.
  • With LEONIDA_CONSOLE_RELEASE_FILTER=1, the walk read words 0-2 of both halves of each slot from heap.copy. That
    copy is in ReBAR VRAM, so these were uncached reads. Without the variable, it fixed every live slot again.
  • One walk took 1.1-1.5 s whatever the scene. It did not get faster when it re-fixed 4,400 slots instead of 9,100.
  • In one world run, the walk was about 91% of the heap phase and about 2.9 s of a 4.6 s frame. The heap refresh lock
    was held for about 70% of the wall time.
  • The walk existed only because nothing recorded which slot had resolved to which backing.

What changes

  • runtime/src/console_heap_slot_records.h (new, portable). For each V# half (the buffer V# and the UAV counter),
    a record of:
    • the title's base and span;
    • the device address its copy names;
    • its state: resolved, waiting or none.
  • Two indexes, one by base and one by target. Each indexes per power-of-two span class and per granule of at least
    64 KiB, so a range lookup visits only the entries near the range.
  • The records are in host RAM and allocated with calloc, so pages for slots that are never written stay untouched.
  • fix_console_slot is still the only writer of a slot's copy, and now also the only writer of its records.
    • A zeroed range, a slot the fix budget deferred and a rewritten slot drop their records.
    • A destroyed heap takes its records with it.
  • Changes go on an unbounded per-device list. They are recorded under the locks the code already takes, with a leaf
    mutex for the list:
    • backing() add and release;
    • title_block_gone;
    • alias ranges added, removed or replaced, and forget_copy: TitleVaAliases now tells listeners as each change
      happens;
    • title memory added.
  • At each submission, refresh_console_heaps takes the whole list and every heap re-fixes exactly the slots it
    touches:
    • a release or removal: every half that names the range;
    • an addition: the waiting halves over the range.
  • A V# whose buffer or alias arrives after the descriptor is fixed at the next submission. Before, it waited for a
    probe of 8 slots every 32 submissions.
  • New heap log line, every 10 s: slot records per submission: N changes, N slots looked at, N fixed again, N ms.
  • This is a root fix: no new environment variable, no switch, and the old walk is not kept as a fallback.
  • Credit to VIctory (marvisak/victory) for the idea of per-slot records instead of a sweep. No code was taken from it.

What is removed

  • The live_vsharps walk and its bitset: src/console_heap_vsharp_slots.h and its test.
  • LEONIDA_CONSOLE_RELEASE_FILTER and its README row. LEONIDA_CONSOLE_GPU_FILTER (GPU heap pass, opt-in) now
    defaults to unset instead of copying that variable's value.
  • The release generation checks: released_backings and TitleVaAliases::invalidations().
  • The 4,096-entry DescriptorRangeChanges ring (src/descriptor_range_changes.h), whose overflow fell back to a full
    sweep, and changed_ranges().
  • The empty-slot probe (8 slots every 32 submissions) and retry_unmapped_slots. The second was never reached: no
    caller set its unmapped flag.
  • Kept: retry_console_slots, the T# retries. Textures are not backings, so they need their own index (step A3).

Tests

  • New console_heap_slot_records_test (portable, CPU only):
    • 60,010 recorded slots, 10 of them name buffer B. Releasing B looks at 10 entries and fixes 10 slots.
    • Cases: an alias moved, removed and added again; a slot overwritten after it was recorded; a zeroed slot; a release
      that only partly overlaps a slot's range; two slots naming the same backing; a buffer that comes back; a refused
      alias copy that is backed later; a large span; a destroyed heap.
    • A randomised differential case: after each of 400 rounds, the copy must equal a full re-resolution of every slot.
    • A mutation that drops releases fails it.
  • d3d12_unmapped_vsharp_test (Wine/Windows):
    • Before, it expected the round-robin probe to restore 16 of 128 waiting slots in 64 submissions. Now it expects
      all 128 restored at the first submission after their alias is added, and none after it is removed.
    • New case: the 10 slots naming a released committed buffer are null after the release; 10 other slots are kept.
  • title_va_alias_test and geometry_views_test check the listener in place of the ring and the invalidation counter.
  • Linux runtime build and ctest (RelWithDebInfo, Ryzen 9 7950X3D iGPU, RADV, Mesa 26.3.1): 113 of 113 pass,
    2 skipped (as on main).
  • Windows runtime, clang-cl with xwin under Wine, on the same iGPU and RADV, compared test by test with main
    2d43417d4: 423 pass, 23 fail, 39 skipped on both. The 23 failures are the same presentation, bcrypt and
    file-system tests as on main. The only differences are console_heap_slot_records added and
    console_heap_vsharp_slots removed. No test went from pass to fail.
  • tests/test_ci_registration.py, tests/test_docs_*.py, tests/test_text_write_line_endings.py and
    scripts/check_no_game_data.py on the changed files all pass.

World run

RX 7900 XTX, RADV (Mesa 26.3.1), Wine, from a local build of main fac8b4bb9 with this change and two others (RT-BINDLESS-DIMENSION-LIMITS and #2230), same settings as a run of plain main:

  • No rescans and no CPU release filter lines in the whole run.
  • The heaps phase of submit phases is 2.2 to 2.4 ms per submission in the world, where plain main had 32 to 321 ms at the same run time.
  • slot records per submission shows changes arriving and slots fixed again (for example 19.6 changes, 4,610 slots looked at, 22.5 fixed again, 0.074 ms).
  • In the busiest windows 83,000 to 397,000 slots are looked at for 1,450 to 3,150 fixed: the index buckets are coarse there. That is a performance follow-up, not a correctness problem.
  • The run ended about 100 s into the world in a graphics-ring timeout with every queue idle in the dispatch markers. That hang also ends runs of plain main here (three of nine earlier runs). In the windows before it there were no slot changes at all, and the paths that release or move a backing were checked again against the code; nothing shows this change as its cause. The run did not reach play, so the frame time in play is not measured yet.

Not tested

  • Frame time in play: the run ended before it. To read in a later run:
    • no rescans and no CPU release filter lines;
    • the slot records per submission line: slots looked at in the thousands, not about 580,000;
    • heaps ms per submission in submit phases;
    • the frame time.
  • MSVC was not run locally. The Windows build is clang-cl with xwin, under Wine.

AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2)

…e re-fixes only the slots naming it (RT-VSHARP-SLOT-RECORDS)

After any arena release, title-window or geometry block destroyed, or alias change, the next submission walked
every live V# slot of the console heap (about 580,000 in world runs), reading each from the copy in ReBAR VRAM:
1.1-1.5 s a walk whatever the scene, about 2.9 s of a 4.6 s frame. It existed only because nothing recorded
which slot resolved into which backing.

Each V# half of a console resource heap's copy now has a record in host RAM (src/console_heap_slot_records.h):
the title's base and span, the device address its copy names, and whether it resolved or waits. Two indexes
(by base, by target; per power-of-two span class and 64 KiB-or-larger granule) find the halves near a range.
fix_console_slot, the only writer of a slot's copy, writes them; a zeroed range, a deferred slot and a
rewritten slot drop theirs; a destroyed heap takes them with it.

Releases (backing(), title_block_gone), alias ranges removed or replaced (TitleVaAliases tells its listeners
as it happens, forget_copy included) and additions (backings, alias ranges, title memory) go on an unbounded
per-device list. refresh_console_heaps takes it whole; every heap re-fixes exactly the slots it touches: a
release or removal every half naming the range, an addition the waiting halves over it. A new heap log line
gives the changes, slots looked at, slots fixed again and ms per submission.

Removed: the live_vsharps walk and its bitset (console_heap_vsharp_slots.h and its test), the release
generation checks (released_backings, TitleVaAliases::invalidations), LEONIDA_CONSOLE_RELEASE_FILTER, the
4,096-entry DescriptorRangeChanges ring with its full-sweep overflow and changed_ranges(), the empty-slot probe
and retry_unmapped_slots (unreachable: nothing set its flag). LEONIDA_CONSOLE_GPU_FILTER now defaults to unset
instead of the removed variable's value. The T# retries (retry_console_slots) stay.

Tests: console_heap_slot_records_test (portable): releasing a buffer 10 of 60,010 slots name looks at 10
entries and fixes 10 slots; an alias moved, removed and added back; overwritten and zeroed slots; partial
overlap; two slots on one backing; a buffer back; a refused alias copy backed later; a large span; a destroyed
heap; and 400 random rounds compared with a full re-resolution of every slot. d3d12_unmapped_vsharp_test now
expects all 128 waiting slots restored at the first submission after their alias comes (was: 16 by the probe in
64 submissions), none after it goes, and the slots naming a released buffer null. title_va_alias_test and
geometry_views_test check the listener in place of the ring.

Linux ctest 113/113; Windows suite under Wine (clang-cl, iGPU, RADV) equal to main 2d43417 test by test.

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

Copy link
Copy Markdown
Collaborator Author

Merging. This is a self-merge.

  • Why now: after any arena release or alias change, the next submission walked every live V# slot (about 580,000 in play here) and read each back from the heap copy. That was most of a 5 s frame on RADV under Wine, and 10 to 15% of a frame on a tester's native NVIDIA run. The walk, its bitset, the 4,096-entry ring, LEONIDA_CONSOLE_RELEASE_FILTER and the round-robin retry are removed; a record per slot and a change list replace them.
  • Tested on main 2d43417d4 + this PR (84db5cd02), integrated RDNA2 GPU (RADV, Mesa 26.3.1):
    • console_heap_slot_records_test: with 60,010 live slots of which 10 name a buffer, releasing it looks at 10. It also passes 400 random rounds checked against a full re-resolution, and a copy with releases dropped fails it.
    • Linux runtime ctest: 113/113. Windows suite under Wine: 423 pass and 23 fail on both builds; no test went from pass to fail.
    • Registration, docs, line-ending and game-data checks pass.
  • World run: see the description. No walk in the whole run and the heaps phase at 2.2 to 2.4 ms per submission against 32 to 321 ms on plain main at the same run time. The run ended in a hang that plain main has as well, before play, so the frame time in play is still to be measured.
  • Follow-ups: the index buckets are coarse in busy windows; a V# that waits because geometry capacity is full is fixed again only when something is added over its address; d3d12: a console heap's V# words are fixed once a pass, not once a slot (RT-CONSOLE-VSHARP-MEMO) #2117's memo still makes sense for the changed-slot pass and needs a rebase onto this.

AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2)

@aslan2142
aslan2142 merged commit 627163c into ProjectLeonida:main Nov 26, 2026
2 of 5 checks passed
@aslan2142
aslan2142 deleted the vsharp-slot-records branch November 26, 2026 21:42
@enlight3d

Copy link
Copy Markdown
Contributor

A/B of this pull request on NVIDIA for #2464 part A ("NVIDIA device losses on main since d1dff7949 suspect it"). A = 20c46b6 (the commit before the merge), B = 627163c (the merge); same machine, recipe and cache states, runs alternated A cold, B cold, A warm, B warm. AI-assisted (Claude Code, Claude Opus 5.5).

PROVISIONAL (n=2 per side): no device loss and no GPU fault in any of the four runs, on either side. How far the runs got does not compare: in A cold and B warm the profile-selection page came up after the input script's last press (90 s), so those two runs stayed on it for the whole 20 minutes; A warm and B cold went into the story load. So only one run per side reached the heavy part of the load, and the result says nothing about losses later than that.

RUN ab2407-A-cold | 2026-11-27 | enlight3d | AI-assisted: Claude Code (Claude Opus 5.5)
BASE:        20c46b646 + none | shaders: one pack for A and B, make_game.py --stages check,shaders,runtime with that commit's translator (no translator change between A and B)
MACHINE:     RTX 3090 24 GB, desktop | NVIDIA 621.40 | Windows 11 Pro 26300 | 64 GB
RECIPE:      documented ("Windows, NVIDIA", mostly TBD, so scripts/windows-boot/boot.ps1 defaults) + DEVIATIONS: LEONIDA_PIPELINE_JOURNAL_SEED_DIR=<the precompile's journal>, LEONIDA_DEVICE_FAULT unset, LEONIDA_COMPUTE_WARMUP_LIVE_MAX_BYTES=131072, LEONIDA_RT_AS=off, LEONIDA_SKIP_COMPUTE=<the library programs over 2,500,000 B of SPIR-V>, LEONIDA_TITLE_WATCHDOG=0 + LEONIDA_TITLE_WATCHDOG_KICK=<local values>, LEONIDA_KEYBOARD_PAD=1, LEONIDA_CAPTURE_LIMIT=300, input script a@45,a@60,a@75,a@90 | precompile: yes, with B's gta6rt (--smallest-first --max-bytes 2500000 --threads 10), its journal read-only by both sides
OS/DRIVER:   Windows defaults (GPU timeout not changed)
TARGET:      device losses and how far | PREDICTED (written before the run): none written
MEASURED:    menu (the profile-selection page for the whole run, in the last captures) | duration 1,208 s | 27.0 frames/s median, 35.2 max; 28,913 presents; at draw 107 graphics pipelines, 90 compiled (225 s)
END:         time limit; no device loss, no GPU fault
CACHES:      cold for the runtime's own caches (this side's cache folder new and empty); the precompiled compute journal used; NVIDIA's driver cache not cleared | RUN 1 of 2 on this side, same recipe
INSTRUMENTS: LEONIDA_TRACE_PIPELINE_COMPILE=1, LEONIDA_DEV_OVERLAY=1, boot.ps1's --trace and --trace-d3d12, a capture every 60 frames
VERDICT:     no prediction written
RUN ab2407-B-cold | 2026-11-27 | enlight3d | AI-assisted: Claude Code (Claude Opus 5.5)
BASE:        627163c8e (merge of #2407) | shaders: one pack for A and B, make_game.py --stages check,shaders,runtime with that commit's translator (no translator change between A and B)
MACHINE:     RTX 3090 24 GB, desktop | NVIDIA 621.40 | Windows 11 Pro 26300 | 64 GB
RECIPE:      documented ("Windows, NVIDIA", mostly TBD, so scripts/windows-boot/boot.ps1 defaults) + DEVIATIONS: LEONIDA_PIPELINE_JOURNAL_SEED_DIR=<the precompile's journal>, LEONIDA_DEVICE_FAULT unset, LEONIDA_COMPUTE_WARMUP_LIVE_MAX_BYTES=131072, LEONIDA_RT_AS=off, LEONIDA_SKIP_COMPUTE=<the library programs over 2,500,000 B of SPIR-V>, LEONIDA_TITLE_WATCHDOG=0 + LEONIDA_TITLE_WATCHDOG_KICK=<local values>, LEONIDA_KEYBOARD_PAD=1, LEONIDA_CAPTURE_LIMIT=300, input script a@45,a@60,a@75,a@90 | precompile: yes, with B's gta6rt (--smallest-first --max-bytes 2500000 --threads 10), its journal read-only by both sides
OS/DRIVER:   Windows defaults (GPU timeout not changed)
TARGET:      device losses and how far | PREDICTED (written before the run): none written
MEASURED:    story load (the frame rate collapses after about 420 s; the last capture is black) | duration 1,216 s | 24.8 frames/s median, 30.0 max; 8,764 presents; at draw 480 graphics pipelines, 439 compiled (1,439 s)
END:         time limit; no device loss, no GPU fault
CACHES:      cold for the runtime's own caches (this side's cache folder new and empty); the precompiled compute journal used; NVIDIA's driver cache not cleared | RUN 1 of 2 on this side, same recipe
INSTRUMENTS: LEONIDA_TRACE_PIPELINE_COMPILE=1, LEONIDA_DEV_OVERLAY=1, boot.ps1's --trace and --trace-d3d12, a capture every 60 frames
VERDICT:     no prediction written
RUN ab2407-A-warm | 2026-11-27 | enlight3d | AI-assisted: Claude Code (Claude Opus 5.5)
BASE:        20c46b646 + none | shaders: one pack for A and B, make_game.py --stages check,shaders,runtime with that commit's translator (no translator change between A and B)
MACHINE:     RTX 3090 24 GB, desktop | NVIDIA 621.40 | Windows 11 Pro 26300 | 64 GB
RECIPE:      documented ("Windows, NVIDIA", mostly TBD, so scripts/windows-boot/boot.ps1 defaults) + DEVIATIONS: LEONIDA_PIPELINE_JOURNAL_SEED_DIR=<the precompile's journal>, LEONIDA_DEVICE_FAULT unset, LEONIDA_COMPUTE_WARMUP_LIVE_MAX_BYTES=131072, LEONIDA_RT_AS=off, LEONIDA_SKIP_COMPUTE=<the library programs over 2,500,000 B of SPIR-V>, LEONIDA_TITLE_WATCHDOG=0 + LEONIDA_TITLE_WATCHDOG_KICK=<local values>, LEONIDA_KEYBOARD_PAD=1, LEONIDA_CAPTURE_LIMIT=300, input script a@45,a@60,a@75,a@90 | precompile: yes, with B's gta6rt (--smallest-first --max-bytes 2500000 --threads 10), its journal read-only by both sides
OS/DRIVER:   Windows defaults (GPU timeout not changed)
TARGET:      device losses and how far | PREDICTED (written before the run): none written
MEASURED:    story load (the frame rate collapses from about 240 s, at most 0.6 frames/s afterwards) | duration 1,208 s | 23.5 frames/s median, 32.0 max; 5,584 presents; at draw 608 graphics pipelines, 515 compiled (1,517 s)
END:         time limit; no device loss, no GPU fault
CACHES:      warm: this side's session and heavy caches from A cold, the precompiled compute journal | RUN 2 of 2 on this side, same recipe
INSTRUMENTS: LEONIDA_TRACE_PIPELINE_COMPILE=1, LEONIDA_DEV_OVERLAY=1, boot.ps1's --trace and --trace-d3d12, a capture every 60 frames
VERDICT:     no prediction written
RUN ab2407-B-warm | 2026-11-27 | enlight3d | AI-assisted: Claude Code (Claude Opus 5.5)
BASE:        627163c8e (merge of #2407) | shaders: one pack for A and B, make_game.py --stages check,shaders,runtime with that commit's translator (no translator change between A and B)
MACHINE:     RTX 3090 24 GB, desktop | NVIDIA 621.40 | Windows 11 Pro 26300 | 64 GB
RECIPE:      documented ("Windows, NVIDIA", mostly TBD, so scripts/windows-boot/boot.ps1 defaults) + DEVIATIONS: LEONIDA_PIPELINE_JOURNAL_SEED_DIR=<the precompile's journal>, LEONIDA_DEVICE_FAULT unset, LEONIDA_COMPUTE_WARMUP_LIVE_MAX_BYTES=131072, LEONIDA_RT_AS=off, LEONIDA_SKIP_COMPUTE=<the library programs over 2,500,000 B of SPIR-V>, LEONIDA_TITLE_WATCHDOG=0 + LEONIDA_TITLE_WATCHDOG_KICK=<local values>, LEONIDA_KEYBOARD_PAD=1, LEONIDA_CAPTURE_LIMIT=300, input script a@45,a@60,a@75,a@90 | precompile: yes, with B's gta6rt (--smallest-first --max-bytes 2500000 --threads 10), its journal read-only by both sides
OS/DRIVER:   Windows defaults (GPU timeout not changed)
TARGET:      device losses and how far | PREDICTED (written before the run): none written
MEASURED:    menu (the profile-selection page for the whole run, in the last captures) | duration 1,201 s | 30.9 frames/s median, 42.7 max; 37,379 presents; at draw 3 graphics pipelines, 1 compiled
END:         time limit; no device loss, no GPU fault
CACHES:      warm: this side's session and heavy caches from B cold, the precompiled compute journal | RUN 2 of 2 on this side, same recipe
INSTRUMENTS: LEONIDA_TRACE_PIPELINE_COMPILE=1, LEONIDA_DEV_OVERLAY=1, boot.ps1's --trace and --trace-d3d12, a capture every 60 frames
VERDICT:     no prediction written

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.

2 participants