Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command encoding validation should not emit errors before CommandEncoder::finish #7391

Open
ErichDonGubler opened this issue Mar 21, 2025 · 0 comments
Assignees

Comments

@ErichDonGubler
Copy link
Member

Many WebGPU CTS tests exercise validation of command encoders with error scopes used this way:

  1. Set up a device and a command encoder.
  2. Do something invalid during command encoding, like using an occlusion query in a GPURenderPassDescriptor.timestampWrites.
  3. Push an error scope, finish the command encoder, and pop an error scope to check if there was a validation error.

WGPU emits errors for validation during command encoding before calling CommandEncoder::finish, and it shouldn't. It's difficult to cite spec. text that is not present, but the easiest way to summarize is that "generate a validation error" does not show up in the validation steps performed by the various methods of GPUCommandEncoder and {Compute,Render}PassEncoder except for GPUCommandEncoder.finish.

Steps to reproduce

[package]
name = "wgpu-cmd-enc-finish-validation-bruh"
version = "0.1.0"
edition = "2024"

[dependencies]
pollster = "0.4.0"
wgpu = { git = "https://github.com/gfx-rs/wgpu", rev = "1e172b2e1461724eb7ded00b6520732db1c5ae92" }
use pollster::FutureExt as _;

fn main() {
    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 occlusion_query = device.create_query_set(&wgpu::QuerySetDescriptor {
        label: None,
        ty: wgpu::QueryType::Occlusion,
        count: 1,
    });

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

    {
        let mut _render_pass = command_encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
            timestamp_writes: Some(wgpu::RenderPassTimestampWrites {
                query_set: &occlusion_query,
                beginning_of_pass_write_index: Some(0),
                end_of_pass_write_index: Some(1),
            }),
            ..Default::default()
        });
    }

    device.push_error_scope(wgpu::ErrorFilter::Validation);
    let _cmd_buf = command_encoder.finish();
    device.pop_error_scope().block_on().unwrap();

    queue.submit([_cmd_buf]);
}

Suggested implementation design

  1. The MVP for this is to stop emitting validation errors on CommandEncoder, RenderPassEncoder, and ComputePassEncoder methods. These methods already invalidate the associated CommandEncoder and other objects when failing validation, so no action should be needed there.
  2. The above loses some significant diagnostic quality. We'll probably want to store the first validation error a command encoder encounters, to counter this.

This issue is likely to become a meta issue, since the API surface to which this issue applies is pretty broad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

1 participant