Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion apps/typegpu-docs/src/content/docs/apis/functions/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ const pipeline = root.createGuardedComputePipeline(() => {

pipeline.dispatchThreads();

// 🚫🚫🚫 This is NOT allowed 🚫🚫🚫
// ‼️ This does NOT affect the pipeline, since it was already compiled
settings.speed = 1.5;

// the shader doesn't get recompiled with the new value
Expand All @@ -277,6 +277,36 @@ There are explicit mechanisms that allow you to achieve this:
- [Use buffers to efficiently share data between the CPU and GPU](/TypeGPU/apis/buffers)
- [Use variables to share state between functions](/TypeGPU/apis/variables)

:::caution
All external values are assumed to be constant during resolution.
This includes values mutated by [comptime](/TypeGPU/apis/utils/#tgpucomptime) functions.

```ts twoslash
import { tgpu } from 'typegpu';
// ---cut---
let state = 0;
const getState = () => { 'use gpu'; return state; };
const incrementState = tgpu.comptime(() => { state++; });

const main = () => {
'use gpu';
// Resolution goes from top to bottom
const a = getState(); // Generates a `getState` that returns 0
incrementState(); // `state` is now 1
const b = getState(); // ‼️ Reuses the `getState` function that returns 0
};

console.log(tgpu.resolve([main]));
// fn getState() -> i32 {
// return 0;
// }
// fn main() {
// let a = getState();
// let b = getState();
// }
```
:::

### Supported JavaScript functionality

You can generally assume that all JavaScript syntax is supported, and in the occasion that it is not, we'll throw a
Expand Down
Loading