typegpu 0.10.1 → 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 +13 -0
- package/builtin.d.ts +50 -0
- package/builtin.js +35 -0
- package/common/fullScreenTriangle.d.ts +22 -0
- package/common/fullScreenTriangle.js +34 -0
- package/common/index.d.ts +4 -4
- package/common/index.js +8 -7
- package/common/writeSoA.d.ts +16 -0
- package/common/writeSoA.js +90 -0
- package/core/buffer/buffer.d.ts +79 -0
- package/core/buffer/buffer.js +246 -0
- package/core/buffer/bufferShorthand.d.ts +48 -0
- package/core/buffer/bufferShorthand.js +53 -0
- package/core/buffer/bufferUsage.d.ts +43 -0
- package/core/buffer/bufferUsage.js +165 -0
- package/core/constant/tgpuConstant.d.ts +29 -0
- package/core/constant/tgpuConstant.js +68 -0
- package/core/declare/tgpuDeclare.d.ts +18 -0
- package/core/declare/tgpuDeclare.js +39 -0
- package/core/function/autoIO.d.ts +38 -0
- package/core/function/autoIO.js +85 -0
- package/core/function/comptime.d.ts +39 -0
- package/core/function/comptime.js +49 -0
- package/core/function/createCallableSchema.js +40 -0
- package/core/function/dualImpl.js +52 -0
- package/core/function/entryInputRouter.js +39 -0
- package/core/function/extractArgs.js +204 -0
- package/core/function/fnCore.js +90 -0
- package/core/function/fnTypes.d.ts +40 -0
- package/core/function/ioSchema.d.ts +10 -0
- package/core/function/ioSchema.js +51 -0
- package/core/function/shelllessImpl.d.ts +28 -0
- package/core/function/shelllessImpl.js +21 -0
- package/core/function/templateUtils.js +12 -0
- package/core/function/tgpuComputeFn.d.ts +48 -0
- package/core/function/tgpuComputeFn.js +55 -0
- package/core/function/tgpuFn.d.ts +52 -0
- package/core/function/tgpuFn.js +168 -0
- package/core/function/tgpuFragmentFn.d.ts +72 -0
- package/core/function/tgpuFragmentFn.js +63 -0
- package/core/function/tgpuVertexFn.d.ts +59 -0
- package/core/function/tgpuVertexFn.js +59 -0
- package/core/pipeline/applyPipelineState.js +35 -0
- package/core/pipeline/computePipeline.d.ts +54 -0
- package/core/pipeline/computePipeline.js +227 -0
- package/core/pipeline/connectAttachmentToShader.js +24 -0
- package/core/pipeline/connectTargetsToShader.js +27 -0
- package/core/pipeline/limitsOverflow.js +12 -0
- package/core/pipeline/pipelineUtils.js +29 -0
- package/core/pipeline/renderPipeline.d.ts +284 -0
- package/core/pipeline/renderPipeline.js +489 -0
- package/core/pipeline/timeable.d.ts +20 -0
- package/core/pipeline/timeable.js +55 -0
- package/core/pipeline/typeGuards.js +27 -0
- package/core/querySet/querySet.d.ts +20 -0
- package/core/querySet/querySet.js +104 -0
- package/core/rawCodeSnippet/tgpuRawCodeSnippet.d.ts +59 -0
- package/core/rawCodeSnippet/tgpuRawCodeSnippet.js +94 -0
- package/core/resolve/externals.d.ts +8 -0
- package/core/resolve/externals.js +56 -0
- package/core/resolve/namespace.d.ts +38 -0
- package/core/resolve/namespace.js +39 -0
- package/core/resolve/resolveData.js +144 -0
- package/core/resolve/stitch.js +23 -0
- package/core/resolve/tgpuResolve.d.ts +153 -0
- package/core/resolve/tgpuResolve.js +66 -0
- package/core/root/configurableImpl.js +17 -0
- package/core/root/init.d.ts +64 -0
- package/core/root/init.js +464 -0
- package/core/root/rootTypes.d.ts +642 -0
- package/core/sampler/sampler.d.ts +31 -0
- package/core/sampler/sampler.js +116 -0
- package/core/simulate/tgpuSimulate.d.ts +36 -0
- package/core/simulate/tgpuSimulate.js +74 -0
- package/core/slot/accessor.d.ts +9 -0
- package/core/slot/accessor.js +95 -0
- package/core/slot/internalSlots.js +5 -0
- package/core/slot/lazy.d.ts +6 -0
- package/core/slot/lazy.js +40 -0
- package/core/slot/slot.d.ts +6 -0
- package/core/slot/slot.js +39 -0
- package/core/slot/slotTypes.d.ts +92 -0
- package/core/slot/slotTypes.js +19 -0
- package/core/texture/externalTexture.d.ts +6 -0
- package/core/texture/externalTexture.js +47 -0
- package/core/texture/texture.d.ts +114 -0
- package/core/texture/texture.js +314 -0
- package/core/texture/textureFormats.d.ts +29 -0
- package/core/texture/textureFormats.js +97 -0
- package/core/texture/textureProps.d.ts +11 -0
- package/core/texture/textureUtils.js +222 -0
- package/core/texture/usageExtension.d.ts +21 -0
- package/core/texture/usageExtension.js +19 -0
- package/core/unroll/tgpuUnroll.d.ts +68 -0
- package/core/unroll/tgpuUnroll.js +94 -0
- package/core/valueProxyUtils.js +42 -0
- package/core/variable/tgpuVariable.d.ts +38 -0
- package/core/variable/tgpuVariable.js +99 -0
- package/core/vertexLayout/connectAttributesToShader.js +57 -0
- package/core/vertexLayout/vertexAttribute.d.ts +29 -0
- package/core/vertexLayout/vertexLayout.d.ts +19 -0
- package/core/vertexLayout/vertexLayout.js +103 -0
- package/data/alignIO.js +14 -0
- package/data/alignmentOf.d.ts +9 -0
- package/data/alignmentOf.js +86 -0
- package/data/array.d.ts +26 -0
- package/data/array.js +46 -0
- package/data/atomic.d.ts +15 -0
- package/data/atomic.js +24 -0
- package/data/attributes.d.ts +121 -0
- package/data/attributes.js +145 -0
- package/data/autoStruct.d.ts +1 -0
- package/data/autoStruct.js +81 -0
- package/data/compiledIO.js +228 -0
- package/data/dataIO.js +556 -0
- package/data/dataTypes.d.ts +115 -0
- package/data/dataTypes.js +100 -0
- package/data/deepEqual.d.ts +25 -0
- package/data/deepEqual.js +56 -0
- package/data/disarray.d.ts +32 -0
- package/data/disarray.js +50 -0
- package/data/getLongestContiguousPrefix.d.ts +9 -0
- package/data/getLongestContiguousPrefix.js +13 -0
- package/data/index.d.ts +26 -4
- package/data/index.js +36 -9
- package/data/instanceToSchema.d.ts +33 -0
- package/data/isContiguous.d.ts +9 -0
- package/data/isContiguous.js +13 -0
- package/data/matrix.d.ts +124 -0
- package/data/matrix.js +531 -0
- package/data/numberOps.js +23 -0
- package/data/numeric.d.ts +81 -0
- package/data/numeric.js +221 -0
- package/data/offsetUtils.d.ts +33 -0
- package/data/offsetUtils.js +165 -0
- package/data/offsets.js +34 -0
- package/data/partialIO.js +113 -0
- package/data/ptr.d.ts +11 -0
- package/data/ptr.js +44 -0
- package/data/ref.d.ts +34 -0
- package/data/ref.js +94 -0
- package/data/sampler.d.ts +107 -0
- package/data/sampler.js +24 -0
- package/data/schemaCallWrapper.js +30 -0
- package/data/schemaMemoryLayout.js +198 -0
- package/data/sizeOf.d.ts +9 -0
- package/data/sizeOf.js +13 -0
- package/data/snippet.d.ts +26 -0
- package/data/snippet.js +70 -0
- package/data/struct.d.ts +17 -0
- package/data/struct.js +44 -0
- package/data/texture.d.ts +292 -0
- package/{texture-BagDrrks.js → data/texture.js} +6 -5
- package/data/unstruct.d.ts +24 -0
- package/data/unstruct.js +41 -0
- package/data/vector.d.ts +191 -0
- package/data/vector.js +239 -0
- package/data/vectorImpl.js +515 -0
- package/data/vectorOps.js +681 -0
- package/data/vertexFormatData.d.ts +190 -0
- package/data/vertexFormatData.js +109 -0
- package/data/wgslTypes.d.ts +924 -0
- package/data/wgslTypes.js +222 -0
- package/errors.d.ts +44 -0
- package/errors.js +131 -0
- package/execMode.js +49 -0
- package/extension.d.ts +11 -0
- package/extension.js +16 -0
- package/getGPUValue.js +7 -0
- package/index.d.ts +42 -243
- package/index.js +21 -6320
- package/indexNamedExports.d.ts +40 -0
- package/mathUtils.js +12 -0
- package/memo.js +22 -0
- package/nameRegistry.d.ts +30 -0
- package/nameRegistry.js +447 -0
- package/package.js +4 -0
- package/package.json +26 -26
- package/resolutionCtx.d.ts +19 -0
- package/resolutionCtx.js +612 -0
- package/shared/env.js +12 -0
- package/shared/generators.js +13 -0
- package/shared/meta.d.ts +39 -0
- package/shared/meta.js +61 -0
- package/shared/repr.d.ts +138 -0
- package/shared/stringify.js +20 -0
- package/shared/symbols.d.ts +70 -0
- package/shared/symbols.js +48 -0
- package/shared/utilityTypes.d.ts +33 -0
- package/shared/utilityTypes.js +6 -0
- package/shared/vertexFormat.d.ts +70 -0
- package/shared/vertexFormat.js +63 -0
- package/std/array.d.ts +7 -0
- package/std/array.js +25 -0
- package/std/atomic.d.ts +19 -0
- package/std/atomic.js +111 -0
- package/std/bitcast.d.ts +10 -0
- package/std/bitcast.js +41 -0
- package/std/boolean.d.ts +141 -0
- package/std/boolean.js +299 -0
- package/std/derivative.d.ts +16 -0
- package/std/derivative.js +87 -0
- package/std/discard.d.ts +6 -0
- package/std/discard.js +14 -0
- package/std/extensions.d.ts +6 -0
- package/std/extensions.js +12 -0
- package/std/index.d.ts +17 -4
- package/std/index.js +21 -7
- package/std/matrix.d.ts +41 -0
- package/std/matrix.js +85 -0
- package/std/numeric.d.ts +200 -0
- package/std/numeric.js +845 -0
- package/std/operators.d.ts +56 -0
- package/std/operators.js +227 -0
- package/std/packing.d.ts +26 -0
- package/std/packing.js +84 -0
- package/std/range.d.ts +24 -0
- package/std/range.js +38 -0
- package/std/subgroup.d.ts +47 -0
- package/std/subgroup.js +218 -0
- package/std/texture.d.ts +117 -0
- package/std/texture.js +207 -0
- package/tgpu.js +42 -0
- package/tgpuBindGroupLayout.d.ts +161 -0
- package/tgpuBindGroupLayout.js +272 -0
- package/tgpuUnstable.d.ts +48 -0
- package/tgpuUnstable.js +64 -0
- package/tgsl/accessIndex.js +43 -0
- package/tgsl/accessProp.js +115 -0
- package/tgsl/consoleLog/deserializers.js +115 -0
- package/tgsl/consoleLog/logGenerator.js +84 -0
- package/tgsl/consoleLog/serializers.js +223 -0
- package/tgsl/consoleLog/types.d.ts +52 -0
- package/tgsl/consoleLog/types.js +11 -0
- package/tgsl/conversion.js +198 -0
- package/tgsl/forOfUtils.js +71 -0
- package/tgsl/generationHelpers.d.ts +37 -0
- package/tgsl/generationHelpers.js +67 -0
- package/tgsl/math.js +43 -0
- package/tgsl/shaderGenerator.d.ts +20 -0
- package/tgsl/shaderGenerator_members.d.ts +2 -0
- package/tgsl/shaderGenerator_members.js +6 -0
- package/tgsl/shellless.d.ts +11 -0
- package/tgsl/shellless.js +46 -0
- package/tgsl/wgslGenerator.d.ts +36 -0
- package/tgsl/wgslGenerator.js +639 -0
- package/types.d.ts +265 -0
- package/types.js +43 -0
- package/unwrapper.d.ts +27 -0
- package/wgslExtensions.d.ts +5 -0
- package/wgslExtensions.js +17 -0
- package/builtin-DdtWpk2t.js +0 -818
- package/builtin-DdtWpk2t.js.map +0 -1
- package/chunk-BYypO7fO.js +0 -18
- package/common/index.d.ts.map +0 -1
- package/common/index.js.map +0 -1
- package/data/index.d.ts.map +0 -1
- package/data/index.js.map +0 -1
- package/deepEqual-DQxK4vdp.js +0 -413
- package/deepEqual-DQxK4vdp.js.map +0 -1
- package/extensions-DIVuAfBM.js +0 -2032
- package/extensions-DIVuAfBM.js.map +0 -1
- package/fullScreenTriangle-CfFyQd_0.js +0 -543
- package/fullScreenTriangle-CfFyQd_0.js.map +0 -1
- package/index.d.ts.map +0 -1
- package/index.js.map +0 -1
- package/indexNamedExports-oL6tyaJ9.d.ts +0 -5697
- package/indexNamedExports-oL6tyaJ9.d.ts.map +0 -1
- package/operators-d-PMVTo7.js +0 -4158
- package/operators-d-PMVTo7.js.map +0 -1
- package/std/index.d.ts.map +0 -1
- package/std/index.js.map +0 -1
- package/texture-BagDrrks.js.map +0 -1
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { TgpuNamable } from "../../shared/meta.js";
|
|
2
|
+
import { $internal } from "../../shared/symbols.js";
|
|
3
|
+
import { AnyComputeBuiltin } from "../../builtin.js";
|
|
4
|
+
import { IORecord, InferIO } from "./fnTypes.js";
|
|
5
|
+
import { Void } from "../../data/wgslTypes.js";
|
|
6
|
+
|
|
7
|
+
//#region src/core/function/tgpuComputeFn.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* Describes a compute entry function signature (its arguments, return type and workgroup size)
|
|
10
|
+
*/
|
|
11
|
+
type TgpuComputeFnShellHeader<ComputeIn extends IORecord<AnyComputeBuiltin>> = {
|
|
12
|
+
readonly argTypes: ComputeIn[keyof ComputeIn][];
|
|
13
|
+
readonly returnType: Void;
|
|
14
|
+
readonly workgroupSize: number[];
|
|
15
|
+
readonly entryPoint: 'compute';
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Describes a compute entry function signature (its arguments, return type and workgroup size).
|
|
19
|
+
* Allows creating tgpu compute functions by calling this shell
|
|
20
|
+
* and passing the implementation (as WGSL string or JS function) as the argument.
|
|
21
|
+
*/
|
|
22
|
+
type TgpuComputeFnShell<ComputeIn extends IORecord<AnyComputeBuiltin>> = TgpuComputeFnShellHeader<ComputeIn> &
|
|
23
|
+
/**
|
|
24
|
+
* Creates a type-safe implementation of this signature
|
|
25
|
+
*/
|
|
26
|
+
((implementation: (input: InferIO<ComputeIn>) => undefined) => TgpuComputeFn<ComputeIn>) &
|
|
27
|
+
/**
|
|
28
|
+
* @param implementation
|
|
29
|
+
* Raw WGSL function implementation with header and body
|
|
30
|
+
* without `fn` keyword and function name
|
|
31
|
+
* e.g. `"(x: f32) -> f32 { return x; }"`;
|
|
32
|
+
*/
|
|
33
|
+
((implementation: string) => TgpuComputeFn<ComputeIn>) & ((strings: TemplateStringsArray, ...values: unknown[]) => TgpuComputeFn<ComputeIn>);
|
|
34
|
+
interface TgpuComputeFn<ComputeIn extends IORecord<AnyComputeBuiltin> = any> extends TgpuNamable {
|
|
35
|
+
readonly [$internal]: true;
|
|
36
|
+
readonly shell: TgpuComputeFnShellHeader<ComputeIn>;
|
|
37
|
+
$uses(dependencyMap: Record<string, unknown>): this;
|
|
38
|
+
}
|
|
39
|
+
declare function computeFn(options: {
|
|
40
|
+
workgroupSize: number[];
|
|
41
|
+
}): TgpuComputeFnShell<{}>;
|
|
42
|
+
declare function computeFn<ComputeIn extends IORecord<AnyComputeBuiltin>>(options: {
|
|
43
|
+
in: ComputeIn;
|
|
44
|
+
workgroupSize: number[];
|
|
45
|
+
}): TgpuComputeFnShell<ComputeIn>;
|
|
46
|
+
declare function isTgpuComputeFn<ComputeIn extends IORecord<AnyComputeBuiltin>>(value: unknown): value is TgpuComputeFn<ComputeIn>;
|
|
47
|
+
//#endregion
|
|
48
|
+
export { TgpuComputeFn, TgpuComputeFnShell, computeFn, isTgpuComputeFn };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { $getNameForward, $internal, $resolve } from "../../shared/symbols.js";
|
|
2
|
+
import { getName, setName } from "../../shared/meta.js";
|
|
3
|
+
import { Void } from "../../data/wgslTypes.js";
|
|
4
|
+
import { separateBuiltins } from "./ioSchema.js";
|
|
5
|
+
import { createFnCore } from "./fnCore.js";
|
|
6
|
+
import { stripTemplate } from "./templateUtils.js";
|
|
7
|
+
import { shaderStageSlot } from "../slot/internalSlots.js";
|
|
8
|
+
//#region src/core/function/tgpuComputeFn.ts
|
|
9
|
+
/**
|
|
10
|
+
* Creates a shell of a typed entry function for the compute shader stage. Any function
|
|
11
|
+
* that implements this shell can perform general-purpose computation.
|
|
12
|
+
*
|
|
13
|
+
* @param options.in
|
|
14
|
+
* Record with builtins used by the compute shader.
|
|
15
|
+
* @param options.workgroupSize
|
|
16
|
+
* Size of blocks that the thread grid will be divided into (up to 3 dimensions).
|
|
17
|
+
*/
|
|
18
|
+
function computeFn(options) {
|
|
19
|
+
const shell = {
|
|
20
|
+
argTypes: Object.values(options.in ?? {}),
|
|
21
|
+
returnType: Void,
|
|
22
|
+
workgroupSize: options.workgroupSize,
|
|
23
|
+
entryPoint: "compute"
|
|
24
|
+
};
|
|
25
|
+
const entryInput = separateBuiltins(options.in ?? {});
|
|
26
|
+
const call = (arg, ...values) => createComputeFn(shell, options.workgroupSize, stripTemplate(arg, ...values), entryInput);
|
|
27
|
+
return Object.assign(call, shell);
|
|
28
|
+
}
|
|
29
|
+
function isTgpuComputeFn(value) {
|
|
30
|
+
return value?.shell?.entryPoint === "compute";
|
|
31
|
+
}
|
|
32
|
+
function createComputeFn(shell, workgroupSize, implementation, entryInput) {
|
|
33
|
+
const core = createFnCore(implementation, `@compute @workgroup_size(${workgroupSize.join(", ")}) `);
|
|
34
|
+
return {
|
|
35
|
+
shell,
|
|
36
|
+
$uses(newExternals) {
|
|
37
|
+
core.applyExternals(newExternals);
|
|
38
|
+
return this;
|
|
39
|
+
},
|
|
40
|
+
[$internal]: true,
|
|
41
|
+
[$getNameForward]: core,
|
|
42
|
+
$name(newLabel) {
|
|
43
|
+
setName(this, newLabel);
|
|
44
|
+
return this;
|
|
45
|
+
},
|
|
46
|
+
[$resolve](ctx) {
|
|
47
|
+
return ctx.withSlots([[shaderStageSlot, "compute"]], () => core.resolve(ctx, [], shell.returnType, entryInput));
|
|
48
|
+
},
|
|
49
|
+
toString() {
|
|
50
|
+
return `computeFn:${getName(core) ?? "<unnamed>"}`;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
export { computeFn, isTgpuComputeFn };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { TgpuNamable } from "../../shared/meta.js";
|
|
2
|
+
import { $internal, $providing } from "../../shared/symbols.js";
|
|
3
|
+
import { Prettify } from "../../shared/utilityTypes.js";
|
|
4
|
+
import { AnyFn, Implementation, InferArgs, InferImplSchema, InheritArgNames } from "./fnTypes.js";
|
|
5
|
+
import { Providing } from "../slot/slotTypes.js";
|
|
6
|
+
import { Withable } from "../root/rootTypes.js";
|
|
7
|
+
import { DualFn } from "../../types.js";
|
|
8
|
+
import { BaseData, Void } from "../../data/wgslTypes.js";
|
|
9
|
+
import { InferGPU } from "../../shared/repr.js";
|
|
10
|
+
|
|
11
|
+
//#region src/core/function/tgpuFn.d.ts
|
|
12
|
+
/**
|
|
13
|
+
* Describes a function signature (its arguments and return type)
|
|
14
|
+
*/
|
|
15
|
+
type TgpuFnShellHeader<Args extends BaseData[], Return extends BaseData> = {
|
|
16
|
+
readonly [$internal]: true;
|
|
17
|
+
readonly argTypes: Args;
|
|
18
|
+
readonly returnType: Return;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Describes a function signature (its arguments and return type).
|
|
22
|
+
* Allows creating tgpu functions by calling this shell
|
|
23
|
+
* and passing the implementation (as WGSL string or JS function) as the argument.
|
|
24
|
+
*/
|
|
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
|
+
interface TgpuFnBase<ImplSchema extends AnyFn> extends TgpuNamable, Withable<TgpuFn<ImplSchema>> {
|
|
27
|
+
[$internal]: {
|
|
28
|
+
implementation: Implementation<ImplSchema>;
|
|
29
|
+
};
|
|
30
|
+
readonly resourceType: 'function';
|
|
31
|
+
readonly shell: TgpuFnShellHeader<Parameters<ImplSchema>, Extract<ReturnType<ImplSchema>, BaseData>>;
|
|
32
|
+
readonly [$providing]?: Providing | undefined;
|
|
33
|
+
$uses(dependencyMap: Record<string, unknown>): this;
|
|
34
|
+
}
|
|
35
|
+
type TgpuFn<ImplSchema extends AnyFn = (...args: any[]) => any> = DualFn<InferImplSchema<ImplSchema>> & TgpuFnBase<ImplSchema>;
|
|
36
|
+
/**
|
|
37
|
+
* A function wrapper that allows providing slot and accessor overrides for shellless functions
|
|
38
|
+
*/
|
|
39
|
+
interface TgpuGenericFn<T extends AnyFn> extends TgpuNamable, Withable<TgpuGenericFn<T>> {
|
|
40
|
+
readonly [$internal]: {
|
|
41
|
+
inner: T;
|
|
42
|
+
};
|
|
43
|
+
readonly [$providing]?: Providing | undefined;
|
|
44
|
+
readonly resourceType: 'generic-function';
|
|
45
|
+
(...args: Parameters<T>): ReturnType<T>;
|
|
46
|
+
}
|
|
47
|
+
declare function fn<Args extends BaseData[] | []>(argTypes: Args, returnType?: undefined): TgpuFnShell<Args, Void>;
|
|
48
|
+
declare function fn<Args extends BaseData[] | [], Return extends BaseData>(argTypes: Args, returnType: Return): TgpuFnShell<Args, Return>;
|
|
49
|
+
declare function fn<T extends AnyFn>(inner: T): TgpuGenericFn<T>;
|
|
50
|
+
declare function isTgpuFn<Args extends BaseData[] | [], Return extends BaseData>(value: unknown): value is TgpuFn<(...args: Args) => Return>;
|
|
51
|
+
//#endregion
|
|
52
|
+
export { TgpuFn, TgpuFnShell, TgpuGenericFn, fn, isTgpuFn };
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { $getNameForward, $internal, $providing, $resolve, isMarkedInternal } from "../../shared/symbols.js";
|
|
2
|
+
import { getName, setName } from "../../shared/meta.js";
|
|
3
|
+
import { Void } from "../../data/wgslTypes.js";
|
|
4
|
+
import { ExecutionError } from "../../errors.js";
|
|
5
|
+
import { isAccessor, isMutableAccessor } from "../slot/slotTypes.js";
|
|
6
|
+
import { provideInsideTgpuFn } from "../../execMode.js";
|
|
7
|
+
import { stitch } from "../resolve/stitch.js";
|
|
8
|
+
import { schemaCallWrapper } from "../../data/schemaCallWrapper.js";
|
|
9
|
+
import { dualImpl } from "./dualImpl.js";
|
|
10
|
+
import { comptime } from "./comptime.js";
|
|
11
|
+
import { addArgTypesToExternals, addReturnTypeToExternals } from "../resolve/externals.js";
|
|
12
|
+
import { createFnCore } from "./fnCore.js";
|
|
13
|
+
import { stripTemplate } from "./templateUtils.js";
|
|
14
|
+
//#region src/core/function/tgpuFn.ts
|
|
15
|
+
function fn(argTypesOrCallback, returnType) {
|
|
16
|
+
if (typeof argTypesOrCallback === "function") return createGenericFn(argTypesOrCallback, []);
|
|
17
|
+
const argTypes = argTypesOrCallback;
|
|
18
|
+
const shell = {
|
|
19
|
+
[$internal]: true,
|
|
20
|
+
argTypes,
|
|
21
|
+
returnType: returnType ?? Void
|
|
22
|
+
};
|
|
23
|
+
const call = (arg, ...values) => createFn(shell, stripTemplate(arg, ...values));
|
|
24
|
+
return Object.assign(call, shell);
|
|
25
|
+
}
|
|
26
|
+
function isTgpuFn(value) {
|
|
27
|
+
return isMarkedInternal(value) && value?.resourceType === "function";
|
|
28
|
+
}
|
|
29
|
+
function isGenericFn(value) {
|
|
30
|
+
return isMarkedInternal(value) && value?.resourceType === "generic-function";
|
|
31
|
+
}
|
|
32
|
+
function stringifyPair([slot, value]) {
|
|
33
|
+
return `${getName(slot) ?? "<unnamed>"}=${value}`;
|
|
34
|
+
}
|
|
35
|
+
function createFn(shell, _implementation) {
|
|
36
|
+
let pairs = [];
|
|
37
|
+
let implementation;
|
|
38
|
+
if (isGenericFn(_implementation)) {
|
|
39
|
+
pairs = _implementation[$providing]?.pairs ?? [];
|
|
40
|
+
implementation = _implementation[$internal].inner;
|
|
41
|
+
} else implementation = _implementation;
|
|
42
|
+
const core = createFnCore(implementation, "");
|
|
43
|
+
const fnBase = {
|
|
44
|
+
shell,
|
|
45
|
+
resourceType: "function",
|
|
46
|
+
[$internal]: { implementation },
|
|
47
|
+
$uses(newExternals) {
|
|
48
|
+
core.applyExternals(newExternals);
|
|
49
|
+
return this;
|
|
50
|
+
},
|
|
51
|
+
[$getNameForward]: core,
|
|
52
|
+
$name(label) {
|
|
53
|
+
setName(this, label);
|
|
54
|
+
return this;
|
|
55
|
+
},
|
|
56
|
+
with: comptime((slot, value) => {
|
|
57
|
+
return createBoundFunction(fn, [[isAccessor(slot) || isMutableAccessor(slot) ? slot.slot : slot, value]]);
|
|
58
|
+
}),
|
|
59
|
+
[$resolve](ctx) {
|
|
60
|
+
if (typeof implementation === "string") {
|
|
61
|
+
addArgTypesToExternals(implementation, shell.argTypes, core.applyExternals);
|
|
62
|
+
addReturnTypeToExternals(implementation, shell.returnType, core.applyExternals);
|
|
63
|
+
}
|
|
64
|
+
return core.resolve(ctx, shell.argTypes, shell.returnType);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const call = dualImpl({
|
|
68
|
+
name: void 0,
|
|
69
|
+
noComptime: true,
|
|
70
|
+
signature: {
|
|
71
|
+
argTypes: shell.argTypes,
|
|
72
|
+
returnType: shell.returnType
|
|
73
|
+
},
|
|
74
|
+
normalImpl: (...args) => provideInsideTgpuFn(() => {
|
|
75
|
+
try {
|
|
76
|
+
if (typeof implementation === "string") throw new Error("Cannot execute on the CPU functions constructed with raw WGSL");
|
|
77
|
+
const castAndCopiedArgs = args.map((arg, index) => schemaCallWrapper(shell.argTypes[index], arg));
|
|
78
|
+
const result = implementation(...castAndCopiedArgs);
|
|
79
|
+
return schemaCallWrapper(shell.returnType, result);
|
|
80
|
+
} catch (err) {
|
|
81
|
+
if (err instanceof ExecutionError) throw err.appendToTrace(fn);
|
|
82
|
+
throw new ExecutionError(err, [fn]);
|
|
83
|
+
}
|
|
84
|
+
}),
|
|
85
|
+
codegenImpl: (ctx, args) => ctx.withResetIndentLevel(() => stitch`${ctx.resolve(fn).value}(${args})`)
|
|
86
|
+
});
|
|
87
|
+
const fn = Object.assign(call, fnBase);
|
|
88
|
+
Object.defineProperty(fn, "toString", { value() {
|
|
89
|
+
return `fn:${getName(core) ?? "<unnamed>"}`;
|
|
90
|
+
} });
|
|
91
|
+
if (pairs.length > 0) return createBoundFunction(fn, pairs);
|
|
92
|
+
return fn;
|
|
93
|
+
}
|
|
94
|
+
function createBoundFunction(innerFn, pairs) {
|
|
95
|
+
const fnBase = {
|
|
96
|
+
resourceType: "function",
|
|
97
|
+
shell: innerFn.shell,
|
|
98
|
+
[$internal]: { implementation: innerFn[$internal].implementation },
|
|
99
|
+
[$providing]: {
|
|
100
|
+
inner: innerFn,
|
|
101
|
+
pairs
|
|
102
|
+
},
|
|
103
|
+
$uses(newExternals) {
|
|
104
|
+
innerFn.$uses(newExternals);
|
|
105
|
+
return this;
|
|
106
|
+
},
|
|
107
|
+
$name(label) {
|
|
108
|
+
setName(this, label);
|
|
109
|
+
return this;
|
|
110
|
+
},
|
|
111
|
+
with: comptime((slot, value) => {
|
|
112
|
+
const s = isAccessor(slot) || isMutableAccessor(slot) ? slot.slot : slot;
|
|
113
|
+
return createBoundFunction(innerFn, [...pairs, [s, value]]);
|
|
114
|
+
})
|
|
115
|
+
};
|
|
116
|
+
const call = dualImpl({
|
|
117
|
+
name: void 0,
|
|
118
|
+
noComptime: true,
|
|
119
|
+
signature: {
|
|
120
|
+
argTypes: innerFn.shell.argTypes,
|
|
121
|
+
returnType: innerFn.shell.returnType
|
|
122
|
+
},
|
|
123
|
+
normalImpl: innerFn,
|
|
124
|
+
codegenImpl: (ctx, args) => ctx.withResetIndentLevel(() => stitch`${ctx.resolve(fn).value}(${args})`)
|
|
125
|
+
});
|
|
126
|
+
const fn = Object.assign(call, fnBase);
|
|
127
|
+
Object.defineProperty(fn, "toString", { value() {
|
|
128
|
+
return `fn:${getName(this) ?? "<unnamed>"}[${pairs.map(stringifyPair).join(", ")}]`;
|
|
129
|
+
} });
|
|
130
|
+
const innerName = getName(innerFn);
|
|
131
|
+
if (innerName) setName(fn, innerName);
|
|
132
|
+
return fn;
|
|
133
|
+
}
|
|
134
|
+
function createGenericFn(inner, pairs) {
|
|
135
|
+
const fnBase = {
|
|
136
|
+
[$internal]: { inner },
|
|
137
|
+
resourceType: "generic-function",
|
|
138
|
+
[$providing]: pairs.length > 0 ? {
|
|
139
|
+
inner,
|
|
140
|
+
pairs
|
|
141
|
+
} : void 0,
|
|
142
|
+
$name(label) {
|
|
143
|
+
setName(this, label);
|
|
144
|
+
if (!getName(inner)) setName(inner, label);
|
|
145
|
+
return this;
|
|
146
|
+
},
|
|
147
|
+
[$resolve](ctx) {
|
|
148
|
+
return ctx.resolve(inner);
|
|
149
|
+
},
|
|
150
|
+
with(slot, value) {
|
|
151
|
+
const s = isAccessor(slot) || isMutableAccessor(slot) ? slot.slot : slot;
|
|
152
|
+
return createGenericFn(inner, [...pairs, [s, value]]);
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
const call = (...args) => {
|
|
156
|
+
return inner(...args);
|
|
157
|
+
};
|
|
158
|
+
const genericFn = Object.assign(call, fnBase);
|
|
159
|
+
if (getName(inner)) setName(genericFn, getName(inner));
|
|
160
|
+
Object.defineProperty(genericFn, "toString", { value() {
|
|
161
|
+
const fnLabel = getName(genericFn) ?? "<unnamed>";
|
|
162
|
+
if (pairs.length > 0) return `fn*:${fnLabel}[${pairs.map(stringifyPair).join(", ")}]`;
|
|
163
|
+
return `fn*:${fnLabel}`;
|
|
164
|
+
} });
|
|
165
|
+
return genericFn;
|
|
166
|
+
}
|
|
167
|
+
//#endregion
|
|
168
|
+
export { fn, isGenericFn, isTgpuFn };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { TgpuNamable } from "../../shared/meta.js";
|
|
2
|
+
import { $internal } from "../../shared/symbols.js";
|
|
3
|
+
import { Prettify } from "../../shared/utilityTypes.js";
|
|
4
|
+
import { AnyFragmentInputBuiltin, AnyFragmentOutputBuiltin, OmitBuiltins } from "../../builtin.js";
|
|
5
|
+
import { BaseIOData, IOLayout, IORecord, InferIO } from "./fnTypes.js";
|
|
6
|
+
import { AnyAutoCustoms, AutoFragmentIn, AutoFragmentOut } from "./autoIO.js";
|
|
7
|
+
import { InstanceToSchema } from "../../data/instanceToSchema.js";
|
|
8
|
+
import { IOLayoutToSchema } from "./ioSchema.js";
|
|
9
|
+
import { BaseData, Decorated, Interpolate, Location, Vec4f, Vec4i, Vec4u, WgslStruct } from "../../data/wgslTypes.js";
|
|
10
|
+
import { UndecorateRecord } from "../../data/dataTypes.js";
|
|
11
|
+
|
|
12
|
+
//#region src/core/function/tgpuFragmentFn.d.ts
|
|
13
|
+
type FragmentInConstrained = IORecord<BaseIOData | Decorated<BaseIOData, (Location | Interpolate)[]> | AnyFragmentInputBuiltin>;
|
|
14
|
+
type VertexOutToVarying<T> = OmitBuiltins<{ [K in keyof T]: InstanceToSchema<T[K]> }>;
|
|
15
|
+
type FragmentColorValue = Vec4f | Vec4i | Vec4u;
|
|
16
|
+
type FragmentOutConstrained = IOLayout<FragmentColorValue | Decorated<FragmentColorValue, (Location | Interpolate)[]> | AnyFragmentOutputBuiltin>;
|
|
17
|
+
/**
|
|
18
|
+
* Describes a fragment entry function signature (its arguments, return type and targets)
|
|
19
|
+
*/
|
|
20
|
+
type TgpuFragmentFnShellHeader<FragmentIn extends TgpuFragmentFn.In = TgpuFragmentFn.In, FragmentOut extends TgpuFragmentFn.Out = TgpuFragmentFn.Out> = {
|
|
21
|
+
readonly in: FragmentIn | undefined;
|
|
22
|
+
readonly out: FragmentOut;
|
|
23
|
+
readonly returnType: IOLayoutToSchema<FragmentOut>;
|
|
24
|
+
readonly entryPoint: 'fragment';
|
|
25
|
+
};
|
|
26
|
+
type CleanIO<T> = T extends Record<string, BaseData> ? Prettify<UndecorateRecord<OmitBuiltins<T>>> : Prettify<UndecorateRecord<OmitBuiltins<{
|
|
27
|
+
a: T;
|
|
28
|
+
}>>> extends {
|
|
29
|
+
a: infer Result;
|
|
30
|
+
} ? Result : Record<string, never>;
|
|
31
|
+
/**
|
|
32
|
+
* Describes a fragment entry function signature (its arguments, return type and targets).
|
|
33
|
+
* Allows creating tgpu fragment functions by calling this shell
|
|
34
|
+
* and passing the implementation (as WGSL string or JS function) as the argument.
|
|
35
|
+
*/
|
|
36
|
+
interface TgpuFragmentFnShell<out TIn extends TgpuFragmentFn.In = TgpuFragmentFn.In, out TOut extends TgpuFragmentFn.Out = TgpuFragmentFn.Out> extends TgpuFragmentFnShellHeader<TIn, TOut> {
|
|
37
|
+
/**
|
|
38
|
+
* Creates a type-safe implementation of this signature
|
|
39
|
+
*/
|
|
40
|
+
(implementation: (input: InferIO<TIn>, out: TOut extends IORecord ? WgslStruct<TOut> : TOut) => InferIO<TOut>): TgpuFragmentFn<CleanIO<TIn>, CleanIO<TOut>>;
|
|
41
|
+
/**
|
|
42
|
+
* @param implementation
|
|
43
|
+
* Raw WGSL function implementation with header and body
|
|
44
|
+
* without `fn` keyword and function name
|
|
45
|
+
* e.g. `"(x: f32) -> f32 { return x; }"`;
|
|
46
|
+
*/
|
|
47
|
+
(implementation: string): TgpuFragmentFn<CleanIO<TIn>, CleanIO<TOut>>;
|
|
48
|
+
(strings: TemplateStringsArray, ...values: unknown[]): TgpuFragmentFn<CleanIO<TIn>, CleanIO<TOut>>;
|
|
49
|
+
}
|
|
50
|
+
interface TgpuFragmentFn<in Varying extends TgpuFragmentFn.In = Record<string, never>, out Output extends TgpuFragmentFn.Out = TgpuFragmentFn.Out> extends TgpuNamable {
|
|
51
|
+
readonly [$internal]: true;
|
|
52
|
+
readonly shell: TgpuFragmentFnShellHeader<Varying, Output>;
|
|
53
|
+
readonly outputType: IOLayoutToSchema<Output>;
|
|
54
|
+
$uses(dependencyMap: Record<string, unknown>): this;
|
|
55
|
+
}
|
|
56
|
+
declare namespace TgpuFragmentFn {
|
|
57
|
+
type In = Record<string, BaseData>;
|
|
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>>;
|
|
62
|
+
}
|
|
63
|
+
declare function fragmentFn<FragmentOut extends FragmentOutConstrained>(options: {
|
|
64
|
+
out: FragmentOut;
|
|
65
|
+
}): TgpuFragmentFnShell<{}, FragmentOut>;
|
|
66
|
+
declare function fragmentFn<FragmentIn extends FragmentInConstrained, FragmentOut extends FragmentOutConstrained>(options: {
|
|
67
|
+
in: FragmentIn;
|
|
68
|
+
out: FragmentOut;
|
|
69
|
+
}): TgpuFragmentFnShell<FragmentIn, FragmentOut>;
|
|
70
|
+
declare function isTgpuFragmentFn<FragmentIn extends FragmentInConstrained, FragmentOut extends FragmentOutConstrained>(value: unknown): value is TgpuFragmentFn<FragmentIn, FragmentOut>;
|
|
71
|
+
//#endregion
|
|
72
|
+
export { FragmentInConstrained, FragmentOutConstrained, TgpuFragmentFn, TgpuFragmentFnShell, VertexOutToVarying, fragmentFn, isTgpuFragmentFn };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { $getNameForward, $internal, $resolve } from "../../shared/symbols.js";
|
|
2
|
+
import { getName, isNamable, setName } from "../../shared/meta.js";
|
|
3
|
+
import { createIoSchema, separateBuiltins } from "./ioSchema.js";
|
|
4
|
+
import { addReturnTypeToExternals } from "../resolve/externals.js";
|
|
5
|
+
import { createFnCore } from "./fnCore.js";
|
|
6
|
+
import { stripTemplate } from "./templateUtils.js";
|
|
7
|
+
import { shaderStageSlot } from "../slot/internalSlots.js";
|
|
8
|
+
//#region src/core/function/tgpuFragmentFn.ts
|
|
9
|
+
/**
|
|
10
|
+
* Creates a shell of a typed entry function for the fragment shader stage. Any function
|
|
11
|
+
* that implements this shell can run for each fragment (pixel), allowing the inner code
|
|
12
|
+
* to process information received from the vertex shader stage and builtins to determine
|
|
13
|
+
* the final color of the pixel (many pixels in case of multiple targets).
|
|
14
|
+
*
|
|
15
|
+
* @param options.in
|
|
16
|
+
* Values computed in the vertex stage and builtins to be made available to functions that implement this shell.
|
|
17
|
+
* @param options.out
|
|
18
|
+
* A `vec4f`, signaling this function outputs a color for one target, or a record containing colors for multiple targets.
|
|
19
|
+
*/
|
|
20
|
+
function fragmentFn(options) {
|
|
21
|
+
const shell = {
|
|
22
|
+
in: options.in,
|
|
23
|
+
out: options.out,
|
|
24
|
+
returnType: createIoSchema(options.out),
|
|
25
|
+
entryPoint: "fragment"
|
|
26
|
+
};
|
|
27
|
+
const call = (arg, ...values) => createFragmentFn(shell, stripTemplate(arg, ...values));
|
|
28
|
+
return Object.assign(call, shell);
|
|
29
|
+
}
|
|
30
|
+
function isTgpuFragmentFn(value) {
|
|
31
|
+
return value?.shell?.entryPoint === "fragment";
|
|
32
|
+
}
|
|
33
|
+
function createFragmentFn(shell, implementation) {
|
|
34
|
+
const core = createFnCore(implementation, "@fragment ");
|
|
35
|
+
const outputType = shell.returnType;
|
|
36
|
+
if (typeof implementation === "string") addReturnTypeToExternals(implementation, outputType, (externals) => core.applyExternals(externals));
|
|
37
|
+
return {
|
|
38
|
+
shell,
|
|
39
|
+
outputType,
|
|
40
|
+
$uses(newExternals) {
|
|
41
|
+
core.applyExternals(newExternals);
|
|
42
|
+
return this;
|
|
43
|
+
},
|
|
44
|
+
[$internal]: true,
|
|
45
|
+
[$getNameForward]: core,
|
|
46
|
+
$name(newLabel) {
|
|
47
|
+
setName(this, newLabel);
|
|
48
|
+
if (isNamable(outputType)) outputType.$name(`${newLabel}_Output`);
|
|
49
|
+
return this;
|
|
50
|
+
},
|
|
51
|
+
[$resolve](ctx) {
|
|
52
|
+
const entryInput = separateBuiltins(shell.in ?? {}, ctx.varyingLocations ?? {});
|
|
53
|
+
if (entryInput.dataSchema && isNamable(entryInput.dataSchema)) entryInput.dataSchema.$name(`${getName(this) ?? ""}_Input`);
|
|
54
|
+
core.applyExternals({ Out: outputType });
|
|
55
|
+
return ctx.withSlots([[shaderStageSlot, "fragment"]], () => core.resolve(ctx, [], shell.returnType, entryInput));
|
|
56
|
+
},
|
|
57
|
+
toString() {
|
|
58
|
+
return `fragmentFn:${getName(core) ?? "<unnamed>"}`;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
//#endregion
|
|
63
|
+
export { fragmentFn, isTgpuFragmentFn };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { TgpuNamable } from "../../shared/meta.js";
|
|
2
|
+
import { $internal } from "../../shared/symbols.js";
|
|
3
|
+
import { Prettify } from "../../shared/utilityTypes.js";
|
|
4
|
+
import { AnyVertexInputBuiltin, AnyVertexOutputBuiltin, OmitBuiltins } from "../../builtin.js";
|
|
5
|
+
import { BaseIOData, IORecord, InferIO } from "./fnTypes.js";
|
|
6
|
+
import { AnyAutoCustoms, AutoVertexOut, _AutoVertexIn } from "./autoIO.js";
|
|
7
|
+
import { IOLayoutToSchema } from "./ioSchema.js";
|
|
8
|
+
import { BaseData, Decorated, Interpolate, Location } from "../../data/wgslTypes.js";
|
|
9
|
+
import { UndecorateRecord } from "../../data/dataTypes.js";
|
|
10
|
+
|
|
11
|
+
//#region src/core/function/tgpuVertexFn.d.ts
|
|
12
|
+
type VertexInConstrained = IORecord<BaseIOData | Decorated<BaseIOData, Location[]> | AnyVertexInputBuiltin>;
|
|
13
|
+
type VertexOutConstrained = IORecord<BaseIOData | Decorated<BaseIOData, (Location | Interpolate)[]> | AnyVertexOutputBuiltin>;
|
|
14
|
+
/**
|
|
15
|
+
* Describes a vertex entry function signature (its arguments, return type and attributes)
|
|
16
|
+
*/
|
|
17
|
+
type TgpuVertexFnShellHeader<VertexIn extends TgpuVertexFn.In, VertexOut extends TgpuVertexFn.Out> = {
|
|
18
|
+
readonly in: VertexIn | undefined;
|
|
19
|
+
readonly out: VertexOut;
|
|
20
|
+
readonly argTypes: [IOLayoutToSchema<VertexIn>] | [];
|
|
21
|
+
readonly entryPoint: 'vertex';
|
|
22
|
+
};
|
|
23
|
+
type CleanIO<T> = T extends Record<string, BaseData> ? Prettify<UndecorateRecord<OmitBuiltins<T>>> : Prettify<UndecorateRecord<OmitBuiltins<{
|
|
24
|
+
a: T;
|
|
25
|
+
}>>> extends {
|
|
26
|
+
a: infer Result;
|
|
27
|
+
} ? Result : never;
|
|
28
|
+
/**
|
|
29
|
+
* Describes a vertex entry function signature (its arguments, return type and attributes).
|
|
30
|
+
* Allows creating tgpu vertex functions by calling this shell
|
|
31
|
+
* and passing the implementation (as WGSL string or JS function) as the argument.
|
|
32
|
+
*/
|
|
33
|
+
interface TgpuVertexFnShell<out TIn extends TgpuVertexFn.In, out TOut extends TgpuVertexFn.Out> extends TgpuVertexFnShellHeader<TIn, TOut> {
|
|
34
|
+
(implementation: (input: InferIO<TIn>, out: IOLayoutToSchema<TOut>) => InferIO<TOut>): TgpuVertexFn<CleanIO<TIn>, CleanIO<TOut>>;
|
|
35
|
+
(implementation: string): TgpuVertexFn<CleanIO<TIn>, CleanIO<TOut>>;
|
|
36
|
+
(strings: TemplateStringsArray, ...values: unknown[]): TgpuVertexFn<CleanIO<TIn>, CleanIO<TOut>>;
|
|
37
|
+
}
|
|
38
|
+
interface TgpuVertexFn<in VertexIn extends TgpuVertexFn.In = Record<string, never>, out VertexOut extends TgpuVertexFn.Out = TgpuVertexFn.Out> extends TgpuNamable {
|
|
39
|
+
readonly [$internal]: true;
|
|
40
|
+
readonly shell: TgpuVertexFnShellHeader<VertexIn, VertexOut>;
|
|
41
|
+
$uses(dependencyMap: Record<string, unknown>): this;
|
|
42
|
+
}
|
|
43
|
+
declare namespace TgpuVertexFn {
|
|
44
|
+
type In = BaseData | Record<string, BaseData>;
|
|
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>>;
|
|
49
|
+
}
|
|
50
|
+
declare function vertexFn<VertexOut extends VertexOutConstrained>(options: {
|
|
51
|
+
out: VertexOut;
|
|
52
|
+
}): TgpuVertexFnShell<{}, VertexOut>;
|
|
53
|
+
declare function vertexFn<VertexIn extends VertexInConstrained, VertexOut extends VertexOutConstrained>(options: {
|
|
54
|
+
in: VertexIn;
|
|
55
|
+
out: VertexOut;
|
|
56
|
+
}): TgpuVertexFnShell<VertexIn, VertexOut>;
|
|
57
|
+
declare function isTgpuVertexFn<VertexIn extends VertexInConstrained, VertexOut extends VertexOutConstrained>(value: unknown): value is TgpuVertexFn<VertexIn, VertexOut>;
|
|
58
|
+
//#endregion
|
|
59
|
+
export { TgpuVertexFn, TgpuVertexFnShell, isTgpuVertexFn, vertexFn };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { $getNameForward, $internal, $resolve } from "../../shared/symbols.js";
|
|
2
|
+
import { getName, setName } from "../../shared/meta.js";
|
|
3
|
+
import { createIoSchema, separateAllAsPositional } from "./ioSchema.js";
|
|
4
|
+
import { createFnCore } from "./fnCore.js";
|
|
5
|
+
import { stripTemplate } from "./templateUtils.js";
|
|
6
|
+
import { shaderStageSlot } from "../slot/internalSlots.js";
|
|
7
|
+
//#region src/core/function/tgpuVertexFn.ts
|
|
8
|
+
/**
|
|
9
|
+
* Creates a shell of a typed entry function for the vertex shader stage. Any function
|
|
10
|
+
* that implements this shell can run for each vertex, allowing the inner code to process
|
|
11
|
+
* attributes and determine the final position of the vertex.
|
|
12
|
+
*
|
|
13
|
+
* @param options.in
|
|
14
|
+
* Vertex attributes and builtins to be made available to functions that implement this shell.
|
|
15
|
+
* @param options.out
|
|
16
|
+
* A record containing the final position of the vertex, and any information
|
|
17
|
+
* passed onto the fragment shader stage.
|
|
18
|
+
*/
|
|
19
|
+
function vertexFn(options) {
|
|
20
|
+
if (Object.keys(options.out).length === 0) throw new Error(`A vertexFn output cannot be empty since it must include the 'position' builtin.`);
|
|
21
|
+
const shell = {
|
|
22
|
+
in: options.in,
|
|
23
|
+
out: options.out,
|
|
24
|
+
argTypes: options.in && Object.keys(options.in).length !== 0 ? [createIoSchema(options.in)] : [],
|
|
25
|
+
entryPoint: "vertex"
|
|
26
|
+
};
|
|
27
|
+
const call = (arg, ...values) => createVertexFn(shell, stripTemplate(arg, ...values));
|
|
28
|
+
return Object.assign(call, shell);
|
|
29
|
+
}
|
|
30
|
+
function isTgpuVertexFn(value) {
|
|
31
|
+
return value?.shell?.entryPoint === "vertex";
|
|
32
|
+
}
|
|
33
|
+
function createVertexFn(shell, implementation) {
|
|
34
|
+
const core = createFnCore(implementation, "@vertex ");
|
|
35
|
+
const entryInput = separateAllAsPositional(shell.in ?? {});
|
|
36
|
+
return {
|
|
37
|
+
shell,
|
|
38
|
+
$uses(newExternals) {
|
|
39
|
+
core.applyExternals(newExternals);
|
|
40
|
+
return this;
|
|
41
|
+
},
|
|
42
|
+
[$internal]: true,
|
|
43
|
+
[$getNameForward]: core,
|
|
44
|
+
$name(newLabel) {
|
|
45
|
+
setName(this, newLabel);
|
|
46
|
+
return this;
|
|
47
|
+
},
|
|
48
|
+
[$resolve](ctx) {
|
|
49
|
+
const outputWithLocation = createIoSchema(shell.out, ctx.varyingLocations).$name(`${getName(this) ?? ""}_Output`);
|
|
50
|
+
if (typeof implementation === "string") core.applyExternals({ Out: outputWithLocation });
|
|
51
|
+
return ctx.withSlots([[shaderStageSlot, "vertex"]], () => core.resolve(ctx, [], outputWithLocation, entryInput));
|
|
52
|
+
},
|
|
53
|
+
toString() {
|
|
54
|
+
return `vertexFn:${getName(core) ?? "<unnamed>"}`;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
export { isTgpuVertexFn, vertexFn };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { MissingBindGroupsError, MissingVertexBuffersError } from "../../errors.js";
|
|
2
|
+
import { isBuffer } from "../buffer/buffer.js";
|
|
3
|
+
import { isBindGroup } from "../../tgpuBindGroupLayout.js";
|
|
4
|
+
import { warnIfOverflow } from "./limitsOverflow.js";
|
|
5
|
+
//#region src/core/pipeline/applyPipelineState.ts
|
|
6
|
+
function applyBindGroups(encoder, root, usedBindGroupLayouts, catchall, resolveBindGroup) {
|
|
7
|
+
const missingBindGroups = new Set(usedBindGroupLayouts);
|
|
8
|
+
warnIfOverflow(usedBindGroupLayouts, root.device.limits);
|
|
9
|
+
usedBindGroupLayouts.forEach((layout, idx) => {
|
|
10
|
+
if (catchall && idx === catchall[0]) {
|
|
11
|
+
encoder.setBindGroup(idx, root.unwrap(catchall[1]));
|
|
12
|
+
missingBindGroups.delete(layout);
|
|
13
|
+
} else {
|
|
14
|
+
const bindGroup = resolveBindGroup(layout);
|
|
15
|
+
if (bindGroup !== void 0) {
|
|
16
|
+
missingBindGroups.delete(layout);
|
|
17
|
+
if (isBindGroup(bindGroup)) encoder.setBindGroup(idx, root.unwrap(bindGroup));
|
|
18
|
+
else encoder.setBindGroup(idx, bindGroup);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
if (missingBindGroups.size > 0) throw new MissingBindGroupsError(missingBindGroups);
|
|
23
|
+
}
|
|
24
|
+
function applyVertexBuffers(encoder, root, usedVertexLayouts, resolveVertexBuffer) {
|
|
25
|
+
const missingVertexLayouts = /* @__PURE__ */ new Set();
|
|
26
|
+
usedVertexLayouts.forEach((vertexLayout, idx) => {
|
|
27
|
+
const entry = resolveVertexBuffer(vertexLayout);
|
|
28
|
+
if (!entry || !entry.buffer) missingVertexLayouts.add(vertexLayout);
|
|
29
|
+
else if (isBuffer(entry.buffer)) encoder.setVertexBuffer(idx, root.unwrap(entry.buffer), entry.offset, entry.size);
|
|
30
|
+
else encoder.setVertexBuffer(idx, entry.buffer, entry.offset, entry.size);
|
|
31
|
+
});
|
|
32
|
+
if (missingVertexLayouts.size > 0) throw new MissingVertexBuffersError(missingVertexLayouts);
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
export { applyBindGroups, applyVertexBuffers };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { TgpuNamable } from "../../shared/meta.js";
|
|
2
|
+
import { $internal } from "../../shared/symbols.js";
|
|
3
|
+
import { AnyComputeBuiltin } from "../../builtin.js";
|
|
4
|
+
import { IORecord } from "../function/fnTypes.js";
|
|
5
|
+
import { TgpuComputeFn } from "../function/tgpuComputeFn.js";
|
|
6
|
+
import { PrimitiveOffsetInfo } from "../../data/offsetUtils.js";
|
|
7
|
+
import { Timeable, TimestampWritesPriors } from "./timeable.js";
|
|
8
|
+
import { TgpuBindGroup, TgpuBindGroupLayout, TgpuLayoutEntry } from "../../tgpuBindGroupLayout.js";
|
|
9
|
+
import { ExperimentalTgpuRoot } from "../root/rootTypes.js";
|
|
10
|
+
import { IndirectFlag, TgpuBuffer } from "../buffer/buffer.js";
|
|
11
|
+
import { SelfResolvable } from "../../types.js";
|
|
12
|
+
import { AnyWgslData } from "../../data/wgslTypes.js";
|
|
13
|
+
|
|
14
|
+
//#region src/core/pipeline/computePipeline.d.ts
|
|
15
|
+
interface ComputePipelineInternals {
|
|
16
|
+
readonly rawPipeline: GPUComputePipeline;
|
|
17
|
+
readonly priors: TgpuComputePipelinePriors & TimestampWritesPriors;
|
|
18
|
+
readonly root: ExperimentalTgpuRoot;
|
|
19
|
+
}
|
|
20
|
+
interface TgpuComputePipeline extends TgpuNamable, SelfResolvable, Timeable {
|
|
21
|
+
readonly [$internal]: ComputePipelineInternals;
|
|
22
|
+
readonly resourceType: 'compute-pipeline';
|
|
23
|
+
/**
|
|
24
|
+
* @deprecated This overload is outdated.
|
|
25
|
+
* Call `pipeline.with(bindGroup)` instead.
|
|
26
|
+
*/
|
|
27
|
+
with<Entries extends Record<string, TgpuLayoutEntry | null>>(bindGroupLayout: TgpuBindGroupLayout<Entries>, bindGroup: TgpuBindGroup<Entries>): this;
|
|
28
|
+
with(bindGroupLayout: TgpuBindGroupLayout, bindGroup: GPUBindGroup): this;
|
|
29
|
+
with(bindGroup: TgpuBindGroup): this;
|
|
30
|
+
with(encoder: GPUCommandEncoder): this;
|
|
31
|
+
with(pass: GPUComputePassEncoder): this;
|
|
32
|
+
dispatchWorkgroups(x: number, y?: number, z?: number): void;
|
|
33
|
+
/**
|
|
34
|
+
* Dispatches compute workgroups using parameters read from a buffer.
|
|
35
|
+
* The buffer must contain 3 consecutive u32 values (x, y, z workgroup counts).
|
|
36
|
+
* To get the correct offset within complex data structures, use `d.memoryLayoutOf(...)`.
|
|
37
|
+
*
|
|
38
|
+
* @param indirectBuffer - Buffer marked with 'indirect' usage containing dispatch parameters or raw GPUBuffer
|
|
39
|
+
* @param start - PrimitiveOffsetInfo pointing to the first dispatch parameter. If not provided, starts at offset 0. To obtain safe offsets, use `d.memoryLayoutOf(...)`.
|
|
40
|
+
*/
|
|
41
|
+
dispatchWorkgroupsIndirect<T extends AnyWgslData>(indirectBuffer: (TgpuBuffer<T> & IndirectFlag) | GPUBuffer, start?: PrimitiveOffsetInfo | number): void;
|
|
42
|
+
}
|
|
43
|
+
declare namespace TgpuComputePipeline {
|
|
44
|
+
type Descriptor<Input extends IORecord<AnyComputeBuiltin> = IORecord<AnyComputeBuiltin>> = {
|
|
45
|
+
compute: TgpuComputeFn<Input>;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
type TgpuComputePipelinePriors = {
|
|
49
|
+
readonly bindGroupLayoutMap?: Map<TgpuBindGroupLayout, TgpuBindGroup | GPUBindGroup>;
|
|
50
|
+
readonly externalEncoder?: GPUCommandEncoder | undefined;
|
|
51
|
+
readonly externalPass?: GPUComputePassEncoder | undefined;
|
|
52
|
+
} & TimestampWritesPriors;
|
|
53
|
+
//#endregion
|
|
54
|
+
export { TgpuComputePipeline };
|