From f1ec934dbc58958b621a9212168e450ce9496c6d Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Thu, 21 Nov 2024 09:49:20 -0500 Subject: [PATCH] fix(core): validate that begin and end indices of pass timestamp writes are not equal --- CHANGELOG.md | 1 + wgpu-core/src/command/compute.rs | 9 +++++++++ wgpu-core/src/command/mod.rs | 4 ++++ wgpu-core/src/command/render.rs | 8 ++++++++ 4 files changed, 22 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 00b81f6a50..ee63a2bde9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -134,6 +134,7 @@ By @ErichDonGubler in [#6456](https://github.com/gfx-rs/wgpu/pull/6456), [#6148] - 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. - Check that indices are in-bounds for the query set. + - Check that begin and end indices are not equal. #### Naga diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index dc8c6055c5..f27ad1a8bb 100644 --- a/wgpu-core/src/command/compute.rs +++ b/wgpu-core/src/command/compute.rs @@ -345,6 +345,15 @@ impl Global { } } + if let Some((begin, end)) = beginning_of_pass_write_index.zip(end_of_pass_write_index) { + if begin == end { + return make_err( + CommandEncoderError::TimestampWriteIndicesEqual { idx: begin }, + arc_desc, + ); + } + } + Some(ArcPassTimestampWrites { query_set, beginning_of_pass_write_index, diff --git a/wgpu-core/src/command/mod.rs b/wgpu-core/src/command/mod.rs index 6c7b26b786..1f1cafaf5e 100644 --- a/wgpu-core/src/command/mod.rs +++ b/wgpu-core/src/command/mod.rs @@ -654,6 +654,10 @@ pub enum CommandEncoderError { InvalidResource(#[from] InvalidResourceError), #[error(transparent)] MissingFeatures(#[from] MissingFeatures), + #[error( + "begin and end indices of pass timestamp writes are both set to {idx}, which is not allowed" + )] + TimestampWriteIndicesEqual { idx: u32 }, #[error(transparent)] TimestampWritesInvalid(#[from] QueryUseError), } diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index ffec953888..21c9a75f5b 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -1412,6 +1412,14 @@ impl Global { query_set.validate_query(SimplifiedQueryType::Timestamp, idx, None)?; } + if let Some((begin, end)) = + beginning_of_pass_write_index.zip(end_of_pass_write_index) + { + if begin == end { + return Err(CommandEncoderError::TimestampWriteIndicesEqual { idx: begin }); + } + } + Some(ArcPassTimestampWrites { query_set, beginning_of_pass_write_index,