[PR #528] [MERGED] vulkan_replay: enforce 4-byte vkCmdFillBuffer alignment in zero_compressed_image #576

Closed
opened 2026-11-26 20:18:21 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/528
Author: @tahffo68hk-hash
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/25/2026
Merged by: @QemmHD

Base: main ← Head: fix/vk-zero-init-fill-align


📝 Commits (1)

  • 1d4310b vulkan_replay: enforce 4-byte vkCmdFillBuffer alignment in zero_compressed_image

📊 Changes

2 files changed (+89 additions, -6 deletions)

View changed files

📝 runtime/src/vulkan_replay.h (+9 -6)
📝 runtime/test/vk_bc_zero_init_test.cpp (+80 -0)

📄 Description

Summary

(AI-assisted) Fixes VK-ZERO-INIT-FILL-ALIGN in runtime/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) into detail::zero_compressed_image(). When vk.zero_buffer is absent (the vk.copy_scratch + vk.fill_buffer fallback), zero_compressed_image() previously rounded fill_bytes and align only to fmt.bytes, assuming fmt.bytes was 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-aligned size (and, with non-4-aligned scratch offsets, a non-4-byte-aligned dstOffset) to vkCmdFillBuffer, violating VUID-vkCmdFillBuffer-dstOffset-00024 and VUID-vkCmdFillBuffer-size-00028.

Changes

  • runtime/src/vulkan_replay.h: In zero_compressed_image(), use align = std::max<VkDeviceSize>(4, fmt.bytes) when sizing the scratch request, computing pad, and rounding usable down to a multiple of align before calling vk.fill_buffer().
  • runtime/test/vk_bc_zero_init_test.cpp:
    • Add real-GPU Vulkan copy-queue (VulkanQueue::QueueKind::copy) zero-init readback tests for poisoned (0x5A) 3x3 VK_FORMAT_R8_UNORM and 3x1 VK_FORMAT_R16_UNORM textures via copy_scratch (no zero_buffer).
    • Add a direct ReplayFunctions alignment check verifying dstOffset % 4 == 0 and size % 4 == 0 for 3x3 R8_UNORM even with a deliberately unaligned scratch offset (offset = 2).

Verification

  • Real Vulkan GPU execution & readback (vk_bc_zero_init_test.exe, MSVC 19.44 + Ninja):
    • NVIDIA GeForce RTX 5060 Ti: all cases including copy-queue zero-init (R8_UNORM 3x3 via copy_scratch) and copy-queue zero-init (R16_UNORM 3x1 via copy_scratch) passed (all readback texels 0x00, 0 validation errors).
    • AMD Radeon(TM) Graphics (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 对齐断言。

验证

  • 真实 Vulkan GPU 执行与读回(vk_bc_zero_init_test.exe):在 NVIDIA RTX 5060 Ti 与 AMD Radeon(TM) Graphics(gfx1036) 上均全部通过,读回纹素全为 0x00。

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/528 **Author:** [@tahffo68hk-hash](https://github.com/tahffo68hk-hash) **Created:** 11/24/2026 **Status:** ✅ Merged **Merged:** 11/25/2026 **Merged by:** [@QemmHD](https://github.com/QemmHD) **Base:** `main` ← **Head:** `fix/vk-zero-init-fill-align` --- ### 📝 Commits (1) - [`1d4310b`](https://github.com/ubiquitarianism/leonida/commit/1d4310bc71ed62a86156a26950ff96fe560ccbf2) vulkan_replay: enforce 4-byte vkCmdFillBuffer alignment in zero_compressed_image ### 📊 Changes **2 files changed** (+89 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `runtime/src/vulkan_replay.h` (+9 -6) 📝 `runtime/test/vk_bc_zero_init_test.cpp` (+80 -0) </details> ### 📄 Description ### Summary (AI-assisted) Fixes `VK-ZERO-INIT-FILL-ALIGN` in `runtime/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`) into `detail::zero_compressed_image()`. When `vk.zero_buffer` is absent (the `vk.copy_scratch` + `vk.fill_buffer` fallback), `zero_compressed_image()` previously rounded `fill_bytes` and `align` only to `fmt.bytes`, assuming `fmt.bytes` was 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-aligned `size` (and, with non-4-aligned scratch offsets, a non-4-byte-aligned `dstOffset`) to `vkCmdFillBuffer`, violating `VUID-vkCmdFillBuffer-dstOffset-00024` and `VUID-vkCmdFillBuffer-size-00028`. ### Changes - `runtime/src/vulkan_replay.h`: In `zero_compressed_image()`, use `align = std::max<VkDeviceSize>(4, fmt.bytes)` when sizing the scratch request, computing `pad`, and rounding `usable` down to a multiple of `align` before calling `vk.fill_buffer()`. - `runtime/test/vk_bc_zero_init_test.cpp`: - Add real-GPU Vulkan copy-queue (`VulkanQueue::QueueKind::copy`) zero-init readback tests for poisoned (`0x5A`) `3x3` `VK_FORMAT_R8_UNORM` and `3x1` `VK_FORMAT_R16_UNORM` textures via `copy_scratch` (no `zero_buffer`). - Add a direct `ReplayFunctions` alignment check verifying `dstOffset % 4 == 0` and `size % 4 == 0` for `3x3` `R8_UNORM` even with a deliberately unaligned scratch offset (`offset = 2`). ### Verification - **Real Vulkan GPU execution & readback (`vk_bc_zero_init_test.exe`, MSVC 19.44 + Ninja)**: - **NVIDIA GeForce RTX 5060 Ti**: all cases including `copy-queue zero-init (R8_UNORM 3x3 via copy_scratch)` and `copy-queue zero-init (R16_UNORM 3x1 via copy_scratch)` passed (all readback texels `0x00`, 0 validation errors). - **AMD Radeon(TM) Graphics (`gfx1036`, RDNA2)**: all cases passed identically. <details> <summary>中文翻译</summary> ### 摘要 (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` 对齐断言。 ### 验证 - **真实 Vulkan GPU 执行与读回(`vk_bc_zero_init_test.exe`)**:在 **NVIDIA RTX 5060 Ti** 与 **AMD Radeon(TM) Graphics(`gfx1036`)** 上均全部通过,读回纹素全为 `0x00`。 </details> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:18:21 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#576
No description provided.