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

View File

@ -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);
}
}

View File

@ -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]

View File

@ -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);

View File

@ -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) {

View File

@ -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();
}
}
}

View File

@ -704,7 +704,7 @@ impl Buffer {
Ok(None)
}
pub(crate) fn destroy(self: &Arc<Self>) -> Result<(), DestroyError> {
pub(crate) fn destroy(self: &Arc<Self>) {
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<Self>) -> Result<(), DestroyError> {
pub(crate) fn destroy(self: &Arc<Self>) {
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<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)
>= 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);
}

View File

@ -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);
}
}