typegpu 0.10.2 → 0.11.0-rc.1
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 +6 -11
- package/builtin.js +1 -3
- package/common/fullScreenTriangle.d.ts +1 -5
- package/common/fullScreenTriangle.js +1 -3
- package/common/index.d.ts +3 -2
- package/common/index.js +6 -4
- package/common/writeSoA.d.ts +16 -0
- package/common/writeSoA.js +90 -0
- package/core/buffer/buffer.d.ts +12 -7
- package/core/buffer/buffer.js +102 -53
- package/core/buffer/bufferShorthand.d.ts +5 -5
- package/core/buffer/bufferShorthand.js +9 -5
- package/core/buffer/bufferUsage.d.ts +0 -2
- package/core/buffer/bufferUsage.js +6 -4
- package/core/constant/tgpuConstant.d.ts +2 -1
- package/core/constant/tgpuConstant.js +8 -7
- package/core/declare/tgpuDeclare.js +8 -9
- package/core/function/autoIO.d.ts +7 -6
- package/core/function/autoIO.js +1 -3
- package/core/function/comptime.js +1 -3
- package/core/function/createCallableSchema.js +4 -6
- package/core/function/dualImpl.js +1 -3
- package/core/function/entryInputRouter.js +39 -0
- package/core/function/extractArgs.js +2 -2
- package/core/function/fnCore.js +19 -8
- package/core/function/fnTypes.d.ts +14 -8
- package/core/function/ioSchema.js +24 -3
- package/core/function/shelllessImpl.js +1 -3
- package/core/function/templateUtils.js +1 -2
- package/core/function/tgpuComputeFn.d.ts +2 -3
- package/core/function/tgpuComputeFn.js +9 -16
- package/core/function/tgpuFn.d.ts +2 -2
- package/core/function/tgpuFn.js +1 -3
- package/core/function/tgpuFragmentFn.d.ts +5 -1
- package/core/function/tgpuFragmentFn.js +5 -10
- package/core/function/tgpuVertexFn.d.ts +4 -0
- package/core/function/tgpuVertexFn.js +6 -12
- package/core/pipeline/applyPipelineState.js +1 -3
- package/core/pipeline/computePipeline.d.ts +2 -6
- package/core/pipeline/computePipeline.js +64 -63
- package/core/pipeline/connectAttachmentToShader.js +1 -3
- package/core/pipeline/connectTargetsToShader.js +1 -3
- package/core/pipeline/limitsOverflow.js +1 -2
- package/core/pipeline/pipelineUtils.js +29 -0
- package/core/pipeline/renderPipeline.d.ts +23 -5
- package/core/pipeline/renderPipeline.js +32 -14
- package/core/pipeline/timeable.d.ts +0 -3
- package/core/pipeline/timeable.js +3 -9
- package/core/pipeline/typeGuards.js +1 -3
- package/core/querySet/querySet.d.ts +0 -2
- package/core/querySet/querySet.js +37 -36
- package/core/rawCodeSnippet/tgpuRawCodeSnippet.js +1 -3
- package/core/resolve/externals.d.ts +0 -2
- package/core/resolve/externals.js +2 -4
- package/core/resolve/namespace.js +1 -3
- package/core/resolve/resolveData.js +1 -3
- package/core/resolve/stitch.js +1 -3
- package/core/resolve/tgpuResolve.d.ts +3 -1
- package/core/resolve/tgpuResolve.js +3 -5
- package/core/root/configurableImpl.js +2 -3
- package/core/root/init.d.ts +0 -5
- package/core/root/init.js +35 -28
- package/core/root/rootTypes.d.ts +25 -5
- package/core/sampler/sampler.d.ts +0 -4
- package/core/sampler/sampler.js +3 -3
- package/core/simulate/tgpuSimulate.js +1 -3
- package/core/slot/accessor.d.ts +0 -4
- package/core/slot/accessor.js +1 -3
- package/core/slot/internalSlots.js +1 -3
- package/core/slot/lazy.js +1 -3
- package/core/slot/slot.js +2 -3
- package/core/slot/slotTypes.js +1 -3
- package/core/texture/externalTexture.d.ts +0 -6
- package/core/texture/externalTexture.js +2 -3
- package/core/texture/texture.d.ts +0 -4
- package/core/texture/texture.js +5 -3
- package/core/texture/textureFormats.js +1 -3
- package/core/texture/textureUtils.js +1 -3
- package/core/texture/usageExtension.js +1 -3
- package/core/unroll/tgpuUnroll.d.ts +58 -3
- package/core/unroll/tgpuUnroll.js +63 -5
- package/core/valueProxyUtils.js +1 -3
- package/core/variable/tgpuVariable.js +1 -3
- package/core/vertexLayout/connectAttributesToShader.js +1 -3
- package/core/vertexLayout/vertexLayout.js +9 -9
- package/data/alignIO.js +1 -2
- package/data/alignmentOf.d.ts +0 -1
- package/data/alignmentOf.js +1 -3
- package/data/array.d.ts +1 -3
- package/data/array.js +2 -4
- package/data/atomic.js +2 -3
- package/data/attributes.js +3 -3
- package/data/autoStruct.d.ts +1 -3
- package/data/autoStruct.js +1 -3
- package/data/compiledIO.js +83 -86
- package/data/dataIO.js +46 -39
- package/data/dataTypes.d.ts +7 -7
- package/data/dataTypes.js +6 -3
- package/data/deepEqual.js +1 -3
- package/data/disarray.d.ts +1 -3
- package/data/disarray.js +1 -3
- package/data/getLongestContiguousPrefix.d.ts +0 -1
- package/data/getLongestContiguousPrefix.js +1 -3
- package/data/index.d.ts +3 -3
- package/data/index.js +10 -3
- package/data/isContiguous.d.ts +0 -1
- package/data/isContiguous.js +1 -3
- package/data/matrix.d.ts +8 -10
- package/data/matrix.js +32 -18
- package/data/numberOps.js +1 -2
- package/data/numeric.js +16 -29
- package/data/offsetUtils.d.ts +2 -2
- package/data/offsetUtils.js +3 -5
- package/data/offsets.js +1 -3
- package/data/partialIO.js +84 -39
- package/data/ptr.d.ts +0 -1
- package/data/ptr.js +1 -3
- package/data/ref.d.ts +0 -3
- package/data/ref.js +1 -3
- package/data/sampler.js +1 -3
- package/data/schemaCallWrapper.js +1 -3
- package/data/schemaMemoryLayout.js +1 -3
- package/data/sizeOf.d.ts +0 -1
- package/data/sizeOf.js +1 -3
- package/data/snippet.js +12 -3
- package/data/struct.js +1 -3
- package/data/texture.js +1 -3
- package/data/unstruct.js +1 -3
- package/data/vector.js +4 -12
- package/data/vectorImpl.js +27 -28
- package/data/vectorOps.js +20 -3
- package/data/vertexFormatData.js +2 -3
- package/data/wgslTypes.d.ts +39 -11
- package/data/wgslTypes.js +10 -3
- package/errors.js +6 -3
- package/execMode.js +1 -3
- package/extension.js +1 -3
- package/getGPUValue.js +1 -3
- package/index.d.ts +4 -2
- package/index.js +3 -3
- package/indexNamedExports.d.ts +3 -1
- package/mathUtils.js +1 -2
- package/memo.js +8 -8
- package/nameRegistry.js +1 -3
- package/package.js +2 -3
- package/package.json +5 -5
- package/resolutionCtx.d.ts +0 -10
- package/resolutionCtx.js +84 -18
- package/shared/env.js +1 -2
- package/shared/generators.js +1 -2
- package/shared/meta.js +1 -3
- package/shared/repr.d.ts +32 -2
- package/shared/stringify.js +1 -3
- package/shared/symbols.d.ts +10 -1
- package/shared/symbols.js +10 -33
- package/shared/utilityTypes.d.ts +6 -2
- package/shared/utilityTypes.js +1 -2
- package/shared/vertexFormat.js +1 -2
- package/std/array.d.ts +1 -1
- package/std/array.js +1 -3
- package/std/atomic.d.ts +12 -12
- package/std/atomic.js +1 -3
- package/std/bitcast.d.ts +2 -2
- package/std/bitcast.js +1 -3
- package/std/boolean.d.ts +30 -16
- package/std/boolean.js +37 -12
- package/std/derivative.d.ts +9 -9
- package/std/derivative.js +1 -3
- package/std/discard.d.ts +1 -1
- package/std/discard.js +1 -3
- package/std/extensions.d.ts +1 -3
- package/std/extensions.js +1 -3
- package/std/index.d.ts +5 -4
- package/std/index.js +8 -5
- package/std/matrix.d.ts +5 -5
- package/std/matrix.js +1 -3
- package/std/numeric.d.ts +78 -132
- package/std/numeric.js +1 -3
- package/std/operators.d.ts +16 -8
- package/std/operators.js +80 -6
- package/std/packing.d.ts +4 -4
- package/std/packing.js +1 -3
- package/std/range.d.ts +24 -0
- package/std/range.js +38 -0
- package/std/subgroup.d.ts +21 -21
- package/std/subgroup.js +1 -3
- package/std/texture.d.ts +20 -11
- package/std/texture.js +13 -3
- package/tgpu.js +1 -3
- package/tgpuBindGroupLayout.js +9 -8
- package/tgpuUnstable.js +1 -3
- package/tgsl/accessIndex.js +2 -4
- package/tgsl/accessProp.js +8 -6
- package/tgsl/consoleLog/deserializers.js +1 -3
- package/tgsl/consoleLog/logGenerator.js +2 -4
- package/tgsl/consoleLog/serializers.js +24 -26
- package/tgsl/consoleLog/types.d.ts +0 -2
- package/tgsl/consoleLog/types.js +1 -2
- package/tgsl/conversion.js +1 -3
- package/tgsl/forOfUtils.js +35 -9
- package/tgsl/generationHelpers.js +3 -3
- package/tgsl/math.js +1 -3
- package/tgsl/shaderGenerator.d.ts +10 -8
- package/tgsl/shaderGenerator_members.d.ts +2 -0
- package/tgsl/shaderGenerator_members.js +6 -0
- package/tgsl/shellless.js +1 -8
- package/tgsl/wgslGenerator.d.ts +36 -0
- package/tgsl/wgslGenerator.js +135 -81
- package/types.d.ts +14 -4
- package/types.js +3 -3
- package/wgslExtensions.js +1 -2
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { $gpuValueOf, $internal, $ownSnippet, $resolve } from "../../shared/symbols.js";
|
|
2
2
|
import { getName, setName } from "../../shared/meta.js";
|
|
3
3
|
import { isNaturallyEphemeral } from "../../data/wgslTypes.js";
|
|
4
|
+
import { isData } from "../../data/dataTypes.js";
|
|
4
5
|
import { snip } from "../../data/snippet.js";
|
|
5
6
|
import { inCodegenMode } from "../../execMode.js";
|
|
6
7
|
import { valueProxyHandler } from "../valueProxyUtils.js";
|
|
7
|
-
|
|
8
8
|
//#region src/core/constant/tgpuConstant.ts
|
|
9
|
-
/**
|
|
10
|
-
* Creates a module constant with specified value.
|
|
11
|
-
*/
|
|
12
9
|
function constant(dataType, value) {
|
|
10
|
+
if (!isData(dataType)) {
|
|
11
|
+
if (!Array.isArray(value)) throw new Error(`Expected an array value for a partially-applied array schema, but received: ${typeof value}.`);
|
|
12
|
+
return new TgpuConstImpl(dataType(value.length), value);
|
|
13
|
+
}
|
|
13
14
|
return new TgpuConstImpl(dataType, value);
|
|
14
15
|
}
|
|
15
16
|
function deepFreeze(object) {
|
|
@@ -23,10 +24,11 @@ function deepFreeze(object) {
|
|
|
23
24
|
var TgpuConstImpl = class {
|
|
24
25
|
[$internal] = {};
|
|
25
26
|
resourceType;
|
|
27
|
+
dataType;
|
|
26
28
|
#value;
|
|
27
29
|
constructor(dataType, value) {
|
|
28
|
-
this.dataType = dataType;
|
|
29
30
|
this.resourceType = "const";
|
|
31
|
+
this.dataType = dataType;
|
|
30
32
|
this.#value = value && typeof value === "object" ? deepFreeze(value) : value;
|
|
31
33
|
}
|
|
32
34
|
$name(label) {
|
|
@@ -62,6 +64,5 @@ var TgpuConstImpl = class {
|
|
|
62
64
|
return this.$;
|
|
63
65
|
}
|
|
64
66
|
};
|
|
65
|
-
|
|
66
67
|
//#endregion
|
|
67
|
-
export { constant };
|
|
68
|
+
export { constant };
|
|
@@ -2,7 +2,6 @@ import { $internal, $resolve } from "../../shared/symbols.js";
|
|
|
2
2
|
import { Void } from "../../data/wgslTypes.js";
|
|
3
3
|
import { snip } from "../../data/snippet.js";
|
|
4
4
|
import { applyExternals, replaceExternalsInWgsl } from "../resolve/externals.js";
|
|
5
|
-
|
|
6
5
|
//#region src/core/declare/tgpuDeclare.ts
|
|
7
6
|
/**
|
|
8
7
|
* Allows defining extra declarations that shall be included in the final WGSL code,
|
|
@@ -16,25 +15,25 @@ function declare(declaration) {
|
|
|
16
15
|
}
|
|
17
16
|
var TgpuDeclareImpl = class {
|
|
18
17
|
[$internal] = true;
|
|
19
|
-
externalsToApply = [];
|
|
18
|
+
#externalsToApply = [];
|
|
19
|
+
#declaration;
|
|
20
20
|
constructor(declaration) {
|
|
21
|
-
this
|
|
21
|
+
this.#declaration = declaration;
|
|
22
22
|
}
|
|
23
23
|
$uses(dependencyMap) {
|
|
24
|
-
this
|
|
24
|
+
this.#externalsToApply.push(dependencyMap);
|
|
25
25
|
return this;
|
|
26
26
|
}
|
|
27
27
|
[$resolve](ctx) {
|
|
28
28
|
const externalMap = {};
|
|
29
|
-
for (const externals of this
|
|
30
|
-
const replacedDeclaration = replaceExternalsInWgsl(ctx, externalMap, this
|
|
29
|
+
for (const externals of this.#externalsToApply) applyExternals(externalMap, externals);
|
|
30
|
+
const replacedDeclaration = replaceExternalsInWgsl(ctx, externalMap, this.#declaration);
|
|
31
31
|
ctx.addDeclaration(replacedDeclaration);
|
|
32
32
|
return snip("", Void, "constant");
|
|
33
33
|
}
|
|
34
34
|
toString() {
|
|
35
|
-
return `declare: ${this
|
|
35
|
+
return `declare: ${this.#declaration}`;
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
-
|
|
39
38
|
//#endregion
|
|
40
|
-
export { declare };
|
|
39
|
+
export { declare };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { Assume, RemoveIndexSignature } from "../../shared/utilityTypes.js";
|
|
1
2
|
import { BuiltinClipDistances, BuiltinFragDepth, BuiltinFrontFacing, BuiltinInstanceIndex, BuiltinPosition, BuiltinPrimitiveIndex, BuiltinSampleIndex, BuiltinSampleMask, BuiltinSubgroupInvocationId, BuiltinSubgroupSize, BuiltinVertexIndex, OmitBuiltins } from "../../builtin.js";
|
|
2
|
-
import "../../data/snippet.js";
|
|
3
3
|
import { BaseIOData } from "./fnTypes.js";
|
|
4
|
-
import "../../
|
|
5
|
-
import "../../
|
|
4
|
+
import { TgpuVertexAttrib } from "../../shared/vertexFormat.js";
|
|
5
|
+
import { FormatToWGSLType } from "../../data/vertexFormatData.js";
|
|
6
6
|
import { v4f } from "../../data/wgslTypes.js";
|
|
7
7
|
import { InferGPU, InferGPURecord, InferRecord } from "../../shared/repr.js";
|
|
8
8
|
|
|
@@ -12,7 +12,8 @@ declare const builtinVertexIn: {
|
|
|
12
12
|
readonly $vertexIndex: BuiltinVertexIndex;
|
|
13
13
|
readonly $instanceIndex: BuiltinInstanceIndex;
|
|
14
14
|
};
|
|
15
|
-
type AutoVertexIn<T extends AnyAutoCustoms> = T & InferRecord<typeof builtinVertexIn>;
|
|
15
|
+
type AutoVertexIn<T extends AnyAutoCustoms> = RemoveIndexSignature<T> & InferRecord<typeof builtinVertexIn>;
|
|
16
|
+
type _AutoVertexIn<T> = AutoVertexIn<{ [Key in keyof T]: T[Key] extends TgpuVertexAttrib ? InferGPU<FormatToWGSLType<T[Key]['format']>> : Assume<T[Key], InferGPU<BaseIOData>> }>;
|
|
16
17
|
declare const builtinVertexOut: {
|
|
17
18
|
readonly $clipDistances: BuiltinClipDistances;
|
|
18
19
|
readonly $position: BuiltinPosition;
|
|
@@ -27,11 +28,11 @@ declare const builtinFragmentIn: {
|
|
|
27
28
|
readonly $subgroupInvocationId: BuiltinSubgroupInvocationId;
|
|
28
29
|
readonly $subgroupSize: BuiltinSubgroupSize;
|
|
29
30
|
};
|
|
30
|
-
type AutoFragmentIn<T extends AnyAutoCustoms> = T & InferRecord<typeof builtinFragmentIn>;
|
|
31
|
+
type AutoFragmentIn<T extends AnyAutoCustoms> = RemoveIndexSignature<T> & InferRecord<typeof builtinFragmentIn>;
|
|
31
32
|
declare const builtinFragmentOut: {
|
|
32
33
|
readonly $fragDepth: BuiltinFragDepth;
|
|
33
34
|
readonly $sampleMask: BuiltinSampleMask;
|
|
34
35
|
};
|
|
35
36
|
type AutoFragmentOut<T extends undefined | v4f | AnyAutoCustoms> = T extends undefined | v4f ? T : T & Partial<InferGPURecord<typeof builtinFragmentOut>>;
|
|
36
37
|
//#endregion
|
|
37
|
-
export { AnyAutoCustoms, AutoFragmentIn, AutoFragmentOut, AutoVertexIn, AutoVertexOut };
|
|
38
|
+
export { AnyAutoCustoms, AutoFragmentIn, AutoFragmentOut, AutoVertexIn, AutoVertexOut, _AutoVertexIn };
|
package/core/function/autoIO.js
CHANGED
|
@@ -5,7 +5,6 @@ import { AutoStruct } from "../../data/autoStruct.js";
|
|
|
5
5
|
import { createFnCore } from "./fnCore.js";
|
|
6
6
|
import { shaderStageSlot } from "../slot/internalSlots.js";
|
|
7
7
|
import { builtin } from "../../builtin.js";
|
|
8
|
-
|
|
9
8
|
//#region src/core/function/autoIO.ts
|
|
10
9
|
const builtinVertexIn = {
|
|
11
10
|
$vertexIndex: builtin.vertexIndex,
|
|
@@ -82,6 +81,5 @@ var AutoVertexFn = class {
|
|
|
82
81
|
};
|
|
83
82
|
AutoVertexFn.prototype[$internal] = true;
|
|
84
83
|
AutoVertexFn.prototype.resourceType = "auto-vertex-fn";
|
|
85
|
-
|
|
86
84
|
//#endregion
|
|
87
|
-
export { AutoFragmentFn, AutoVertexFn };
|
|
85
|
+
export { AutoFragmentFn, AutoVertexFn };
|
|
@@ -3,7 +3,6 @@ import { setName } from "../../shared/meta.js";
|
|
|
3
3
|
import { WgslTypeError } from "../../errors.js";
|
|
4
4
|
import { isKnownAtComptime } from "../../types.js";
|
|
5
5
|
import { coerceToSnippet } from "../../tgsl/generationHelpers.js";
|
|
6
|
-
|
|
7
6
|
//#region src/core/function/comptime.ts
|
|
8
7
|
/**
|
|
9
8
|
* Creates a version of `func` that can called safely in a TypeGPU function to
|
|
@@ -46,6 +45,5 @@ function comptime(func) {
|
|
|
46
45
|
Object.defineProperty(impl, $internal, { value: { isComptime: true } });
|
|
47
46
|
return impl;
|
|
48
47
|
}
|
|
49
|
-
|
|
50
48
|
//#endregion
|
|
51
|
-
export { comptime };
|
|
49
|
+
export { comptime };
|
|
@@ -4,7 +4,6 @@ import { isPtr } from "../../data/wgslTypes.js";
|
|
|
4
4
|
import { snip } from "../../data/snippet.js";
|
|
5
5
|
import { NormalState, isKnownAtComptime } from "../../types.js";
|
|
6
6
|
import { tryConvertSnippet } from "../../tgsl/conversion.js";
|
|
7
|
-
|
|
8
7
|
//#region src/core/function/createCallableSchema.ts
|
|
9
8
|
function callableSchema(options) {
|
|
10
9
|
const impl = ((...args) => {
|
|
@@ -15,7 +14,7 @@ function callableSchema(options) {
|
|
|
15
14
|
impl[$gpuCallable] = {
|
|
16
15
|
get strictSignature() {},
|
|
17
16
|
call(ctx, args) {
|
|
18
|
-
const
|
|
17
|
+
const argTypes = options.argTypes(...args.map((s) => {
|
|
19
18
|
if (isPtr(s.dataType) && s.dataType.implicit) return s.dataType.inner;
|
|
20
19
|
return s.dataType;
|
|
21
20
|
}));
|
|
@@ -27,16 +26,15 @@ function callableSchema(options) {
|
|
|
27
26
|
if (converted.every((s) => isKnownAtComptime(s))) {
|
|
28
27
|
ctx.pushMode(new NormalState());
|
|
29
28
|
try {
|
|
30
|
-
return snip(options.normalImpl(...converted.map((s) => s.value)),
|
|
29
|
+
return snip(options.normalImpl(...converted.map((s) => s.value)), options.schema(), "constant");
|
|
31
30
|
} finally {
|
|
32
31
|
ctx.popMode("normal");
|
|
33
32
|
}
|
|
34
33
|
}
|
|
35
|
-
return
|
|
34
|
+
return options.codegenImpl(ctx, converted);
|
|
36
35
|
}
|
|
37
36
|
};
|
|
38
37
|
return impl;
|
|
39
38
|
}
|
|
40
|
-
|
|
41
39
|
//#endregion
|
|
42
|
-
export { callableSchema };
|
|
40
|
+
export { callableSchema };
|
|
@@ -5,7 +5,6 @@ import { snip } from "../../data/snippet.js";
|
|
|
5
5
|
import { NormalState, isKnownAtComptime } from "../../types.js";
|
|
6
6
|
import { tryConvertSnippet } from "../../tgsl/conversion.js";
|
|
7
7
|
import { concretize } from "../../tgsl/generationHelpers.js";
|
|
8
|
-
|
|
9
8
|
//#region src/core/function/dualImpl.ts
|
|
10
9
|
var MissingCpuImplError = class extends Error {
|
|
11
10
|
constructor(message) {
|
|
@@ -49,6 +48,5 @@ function dualImpl(options) {
|
|
|
49
48
|
};
|
|
50
49
|
return impl;
|
|
51
50
|
}
|
|
52
|
-
|
|
53
51
|
//#endregion
|
|
54
|
-
export { MissingCpuImplError, dualImpl };
|
|
52
|
+
export { MissingCpuImplError, dualImpl };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { $internal } from "../../shared/symbols.js";
|
|
2
|
+
import { isWgslStruct } from "../../data/wgslTypes.js";
|
|
3
|
+
import { undecorate } from "../../data/dataTypes.js";
|
|
4
|
+
import { snip } from "../../data/snippet.js";
|
|
5
|
+
//#region src/core/function/entryInputRouter.ts
|
|
6
|
+
/**
|
|
7
|
+
* Routes `(input) => { input.x }` style property access to the correct WGSL
|
|
8
|
+
* expression: positional args get a direct snippet, struct fields get
|
|
9
|
+
* `structArgName.fieldName`.
|
|
10
|
+
*/
|
|
11
|
+
var EntryInputRouter = class {
|
|
12
|
+
[$internal] = {};
|
|
13
|
+
type = "entry-input-router";
|
|
14
|
+
structArgName;
|
|
15
|
+
dataSchema;
|
|
16
|
+
/** Maps schemaKey → { WGSL arg name, type } */
|
|
17
|
+
positionalArgsMap;
|
|
18
|
+
constructor(structArgName, dataSchema, positionalArgs) {
|
|
19
|
+
this.structArgName = structArgName;
|
|
20
|
+
this.dataSchema = dataSchema;
|
|
21
|
+
this.positionalArgsMap = new Map(positionalArgs.map((a) => [a.schemaKey, {
|
|
22
|
+
argName: a.argName,
|
|
23
|
+
type: a.type
|
|
24
|
+
}]));
|
|
25
|
+
}
|
|
26
|
+
toString() {
|
|
27
|
+
return "entry-input-router";
|
|
28
|
+
}
|
|
29
|
+
accessProp(propName) {
|
|
30
|
+
const positionalEntry = this.positionalArgsMap.get(propName);
|
|
31
|
+
if (positionalEntry) return snip(positionalEntry.argName, positionalEntry.type, "argument");
|
|
32
|
+
if (this.dataSchema && isWgslStruct(this.dataSchema)) {
|
|
33
|
+
const propType = this.dataSchema.propTypes[propName];
|
|
34
|
+
if (propType) return snip(`${this.structArgName}.${propName}`, undecorate(propType), "argument");
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
//#endregion
|
|
39
|
+
export { EntryInputRouter };
|
|
@@ -111,6 +111,7 @@ function strip(rawCode) {
|
|
|
111
111
|
throw new Error("Invalid wgsl code!");
|
|
112
112
|
}
|
|
113
113
|
var ParsableString = class {
|
|
114
|
+
str;
|
|
114
115
|
#parseStartPos;
|
|
115
116
|
#pos;
|
|
116
117
|
constructor(str) {
|
|
@@ -199,6 +200,5 @@ const openingCommentBlock = new Set(["*/"]);
|
|
|
199
200
|
const parentheses = ["(", ")"];
|
|
200
201
|
const angleBrackets = ["<", ">"];
|
|
201
202
|
const commentBlocks = ["/*", "*/"];
|
|
202
|
-
|
|
203
203
|
//#endregion
|
|
204
|
-
export { extractArgs };
|
|
204
|
+
export { extractArgs };
|
package/core/function/fnCore.js
CHANGED
|
@@ -7,7 +7,6 @@ import { MissingLinksError } from "../../errors.js";
|
|
|
7
7
|
import { getAttributesString } from "../../data/attributes.js";
|
|
8
8
|
import { applyExternals, replaceExternalsInWgsl } from "../resolve/externals.js";
|
|
9
9
|
import { extractArgs } from "./extractArgs.js";
|
|
10
|
-
|
|
11
10
|
//#region src/core/function/fnCore.ts
|
|
12
11
|
function createFnCore(implementation, fnAttribute = "") {
|
|
13
12
|
/**
|
|
@@ -22,24 +21,33 @@ function createFnCore(implementation, fnAttribute = "") {
|
|
|
22
21
|
applyExternals(newExternals) {
|
|
23
22
|
externalsToApply.push(newExternals);
|
|
24
23
|
},
|
|
25
|
-
resolve(ctx, argTypes, returnType) {
|
|
24
|
+
resolve(ctx, argTypes, returnType, entryInput) {
|
|
26
25
|
const externalMap = {};
|
|
27
26
|
for (const externals of externalsToApply) applyExternals(externalMap, externals);
|
|
28
27
|
const id = ctx.getUniqueName(this);
|
|
29
28
|
if (typeof implementation === "string") {
|
|
30
29
|
if (!returnType) throw new Error("Explicit return type is required for string implementation");
|
|
30
|
+
const validArgNames = entryInput ? Object.fromEntries(entryInput.positionalArgs.map((a) => [a.schemaKey, ctx.makeNameValid(a.schemaKey)])) : void 0;
|
|
31
|
+
if (validArgNames && Object.keys(validArgNames).length > 0) applyExternals(externalMap, { in: validArgNames });
|
|
31
32
|
const replacedImpl = replaceExternalsInWgsl(ctx, externalMap, implementation);
|
|
32
33
|
let header = "";
|
|
33
34
|
let body = "";
|
|
34
|
-
if (fnAttribute !== "") {
|
|
35
|
-
const
|
|
35
|
+
if (fnAttribute !== "" && entryInput && validArgNames) {
|
|
36
|
+
const { dataSchema, positionalArgs } = entryInput;
|
|
37
|
+
const parts = [];
|
|
38
|
+
if (dataSchema && isArgUsedInBody("in", replacedImpl)) parts.push(`in: ${ctx.resolve(dataSchema).value}`);
|
|
39
|
+
for (const a of positionalArgs) {
|
|
40
|
+
const argName = validArgNames[a.schemaKey] ?? "";
|
|
41
|
+
if (argName !== "" && isArgUsedInBody(argName, replacedImpl)) parts.push(`${getAttributesString(a.type)}${argName}: ${ctx.resolve(a.type).value}`);
|
|
42
|
+
}
|
|
43
|
+
const input = `(${parts.join(", ")})`;
|
|
36
44
|
const attributes = isWgslData(returnType) ? getAttributesString(returnType) : "";
|
|
37
|
-
header = `${input}
|
|
45
|
+
header = `${input}${returnType !== Void ? isWgslStruct(returnType) ? ` -> ${ctx.resolve(returnType).value} ` : ` -> ${attributes !== "" ? attributes : "@location(0)"} ${ctx.resolve(returnType).value} ` : " "}`;
|
|
38
46
|
body = replacedImpl;
|
|
39
47
|
} else {
|
|
40
48
|
const providedArgs = extractArgs(replacedImpl);
|
|
41
49
|
if (providedArgs.args.length !== argTypes.length) throw new Error(`WGSL implementation has ${providedArgs.args.length} arguments, while the shell has ${argTypes.length} arguments.`);
|
|
42
|
-
header = `(${providedArgs.args.map((argInfo, i) => `${argInfo.identifier}: ${checkAndReturnType(ctx, `parameter ${argInfo.identifier}`, argInfo.type, argTypes[i])}`).join(", ")})
|
|
50
|
+
header = `(${providedArgs.args.map((argInfo, i) => `${argInfo.identifier}: ${checkAndReturnType(ctx, `parameter ${argInfo.identifier}`, argInfo.type, argTypes[i])}`).join(", ")})${returnType === Void ? " " : ` -> ${checkAndReturnType(ctx, "return type", providedArgs.ret?.type, returnType)} `}`;
|
|
43
51
|
body = replacedImpl.slice(providedArgs.range.end);
|
|
44
52
|
}
|
|
45
53
|
ctx.addDeclaration(`${fnAttribute}fn ${id}${header}${body}`);
|
|
@@ -57,6 +65,7 @@ function createFnCore(implementation, fnAttribute = "") {
|
|
|
57
65
|
const { head, body, returnType: actualReturnType } = ctx.fnToWgsl({
|
|
58
66
|
functionType: fnAttribute.includes("@compute") ? "compute" : fnAttribute.includes("@vertex") ? "vertex" : fnAttribute.includes("@fragment") ? "fragment" : "normal",
|
|
59
67
|
argTypes,
|
|
68
|
+
entryInput,
|
|
60
69
|
params: ast.params,
|
|
61
70
|
returnType,
|
|
62
71
|
body: ast.body,
|
|
@@ -67,6 +76,9 @@ function createFnCore(implementation, fnAttribute = "") {
|
|
|
67
76
|
}
|
|
68
77
|
};
|
|
69
78
|
}
|
|
79
|
+
function isArgUsedInBody(argName, body) {
|
|
80
|
+
return new RegExp(`\\b${argName}\\b`).test(body);
|
|
81
|
+
}
|
|
70
82
|
function checkAndReturnType(ctx, name, wgslType, jsType) {
|
|
71
83
|
const resolvedJsType = ctx.resolve(jsType).value.replace(/\s/g, "");
|
|
72
84
|
if (!wgslType) return resolvedJsType;
|
|
@@ -74,6 +86,5 @@ function checkAndReturnType(ctx, name, wgslType, jsType) {
|
|
|
74
86
|
if (resolvedWgslType !== resolvedJsType) throw new Error(`Type mismatch between TGPU shell and WGSL code string: ${name}, JS type "${resolvedJsType}", WGSL type "${resolvedWgslType}".`);
|
|
75
87
|
return wgslType;
|
|
76
88
|
}
|
|
77
|
-
|
|
78
89
|
//#endregion
|
|
79
|
-
export { createFnCore };
|
|
90
|
+
export { createFnCore };
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { BuiltinClipDistances } from "../../builtin.js";
|
|
2
2
|
import { AnyAttribute } from "../../data/attributes.js";
|
|
3
|
-
import { Bool, Decorated, F16, F32, I32, U32, Vec2f, Vec2h, Vec2i, Vec2u, Vec3f, Vec3h, Vec3i, Vec3u, Vec4f, Vec4h, Vec4i, Vec4u, Void } from "../../data/wgslTypes.js";
|
|
4
|
-
import {
|
|
5
|
-
import "tinyest";
|
|
6
|
-
|
|
3
|
+
import { BaseData, Bool, Decorated, F16, F32, I32, U32, Vec2f, Vec2h, Vec2i, Vec2u, Vec3f, Vec3h, Vec3i, Vec3u, Vec4f, Vec4h, Vec4i, Vec4u, Void } from "../../data/wgslTypes.js";
|
|
4
|
+
import { InferGPU } from "../../shared/repr.js";
|
|
7
5
|
//#region src/core/function/fnTypes.d.ts
|
|
8
6
|
type AnyFn = (...args: never[]) => unknown;
|
|
9
|
-
type InferArgs<T extends unknown[]> = { [Idx in keyof T]:
|
|
7
|
+
type InferArgs<T extends unknown[]> = { [Idx in keyof T]: InferGPU<T[Idx]> };
|
|
10
8
|
type InheritTupleValues<T, From> = { [K in keyof T]: K extends keyof From ? From[K] : never };
|
|
11
9
|
/**
|
|
12
10
|
* Returns a type that has arg and return types of `T`, but argument
|
|
@@ -18,7 +16,7 @@ type InheritTupleValues<T, From> = { [K in keyof T]: K extends keyof From ? From
|
|
|
18
16
|
type InheritArgNames<T extends AnyFn, From extends AnyFn> = {
|
|
19
17
|
result: (...args: Parameters<((...args: InheritTupleValues<Parameters<From>, Parameters<T>>) => ReturnType<T>) & T>) => ReturnType<T>;
|
|
20
18
|
};
|
|
21
|
-
type InferImplSchema<ImplSchema extends AnyFn> = (...args: InferArgs<Parameters<ImplSchema>>) =>
|
|
19
|
+
type InferImplSchema<ImplSchema extends AnyFn> = (...args: InferArgs<Parameters<ImplSchema>>) => InferGPU<ReturnType<ImplSchema>>;
|
|
22
20
|
type Implementation<ImplSchema extends AnyFn = AnyFn> = string | InferImplSchema<ImplSchema>;
|
|
23
21
|
type BaseIOData = Bool | F32 | F16 | I32 | U32 | Vec2f | Vec3f | Vec4f | Vec2h | Vec3h | Vec4h | Vec2i | Vec3i | Vec4i | Vec2u | Vec3u | Vec4u;
|
|
24
22
|
type IOData = BaseIOData | Decorated<BaseIOData, AnyAttribute[]> | BuiltinClipDistances;
|
|
@@ -29,6 +27,14 @@ type IORecord<TElementType extends IOData = IOData> = Record<string, TElementTyp
|
|
|
29
27
|
type IOLayout<TElementType extends IOData = IOData> = TElementType | IORecord<TElementType> | Void;
|
|
30
28
|
type InferIO<T> = T extends {
|
|
31
29
|
type: string;
|
|
32
|
-
} ?
|
|
30
|
+
} ? InferGPU<T> : T extends Record<string, unknown> ? { [K in keyof T]: InferGPU<T[K]> } : T;
|
|
31
|
+
interface PositionalArgInfo {
|
|
32
|
+
schemaKey: string;
|
|
33
|
+
type: BaseData;
|
|
34
|
+
}
|
|
35
|
+
interface SeparatedEntryArgs {
|
|
36
|
+
dataSchema: BaseData | undefined;
|
|
37
|
+
positionalArgs: PositionalArgInfo[];
|
|
38
|
+
}
|
|
33
39
|
//#endregion
|
|
34
|
-
export { AnyFn, BaseIOData, IOLayout, IORecord, Implementation, InferArgs, InferIO, InferImplSchema, InheritArgNames };
|
|
40
|
+
export { AnyFn, BaseIOData, IOLayout, IORecord, Implementation, InferArgs, InferIO, InferImplSchema, InheritArgNames, SeparatedEntryArgs };
|
|
@@ -2,7 +2,6 @@ import { isVoid } from "../../data/wgslTypes.js";
|
|
|
2
2
|
import { getCustomLocation, isData } from "../../data/dataTypes.js";
|
|
3
3
|
import { isBuiltin, location } from "../../data/attributes.js";
|
|
4
4
|
import { INTERNAL_createStruct } from "../../data/struct.js";
|
|
5
|
-
|
|
6
5
|
//#region src/core/function/ioSchema.ts
|
|
7
6
|
function withLocations(members, locations = {}) {
|
|
8
7
|
let nextLocation = 0;
|
|
@@ -22,9 +21,31 @@ function withLocations(members, locations = {}) {
|
|
|
22
21
|
return [key, location(nextLocation++, member)];
|
|
23
22
|
}));
|
|
24
23
|
}
|
|
24
|
+
function separateBuiltins(schema, locations = {}) {
|
|
25
|
+
const positionalArgs = [];
|
|
26
|
+
const dataFields = {};
|
|
27
|
+
for (const [key, type] of Object.entries(schema)) if (isBuiltin(type)) positionalArgs.push({
|
|
28
|
+
schemaKey: key,
|
|
29
|
+
type
|
|
30
|
+
});
|
|
31
|
+
else dataFields[key] = type;
|
|
32
|
+
return {
|
|
33
|
+
dataSchema: Object.keys(dataFields).length > 0 ? INTERNAL_createStruct(withLocations(dataFields, locations), false) : void 0,
|
|
34
|
+
positionalArgs
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function separateAllAsPositional(schema) {
|
|
38
|
+
const withLocs = withLocations(schema);
|
|
39
|
+
return {
|
|
40
|
+
dataSchema: void 0,
|
|
41
|
+
positionalArgs: Object.entries(withLocs).map(([key, type]) => ({
|
|
42
|
+
schemaKey: key,
|
|
43
|
+
type
|
|
44
|
+
}))
|
|
45
|
+
};
|
|
46
|
+
}
|
|
25
47
|
function createIoSchema(layout, locations = {}) {
|
|
26
48
|
return isData(layout) ? isVoid(layout) ? layout : isBuiltin(layout) ? layout : getCustomLocation(layout) !== void 0 ? layout : location(0, layout) : INTERNAL_createStruct(withLocations(layout, locations), false);
|
|
27
49
|
}
|
|
28
|
-
|
|
29
50
|
//#endregion
|
|
30
|
-
export { createIoSchema };
|
|
51
|
+
export { createIoSchema, separateAllAsPositional, separateBuiltins };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { $getNameForward, $internal, $resolve } from "../../shared/symbols.js";
|
|
2
2
|
import { getName } from "../../shared/meta.js";
|
|
3
3
|
import { createFnCore } from "./fnCore.js";
|
|
4
|
-
|
|
5
4
|
//#region src/core/function/shelllessImpl.ts
|
|
6
5
|
function createShelllessImpl(argTypes, implementation) {
|
|
7
6
|
const core = createFnCore(implementation, "");
|
|
@@ -18,6 +17,5 @@ function createShelllessImpl(argTypes, implementation) {
|
|
|
18
17
|
}
|
|
19
18
|
};
|
|
20
19
|
}
|
|
21
|
-
|
|
22
20
|
//#endregion
|
|
23
|
-
export { createShelllessImpl };
|
|
21
|
+
export { createShelllessImpl };
|
|
@@ -8,6 +8,5 @@ function isTemplateStringsArray(value) {
|
|
|
8
8
|
function templateLiteralIdentity(strings, ...values) {
|
|
9
9
|
return strings.slice(1).reduce((acc, elem, index) => `${acc}${values[index]}${elem}`, strings[0]);
|
|
10
10
|
}
|
|
11
|
-
|
|
12
11
|
//#endregion
|
|
13
|
-
export { stripTemplate };
|
|
12
|
+
export { stripTemplate };
|
|
@@ -2,7 +2,6 @@ import { TgpuNamable } from "../../shared/meta.js";
|
|
|
2
2
|
import { $internal } from "../../shared/symbols.js";
|
|
3
3
|
import { AnyComputeBuiltin } from "../../builtin.js";
|
|
4
4
|
import { IORecord, InferIO } from "./fnTypes.js";
|
|
5
|
-
import { IOLayoutToSchema } from "./ioSchema.js";
|
|
6
5
|
import { Void } from "../../data/wgslTypes.js";
|
|
7
6
|
|
|
8
7
|
//#region src/core/function/tgpuComputeFn.d.ts
|
|
@@ -10,9 +9,9 @@ import { Void } from "../../data/wgslTypes.js";
|
|
|
10
9
|
* Describes a compute entry function signature (its arguments, return type and workgroup size)
|
|
11
10
|
*/
|
|
12
11
|
type TgpuComputeFnShellHeader<ComputeIn extends IORecord<AnyComputeBuiltin>> = {
|
|
13
|
-
readonly argTypes: [
|
|
12
|
+
readonly argTypes: ComputeIn[keyof ComputeIn][];
|
|
14
13
|
readonly returnType: Void;
|
|
15
|
-
readonly workgroupSize: [
|
|
14
|
+
readonly workgroupSize: number[];
|
|
16
15
|
readonly entryPoint: 'compute';
|
|
17
16
|
};
|
|
18
17
|
/**
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { $getNameForward, $internal, $resolve } from "../../shared/symbols.js";
|
|
2
|
-
import { getName,
|
|
2
|
+
import { getName, setName } from "../../shared/meta.js";
|
|
3
3
|
import { Void } from "../../data/wgslTypes.js";
|
|
4
|
-
import {
|
|
4
|
+
import { separateBuiltins } from "./ioSchema.js";
|
|
5
5
|
import { createFnCore } from "./fnCore.js";
|
|
6
6
|
import { stripTemplate } from "./templateUtils.js";
|
|
7
7
|
import { shaderStageSlot } from "../slot/internalSlots.js";
|
|
8
|
-
|
|
9
8
|
//#region src/core/function/tgpuComputeFn.ts
|
|
10
9
|
/**
|
|
11
10
|
* Creates a shell of a typed entry function for the compute shader stage. Any function
|
|
@@ -18,24 +17,20 @@ import { shaderStageSlot } from "../slot/internalSlots.js";
|
|
|
18
17
|
*/
|
|
19
18
|
function computeFn(options) {
|
|
20
19
|
const shell = {
|
|
21
|
-
argTypes:
|
|
20
|
+
argTypes: Object.values(options.in ?? {}),
|
|
22
21
|
returnType: Void,
|
|
23
|
-
workgroupSize:
|
|
24
|
-
options.workgroupSize[0] ?? 1,
|
|
25
|
-
options.workgroupSize[1] ?? 1,
|
|
26
|
-
options.workgroupSize[2] ?? 1
|
|
27
|
-
],
|
|
22
|
+
workgroupSize: options.workgroupSize,
|
|
28
23
|
entryPoint: "compute"
|
|
29
24
|
};
|
|
30
|
-
const
|
|
25
|
+
const entryInput = separateBuiltins(options.in ?? {});
|
|
26
|
+
const call = (arg, ...values) => createComputeFn(shell, options.workgroupSize, stripTemplate(arg, ...values), entryInput);
|
|
31
27
|
return Object.assign(call, shell);
|
|
32
28
|
}
|
|
33
29
|
function isTgpuComputeFn(value) {
|
|
34
30
|
return value?.shell?.entryPoint === "compute";
|
|
35
31
|
}
|
|
36
|
-
function createComputeFn(shell, workgroupSize, implementation) {
|
|
32
|
+
function createComputeFn(shell, workgroupSize, implementation, entryInput) {
|
|
37
33
|
const core = createFnCore(implementation, `@compute @workgroup_size(${workgroupSize.join(", ")}) `);
|
|
38
|
-
const inputType = shell.argTypes[0];
|
|
39
34
|
return {
|
|
40
35
|
shell,
|
|
41
36
|
$uses(newExternals) {
|
|
@@ -46,17 +41,15 @@ function createComputeFn(shell, workgroupSize, implementation) {
|
|
|
46
41
|
[$getNameForward]: core,
|
|
47
42
|
$name(newLabel) {
|
|
48
43
|
setName(this, newLabel);
|
|
49
|
-
if (isNamable(inputType)) inputType.$name(`${newLabel}_Input`);
|
|
50
44
|
return this;
|
|
51
45
|
},
|
|
52
46
|
[$resolve](ctx) {
|
|
53
|
-
return ctx.withSlots([[shaderStageSlot, "compute"]], () => core.resolve(ctx,
|
|
47
|
+
return ctx.withSlots([[shaderStageSlot, "compute"]], () => core.resolve(ctx, [], shell.returnType, entryInput));
|
|
54
48
|
},
|
|
55
49
|
toString() {
|
|
56
50
|
return `computeFn:${getName(core) ?? "<unnamed>"}`;
|
|
57
51
|
}
|
|
58
52
|
};
|
|
59
53
|
}
|
|
60
|
-
|
|
61
54
|
//#endregion
|
|
62
|
-
export { computeFn, isTgpuComputeFn };
|
|
55
|
+
export { computeFn, isTgpuComputeFn };
|
|
@@ -6,7 +6,7 @@ import { Providing } from "../slot/slotTypes.js";
|
|
|
6
6
|
import { Withable } from "../root/rootTypes.js";
|
|
7
7
|
import { DualFn } from "../../types.js";
|
|
8
8
|
import { BaseData, Void } from "../../data/wgslTypes.js";
|
|
9
|
-
import {
|
|
9
|
+
import { InferGPU } from "../../shared/repr.js";
|
|
10
10
|
|
|
11
11
|
//#region src/core/function/tgpuFn.d.ts
|
|
12
12
|
/**
|
|
@@ -22,7 +22,7 @@ type TgpuFnShellHeader<Args extends BaseData[], Return extends BaseData> = {
|
|
|
22
22
|
* Allows creating tgpu functions by calling this shell
|
|
23
23
|
* and passing the implementation (as WGSL string or JS function) as the argument.
|
|
24
24
|
*/
|
|
25
|
-
type TgpuFnShell<Args extends BaseData[], Return extends BaseData> = TgpuFnShellHeader<Args, Return> & (<T extends (...args: InferArgs<Args>) =>
|
|
25
|
+
type TgpuFnShell<Args extends BaseData[], Return extends BaseData> = TgpuFnShellHeader<Args, Return> & (<T extends (...args: InferArgs<Args>) => InferGPU<Return>>(implementation: T) => TgpuFn<Prettify<InheritArgNames<(...args: Args) => Return, T>>['result']>) & ((implementation: string) => TgpuFn<(...args: Args) => Return>) & ((strings: TemplateStringsArray, ...values: unknown[]) => TgpuFn<(...args: Args) => Return>);
|
|
26
26
|
interface TgpuFnBase<ImplSchema extends AnyFn> extends TgpuNamable, Withable<TgpuFn<ImplSchema>> {
|
|
27
27
|
[$internal]: {
|
|
28
28
|
implementation: Implementation<ImplSchema>;
|
package/core/function/tgpuFn.js
CHANGED
|
@@ -11,7 +11,6 @@ import { comptime } from "./comptime.js";
|
|
|
11
11
|
import { addArgTypesToExternals, addReturnTypeToExternals } from "../resolve/externals.js";
|
|
12
12
|
import { createFnCore } from "./fnCore.js";
|
|
13
13
|
import { stripTemplate } from "./templateUtils.js";
|
|
14
|
-
|
|
15
14
|
//#region src/core/function/tgpuFn.ts
|
|
16
15
|
function fn(argTypesOrCallback, returnType) {
|
|
17
16
|
if (typeof argTypesOrCallback === "function") return createGenericFn(argTypesOrCallback, []);
|
|
@@ -165,6 +164,5 @@ function createGenericFn(inner, pairs) {
|
|
|
165
164
|
} });
|
|
166
165
|
return genericFn;
|
|
167
166
|
}
|
|
168
|
-
|
|
169
167
|
//#endregion
|
|
170
|
-
export { fn, isGenericFn, isTgpuFn };
|
|
168
|
+
export { fn, isGenericFn, isTgpuFn };
|
|
@@ -3,8 +3,9 @@ import { $internal } from "../../shared/symbols.js";
|
|
|
3
3
|
import { Prettify } from "../../shared/utilityTypes.js";
|
|
4
4
|
import { AnyFragmentInputBuiltin, AnyFragmentOutputBuiltin, OmitBuiltins } from "../../builtin.js";
|
|
5
5
|
import { BaseIOData, IOLayout, IORecord, InferIO } from "./fnTypes.js";
|
|
6
|
-
import {
|
|
6
|
+
import { AnyAutoCustoms, AutoFragmentIn, AutoFragmentOut } from "./autoIO.js";
|
|
7
7
|
import { InstanceToSchema } from "../../data/instanceToSchema.js";
|
|
8
|
+
import { IOLayoutToSchema } from "./ioSchema.js";
|
|
8
9
|
import { BaseData, Decorated, Interpolate, Location, Vec4f, Vec4i, Vec4u, WgslStruct } from "../../data/wgslTypes.js";
|
|
9
10
|
import { UndecorateRecord } from "../../data/dataTypes.js";
|
|
10
11
|
|
|
@@ -55,6 +56,9 @@ interface TgpuFragmentFn<in Varying extends TgpuFragmentFn.In = Record<string, n
|
|
|
55
56
|
declare namespace TgpuFragmentFn {
|
|
56
57
|
type In = Record<string, BaseData>;
|
|
57
58
|
type Out = Record<string, BaseData> | BaseData;
|
|
59
|
+
type AutoIn<T extends AnyAutoCustoms> = AutoFragmentIn<T>;
|
|
60
|
+
type AutoOut<T extends AnyAutoCustoms = AnyAutoCustoms> = AutoFragmentOut<T>;
|
|
61
|
+
type AutoInEmpty = AutoFragmentIn<Record<string, never>>;
|
|
58
62
|
}
|
|
59
63
|
declare function fragmentFn<FragmentOut extends FragmentOutConstrained>(options: {
|
|
60
64
|
out: FragmentOut;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { $getNameForward, $internal, $resolve } from "../../shared/symbols.js";
|
|
2
2
|
import { getName, isNamable, setName } from "../../shared/meta.js";
|
|
3
|
-
import { createIoSchema } from "./ioSchema.js";
|
|
3
|
+
import { createIoSchema, separateBuiltins } from "./ioSchema.js";
|
|
4
4
|
import { addReturnTypeToExternals } from "../resolve/externals.js";
|
|
5
5
|
import { createFnCore } from "./fnCore.js";
|
|
6
6
|
import { stripTemplate } from "./templateUtils.js";
|
|
7
7
|
import { shaderStageSlot } from "../slot/internalSlots.js";
|
|
8
|
-
|
|
9
8
|
//#region src/core/function/tgpuFragmentFn.ts
|
|
10
9
|
/**
|
|
11
10
|
* Creates a shell of a typed entry function for the fragment shader stage. Any function
|
|
@@ -50,19 +49,15 @@ function createFragmentFn(shell, implementation) {
|
|
|
50
49
|
return this;
|
|
51
50
|
},
|
|
52
51
|
[$resolve](ctx) {
|
|
53
|
-
const
|
|
54
|
-
if (
|
|
55
|
-
inputWithLocation.$name(`${getName(this) ?? ""}_Input`);
|
|
56
|
-
core.applyExternals({ In: inputWithLocation });
|
|
57
|
-
}
|
|
52
|
+
const entryInput = separateBuiltins(shell.in ?? {}, ctx.varyingLocations ?? {});
|
|
53
|
+
if (entryInput.dataSchema && isNamable(entryInput.dataSchema)) entryInput.dataSchema.$name(`${getName(this) ?? ""}_Input`);
|
|
58
54
|
core.applyExternals({ Out: outputType });
|
|
59
|
-
return ctx.withSlots([[shaderStageSlot, "fragment"]], () => core.resolve(ctx,
|
|
55
|
+
return ctx.withSlots([[shaderStageSlot, "fragment"]], () => core.resolve(ctx, [], shell.returnType, entryInput));
|
|
60
56
|
},
|
|
61
57
|
toString() {
|
|
62
58
|
return `fragmentFn:${getName(core) ?? "<unnamed>"}`;
|
|
63
59
|
}
|
|
64
60
|
};
|
|
65
61
|
}
|
|
66
|
-
|
|
67
62
|
//#endregion
|
|
68
|
-
export { fragmentFn, isTgpuFragmentFn };
|
|
63
|
+
export { fragmentFn, isTgpuFragmentFn };
|
|
@@ -3,6 +3,7 @@ import { $internal } from "../../shared/symbols.js";
|
|
|
3
3
|
import { Prettify } from "../../shared/utilityTypes.js";
|
|
4
4
|
import { AnyVertexInputBuiltin, AnyVertexOutputBuiltin, OmitBuiltins } from "../../builtin.js";
|
|
5
5
|
import { BaseIOData, IORecord, InferIO } from "./fnTypes.js";
|
|
6
|
+
import { AnyAutoCustoms, AutoVertexOut, _AutoVertexIn } from "./autoIO.js";
|
|
6
7
|
import { IOLayoutToSchema } from "./ioSchema.js";
|
|
7
8
|
import { BaseData, Decorated, Interpolate, Location } from "../../data/wgslTypes.js";
|
|
8
9
|
import { UndecorateRecord } from "../../data/dataTypes.js";
|
|
@@ -42,6 +43,9 @@ interface TgpuVertexFn<in VertexIn extends TgpuVertexFn.In = Record<string, neve
|
|
|
42
43
|
declare namespace TgpuVertexFn {
|
|
43
44
|
type In = BaseData | Record<string, BaseData>;
|
|
44
45
|
type Out = Record<string, BaseData>;
|
|
46
|
+
type AutoIn<T> = _AutoVertexIn<T>;
|
|
47
|
+
type AutoOut<T extends AnyAutoCustoms = AnyAutoCustoms> = AutoVertexOut<T>;
|
|
48
|
+
type AutoInEmpty = _AutoVertexIn<Record<string, never>>;
|
|
45
49
|
}
|
|
46
50
|
declare function vertexFn<VertexOut extends VertexOutConstrained>(options: {
|
|
47
51
|
out: VertexOut;
|