Skip to content

Commit f60b4f7

Browse files
authored
fix: Properly infer layout .$ using InferGPU (#2258)
1 parent 79aacfd commit f60b4f7

3 files changed

Lines changed: 22 additions & 8 deletions

File tree

packages/typegpu/src/data/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ export type {
5757
AnyWgslData,
5858
AnyWgslStruct,
5959
Atomic,
60+
atomicI32,
61+
atomicU32,
6062
BaseData,
6163
BaseData as BaseWgslData,
6264
Bool,

packages/typegpu/src/tgpuBindGroupLayout.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import { NotUniformError } from './errors.ts';
4949
import { isUsableAsStorage, NotStorageError, type StorageFlag } from './extension.ts';
5050
import type { TgpuNamable } from './shared/meta.ts';
5151
import { getName, setName } from './shared/meta.ts';
52-
import type { Infer, MemIdentity } from './shared/repr.ts';
52+
import type { InferGPU, MemIdentity } from './shared/repr.ts';
5353
import { safeStringify } from './shared/stringify.ts';
5454
import { $gpuValueOf, $internal } from './shared/symbols.ts';
5555
import type { Default, NullableToOptional, Prettify } from './shared/utilityTypes.ts';
@@ -392,19 +392,19 @@ export type BindLayoutEntry<T extends TgpuLayoutEntry | null> = T extends TgpuLa
392392
: never;
393393

394394
export type InferLayoutEntry<T extends TgpuLayoutEntry | null> = T extends TgpuLayoutUniform
395-
? Infer<T['uniform']>
395+
? InferGPU<T['uniform']>
396396
: T extends TgpuLayoutStorage
397-
? Infer<UnwrapRuntimeConstructor<T['storage']>>
397+
? InferGPU<UnwrapRuntimeConstructor<T['storage']>>
398398
: T extends TgpuLayoutSampler
399-
? Infer<WgslSampler>
399+
? InferGPU<WgslSampler>
400400
: T extends TgpuLayoutComparisonSampler
401-
? Infer<WgslComparisonSampler>
401+
? InferGPU<WgslComparisonSampler>
402402
: T extends TgpuLayoutTexture<infer TSchema>
403-
? Infer<TSchema>
403+
? InferGPU<TSchema>
404404
: T extends TgpuLayoutStorageTexture<infer TSchema>
405-
? Infer<TSchema>
405+
? InferGPU<TSchema>
406406
: T extends TgpuLayoutExternalTexture
407-
? Infer<T['externalTexture']>
407+
? InferGPU<T['externalTexture']>
408408
: never;
409409

410410
export type ExtractBindGroupInputFromLayout<T extends Record<string, TgpuLayoutEntry | null>> =

packages/typegpu/tests/bindGroupLayout.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,18 @@ describe('TgpuBindGroupLayout', () => {
167167
`);
168168
});
169169

170+
it('infers atomics as GPU atomic types in layout.$', () => {
171+
const layout = tgpu.bindGroupLayout({
172+
counter: { storage: d.atomic(d.u32), access: 'mutable' },
173+
signedCounter: { storage: d.atomic(d.i32), access: 'mutable' },
174+
atomicArray: { storage: d.arrayOf(d.atomic(d.u32)), access: 'mutable' },
175+
});
176+
177+
expectTypeOf<typeof layout.$.counter>().toEqualTypeOf<d.atomicU32>();
178+
expectTypeOf<typeof layout.$.signedCounter>().toEqualTypeOf<d.atomicI32>();
179+
expectTypeOf<typeof layout.$.atomicArray>().toEqualTypeOf<d.atomicU32[]>();
180+
});
181+
170182
it('takes a pointer to layout.$... if assigned to a const variable', () => {
171183
const Boid = d.struct({
172184
pos: d.vec3f,

0 commit comments

Comments
 (0)