Repository navigation
Conversation
|
Full-suite run, since this PR has no test report yet. Tested exact head Tested
Not tested
AI use
|
…PC reads them Clean-room XCL implementation. Assisted-by: Claude Code
7b9a1e0 to
201d67d
Compare
|
Verification on RTX 3060 Ti (Windows 11): merge conflict with current |
|
Title run of Tested:
Runs 3 to 8 also had #1323 (
Not tested: more than one run with the clamp off. What was running at the removal in runs 3 and 5 to 8: AI use: Claude Code (Claude Opus 5.5) merged the build, ran the title, read the logs and wrote this comment. |
|
Regression run for this PR: head main this PR: No device removals or crashes; 101 % of main's frames, 94 % of its peak commit. Not tested: the whole suite; whether the title reaches the changed code in these 60 s. Written with Claude Code (Claude Opus 5.5) from runs on this machine. |
PR #1795 — ExecuteIndirect clamp on Intel Arc A770Tested commit Tested
Failures and skips
Not tested No main baseline or retail-title smoke run, sample-data coverage, or other GPU vendors. The clamp readback exercised indexed draws. GPU dispatch and mesh clamping and the full title-to-clamp path were outside that test. AI use T3 Code / Codex ( |
|
FYI, a lock-order note from running this PR in the newer retail title's world (#505) on an RTX 5080, on a tree based on an older There, from a symbolised thread dump when every title thread had stopped:
If you want AI use: Claude Code (Claude Opus 5.5; a Claude Fable 5.2 subagent read the dump and wrote the local fix). I checked both call chains and that 892177b is in |
|
Linux (Wine + vkd3d-proton) + NVIDIA, the title, 3 runs with #1795 and 3 without: in each run with it, the clamp bounded each of the first 256 Setup:
Not tested: today's AI use: Claude Code (Claude Opus 5.5) read the change, wrote the counter, ran the title and the tests, and wrote this comment. Posted without review by a person: the account owner was away and reads replies later. |
|
A frame-rate cost of this PR on a retail title, and a fix: the scratch pool churns, under a lock every render thread takes. RTX 5070 Ti 16 GB (driver 610.88), Windows 11 26300, release. The PR is in a local integration tree ( What the stack dumps showed. cdb dumps were taken while the title logged nothing for over 6 s. In every one, 3–4 of the title's render threads were waiting on
Why it happens. A frame takes one scratch buffer per bounded The change (diff below, against this PR's
Measured. One run each, same switches, warm caches, frames counted from the world's first
With the change, the pool stopped growing at about 4,096 buffers (256 MB). No device removal, no crash. diffdiff --git a/crates/xcl/src/hle/d3d12x/indirect_clamp.rs b/crates/xcl/src/hle/d3d12x/indirect_clamp.rs
index 93dec17..cdcc9e0 100644
--- a/crates/xcl/src/hle/d3d12x/indirect_clamp.rs
+++ b/crates/xcl/src/hle/d3d12x/indirect_clamp.rs
@@ -156,17 +156,28 @@ struct Scratch {
}
static SCRATCH: Mutex<Option<Scratch>> = Mutex::new(None);
-/// free buffers kept for reuse (the rest are released)
-const FREE_KEPT: usize = 64;
+/// Bytes of free buffers kept for reuse (the rest are released). A frame takes one buffer per
+/// bounded call, often hundreds; keeping too few made and released them again every frame, each
+/// make waiting on the device's paging queue and each release on XCL's late release. LOCAL
+fn free_kept_bytes() -> u64 {
+ static N: OnceLock<u64> = OnceLock::new();
+ *N.get_or_init(|| std::env::var("XCL_INDIRECT_SCRATCH_MB").ok().and_then(|v| v.trim().parse().ok()).unwrap_or(256u64) << 20)
+}
+static MADE: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);
+static MADE_BYTES: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);
/// A buffer of at least `bytes` in UNORDERED_ACCESS, held for `allocator` until its reset.
unsafe fn scratch(dev: &ID3D12Device, allocator: usize, bytes: u64) -> Option<ID3D12Resource> {
let key = dev.as_raw() as usize;
- let mut g = SCRATCH.lock().unwrap();
- let s = g.get_or_insert_with(Default::default);
- let reuse = s.free.iter().enumerate().filter(|(_, (d, n, _))| *d == key && *n >= bytes).min_by_key(|(_, (_, n, _))| *n).map(|(i, _)| i);
- let entry = match reuse {
- Some(i) => s.free.swap_remove(i),
+ let reused = {
+ let mut g = SCRATCH.lock().unwrap();
+ let s = g.get_or_insert_with(Default::default);
+ let reuse = s.free.iter().enumerate().filter(|(_, (d, n, _))| *d == key && *n >= bytes).min_by_key(|(_, (_, n, _))| *n).map(|(i, _)| i);
+ reuse.map(|i| s.free.swap_remove(i))
+ };
+ // made outside the lock: CreateCommittedResource can wait on the paging queue for seconds
+ let entry = match reused {
+ Some(e) => e,
None => {
let size = bytes.next_power_of_two().max(64 << 10);
let mut out: Option<ID3D12Resource> = None;
@@ -189,26 +200,43 @@ unsafe fn scratch(dev: &ID3D12Device, allocator: usize, bytes: u64) -> Option<ID
&mut out,
)
.ok()?;
+ let n = MADE.fetch_add(1, std::sync::atomic::Ordering::Relaxed) + 1;
+ let b = MADE_BYTES.fetch_add(size, std::sync::atomic::Ordering::Relaxed) + size;
+ if n.is_power_of_two() || n.is_multiple_of(1024) {
+ crate::xlog_info!("D3D12.X: ExecuteIndirect bounding: {n} scratch buffers made ({} MB in all)", b >> 20);
+ }
(key, size, out?)
}
};
let r = entry.2.clone();
- s.held.entry(allocator).or_default().push(entry);
+ SCRATCH.lock().unwrap().get_or_insert_with(Default::default).held.entry(allocator).or_default().push(entry);
Some(r)
}
/// The GPU is done with what lists recorded from `allocator` (reset or released): its copies
/// can be reused.
pub(super) fn allocator_reset(allocator: usize) {
- let mut g = SCRATCH.lock().unwrap();
- let Some(s) = g.as_mut() else { return };
- if let Some(done) = s.held.remove(&allocator) {
+ let dropped = {
+ let mut g = SCRATCH.lock().unwrap();
+ let Some(s) = g.as_mut() else { return };
+ let Some(done) = s.held.remove(&allocator) else { return };
s.free.extend(done);
- if s.free.len() > FREE_KEPT {
- s.free.sort_by_key(|e| std::cmp::Reverse(e.1));
- s.free.truncate(FREE_KEPT);
+ let mut total: u64 = s.free.iter().map(|e| e.1).sum();
+ let kept = free_kept_bytes();
+ let mut dropped = Vec::new();
+ if total > kept {
+ // the largest go first; small ones are the common case
+ s.free.sort_by_key(|e| e.1);
+ while total > kept {
+ let Some(e) = s.free.pop() else { break };
+ total -= e.1;
+ dropped.push(e);
+ }
}
- }
+ dropped
+ };
+ // released outside the lock: a release runs XCL's late release, which can wait on fences
+ drop(dropped);
}
/// Where `bytes` at console offset `offset` of console buffer `res` are on the GPU: the GPUNot tested: AMD; other titles; a AI use: Claude Code (Claude Opus 5.5) found this in the stack dumps, wrote the change, ran the runs and wrote this comment. |
|
Re-verification on RTX 3060 Ti (Windows 11): still a merge conflict with current |
Summary
Adds a small GPU compute clamp pass (
indirect_clamp.hlsl/indirect_clamp.rs) that runs beforeExecuteIndirectfor command signatures without root arguments. Corrupt or garbage indirect draw/dispatch counts can no longer triggerDXGI_ERROR_DEVICE_HUNG(0x887a0006): argument records and total work are bounded on the GPU before the PC reads them.XCL_INDIRECT_CLAMP=0disables it.Tested
Windows 11 x64, NVIDIA GeForce RTX 5080 16 GB.
cargo test -p xcl --lib indirect_clamp -- --nocapture --test-threads=1: 4 passed, 0 failed (includes live GPU execution ofgpu_records_are_clamped_and_budgeted)cargo test -p xcl --lib execute_indirect -- --test-threads=1: 2 passed, 0 failedcargo test -p xcl --lib -- --test-threads=1: 844 passed, 0 failed, 22 ignored (no new warnings)Regression run
Smoke run by @Anon64 in comment below: #1795 (comment)
Contributed by a community tester; the PR author did not run it. Both blocks are pasted as posted.
main:
PR:
Tester's setup: RTX 3060 12 GB (581.80, wave32), Windows 11 26200, release,
XCL_NETWORK=0, A pressed every 4 s from 20 s,scripts/smoke.ps1on a retail title for 60 s, in one batch with themainrun.No device removals or crashes; 101 % of main's frames, 94 % of its peak commit.
Tester's AI use: Written with Claude Code (Claude Opus 5.5) from runs on the tester's machine.
Not tested
cargo test --workspacerun by the author: the widest run reported above is thexcllibrary tests.AI use
Assisted-bytrailer); the model is not recorded there.