[PR #326] runtime: the index buffer view size bounds the index fetch in the Vulkan replay (reads past the view are 0) #378

Open
opened 2026-11-26 20:17:41 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/326
Author: @Andretuta
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: old-pr/10061


📝 Commits (6)

  • 7c56e90 fix: index buffer view SizeInBytes bounds the index fetch; reads outside the view are 0
  • 561a063 fix: a draw that crosses the index view's end reads index 0 past it, from a staged copy
  • fc9b2f3 fix: scratch buffers allow index-buffer use for the staged index copy
  • 3e70e82 fix: bound null index views to zero page
  • 74fc913 test: the null index view test releases its buffers before the device proxy reference check
  • 5f86fa5 test: replay_index_view_test covers the index view bounds in prepare_draw without a GPU

📊 Changes

5 files changed (+288 additions, -11 deletions)

View changed files

📝 runtime/CMakeLists.txt (+7 -0)
📝 runtime/src/vulkan_replay.h (+58 -6)
📝 runtime/src/vulkan_scratch.h (+2 -1)
📝 runtime/test/d3d12_draw_test.cpp (+87 -4)
➕ runtime/test/replay_index_view_test.cpp (+134 -0)

📄 Description

Carried over from old PR 10061 by tedin7 in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/10061, exactly that PR's last commit. All carried-over PRs are listed in #17.
Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it.
tedin7: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one.


Original description (mentions and #N references are disabled; the numbers refer to the old repository):

What

An indexed draw now honours the index buffer view's SizeInBytes in the Vulkan replay (prepare_draw, runtime/src/vulkan_replay.h):

  • draw wholly inside the view: the buffer is bound as before;
  • draw wholly outside the view (or no index buffer): binds the zero page and draws with firstIndex 0, so every index reads 0;
  • draw that crosses the view's end: indices inside the view are copied to a transfer-scratch buffer, the rest is zero, so no byte past the view is read (vkCmdBindIndexBuffer has no size without VK_KHR_maintenance5, so it binds to the end of the whole buffer);
  • null view over a draw bigger than the zero page: a zeroed scratch (previously it could read the arena bytes after the page);
  • scratch buffers get the index-buffer usage flag for the staged copy.

Why

D3D12 defines an index fetch outside the view as 0. The replay bound the whole buffer, so a title that leaves stale or larger data behind its view (common with suballocated index buffers) drew geometry it should not, or read other resources' bytes: wrong 3D rendering.

Rebased cleanly on current main; supersedes #7808 closed during org migration (same 5 commits, cherry-picked without conflicts) plus a new CPU-only test.

Tested

No GPU pod was available (all down), so:

  • NEW replay_index_view_test (native g++, no GPU, drives prepare_draw with fake Vulkan callbacks): 5 cases pass (inside / outside / straddle / null view / null view bigger than the zero page).
  • Negative control: the same cases against main's prepare_draw: 3 of 5 FAIL ("outside: the zero page is bound", "straddle: a staged copy is bound", "null view, large draw: a zeroed scratch covers the whole draw").
  • Neighbours, native g++, all pass: replay_copy_offset_test, replay_clear_gate_test, replay_texture_barrier_test, replay_write_immediate_predication_test.
  • d3d12_draw_test.cpp (the original GPU test with the pixel checks for view_out / view_in / straddle / null / zero / live) compiles clean with clang-cl 19 (-fsyntax-only), but I could NOT run it: it needs a Vulkan device (and main's d3d12_vulkan_device.cpp does not build until #9809/#9815 land). Its GPU result is unverified in this PR.

🔄 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/326 **Author:** [@Andretuta](https://github.com/Andretuta) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `old-pr/10061` --- ### 📝 Commits (6) - [`7c56e90`](https://github.com/ubiquitarianism/leonida/commit/7c56e90584dea7d417335e2bf29efb022a337ff4) fix: index buffer view SizeInBytes bounds the index fetch; reads outside the view are 0 - [`561a063`](https://github.com/ubiquitarianism/leonida/commit/561a0637e3fdbac0ff93dd4cdcd8b1d9e1aae889) fix: a draw that crosses the index view's end reads index 0 past it, from a staged copy - [`fc9b2f3`](https://github.com/ubiquitarianism/leonida/commit/fc9b2f32bc4fec18970c012febedf3d70b2a3dce) fix: scratch buffers allow index-buffer use for the staged index copy - [`3e70e82`](https://github.com/ubiquitarianism/leonida/commit/3e70e8213f15d3e52bc6d66ba72781da070b8eac) fix: bound null index views to zero page - [`74fc913`](https://github.com/ubiquitarianism/leonida/commit/74fc9130876720fc787de7ed455f9bdcf084212e) test: the null index view test releases its buffers before the device proxy reference check - [`5f86fa5`](https://github.com/ubiquitarianism/leonida/commit/5f86fa5d449691032ecbe9a15785a23fe22058c6) test: replay_index_view_test covers the index view bounds in prepare_draw without a GPU ### 📊 Changes **5 files changed** (+288 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `runtime/CMakeLists.txt` (+7 -0) 📝 `runtime/src/vulkan_replay.h` (+58 -6) 📝 `runtime/src/vulkan_scratch.h` (+2 -1) 📝 `runtime/test/d3d12_draw_test.cpp` (+87 -4) ➕ `runtime/test/replay_index_view_test.cpp` (+134 -0) </details> ### 📄 Description > Carried over from **old PR 10061** by `tedin7` in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch `old-pr/10061`, exactly that PR's last commit. All carried-over PRs are listed in #17. > Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it. > `tedin7`: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one. --- Original description (mentions and `#N` references are disabled; the numbers refer to the old repository): ## What An indexed draw now honours the index buffer view's `SizeInBytes` in the Vulkan replay (`prepare_draw`, `runtime/src/vulkan_replay.h`): - draw wholly inside the view: the buffer is bound as before; - draw wholly outside the view (or no index buffer): binds the zero page and draws with firstIndex 0, so every index reads 0; - draw that crosses the view's end: indices inside the view are copied to a transfer-scratch buffer, the rest is zero, so no byte past the view is read (`vkCmdBindIndexBuffer` has no size without VK_KHR_maintenance5, so it binds to the end of the whole buffer); - null view over a draw bigger than the zero page: a zeroed scratch (previously it could read the arena bytes after the page); - scratch buffers get the index-buffer usage flag for the staged copy. ## Why D3D12 defines an index fetch outside the view as 0. The replay bound the whole buffer, so a title that leaves stale or larger data behind its view (common with suballocated index buffers) drew geometry it should not, or read other resources' bytes: wrong 3D rendering. Rebased cleanly on current main; supersedes `#7808` closed during org migration (same 5 commits, cherry-picked without conflicts) plus a new CPU-only test. ## Tested No GPU pod was available (all down), so: - NEW `replay_index_view_test` (native g++, no GPU, drives `prepare_draw` with fake Vulkan callbacks): 5 cases pass (inside / outside / straddle / null view / null view bigger than the zero page). - Negative control: the same cases against main's `prepare_draw`: 3 of 5 FAIL ("outside: the zero page is bound", "straddle: a staged copy is bound", "null view, large draw: a zeroed scratch covers the whole draw"). - Neighbours, native g++, all pass: replay_copy_offset_test, replay_clear_gate_test, replay_texture_barrier_test, replay_write_immediate_predication_test. - `d3d12_draw_test.cpp` (the original GPU test with the pixel checks for view_out / view_in / straddle / null / zero / live) compiles clean with clang-cl 19 (-fsyntax-only), but I could NOT run it: it needs a Vulkan device (and main's d3d12_vulkan_device.cpp does not build until `#9809`/#9815 land). Its GPU result is unverified in this PR. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#378
No description provided.