mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-22 06:44:14 +00:00
Add feature flags in hal to panic when running into some types of errors (#5273)
This commit is contained in:
parent
75a98f2712
commit
66c7e98ad7
@ -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"
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user