Skip to content

Commit eb17b31

Browse files
fix(core): validate bounds of timestamp write indices in compute passes
1 parent d0b9929 commit eb17b31

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

wgpu-core/src/command/compute.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,8 @@ impl Global {
313313
arc_desc.timestamp_writes = if let Some(tw) = desc.timestamp_writes {
314314
let &PassTimestampWrites {
315315
query_set,
316-
beginning_of_pass_write_index: _,
317-
end_of_pass_write_index: _,
316+
beginning_of_pass_write_index,
317+
end_of_pass_write_index,
318318
} = tw;
319319

320320
match cmd_buf
@@ -335,6 +335,16 @@ impl Global {
335335
Err(e) => return make_err(e.into(), arc_desc),
336336
}
337337

338+
for idx in [beginning_of_pass_write_index, end_of_pass_write_index]
339+
.into_iter()
340+
.flatten()
341+
{
342+
match query_set.validate_query(SimplifiedQueryType::Timestamp, idx, None) {
343+
Ok(()) => (),
344+
Err(e) => return make_err(e.into(), arc_desc),
345+
}
346+
}
347+
338348
Some(ArcPassTimestampWrites {
339349
query_set,
340350
beginning_of_pass_write_index: tw.beginning_of_pass_write_index,

wgpu-core/src/command/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,8 @@ pub enum CommandEncoderError {
654654
InvalidResource(#[from] InvalidResourceError),
655655
#[error(transparent)]
656656
MissingFeatures(#[from] MissingFeatures),
657+
#[error(transparent)]
658+
TimestampWritesInvalid(#[from] QueryUseError),
657659
}
658660

659661
impl Global {

wgpu-core/src/command/query.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ pub enum ResolveError {
160160
}
161161

162162
impl QuerySet {
163-
fn validate_query(
163+
pub(crate) fn validate_query(
164164
self: &Arc<Self>,
165165
query_type: SimplifiedQueryType,
166166
query_index: u32,

wgpu-core/src/command/render.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::binding_model::BindGroup;
22
use crate::command::{
33
validate_and_begin_occlusion_query, validate_and_begin_pipeline_statistics_query,
4+
SimplifiedQueryType,
45
};
56
use crate::init_tracker::BufferInitTrackerAction;
67
use crate::pipeline::RenderPipeline;
@@ -1394,8 +1395,8 @@ impl Global {
13941395
arc_desc.timestamp_writes = if let Some(tw) = desc.timestamp_writes {
13951396
let &PassTimestampWrites {
13961397
query_set,
1397-
beginning_of_pass_write_index: _,
1398-
end_of_pass_write_index: _,
1398+
beginning_of_pass_write_index,
1399+
end_of_pass_write_index,
13991400
} = tw;
14001401

14011402
let query_set = query_sets.get(query_set).get()?;
@@ -1404,6 +1405,13 @@ impl Global {
14041405

14051406
query_set.same_device(device)?;
14061407

1408+
for idx in [beginning_of_pass_write_index, end_of_pass_write_index]
1409+
.into_iter()
1410+
.flatten()
1411+
{
1412+
query_set.validate_query(SimplifiedQueryType::Timestamp, idx, None)?;
1413+
}
1414+
14071415
Some(ArcPassTimestampWrites {
14081416
query_set,
14091417
beginning_of_pass_write_index: tw.beginning_of_pass_write_index,

0 commit comments

Comments
 (0)