WebGPU

3.2 Conceptos básicos de sintaxis de WGSL

En general, la sintaxis es similar (WGSL es un lenguaje de sombreado, por lo que la comunicación con las GPU sigue siendo prácticamente la misma), pero con algunas peculiaridades, especialmente al usar tanto WGSL como GLSL (4.5) en mi motor WebGPU, dgel. Por lo tanto, compartiré mis hallazgos aquí. Hagamos una comparación de características individual.

3.2.1 Scalar and matrix types

First off, even though the specs says that ‘Plain’ types in WGSL are similar to ‘Plain-Old-Data’ types in C++, you also very much feel the influence of Rust in the design.

The bool (true/false) behaves tha same but for other scalars it seems somehow very important for you to know that they are 32-bit.

With WGSL, the component type needs to be specified in angle brackets e.g. a vector with 4 int elements is vec4<32>. Very explicit.

If you were thinking of rejecting this new type syntax and just alias them, well sorry to disappoint but type `vec4 = vec4<32>; will fail as vec4 is a reserved word.

The matrix types are also very verbose: matNxM<f32> with N columns and M rows (2, 3, 4 each) of floats. No shorthand here.

It is also not possible to generate the ‘identity matrix’ as easily as with mat4(1.0). At least, they are still column-major.

At the time of writing, you can only pass vectors to construct the matrix