Skip to content

Commit b22d123

Browse files
ErichDonGublercwfitzgerald
authored andcommitted
fix(core): check query set index before other validation (#7908)
1 parent dd32435 commit b22d123

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Bottom level categories:
4444

4545
- Fixed build error inside `wgpu::util::initialize_adapter_from_env` when `std` feature is not enabled. By @kpreid in [#7918](https://github.com/gfx-rs/wgpu/pull/7918).
4646
- Fixed build error occurring when the `profiling` dependency is configured to have profiling active. By @kpreid in [#7916](https://github.com/gfx-rs/wgpu/pull/7916).
47+
- Emit a validation error instead of panicking when a query set index is OOB. By @ErichDonGubler in [#7908](https://github.com/gfx-rs/wgpu/pull/7908).
4748

4849
## v26.0.0 (2025-07-09)
4950

cts_runner/test.lst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ webgpu:api,validation,encoding,programmable,pipeline_bind_group_compat:bind_grou
4343
webgpu:api,validation,encoding,programmable,pipeline_bind_group_compat:bind_groups_and_pipeline_layout_mismatch:encoderType="render%20pass";*
4444
webgpu:api,validation,encoding,programmable,pipeline_bind_group_compat:buffer_binding,render_pipeline:*
4545
webgpu:api,validation,encoding,programmable,pipeline_bind_group_compat:sampler_binding,render_pipeline:*
46+
webgpu:api,validation,encoding,queries,general:occlusion_query,query_index:*
4647
webgpu:api,validation,image_copy,layout_related:copy_end_overflows_u64:*
4748
webgpu:api,validation,image_copy,texture_related:format:dimension="1d";*
4849
webgpu:api,validation,queue,submit:command_buffer,device_mismatch:*

wgpu-core/src/command/query.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,14 @@ impl QuerySet {
210210
query_index: u32,
211211
reset_state: Option<&mut QueryResetMap>,
212212
) -> Result<(), QueryUseError> {
213+
// NOTE: Further code assumes the index is good, so do this first.
214+
if query_index >= self.desc.count {
215+
return Err(QueryUseError::OutOfBounds {
216+
query_index,
217+
query_set_size: self.desc.count,
218+
});
219+
}
220+
213221
// We need to defer our resets because we are in a renderpass,
214222
// add the usage to the reset map.
215223
if let Some(reset) = reset_state {
@@ -227,13 +235,6 @@ impl QuerySet {
227235
});
228236
}
229237

230-
if query_index >= self.desc.count {
231-
return Err(QueryUseError::OutOfBounds {
232-
query_index,
233-
query_set_size: self.desc.count,
234-
});
235-
}
236-
237238
Ok(())
238239
}
239240

0 commit comments

Comments
 (0)