Skip to content

D3D12.X: execute two-pass mesh shaders on DispatchMesh and ExecuteIndirect (supersedes #724) - #2092

Open
PracticalStudios wants to merge 9 commits into
xcl-dev:mainfrom
PracticalStudios:mesh/two-pass-execution
Open

PracticalStudios wants to merge 9 commits into
xcl-dev:mainfrom
PracticalStudios:mesh/two-pass-execution

Conversation

@PracticalStudios

@PracticalStudios PracticalStudios commented Nov 25, 2026 •

Copy link
Copy Markdown

Supersedes #724 (@Cattn's, inactive since the reviews): its commit rebased onto main with authorship kept, plus the five points @ivall listed on #724 before it can merge. Two-pass mesh pipelines (what #541 builds) run on DispatchMesh and ExecuteIndirect; #1984 deferred this path to #724.

Size: 907 lines, over the target. #724's own commit is 462 of them and the rest are its review fixes and their tests, one commit each; splitting further would leave a path that runs but is unsafe. @Cattn, happy to close this if you'd rather pull the commits into #724.

What is in it (hle/d3d12x/bind.rs mostly, plus console_list.rs, device_x.rs, real.rs)

  • 99b9816 D3D12.X: execute two-pass mesh shaders on DispatchMesh and ExecuteIndirect #724's commit (rebased; conflicts in console_list.rs / bind.rs resolved keeping both sides).
  • d41d2f3 the two-pass io block gets IO_UMA_BASE_HI.
  • ee561d0 groups stay inside the record buffer; ccfe5c1 indirect Y / Z > 1 are folded into X.
  • e284043 indirect arguments are read through unified memory instead of transitioning the title's buffer; per-list scratch is capped.
  • 3442b58 an ExecuteIndirect with max > 1 runs one command at a time, so commands don't overwrite each other's records.
  • e9471c5 two-pass binds set the shared view heap first (heap windows read it).
  • 47c7cc1 pooled scratch stays within the recording's remaining budget (found and fixed by @WebIdentity1).
  • A test for each fix, checked to fail without it.

Tested

Regression run
.\scripts\smoke.ps1 -Game <retail title> -Seconds 60, no input, main first, same machine:

xcl-smoke v1
commit: cbc296ab65a2661a61e3e2da109134bcd5319f60
gpu: NVIDIA GeForce RTX 3090
title: 2c508222
seconds: 60
exit: 0x0
frames shown: 1612 (PresentX 1612)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 18795 MB
xcl-smoke v1
commit: 47c7cc13c1b872ae5f45e4c9ffed6332ca74a4d0
gpu: NVIDIA GeForce RTX 3090
title: 2c508222
seconds: 60
exit: 0x0
frames shown: 1637 (PresentX 1637)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 18866 MB

Not tested

AI use

  • Claude Code (Claude Opus 5.5, with Claude Sonnet subagents) wrote the fixes, tests and this text; the test runs are real runs on the hardware above.

https://claude.ai/code/session_01HqVqYwUoC2oJRwQSXDePn3

Cattn and others added 8 commits November 24, 2026 23:40
…irect

Console mesh shaders translated to a two-pass pair (compute + mesh/PS,
TwoPassPso) were built by CreatePipelineState but had no execution path:
DispatchMesh was not hooked on the console command list vtable, and
ExecuteIndirect did not dispatch the compute pass or bind the record
buffer (u1) before invoking the mesh pass.

Hook DispatchMesh (slot 127, newer layout slot 129) and handle TwoPassPso
in ExecuteIndirect:
- Track console mesh root-argument layout (s[8:9] spill table, inline
  arguments from s16 across 16 SGPRs) in console_list::user_data_ms.
- Create a companion DISPATCH command signature alongside non-root-changing
  DISPATCH_MESH command signatures in device_x::create_command_signature_x.
- Allocate/recycle a DEFAULT-heap UAV record buffer per command list
  (recycled on allocator reset), bind u0 (io), u1 (res), u2..u5 (UMA),
  run the compute pass -> UAV barrier -> mesh pass -> UAV barrier, and
  scale indirect DispatchMesh group counts on the GPU when
  mesh_groups_per_record > 1.

Assisted-by: Antigravity (Gemini 4 Neon)
Without IO_UMA_BASE_HI the pair picked no memory window for any access.
DispatchMesh runs at most the groups the buffer holds; ExecuteIndirect's
arguments are rewritten on the GPU with the same bound for both passes.
Both passes index records by gid.x, so the rewritten arguments put x·y·z in X.
…cratch

The rewrite reads the commands through the memory window, not the title's buffer
in a guessed state, into shared scratch blocks capped at 16 MiB a recording.
Each command's records start at record 0, so its mesh pass draws them before the
next command's compute pass; commands past a count buffer's count get no groups.
With XCL_HEAP_WINDOWS=1 the pair reads the memory windows from the shared heap, as
bind_abi's programs do; a list that set none got no heap.
@WebIdentity1

WebIdentity1 commented Nov 25, 2026 •

Copy link
Copy Markdown

Verified a small pool-reuse bug on e9471c51ddfeef2019a7f3a9f43d194e77a90287: scratch_args can exceed the recording's 16 MiB cap. With 1 MiB already taken, a second 1 MiB request selects a cached 16 MiB block, bringing scratch_taken to 17 MiB. The initial guard checks the request size, but the pool filter checks the block against the full cap rather than the remaining budget.

The attached fix uses the remaining budget for both checks. The same sequence then takes 2 MiB. The test also confirms the cached 16 MiB resource remains reusable by identity for an empty recording, and that recording rejects an additional 256-byte request at its cap.

Tested: native Windows 10 Home 19045, RTX 3090 driver 591.74, Ryzen 7 7800X3D, Rust/Cargo 1.98.1 MSVC, debug. Actual D3D12 resource allocations through scratch_args; the test explicitly selects and prints the RTX 3090. Paired head+test vs head+test+fix: 0 passed / 1 failed / 0 ignored → 1 passed / 0 failed / 0 ignored, zero skips; Cargo exits 101 → 0. All 304 source hashes match before/after each run; both snapshots rebuilt.

Not tested: no GPU commands submitted, shader output, visible geometry, retail smoke, AMD, or full suite. These are allocated scratch capacities, not measured peak VRAM/process commit or performance. Run this reproducer alone in a fresh process (--exact --test-threads=1) to isolate the global pool; it is not qualified for arbitrary concurrent full-suite execution.

cargo test --locked -p xcl --lib -- hle::d3d12x::bind::tests::gpu_two_pass_pooled_scratch_respects_remaining_budget --exact --test-threads=1 --nocapture
Small runtime fix
--- a/crates/xcl/src/hle/d3d12x/bind.rs
+++ b/crates/xcl/src/hle/d3d12x/bind.rs
@@ -555,13 +555,14 @@
         return Ok(r);
     }
     let size = bytes.max(SCRATCH_BLOCK);
