Skip to content

feat: Autoname unstruct definitions #1413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions packages/typegpu/tests/resolve.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,21 +231,23 @@ describe('tgpu resolve', () => {
});

it('should resolve an unstruct with a complex nested structure', () => {
const Extra = d.unstruct({
a: d.snorm8,
b: d.snorm8x4,
c: d.float16x2,
});

const More = d.unstruct({
a: d.snorm8,
b: d.snorm8x4,
});

const VertexInfo = d.unstruct({
color: d.snorm8x4,
colorHDR: d.unorm10_10_10_2,
position2d: d.float16x2,
extra: d
.unstruct({
a: d.snorm8,
b: d.snorm8x4,
c: d.float16x2,
})
.$name('extra'),
more: d.disarrayOf(
d.unstruct({ a: d.snorm8, b: d.snorm8x4 }).$name('more'),
16,
),
extra: Extra,
more: d.disarrayOf(More, 16),
});

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

expect(parse(resolved)).toBe(
parse(`
struct extra {
struct Extra {
a: f32,
b: vec4f,
c: vec2f,
}

struct more {
struct More {
a: f32,
b: vec4f,
}
Expand All @@ -271,8 +273,8 @@ describe('tgpu resolve', () => {
color: vec4f,
colorHDR: vec4f,
position2d: vec2f,
extra: extra,
more: array<more, 16>,
extra: Extra,
more: array<More, 16>,
}

fn foo() { var v: VertexInfo; }
Expand Down
18 changes: 9 additions & 9 deletions packages/typegpu/tests/root.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ describe('TgpuRoot', () => {
label: 'dataBuffer',
mappedAtCreation: false,
size: 4,
usage: global.GPUBufferUsage.UNIFORM |
global.GPUBufferUsage.COPY_DST |
global.GPUBufferUsage.COPY_SRC,
usage: GPUBufferUsage.UNIFORM |
GPUBufferUsage.COPY_DST |
GPUBufferUsage.COPY_SRC,
});
});

Expand All @@ -36,9 +36,9 @@ describe('TgpuRoot', () => {
label: 'dataBuffer',
mappedAtCreation: true,
size: 12,
usage: global.GPUBufferUsage.UNIFORM |
global.GPUBufferUsage.COPY_DST |
global.GPUBufferUsage.COPY_SRC,
usage: GPUBufferUsage.UNIFORM |
GPUBufferUsage.COPY_DST |
GPUBufferUsage.COPY_SRC,
});
});

Expand All @@ -52,9 +52,9 @@ describe('TgpuRoot', () => {
label: 'dataBuffer',
mappedAtCreation: false,
size: 12,
usage: global.GPUBufferUsage.UNIFORM |
global.GPUBufferUsage.COPY_DST |
global.GPUBufferUsage.COPY_SRC,
usage: GPUBufferUsage.UNIFORM |
GPUBufferUsage.COPY_DST |
GPUBufferUsage.COPY_SRC,
});
});
});
Expand Down
1 change: 1 addition & 0 deletions packages/unplugin-typegpu/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ const resourceConstructors: string[] = [
...fnShellFunctionNames,
// d
'struct',
'unstruct',
// root
'createBuffer',
'createMutable',
Expand Down