diff --git a/cts_runner/test.lst b/cts_runner/test.lst index cb02b6d13..1b9398be5 100644 --- a/cts_runner/test.lst +++ b/cts_runner/test.lst @@ -11,5 +11,4 @@ webgpu:api,operation,rendering,color_target_state:blending,formats:* webgpu:api,operation,rendering,color_target_state:blend_constant,setting:* webgpu:api,operation,rendering,depth:* webgpu:api,operation,rendering,draw:* -// https://github.com/gfx-rs/wgpu/issues/7391 -//FAIL: webgpu:api,operation,uncapturederror:* +webgpu:api,operation,uncapturederror:* diff --git a/deno_webgpu/buffer.rs b/deno_webgpu/buffer.rs index da0b1a52d..6b9d12483 100644 --- a/deno_webgpu/buffer.rs +++ b/deno_webgpu/buffer.rs @@ -251,9 +251,7 @@ impl GPUBuffer { } #[fast] - fn destroy(&self) -> Result<(), JsErrorBox> { - self.instance - .buffer_destroy(self.id) - .map_err(|e| JsErrorBox::generic(e.to_string())) + fn destroy(&self) { + self.instance.buffer_destroy(self.id); } } diff --git a/deno_webgpu/texture.rs b/deno_webgpu/texture.rs index 4ecaa3220..bb1d026f1 100644 --- a/deno_webgpu/texture.rs +++ b/deno_webgpu/texture.rs @@ -113,10 +113,8 @@ impl GPUTexture { self.usage } #[fast] - fn destroy(&self) -> Result<(), JsErrorBox> { - self.instance - .texture_destroy(self.id) - .map_err(|e| JsErrorBox::generic(e.to_string())) + fn destroy(&self) { + self.instance.texture_destroy(self.id); } #[cppgc] diff --git a/player/src/lib.rs b/player/src/lib.rs index b1934036b..7fbcb25f6 100644 --- a/player/src/lib.rs +++ b/player/src/lib.rs @@ -247,7 +247,7 @@ impl GlobalPlay for wgc::global::Global { } } Action::FreeBuffer(id) => { - self.buffer_destroy(id).unwrap(); + self.buffer_destroy(id); } Action::DestroyBuffer(id) => { self.buffer_drop(id); @@ -259,7 +259,7 @@ impl GlobalPlay for wgc::global::Global { } } Action::FreeTexture(id) => { - self.texture_destroy(id).unwrap(); + self.texture_destroy(id); } Action::DestroyTexture(id) => { self.texture_drop(id); diff --git a/wgpu-core/src/device/global.rs b/wgpu-core/src/device/global.rs index f48574267..35ad371e2 100644 --- a/wgpu-core/src/device/global.rs +++ b/wgpu-core/src/device/global.rs @@ -252,13 +252,16 @@ impl Global { Ok(()) } - pub fn buffer_destroy(&self, buffer_id: id::BufferId) -> Result<(), resource::DestroyError> { + pub fn buffer_destroy(&self, buffer_id: id::BufferId) { profiling::scope!("Buffer::destroy"); api_log!("Buffer::destroy {buffer_id:?}"); let hub = &self.hub; - let buffer = hub.buffers.get(buffer_id).get()?; + let Ok(buffer) = hub.buffers.get(buffer_id).get() else { + // If the buffer is already invalid, there's nothing to do. + return; + }; #[cfg(feature = "trace")] if let Some(trace) = buffer.device.trace.lock().as_mut() { @@ -270,7 +273,7 @@ impl Global { buffer_id, ); - buffer.destroy() + buffer.destroy(); } pub fn buffer_drop(&self, buffer_id: id::BufferId) { @@ -409,20 +412,23 @@ impl Global { (id, err) } - pub fn texture_destroy(&self, texture_id: id::TextureId) -> Result<(), resource::DestroyError> { + pub fn texture_destroy(&self, texture_id: id::TextureId) { profiling::scope!("Texture::destroy"); api_log!("Texture::destroy {texture_id:?}"); let hub = &self.hub; - let texture = hub.textures.get(texture_id).get()?; + let Ok(texture) = hub.textures.get(texture_id).get() else { + // If the texture is already invalid, there's nothing to do. + return; + }; #[cfg(feature = "trace")] if let Some(trace) = texture.device.trace.lock().as_mut() { trace.add(trace::Action::FreeTexture(texture_id)); } - texture.destroy() + texture.destroy(); } pub fn texture_drop(&self, texture_id: id::TextureId) { diff --git a/wgpu-core/src/device/resource.rs b/wgpu-core/src/device/resource.rs index f73bd3956..820c2d411 100644 --- a/wgpu-core/src/device/resource.rs +++ b/wgpu-core/src/device/resource.rs @@ -3914,12 +3914,12 @@ impl Device { let trackers = self.trackers.lock(); for buffer in trackers.buffers.used_resources() { if let Some(buffer) = Weak::upgrade(buffer) { - let _ = buffer.destroy(); + buffer.destroy(); } } for texture in trackers.textures.used_resources() { if let Some(texture) = Weak::upgrade(texture) { - let _ = texture.destroy(); + texture.destroy(); } } } diff --git a/wgpu-core/src/resource.rs b/wgpu-core/src/resource.rs index 30521f8ae..8a3ec4465 100644 --- a/wgpu-core/src/resource.rs +++ b/wgpu-core/src/resource.rs @@ -704,7 +704,7 @@ impl Buffer { Ok(None) } - pub(crate) fn destroy(self: &Arc) -> Result<(), DestroyError> { + pub(crate) fn destroy(self: &Arc) { let device = &self.device; let temp = { @@ -714,7 +714,7 @@ impl Buffer { Some(raw) => raw, None => { // Per spec, it is valid to call `destroy` multiple times. - return Ok(()); + return; } }; @@ -755,8 +755,6 @@ impl Buffer { } } } - - Ok(()) } } @@ -1180,18 +1178,18 @@ impl Texture { } } - pub(crate) fn destroy(self: &Arc) -> Result<(), DestroyError> { + pub(crate) fn destroy(self: &Arc) { let device = &self.device; let temp = { let raw = match self.inner.snatch(&mut device.snatchable_lock.write()) { Some(TextureInner::Native { raw }) => raw, Some(TextureInner::Surface { .. }) => { - return Ok(()); + return; } None => { // Per spec, it is valid to call `destroy` multiple times. - return Ok(()); + return; } }; @@ -1227,8 +1225,6 @@ impl Texture { } } } - - Ok(()) } } @@ -1968,13 +1964,6 @@ impl QuerySet { } } -#[derive(Clone, Debug, Error)] -#[non_exhaustive] -pub enum DestroyError { - #[error(transparent)] - InvalidResource(#[from] InvalidResourceError), -} - pub type BlasDescriptor<'a> = wgt::CreateBlasDescriptor>; pub type TlasDescriptor<'a> = wgt::CreateTlasDescriptor>; diff --git a/wgpu-hal/src/dx12/suballocation.rs b/wgpu-hal/src/dx12/suballocation.rs index e12b798d5..509622d18 100644 --- a/wgpu-hal/src/dx12/suballocation.rs +++ b/wgpu-hal/src/dx12/suballocation.rs @@ -602,8 +602,10 @@ impl<'a> DeviceAllocationContext<'a> { } }; - if info.CurrentUsage + allocation_info.SizeInBytes.max(memblock_size) - >= info.Budget / 100 * threshold as u64 + if info + .CurrentUsage + .checked_add(allocation_info.SizeInBytes.max(memblock_size)) + .is_none_or(|usage| usage >= info.Budget / 100 * threshold as u64) { return Err(crate::DeviceError::OutOfMemory); } diff --git a/wgpu/src/backend/wgpu_core.rs b/wgpu/src/backend/wgpu_core.rs index 2c28df9fb..32eb13752 100644 --- a/wgpu/src/backend/wgpu_core.rs +++ b/wgpu/src/backend/wgpu_core.rs @@ -2056,8 +2056,7 @@ impl dispatch::BufferInterface for CoreBuffer { } fn destroy(&self) { - // Per spec, no error to report. Even calling destroy multiple times is valid. - let _ = self.context.0.buffer_destroy(self.id); + self.context.0.buffer_destroy(self.id); } } @@ -2101,8 +2100,7 @@ impl dispatch::TextureInterface for CoreTexture { } fn destroy(&self) { - // Per spec, no error to report. Even calling destroy multiple times is valid. - let _ = self.context.0.texture_destroy(self.id); + self.context.0.texture_destroy(self.id); } }