From 29e288f81cee26857cd615cab8cf53e0118d9100 Mon Sep 17 00:00:00 2001 From: teoxoy <28601907+teoxoy@users.noreply.github.com> Date: Wed, 21 Aug 2024 13:13:44 +0200 Subject: [PATCH] move `hal_usage_error` from the vk backend to lib.rs --- wgpu-hal/src/lib.rs | 6 ++++++ wgpu-hal/src/vulkan/adapter.rs | 2 +- wgpu-hal/src/vulkan/device.rs | 10 +++++----- wgpu-hal/src/vulkan/mod.rs | 5 ----- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/wgpu-hal/src/lib.rs b/wgpu-hal/src/lib.rs index 20ce8150c..60b3a67bb 100644 --- a/wgpu-hal/src/lib.rs +++ b/wgpu-hal/src/lib.rs @@ -345,6 +345,12 @@ pub enum DeviceError { Unexpected, } +#[allow(dead_code)] // may be unused on some platforms +#[cold] +fn hal_usage_error(txt: T) -> ! { + panic!("wgpu-hal invariant was violated (usage error): {txt}") +} + #[derive(Clone, Debug, Eq, PartialEq, Error)] pub enum ShaderError { #[error("Compilation failed: {0:?}")] diff --git a/wgpu-hal/src/vulkan/adapter.rs b/wgpu-hal/src/vulkan/adapter.rs index 25d0d7504..d699e9859 100644 --- a/wgpu-hal/src/vulkan/adapter.rs +++ b/wgpu-hal/src/vulkan/adapter.rs @@ -2010,7 +2010,7 @@ impl crate::Adapter for super::Adapter { vk::Result::ERROR_TOO_MANY_OBJECTS => crate::DeviceError::OutOfMemory, vk::Result::ERROR_INITIALIZATION_FAILED => crate::DeviceError::Lost, vk::Result::ERROR_EXTENSION_NOT_PRESENT | vk::Result::ERROR_FEATURE_NOT_PRESENT => { - super::hal_usage_error(err) + crate::hal_usage_error(err) } other => super::map_host_device_oom_and_lost_err(other), } diff --git a/wgpu-hal/src/vulkan/device.rs b/wgpu-hal/src/vulkan/device.rs index 4283f844a..f21a24364 100644 --- a/wgpu-hal/src/vulkan/device.rs +++ b/wgpu-hal/src/vulkan/device.rs @@ -970,14 +970,14 @@ impl crate::Device for super::Device { .contains(gpu_alloc::MemoryPropertyFlags::HOST_COHERENT); Ok(crate::BufferMapping { ptr, is_coherent }) } else { - super::hal_usage_error("tried to map external buffer") + crate::hal_usage_error("tried to map external buffer") } } unsafe fn unmap_buffer(&self, buffer: &super::Buffer) { if let Some(ref block) = buffer.block { unsafe { block.lock().unmap(&*self.shared) }; } else { - super::hal_usage_error("tried to unmap external buffer") + crate::hal_usage_error("tried to unmap external buffer") } } @@ -2520,7 +2520,7 @@ impl super::DeviceShared { } } None => { - super::hal_usage_error(format!( + crate::hal_usage_error(format!( "no signals reached value {}", wait_value )); @@ -2537,7 +2537,7 @@ impl From for crate::DeviceError { use gpu_alloc::AllocationError as Ae; match error { Ae::OutOfDeviceMemory | Ae::OutOfHostMemory | Ae::TooManyObjects => Self::OutOfMemory, - Ae::NoCompatibleMemoryTypes => super::hal_usage_error(error), + Ae::NoCompatibleMemoryTypes => crate::hal_usage_error(error), } } } @@ -2546,7 +2546,7 @@ impl From for crate::DeviceError { use gpu_alloc::MapError as Me; match error { Me::OutOfDeviceMemory | Me::OutOfHostMemory | Me::MapFailed => Self::OutOfMemory, - Me::NonHostVisible | Me::AlreadyMapped => super::hal_usage_error(error), + Me::NonHostVisible | Me::AlreadyMapped => crate::hal_usage_error(error), } } } diff --git a/wgpu-hal/src/vulkan/mod.rs b/wgpu-hal/src/vulkan/mod.rs index 0ee90c459..338579ef5 100644 --- a/wgpu-hal/src/vulkan/mod.rs +++ b/wgpu-hal/src/vulkan/mod.rs @@ -1360,8 +1360,3 @@ fn get_lost_err() -> crate::DeviceError { #[allow(unreachable_code)] crate::DeviceError::Lost } - -#[cold] -fn hal_usage_error(txt: T) -> ! { - panic!("wgpu-hal invariant was violated (usage error): {txt}") -}