Skip to content

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

Closed
TimIdle wants to merge 9 commits into
ProjectLeonida:mainfrom
TimIdle:oldpr-10061-index-view
Closed

TimIdle wants to merge 9 commits into
ProjectLeonida:mainfrom
TimIdle:oldpr-10061-index-view

Conversation

@TimIdle

@TimIdle TimIdle commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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

@abnalstlll-byte abnalstlll-byte left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed and verified. Crucial fix for index buffer out-of-bounds fetches in D3D12 Vulkan replay (OLD-10061). Correctly bounds index fetches to IndexBufferView size: in-view fetches bind normally, fully out-of-view/null binds the zero page, and boundary crossings copy valid indices with trailing zeros into a scratch buffer with VK_BUFFER_USAGE_INDEX_BUFFER_BIT. Verified on Windows 11 with MSVC/RTX 2050 in d3d12_draw_test and replay_index_view_test. 100% clean-room.

@madhyn

madhyn commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Tested 0ab946721 on Arch Linux + Wine 11.22 + NVIDIA RTX 3060 Ti (clang-cl + xwin cross-build):

  • d3d12_draw: Passed (5.47 s)
  • replay_index_view: Passed (5.31 s)

AI-assisted: yes

@TimIdle

TimIdle commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Thank you for the Wine run on the RTX 3060 Ti. With the native Windows run in the description, both test files now pass on two hosts.

@Deedlyy

Deedlyy commented Nov 24, 2026

Copy link
Copy Markdown

Recommendation: [MERGE]

Reasoning: Carries #326: the Vulkan replay bounds index fetches by the D3D12 index buffer view (out-of-view reads return 0 via the zero page) instead of reading past the view. Fixes wrong-pixel rendering; adds a dedicated test plus d3d12_draw cases. Verified natively on Windows by the author and on Wine + RTX 3060 Ti by madhyn. CI (label, change-scope, no-game-data and the Runtime jobs) is still queued awaiting maintainer workflow approval, so nothing has run in CI yet; GitHub reports no merge conflict with main. Merge once the queued checks are green.

Impact level: 5/10

@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Nov 25, 2026
tedin7 and others added 9 commits November 25, 2026 14:38
…ndex table

main now puts a 256 KiB table of quad-list indices (kQuadIndexCount 32-bit
indices) right after the 64 KiB zero page, so the first committed buffer of the
null index view check starts at 320 KiB, not 64 KiB. Only the expected address
changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…aged index copy

main's prepare_quad_indices already reads only the index view and zero-fills the rest, from
p.index_buffer, p.index_size and draw.first. A staged copy would rebase the indices to 0 under it.
replay_index_view_test covers a quad list that straddles the view and one with no index buffer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…follows main's quad index table

main gives ScratchBuffers an extra_usage set by its creator and vulkan_scratch_test checks that a
chunk carries only what was asked. The staged index copy now asks for INDEX_BUFFER there, on every
GPU, instead of in vulkan_scratch.h. The first arena allocation follows the 64 KiB zero page and
main's quad index table of 16 Ki quads of 6 indices.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@TimIdle
TimIdle force-pushed the oldpr-10061-index-view branch from 0ab9467 to b403c27 Compare November 25, 2026 07:07
@TimIdle

TimIdle commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main 42537e7, and it also merges cleanly with 3f81d46. main now has its own indexed quad-list expansion, an index_size and a title_memory fallback in prepare_draw, so I merged the two instead of taking one side. An indexed quad list keeps main's expansion pass, which already reads only the view. Every other indexed draw keeps the bounds of this PR, including one whose buffer is found through title_memory. The staged copy now asks for index-buffer use through main's scratch extra_usage, because vulkan_scratch_test checks that a chunk carries only what its creator asked for. replay_index_view_test has a new quad-list case, and it fails when the quad-list branch is taken out. On the RTX 2050 d3d12_draw_test passes and the full ctest is 403 of 403.

@TimIdle

TimIdle commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Closing this one, no review yet and CI is red. Will reopen if it is still needed.

@TimIdle TimIdle closed this Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs rebase Conflicts with the base branch: rebase it on main

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants