Skip to content

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

Merged
aslan2142 merged 3 commits into
ProjectLeonida:mainfrom
milk4sale:d3d12/barrier-into-undefined
Nov 24, 2026
Merged

aslan2142 merged 3 commits into
ProjectLeonida:mainfrom
milk4sale:d3d12/barrier-into-undefined

Conversation

@milk4sale

Copy link
Copy Markdown
Contributor

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:

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

Tested

On main 3295055 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 3295055. The "without it" column and the three runs below are from the same commit on its first base, main 82a2aab; 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 82a2aab 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

…eeps the layout (D3D-BARRIER-INTO-UNDEFINED)

CommandList::barrier(TextureBarrier) refused LayoutAfter = UNDEFINED from a
defined layout, so the list's Close failed. D3D12 allows it: the contents are
no longer needed, as before the memory is aliased. WARP closes such a list
(measured on Windows 11 26340 in ProjectLeonida#984), and ProjectLeonida#984 reports that the retail title
ends a depth buffer's use this way and takes the failed Close as fatal.

The rule goes. Vulkan has no transition into UNDEFINED
(VUID-VkImageMemoryBarrier2-newLayout-01198), so replay gives each piece 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 the
layouts. A piece that was never used gets no barrier and is not zero-filled
for it. The next barrier starts from UNDEFINED and discards, as before.

UNDEFINED -> UNDEFINED is not touched here: that is ProjectLeonida#600.

The barrier half of item 2 of the split proposed in ProjectLeonida#984, carried onto main
from Moriz82's integration branch (command_list.h, the emit change and the
command_list_test, replay_texture_barrier_test and d3d12_close_parity_test
cases), restricted to a defined LayoutBefore, with more cases and two GPU
tests added.

Tests:
- command_list_test, replay_texture_barrier_test (CPU): the recorded barrier;
  kept layouts over mips in two layouts, with the discard flag and without a
  tracker; an unused image released without a barrier or a zero-fill; the
  barrier from UNDEFINED that follows.
- d3d12_close_parity_test: three enhanced-barrier rows (116 cases, 85 match).
- vk_command_replay_test part K (GPU): a colour target, a depth buffer whose
  planes are in two layouts and an unused image released; the target used
  again and read back.
- d3d12_com_test (GPU, D3D12 list and queue): a depth buffer cleared,
  released, taken from UNDEFINED again, cleared and read back.

Co-authored-by: Moriz82 <72836413+Moriz82@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@moffington

Copy link
Copy Markdown
Contributor

Reviewed 37c5af12a on Linux with an RTX 3060 (615.78.08) and Vulkan validation enabled.

  • command_list, replay_texture_barrier, and vk_command_replay all passed with zero validation errors.
  • Windows cross-build tests also passed under Wine 11.20.
  • Additional tests covering mixed initialized/uninitialized subresource releases and release/reuse of individual array layers passed. Untouched subresource contents were preserved.
  • The additional test failed as expected on the exact base revision.

No correctness issues found in the release/discard or layout-tracking paths. Also checked merge compatibility with #600; no conflicts.

Wine close-parity testing used recorded WARP expectations rather than native WARP execution.

main gained its own Part K in vk_command_replay_test and a sentence in the
same bullet of docs/d3d12_vulkan.md (D3D-838, pull request 751). Both stay as
they are on main; this branch's release test becomes Part L, and the doc
bullet for LayoutAfter = UNDEFINED names it so.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Nov 24, 2026
@Luna-OS

Luna-OS commented Nov 24, 2026

Copy link
Copy Markdown

Independent Windows verification of 37c5af12a (merge base 3295055).

Host: Windows 11 Pro 26300, NVIDIA GeForce RTX 5070 Ti (driver 621.24, Resizable BAR), live WARP, MSVC 19.44.35207 (VS 2022 Build Tools), Ninja, RelWithDebInfo, LEONIDA_VULKAN_HEADERS_FETCH=ON, LEONIDA_SDL3_FETCH=ON. Two full runs per head: without glslang (272 tests), and with glslang (KhronosGroup main-tot) so d3d12_compute, d3d12_draw and d3d12_mesh are built too (298 tests). No game files. AI-assisted (Claude Code).

