Skip to content

d3d12: translate GPU-view V#s and guard untranslated title V#s (RT-UNTRANSLATED-VSHARP-GUARD) - #1728

Open
TanmaySatyam wants to merge 1 commit into
ProjectLeonida:mainfrom
TanmaySatyam:fix/rt-untranslated-vsharp-guard
Open

TanmaySatyam wants to merge 1 commit into
ProjectLeonida:mainfrom
TanmaySatyam:fix/rt-untranslated-vsharp-guard

Conversation

@TanmaySatyam

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: RT-UNTRANSLATED-VSHARP-GUARD (#1608 (comment))

What and why

When resolve_title_memory or rebase_title_vsharp encounters a title-memory buffer V# in either an explicit descriptor table (scan_title_table) or the directly-indexed console resource heap (fix_console_slot), three gaps can leave an unrebased raw title virtual address in the live GPU descriptor heap, causing READ_INVALID / WRITE_INVALID (VK_ERROR_DEVICE_LOST):

  1. GPU-only title views not mapped in resolve_title_memory / rebase_title_vsharp: resolve_title_memory and rebase_title_vsharp checked aliases.title_memory(base) directly without mapping GPU-only views through leonida::title_gpu_views::to_cpu(base, span).
  2. Decoded title-memory V#s in console heap rebasing: when LEONIDA_GEOMETRY_MB is set (heap.scratch != nullptr), fix_console_slot passed make_window = false, so decoded title-memory V#s within kTitleWindowMax that geometry_va did not claim could not fall back to aliases.resolve(..., table_view).
  3. Unresolvable raw title V#s reaching the GPU: when rebase_title_vsharp returns false on a decoded title-memory V# (e.g. uncommitted page, over-cap window, or unmapped GPU-only address), copying the original words leaves a raw title VA in the GPU descriptor heap.

This adds a portable standalone helper runtime/src/title_vsharp_guard.h (leonida::title_vsharp_guard::redirect_untranslated_vsharp) with deterministic unit tests in runtime/test/title_vsharp_guard_test.cpp and hooks it into runtime/shims/d3d12_vulkan_device.cpp:

  • Maps GPU-only title views via leonida::title_gpu_views::to_cpu in resolve_title_memory and rebase_title_vsharp.
  • Allows decoded title-memory V#s within kTitleWindowMax in rebase_title_vsharp to request a title window via aliases.resolve.
  • Redirects any remaining unresolvable raw title-memory V# to a lazily allocated 64 KiB zeroed arena scratch range with num_records = 0 (w[2] = 0) so translated buffer loads return 0 and buffer stores drop OOB instead of faulting the GPU. Leaves null descriptors, image T#s, arena VAs, known GPU buffer VAs (host imports / geometry views), and non-V# data untouched.

Tested

  • ctest -R "^(title_vsharp_guard|title_va_alias|d3d12_existing_heap|d3d12_descriptor|d3d12_console_descriptor_heap)$" with LEONIDA_VK_VALIDATION=1 -> 5/5 passed (0 VUIDs)
  • title_vsharp_guard_test covers 8 deterministic cases (null, T#, arena VA, known GPU VA, non-title address, raw title V#, GPU-only view V#, unavailable scratch) with no GPU or game files
  • python -I scripts/check_no_game_data.py runtime/src/title_vsharp_guard.h runtime/test/title_vsharp_guard_test.cpp runtime/shims/d3d12_vulkan_device.cpp runtime/CMakeLists.txt -> exit 0

GPUs tested: NVIDIA GeForce RTX 5070 (Windows 11, MSVC RelWithDebInfo, Vulkan validation enabled, 0 VUIDs)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a)

…TRANSLATED-VSHARP-GUARD)

Maps GPU-only title views via title_gpu_views::to_cpu in resolve_title_memory and rebase_title_vsharp, allows decoded title-memory V#s within kTitleWindowMax to resolve title windows in console heap rebasing, and redirects any remaining unresolvable raw title-memory V# to a zeroed arena scratch slot with num_records=0 via runtime/src/title_vsharp_guard.h. Adds portable unit tests in runtime/test/title_vsharp_guard_test.cpp.
@HasiKe

HasiKe commented Nov 25, 2026

Copy link
Copy Markdown

Tested this branch (4ebe446) against the retail 1.0.2.1 boot on an NVIDIA GeForce RTX 2070 SUPER (driver 616.56, Windows 11, LEONIDA_D3D12=vulkan, LEONIDA_CONSOLE_D16S8=native). The device loss during the world load is still there, so this does not cover the case I hit:

  • Reproducible with a recorded LEONIDA_INPUT_SCRIPT; VK_ERROR_DEVICE_LOST 200-460 s in, on this branch and on c7e82e2.
  • VK_LAYER_LUNARG_crash_diagnostic + VK_EXT_device_fault, 4 dumps: the incomplete command buffer is always on the dedicated compute family (2), a single vkCmdDispatch (28 or 241 groups) right after push constants. The fault is an Invalid Read at an address in the title's CPU range (e.g. 0x2281E7AB000), plus an instruction-pointer record.
  • Every run logs title memory named by a shader address is past LEONIDA_TITLE_WINDOWS_MB, left untranslated before the loss: at the 64 MiB default, and still once at 512 MiB.
  • Not the cause: a 4095 MiB arena (no more "does not fit the GPU address arena" lines, same loss), and RehydrateRaytracingAccelerationStructureBatched2X (its E_NOTIMPL comes after the loss).

Hypothesis, not confirmed: the shader reaches the untranslated address through a raw 64-bit pointer loaded from memory rather than through a buffer V#, which a V# guard cannot redirect. Naming pipelines with VK_EXT_debug_utils would let the dump name the shader; I can rerun with that if it helps.

AI-assisted (Claude Code); logs and dumps stay on my machine.

@aslan2142

Copy link
Copy Markdown
Collaborator

Thanks, @TanmaySatyam. #1723 was merged just before this PR opened, and it covers most of it:

  • Inline-table and console-heap V#s go through fix_vsharp; one with no backing gets zero records, the same as the guard here.
  • rebase_title_vsharp is no longer called.
  • GPU-only stream-pool views resolve through resolve_pool_memory.

The one piece main doesn't have is the window request for decoded V#s on the console scratch path. That may matter: on a retail run here, main still wrote a few hundred title-memory views with no GPU copy. Could you merge main and keep only that piece, on top of fix_vsharp, with a test?

Two more things:

  • In fix_console_slot, the retry check reads the base after the guard has rewritten it, so a slot whose page wasn't committed yet is never retried (main keeps those in empty_slots).
  • Please name the model in the AI note.

AI-assisted (Claude Code, Claude Opus 5.5).

@PierreEbele

Copy link
Copy Markdown
Contributor

Reviewed 4ebe446: read the diff (4 files); ran the CMake-parsing Python tests on this tree and main (pass); the new C++ test could not be built here (no C++ toolchain available). git merge-tree shows conflicts with current main in runtime/CMakeLists.txt and d3d12_vulkan_device.cpp. Main's #1723 chain, merged after this PR's base, already covers it: fix_vsharp writes unbacked V#s as zero-records across the inline-table, console-shadow and console-scratch paths - including each slot's counter V#, which this guard skips - and d3d12_unmapped_vsharp_test pins the behavior. Unless there is an angle fix_vsharp does not cover, closing in favor of main seems right. One reading note (not reproduced): the guard settles a console-heap slot on first failure, dropping the retry a late-committing page used to get.

AI-assisted review.

Recommendation: Close

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

Labels

needs rebase Conflicts with the base branch: rebase it on main

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants