From b17c30338d37a15fcf0ee737de4d9aff6d3baeac Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Thu, 21 Nov 2024 09:16:40 -0500 Subject: [PATCH] fix(core): validate `TIMESTAMP_QUERY` feature before other query set validation in pass creation --- CHANGELOG.md | 2 ++ wgpu-core/src/command/compute.rs | 18 ++++++++++-------- wgpu-core/src/command/render.rs | 3 ++- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dee57f6e78..137724e88b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -131,6 +131,8 @@ By @ErichDonGubler in [#6456](https://github.com/gfx-rs/wgpu/pull/6456), [#6148] - Lower `QUERY_SET_MAX_QUERIES` (and enforced limits) from 8192 to 4096 to match WebGPU spec. By @ErichDonGubler in [#6525](https://github.com/gfx-rs/wgpu/pull/6525). - Allow non-filterable float on texture bindings never used with samplers when using a derived bind group layout. By @ErichDonGubler in [#6531](https://github.com/gfx-rs/wgpu/pull/6531/). - Replace potentially unsound usage of `PreHashedMap` with `FastHashMap`. By @jamienicol in [#6541](https://github.com/gfx-rs/wgpu/pull/6541). +- Add missing validation for timestamp writes in compute and render passes. By @ErichDonGubler in [#6578](https://github.com/gfx-rs/wgpu/pull/6578). + - Check the status of the `TIMESTAMP_QUERY` feature before other validation. #### Naga diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index 28e76c1115..747fddb0d0 100644 --- a/wgpu-core/src/command/compute.rs +++ b/wgpu-core/src/command/compute.rs @@ -309,14 +309,6 @@ 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) @@ -325,6 +317,16 @@ 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), + }; + + match query_set.same_device(&cmd_buf.device) { + Ok(()) => (), + 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 ad3a5b6ca3..db03e1c156 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -1393,10 +1393,11 @@ impl Global { arc_desc.timestamp_writes = if let Some(tw) = desc.timestamp_writes { let query_set = query_sets.get(tw.query_set).get()?; - query_set.same_device(device)?; device.require_features(wgt::Features::TIMESTAMP_QUERY)?; + query_set.same_device(device)?; + Some(ArcPassTimestampWrites { query_set, beginning_of_pass_write_index: tw.beginning_of_pass_write_index,