Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Device valid #4163

Merged
merged 45 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
fff56b6
Implement Device validity, and make it invalid when Device is lost.
bradwerth Sep 11, 2023
0d4825c
Implement device validity, and make it invalid when device is lost.
bradwerth Sep 11, 2023
dfb34f5
Fixup merge.
bradwerth Sep 15, 2023
2887ad6
Drop texture `clear_view`s in surface_texture_discard (#4057)
rajveermalviya Aug 30, 2023
74bbc7d
Bump profiling from 1.0.9 to 1.0.10 (#4102)
dependabot[bot] Sep 1, 2023
451dfeb
Fix limits interface on web. (#4107)
OptimisticPeach Sep 1, 2023
8fc3eb5
Add details to `InstanceError` and `CreateSurfaceError`. (#4066)
kpreid Sep 1, 2023
8fc8962
Skip `test_multithreaded_compute` on MoltenVK. (#4096)
jimblandy Sep 4, 2023
fef6235
Bump thiserror from 1.0.47 to 1.0.48 (#4112)
dependabot[bot] Sep 5, 2023
cc0135e
Bump serde from 1.0.186 to 1.0.188 (#4091)
dependabot[bot] Sep 5, 2023
dbf82b7
Bump actions/checkout from 3 to 4 (#4117)
dependabot[bot] Sep 5, 2023
cdcf934
hal/vulkan: `Instance::required_extensions` -> `desired_extensions` (…
jimblandy Sep 5, 2023
bbb3cd9
Enable vulkan presentation on Intel Mesa >= v21.2 (#4110)
flukejones Sep 5, 2023
7c47c49
wgpu_core: Add logging to Instance::new.
jimblandy Sep 4, 2023
1acf857
Fix D3D12 Surface Leak (#4106)
cwfitzgerald Sep 5, 2023
6ac37a5
Bump bytemuck from 1.13.1 to 1.14.0 (#4123)
dependabot[bot] Sep 6, 2023
8c75d36
Update `naga` to 0.13.0@git:cc87b8f9eb30bb55d0735b89d3df3e099e1a6e7c …
nical Sep 11, 2023
bcf544d
Bump serde_json from 1.0.105 to 1.0.106 (#4129)
dependabot[bot] Sep 11, 2023
118b7e6
Print errors in a more readable format in the player. (#4137)
nical Sep 14, 2023
cd3e1f3
Workaround NV bug (#4132)
cwfitzgerald Sep 14, 2023
e8b839d
Bump serde_json from 1.0.106 to 1.0.107 (#4133)
dependabot[bot] Sep 14, 2023
eede6bd
Bump libc from 0.2.147 to 0.2.148 (#4134)
dependabot[bot] Sep 14, 2023
2f5dc46
Add details to `RequestDeviceError`. (#4145)
kpreid Sep 16, 2023
2003dd9
Metal encoder & pass timestamp support (#4008)
Wumpf Sep 16, 2023
118359a
Tests for wgpu#4139. (#4148)
jimblandy Sep 17, 2023
4dbff2e
Update Naga to df8107b7 (2023-9-15). (#4149)
jimblandy Sep 17, 2023
36a21e4
[d3d12] Document `map_blend_factor` (#4151)
teoxoy Sep 18, 2023
573fdee
Make `StoreOp` an enum instead of a bool (#4147)
Wumpf Sep 18, 2023
c377399
Bump profiling from 1.0.10 to 1.0.11 (#4153)
dependabot[bot] Sep 19, 2023
db408aa
Bump termcolor from 1.2.0 to 1.3.0 (#4152)
dependabot[bot] Sep 19, 2023
17114ff
Support dual source blending (#4022)
freqmod Sep 19, 2023
3659bb5
Implement device validity, and make it invalid when device is lost.
bradwerth Sep 11, 2023
ef12c6a
This makes device_lose testable and adds a meaningful test.
bradwerth Sep 19, 2023
4b6d4b5
Add partial information to CHANGELOG.md.
bradwerth Sep 21, 2023
2ea06be
Update CHANGELOG.md.
bradwerth Sep 21, 2023
ba05653
Merge branch 'trunk' into deviceValid
bradwerth Sep 21, 2023
5f0ec42
Fixup merge of tests/device.rs.
bradwerth Sep 21, 2023
a4a5403
Fixup web.rs implementation of device_lose.
bradwerth Sep 21, 2023
e1f3d7c
Stub out web.rs device_lose.
bradwerth Sep 21, 2023
2feef8f
Fixup test problems on different backends, and fixup stub of web.rs d…
bradwerth Sep 21, 2023
084d036
Run rustfmt, fix issues in tests/device.rs.
bradwerth Sep 22, 2023
b756739
Test skipped in DX12 for validation errors, more comments in test, in…
bradwerth Sep 22, 2023
48b2812
Update test to use device.destroy, and remove the public exposure of …
bradwerth Sep 25, 2023
166549c
Restore config.toml.
bradwerth Sep 26, 2023
835a733
rustfmt device.rs.
bradwerth Sep 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions .cargo/config.toml

This file was deleted.

5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ By @wumpf in [#4147](https://github.com/gfx-rs/wgpu/pull/4147)
- `wgpu::CreateSurfaceError` and `wgpu::RequestDeviceError` now give details of the failure, but no longer implement `PartialEq` and cannot be constructed. By @kpreid in [#4066](https://github.com/gfx-rs/wgpu/pull/4066) and [#4145](https://github.com/gfx-rs/wgpu/pull/4145)
- Make `WGPU_POWER_PREF=none` a valid value. By @fornwall in [4076](https://github.com/gfx-rs/wgpu/pull/4076)
- Support dual source blending in OpenGL ES, Metal, Vulkan & DX12. By @freqmod in [4022](https://github.com/gfx-rs/wgpu/pull/4022)
- Add stub support for "lose the device" and device validity. By @bradwerth in [4163](https://github.com/gfx-rs/wgpu/pull/4163)

#### Vulkan

Expand All @@ -117,6 +118,10 @@ By @wumpf in [#4147](https://github.com/gfx-rs/wgpu/pull/4147)

- Support for timestamp queries on encoders and passes. By @wumpf in [#4008](https://github.com/gfx-rs/wgpu/pull/4008)

#### Metal

- Support for timestamp queries on encoders and passes. By @wumpf in [#4008](https://github.com/gfx-rs/wgpu/pull/4008)

bradwerth marked this conversation as resolved.
Show resolved Hide resolved
### Bug Fixes

#### General
Expand Down
180 changes: 179 additions & 1 deletion tests/tests/device.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use wasm_bindgen_test::*;

use wgpu_test::{initialize_test, FailureCase, TestParameters};
use wgpu_test::{fail, initialize_test, FailureCase, TestParameters};

#[test]
#[wasm_bindgen_test]
Expand Down Expand Up @@ -91,3 +91,181 @@ async fn request_device_error_message() {
}
assert!(device_error.contains(expected), "{device_error}");
}

#[test]
fn device_lose_then_more() {
// This is a test of device behavior after "lose the device". Specifically, all operations
// should trigger errors. To test this, it calls an explicit function to lose the device,
// which is not part of normal use and ideally wouldn't be exposed at all.
//
// TODO: Figure out how to make device.lose a private function only available to the test
// harness.
bradwerth marked this conversation as resolved.
Show resolved Hide resolved
//
// On DX12 this test fails with a validation error in the very artifical actions taken
// after lose the device. The error is "ID3D12CommandAllocator::Reset: The command
bradwerth marked this conversation as resolved.
Show resolved Hide resolved
// allocator cannot be reset because a command list is currently being recorded with the
// allocator." That may indicate that DX12 doesn't like opened command buffers staying
// open even after they return an error. For now, this test is skipped on DX12.
initialize_test(
TestParameters::default()
.features(wgpu::Features::CLEAR_TEXTURE)
.skip(FailureCase::backend(wgpu::Backends::DX12)),
|ctx| {
// Create some resources on the device that we will attempt to use *after* losing the
// device.

// Create a 512 x 512 2D texture, and a target view of it.
let texture_extent = wgpu::Extent3d {
width: 512,
height: 512,
depth_or_array_layers: 1,
};
let texture_for_view = ctx.device.create_texture(&wgpu::TextureDescriptor {
label: None,
size: texture_extent,
mip_level_count: 2,
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Rg8Uint,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
view_formats: &[],
});
let target_view = texture_for_view.create_view(&wgpu::TextureViewDescriptor::default());

let texture_for_write = ctx.device.create_texture(&wgpu::TextureDescriptor {
label: None,
size: texture_extent,
mip_level_count: 2,
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Rg8Uint,
usage: wgpu::TextureUsages::COPY_DST,
view_formats: &[],
});

// Create some buffers.
let buffer_source = ctx.device.create_buffer(&wgpu::BufferDescriptor {
label: None,
size: 256,
usage: wgpu::BufferUsages::MAP_WRITE | wgpu::BufferUsages::COPY_SRC,
mapped_at_creation: false,
});
let buffer_dest = ctx.device.create_buffer(&wgpu::BufferDescriptor {
label: None,
size: 256,
usage: wgpu::BufferUsages::MAP_READ | wgpu::BufferUsages::COPY_DST,
mapped_at_creation: false,
});

// Create some command encoders.
let mut encoder_for_clear = ctx
.device
.create_command_encoder(&wgpu::CommandEncoderDescriptor::default());

let mut encoder_for_compute_pass = ctx
.device
.create_command_encoder(&wgpu::CommandEncoderDescriptor::default());

let mut encoder_for_render_pass = ctx
.device
.create_command_encoder(&wgpu::CommandEncoderDescriptor::default());

let mut encoder_for_buffer_buffer_copy = ctx
.device
.create_command_encoder(&wgpu::CommandEncoderDescriptor::default());

let mut encoder_for_buffer_texture_copy = ctx
.device
.create_command_encoder(&wgpu::CommandEncoderDescriptor::default());

// Lose the device. This will cause all other requests to return some variation of a
// device invalid error.
ctx.device.lose();

// TODO: change these fail calls to check for the specific errors which indicate that
// the device is not valid.

// Creating a texture should fail.
fail(&ctx.device, || {
ctx.device.create_texture(&wgpu::TextureDescriptor {
label: None,
size: wgpu::Extent3d {
width: 512,
height: 512,
depth_or_array_layers: 1,
},
mip_level_count: 2,
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Rg8Uint,
usage: wgpu::TextureUsages::COPY_SRC,
view_formats: &[],
});
});

bradwerth marked this conversation as resolved.
Show resolved Hide resolved
// Texture clear should fail.
fail(&ctx.device, || {
encoder_for_clear.clear_texture(
&texture_for_write,
&wgpu::ImageSubresourceRange {
aspect: wgpu::TextureAspect::All,
base_mip_level: 0,
mip_level_count: None,
base_array_layer: 0,
array_layer_count: None,
},
);
});

// Creating a compute pass should fail.
fail(&ctx.device, || {
encoder_for_compute_pass.begin_compute_pass(&wgpu::ComputePassDescriptor {
label: None,
timestamp_writes: None,
});
});

// Creating a render pass should fail.
fail(&ctx.device, || {
encoder_for_render_pass.begin_render_pass(&wgpu::RenderPassDescriptor {
label: None,
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
ops: wgpu::Operations::default(),
resolve_target: None,
view: &target_view,
})],
depth_stencil_attachment: None,
timestamp_writes: None,
occlusion_query_set: None,
});
});

// Copying a buffer to a buffer should fail.
fail(&ctx.device, || {
encoder_for_buffer_buffer_copy.copy_buffer_to_buffer(
&buffer_source,
0,
&buffer_dest,
0,
256,
);
});

// Copying a buffer to a texture should fail.
fail(&ctx.device, || {
encoder_for_buffer_texture_copy.copy_buffer_to_texture(
wgpu::ImageCopyBuffer {
buffer: &buffer_source,
layout: wgpu::ImageDataLayout {
offset: 0,
bytes_per_row: Some(4),
rows_per_image: None,
},
},
texture_for_write.as_image_copy(),
texture_extent,
);
});
},
)
}
3 changes: 3 additions & 0 deletions wgpu-core/src/command/clear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}

let device = &device_guard[cmd_buf.device_id.value];
if !device.is_valid() {
return Err(ClearError::InvalidDevice(cmd_buf.device_id.value.0));
}

clear_texture(
&*texture_guard,
Expand Down
9 changes: 9 additions & 0 deletions wgpu-core/src/command/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::{
hal_api::HalApi,
hub::Token,
id,
id::DeviceId,
identity::GlobalIdentityHandlerFactory,
init_tracker::MemoryInitKind,
pipeline,
Expand Down Expand Up @@ -193,6 +194,8 @@ pub enum ComputePassErrorInner {
Encoder(#[from] CommandEncoderError),
#[error("Bind group {0:?} is invalid")]
InvalidBindGroup(id::BindGroupId),
#[error("Device {0:?} is invalid")]
InvalidDevice(DeviceId),
#[error("Bind group index {index} is greater than the device's requested `max_bind_group` limit {max}")]
BindGroupIndexOutOfRange { index: u32, max: u32 },
#[error("Compute pipeline {0:?} is invalid")]
Expand Down Expand Up @@ -390,6 +393,12 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let raw = cmd_buf.encoder.open();

let device = &device_guard[cmd_buf.device_id.value];
if !device.is_valid() {
return Err(ComputePassErrorInner::InvalidDevice(
cmd_buf.device_id.value.0,
))
.map_pass_err(init_scope);
}

#[cfg(feature = "trace")]
if let Some(ref mut list) = cmd_buf.commands {
Expand Down
9 changes: 9 additions & 0 deletions wgpu-core/src/command/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::{
hal_api::HalApi,
hub::Token,
id,
id::DeviceId,
identity::GlobalIdentityHandlerFactory,
init_tracker::{MemoryInitKind, TextureInitRange, TextureInitTrackerAction},
pipeline::{self, PipelineFlags},
Expand Down Expand Up @@ -523,6 +524,8 @@ pub enum RenderPassErrorInner {
ColorAttachment(#[from] ColorAttachmentError),
#[error(transparent)]
Encoder(#[from] CommandEncoderError),
#[error("Device {0:?} is invalid")]
InvalidDevice(DeviceId),
#[error("Attachment texture view {0:?} is invalid")]
InvalidAttachment(id::TextureViewId),
#[error("The format of the depth-stencil attachment ({0:?}) is not a depth-stencil format")]
Expand Down Expand Up @@ -1346,6 +1349,12 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}

let device = &device_guard[cmd_buf.device_id.value];
if !device.is_valid() {
return Err(RenderPassErrorInner::InvalidDevice(
cmd_buf.device_id.value.0,
))
.map_pass_err(init_scope);
}
cmd_buf.encoder.open_pass(base.label);

let (bundle_guard, mut token) = hub.render_bundles.read(&mut token);
Expand Down
16 changes: 15 additions & 1 deletion wgpu-core/src/command/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
global::Global,
hal_api::HalApi,
hub::Token,
id::{BufferId, CommandEncoderId, TextureId, Valid},
id::{BufferId, CommandEncoderId, DeviceId, TextureId, Valid},
identity::GlobalIdentityHandlerFactory,
init_tracker::{
has_copy_partial_init_tracker_coverage, MemoryInitKind, TextureInitRange,
Expand Down Expand Up @@ -40,6 +40,8 @@ pub enum CopySide {
#[derive(Clone, Debug, Error)]
#[non_exhaustive]
pub enum TransferError {
#[error("Device {0:?} is invalid")]
InvalidDevice(DeviceId),
#[error("Buffer {0:?} is invalid or destroyed")]
InvalidBuffer(BufferId),
#[error("Texture {0:?} is invalid or destroyed")]
Expand Down Expand Up @@ -569,6 +571,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let (buffer_guard, _) = hub.buffers.read(&mut token);

let device = &device_guard[cmd_buf.device_id.value];
if !device.is_valid() {
return Err(TransferError::InvalidDevice(cmd_buf.device_id.value.0).into());
}

#[cfg(feature = "trace")]
if let Some(ref mut list) = cmd_buf.commands {
Expand Down Expand Up @@ -714,6 +719,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let (texture_guard, _) = hub.textures.read(&mut token);

let device = &device_guard[cmd_buf.device_id.value];
if !device.is_valid() {
return Err(TransferError::InvalidDevice(cmd_buf.device_id.value.0).into());
}

#[cfg(feature = "trace")]
if let Some(ref mut list) = cmd_buf.commands {
Expand Down Expand Up @@ -858,6 +866,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let (texture_guard, _) = hub.textures.read(&mut token);

let device = &device_guard[cmd_buf.device_id.value];
if !device.is_valid() {
return Err(TransferError::InvalidDevice(cmd_buf.device_id.value.0).into());
}

#[cfg(feature = "trace")]
if let Some(ref mut list) = cmd_buf.commands {
Expand Down Expand Up @@ -1020,6 +1031,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let (texture_guard, _) = hub.textures.read(&mut token);

let device = &device_guard[cmd_buf.device_id.value];
if !device.is_valid() {
return Err(TransferError::InvalidDevice(cmd_buf.device_id.value.0).into());
}

#[cfg(feature = "trace")]
if let Some(ref mut list) = cmd_buf.commands {
Expand Down
Loading