Skip to content

Commit 29e288f

Browse files
committed
move hal_usage_error from the vk backend to lib.rs
1 parent e25051e commit 29e288f

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

wgpu-hal/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,12 @@ pub enum DeviceError {
345345
Unexpected,
346346
}
347347

348+
#[allow(dead_code)] // may be unused on some platforms
349+
#[cold]
350+
fn hal_usage_error<T: fmt::Display>(txt: T) -> ! {
351+
panic!("wgpu-hal invariant was violated (usage error): {txt}")
352+
}
353+
348354
#[derive(Clone, Debug, Eq, PartialEq, Error)]
349355
pub enum ShaderError {
350356
#[error("Compilation failed: {0:?}")]

wgpu-hal/src/vulkan/adapter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2010,7 +2010,7 @@ impl crate::Adapter for super::Adapter {
20102010
vk::Result::ERROR_TOO_MANY_OBJECTS => crate::DeviceError::OutOfMemory,
20112011
vk::Result::ERROR_INITIALIZATION_FAILED => crate::DeviceError::Lost,
20122012
vk::Result::ERROR_EXTENSION_NOT_PRESENT | vk::Result::ERROR_FEATURE_NOT_PRESENT => {
2013-
super::hal_usage_error(err)
2013+
crate::hal_usage_error(err)
20142014
}
20152015
other => super::map_host_device_oom_and_lost_err(other),
20162016
}

wgpu-hal/src/vulkan/device.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -970,14 +970,14 @@ impl crate::Device for super::Device {
970970
.contains(gpu_alloc::MemoryPropertyFlags::HOST_COHERENT);
971971
Ok(crate::BufferMapping { ptr, is_coherent })
972972
} else {
973-
super::hal_usage_error("tried to map external buffer")
973+
crate::hal_usage_error("tried to map external buffer")
974974
}
975975
}
976976
unsafe fn unmap_buffer(&self, buffer: &super::Buffer) {
977977
if let Some(ref block) = buffer.block {
978978
unsafe { block.lock().unmap(&*self.shared) };
979979
} else {
980-
super::hal_usage_error("tried to unmap external buffer")
980+
crate::hal_usage_error("tried to unmap external buffer")
981981
}
982982
}
983983

@@ -2520,7 +2520,7 @@ impl super::DeviceShared {
25202520
}
25212521
}
25222522
None => {
2523-
super::hal_usage_error(format!(
2523+
crate::hal_usage_error(format!(
25242524
"no signals reached value {}",
25252525
wait_value
25262526
));
@@ -2537,7 +2537,7 @@ impl From<gpu_alloc::AllocationError> for crate::DeviceError {
25372537
use gpu_alloc::AllocationError as Ae;
25382538
match error {
25392539
Ae::OutOfDeviceMemory | Ae::OutOfHostMemory | Ae::TooManyObjects => Self::OutOfMemory,
2540-
Ae::NoCompatibleMemoryTypes => super::hal_usage_error(error),
2540+
Ae::NoCompatibleMemoryTypes => crate::hal_usage_error(error),
25412541
}
25422542
}
25432543
}
@@ -2546,7 +2546,7 @@ impl From<gpu_alloc::MapError> for crate::DeviceError {
25462546
use gpu_alloc::MapError as Me;
25472547
match error {
25482548
Me::OutOfDeviceMemory | Me::OutOfHostMemory | Me::MapFailed => Self::OutOfMemory,
2549-
Me::NonHostVisible | Me::AlreadyMapped => super::hal_usage_error(error),
2549+
Me::NonHostVisible | Me::AlreadyMapped => crate::hal_usage_error(error),
25502550
}
25512551
}
25522552
}

wgpu-hal/src/vulkan/mod.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,8 +1360,3 @@ fn get_lost_err() -> crate::DeviceError {
13601360
#[allow(unreachable_code)]
13611361
crate::DeviceError::Lost
13621362
}
1363-
1364-
#[cold]
1365-
fn hal_usage_error<T: fmt::Display>(txt: T) -> ! {
1366-
panic!("wgpu-hal invariant was violated (usage error): {txt}")
1367-
}

0 commit comments

Comments
 (0)