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

Closed
Undefined3301 wants to merge 1 commit from upstream-pr/2109 into main
Undefined3301 commented 2026-11-25 21:00:43 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Undefined3301 on 2026-11-25T21:00:43Z.


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

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5499098383 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2109). Originally posted by [Undefined3301](https://github.com/Undefined3301) on 2026-11-25T21:00:43Z. --- 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).
Undefined3301 commented 2026-11-25 23:45:13 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Undefined3301 on 2026-11-25T23:45:13Z.


Closing this; not pursuing the contribution.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7178000828 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2109#issuecomment-7178000828). Originally posted by [Undefined3301](https://github.com/Undefined3301) on 2026-11-25T23:45:13Z. --- Closing this; not pursuing the contribution.

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!2109
No description provided.