Skip to content

Commit d9601fd

Browse files
committed
Merge branch 'main' into docs/stable-fn-guide
2 parents 5f58f90 + b4d3183 commit d9601fd

File tree

115 files changed

+2787
-3681
lines changed

Some content is hidden

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

115 files changed

+2787
-3681
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ out our [Official Docs](https://docs.swmansion.com/TypeGPU/getting-started)!
180180

181181
- [packages/unplugin-typegpu](/packages/unplugin-typegpu) - Plugin for your
182182
favorite bundler, enabling TypeGPU shader functions to be written in JS.
183-
- [packages/tgpu-jit](/packages/tgpu-jit) - Just-In-Time transpiler for TypeGPU.
184183
- [packages/tgpu-gen](/packages/tgpu-gen) - CLI tool for automatic TypeGPU code
185184
generation.
186185

apps/typegpu-docs/src/components/ExampleLayout.tsx

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import cs from 'classnames';
22
import { useAtom, useAtomValue } from 'jotai';
3-
import { useId, useRef, useState } from 'react';
3+
import { useId, useRef } from 'react';
44
import CrossSvg from '../assets/cross.svg';
55
import DiscordIconSvg from '../assets/discord-icon.svg';
66
import GithubIconSvg from '../assets/github-icon.svg';
@@ -14,6 +14,7 @@ import ExamplePage from './ExamplePage.tsx';
1414
import { SearchableExampleList } from './SearchableExampleList.tsx';
1515
import { Button } from './design/Button.tsx';
1616
import { Toggle } from './design/Toggle.tsx';
17+
import { experimentalExamplesShownAtom } from '../utils/examples/showExperimentalExamplesAtom.ts';
1718

1819
export function ExampleLayout() {
1920
const menuShown = useAtomValue(menuShownAtom);
@@ -49,13 +50,11 @@ export function ExampleLayout() {
4950
);
5051
}
5152

52-
const experimentalShowingLSKey = 'experimental-showing';
53-
5453
function SideMenu() {
5554
const menuShown = useAtomValue(menuShownAtom);
5655
const [menuShownMobile, setMenuShownMobile] = useAtom(menuShownMobileAtom);
57-
const [experimentalShowing, setExperimentalShowing] = useState(
58-
localStorage.getItem(experimentalShowingLSKey) === 'true',
56+
const [experimentalShowing, setExperimentalShowing] = useAtom(
57+
experimentalExamplesShownAtom,
5958
);
6059
const scrollRef = useRef<HTMLDivElement>(null);
6160
const experimentalExamplesToggleId = useId();
@@ -82,14 +81,8 @@ function SideMenu() {
8281
</div>
8382
<div className='absolute top-5 right-5 md:hidden'>
8483
{menuShownMobile && (
85-
<Button
86-
onClick={() => setMenuShownMobile(false)}
87-
>
88-
<img
89-
src={CrossSvg.src}
90-
alt='Close menu'
91-
className='h-3 w-3'
92-
/>
84+
<Button onClick={() => setMenuShownMobile(false)}>
85+
<img src={CrossSvg.src} alt='Close menu' className='h-3 w-3' />
9386
</Button>
9487
)}
9588
</div>
@@ -99,10 +92,7 @@ function SideMenu() {
9992
<hr className='my-0 box-border w-full border-tameplum-100 border-t' />
10093
</div>
10194

102-
<div
103-
className='my-5 min-h-0 flex-1 overflow-y-auto px-5'
104-
ref={scrollRef}
105-
>
95+
<div className='my-5 min-h-0 flex-1 overflow-y-auto px-5' ref={scrollRef}>
10696
<section className='mb-5 space-y-2 border-tameplum-100 border-b pb-5'>
10797
<h1 className='font-medium text-lg'>Welcome to examples page</h1>
10898
<p className='text-sm'>
@@ -138,14 +128,7 @@ function SideMenu() {
138128
<Toggle
139129
id={experimentalExamplesToggleId}
140130
checked={experimentalShowing}
141-
onChange={(e) => {
142-
const checked = e.target.checked;
143-
localStorage.setItem(
144-
experimentalShowingLSKey,
145-
checked ? 'true' : 'false',
146-
);
147-
setExperimentalShowing(checked);
148-
}}
131+
onChange={(e) => setExperimentalShowing(e.target.checked)}
149132
/>
150133
</label>
151134

apps/typegpu-docs/src/components/ExamplePage.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const getRandomExampleKey = () => {
1414
/**
1515
* The example we want to show off first.
1616
*/
17-
const FLAGSHIP = 'simulation--boids';
17+
const FLAGSHIP = 'rendering--caustics';
1818

1919
function RedirectToFlagship() {
2020
const setCurrentExample = useSetAtom(currentExampleAtom);
@@ -26,9 +26,7 @@ function RedirectToFlagship() {
2626
}
2727
redirectedRef.current = true;
2828

29-
setCurrentExample(
30-
FLAGSHIP in examplesStable ? FLAGSHIP : getRandomExampleKey(),
31-
);
29+
setCurrentExample(FLAGSHIP in examples ? FLAGSHIP : getRandomExampleKey());
3230
}, [setCurrentExample]);
3331

3432
return null;

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

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ which is then used to generate equivalent WGSL.
1313

1414
You can check the current state of supported JavaScript syntax in the [tinyest-for-wgsl repository](https://github.com/software-mansion/TypeGPU/blob/release/packages/tinyest-for-wgsl/src/parsers.ts).
1515

16-
For the TGSL functions to work, you need to use either the dedicated build plugin -- [unplugin-typegpu](/TypeGPU/tooling/unplugin-typegpu),
17-
or the Just-In-Time transpiler -- *tgpu-jit* (WIP).
16+
For the TGSL functions to work, you need to use the dedicated build plugin -- [unplugin-typegpu](/TypeGPU/tooling/unplugin-typegpu).
1817

1918
## Usage
2019

@@ -35,24 +34,22 @@ const obstacles = root
3534
enabled: d.u32,
3635
}), MAX_OBSTACLES));
3736

38-
const isInsideObstacle = tgpu['~unstable'].fn([d.i32, d.i32], d.bool)(
39-
(x, y) => {
40-
for (let obsIdx = 0; obsIdx < MAX_OBSTACLES; obsIdx++) {
41-
const obs = obstacles.$[obsIdx];
42-
if (obs.enabled === 0) {
43-
continue;
44-
}
45-
const minX = std.max(0, obs.center.x - d.i32(obs.size.x / 2));
46-
const maxX = std.min(gridSize, obs.center.x + d.i32(obs.size.x / 2));
47-
const minY = std.max(0, obs.center.y - d.i32(obs.size.y / 2));
48-
const maxY = std.min(gridSize, obs.center.y + d.i32(obs.size.y / 2));
49-
if (x >= minX && x <= maxX && y >= minY && y <= maxY) {
50-
return true;
51-
}
37+
const isInsideObstacle = tgpu.fn([d.i32, d.i32], d.bool)((x, y) => {
38+
for (let obsIdx = 0; obsIdx < MAX_OBSTACLES; obsIdx++) {
39+
const obs = obstacles.$[obsIdx];
40+
if (obs.enabled === 0) {
41+
continue;
5242
}
53-
return false;
54-
},
55-
);
43+
const minX = std.max(0, obs.center.x - d.i32(obs.size.x / 2));
44+
const maxX = std.min(gridSize, obs.center.x + d.i32(obs.size.x / 2));
45+
const minY = std.max(0, obs.center.y - d.i32(obs.size.y / 2));
46+
const maxY = std.min(gridSize, obs.center.y + d.i32(obs.size.y / 2));
47+
if (x >= minX && x <= maxX && y >= minY && y <= maxY) {
48+
return true;
49+
}
50+
}
51+
return false;
52+
});
5653
```
5754

5855
```ts

apps/typegpu-docs/src/content/docs/reference/naming-convention.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const cells3 = root.createReadonly(Cells);
6767
We give slots *camelCase* names with the `Slot` suffix.
6868

6969
```ts
70-
const colorSlot = tgpu['~unstable'].slot(vec4f(1, 0, 0, 1));
70+
const colorSlot = tgpu.slot(vec4f(1, 0, 0, 1));
7171
```
7272

7373
## Accessors

apps/typegpu-docs/src/content/docs/tooling/unplugin-typegpu.mdx

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,14 @@ The package includes the following functionalities:
2323
import tgpu from 'typegpu';
2424
import * as d from 'typegpu/data';
2525

26-
const add = tgpu['~unstable'].fn([d.u32, d.u32], d.u32)(
27-
(a, b) => a + b,
28-
);
26+
const add = tgpu.fn([d.u32, d.u32], d.u32)((a, b) => a + b);
2927
```
3028

3129
However, if the implementation function, or the shell, is referenced via a variable, the plugin will not recognize it as TGSL,
3230
thus to make it work, the function needs to be marked with a `"kernel"` directive.
3331

3432
```ts
35-
const addFn = tgpu['~unstable'].fn([d.u32, d.u32], d.u32);
33+
const addFn = tgpu.fn([d.u32, d.u32], d.u32);
3634

3735
const add = addFn((a, b) => {
3836
'kernel';
@@ -46,14 +44,14 @@ The package includes the following functionalities:
4644
return a + b;
4745
};
4846

49-
const add = tgpu['~unstable'].fn([d.u32, d.u32], d.u32)(addImpl);
47+
const add = tgpu.fn([d.u32, d.u32], d.u32)(addImpl);
5048
```
5149

5250
After transpiling the function, the JS implementation is removed from the bundle in order to save space.
5351
To be able to invoke the function both on GPU and CPU, it needs to be marked with `"kernel & js"` directive;
5452

5553
```ts
56-
const add = tgpu['~unstable'].fn([d.u32, d.u32], d.u32)((a, b) => {
54+
const add = tgpu.fn([d.u32, d.u32], d.u32)((a, b) => {
5755
'kernel & js';
5856
return a + b;
5957
});
@@ -62,17 +60,11 @@ The package includes the following functionalities:
6260
```
6361

6462
Besides transpiling JS into AST, the plugin also collects external references, so it is not necessary to pass them to the `$uses` method anymore.
65-
This is not possible when using a JIT transpiler.
6663

67-
- **[WIP] Automatic naming of tgpu objects**
64+
- **Automatic naming of tgpu objects**
6865

69-
Naming gpu objects via the `$name` method is very helpful for debugging. Soon it will not be necessary to do that explicitly.
70-
Instead, the plugin will be able to name the objects based on the variable names that they are assigned to.
71-
72-
:::caution
73-
In order for the plugin to work, the file that is to be transformed needs to import _typegpu_.
74-
Note that unused imports may be automatically removed by bundlers, so make sure this does not happen.
75-
:::
66+
Naming TypeGPU resources via the `$name` method is very helpful for debugging, but it's can get very repetitive.
67+
Instead, the plugin is able to automatically name each resource based on the variable names that they are assigned to.
7668

7769
## Installation
7870

apps/typegpu-docs/src/content/examples/algorithms/matrix-next/computeShared.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import { computeLayout } from './types.ts';
77
const tileA = tgpu['~unstable'].workgroupVar(d.arrayOf(d.i32, TILE_SIZE ** 2));
88
const tileB = tgpu['~unstable'].workgroupVar(d.arrayOf(d.i32, TILE_SIZE ** 2));
99

10-
export const getIndex = tgpu['~unstable'].fn([d.u32, d.u32, d.u32], d.u32)(
10+
export const getIndex = tgpu.fn([d.u32, d.u32, d.u32], d.u32)(
1111
(row, col, columns) => {
1212
return col + row * columns;
1313
},
1414
);
1515

16-
const getTileIndex = tgpu['~unstable'].fn([d.u32, d.u32], d.u32)((row, col) => {
16+
const getTileIndex = tgpu.fn([d.u32, d.u32], d.u32)((row, col) => {
1717
return col + row * TILE_SIZE;
1818
});
1919

apps/typegpu-docs/src/content/examples/image-processing/ascii-filter/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const displayModes = {
3434
* Adapted from the original Shadertoy implementation by movAX13h:
3535
* https://www.shadertoy.com/view/lssGDj
3636
*/
37-
const characterFn = tgpu['~unstable'].fn([d.u32, d.vec2f], d.f32)((n, p) => {
37+
const characterFn = tgpu.fn([d.u32, d.vec2f], d.f32)((n, p) => {
3838
// Transform texture coordinates to character bitmap coordinates (5x5 grid)
3939
const pos = std.floor(std.add(std.mul(p, d.vec2f(-4, 4)), 2.5));
4040

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"title": "ASCII filter",
33
"category": "image-processing",
4-
"tags": ["camera", "filtering", "external texture"]
4+
"tags": ["experimental", "camera", "filtering", "external texture"]
55
}

apps/typegpu-docs/src/content/examples/image-processing/camera-thresholding/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,7 @@ const sampler = root.device.createSampler({
8686
minFilter: 'linear',
8787
});
8888

89-
const thresholdBuffer = root
90-
.createBuffer(d.f32)
91-
.$name('threshold')
92-
.$usage('uniform');
89+
const thresholdBuffer = root.createBuffer(d.f32).$usage('uniform');
9390

9491
const rareBindGroup = root.createBindGroup(rareLayout, {
9592
sampling: sampler,

0 commit comments

Comments
 (0)