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

Bad global type in WGSL causes create_shader_module to panic, not return an error #2583

Closed
jimblandy opened this issue Apr 7, 2022 · 1 comment · Fixed by #2584
Closed
Labels
area: validation Issues related to validation, diagnostics, and error handling type: bug Something isn't working

Comments

@jimblandy
Copy link
Member

If you call wgpu_core::Global::create_shader_module with WGSL that has a var<uniform> of type mat2x2<f32>, and an entry point that uses it, the module passes Naga validation, but wgpu_core::validation::Interface::new panics.

To reproduce:

use anyhow::Result; // anyhow = "1"
use futures_executor::block_on; // futures-executor = "0.3"

fn main() -> Result<()> {
    let instance = wgpu::Instance::new(wgpu::Backends::VULKAN);

    let (device, queue) = block_on(async {
        let adapter = instance.request_adapter(&wgpu::RequestAdapterOptions::default())
            .await
            .expect("request_adapter returned None");
        adapter.request_device(&wgpu::DeviceDescriptor {
            label: Some("play-wgpu device"),
            features: wgpu::Features::default(),
            limits: wgpu::Limits::default(),
        },
                               None).await
    })?;

    let module = device.create_shader_module(&wgpu::ShaderModuleDescriptor {
        label: Some("play-wgpu shader module"),
        source: wgpu::ShaderSource::Wgsl("
            @group(0) @binding(0) var<uniform> xform: mat2x2<f32>;
            @stage(compute) @workgroup_size(32) fn main() { let use_it = xform; }
        ".into())
    });

    drop((module, queue));

    Ok(())
}

Because xform has an unexpected type for a global, there is no entry created for it in Interface::new's resource_mapping table, and then trying to push the EntryPoint::resources entry for main's use of xform panics.

@jimblandy jimblandy added type: bug Something isn't working area: validation Issues related to validation, diagnostics, and error handling labels Apr 7, 2022
@jimblandy
Copy link
Member Author

I think I know what happened here:

jimblandy added a commit to jimblandy/wgpu that referenced this issue Apr 7, 2022
jimblandy added a commit to jimblandy/wgpu that referenced this issue Apr 15, 2022
jimblandy added a commit to jimblandy/wgpu that referenced this issue Apr 18, 2022
jimblandy added a commit that referenced this issue Apr 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: validation Issues related to validation, diagnostics, and error handling type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant