introduce a new function for hal usage errors

This commit is contained in:
teoxoy
2024-08-15 09:58:31 +01:00
committed by Teodor Tanasoaia
parent a0c107f7c8
commit 7103520bd3
2 changed files with 15 additions and 14 deletions

View File

@@ -948,13 +948,14 @@ impl crate::Device for super::Device {
.contains(gpu_alloc::MemoryPropertyFlags::HOST_COHERENT);
Ok(crate::BufferMapping { ptr, is_coherent })
} else {
Err(crate::DeviceError::OutOfMemory)
super::hal_usage_error("tried to map external buffer")
}
}
unsafe fn unmap_buffer(&self, buffer: &super::Buffer) {
// We can only unmap the buffer if it was already mapped successfully.
if let Some(ref block) = buffer.block {
unsafe { block.lock().unmap(&*self.shared) };
} else {
super::hal_usage_error("tried to unmap external buffer")
}
}
@@ -2463,8 +2464,10 @@ impl super::DeviceShared {
}
}
None => {
log::error!("No signals reached value {}", wait_value);
Err(crate::DeviceError::Lost)
super::hal_usage_error(format!(
"no signals reached value {}",
wait_value
));
}
}
}
@@ -2477,11 +2480,8 @@ impl From<gpu_alloc::AllocationError> for crate::DeviceError {
fn from(error: gpu_alloc::AllocationError) -> Self {
use gpu_alloc::AllocationError as Ae;
match error {
Ae::OutOfDeviceMemory | Ae::OutOfHostMemory => Self::OutOfMemory,
_ => {
log::error!("memory allocation: {:?}", error);
Self::Lost
}
Ae::OutOfDeviceMemory | Ae::OutOfHostMemory | Ae::TooManyObjects => Self::OutOfMemory,
Ae::NoCompatibleMemoryTypes => super::hal_usage_error(error),
}
}
}
@@ -2489,11 +2489,8 @@ impl From<gpu_alloc::MapError> for crate::DeviceError {
fn from(error: gpu_alloc::MapError) -> Self {
use gpu_alloc::MapError as Me;
match error {
Me::OutOfDeviceMemory | Me::OutOfHostMemory => Self::OutOfMemory,
_ => {
log::error!("memory mapping: {:?}", error);
Self::Lost
}
Me::OutOfDeviceMemory | Me::OutOfHostMemory | Me::MapFailed => Self::OutOfMemory,
Me::NonHostVisible | Me::AlreadyMapped => super::hal_usage_error(error),
}
}
}

View File

@@ -1199,3 +1199,7 @@ impl From<vk::Result> for crate::DeviceError {
}
}
}
fn hal_usage_error<T: fmt::Display>(txt: T) -> ! {
panic!("wgpu-hal invariant was violated (usage error): {txt}")
}