vkback/shader: clamp view indices (typed and raw twins) to the title's null slot #206

Manually merged
github merged 2 commits from github-bot/gh-206 into gh-pr/206/base 2026-12-02 20:12:48 +00:00 AGit
Owner

@⁠lordra9-svg on GitHub · 2026-12-02 12:07 UTC · original
lordra9-svg:fix/view-heap-null-slot → main · +235 −36 · 11 files · 2 commits · merged 2026-12-02 20:07 UTC

What

docs/TASKS.md:1265: a garbage view index could read past its typed binding or past the raw twins.

  • The translator clamped view indices to VKBACK_RAW_VIEWS - 1 = 2,097,151, but each typed binding holds HEAP_SLOTS = 1,245,184 slots, so an index in [1,245,184, 2,097,151] read past binding 0-3/6's array (for binding 6, past the descriptor buffer) instead of a null.
  • Lower::raw_twin clamped a garbage title index to 2^21-1 then OR'd 2^21, giving 2^22-1 = 4,194,303, past bindings 4/5's 3,342,337 slots (binding 4 into 5, binding 5 into binding 6's UBO).

Change

  • vkback desc_counts keeps one reserve slot per typed binding (typed = heap_slots + 1); null_fill already fills it null. VKBACK_HEAP_SLOTS = 1,245,184 shared with the translator (slot_tables_match_the_translator asserts equality).
  • set_view_heap_limit(VKBACK_HEAP_SLOTS) (was VKBACK_RAW_VIEWS - 1), so a typed index >= HEAP_SLOTS reads the reserve null slot.
  • Lower::raw_twin clamps to the same limit before OR-ing the twin base, so the largest twin index is RAW_TWIN + HEAP_SLOTS = 3,342,336, exactly the twin null slot; with no heap limit it keeps the old first - 1 fallback.
  • TRANSLATOR_VERSION 13 -> 14 (the emitted clamp changed); desc_counts is pub so vk-mutprobe uses the single formula.

Verified

  • cargo test -p victory-shader --lib: 243 passed (2 new: garbage twin index clamps to the twin null slot; fallback without a heap limit).
  • cargo test -p vkback --lib: 169 passed; policy 6; cargo test -p frame --lib 13; clippy -D warnings clean; tools/build.sh exit 0.
  • Validation run (VK_LAYER_KHRONOS_validation, house save, 220 s): only the four known VUIDs (06409 x4, 01687/01688/03428 x20 each), no new errors, no device loss.
  • In-game (no layer): 30 fps in world, no device loss.
  • Device limits: per typed binding 1,245,185 (7.1M headroom); storage-buffer pair 6,684,674 of 8,388,606.

Notes

A latent safety fix (indices seen to be garbage), so no picture change is expected; the evidence is the clamp constants and the clean validation run.

**@⁠lordra9-svg** on GitHub · 2026-12-02 12:07 UTC · [original](https://github.com/vktory6/VKtory/pull/206) `lordra9-svg:fix/view-heap-null-slot` → `main` · +235 −36 · 11 files · 2 commits · merged 2026-12-02 20:07 UTC ## What `docs/TASKS.md:1265`: a garbage view index could read past its typed binding or past the raw twins. - The translator clamped view indices to `VKBACK_RAW_VIEWS - 1 = 2,097,151`, but each typed binding holds `HEAP_SLOTS = 1,245,184` slots, so an index in `[1,245,184, 2,097,151]` read past binding 0-3/6's array (for binding 6, past the descriptor buffer) instead of a null. - `Lower::raw_twin` clamped a garbage title index to `2^21-1` then OR'd `2^21`, giving `2^22-1 = 4,194,303`, past bindings 4/5's `3,342,337` slots (binding 4 into 5, binding 5 into binding 6's UBO). ## Change - vkback `desc_counts` keeps **one reserve slot per typed binding** (`typed = heap_slots + 1`); `null_fill` already fills it null. `VKBACK_HEAP_SLOTS = 1,245,184` shared with the translator (`slot_tables_match_the_translator` asserts equality). - `set_view_heap_limit(VKBACK_HEAP_SLOTS)` (was `VKBACK_RAW_VIEWS - 1`), so a typed index `>= HEAP_SLOTS` reads the reserve null slot. - `Lower::raw_twin` clamps to the same limit before OR-ing the twin base, so the largest twin index is `RAW_TWIN + HEAP_SLOTS = 3,342,336`, exactly the twin null slot; with no heap limit it keeps the old `first - 1` fallback. - `TRANSLATOR_VERSION` 13 -> 14 (the emitted clamp changed); `desc_counts` is `pub` so `vk-mutprobe` uses the single formula. ## Verified - `cargo test -p victory-shader --lib`: **243 passed** (2 new: garbage twin index clamps to the twin null slot; fallback without a heap limit). - `cargo test -p vkback --lib`: 169 passed; policy 6; `cargo test -p frame --lib` 13; clippy `-D warnings` clean; `tools/build.sh` exit 0. - **Validation run** (`VK_LAYER_KHRONOS_validation`, house save, 220 s): only the four known VUIDs (06409 x4, 01687/01688/03428 x20 each), **no new errors**, no device loss. - In-game (no layer): 30 fps in world, no device loss. - Device limits: per typed binding 1,245,185 (7.1M headroom); storage-buffer pair 6,684,674 of 8,388,606. ## Notes A latent safety fix (indices seen to be garbage), so no picture change is expected; the evidence is the clamp constants and the clean validation run.
set_vkback_host clamped every typed view index to VKBACK_RAW_VIEWS - 1
(2^21 - 1), but since #34 each typed binding holds only the title's
1,245,184 slots. A garbage index in [HEAP_SLOTS, 2^21) read into the next
binding, or past binding 6's descriptor buffer, instead of a null.

Give each typed binding one reserve slot (typed = heap_slots + 1, twin =
typed + RAW_TWIN) and clamp to it: VKBACK_HEAP_SLOTS = 1,245,184, checked
equal to vkback's HEAP_SLOTS. The slot stays null: null_fill fills the
whole array with the null descriptor, and slotwrite.rs refuses any title
index at or past cfg.heap_slots.

The raw-twin clamp had the same gap: min(index, raw_views - 1) | raw_views
reaches 2^22 - 1, past binding 4/5. Clamp the title index to the view heap
limit first, so the twin index is raw_views + VKBACK_HEAP_SLOTS, the null
slot past the twins (fallback: the old raw_views - 1 when no heap limit is
set). Bump TRANSLATOR_VERSION for the changed clamp.

Typed counts grow by one per binding (1,245,185 typed, 3,342,337 per twin
binding), still under the device's 8,388,606 per type.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 12:08:12 +00:00
Conflicts with #169 (set_vkback_host(lanes, rdna)): kept #169's signature, the views'
raw/heap clamp goes through vkback_view_settings(), the test checks raw/heap only.
TRANSLATOR_VERSION 15 (main is at 14 after #180).
github-bot changed target branch from main to gh-pr/206/base 2026-12-02 20:12:47 +00:00
github manually merged commit eaa0aece5c into gh-pr/206/base 2026-12-02 20:12:48 +00:00
Author
Owner

@⁠vktory6 on GitHub · 2026-12-02 20:07 UTC · original

Merged, thanks. We merged main into your branch. It conflicted with #169's set_vkback_host(lanes, rdna): we kept that signature, your raw/heap clamp now goes through vkback_view_settings(), and the test checks raw and heap only. TRANSLATOR_VERSION is 15, after #180's 14.

On the reference card: the card tests pass on the merged state (345). The whole-store diff on your branch translated all 19,112 shaders with 0 failures; 18,732 changed, the clamp constant as expected. Your validation run (only the four listed errors) covers the new descriptor counts.

The translator's direction, including what the emitted clamps should look like, is being discussed in https://github.com/vktory6/VKtory/discussions/270.

**@⁠vktory6** on GitHub · 2026-12-02 20:07 UTC · [original](https://github.com/vktory6/VKtory/pull/206#issuecomment-7357252461) Merged, thanks. We merged main into your branch. It conflicted with #169's `set_vkback_host(lanes, rdna)`: we kept that signature, your raw/heap clamp now goes through `vkback_view_settings()`, and the test checks raw and heap only. `TRANSLATOR_VERSION` is 15, after #180's 14. On the reference card: the card tests pass on the merged state (345). The whole-store diff on your branch translated all 19,112 shaders with 0 failures; 18,732 changed, the clamp constant as expected. Your validation run (only the four listed errors) covers the new descriptor counts. The translator's direction, including what the emitted clamps should look like, is being discussed in https://github.com/vktory6/VKtory/discussions/270.
This discussion has been locked. Commenting is limited to contributors.
No description provided.