Skip to content

d3d12: never defer buffer V#s past console-fix budget (RT-CONSOLE-FIX-NEVER-DEFER-BUFFER-VSHARP) - #2162

Merged
aslan2142 merged 1 commit into
ProjectLeonida:mainfrom
abnalstlll-byte:feat/rt-console-fix-never-defer-buffer-vsharp
Nov 26, 2026
Merged

aslan2142 merged 1 commit into
ProjectLeonida:mainfrom
abnalstlll-byte:feat/rt-console-fix-never-defer-buffer-vsharp

Conversation

@abnalstlll-byte

Copy link
Copy Markdown
Contributor

Claimed in Issue #1608: RT-CONSOLE-FIX-NEVER-DEFER-BUFFER-VSHARP.

What and why

In fix_console_slots() (runtime/shims/d3d12_vulkan_device.cpp), when the LEONIDA_CONSOLE_FIX_US submission budget expires (heap.fix_over == true), the code currently zeroes every remaining descriptor slot and defers them to retry_console_slots.

Nulling buffer descriptor slots (V#s) causes compute shaders during the world transition (e.g. lib_cs_01144) to divide by 0 or read zero loop bounds from buffer descriptors, causing an infinite loop and GPU device loss.

Buffer V# descriptors (!(w3 >> 30)) only rebase virtual addresses and are fast to process without causing submission stalls (the 28s freeze is driven by thousands of image T# descriptors performing image binding and view lookups).

This change ensures that buffer V# descriptors are never nulled or deferred when the fix budget expires: they are always resolved in-place with fix_console_slot, while image T# descriptors continue to be safely deferred to retry_console_slots.

Testing

  • console_heap_vsharp_slots_test: added test_console_fix_budget_buffer_vsharp_non_deferral() verifying that under fix_over == true, buffer V# descriptors are preserved live while image T#s are deferred and nulled. Passed (100%).
  • vk_console_heap_gpu_test: passed on NVIDIA GeForce RTX 5060 Ti.
  • scripts/check_no_game_data.py: passed (0 violations).
  • tests/test_text_write_line_endings.py: passed.

AI-assisted (Claude Code).

…-NEVER-DEFER-BUFFER-VSHARP)

In fix_console_slots, when the LEONIDA_CONSOLE_FIX_US budget expires, do not null or defer buffer descriptors (!(w3 >> 30)). Only defer image T# descriptors to retry_console_slots.

Buffer V# descriptors only rebase address offsets and are fast to fix, whereas image T#s perform costly texture lookups and view creation. Compute shaders during world transition (e.g. lib_cs_01144) read loop bounds and record counts from buffer descriptors; nulling them causes infinite loops and device loss.

Tested with console_heap_vsharp_slots_test and vk_console_heap_gpu_test.

AI-assisted (Claude Code).
@moffington

Copy link
Copy Markdown
Contributor

Checked 2769c5a7 on Linux (AMD Ryzen 5 5600X3D, NVIDIA GeForce RTX 3060, driver 615.78.08) and Windows/Wine (clang-cl 23.1.3 + xwin SDK 10.0.26100).

  • console_heap_vsharp_slots_test: passed at both merge-base (61732aca) and head (2769c5a7) on Linux (g++ 16.2.1, RelWithDebInfo and ASan+UBSan -Wall -Wextra -Werror) and under Wine.
  • d3d12_vulkan_device_test and d3d12_console_descriptor_heap_test (with LEONIDA_CONSOLE_FIX_US=1): built cleanly with clang-cl and passed under Wine on RTX 3060.
  • Code check: in DeviceState::fix_console_slots() (runtime/shims/d3d12_vulkan_device.cpp), !(w3 >> 30) at heap.previous + at + 12 matches fix_console_slot()'s buffer V# classification.
  • Coverage limitation: test_console_fix_budget_buffer_vsharp_non_deferral() in console_heap_vsharp_slots_test.cpp simulates the !(w3 >> 30) deferral branch inline on a local array rather than calling DeviceState::fix_console_slots(), and no existing runtime/test/ target exercises LEONIDA_CONSOLE_FIX_US budget expiry through fix_console_slots().

