Remove another type of error that could be raised by destroy (#7720)

This commit is contained in:
Andy Leiserson 2025-05-24 08:02:00 -07:00 committed by GitHub
parent 44957709ff
commit 24d0eae36c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 32 additions and 42 deletions

View File

@ -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,color_target_state:blend_constant,setting:*
webgpu:api,operation,rendering,depth:* webgpu:api,operation,rendering,depth:*
webgpu:api,operation,rendering,draw:* webgpu:api,operation,rendering,draw:*
// https://github.com/gfx-rs/wgpu/issues/7391 webgpu:api,operation,uncapturederror:*
//FAIL: webgpu:api,operation,uncapturederror:*

View File

@ -251,9 +251,7 @@ impl GPUBuffer {
} }
#[fast] #[fast]
fn destroy(&self) -> Result<(), JsErrorBox> { fn destroy(&self) {
self.instance self.instance.buffer_destroy(self.id);
.buffer_destroy(self.id)
.map_err(|e| JsErrorBox::generic(e.to_string()))
} }
} }

View File

@ -113,10 +113,8 @@ impl GPUTexture {
self.usage self.usage
} }
#[fast] #[fast]
fn destroy(&self) -> Result<(), JsErrorBox> { fn destroy(&self) {
self.instance self.instance.texture_destroy(self.id);
.texture_destroy(self.id)
.map_err(|e| JsErrorBox::generic(e.to_string()))
} }
#[cppgc] #[cppgc]

View File

@ -247,7 +247,7 @@ impl GlobalPlay for wgc::global::Global {
} }
} }
Action::FreeBuffer(id) => { Action::FreeBuffer(id) => {
self.buffer_destroy(id).unwrap(); self.buffer_destroy(id);
} }
Action::DestroyBuffer(id) => { Action::DestroyBuffer(id) => {
self.buffer_drop(id); self.buffer_drop(id);
@ -259,7 +259,7 @@ impl GlobalPlay for wgc::global::Global {
} }
} }
Action::FreeTexture(id) => { Action::FreeTexture(id) => {
self.texture_destroy(id).unwrap(); self.texture_destroy(id);
} }
Action::DestroyTexture(id) => { Action::DestroyTexture(id) => {
self.texture_drop(id); self.texture_drop(id);

View File

@ -252,13 +252,16 @@ impl Global {
Ok(()) 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"); profiling::scope!("Buffer::destroy");
api_log!("Buffer::destroy {buffer_id:?}"); api_log!("Buffer::destroy {buffer_id:?}");
let hub = &self.hub; 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")] #[cfg(feature = "trace")]
if let Some(trace) = buffer.device.trace.lock().as_mut() { if let Some(trace) = buffer.device.trace.lock().as_mut() {
@ -270,7 +273,7 @@ impl Global {
buffer_id, buffer_id,
); );
buffer.destroy() buffer.destroy();
} }
pub fn buffer_drop(&self, buffer_id: id::BufferId) { pub fn buffer_drop(&self, buffer_id: id::BufferId) {
@ -409,20 +412,23 @@ impl Global {
(id, err) (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"); profiling::scope!("Texture::destroy");
api_log!("Texture::destroy {texture_id:?}"); api_log!("Texture::destroy {texture_id:?}");
let hub = &self.hub; 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")] #[cfg(feature = "trace")]
if let Some(trace) = texture.device.trace.lock().as_mut() { if let Some(trace) = texture.device.trace.lock().as_mut() {
trace.add(trace::Action::FreeTexture(texture_id)); trace.add(trace::Action::FreeTexture(texture_id));
} }
texture.destroy() texture.destroy();
} }
pub fn texture_drop(&self, texture_id: id::TextureId) { pub fn texture_drop(&self, texture_id: id::TextureId) {

View File

@ -3914,12 +3914,12 @@ impl Device {
let trackers = self.trackers.lock(); let trackers = self.trackers.lock();
for buffer in trackers.buffers.used_resources() { for buffer in trackers.buffers.used_resources() {
if let Some(buffer) = Weak::upgrade(buffer) { if let Some(buffer) = Weak::upgrade(buffer) {
let _ = buffer.destroy(); buffer.destroy();
} }
} }
for texture in trackers.textures.used_resources() { for texture in trackers.textures.used_resources() {
if let Some(texture) = Weak::upgrade(texture) { if let Some(texture) = Weak::upgrade(texture) {
let _ = texture.destroy(); texture.destroy();
} }
} }
} }

View File

@ -704,7 +704,7 @@ impl Buffer {
Ok(None) Ok(None)
} }
pub(crate) fn destroy(self: &Arc<Self>) -> Result<(), DestroyError> { pub(crate) fn destroy(self: &Arc<Self>) {
let device = &self.device; let device = &self.device;
let temp = { let temp = {
@ -714,7 +714,7 @@ impl Buffer {
Some(raw) => raw, Some(raw) => raw,
None => { None => {
// Per spec, it is valid to call `destroy` multiple times. // 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<Self>) -> Result<(), DestroyError> { pub(crate) fn destroy(self: &Arc<Self>) {
let device = &self.device; let device = &self.device;
let temp = { let temp = {
let raw = match self.inner.snatch(&mut device.snatchable_lock.write()) { let raw = match self.inner.snatch(&mut device.snatchable_lock.write()) {
Some(TextureInner::Native { raw }) => raw, Some(TextureInner::Native { raw }) => raw,
Some(TextureInner::Surface { .. }) => { Some(TextureInner::Surface { .. }) => {
return Ok(()); return;
} }
None => { None => {
// Per spec, it is valid to call `destroy` multiple times. // 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<Label<'a>>; pub type BlasDescriptor<'a> = wgt::CreateBlasDescriptor<Label<'a>>;
pub type TlasDescriptor<'a> = wgt::CreateTlasDescriptor<Label<'a>>; pub type TlasDescriptor<'a> = wgt::CreateTlasDescriptor<Label<'a>>;

View File

@ -602,8 +602,10 @@ impl<'a> DeviceAllocationContext<'a> {
} }
}; };
if info.CurrentUsage + allocation_info.SizeInBytes.max(memblock_size) if info
>= info.Budget / 100 * threshold as u64 .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); return Err(crate::DeviceError::OutOfMemory);
} }

View File

@ -2056,8 +2056,7 @@ impl dispatch::BufferInterface for CoreBuffer {
} }
fn destroy(&self) { fn destroy(&self) {
// Per spec, no error to report. Even calling destroy multiple times is valid. self.context.0.buffer_destroy(self.id);
let _ = self.context.0.buffer_destroy(self.id);
} }
} }
@ -2101,8 +2100,7 @@ impl dispatch::TextureInterface for CoreTexture {
} }
fn destroy(&self) { fn destroy(&self) {
// Per spec, no error to report. Even calling destroy multiple times is valid. self.context.0.texture_destroy(self.id);
let _ = self.context.0.texture_destroy(self.id);
} }
} }