Skip to content

Brain dump on all things wrong with WGSL #2048

@morganbarrett

Description

@morganbarrett

So WGSL is meant to be the de facto shader language for the web, designed solely for the needs of the web. The cpu equivalent of this is Javascript which is obviously what WGSL is used with. So my main question would be why it takes inspiration (in terms of purely syntactical sugar) from everything but Javascript and its influencers. Below are all the idiosyncrasies that annoy me and are sure to cause trouble for anyone starting out in the future.

Loop

I don't understand what is to be gained by loop {...if(cond){ break; }...}, why not while and do while, it is trivial to translate.

(De)increment

Like this is an easy one, no? The prefix version at least.

Let

I don't even need to explain this one, let should be const.

Fn

Same goes as above, this should be function surely?

Vec3<f32>

I've seen this one mentioned already, I'm assuming one can't make a vector of a custom structure, if so the abstract type thing really doesn't make sense and is a pain in the ass to write. vec4f vec2i vec3u this sort of thing?

->

The type hinting already very closely resembles typescript/flow, so it might make more sense to take inspiration from here for return types. Instead of fn test(i: u32) -> u32 { would be better as function test(i: u32): u32 {.

std

I've seen the standard library mentioned as well and for the sake of learning curve, code completion and coming from js, would work better modularised e.g Math.cos(x) Vector.dot(x, y) Array.length(arr).

[[block]]

The double bracket expressions would be more familiar as @ expressions.

Blockless ifs

if(true) hi();

420u

I think unsigned ints should be un postfixed and signed ints should start with +/-.

Storage

var<uniform> blah do something, anything, differently.

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