Skip to content

Commit b314b44

Browse files
committed
Merge branch 'main' into feat/noise-utils-xoroshiro
2 parents 7963f69 + 1e92af8 commit b314b44

255 files changed

Lines changed: 13057 additions & 3067 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<div align="center">
22

3-
![TypeGPU (light mode)](./apps/typegpu-docs/public/typegpu-logo-light.svg#gh-light-mode-only)
4-
![TypeGPU (dark mode)](./apps/typegpu-docs/public/typegpu-logo-dark.svg#gh-dark-mode-only)
3+
<picture>
4+
<source srcset="https://typegpu.com/typegpu-logo-dark.svg" media="(prefers-color-scheme: dark)" />
5+
<img src="https://typegpu.com/typegpu-logo-light.svg" />
6+
</picture>
57

68
[Website](https://docs.swmansion.com/TypeGPU)
79
[Documentation](https://docs.swmansion.com/TypeGPU/getting-started)

apps/typegpu-docs/astro.config.mjs

Lines changed: 88 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ export default defineConfig({
7474
navigation: 'none',
7575
}),
7676
starlightTypeDoc({
77+
sidebar: {
78+
label: 'Reference',
79+
},
7780
entryPoints: [
7881
'../../packages/typegpu/src/index.d.ts',
7982
'../../packages/typegpu/src/data/index.ts',
@@ -115,110 +118,105 @@ export default defineConfig({
115118
},
116119
{
117120
label: 'Fundamentals',
121+
items: stripFalsy([
122+
{
123+
label: 'Your first GPU program',
124+
slug: 'fundamentals/your-first-gpu-program',
125+
badge: { text: 'new' },
126+
},
127+
{
128+
label: 'Going parallel with reusable resources',
129+
slug: 'fundamentals/compute-shaders',
130+
badge: { text: 'new' },
131+
},
132+
{
133+
label: 'Vertices and fragments',
134+
slug: 'fundamentals/vertices-and-fragments',
135+
badge: { text: 'new' },
136+
},
137+
]),
138+
},
139+
{
140+
label: 'APIs',
118141
items: stripFalsy([
119142
{
120143
label: 'Roots',
121-
slug: 'fundamentals/roots',
144+
slug: 'apis/roots',
122145
},
123146
{
124147
label: 'Functions',
125-
slug: 'fundamentals/functions',
148+
slug: 'apis/functions',
126149
},
127150
{
128151
label: 'Pipelines',
129-
slug: 'fundamentals/pipelines',
152+
slug: 'apis/pipelines',
130153
badge: { text: 'new' },
131154
},
132155
{
133156
label: 'Buffers',
134-
slug: 'fundamentals/buffers',
157+
slug: 'apis/buffers',
135158
},
136159
{
137160
label: 'Textures',
138-
slug: 'fundamentals/textures',
161+
slug: 'apis/textures',
139162
badge: { text: 'new' },
140163
},
141164
{
142165
label: 'Variables',
143-
slug: 'fundamentals/variables',
166+
slug: 'apis/variables',
144167
},
145168
{
146169
label: 'Data Schemas',
147-
slug: 'fundamentals/data-schemas',
170+
slug: 'apis/data-schemas',
148171
},
149172
{
150173
label: 'Bind Groups',
151-
slug: 'fundamentals/bind-groups',
174+
slug: 'apis/bind-groups',
152175
},
153176
{
154177
label: 'Resolve',
155-
slug: 'fundamentals/resolve',
178+
slug: 'apis/resolve',
156179
},
157180
{
158181
label: 'Vertex Layouts',
159-
slug: 'fundamentals/vertex-layouts',
160-
},
161-
{
162-
label: 'Enabling Features',
163-
slug: 'fundamentals/enabling-features',
164-
},
165-
{
166-
label: 'Timing Your Pipelines',
167-
slug: 'fundamentals/timestamp-queries',
182+
slug: 'apis/vertex-layouts',
168183
},
184+
169185
{
170186
label: 'Slots',
171-
slug: 'fundamentals/slots',
187+
slug: 'apis/slots',
172188
},
173189
{
174190
label: 'Accessors',
175-
slug: 'fundamentals/accessors',
191+
slug: 'apis/accessors',
176192
},
177193
{
178194
label: 'Utilities',
179-
slug: 'fundamentals/utils',
195+
slug: 'apis/utils',
180196
badge: { text: 'new' },
181197
},
182-
// {
183-
// label: 'Basic Principles',
184-
// slug: 'guides/basic-principles',
185-
// },
186-
// {
187-
// label: 'State Management',
188-
// slug: 'guides/state-management',
189-
// },
190-
// {
191-
// label: 'Parametrized Functions',
192-
// slug: 'guides/parametrized-functions',
193-
// },
194198
]),
195199
},
196200
{
197-
label: 'Ecosystem',
201+
label: 'Advanced',
198202
items: stripFalsy([
199203
{
200-
label: '@typegpu/noise',
201-
slug: 'ecosystem/typegpu-noise',
202-
},
203-
{
204-
label: '@typegpu/three',
205-
slug: 'ecosystem/typegpu-three',
206-
},
207-
{
208-
label: '@typegpu/sdf',
209-
slug: 'ecosystem/typegpu-sdf',
204+
label: 'Enabling Features',
205+
slug: 'advanced/enabling-features',
210206
},
211207
{
212-
label: '@typegpu/radiance-cascades',
213-
slug: 'ecosystem/typegpu-radiance-cascades',
208+
label: 'Timing Your Pipelines',
209+
slug: 'advanced/timestamp-queries',
214210
},
215211
DEV && {
216-
label: '@typegpu/color',
217-
slug: 'ecosystem/typegpu-color',
212+
label: 'Naming Convention',
213+
slug: 'advanced/naming-convention',
214+
badge: { text: 'dev', variant: 'note' },
218215
},
219216
DEV && {
220-
label: 'Third-party',
221-
slug: 'ecosystem/third-party',
217+
label: 'Shader Generation',
218+
slug: 'advanced/shader-generation',
219+
badge: { text: 'dev', variant: 'note' },
222220
},
223221
]),
224222
},
@@ -244,20 +242,37 @@ export default defineConfig({
244242
]),
245243
},
246244
{
247-
label: 'Tooling',
245+
label: 'Ecosystem',
248246
items: stripFalsy([
249247
{
250-
label: 'Build Plugin',
251-
slug: 'tooling/unplugin-typegpu',
248+
label: '@typegpu/noise',
249+
slug: 'ecosystem/typegpu-noise',
252250
},
253251
{
254-
label: 'Lint Plugin',
255-
slug: 'tooling/eslint-plugin-typegpu',
256-
badge: { text: 'new' },
252+
label: '@typegpu/three',
253+
slug: 'ecosystem/typegpu-three',
257254
},
258255
{
259-
label: 'Generator CLI',
260-
slug: 'tooling/tgpu-gen',
256+
label: '@typegpu/react',
257+
slug: 'ecosystem/typegpu-react',
258+
},
259+
{
260+
label: '@typegpu/sdf',
261+
slug: 'ecosystem/typegpu-sdf',
262+
},
263+
{
264+
label: '@typegpu/radiance-cascades',
265+
slug: 'ecosystem/typegpu-radiance-cascades',
266+
},
267+
DEV && {
268+
label: '@typegpu/color',
269+
slug: 'ecosystem/typegpu-color',
270+
badge: { text: 'dev', variant: 'note' },
271+
},
272+
DEV && {
273+
label: 'Third-party',
274+
slug: 'ecosystem/third-party',
275+
badge: { text: 'dev', variant: 'note' },
261276
},
262277
]),
263278
},
@@ -267,27 +282,34 @@ export default defineConfig({
267282
{
268283
label: 'From a Triangle to Simulating Boids: Step-by-step Tutorial',
269284
slug: 'tutorials/triangle-to-boids',
285+
badge: { text: 'dev', variant: 'note' },
270286
},
271287
{
272288
label: 'Game of life tutorial',
273289
slug: 'tutorials/game-of-life',
290+
badge: { text: 'dev', variant: 'note' },
274291
},
275292
],
276293
},
277294
{
278-
label: 'Reference',
295+
label: 'Tooling',
279296
items: stripFalsy([
280-
DEV && {
281-
label: 'Naming Convention',
282-
slug: 'reference/naming-convention',
297+
{
298+
label: 'Build Plugin',
299+
slug: 'tooling/unplugin-typegpu',
283300
},
284-
DEV && {
285-
label: 'Shader Generation',
286-
slug: 'reference/shader-generation',
301+
{
302+
label: 'Lint Plugin',
303+
slug: 'tooling/eslint-plugin-typegpu',
304+
badge: { text: 'new' },
305+
},
306+
{
307+
label: 'Generator CLI',
308+
slug: 'tooling/tgpu-gen',
287309
},
288-
typeDocSidebarGroup,
289310
]),
290311
},
312+
typeDocSidebarGroup,
291313
]),
292314
}),
293315
react(),

apps/typegpu-docs/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@
3232
"@typegpu/geometry": "workspace:*",
3333
"@typegpu/noise": "workspace:*",
3434
"@typegpu/radiance-cascades": "workspace:*",
35+
"@typegpu/react": "workspace:*",
3536
"@typegpu/sdf": "workspace:*",
3637
"@typegpu/sort": "workspace:*",
3738
"@typegpu/three": "workspace:*",
38-
"@types/react": "^19.1.8",
39-
"@types/react-dom": "^19.1.6",
39+
"@types/react": "^19.2.14",
40+
"@types/react-dom": "^19.2.3",
4041
"arktype": "catalog:",
4142
"astro": "^6.0.8",
4243
"classnames": "^2.5.1",
@@ -51,8 +52,8 @@
5152
"motion": "^12.23.24",
5253
"onnxruntime-web": "1.23.0-dev.20250917-21fbad8a65",
5354
"pathe": "^2.0.3",
54-
"react": "^19.1.0",
55-
"react-dom": "^19.1.0",
55+
"react": "catalog:",
56+
"react-dom": "catalog:",
5657
"rehype-mathjax": "^7.1.0",
5758
"remark-math": "^6.0.0",
5859
"remeda": "^2.21.2",
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import type { ReactNode } from 'react';
2+
import { d, type TgpuGuardedComputePipeline, type TgpuMutable, type TgpuRoot } from 'typegpu';
3+
import {
4+
createExampleRoot,
5+
LinearCellGrid,
6+
RunnablePreviewHeader,
7+
RunnableSnippet,
8+
} from './runnable/index.ts';
9+
10+
const VALUE_COUNT = 16;
11+
const ValuesSchema = d.arrayOf(d.u32, VALUE_COUNT);
12+
13+
export const COMPUTE_SHADER_ARRAY_SNIPPET = `import tgpu, { d } from 'typegpu';
14+
15+
const root = await tgpu.init();
16+
17+
const valuesMutable = root.createMutable(d.arrayOf(d.u32, 16));
18+
19+
const program = root.createGuardedComputePipeline((x) => {
20+
'use gpu';
21+
valuesMutable.$[x]++;
22+
});
23+
24+
export async function execute() {
25+
const threadCount = Math.floor(Math.random() * 16) + 1;
26+
program.dispatchThreads(threadCount);
27+
28+
return {
29+
threadCount,
30+
values: await valuesMutable.read(),
31+
};
32+
}
33+
`;
34+
35+
type ArrayProgram = {
36+
program: TgpuGuardedComputePipeline<[number]>;
37+
root: TgpuRoot;
38+
valuesMutable: TgpuMutable<typeof ValuesSchema>;
39+
};
40+
41+
type ArrayResult = {
42+
threadCount: number;
43+
values: readonly number[];
44+
};
45+
46+
const INITIAL_VALUES: readonly number[] = Array.from({ length: VALUE_COUNT }, () => 0);
47+
48+
async function createArrayProgram(): Promise<ArrayProgram> {
49+
const root = await createExampleRoot();
50+
const valuesMutable = root.createMutable(ValuesSchema);
51+
52+
const program = root.createGuardedComputePipeline((x) => {
53+
'use gpu';
54+
valuesMutable.$[x]++;
55+
});
56+
57+
return { program, root, valuesMutable };
58+
}
59+
60+
type Props = {
61+
children: ReactNode;
62+
};
63+
64+
export default function ComputeShadersArrayExample({ children }: Props) {
65+
return (
66+
<RunnableSnippet<ArrayProgram, ArrayResult>
67+
createProgram={() => createArrayProgram()}
68+
preview={({ lastResult }) => {
69+
const threadCount = lastResult?.threadCount ?? 0;
70+
const values = lastResult?.values ?? INITIAL_VALUES;
71+
72+
return (
73+
<>
74+
<RunnablePreviewHeader
75+
label="Values"
76+
value={
77+
threadCount === 0
78+
? 'Not run'
79+
: `${threadCount} thread${threadCount === 1 ? '' : 's'}`
80+
}
81+
/>
82+
<LinearCellGrid columns={VALUE_COUNT} highlightCount={threadCount} values={values} />
83+
</>
84+
);
85+
}}
86+
run={async ({ program, valuesMutable }) => {
87+
const threadCount = Math.floor(Math.random() * VALUE_COUNT) + 1;
88+
program.dispatchThreads(threadCount);
89+
const values = await valuesMutable.read();
90+
return { threadCount, values: [...values] };
91+
}}
92+
>
93+
{children}
94+
</RunnableSnippet>
95+
);
96+
}

0 commit comments

Comments
 (0)