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

Closed
tahffo68hk-hash wants to merge 1 commit from upstream-pr/600 into main
tahffo68hk-hash commented 2026-11-24 09:44:40 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by tahffo68hk-hash on 2026-11-24T09:44:40Z.


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 辅助:是。
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5469757994 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/600). Originally posted by [tahffo68hk-hash](https://github.com/tahffo68hk-hash) on 2026-11-24T09:44:40Z. --- ## 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>
trigger337 commented 2026-11-24 09:50:05 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by trigger337 on 2026-11-24T09:50:05Z.


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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7127953260 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/600#issuecomment-7127953260). Originally posted by [trigger337](https://github.com/trigger337) on 2026-11-24T09:50:05Z. --- 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
MoonEyes commented 2026-11-27 23:20:10 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-27T23:20:10Z.


Hi @tahffo68hk-hash, thanks for this pull request. It currently conflicts with main (conflicting file(s): runtime/CMakeLists.txt), so it carries the needs rebase label. CONTRIBUTING.md asks authors to rebase their branch on main; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7230060790 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/600#issuecomment-7230060790). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-27T23:20:10Z. --- Hi @tahffo68hk-hash, thanks for this pull request. It currently conflicts with `main` (conflicting file(s): `runtime/CMakeLists.txt`), so it carries the `needs rebase` label. CONTRIBUTING.md asks authors to rebase their branch on `main`; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here. AI-assisted (Claude Code, Claude Opus 5.5).
aslan2142 commented 2026-12-01 16:30:57 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T16:30:57Z.


Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7317734285 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/600#issuecomment-7317734285). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T16:30:57Z. --- Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!600
No description provided.