Skip to content

Commit 680f4f3

Browse files
committed
Update to typegpu 0.7.0
1 parent 1f70417 commit 680f4f3

File tree

7 files changed

+111
-109
lines changed

7 files changed

+111
-109
lines changed

apps/phoure-www/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"@radix-ui/react-tooltip": "^1.1.6",
2929
"@typegpu/color": "workspace:*",
3030
"@typegpu/common": "workspace:*",
31-
"@typegpu/noise": "^0.0.9",
31+
"@typegpu/noise": "^0.1.0",
3232
"@typegpu/sdf": "workspace:*",
3333
"@types/react": "^18.0.2",
3434
"@types/react-dom": "^18.0.2",
@@ -48,9 +48,9 @@
4848
"tailwindcss-animate": "^1.0.7",
4949
"typegpu": "catalog:",
5050
"unplugin-typegpu": "catalog:",
51-
"wgpu-matrix": "^3.3.0"
51+
"wgpu-matrix": "^3.4.0"
5252
},
5353
"devDependencies": {
54-
"@webgpu/types": "^0.1.34"
54+
"@webgpu/types": "^0.1.64"
5555
}
5656
}

apps/phoure-www/src/lib-phoure/menderStep.ts

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,8 @@ type Options = {
2828
targetTexture: () => GPUTextureView;
2929
};
3030

31-
const reluSlot = tgpu['~unstable'].slot<boolean>().$name('relu');
32-
const inputFromGBufferSlot = tgpu['~unstable']
33-
.slot<boolean>()
34-
.$name('input_from_gbuffer');
31+
const reluSlot = tgpu.slot<boolean>();
32+
const inputFromGBufferSlot = tgpu.slot<boolean>();
3533
const BLOCK_SIZE = 8;
3634

