mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 21:55:52 +01:00
[PR #539] vulkan_replay: enforce index buffer offset alignment in prepare_draw (VK-DRAW-INDEX-OFFSET-ALIGN) #587
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#587
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/539
Author: @tahffo68hk-hash
Created: 11/24/2026
Status: 🔄 Open
Base:
main← Head:fix/vk-draw-index-offset-align📝 Commits (1)
9ef7469vulkan_replay: enforce index buffer offset alignment in prepare_draw (VK-DRAW-INDEX-OFFSET-ALIGN)📊 Changes
3 files changed (+124 additions, -0 deletions)
View changed files
📝
runtime/CMakeLists.txt(+7 -0)📝
runtime/src/vulkan_replay.h(+3 -0)➕
runtime/test/replay_index_align_test.cpp(+114 -0)📄 Description
Summary
detail::prepare_draw()inruntime/src/vulkan_replay.hresolves an indexed draw'sdraw.index.vaviavk.buffer_at(...)intop.index_offset(or falls back tovk.zero_offsetwhen unbound) and later emitsvk.bind_index_buffer(command_buffer, d.index_buffer, d.index_offset, d.index_type)without checking alignment ofp.index_offsetagainst the index element size.Vulkan requires
offsetinvkCmdBindIndexBufferto be a multiple of the index type's size (2bytes forVK_INDEX_TYPE_UINT16,4bytes forVK_INDEX_TYPE_UINT32;VUID-vkCmdBindIndexBuffer-offset-08783), matching D3D12'sIASetIndexBufferalignment requirement. Passing a misaligned offset previously bypassedprepare_draw()and reachedvkCmdBindIndexBufferdirectly.Fix
p.index_offset % index_align != 0(index_align = 4forVK_INDEX_TYPE_UINT32,2forVK_INDEX_TYPE_UINT16) indetail::prepare_draw()(runtime/src/vulkan_replay.h), returningReplayResult::invalid_drawbefore any Vulkan command is recorded.runtime/test/replay_index_align_test.cpp(registered asreplay_index_aligninruntime/CMakeLists.txt) covering aligned and misaligned offsets forDXGI_FORMAT_R16_UINT,DXGI_FORMAT_R32_UINT, and unboundzero_bufferfallback, verifyingvkCmdBindIndexBufferis never invoked on rejection.Verification
replay_index_align_test.exeandreplay_copy_offset_test.exe(MSVC 19.44, Ninja, C++20, CPU-only mock-callback replay tests — not real GPU execution):replay_index_align: 10/10 cases OKreplay_copy_offset: CopyResource and CopyTexture apply ResourceBinding::buffer_offsetCoordination
VK-DRAW-INDEX-OFFSET-ALIGN(no overlapping open PRs or claims; does not touchExecuteIndirect/ #499).中文翻译
摘要
runtime/src/vulkan_replay.h中的detail::prepare_draw()在解析索引绘制的draw.index.va(或未绑定时回退至vk.zero_offset)得到p.index_offset后,未校验其与索引元素大小的对齐关系,直接交给vkCmdBindIndexBuffer。根据 Vulkan 规范
VUID-vkCmdBindIndexBuffer-offset-08783(与 D3D12IASetIndexBuffer要求一致),offset必须按索引类型大小对齐(VK_INDEX_TYPE_UINT16为 2 字节,VK_INDEX_TYPE_UINT32为 4 字节)。此前未对齐的偏移会绕过准备阶段直接触发 Vulkan 验证错误。修复
detail::prepare_draw()中增加p.index_offset % index_align校验(UINT32为 4、UINT16为 2),未对齐时返回ReplayResult::invalid_draw,阻止录制非法vkCmdBindIndexBuffer。runtime/test/replay_index_align_test.cpp(注册为replay_index_align),覆盖R16_UINT、R32_UINT及zero_buffer回退路径的对齐/未对齐用例,并确认拒绝路径不会调用vkCmdBindIndexBuffer。验证
replay_index_align_test.exe(10/10 通过)与replay_copy_offset_test.exe(通过)(均为 CPU 回调测试,非真实 GPU 执行)。协同
VK-DRAW-INDEX-OFFSET-ALIGN(无重复 PR/认领,未改动 #499 涉及的ExecuteIndirect)。🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.