Skip to content
Draft
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
33 changes: 33 additions & 0 deletions crates/xcl/src/hle/d3d12x/real.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,11 @@ fn graphics_wave32(device: *mut c_void) -> bool {
/// by default the high-performance GPU → WARP); once – later calls
/// return the existing device's adapter.
pub fn init() -> Result<String, String> {
if !device_raw().is_null() {
return Ok(ADAPTER.lock().map(|a| a.clone()).unwrap_or_default());
}
static INIT: Mutex<()> = Mutex::new(());
let _init = INIT.lock().unwrap();
if !device_raw().is_null() {
return Ok(ADAPTER.lock().map(|a| a.clone()).unwrap_or_default());
}
Expand Down Expand Up @@ -5531,3 +5536,31 @@ mod console_format_query_tests {
}
}
}

#[cfg(test)]
mod init_tests {
use super::*;

#[test]
fn concurrent_init_returns_consistent_adapter() {
let barrier = std::sync::Arc::new(std::sync::Barrier::new(4));
let handles: Vec<_> = (0..4)
.map(|_| {
let b = std::sync::Arc::clone(&barrier);
std::thread::spawn(move || {
b.wait();
init()
})
})
.collect();
let results: Vec<_> = handles.into_iter().map(|h| h.join().unwrap()).collect();
if results.iter().any(|r| r.is_err()) {
crate::gpu::recomp::runner::skip_test("no GPU");
return;
}
let first = results[0].as_ref().unwrap();
for res in &results {
assert_eq!(res.as_ref().unwrap(), first);
}
}
}
Loading