From ad4286102adceac5e26c4cccc4fece8d5cb7c67b Mon Sep 17 00:00:00 2001 From: Jamie Nicol Date: Tue, 17 Jun 2025 11:58:53 +0100 Subject: [PATCH] [dx12] Return OOM error when GetResourceAllocationInfo() returns SizeInBytes == 0 Some versions of WARP return an allocation info with SizeInBytes == 0 for very large allocations. Proceeding to attempt to allocate a zero- sized resource results in a device lost error. It's preferable to instead return an out of memory error. --- wgpu-hal/src/dx12/suballocation.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/wgpu-hal/src/dx12/suballocation.rs b/wgpu-hal/src/dx12/suballocation.rs index 509622d18..8547f1300 100644 --- a/wgpu-hal/src/dx12/suballocation.rs +++ b/wgpu-hal/src/dx12/suballocation.rs @@ -566,6 +566,14 @@ impl<'a> DeviceAllocationContext<'a> { .GetResourceAllocationInfo(0, core::slice::from_ref(desc)) }; + // Some versions of WARP return SizeInBytes == 0 for very large + // allocations. Proceeding to attempt to allocate a zero-sized resource + // will result in a device lost error, so it seems preferable to return + // an out of memory error now. + if allocation_info.SizeInBytes == 0 { + return Err(crate::DeviceError::OutOfMemory); + } + let Some(threshold) = self .mem_allocator .memory_budget_thresholds