Skip to content

Commit 54ce5f9

Browse files
authored
chore: Rename 'dispatch' to 'dispatchThreads' (#1828)
1 parent 4db4b07 commit 54ce5f9

File tree

10 files changed

+44
-44
lines changed

10 files changed

+44
-44
lines changed

apps/typegpu-docs/src/content/docs/fundamentals/utils.mdx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ description: A list of various utilities provided by TypeGPU.
66
## *prepareDispatch*
77

88
The `prepareDispatch` function streamlines running simple computations on the GPU.
9-
Under the hood, it wraps the callback in a `TgpuFn`, creates a compute pipeline, and returns an object with dispatch method that executes the pipeline.
9+
Under the hood, it wraps the callback in a `TgpuFn`, creates a compute pipeline, and returns an object with a `dispatchThreads` method that executes the pipeline.
1010
Since the pipeline is reused, there’s no additional overhead for subsequent calls.
1111

1212
```ts twoslash
@@ -21,9 +21,9 @@ const doubleUp = root['~unstable'].prepareDispatch((x) => {
2121
data.$[x] *= 2;
2222
});
2323

24-
doubleUp.dispatch(8);
25-
doubleUp.dispatch(8);
26-
doubleUp.dispatch(4);
24+
doubleUp.dispatchThreads(8);
25+
doubleUp.dispatchThreads(8);
26+
doubleUp.dispatchThreads(4);
2727

2828
// the command encoder will queue the read after `doubleUp`
2929
console.log(await data.read()); // [0, 8, 16, 24, 16, 20, 24, 28]
@@ -55,7 +55,7 @@ root['~unstable'].prepareDispatch((x, y) => {
5555
'use gpu';
5656
randf.seed2(d.vec2f(x, y).div(1024));
5757
waterLevelMutable.$[x][y] = 10 + randf.sample();
58-
}).dispatch(1024, 512);
58+
}).dispatchThreads(1024, 512);
5959
// callback will be called for x in range 0..1023 and y in range 0..511
6060

6161
// (optional) read values in JS
@@ -89,8 +89,8 @@ const test = root['~unstable'].prepareDispatch((x) => {
8989
layout.$.buffer[x] *= 2;
9090
});
9191

92-
test.with(bindGroup1).dispatch(3);
93-
test.with(bindGroup2).dispatch(4);
92+
test.with(bindGroup1).dispatchThreads(3);
93+
test.with(bindGroup2).dispatchThreads(4);
9494

9595
console.log(await buffer1.read()); // [2, 4, 6];
9696
console.log(await buffer2.read()); // [4, 8, 16, 32];
@@ -135,8 +135,8 @@ const compute = root['~unstable'].prepareDispatch(() => {
135135
console.log('Call number', callCountMutable.$);
136136
});
137137

138-
compute.dispatch();
139-
compute.dispatch();
138+
compute.dispatchThreads();
139+
compute.dispatchThreads();
140140

141141
// Eventually...
142142
// "[GPU] Call number 1"

apps/typegpu-docs/src/examples/rendering/3d-fish/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ const randomizeFishPositionsOnGPU = root['~unstable'].prepareDispatch((x) => {
124124

125125
const randomizeFishPositions = () => {
126126
seedUniform.write((performance.now() % 10000) / 10000);
127-
randomizeFishPositionsOnGPU.dispatch(p.fishAmount);
127+
randomizeFishPositionsOnGPU.dispatchThreads(p.fishAmount);
128128
enqueuePresetChanges();
129129
};
130130

@@ -256,7 +256,7 @@ function frame(timestamp: DOMHighResTimeStamp) {
256256

257257
simulateAction
258258
.with(computeBindGroups[odd ? 1 : 0])
259-
.dispatch(p.fishAmount);
259+
.dispatchThreads(p.fishAmount);
260260

261261
renderPipeline
262262
.withColorAttachment({

apps/typegpu-docs/src/examples/simple/increment/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const gpuIncrement = root['~unstable'].prepareDispatch(() => {
1313

1414
async function increment() {
1515
// Dispatch and read the result
16-
gpuIncrement.dispatch();
16+
gpuIncrement.dispatchThreads();
1717
return await counter.read();
1818
}
1919

apps/typegpu-docs/src/examples/simulation/boids-next/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ function frame() {
270270

271271
simulateAction
272272
.with(computeBindGroups[even ? 0 : 1])
273-
.dispatch(triangleAmount);
273+
.dispatchThreads(triangleAmount);
274274

275275
renderPipeline
276276
.withColorAttachment({

apps/typegpu-docs/src/examples/simulation/fluid-double-buffering/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -496,17 +496,17 @@ function makePipelines(
496496

497497
return {
498498
init() {
499-
initWorldAction.dispatch(gridSize, gridSize);
499+
initWorldAction.dispatchThreads(gridSize, gridSize);
500500
},
501501

502502
applyMovedObstacles(bufferData: d.Infer<BoxObstacle>[]) {
503503
obstacles.write(bufferData);
504-
moveObstaclesAction.dispatch();
504+
moveObstaclesAction.dispatchThreads();
505505
prevObstacles.write(bufferData);
506506
},
507507

508508
compute() {
509-
simulateAction.dispatch(gridSize, gridSize);
509+
simulateAction.dispatchThreads(gridSize, gridSize);
510510
},
511511

512512
render() {

apps/typegpu-docs/src/examples/simulation/slime-mold-3d/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ root['~unstable'].prepareDispatch((x) => {
113113
const center = resolution.div(2);
114114
const dir = std.normalize(center.sub(pos));
115115
agentsData.$[x] = Agent({ position: pos, direction: dir });
116-
}).dispatch(NUM_AGENTS);
116+
}).dispatchThreads(NUM_AGENTS);
117117

118118
const params = root.createUniform(Params, {
119119
deltaTime: 0,

apps/typegpu-docs/src/examples/tests/dispatch/index.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ async function test0d(): Promise<boolean> {
1616
root['~unstable'].prepareDispatch(() => {
1717
'use gpu';
1818
mutable.$ = 126;
19-
}).dispatch();
19+
}).dispatchThreads();
2020
const filled = await mutable.read();
2121
return isEqual(filled, 126);
2222
}
@@ -27,7 +27,7 @@ async function test1d(): Promise<boolean> {
2727
root['~unstable'].prepareDispatch((x) => {
2828
'use gpu';
2929
mutable.$[x] = x;
30-
}).dispatch(...size);
30+
}).dispatchThreads(...size);
3131
const filled = await mutable.read();
3232
return isEqual(filled, [0, 1, 2, 3, 4, 5, 6]);
3333
}
@@ -40,7 +40,7 @@ async function test2d(): Promise<boolean> {
4040
root['~unstable'].prepareDispatch((x, y) => {
4141
'use gpu';
4242
mutable.$[x][y] = d.vec2u(x, y);
43-
}).dispatch(...size);
43+
}).dispatchThreads(...size);
4444
const filled = await mutable.read();
4545
return isEqual(filled, [
4646
[d.vec2u(0, 0), d.vec2u(0, 1), d.vec2u(0, 2)],
@@ -59,7 +59,7 @@ async function test3d(): Promise<boolean> {
5959
root['~unstable'].prepareDispatch((x, y, z) => {
6060
'use gpu';
6161
mutable.$[x][y][z] = d.vec3u(x, y, z);
62-
}).dispatch(...size);
62+
}).dispatchThreads(...size);
6363
const filled = await mutable.read();
6464
return isEqual(filled, [
6565
[[d.vec3u(0, 0, 0), d.vec3u(0, 0, 1)]],
@@ -72,7 +72,7 @@ async function testWorkgroupSize(): Promise<boolean> {
7272
root['~unstable'].prepareDispatch((x, y, z) => {
7373
'use gpu';
7474
std.atomicAdd(mutable.$, 1);
75-
}).dispatch(4, 3, 2);
75+
}).dispatchThreads(4, 3, 2);
7676
const filled = await mutable.read();
7777
return isEqual(filled, 4 * 3 * 2);
7878
}
@@ -85,9 +85,9 @@ async function testMultipleDispatches(): Promise<boolean> {
8585
'use gpu';
8686
mutable.$[x] *= 2;
8787
});
88-
test.dispatch(6);
89-
test.dispatch(2);
90-
test.dispatch(4);
88+
test.dispatchThreads(6);
89+
test.dispatchThreads(2);
90+
test.dispatchThreads(4);
9191
const filled = await mutable.read();
9292
return isEqual(filled, [0 * 8, 1 * 8, 2 * 4, 3 * 4, 4 * 2, 5 * 2, 6 * 1]);
9393
}
@@ -114,8 +114,8 @@ async function testDifferentBindGroups(): Promise<boolean> {
114114
}
115115
});
116116

117-
test.with(bindGroup1).dispatch();
118-
test.with(bindGroup2).dispatch();
117+
test.with(bindGroup1).dispatchThreads();
118+
test.with(bindGroup2).dispatchThreads();
119119

120120
const filled1 = await buffer1.read();
121121
const filled2 = await buffer2.read();
@@ -131,8 +131,8 @@ async function testSlots(): Promise<boolean> {
131131
result.$ += valueSlot.$;
132132
};
133133

134-
root['~unstable'].prepareDispatch(main).dispatch(); // add 1
135-
root['~unstable'].with(valueSlot, 3).prepareDispatch(main).dispatch(); // add 3
134+
root['~unstable'].prepareDispatch(main).dispatchThreads(); // add 1
135+
root['~unstable'].with(valueSlot, 3).prepareDispatch(main).dispatchThreads(); // add 3
136136

137137
return await result.read() === 4;
138138
}

apps/typegpu-docs/src/examples/tests/log-test/index.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,29 +53,29 @@ export const controls = {
5353
root['~unstable'].prepareDispatch(() => {
5454
'use gpu';
5555
console.log(d.u32(321));
56-
}).dispatch(),
56+
}).dispatchThreads(),
5757
},
5858
'Multiple arguments': {
5959
onButtonClick: () =>
6060
root['~unstable'].prepareDispatch(() => {
6161
'use gpu';
6262
console.log(1, d.vec3u(2, 3, 4), 5, 6);
63-
}).dispatch(),
63+
}).dispatchThreads(),
6464
},
6565
'String literals': {
6666
onButtonClick: () =>
6767
root['~unstable'].prepareDispatch(() => {
6868
'use gpu';
6969
console.log(2, 'plus', 3, 'equals', 5);
70-
}).dispatch(),
70+
}).dispatchThreads(),
7171
},
7272
'Two logs': {
7373
onButtonClick: () =>
7474
root['~unstable'].prepareDispatch(() => {
7575
'use gpu';
7676
console.log('First log.');
7777
console.log('Second log.');
78-
}).dispatch(),
78+
}).dispatchThreads(),
7979
},
8080
'Different types': {
8181
onButtonClick: () =>
@@ -119,7 +119,7 @@ export const controls = {
119119
} else {
120120
console.log("The 'shader-f16' flag is not enabled.");
121121
}
122-
}).dispatch(),
122+
}).dispatchThreads(),
123123
},
124124
'Compound types': {
125125
onButtonClick: () => {
@@ -144,15 +144,15 @@ export const controls = {
144144

145145
const complexArray = ComplexArray([[3, 4], [5, 6], [7, 8]]);
146146
console.log(complexArray);
147-
}).dispatch();
147+
}).dispatchThreads();
148148
},
149149
},
150150
'Two threads': {
151151
onButtonClick: () =>
152152
root['~unstable'].prepareDispatch((x) => {
153153
'use gpu';
154154
console.log('Log from thread', x);
155-
}).dispatch(2),
155+
}).dispatchThreads(2),
156156
},
157157
'100 dispatches': {
158158
onButtonClick: async () => {
@@ -163,7 +163,7 @@ export const controls = {
163163
});
164164
for (let i = 0; i < 100; i++) {
165165
indexUniform.write(i);
166-
test.dispatch();
166+
test.dispatchThreads();
167167
}
168168
},
169169
},
@@ -177,9 +177,9 @@ export const controls = {
177177
}
178178
});
179179
logCountUniform.write(3);
180-
test.dispatch();
180+
test.dispatchThreads();
181181
logCountUniform.write(1);
182-
test.dispatch();
182+
test.dispatchThreads();
183183
},
184184
},
185185
'Render pipeline': {
@@ -235,7 +235,7 @@ export const controls = {
235235
console.log('Log 1 from thread', x);
236236
console.log('Log 2 from thread', x);
237237
console.log('Log 3 from thread', x);
238-
}).dispatch(16),
238+
}).dispatchThreads(16),
239239
},
240240
};
241241

packages/typegpu/src/core/root/init.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ export class PreparedDispatchImpl<TArgs extends number[]>
177177
* Unlike `TgpuComputePipeline.dispatchWorkgroups()`,
178178
* this method takes in the number of threads to run in each dimension.
179179
*/
180-
dispatch(...threads: TArgs): void {
180+
dispatchThreads(...threads: TArgs): void {
181181
const sanitizedSize = toVec3(threads);
182182
const workgroupCount = ceil(
183183
vec3f(sanitizedSize).div(vec3f(this.#workgroupSize)),

packages/typegpu/src/core/root/rootTypes.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export interface PreparedDispatch<TArgs extends number[]> {
9090
* Unlike `TgpuComputePipeline.dispatchWorkgroups()`,
9191
* this method takes in the number of threads to run in each dimension.
9292
*/
93-
dispatch(...args: TArgs): void;
93+
dispatchThreads(...args: TArgs): void;
9494
}
9595

9696
export interface WithCompute {
@@ -220,7 +220,7 @@ export interface WithBinding {
220220
* console.log('Hello, GPU!');
221221
* });
222222
*
223-
* action.dispatch();
223+
* action.dispatchThreads();
224224
* ```
225225
*
226226
* @example
@@ -232,7 +232,7 @@ export interface WithBinding {
232232
* console.log('I am the', x, 'thread');
233233
* });
234234
*
235-
* action.dispatch(12); // executing 12 threads
235+
* action.dispatchThreads(12); // executing 12 threads
236236
* ```
237237
*/
238238
prepareDispatch<TArgs extends number[]>(

0 commit comments

Comments
 (0)