Skip to content

Commit 487f79b

Browse files
committed
Add missing device validity checks
1 parent e10e179 commit 487f79b

File tree

8 files changed

+47
-4
lines changed

8 files changed

+47
-4
lines changed

wgpu-core/src/command/clear.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ impl Global {
125125
list.push(TraceCommand::ClearBuffer { dst, offset, size });
126126
}
127127

128+
cmd_buf.device.check_is_valid()?;
129+
128130
let dst_buffer = hub.buffers.get(dst).get()?;
129131

130132
dst_buffer.same_device_as(cmd_buf.as_ref())?;
@@ -213,6 +215,8 @@ impl Global {
213215
});
214216
}
215217

218+
cmd_buf.device.check_is_valid()?;
219+
216220
if !cmd_buf.support_clear_texture {
217221
return Err(ClearError::MissingClearTextureFeature);
218222
}

wgpu-core/src/command/compute.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,13 @@ impl Global {
348348
match cmd_buf_data.lock_encoder() {
349349
Ok(()) => {
350350
drop(cmd_buf_data);
351+
if let Err(err) = cmd_buf.device.check_is_valid() {
352+
return (
353+
ComputePass::new_invalid(cmd_buf, &label, err.map_pass_err(scope)),
354+
None,
355+
);
356+
}
357+
351358
match desc
352359
.timestamp_writes
353360
.as_ref()

wgpu-core/src/command/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,8 @@ impl Global {
11441144
list.push(TraceCommand::PushDebugGroup(label.to_owned()));
11451145
}
11461146

1147+
cmd_buf.device.check_is_valid()?;
1148+
11471149
let cmd_buf_raw = cmd_buf_data.encoder.open()?;
11481150
if !cmd_buf
11491151
.device
@@ -1177,6 +1179,8 @@ impl Global {
11771179
list.push(TraceCommand::InsertDebugMarker(label.to_owned()));
11781180
}
11791181

1182+
cmd_buf.device.check_is_valid()?;
1183+
11801184
if !cmd_buf
11811185
.device
11821186
.instance_flags
@@ -1209,6 +1213,8 @@ impl Global {
12091213
list.push(TraceCommand::PopDebugGroup);
12101214
}
12111215

1216+
cmd_buf.device.check_is_valid()?;
1217+
12121218
let cmd_buf_raw = cmd_buf_data.encoder.open()?;
12131219
if !cmd_buf
12141220
.device

wgpu-core/src/command/query.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,6 @@ impl Global {
367367
.get(command_encoder_id.into_command_buffer_id());
368368
let mut cmd_buf_data = cmd_buf.data.lock();
369369
cmd_buf_data.record_with(|cmd_buf_data| -> Result<(), QueryError> {
370-
cmd_buf
371-
.device
372-
.require_features(wgt::Features::TIMESTAMP_QUERY_INSIDE_ENCODERS)?;
373-
374370
#[cfg(feature = "trace")]
375371
if let Some(ref mut list) = cmd_buf_data.commands {
376372
list.push(TraceCommand::WriteTimestamp {
@@ -379,9 +375,16 @@ impl Global {
379375
});
380376
}
381377

378+
cmd_buf.device.check_is_valid()?;
379+
380+
cmd_buf
381+
.device
382+
.require_features(wgt::Features::TIMESTAMP_QUERY_INSIDE_ENCODERS)?;
383+
382384
let raw_encoder = cmd_buf_data.encoder.open()?;
383385

384386
let query_set = hub.query_sets.get(query_set_id).get()?;
387+
query_set.same_device_as(cmd_buf.as_ref())?;
385388

386389
query_set.validate_and_write_timestamp(raw_encoder, query_index, None)?;
387390

@@ -418,6 +421,8 @@ impl Global {
418421
});
419422
}
420423

424+
cmd_buf.device.check_is_valid()?;
425+
421426
if destination_offset % wgt::QUERY_RESOLVE_BUFFER_ALIGNMENT != 0 {
422427
return Err(QueryError::Resolve(ResolveError::BufferOffsetAlignment));
423428
}

wgpu-core/src/command/ray_tracing.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ impl Global {
7777
cmd_buf_data.record_with(
7878
|cmd_buf_data| -> Result<(), BuildAccelerationStructureError> {
7979
let device = &cmd_buf.device;
80+
device.check_is_valid()?;
8081
device
8182
.require_features(Features::EXPERIMENTAL_RAY_TRACING_ACCELERATION_STRUCTURE)?;
8283

@@ -214,6 +215,7 @@ impl Global {
214215
}
215216

216217
let device = &cmd_buf.device;
218+
device.check_is_valid()?;
217219
device.require_features(Features::EXPERIMENTAL_RAY_TRACING_ACCELERATION_STRUCTURE)?;
218220

219221
let mut buf_storage = Vec::new();

wgpu-core/src/command/render.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,6 +1548,8 @@ impl Global {
15481548
arc_desc: &mut ArcRenderPassDescriptor,
15491549
device: &Device,
15501550
) -> Result<(), RenderPassErrorInner> {
1551+
device.check_is_valid()?;
1552+
15511553
let query_sets = hub.query_sets.read();
15521554
let texture_views = hub.texture_views.read();
15531555

wgpu-core/src/device/global.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,10 @@ impl Global {
654654
trace.add(trace::Action::CreatePipelineLayout(fid.id(), desc.clone()));
655655
}
656656

657+
if let Err(e) = device.check_is_valid() {
658+
break 'error e.into();
659+
}
660+
657661
let bind_group_layouts = {
658662
let bind_group_layouts_guard = hub.bind_group_layouts.read();
659663
desc.bind_group_layouts
@@ -722,6 +726,10 @@ impl Global {
722726
trace.add(trace::Action::CreateBindGroup(fid.id(), desc.clone()));
723727
}
724728

729+
if let Err(e) = device.check_is_valid() {
730+
break 'error e.into();
731+
}
732+
725733
let layout = match hub.bind_group_layouts.get(desc.layout).get() {
726734
Ok(layout) => layout,
727735
Err(e) => break 'error e.into(),
@@ -1250,6 +1258,10 @@ impl Global {
12501258
});
12511259
}
12521260

1261+
if let Err(e) = device.check_is_valid() {
1262+
break 'error e.into();
1263+
}
1264+
12531265
let layout = desc
12541266
.layout
12551267
.map(|layout| hub.pipeline_layouts.get(layout).get())
@@ -1485,6 +1497,10 @@ impl Global {
14851497
});
14861498
}
14871499

1500+
if let Err(e) = device.check_is_valid() {
1501+
break 'error e.into();
1502+
}
1503+
14881504
let layout = desc
14891505
.layout
14901506
.map(|layout| hub.pipeline_layouts.get(layout).get())

wgpu-core/src/device/queue.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,6 +1445,7 @@ impl Queue {
14451445
profiling::scope!("Queue::compact_blas");
14461446
api_log!("Queue::compact_blas");
14471447

1448+
self.device.check_is_valid()?;
14481449
self.same_device_as(blas.as_ref())?;
14491450

14501451
let device = blas.device.clone();

0 commit comments

Comments
 (0)