vulkan_replay: validate backing buffer_offset alignment in buffer UAV clear (VK-UAV-CLEAR-ALIGN) #418
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!418
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/418/head"
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?
@tahffo68hk-hash on GitHub · 2026-11-24 04:53 UTC · original
tahffo68hk-hash:fix/vk-uav-clear-align→main· +13 −0 · 2 files · 1 commits · merged 2026-11-24 16:24 UTCClaimed in the coordination issue as:
VK-UAV-CLEAR-ALIGNProblem
prepare_buffer_uav_clear()inruntime/src/vulkan_replay.hcheckedoffset % std::min(e, 4u)before addingp.binding.buffer_offset. When a sub-allocated buffer has a misalignedbuffer_offset:e > 4, e.g.,R32G32B32A32_UINT),emit_buffer_fill()calledvkCmdUpdateBufferwithdstOffset % 4 != 0, violatingVUID-vkCmdUpdateBuffer-dstOffset-00032.e == 2ore == 4),emit_buffer_fill()filled 4-byte-aligned words with an unrotated pattern, byte-swapping/rotating every cleared element.(Compare
prepare_texture_copy(), which explicitly checksbacking_offset % alignmentafter addingbuffer.buffer_offset.)Fix
prepare_buffer_uav_clear(), checkif (offset % std::min(e, 4u)) return ReplayResult::unsupported;after addingp.binding.buffer_offset, while still allowing oddbuffer_offsetfor 1-byte (R8_*) elements.runtime/test/replay_uav_clear_offset_test.cppcovering misalignedbuffer_offsetfor 16-byte, 4-byte, 2-byte, and 1-byte UAV clears.Verification
-DLEONIDA_BUILD_WINDOWS_RUNTIME=OFF) on Windows 11.ctest -R "^replay_uav_clear_offset$" --output-on-failure-> 1/1 PASS (no game files).中文翻译
在协调帖 #14 中认领的 ID:
VK-UAV-CLEAR-ALIGN问题描述
runtime/src/vulkan_replay.h的prepare_buffer_uav_clear()仅在叠加p.binding.buffer_offset之前检查offset % std::min(e, 4u)。当子分配缓冲区的buffer_offset未对齐时:e > 4)会以未 4 字节对齐的dstOffset调用vkCmdUpdateBuffer,违反VUID-vkCmdUpdateBuffer-dstOffset-00032;修复方案
p.binding.buffer_offset后检查offset % std::min(e, 4u),未对齐时返回ReplayResult::unsupported(同时保留 1 字节R8_*元素的合法性)。runtime/test/replay_uav_clear_offset_test.cpp中补充 16/4/2/1 字节元素的回归测试。验证结果
ctest -R "^replay_uav_clear_offset$"(无游戏文件)。@moffington on GitHub · 2026-11-24 05:21 UTC · original
Tested
c9099b0con Linux. replay_uav_clear_offset passed. I ran the same test against the merge-base replay code (d2cd6c0d), and all three new rejection assertions failed as expected for misaligned backing offsets with 16-, 4-, and 2-byte elements. The R8 case passed on both revisions. This was a CPU-only test with mocked Vulkan commands.@QemmHD on GitHub · 2026-11-24 16:24 UTC · original
Merging.
Why merged: A buffer UAV clear whose backing buffer_offset is misaligned for 2-, 4- or 16-byte elements is now refused before vkCmdFillBuffer/vkCmdUpdateBuffer, instead of recording an invalid command. R8 still replays. moffington showed the new assertions fail on the merge base.
Why it's good: replay_uav_clear_offset passes both plain and under validation, with 0 errors.
Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Alone on main, its tests passed both plain and with LEONIDA_VK_VALIDATION=1. Cumulative: #388, #418, #421, #434, #470, #484, #485, #486 and #488 merged onto main
1504c1af6(a225e593e). There the repo-consistency set gives 566 passed / 5 skipped / 0 failed, compileall is clean, and full ctest is 306/308. The 2 failures are the same pre-existing ones as main (d3d12_execute_indirect_validation, d3d12_depth_resolve), with the same skip set. git merge-tree against current main98a977b4b: no conflicts. Security read of the three-dot diff: no binaries, game data, downloads, network calls or CI changes.AI-assisted (Claude Code, Claude Opus 5.5).