base this PR
build OK OK
ctest (no glslang) 271/272 271/272
ctest (glslang) 296/298 296/298
changed tests replay_texture_barrier, vk_command_replay, d3d12_com, d3d12_close_parity, command_list Passed Passed

Failures shared with the merge base 3295055 and not caused by this PR: d3d12_execute_indirect_validation (the five rows of #504), and with glslang d3d12_draw SEGFAULTs on the base too (slot-14 false positive, claimed as D3D-SLOT14-TAIL-NULL-PAGE, PR follows).

@milk4sale

Copy link
Copy Markdown
Contributor Author

Merged main (6293c1c4f) into the branch as 8c1b8da15. The reviewed commit 37c5af12a is still in it: no force-push.

It conflicted with #751, which merged since: #751 added its own Part K to vk_command_replay_test and a sentence to the same bullet of docs/d3d12_vulkan.md section 4.3. Both stay as they are on main. This pull request's release test is now Part L, and its doc bullet says so.

Nothing else of the change moved. Compared with 37c5af12a, the change to runtime/src/command_list.h, runtime/src/vulkan_replay.h and the other four tests is line for line the same; vk_command_replay_test.cpp and the doc differ only by K -> L.

Rerun on the merged tree (RTX 4070 Ti, NVIDIA 620.70.06, Linux): the three native tests with the validation layer 1.4.363 (parts K and L both pass, no validation error), and the five tests under wine-staging 11.21 (d3d12_close_parity still 116 cases, 85 matching). It merges cleanly with #600, #1062, #1099 and #1100. AI-assisted (Claude Code).

@iFeyz

iFeyz commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

AMD run (the "No AMD or Intel GPU" gap): RX 9070 XT (RDNA4, GFX1201), AMD proprietary Windows driver 26.11.2 (Vulkan 1.4.359), Windows 11, MSVC 2022 RelWithDebInfo. Head 8c1b8da15, the five tests this pull request touches built from it:

  • command_list, vk_command_replay, d3d12_com, d3d12_close_parity, replay_texture_barrier: 5 of 5 pass, no build warning or error in the touched files.

@azsekazvamdimitar

Copy link
Copy Markdown
Contributor

Checked on Linux with Wine and Proton (VERIFY-WINE-PROTON-GPU in #14). AI-assisted; no game files, not run on Windows or the retail package.

Setup: RTX 3090 (NVIDIA 590.48.01) and the Radeon iGPU of a Ryzen 5 7600 (RADV, Mesa 26.0.8). Native build with clang 21; Windows build with clang-cl 21 and xwin, run under WineHQ 11.22 (winewayland) and GE-Proton11-14 (winex11, d3d12=n;d3d12core=n;dxgi=n). Base: main at 58be9cd.

Tree native (3090, RADV) WineHQ 11.22 GE-Proton (3090, Radeon)
main 3/3 pass 5/5 pass 5/5 pass
main + this PR 3/3 pass 5/5 pass 5/5 pass
main + only this PR's runtime/test (3090 only) 0/3 0/5 0/5

Tests: command_list, vk_command_replay, replay_texture_barrier (native and Windows), d3d12_com, d3d12_close_parity (Windows only).

The last row shows the new checks catch the bug on main's code: record/prepare a barrier into UNDEFINED fail, d3d12_close_parity reports layer Close 0x80070057, WARP succeeds for COMMON -> UNDEFINED and DEPTH_STENCIL_WRITE -> UNDEFINED, and replay_texture_barrier segfaults natively (times out under WineHQ) instead of failing a check. The WARP side there is the host's d3d12 (vkd3d under Wine, vkd3d-proton under Proton), not Microsoft's WARP.

Brings the branch up to date with main 68d1331. No conflicts; the merged tree was tested before the push (every standalone
test file under tests/ passes except tests/test_ci_registration.py, which fails on main alone since ProjectLeonida#930).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@github-actions github-actions Bot removed the needs rebase Conflicts with the base branch: rebase it on main label Nov 24, 2026
@aslan2142
aslan2142 merged commit cdb003e into ProjectLeonida:main Nov 24, 2026
4 of 5 checks passed
@aslan2142

Copy link
Copy Markdown
Collaborator

Merged. Thanks, and thanks to Moriz82 for the split and to everyone who ran it.

  • Claim: valid. D3D-BARRIER-INTO-UNDEFINED was posted at 16:46 UTC, before this PR, and is unedited. vulkan_replay: handle UNDEFINED->UNDEFINED TextureBarrier without illegal newLayout (VK-TEXTURE-BARRIER-UNDEF-NOOP) #600 covers the separate UNDEFINED → UNDEFINED case and still merges cleanly next to this.
  • The change is sound: the record no longer refuses LayoutAfter = UNDEFINED from a defined layout, and the replay gives each piece oldLayout == newLayout from the tracker, so nothing is discarded or zero-filled and the tracker keeps its layout. The next barrier from UNDEFINED discards as before. WARP closes such a list, and the three new d3d12_close_parity rows match.
  • Linux portable ctest: 75 of 75 on main and with this PR. On main's code the new checks in command_list and vk_command_replay fail and replay_texture_barrier crashes, so they do catch the bug.
  • Windows suite under Wine (clang-cl; llvmpipe and an RDNA2 iGPU, RADV), main 16ff59721 + this PR against that main: no test changed state on either device (259 pass and 15 fail on llvmpipe, 255 and 21 on the iGPU, on both sides). d3d12_close_parity, d3d12_com, replay_texture_barrier, vk_command_replay and command_list pass on both.
  • On today's main 79d044e54 + 59dcc9e91: it merges cleanly; the 13 docs and writer tests pass; check_no_game_data.py is clean on the 8 changed files. The merges into main since that suite run are Python and shader-fixture changes only.
  • Not measured here: live WARP for the three new rows (Luna-OS ran live WARP on an earlier head) and the retail title issuing this barrier ([integration] Linux/Proton and native Windows: boot through the story load (RT-PROTON-STORY-LOAD) #984's report).
  • CI had not finished on this head. The needs rebase label was out of date.

A small follow-up, not blocking: on main's code replay_texture_barrier crashes instead of failing a check; an early return after the failed record would make that failure easier to read.

AI-assisted (Claude Code, Claude Fable 5.2 and Claude Opus 5.5).

QemmHD added a commit that referenced this pull request Nov 25, 2026
Merging.

**Why merged:** RT-STREAM-TRANSFER-BARRIER: a transfer-write → transfer-read/write barrier goes before every vkCmdCopyBuffer, so back-to-back streamed copies are ordered. moffington measured SyncVal at 10 errors on the base and 0 on the head. Plaaasma (4070 Ti), iFeyz (RX 9070 XT) and whoalin1 (gfx1035) passed it. LEONIDA_ORDER_BUFFER_COPIES=0 turns it off (documented in docs/d3d12_vulkan.md).

**Why it's good:** replay_*, vk_bc_zero_init, vk_queue* and d3d12_close_parity: 16/16 both plain and under validation. A negative control on the cumulative build checked that the test really catches a missing barrier: with the barrier on, `--expect-unordered` fails; with the env var at 0, the ordered check fails and `--expect-unordered` passes. It also passes on top of #1055's vulkan_replay.h change. It adds one barrier per buffer copy, a small sync-policy cost with an opt-out.

Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Merged alone onto main 0f98d19, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative with the rest of this batch on main 507029d: the repo-consistency set gives 578 passed / 5 skipped / 0 failed, compileall is clean, and full ctest is 317/318 with the usual 11 skips; the only failure is main's pre-existing d3d12_depth_resolve. All d3d12_* tests under validation: 119/120 with 0 VUIDs. The semantic suite has only the known environment-only failure. git merge-tree against current main 9c5e706: no conflicts. Security read of the three-dot diff: no binaries, game data, downloads, network calls or CI changes.

AI-assisted (Claude Code, Claude Opus 5.5).
aslan2142 added a commit to Rain156/leonida-contrib that referenced this pull request Nov 25, 2026
…ProjectLeonida#939

The base is 8a242ef, the merge of main and ProjectLeonida#984. 68 files conflicted; they were resolved in seven groups by
one rule: the same change in two forms keeps the base's form, everything only ProjectLeonida#939 has is kept, and where the
two solve one problem in two ways the base's is the frame and ProjectLeonida#939's plugs into it.

A, the Xbox proxy (d3d12_xs_device.cpp/.h, d3d12_xs.cpp, d3d12_xs_pso_stream.cpp/.h, d3d12_xs_alloc_size.h,
d3d12_xs_desc_clean.h, device_proxy_test.cpp, queue_proxy_test.cpp): the base's files with ProjectLeonida#939's additions
ported in. Device slot 57 asks ProjectLeonida#939's NativeGraphicsFactory first and falls back to the base's
proxy_create_graphics_pipeline_from_native_code on E_NOTIMPL. Kept from ProjectLeonida#939: the providers (texture lease,
raw texture view, resource by address, constant view, descriptor mapping, depth-stencil UAV, texture pages),
the title-backed descriptor mirror, slot 13's feature answers, GPU labels on list slots 71/72. Dropped: ProjectLeonida#939's
duplicates of the boot ladder routes, its fallback window, its slot 133 stand-in.

A2 (xs_proxy_mock_test.cpp): the base's test with ProjectLeonida#939's slot 70 raw-buffer case; presentation cases follow
ProjectLeonida#939's rule that a device which ever had a handler has no queue fallback.

B1, the Vulkan device (d3d12_vulkan_device.cpp, d3d12_com.cpp/.h, shader_library.h, queue_families.h,
pipeline_cache_file.h, startup_trace.h): one lazy-pipeline mechanism, the base's; ProjectLeonida#939's pending_base_compile
and first_use_backend_pipelines dropped, prepare_on_bind and cold_graphics_compile kept. create_texture keeps
the base's signature; ProjectLeonida#939's deferred backing is folded into the base's placed-memory binder. ProjectLeonida#939's quad
lists as triangle indices.

B2, the D3D12 tests (d3d12_existing_heap, a8_dimensions, pipeline_cache_seed, title_va, rect_list,
shader_library, loader_tls_index0, draw, compute, xmem_placed, shader_library_corpus): the base's tests where
both carry the same case, ProjectLeonida#939's cases added (rebound tables, linear texture map, large vertex batch,
executable shaders, default A8 views).

C, the backend (vulkan_replay.h, vulkan_backend.h, vulkan_bindless.h, vulkan_scratch.h, vulkan_present.h,
rect_list_geometry.h, vk_test_device.h, vk_pipeline_check.cpp, vk_store_test.cpp, bindless_sizing_test.cpp,
replay_texture_barrier_test.cpp): the base's prepare_draw and lazy compute, its ProjectLeonida#1055 release rule and its
rectangle generator; ProjectLeonida#939's rectangle variants, GPU quad index expansion, 1D/3D and depth-stencil UAVs, the
label fence on the base's submit.

D, memory, services, presentation (xmem.cpp/.h, xg_xs.cpp, xg_xs_test.cpp, title_va_alias.h and its test,
main.cpp, frame_pacer.h, xbox_present.cpp/.h; xgameruntime_offline.cpp for one comment): the base's xmem with
ProjectLeonida#939's label hooks, file-backed sections and pin_mapped_data; both texture computers in xg_xs.cpp, the base's
answering first; --first-run-ui kept without host speech in its profile.

E, build, tools, docs (runtime/CMakeLists.txt, make_game.py, tools/rdna2spirv.py, tools/shader_disasm.py,
scripts, tests, docs; docs/README.md and tests/test_exe_shaders_stage.py beyond the conflicts): the base's
v_dot4 decode, ProjectLeonida#281's disassembler form and tests/semantic/test_fspx_dot4_op_sel_disasm.py dropped; the
base's executable-shader step with ProjectLeonida#939's cache fix; 366 registered tests.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants