[PR #2109] [CLOSED] rt: bound V# offsets to the translator signed 48-bit range (SHADER-VSHARP-47-BOUND) #2115

Closed
opened 2026-11-26 21:20:05 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2109
Author: @Undefined3301
Created: 11/25/2026
Status: ❌ Closed

Base: main ← Head: rt-vsharp-47-bound


📝 Commits (1)

  • 338a32b rt: bound V# offsets to the translator's signed 48-bit range

📊 Changes

6 files changed (+99 additions, -8 deletions)

View changed files

📝 docs/design.md (+1 -1)
📝 runtime/CMakeLists.txt (+7 -1)
📝 runtime/shims/d3d12_vulkan_device.cpp (+25 -5)
➕ runtime/src/vsharp_range.h (+16 -0)
📝 runtime/test/d3d12_title_va_test.cpp (+2 -1)
➕ runtime/test/vsharp_range_test.cpp (+48 -0)

📄 Description

Item: SHADER-VSHARP-47-BOUND

What and why

Every translated shader reads a V#'s 48-bit base sign-extended from bit 47 (docs/design.md, "Heap-relative buffer device addresses"). vsharp_address accepted any positive offset below 2^48, so a base in [2^47, 2^48) became a device address 2^48 lower — a wild read (one such base produced a fault at 0xffff...).

This adds runtime/src/vsharp_range.h with the portable predicate the runtime uses:

  • a positive offset must stay below 2^47 (and the access fit below it);
  • a negative offset may reach -2^47 (the signed range of the 48-bit field).

vsharp_address's encodable uses it, and a slot-133 import whose device address would need bit 47 above the arena takes the arena shadow instead (its console VA is then an arena offset, which is always in range). A base outside the range is refused and the slot gets the existing no-records treatment.

Tests

  • runtime/test/vsharp_range_test.cpp (new, portable): the boundaries, a below-arena buffer, and the sign-extension equivalence.
  • runtime/test/d3d12_title_va_test.cpp: extra cases for the refused range.
  • Measured on RTX 4080 / NVIDIA 621.24: the related ctests pass (11/11, including d3d12_title_va, d3d12_indirect_rt, d3d12_mesh, d3d12_console_descriptor_heap) and the retail boot with below-arena imports is unchanged (LEONIDA_IMPORT_BELOW_ARENA=1, same frame rate, no new faults).

No game files are needed for the tests.

AI-assisted: yes (Claude Code patch series, reviewed and carried over by DeepSeek V4.1 Flash via OpenCode/T3 Code).


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/2109 **Author:** [@Undefined3301](https://github.com/Undefined3301) **Created:** 11/25/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `rt-vsharp-47-bound` --- ### 📝 Commits (1) - [`338a32b`](https://github.com/ubiquitarianism/leonida/commit/338a32b817705fb583b25393623f3f9782879011) rt: bound V# offsets to the translator's signed 48-bit range ### 📊 Changes **6 files changed** (+99 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `docs/design.md` (+1 -1) 📝 `runtime/CMakeLists.txt` (+7 -1) 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+25 -5) ➕ `runtime/src/vsharp_range.h` (+16 -0) 📝 `runtime/test/d3d12_title_va_test.cpp` (+2 -1) ➕ `runtime/test/vsharp_range_test.cpp` (+48 -0) </details> ### 📄 Description Item: SHADER-VSHARP-47-BOUND ## What and why Every translated shader reads a V#'s 48-bit base sign-extended from bit 47 (docs/design.md, "Heap-relative buffer device addresses"). `vsharp_address` accepted any positive offset below 2^48, so a base in `[2^47, 2^48)` became a device address 2^48 lower — a wild read (one such base produced a fault at `0xffff...`). This adds `runtime/src/vsharp_range.h` with the portable predicate the runtime uses: - a positive offset must stay below `2^47` (and the access fit below it); - a negative offset may reach `-2^47` (the signed range of the 48-bit field). `vsharp_address`'s `encodable` uses it, and a slot-133 import whose device address would need bit 47 above the arena takes the arena shadow instead (its console VA is then an arena offset, which is always in range). A base outside the range is refused and the slot gets the existing no-records treatment. ## Tests - `runtime/test/vsharp_range_test.cpp` (new, portable): the boundaries, a below-arena buffer, and the sign-extension equivalence. - `runtime/test/d3d12_title_va_test.cpp`: extra cases for the refused range. - Measured on RTX 4080 / NVIDIA 621.24: the related ctests pass (11/11, including `d3d12_title_va`, `d3d12_indirect_rt`, `d3d12_mesh`, `d3d12_console_descriptor_heap`) and the retail boot with below-arena imports is unchanged (`LEONIDA_IMPORT_BELOW_ARENA=1`, same frame rate, no new faults). No game files are needed for the tests. AI-assisted: yes (Claude Code patch series, reviewed and carried over by DeepSeek V4.1 Flash via OpenCode/T3 Code). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 21:20:05 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#2115
No description provided.