Add feature flags in hal to panic when running into some types of errors (#5273)

This commit is contained in:
Nicolas Silva 2024-02-21 08:35:24 -08:00 committed by GitHub
parent 75a98f2712
commit 66c7e98ad7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 44 additions and 2 deletions

View File

@ -63,6 +63,18 @@ dxc_shader_compiler = ["hassle-rs"]
renderdoc = ["libloading", "renderdoc-sys"]
fragile-send-sync-non-atomic-wasm = ["wgt/fragile-send-sync-non-atomic-wasm"]
link = ["metal/link"]
# Panic when running into an out-of-memory error (for debugging purposes).
#
# Only affects the d3d12 and vulkan backends.
oom_panic = []
# Panic when running into a device lost error (for debugging purposes).
# Only affects the d3d12 and vulkan backends.
device_lost_panic = []
# Panic when running into an internal error other than out-of-memory and device lost
# (for debugging purposes).
#
# Only affects the d3d12 and vulkan backends.
internal_error_panic = []
[[example]]
name = "halmark"

View File

@ -21,8 +21,26 @@ impl HResult<()> for i32 {
Err(Cow::Borrowed(description))
}
fn into_device_result(self, description: &str) -> Result<(), crate::DeviceError> {
#![allow(unreachable_code)]
self.into_result().map_err(|err| {
log::error!("{} failed: {}", description, err);
match self {
winerror::E_OUTOFMEMORY => {
#[cfg(feature = "oom_panic")]
panic!("{description} failed: Out of memory");
}
winerror::DXGI_ERROR_DEVICE_RESET | winerror::DXGI_ERROR_DEVICE_REMOVED => {
#[cfg(feature = "device_lost_panic")]
panic!("{description} failed: Device lost ({err})");
}
_ => {
#[cfg(feature = "internal_error_panic")]
panic!("{description} failed: {err}");
}
}
if self == winerror::E_OUTOFMEMORY {
crate::DeviceError::OutOfMemory
} else {

View File

@ -724,13 +724,25 @@ impl crate::Queue<Api> for Queue {
impl From<vk::Result> for crate::DeviceError {
fn from(result: vk::Result) -> Self {
#![allow(unreachable_code)]
match result {
vk::Result::ERROR_OUT_OF_HOST_MEMORY | vk::Result::ERROR_OUT_OF_DEVICE_MEMORY => {
#[cfg(feature = "oom_panic")]
panic!("Out of memory ({result:?})");
Self::OutOfMemory
}
vk::Result::ERROR_DEVICE_LOST => Self::Lost,
vk::Result::ERROR_DEVICE_LOST => {
#[cfg(feature = "device_lost_panic")]
panic!("Device lost");
Self::Lost
}
_ => {
log::warn!("Unrecognized device error {:?}", result);
#[cfg(feature = "internal_error_panic")]
panic!("Internal error: {result:?}");
log::warn!("Unrecognized device error {result:?}");
Self::Lost
}
}