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

Move out invalidity from the Registry #6243

Merged
merged 26 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ef9c0fd
[wgpu-core] use `device.instance_flags` when possible
teoxoy Sep 5, 2024
cd7bb3a
[wgpu-core] make the `Registry` generic over `T: Clone`
teoxoy Sep 5, 2024
3e3763c
[wgpu-core] introduce `Registry` `.strict_get()` & `.strict_unregiste…
teoxoy Sep 5, 2024
9031dd1
[wgpu-core] use `.strict_get()` & `.strict_unregister()` for surfaces
teoxoy Sep 5, 2024
dee498b
[wgpu-core] change return type of device creation methods to be more …
teoxoy Sep 5, 2024
7f4405c
[wgpu-core] use `.strict_get()` & `.strict_unregister()` for queues
teoxoy Sep 5, 2024
bfd59f2
[wgpu-core] use `.strict_get()` & `.strict_unregister()` for devices
teoxoy Sep 5, 2024
870e8e2
[wgpu-core] introduce `Fallible` and use it for `Buffer` (first step …
teoxoy Sep 6, 2024
32c78b5
[wgpu-core] use `Fallible` for `Texture`
teoxoy Sep 6, 2024
25259d7
[wgpu-core] use `Fallible` for `TextureView`
teoxoy Sep 6, 2024
4bfd0f7
[wgpu-core] use `Fallible` for `Sampler`
teoxoy Sep 6, 2024
11b84bd
[wgpu-core] use `Fallible` for `QuerySet`
teoxoy Sep 6, 2024
6450a0b
[wgpu-core] remove `Arc` around `StagingBuffer`
teoxoy Sep 6, 2024
e441139
[wgpu-core] use `Fallible` for `BindGroup`
teoxoy Sep 6, 2024
6ac1011
[wgpu-core] use `Fallible` for `ComputePipeline`
teoxoy Sep 6, 2024
d81e418
[wgpu-core] use `Fallible` for `RenderPipeline`
teoxoy Sep 6, 2024
e8969bc
[wgpu-core] use `Fallible` for `BindGroupLayout`
teoxoy Sep 6, 2024
fae8a71
[wgpu-core] use `Fallible` for `PipelineLayout`
teoxoy Sep 6, 2024
92a85b6
[wgpu-core] use `Fallible` for `ShaderModule`
teoxoy Sep 6, 2024
d2a8f1d
[wgpu-core] use `Fallible` for `PipelineCache`
teoxoy Sep 6, 2024
3fbf8f5
[wgpu-core] use `Fallible` for `RenderBundle`
teoxoy Sep 6, 2024
4522cba
[wgpu-core] use `.strict_get()` & `.strict_unregister()` for command …
teoxoy Sep 7, 2024
16bbf41
[wgpu-core] rename `.strict_get()` to `.get()`
teoxoy Sep 7, 2024
747e427
[wgpu-core] rename `.strict_unregister()` & `.strict_remove()` to `.r…
teoxoy Sep 7, 2024
a7428ab
[wgpu-core] remove `FutureId.into_id()`
teoxoy Sep 7, 2024
7ad4c37
[wgpu-core] inline `Storage.insert_impl()`
teoxoy Sep 7, 2024
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
17 changes: 8 additions & 9 deletions deno_webgpu/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,9 @@ pub fn op_webgpu_request_adapter(
})
}
};
let adapter_features = instance.adapter_features(adapter)?;
let adapter_features = instance.adapter_features(adapter);
let features = deserialize_features(&adapter_features);
let adapter_limits = instance.adapter_limits(adapter)?;
let adapter_limits = instance.adapter_limits(adapter);

let instance = instance.clone();

Expand Down Expand Up @@ -649,7 +649,7 @@ pub fn op_webgpu_request_device(
memory_hints: wgpu_types::MemoryHints::default(),
};

