vulkan_replay: enforce 4-byte vkCmdFillBuffer alignment in zero_compressed_image #528
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!528
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/528/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 06:58 UTC · original
tahffo68hk-hash:fix/vk-zero-init-fill-align→main· +89 −6 · 2 files · 1 commits · merged 2026-11-25 00:02 UTCSummary
(AI-assisted) Fixes
VK-ZERO-INIT-FILL-ALIGNinruntime/src/vulkan_replay.h:detail::initialize()routes not only block-compressed (fmt.block > 1) textures, but also uncompressed color textures on copy-only queues (!can_clear && color) intodetail::zero_compressed_image(). Whenvk.zero_bufferis absent (thevk.copy_scratch+vk.fill_bufferfallback),zero_compressed_image()previously roundedfill_bytesandalignonly tofmt.bytes, assumingfmt.byteswas 8 or 16.For 1-byte (
R8_UNORM, e.g.3x3 = 9 B) or 2-byte (R16_UNORM, e.g.3x1 = 6 B) color textures with non-4-byte-multiple sizes, this passed a non-4-byte-alignedsize(and, with non-4-aligned scratch offsets, a non-4-byte-aligneddstOffset) tovkCmdFillBuffer, violatingVUID-vkCmdFillBuffer-dstOffset-00024andVUID-vkCmdFillBuffer-size-00028.Changes
runtime/src/vulkan_replay.h: Inzero_compressed_image(), usealign = std::max<VkDeviceSize>(4, fmt.bytes)when sizing the scratch request, computingpad, and roundingusabledown to a multiple ofalignbefore callingvk.fill_buffer().runtime/test/vk_bc_zero_init_test.cpp:VulkanQueue::QueueKind::copy) zero-init readback tests for poisoned (0x5A)3x3VK_FORMAT_R8_UNORMand3x1VK_FORMAT_R16_UNORMtextures viacopy_scratch(nozero_buffer).ReplayFunctionsalignment check verifyingdstOffset % 4 == 0andsize % 4 == 0for3x3R8_UNORMeven with a deliberately unaligned scratch offset (offset = 2).Verification
vk_bc_zero_init_test.exe, MSVC 19.44 + Ninja):copy-queue zero-init (R8_UNORM 3x3 via copy_scratch)andcopy-queue zero-init (R16_UNORM 3x1 via copy_scratch)passed (all readback texels0x00, 0 validation errors).gfx1036, RDNA2): all cases passed identically.中文翻译
摘要
(AI 辅助)修复
runtime/src/vulkan_replay.h中的VK-ZERO-INIT-FILL-ALIGN:detail::initialize()不仅会将 BC 压缩纹理送入detail::zero_compressed_image(),在仅拷贝队列(!can_clear && color)上也会将未压缩彩色纹理送入该函数。当未配置vk.zero_buffer而走copy_scratch+vk.fill_buffer回退路径时,原实现假设fmt.bytes恒为 8 或 16,对 1 字节(如R8_UNORM 3x3 = 9B)或 2 字节(如R16_UNORM 3x1 = 6B)纹理会向vkCmdFillBuffer传入非 4 字节对齐的size/dstOffset,违反VUID-vkCmdFillBuffer-dstOffset-00024与VUID-vkCmdFillBuffer-size-00028。改动
runtime/src/vulkan_replay.h:在zero_compressed_image()中将align提升为std::max<VkDeviceSize>(4, fmt.bytes),确保vk.fill_buffer的偏移与长度均满足 4 字节与fmt.bytes对齐。runtime/test/vk_bc_zero_init_test.cpp:新增仅拷贝队列下R8_UNORM 3x3与R16_UNORM 3x1的真实 GPU 零初始化读回测试,以及非对齐暂存偏移下的vkCmdFillBuffer对齐断言。验证
vk_bc_zero_init_test.exe):在 NVIDIA RTX 5060 Ti 与 AMD Radeon(TM) Graphics(gfx1036) 上均全部通过,读回纹素全为0x00。@kawaii-shakal on GitHub · 2026-11-24 07:55 UTC · original
Review of head
1d4310bc71ed62a86156a26950ff96fe560ccbf2.Environment: Linux (WSL2), g++ C++20 with
-fsanitize=address,undefined, Vulkan-Headers only. No GPU, no MSVC.What ran:
vk_bc_zero_init_testreturns 77 (skip) without a Vulkan device before it reaches the new mock check. So I copied the "Direct ReplayFunctions check" block unchanged into a standalone file that only includesvulkan_replay.h, and ran it:dstOffset=4,size=8for R8 3x3 with scratch offset 2. No ASan/UBSan reports.vulkan_replay.hfromorigin/main: fails the% 4/ size assertion, so the check catches the bug.VUID-vkCmdFillBuffer-dstOffset-00024/-size-00028.align = max(4, fmt.bytes)is still a multiple offmt.bytesfor every block size (1, 2, 4, 8, 16), sobufferOffsetstays valid forvkCmdCopyBufferToImage.Finding (non-blocking, from reading the code, not executed):
fill_bytesis requested without room forpad. With an unaligned scratch offset,zero_capcan end up smaller thanneeded: 8 < 9 in the mock case. The image is still fully covered because the row-chunk path takes over (rows_per_copy = 2), so it costs extra regions, not correctness. Requestingfill_bytes + align - 4(or+ align) would keep the single-region path. The old code had the same shortfall.Not tested: the new real-GPU copy-queue readback cases (no GPU here), validation-layer output, and the MSVC build.
Review written by Claude (Claude Code, Opus 5.5), an AI agent, posted from a contributor's account.
@Sangonapou on GitHub · 2026-11-24 19:11 UTC · original
Tested
1d4310bcon NVIDIA GeForce RTX 3080 Ti Laptop (Ampere), NVIDIA 621.24, Vulkan 1.4.357, Windows 11 Pro (build 26300), native Windows on real hardware: passBuilt at this head with
scripts\build_runtime.ps1(MSVC 19.51, VS Build Tools 2026, Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0). No game files.ctest -R ^vk_bc_zero_init$ -V: passed:@QemmHD on GitHub · 2026-11-25 00:01 UTC · original
Merging.
Why merged: VK-ZERO-INIT-FILL-ALIGN: zero_compressed_image aligns the fill to max(4, fmt.bytes) and rounds the usable size down, so vkCmdFillBuffer's offset and size are 4-aligned. That also makes the copy offset 4-aligned on transfer queues, which closes the VUID-07737 gap noted on #434. kawaii-shakal (ASan mock) and Sangonapou (RTX 3080 Ti) checked it.
Why it's good: vk_bc_zero_init, vk_queue and the replay_* tests: 12/12 both plain and under validation.
Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Merged alone onto main
0f98d193c, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative with the rest of this batch on main507029d1e: the repo-consistency set gives 578 passed / 5 skipped / 0 failed, compileall is clean, and full ctest is 317/318 with the usual 11 skips; the only failure is main's pre-existing d3d12_depth_resolve. All d3d12_* tests under validation: 119/120 with 0 VUIDs. The semantic suite has only the known environment-only failure. git merge-tree against current main9c5e70661: 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).