[PR #418] [MERGED] vulkan_replay: validate backing buffer_offset alignment in buffer UAV clear (VK-UAV-CLEAR-ALIGN) #469

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

📋 Pull Request Information

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

Base: main ← Head: fix/vk-uav-clear-align


📝 Commits (1)

  • c9099b0 vulkan_replay: validate backing buffer_offset alignment in prepare_buffer_uav_clear (VK-UAV-CLEAR-ALIGN)

📊 Changes

2 files changed (+13 additions, -0 deletions)

View changed files

📝 runtime/src/vulkan_replay.h (+1 -0)
📝 runtime/test/replay_uav_clear_offset_test.cpp (+12 -0)

📄 Description

Claimed in the coordination issue as: VK-UAV-CLEAR-ALIGN

Problem

prepare_buffer_uav_clear() in runtime/src/vulkan_replay.h checked offset % std::min(e, 4u) before adding p.binding.buffer_offset. When a sub-allocated buffer has a misaligned buffer_offset:

  1. For 8- or 16-byte UAV elements (e > 4, e.g., R32G32B32A32_UINT), emit_buffer_fill() called vkCmdUpdateBuffer with dstOffset % 4 != 0, violating VUID-vkCmdUpdateBuffer-dstOffset-00032.
  2. For 2- or 4-byte UAV elements (e == 2 or e == 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 checks backing_offset % alignment after adding buffer.buffer_offset.)

Fix

  • In prepare_buffer_uav_clear(), check if (offset % std::min(e, 4u)) return ReplayResult::unsupported; after adding p.binding.buffer_offset, while still allowing odd buffer_offset for 1-byte (R8_*) elements.
  • Add regression tests in runtime/test/replay_uav_clear_offset_test.cpp covering misaligned buffer_offset for 16-byte, 4-byte, 2-byte, and 1-byte UAV clears.

Verification

  • Built with MSVC 19.44 + Ninja (-DLEONIDA_BUILD_WINDOWS_RUNTIME=OFF) on Windows 11.
  • ctest -R "^replay_uav_clear_offset$" --output-on-failure -> 1/1 PASS (no game files).
  • AI-assisted: Yes (Antigravity).
中文翻译

在协调帖 #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 未对齐时:

  1. 对 8/16 字节元素(e > 4)会以未 4 字节对齐的 dstOffset 调用 vkCmdUpdateBuffer,违反 VUID-vkCmdUpdateBuffer-dstOffset-00032;
  2. 对 2/4 字节元素会以未旋转字填充,导致写入元素字节错位。

修复方案

  • 在叠加 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 字节元素的回归测试。

验证结果

  • Windows 11 + MSVC 19.44 + Ninja 编译并通过 ctest -R "^replay_uav_clear_offset$"(无游戏文件)。
  • AI 辅助:是(Antigravity)。

🔄 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/418 **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-uav-clear-align` --- ### 📝 Commits (1) - [`c9099b0`](https://github.com/ubiquitarianism/leonida/commit/c9099b0cad7287923e15300669d92b0c08c3e3f6) vulkan_replay: validate backing buffer_offset alignment in prepare_buffer_uav_clear (VK-UAV-CLEAR-ALIGN) ### 📊 Changes **2 files changed** (+13 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `runtime/src/vulkan_replay.h` (+1 -0) 📝 `runtime/test/replay_uav_clear_offset_test.cpp` (+12 -0) </details> ### 📄 Description Claimed in the coordination issue as: `VK-UAV-CLEAR-ALIGN` ## Problem `prepare_buffer_uav_clear()` in `runtime/src/vulkan_replay.h` checked `offset % std::min(e, 4u)` *before* adding `p.binding.buffer_offset`. When a sub-allocated buffer has a misaligned `buffer_offset`: 1. For 8- or 16-byte UAV elements (`e > 4`, e.g., `R32G32B32A32_UINT`), `emit_buffer_fill()` called `vkCmdUpdateBuffer` with `dstOffset % 4 != 0`, violating `VUID-vkCmdUpdateBuffer-dstOffset-00032`. 2. For 2- or 4-byte UAV elements (`e == 2` or `e == 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 checks `backing_offset % alignment` after adding `buffer.buffer_offset`.) ## Fix - In `prepare_buffer_uav_clear()`, check `if (offset % std::min(e, 4u)) return ReplayResult::unsupported;` after adding `p.binding.buffer_offset`, while still allowing odd `buffer_offset` for 1-byte (`R8_*`) elements. - Add regression tests in `runtime/test/replay_uav_clear_offset_test.cpp` covering misaligned `buffer_offset` for 16-byte, 4-byte, 2-byte, and 1-byte UAV clears. ## Verification - Built with MSVC 19.44 + Ninja (`-DLEONIDA_BUILD_WINDOWS_RUNTIME=OFF`) on Windows 11. - `ctest -R "^replay_uav_clear_offset$" --output-on-failure` -> 1/1 PASS (no game files). - AI-assisted: Yes (Antigravity). <details> <summary>中文翻译</summary> 在协调帖 #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` 未对齐时: 1. 对 8/16 字节元素(`e > 4`)会以未 4 字节对齐的 `dstOffset` 调用 `vkCmdUpdateBuffer`,违反 `VUID-vkCmdUpdateBuffer-dstOffset-00032`; 2. 对 2/4 字节元素会以未旋转字填充,导致写入元素字节错位。 ## 修复方案 - 在叠加 `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 字节元素的回归测试。 ## 验证结果 - Windows 11 + MSVC 19.44 + Ninja 编译并通过 `ctest -R "^replay_uav_clear_offset$"`(无游戏文件)。 - AI 辅助:是(Antigravity)。 </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:17:59 +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#469
No description provided.