forked from gfx-rs/wgpu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better handle destroying textures and buffers
Before this commit, explicitly destroying a texture or a buffer (without dropping it) schedules the asynchronous destruction of its raw resources but does not actually mark it as destroyed. This can cause some incorrect behavior, for example mapping a buffer after destroying it does not cause a validation error (and later panics due to the map callback being dropped without being called). This Commit adds `Storage::take_and_mark_destroyed` for use in `destroy` methods. Since it puts the resource in the error state, other methods properly catch that the resource is no longer usable when attempting to access it and raise validation errors. There are other resource types that require similar treatment and will be addressed in followup work.
- Loading branch information
Showing
4 changed files
with
84 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use wgpu_test::{gpu_test, FailureCase, GpuTestConfiguration, TestParameters}; | ||
|
||
#[gpu_test] | ||
static BUFFER_DESTROY: GpuTestConfiguration = GpuTestConfiguration::new() | ||
.parameters(TestParameters::default().expect_fail(FailureCase::always())) | ||
.run_sync(|ctx| { | ||
let buffer = ctx.device.create_buffer(&wgpu::BufferDescriptor { | ||
label: None, | ||
size: 256, | ||
usage: wgpu::BufferUsages::MAP_WRITE | wgpu::BufferUsages::COPY_SRC, | ||
mapped_at_creation: false, | ||
}); | ||
|
||
buffer.destroy(); | ||
|
||
buffer.destroy(); | ||
|
||
ctx.device.poll(wgpu::MaintainBase::Wait); | ||
|
||
buffer | ||
.slice(..) | ||
.map_async(wgpu::MapMode::Write, move |_| {}); | ||
|
||
buffer.destroy(); | ||
|
||
ctx.device.poll(wgpu::MaintainBase::Wait); | ||
|
||
buffer.destroy(); | ||
|
||
buffer.destroy(); | ||
}); | ||
|
||
#[gpu_test] | ||
static TEXTURE_DESTROY: GpuTestConfiguration = GpuTestConfiguration::new().run_sync(|ctx| { | ||
let texture = ctx.device.create_texture(&wgpu::TextureDescriptor { | ||
label: None, | ||
size: wgpu::Extent3d { | ||
width: 128, | ||
height: 128, | ||
depth_or_array_layers: 1, | ||
}, | ||
mip_level_count: 1, | ||
sample_count: 1, // multisampling is not supported for clear | ||
dimension: wgpu::TextureDimension::D2, | ||
format: wgpu::TextureFormat::Rgba8Snorm, | ||
usage: wgpu::TextureUsages::COPY_DST | wgpu::TextureUsages::TEXTURE_BINDING, | ||
view_formats: &[], | ||
}); | ||
|
||
texture.destroy(); | ||
|
||
texture.destroy(); | ||
|
||
ctx.device.poll(wgpu::MaintainBase::Wait); | ||
|
||
texture.destroy(); | ||
|
||
ctx.device.poll(wgpu::MaintainBase::Wait); | ||
|
||
texture.destroy(); | ||
|
||
texture.destroy(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters