[PR #1055] [MERGED] d3d12: an enhanced texture barrier into LAYOUT_UNDEFINED closes and keeps the layout (D3D-BARRIER-INTO-UNDEFINED) #1091

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1055
Author: @milk4sale
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/25/2026
Merged by: @aslan2142

Base: main ← Head: d3d12/barrier-into-undefined


📝 Commits (3)

  • 37c5af1 d3d12: an enhanced texture barrier into LAYOUT_UNDEFINED closes and keeps the layout (D3D-BARRIER-INTO-UNDEFINED)
  • 8c1b8da Merge main into d3d12/barrier-into-undefined
  • 59dcc9e Merge main into d3d12/barrier-into-undefined

📊 Changes

8 files changed (+446 additions, -17 deletions)

View changed files

📝 docs/d3d12_vulkan.md (+19 -1)
📝 runtime/src/command_list.h (+3 -2)
📝 runtime/src/vulkan_replay.h (+19 -8)
📝 runtime/test/command_list_test.cpp (+6 -2)
📝 runtime/test/d3d12_close_parity_test.cpp (+54 -1)
📝 runtime/test/d3d12_com_test.cpp (+93 -0)
📝 runtime/test/replay_texture_barrier_test.cpp (+135 -1)
📝 runtime/test/vk_command_replay_test.cpp (+117 -2)

📄 Description

Claimed in the coordination issue as: D3D-BARRIER-INTO-UNDEFINED (claim)

What and why

On main, CommandList::barrier(const TextureBarrier&) refuses an enhanced texture barrier whose LayoutAfter is D3D12_BARRIER_LAYOUT_UNDEFINED when LayoutBefore is a defined layout, so the list's Close returns E_INVALIDARG. D3D12 allows that barrier: it says the contents are no longer needed, as before the memory is aliased. #984 measured that WARP closes such a list (Windows 11 26340) and reports that the retail title ends a depth buffer's use this way and takes the failed Close as fatal.

This is the barrier half of item 2 of the split @Moriz82 proposes in #984 ("How this can land"), carried onto current main with Moriz82 as co-author of the commit:

  • Record: the rule goes (runtime/src/command_list.h).
  • Replay: Vulkan has no transition into UNDEFINED (VUID-VkImageMemoryBarrier2-newLayout-01198). Each piece of the range gets a barrier with oldLayout = newLayout, the layout the tracker has for it, which orders the accesses and changes nothing in the image. The tracker keeps those layouts. A piece that was never used gets no barrier and is not zero-filled for it. The next barrier on those subresources starts from UNDEFINED and discards, as before (emit in runtime/src/vulkan_replay.h).
  • Docs: the rule and how it was checked are in docs/d3d12_vulkan.md section 4.3, and the close-parity counts in section 3.2 are 116 cases, 85 matching.

What differs from the code in #984:

  • Only a defined LayoutBefore is treated as a release. UNDEFINED to UNDEFINED behaves as it does on main today and stays with #600 (VK-TEXTURE-BARRIER-UNDEF-NOOP). This branch merges cleanly with #600's head, and on the merged tree replay_texture_barrier_test, command_list_test, #600's vk_texture_barrier_undef_noop_test and vk_command_replay_test (under validation) pass.
  • A release that also carries the discard flag keeps the layouts too, instead of recording nothing.
  • More cases in replay_texture_barrier_test, and two GPU tests (below).

The bindless flush of the same item in #984 is not part of this.

Tested

On main 32950551e plus this commit, RTX 4070 Ti:

Test Result with the change Without it
command_list_test (CPU) passes, natively and under Wine fails at the new check: the barrier is refused
replay_texture_barrier_test (CPU): mips in two layouts each keep theirs, also with the discard flag and without a tracker; an unused image is released with no barrier and no zero-fill; the barrier from UNDEFINED that follows passes, natively and under Wine with only the replay half reverted: 17 failed checks, exit 1
d3d12_close_parity_test, three new enhanced-barrier rows 116 cases, 85 match the measured WARP column, 16 known layer-stricter, 15 known layer-looser, 0 failures (under Wine there is no WARP, so the layer is compared with the measured column) 2 failures: the two rows into UNDEFINED close with 0x80070057
vk_command_replay_test part K (GPU, native): a colour target, a depth buffer whose two planes are in different layouts and an unused image are released; the target is taken from UNDEFINED again, cleared and read back 16 texels exact, no validation errors with VK_LAYER_KHRONOS_validation 1.4.363 with only the replay half reverted: VUID-VkImageMemoryBarrier2-newLayout-01198 four times, part K fails
d3d12_com_test (GPU, D3D12 list and queue, under Wine): a depth buffer is cleared, released, taken from UNDEFINED again, cleared and read back passes, 16 depth and 16 stencil texels exact fails at list->Close() == S_OK

The five tests in the table were run again after the rebase onto 32950551e. The "without it" column and the three runs below are from the same commit on its first base, main 82a2aabcc; the eleven commits in between touch none of these files (shader fixtures, translator tests and four lines of runtime/CMakeLists.txt).

Also run:

  • The native suite on the RTX 4070 Ti: 74 tests, 72 pass and 2 skip (shader_library_corpus and vk_sync_validation).
  • The whole Windows tree cross-builds (clang-cl 23.1.4, xwin SDK 10.0.26100). Under wine-staging 11.21, 32 tests around this code (d3d12_com, d3d12_vulkan_device, d3d12_close_parity, the three d3d12_queue_handover*, d3d12_m2_*, d3d12_m3_*, d3d12_m4_compute, d3d12_draw, the depth, placed, clear and copy tests, the ten replay_* tests, vk_command_replay and command_list): 28 pass, 2 skip, 2 fail. The two that fail, d3d12_clear and d3d12_clear_formats, compare the layer with Wine's own D3D12 and fail the same way without this change: 20 and 99 differing lines, identical line for line on main 82a2aabcc and on this branch.
  • d3d12_com_test and vk_command_replay_test under Wine with the validation layer inserted on the Linux side: the only error is VUID-vkCreateDevice-ppEnabledExtensionNames-01387, which Wine's device creation gives on main too.
  • The tests/test_docs_*.py checks, python -I scripts/check_no_game_data.py on the eight files, and git diff --check.

Not run: Windows itself and MSVC, which I do not have, so no live WARP; the WARP column of the three new rows is #984's measurement on Windows 11 26340 (the test's header names the build the other rows were measured on). The retail title was not booted with this change: that it issues this barrier is #984's report, not something measured here. No AMD or Intel GPU. The rest of the Wine suite was not run.

GPUs tested: NVIDIA GeForce RTX 4070 Ti, driver 620.70.06, Linux (CachyOS): natively, and through wine-staging 11.21

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.

🤖 Generated with Claude Code


🔄 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/1055 **Author:** [@milk4sale](https://github.com/milk4sale) **Created:** 11/24/2026 **Status:** ✅ Merged **Merged:** 11/25/2026 **Merged by:** [@aslan2142](https://github.com/aslan2142) **Base:** `main` ← **Head:** `d3d12/barrier-into-undefined` --- ### 📝 Commits (3) - [`37c5af1`](https://github.com/ubiquitarianism/leonida/commit/37c5af12a45f256767e0274b0d1a2d0a858968c8) d3d12: an enhanced texture barrier into LAYOUT_UNDEFINED closes and keeps the layout (D3D-BARRIER-INTO-UNDEFINED) - [`8c1b8da`](https://github.com/ubiquitarianism/leonida/commit/8c1b8da1526564f01e1e3c5ad3d628db8c60169c) Merge main into d3d12/barrier-into-undefined - [`59dcc9e`](https://github.com/ubiquitarianism/leonida/commit/59dcc9e91713887215168873f0c5268e4298cfd9) Merge main into d3d12/barrier-into-undefined ### 📊 Changes **8 files changed** (+446 additions, -17 deletions) <details> <summary>View changed files</summary> 📝 `docs/d3d12_vulkan.md` (+19 -1) 📝 `runtime/src/command_list.h` (+3 -2) 📝 `runtime/src/vulkan_replay.h` (+19 -8) 📝 `runtime/test/command_list_test.cpp` (+6 -2) 📝 `runtime/test/d3d12_close_parity_test.cpp` (+54 -1) 📝 `runtime/test/d3d12_com_test.cpp` (+93 -0) 📝 `runtime/test/replay_texture_barrier_test.cpp` (+135 -1) 📝 `runtime/test/vk_command_replay_test.cpp` (+117 -2) </details> ### 📄 Description Claimed in the coordination issue as: D3D-BARRIER-INTO-UNDEFINED ([claim](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7138180483)) ### What and why On `main`, `CommandList::barrier(const TextureBarrier&)` refuses an enhanced texture barrier whose `LayoutAfter` is `D3D12_BARRIER_LAYOUT_UNDEFINED` when `LayoutBefore` is a defined layout, so the list's `Close` returns `E_INVALIDARG`. D3D12 allows that barrier: it says the contents are no longer needed, as before the memory is aliased. #984 measured that WARP closes such a list (Windows 11 26340) and reports that the retail title ends a depth buffer's use this way and takes the failed `Close` as fatal. This is the barrier half of item 2 of the split @Moriz82 proposes in #984 ("How this can land"), carried onto current `main` with Moriz82 as co-author of the commit: - **Record:** the rule goes (`runtime/src/command_list.h`). - **Replay:** Vulkan has no transition into `UNDEFINED` (VUID-VkImageMemoryBarrier2-newLayout-01198). Each piece of the range gets a barrier with `oldLayout = newLayout`, the layout the tracker has for it, which orders the accesses and changes nothing in the image. The tracker keeps those layouts. A piece that was never used gets no barrier and is not zero-filled for it. The next barrier on those subresources starts from `UNDEFINED` and discards, as before (`emit` in `runtime/src/vulkan_replay.h`). - **Docs:** the rule and how it was checked are in `docs/d3d12_vulkan.md` section 4.3, and the close-parity counts in section 3.2 are 116 cases, 85 matching. What differs from the code in #984: - Only a defined `LayoutBefore` is treated as a release. `UNDEFINED` to `UNDEFINED` behaves as it does on `main` today and stays with #600 (VK-TEXTURE-BARRIER-UNDEF-NOOP). This branch merges cleanly with #600's head, and on the merged tree `replay_texture_barrier_test`, `command_list_test`, #600's `vk_texture_barrier_undef_noop_test` and `vk_command_replay_test` (under validation) pass. - A release that also carries the discard flag keeps the layouts too, instead of recording nothing. - More cases in `replay_texture_barrier_test`, and two GPU tests (below). The bindless flush of the same item in #984 is not part of this. ### Tested On `main` 32950551e plus this commit, RTX 4070 Ti: | Test | Result with the change | Without it | |---|---|---| | `command_list_test` (CPU) | passes, natively and under Wine | fails at the new check: the barrier is refused | | `replay_texture_barrier_test` (CPU): mips in two layouts each keep theirs, also with the discard flag and without a tracker; an unused image is released with no barrier and no zero-fill; the barrier from `UNDEFINED` that follows | passes, natively and under Wine | with only the replay half reverted: 17 failed checks, exit 1 | | `d3d12_close_parity_test`, three new enhanced-barrier rows | 116 cases, 85 match the measured WARP column, 16 known layer-stricter, 15 known layer-looser, 0 failures (under Wine there is no WARP, so the layer is compared with the measured column) | 2 failures: the two rows into `UNDEFINED` close with `0x80070057` | | `vk_command_replay_test` part K (GPU, native): a colour target, a depth buffer whose two planes are in different layouts and an unused image are released; the target is taken from `UNDEFINED` again, cleared and read back | 16 texels exact, **no validation errors** with VK_LAYER_KHRONOS_validation 1.4.363 | with only the replay half reverted: VUID-VkImageMemoryBarrier2-newLayout-01198 four times, part K fails | | `d3d12_com_test` (GPU, D3D12 list and queue, under Wine): a depth buffer is cleared, released, taken from `UNDEFINED` again, cleared and read back | passes, 16 depth and 16 stencil texels exact | fails at `list->Close() == S_OK` | The five tests in the table were run again after the rebase onto 32950551e. The "without it" column and the three runs below are from the same commit on its first base, `main` 82a2aabcc; the eleven commits in between touch none of these files (shader fixtures, translator tests and four lines of `runtime/CMakeLists.txt`). Also run: - The native suite on the RTX 4070 Ti: 74 tests, 72 pass and 2 skip (`shader_library_corpus` and `vk_sync_validation`). - The whole Windows tree cross-builds (clang-cl 23.1.4, xwin SDK 10.0.26100). Under wine-staging 11.21, 32 tests around this code (`d3d12_com`, `d3d12_vulkan_device`, `d3d12_close_parity`, the three `d3d12_queue_handover*`, `d3d12_m2_*`, `d3d12_m3_*`, `d3d12_m4_compute`, `d3d12_draw`, the depth, placed, clear and copy tests, the ten `replay_*` tests, `vk_command_replay` and `command_list`): 28 pass, 2 skip, 2 fail. The two that fail, `d3d12_clear` and `d3d12_clear_formats`, compare the layer with Wine's own D3D12 and fail the same way without this change: 20 and 99 differing lines, identical line for line on `main` 82a2aabcc and on this branch. - `d3d12_com_test` and `vk_command_replay_test` under Wine with the validation layer inserted on the Linux side: the only error is VUID-vkCreateDevice-ppEnabledExtensionNames-01387, which Wine's device creation gives on `main` too. - The `tests/test_docs_*.py` checks, `python -I scripts/check_no_game_data.py` on the eight files, and `git diff --check`. Not run: Windows itself and MSVC, which I do not have, so no live WARP; the WARP column of the three new rows is #984's measurement on Windows 11 26340 (the test's header names the build the other rows were measured on). The retail title was not booted with this change: that it issues this barrier is #984's report, not something measured here. No AMD or Intel GPU. The rest of the Wine suite was not run. GPUs tested: NVIDIA GeForce RTX 4070 Ti, driver 620.70.06, Linux (CachyOS): natively, and through wine-staging 11.21 AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:20:03 +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#1091
No description provided.