schell / schell/wgsl-rs

`0 & 0== 0` compiles but produces invalid wgsl

Open
#159 1 comment 0 reactions 0 assignees View on GitHub
bug P1
Dominant language
Rust
Stars
61
Forks
4
Avg merge
1d 21h
Merged PRs (30d)
9

Description

```rust
#[wgsl]
pub mod my_shader {
#[compute]
#[workgroup_size(1, 1, 1)]
pub fn compute() {
let x = 0 & 0 == 0;
}
}
```

compiles successfully, but when you try to use the wgsl:
```
Shader 'compute' parsing error: failed to convert expression to a concrete type
┌─ wgsl:62:13

62 │ let x = 0 & 0 == 0;
│ ^^^^^^^^^^ this expression has type {AbstractInt}

= note: the expression couldn't be converted to have i32 scalar type: Subexpression(s) are not constant
= note: the expression couldn't be converted to have u32 scalar type: Subexpression(s) are not constant
= note: the expression couldn't be converted to have f32 scalar type: Subexpression(s) are not constant
```
if you change it to `0u32 & 0u32 == 0u32`, you get:

```
Shader validation error: Entry point compute at Compute is invalid
┌─ compute:62:13

62 │ let x = 0u & 0u == 0u;
│ ^^^^^^^^^^^^^ naga::ir::Expression [2]

= Expression [2] is invalid
= Operation And can't work with [0] (of type Scalar(Scalar { kind: Uint, width: 4 })) and [1] (of type Scalar(Scalar { kind: Bool, width: 1 }))

Expression [2] is invalid
Operation And can't work with [0] (of type Scalar(Scalar { kind: Uint, width: 4 })) and [1] (of type Scalar(Scalar { kind: Bool, width: 1 }))
```

looks like the operator precedence of Rust and WGSL is different 😭

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the `#[wgsl]` example with `0 & 0 == 0` and inspect the generated WGSL and its validation errors. Trace the `#[wgsl]` attribute macro's expression parsing and operator-precedence handling, then confirm that the generated expression is accepted by WGSL validation.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.