gfx-rs/wgpu · critical

Device lost

Error message

Device lost

What it means

When the Vulkan logical device is lost (e.g. the GPU reset, driver crash, or device was destroyed), wgpu-hal returns `DeviceError::Lost`. With the `device_lost_panic` feature flag enabled, this helper panics with "Device lost" instead, so that lost devices fail loudly in testing. Normally callers get a recoverable `DeviceError::Lost` that they must handle by recreating the device.

Source

Thrown at wgpu-hal/src/vulkan/mod.rs:1854

/// feature flag is enabled.
fn get_unexpected_err(_err: vk::Result) -> crate::DeviceError {
    #[cfg(feature = "internal_error_panic")]
    panic!("Unexpected Vulkan error: {_err:?}");

    #[allow(unreachable_code)]
    crate::DeviceError::Unexpected
}

/// Returns [`crate::DeviceError::OutOfMemory`].
fn get_oom_err(_err: vk::Result) -> crate::DeviceError {
    crate::DeviceError::OutOfMemory
}

/// Returns [`crate::DeviceError::Lost`] or panics if the `device_lost_panic`
/// feature flag is enabled.
fn get_lost_err() -> crate::DeviceError {
    #[cfg(feature = "device_lost_panic")]
    panic!("Device lost");

    #[allow(unreachable_code)]
    crate::DeviceError::Lost
}

#[derive(Clone, Copy, Pod, Zeroable)]
#[repr(C)]
struct RawTlasInstance {
    transform: [f32; 12],
    custom_data_and_mask: u32,
    shader_binding_table_record_offset_and_flags: u32,
    acceleration_structure_reference: u64,
}

/// Arguments to the [`CreateDeviceCallback`].
#[derive(Debug)]
pub struct CreateDeviceCallbackArgs<'arg, 'pnext, 'this>
where

View on GitHub (pinned to 3e11ff59bf)

Solutions

  1. Handle `DeviceError::Lost` in the application: drop the device and recreate device + all dependent resources.
  2. Investigate root cause: shorten long-running shaders/launches to avoid TDR, update drivers, check thermals.
  3. Rebuild without the `device_lost_panic` feature to get the recoverable error instead of a panic.
  4. Check that a previous submit didn't trigger a validation/robustness violation leading to device removal.

Example fix

// before
queue.submit(Some(encoder.finish()));
// after
if let Err(wgpu::DeviceError::Lost) = queue.submit(Some(encoder.finish())).map_err(|e| *e) {
    // drop and recreate the device and all resources
}
Defensive patterns

Strategy: retry

Type guard

fn is_device_lost(res: &Result<(), wgpu::Error>) -> bool {
    matches!(res.as_ref().err().map(|e| e.inner()), Some(wgpu::DeviceError::Lost))
}

Try / catch

// Do not retry on DeviceError::Lost with the same device; rebuild first.
match queue.submit(Some(encoder.finish())) {
    Ok(()) => {}
    Err(e) if matches!(*e, wgpu::DeviceError::Lost) => {
        drop(device); // release all resources
        let (device, queue) = adapter.request_device(&desc, None)?;
        rebuild_all_resources(&device);
    }
    Err(e) => return Err(e.into()),
}

Prevention

When it happens

Trigger: Any Vulkan call returning VK_ERROR_DEVICE_LOST and routed through `get_lost_err` at wgpu-hal/src/vulkan/mod.rs:1854, e.g. during queue submit, present, or map operations.

Common situations: GPU timeouts (TDR) on Windows from long shaders; driver crashes; overheating/overclocked hardware; virtualized or remote GPU environments; tests built with device_lost_panic.

Related errors


AI-assisted analysis of gfx-rs/wgpu@3e11ff59bf (2026-09-03). Data as JSON: /api/errors/322e7be7079f8e0f. Report an issue: GitHub.