Skip to content

Conversation

@mooori
Copy link
Contributor

@mooori mooori commented Dec 16, 2025

Connections

Fixes #8442

Description

Usage of dynamically sized arrays is restricted to a few special cases. let a = array<f32>() is trying to construct the ZeroValue of a dynamically sized array, which is not allowed. With this PR, ZeroValue construction of dynamically sized arrays gets validated out.

Compiling the wgsl from #8442 doesn't crash naga anymore but instead throws an error:

$ RUST_BACKTRACE=1 cargo run -p naga-cli -- canary.wgsl canary.hlsl

[ERROR naga::valid::zero_value] Constructing zero value of runtime-sized array
error: Entry point main at Compute is invalid
  ┌─ canary.wgsl:3:13
  │
3 │     let a = array<f32>();
  │             ^^^^^^^^^^^ naga::ir::Expression [0]
  │
  = Expression [0] is invalid
  = ZeroValue construction of runtime-sized array is not allowed

Testing

Adds test zero_value_dyn_array_error.

Squash or Rebase?

Squash

Checklist

  • Run cargo fmt.
  • Run taplo format.
  • Run cargo clippy --tests. If applicable, add:
    • --target wasm32-unknown-unknown
  • Run cargo xtask test to run tests.
  • If this contains user-facing changes, add a CHANGELOG.md entry.

@mooori mooori changed the title Fix zero val dyn arr fix(naga): crash on zero value of runtime-sized array Dec 16, 2025
@mooori mooori changed the title fix(naga): crash on zero value of runtime-sized array fix(naga): crash on zero value of dynamically-sized array Dec 17, 2025
@mooori mooori marked this pull request as ready for review December 17, 2025 11:23
@ErichDonGubler ErichDonGubler changed the title fix(naga): crash on zero value of dynamically-sized array fix(naga): don't crash on zero value of dynamically-sized array Dec 19, 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.

There is a relevant CTS test webgpu:shader,validation,expression,call,builtin,value_constructor:array_zero_value:case="invalid_rta", but it isn't failing, because it expects any validation error, and is getting one related to constructibility. (I'm looking at fixing this in the CTS.)

There are also some related CTS tests that expose other broken cases (atomics, override-sized arrays). Also see #4720.

Submitting as comments right now, but this is all nits, there's nothing here that is essential to fix before merging this.

@andyleiserson
Copy link
Contributor

There is a relevant CTS test webgpu:shader,validation,expression,call,builtin,value_constructor:array_zero_value:case="invalid_rta", but it isn't failing, because it expects any validation error, and is getting one related to constructibility. (I'm looking at fixing this in the CTS.)

gpuweb/cts#4550 has my proposed change to the CTS.

@mooori mooori requested a review from andyleiserson January 6, 2026 17:13
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.

Thanks for the contribution!

@andyleiserson andyleiserson enabled auto-merge (squash) January 7, 2026 01:44
@andyleiserson andyleiserson merged commit 6e55831 into gfx-rs:trunk Jan 7, 2026
53 checks passed
@mooori mooori deleted the fix-zero-val-dyn-arr branch January 7, 2026 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[hlsl-out] let a = array<f32>(); causes a crash

3 participants