[PR #1123] [CLOSED] OLD-10061: the index buffer view's size bounds the index fetch in the Vulkan replay (carries #326) #1157

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1123
Author: @TimIdle
Created: 11/24/2026
Status: ❌ Closed

Base: main ← Head: oldpr-10061-index-view


📝 Commits (9)

  • b332c6d fix: index buffer view SizeInBytes bounds the index fetch; reads outside the view are 0
  • f86e681 fix: a draw that crosses the index view's end reads index 0 past it, from a staged copy
  • 369b326 fix: scratch buffers allow index-buffer use for the staged index copy
  • b86163a fix: bound null index views to zero page
  • 0ee8064 test: the null index view test releases its buffers before the device proxy reference check
  • ce7ade9 test: replay_index_view_test covers the index view bounds in prepare_draw without a GPU
  • 26f1f58 test: the first arena allocation follows the zero page and the quad index table
  • 21c7bc8 fix: an indexed quad list keeps main's expansion pass instead of a staged index copy
  • b403c27 fix: the device asks scratch for index-buffer use, and the draw test follows main's quad index table

📊 Changes

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

View changed files

📝 runtime/CMakeLists.txt (+7 -0)
📝 runtime/shims/d3d12_vulkan_device.cpp (+4 -1)
📝 runtime/src/vulkan_replay.h (+65 -6)
📝 runtime/test/d3d12_draw_test.cpp (+89 -4)
➕ runtime/test/replay_index_view_test.cpp (+148 -0)

📄 Description

Claimed in the coordination issue as: OLD-10061 (claim)

What and why

This carries forward old-pr/10061 by @tedin7 (draft #326). The six commits are rebased onto main with tedin7 kept as author. Three commits of mine follow. One moves the arena address the draw test expects, since main now puts the quad index table after the zero page. One leaves indexed quad lists to main's expansion pass. One asks for the index-buffer use through main's new scratch extra_usage instead of in vulkan_scratch.h.

In D3D12, an index fetch outside the index buffer view reads 0. vkCmdBindIndexBuffer binds to the end of the buffer instead, so the replay read real index data past the view and lit the wrong pixels.

  • A draw wholly inside the view binds the buffer as before.
  • A draw wholly outside the view, or with a null view, binds the zero page.
  • A draw that crosses the view's end binds a scratch copy. The in-view indices are copied and the rest is zero-filled, before vkCmdBeginRendering. The device asks its scratch buffers for VK_BUFFER_USAGE_INDEX_BUFFER_BIT for this, on every GPU.
  • An indexed quad list keeps main's expansion pass (prepare_quad_indices), which already reads only the view and zero-fills the rest. An index buffer found through title_memory is bounded the same way as one found through buffer_at.

@Sigtryggur-Mani-Gudmundsson checked the series on Linux (RTX 4070 Ti, synchronization validation) in #326 and noted that the Windows D3D12 entry point was untested. This PR adds that run.

Tested

Native Windows 11 10.0.26300, MSVC 19.44, RelWithDebInfo, LEONIDA_REQUIRE_VULKAN=ON, on main 42537e7 plus the nine commits.

Check Result
d3d12_draw_test with the fix pass: "draw past the view painted 0 red pixels (want 0); view covering the draw painted 1024 of 1024 top-left pixels"
d3d12_draw_test with main's vulkan_replay.h and vulkan_scratch.h (run on 955d9be, before the rebase) fail: line 1171: view_out_red == 0
replay_index_view_test (no GPU) all passed, including an indexed quad list that straddles the view (does not compile against main's headers, since it checks the new PreparedDraw fields)
replay_index_view_test with the quad-list branch taken out fail: quad straddle: the buffer and view size go to the expansion pass, no staging
full ctest -j 6 403 of 403 passed, gameinput and gameinput_script disabled.

Not covered:

ExecuteIndirect with DRAW_INDEXED binds no index buffer in the replay, so these bounds never reach indirect indexed draws. #499 works on that path.

A huge index count past a small view asks scratch for count * index size bytes. If that allocation fails, the list is refused. I did not hit this. It is a limit, not a measured failure.

GPUs tested: NVIDIA GeForce RTX 2050 (Ampere GA107, laptop), driver 621.24, Windows 11

AI-assisted: yes (Claude Code)

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. (No translator rule here.)

🤖 Generated with Claude 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/1123 **Author:** [@TimIdle](https://github.com/TimIdle) **Created:** 11/24/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `oldpr-10061-index-view` --- ### 📝 Commits (9) - [`b332c6d`](https://github.com/ubiquitarianism/leonida/commit/b332c6d2854cbeedfe4381437d33e6468d26f300) fix: index buffer view SizeInBytes bounds the index fetch; reads outside the view are 0 - [`f86e681`](https://github.com/ubiquitarianism/leonida/commit/f86e68120ab366c8940123a221fcc1713ce9f2e7) fix: a draw that crosses the index view's end reads index 0 past it, from a staged copy - [`369b326`](https://github.com/ubiquitarianism/leonida/commit/369b3265995ae3668410e5ffc99cedbb1d123740) fix: scratch buffers allow index-buffer use for the staged index copy - [`b86163a`](https://github.com/ubiquitarianism/leonida/commit/b86163a92f293712167f613381803b62560ac0b5) fix: bound null index views to zero page - [`0ee8064`](https://github.com/ubiquitarianism/leonida/commit/0ee8064a74a2d62d349885177494be1f259c86e2) test: the null index view test releases its buffers before the device proxy reference check - [`ce7ade9`](https://github.com/ubiquitarianism/leonida/commit/ce7ade93f8a2078add9ba0f77b5196057c8e1d03) test: replay_index_view_test covers the index view bounds in prepare_draw without a GPU - [`26f1f58`](https://github.com/ubiquitarianism/leonida/commit/26f1f58f0564f5c5703c78c6299218a03f15212b) test: the first arena allocation follows the zero page and the quad index table - [`21c7bc8`](https://github.com/ubiquitarianism/leonida/commit/21c7bc80650f32960e31adb1784dfd8a6364e6d3) fix: an indexed quad list keeps main's expansion pass instead of a staged index copy - [`b403c27`](https://github.com/ubiquitarianism/leonida/commit/b403c27e177666507762a20ed3563341454a0084) fix: the device asks scratch for index-buffer use, and the draw test follows main's quad index table ### 📊 Changes **5 files changed** (+313 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `runtime/CMakeLists.txt` (+7 -0) 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+4 -1) 📝 `runtime/src/vulkan_replay.h` (+65 -6) 📝 `runtime/test/d3d12_draw_test.cpp` (+89 -4) ➕ `runtime/test/replay_index_view_test.cpp` (+148 -0) </details> ### 📄 Description Claimed in the coordination issue as: OLD-10061 ([claim](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7140571964)) ### What and why This carries forward `old-pr/10061` by @tedin7 (draft #326). The six commits are rebased onto `main` with tedin7 kept as author. Three commits of mine follow. One moves the arena address the draw test expects, since `main` now puts the quad index table after the zero page. One leaves indexed quad lists to `main`'s expansion pass. One asks for the index-buffer use through `main`'s new scratch `extra_usage` instead of in `vulkan_scratch.h`. In D3D12, an index fetch outside the index buffer view reads 0. `vkCmdBindIndexBuffer` binds to the end of the buffer instead, so the replay read real index data past the view and lit the wrong pixels. - A draw wholly inside the view binds the buffer as before. - A draw wholly outside the view, or with a null view, binds the zero page. - A draw that crosses the view's end binds a scratch copy. The in-view indices are copied and the rest is zero-filled, before `vkCmdBeginRendering`. The device asks its scratch buffers for `VK_BUFFER_USAGE_INDEX_BUFFER_BIT` for this, on every GPU. - An indexed quad list keeps `main`'s expansion pass (`prepare_quad_indices`), which already reads only the view and zero-fills the rest. An index buffer found through `title_memory` is bounded the same way as one found through `buffer_at`. @Sigtryggur-Mani-Gudmundsson checked the series on Linux (RTX 4070 Ti, synchronization validation) in #326 and noted that the Windows D3D12 entry point was untested. This PR adds that run. ### Tested Native Windows 11 10.0.26300, MSVC 19.44, RelWithDebInfo, `LEONIDA_REQUIRE_VULKAN=ON`, on `main` `42537e7` plus the nine commits. | Check | Result | |---|---| | `d3d12_draw_test` with the fix | pass: "draw past the view painted 0 red pixels (want 0); view covering the draw painted 1024 of 1024 top-left pixels" | | `d3d12_draw_test` with `main`'s `vulkan_replay.h` and `vulkan_scratch.h` (run on `955d9be`, before the rebase) | fail: `line 1171: view_out_red == 0` | | `replay_index_view_test` (no GPU) | all passed, including an indexed quad list that straddles the view (does not compile against `main`'s headers, since it checks the new `PreparedDraw` fields) | | `replay_index_view_test` with the quad-list branch taken out | fail: `quad straddle: the buffer and view size go to the expansion pass, no staging` | | full `ctest -j 6` | 403 of 403 passed, `gameinput` and `gameinput_script` disabled. | Not covered: `ExecuteIndirect` with `DRAW_INDEXED` binds no index buffer in the replay, so these bounds never reach indirect indexed draws. #499 works on that path. A huge index count past a small view asks scratch for `count * index size` bytes. If that allocation fails, the list is refused. I did not hit this. It is a limit, not a measured failure. GPUs tested: NVIDIA GeForce RTX 2050 (Ampere GA107, laptop), driver 621.24, Windows 11 AI-assisted: yes (Claude Code) ### 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. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (No translator rule here.) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:20:16 +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#1157
No description provided.