Skip to content

Commit 83cb0cd

Browse files
author
Aleksander Katan
committed
Add resolved wgsl for compute
1 parent e58b9fd commit 83cb0cd

File tree

1 file changed

+21
-0
lines changed
  • apps/typegpu-docs/src/content/docs/fundamentals/functions

1 file changed

+21
-0
lines changed

apps/typegpu-docs/src/content/docs/fundamentals/functions/index.mdx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,27 @@ const mainCompute = tgpu['~unstable'].computeFn({
171171
}`.$uses({ particleData: particleDataStorage, deltaTime, time });
172172
```
173173

174+
Resolved WGSL for the compute function above is equivalent (with respect to some cleanup) to the following:
175+
176+
```wgsl
177+
@group(0) @binding(0) var<storage, read_write> particleData: array<u32, 100>;
178+
@group(0) @binding(1) var<uniform> deltaTime: f32;
179+
@group(0) @binding(2) var<storage, read_write> time: f32;
180+
181+
struct mainCompute_Input {
182+
@builtin(global_invocation_id) gid: vec3u,
183+
}
184+
185+
@compute @workgroup_size(1) fn mainCompute(in: mainCompute_Input) {
186+
let index = in.gid.x;
187+
if index == 0 {
188+
time += deltaTime;
189+
}
190+
let phase = (time / 300) + particleData[index].seed;
191+
particleData[index].position += particleData[index].velocity * deltaTime / 20 + vec2f(sin(phase) / 600, cos(phase) / 500);
192+
}
193+
```
194+
174195
### Vertex and fragment
175196

176197
`TgpuVertexFn` accepts an object with two properties:

0 commit comments

Comments
 (0)