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

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/600
Author: @tahffo68hk-hash
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: fix/vk-texture-barrier-undef-noop


📝 Commits (1)

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

📊 Changes

3 files changed (+174 additions, -2 deletions)

View changed files

📝 runtime/CMakeLists.txt (+15 -0)
📝 runtime/src/vulkan_replay.h (+19 -2)
➕ runtime/test/vk_texture_barrier_undef_noop_test.cpp (+140 -0)

📄 Description

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 辅助:是。

🔄 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/600 **Author:** [@tahffo68hk-hash](https://github.com/tahffo68hk-hash) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/vk-texture-barrier-undef-noop` --- ### 📝 Commits (1) - [`ab302ee`](https://github.com/ubiquitarianism/leonida/commit/ab302eecd34eefa9eccd82f1baf77b2b79cf231e) vulkan_replay: handle UNDEFINED->UNDEFINED TextureBarrier without illegal newLayout (VK-TEXTURE-BARRIER-UNDEF-NOOP) ### 📊 Changes **3 files changed** (+174 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `runtime/CMakeLists.txt` (+15 -0) 📝 `runtime/src/vulkan_replay.h` (+19 -2) ➕ `runtime/test/vk_texture_barrier_undef_noop_test.cpp` (+140 -0) </details> ### 📄 Description ## 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> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#642
No description provided.