diff --git a/wgpu-core/src/command/clear.rs b/wgpu-core/src/command/clear.rs index 34a345ff5..f0dee4729 100644 --- a/wgpu-core/src/command/clear.rs +++ b/wgpu-core/src/command/clear.rs @@ -125,6 +125,8 @@ impl Global { list.push(TraceCommand::ClearBuffer { dst, offset, size }); } + cmd_buf.device.check_is_valid()?; + let dst_buffer = hub.buffers.get(dst).get()?; dst_buffer.same_device_as(cmd_buf.as_ref())?; @@ -213,6 +215,8 @@ impl Global { }); } + cmd_buf.device.check_is_valid()?; + if !cmd_buf.support_clear_texture { return Err(ClearError::MissingClearTextureFeature); } diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index 2015745ea..bd1c0cc02 100644 --- a/wgpu-core/src/command/compute.rs +++ b/wgpu-core/src/command/compute.rs @@ -348,6 +348,13 @@ impl Global { match cmd_buf_data.lock_encoder() { Ok(()) => { drop(cmd_buf_data); + if let Err(err) = cmd_buf.device.check_is_valid() { + return ( + ComputePass::new_invalid(cmd_buf, &label, err.map_pass_err(scope)), + None, + ); + } + match desc .timestamp_writes .as_ref() diff --git a/wgpu-core/src/command/mod.rs b/wgpu-core/src/command/mod.rs index 069663972..80133c5b8 100644 --- a/wgpu-core/src/command/mod.rs +++ b/wgpu-core/src/command/mod.rs @@ -1144,6 +1144,8 @@ impl Global { list.push(TraceCommand::PushDebugGroup(label.to_owned())); } + cmd_buf.device.check_is_valid()?; + let cmd_buf_raw = cmd_buf_data.encoder.open()?; if !cmd_buf .device @@ -1177,6 +1179,8 @@ impl Global { list.push(TraceCommand::InsertDebugMarker(label.to_owned())); } + cmd_buf.device.check_is_valid()?; + if !cmd_buf .device .instance_flags @@ -1209,6 +1213,8 @@ impl Global { list.push(TraceCommand::PopDebugGroup); } + cmd_buf.device.check_is_valid()?; + let cmd_buf_raw = cmd_buf_data.encoder.open()?; if !cmd_buf .device diff --git a/wgpu-core/src/command/query.rs b/wgpu-core/src/command/query.rs index 3c7885a84..2f250e9ac 100644 --- a/wgpu-core/src/command/query.rs +++ b/wgpu-core/src/command/query.rs @@ -367,10 +367,6 @@ impl Global { .get(command_encoder_id.into_command_buffer_id()); let mut cmd_buf_data = cmd_buf.data.lock(); cmd_buf_data.record_with(|cmd_buf_data| -> Result<(), QueryError> { - cmd_buf - .device - .require_features(wgt::Features::TIMESTAMP_QUERY_INSIDE_ENCODERS)?; - #[cfg(feature = "trace")] if let Some(ref mut list) = cmd_buf_data.commands { list.push(TraceCommand::WriteTimestamp { @@ -379,9 +375,16 @@ impl Global { }); } + cmd_buf.device.check_is_valid()?; + + cmd_buf + .device + .require_features(wgt::Features::TIMESTAMP_QUERY_INSIDE_ENCODERS)?; + let raw_encoder = cmd_buf_data.encoder.open()?; let query_set = hub.query_sets.get(query_set_id).get()?; + query_set.same_device_as(cmd_buf.as_ref())?; query_set.validate_and_write_timestamp(raw_encoder, query_index, None)?; @@ -418,6 +421,8 @@ impl Global { }); } + cmd_buf.device.check_is_valid()?; + if destination_offset % wgt::QUERY_RESOLVE_BUFFER_ALIGNMENT != 0 { return Err(QueryError::Resolve(ResolveError::BufferOffsetAlignment)); } diff --git a/wgpu-core/src/command/ray_tracing.rs b/wgpu-core/src/command/ray_tracing.rs index 42e86d582..bdd111127 100644 --- a/wgpu-core/src/command/ray_tracing.rs +++ b/wgpu-core/src/command/ray_tracing.rs @@ -77,6 +77,7 @@ impl Global { cmd_buf_data.record_with( |cmd_buf_data| -> Result<(), BuildAccelerationStructureError> { let device = &cmd_buf.device; + device.check_is_valid()?; device .require_features(Features::EXPERIMENTAL_RAY_TRACING_ACCELERATION_STRUCTURE)?; @@ -214,6 +215,7 @@ impl Global { } let device = &cmd_buf.device; + device.check_is_valid()?; device.require_features(Features::EXPERIMENTAL_RAY_TRACING_ACCELERATION_STRUCTURE)?; let mut buf_storage = Vec::new(); diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index 1fb8f5ca1..19129f891 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -1548,6 +1548,8 @@ impl Global { arc_desc: &mut ArcRenderPassDescriptor, device: &Device, ) -> Result<(), RenderPassErrorInner> { + device.check_is_valid()?; + let query_sets = hub.query_sets.read(); let texture_views = hub.texture_views.read(); diff --git a/wgpu-core/src/device/global.rs b/wgpu-core/src/device/global.rs index 3c3e8d38d..d61be9613 100644 --- a/wgpu-core/src/device/global.rs +++ b/wgpu-core/src/device/global.rs @@ -654,6 +654,10 @@ impl Global { trace.add(trace::Action::CreatePipelineLayout(fid.id(), desc.clone())); } + if let Err(e) = device.check_is_valid() { + break 'error e.into(); + } + let bind_group_layouts = { let bind_group_layouts_guard = hub.bind_group_layouts.read(); desc.bind_group_layouts @@ -722,6 +726,10 @@ impl Global { trace.add(trace::Action::CreateBindGroup(fid.id(), desc.clone())); } + if let Err(e) = device.check_is_valid() { + break 'error e.into(); + } + let layout = match hub.bind_group_layouts.get(desc.layout).get() { Ok(layout) => layout, Err(e) => break 'error e.into(), @@ -1250,6 +1258,10 @@ impl Global { }); } + if let Err(e) = device.check_is_valid() { + break 'error e.into(); + } + let layout = desc .layout .map(|layout| hub.pipeline_layouts.get(layout).get()) @@ -1485,6 +1497,10 @@ impl Global { }); } + if let Err(e) = device.check_is_valid() { + break 'error e.into(); + } + let layout = desc .layout .map(|layout| hub.pipeline_layouts.get(layout).get()) diff --git a/wgpu-core/src/device/queue.rs b/wgpu-core/src/device/queue.rs index 1a4849f3f..c7b810c48 100644 --- a/wgpu-core/src/device/queue.rs +++ b/wgpu-core/src/device/queue.rs @@ -1445,6 +1445,7 @@ impl Queue { profiling::scope!("Queue::compact_blas"); api_log!("Queue::compact_blas"); + self.device.check_is_valid()?; self.same_device_as(blas.as_ref())?; let device = blas.device.clone();