Skip to content

Commit 5805cac

Browse files
committed
Simplify implicit pointer dereferencing
1 parent b1fe352 commit 5805cac

File tree

6 files changed

+107
-152
lines changed

6 files changed

+107
-152
lines changed

packages/typegpu/src/core/function/dualImpl.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,13 @@ export function dualImpl<T extends (...args: never[]) => unknown>(
7070
const gpuImpl = (...args: MapValueToSnippet<Parameters<T>>) => {
7171
const { argTypes, returnType } = typeof options.signature === 'function'
7272
? options.signature(
73-
...args.map((s) => s.dataType) as MapValueToDataType<Parameters<T>>,
73+
...args.map((s) => {
74+
// Dereference implicit pointers
75+
if (s.dataType.type === 'ptr' && s.dataType.implicit) {
76+
return s.dataType.inner;
77+
}
78+
return s.dataType;
79+
}) as MapValueToDataType<Parameters<T>>,
7480
)
7581
: options.signature;
7682

packages/typegpu/src/data/dataTypes.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,6 @@ export function toStorable(schema: AnyData): AnyData {
146146
return undecorate(unptr(undecorate(schema)));
147147
}
148148

149-
export function toStorables<T extends AnyData[]>(schemas: T): T {
150-
return schemas.map(toStorable) as T;
151-
}
152-
153149
const looseTypeLiterals = [
154150
'unstruct',
155151
'disarray',

packages/typegpu/src/data/vector.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { dualImpl } from '../core/function/dualImpl.ts';
22
import { stitch } from '../core/resolve/stitch.ts';
33
import { $repr } from '../shared/symbols.ts';
4-
import { type AnyData, toStorable } from './dataTypes.ts';
4+
import type { AnyData } from './dataTypes.ts';
55
import { bool, f16, f32, i32, u32 } from './numeric.ts';
66
import {
77
Vec2bImpl,
@@ -310,10 +310,7 @@ function makeVecSchema<TValue, S extends number | boolean>(
310310
const construct = dualImpl({
311311
name: type,
312312
signature: (...args) => ({
313-
argTypes: args.map((arg) => {
314-
const argType = toStorable(arg);
315-
return isVec(argType) ? argType : primitive;
316-
}),
313+
argTypes: args.map((arg) => isVec(arg) ? arg : primitive),
317314
returnType: schema as AnyData,
318315
}),
319316
normalImpl: cpuConstruct,

packages/typegpu/src/std/boolean.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { dualImpl } from '../core/function/dualImpl.ts';
22
import { stitch } from '../core/resolve/stitch.ts';
3-
import { type AnyData, toStorables } from '../data/dataTypes.ts';
3+
import type { AnyData } from '../data/dataTypes.ts';
44
import { bool, f32 } from '../data/numeric.ts';
55
import { isSnippetNumeric, snip } from '../data/snippet.ts';
66
import { vec2b, vec3b, vec4b } from '../data/vector.ts';
@@ -338,8 +338,7 @@ function cpuSelect<T extends number | boolean | AnyVecInstance>(
338338
*/
339339
export const select = dualImpl({
340340
name: 'select',
341-
signature: (...args) => {
342-
const [f, t, cond] = toStorables(args);
341+
signature: (f, t, cond) => {
343342
const [uf, ut] = unify([f, t]) ?? [f, t] as const;
344343
return ({ argTypes: [uf, ut, cond], returnType: uf });
345344
},

0 commit comments

Comments
 (0)