3735
// const convolveLocalFn = wgsl.fn`(local: vec2u, result: ptr<function, array<f32, ${outChannelsSlot}>>) {
@@ -68,7 +66,7 @@ const ioLayout = tgpu.bindGroupLayout({
6866
const { weights, biases } = layerLayout.bound;
6967

7068
const sampleGlobal = tgpu['~unstable'].derived(() => {
71-
return tgpu['~unstable']
69+
return tgpu
7270
.fn([d.i32, d.i32, d.ptrFn(d.arrayOf(d.vec4f, inChannelsQuarter.value))])(
7371
(x, y, result) => {
7472
const canvasSize = accessViewportSize.value;
@@ -77,7 +75,7 @@ const sampleGlobal = tgpu['~unstable'].derived(() => {
7775
d.u32(std.max(0, std.min(y, d.i32(canvasSize.y) - 1))),
7876
);
7977

80-
if (inputFromGBufferSlot) {
78+
if (inputFromGBufferSlot.$) {
8179
const blurred = std.textureLoad(ioLayout.$.blurred_tex, coord, 0);
8280

8381
const aux = std.textureLoad(ioLayout.$.aux_tex, coord, 0);
@@ -96,8 +94,10 @@ const sampleGlobal = tgpu['~unstable'].derived(() => {
9694
);
9795
} else {
9896
for (let i = d.u32(0); i < inChannelsQuarter.value; i++) {
99-
const index = (coord.y * d.u32(canvasSize.x) + coord.x) *
100-
inChannelsQuarter.value + i;
97+
const index =
98+
(coord.y * d.u32(canvasSize.x) + coord.x) *
99+
inChannelsQuarter.value +
100+
i;
101101

102102
result[i] = ioLayout.$.input_buffer[index];
103103
}
@@ -121,56 +121,49 @@ const applyReLU = tgpu['~unstable'].derived(() => {
121121
.$name('apply_relu');
122122
});
123123

124-
const readKernel = tgpu['~unstable']
125-
.fn(
126-
[d.u32],
127-
d.vec4f,
128-
)((idx) => weights.value[idx])
129-
.$name('readKernel');
124+
const readKernel = tgpu.fn([d.u32], d.vec4f)((idx) => weights.value[idx]);
130125

131126
const menderConvolveFn = convolveFn({
132127
sampleFiller: sampleGlobal,
133128
kernelReader: readKernel,
134129
});
135130

136-
const entryComputeFn = tgpu['~unstable']
137-
.computeFn({
138-
workgroupSize: [BLOCK_SIZE, BLOCK_SIZE],
139-
in: {
140-
gid: d.builtin.globalInvocationId,
141-
},
142-
})(/* wgsl */ `{
131+
const entryComputeFn = tgpu['~unstable'].computeFn({
132+
workgroupSize: [BLOCK_SIZE, BLOCK_SIZE],
133+
in: {
134+
gid: d.builtin.globalInvocationId,
135+
},
136+
})`{
143137
var result: array<f32, OUT_CHANNELS>;
144-
138+
145139
for (var i = 0; i < OUT_CHANNELS; i += 1) {
146140
result[i] = biases[i];
147141
}
148142
149143
menderConvolveFn(in.gid.xy, &result);
150-
144+
151145
if (reluSlot) {
152146
applyReLU(&result);
153147
}
154148
155149
let canvasSize = accessViewportSize;
156-
150+
157151
let output_buffer_begin =
158152
(in.gid.y * u32(canvasSize.x) +
159153
in.gid.x) * OUT_CHANNELS;
160-
154+
161155
for (var i: u32 = 0; i < OUT_CHANNELS; i++) {
162156
output_buffer[output_buffer_begin + i] = result[i];
163157
}
164-
}`)
165-
.$uses({
166-
menderConvolveFn,
167-
reluSlot,
168-
applyReLU,
169-
biases,
170-
accessViewportSize,
171-
output_buffer: ioLayout.bound.output_buffer,
172-
OUT_CHANNELS: outChannelsSlot,
173-
});
158+
}`.$uses({
159+
menderConvolveFn,
160+
reluSlot,
161+
applyReLU,
162+
biases,
163+
accessViewportSize,
164+
output_buffer: ioLayout.bound.output_buffer,
165+
OUT_CHANNELS: outChannelsSlot,
166+
});
174167

175168
export const MenderStep = ({ root, gBuffer, targetTexture }: Options) => {
176169
// Resource locators

apps/phoure-www/src/lib/GameEngine/convolve.ts

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,18 @@ import {
1212
} from 'typegpu/data';
1313

1414
export type SampleFiller = TgpuFn<
15-
[x: I32, y: I32, outSamplerPtr: Ptr<'function', WgslArray<Vec4f>>]
15+
(x: I32, y: I32, outSamplerPtr: Ptr<'function', WgslArray<Vec4f>>) => void
1616
>;
17-
export type KernelReader = TgpuFn<[idx: U32], Vec4f>;
17+
export type KernelReader = TgpuFn<(idx: U32) => Vec4f>;
1818

1919
/**
2020
* Has to be divisible by 4
2121
*/
22-
export const inChannelsSlot = tgpu['~unstable']
23-
.slot<number>()
24-
.$name('in_channels');
25-
export const outChannelsSlot = tgpu['~unstable']
26-
.slot<number>()
27-
.$name('out_channels');
28-
export const kernelRadiusSlot = tgpu['~unstable']
29-
.slot<number>()
30-
.$name('kernel_radius');
31-
const sampleFillerSlot = tgpu['~unstable']
32-
.slot<SampleFiller>()
33-
.$name('sample_filler');
34-
const kernelReaderSlot = tgpu['~unstable']
35-
.slot<KernelReader>()
36-
.$name('kernel_reader');
22+
export const inChannelsSlot = tgpu.slot<number>().$name('in_channels');
23+
export const outChannelsSlot = tgpu.slot<number>().$name('out_channels');
24+
export const kernelRadiusSlot = tgpu.slot<number>().$name('kernel_radius');
25+
const sampleFillerSlot = tgpu.slot<SampleFiller>().$name('sample_filler');
26+
const kernelReaderSlot = tgpu.slot<KernelReader>().$name('kernel_reader');
3727

3828
export const inChannelsQuarter = tgpu['~unstable'].derived(() => {
3929
if (inChannelsSlot.value % 4 !== 0) {
@@ -43,7 +33,7 @@ export const inChannelsQuarter = tgpu['~unstable'].derived(() => {
4333
});
4434

4535
const _convolveFn = tgpu['~unstable'].derived(() => {
46-
return tgpu['~unstable']
36+
return tgpu
4737
.fn([vec2u, ptrFn(arrayOf(f32, outChannelsSlot.value))])(
4838
/* wgsl */ `(coord: vec2u, result: ptr<function, array<f32, outChannels>>) {
4939
var sample = array<vec4f, inChannelsQuarter>();

packages/typegpu-common/package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515
"require": "./dist/index.cjs"
1616
}
1717
},
18-
"files": ["README.md", "package.json", "dist"],
18+
"files": [
19+
"README.md",
20+
"package.json",
21+
"dist"
22+
],
1923
"scripts": {
2024
"build": "rollup -c",
2125
"dev:build": "rollup -c",
@@ -32,6 +36,6 @@
3236
"typegpu": "catalog:"
3337
},
3438
"peerDependencies": {
35-
"typegpu": "^0.3.0"
39+
"typegpu": "^0.7.0"
3640
}
3741
}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import tgpu from 'typegpu';
22
import { vec2f } from 'typegpu/data';
33

4-
export const accessViewportSize = tgpu['~unstable']
5-
.accessor(vec2f)
6-
.$name('accessViewportSize');
4+
export const accessViewportSize = tgpu['~unstable'].accessor(vec2f);

0 commit comments

Comments
 (0)