-    if with(this, |s| s.scratch_taken) + size > SCRATCH_CAP {
+    let remaining = SCRATCH_CAP.saturating_sub(with(this, |s| s.scratch_taken));
+    if size > remaining {
         return Err(format!("its rewritten arguments are past {} MiB this recording", SCRATCH_CAP >> 20));
     }
     let dev_key = dev.as_raw() as usize;
     let picked = {
         let mut free = FREE_RES.lock().unwrap();
-        free.iter().position(|(_, cap, d)| *d == dev_key && *cap >= size && *cap <= SCRATCH_CAP).map(|i| free.swap_remove(i))
+        free.iter().position(|(_, cap, d)| *d == dev_key && *cap >= size && *cap <= remaining).map(|i| free.swap_remove(i))
     };
     let block = match picked {
         Some(e) => e,
Isolated native reproducer (applies to the original head)
diff --git a/crates/xcl/src/hle/d3d12x/bind.rs b/crates/xcl/src/hle/d3d12x/bind.rs
index 8c4c819..ca21d74 100644
--- a/crates/xcl/src/hle/d3d12x/bind.rs
+++ b/crates/xcl/src/hle/d3d12x/bind.rs
@@ -2338,4 +2338,58 @@ void ms(uint3 g : SV_GroupID) { o.Store((v * 16u + g.x) * 4u, rec.Load(g.x * 4u)
             forget(this);
         }
     }
+
+    /// A reusable block must fit the recording's remaining budget, not just its request.
+    #[test]
+    fn gpu_two_pass_pooled_scratch_respects_remaining_budget() {
+        use windows::Win32::Graphics::{Direct3D::D3D_FEATURE_LEVEL_12_0, Dxgi::*};
+        unsafe {
+            let factory: IDXGIFactory4 = CreateDXGIFactory1().unwrap();
+            let wanted = std::env::var("XCL_ADAPTER").unwrap_or_default();
+            let mut chosen = None;
+            for i in 0.. {
+                let Ok(adapter) = factory.EnumAdapters1(i) else { break };
+                let desc = adapter.GetDesc1().unwrap();
+                let end = desc.Description.iter().position(|&c| c == 0).unwrap_or(desc.Description.len());
+                let name = String::from_utf16_lossy(&desc.Description[..end]);
+                if !wanted.is_empty() && !name.contains(&wanted) { continue; }
+                let mut dev: Option<ID3D12Device> = None;
+                if D3D12CreateDevice(&adapter, D3D_FEATURE_LEVEL_12_0, &mut dev).is_ok() {
+                    chosen = Some((name, dev.unwrap()));
+                    break;
+                }
+            }
+            let Some((name, dev)) = chosen else {
+                crate::gpu::recomp::runner::skip_test("no selected D3D12 adapter");
+                return;
+            };
+            println!("POOLED_SCRATCH_ADAPTER={name}");
+            let key = dev.as_raw() as usize;
+            // These are state keys only; scratch_args does not call through a list pointer.
+            let (consumer, producer, empty) = (0x7500_1011usize as *mut c_void, 0x7500_1012usize as *mut c_void, 0x7500_1013usize as *mut c_void);
+            let allocator = 0x7500_1014usize;
+            let first = scratch_args(consumer, &dev, SCRATCH_BLOCK).unwrap();
+            assert_eq!(with(consumer, |s| s.scratch_taken), SCRATCH_BLOCK);
+            reset(producer, allocator, 0);
+            let large = scratch_args(producer, &dev, SCRATCH_CAP).unwrap();
+            assert_eq!(large.0.GetDesc().Width, SCRATCH_CAP);
+            reset(producer, 0, 0);
+            release_allocator_res(allocator);
+            let second = scratch_args(consumer, &dev, SCRATCH_BLOCK).unwrap();
+            let taken = with(consumer, |s| s.scratch_taken);
+            println!("POOLED_SCRATCH taken={taken} second_bytes={} cap={SCRATCH_CAP}", second.0.GetDesc().Width);
+            // If it was too large for consumer, the cached block remains reusable by an empty recording.
+            let reused = if taken <= SCRATCH_CAP {
+                let r = scratch_args(empty, &dev, SCRATCH_CAP).unwrap();
+                assert_eq!(r.0.as_raw(), large.0.as_raw());
+                assert_eq!(with(empty, |s| s.scratch_taken), SCRATCH_CAP);
+                assert!(scratch_args(empty, &dev, 256).is_err());
+                Some(r)
+            } else { None };
+            drop((first, second, large, reused));
+            for list in [consumer, producer, empty] { forget(list); }
+            FREE_RES.lock().unwrap().retain(|(_, _, d)| *d != key);
+            assert!(taken <= SCRATCH_CAP, "pooled block exceeds recording budget: {taken} > {SCRATCH_CAP}");
+        }
+    }
 }

AI assistance: Codex (GPT-6), investigation, fix/reproducer preparation, native Windows test execution and report. No competing PR.

@PracticalStudios

Copy link
Copy Markdown
Author

@WebIdentity1 thanks — confirmed here too (RTX 3090: 17 825 792 B taken without the fix, 2 097 152 B with it). Your fix and test are in 47c7cc1, credited to you; the regression blocks for the new head follow.

AI use: Claude Code (Claude Opus 5.5) wrote this reply.

@CharlyRien

CharlyRien commented Nov 25, 2026 •

Copy link
Copy Markdown

Update (in-title result): with #1803 and the heap addresses passed to the two-pass compute pass, s23 / s24 do hold the heap bases (10 000 of 10 000 binds logged) and the records are still (1, 1), so the explanation in the third bullet below is refuted on my tree; base 16 and the need for the heap addresses stand. Details: #724 (comment)

A correction that concerns the (1, 1) records listed here as not fixed: FIRST_SGPR_MS = 16 is right, my "one register too late" on #724 was wrong. Details and the decoded per-stage table are in #724 (comment).

Short version, from decoding the root-layout table of every stage in the retail title's shader pack (offline, no run behind it yet):

  • the root arguments of every mesh stage start at user-data dword 8 = s16 and pack exactly as XCL packs them (0 differences);
  • all but 23 mesh stages also expect the descriptor-heap base addresses right after their arguments (view heap, then sampler heap); for the most common layout [table, table, table, root SRV, 2 constants] that is s23 / s24, and the code loads a V# from s23 + index × 32;
  • the two-pass path leaves those registers 0, which is my current explanation for the (1, 1) records (inferred; the in-title check is running and I will report it on D3D12.X: execute two-pass mesh shaders on DispatchMesh and ExecuteIndirect #724).

So nothing to change in the base register; what this path needs is what #1803 does for compute and graphics.

AI use: Claude Code (Claude Fable 5.2 coordinating, Claude Opus 5.5 for the decoder) did this and drafted the comment.

@IAmTheSween

Copy link
Copy Markdown

Test report from a desktop RTX 5070 (Blackwell, 11 943 MiB, driver 32.0.16.2114), Ryzen 5 5600X / 31.9 GB, Windows 11 26300.9974, rustc 1.100.0, release build of head 47c7cc13c1b872ae5f45e4c9ffed6332ca74a4d0 (its base is cbc296a, so the suite count is comparable to that tree).

Suite: clean

  • cargo build --release -p xcl: clean.
  • cargo test --workspace -- --test-threads=4: 971 passed, 0 failed, 43 ignored across 20 binaries, no flakes. 24 SKIPPED: 18 no wave64, 3 refused per-lane cases (f16 ×2, f32 conversions), two_pass_binds_set_the_shared_view_heap (no heap windows), pso_measurement_compiles_an_exact_synthetic_record (no Developer Mode), and heap_window_out_of_memory_falls_back_to_the_switch_form. 4 runtime xcl: … skipped notices. The PR's own report has 970 passed / 1 failed on the xmem_virtual_query… test that also fails on its base here; that test passes on this machine.

Title run: the new path is not exercised by my route

Not a clean A/B against main

  • The isolated main cbc296a baseline on the same route/state crashed at 92.658 s with the known unhandled exception 0xc0000005 in game_scarlett_master.exe+0x2215c35 (write at address 0x0), 885 frames, peak 13 505 MB. That is the title bug already reported elsewhere, not a device removal. Because main died before reaching the late run phase, I cannot attribute the black last frame or the high commit to this PR.
  • Also not tested: AMD / wave64, the two-pass path itself (needs D3D12.X: a console MS in the AS slot is translated as the mesh shader it is #541 or equivalent), XCL_HEAP_WINDOWS=1, XCL_DIRECT_DXIL=1, and a run without the concurrent process.

AI use

  • OpenCode with DeepSeek V4.1 Flash Abliterated (deepseek-v4-pro-uncensored); ran the build, suite and isolated title runs, wrote this from the preserved logs.

@JoaoPauluu

Copy link
Copy Markdown

A regression run under Wine on Linux on the retail title: no device removal, no crash, frames level with main (1386 here; 1371 and 1356 on the two main runs). No two-pass DispatchMesh line appears in the log, and the same 40 mesh pipelines as on main are refused (MS … in the AS slot), so the two-pass path is not reached here; this is a regression run only. The last console code so far line read 16384 draws and 826 dispatches at 59.5 s, against 10243 / 512 (58.4 s) and 11488 / 512 (54.3 s) on the two main runs. Those lines are printed at milestones, so these are not exact totals.

Tested

Regression run

main (first run):

xcl-smoke v1
commit: f5c5bdf0e91035f8f1404f46f4f2f7aedc259e7f
gpu: NVIDIA GeForce RTX 3060
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1371 (PresentX 1371)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 0 MB

this PR:

xcl-smoke v1
commit: 47c7cc13c1b872ae5f45e4c9ffed6332ca74a4d0
gpu: NVIDIA GeForce RTX 3060
title: GTA6.Xbox.v1.0.2.1
seconds: 60
exit: 0x0
frames shown: 1386 (PresentX 1386)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 0 MB

The second main run: 1356 frames, exit: 0x0, no device removal, no crash. Under Wine, peak commit reads 0 MB, so these blocks do not check memory.

Not tested

  • the test suite on this head, the mesh pipelines this title refuses, native Windows, native Windows.

AI use

  • Claude Code (Claude Opus 5.5) built both commits, ran the runs and wrote this report. The account owner asked for test reports to be posted and has not reviewed this one.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

IvyNotFound added a commit to IvyNotFound/xcl that referenced this pull request Nov 25, 2026
# Conflicts:
#	crates/xcl/src/hle/d3d12x/bind.rs
#	crates/xcl/src/hle/d3d12x/console_list.rs
#	crates/xcl/src/hle/d3d12x/device_x.rs
#	crates/xcl/src/hle/d3d12x/real.rs
@CharlyRien

Copy link
Copy Markdown

In-title result for the two-pass path, on the tree of my #724 comments (this PR's 3442b58 state with #541, #1887, #1803): once the buffers the mesh programs and the culling read are readable, the records carry real meshlet counts and geometry reaches the depth target and the G-buffer.

Details, setup and limits are in #697 (comment). What matters for this PR:

One run plus one partial run, RTX 3090; the copies that made the GPU view readable are a local experiment.

AI use: Claude Code (Claude Fable 5.2 coordinating, Claude Opus 5.5 for the ports and the runs) did this and drafted the comment.

@ettehn

ettehn commented Nov 25, 2026 •

Copy link
Copy Markdown

Synthetic mesh readback on RTX 5070 Ti Laptop. I tested 47c7cc1 plus a local test-only extension on Windows 11 25H2 (26200.9974), NVIDIA driver 32.0.16.2124, Ryzen 9 8945HX, Rust 1.97.1 MSVC and DXC 1.8.2502.11. XCL_ADAPTER=nvidia, XCL_HEAP_WINDOWS=0, XCL_DIRECT_DXIL=0.

cargo test --locked --offline -j 2 -p xcl --lib <filter> -- --nocapture --test-threads=1 ran 7 tests, all passed with zero skips across these filters:

  • gpu_mesh_mode (2): read the expected vertex table from the second memory window, with a decoy table in the first. The two-pass test read back 3 vertices and 1 primitive per group and the expected triangle pixels, including identical pixels through the split passthrough.
  • gpu_indirect_two_pass (4): the additional fixture rewrites 130 commands with a count of 65. The last live command in the second 64-thread group was correct in both output arrays. Commands after it had zero groups, and the output guard remained intact. The same four tests passed on WARP.
  • gpu_two_pass_indirect_commands_keep_their_own_records (1): verified the record isolation with the test’s stand-in compute passes and D3D12 ExecuteIndirect.

These fixtures cover synthetic inputs. Retail GPU-view aliases, visible world geometry and heap-window mode were outside this run. Testing and the test-only extension assisted by OpenAI Codex (GPT-6).

Heap-window follow-up. On the same build base and machine with XCL_HEAP_WINDOWS=1, three focused tests passed with zero skips using the command above. two_pass_binds_set_the_shared_view_heap observed both stages bind the shared view heap on a command-list stand-in that started with no heap. I extended gpu_mesh_mode_reads_memory_windows to compile and execute the descriptor-heap variant: readback matched all three expected window-1 vertex positions for both descriptor-heap and root-UAV translations, while the one-window control read the decoy. gpu_heap_windows_reject_out_of_uma_aliasing also passed. The binding fixture and shader readback are separate checks. Retail GPU-view aliasing and an actual title run remain untested. Verification and test extension assisted by OpenAI Codex (GPT-6).

@imnicho

imnicho commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

RTX 5080 16 GB, 47c7cc1 with #541 and #1803 in the retail title: the mesh draws run here too, nothing is refused, and the visibility target stays empty

A third NVIDIA card, on the current heads and on a newer base than the runs above.

Setup. RTX 5080 16 GB (driver 610.47, 32-lane waves), i7-7700K, 16 GB RAM, Windows 10 22H2, release. The retail title of #505 (my own copy), XCL_NETWORK=0, scripted pad, binds waiting (no XCL_PSO_WAIT_MS), XCL_DIRECT_DXIL=1 XCL_HEAP_WINDOWS=1 XCL_UMA_SHADOW=1 XCL_HUGE_PSO_CONCURRENCY=2, compute pipelines prebuilt with --precompile --used-only.

Tree (local): #2057 at 41303e4 + #2067 + #684 + #266 + #1515 + #495 + #1405 + #751, then this PR at 47c7cc1, #1803 at cb00751, #1887 at 5fe5b41 and #541's four own commits (70f9185 … 6bd8f64), plus six local lines that pass #1803's heap addresses to both two-pass stages (with_heaps over user_data_ms / user_data_gfx in two_pass_io). For the second run also #2050.

Conflicts, for whoever merges the same

Measured

without this PR and #541 (one run, 283 s in the world) with them (one run, 454 s in the world)
mesh pipeline … in the AS slot – refused 40 logged (the log's cap; 6,685 distinct shaders arrive in the AS slot) 0
draws in the world 86,722, at most 2,943 in 2 s 126,248, at most 14,967 in 2 s
dispatches in the world 496,226 105,661
presents in the world 163 (0.6 a second) 41 (0.1 a second)
skipped draws or dispatches 0 0
waits released by the GPU-wait watchdog 0 0
end 0x887a0005 with local video memory at 20.7 GB (budget 15.1 GB) access violation in nvwgf2umx.dll at 561 s, local video memory 21.7 GB (budget 15.1 GB)
  • The log has two-pass DispatchMesh with real group counts (92 groups in the first ones), two-pass ExecuteIndirect(DispatchMesh) and 31 two-pass MS PSO lines. One mesh pipeline was refused: the driver rejected the mesh pipeline from the console MS (0x80070057) at 414.7 s, the line @ThiagoAlexsander also got on an RTX 5080 on D3D12.X: a console MS in the AS slot is translated as the mesh shader it is #541. I have not found out which one or why.
  • With D3D12.X: XCL_DUMP_TARGETS dumps the most-drawn render targets of a frame #2050 (XCL_DUMP_TARGETS=3000,4, one run, four world frames): a frame has 5,500 to 9,900 draws and dispatches into 35 to 43 render targets, every draw "ran" (0 stand-in, 0 PC, 0 skipped). The 2560x1440 R32_UINT target takes 180 draws a frame (360 in one) and is all zero in all four frames. The 2560x1440 R16G16B16A16_FLOAT target takes 216 to 562 draws; 291 of 230,400 sampled texels are not zero in the first frame, about 198,000 in the other three, where the most common raw words are 0x00020000 and 0x00050001. So the mesh draws execute and nothing lands in the target they share, which is what the (1, 1) records above give. The presented frame is the uniform grey.
  • The frame rate in the world fell from 0.6 to 0.1 presents a second with the two-pass path on. I have not looked at where the time goes; video memory is 6 GB over this card's budget in both runs, which alone slows everything.

Not tested

  • This PR by itself on main, and the suite on it: every number here is from the tree above.
  • AMD, Intel, native 64-lane waves. One run per column.

AI use: Claude Code with Claude Fable 5.2 merged the tree, ran the title and wrote this.

@CharlyRien

Copy link
Copy Markdown

Offer: one commit for the compute pass's heap addresses once #1803 is in (or if you want to take #1803's with_heaps along).

With #2092 (47c7cc1) and #1803 (cb00751) merged together, the two-pass compute pass still builds its user data with user_data_ms alone, so a mesh program whose root signature has CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED reads 0 where its view-heap address should be. In a retail title, the mesh programs built for the most common mesh root signature [table, table, table, root SRV, 2 constants] load their meshlet list's descriptor from s23 + index × 32. Their container's root-layout table puts the view heap at user-data dword 15 = s23 and the sampler heap at s24, right after the arguments, with your first register 16 (format on #724: #724 (comment)). Two testers have already wired this by hand: ettehn for a synthetic readback (#697 (comment)) and imnicho in the retail title just above (six local lines, both two-pass stages). So this is the same change as a commit with a unit test, so that it does not have to be redone on each tree. In-title numbers with an equivalent local change are on #697 (#697 (comment)). That tree is larger; the change was necessary there, not sufficient on its own: as in imnicho's run, the targets stay empty until the buffers the culling and the mesh programs read from the GPU view of the title's 24 GB reservation are readable (#697).

The commit below is on top of a local merge of your head with #1803's head. Both sides of each conflict were kept: Layout (inline_ms + heaps), user_data_ms next to with_heaps, and reset() clears heaps as well as your scratch / resource buffers. It changes two_pass_io only (one with_heaps call, a heaps parameter from State::heaps), and it adds a unit test: the 5-slot layout with both flags gives s16..s24 = t0 t4 t8 d.lo d.hi c c H S. Without the flags, nothing follows the arguments. The mesh pass's pixel shader is left as it is.

Feel free to squash it into your branch once #1803 lands, or tell me and I will open it as a stacked PR instead.

Tested on an RTX 3090 24 GB (driver 616.56), Ryzen 9 5950X, Windows 11 22631, debug build. On the merged tree, cargo test -p xcl --lib two_pass: 12 passed; 0 failed; 0 ignored (one SKIPPED line: no heap windows). Without the with_heaps call the new test fails (left: [256, 288, 320, 20480, 7, 1, 2, 0, 0]). cargo build -p xcl builds with no new warning. Not run: the whole suite, the retail title with this exact head.

AI use: Claude Code (Claude Fable 5.2 coordinating, Claude Opus 5.5 writing the code and tests).

Patch (git format-patch, applies on 47c7cc1 + cb00751 merged)
From 264b6a80922ccc3d79e06cad82ee5f892874e99e Mon Sep 17 00:00:00 2001
From: CharlyRien <address removed>
Date: Wed, 25 Nov 2026 10:09:36 +0100
Subject: [PATCH] D3D12.X: the two-pass mesh compute pass gets the heap
 addresses

The compute pass of a two-pass mesh draw runs the console MS with the user
data of `user_data_ms` only, so a mesh program built for a root signature with
CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED / SAMPLER_HEAP_DIRECTLY_INDEXED read 0 where
its heaps' addresses should be. `two_pass_io` now appends them after the mesh
root arguments with `with_heaps`, as `bind_abi` does for the other binds; the
first register stays 16.

In a retail title the mesh programs of the most common mesh root signature
[table, table, table, root SRV, 2 constants] load their meshlet list's
descriptor from s23 + index * 32, and their container's root-layout table puts
the view heap at s23 and the sampler heap at s24, right after the arguments.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
---
 crates/xcl/src/hle/d3d12x/bind.rs | 40 +++++++++++++++++++++++++------
 1 file changed, 33 insertions(+), 7 deletions(-)

diff --git a/crates/xcl/src/hle/d3d12x/bind.rs b/crates/xcl/src/hle/d3d12x/bind.rs
index ef04351..f31b79b 100644
--- a/crates/xcl/src/hle/d3d12x/bind.rs
+++ b/crates/xcl/src/hle/d3d12x/bind.rs
@@ -434,10 +434,12 @@ unsafe fn ensure_res_buffer(this: *mut c_void, need_bytes: u64) -> Result<(ID3D1
 
 /// The `io` block of a two-pass stage: its user SGPRs (`compute_pass`: the MS layout) with the
 /// argument table at `table_at`, and the high dword of unified memory's base, as the other binds
-/// write it (the translated pair picks each access's memory window from it).
-fn two_pass_io(layout: Option<&Layout>, args: &[u8], table_at: u64, compute_pass: bool, uma_base: usize) -> Vec<u32> {
+/// write it (the translated pair picks each access's memory window from it). The compute pass
+/// runs the console MS: when its layout says the shaders index the heaps themselves, the heaps'
+/// addresses (`State::heaps`) follow the mesh root arguments, as `bind_abi` places them.
+fn two_pass_io(layout: Option<&Layout>, args: &[u8], table_at: u64, compute_pass: bool, uma_base: usize, heaps: [u32; 2]) -> Vec<u32> {
     let mut io = match layout {
-        Some(l) if compute_pass => console_list::user_data_ms(l, args, table_at),
+        Some(l) if compute_pass => console_list::with_heaps(l, None, console_list::user_data_ms(l, args, table_at), heaps),
         Some(l) => console_list::user_data_gfx(l, args, table_at),
         None if compute_pass => {
             let mut v = vec![0u32; 16];
@@ -465,7 +467,7 @@ unsafe fn bind_two_pass_stage(
     let u = crate::gpu::uma::get().ok_or("no unified memory")?;
     let windows = super::real::uma_window_vas();
     let first = *windows.first().ok_or("unified memory is not open on the GPU")?;
-    let (layout, args) = with(this, |s| (s.layout_gfx.clone(), s.args_gfx.clone()));
+    let (layout, args, heaps) = with(this, |s| (s.layout_gfx.clone(), s.args_gfx.clone(), s.heaps));
     let copy = |bytes: &[u8]| -> Result<usize, String> {
         let p = with(this, |s| s.arena.take(u, bytes.len().max(16), 256, &mut s.uma)).ok_or("unified memory is full")?;
         std::ptr::copy_nonoverlapping(bytes.as_ptr(), p, bytes.len());
@@ -476,7 +478,7 @@ unsafe fn bind_two_pass_stage(
         .map_or(0, |l| if compute_pass { l.inline_ms } else { l.inline_gfx } as usize)
         .min(args.len());
     let table_at = copy(&args[inline..])?;
-    let io = two_pass_io(layout.as_deref(), &args, table_at as u64, compute_pass, u.base());
+    let io = two_pass_io(layout.as_deref(), &args, table_at as u64, compute_pass, u.base(), heaps);
     let io_at = copy(&io.iter().flat_map(|w| w.to_le_bytes()).collect::<Vec<u8>>())?;
     let va = |p: usize| super::real::uma_va_of(p).unwrap_or(first);
     let rs_raw = if compute_pass { tp.compute_rs } else { tp.mesh_rs } as *mut c_void;
@@ -2069,14 +2071,38 @@ void main(uint t : SV_GroupIndex) {
         use crate::gpu::recomp::{IO_UMA_BASE_HI, KERNEL_SGPRS};
         let base = 0x4_0000_0000usize;
         for compute_pass in [true, false] {
-            let io = two_pass_io(None, &[], 0x4_1234_5600, compute_pass, base);
+            let io = two_pass_io(None, &[], 0x4_1234_5600, compute_pass, base, [0; 2]);
             assert_eq!(io.len(), KERNEL_SGPRS);
             assert_eq!(io[IO_UMA_BASE_HI], 4, "compute pass {compute_pass}");
         }
-        let io = two_pass_io(None, &[], 0x4_1234_5600, true, base);
+        let io = two_pass_io(None, &[], 0x4_1234_5600, true, base, [0; 2]);
         assert_eq!((io[8], io[9]), (0x1234_5600, 4));
     }
 
+    /// The compute pass of a mesh draw whose shaders index the heaps: the heaps' addresses right
+    /// after the mesh root arguments (from s16), the view heap's first – the 5-slot mesh layout
+    /// [table, table, table, root SRV, 2 constants] a retail title's mesh programs are built for
+    /// reads its view heap from s23.
+    #[test]
+    fn two_pass_compute_pass_gets_the_heap_addresses() {
+        // RTS0 v2: tables (0), an SRV (3), two constants (1); both DIRECTLY_INDEXED flags
+        let params = [(0u32, 0u32), (0, 0), (0, 0), (3, 0), (1, 2)];
+        let mut r = vec![2u32, 5, 24, 0, 0, 0x400 | 0x800];
+        r.extend(params.iter().enumerate().flat_map(|(k, &(ty, _))| [ty, 0, 24 + 12 * 5 + 12 * k as u32]));
+        r.extend(params.iter().flat_map(|&(_, count)| [0, 0, count]));
+        let l = console_list::layout_from_blob(&r.iter().flat_map(|w| w.to_le_bytes()).collect::<Vec<u8>>()).unwrap();
+        assert_eq!(l.heaps, [true, true]);
+        let args: Vec<u8> = [0x100u32, 0x120, 0x140, 0x5000, 7, 1, 2].iter().flat_map(|w| w.to_le_bytes()).collect();
+        let heaps = [0x4c61_0000, 0x6381_0000];
+        let io = two_pass_io(Some(&l), &args, 0x7_0000_0200, true, 0x4_0000_0000, heaps);
+        assert_eq!((io[8], io[9]), (0x200, 7));
+        assert_eq!(&io[16..25], &[0x100, 0x120, 0x140, 0x5000, 7, 1, 2, 0x4c61_0000, 0x6381_0000]);
+        // a layout without the flags: nothing after the arguments
+        let mut l = l;
+        l.heaps = [false; 2];
+        assert_eq!(two_pass_io(Some(&l), &args, 0x7_0000_0200, true, 0x4_0000_0000, heaps)[23..25], [0, 0]);
+    }
+
     #[test]
     fn two_pass_groups_stay_inside_the_record_buffer() {
         // #304's transform record: 11 908 dwords
-- 
2.46.0.windows.1

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.

9 participants