gfx-rs/wgpu · error

IMMEDIATES feature must be enabled to call set_immediates

Error message

IMMEDIATES feature must be enabled to call set_immediates

What it means

The WebGPU backend does not support immediates (push-constants-style inline data), so ComputePassEncoder::set_immediates is unimplemented there and wgpu panics. Callers must not invoke it when running on WebGPU.

Source

Thrown at wgpu/src/backend/webgpu.rs:3650

        let bind_group = bind_group.map(|bind_group| &bind_group.as_webgpu().inner);

        if offsets.is_empty() {
            self.inner.set_bind_group(index, bind_group);
        } else {
            self.inner
                .set_bind_group_with_u32_slice_and_f64_and_dynamic_offsets_data_length(
                    index,
                    bind_group,
                    offsets,
                    0f64,
                    offsets.len() as u32,
                )
                .unwrap();
        }
    }

    fn set_immediates(&mut self, _offset: u32, _data: &[u8]) {
        panic!("IMMEDIATES feature must be enabled to call set_immediates")
    }

    fn insert_debug_marker(&mut self, label: &str) {
        self.inner.insert_debug_marker(label);
    }

    fn push_debug_group(&mut self, group_label: &str) {
        self.inner.push_debug_group(group_label);
    }

    fn pop_debug_group(&mut self) {
        self.inner.pop_debug_group();
    }

    fn write_timestamp(&mut self, _query_set: &dispatch::DispatchQuerySet, _query_index: u32) {
        panic!("TIMESTAMP_QUERY_INSIDE_PASSES feature must be enabled to call write_timestamp in a compute pass.")
    }

View on GitHub (pinned to 3e11ff59bf)

Solutions

  1. Do not call set_immediates on the WebGPU backend; gate the call on backend detection.
  2. Use a bind group with a dynamic uniform buffer instead of immediates.
  3. Restrict immediates-dependent pipelines to native backends and check capabilities at startup.
  4. Route per-dispatch data through uniform/storage buffers.

Example fix

// before
compute_pass.set_immediates(0, bytemuck::bytes_of(&data));
// after
if !is_webgpu {
    compute_pass.set_immediates(0, bytemuck::bytes_of(&data));
} else {
    compute_pass.set_bind_group(0, &uniform_bg, &[offset]);
}
Defensive patterns

Strategy: validation

Validate before calling

if !is_webgpu_backend(device) { pass.set_immediates(0, &data); } else { /* bind-group path */ }

Type guard

fn supports_immediates(b: Backend) -> bool { b != Backend::Browser }

Prevention

When it happens

Trigger: Calling set_immediates(offset, data) on a compute pass encoder while running on the webgpu backend, even if the pipeline layout declares immediate data ranges.

Common situations: Pipelines ported from native (Vulkan push constants / DX12 root constants) to wasm; shared per-dispatch uniform updates relying on immediates; missing runtime or cfg gating for the web backend.

Related errors


AI-assisted analysis of gfx-rs/wgpu@3e11ff59bf (2026-09-03). Data as JSON: /api/errors/119007e9ef1ae29b. Report an issue: GitHub.