diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f8abcc209..ae6710dd8f 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 #????): - 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 db9ba51d39..4512118dac 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: tw.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 f06249fc78..ff81e80370 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: tw.beginning_of_pass_write_index,