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

Closed
TanmaySatyam wants to merge 1 commit from upstream-pr/1728 into main
TanmaySatyam commented 2026-11-25 09:54:14 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TanmaySatyam on 2026-11-25T09:54:14Z.


Claimed in the coordination issue as: RT-UNTRANSLATED-VSHARP-GUARD (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7158772853)

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)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5489019902 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1728). Originally posted by [TanmaySatyam](https://github.com/TanmaySatyam) on 2026-11-25T09:54:14Z. --- Claimed in the coordination issue as: RT-UNTRANSLATED-VSHARP-GUARD (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7158772853) ### 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 - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] 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)
HasiKe commented 2026-11-25 12:32:31 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by HasiKe on 2026-11-25T12:32:31Z.


Tested this branch (4ebe44664) 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 c7e82e26e.
  • 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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7162514907 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1728#issuecomment-7162514907). Originally posted by [HasiKe](https://github.com/HasiKe) on 2026-11-25T12:32:31Z. --- Tested this branch (4ebe44664) 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 c7e82e26e. - `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 commented 2026-11-25 14:42:39 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-11-25T14:42:39Z.


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).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7165694598 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1728#issuecomment-7165694598). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-11-25T14:42:39Z. --- 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 commented 2026-11-25 18:12:25 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by PierreEbele on 2026-11-25T18:12:25Z.


Reviewed 4ebe44664: 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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7170589070 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1728#issuecomment-7170589070). Originally posted by [PierreEbele](https://github.com/PierreEbele) on 2026-11-25T18:12:25Z. --- Reviewed 4ebe44664: 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
DadaCap commented 2026-11-28 10:34:40 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-28T10:34:40Z.


Thanks for the contribution! This PR was reviewed by the maintainers and is being closed as part of a large batch of closures.

Reason: superseded by main.

If this looks like a mistake, mention @DadaCap here at any time and it will be looked at again.

AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7237986627 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1728#issuecomment-7237986627). Originally posted by [DadaCap](https://github.com/DadaCap) on 2026-11-28T10:34:40Z. --- Thanks for the contribution! This PR was reviewed by the maintainers and is being closed as part of a large batch of closures. Reason: superseded by main. If this looks like a mistake, mention @DadaCap here at any time and it will be looked at again. AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!1728
No description provided.