[PR #434] [MERGED] vulkan_replay: honor format alignment, block size, and depth in tile_footprint staging #487

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

📋 Pull Request Information

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

Base: main ← Head: fix/vk-tile-copy-align


📝 Commits (1)

  • cfb3436 vulkan_replay: honor format alignment, block size, and depth in tile_footprint staging

📊 Changes

2 files changed (+138 additions, -14 deletions)

View changed files

📝 runtime/src/vulkan_replay.h (+41 -14)
📝 runtime/test/replay_copy_offset_test.cpp (+97 -0)

📄 Description

Summary

(AI-assisted) Fixes VK-TILE-COPY-ALIGN in
untime/src/vulkan_replay.h:

  1. Missed Vulkan alignment check (VUID-vkCmdCopyBufferToImage-dstImage-07975 / VUID-vkCmdCopyImageToBuffer-srcImage-07975): prepare_texture_copy() skips the offset % alignment / acking_offset % alignment rejection when copy.tile_footprint is true (for any format alignment), but the caller in prepare_replay() only checked ufferOffset % 4 instead of ufferOffset % alignment. A ile_footprint copy with a 4-byte-aligned (but not 8- or 16-byte-aligned) offset on an 8B/16B texel or BC format bypassed staging and emitted an unaligned VkBufferImageCopy.
  2. Hardcoded RGBA8 2D geometry in stage_unaligned_tile(): stage_unaligned_tile() hardcoded * 4 for
    ow_bytes and pitch, ignored mt.block for block-compressed formats, ignored imageExtent.depth > 1 (only copying slice 0), left ufferImageHeight non-zero on the tightly-packed scratch region, and did not guard against
    gb96 / depth24_as_float paths that read uffer.buffer directly.

Changes

untime/src/vulkan_replay.h:

  • Compute the exact format alignment via copy_block_format(image, aspectMask) when deciding whether a ile_footprint copy needs staging.
  • Generalize stage_unaligned_tile() to compute block-rounded
    ow_bytes, pitch, slice_rows, slice_pitch, and depth slices from BlockFormat, clear ufferImageHeight = 0 alongside ufferRowLength = 0, and reject unsupported
    gb96 / depth24_as_float unaligned tile staging.

untime/test/replay_copy_offset_test.cpp: Add regression coverage for 8-byte 3D (VK_FORMAT_R16G16B16A16_SFLOAT) and block-compressed (VK_FORMAT_BC1_RGBA_UNORM_BLOCK) ile_footprint copies with offset = 4, verifying scratch size, per-row/per-slice VkBufferCopy offsets/sizes, aligned VkBufferImageCopy::bufferOffset, and cleared ufferRowLength/ufferImageHeight.

Verification

  • Built
    eplay_copy_offset_test with MSVC 19.44 + Ninja and ran ctest -R "^replay_copy_offset$" --output-on-failure: 1/1 PASS (0.16s).
中文翻译

摘要

(AI 辅助)修复
untime/src/vulkan_replay.h 中的 VK-TILE-COPY-ALIGN:

  1. 漏检 Vulkan 偏移对齐(VUID-vkCmdCopyBufferToImage-dstImage-07975 / VUID-vkCmdCopyImageToBuffer-srcImage-07975):当 copy.tile_footprint 为真时,prepare_texture_copy() 会跳过任意格式的对齐拒绝检查,但 prepare_replay() 仅判断 ufferOffset % 4 而非 ufferOffset % alignment。对于 8 字节/16 字节纹素或 BC 压缩格式,偏移为 4 的拷贝会绕过暂存直接发出非对齐的 VkBufferImageCopy。
  2. stage_unaligned_tile() 硬编码 RGBA8 2D 布局:原实现将
    ow_bytes 与 pitch 硬编码乘以 4,未处理块压缩格式的 mt.block,未拷贝 depth > 1 的后续切片且未清零 ufferImageHeight,也未拦截与暂存路径冲突的
    gb96 / depth24_as_float 路径。

改动

untime/src/vulkan_replay.h:按 copy_block_format(image, aspectMask) 计算真实格式对齐;泛化 stage_unaligned_tile() 支持任意元素字节数、块压缩尺寸与 3D 切片,并清零 ufferImageHeight。

untime/test/replay_copy_offset_test.cpp:新增 8 字节 3D(R16G16B16A16_SFLOAT)与 BC1_RGBA_UNORM_BLOCK 在 offset=4 下的回归测试,验证暂存大小、行/切片步长及 VkBufferImageCopy 对齐参数。

验证

  • MSVC 19.44 + Ninja 编译并通过 ctest -R "^replay_copy_offset$":1/1 PASS。

🔄 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/434 **Author:** [@tahffo68hk-hash](https://github.com/tahffo68hk-hash) **Created:** 11/24/2026 **Status:** ✅ Merged **Merged:** 11/24/2026 **Merged by:** [@QemmHD](https://github.com/QemmHD) **Base:** `main` ← **Head:** `fix/vk-tile-copy-align` --- ### 📝 Commits (1) - [`cfb3436`](https://github.com/ubiquitarianism/leonida/commit/cfb343636943adc40108c636951eadc95ef3490d) vulkan_replay: honor format alignment, block size, and depth in tile_footprint staging ### 📊 Changes **2 files changed** (+138 additions, -14 deletions) <details> <summary>View changed files</summary> 📝 `runtime/src/vulkan_replay.h` (+41 -14) 📝 `runtime/test/replay_copy_offset_test.cpp` (+97 -0) </details> ### 📄 Description ### Summary (AI-assisted) Fixes VK-TILE-COPY-ALIGN in untime/src/vulkan_replay.h: 1. **Missed Vulkan alignment check (VUID-vkCmdCopyBufferToImage-dstImage-07975 / VUID-vkCmdCopyImageToBuffer-srcImage-07975)**: prepare_texture_copy() skips the offset % alignment / acking_offset % alignment rejection when copy.tile_footprint is true (for any format alignment), but the caller in prepare_replay() only checked ufferOffset % 4 instead of ufferOffset % alignment. A ile_footprint copy with a 4-byte-aligned (but not 8- or 16-byte-aligned) offset on an 8B/16B texel or BC format bypassed staging and emitted an unaligned VkBufferImageCopy. 2. **Hardcoded RGBA8 2D geometry in stage_unaligned_tile()**: stage_unaligned_tile() hardcoded * 4 for ow_bytes and pitch, ignored mt.block for block-compressed formats, ignored imageExtent.depth > 1 (only copying slice 0), left ufferImageHeight non-zero on the tightly-packed scratch region, and did not guard against gb96 / depth24_as_float paths that read uffer.buffer directly. ### Changes - untime/src/vulkan_replay.h: - Compute the exact format alignment via copy_block_format(image, aspectMask) when deciding whether a ile_footprint copy needs staging. - Generalize stage_unaligned_tile() to compute block-rounded ow_bytes, pitch, slice_rows, slice_pitch, and depth slices from BlockFormat, clear ufferImageHeight = 0 alongside ufferRowLength = 0, and reject unsupported gb96 / depth24_as_float unaligned tile staging. - untime/test/replay_copy_offset_test.cpp: Add regression coverage for 8-byte 3D (VK_FORMAT_R16G16B16A16_SFLOAT) and block-compressed (VK_FORMAT_BC1_RGBA_UNORM_BLOCK) ile_footprint copies with offset = 4, verifying scratch size, per-row/per-slice VkBufferCopy offsets/sizes, aligned VkBufferImageCopy::bufferOffset, and cleared ufferRowLength/ufferImageHeight. ### Verification - Built eplay_copy_offset_test with MSVC 19.44 + Ninja and ran ctest -R "^replay_copy_offset$" --output-on-failure: **1/1 PASS** (0.16s). <details> <summary>中文翻译</summary> ### 摘要 (AI 辅助)修复 untime/src/vulkan_replay.h 中的 VK-TILE-COPY-ALIGN: 1. **漏检 Vulkan 偏移对齐(VUID-vkCmdCopyBufferToImage-dstImage-07975 / VUID-vkCmdCopyImageToBuffer-srcImage-07975)**:当 copy.tile_footprint 为真时,prepare_texture_copy() 会跳过任意格式的对齐拒绝检查,但 prepare_replay() 仅判断 ufferOffset % 4 而非 ufferOffset % alignment。对于 8 字节/16 字节纹素或 BC 压缩格式,偏移为 4 的拷贝会绕过暂存直接发出非对齐的 VkBufferImageCopy。 2. **stage_unaligned_tile() 硬编码 RGBA8 2D 布局**:原实现将 ow_bytes 与 pitch 硬编码乘以 4,未处理块压缩格式的 mt.block,未拷贝 depth > 1 的后续切片且未清零 ufferImageHeight,也未拦截与暂存路径冲突的 gb96 / depth24_as_float 路径。 ### 改动 - untime/src/vulkan_replay.h:按 copy_block_format(image, aspectMask) 计算真实格式对齐;泛化 stage_unaligned_tile() 支持任意元素字节数、块压缩尺寸与 3D 切片,并清零 ufferImageHeight。 - untime/test/replay_copy_offset_test.cpp:新增 8 字节 3D(R16G16B16A16_SFLOAT)与 BC1_RGBA_UNORM_BLOCK 在 offset=4 下的回归测试,验证暂存大小、行/切片步长及 VkBufferImageCopy 对齐参数。 ### 验证 - MSVC 19.44 + Ninja 编译并通过 ctest -R "^replay_copy_offset$":**1/1 PASS**。 </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:02 +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#487
No description provided.