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

Closed
Andretuta wants to merge 6 commits from upstream-pr/326 into main
Andretuta commented 2026-11-24 03:10:40 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Andretuta on 2026-11-24T03:10:40Z.


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.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5465362540 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/326). Originally posted by [Andretuta](https://github.com/Andretuta) on 2026-11-24T03:10:40Z. --- > 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.
Sigtryggur-Mani-Gudmundsson commented 2026-11-24 03:25:44 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Sigtryggur-Mani-Gudmundsson on 2026-11-24T03:25:44Z.


I ran tedin7’s six commits through native Vulkan replay on Linux with an RTX 4070 Ti and Khronos synchronization validation enabled. On the original code, the two in-view controls passed and eight other indexed draws lit the wrong pixels. With the patch, all ten matched the expected image, with zero validation errors. Applying the series independently to de4c373 reproduced the result.

The fixture covers 16- and 32-bit indices, a 16-bit view ending halfway through an index, a view clipped at the resource end, and empty, null, or wholly outside views. It records a CommandList and exercises the fill, copy, index binding and indexed draw on the GPU. The Windows D3D12 entry point remains untested here.

Test source, pixel masks and reproduction commands

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7121079656 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/326#issuecomment-7121079656). Originally posted by [Sigtryggur-Mani-Gudmundsson](https://github.com/Sigtryggur-Mani-Gudmundsson) on 2026-11-24T03:25:44Z. --- I ran tedin7’s six commits through native Vulkan replay on Linux with an RTX 4070 Ti and Khronos synchronization validation enabled. On the original code, the two in-view controls passed and eight other indexed draws lit the wrong pixels. With the patch, all ten matched the expected image, with zero validation errors. Applying the series independently to `de4c373` reproduced the result. The fixture covers 16- and 32-bit indices, a 16-bit view ending halfway through an index, a view clipped at the resource end, and empty, null, or wholly outside views. It records a `CommandList` and exercises the fill, copy, index binding and indexed draw on the GPU. The Windows D3D12 entry point remains untested here. [Test source, pixel masks and reproduction commands](https://github.com/Sigtryggur-Mani-Gudmundsson/graphics-runtime-patches/tree/1699e1111c547dcd456f4a92bd24e47e27db872e/tests/index-view)
OreoFR commented 2026-11-29 17:02:21 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T17:02:21Z.


@tedin7 this carried-over PR (your old PR 10061) now conflicts with main (runtime/src/vulkan_replay.h, runtime/src/vulkan_scratch.h). Could you merge main into it, by pushing to its branch or in your own PR from it (no force-push needed)? It was verified before the conflict: https://github.com/ProjectLeonida/mandy/pull/326#issuecomment-7121079656. If there's no update within 24 h, OreoFR may carry it in a new PR that keeps you as co-author (per the maintainers' plan). — OreoFR's agent (AI-assisted)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7259371500 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/326#issuecomment-7259371500). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-29T17:02:21Z. --- @tedin7 this carried-over PR (your old PR 10061) now conflicts with `main` (`runtime/src/vulkan_replay.h`, `runtime/src/vulkan_scratch.h`). Could you merge `main` into it, by pushing to its branch or in your own PR from it (no force-push needed)? It was verified before the conflict: https://github.com/ProjectLeonida/mandy/pull/326#issuecomment-7121079656. If there's no update within 24 h, OreoFR may carry it in a new PR that keeps you as co-author (per the maintainers' plan). — OreoFR's agent (AI-assisted)
aslan2142 commented 2026-12-01 12:18:32 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T12:18:32Z.


Marking Ready for Review since no WIP/blocker reason for draft status is specified on this PR, so it can enter normal CI and review.

(AI-assisted triage.)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7310946749 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/326#issuecomment-7310946749). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T12:18:32Z. --- Marking Ready for Review since no WIP/blocker reason for draft status is specified on this PR, so it can enter normal CI and review. *(AI-assisted triage.)*
aslan2142 commented 2026-12-01 16:29:34 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T16:29:34Z.


Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7317696390 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/326#issuecomment-7317696390). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T16:29:34Z. --- Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.

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