Skip to content

Commit a01aa6d

Browse files
authored
feat: Autoname unstruct definitions (#1413)
1 parent fd67137 commit a01aa6d

File tree

3 files changed

+27
-24
lines changed

3 files changed

+27
-24
lines changed

packages/typegpu/tests/resolve.test.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -231,21 +231,23 @@ describe('tgpu resolve', () => {
231231
});
232232

233233
it('should resolve an unstruct with a complex nested structure', () => {
234+
const Extra = d.unstruct({
235+
a: d.snorm8,
236+
b: d.snorm8x4,
237+
c: d.float16x2,
238+
});
239+
240+
const More = d.unstruct({
241+
a: d.snorm8,
242+
b: d.snorm8x4,
243+
});
244+
234245
const VertexInfo = d.unstruct({
235246
color: d.snorm8x4,
236247
colorHDR: d.unorm10_10_10_2,
237248
position2d: d.float16x2,
238-
extra: d
239-
.unstruct({
240-
a: d.snorm8,
241-
b: d.snorm8x4,
242-
c: d.float16x2,
243-
})
244-
.$name('extra'),
245-
more: d.disarrayOf(
246-
d.unstruct({ a: d.snorm8, b: d.snorm8x4 }).$name('more'),
247-
16,
248-
),
249+
extra: Extra,
250+
more: d.disarrayOf(More, 16),
249251
});
250252

251253
const resolved = tgpu.resolve({
@@ -256,13 +258,13 @@ describe('tgpu resolve', () => {
256258

257259
expect(parse(resolved)).toBe(
258260
parse(`
259-
struct extra {
261+
struct Extra {
260262
a: f32,
261263
b: vec4f,
262264
c: vec2f,
263265
}
264266
265-
struct more {
267+
struct More {
266268
a: f32,
267269
b: vec4f,
268270
}
@@ -271,8 +273,8 @@ describe('tgpu resolve', () => {
271273
color: vec4f,
272274
colorHDR: vec4f,
273275
position2d: vec2f,
274-
extra: extra,
275-
more: array<more, 16>,
276+
extra: Extra,
277+
more: array<More, 16>,
276278
}
277279
278280
fn foo() { var v: VertexInfo; }

packages/typegpu/tests/root.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ describe('TgpuRoot', () => {
1717
label: 'dataBuffer',
1818
mappedAtCreation: false,
1919
size: 4,
20-
usage: global.GPUBufferUsage.UNIFORM |
21-
global.GPUBufferUsage.COPY_DST |
22-
global.GPUBufferUsage.COPY_SRC,
20+
usage: GPUBufferUsage.UNIFORM |
21+
GPUBufferUsage.COPY_DST |
22+
GPUBufferUsage.COPY_SRC,
2323
});
2424
});
2525

@@ -36,9 +36,9 @@ describe('TgpuRoot', () => {
3636
label: 'dataBuffer',
3737
mappedAtCreation: true,
3838
size: 12,
39-
usage: global.GPUBufferUsage.UNIFORM |
40-
global.GPUBufferUsage.COPY_DST |
41-
global.GPUBufferUsage.COPY_SRC,
39+
usage: GPUBufferUsage.UNIFORM |
40+
GPUBufferUsage.COPY_DST |
41+
GPUBufferUsage.COPY_SRC,
4242
});
4343
});
4444

@@ -52,9 +52,9 @@ describe('TgpuRoot', () => {
5252
label: 'dataBuffer',
5353
mappedAtCreation: false,
5454
size: 12,
55-
usage: global.GPUBufferUsage.UNIFORM |
56-
global.GPUBufferUsage.COPY_DST |
57-
global.GPUBufferUsage.COPY_SRC,
55+
usage: GPUBufferUsage.UNIFORM |
56+
GPUBufferUsage.COPY_DST |
57+
GPUBufferUsage.COPY_SRC,
5858
});
5959
});
6060
});

packages/unplugin-typegpu/src/common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ const resourceConstructors: string[] = [
120120
...fnShellFunctionNames,
121121
// d
122122
'struct',
123+
'unstruct',
123124
// root
124125
'createBuffer',
125126
'createMutable',

0 commit comments

Comments
 (0)