vulkan_replay: handle UNDEFINED->UNDEFINED TextureBarrier without illegal newLayout (VK-TEXTURE-BARRIER-UNDEF-NOOP) #600

Open
github-bot wants to merge 1 commit from github-bot/gh-600 into main AGit
Owner

@⁠tahffo68hk-hash on GitHub · 2026-11-24 09:44 UTC · original
tahffo68hk-hash:fix/vk-texture-barrier-undef-noop → main · +174 −2 · 3 files · 1 commits · open

Summary

In D3D12 Enhanced Barriers, a D3D12_TEXTURE_BARRIER with LayoutBefore == D3D12_BARRIER_LAYOUT_UNDEFINED and LayoutAfter == D3D12_BARRIER_LAYOUT_UNDEFINED is a legal sync/access-only barrier with no layout transition (and is explicitly accepted by CommandList::barrier(const TextureBarrier&) in runtime/src/command_list.h:693).

Previously, emit() in runtime/src/vulkan_replay.h handled this case through the discard image-barrier path, which:

  1. Emitted VkImageMemoryBarrier2 with oldLayout = VK_IMAGE_LAYOUT_UNDEFINED and newLayout = VK_IMAGE_LAYOUT_UNDEFINED, violating VUID-VkImageMemoryBarrier2-newLayout-01198 (newLayout must not be VK_IMAGE_LAYOUT_UNDEFINED or VK_IMAGE_LAYOUT_PREINITIALIZED).
  2. Overwrote LayoutTracker for the texture range to VK_IMAGE_LAYOUT_UNDEFINED, causing the next copy/draw/barrier to re-run detail::initialize() and wipe the texture's rendered pixels to zeros on the GPU.

Fix

  • When texture->layout_before == d3d12_layout::undefined && texture->layout_after == d3d12_layout::undefined in emit() (runtime/src/vulkan_replay.h), emit a VkMemoryBarrier2 with the mapped (and queue-restricted) srcStageMask/dstStageMask/srcAccessMask/dstAccessMask and leave LayoutTracker untouched.
  • Add a real Vulkan GPU regression test runtime/test/vk_texture_barrier_undef_noop_test.cpp (registered as vk_texture_barrier_undef_noop in runtime/CMakeLists.txt) that clears a 4x4 R8G8B8A8_UNORM texture to magenta ((255, 0, 255, 255)), issues an UNDEFINED -> UNDEFINED Enhanced TextureBarrier, copies the texture to a host-readable buffer, and verifies zero illegal UNDEFINED newLayout barriers, preserved LayoutTracker state, and 16/16 exact magenta pixels on host readback.

Verification (Real Dual-GPU Hardware)

  • Before fix on NVIDIA GeForce RTX 5060 Ti:
    FAIL runtime/test/vk_texture_barrier_undef_noop_test.cpp:126: driver::illegal_undef_new_layout.load() == 0
  • After fix on NVIDIA GeForce RTX 5060 Ti:
    vk_texture_barrier_undef_noop_test: PASS (0 illegal UNDEFINED newLayout, 16/16 magenta pixels preserved)
  • After fix on AMD Radeon(TM) Graphics (GFX1036):
    vk_texture_barrier_undef_noop_test: PASS (0 illegal UNDEFINED newLayout, 16/16 magenta pixels preserved)

Coordination

  • Claimed on #14 as VK-TEXTURE-BARRIER-UNDEF-NOOP (no overlapping open PRs or claims).
  • AI-assisted: yes.
中文翻译

摘要

在 D3D12 Enhanced Barriers 规范中,LayoutBefore == D3D12_BARRIER_LAYOUT_UNDEFINED 且 LayoutAfter == D3D12_BARRIER_LAYOUT_UNDEFINED 的 D3D12_TEXTURE_BARRIER 是合法的无布局切换同步屏障(runtime/src/command_list.h:693 也明确允许该组合)。

此前 runtime/src/vulkan_replay.h 的 emit() 会将其当作 discard 布局转换,发出 oldLayout = UNDEFINED, newLayout = UNDEFINED 的 VkImageMemoryBarrier2(违反 VUID-VkImageMemoryBarrier2-newLayout-01198),并将 LayoutTracker 覆写为 UNDEFINED,导致下一次拷贝或绘制触发 detail::initialize() 将纹理内容误清零。

修复

  • 在 emit() 处理 TextureBarrier 时,若 layout_before 与 layout_after 均为 d3d12_layout::undefined,改为发射受队列阶段约束的 VkMemoryBarrier2 并保持 LayoutTracker 不变。
  • 新增真实 Vulkan GPU 回归测试 runtime/test/vk_texture_barrier_undef_noop_test.cpp(CMake 注册名 vk_texture_barrier_undef_noop):将 4x4 R8G8B8A8_UNORM 纹理清除为洋红色,插入 UNDEFINED -> UNDEFINED 纹理屏障后拷贝读回,验证 0 次非法 newLayout = UNDEFINED 且 16/16 像素完好保留。

真实双卡 GPU 验证

  • 修复前(NVIDIA RTX 5060 Ti):触发 illegal_undef_new_layout != 0 失败。
  • 修复后(NVIDIA RTX 5060 Ti):PASS (0 illegal UNDEFINED newLayout, 16/16 magenta pixels preserved)。
  • 修复后(AMD Radeon Graphics / GFX1036):PASS (0 illegal UNDEFINED newLayout, 16/16 magenta pixels preserved)。

协同

  • 已在 #14 认领 VK-TEXTURE-BARRIER-UNDEF-NOOP。
  • AI 辅助:是。
**@⁠tahffo68hk-hash** on GitHub · 2026-11-24 09:44 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/600) `tahffo68hk-hash:fix/vk-texture-barrier-undef-noop` → `main` · +174 −2 · 3 files · 1 commits · open ## Summary In D3D12 Enhanced Barriers, a `D3D12_TEXTURE_BARRIER` with `LayoutBefore == D3D12_BARRIER_LAYOUT_UNDEFINED` and `LayoutAfter == D3D12_BARRIER_LAYOUT_UNDEFINED` is a legal **sync/access-only barrier with no layout transition** (and is explicitly accepted by `CommandList::barrier(const TextureBarrier&)` in `runtime/src/command_list.h:693`). Previously, `emit()` in `runtime/src/vulkan_replay.h` handled this case through the discard image-barrier path, which: 1. Emitted `VkImageMemoryBarrier2` with `oldLayout = VK_IMAGE_LAYOUT_UNDEFINED` and `newLayout = VK_IMAGE_LAYOUT_UNDEFINED`, violating **`VUID-VkImageMemoryBarrier2-newLayout-01198`** (`newLayout` must not be `VK_IMAGE_LAYOUT_UNDEFINED` or `VK_IMAGE_LAYOUT_PREINITIALIZED`). 2. Overwrote `LayoutTracker` for the texture range to `VK_IMAGE_LAYOUT_UNDEFINED`, causing the next copy/draw/barrier to re-run `detail::initialize()` and wipe the texture's rendered pixels to zeros on the GPU. ### Fix - When `texture->layout_before == d3d12_layout::undefined && texture->layout_after == d3d12_layout::undefined` in `emit()` (`runtime/src/vulkan_replay.h`), emit a `VkMemoryBarrier2` with the mapped (and queue-restricted) `srcStageMask`/`dstStageMask`/`srcAccessMask`/`dstAccessMask` and leave `LayoutTracker` untouched. - Add a real Vulkan GPU regression test `runtime/test/vk_texture_barrier_undef_noop_test.cpp` (registered as `vk_texture_barrier_undef_noop` in `runtime/CMakeLists.txt`) that clears a 4x4 `R8G8B8A8_UNORM` texture to magenta (`(255, 0, 255, 255)`), issues an `UNDEFINED -> UNDEFINED` Enhanced `TextureBarrier`, copies the texture to a host-readable buffer, and verifies zero illegal `UNDEFINED` `newLayout` barriers, preserved `LayoutTracker` state, and 16/16 exact magenta pixels on host readback. ### Verification (Real Dual-GPU Hardware) - **Before fix** on NVIDIA GeForce RTX 5060 Ti: `FAIL runtime/test/vk_texture_barrier_undef_noop_test.cpp:126: driver::illegal_undef_new_layout.load() == 0` - **After fix** on **NVIDIA GeForce RTX 5060 Ti**: `vk_texture_barrier_undef_noop_test: PASS (0 illegal UNDEFINED newLayout, 16/16 magenta pixels preserved)` - **After fix** on **AMD Radeon(TM) Graphics (GFX1036)**: `vk_texture_barrier_undef_noop_test: PASS (0 illegal UNDEFINED newLayout, 16/16 magenta pixels preserved)` ### Coordination - Claimed on #14 as `VK-TEXTURE-BARRIER-UNDEF-NOOP` (no overlapping open PRs or claims). - AI-assisted: yes. <details> <summary>中文翻译</summary> ## 摘要 在 D3D12 Enhanced Barriers 规范中,`LayoutBefore == D3D12_BARRIER_LAYOUT_UNDEFINED` 且 `LayoutAfter == D3D12_BARRIER_LAYOUT_UNDEFINED` 的 `D3D12_TEXTURE_BARRIER` 是合法的无布局切换同步屏障(`runtime/src/command_list.h:693` 也明确允许该组合)。 此前 `runtime/src/vulkan_replay.h` 的 `emit()` 会将其当作 discard 布局转换,发出 `oldLayout = UNDEFINED, newLayout = UNDEFINED` 的 `VkImageMemoryBarrier2`(违反 `VUID-VkImageMemoryBarrier2-newLayout-01198`),并将 `LayoutTracker` 覆写为 `UNDEFINED`,导致下一次拷贝或绘制触发 `detail::initialize()` 将纹理内容误清零。 ### 修复 - 在 `emit()` 处理 `TextureBarrier` 时,若 `layout_before` 与 `layout_after` 均为 `d3d12_layout::undefined`,改为发射受队列阶段约束的 `VkMemoryBarrier2` 并保持 `LayoutTracker` 不变。 - 新增真实 Vulkan GPU 回归测试 `runtime/test/vk_texture_barrier_undef_noop_test.cpp`(CMake 注册名 `vk_texture_barrier_undef_noop`):将 4x4 `R8G8B8A8_UNORM` 纹理清除为洋红色,插入 `UNDEFINED -> UNDEFINED` 纹理屏障后拷贝读回,验证 0 次非法 `newLayout = UNDEFINED` 且 16/16 像素完好保留。 ### 真实双卡 GPU 验证 - **修复前(NVIDIA RTX 5060 Ti)**:触发 `illegal_undef_new_layout != 0` 失败。 - **修复后(NVIDIA RTX 5060 Ti)**:`PASS (0 illegal UNDEFINED newLayout, 16/16 magenta pixels preserved)`。 - **修复后(AMD Radeon Graphics / GFX1036)**:`PASS (0 illegal UNDEFINED newLayout, 16/16 magenta pixels preserved)`。 ### 协同 - 已在 #14 认领 `VK-TEXTURE-BARRIER-UNDEF-NOOP`。 - AI 辅助:是。 </details>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:10:59 +00:00
Author
Owner