let (device, queue, maybe_err) = instance.adapter_request_device(
let res = instance.adapter_request_device(
adapter,
&descriptor,
std::env::var("DENO_WEBGPU_TRACE")
Expand All @@ -660,13 +660,12 @@ pub fn op_webgpu_request_device(
None,
);
adapter_resource.close();
if let Some(err) = maybe_err {
return Err(DomExceptionOperationError::new(&err.to_string()).into());
}

let device_features = instance.device_features(device)?;
let (device, queue) = res.map_err(|err| DomExceptionOperationError::new(&err.to_string()))?;

let device_features = instance.device_features(device);
let features = deserialize_features(&device_features);
let limits = instance.device_limits(device)?;
let limits = instance.device_limits(device);

let instance = instance.clone();
let instance2 = instance.clone();
Expand Down Expand Up @@ -705,7 +704,7 @@ pub fn op_webgpu_request_adapter_info(
let adapter = adapter_resource.1;
let instance = state.borrow::<Instance>();

let info = instance.adapter_get_info(adapter)?;
let info = instance.adapter_get_info(adapter);
adapter_resource.close();

Ok(GPUAdapterInfo {
Expand Down
6 changes: 3 additions & 3 deletions player/src/bin/play.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,18 @@ fn main() {
)
.expect("Unable to find an adapter for selected backend");

let info = global.adapter_get_info(adapter).unwrap();
let info = global.adapter_get_info(adapter);
log::info!("Picked '{}'", info.name);
let device_id = wgc::id::Id::zip(1, 0, backend);
let queue_id = wgc::id::Id::zip(1, 0, backend);
let (_, _, error) = global.adapter_request_device(
let res = global.adapter_request_device(
adapter,
&desc,
None,
Some(device_id),
Some(queue_id),
);
if let Some(e) = error {
if let Err(e) = res {
panic!("{:?}", e);
}
(device_id, queue_id)
Expand Down
8 changes: 4 additions & 4 deletions player/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl Test<'_> {
let backend = adapter.backend();
let device_id = wgc::id::Id::zip(test_num, 0, backend);
let queue_id = wgc::id::Id::zip(test_num, 0, backend);
let (_, _, error) = global.adapter_request_device(
let res = global.adapter_request_device(
adapter,
&wgt::DeviceDescriptor {
label: None,
Expand All @@ -120,7 +120,7 @@ impl Test<'_> {
Some(device_id),
Some(queue_id),
);
if let Some(e) = error {
if let Err(e) = res {
panic!("{:?}", e);
}

Expand Down Expand Up @@ -244,8 +244,8 @@ impl Corpus {
};

println!("\tBackend {:?}", backend);
let supported_features = global.adapter_features(adapter).unwrap();
let downlevel_caps = global.adapter_downlevel_capabilities(adapter).unwrap();
let supported_features = global.adapter_features(adapter);
let downlevel_caps = global.adapter_downlevel_capabilities(adapter);

let test = Test::load(dir.join(test_path), adapter.backend());
if !supported_features.contains(test.features) {
Expand Down
27 changes: 0 additions & 27 deletions tests/tests/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,33 +651,6 @@ static DEVICE_DROP_THEN_LOST: GpuTestConfiguration = GpuTestConfiguration::new()
);
});

#[gpu_test]
static DEVICE_INVALID_THEN_SET_LOST_CALLBACK: GpuTestConfiguration = GpuTestConfiguration::new()
.parameters(TestParameters::default().expect_fail(FailureCase::webgl2()))
.run_sync(|ctx| {
// This test checks that when the device is invalid, a subsequent call
// to set the device lost callback will immediately call the callback.
// Invalidating the device is done via a testing-only method. Fails on
// webgl because webgl doesn't implement make_invalid.

// Make the device invalid.
ctx.device.make_invalid();

static WAS_CALLED: AtomicBool = AtomicBool::new(false);

// Set a LoseDeviceCallback on the device.
let callback = Box::new(|reason, _m| {
WAS_CALLED.store(true, std::sync::atomic::Ordering::SeqCst);
assert_eq!(reason, wgt::DeviceLostReason::DeviceInvalid);
});
ctx.device.set_device_lost_callback(callback);

assert!(
WAS_CALLED.load(std::sync::atomic::Ordering::SeqCst),
"Device lost callback should have been called."
);
});

#[gpu_test]
static DEVICE_LOST_REPLACED_CALLBACK: GpuTestConfiguration = GpuTestConfiguration::new()
.parameters(TestParameters::default())
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ static PIPELINE_DEFAULT_LAYOUT_BAD_MODULE: GpuTestConfiguration = GpuTestConfigu
.parameters(
TestParameters::default()
// https://github.com/gfx-rs/wgpu/issues/4167
.expect_fail(FailureCase::always().panic("Pipeline is invalid")),
.expect_fail(FailureCase::always().panic("Error reflecting bind group")),
)
.run_sync(|ctx| {
ctx.device.push_error_scope(wgpu::ErrorFilter::Validation);
Expand Down
28 changes: 7 additions & 21 deletions tests/tests/resource_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,16 @@ static BAD_BUFFER: GpuTestConfiguration = GpuTestConfiguration::new().run_sync(|
Some("`map` usage can only be combined with the opposite `copy`"),
);

let error = match ctx.adapter_info.backend.to_str() {
"vulkan" | "vk" => "bufferid id(0,1,vk) is invalid",
"dx12" | "d3d12" => "bufferid id(0,1,d3d12) is invalid",
"metal" | "mtl" => "bufferid id(0,1,mtl) is invalid",
"opengl" | "gles" | "gl" => "bufferid id(0,1,gl) is invalid",
"webgpu" => "bufferid id(0,1,webgpu) is invalid",
b => b,
};

fail(
&ctx.device,
|| buffer.slice(..).map_async(wgpu::MapMode::Write, |_| {}),
Some(error),
Some("Buffer with '' label is invalid"),
);
fail(
&ctx.device,
|| buffer.unmap(),
Some("Buffer with '' label is invalid"),
);
fail(&ctx.device, || buffer.unmap(), Some(error));
valid(&ctx.device, || buffer.destroy());
valid(&ctx.device, || buffer.destroy());
});
Expand Down Expand Up @@ -59,21 +54,12 @@ static BAD_TEXTURE: GpuTestConfiguration = GpuTestConfiguration::new().run_sync(
Some("dimension x is zero"),
);

let error = match ctx.adapter_info.backend.to_str() {
"vulkan" | "vk" => "textureid id(0,1,vk) is invalid",
"dx12" | "d3d12" => "textureid id(0,1,d3d12) is invalid",
"metal" | "mtl" => "textureid id(0,1,mtl) is invalid",
"opengl" | "gles" | "gl" => "textureid id(0,1,gl) is invalid",
"webgpu" => "textureid id(0,1,webgpu) is invalid",
b => b,
};

fail(
&ctx.device,
|| {
let _ = texture.create_view(&wgpu::TextureViewDescriptor::default());
},
Some(error),
Some("Texture with '' label is invalid"),
);
valid(&ctx.device, || texture.destroy());
valid(&ctx.device, || texture.destroy());
Expand Down
22 changes: 8 additions & 14 deletions wgpu-core/src/binding_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use crate::{
init_tracker::{BufferInitTrackerAction, TextureInitTrackerAction},
pipeline::{ComputePipeline, RenderPipeline},
resource::{
Buffer, DestroyedResourceError, Labeled, MissingBufferUsageError, MissingTextureUsageError,
ResourceErrorIdent, Sampler, TextureView, TrackingData,
Buffer, DestroyedResourceError, InvalidResourceError, Labeled, MissingBufferUsageError,
MissingTextureUsageError, ResourceErrorIdent, Sampler, TextureView, TrackingData,
},
resource_log,
snatch::{SnatchGuard, Snatchable},
Expand Down Expand Up @@ -79,14 +79,6 @@ pub enum CreateBindGroupLayoutError {
pub enum CreateBindGroupError {
#[error(transparent)]
Device(#[from] DeviceError),
#[error("Bind group layout is invalid")]
InvalidLayout,
#[error("BufferId {0:?} is invalid")]
InvalidBufferId(BufferId),
#[error("TextureViewId {0:?} is invalid")]
InvalidTextureViewId(TextureViewId),
#[error("SamplerId {0:?} is invalid")]
InvalidSamplerId(SamplerId),
#[error(transparent)]
DestroyedResource(#[from] DestroyedResourceError),
#[error(
Expand Down Expand Up @@ -188,6 +180,8 @@ pub enum CreateBindGroupError {
StorageReadNotSupported(wgt::TextureFormat),
#[error(transparent)]
ResourceUsageCompatibility(#[from] ResourceUsageCompatibilityError),
#[error(transparent)]
InvalidResource(#[from] InvalidResourceError),
}

#[derive(Clone, Debug, Error)]
Expand Down Expand Up @@ -545,8 +539,6 @@ impl BindGroupLayout {
pub enum CreatePipelineLayoutError {
#[error(transparent)]
Device(#[from] DeviceError),
#[error("BindGroupLayoutId {0:?} is invalid")]
InvalidBindGroupLayoutId(BindGroupLayoutId),
#[error(
"Push constant at index {index} has range bound {bound} not aligned to {}",
wgt::PUSH_CONSTANT_ALIGNMENT
Expand All @@ -570,6 +562,8 @@ pub enum CreatePipelineLayoutError {
TooManyBindings(BindingTypeMaxCountError),
#[error("Bind group layout count {actual} exceeds device bind group limit {max}")]
TooManyGroups { actual: usize, max: usize },
#[error(transparent)]
InvalidResource(#[from] InvalidResourceError),
}

#[derive(Clone, Debug, Error)]
Expand Down Expand Up @@ -1003,10 +997,10 @@ crate::impl_trackable!(BindGroup);
#[derive(Clone, Debug, Error)]
#[non_exhaustive]
pub enum GetBindGroupLayoutError {
#[error("Pipeline is invalid")]
InvalidPipeline,
#[error("Invalid group index {0}")]
InvalidGroupIndex(u32),
#[error(transparent)]
InvalidResource(#[from] InvalidResourceError),
}

#[derive(Clone, Debug, Error, Eq, PartialEq)]
Expand Down
37 changes: 16 additions & 21 deletions wgpu-core/src/command/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ use crate::{
id,
init_tracker::{BufferInitTrackerAction, MemoryInitKind, TextureInitTrackerAction},
pipeline::{PipelineFlags, RenderPipeline, VertexStep},
resource::{Buffer, DestroyedResourceError, Labeled, ParentDevice, TrackingData},
resource::{
Buffer, DestroyedResourceError, Fallible, InvalidResourceError, Labeled, ParentDevice,
TrackingData,
},
resource_log,
snatch::SnatchGuard,
track::RenderBundleScope,
Expand Down Expand Up @@ -578,7 +581,7 @@ impl RenderBundleEncoder {

fn set_bind_group(
state: &mut State,
bind_group_guard: &crate::lock::RwLockReadGuard<crate::storage::Storage<BindGroup>>,
bind_group_guard: &crate::storage::Storage<Fallible<BindGroup>>,
dynamic_offsets: &[u32],
index: u32,
num_dynamic_offsets: usize,
Expand All @@ -591,9 +594,7 @@ fn set_bind_group(

let bind_group_id = bind_group_id.unwrap();

let bind_group = bind_group_guard
.get_owned(bind_group_id)
.map_err(|_| RenderCommandError::InvalidBindGroupId(bind_group_id))?;
let bind_group = bind_group_guard.get(bind_group_id).get()?;

bind_group.same_device(&state.device)?;

Expand Down Expand Up @@ -630,15 +631,13 @@ fn set_bind_group(

fn set_pipeline(
state: &mut State,
pipeline_guard: &crate::lock::RwLockReadGuard<crate::storage::Storage<RenderPipeline>>,
pipeline_guard: &crate::storage::Storage<Fallible<RenderPipeline>>,
context: &RenderPassContext,
is_depth_read_only: bool,
is_stencil_read_only: bool,
pipeline_id: id::Id<id::markers::RenderPipeline>,
) -> Result<(), RenderBundleErrorInner> {
let pipeline = pipeline_guard
.get_owned(pipeline_id)
.map_err(|_| RenderCommandError::InvalidPipelineId(pipeline_id))?;
let pipeline = pipeline_guard.get(pipeline_id).get()?;

pipeline.same_device(&state.device)?;

Expand Down Expand Up @@ -673,15 +672,13 @@ fn set_pipeline(

fn set_index_buffer(
state: &mut State,
buffer_guard: &crate::lock::RwLockReadGuard<crate::storage::Storage<Buffer>>,
buffer_guard: &crate::storage::Storage<Fallible<Buffer>>,
buffer_id: id::Id<id::markers::Buffer>,
index_format: wgt::IndexFormat,
offset: u64,
size: Option<std::num::NonZeroU64>,
) -> Result<(), RenderBundleErrorInner> {
let buffer = buffer_guard
.get_owned(buffer_id)
.map_err(|_| RenderCommandError::InvalidBufferId(buffer_id))?;
let buffer = buffer_guard.get(buffer_id).get()?;

state
.trackers
Expand All @@ -708,7 +705,7 @@ fn set_index_buffer(

fn set_vertex_buffer(
state: &mut State,
buffer_guard: &crate::lock::RwLockReadGuard<crate::storage::Storage<Buffer>>,
buffer_guard: &crate::storage::Storage<Fallible<Buffer>>,
slot: u32,
buffer_id: id::Id<id::markers::Buffer>,
offset: u64,
Expand All @@ -723,9 +720,7 @@ fn set_vertex_buffer(
.into());
}

let buffer = buffer_guard
.get_owned(buffer_id)
.map_err(|_| RenderCommandError::InvalidBufferId(buffer_id))?;
let buffer = buffer_guard.get(buffer_id).get()?;

state
.trackers
Expand Down Expand Up @@ -852,7 +847,7 @@ fn draw_indexed(
fn multi_draw_indirect(
state: &mut State,
dynamic_offsets: &[u32],
buffer_guard: &crate::lock::RwLockReadGuard<crate::storage::Storage<Buffer>>,
buffer_guard: &crate::storage::Storage<Fallible<Buffer>>,
buffer_id: id::Id<id::markers::Buffer>,
offset: u64,
indexed: bool,
Expand All @@ -864,9 +859,7 @@ fn multi_draw_indirect(
let pipeline = state.pipeline()?;
let used_bind_groups = pipeline.used_bind_groups;

let buffer = buffer_guard
.get_owned(buffer_id)
.map_err(|_| RenderCommandError::InvalidBufferId(buffer_id))?;
let buffer = buffer_guard.get(buffer_id).get()?;

state
.trackers
Expand Down Expand Up @@ -1538,6 +1531,8 @@ pub(super) enum RenderBundleErrorInner {
MissingDownlevelFlags(#[from] MissingDownlevelFlags),
#[error(transparent)]
Bind(#[from] BindError),
#[error(transparent)]
InvalidResource(#[from] InvalidResourceError),
}

impl<T> From<T> for RenderBundleErrorInner
Expand Down
Loading
Loading