gfx-rs/wgpu wgsl examples uses @ instead of [[]]

505 views Asked by At

I have been learning wgpu over the past few days and I have one point of confusion. When I browse athe wgpu examples (https://github.com/gfx-rs/wgpu/tree/master/wgpu/examples) they use this syntax for their shaders:

struct VertexOutput {
    @location(0)       color:    vec4<f32>,
    @builtin(position) position: vec4<f32>,
}

but I have to write my shaders like this:

struct VertexOutput {
    [[location(0)]]       color:    vec4<f32>;
    [[builtin(position)]] position: vec4<f32>;
};

I much prefer the @ syntax to the [[]] syntax. My guess is that it is a feature I need to enable in my Cargo.toml but I have not been able to find out what feature this is. So if someone could tell me how to use the @ syntax in my wgsl shaders it would be much appreciated.

1

There are 1 answers

0
frankenapps On BEST ANSWER

I guess you currently use wgpu version 0.12.0 from crates.io?

The @ syntax is the new updated syntax from the webgpu spec. The latest released version of wgpu however still uses the old syntax.

If you want to use the new syntax now, you can use the master branch from git like so (in your Cargo.toml):

wgpu = { git = "https://github.com/gfx-rs/wgpu" }

Update

wgpu version 0.13 was released in the meantime, so you can now use

wgpu = "0.13"

to get the new wgsl syntax.