From 114be5e0def3730dc39d0e0b262d4bb3eed183f7 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 --- wgpu-core/src/command/compute.rs | 9 +++++++++ wgpu-core/src/command/mod.rs | 4 ++++ wgpu-core/src/command/render.rs | 8 ++++++++ 3 files changed, 21 insertions(+) diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index 9b0026f504..9f89dead1d 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,