AI-assisted.

@moffington

Copy link
Copy Markdown
Contributor

Follow-up negative control on 2769c5a7 (coverage gap, not a defect in the d3d12_vulkan_device.cpp fix itself):

  • Compiling #2162 HEAD's runtime/test/console_heap_vsharp_slots_test.cpp against merge-base (61732aca) runtime/src — i.e., with the DeviceState::fix_console_slots() change reverted — still builds and passes (console_heap_vsharp_slots_test: ok).
  • This confirms test_console_fix_budget_buffer_vsharp_non_deferral() would not catch a regression in fix_console_slots(), since it only exercises an inline local array rather than the production DeviceState::fix_console_slots() path.

AI-assisted.

@aslan2142
aslan2142 merged commit 6a405cd into ProjectLeonida:main Nov 26, 2026
5 of 12 checks passed
@aslan2142

Copy link
Copy Markdown
Collaborator

Thank you, @abnalstlll-byte. This went into main through #2350 (RT-LINUX-AMD-WORLD), merged at your head 2769c5a73 with your commits and authorship kept. The one conflict, in fix_console_slots, came from a host-RAM mirror of the heap copy in the same PR. Your buffer-V# exception was kept, and the zeroing now goes through heap.copy.zero(). GitHub shows this PR as merged for that reason, so nothing needs closing.

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

aslan2142 added a commit that referenced this pull request Nov 26, 2026
Both came in with #2350 as additions on top of stopgap mechanisms, broke world runs (remap release: a GPUVM page
fault and a lost device; the mirror: a GPU hang) and were made opt-in by #2356. They go completely; with both
variables unset, main behaves as before.

Remap release (LEONIDA_GEOMETRY_REMAP_RELEASE, from 36771ec):
- xmem.cpp: RemapReleases, remap_releases_enabled() and the page recording in unmap_range_locked; the four call
  sites (XMemMapPhysicalPages, the scatter call, both copy_page_mappings).
- xmem.h/xmem.cpp: the test seam rt::xmem::reload_remap_release_setting().
- xmem_test: test_remap_releases (and the title_geometry_watch.h include only it used).
- README row, the docs/d3d12_vulkan.md paragraph; comments that named it.

Console heap mirror (LEONIDA_HEAP_MIRROR, LEONIDA_HEAP_MIRROR_CHECK, from 7460590):
- src/console_heap_copy.h goes. ConsoleHeap::copy is a plain std::uint8_t* again, written with memcpy/memset as
  before the mirror, including the zeroing site that #2350's merge of #2162 resolved as heap.copy.zero(); the
  compute-input probe reads it directly again. Without the mirror, view() was the copy itself, so nothing changes.
- heap_mirror_enabled(), heap_mirror_check_enabled(), check_console_heap_mirror(), the per-heap check counters and
  log line, and the test API console_heap_mirror_mismatches() (d3d12_com.h).
- Tests console_heap_copy, d3d12_console_heap_mirror, _off and _default with their CMake entries; README rows and
  the docs/d3d12_vulkan.md sentences.

Kept, because other paths use them or main's behaviour with the variable unset depends on them:
- LEONIDA_GEOMETRY_HOST and its DeviceState memory-type assert (dc9ef1a).
- The final copy at retirement (GeometryViews::retire_range's final_copy, "copied at retirement" in the geometry
  buffers line): XMemFree of a title heap block (free_title_block) reports a release while the block's memory stays
  committed and readable, so that copy is still made without remap release. Comments now say that instead of
  naming remaps; geometry_views_test case 15 stays.
- forget_pool_span and "retired with their copy" in the title memory line: any retirement (free, decommit, unmap)
  feeds it.
- The release queue's joining of touching ranges (title_geometry_watch.h): unmaps report page runs too;
  geometry_views_test case 16 stays.
- LEONIDA_CONSOLE_RELEASE_FILTER, which predates the mirror; its sweep reads the copy again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

3 participants