vulkan_replay: honor format alignment, block size, and depth in tile_footprint staging #434

Manually merged
github merged 1 commit from gh-pr/434/head into gh-pr/434/base 2026-11-26 08:59:56 +00:00
Owner

@⁠tahffo68hk-hash on GitHub · 2026-11-24 05:11 UTC · original
tahffo68hk-hash:fix/vk-tile-copy-align → main · +138 −14 · 2 files · 1 commits · merged 2026-11-24 16:25 UTC

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。
**@⁠tahffo68hk-hash** on GitHub · 2026-11-24 05:11 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/434) `tahffo68hk-hash:fix/vk-tile-copy-align` → `main` · +138 −14 · 2 files · 1 commits · merged 2026-11-24 16:25 UTC ### 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>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:59:54 +00:00
github manually merged commit cfb3436369 into gh-pr/434/base 2026-11-26 08:59:56 +00:00
Author
Owner

@⁠moffington on GitHub · 2026-11-24 05:26 UTC · original

Tested cfb34363 on Linux. replay_copy_offset passed. Running the same test against the merge base (2a2b1680) failed seven of the new assertions covering scratch allocation, row and slice offsets, and image-copy parameters for BC1 and 8-byte 3D uploads. This was a CPU replay test that checked the emitted Vulkan command parameters.

**@⁠moffington** on GitHub · 2026-11-24 05:26 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/434#issuecomment-7122956240) Tested cfb34363 on Linux. replay_copy_offset passed. Running the same test against the merge base (2a2b1680) failed seven of the new assertions covering scratch allocation, row and slice offsets, and image-copy parameters for BC1 and 8-byte 3D uploads. This was a CPU replay test that checked the emitted Vulkan command parameters.
Author
Owner

@⁠Dezmonius on GitHub · 2026-11-24 05:45 UTC · original

Independent Windows check of PR head cfb343636 applied to main@8f481cf16. Windows 10 22H2, RTX 5070 / NVIDIA 610.88, MSVC 19.51.36256, Windows SDK 10.0.26100, Vulkan-Headers 1.4.363, Ninja Release.

  • Clean builds: 3/3 passed on the base and with the PR (replay_copy_offset, replay_texture_barrier, d3d12_texture_tiles). The hardware tile test matched 992,768 native D3D12 pixels across four cases in each run.
  • Negative control (new test on unchanged implementation): seven new replay assertions failed for the 8-byte 3D and BC1 uploads. They all pass with the implementation change.
  • Supplemental CPU replay case, run locally on top of the PR: a 16-byte-per-texel 3D readback at offset 4 passed. It stages 128 bytes across two slices, emits four reversed scratch-to-linear row copies, and uses a tightly packed image-copy region at the aligned scratch offset.

Synthetic fixtures only. The Khronos validation layer was unavailable. AI-assisted.

**@⁠Dezmonius** on GitHub · 2026-11-24 05:45 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/434#issuecomment-7123244769) Independent Windows check of PR head `cfb343636` applied to `main@8f481cf16`. Windows 10 22H2, RTX 5070 / NVIDIA 610.88, MSVC 19.51.36256, Windows SDK 10.0.26100, Vulkan-Headers 1.4.363, Ninja Release. - Clean builds: **3/3 passed** on the base and with the PR (`replay_copy_offset`, `replay_texture_barrier`, `d3d12_texture_tiles`). The hardware tile test matched **992,768** native D3D12 pixels across four cases in each run. - Negative control (new test on unchanged implementation): seven new replay assertions failed for the 8-byte 3D and BC1 uploads. They all pass with the implementation change. - Supplemental CPU replay case, run locally on top of the PR: a 16-byte-per-texel 3D **readback** at offset 4 passed. It stages 128 bytes across two slices, emits four reversed scratch-to-linear row copies, and uses a tightly packed image-copy region at the aligned scratch offset. Synthetic fixtures only. The Khronos validation layer was unavailable. AI-assisted.
Author
Owner

@⁠QemmHD on GitHub · 2026-11-24 16:25 UTC · original

Merging.

Why merged: tile_footprint staging now follows the format's real alignment, block size and depth. Before, it assumed 2D RGBA8, which was wrong for 8- and 16-byte texels, BC formats and 3D. moffington showed 7 new asserts fail on the base, and Dezmonius passed it on Windows with an RTX 5070.

Why it's good: replay_copy_offset, replay_texture_barrier and d3d12_texture_tiles all pass both plain and under validation. A possible follow-up, not a blocker: staging now triggers on offset % fmt.bytes, so an R8/R16 tile copy at an offset that isn't a multiple of 4 is no longer staged. On a transfer-only queue that would hit VUID-vkCmdCopyBufferToImage-commandBuffer-07737. main's non-tile path already behaves that way, and the old *4 staging was wrong for R8/R16 anyway; max(4, fmt.bytes) for colour formats would cover both.

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 main 98a977b4b: 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).

**@⁠QemmHD** on GitHub · 2026-11-24 16:25 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/434#issuecomment-7137631874) Merging. **Why merged:** tile_footprint staging now follows the format's real alignment, block size and depth. Before, it assumed 2D RGBA8, which was wrong for 8- and 16-byte texels, BC formats and 3D. moffington showed 7 new asserts fail on the base, and Dezmonius passed it on Windows with an RTX 5070. **Why it's good:** replay_copy_offset, replay_texture_barrier and d3d12_texture_tiles all pass both plain and under validation. A possible follow-up, not a blocker: staging now triggers on offset % fmt.bytes, so an R8/R16 tile copy at an offset that isn't a multiple of 4 is no longer staged. On a transfer-only queue that would hit VUID-vkCmdCopyBufferToImage-commandBuffer-07737. main's non-tile path already behaves that way, and the old *4 staging was wrong for R8/R16 anyway; max(4, fmt.bytes) for colour formats would cover both. 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 main 98a977b4b: 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).
This discussion has been locked. Commenting is limited to contributors.
No description provided.