Files
photocraft/crates/gpu/tests/it/main.rs
FredApps 8543937a76 fix(gpu): wait for a timed-out GPU request before the process exits
`NativeContext::request` gives up after its timeout (10 s by default) but
leaves its `pc_gpu_init` thread inside wgpu and the driver. When the
process then exits, the driver is torn down under that thread, and
Lavapipe crashes the process: on a loaded CI runner two headless GPU
tests took the "no GPU adapter available" path, printed ok, and then
died with SIGSEGV ("error: scalar-to-vector conversion failed" from
LLVM) as the test process exited (#9824's Ubuntu gate).

Count the initialization threads a request gave up on, and add
`NativeContext::wait_for_abandoned_requests(limit)` to wait for them.
A `GpuRenderer` whose request failed now waits (at least 30 s, bounded)
for its abandoned request when it is dropped, so the process no longer
exits under it.

Signed-off-by: FredApps <[email protected]>
2026-11-18 15:25:11 +07:00

44 lines
1.6 KiB
Rust

//! The crate's integration tests, linked into one test binary.
/// Concurrent wgpu instances in one process segfault on some drivers (RADV), so every test that
/// creates a device takes this lock and holds it until the device is dropped.
static GPU_LOCK: std::sync::Mutex<()> = std::sync::Mutex::new(());
/// The wgpu instance every test uses (`WGPU_BACKEND` picks its backends), kept for the whole
/// run: the last instance going away tears the Vulkan loader down, and an instance made while
/// that happens can crash in libvulkan.
pub(crate) fn instance() -> wgpu::Instance {
static KEPT: std::sync::OnceLock<wgpu::Instance> = std::sync::OnceLock::new();
KEPT.get_or_init(|| {
INSTANCES_MADE.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
wgpu::Instance::new(wgpu::InstanceDescriptor::new_without_display_handle_from_env())
})
.clone()
}
/// How many instances [`instance`] has made: one for the whole run.
static INSTANCES_MADE: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
/// [`instance`] makes its instance once, however many tests and threads ask for it: a fresh one
/// per test could crash in libvulkan while another goes away.
#[test]
fn the_instance_is_made_once() {
let threads: Vec<_> = (0..4).map(|_| std::thread::spawn(|| drop(instance()))).collect();
for t in threads {
assert!(t.join().is_ok());
}
drop(instance());
assert_eq!(INSTANCES_MADE.load(std::sync::atomic::Ordering::SeqCst), 1);
}
mod bounded_readback;
mod camera_raw;
mod device_loss;
mod init_timeout;
mod parity;
mod pipeline_errors;
mod pipelines;
mod timing;
mod uniform_limits;
mod vector_mask;