Repository navigation
vulkan_replay: enforce index buffer offset alignment in prepare_draw (VK-DRAW-INDEX-OFFSET-ALIGN) - #539
Open
tahffo68hk-hash wants to merge 1 commit into
Conversation
…(VK-DRAW-INDEX-OFFSET-ALIGN)
demoz53
added a commit
to demoz53/leonida
that referenced
this pull request
Nov 24, 2026
…et alignment in prepare_draw (VK-DRAW-INDEX-OFFSET-ALIGN)
Contributor
|
Tested 9ef7469 on NVIDIA GeForce RTX 3080 Ti Laptop (Ampere, subgroup 32..32, mesh shaders), NVIDIA 621.24, Vulkan 1.4.357, Windows 11 Pro (build 26300), native Windows: pass Runtime built at this head with
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/ d3d12/vulkan: replay full graphics state for ExecuteIndirect DRAW and DRAW_INDEXED (D3D-EXECIND-GRAPHICS) #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/认领,未改动 d3d12/vulkan: replay full graphics state for ExecuteIndirect DRAW and DRAW_INDEXED (D3D-EXECIND-GRAPHICS) #499 涉及的ExecuteIndirect)。