WGSL is the shading language specifically designed for WebGPU. Use this tag for questions about shaders syntax, bugs, usage in WebGPU and implementation details in comparison to other shader languages such as GLSL and HLSL.
Questions tagged [wgsl]
37 questions
5
votes
1 answer
What does storageBarrier in WebGPU actually do?
So I'm exploring WebGPU and figured it would be an interesting exercise to implement a basic neural network in it. Having little understanding of both GPU shader programming and neural networks and my only reference for WebGPU(w3.org/TR/webgpu and…

user81993
- 6,167
- 6
- 32
- 64
4
votes
1 answer
Cellular automata on GPU with WGSL
I am writing a physic simulation which is like a cellular automata. Each steps dependents on the previous one, but more precisely, each cell needs the state of itself and its direct neighbors to compute its new state. I am using two buffers,…

uben
- 1,221
- 2
- 11
- 20
2
votes
1 answer
WGSL atomics with multiple compute passes
I'm having an issue with atomics in wgpu / WGSL but I'm not sure if it's due to a fundamental misunderstanding or a bug in my code.
I have a input array declared in WGSL as
struct FourTileUpdate {
// (u32 = 4 bytes)
data: array

user12638523
- 23
- 3
2
votes
0 answers
How to reduce over an entire dataset in the GPU?
I'm using WebGPU/WGSL compute modules to analyze medium-large datasets (millions of data points) by slicing or sharding the data and making each invocation of the shader work on its own slice of data.
This works fine when data operations are local…

Tobia
- 17,856
- 6
- 74
- 93
2
votes
1 answer
gfx-rs/wgpu wgsl examples uses @ instead of [[]]
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 {
…

NongusStudios
- 119
- 5
1
vote
1 answer
WGSL get different results even using the same data
I am new to WGSL. I am following the tuorial of wgpu to write my first traingle.
The correct shader is like this
// Vertex shader
struct VertexOutput {
@builtin(position) clip_position: vec4,
@location(0) position:…

qiuweikang
- 47
- 4
1
vote
0 answers
type numbers to names in wgsl
I have recently tried to save a arrayLength(&inArr) into i32 but I ended up getting this error.
┌─ gpu_test:24:9
│
24 │ outArr[i] = arrLen;
│ ^^^^^^^^^ naga::Expression [40]
Entry point main at Compute is invalid
…

LAYTOR
- 381
- 4
- 12
1
vote
1 answer
z and w components of position vector act like they are switched in WGSL
I have the following WGSL shader that creates a triangle:
struct Vertex {
@builtin(position) position : vec4,
@location(0) color : vec4,
}
@vertex
fn vMain(@builtin(vertex_index) vertexIndex: u32) -> Vertex {
var positions =…

luek baja
- 1,475
- 8
- 20
1
vote
1 answer
Writing a full game in WGSL?
The goal would be to get the optimum of performance, when every major calculation is done on the GPU, to make huge simulations in the browser possible, to achieve something like the
powdertoy or more advanced.
And since WebGPU shipped on chrome, it…

Hutzlibu
- 114
- 5
1
vote
0 answers
How to dynamically index array inside array that is stored as storage in wgsl
I have the following structure that represents a 3D VoxelGrid:
var chunks: array;
struct Chunk {
position: vec3,
metadata: u32,
data: array, CHUNK_DATA_SIZE>,
};
I had to use a vector inside the…

BrunoWallner
- 417
- 3
- 10
1
vote
1 answer
How to use Storage Buffers in WGPU to store dynamic sized arrays
I am working on a Pathtracer that uses the fragment-shader to render onto a Texture.
Currently I only render Spheres that are stored as a UniformBuffer like this:
var geometry: Geometry;
struct Geometry {
sphere_count: u32,
spheres:…

BrunoWallner
- 417
- 3
- 10
1
vote
1 answer
Is there any way to pass a callback to a function in WGSL?
I can't seem to figure out how or if it is acually possible to pass acallback to a function in WGSL. I would like to make something along these lines.
fn foo(x: f32, bar: ?callback?) {
bar(x);
}
fn baz(y: f32) -> f32 {
return y +…

not Sam
- 23
- 5
1
vote
2 answers
How do vec attributes/accessors work in wgsl
Hi this is a simple question.
I'm trying to read and understand a shader function which makes use of vec3 variable types.
I don't understand what is that .zzzz key for:
var myvar: vec3 = vec3(1.3, 3.3, 3.3);
myvar.zzzz; // ??
…

commonUser
- 599
- 1
- 6
- 17
1
vote
1 answer
WebGPU WGLSL error occurs following outdated tutorials: "access mode 'write' is not valid for the 'storage' address space"
Note: I've answered my own question here, and am posting so that others in the same situation may benefit.
I was following along with various WebGPU tutorials, in particular for compute shaders, these articles in particular:…

ChaseMoskal
- 7,151
- 5
- 37
- 50
1
vote
3 answers
Using mat4x4 as uniform in WGSL
Is it possible to use a mat4x4 as a uniform data type in WGSL?
I get the following error when doing so:
Shader validation error:
┌─ Shader:18:4
│
18 │ var model: mat4x4;
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^…

junglie85
- 1,243
- 10
- 30