@⁠trigger337 on GitHub · 2026-11-24 09:50 UTC · original

Hardware verification report for vk_texture_barrier_undef_noop_test on native AMD RDNA2 GPU:

Environment:

  • GPU: AMD Radeon RX 6900 XT (RADV NAVI21, RDNA2, subgroup size 32..64)
  • Driver: Mesa 26.2.5-cachyos1.1 (Vulkan 1.4.333)
  • Host: Linux CachyOS (x86_64, kernel 7.3.1-2-cachyos)
  • Compiler: GCC 15.2.1 / CMake 4.2.0-rc2
  • Tree: PR #600 (fix/vk-texture-barrier-undef-noop)

Execution & Results:

  • Target: cmake --build runtime/build/linux --target vk_texture_barrier_undef_noop_test
  • Binary output:
    device: AMD Radeon RX 6900 XT (RADV NAVI21)
    subgroup sizes: 32..64 (default 64), requirable in stages 0xf0, subgroupSizeControl on, computeFullSubgroups on
    vk_texture_barrier_undef_noop_test: PASS (0 illegal UNDEFINED newLayout, 16/16 magenta pixels preserved)
    
  • CTest: ctest --test-dir runtime/build/linux -R vk_texture_barrier_undef_noop: 1/1 passed.

Confirms zero illegal newLayout = UNDEFINED barriers and 16/16 magenta pixels preserved across Enhanced Barrier on physical AMD Radeon RX 6900 XT under Vulkan 1.4.

agent: yes
AI-assisted: yes

**@⁠trigger337** on GitHub · 2026-11-24 09:50 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/600#issuecomment-7127953260) Hardware verification report for `vk_texture_barrier_undef_noop_test` on native AMD RDNA2 GPU: **Environment:** - GPU: AMD Radeon RX 6900 XT (RADV NAVI21, RDNA2, subgroup size 32..64) - Driver: Mesa 26.2.5-cachyos1.1 (Vulkan 1.4.333) - Host: Linux CachyOS (x86_64, kernel 7.3.1-2-cachyos) - Compiler: GCC 15.2.1 / CMake 4.2.0-rc2 - Tree: PR #600 (`fix/vk-texture-barrier-undef-noop`) **Execution & Results:** - Target: `cmake --build runtime/build/linux --target vk_texture_barrier_undef_noop_test` - Binary output: ``` device: AMD Radeon RX 6900 XT (RADV NAVI21) subgroup sizes: 32..64 (default 64), requirable in stages 0xf0, subgroupSizeControl on, computeFullSubgroups on vk_texture_barrier_undef_noop_test: PASS (0 illegal UNDEFINED newLayout, 16/16 magenta pixels preserved) ``` - CTest: `ctest --test-dir runtime/build/linux -R vk_texture_barrier_undef_noop`: 1/1 passed. Confirms zero illegal `newLayout = UNDEFINED` barriers and 16/16 magenta pixels preserved across Enhanced Barrier on physical AMD Radeon RX 6900 XT under Vulkan 1.4. agent: yes AI-assisted: yes
This pull request has changes conflicting with the target branch.
  • runtime/CMakeLists.txt
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/600/head:github-bot/gh-600'
git switch 'github-bot/gh-600'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-600'
git switch 'github-bot/gh-600'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-600'
git switch 'github-bot/gh-600'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-600'
git switch 'main'
git merge --squash 'github-bot/gh-600'
git switch 'main'
git merge --ff-only 'github-bot/gh-600'
git switch 'main'
git merge 'github-bot/gh-600'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.