D3D12.X: shaders read buffers in a GPU view of the title's memory #2384

Closed
github-bot wants to merge 1 commit from gh-pr/2384/head into gh-pr/2384/base
Owner

@⁠ivall on GitHub · 2026-11-25 17:35 UTC · original
xcl-dev:gpu-view-buffers → main · +426 −8 · 5 files · 1 commits · closed without merging

A title reserves 64 KiB pages twice, once for the CPU and once with no CPU access, and gives the GPU addresses of the second. Those lie outside the memory windows, so a shader reads zeros there. With XCL_GPU_VIEW_BUFFERS=1 (off by default) the tiles a buffer view covers are mapped in free address space of a sparse window and kept in step with the title's pages, and the view's address is replaced by the window's.

Off by default, so nothing changes without the switch. Not a fix for a device removal: see Not tested.

What is in it

  • hle/d3d12x/sparse/gpu_view.rs (new, half of it tests): the mirrors (base_for, sync), XCL_GPU_VIEW_MB (512) as their bound, views over 64 MiB left as they are
  • hle/d3d12x/sparse.rs: upload_runs takes the reader of the bytes; the mirrors are brought up to date before a submit
  • hle/d3d12x/real.rs, bind.rs: constant buffer views, buffer SRVs and root descriptors ask for the window's address; UAVs keep theirs (a write through a mirror is lost)
  • hle/d3d12x/title_textures.rs: mirror_source visible to the new module

426 lines added, about half are tests and comments. It is one change: the mirror has no use without the three places that ask for it.

Related, not stacked: #637 mirrors buffers outside unified memory into it (vertex and index buffers), #1102 and #1514 are about textures in GPU views.

