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/tgsl/shellless.js
CHANGED
|
@@ -5,6 +5,7 @@ import { WgslTypeError } from "../errors.js";
|
|
|
5
5
|
import { RefOperator } from "../data/ref.js";
|
|
6
6
|
import { concretize } from "./generationHelpers.js";
|
|
7
7
|
import { createShelllessImpl } from "../core/function/shelllessImpl.js";
|
|
8
|
+
|
|
8
9
|
//#region src/tgsl/shellless.ts
|
|
9
10
|
function shallowEqualSchemas(a, b) {
|
|
10
11
|
if (a.type !== b.type) return false;
|
|
@@ -42,5 +43,6 @@ var ShelllessRepository = class {
|
|
|
42
43
|
return shellless;
|
|
43
44
|
}
|
|
44
45
|
};
|
|
46
|
+
|
|
45
47
|
//#endregion
|
|
46
|
-
export { ShelllessRepository };
|
|
48
|
+
export { ShelllessRepository };
|
package/tgsl/wgslGenerator.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Origin, ResolvedSnippet, Snippet } from "../data/snippet.js";
|
|
2
2
|
import { GenerationCtx } from "./generationHelpers.js";
|
|
3
|
+
import { FunctionDefinitionOptions } from "./shaderGenerator_members.js";
|
|
3
4
|
import { ShaderGenerator } from "./shaderGenerator.js";
|
|
4
5
|
import { BaseData, StorableData } from "../data/wgslTypes.js";
|
|
5
6
|
import { UnknownData } from "../data/dataTypes.js";
|
|
@@ -22,7 +23,7 @@ declare class WgslGenerator implements ShaderGenerator {
|
|
|
22
23
|
*/
|
|
23
24
|
_typedExpression(expression: tinyest.Expression, expectedType: BaseData | BaseData[]): Snippet;
|
|
24
25
|
_expression(expression: tinyest.Expression): Snippet;
|
|
25
|
-
functionDefinition(
|
|
26
|
+
functionDefinition(options: FunctionDefinitionOptions): string;
|
|
26
27
|
/**
|
|
27
28
|
* Generates a WGSL type string for the given data type, and adds necessary
|
|
28
29
|
* definitions to the shader preamble. This shouldn't be called directly, only
|
|
@@ -30,6 +31,7 @@ declare class WgslGenerator implements ShaderGenerator {
|
|
|
30
31
|
*/
|
|
31
32
|
typeAnnotation(data: BaseData): string;
|
|
32
33
|
typeInstantiation(schema: BaseData, args: readonly Snippet[]): ResolvedSnippet;
|
|
34
|
+
_return(statement: tinyest.Return): string;
|
|
33
35
|
_statement(statement: tinyest.Statement): string;
|
|
34
36
|
}
|
|
35
37
|
//#endregion
|
package/tgsl/wgslGenerator.js
CHANGED
|
@@ -13,6 +13,7 @@ import { convertStructValues, convertToCommonType, tryConvertSnippet } from "./c
|
|
|
13
13
|
import { bool, i32, u32 } from "../data/numeric.js";
|
|
14
14
|
import { ArrayExpression, coerceToSnippet, concretize, numericLiteralToSnippet } from "./generationHelpers.js";
|
|
15
15
|
import { vec2u, vec3u, vec4u } from "../data/vector.js";
|
|
16
|
+
import { getAttributesString } from "../data/attributes.js";
|
|
16
17
|
import { AutoStruct } from "../data/autoStruct.js";
|
|
17
18
|
import { add, div, mul, neg, sub } from "../std/operators.js";
|
|
18
19
|
import { accessProp } from "./accessProp.js";
|
|
@@ -27,6 +28,7 @@ import { mathToStd } from "./math.js";
|
|
|
27
28
|
import { isTgpuRange } from "../std/range.js";
|
|
28
29
|
import { getElementSnippet, getElementType, getLoopVarKind, getRangeSnippets } from "./forOfUtils.js";
|
|
29
30
|
import * as tinyest from "tinyest";
|
|
31
|
+
|
|
30
32
|
//#region src/tgsl/wgslGenerator.ts
|
|
31
33
|
const { NodeTypeCatalog: NODE } = tinyest;
|
|
32
34
|
const parenthesizedOps = [
|
|
@@ -215,12 +217,12 @@ ${this.ctx.pre}}`;
|
|
|
215
217
|
const lhsExpr = this._expression(lhs);
|
|
216
218
|
if ((op === "||" || op === "&&") && isKnownAtComptime(lhsExpr)) {
|
|
217
219
|
if (!(op === "&&" ? lhsExpr.value : !lhsExpr.value)) return snip(op === "||", bool, "constant");
|
|
218
|
-
const rhsExpr = this._expression(rhs);
|
|
219
|
-
if (rhsExpr.dataType === UnknownData) throw new WgslTypeError(`Right-hand side of '${op}' is of unknown type`);
|
|
220
|
-
if (isKnownAtComptime(rhsExpr)) return snip(!!rhsExpr.value, bool, "constant");
|
|
221
|
-
const convRhs = tryConvertSnippet(this.ctx, rhsExpr, bool, false);
|
|
222
|
-
const rhsStr = this.ctx.resolve(convRhs.value, convRhs.dataType).value;
|
|
223
|
-
return snip(rhsStr, bool, "runtime");
|
|
220
|
+
const rhsExpr$1 = this._expression(rhs);
|
|
221
|
+
if (rhsExpr$1.dataType === UnknownData) throw new WgslTypeError(`Right-hand side of '${op}' is of unknown type`);
|
|
222
|
+
if (isKnownAtComptime(rhsExpr$1)) return snip(!!rhsExpr$1.value, bool, "constant");
|
|
223
|
+
const convRhs$1 = tryConvertSnippet(this.ctx, rhsExpr$1, bool, false);
|
|
224
|
+
const rhsStr$1 = this.ctx.resolve(convRhs$1.value, convRhs$1.dataType).value;
|
|
225
|
+
return snip(rhsStr$1, bool, "runtime");
|
|
224
226
|
}
|
|
225
227
|
const rhsExpr = this._expression(rhs);
|
|
226
228
|
if (rhsExpr.value instanceof RefOperator) throw new WgslTypeError(stitch`Cannot assign a ref to an existing variable '${lhsExpr}', define a new variable instead.`);
|
|
@@ -291,7 +293,7 @@ ${this.ctx.pre}}`;
|
|
|
291
293
|
if (!accessed) {
|
|
292
294
|
const targetStr = this.ctx.resolve(target.value, target.dataType).value;
|
|
293
295
|
const propertyStr = this.ctx.resolve(property.value, property.dataType).value;
|
|
294
|
-
throw new Error(`
|
|
296
|
+
throw new Error(`Index access '${targetStr}[${propertyStr}]' is invalid. If the value is an array, to address this, consider one of the following approaches: (1) declare the array using 'tgpu.const', (2) store the array in a buffer, or (3) define the array within the GPU function scope.`);
|
|
295
297
|
}
|
|
296
298
|
return accessed;
|
|
297
299
|
}
|
|
@@ -421,8 +423,13 @@ ${this.ctx.pre}}`;
|
|
|
421
423
|
if (expression[0] === NODE.preUpdate) throw new Error("Cannot use pre-updates in TypeGPU functions.");
|
|
422
424
|
assertExhaustive(expression);
|
|
423
425
|
}
|
|
424
|
-
functionDefinition(
|
|
425
|
-
|
|
426
|
+
functionDefinition(options) {
|
|
427
|
+
const body = this._block(options.body);
|
|
428
|
+
const returnType = options.determineReturnType();
|
|
429
|
+
const argList = options.args.filter((arg) => arg.used || options.functionType === "normal").map((arg) => {
|
|
430
|
+
return `${getAttributesString(arg.decoratedType)}${arg.name}: ${this.ctx.resolve(arg.decoratedType).value}`;
|
|
431
|
+
}).join(", ");
|
|
432
|
+
return `${returnType.type !== "void" ? `(${argList}) -> ${getAttributesString(returnType)}${this.ctx.resolve(returnType).value} ` : `(${argList}) `}${body}`;
|
|
426
433
|
}
|
|
427
434
|
/**
|
|
428
435
|
* Generates a WGSL type string for the given data type, and adds necessary
|
|
@@ -436,35 +443,36 @@ ${this.ctx.pre}}`;
|
|
|
436
443
|
if (args.length === 1 && args[0]?.dataType === schema) return snip(stitch`${args[0]}`, schema, fallthroughCopyOrigin(args[0].origin));
|
|
437
444
|
return snip(stitch`${this.ctx.resolve(schema).value}(${args})`, schema, "runtime");
|
|
438
445
|
}
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
const
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
let returnSnippet = expectedReturnType ? this._typedExpression(returnNode, expectedReturnType) : this._expression(returnNode);
|
|
451
|
-
if (returnSnippet.value instanceof RefOperator) throw new WgslTypeError(stitch`Cannot return references, returning '${returnSnippet.value.snippet}'`);
|
|
452
|
-
if (returnSnippet.origin === "argument" && !isNaturallyEphemeral(returnSnippet.dataType) && this.ctx.topFunctionScope?.functionType === "normal") throw new WgslTypeError(stitch`Cannot return references to arguments, returning '${returnSnippet}'. Copy the argument before returning it.`);
|
|
453
|
-
if (!expectedReturnType && !isEphemeralSnippet(returnSnippet) && returnSnippet.origin !== "this-function") {
|
|
454
|
-
const str = this.ctx.resolve(returnSnippet.value, returnSnippet.dataType).value;
|
|
455
|
-
const typeStr = this.ctx.resolve(unptr(returnSnippet.dataType)).value;
|
|
456
|
-
throw new WgslTypeError(`'return ${str};' is invalid, cannot return references.
|
|
446
|
+
_return(statement) {
|
|
447
|
+
const returnNode = statement[1];
|
|
448
|
+
if (returnNode !== void 0) {
|
|
449
|
+
const expectedReturnType = this.ctx.topFunctionReturnType;
|
|
450
|
+
let returnSnippet = expectedReturnType ? this._typedExpression(returnNode, expectedReturnType) : this._expression(returnNode);
|
|
451
|
+
if (returnSnippet.value instanceof RefOperator) throw new WgslTypeError(stitch`Cannot return references, returning '${returnSnippet.value.snippet}'`);
|
|
452
|
+
if (returnSnippet.origin === "argument" && !isNaturallyEphemeral(returnSnippet.dataType) && this.ctx.topFunctionScope?.functionType === "normal") throw new WgslTypeError(stitch`Cannot return references to arguments, returning '${returnSnippet}'. Copy the argument before returning it.`);
|
|
453
|
+
if (!expectedReturnType && !isEphemeralSnippet(returnSnippet) && returnSnippet.origin !== "this-function") {
|
|
454
|
+
const str = this.ctx.resolve(returnSnippet.value, returnSnippet.dataType).value;
|
|
455
|
+
const typeStr = this.ctx.resolve(unptr(returnSnippet.dataType)).value;
|
|
456
|
+
throw new WgslTypeError(`'return ${str};' is invalid, cannot return references.
|
|
457
457
|
-----
|
|
458
458
|
Try 'return ${typeStr}(${str});' instead.
|
|
459
459
|
-----`);
|
|
460
|
-
}
|
|
461
|
-
returnSnippet = tryConvertSnippet(this.ctx, returnSnippet, unptr(returnSnippet.dataType), false);
|
|
462
|
-
invariant(returnSnippet.dataType !== UnknownData, "Return type should be known");
|
|
463
|
-
this.ctx.reportReturnType(returnSnippet.dataType);
|
|
464
|
-
return stitch`${this.ctx.pre}return ${returnSnippet};`;
|
|
465
460
|
}
|
|
466
|
-
|
|
461
|
+
returnSnippet = tryConvertSnippet(this.ctx, returnSnippet, unptr(returnSnippet.dataType), false);
|
|
462
|
+
invariant(returnSnippet.dataType !== UnknownData, "Return type should be known");
|
|
463
|
+
this.ctx.reportReturnType(returnSnippet.dataType);
|
|
464
|
+
return stitch`${this.ctx.pre}return ${returnSnippet};`;
|
|
467
465
|
}
|
|
466
|
+
return `${this.ctx.pre}return;`;
|
|
467
|
+
}
|
|
468
|
+
_statement(statement) {
|
|
469
|
+
if (typeof statement === "string") {
|
|
470
|
+
const id = this._identifier(statement);
|
|
471
|
+
const resolved$1 = id.value && this.ctx.resolve(id.value).value;
|
|
472
|
+
return resolved$1 ? `${this.ctx.pre}${resolved$1};` : "";
|
|
473
|
+
}
|
|
474
|
+
if (typeof statement === "boolean") return `${this.ctx.pre}${statement ? "true" : "false"};`;
|
|
475
|
+
if (statement[0] === NODE.return) return this._return(statement);
|
|
468
476
|
if (statement[0] === NODE.if) {
|
|
469
477
|
const [_, condNode, consNode, altNode] = statement;
|
|
470
478
|
const condition = this._typedExpression(condNode, bool);
|
|
@@ -500,12 +508,12 @@ ${this.ctx.pre}else ${alternate}`;
|
|
|
500
508
|
}
|
|
501
509
|
if (!ephemeral) {
|
|
502
510
|
if (stmtType === NODE.let) {
|
|
503
|
-
const rhsStr = this.ctx.resolve(eq.value).value;
|
|
511
|
+
const rhsStr$1 = this.ctx.resolve(eq.value).value;
|
|
504
512
|
const rhsTypeStr = this.ctx.resolve(unptr(eq.dataType)).value;
|
|
505
|
-
throw new WgslTypeError(`'let ${rawId} = ${rhsStr}' is invalid, because references cannot be assigned to 'let' variable declarations.
|
|
513
|
+
throw new WgslTypeError(`'let ${rawId} = ${rhsStr$1}' is invalid, because references cannot be assigned to 'let' variable declarations.
|
|
506
514
|
-----
|
|
507
|
-
- Try 'let ${rawId} = ${rhsTypeStr}(${rhsStr})' if you need to reassign '${rawId}' later
|
|
508
|
-
- Try 'const ${rawId} = ${rhsStr}' if you won't reassign '${rawId}' later.
|
|
515
|
+
- Try 'let ${rawId} = ${rhsTypeStr}(${rhsStr$1})' if you need to reassign '${rawId}' later
|
|
516
|
+
- Try 'const ${rawId} = ${rhsStr$1}' if you won't reassign '${rawId}' later.
|
|
509
517
|
-----`);
|
|
510
518
|
}
|
|
511
519
|
if (eq.origin === "constant-tgpu-const-ref") varType = "const";
|
|
@@ -524,12 +532,12 @@ ${this.ctx.pre}else ${alternate}`;
|
|
|
524
532
|
else if (naturallyEphemeral) varType = eq.origin === "constant" ? "const" : "let";
|
|
525
533
|
} else if (eq.origin === "argument") {
|
|
526
534
|
if (!naturallyEphemeral) {
|
|
527
|
-
const rhsStr = this.ctx.resolve(eq.value).value;
|
|
535
|
+
const rhsStr$1 = this.ctx.resolve(eq.value).value;
|
|
528
536
|
const rhsTypeStr = this.ctx.resolve(unptr(eq.dataType)).value;
|
|
529
|
-
throw new WgslTypeError(`'let ${rawId} = ${rhsStr}' is invalid, because references to arguments cannot be assigned to 'let' variable declarations.
|
|
537
|
+
throw new WgslTypeError(`'let ${rawId} = ${rhsStr$1}' is invalid, because references to arguments cannot be assigned to 'let' variable declarations.
|
|
530
538
|
-----
|
|
531
|
-
- Try 'let ${rawId} = ${rhsTypeStr}(${rhsStr})' if you need to reassign '${rawId}' later
|
|
532
|
-
- Try 'const ${rawId} = ${rhsStr}' if you won't reassign '${rawId}' later.
|
|
539
|
+
- Try 'let ${rawId} = ${rhsTypeStr}(${rhsStr$1})' if you need to reassign '${rawId}' later
|
|
540
|
+
- Try 'const ${rawId} = ${rhsStr$1}' if you won't reassign '${rawId}' later.
|
|
533
541
|
-----`);
|
|
534
542
|
}
|
|
535
543
|
}
|
|
@@ -591,7 +599,7 @@ ${this.ctx.pre}else ${alternate}`;
|
|
|
591
599
|
const length = range.end.value;
|
|
592
600
|
if (length === 0) return "";
|
|
593
601
|
const { value } = iterableSnippet;
|
|
594
|
-
const elements = isTgpuRange(value) ? value.map((i) => coerceToSnippet(i)) : value instanceof ArrayExpression ? value.elements : Array.from({ length }, (_, i) => getElementSnippet(iterableSnippet, snip(i, u32, "constant")));
|
|
602
|
+
const elements = isTgpuRange(value) ? value.map((i) => coerceToSnippet(i)) : value instanceof ArrayExpression ? value.elements : Array.from({ length }, (_$1, i) => getElementSnippet(iterableSnippet, snip(i, u32, "constant")));
|
|
595
603
|
if (isEphemeralSnippet(elements[0]) && !isNaturallyEphemeral(elements[0]?.dataType)) throw new WgslTypeError("Cannot unroll loop. The elements of iterable are emphemeral but not naturally ephemeral.");
|
|
596
604
|
return elements.map((e, i) => `${this.ctx.pre}// unrolled iteration #${i}\n${this.ctx.pre}${this._block(blockified, { [originalLoopVarName]: e })}`).join("\n");
|
|
597
605
|
}
|
|
@@ -599,7 +607,7 @@ ${this.ctx.pre}else ${alternate}`;
|
|
|
599
607
|
const index = this.ctx.makeNameValid("i");
|
|
600
608
|
const forHeaderStr = stitch`${this.ctx.pre}for (var ${index} = ${range.start}; ${index} ${range.comparison} ${range.end}; ${index} += ${range.step})`;
|
|
601
609
|
let bodyStr = "";
|
|
602
|
-
if (isTgpuRange(iterableSnippet.value)) bodyStr = this._block(blockified, { [originalLoopVarName]: snip(index,
|
|
610
|
+
if (isTgpuRange(iterableSnippet.value)) bodyStr = this._block(blockified, { [originalLoopVarName]: snip(index, range.start.dataType, "runtime") });
|
|
603
611
|
else {
|
|
604
612
|
this.ctx.indent();
|
|
605
613
|
ctxIndent = true;
|
|
@@ -644,5 +652,7 @@ function blockifySingleStatement(statement) {
|
|
|
644
652
|
return typeof statement !== "object" || statement[0] !== NODE.block ? [NODE.block, [statement]] : statement;
|
|
645
653
|
}
|
|
646
654
|
const wgslGenerator = new WgslGenerator();
|
|
655
|
+
var wgslGenerator_default = wgslGenerator;
|
|
656
|
+
|
|
647
657
|
//#endregion
|
|
648
|
-
export { WgslGenerator,
|
|
658
|
+
export { WgslGenerator, wgslGenerator_default as default };
|
package/types.d.ts
CHANGED
|
@@ -49,11 +49,17 @@ type ItemLayer = {
|
|
|
49
49
|
type: 'item';
|
|
50
50
|
usedSlots: Set<TgpuSlot<unknown>>;
|
|
51
51
|
};
|
|
52
|
+
type FunctionArgumentAccess = () => Snippet | undefined;
|
|
53
|
+
interface FunctionArgument {
|
|
54
|
+
name: string;
|
|
55
|
+
access: FunctionArgumentAccess;
|
|
56
|
+
decoratedType: BaseData;
|
|
57
|
+
used: boolean;
|
|
58
|
+
}
|
|
52
59
|
type FunctionScopeLayer = {
|
|
53
60
|
type: 'functionScope';
|
|
54
61
|
functionType: 'normal' | 'compute' | 'vertex' | 'fragment';
|
|
55
|
-
|
|
56
|
-
argAliases: Record<string, Snippet>;
|
|
62
|
+
argAccess: Record<string, FunctionArgumentAccess>;
|
|
57
63
|
externalMap: Record<string, unknown>;
|
|
58
64
|
/**
|
|
59
65
|
* The return type of the function. If undefined, the type should be inferred
|
|
@@ -81,12 +87,11 @@ interface ItemStateStack {
|
|
|
81
87
|
readonly topFunctionScope: FunctionScopeLayer | undefined;
|
|
82
88
|
pushItem(): void;
|
|
83
89
|
pushSlotBindings(pairs: SlotValuePair[]): void;
|
|
84
|
-
pushFunctionScope(functionType: 'normal' | TgpuShaderStage,
|
|
90
|
+
pushFunctionScope(functionType: 'normal' | TgpuShaderStage, argAccess: Record<string, FunctionArgumentAccess>,
|
|
85
91
|
/**
|
|
86
92
|
* The return type of the function. If undefined, the type should be inferred
|
|
87
93
|
* from the implementation (relevant for shellless functions).
|
|
88
94
|
*/
|
|
89
|
-
|
|
90
95
|
returnType: BaseData | undefined, externalMap: Record<string, unknown>): FunctionScopeLayer;
|
|
91
96
|
pushBlockScope(): void;
|
|
92
97
|
setBlockExternals(externals: Record<string, Snippet>): void;
|
|
@@ -218,8 +223,7 @@ interface ResolutionCtx {
|
|
|
218
223
|
*/
|
|
219
224
|
resolveSnippet(snippet: Snippet): ResolvedSnippet;
|
|
220
225
|
fnToWgsl(options: FnToWgslOptions): {
|
|
221
|
-
|
|
222
|
-
body: Wgsl;
|
|
226
|
+
code: string;
|
|
223
227
|
returnType: BaseData;
|
|
224
228
|
};
|
|
225
229
|
withVaryingLocations<T>(locations: Record<string, number>, callback: () => T): T;
|
|
@@ -262,4 +266,4 @@ type AnyFn = (...args: never[]) => unknown;
|
|
|
262
266
|
type DualFn<T extends AnyFn> = T & GPUCallable<Parameters<T>>;
|
|
263
267
|
type BindableBufferUsage = 'uniform' | 'readonly' | 'mutable';
|
|
264
268
|
//#endregion
|
|
265
|
-
export { BindableBufferUsage, DualFn, FunctionScopeLayer, GPUCallable, ResolutionCtx, ResolvableObject, SelfResolvable, TgpuShaderStage, Wgsl, WithCast };
|
|
269
|
+
export { BindableBufferUsage, DualFn, FunctionArgument, FunctionScopeLayer, GPUCallable, ResolutionCtx, ResolvableObject, SelfResolvable, TgpuShaderStage, Wgsl, WithCast };
|
package/types.js
CHANGED
|
@@ -2,6 +2,7 @@ import { $cast, $gpuCallable, $ownSnippet, $resolve } from "./shared/symbols.js"
|
|
|
2
2
|
import { isWgslData } from "./data/wgslTypes.js";
|
|
3
3
|
import { UnknownData } from "./data/dataTypes.js";
|
|
4
4
|
import { isLazy, isProviding, isSlot } from "./core/slot/slotTypes.js";
|
|
5
|
+
|
|
5
6
|
//#region src/types.ts
|
|
6
7
|
var NormalState = class {
|
|
7
8
|
type = "normal";
|
|
@@ -39,5 +40,6 @@ function isWgsl(value) {
|
|
|
39
40
|
function isGPUBuffer(value) {
|
|
40
41
|
return !!value && typeof value === "object" && "getMappedRange" in value && "mapAsync" in value;
|
|
41
42
|
}
|
|
43
|
+
|
|
42
44
|
//#endregion
|
|
43
|
-
export { CodegenState, NormalState, SimulationState, getOwnSnippet, hasCast, isGPUBuffer, isGPUCallable, isKnownAtComptime, isSelfResolvable, isWgsl };
|
|
45
|
+
export { CodegenState, NormalState, SimulationState, getOwnSnippet, hasCast, isGPUBuffer, isGPUCallable, isKnownAtComptime, isSelfResolvable, isWgsl };
|
package/wgslExtensions.js
CHANGED