From 5936fe58f4eb429e51f29cc8b80204660e5d4159 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Tue, 5 Nov 2024 16:09:21 -0500 Subject: [PATCH] fix: check for device mismatch in `create_{render,compute}_pass` --- CHANGELOG.md | 1 + wgpu-core/src/command/compute.rs | 13 ++++++++----- wgpu-core/src/command/render.rs | 9 +++++++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a9928c90..de11b3045 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -63,6 +63,7 @@ Bottom level categories: #### General - Ensure that `Features::TIMESTAMP_QUERY` is set when using timestamp writes in render and compute passes. By @ErichDonGubler in [#6497](https://github.com/gfx-rs/wgpu/pull/6497). +- Check for device mismatches when beginning render and compute passes. By @ErichDonGubler in [#6497](https://github.com/gfx-rs/wgpu/pull/6497). ## 23.0.0 (2024-10-25) diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index 4bc6839ec..93654c923 100644 --- a/wgpu-core/src/command/compute.rs +++ b/wgpu-core/src/command/compute.rs @@ -308,6 +308,14 @@ impl Global { }; arc_desc.timestamp_writes = if let Some(tw) = desc.timestamp_writes { + let query_set = match hub.query_sets.get(tw.query_set).get() { + Ok(query_set) => query_set, + Err(e) => return make_err(e.into(), arc_desc), + }; + match query_set.same_device(&cmd_buf.device) { + Ok(()) => (), + Err(e) => return make_err(e.into(), arc_desc), + } match cmd_buf .device .require_features(wgt::Features::TIMESTAMP_QUERY) @@ -316,11 +324,6 @@ impl Global { Err(e) => return make_err(e.into(), arc_desc), } - let query_set = match hub.query_sets.get(tw.query_set).get() { - Ok(query_set) => query_set, - Err(e) => return make_err(e.into(), arc_desc), - }; - Some(ArcPassTimestampWrites { query_set, beginning_of_pass_write_index: tw.beginning_of_pass_write_index, diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index fef6fcad9..6102d0d49 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -1358,9 +1358,11 @@ impl Global { }) = color_attachment { let view = texture_views.get(*view_id).get()?; + view.same_device(device)?; let resolve_target = if let Some(resolve_target_id) = resolve_target { let rt_arc = texture_views.get(*resolve_target_id).get()?; + rt_arc.same_device(device)?; Some(rt_arc) } else { @@ -1382,6 +1384,7 @@ impl Global { arc_desc.depth_stencil_attachment = if let Some(depth_stencil_attachment) = desc.depth_stencil_attachment { let view = texture_views.get(depth_stencil_attachment.view).get()?; + view.same_device(device)?; Some(ArcRenderPassDepthStencilAttachment { view, @@ -1393,9 +1396,10 @@ impl Global { }; arc_desc.timestamp_writes = if let Some(tw) = desc.timestamp_writes { - device.require_features(wgt::Features::TIMESTAMP_QUERY)?; - let query_set = query_sets.get(tw.query_set).get()?; + query_set.same_device(device)?; + + device.require_features(wgt::Features::TIMESTAMP_QUERY)?; Some(ArcPassTimestampWrites { query_set, @@ -1409,6 +1413,7 @@ impl Global { arc_desc.occlusion_query_set = if let Some(occlusion_query_set) = desc.occlusion_query_set { let query_set = query_sets.get(occlusion_query_set).get()?; + query_set.same_device(device)?; Some(query_set) } else {