Skip to content

Simplifications and improvements to WGSL syntax #1466

@lain-dono

Description

@lain-dono
  1. Remove trailing ; for struct declaration. Current syntax is awful.
struct Data {
    a: i32;
    b: vec<f32>;
}                  🠔 no semicolon here!
  1. Remove parentheses from if, switch, etc. Example:
if alpha < 0.5 {
    discard;
}
  1. Use separate syntax for struct, block, uniform, etc. Examples:
struct Data {
    a: i32;
    b: vec<f32>;
}

block Data {
    a: i32;
    b: vec<f32>;
}

uniform viewport: Viewport {
    size: vec2<f32>;
    ivn_size: vec2<f32>;
}
  1. Remove : from variable, struct members and function arguments declaration. Examples:
var foo f32 = 1.234;

struct Data {
    a i32            🠔 makes sense without semicolon here
    a vec<f32>       after all, there is an end-of-line character
}

fn foo(a f32, b f32) -> bool { .. }
fn foo(a, b f32) -> bool { .. }        🠔 optional variant
  1. Remove -> from function declaration (between args and body): fn foo(a: f32, b: f32) bool { .. }.
  2. In addition to simd-types from vec4<f32> is too hard to type on the keyboard #736. New syntax for arrays and pointers:
[f32]         🠔 array without size
[f32; 4]      🠔 array with size
[[f32; 3]; 4] 🠔 nested array

*f32          🠔 without storage class
*private f32  🠔 with storage class
  1. To eliminate ambiguity with (5) a new syntax for attributes:
#[location(0), input, read_only] var position f32x4;    🠔 use attributes instead of pseudo-generics

#[group(2), binding(0)]
uniform viewport Viewport {
    size     f32x2
    ivn_size f32x2
}
  1. In addition to (3) it is possible to make ; optional.
var foo i32 = 42
foo = 3 * 7

Metadata

Metadata

Assignees

No one assigned

    Labels

    wgslWebGPU Shading Language Issues

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions