typegpu 0.11.1 → 0.11.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_virtual/{_rolldown/runtime.js → rolldown_runtime.js} +4 -4
- package/builtin.js +3 -1
- package/common/fullScreenTriangle.d.ts +6 -1
- package/common/fullScreenTriangle.js +3 -1
- package/common/index.js +5 -3
- package/common/writeSoA.js +3 -1
- package/core/buffer/buffer.d.ts +3 -0
- package/core/buffer/buffer.js +5 -3
- package/core/buffer/bufferShorthand.d.ts +2 -0
- package/core/buffer/bufferShorthand.js +3 -1
- package/core/buffer/bufferUsage.d.ts +2 -0
- package/core/buffer/bufferUsage.js +3 -1
- package/core/constant/tgpuConstant.d.ts +2 -1
- package/core/constant/tgpuConstant.js +3 -1
- package/core/declare/tgpuDeclare.js +3 -1
- package/core/function/autoIO.d.ts +3 -0
- package/core/function/autoIO.js +5 -3
- package/core/function/comptime.js +3 -1
- package/core/function/createCallableSchema.js +3 -1
- package/core/function/dualImpl.js +3 -1
- package/core/function/entryInputRouter.js +13 -17
- package/core/function/extractArgs.js +2 -1
- package/core/function/fnCore.js +17 -11
- package/core/function/fnTypes.d.ts +2 -0
- package/core/function/ioSchema.d.ts +1 -0
- package/core/function/ioSchema.js +3 -1
- package/core/function/shelllessImpl.d.ts +1 -0
- package/core/function/shelllessImpl.js +4 -2
- package/core/function/templateUtils.js +2 -1
- package/core/function/tgpuComputeFn.d.ts +1 -0
- package/core/function/tgpuComputeFn.js +4 -2
- package/core/function/tgpuFn.d.ts +1 -0
- package/core/function/tgpuFn.js +17 -15
- package/core/function/tgpuFragmentFn.js +4 -2
- package/core/function/tgpuVertexFn.js +4 -2
- package/core/pipeline/applyPipelineState.js +3 -1
- package/core/pipeline/computePipeline.d.ts +4 -0
- package/core/pipeline/computePipeline.js +8 -6
- package/core/pipeline/connectAttachmentToShader.js +3 -1
- package/core/pipeline/connectTargetsToShader.js +3 -1
- package/core/pipeline/limitsOverflow.js +2 -1
- package/core/pipeline/pipelineUtils.js +6 -4
- package/core/pipeline/renderPipeline.js +21 -19
- package/core/pipeline/timeable.d.ts +2 -0
- package/core/pipeline/timeable.js +3 -1
- package/core/pipeline/typeGuards.js +3 -1
- package/core/querySet/querySet.d.ts +2 -0
- package/core/querySet/querySet.js +3 -1
- package/core/rawCodeSnippet/tgpuRawCodeSnippet.d.ts +1 -0
- package/core/rawCodeSnippet/tgpuRawCodeSnippet.js +3 -1
- package/core/resolve/externals.d.ts +3 -0
- package/core/resolve/externals.js +7 -5
- package/core/resolve/namespace.js +6 -4
- package/core/resolve/resolveData.js +3 -1
- package/core/resolve/stitch.js +3 -1
- package/core/resolve/tgpuResolve.js +7 -5
- package/core/root/configurableImpl.js +3 -1
- package/core/root/init.d.ts +10 -2
- package/core/root/init.js +4 -2
- package/core/root/rootTypes.d.ts +11 -11
- package/core/sampler/sampler.d.ts +4 -0
- package/core/sampler/sampler.js +3 -1
- package/core/simulate/tgpuSimulate.js +6 -4
- package/core/slot/accessor.d.ts +4 -0
- package/core/slot/accessor.js +3 -1
- package/core/slot/internalSlots.js +3 -1
- package/core/slot/lazy.js +3 -1
- package/core/slot/slot.js +3 -1
- package/core/slot/slotTypes.js +3 -1
- package/core/texture/externalTexture.d.ts +6 -0
- package/core/texture/externalTexture.js +3 -1
- package/core/texture/texture.d.ts +4 -0
- package/core/texture/texture.js +6 -4
- package/core/texture/textureFormats.js +3 -1
- package/core/texture/textureUtils.js +3 -1
- package/core/texture/usageExtension.js +3 -1
- package/core/unroll/tgpuUnroll.d.ts +3 -1
- package/core/unroll/tgpuUnroll.js +3 -1
- package/core/valueProxyUtils.js +7 -5
- package/core/variable/tgpuVariable.d.ts +3 -1
- package/core/variable/tgpuVariable.js +3 -1
- package/core/vertexLayout/connectAttributesToShader.js +3 -1
- package/core/vertexLayout/vertexAttribute.d.ts +1 -0
- package/core/vertexLayout/vertexLayout.js +7 -5
- package/data/alignIO.js +3 -1
- package/data/alignmentOf.d.ts +2 -0
- package/data/alignmentOf.js +3 -1
- package/data/array.js +3 -1
- package/data/atomic.d.ts +1 -0
- package/data/atomic.js +3 -1
- package/data/attributes.js +7 -5
- package/data/autoStruct.d.ts +3 -1
- package/data/autoStruct.js +3 -1
- package/data/compiledIO.js +39 -37
- package/data/dataIO.js +22 -20
- package/data/dataTypes.d.ts +9 -4
- package/data/dataTypes.js +3 -1
- package/data/deepEqual.d.ts +1 -0
- package/data/deepEqual.js +3 -1
- package/data/disarray.d.ts +3 -1
- package/data/disarray.js +3 -1
- package/data/getLongestContiguousPrefix.d.ts +2 -0
- package/data/getLongestContiguousPrefix.js +3 -1
- package/data/index.d.ts +3 -3
- package/data/index.js +5 -6
- package/data/isContiguous.d.ts +2 -0
- package/data/isContiguous.js +3 -1
- package/data/matrix.d.ts +11 -8
- package/data/matrix.js +3 -1
- package/data/numberOps.js +2 -1
- package/data/numeric.d.ts +1 -0
- package/data/numeric.js +19 -15
- package/data/offsetUtils.d.ts +1 -0
- package/data/offsetUtils.js +3 -1
- package/data/offsets.js +5 -3
- package/data/partialIO.js +3 -1
- package/data/ptr.d.ts +1 -0
- package/data/ptr.js +3 -1
- package/data/ref.d.ts +3 -0
- package/data/ref.js +5 -3
- package/data/sampler.js +3 -1
- package/data/schemaCallWrapper.js +3 -1
- package/data/schemaMemoryLayout.js +3 -1
- package/data/sizeOf.d.ts +2 -0
- package/data/sizeOf.js +3 -1
- package/data/snippet.d.ts +1 -6
- package/data/snippet.js +3 -1
- package/data/struct.d.ts +1 -0
- package/data/struct.js +3 -1
- package/data/texture.js +3 -1
- package/data/unstruct.d.ts +1 -0
- package/data/unstruct.js +3 -1
- package/data/vector.d.ts +1 -0
- package/data/vector.js +3 -1
- package/data/vectorImpl.js +3 -1
- package/data/vectorOps.js +3 -1
- package/data/vertexFormatData.js +3 -1
- package/data/wgslTypes.d.ts +4 -0
- package/data/wgslTypes.js +3 -1
- package/errors.d.ts +1 -0
- package/errors.js +3 -1
- package/execMode.js +3 -1
- package/extension.d.ts +1 -0
- package/extension.js +3 -1
- package/getGPUValue.js +3 -1
- package/index.js +3 -4
- package/indexNamedExports.d.ts +1 -0
- package/mathUtils.js +2 -1
- package/memo.js +2 -1
- package/nameRegistry.js +3 -1
- package/package.js +3 -2
- package/package.json +1 -1
- package/resolutionCtx.d.ts +11 -0
- package/resolutionCtx.js +86 -87
- package/shared/env.js +2 -1
- package/shared/generators.js +2 -1
- package/shared/meta.js +3 -1
- package/shared/repr.d.ts +1 -0
- package/shared/stringify.js +3 -1
- package/shared/symbols.js +42 -10
- package/shared/utilityTypes.js +2 -1
- package/shared/vertexFormat.js +2 -1
- package/std/array.d.ts +1 -1
- package/std/array.js +3 -1
- package/std/atomic.d.ts +12 -12
- package/std/atomic.js +3 -1
- package/std/bitcast.d.ts +2 -2
- package/std/bitcast.js +3 -1
- package/std/boolean.d.ts +15 -14
- package/std/boolean.js +3 -1
- package/std/derivative.d.ts +9 -9
- package/std/derivative.js +3 -1
- package/std/discard.d.ts +1 -1
- package/std/discard.js +3 -1
- package/std/extensions.d.ts +3 -1
- package/std/extensions.js +3 -1
- package/std/index.js +5 -3
- package/std/matrix.d.ts +6 -5
- package/std/matrix.js +3 -1
- package/std/numeric.d.ts +132 -78
- package/std/numeric.js +7 -5
- package/std/operators.d.ts +8 -8
- package/std/operators.js +7 -5
- package/std/packing.d.ts +5 -4
- package/std/packing.js +3 -1
- package/std/range.d.ts +3 -1
- package/std/range.js +3 -1
- package/std/subgroup.d.ts +21 -21
- package/std/subgroup.js +3 -1
- package/std/texture.d.ts +11 -11
- package/std/texture.js +9 -7
- package/tgpu.js +5 -3
- package/tgpuBindGroupLayout.d.ts +11 -7
- package/tgpuBindGroupLayout.js +3 -1
- package/tgpuUnstable.js +5 -3
- package/tgsl/accessIndex.js +5 -3
- package/tgsl/accessProp.js +10 -3
- package/tgsl/consoleLog/deserializers.js +3 -1
- package/tgsl/consoleLog/logGenerator.js +18 -9
- package/tgsl/consoleLog/serializers.js +3 -1
- package/tgsl/consoleLog/types.d.ts +3 -0
- package/tgsl/consoleLog/types.js +2 -1
- package/tgsl/conversion.js +18 -6
- package/tgsl/forOfUtils.js +17 -7
- package/tgsl/generationHelpers.d.ts +1 -0
- package/tgsl/generationHelpers.js +3 -4
- package/tgsl/math.js +3 -1
- package/tgsl/shaderGenerator.d.ts +3 -2
- package/tgsl/shaderGenerator_members.d.ts +15 -2
- package/tgsl/shaderGenerator_members.js +5 -3
- package/tgsl/shellless.js +3 -1
- package/tgsl/wgslGenerator.d.ts +3 -1
- package/tgsl/wgslGenerator.js +54 -44
- package/types.d.ts +11 -7
- package/types.js +3 -1
- package/wgslExtensions.js +2 -1
package/package.json
CHANGED
package/resolutionCtx.d.ts
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
|
+
import "./data/snippet.js";
|
|
2
|
+
import "./tgsl/shellless.js";
|
|
1
3
|
import { LogResources } from "./tgsl/consoleLog/types.js";
|
|
4
|
+
import "./core/slot/slotTypes.js";
|
|
2
5
|
import { TgpuBindGroup, TgpuBindGroupLayout } from "./tgpuBindGroupLayout.js";
|
|
6
|
+
import "./tgsl/shaderGenerator.js";
|
|
7
|
+
import "./core/root/rootTypes.js";
|
|
8
|
+
import "./types.js";
|
|
9
|
+
import "./data/wgslTypes.js";
|
|
10
|
+
import "./data/dataTypes.js";
|
|
11
|
+
import "./core/resolve/namespace.js";
|
|
12
|
+
|
|
3
13
|
//#region src/resolutionCtx.d.ts
|
|
14
|
+
|
|
4
15
|
/**
|
|
5
16
|
* The results of a WGSL resolution.
|
|
6
17
|
*
|
package/resolutionCtx.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { $internal, $providing, $resolve, isMarkedInternal } from "./shared/symbols.js";
|
|
2
2
|
import { getName, hasTinyestMetadata, setName } from "./shared/meta.js";
|
|
3
3
|
import { Void, isPtr, isWgslArray, isWgslStruct } from "./data/wgslTypes.js";
|
|
4
|
-
import { UnknownData, isData
|
|
4
|
+
import { UnknownData, isData } from "./data/dataTypes.js";
|
|
5
5
|
import { snip } from "./data/snippet.js";
|
|
6
6
|
import { MissingSlotValueError, ResolutionError, WgslTypeError, invariant } from "./errors.js";
|
|
7
7
|
import { isLazy, isProviding, isSlot } from "./core/slot/slotTypes.js";
|
|
@@ -12,7 +12,6 @@ import { safeStringify } from "./shared/stringify.js";
|
|
|
12
12
|
import { getBestConversion } from "./tgsl/conversion.js";
|
|
13
13
|
import { bool } from "./data/numeric.js";
|
|
14
14
|
import { coerceToSnippet, concretize, numericLiteralToSnippet } from "./tgsl/generationHelpers.js";
|
|
15
|
-
import { getAttributesString } from "./data/attributes.js";
|
|
16
15
|
import { createIoSchema } from "./core/function/ioSchema.js";
|
|
17
16
|
import { AutoStruct } from "./data/autoStruct.js";
|
|
18
17
|
import { EntryInputRouter } from "./core/function/entryInputRouter.js";
|
|
@@ -23,8 +22,9 @@ import { ConfigurableImpl } from "./core/root/configurableImpl.js";
|
|
|
23
22
|
import { naturalsExcept } from "./shared/generators.js";
|
|
24
23
|
import { TgpuBindGroupImpl, bindGroupLayout } from "./tgpuBindGroupLayout.js";
|
|
25
24
|
import { LogGeneratorImpl, LogGeneratorNullImpl } from "./tgsl/consoleLog/logGenerator.js";
|
|
26
|
-
import
|
|
25
|
+
import wgslGenerator_default from "./tgsl/wgslGenerator.js";
|
|
27
26
|
import { FuncParameterType } from "tinyest";
|
|
27
|
+
|
|
28
28
|
//#region src/resolutionCtx.ts
|
|
29
29
|
/**
|
|
30
30
|
* Inserted into bind group entry definitions that belong
|
|
@@ -63,12 +63,11 @@ var ItemStateStackImpl = class {
|
|
|
63
63
|
bindingMap: new WeakMap(pairs)
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
|
-
pushFunctionScope(functionType,
|
|
66
|
+
pushFunctionScope(functionType, argAccess, returnType, externalMap) {
|
|
67
67
|
const scope = {
|
|
68
68
|
type: "functionScope",
|
|
69
69
|
functionType,
|
|
70
|
-
|
|
71
|
-
argAliases,
|
|
70
|
+
argAccess,
|
|
72
71
|
returnType,
|
|
73
72
|
externalMap,
|
|
74
73
|
reportedReturnTypes: /* @__PURE__ */ new Set()
|
|
@@ -105,9 +104,8 @@ var ItemStateStackImpl = class {
|
|
|
105
104
|
for (let i = this._stack.length - 1; i >= 0; --i) {
|
|
106
105
|
const layer = this._stack[i];
|
|
107
106
|
if (layer?.type === "functionScope") {
|
|
108
|
-
const
|
|
109
|
-
if (
|
|
110
|
-
if (layer.argAliases[id]) return layer.argAliases[id];
|
|
107
|
+
const access = layer.argAccess[id];
|
|
108
|
+
if (access) return access();
|
|
111
109
|
const external = layer.externalMap[id];
|
|
112
110
|
if (external !== void 0 && external !== null) return coerceToSnippet(external);
|
|
113
111
|
return;
|
|
@@ -188,6 +186,27 @@ var IndentController = class {
|
|
|
188
186
|
}
|
|
189
187
|
}
|
|
190
188
|
};
|
|
189
|
+
function createArgument(name, type, origin = "argument") {
|
|
190
|
+
let used = false;
|
|
191
|
+
return {
|
|
192
|
+
name,
|
|
193
|
+
access: () => {
|
|
194
|
+
used = true;
|
|
195
|
+
return snip(name, type, origin);
|
|
196
|
+
},
|
|
197
|
+
decoratedType: type,
|
|
198
|
+
get used() {
|
|
199
|
+
return used;
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
function createArgumentPropAccess(argAccess, prop) {
|
|
204
|
+
return () => {
|
|
205
|
+
const argSnippet = argAccess();
|
|
206
|
+
if (!argSnippet) return;
|
|
207
|
+
return accessProp(argSnippet, prop);
|
|
208
|
+
};
|
|
209
|
+
}
|
|
191
210
|
var ResolutionCtxImpl = class {
|
|
192
211
|
#namespaceInternal;
|
|
193
212
|
_indentController = new IndentController();
|
|
@@ -215,7 +234,7 @@ var ResolutionCtxImpl = class {
|
|
|
215
234
|
expectedType;
|
|
216
235
|
constructor(opts) {
|
|
217
236
|
this.enableExtensions = opts.enableExtensions;
|
|
218
|
-
this.gen = opts.shaderGenerator ??
|
|
237
|
+
this.gen = opts.shaderGenerator ?? wgslGenerator_default;
|
|
219
238
|
this.#logGenerator = opts.root ? new LogGeneratorImpl(opts.root) : new LogGeneratorNullImpl();
|
|
220
239
|
this.#namespaceInternal = opts.namespace[$internal];
|
|
221
240
|
}
|
|
@@ -286,107 +305,93 @@ var ResolutionCtxImpl = class {
|
|
|
286
305
|
try {
|
|
287
306
|
this.#namespaceInternal.nameRegistry.pushFunctionScope();
|
|
288
307
|
const args = [];
|
|
289
|
-
const
|
|
290
|
-
const pendingHeaderEntries = [];
|
|
308
|
+
const argAccess = {};
|
|
291
309
|
if (options.entryInput) {
|
|
292
310
|
const { dataSchema, positionalArgs } = options.entryInput;
|
|
293
311
|
const firstParam = options.params[0];
|
|
294
|
-
const
|
|
295
|
-
|
|
296
|
-
if (structArg) {
|
|
297
|
-
args.push(structArg);
|
|
298
|
-
pendingHeaderEntries.push({
|
|
299
|
-
argName: structArgName,
|
|
300
|
-
header: `${structArgName}: ${this.resolve(dataSchema).value}`
|
|
301
|
-
});
|
|
302
|
-
}
|
|
312
|
+
const structArg = dataSchema ? createArgument(this.makeNameValid("_arg_0"), dataSchema) : void 0;
|
|
313
|
+
if (structArg) args.push(structArg);
|
|
303
314
|
if (firstParam?.type === FuncParameterType.destructuredObject) for (const { name, alias } of firstParam.props) {
|
|
304
315
|
const argInfo = positionalArgs.find((a) => a.schemaKey === name);
|
|
305
316
|
if (argInfo) {
|
|
306
|
-
const
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
pendingHeaderEntries.push({
|
|
311
|
-
argName,
|
|
312
|
-
header: `${getAttributesString(argInfo.type)}${argName}: ${this.resolve(undecorate(argInfo.type)).value}`
|
|
313
|
-
});
|
|
314
|
-
} else if (structArg) {
|
|
315
|
-
const propSnippet = accessProp(structArg, name);
|
|
316
|
-
if (propSnippet) argAliases.push([alias, propSnippet]);
|
|
317
|
-
}
|
|
317
|
+
const arg = createArgument(this.makeNameValid(alias), argInfo.type);
|
|
318
|
+
args.push(arg);
|
|
319
|
+
argAccess[alias] = arg.access;
|
|
320
|
+
} else if (structArg) argAccess[alias] = createArgumentPropAccess(structArg.access, name);
|
|
318
321
|
}
|
|
319
322
|
else if (firstParam?.type === FuncParameterType.identifier) {
|
|
320
323
|
const proxyEntries = [];
|
|
321
324
|
for (const a of positionalArgs) {
|
|
322
|
-
const
|
|
323
|
-
|
|
324
|
-
args.push(s);
|
|
325
|
+
const arg = createArgument(this.makeNameValid(`_arg_${a.schemaKey}`), a.type);
|
|
326
|
+
args.push(arg);
|
|
325
327
|
proxyEntries.push({
|
|
326
328
|
schemaKey: a.schemaKey,
|
|
327
|
-
|
|
328
|
-
type: a.type
|
|
329
|
-
});
|
|
330
|
-
pendingHeaderEntries.push({
|
|
331
|
-
argName,
|
|
332
|
-
header: `${getAttributesString(a.type)}${argName}: ${this.resolve(undecorate(a.type)).value}`
|
|
329
|
+
arg: arg.access
|
|
333
330
|
});
|
|
334
331
|
}
|
|
335
|
-
const router = new EntryInputRouter(
|
|
336
|
-
|
|
332
|
+
const router = new EntryInputRouter(structArg?.access, proxyEntries);
|
|
333
|
+
argAccess[firstParam.name] = () => snip("N/A", router, "argument");
|
|
337
334
|
} else for (const a of positionalArgs) {
|
|
338
335
|
const argName = this.makeNameValid(`_arg_${a.schemaKey}`);
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
header: `${getAttributesString(a.type)}${argName}: ${this.resolve(undecorate(a.type)).value}`
|
|
343
|
-
});
|
|
336
|
+
const arg = createArgument(argName, a.type);
|
|
337
|
+
args.push(arg);
|
|
338
|
+
argAccess[argName] = arg.access;
|
|
344
339
|
}
|
|
345
340
|
} else for (const [i, argType] of options.argTypes.entries()) {
|
|
346
341
|
const astParam = options.params[i];
|
|
347
342
|
const origin = isPtr(argType) ? argType.addressSpace === "storage" ? argType.access === "read" ? "readonly" : "mutable" : argType.addressSpace : "argument";
|
|
348
343
|
switch (astParam?.type) {
|
|
349
344
|
case FuncParameterType.identifier: {
|
|
350
|
-
const
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
if (snippet.value !== rawName) argAliases.push([rawName, snippet]);
|
|
345
|
+
const arg = createArgument(this.makeNameValid(astParam.name), argType, origin);
|
|
346
|
+
args.push(arg);
|
|
347
|
+
argAccess[astParam.name] = arg.access;
|
|
354
348
|
break;
|
|
355
349
|
}
|
|
356
350
|
case FuncParameterType.destructuredObject: {
|
|
357
|
-
const
|
|
358
|
-
args.push(
|
|
359
|
-
|
|
351
|
+
const objArg = createArgument(this.makeNameValid(`_arg_${i}`), argType, origin);
|
|
352
|
+
args.push(objArg);
|
|
353
|
+
for (const { name, alias } of astParam.props) argAccess[alias] = createArgumentPropAccess(objArg.access, name);
|
|
360
354
|
break;
|
|
361
355
|
}
|
|
362
|
-
case void 0: if (!(argType instanceof AutoStruct)) args.push(
|
|
356
|
+
case void 0: if (!(argType instanceof AutoStruct)) args.push({
|
|
357
|
+
name: this.makeNameValid(`_arg_${i}`),
|
|
358
|
+
access: () => {
|
|
359
|
+
throw new Error(`Unreachable: Accessing an argument that wasn't named in the function signature`);
|
|
360
|
+
},
|
|
361
|
+
decoratedType: argType,
|
|
362
|
+
used: false
|
|
363
|
+
});
|
|
363
364
|
}
|
|
364
365
|
}
|
|
365
|
-
const scope = this._itemStateStack.pushFunctionScope(options.functionType,
|
|
366
|
+
const scope = this._itemStateStack.pushFunctionScope(options.functionType, argAccess, options.returnType, options.externalMap);
|
|
366
367
|
fnScopePushed = true;
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
368
|
+
let returnType;
|
|
369
|
+
const code = this.gen.functionDefinition({
|
|
370
|
+
functionType: options.functionType,
|
|
371
|
+
args,
|
|
372
|
+
body: options.body,
|
|
373
|
+
determineReturnType: () => {
|
|
374
|
+
if (returnType) return returnType;
|
|
375
|
+
returnType = options.returnType;
|
|
376
|
+
if (returnType instanceof AutoStruct) if (isWgslStruct(scope.reportedReturnTypes.values().next().value)) returnType = returnType.completeStruct;
|
|
377
|
+
else returnType = void 0;
|
|
378
|
+
if (!returnType) {
|
|
379
|
+
const returnTypes = [...scope.reportedReturnTypes];
|
|
380
|
+
if (returnTypes.length === 0) returnType = Void;
|
|
381
|
+
else {
|
|
382
|
+
const conversion = getBestConversion(returnTypes);
|
|
383
|
+
if (conversion && !conversion.hasImplicitConversions) returnType = conversion.targetType;
|
|
384
|
+
}
|
|
385
|
+
if (!returnType) throw new Error(`Expected function to have a single return type, got [${returnTypes.join(", ")}]. Cast explicitly to the desired type.`);
|
|
386
|
+
returnType = concretize(returnType);
|
|
387
|
+
if (options.functionType === "vertex" || options.functionType === "fragment") returnType = createIoSchema(returnType);
|
|
388
|
+
}
|
|
389
|
+
return returnType;
|
|
377
390
|
}
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
if (options.functionType === "vertex" || options.functionType === "fragment") returnType = createIoSchema(returnType);
|
|
381
|
-
}
|
|
382
|
-
if (options.entryInput) return {
|
|
383
|
-
head: `(${pendingHeaderEntries.filter(({ argName }) => isArgUsedInBody(argName, body)).map(({ header }) => header).join(", ")}) ${returnType.type !== "void" ? `-> ${getAttributesString(returnType)}${this.resolve(returnType).value} ` : ""}`,
|
|
384
|
-
body,
|
|
385
|
-
returnType
|
|
386
|
-
};
|
|
391
|
+
});
|
|
392
|
+
if (!returnType) throw new Error(`Failed to determine return type`);
|
|
387
393
|
return {
|
|
388
|
-
|
|
389
|
-
body,
|
|
394
|
+
code,
|
|
390
395
|
returnType
|
|
391
396
|
};
|
|
392
397
|
} finally {
|
|
@@ -601,12 +606,6 @@ function resolve(item, options) {
|
|
|
601
606
|
logResources: ctx.logResources
|
|
602
607
|
};
|
|
603
608
|
}
|
|
604
|
-
|
|
605
|
-
return new RegExp(`\\b${argName}\\b`).test(body);
|
|
606
|
-
}
|
|
607
|
-
function resolveFunctionHeader(ctx, args, returnType) {
|
|
608
|
-
const argList = args.map((arg) => `${arg.value}: ${ctx.resolve(arg.dataType).value}`).join(", ");
|
|
609
|
-
return returnType.type !== "void" ? `(${argList}) -> ${getAttributesString(returnType)}${ctx.resolve(returnType).value} ` : `(${argList}) `;
|
|
610
|
-
}
|
|
609
|
+
|
|
611
610
|
//#endregion
|
|
612
|
-
export { ResolutionCtxImpl, resolve };
|
|
611
|
+
export { ResolutionCtxImpl, resolve };
|
package/shared/env.js
CHANGED
package/shared/generators.js
CHANGED
package/shared/meta.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { version } from "../package.js";
|
|
2
2
|
import { DEV, TEST } from "./env.js";
|
|
3
3
|
import { $getNameForward, isMarkedInternal } from "./symbols.js";
|
|
4
|
+
|
|
4
5
|
//#region src/shared/meta.ts
|
|
5
6
|
const globalWithMeta = globalThis;
|
|
6
7
|
if (globalWithMeta.__TYPEGPU_VERSION__ !== void 0) console.warn(`Found duplicate TypeGPU version. First was ${globalWithMeta.__TYPEGPU_VERSION__}, this one is ${version}. This may cause unexpected behavior.`);
|
|
@@ -57,5 +58,6 @@ function setMetaData(definition, metaData) {
|
|
|
57
58
|
...metaData
|
|
58
59
|
});
|
|
59
60
|
}
|
|
61
|
+
|
|
60
62
|
//#endregion
|
|
61
|
-
export { PERF, getMetaData, getName, hasTinyestMetadata, isNamable, setName };
|
|
63
|
+
export { PERF, getMetaData, getName, hasTinyestMetadata, isNamable, setName };
|
package/shared/repr.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { TgpuTexture } from "../core/texture/texture.js";
|
|
|
7
7
|
import { Disarray, Undecorate } from "../data/dataTypes.js";
|
|
8
8
|
|
|
9
9
|
//#region src/shared/repr.d.ts
|
|
10
|
+
|
|
10
11
|
/**
|
|
11
12
|
* Extracts the inferred representation of a resource.
|
|
12
13
|
* For inferring types as seen by the GPU, see {@link InferGPU}
|
package/shared/stringify.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isMatInstance, isVecInstance } from "../data/wgslTypes.js";
|
|
2
|
+
|
|
2
3
|
//#region src/shared/stringify.ts
|
|
3
4
|
function safeStringify(item) {
|
|
4
5
|
const asString = String(item);
|
|
@@ -16,5 +17,6 @@ function niceStringify(item) {
|
|
|
16
17
|
if (item && typeof item === "object") return `{ ${Object.entries(item).map(([key, value]) => `${key}: ${niceStringify(value)}`).join(", ")} }`;
|
|
17
18
|
return String(item);
|
|
18
19
|
}
|
|
20
|
+
|
|
19
21
|
//#endregion
|
|
20
|
-
export { niceStringify, safeStringify };
|
|
22
|
+
export { niceStringify, safeStringify };
|
package/shared/symbols.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { version } from "../package.js";
|
|
2
|
+
|
|
2
3
|
//#region src/shared/symbols.ts
|
|
3
4
|
const $internal = Symbol(`typegpu:${version}:$internal`);
|
|
4
5
|
/**
|
|
@@ -32,17 +33,48 @@ const $gpuCallable = Symbol(`typegpu:${version}:$gpuCallable`);
|
|
|
32
33
|
* Type token for the inferred (CPU & GPU) representation of a resource
|
|
33
34
|
*/
|
|
34
35
|
const $repr = Symbol(`typegpu:${version}:$repr`);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
Symbol(`typegpu:${version}:$
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Type token for the inferred (GPU-side) representation of a resource
|
|
38
|
+
* If present, it shadows the value of `$repr` for GPU-side inference.
|
|
39
|
+
*/
|
|
40
|
+
const $gpuRepr = Symbol(`typegpu:${version}:$gpuRepr`);
|
|
41
|
+
/**
|
|
42
|
+
* Type token for the inferred partial representation of a resource.
|
|
43
|
+
* If present, it shadows the value of `$repr` for use in partial IO.
|
|
44
|
+
*/
|
|
45
|
+
const $reprPartial = Symbol(`typegpu:${version}:$reprPartial`);
|
|
46
|
+
/**
|
|
47
|
+
* Type token for the inferred patch representation of a resource.
|
|
48
|
+
* Used by the `buffer.patch` API with `Record<number, T>` sparse arrays.
|
|
49
|
+
*/
|
|
50
|
+
const $reprPatch = Symbol(`typegpu:${version}:$reprPatch`);
|
|
51
|
+
/**
|
|
52
|
+
* Type token for the write-side (input) representation of a resource.
|
|
53
|
+
*/
|
|
54
|
+
const $inRepr = Symbol(`typegpu:${version}:$inRepr`);
|
|
55
|
+
/**
|
|
56
|
+
* Type token holding schemas that are identical in memory layout.
|
|
57
|
+
*/
|
|
58
|
+
const $memIdent = Symbol(`typegpu:${version}:$memIdent`);
|
|
59
|
+
/**
|
|
60
|
+
* Type token, signaling that a schema can be used in a storage buffer.
|
|
61
|
+
*/
|
|
62
|
+
const $validStorageSchema = Symbol(`typegpu:${version}:$invalidStorageSchema`);
|
|
63
|
+
/**
|
|
64
|
+
* Type token, signaling that a schema can be used in a uniform buffer.
|
|
65
|
+
*/
|
|
66
|
+
const $validUniformSchema = Symbol(`typegpu:${version}:$validUniformSchema`);
|
|
67
|
+
/**
|
|
68
|
+
* Type token, signaling that a schema can be used in a vertex buffer.
|
|
69
|
+
*/
|
|
70
|
+
const $validVertexSchema = Symbol(`typegpu:${version}:$validVertexSchema`);
|
|
71
|
+
/**
|
|
72
|
+
* Type token, containing a reason for why the schema is invalid (if it is).
|
|
73
|
+
*/
|
|
74
|
+
const $invalidSchemaReason = Symbol(`typegpu:${version}:$invalidSchemaReason`);
|
|
44
75
|
function isMarkedInternal(value) {
|
|
45
76
|
return !!value?.[$internal];
|
|
46
77
|
}
|
|
78
|
+
|
|
47
79
|
//#endregion
|
|
48
|
-
export { $cast, $getNameForward, $gpuCallable, $gpuValueOf, $internal, $ownSnippet, $providing, $repr, $resolve, isMarkedInternal };
|
|
80
|
+
export { $cast, $getNameForward, $gpuCallable, $gpuValueOf, $internal, $ownSnippet, $providing, $repr, $resolve, isMarkedInternal };
|
package/shared/utilityTypes.js
CHANGED
package/shared/vertexFormat.js
CHANGED
package/std/array.d.ts
CHANGED
|
@@ -2,6 +2,6 @@ import { DualFn } from "../types.js";
|
|
|
2
2
|
import { _ref } from "../data/ref.js";
|
|
3
3
|
|
|
4
4
|
//#region src/std/array.d.ts
|
|
5
|
-
declare const arrayLength: DualFn
|
|
5
|
+
declare const arrayLength: DualFn<(a: unknown[] | _ref<unknown[]>) => number>;
|
|
6
6
|
//#endregion
|
|
7
7
|
export { arrayLength };
|
package/std/array.js
CHANGED
|
@@ -4,6 +4,7 @@ import { ptrFn } from "../data/ptr.js";
|
|
|
4
4
|
import { isRef } from "../data/ref.js";
|
|
5
5
|
import { abstractInt, u32 } from "../data/numeric.js";
|
|
6
6
|
import { dualImpl } from "../core/function/dualImpl.js";
|
|
7
|
+
|
|
7
8
|
//#region src/std/array.ts
|
|
8
9
|
const sizeOfPointedToArray = (dataType) => isPtr(dataType) && isWgslArray(dataType.inner) ? dataType.inner.elementCount : 0;
|
|
9
10
|
const arrayLength = dualImpl({
|
|
@@ -21,5 +22,6 @@ const arrayLength = dualImpl({
|
|
|
21
22
|
return length > 0 ? `${length}` : stitch`arrayLength(${a})`;
|
|
22
23
|
}
|
|
23
24
|
});
|
|
25
|
+
|
|
24
26
|
//#endregion
|
|
25
|
-
export { arrayLength };
|
|
27
|
+
export { arrayLength };
|
package/std/atomic.d.ts
CHANGED
|
@@ -3,17 +3,17 @@ import { atomicI32, atomicU32 } from "../data/wgslTypes.js";
|
|
|
3
3
|
|
|
4
4
|
//#region src/std/atomic.d.ts
|
|
5
5
|
type AnyAtomic = atomicI32 | atomicU32;
|
|
6
|
-
declare const workgroupBarrier: DualFn
|
|
7
|
-
declare const storageBarrier: DualFn
|
|
8
|
-
declare const textureBarrier: DualFn
|
|
9
|
-
declare const atomicLoad: DualFn
|
|
10
|
-
declare const atomicStore: DualFn
|
|
11
|
-
declare const atomicAdd: DualFn
|
|
12
|
-
declare const atomicSub: DualFn
|
|
13
|
-
declare const atomicMax: DualFn
|
|
14
|
-
declare const atomicMin: DualFn
|
|
15
|
-
declare const atomicAnd: DualFn
|
|
16
|
-
declare const atomicOr: DualFn
|
|
17
|
-
declare const atomicXor: DualFn
|
|
6
|
+
declare const workgroupBarrier: DualFn<(...args: never[]) => unknown>;
|
|
7
|
+
declare const storageBarrier: DualFn<(...args: never[]) => unknown>;
|
|
8
|
+
declare const textureBarrier: DualFn<(...args: never[]) => unknown>;
|
|
9
|
+
declare const atomicLoad: DualFn<(<T extends AnyAtomic>(a: T) => number)>;
|
|
10
|
+
declare const atomicStore: DualFn<(<T extends AnyAtomic>(a: T, value: number) => void)>;
|
|
11
|
+
declare const atomicAdd: DualFn<(<T extends AnyAtomic>(a: T, value: number) => number)>;
|
|
12
|
+
declare const atomicSub: DualFn<(<T extends AnyAtomic>(a: T, value: number) => number)>;
|
|
13
|
+
declare const atomicMax: DualFn<(<T extends AnyAtomic>(a: T, value: number) => number)>;
|
|
14
|
+
declare const atomicMin: DualFn<(<T extends AnyAtomic>(a: T, value: number) => number)>;
|
|
15
|
+
declare const atomicAnd: DualFn<(<T extends AnyAtomic>(a: T, value: number) => number)>;
|
|
16
|
+
declare const atomicOr: DualFn<(<T extends AnyAtomic>(a: T, value: number) => number)>;
|
|
17
|
+
declare const atomicXor: DualFn<(<T extends AnyAtomic>(a: T, value: number) => number)>;
|
|
18
18
|
//#endregion
|
|
19
19
|
export { atomicAdd, atomicAnd, atomicLoad, atomicMax, atomicMin, atomicOr, atomicStore, atomicSub, atomicXor, storageBarrier, textureBarrier, workgroupBarrier };
|
package/std/atomic.js
CHANGED
|
@@ -3,6 +3,7 @@ import { stitch } from "../core/resolve/stitch.js";
|
|
|
3
3
|
import { safeStringify } from "../shared/stringify.js";
|
|
4
4
|
import { i32, u32 } from "../data/numeric.js";
|
|
5
5
|
import { dualImpl } from "../core/function/dualImpl.js";
|
|
6
|
+
|
|
6
7
|
//#region src/std/atomic.ts
|
|
7
8
|
const workgroupBarrier = dualImpl({
|
|
8
9
|
name: "workgroupBarrier",
|
|
@@ -107,5 +108,6 @@ const atomicXor = dualImpl({
|
|
|
107
108
|
signature: atomicOpSignature,
|
|
108
109
|
codegenImpl: (_ctx, [a, value]) => stitch`atomicXor(&${a}, ${value})`
|
|
109
110
|
});
|
|
111
|
+
|
|
110
112
|
//#endregion
|
|
111
|
-
export { atomicAdd, atomicAnd, atomicLoad, atomicMax, atomicMin, atomicOr, atomicStore, atomicSub, atomicXor, storageBarrier, textureBarrier, workgroupBarrier };
|
|
113
|
+
export { atomicAdd, atomicAnd, atomicLoad, atomicMax, atomicMin, atomicOr, atomicStore, atomicSub, atomicXor, storageBarrier, textureBarrier, workgroupBarrier };
|
package/std/bitcast.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { v2f, v2i, v2u, v3f, v3i, v3u, v4f, v4i, v4u } from "../data/wgslTypes.j
|
|
|
3
3
|
|
|
4
4
|
//#region src/std/bitcast.d.ts
|
|
5
5
|
type BitcastU32toF32Overload = ((value: number) => number) & ((value: v2u) => v2f) & ((value: v3u) => v3f) & ((value: v4u) => v4f);
|
|
6
|
-
declare const bitcastU32toF32: DualFn
|
|
6
|
+
declare const bitcastU32toF32: DualFn<BitcastU32toF32Overload>;
|
|
7
7
|
type BitcastU32toI32Overload = ((value: number) => number) & ((value: v2u) => v2i) & ((value: v3u) => v3i) & ((value: v4u) => v4i);
|
|
8
|
-
declare const bitcastU32toI32: DualFn
|
|
8
|
+
declare const bitcastU32toI32: DualFn<BitcastU32toI32Overload>;
|
|
9
9
|
//#endregion
|
|
10
10
|
export { bitcastU32toF32, bitcastU32toI32 };
|
package/std/bitcast.js
CHANGED
|
@@ -6,6 +6,7 @@ import { vec2f, vec2i, vec3f, vec3i, vec4f, vec4i } from "../data/vector.js";
|
|
|
6
6
|
import { dualImpl } from "../core/function/dualImpl.js";
|
|
7
7
|
import { bitcastU32toF32Impl, bitcastU32toI32Impl } from "../data/numberOps.js";
|
|
8
8
|
import { VectorOps } from "../data/vectorOps.js";
|
|
9
|
+
|
|
9
10
|
//#region src/std/bitcast.ts
|
|
10
11
|
const bitcastU32toF32 = dualImpl({
|
|
11
12
|
name: "bitcastU32toF32",
|
|
@@ -37,5 +38,6 @@ const bitcastU32toI32 = dualImpl({
|
|
|
37
38
|
};
|
|
38
39
|
}
|
|
39
40
|
});
|
|
41
|
+
|
|
40
42
|
//#endregion
|
|
41
|
-
export { bitcastU32toF32, bitcastU32toI32 };
|
|
43
|
+
export { bitcastU32toF32, bitcastU32toI32 };
|