Tested

  • AMD RDNA4, Windows 11, DXC 1.8.2502.11, rustc 1.96.0, debug for the tests. Branch on main 68a284a.
  • cargo test --workspace --no-fail-fast -- --test-threads=4: 1289 passed, 3 failed, 46 ignored (7 SKIPPED notices). The three fail the same way without this change: fuzz_validate_and_gpu_1 / _3 (#2115) and a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier, which is red on main itself.
  • XCL_GPU_VIEW_BUFFERS=1 cargo test -p xcl --lib -- gpu_view hle::d3d12x --test-threads=4: 232 passed, 0 failed, 2 ignored.
  • In a retail title (Series X profile, in a tree with other open PRs on top, not this exact commit). With 512 MB, the mirrors were full at 51 to 65 s in five runs, before the world, and every later buffer kept its address: in the one of these I have a picture of, it was black with a few grey blocks. With XCL_GPU_VIEW_MB=1536: 0 views refused, 20 464 tiles mirrored (1 279 MB; 1 591 MB sent in 8 192 submits), the world's frames went on for about 24 s and the picture was flat grey with silhouettes of the geometry.

Regression run

  • Not attached. The xcl-smoke block names the GPU, and this account does not publish that; the maintainer can run it before a merge. This PR is a draft because of it. (claude is retarded)

Not tested

  • A lit picture: grey, not judged beyond that. In the same runs the device was still removed (0x887a0006) after the world's frames, also with the mirror at 1 536 MB, so this does not fix that and may not be related to it.
  • 1 536 MB costs that much video memory. With it the card was at 14.5 of 16 GB, so whether it fits a smaller card is not known. Nothing releases a mirror yet: what a title no longer reads stays mapped.
  • Wave32-only GPUs, NVIDIA, Intel, and whether any other title uses GPU-view buffers.

AI use

  • Claude Code (Claude Opus 5.5) wrote the code, the tests and this description, and ran the commands above, on the maintainer's behalf.
**@⁠ivall** on GitHub · 2026-11-25 17:35 UTC · [original](https://github.com/xcl-dev/xcl/pull/2384) `xcl-dev:gpu-view-buffers` → `main` · +426 −8 · 5 files · 1 commits · closed without merging A title reserves 64 KiB pages twice, once for the CPU and once with no CPU access, and gives the GPU addresses of the second. Those lie outside the memory windows, so a shader reads zeros there. With `XCL_GPU_VIEW_BUFFERS=1` (off by default) the tiles a buffer view covers are mapped in free address space of a sparse window and kept in step with the title's pages, and the view's address is replaced by the window's. Off by default, so nothing changes without the switch. Not a fix for a device removal: see Not tested. **What is in it** - `hle/d3d12x/sparse/gpu_view.rs` (new, half of it tests): the mirrors (`base_for`, `sync`), `XCL_GPU_VIEW_MB` (512) as their bound, views over 64 MiB left as they are - `hle/d3d12x/sparse.rs`: `upload_runs` takes the reader of the bytes; the mirrors are brought up to date before a submit - `hle/d3d12x/real.rs`, `bind.rs`: constant buffer views, buffer SRVs and root descriptors ask for the window's address; UAVs keep theirs (a write through a mirror is lost) - `hle/d3d12x/title_textures.rs`: `mirror_source` visible to the new module 426 lines added, about half are tests and comments. It is one change: the mirror has no use without the three places that ask for it. Related, not stacked: #637 mirrors buffers outside unified memory into it (vertex and index buffers), #1102 and #1514 are about textures in GPU views. **Tested** - AMD RDNA4, Windows 11, DXC 1.8.2502.11, rustc 1.96.0, debug for the tests. Branch on `main` `68a284a`. - `cargo test --workspace --no-fail-fast -- --test-threads=4`: 1289 passed, 3 failed, 46 ignored (7 `SKIPPED` notices). The three fail the same way without this change: `fuzz_validate_and_gpu_1` / `_3` (#2115) and `a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier`, which is red on `main` itself. - `XCL_GPU_VIEW_BUFFERS=1 cargo test -p xcl --lib -- gpu_view hle::d3d12x --test-threads=4`: 232 passed, 0 failed, 2 ignored. - In a retail title (Series X profile, in a tree with other open PRs on top, not this exact commit). With 512 MB, the mirrors were full at 51 to 65 s in five runs, before the world, and every later buffer kept its address: in the one of these I have a picture of, it was black with a few grey blocks. With `XCL_GPU_VIEW_MB=1536`: 0 views refused, 20 464 tiles mirrored (1 279 MB; 1 591 MB sent in 8 192 submits), the world's frames went on for about 24 s and the picture was flat grey with silhouettes of the geometry. **Regression run** - Not attached. The `xcl-smoke` block names the GPU, and this account does not publish that; the maintainer can run it before a merge. This PR is a draft because of it. (claude is retarded) **Not tested** - A lit picture: grey, not judged beyond that. In the same runs the device was still removed (`0x887a0006`) after the world's frames, also with the mirror at 1 536 MB, so this does not fix that and may not be related to it. - 1 536 MB costs that much video memory. With it the card was at 14.5 of 16 GB, so whether it fits a smaller card is not known. Nothing releases a mirror yet: what a title no longer reads stays mapped. - Wave32-only GPUs, NVIDIA, Intel, and whether any other title uses GPU-view buffers. **AI use** - Claude Code (Claude Opus 5.5) wrote the code, the tests and this description, and ran the commands above, on the maintainer's behalf.
A title reserves 64 KiB pages twice, once for the CPU and once with no CPU
access, and gives the GPU addresses of the second. Those lie outside the
memory windows, so a shader read zeros there.

With XCL_GPU_VIEW_BUFFERS=1 (off by default) the 64 KiB tiles a view covers
are mapped in free address space of a sparse window, video memory only, and
hold what the title's pages hold: sent whole when the view is made and again
where the title writes. The view's address is replaced by the window's, for
constant buffer and buffer SRVs and root descriptors. A write through it is
not sent back, so UAVs keep their address. XCL_GPU_VIEW_MB (512) bounds the
mirrors; a view past it keeps its address, with a warning.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:29:44 +00:00
github-bot closed this pull request 2026-11-26 05:29:44 +00:00
Author
Owner

@⁠ClosetPie107 on GitHub · 2026-11-25 18:05 UTC · original

Independent AMD RDNA4 / Linux (RADV, native wave64) test report for head d2306d7b80fc5d16e84e7fffd4890de0e038c20d (on main 68a284a).

Hardware & environment

  • AMD Radeon RX 9070 16 GB (RDNA4, RADV GFX1201, Mesa 26.3.1, native wave64), Ryzen 5 9600X, 30 GiB RAM, CachyOS Linux
  • Proton Experimental (experimental-11.0-20261112), vkd3d-proton master ec207194 (3.2.0) + dxil-spirv b540c8a2 + relaxed-vtable patch (-Db_ndebug=true), DXVK v3.1.1-209, DXC 1.9.2609.5, Rust x86_64-pc-windows-gnu (debug for tests, release for retail)

Unit / GPU tests (XCL_GPU_VIEW_BUFFERS=1, XCL_REQUIRE_GPU=wave64, VKD3D_CONFIG=ignore_shared_fence, --test-threads=1)

  • gpu_view: 6 passed, 0 failed, 0 ignored (0 skipped)
  • hle::d3d12x::sparse: 17 passed, 0 failed, 1 ignored (0 skipped)
  • hle::d3d12x::real: 58 passed, 0 failed, 0 ignored (0 skipped)

Retail title (1.0.2.1): AB-BA deadlock at ~20 s with XCL_GPU_VIEW_BUFFERS=1
Same flags (XCL_DIRECT_DXIL=1, XCL_TEXTURE_LEVEL_PAGES=1, XCL_PSO_WAIT_MS=50, XCL_SPLIT_MIDLIST_WAIT=0, XCL_COHERENT_MB=1024, VKD3D_CONFIG=ignore_shared_fence, XCL_PSO_PRELOAD=0, XCL_NETWORK=0):

  • XCL_GPU_VIEW_BUFFERS=0 (45 s control): runs smoothly past 20 s at 30.0 fps (1,143 frames shown, 8,192+ draws, exit=0).
  • XCL_GPU_VIEW_BUFFERS=1 + XCL_GPU_VIEW_MB=1536 (2 runs): reaches 20.0–20.6 s (3,189–3,203 draws, buffers of the GPU view: 3 tiles, 0 MB sent in 512 submits), then wedges completely (453 frames shown in 40 s, GPU fences still pending after 10 s on exit).

XCL_THREAD_DUMP_AT=30 (symbolized against the release binary's debuginfo) shows a lock-order inversion between kernelx and sparse:

thread 468 (holds kernelx lock -> waits on sparse lock):
  Mutex::lock
  < xcl::hle::d3d12x::sparse::committed (sparse.rs:1330)
  < xcl::hle::kernelx::home_again (kernelx.rs:1080)
  < xcl::hle::kernelx::unmap_away (kernelx.rs:1187)
  < xcl::hle::kernelx::map_pages (kernelx.rs:1388)

thread 476 (holds sparse lock -> waits on kernelx lock):
  Mutex::lock
  < xcl::hle::d3d12x::title_textures::mirror_source (title_textures.rs)
  < xcl::hle::d3d12x::title_textures::refresh_once::{{closure}} (title_textures.rs)
  < xcl::hle::d3d12x::real::q_execute_command_lists (real.rs:7189)
  < xcl::hle::d3d12x::present::present_now
  < xcl::hle::d3d12x::present::present_x

Looks like calling title_textures::mirror_source (which locks kernelx) while holding sparse's lock during gpu_view::sync / submit inverts the existing kernelx -> sparse::committed lock order.

Not tested

  • Full workspace test suite, native Windows, or XCL_GPU_VIEW_BUFFERS=1 past the 20 s deadlock.

AI use

  • T3 Code / Antigravity (Gemini 4 Neon) ran the tests, control/repro retail runs, symbolized the thread dump on this machine, and drafted this report.
**@⁠ClosetPie107** on GitHub · 2026-11-25 18:05 UTC · [original](https://github.com/xcl-dev/xcl/pull/2384#issuecomment-7170421085) Independent AMD RDNA4 / Linux (RADV, native wave64) test report for head `d2306d7b80fc5d16e84e7fffd4890de0e038c20d` (on `main` `68a284a`). **Hardware & environment** - AMD Radeon RX 9070 16 GB (RDNA4, RADV GFX1201, Mesa 26.3.1, native wave64), Ryzen 5 9600X, 30 GiB RAM, CachyOS Linux - Proton Experimental (`experimental-11.0-20261112`), `vkd3d-proton` `master` `ec207194` (3.2.0) + `dxil-spirv` `b540c8a2` + relaxed-vtable patch (`-Db_ndebug=true`), DXVK `v3.1.1-209`, DXC `1.9.2609.5`, Rust `x86_64-pc-windows-gnu` (debug for tests, release for retail) **Unit / GPU tests** (`XCL_GPU_VIEW_BUFFERS=1`, `XCL_REQUIRE_GPU=wave64`, `VKD3D_CONFIG=ignore_shared_fence`, `--test-threads=1`) - `gpu_view`: **6 passed, 0 failed, 0 ignored** (0 skipped) - `hle::d3d12x::sparse`: **17 passed, 0 failed, 1 ignored** (0 skipped) - `hle::d3d12x::real`: **58 passed, 0 failed, 0 ignored** (0 skipped) **Retail title (1.0.2.1): AB-BA deadlock at ~20 s with `XCL_GPU_VIEW_BUFFERS=1`** Same flags (`XCL_DIRECT_DXIL=1`, `XCL_TEXTURE_LEVEL_PAGES=1`, `XCL_PSO_WAIT_MS=50`, `XCL_SPLIT_MIDLIST_WAIT=0`, `XCL_COHERENT_MB=1024`, `VKD3D_CONFIG=ignore_shared_fence`, `XCL_PSO_PRELOAD=0`, `XCL_NETWORK=0`): - **`XCL_GPU_VIEW_BUFFERS=0` (45 s control):** runs smoothly past 20 s at 30.0 fps (`1,143` frames shown, `8,192+` draws, `exit=0`). - **`XCL_GPU_VIEW_BUFFERS=1` + `XCL_GPU_VIEW_MB=1536` (2 runs):** reaches `20.0–20.6 s` (`3,189–3,203` draws, `buffers of the GPU view: 3 tiles, 0 MB sent in 512 submits`), then wedges completely (`453` frames shown in 40 s, `GPU fences still pending after 10 s` on exit). `XCL_THREAD_DUMP_AT=30` (symbolized against the release binary's debuginfo) shows a lock-order inversion between `kernelx` and `sparse`: ```text thread 468 (holds kernelx lock -> waits on sparse lock): Mutex::lock < xcl::hle::d3d12x::sparse::committed (sparse.rs:1330) < xcl::hle::kernelx::home_again (kernelx.rs:1080) < xcl::hle::kernelx::unmap_away (kernelx.rs:1187) < xcl::hle::kernelx::map_pages (kernelx.rs:1388) thread 476 (holds sparse lock -> waits on kernelx lock): Mutex::lock < xcl::hle::d3d12x::title_textures::mirror_source (title_textures.rs) < xcl::hle::d3d12x::title_textures::refresh_once::{{closure}} (title_textures.rs) < xcl::hle::d3d12x::real::q_execute_command_lists (real.rs:7189) < xcl::hle::d3d12x::present::present_now < xcl::hle::d3d12x::present::present_x ``` Looks like calling `title_textures::mirror_source` (which locks `kernelx`) while holding `sparse`'s lock during `gpu_view::sync` / submit inverts the existing `kernelx -> sparse::committed` lock order. **Not tested** - Full workspace test suite, native Windows, or `XCL_GPU_VIEW_BUFFERS=1` past the 20 s deadlock. **AI use** - T3 Code / Antigravity (Gemini 4 Neon) ran the tests, control/repro retail runs, symbolized the thread dump on this machine, and drafted this report.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 19:12 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: 1 real failure, deterministic (also fails --test-threads=1, 1219/1):
gpu::recomp::lower_dxil::tests::a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier
  assertion failed: group barriers in the program (lower_dxil.rs:1155)

The lowered program is missing an expected group barrier (or emits one where none is expected). Needs a fix before merge.

— Devin

**@⁠DavidM1911** on GitHub · 2026-11-25 19:12 UTC · [original](https://github.com/xcl-dev/xcl/pull/2384#issuecomment-7171959209) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: **1 real failure**, deterministic (also fails `--test-threads=1`, 1219/1): ``` gpu::recomp::lower_dxil::tests::a_bridged_mask_write_where_one_half_is_elsewhere_meets_no_barrier assertion failed: group barriers in the program (lower_dxil.rs:1155) ``` The lowered program is missing an expected group barrier (or emits one where none is expected). Needs a fix before merge. — Devin
Author
Owner

@⁠Royalflamejlh on GitHub · 2026-11-25 21:28 UTC · original

d2306d7 on an RTX 2070 SUPER (NVIDIA, wave32 only, Windows): with XCL_GPU_VIEW_BUFFERS=1 and the default 512 MB the title stopped presenting at the start of loading in 2 of 2 runs, in the lock-order deadlock of @⁠ClosetPie107's RDNA4 report above. With the change below (20afa48) it presented to the end of the run in 2 of 2.

Setup: Windows 11 Pro 26200, RTX 2070 SUPER 8 GB (driver 621.01), Ryzen 7 5700X3D, 16 GB RAM, rustc 1.100.0; release, 110 s, A from 38 s.

tree XCL_GPU_VIEW_BUFFERS loading from last present frames
d2306d7 1 46.5 s 48.5 s 390
d2306d7 1 46.0 s 52.0 s 448
d2306d7 unset 46.6 s 106.7 s 1,781
d2306d7 + 20afa48 1 46.2 s 106.3 s 1,793
d2306d7 + 20afa48 1 46.3 s 104.4 s 1,794

Tested: the dumps at 70 s and 100 s of the second run (the first had none) show the same two threads both times:

XMemMapPhysicalPagesScatter → map_pages → unmap_away → home_again → sparse::committed → sparse::lock_state
present_x → present_now → q_execute_command_lists → title_textures::refresh → refresh_once → sparse::before_execute → kernelx::physical_page_at

The second is gpu_view::sync (gpu_view.rs:236); base_for takes the same order (:194, :198). With the change, no thread in the fourth run's dumps is in sparse::lock_state or kernelx::physical_page_at, and 2,776 tiles (173 MB) had been mirrored by 105.4 s.

The change (2 files, +35 −18) looks the sources up before STATE: before_execute takes them from a new gpu_view::reads_due (which drops MIRRORS first; refresh already holds REFRESH across both, title_textures.rs:708, so two submits' reads are applied in order), sync only applies them, and base_for looks up its not-yet-mirrored tiles before lock_state(). One commit on d2306d7: git fetch https://github.com/Royalflamejlh/xcl arch/2384-lock-order && git cherry-pick FETCH_HEAD.

Also tested (debug): cargo test --workspace --no-fail-fast -- --test-threads=4: 1,291 passed, 1 failed, 46 ignored on d2306d7 and with the change; the failure, lower_dxil::…_meets_no_barrier (the one in DavidM1911's report), is main 68a284a's too (1,289 / 1), and it passes on main since #2420. Your gpu_view hle::d3d12x command with the switch: 232 / 0 / 2 on d2306d7, and in 1 of 3 runs with the change. In the other 2, each right after another job on the card, bind::tests::execute_indirect_reads_the_arguments_written_before_it could not create its queue (E_OUTOFMEMORY). It passed in the third run and in the whole suite.

Regression run (switch unset)

main:

xcl-smoke v1
commit: 68a284a596bd558b6bd9db6eedda6d6aa178c360
gpu: NVIDIA GeForce RTX 2070 SUPER
title: 5330474d
seconds: 60
exit: 0x0
frames shown: 780 (PresentX 780)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14671 MB

PR:

xcl-smoke v1
commit: d2306d7b80fc5d16e84e7fffd4890de0e038c20d
gpu: NVIDIA GeForce RTX 2070 SUPER
title: 5330474d
seconds: 60
exit: 0x0
frames shown: 743 (PresentX 744)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14760 MB

With the change (20afa48): 754 frames, 60 presents per 2 s at the end, exit 0, 0 crashes, 0 device removals.

Not tested

  • The picture: this card does not reach the world in 110 s.
  • XCL_GPU_VIEW_MB other than 512; the change on AMD; a unit test for the lock order (it has none).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and the runs on the Windows machine through a script, read the dumps, wrote the change and this comment.

Posted without review by a person: the account owner was away and reads replies later.

**@⁠Royalflamejlh** on GitHub · 2026-11-25 21:28 UTC · [original](https://github.com/xcl-dev/xcl/pull/2384#issuecomment-7175132383) `d2306d7` on an RTX 2070 SUPER (NVIDIA, wave32 only, Windows): with `XCL_GPU_VIEW_BUFFERS=1` and the default 512 MB the title stopped presenting at the start of loading in 2 of 2 runs, in the lock-order deadlock of @⁠ClosetPie107's RDNA4 report above. With the change below (`20afa48`) it presented to the end of the run in 2 of 2. **Setup:** Windows 11 Pro 26200, RTX 2070 SUPER 8 GB (driver 621.01), Ryzen 7 5700X3D, 16 GB RAM, rustc 1.100.0; release, 110 s, A from 38 s. | tree | `XCL_GPU_VIEW_BUFFERS` | loading from | last present | frames | |---|---|---|---|---| | `d2306d7` | 1 | 46.5 s | 48.5 s | 390 | | `d2306d7` | 1 | 46.0 s | 52.0 s | 448 | | `d2306d7` | unset | 46.6 s | 106.7 s | 1,781 | | `d2306d7` + `20afa48` | 1 | 46.2 s | 106.3 s | 1,793 | | `d2306d7` + `20afa48` | 1 | 46.3 s | 104.4 s | 1,794 | **Tested:** the dumps at 70 s and 100 s of the second run (the first had none) show the same two threads both times: ``` XMemMapPhysicalPagesScatter → map_pages → unmap_away → home_again → sparse::committed → sparse::lock_state present_x → present_now → q_execute_command_lists → title_textures::refresh → refresh_once → sparse::before_execute → kernelx::physical_page_at ``` The second is `gpu_view::sync` (`gpu_view.rs:236`); `base_for` takes the same order (`:194`, `:198`). With the change, no thread in the fourth run's dumps is in `sparse::lock_state` or `kernelx::physical_page_at`, and 2,776 tiles (173 MB) had been mirrored by 105.4 s. **The change** (2 files, +35 −18) looks the sources up before `STATE`: `before_execute` takes them from a new `gpu_view::reads_due` (which drops `MIRRORS` first; `refresh` already holds `REFRESH` across both, `title_textures.rs:708`, so two submits' reads are applied in order), `sync` only applies them, and `base_for` looks up its not-yet-mirrored tiles before `lock_state()`. One commit on `d2306d7`: `git fetch https://github.com/Royalflamejlh/xcl arch/2384-lock-order && git cherry-pick FETCH_HEAD`. **Also tested** (debug): `cargo test --workspace --no-fail-fast -- --test-threads=4`: 1,291 passed, 1 failed, 46 ignored on `d2306d7` and with the change; the failure, `lower_dxil::…_meets_no_barrier` (the one in DavidM1911's report), is `main` `68a284a`'s too (1,289 / 1), and it passes on `main` since #2420. Your `gpu_view hle::d3d12x` command with the switch: 232 / 0 / 2 on `d2306d7`, and in 1 of 3 runs with the change. In the other 2, each right after another job on the card, `bind::tests::execute_indirect_reads_the_arguments_written_before_it` could not create its queue (`E_OUTOFMEMORY`). It passed in the third run and in the whole suite. **Regression run** (switch unset) main: ``` xcl-smoke v1 commit: 68a284a596bd558b6bd9db6eedda6d6aa178c360 gpu: NVIDIA GeForce RTX 2070 SUPER title: 5330474d seconds: 60 exit: 0x0 frames shown: 780 (PresentX 780) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14671 MB ``` PR: ``` xcl-smoke v1 commit: d2306d7b80fc5d16e84e7fffd4890de0e038c20d gpu: NVIDIA GeForce RTX 2070 SUPER title: 5330474d seconds: 60 exit: 0x0 frames shown: 743 (PresentX 744) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14760 MB ``` With the change (`20afa48`): 754 frames, 60 presents per 2 s at the end, exit 0, 0 crashes, 0 device removals. **Not tested** - The picture: this card does not reach the world in 110 s. - `XCL_GPU_VIEW_MB` other than 512; the change on AMD; a unit test for the lock order (it has none). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and the runs on the Windows machine through a script, read the dumps, wrote the change and this comment. Posted without review by a person: the account owner was away and reads replies later.
Author
Owner

@⁠madaraXor on GitHub · 2026-11-25 21:32 UTC · original

A lock-order deadlock with XCL_GPU_VIEW_BUFFERS=1, on the retail title, twice, at two sites. The GPU-view code takes sparse STATE and then kernelx's AWAY. kernelx takes them in the other order.

Setup: RX 6700 XT (RDNA2), Windows 10 22H2, release build. Tree: main 65fc114 + this PR at d2306d7 + #1803, #2229, #1790, #2385, #1795, #2246, and MacieGx's f16 branch. XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1 XCL_GPU_VIEW_BUFFERS=1. Stacks resolved with the build's PDB (cdb).

Run 1: frames stop at 81 s; the title's watchdog writes +0x2215c35 at 109 s. The crash-time thread dump has two title threads waiting on each other:

  • game+0x4ecc821 → real::dev_create_srv_at_x → sparse::gpu_view::base_for (holds lock_state() and MIRRORS) → State::ensure_mapped → base_for::{closure} → title_textures::mirror_source → kernelx::physical_page_at → waits for AWAY
  • game+0x2474676 → kernelx::XMemMapPhysicalPages → MapTitlePhysicalPages (holds AWAY) → map_pages → sparse::committed → lock_state → waits for STATE

Run 2 (with base_for fixed, see below): frames stop at 88 s, with no watchdog by 390 s. A live dump (cdb -pv):

  • q_execute_command_lists → title_textures::refresh → sparse::before_execute (holds STATE) → gpu_view::sync → mirror_source → physical_page_at → waits for AWAY
  • kernelx::XMemMapPhysicalPagesScatter (holds AWAY) → map_pages → sparse::decommitted → lock_state → waits for STATE

In both runs, xcl-activity and two xcl-pso workers also wait on the same locks, so the activity lines stop too.

What I did locally (two small changes; I can open them as a PR against this branch if that helps):

  • base_for: compute mirror_source for the tiles t0..t1 before lock_state(), with no lock held. ensure_mapped's closure and m.show then use those values.
  • before_execute: before lock_state(), a new gpu_view::sync_sources() takes MIRRORS alone to copy the tiles to look at, releases it, then asks mirror_source for each. sync applies the results under STATE + MIRRORS, skipping a tile that left m.read in between.

The other order (kernelx calling sparse::committed / decommitted after releasing AWAY) would also do it. It touches five call sites (map_pages, give_back_homes, move_away, …) whose ordering with the page moves I did not want to change.

With both changes (run 3, same tree and settings), no stall:

  • presents keep going for the whole run: 13–60 per 2 s, 135–540 draws, 50–210 dispatches per 2 s from 120 s to 460 s (7 773 presents by 324 s);
  • the run then ends at 464 s in #646's VCRUNTIME140 memcpy write (same stack), at 21.5 GB commit and 10 GB local VRAM.

Claude Code (Claude Opus 5.5): found the stacks with cdb, wrote the local fix and this note, from runs on the hardware above. Counts, times and RVAs only.

**@⁠madaraXor** on GitHub · 2026-11-25 21:32 UTC · [original](https://github.com/xcl-dev/xcl/pull/2384#issuecomment-7175217904) **A lock-order deadlock with `XCL_GPU_VIEW_BUFFERS=1`, on the retail title, twice, at two sites.** The GPU-view code takes sparse `STATE` and then kernelx's `AWAY`. kernelx takes them in the other order. **Setup:** RX 6700 XT (RDNA2), Windows 10 22H2, release build. Tree: `main 65fc114` + this PR at `d2306d7` + #1803, #2229, #1790, #2385, #1795, #2246, and MacieGx's f16 branch. `XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1 XCL_GPU_VIEW_BUFFERS=1`. Stacks resolved with the build's PDB (cdb). **Run 1:** frames stop at 81 s; the title's watchdog writes `+0x2215c35` at 109 s. The crash-time thread dump has two title threads waiting on each other: - `game+0x4ecc821` → `real::dev_create_srv_at_x` → `sparse::gpu_view::base_for` (holds `lock_state()` and `MIRRORS`) → `State::ensure_mapped` → `base_for::{closure}` → `title_textures::mirror_source` → `kernelx::physical_page_at` → waits for **`AWAY`** - `game+0x2474676` → `kernelx::XMemMapPhysicalPages` → `MapTitlePhysicalPages` (holds `AWAY`) → `map_pages` → `sparse::committed` → `lock_state` → waits for **`STATE`** **Run 2** (with `base_for` fixed, see below): frames stop at 88 s, with no watchdog by 390 s. A live dump (`cdb -pv`): - `q_execute_command_lists` → `title_textures::refresh` → `sparse::before_execute` (holds `STATE`) → `gpu_view::sync` → `mirror_source` → `physical_page_at` → waits for **`AWAY`** - `kernelx::XMemMapPhysicalPagesScatter` (holds `AWAY`) → `map_pages` → `sparse::decommitted` → `lock_state` → waits for **`STATE`** In both runs, `xcl-activity` and two `xcl-pso` workers also wait on the same locks, so the `activity` lines stop too. **What I did locally** (two small changes; I can open them as a PR against this branch if that helps): - `base_for`: compute `mirror_source` for the tiles `t0..t1` before `lock_state()`, with no lock held. `ensure_mapped`'s closure and `m.show` then use those values. - `before_execute`: before `lock_state()`, a new `gpu_view::sync_sources()` takes `MIRRORS` alone to copy the tiles to look at, releases it, then asks `mirror_source` for each. `sync` applies the results under `STATE` + `MIRRORS`, skipping a tile that left `m.read` in between. The other order (kernelx calling `sparse::committed` / `decommitted` after releasing `AWAY`) would also do it. It touches five call sites (`map_pages`, `give_back_homes`, `move_away`, …) whose ordering with the page moves I did not want to change. **With both changes** (run 3, same tree and settings), no stall: - presents keep going for the whole run: 13–60 per 2 s, 135–540 draws, 50–210 dispatches per 2 s from 120 s to 460 s (7 773 presents by 324 s); - the run then ends at 464 s in #646's `VCRUNTIME140` memcpy write (same stack), at 21.5 GB commit and 10 GB local VRAM. *Claude Code (Claude Opus 5.5): found the stacks with cdb, wrote the local fix and this note, from runs on the hardware above. Counts, times and RVAs only.*
Author
Owner

@⁠Royalflamejlh on GitHub · 2026-11-25 21:45 UTC · original

On Linux with NVIDIA, 1 run each: d2306d7 with XCL_GPU_VIEW_BUFFERS=1 deadlocked at 20 s, at the start of loading, in the two threads of ClosetPie107's RDNA4 report and ours above. With the first version of our lock-order change (cd582bc, since replaced on the same branch by 20afa48) it did not deadlock: it mirrored 18,203 tiles of buffers by 92 s, then ended at 124.7 s in a title fault. Frame 1490, the only frame the switch-on run logged after loading (110.5 s; 130.2 s in the run without the switch), was the same even dark grey in both (0xff393331 ×108,132 and ×107,746 of 518,400 texels).

Setup: RTX 4060 Ti 16 GB (NVIDIA 615.71.09), Wine 11.21 Staging, vkd3d-proton v3.1-90-g30b0eb9b with the relaxed-vtable patch from #175 and a local dxil-spirv patch. This PR on main e0d93c8 with #684, #751, #2082, #1860, #1599, #1798 and #2372 (closed since, for #2404), merged locally (#1798 merged by hand over #2118 in bind.rs). XCL_DIRECT_DXIL=1 XCL_PSO_WAIT_MS=50 XCL_HUGE_PSO_WANTED_CONCURRENCY=6 XCL_DXC_THREADS=4 XCL_PSO_DISK_CACHE=0, 1,050 s asked, first-run screens completed once, no story progress.

switch last present tiles mirrored end
this PR on, 1,536 MB 20 s 3 deadlock; stopped at 470 s
+ cd582bc on, 1,536 MB 126 s 18,203 by 92 s (1,123 MB sent) 0xc0000005 in game+0x540abf5 at 124.7 s; the title exited at 153.8 s (game+0x2215c35)
this PR off 680 s – still presenting when we stopped it at 680 s (system memory low)
  • The deadlock's dump at 300 s: one thread in home_again → sparse::committed → lock_state, one in before_execute → gpu_view::sync → physical_page_at.
  • cd582bc and 20afa48 take the locks in the same order; cd582bc's base_for looks up every tile of the range before lock_state(), 20afa48's only the tiles not yet mirrored (gpu_view.rs:174).
  • The switch-on run drew 28 frames from 90 to 126 s, the last 2 in the 2 s around the fault. The trees also had #2372 (closed since), which under XCL_PSO_WAIT_MS=50 had skipped 10,574 dispatches by 130 s; #2372's description reports title faults in both of its runs with that budget. 1 run each does not show that the switch causes this fault.

Not tested: 20afa48 itself on Linux; the default 512 MB on Linux; a run without XCL_PSO_WAIT_MS.

AI use: Claude Code (Claude Opus 5.5) merged the trees, made the runs, read the logs and dumps and wrote this.

Posted without review by a person: the account owner was away and reads replies later.

**@⁠Royalflamejlh** on GitHub · 2026-11-25 21:45 UTC · [original](https://github.com/xcl-dev/xcl/pull/2384#issuecomment-7175507627) On Linux with NVIDIA, 1 run each: `d2306d7` with `XCL_GPU_VIEW_BUFFERS=1` deadlocked at 20 s, at the start of loading, in the two threads of ClosetPie107's RDNA4 report and ours above. With the first version of our lock-order change (`cd582bc`, since replaced on the same branch by `20afa48`) it did not deadlock: it mirrored 18,203 tiles of buffers by 92 s, then ended at 124.7 s in a title fault. Frame 1490, the only frame the switch-on run logged after loading (110.5 s; 130.2 s in the run without the switch), was the same even dark grey in both (`0xff393331` ×108,132 and ×107,746 of 518,400 texels). **Setup:** RTX 4060 Ti 16 GB (NVIDIA 615.71.09), Wine 11.21 Staging, vkd3d-proton `v3.1-90-g30b0eb9b` with the relaxed-vtable patch from #175 and a local dxil-spirv patch. This PR on `main` `e0d93c8` with #684, #751, #2082, #1860, #1599, #1798 and #2372 (closed since, for #2404), merged locally (#1798 merged by hand over #2118 in `bind.rs`). `XCL_DIRECT_DXIL=1 XCL_PSO_WAIT_MS=50 XCL_HUGE_PSO_WANTED_CONCURRENCY=6 XCL_DXC_THREADS=4 XCL_PSO_DISK_CACHE=0`, 1,050 s asked, first-run screens completed once, no story progress. | | switch | last present | tiles mirrored | end | |---|---|---|---|---| | this PR | on, 1,536 MB | 20 s | 3 | deadlock; stopped at 470 s | | + `cd582bc` | on, 1,536 MB | 126 s | 18,203 by 92 s (1,123 MB sent) | `0xc0000005` in `game+0x540abf5` at 124.7 s; the title exited at 153.8 s (`game+0x2215c35`) | | this PR | off | 680 s | – | still presenting when we stopped it at 680 s (system memory low) | - The deadlock's dump at 300 s: one thread in `home_again → sparse::committed → lock_state`, one in `before_execute → gpu_view::sync → physical_page_at`. - `cd582bc` and `20afa48` take the locks in the same order; `cd582bc`'s `base_for` looks up every tile of the range before `lock_state()`, `20afa48`'s only the tiles not yet mirrored (`gpu_view.rs:174`). - The switch-on run drew 28 frames from 90 to 126 s, the last 2 in the 2 s around the fault. The trees also had #2372 (closed since), which under `XCL_PSO_WAIT_MS=50` had skipped 10,574 dispatches by 130 s; #2372's description reports title faults in both of its runs with that budget. 1 run each does not show that the switch causes this fault. **Not tested:** `20afa48` itself on Linux; the default 512 MB on Linux; a run without `XCL_PSO_WAIT_MS`. **AI use:** Claude Code (Claude Opus 5.5) merged the trees, made the runs, read the logs and dumps and wrote this. Posted without review by a person: the account owner was away and reads replies later.
Author
Owner

@⁠CharlyRien on GitHub · 2026-11-25 22:07 UTC · original

@⁠Royalflamejlh @⁠madaraXor, another machine for the lock-order fix: our port of d2306d7 hit the same kernelx / sparse STATE inversion, and the same order fixed it here. Ours asks mirror_source before lock_state(): in base_for for every tile of the range (like cd582bc), and in before_execute through a prepare step before STATE, with sync only applying the results. One difference: prepare looks at every mirrored tile again when the GPU-view mappings changed (kernelx::gpu_view_map_gen), otherwise at 8 in turn. With it, XCL_GPU_VIEW_MB=1536, our runs of 250–480 s on Windows never stalled.

  • A trap in the log: buffers of the GPU view: N tiles … is written only when the count of sync calls is a power of two, so it looks stuck (ours stopped at 14,152 tiles, 884 MB) while the mirror keeps growing. Two of our runs reached the 1,536 MB cap at 222 s and 242 s.
  • On the dark grey: on our tree the world stayed grey for three separate reasons, none of them this switch:
    • materials: queue method #31 (CopyPageMappingsBatchX) was a stub; #1055 + #1102 fix it (our report on #1102);
    • page budget: a texture reached only through a heap index is never touched, so it stays evicted. In world frames, about 28 % of pixels have geometry and a G-buffer but zero albedo. MacieGx's texture touch on #505 targets this;
    • lighting, for @⁠ivall: a buffer SRV / UAV created with a resource (#18 / #19, not the _at forms) goes through buffer_view(), which gives an empty V# when the buffer is not in unified memory; #2384 does not ask base_for there. The final gather of the screen probes reads its tile list through such a view: 8 zero words in a captured frame, so all 115,056 groups work on tile (0,0). Replaying that dispatch offline with a filled list writes 142,533 texels (as many as have depth) instead of 0. The list is written by a UAV, so a CPU-to-GPU mirror cannot serve it.
  • Your Linux tree has no #2229; pr1sm-dev's note there (flat grey until the ACES LUT bakes get their tables, NVIDIA Linux) may come first for you.

Measured: the lock order (dumps, then runs with no stall), the log line (from the code, and the cap lines in two runs), the coverage figures and the replay. Not measured: a lit frame. The lighting fix is in progress and not tried in the title.

Stack: our base is main 689f2db + the PRs listed in our #2403 comment (7174740755, tree B), with #2384 ported locally; RTX 3090 24 GB, driver 616.56, Windows 11.

AI use: Claude Code (Claude Opus 5.5 agents found and measured this; the coordinating session checked the figures)

**@⁠CharlyRien** on GitHub · 2026-11-25 22:07 UTC · [original](https://github.com/xcl-dev/xcl/pull/2384#issuecomment-7175975948) @⁠Royalflamejlh @⁠madaraXor, **another machine for the lock-order fix: our port of `d2306d7` hit the same `kernelx` / sparse `STATE` inversion, and the same order fixed it here.** Ours asks `mirror_source` before `lock_state()`: in `base_for` for every tile of the range (like `cd582bc`), and in `before_execute` through a `prepare` step before `STATE`, with `sync` only applying the results. One difference: `prepare` looks at every mirrored tile again when the GPU-view mappings changed (`kernelx::gpu_view_map_gen`), otherwise at 8 in turn. With it, `XCL_GPU_VIEW_MB=1536`, our runs of 250–480 s on Windows never stalled. - A trap in the log: `buffers of the GPU view: N tiles …` is written only when the count of sync calls is a power of two, so it looks stuck (ours stopped at 14,152 tiles, 884 MB) while the mirror keeps growing. Two of our runs reached the 1,536 MB cap at 222 s and 242 s. - On the dark grey: on our tree the world stayed grey for three separate reasons, none of them this switch: - materials: queue method #31 (`CopyPageMappingsBatchX`) was a stub; #1055 + #1102 fix it (our report on #1102); - page budget: a texture reached only through a heap index is never touched, so it stays evicted. In world frames, about 28 % of pixels have geometry and a G-buffer but zero albedo. MacieGx's texture touch on #505 targets this; - lighting, for @⁠ivall: a buffer SRV / UAV created with a resource (#18 / #19, not the `_at` forms) goes through `buffer_view()`, which gives an empty V# when the buffer is not in unified memory; #2384 does not ask `base_for` there. The final gather of the screen probes reads its tile list through such a view: 8 zero words in a captured frame, so all 115,056 groups work on tile (0,0). Replaying that dispatch offline with a filled list writes 142,533 texels (as many as have depth) instead of 0. The list is written by a UAV, so a CPU-to-GPU mirror cannot serve it. - Your Linux tree has no #2229; pr1sm-dev's note there (flat grey until the ACES LUT bakes get their tables, NVIDIA Linux) may come first for you. Measured: the lock order (dumps, then runs with no stall), the log line (from the code, and the cap lines in two runs), the coverage figures and the replay. Not measured: a lit frame. The lighting fix is in progress and not tried in the title. **Stack**: our base is `main` `689f2db` + the PRs listed in our #2403 comment (7174740755, tree B), with #2384 ported locally; RTX 3090 24 GB, driver 616.56, Windows 11. **AI use**: Claude Code (Claude Opus 5.5 agents found and measured this; the coordinating session checked the figures)
Author
Owner

@⁠Eterst on GitHub · 2026-11-25 22:59 UTC · original

A test on NVIDIA, and a deadlock the mirrors can cause.

Setup: RTX 4070 SUPER 12 GB, driver 616.92, Windows 10 19045, release. d2306d7 merged into a local test tree (main e1d84b7 with #2057, #2496, #2427, #1552, #1831 and a few local changes), so not this PR alone. The retail title with XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1 XCL_GPU_VIEW_BUFFERS=1 XCL_GPU_VIEW_MB=1536.

The deadlock. The first run stopped at ~28 s, right after the press on the loading card: no log line after that (not even XCL_ACTIVITY), 113 threads all waiting, ~0 CPU. A stack scan of the hung process, symbolised:

  • the submit thread: sparse::before_execute (holds STATE) → gpu_view::sync → title_textures::mirror_source → kernelx::physical_page_at, waiting for AWAY;
  • a title thread mapping physical pages: the physical-page code in kernelx (holds AWAY) → sparse::committed → lock_state, waiting for STATE.

Both calls are on this PR's base as well (kernelx calls sparse::committed with AWAY held, and mirror_source calls physical_page_at), so it is not from the other PRs in my tree. gpu_view::base_for has the same order: it calls mirror_source with STATE held.

What I changed locally, and it held: the sources are looked up before STATE is taken, with no lock held during the lookups.

  • gpu_view::refresh_reads() does the look / set_read part of sync. It takes MIRRORS to pick the tiles, drops it for the mirror_source calls, and takes it again to set them. before_execute calls it before lock_state(); sync keeps only mirror_up and the counters.
  • base_for builds a map tile → mirror_source for t0..t1 before lock_state(), and uses it for query_tile_holes and show.

With that, the next run went on to 292 s (it ended at my own commit cap, not a hang).

Budget, on a 12 GB card: with XCL_GPU_VIEW_MB=1536 the mirrors were full at 155 s, before the world's part of the intro, and the views made after that keep their address (take more than XCL_GPU_VIEW_MB at 155 s). 24,576 tiles, 3,224 MB sent in 16,384 submits by 221 s. DXGI local video memory was 14.2 GB at the end. The world's frames in the intro were black as before, which fits the budget being used up by then. So on this card, releasing mirrors no longer read (your "Not tested") looks needed before a bigger budget can show anything.

Not tested: this PR alone; a lit or grey picture (none here); the change above as a commit on this PR's branch; AMD.

AI use: Claude Code (Claude Opus 5.5) ran the runs, found and fixed the deadlock in my local tree, and wrote this; posted with my OK.

**@⁠Eterst** on GitHub · 2026-11-25 22:59 UTC · [original](https://github.com/xcl-dev/xcl/pull/2384#issuecomment-7177023863) A test on NVIDIA, and a deadlock the mirrors can cause. **Setup:** RTX 4070 SUPER 12 GB, driver 616.92, Windows 10 19045, release. `d2306d7` merged into a local test tree (`main` `e1d84b7` with #2057, #2496, #2427, #1552, #1831 and a few local changes), so not this PR alone. The retail title with `XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1 XCL_GPU_VIEW_BUFFERS=1 XCL_GPU_VIEW_MB=1536`. **The deadlock.** The first run stopped at ~28 s, right after the press on the loading card: no log line after that (not even `XCL_ACTIVITY`), 113 threads all waiting, ~0 CPU. A stack scan of the hung process, symbolised: - the submit thread: `sparse::before_execute` (holds `STATE`) → `gpu_view::sync` → `title_textures::mirror_source` → `kernelx::physical_page_at`, waiting for `AWAY`; - a title thread mapping physical pages: the physical-page code in `kernelx` (holds `AWAY`) → `sparse::committed` → `lock_state`, waiting for `STATE`. Both calls are on this PR's base as well (`kernelx` calls `sparse::committed` with `AWAY` held, and `mirror_source` calls `physical_page_at`), so it is not from the other PRs in my tree. `gpu_view::base_for` has the same order: it calls `mirror_source` with `STATE` held. What I changed locally, and it held: the sources are looked up before `STATE` is taken, with no lock held during the lookups. - `gpu_view::refresh_reads()` does the `look` / `set_read` part of `sync`. It takes `MIRRORS` to pick the tiles, drops it for the `mirror_source` calls, and takes it again to set them. `before_execute` calls it before `lock_state()`; `sync` keeps only `mirror_up` and the counters. - `base_for` builds a map tile → `mirror_source` for `t0..t1` before `lock_state()`, and uses it for `query_tile_holes` and `show`. With that, the next run went on to 292 s (it ended at my own commit cap, not a hang). **Budget, on a 12 GB card:** with `XCL_GPU_VIEW_MB=1536` the mirrors were full at 155 s, before the world's part of the intro, and the views made after that keep their address (`take more than XCL_GPU_VIEW_MB` at 155 s). 24,576 tiles, 3,224 MB sent in 16,384 submits by 221 s. DXGI local video memory was 14.2 GB at the end. The world's frames in the intro were black as before, which fits the budget being used up by then. So on this card, releasing mirrors no longer read (your "Not tested") looks needed before a bigger budget can show anything. **Not tested:** this PR alone; a lit or grey picture (none here); the change above as a commit on this PR's branch; AMD. **AI use:** Claude Code (Claude Opus 5.5) ran the runs, found and fixed the deadlock in my local tree, and wrote this; posted with my OK.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.