Skip to content

Commit 24d0eae

Browse files
Remove another type of error that could be raised by destroy (#7720)
1 parent 4495770 commit 24d0eae

File tree

9 files changed

+32
-42
lines changed

9 files changed

+32
-42
lines changed

cts_runner/test.lst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,4 @@ webgpu:api,operation,rendering,color_target_state:blending,formats:*
1111
webgpu:api,operation,rendering,color_target_state:blend_constant,setting:*
1212
webgpu:api,operation,rendering,depth:*
1313
webgpu:api,operation,rendering,draw:*
14-
// https://github.com/gfx-rs/wgpu/issues/7391
15-
//FAIL: webgpu:api,operation,uncapturederror:*
14+
webgpu:api,operation,uncapturederror:*

deno_webgpu/buffer.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,7 @@ impl GPUBuffer {
251251
}
252252

253253
#[fast]
254-
fn destroy(&self) -> Result<(), JsErrorBox> {
255-
self.instance
256-
.buffer_destroy(self.id)
257-
.map_err(|e| JsErrorBox::generic(e.to_string()))
254+
fn destroy(&self) {
255+
self.instance.buffer_destroy(self.id);
258256
}
259257
}

deno_webgpu/texture.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,8 @@ impl GPUTexture {
113113
self.usage
114114
}
115115
#[fast]
116-
fn destroy(&self) -> Result<(), JsErrorBox> {
117-
self.instance
118-
.texture_destroy(self.id)
119-
.map_err(|e| JsErrorBox::generic(e.to_string()))
116+
fn destroy(&self) {
117+
self.instance.texture_destroy(self.id);
120118
}
121119

122120
#[cppgc]

player/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ impl GlobalPlay for wgc::global::Global {
247247
}
248248
}
249249
Action::FreeBuffer(id) => {
250-
self.buffer_destroy(id).unwrap();
250+
self.buffer_destroy(id);
251251
}
252252
Action::DestroyBuffer(id) => {
253253
self.buffer_drop(id);
@@ -259,7 +259,7 @@ impl GlobalPlay for wgc::global::Global {
259259
}
260260
}
261261
Action::FreeTexture(id) => {
262-
self.texture_destroy(id).unwrap();
262+
self.texture_destroy(id);
263263
}
264264
Action::DestroyTexture(id) => {
265265
self.texture_drop(id);

wgpu-core/src/device/global.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,16 @@ impl Global {
252252
Ok(())
253253
}
254254

255-
pub fn buffer_destroy(&self, buffer_id: id::BufferId) -> Result<(), resource::DestroyError> {
255+
pub fn buffer_destroy(&self, buffer_id: id::BufferId) {
256256
profiling::scope!("Buffer::destroy");
257257
api_log!("Buffer::destroy {buffer_id:?}");
258258

259259
let hub = &self.hub;
260260

261-
let buffer = hub.buffers.get(buffer_id).get()?;
261+
let Ok(buffer) = hub.buffers.get(buffer_id).get() else {
262+
// If the buffer is already invalid, there's nothing to do.
263+
return;
264+
};
262265

263266
#[cfg(feature = "trace")]
264267
if let Some(trace) = buffer.device.trace.lock().as_mut() {
@@ -270,7 +273,7 @@ impl Global {
270273
buffer_id,
271274
);
272275

273-
buffer.destroy()
276+
buffer.destroy();
274277
}
275278

276279
pub fn buffer_drop(&self, buffer_id: id::BufferId) {
@@ -409,20 +412,23 @@ impl Global {
409412
(id, err)
410413
}
411414

412-
pub fn texture_destroy(&self, texture_id: id::TextureId) -> Result<(), resource::DestroyError> {
415+
pub fn texture_destroy(&self, texture_id: id::TextureId) {
413416
profiling::scope!("Texture::destroy");
414417
api_log!("Texture::destroy {texture_id:?}");
415418

416419
let hub = &self.hub;
417420

418-
let texture = hub.textures.get(texture_id).get()?;
421+
let Ok(texture) = hub.textures.get(texture_id).get() else {
422+
// If the texture is already invalid, there's nothing to do.
423+
return;
424+
};
419425

420426
#[cfg(feature = "trace")]
421427
if let Some(trace) = texture.device.trace.lock().as_mut() {
422428
trace.add(trace::Action::FreeTexture(texture_id));
423429
}
424430

425-
texture.destroy()
431+
texture.destroy();
426432
}
427433

428434
pub fn texture_drop(&self, texture_id: id::TextureId) {

wgpu-core/src/device/resource.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3914,12 +3914,12 @@ impl Device {
39143914
let trackers = self.trackers.lock();
39153915
for buffer in trackers.buffers.used_resources() {
39163916
if let Some(buffer) = Weak::upgrade(buffer) {
3917-
let _ = buffer.destroy();
3917+
buffer.destroy();
39183918
}
39193919
}
39203920
for texture in trackers.textures.used_resources() {
39213921
if let Some(texture) = Weak::upgrade(texture) {
3922-
let _ = texture.destroy();
3922+
texture.destroy();
39233923
}
39243924
}
39253925
}

wgpu-core/src/resource.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ impl Buffer {
704704
Ok(None)
705705
}
706706

707-
pub(crate) fn destroy(self: &Arc<Self>) -> Result<(), DestroyError> {
707+
pub(crate) fn destroy(self: &Arc<Self>) {
708708
let device = &self.device;
709709

710710
let temp = {
@@ -714,7 +714,7 @@ impl Buffer {
714714
Some(raw) => raw,
715715
None => {
716716
// Per spec, it is valid to call `destroy` multiple times.
717-
return Ok(());
717+
return;
718718
}
719719
};
720720

@@ -755,8 +755,6 @@ impl Buffer {
755755
}
756756
}
757757
}
758-
759-
Ok(())
760758
}
761759
}
762760

@@ -1180,18 +1178,18 @@ impl Texture {
11801178
}
11811179
}
11821180

1183-
pub(crate) fn destroy(self: &Arc<Self>) -> Result<(), DestroyError> {
1181+
pub(crate) fn destroy(self: &Arc<Self>) {
11841182
let device = &self.device;
11851183

11861184
let temp = {
11871185
let raw = match self.inner.snatch(&mut device.snatchable_lock.write()) {
11881186
Some(TextureInner::Native { raw }) => raw,
11891187
Some(TextureInner::Surface { .. }) => {
1190-
return Ok(());
1188+
return;
11911189
}
11921190
None => {
11931191
// Per spec, it is valid to call `destroy` multiple times.
1194-
return Ok(());
1192+
return;
11951193
}
11961194
};
11971195

@@ -1227,8 +1225,6 @@ impl Texture {
12271225
}
12281226
}
12291227
}
1230-
1231-
Ok(())
12321228
}
12331229
}
12341230

@@ -1968,13 +1964,6 @@ impl QuerySet {
19681964
}
19691965
}
19701966

1971-
#[derive(Clone, Debug, Error)]
1972-
#[non_exhaustive]
1973-
pub enum DestroyError {
1974-
#[error(transparent)]
1975-
InvalidResource(#[from] InvalidResourceError),
1976-
}
1977-
19781967
pub type BlasDescriptor<'a> = wgt::CreateBlasDescriptor<Label<'a>>;
19791968
pub type TlasDescriptor<'a> = wgt::CreateTlasDescriptor<Label<'a>>;
19801969

wgpu-hal/src/dx12/suballocation.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,8 +602,10 @@ impl<'a> DeviceAllocationContext<'a> {
602602
}
603603
};
604604

605-
if info.CurrentUsage + allocation_info.SizeInBytes.max(memblock_size)
606-
>= info.Budget / 100 * threshold as u64
605+
if info
606+
.CurrentUsage
607+
.checked_add(allocation_info.SizeInBytes.max(memblock_size))
608+
.is_none_or(|usage| usage >= info.Budget / 100 * threshold as u64)
607609
{
608610
return Err(crate::DeviceError::OutOfMemory);
609611
}

wgpu/src/backend/wgpu_core.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2056,8 +2056,7 @@ impl dispatch::BufferInterface for CoreBuffer {
20562056
}
20572057

20582058
fn destroy(&self) {
2059-
// Per spec, no error to report. Even calling destroy multiple times is valid.
2060-
let _ = self.context.0.buffer_destroy(self.id);
2059+
self.context.0.buffer_destroy(self.id);
20612060
}
20622061
}
20632062

@@ -2101,8 +2100,7 @@ impl dispatch::TextureInterface for CoreTexture {
21012100
}
21022101

21032102
fn destroy(&self) {
2104-
// Per spec, no error to report. Even calling destroy multiple times is valid.
2105-
let _ = self.context.0.texture_destroy(self.id);
2103+
self.context.0.texture_destroy(self.id);
21062104
}
21072105
}
21082106

0 commit comments

Comments
 (0)