Skip to content

Commit e4c5b47

Browse files
committed
introduce a new function that handles unexpected vulkan errors that can't be mapped to DeviceError::Lost
1 parent 8b6450a commit e4c5b47

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

wgpu-hal/src/vulkan/device.rs

+15-11
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ impl gpu_alloc::MemoryDevice<vk::DeviceMemory> for super::DeviceShared {
322322
Err(vk::Result::ERROR_OUT_OF_HOST_MEMORY) => {
323323
Err(gpu_alloc::OutOfMemory::OutOfHostMemory)
324324
}
325-
Err(err) => panic!("Unexpected Vulkan error: `{err}`"),
325+
Err(err) => handle_unexpected(err),
326326
}
327327
}
328328

@@ -351,7 +351,7 @@ impl gpu_alloc::MemoryDevice<vk::DeviceMemory> for super::DeviceShared {
351351
Err(gpu_alloc::DeviceMapError::OutOfHostMemory)
352352
}
353353
Err(vk::Result::ERROR_MEMORY_MAP_FAILED) => Err(gpu_alloc::DeviceMapError::MapFailed),
354-
Err(err) => panic!("Unexpected Vulkan error: `{err}`"),
354+
Err(err) => handle_unexpected(err),
355355
}
356356
}
357357

@@ -450,10 +450,7 @@ impl
450450
Err(vk::Result::ERROR_FRAGMENTATION) => {
451451
Err(gpu_descriptor::CreatePoolError::Fragmentation)
452452
}
453-
Err(other) => {
454-
log::error!("create_descriptor_pool: {:?}", other);
455-
Err(gpu_descriptor::CreatePoolError::OutOfHostMemory)
456-
}
453+
Err(err) => handle_unexpected(err),
457454
}
458455
}
459456

@@ -494,10 +491,7 @@ impl
494491
Err(vk::Result::ERROR_FRAGMENTED_POOL) => {
495492
Err(gpu_descriptor::DeviceAllocationError::FragmentedPool)
496493
}
497-
Err(other) => {
498-
log::error!("allocate_descriptor_sets: {:?}", other);
499-
Err(gpu_descriptor::DeviceAllocationError::OutOfHostMemory)
500-
}
494+
Err(err) => handle_unexpected(err),
501495
}
502496
}
503497

@@ -514,7 +508,7 @@ impl
514508
};
515509
match result {
516510
Ok(()) => {}
517-
Err(err) => log::error!("free_descriptor_sets: {:?}", err),
511+
Err(err) => handle_unexpected(err),
518512
}
519513
}
520514
}
@@ -2502,3 +2496,13 @@ impl From<gpu_descriptor::AllocationError> for crate::DeviceError {
25022496
}
25032497
}
25042498
}
2499+
2500+
/// We usually map unexpected vulkan errors to the [`crate::DeviceError::Lost`]
2501+
/// variant to be more robust even in cases where the driver is not
2502+
/// complying with the spec.
2503+
///
2504+
/// However, we implement a few Trait methods that don't have an equivalent
2505+
/// error variant. In those cases we use this function.
2506+
fn handle_unexpected(err: vk::Result) -> ! {
2507+
panic!("Unexpected Vulkan error: `{err}`")
2508+
}

0 commit comments

Comments
 (0)