Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions THIRD_PARTY.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ carry a note in their header about its origin and the date of changes (GPL-3.0
| [AMD Machine-Readable GPU ISA](https://gpuopen.com/machine-readable-isa/) | MIT | `crates/xcl/src/gpu/rdna2_spec.rs` (generated by `scripts/gen_rdna2.py`) | encoding and instruction tables |
| [AMD addrlib](https://gitlab.freedesktop.org/mesa/mesa/-/tree/main/src/amd/addrlib) (Mesa) | MIT | `crates/xcl/src/gpu/tiling_tables.rs` (generated by `scripts/gen_tiling.py` from `gfx10SwizzlePattern.h`); GFX10 mip chain / mip tail layout in `gpu/tiling.rs` (after `Gfx10Lib::ComputeSurfaceInfoMacroTiled`) | swizzle tables; layout logic ported with annotation |
| [VIctory](https://github.com/Marvisak/VIctory) | GPL-3.0 | `crates/xcl/src/hle/bcpack/`: port of its `victory-formats/src/bcpack.rs`, and `tables.rs` generated by `scripts/gen_bcpack_victory_tables.py` from its `bcpack-tables.bin` (the format's constant tables; its 128 rANS models are those of Microsoft's [silicon-rans](https://github.com/microsoft/silicon-rans) sample, MIT) | port to Rust; tables |
| [victory-fork](https://github.com/fxceless/victory-fork) | GPL-3.0-or-later | `crates/xcl/src/hle/d3d12x/pso_async.rs` (`run`): a pipeline build that panics counts as a failed one, adapted from its `crates/victory-gpu/src/pipeline/make.rs` (victory-fork commit 46da5ee) | adapted, with annotation |
| [LLVM](https://github.com/llvm/llvm-project) | Apache-2.0 WITH LLVM-exception | `tests/data/llvm-amdgpu/*` (test data, not part of the program); GFX10 buffer format values (`UfmtSymbolicGFX10`) in `gpu/recomp/emit.rs` | test vectors; hardware facts |
| [WinDurango](https://github.com/WinDurango/WinDurango) | LGPL-3.0 | no code; d3d12_x.dll export numbers (facts) in `crates/xcl/data/stubdb.toml` | reference only |
| [libHttpClient](https://github.com/microsoft/libHttpClient) | MIT | no code; XTaskQueue/XAsync contract | specification |
Expand Down
70 changes: 67 additions & 3 deletions crates/xcl/src/hle/d3d12x/pso_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
//! as it is there. A graphics pipeline draws nothing until then; a compute pipeline is waited
//! for where it is used, a `Dispatch` at its submit (a skipped dispatch would corrupt what it computes).
//! `XCL_ASYNC_PSO=0` builds every pipeline in the call, as before.
//!
//! `run` (a panicking build counts as failed) is adapted from victory-fork
//! (https://github.com/fxceless/victory-fork, GPL-3.0-or-later), commit 46da5ee; 2026-11-27.

use std::collections::HashMap;
use std::sync::atomic::{AtomicUsize, Ordering};
Expand Down Expand Up @@ -79,7 +82,7 @@ fn build(p: &Arc<Pending>, job: Job, preload: bool) {
unsafe { SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL) };
}
}
complete(p, job());
complete(p, run(job));
if preload {
// (under the lock: `want` does not raise this thread after it)
let mut d = p.demand.lock().unwrap();
Expand Down Expand Up @@ -269,6 +272,22 @@ pub fn enabled() -> bool {
/// Builds the real pipeline: its raw pointer, 0 = failed.
pub type Job = Box<dyn FnOnce() -> usize + Send>;

/// Runs `job`; a build that panics (a translator bug, an unwrap on a driver error) counts as a
/// failed one: its waiters get the stand-in instead of waiting forever, and the worker goes on
/// with the next build.
/// Adapted from victory-fork (https://github.com/fxceless/victory-fork, GPL-3.0-or-later),
/// `crates/victory-gpu/src/pipeline/make.rs`, `Pending::make_with`, victory-fork commit 46da5ee.
fn run(job: Job) -> usize {
std::panic::catch_unwind(std::panic::AssertUnwindSafe(job)).unwrap_or_else(|_| {
static N: AtomicUsize = AtomicUsize::new(0);
let n = N.fetch_add(1, Ordering::Relaxed);
if n < 16 || n.is_power_of_two() {
crate::xlog_warn!("D3D12.X: a pipeline build panicked: the pipeline counts as failed; later builds may fail too if it panicked holding a lock ({} so far)", n + 1);
}
0
})
}

/// pipelines a submit will wait for: the workers take these before their queue (`need_by_submit`)
static NEEDED: Mutex<std::collections::VecDeque<Arc<Pending>>> = Mutex::new(std::collections::VecDeque::new());

Expand Down Expand Up @@ -339,7 +358,7 @@ pub(super) fn build_pieces(jobs: Vec<Job>) -> Vec<usize> {
let drain = move || loop {
let job = jobs.lock().unwrap().pop();
let Some((i, job)) = job else { return };
let _ = send.send((i, job()));
let _ = send.send((i, run(job)));
};
// the helpers build for this worker's pipeline: the title waiting for it waits for them too
let parent = BUILDING.with(|b| b.borrow().clone());
Expand Down Expand Up @@ -642,6 +661,51 @@ mod used_tests {
assert_eq!((released(fails), released(builds)), (0, 0x1234));
}

/// A build that panics on a worker counts as failed: a bind waiting for it gets the stand-in,
/// asking again does not wait, and the workers build the next pipeline.
#[test]
fn a_panicking_build_fails_and_the_workers_go_on() {
let _sat = WORKER_SATURATION_LOCK.lock().unwrap_or_else(|e| e.into_inner());
let (bad, good) = (0x7E57_B0D1usize, 0x7E57_B0D2usize);
let worker = |name: Option<&str>| name.is_some_and(|n| n.starts_with("xcl-pso-"));
let (tx, rx) = std::sync::mpsc::channel();
submit(bad, true, Box::new(move || {
let _ = tx.send(worker(std::thread::current().name()));
panic!("synthetic pipeline build panic")
}));
assert!(rx.recv_timeout(std::time::Duration::from_secs(10)).expect("a worker took the build"), "built on a worker");
// (the worker finishes the entry: a wait that is not a build of its own ends)
let t = std::time::Instant::now();
while !*entry(bad).unwrap().done.lock().unwrap() {
assert!(t.elapsed() < std::time::Duration::from_secs(10), "the panicked build was never finished");
std::thread::sleep(std::time::Duration::from_millis(1));
}
assert_eq!((resolve_wait_for(bad, None), resolve_wait_for(bad, None)), (bad, bad), "a panicked build is a failed one: the stand-in");
// (every worker in turn: one that died would leave the builds after it undone)
let n = crate::gpu::recomp::dxc::compile_threads() + 1;
for k in 0..n {
submit(good + 0x10 * (k + 1), true, Box::new(|| panic!("synthetic pipeline build panic")));
}
let (tx, rx) = std::sync::mpsc::channel();
submit(good, true, Box::new(move || {
let _ = tx.send(worker(std::thread::current().name()));
0x5C5C
}));
assert!(rx.recv_timeout(std::time::Duration::from_secs(10)).expect("a worker built the next pipeline"), "built on a worker");
let t = std::time::Instant::now();
while !*entry(good).unwrap().done.lock().unwrap() {
assert!(t.elapsed() < std::time::Duration::from_secs(10));
std::thread::sleep(std::time::Duration::from_millis(1));
}
assert_eq!(resolve(good), 0x5C5C);
// (no lock was left poisoned)
assert!(!PENDING.is_poisoned() && !entry(bad).unwrap().done.is_poisoned());
for k in 0..n {
let _ = released(good + 0x10 * (k + 1));
}
let _ = (released(bad), released(good));
}

/// A bind does not wait for a compute pipeline that writes only images: it gets the stand-in
/// at once, with no budget, the build goes to the workers
/// unwanted, and once built the bind gets the real one. Without `image_only` the same bind
Expand Down Expand Up @@ -1084,7 +1148,7 @@ fn resolve_wait_for(pso: usize, budget: Option<std::time::Duration>) -> usize {
}
let job = p.job.lock().unwrap().take();
if let Some(job) = job {
complete(&p, job());
complete(&p, run(job));
}
p.want();
let mut done = p.done.lock().unwrap();
Expand Down
3 changes: 2 additions & 1 deletion crates/xcl/src/hle/d3d12x/real/dispatch_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ struct Chain {
impl Chain {
unsafe fn whole(&self) -> Result<ID3D12PipelineState, String> {
if let Some(p) = self.whole.get() { return Ok(p.clone()); }
let _guard = self.build_whole.lock().unwrap();
// (guards no data: a build that panicked here leaves `whole` unset, and the next one tries again)
let _guard = self.build_whole.lock().unwrap_or_else(|e| e.into_inner());
if let Some(p) = self.whole.get() { return Ok(p.clone()); }
let p = self.builder.pipeline(&self.whole_code, &pc_iid(Kind::PipelineState)).ok_or("whole compute pipeline")?;
let _ = self.whole.set(p.clone());
Expand Down
Loading