Repository navigation
D3D12.X: execute two-pass mesh shaders on DispatchMesh and ExecuteIndirect (supersedes #724) - #2092
PracticalStudios wants to merge 9 commits into
Conversation
…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.
|
Verified a small pool-reuse bug on 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 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 ( cargo test --locked -p xcl --lib -- hle::d3d12x::bind::tests::gpu_two_pass_pooled_scratch_respects_remaining_budget --exact --test-threads=1 --nocaptureSmall 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. |
Found and fixed by @WebIdentity1 in xcl-dev#2092.
|
@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 AI use: Claude Code (Claude Opus 5.5) wrote this reply. |
|
Update (in-title result): with #1803 and the heap addresses passed to the two-pass compute pass, A correction that concerns the (1, 1) records listed here as not fixed: Short version, from decoding the root-layout table of every stage in the retail title's shader pack (offline, no run behind it yet):
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. |
|
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 Suite: clean
Title run: the new path is not exercised by my route
Not a clean A/B against
AI use
|
|
A regression run under Wine on Linux on the retail title: no device removal, no crash, frames level with Tested
Regression run main (first run): this PR: The second Not tested
AI use
|
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
Supersedes #724 (@Cattn's, inactive since the reviews): its commit rebased onto
mainwith authorship kept, plus the five points @ivall listed on #724 before it can merge. Two-pass mesh pipelines (what #541 builds) run onDispatchMeshandExecuteIndirect; #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.rsmostly, plusconsole_list.rs,device_x.rs,real.rs)99b9816D3D12.X: execute two-pass mesh shaders on DispatchMesh and ExecuteIndirect #724's commit (rebased; conflicts inconsole_list.rs/bind.rsresolved keeping both sides).d41d2f3the two-passioblock getsIO_UMA_BASE_HI.ee561d0groups stay inside the record buffer;ccfe5c1indirect Y / Z > 1 are folded into X.e284043indirect arguments are read through unified memory instead of transitioning the title's buffer; per-list scratch is capped.3442b58an ExecuteIndirect withmax > 1runs one command at a time, so commands don't overwrite each other's records.e9471c5two-pass binds set the shared view heap first (heap windows read it).47c7cc1pooled scratch stays within the recording's remaining budget (found and fixed by @WebIdentity1).Tested
cargo test --workspace --no-fail-fast -- --test-threads=2on47c7cc1: 970 passed, 1 failed, 43 ignored. The failure (kernelx::tests::xmem_virtual_query_marks_cpu_readable_memory) fails the same way onmainhere (Tests: align XMemVirtualQuery buffers and verify CPU flags #650).3442b58with D3D12.X: a console MS in the AS slot is translated as the mesh shader it is #541: @cafeoh (RTX 2080 Ti) and @CharlyRien (RTX 3090) — the mesh draws now run (thousands per frame, none skipped; 6 685 pipelines refused without D3D12.X: a console MS in the AS slot is translated as the mesh shader it is #541/D3D12.X: execute two-pass mesh shaders on DispatchMesh and ExecuteIndirect #724).Regression run
.\scripts\smoke.ps1 -Game <retail title> -Seconds 60, no input,mainfirst, same machine:Not tested
AI use
https://claude.ai/code/session_01HqVqYwUoC2oJRwQSXDePn3