Skip to content

Conversation

@ErichDonGubler
Copy link
Member

@ErichDonGubler ErichDonGubler commented Jun 13, 2025

While looking at Firefox's CTS results for webgpu:shader,validation,expression,call,builtin,max:values:*, I found an issue which, minimized as this small WGPU application:

# Cargo.toml

[package]
name = "tmp-a05txx"
version = "0.1.0"
edition = "2024"

[dependencies]
# wgpu = { git = "https://github.com/gfx-rs/wgpu", rev = "620c9d1e8bcdede08a76134692babd6ccc004ecb" }
wgpu = { path = "/Users/mozilla/workspace/wgpu/wgpu/" }
env_logger = "*"
pollster = "*"
// src/main.rs

use pollster::FutureExt as _;

fn main() {
    let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor {
        backends: wgpu::Backends::PRIMARY, // & !wgpu::Backends::VULKAN,
        ..Default::default()
    });
    let adapter = instance
        .request_adapter(&Default::default())
        .block_on()
        .unwrap();

    let (device, _queue) = adapter
        .request_device(&wgpu::DeviceDescriptor {
            required_features: wgpu::Features::SHADER_F16,
            ..Default::default()
        })
        .block_on()
        .unwrap();

    let source = "enable f16;
override o0 : f16;
override o1 : f16;
var<private> v  = max(f16(o0), f16(o1));

@workgroup_size(1) @compute
fn main() {
    _ = o0;
    _ = o1;
    _ = v;
}";

    let module = device.create_shader_module(wgpu::ShaderModuleDescriptor {
        label: None,
        source: wgpu::ShaderSource::Wgsl(source.into()),
    });

    let _ = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
        label: None,
        layout: None,
        module: &module,
        entry_point: None,
        compilation_options: wgpu::PipelineCompilationOptions {
            constants: &[("o0", -65504.), ("o1", -65504.)],
            ..Default::default()
        },
        cache: None,
    });
}

…crashes like this:

thread 'main' panicked at <snip>/wgpu/naga/src/back/pipeline_constants.rs:969:14:
internal error: entered unreachable code
stack backtrace:
   0: __rustc::rust_begin_unwind
             at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/std/src/panicking.rs:697:5
   1: core::panicking::panic_fmt
             at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/core/src/panicking.rs:75:14
   2: core::panicking::panic
             at /rustc/17067e9ac6d7ecb70e50f92c1944e545188d2359/library/core/src/panicking.rs:145:5
   3: naga::back::pipeline_constants::map_value_to_literal
             at <snip>/wgpu/naga/src/back/pipeline_constants.rs:969:14
   4: naga::back::pipeline_constants::process_override
             at <snip>/wgpu/naga/src/back/pipeline_constants.rs:307:42
   5: naga::back::pipeline_constants::process_overrides
             at <snip>/wgpu/naga/src/back/pipeline_constants.rs:145:38
   6: wgpu_hal::metal::device::<impl wgpu_hal::metal::Device>::load_shader
             at <snip>/wgpu/wgpu-hal/src/metal/device.rs:137:37
   7: wgpu_hal::metal::device::<impl wgpu_hal::Device for wgpu_hal::metal::Device>::create_compute_pipeline::{{closure}}
             at <snip>/wgpu/wgpu-hal/src/metal/device.rs:1358:17
   8: objc::rc::autorelease::autoreleasepool
             at <snip>/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/objc-0.2.7/src/rc/autorelease.rs:29:5
   9: wgpu_hal::metal::device::<impl wgpu_hal::Device for wgpu_hal::metal::Device>::create_compute_pipeline
             at <snip>/wgpu/wgpu-hal/src/metal/device.rs:1340:9
  10: <D as wgpu_hal::dynamic::device::DynDevice>::create_compute_pipeline
             at <snip>/wgpu/wgpu-hal/src/dynamic/device.rs:451:18
  11: wgpu_core::device::resource::Device::create_compute_pipeline
             at <snip>/wgpu/wgpu-core/src/device/resource.rs:3017:22
  12: wgpu_core::device::global::<impl wgpu_core::global::Global>::device_create_compute_pipeline
             at <snip>/wgpu/wgpu-core/src/device/global.rs:1513:34
  13: <wgpu::backend::wgpu_core::CoreDevice as wgpu::dispatch::DeviceInterface>::create_compute_pipeline
             at <snip>/wgpu/wgpu/src/backend/wgpu_core.rs:1436:13
  14: wgpu::api::device::Device::create_compute_pipeline
             at <snip>/wgpu/wgpu/src/api/device.rs:249:24
  15: tmp_a05txx::main
             at ./src/main.rs:38:13
  16: core::ops::function::FnOnce::call_once
             at <snip>/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Testing

webgpu:shader,validation,expression,call,builtin,max:values:* crashes before this change, and PASSes afterwards. 😤

Squash or Rebase?

sqoosh

Checklist

  • If this contains user-facing changes, add a CHANGELOG.md entry.

@ErichDonGubler ErichDonGubler requested review from a team and crowlKats as code owners June 13, 2025 05:38
@ErichDonGubler
Copy link
Member Author

I don't think @crowlKats' review needs to block on this, since this is adding coverage for the CTS.

@ErichDonGubler ErichDonGubler force-pushed the f16-pipeline-constants branch from adbfd79 to 2c9e80c Compare June 13, 2025 05:44
@ErichDonGubler
Copy link
Member Author

This panicking seems to go as far back as initial support for f16s with #5701. 👀

@ErichDonGubler ErichDonGubler added type: bug Something isn't working area: correctness We're behaving incorrectly area: cts Issues stemming from the WebGPU Conformance Test Suite naga Shader Translator area: naga processing Passes over IR in the middle labels Jun 13, 2025
Copy link
Contributor

@andyleiserson andyleiserson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@andyleiserson andyleiserson merged commit f96ac55 into gfx-rs:trunk Jun 13, 2025
55 checks passed
@ErichDonGubler ErichDonGubler deleted the f16-pipeline-constants branch August 6, 2025 00:48
sharmajai pushed a commit to sharmajai/wgpu that referenced this pull request Oct 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: correctness We're behaving incorrectly area: cts Issues stemming from the WebGPU Conformance Test Suite area: naga processing Passes over IR in the middle naga Shader Translator type: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants