Repository navigation
vulkan_replay: enforce index buffer offset alignment in prepare_draw (VK-DRAW-INDEX-OFFSET-ALIGN) - #539
Conversation
…(VK-DRAW-INDEX-OFFSET-ALIGN)
…et alignment in prepare_draw (VK-DRAW-INDEX-OFFSET-ALIGN)
|
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
|
Verification Report (
|
| Target | Base main vulkan_replay.h + #539 test |
Merged main + #539 (9ef746972e) |
|---|---|---|
replay_index_align_test (CPU replay) |
RED (rc=1: misaligned DXGI_FORMAT_R16_UINT offset 1 returns ReplayResult::success and invokes vkCmdBindIndexBuffer) |
GREEN (rc=0: replay_index_align: 10/10 cases OK across R16_UINT, R32_UINT, and misaligned zero_offset fallback; bind_index_calls == 0 on every rejected draw) |
Combined merge with #778 + #1179 + #1443 (d3d12_indirect_draw, d3d12_msaa_draw, replay_index_align on RTX 3090, LEONIDA_VK_VALIDATION=1) |
— | GREEN (rc=0, 0 validation errors) |
- Verdict: PASS (reproduces the misaligned
vkCmdBindIndexBufferbypass onmain, passes 10/10 alignment cases, and composes cleanly withmain's indirect-draw path).
AI-assisted.
|
Validation run of this pull request.
|
|
Independent verification on this machine (Windows 11, MSVC 19.44.35226), with a negative control that bites. 1. It applies. 2. Its test is a CPU test - the header says so ("no GPU") - and with the branch it passes: 3. The control - revert only the header, keep the test: So the assertion is about the change: an indexed draw whose index-buffer offset is not aligned to the index size ( What I did not test: the rest of Why I am commenting: I verify open pull requests that replay onto current Written with an AI assistant. |
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)。