Skip to content

OOB query indices panic #7906

@ErichDonGubler

Description

@ErichDonGubler

If one tries to use a OOB query index, we panic, instead of as the WebGPU spec. demands. This example, for instance, should run successfully, but instead crashes:

use pollster::FutureExt;

fn main() {
    env_logger::init();

    let instance = wgpu::Instance::new(&Default::default());
    let adapter = instance
        .request_adapter(&Default::default())
        .block_on()
        .unwrap();
    let (device, _queue) = adapter
        .request_device(&Default::default())
        .block_on()
        .unwrap();

    let num_query_sets = 2;

    let query_set = device.create_query_set(&wgpu::QuerySetDescriptor {
        label: None,
        ty: wgpu::QueryType::Occlusion,
        count: num_query_sets,
    });

    let color_attachment = device.create_texture(&wgpu::TextureDescriptor {
        label: None,
        size: wgpu::Extent3d {
            width: 16,
            height: 16,
            depth_or_array_layers: 1,
        },
        mip_level_count: 1,
        sample_count: 1,
        dimension: wgpu::TextureDimension::D2,
        format: wgpu::TextureFormat::Rgba8Unorm,
        usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
        view_formats: &[],
    });

    let color_attachment_view = color_attachment.create_view(&Default::default());

    // Begin interesting part of this test.

    let mut command_encoder = device.create_command_encoder(&Default::default());

    device.push_error_scope(wgpu::ErrorFilter::Validation);

    {
        let mut render_pass = command_encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
            label: None,
            occlusion_query_set: Some(&query_set),
            color_attachments: &[Some(wgpu::RenderPassColorAttachment {
                view: &color_attachment_view,
                resolve_target: None,
                ops: wgpu::Operations {
                    load: wgpu::LoadOp::Clear(wgpu::Color::TRANSPARENT),
                    store: wgpu::StoreOp::Store,
                },
                depth_slice: Default::default(),
            })],
            depth_stencil_attachment: None,
            timestamp_writes: None,
        });
        render_pass.begin_occlusion_query(num_query_sets); // NOTE: Invalid, because we're OOB.
        render_pass.end_occlusion_query();
    }

    let _cmd_buf = command_encoder.finish();

    device.push_error_scope(wgpu::ErrorFilter::Validation);
}

The above is a converted example from the webgpu:api,validation,encoding,queries,general:occlusion_query,query_index:* CTS test.

Metadata

Metadata

Labels

area: correctnessWe're behaving incorrectlyarea: ctsIssues stemming from the WebGPU Conformance Test Suitetype: bugSomething isn't working

Type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions