typegpu 0.10.0 → 0.10.2
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/{chunk-BYypO7fO.js → _virtual/_rolldown/runtime.js} +1 -1
- package/builtin.d.ts +50 -0
- package/builtin.js +37 -0
- package/common/fullScreenTriangle.d.ts +26 -0
- package/common/fullScreenTriangle.js +36 -0
- package/common/index.d.ts +2 -3
- package/common/index.js +3 -4
- package/core/buffer/buffer.d.ts +74 -0
- package/core/buffer/buffer.js +197 -0
- package/core/buffer/bufferShorthand.d.ts +48 -0
- package/core/buffer/bufferShorthand.js +49 -0
- package/core/buffer/bufferUsage.d.ts +45 -0
- package/core/buffer/bufferUsage.js +163 -0
- package/core/constant/tgpuConstant.d.ts +28 -0
- package/core/constant/tgpuConstant.js +67 -0
- package/core/declare/tgpuDeclare.d.ts +18 -0
- package/core/declare/tgpuDeclare.js +40 -0
- package/core/function/autoIO.d.ts +37 -0
- package/core/function/autoIO.js +87 -0
- package/core/function/comptime.d.ts +39 -0
- package/core/function/comptime.js +51 -0
- package/core/function/createCallableSchema.js +42 -0
- package/core/function/dualImpl.js +54 -0
- package/core/function/extractArgs.js +204 -0
- package/core/function/fnCore.js +79 -0
- package/core/function/fnTypes.d.ts +34 -0
- package/core/function/ioSchema.d.ts +10 -0
- package/core/function/ioSchema.js +30 -0
- package/core/function/shelllessImpl.d.ts +28 -0
- package/core/function/shelllessImpl.js +23 -0
- package/core/function/templateUtils.js +13 -0
- package/core/function/tgpuComputeFn.d.ts +49 -0
- package/core/function/tgpuComputeFn.js +62 -0
- package/core/function/tgpuFn.d.ts +52 -0
- package/core/function/tgpuFn.js +170 -0
- package/core/function/tgpuFragmentFn.d.ts +68 -0
- package/core/function/tgpuFragmentFn.js +68 -0
- package/core/function/tgpuVertexFn.d.ts +55 -0
- package/core/function/tgpuVertexFn.js +65 -0
- package/core/pipeline/applyPipelineState.js +37 -0
- package/core/pipeline/computePipeline.d.ts +58 -0
- package/core/pipeline/computePipeline.js +226 -0
- package/core/pipeline/connectAttachmentToShader.js +26 -0
- package/core/pipeline/connectTargetsToShader.js +29 -0
- package/core/pipeline/limitsOverflow.js +13 -0
- package/core/pipeline/renderPipeline.d.ts +266 -0
- package/core/pipeline/renderPipeline.js +471 -0
- package/core/pipeline/timeable.d.ts +23 -0
- package/core/pipeline/timeable.js +61 -0
- package/core/pipeline/typeGuards.js +29 -0
- package/core/querySet/querySet.d.ts +22 -0
- package/core/querySet/querySet.js +103 -0
- package/core/rawCodeSnippet/tgpuRawCodeSnippet.d.ts +59 -0
- package/core/rawCodeSnippet/tgpuRawCodeSnippet.js +96 -0
- package/core/resolve/externals.d.ts +10 -0
- package/core/resolve/externals.js +58 -0
- package/core/resolve/namespace.d.ts +38 -0
- package/core/resolve/namespace.js +41 -0
- package/core/resolve/resolveData.js +146 -0
- package/core/resolve/stitch.js +25 -0
- package/core/resolve/tgpuResolve.d.ts +151 -0
- package/core/resolve/tgpuResolve.js +68 -0
- package/core/root/configurableImpl.js +18 -0
- package/core/root/init.d.ts +69 -0
- package/core/root/init.js +457 -0
- package/core/root/rootTypes.d.ts +622 -0
- package/core/sampler/sampler.d.ts +35 -0
- package/core/sampler/sampler.js +116 -0
- package/core/simulate/tgpuSimulate.d.ts +36 -0
- package/core/simulate/tgpuSimulate.js +76 -0
- package/core/slot/accessor.d.ts +13 -0
- package/core/slot/accessor.js +97 -0
- package/core/slot/internalSlots.js +7 -0
- package/core/slot/lazy.d.ts +6 -0
- package/core/slot/lazy.js +42 -0
- package/core/slot/slot.d.ts +6 -0
- package/core/slot/slot.js +40 -0
- package/core/slot/slotTypes.d.ts +92 -0
- package/core/slot/slotTypes.js +21 -0
- package/core/texture/externalTexture.d.ts +12 -0
- package/core/texture/externalTexture.js +48 -0
- package/core/texture/texture.d.ts +118 -0
- package/core/texture/texture.js +312 -0
- package/core/texture/textureFormats.d.ts +29 -0
- package/core/texture/textureFormats.js +99 -0
- package/core/texture/textureProps.d.ts +11 -0
- package/core/texture/textureUtils.js +224 -0
- package/core/texture/usageExtension.d.ts +21 -0
- package/core/texture/usageExtension.js +21 -0
- package/core/unroll/tgpuUnroll.d.ts +13 -0
- package/core/unroll/tgpuUnroll.js +36 -0
- package/core/valueProxyUtils.js +44 -0
- package/core/variable/tgpuVariable.d.ts +38 -0
- package/core/variable/tgpuVariable.js +101 -0
- package/core/vertexLayout/connectAttributesToShader.js +59 -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 +15 -0
- package/data/alignmentOf.d.ts +10 -0
- package/data/alignmentOf.js +88 -0
- package/data/array.d.ts +28 -0
- package/data/array.js +48 -0
- package/data/atomic.d.ts +15 -0
- package/data/atomic.js +25 -0
- package/data/attributes.d.ts +121 -0
- package/data/attributes.js +145 -0
- package/data/autoStruct.d.ts +3 -0
- package/data/autoStruct.js +83 -0
- package/data/compiledIO.js +231 -0
- package/data/dataIO.js +549 -0
- package/data/dataTypes.d.ts +115 -0
- package/data/dataTypes.js +97 -0
- package/data/deepEqual.d.ts +25 -0
- package/data/deepEqual.js +58 -0
- package/data/disarray.d.ts +34 -0
- package/data/disarray.js +52 -0
- package/data/getLongestContiguousPrefix.d.ts +10 -0
- package/data/getLongestContiguousPrefix.js +15 -0
- package/data/index.d.ts +26 -4
- package/data/index.js +27 -7
- package/data/instanceToSchema.d.ts +33 -0
- package/data/isContiguous.d.ts +10 -0
- package/data/isContiguous.js +15 -0
- package/data/matrix.d.ts +126 -0
- package/data/matrix.js +517 -0
- package/data/numberOps.js +24 -0
- package/data/numeric.d.ts +81 -0
- package/data/numeric.js +234 -0
- package/data/offsetUtils.d.ts +33 -0
- package/data/offsetUtils.js +167 -0
- package/data/offsets.js +36 -0
- package/data/partialIO.js +68 -0
- package/data/ptr.d.ts +12 -0
- package/data/ptr.js +46 -0
- package/data/ref.d.ts +37 -0
- package/data/ref.js +96 -0
- package/data/sampler.d.ts +107 -0
- package/data/sampler.js +26 -0
- package/data/schemaCallWrapper.js +32 -0
- package/data/schemaMemoryLayout.js +200 -0
- package/data/sizeOf.d.ts +10 -0
- package/data/sizeOf.js +15 -0
- package/data/snippet.d.ts +26 -0
- package/data/snippet.js +61 -0
- package/data/struct.d.ts +17 -0
- package/data/struct.js +46 -0
- package/data/texture.d.ts +292 -0
- package/{texture-Dg5ybJro.js → data/texture.js} +6 -3
- package/data/unstruct.d.ts +24 -0
- package/data/unstruct.js +43 -0
- package/data/vector.d.ts +191 -0
- package/data/vector.js +247 -0
- package/data/vectorImpl.js +516 -0
- package/data/vectorOps.js +664 -0
- package/data/vertexFormatData.d.ts +190 -0
- package/data/vertexFormatData.js +110 -0
- package/data/wgslTypes.d.ts +896 -0
- package/data/wgslTypes.js +215 -0
- package/errors.d.ts +44 -0
- package/errors.js +128 -0
- package/execMode.js +51 -0
- package/extension.d.ts +11 -0
- package/extension.js +18 -0
- package/getGPUValue.js +9 -0
- package/index.d.ts +40 -243
- package/index.js +19 -6318
- package/indexNamedExports.d.ts +38 -0
- package/mathUtils.js +13 -0
- package/memo.js +22 -0
- package/nameRegistry.d.ts +30 -0
- package/nameRegistry.js +449 -0
- package/package.js +5 -0
- package/package.json +23 -23
- package/resolutionCtx.d.ts +29 -0
- package/resolutionCtx.js +546 -0
- package/shared/env.js +13 -0
- package/shared/generators.js +14 -0
- package/shared/meta.d.ts +39 -0
- package/shared/meta.js +63 -0
- package/shared/repr.d.ts +108 -0
- package/shared/stringify.js +22 -0
- package/shared/symbols.d.ts +61 -0
- package/shared/symbols.js +71 -0
- package/shared/utilityTypes.d.ts +29 -0
- package/shared/utilityTypes.js +7 -0
- package/shared/vertexFormat.d.ts +70 -0
- package/shared/vertexFormat.js +64 -0
- package/std/array.d.ts +7 -0
- package/std/array.js +27 -0
- package/std/atomic.d.ts +19 -0
- package/std/atomic.js +113 -0
- package/std/bitcast.d.ts +10 -0
- package/std/bitcast.js +43 -0
- package/std/boolean.d.ts +127 -0
- package/std/boolean.js +274 -0
- package/std/derivative.d.ts +16 -0
- package/std/derivative.js +89 -0
- package/std/discard.d.ts +6 -0
- package/std/discard.js +16 -0
- package/std/extensions.d.ts +8 -0
- package/std/extensions.js +14 -0
- package/std/index.d.ts +15 -3
- package/std/index.js +16 -5
- package/std/matrix.d.ts +41 -0
- package/std/matrix.js +87 -0
- package/std/numeric.d.ts +254 -0
- package/std/numeric.js +847 -0
- package/std/operators.d.ts +48 -0
- package/std/operators.js +153 -0
- package/std/packing.d.ts +26 -0
- package/std/packing.js +86 -0
- package/std/subgroup.d.ts +47 -0
- package/std/subgroup.js +220 -0
- package/std/texture.d.ts +108 -0
- package/std/texture.js +197 -0
- package/tgpu.js +44 -0
- package/tgpuBindGroupLayout.d.ts +161 -0
- package/tgpuBindGroupLayout.js +271 -0
- package/tgpuUnstable.d.ts +48 -0
- package/tgpuUnstable.js +66 -0
- package/tgsl/accessIndex.js +45 -0
- package/tgsl/accessProp.js +113 -0
- package/tgsl/consoleLog/deserializers.js +117 -0
- package/tgsl/consoleLog/logGenerator.js +86 -0
- package/tgsl/consoleLog/serializers.js +225 -0
- package/tgsl/consoleLog/types.d.ts +54 -0
- package/tgsl/consoleLog/types.js +12 -0
- package/tgsl/conversion.js +200 -0
- package/tgsl/forOfUtils.js +45 -0
- package/tgsl/generationHelpers.d.ts +37 -0
- package/tgsl/generationHelpers.js +67 -0
- package/tgsl/math.js +45 -0
- package/tgsl/shaderGenerator.d.ts +18 -0
- package/tgsl/shellless.d.ts +11 -0
- package/tgsl/shellless.js +53 -0
- package/tgsl/wgslGenerator.js +585 -0
- package/types.d.ts +255 -0
- package/types.js +43 -0
- package/unwrapper.d.ts +27 -0
- package/wgslExtensions.d.ts +5 -0
- package/wgslExtensions.js +18 -0
- package/builtin-ClEnM-Ye.js +0 -818
- package/builtin-ClEnM-Ye.js.map +0 -1
- 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-yZXvaV2C.js +0 -413
- package/deepEqual-yZXvaV2C.js.map +0 -1
- package/extensions-0SFbU9FH.js +0 -2032
- package/extensions-0SFbU9FH.js.map +0 -1
- package/fullScreenTriangle-MdLGaAMR.js +0 -543
- package/fullScreenTriangle-MdLGaAMR.js.map +0 -1
- package/index.d.ts.map +0 -1
- package/index.js.map +0 -1
- package/indexNamedExports-Cdy7USiY.d.ts +0 -5696
- package/indexNamedExports-Cdy7USiY.d.ts.map +0 -1
- package/operators-HTxa_0k9.js +0 -4156
- package/operators-HTxa_0k9.js.map +0 -1
- package/std/index.d.ts.map +0 -1
- package/std/index.js.map +0 -1
- package/texture-Dg5ybJro.js.map +0 -1
|
@@ -0,0 +1,622 @@
|
|
|
1
|
+
import { TgpuNamable } from "../../shared/meta.js";
|
|
2
|
+
import { $internal } from "../../shared/symbols.js";
|
|
3
|
+
import { Assume, Mutable, OmitProps, Prettify } from "../../shared/utilityTypes.js";
|
|
4
|
+
import { WgslComparisonSamplerProps, WgslSamplerProps } from "../../data/sampler.js";
|
|
5
|
+
import { AnyComputeBuiltin, AnyFragmentInputBuiltin, OmitBuiltins } from "../../builtin.js";
|
|
6
|
+
import { TgpuQuerySet } from "../querySet/querySet.js";
|
|
7
|
+
import { TgpuMutable, TgpuReadonly, TgpuUniform } from "../buffer/bufferShorthand.js";
|
|
8
|
+
import { LogGeneratorOptions } from "../../tgsl/consoleLog/types.js";
|
|
9
|
+
import { IORecord } from "../function/fnTypes.js";
|
|
10
|
+
import { TgpuComputeFn } from "../function/tgpuComputeFn.js";
|
|
11
|
+
import { Eventual, TgpuAccessor, TgpuMutableAccessor, TgpuSlot } from "../slot/slotTypes.js";
|
|
12
|
+
import { TgpuComputePipeline } from "../pipeline/computePipeline.js";
|
|
13
|
+
import { AnyAutoCustoms, AutoFragmentIn, AutoFragmentOut, AutoVertexIn, AutoVertexOut } from "../function/autoIO.js";
|
|
14
|
+
import { InstanceToSchema } from "../../data/instanceToSchema.js";
|
|
15
|
+
import { FragmentInConstrained, FragmentOutConstrained, TgpuFragmentFn, VertexOutToVarying } from "../function/tgpuFragmentFn.js";
|
|
16
|
+
import { TgpuVertexFn } from "../function/tgpuVertexFn.js";
|
|
17
|
+
import { AttribRecordToDefaultDataTypes, LayoutToAllowedAttribs } from "../vertexLayout/vertexAttribute.js";
|
|
18
|
+
import { TgpuVertexLayout } from "../vertexLayout/vertexLayout.js";
|
|
19
|
+
import { FragmentOutToTargets, TgpuRenderPipeline } from "../pipeline/renderPipeline.js";
|
|
20
|
+
import { Unwrapper } from "../../unwrapper.js";
|
|
21
|
+
import { TgpuFixedComparisonSampler, TgpuFixedSampler } from "../sampler/sampler.js";
|
|
22
|
+
import { ExtractBindGroupInputFromLayout, TgpuBindGroup, TgpuBindGroupLayout, TgpuLayoutEntry } from "../../tgpuBindGroupLayout.js";
|
|
23
|
+
import { ShaderGenerator } from "../../tgsl/shaderGenerator.js";
|
|
24
|
+
import { TgpuBuffer, VertexFlag } from "../buffer/buffer.js";
|
|
25
|
+
import { AnyWgslData, BaseData, U16, U32, Vec3u, Void, WgslArray, v4f } from "../../data/wgslTypes.js";
|
|
26
|
+
import { TgpuTexture } from "../texture/texture.js";
|
|
27
|
+
import { ExtractInvalidSchemaError, Infer, InferGPURecord, IsValidBufferSchema, IsValidStorageSchema, IsValidUniformSchema } from "../../shared/repr.js";
|
|
28
|
+
import { AnyData, Disarray, UndecorateRecord } from "../../data/dataTypes.js";
|
|
29
|
+
|
|
30
|
+
//#region src/core/root/rootTypes.d.ts
|
|
31
|
+
interface TgpuGuardedComputePipeline<TArgs extends number[] = number[]> extends TgpuNamable {
|
|
32
|
+
/**
|
|
33
|
+
* Returns a pipeline wrapper with the specified bind group bound.
|
|
34
|
+
* Analogous to `TgpuComputePipeline.with(bindGroup)`.
|
|
35
|
+
*/
|
|
36
|
+
with(bindGroup: TgpuBindGroup): TgpuGuardedComputePipeline<TArgs>;
|
|
37
|
+
/**
|
|
38
|
+
* Dispatches the pipeline.
|
|
39
|
+
* Unlike `TgpuComputePipeline.dispatchWorkgroups()`, this method takes in the
|
|
40
|
+
* number of threads to run in each dimension.
|
|
41
|
+
*
|
|
42
|
+
* Under the hood, the number of expected threads is sent as a uniform, and
|
|
43
|
+
* "guarded" by a bounds check.
|
|
44
|
+
*/
|
|
45
|
+
dispatchThreads(...args: TArgs): void;
|
|
46
|
+
/**
|
|
47
|
+
* The underlying pipeline used during `dispatchThreads`.
|
|
48
|
+
*/
|
|
49
|
+
pipeline: TgpuComputePipeline;
|
|
50
|
+
/**
|
|
51
|
+
* The buffer used to automatically pass the thread count to the underlying pipeline during `dispatchThreads`.
|
|
52
|
+
* For pipelines with a dimension count lower than 3, the remaining coordinates are expected to be 1.
|
|
53
|
+
*/
|
|
54
|
+
sizeUniform: TgpuUniform<Vec3u>;
|
|
55
|
+
}
|
|
56
|
+
interface WithCompute {
|
|
57
|
+
createPipeline(): TgpuComputePipeline;
|
|
58
|
+
}
|
|
59
|
+
type OptionalArgs<T> = T extends Record<string, never> | undefined ? [] | [T] : [T];
|
|
60
|
+
/**
|
|
61
|
+
* TODO: Remove in favor of createRenderPipeline's validation
|
|
62
|
+
*/
|
|
63
|
+
type ValidateFragmentIn<VertexOut extends TgpuVertexFn.Out, FragmentIn extends FragmentInConstrained, FragmentOut extends FragmentOutConstrained> = UndecorateRecord<FragmentIn> extends Partial<UndecorateRecord<VertexOut>> ? UndecorateRecord<VertexOut> extends UndecorateRecord<FragmentIn> ? OptionalArgs<FragmentOutToTargets<FragmentOut>> extends infer Args ? Args extends [infer T] ? [entryFn: TgpuFragmentFn<FragmentIn, FragmentOut>, targets: T] : Args extends [] | [infer T] ? [entryFn: TgpuFragmentFn<FragmentIn, FragmentOut>] | [entryFn: TgpuFragmentFn<FragmentIn, FragmentOut>, targets: T] : never : never : [entryFn: 'n/a', targets: 'n/a', MissingFromVertexOutput: { [Key in Exclude<keyof FragmentIn, keyof VertexOut>]: FragmentIn[Key] }] : [entryFn: 'n/a', targets: 'n/a', MismatchedVertexOutput: { [Key in keyof FragmentIn & keyof VertexOut as FragmentIn[Key] extends VertexOut[Key] ? never : Key]: [got: VertexOut[Key], expecting: FragmentIn[Key]] }];
|
|
64
|
+
interface WithVertex<VertexOut extends TgpuVertexFn.Out = TgpuVertexFn.Out> {
|
|
65
|
+
/**
|
|
66
|
+
* @deprecated Use `root.createRenderPipeline` instead.
|
|
67
|
+
*/
|
|
68
|
+
withFragment<FragmentIn extends FragmentInConstrained, FragmentOut extends FragmentOutConstrained>(...args: ValidateFragmentIn<VertexOut, FragmentIn, FragmentOut>): WithFragment<FragmentOut>;
|
|
69
|
+
/**
|
|
70
|
+
* @deprecated Use `root.createRenderPipeline` instead.
|
|
71
|
+
*/
|
|
72
|
+
withPrimitive(primitiveState: GPUPrimitiveState | (Omit<GPUPrimitiveState, 'stripIndexFormat'> & {
|
|
73
|
+
stripIndexFormat?: U32 | U16;
|
|
74
|
+
}) | undefined): WithFragment<Void>;
|
|
75
|
+
/**
|
|
76
|
+
* @deprecated Use `root.createRenderPipeline` instead.
|
|
77
|
+
*/
|
|
78
|
+
withDepthStencil(depthStencilState: GPUDepthStencilState | undefined): WithFragment<Void>;
|
|
79
|
+
/**
|
|
80
|
+
* @deprecated Use `root.createRenderPipeline` instead.
|
|
81
|
+
*/
|
|
82
|
+
withMultisample(multisampleState: GPUMultisampleState | undefined): WithFragment<Void>;
|
|
83
|
+
/**
|
|
84
|
+
* @deprecated Use `root.createRenderPipeline` instead.
|
|
85
|
+
*/
|
|
86
|
+
createPipeline(): TgpuRenderPipeline<Void>;
|
|
87
|
+
}
|
|
88
|
+
interface WithFragment<Targets extends FragmentOutConstrained = FragmentOutConstrained> {
|
|
89
|
+
withPrimitive(primitiveState: GPUPrimitiveState | (Omit<GPUPrimitiveState, 'stripIndexFormat'> & {
|
|
90
|
+
stripIndexFormat?: U32 | U16;
|
|
91
|
+
}) | undefined): WithFragment<Targets>;
|
|
92
|
+
withDepthStencil(depthStencilState: GPUDepthStencilState | undefined): WithFragment<Targets>;
|
|
93
|
+
withMultisample(multisampleState: GPUMultisampleState | undefined): WithFragment<Targets>;
|
|
94
|
+
createPipeline(): TgpuRenderPipeline<Targets>;
|
|
95
|
+
}
|
|
96
|
+
interface Withable<TSelf> {
|
|
97
|
+
with<T>(slot: TgpuSlot<T>, value: Eventual<T>): TSelf;
|
|
98
|
+
with<T extends BaseData>(accessor: TgpuAccessor<T>, value: TgpuAccessor.In<NoInfer<T>>): TSelf;
|
|
99
|
+
with<T extends BaseData>(accessor: TgpuMutableAccessor<T>, value: TgpuMutableAccessor.In<NoInfer<T>>): TSelf;
|
|
100
|
+
}
|
|
101
|
+
interface Withable_Deprecated<TSelf> {
|
|
102
|
+
/**
|
|
103
|
+
* @deprecated This feature is stable, remove the `['~unstable']`
|
|
104
|
+
* @param slot
|
|
105
|
+
* @param value
|
|
106
|
+
*/
|
|
107
|
+
with<T>(slot: TgpuSlot<T>, value: Eventual<T>): TSelf;
|
|
108
|
+
/**
|
|
109
|
+
* @deprecated This feature is stable, remove the `['~unstable']`
|
|
110
|
+
* @param slot
|
|
111
|
+
* @param value
|
|
112
|
+
*/
|
|
113
|
+
with<T extends BaseData>(accessor: TgpuAccessor<T>, value: TgpuAccessor.In<NoInfer<T>>): TSelf;
|
|
114
|
+
/**
|
|
115
|
+
* @deprecated This feature is stable, remove the `['~unstable']`
|
|
116
|
+
* @param slot
|
|
117
|
+
* @param value
|
|
118
|
+
*/
|
|
119
|
+
with<T extends BaseData>(accessor: TgpuMutableAccessor<T>, value: TgpuMutableAccessor.In<NoInfer<T>>): TSelf;
|
|
120
|
+
}
|
|
121
|
+
interface Configurable extends Withable<Configurable> {
|
|
122
|
+
readonly bindings: [slot: TgpuSlot<unknown>, value: unknown][];
|
|
123
|
+
pipe(transform: (cfg: Configurable) => Configurable): Configurable;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Gets rid of builtins, and turns instances into schemas
|
|
127
|
+
* @example d.v4f => d.Vec4f
|
|
128
|
+
* @example d.builtin.position => d.Void
|
|
129
|
+
* @example { a: d.v4f, $fragDepth: number } => { a: d.Vec4f }
|
|
130
|
+
*/
|
|
131
|
+
type NormalizeOutput<T> = T extends {
|
|
132
|
+
readonly [$internal]: unknown;
|
|
133
|
+
} | number | boolean ? [OmitBuiltins<InstanceToSchema<T>>] extends [never] ? Void : OmitBuiltins<InstanceToSchema<T>> : { [K in keyof OmitBuiltins<T>]: InstanceToSchema<OmitBuiltins<T>[K]> };
|
|
134
|
+
interface WithBinding extends Withable<WithBinding> {
|
|
135
|
+
/** @deprecated Use `root.createComputePipeline` instead. */
|
|
136
|
+
withCompute<ComputeIn extends IORecord<AnyComputeBuiltin>>(entryFn: TgpuComputeFn<ComputeIn>): WithCompute;
|
|
137
|
+
createComputePipeline<ComputeIn extends IORecord<AnyComputeBuiltin>>(descriptor: TgpuComputePipeline.Descriptor<ComputeIn>): TgpuComputePipeline;
|
|
138
|
+
createRenderPipeline<TVertexIn extends TgpuVertexFn.In = Record<string, any>, TAttribs extends LayoutToAllowedAttribs<TVertexIn> = LayoutToAllowedAttribs<TVertexIn>, TVertexOut = unknown, TFragmentOut = unknown>(descriptor: TgpuRenderPipeline.DescriptorBase & {
|
|
139
|
+
attribs?: TAttribs;
|
|
140
|
+
vertex: TgpuVertexFn<TVertexIn, Assume<TVertexOut, TgpuVertexFn.Out>> | ((input: AutoVertexIn<Assume<InferGPURecord<AttribRecordToDefaultDataTypes<TAttribs>>, AnyAutoCustoms>>) => AutoVertexOut<Assume<TVertexOut, AnyAutoCustoms>>);
|
|
141
|
+
fragment: TgpuFragmentFn<VertexOutToVarying<TVertexOut> & Record<string, AnyFragmentInputBuiltin>, Assume<TFragmentOut, TgpuFragmentFn.Out>> | ((input: AutoFragmentIn<Assume<InferGPURecord<VertexOutToVarying<TVertexOut>>, AnyAutoCustoms>>) => AutoFragmentOut<Assume<TFragmentOut, AnyAutoCustoms | v4f>>);
|
|
142
|
+
targets?: FragmentOutToTargets<NoInfer<TFragmentOut>>;
|
|
143
|
+
}): TgpuRenderPipeline<NormalizeOutput<TFragmentOut>>;
|
|
144
|
+
createRenderPipeline<TVertexIn extends TgpuVertexFn.In = Record<string, any>, TAttribs extends LayoutToAllowedAttribs<TVertexIn> = LayoutToAllowedAttribs<TVertexIn>, TVertexOut extends TgpuVertexFn.Out = TgpuVertexFn.Out>(descriptor: TgpuRenderPipeline.DescriptorBase & {
|
|
145
|
+
attribs?: TAttribs;
|
|
146
|
+
vertex: TgpuVertexFn<TVertexIn, Assume<TVertexOut, TgpuVertexFn.Out>> | ((input: AutoVertexIn<Assume<InferGPURecord<AttribRecordToDefaultDataTypes<TAttribs>>, AnyAutoCustoms>>) => AutoVertexOut<Assume<TVertexOut, AnyAutoCustoms>>);
|
|
147
|
+
fragment?: undefined | TgpuFragmentFn<VertexOutToVarying<OmitBuiltins<TVertexOut>> & Record<string, AnyFragmentInputBuiltin>, Record<string, never> | Void> | ((input: AutoFragmentIn<Assume<InferGPURecord<OmitBuiltins<NoInfer<TVertexOut>>>, AnyAutoCustoms>>) => AutoFragmentOut<undefined>);
|
|
148
|
+
targets?: undefined;
|
|
149
|
+
}): TgpuRenderPipeline<Void>;
|
|
150
|
+
createRenderPipeline<TVertexIn extends TgpuVertexFn.In = Record<string, any>, TAttribs extends LayoutToAllowedAttribs<TVertexIn> = LayoutToAllowedAttribs<TVertexIn>, TVertexOut extends TgpuVertexFn.Out = TgpuVertexFn.Out, TFragmentOut = unknown>(descriptor: TgpuRenderPipeline.DescriptorBase & ({
|
|
151
|
+
attribs?: TAttribs;
|
|
152
|
+
vertex: TgpuVertexFn<TVertexIn, Assume<TVertexOut, TgpuVertexFn.Out>> | ((input: AutoVertexIn<Assume<InferGPURecord<AttribRecordToDefaultDataTypes<TAttribs>>, AnyAutoCustoms>>) => AutoVertexOut<Assume<TVertexOut, AnyAutoCustoms>>);
|
|
153
|
+
fragment: ((input: AutoFragmentIn<Assume<InferGPURecord<OmitBuiltins<NoInfer<TVertexOut>>>, AnyAutoCustoms>>) => AutoFragmentOut<Assume<TFragmentOut, AnyAutoCustoms | v4f>>) | TgpuFragmentFn<VertexOutToVarying<OmitBuiltins<TVertexOut>> & Record<string, AnyFragmentInputBuiltin>, Assume<TFragmentOut, TgpuFragmentFn.Out>>;
|
|
154
|
+
targets?: FragmentOutToTargets<NoInfer<TFragmentOut>>;
|
|
155
|
+
} | {
|
|
156
|
+
attribs?: TAttribs;
|
|
157
|
+
vertex: TgpuVertexFn<TVertexIn, Assume<TVertexOut, TgpuVertexFn.Out>> | ((input: AutoVertexIn<Assume<InferGPURecord<AttribRecordToDefaultDataTypes<TAttribs>>, AnyAutoCustoms>>) => AutoVertexOut<Assume<TVertexOut, AnyAutoCustoms>>);
|
|
158
|
+
fragment?: undefined | TgpuFragmentFn<VertexOutToVarying<OmitBuiltins<TVertexOut>> & Record<string, AnyFragmentInputBuiltin>, Record<string, never>> | ((input: AutoFragmentIn<Assume<InferGPURecord<OmitBuiltins<NoInfer<TVertexOut>>>, AnyAutoCustoms>>) => AutoFragmentOut<undefined>);
|
|
159
|
+
targets?: undefined;
|
|
160
|
+
})): TgpuRenderPipeline<NormalizeOutput<TFragmentOut>> | TgpuRenderPipeline<Void>;
|
|
161
|
+
/**
|
|
162
|
+
* Creates a compute pipeline that executes the given callback in an exact number of threads.
|
|
163
|
+
* This is different from `withCompute(...).createPipeline()` in that it does a bounds check on the
|
|
164
|
+
* thread id, where as regular pipelines do not and work in units of workgroups.
|
|
165
|
+
*
|
|
166
|
+
* @param callback A function converted to WGSL and executed on the GPU.
|
|
167
|
+
* It can accept up to 3 parameters (x, y, z) which correspond to the global invocation ID
|
|
168
|
+
* of the executing thread.
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* If no parameters are provided, the callback will be executed once, in a single thread.
|
|
172
|
+
*
|
|
173
|
+
* ```ts
|
|
174
|
+
* const fooPipeline = root
|
|
175
|
+
* .createGuardedComputePipeline(() => {
|
|
176
|
+
* 'use gpu';
|
|
177
|
+
* console.log('Hello, GPU!');
|
|
178
|
+
* });
|
|
179
|
+
*
|
|
180
|
+
* fooPipeline.dispatchThreads();
|
|
181
|
+
* // [GPU] Hello, GPU!
|
|
182
|
+
* ```
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* One parameter means n-threads will be executed in parallel.
|
|
186
|
+
*
|
|
187
|
+
* ```ts
|
|
188
|
+
* const fooPipeline = root
|
|
189
|
+
* .createGuardedComputePipeline((x) => {
|
|
190
|
+
* 'use gpu';
|
|
191
|
+
* if (x % 16 === 0) {
|
|
192
|
+
* // Logging every 16th thread
|
|
193
|
+
* console.log('I am the', x, 'thread');
|
|
194
|
+
* }
|
|
195
|
+
* });
|
|
196
|
+
*
|
|
197
|
+
* // executing 512 threads
|
|
198
|
+
* fooPipeline.dispatchThreads(512);
|
|
199
|
+
* // [GPU] I am the 256 thread
|
|
200
|
+
* // [GPU] I am the 272 thread
|
|
201
|
+
* // ... (30 hidden logs)
|
|
202
|
+
* // [GPU] I am the 16 thread
|
|
203
|
+
* // [GPU] I am the 240 thread
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
createGuardedComputePipeline<TArgs extends number[]>(callback: (...args: TArgs) => void): TgpuGuardedComputePipeline<TArgs>;
|
|
207
|
+
/**
|
|
208
|
+
* @deprecated Use `root.createRenderPipeline` instead.
|
|
209
|
+
*/
|
|
210
|
+
withVertex<VertexIn extends TgpuVertexFn.In, VertexOut extends TgpuVertexFn.Out>(entryFn: TgpuVertexFn<VertexIn, VertexOut>, ...args: OptionalArgs<LayoutToAllowedAttribs<OmitBuiltins<VertexIn>>>): WithVertex<VertexOut>;
|
|
211
|
+
pipe(transform: (cfg: Configurable) => Configurable): WithBinding;
|
|
212
|
+
}
|
|
213
|
+
type SrgbVariants = {
|
|
214
|
+
rgba8unorm: 'rgba8unorm-srgb';
|
|
215
|
+
bgra8unorm: 'bgra8unorm-srgb';
|
|
216
|
+
'bc1-rgba-unorm': 'bc1-rgba-unorm-srgb';
|
|
217
|
+
'bc2-rgba-unorm': 'bc2-rgba-unorm-srgb';
|
|
218
|
+
'bc3-rgba-unorm': 'bc3-rgba-unorm-srgb';
|
|
219
|
+
'bc7-rgba-unorm': 'bc7-rgba-unorm-srgb';
|
|
220
|
+
'etc2-rgb8unorm': 'etc2-rgb8unorm-srgb';
|
|
221
|
+
'etc2-rgb8a1unorm': 'etc2-rgb8a1unorm-srgb';
|
|
222
|
+
'etc2-rgba8unorm': 'etc2-rgba8unorm-srgb';
|
|
223
|
+
'astc-4x4-unorm': 'astc-4x4-unorm-srgb';
|
|
224
|
+
'astc-5x4-unorm': 'astc-5x4-unorm-srgb';
|
|
225
|
+
'astc-5x5-unorm': 'astc-5x5-unorm-srgb';
|
|
226
|
+
'astc-6x5-unorm': 'astc-6x5-unorm-srgb';
|
|
227
|
+
'astc-6x6-unorm': 'astc-6x6-unorm-srgb';
|
|
228
|
+
'astc-8x5-unorm': 'astc-8x5-unorm-srgb';
|
|
229
|
+
'astc-8x6-unorm': 'astc-8x6-unorm-srgb';
|
|
230
|
+
'astc-8x8-unorm': 'astc-8x8-unorm-srgb';
|
|
231
|
+
'astc-10x5-unorm': 'astc-10x5-unorm-srgb';
|
|
232
|
+
'astc-10x6-unorm': 'astc-10x6-unorm-srgb';
|
|
233
|
+
'astc-10x8-unorm': 'astc-10x8-unorm-srgb';
|
|
234
|
+
'astc-10x10-unorm': 'astc-10x10-unorm-srgb';
|
|
235
|
+
'astc-12x10-unorm': 'astc-12x10-unorm-srgb';
|
|
236
|
+
'astc-12x12-unorm': 'astc-12x12-unorm-srgb';
|
|
237
|
+
};
|
|
238
|
+
type SrgbVariantOrSelf<T extends GPUTextureFormat> = T extends keyof SrgbVariants ? (SrgbVariants[T] | T)[] | undefined : T extends `${infer Base}-srgb` ? Base extends keyof SrgbVariants ? (T | SrgbVariants[Base])[] | undefined : T[] | undefined : T[] | undefined;
|
|
239
|
+
type CreateTextureOptions<TSize, TFormat extends GPUTextureFormat, TMipLevelCount extends number, TSampleCount extends number, TViewFormats extends GPUTextureFormat[], TDimension extends GPUTextureDimension> = {
|
|
240
|
+
/**
|
|
241
|
+
* The width, height, and depth or layer count of the texture.
|
|
242
|
+
*/
|
|
243
|
+
size: TSize;
|
|
244
|
+
/**
|
|
245
|
+
* The format of the texture.
|
|
246
|
+
*/
|
|
247
|
+
format: TFormat;
|
|
248
|
+
/**
|
|
249
|
+
* The number of mip levels the texture will contain.
|
|
250
|
+
* @default 1
|
|
251
|
+
*/
|
|
252
|
+
mipLevelCount?: TMipLevelCount | undefined;
|
|
253
|
+
/**
|
|
254
|
+
* The sample count of the texture. A sampleCount > 1 indicates a multisampled texture.
|
|
255
|
+
* @default 1
|
|
256
|
+
*/
|
|
257
|
+
sampleCount?: TSampleCount | undefined;
|
|
258
|
+
/**
|
|
259
|
+
* Specifies extra formats (in addition to the texture's actual format) that can be used
|
|
260
|
+
* when creating views of this texture.
|
|
261
|
+
* @default []
|
|
262
|
+
*/
|
|
263
|
+
viewFormats?: TViewFormats extends SrgbVariantOrSelf<NoInfer<TFormat>> ? TViewFormats : SrgbVariantOrSelf<NoInfer<TFormat>>;
|
|
264
|
+
/**
|
|
265
|
+
* Whether the texture is one-dimensional, an array of two-dimensional layers, or three-dimensional.
|
|
266
|
+
* @default '2d'
|
|
267
|
+
*/
|
|
268
|
+
dimension?: TDimension | undefined;
|
|
269
|
+
};
|
|
270
|
+
type CreateTextureResult<TSize extends readonly number[], TFormat extends GPUTextureFormat, TMipLevelCount extends number, TSampleCount extends number, TViewFormats extends GPUTextureFormat[], TDimension extends GPUTextureDimension> = Prettify<{
|
|
271
|
+
size: Mutable<TSize>;
|
|
272
|
+
format: TFormat;
|
|
273
|
+
} & OmitProps<{
|
|
274
|
+
dimension: GPUTextureDimension extends TDimension ? undefined : TDimension extends '2d' ? undefined : TDimension;
|
|
275
|
+
mipLevelCount: number extends TMipLevelCount ? undefined : TMipLevelCount extends 1 ? undefined : TMipLevelCount;
|
|
276
|
+
sampleCount: number extends TSampleCount ? undefined : TSampleCount extends 1 ? undefined : TSampleCount;
|
|
277
|
+
viewFormats: GPUTextureFormat[] extends TViewFormats ? undefined : TViewFormats extends never[] ? undefined : TViewFormats extends SrgbVariantOrSelf<TFormat> ? TViewFormats : never;
|
|
278
|
+
}, undefined>>;
|
|
279
|
+
interface RenderBundleEncoderPass {
|
|
280
|
+
/**
|
|
281
|
+
* Sets the current {@link TgpuRenderPipeline} for subsequent draw calls.
|
|
282
|
+
* @param pipeline - The render pipeline to use.
|
|
283
|
+
*/
|
|
284
|
+
setPipeline(pipeline: TgpuRenderPipeline): void;
|
|
285
|
+
/**
|
|
286
|
+
* Sets the current index buffer.
|
|
287
|
+
* @param buffer - Buffer containing index data to use for subsequent drawing commands.
|
|
288
|
+
* @param indexFormat - Format of the index data contained in `buffer`.
|
|
289
|
+
* @param offset - Offset in bytes into `buffer` where the index data begins. Defaults to `0`.
|
|
290
|
+
* @param size - Size in bytes of the index data in `buffer`.
|
|
291
|
+
* Defaults to the size of the buffer minus the offset.
|
|
292
|
+
*/
|
|
293
|
+
setIndexBuffer<TData extends WgslArray | Disarray>(buffer: TgpuBuffer<TData> | GPUBuffer, indexFormat: GPUIndexFormat, offset?: GPUSize64, size?: GPUSize64): void;
|
|
294
|
+
/**
|
|
295
|
+
* Binds a vertex buffer to the given vertex layout for subsequent draw calls.
|
|
296
|
+
* @param vertexLayout - The vertex layout describing the buffer's structure.
|
|
297
|
+
* @param buffer - The vertex buffer to bind.
|
|
298
|
+
* @param offset - Offset in bytes into `buffer`. Defaults to `0`.
|
|
299
|
+
* @param size - Size in bytes to bind. Defaults to the remainder of the buffer.
|
|
300
|
+
*/
|
|
301
|
+
setVertexBuffer<TData extends WgslArray | Disarray>(vertexLayout: TgpuVertexLayout<TData>, buffer: (TgpuBuffer<TData> & VertexFlag) | GPUBuffer, offset?: GPUSize64, size?: GPUSize64): void;
|
|
302
|
+
/**
|
|
303
|
+
* Associates a bind group with the given layout for subsequent draw calls.
|
|
304
|
+
* @param bindGroupLayout - The layout the bind group conforms to.
|
|
305
|
+
* @param bindGroup - The bind group to associate.
|
|
306
|
+
*/
|
|
307
|
+
setBindGroup<Entries extends Record<string, TgpuLayoutEntry | null>>(bindGroupLayout: TgpuBindGroupLayout<Entries>, bindGroup: TgpuBindGroup<Entries> | GPUBindGroup): void;
|
|
308
|
+
/**
|
|
309
|
+
* Draws primitives.
|
|
310
|
+
* @param vertexCount - The number of vertices to draw.
|
|
311
|
+
* @param instanceCount - The number of instances to draw.
|
|
312
|
+
* @param firstVertex - Offset into the vertex buffers, in vertices, to begin drawing from.
|
|
313
|
+
* @param firstInstance - First instance to draw.
|
|
314
|
+
*/
|
|
315
|
+
draw(vertexCount: number, instanceCount?: number, firstVertex?: number, firstInstance?: number): void;
|
|
316
|
+
/**
|
|
317
|
+
* Draws indexed primitives.
|
|
318
|
+
* @param indexCount - The number of indices to draw.
|
|
319
|
+
* @param instanceCount - The number of instances to draw.
|
|
320
|
+
* @param firstIndex - Offset into the index buffer, in indices, begin drawing from.
|
|
321
|
+
* @param baseVertex - Added to each index value before indexing into the vertex buffers.
|
|
322
|
+
* @param firstInstance - First instance to draw.
|
|
323
|
+
*/
|
|
324
|
+
drawIndexed(indexCount: number, instanceCount?: number, firstIndex?: number, baseVertex?: number, firstInstance?: number): void;
|
|
325
|
+
/**
|
|
326
|
+
* Draws primitives using parameters read from a {@link GPUBuffer}.
|
|
327
|
+
* @param indirectBuffer - Buffer containing the indirect draw parameters.
|
|
328
|
+
* @param indirectOffset - Offset in bytes into `indirectBuffer` where the drawing data begins.
|
|
329
|
+
*/
|
|
330
|
+
drawIndirect(indirectBuffer: GPUBuffer, indirectOffset: GPUSize64): void;
|
|
331
|
+
/**
|
|
332
|
+
* Draws indexed primitives using parameters read from a {@link GPUBuffer}.
|
|
333
|
+
* @param indirectBuffer - Buffer containing the indirect drawIndexed parameters.
|
|
334
|
+
* @param indirectOffset - Offset in bytes into `indirectBuffer` where the drawing data begins.
|
|
335
|
+
*/
|
|
336
|
+
drawIndexedIndirect(indirectBuffer: GPUBuffer, indirectOffset: GPUSize64): void;
|
|
337
|
+
}
|
|
338
|
+
interface RenderPass extends RenderBundleEncoderPass {
|
|
339
|
+
/**
|
|
340
|
+
* Sets the viewport used during the rasterization stage to linearly map from
|
|
341
|
+
* NDC (i.e., normalized device coordinates) to viewport coordinates.
|
|
342
|
+
* @param x - Minimum X value of the viewport in pixels.
|
|
343
|
+
* @param y - Minimum Y value of the viewport in pixels.
|
|
344
|
+
* @param width - Width of the viewport in pixels.
|
|
345
|
+
* @param height - Height of the viewport in pixels.
|
|
346
|
+
* @param minDepth - Minimum depth value of the viewport.
|
|
347
|
+
* @param maxDepth - Maximum depth value of the viewport.
|
|
348
|
+
*/
|
|
349
|
+
setViewport(x: number, y: number, width: number, height: number, minDepth: number, maxDepth: number): void;
|
|
350
|
+
/**
|
|
351
|
+
* Sets the scissor rectangle used during the rasterization stage.
|
|
352
|
+
* After transformation into viewport coordinates any fragments which fall outside the scissor
|
|
353
|
+
* rectangle will be discarded.
|
|
354
|
+
* @param x - Minimum X value of the scissor rectangle in pixels.
|
|
355
|
+
* @param y - Minimum Y value of the scissor rectangle in pixels.
|
|
356
|
+
* @param width - Width of the scissor rectangle in pixels.
|
|
357
|
+
* @param height - Height of the scissor rectangle in pixels.
|
|
358
|
+
*/
|
|
359
|
+
setScissorRect(x: number, y: number, width: number, height: number): void;
|
|
360
|
+
/**
|
|
361
|
+
* Sets the constant blend color and alpha values used with {@link GPUBlendFactor#constant}
|
|
362
|
+
* and {@link GPUBlendFactor#"one-minus-constant"} {@link GPUBlendFactor}s.
|
|
363
|
+
* @param color - The color to use when blending.
|
|
364
|
+
*/
|
|
365
|
+
setBlendConstant(color: GPUColor): void;
|
|
366
|
+
/**
|
|
367
|
+
* Sets the {@link RenderState#[[stencilReference]]} value used during stencil tests with
|
|
368
|
+
* the {@link GPUStencilOperation#"replace"} {@link GPUStencilOperation}.
|
|
369
|
+
* @param reference - The new stencil reference value.
|
|
370
|
+
*/
|
|
371
|
+
setStencilReference(reference: GPUStencilValue): void;
|
|
372
|
+
/**
|
|
373
|
+
* @param queryIndex - The index of the query in the query set.
|
|
374
|
+
*/
|
|
375
|
+
beginOcclusionQuery(queryIndex: GPUSize32): void;
|
|
376
|
+
endOcclusionQuery(): void;
|
|
377
|
+
/**
|
|
378
|
+
* Executes the commands previously recorded into the given {@link GPURenderBundle}s as part of
|
|
379
|
+
* this render pass.
|
|
380
|
+
* When a {@link GPURenderBundle} is executed, it does not inherit the render pass's pipeline, bind
|
|
381
|
+
* groups, or vertex and index buffers. After a {@link GPURenderBundle} has executed, the render
|
|
382
|
+
* pass's pipeline, bind group, and vertex/index buffer state is cleared
|
|
383
|
+
* (to the initial, empty values).
|
|
384
|
+
* Note: The state is cleared, not restored to the previous state.
|
|
385
|
+
* This occurs even if zero {@link GPURenderBundle|GPURenderBundles} are executed.
|
|
386
|
+
* @param bundles - List of render bundles to execute.
|
|
387
|
+
*/
|
|
388
|
+
executeBundles(bundles: Iterable<GPURenderBundle>): undefined;
|
|
389
|
+
setPipeline(pipeline: TgpuRenderPipeline): void;
|
|
390
|
+
/**
|
|
391
|
+
* Sets the current index buffer.
|
|
392
|
+
* @param buffer - Buffer containing index data to use for subsequent drawing commands.
|
|
393
|
+
* @param indexFormat - Format of the index data contained in `buffer`.
|
|
394
|
+
* @param offset - Offset in bytes into `buffer` where the index data begins. Defaults to `0`.
|
|
395
|
+
* @param size - Size in bytes of the index data in `buffer`.
|
|
396
|
+
* Defaults to the size of the buffer minus the offset.
|
|
397
|
+
*/
|
|
398
|
+
setIndexBuffer<TData extends WgslArray | Disarray>(buffer: TgpuBuffer<TData> | GPUBuffer, indexFormat: GPUIndexFormat, offset?: GPUSize64, size?: GPUSize64): void;
|
|
399
|
+
setVertexBuffer<TData extends WgslArray | Disarray>(vertexLayout: TgpuVertexLayout<TData>, buffer: (TgpuBuffer<TData> & VertexFlag) | GPUBuffer, offset?: GPUSize64, size?: GPUSize64): void;
|
|
400
|
+
setBindGroup<Entries extends Record<string, TgpuLayoutEntry | null>>(bindGroupLayout: TgpuBindGroupLayout<Entries>, bindGroup: TgpuBindGroup<Entries> | GPUBindGroup): void;
|
|
401
|
+
/**
|
|
402
|
+
* Draws primitives.
|
|
403
|
+
* @param vertexCount - The number of vertices to draw.
|
|
404
|
+
* @param instanceCount - The number of instances to draw.
|
|
405
|
+
* @param firstVertex - Offset into the vertex buffers, in vertices, to begin drawing from.
|
|
406
|
+
* @param firstInstance - First instance to draw.
|
|
407
|
+
*/
|
|
408
|
+
draw(vertexCount: number, instanceCount?: number, firstVertex?: number, firstInstance?: number): void;
|
|
409
|
+
/**
|
|
410
|
+
* Draws indexed primitives.
|
|
411
|
+
* @param indexCount - The number of indices to draw.
|
|
412
|
+
* @param instanceCount - The number of instances to draw.
|
|
413
|
+
* @param firstIndex - Offset into the index buffer, in indices, begin drawing from.
|
|
414
|
+
* @param baseVertex - Added to each index value before indexing into the vertex buffers.
|
|
415
|
+
* @param firstInstance - First instance to draw.
|
|
416
|
+
*/
|
|
417
|
+
drawIndexed(indexCount: number, instanceCount?: number, firstIndex?: number, baseVertex?: number, firstInstance?: number): void;
|
|
418
|
+
/**
|
|
419
|
+
* Draws primitives using parameters read from a {@link GPUBuffer}.
|
|
420
|
+
* Packed block of **four 32-bit unsigned integer values (16 bytes total)**, given in the same
|
|
421
|
+
* order as the arguments for {@link GPURenderEncoderBase#draw}. For example:
|
|
422
|
+
* @param indirectBuffer - Buffer containing the indirect draw parameters.
|
|
423
|
+
* @param indirectOffset - Offset in bytes into `indirectBuffer` where the drawing data begins.
|
|
424
|
+
*/
|
|
425
|
+
drawIndirect(indirectBuffer: GPUBuffer, indirectOffset: GPUSize64): void;
|
|
426
|
+
/**
|
|
427
|
+
* Draws indexed primitives using parameters read from a {@link GPUBuffer}.
|
|
428
|
+
* Tightly packed block of **five 32-bit unsigned integer values (20 bytes total)**, given in
|
|
429
|
+
* the same order as the arguments for {@link GPURenderEncoderBase#drawIndexed}. For example:
|
|
430
|
+
* @param indirectBuffer - Buffer containing the indirect drawIndexed parameters.
|
|
431
|
+
* @param indirectOffset - Offset in bytes into `indirectBuffer` where the drawing data begins.
|
|
432
|
+
*/
|
|
433
|
+
drawIndexedIndirect(indirectBuffer: GPUBuffer, indirectOffset: GPUSize64): void;
|
|
434
|
+
}
|
|
435
|
+
type ValidateBufferSchema<TData extends BaseData> = IsValidBufferSchema<TData> extends false ? ExtractInvalidSchemaError<TData, '(Error) '> : TData;
|
|
436
|
+
type ValidateStorageSchema<TData extends BaseData> = IsValidStorageSchema<TData> extends false ? ExtractInvalidSchemaError<TData, '(Error) '> : TData;
|
|
437
|
+
type ValidateUniformSchema<TData extends BaseData> = IsValidUniformSchema<TData> extends false ? ExtractInvalidSchemaError<TData, '(Error) '> : TData;
|
|
438
|
+
type ConfigureContextOptions = {
|
|
439
|
+
/**
|
|
440
|
+
* The canvas for which a context will be created and configured.
|
|
441
|
+
*/
|
|
442
|
+
canvas: HTMLCanvasElement | OffscreenCanvas;
|
|
443
|
+
/**
|
|
444
|
+
* Passed to `context.configure()`.
|
|
445
|
+
* Defaults to `navigator.gpu.getPreferredCanvasFormat()` if not provided.
|
|
446
|
+
*/
|
|
447
|
+
format?: GPUTextureFormat;
|
|
448
|
+
} & Omit<GPUCanvasConfiguration, 'device' | 'format'>;
|
|
449
|
+
interface TgpuRoot extends Unwrapper, WithBinding {
|
|
450
|
+
[$internal]: {
|
|
451
|
+
logOptions: LogGeneratorOptions;
|
|
452
|
+
};
|
|
453
|
+
/**
|
|
454
|
+
* The GPU device associated with this root.
|
|
455
|
+
*/
|
|
456
|
+
readonly device: GPUDevice;
|
|
457
|
+
/**
|
|
458
|
+
* Creates and configures context for the provided canvas.
|
|
459
|
+
* Automatically sets the format to `navigator.gpu.getPreferredCanvasFormat()` if not provided.
|
|
460
|
+
* @throws An error if no context could be obtained
|
|
461
|
+
*/
|
|
462
|
+
configureContext(options: ConfigureContextOptions): GPUCanvasContext;
|
|
463
|
+
/**
|
|
464
|
+
* Allocates memory on the GPU, allows passing data between host and shader.
|
|
465
|
+
*
|
|
466
|
+
* @remarks
|
|
467
|
+
* Typed wrapper around a GPUBuffer.
|
|
468
|
+
*
|
|
469
|
+
* @param typeSchema The type of data that this buffer will hold.
|
|
470
|
+
* @param initial The initial value of the buffer. (optional)
|
|
471
|
+
*/
|
|
472
|
+
createBuffer<TData extends AnyData>(typeSchema: ValidateBufferSchema<TData>, initial?: Infer<NoInfer<TData>>): TgpuBuffer<TData>;
|
|
473
|
+
/**
|
|
474
|
+
* Allocates memory on the GPU, allows passing data between host and shader.
|
|
475
|
+
*
|
|
476
|
+
* @remarks
|
|
477
|
+
* Typed wrapper around a GPUBuffer.
|
|
478
|
+
*
|
|
479
|
+
* @param typeSchema The type of data that this buffer will hold.
|
|
480
|
+
* @param gpuBuffer A vanilla WebGPU buffer.
|
|
481
|
+
*/
|
|
482
|
+
createBuffer<TData extends AnyData>(typeSchema: ValidateBufferSchema<TData>, gpuBuffer: GPUBuffer): TgpuBuffer<TData>;
|
|
483
|
+
/**
|
|
484
|
+
* Allocates memory on the GPU, allows passing data between host and shader.
|
|
485
|
+
* Read-only on the GPU, optimized for small data. For a general-purpose buffer,
|
|
486
|
+
* use {@link TgpuRoot.createBuffer}.
|
|
487
|
+
*
|
|
488
|
+
* @param typeSchema The type of data that this buffer will hold.
|
|
489
|
+
* @param initial The initial value of the buffer. (optional)
|
|
490
|
+
*/
|
|
491
|
+
createUniform<TData extends AnyWgslData>(typeSchema: ValidateUniformSchema<TData>, initial?: Infer<NoInfer<TData>>): TgpuUniform<TData>;
|
|
492
|
+
/**
|
|
493
|
+
* Allocates memory on the GPU, allows passing data between host and shader.
|
|
494
|
+
* Read-only on the GPU, optimized for small data. For a general-purpose buffer,
|
|
495
|
+
* use {@link TgpuRoot.createBuffer}.
|
|
496
|
+
*
|
|
497
|
+
* @param typeSchema The type of data that this buffer will hold.
|
|
498
|
+
* @param gpuBuffer A vanilla WebGPU buffer.
|
|
499
|
+
*/
|
|
500
|
+
createUniform<TData extends AnyWgslData>(typeSchema: ValidateUniformSchema<TData>, gpuBuffer: GPUBuffer): TgpuUniform<TData>;
|
|
501
|
+
/**
|
|
502
|
+
* Allocates memory on the GPU, allows passing data between host and shader.
|
|
503
|
+
* Can be mutated in-place on the GPU. For a general-purpose buffer,
|
|
504
|
+
* use {@link TgpuRoot.createBuffer}.
|
|
505
|
+
*
|
|
506
|
+
* @param typeSchema The type of data that this buffer will hold.
|
|
507
|
+
* @param initial The initial value of the buffer. (optional)
|
|
508
|
+
*/
|
|
509
|
+
createMutable<TData extends AnyWgslData>(typeSchema: ValidateStorageSchema<TData>, initial?: Infer<NoInfer<TData>>): TgpuMutable<TData>;
|
|
510
|
+
/**
|
|
511
|
+
* Allocates memory on the GPU, allows passing data between host and shader.
|
|
512
|
+
* Can be mutated in-place on the GPU. For a general-purpose buffer,
|
|
513
|
+
* use {@link TgpuRoot.createBuffer}.
|
|
514
|
+
*
|
|
515
|
+
* @param typeSchema The type of data that this buffer will hold.
|
|
516
|
+
* @param gpuBuffer A vanilla WebGPU buffer.
|
|
517
|
+
*/
|
|
518
|
+
createMutable<TData extends AnyWgslData>(typeSchema: ValidateStorageSchema<TData>, gpuBuffer: GPUBuffer): TgpuMutable<TData>;
|
|
519
|
+
/**
|
|
520
|
+
* Allocates memory on the GPU, allows passing data between host and shader.
|
|
521
|
+
* Read-only on the GPU, optimized for large data. For a general-purpose buffer,
|
|
522
|
+
* use {@link TgpuRoot.createBuffer}.
|
|
523
|
+
*
|
|
524
|
+
* @param typeSchema The type of data that this buffer will hold.
|
|
525
|
+
* @param initial The initial value of the buffer. (optional)
|
|
526
|
+
*/
|
|
527
|
+
createReadonly<TData extends AnyWgslData>(typeSchema: ValidateStorageSchema<TData>, initial?: Infer<NoInfer<TData>>): TgpuReadonly<TData>;
|
|
528
|
+
/**
|
|
529
|
+
* Allocates memory on the GPU, allows passing data between host and shader.
|
|
530
|
+
* Read-only on the GPU, optimized for large data. For a general-purpose buffer,
|
|
531
|
+
* use {@link TgpuRoot.createBuffer}.
|
|
532
|
+
*
|
|
533
|
+
* @param typeSchema The type of data that this buffer will hold.
|
|
534
|
+
* @param gpuBuffer A vanilla WebGPU buffer.
|
|
535
|
+
*/
|
|
536
|
+
createReadonly<TData extends AnyWgslData>(typeSchema: ValidateStorageSchema<TData>, gpuBuffer: GPUBuffer): TgpuReadonly<TData>;
|
|
537
|
+
/**
|
|
538
|
+
* Creates a query set for collecting timestamps or occlusion queries.
|
|
539
|
+
*
|
|
540
|
+
* @remarks
|
|
541
|
+
* Typed wrapper around a GPUQuerySet.
|
|
542
|
+
*
|
|
543
|
+
* @param type The type of queries to collect ('occlusion' or 'timestamp').
|
|
544
|
+
* @param count The number of queries in the set.
|
|
545
|
+
* @param rawQuerySet An optional pre-existing GPUQuerySet to use instead of creating a new one.
|
|
546
|
+
*/
|
|
547
|
+
createQuerySet<T extends GPUQueryType>(type: T, count: number, rawQuerySet?: GPUQuerySet): TgpuQuerySet<T>;
|
|
548
|
+
/**
|
|
549
|
+
* Creates a group of resources that can be bound to a shader based on a specified layout.
|
|
550
|
+
*
|
|
551
|
+
* @remarks
|
|
552
|
+
* Typed wrapper around a GPUBindGroup.
|
|
553
|
+
*
|
|
554
|
+
* @example
|
|
555
|
+
* const fooLayout = tgpu.bindGroupLayout({
|
|
556
|
+
* foo: { uniform: d.vec3f },
|
|
557
|
+
* bar: { texture: 'float' },
|
|
558
|
+
* });
|
|
559
|
+
*
|
|
560
|
+
* const fooBuffer = ...;
|
|
561
|
+
* const barTexture = ...;
|
|
562
|
+
*
|
|
563
|
+
* const fooBindGroup = root.createBindGroup(fooLayout, {
|
|
564
|
+
* foo: fooBuffer,
|
|
565
|
+
* bar: barTexture,
|
|
566
|
+
* });
|
|
567
|
+
*
|
|
568
|
+
* @param layout Layout describing the bind group to be created.
|
|
569
|
+
* @param entries A record with values being the resources populating the bind group
|
|
570
|
+
* and keys being their associated names, matching the layout keys.
|
|
571
|
+
*/
|
|
572
|
+
createBindGroup<Entries extends Record<string, TgpuLayoutEntry | null> = Record<string, TgpuLayoutEntry | null>>(layout: TgpuBindGroupLayout<Entries>, entries: ExtractBindGroupInputFromLayout<Entries>): TgpuBindGroup<Entries>;
|
|
573
|
+
/**
|
|
574
|
+
* Retrieves a read-only list of all enabled features of the GPU device.
|
|
575
|
+
* @returns A set of strings representing the enabled features.
|
|
576
|
+
*/
|
|
577
|
+
get enabledFeatures(): ReadonlySet<GPUFeatureName>;
|
|
578
|
+
/**
|
|
579
|
+
* Destroys all underlying resources (i.e. buffers...) created through this root object.
|
|
580
|
+
* If the object is created via `tgpu.init` instead of `tgpu.initFromDevice`,
|
|
581
|
+
* then the inner GPU device is destroyed as well.
|
|
582
|
+
*/
|
|
583
|
+
destroy(): void;
|
|
584
|
+
'~unstable': Pick<ExperimentalTgpuRoot, 'beginRenderPass' | 'beginRenderBundleEncoder' | 'createComparisonSampler' | 'createGuardedComputePipeline' | 'createSampler' | 'createTexture' | 'flush' | 'nameRegistrySetting' | 'shaderGenerator' | 'pipe' | 'with' | 'withCompute' | 'withVertex'>;
|
|
585
|
+
}
|
|
586
|
+
interface ExperimentalTgpuRoot extends Omit<TgpuRoot, 'with'>, Withable_Deprecated<WithBinding> {
|
|
587
|
+
readonly nameRegistrySetting: 'strict' | 'random';
|
|
588
|
+
readonly shaderGenerator?: ShaderGenerator | undefined;
|
|
589
|
+
createTexture<TWidth extends number, THeight extends number, TDepth extends number, TSize extends readonly [TWidth] | readonly [TWidth, THeight] | readonly [TWidth, THeight, TDepth], TFormat extends GPUTextureFormat, TMipLevelCount extends number, TSampleCount extends number, TViewFormats extends GPUTextureFormat[], TDimension extends GPUTextureDimension>(props: CreateTextureOptions<TSize, TFormat, TMipLevelCount, TSampleCount, TViewFormats, TDimension>): TgpuTexture<CreateTextureResult<TSize, TFormat, TMipLevelCount, TSampleCount, TViewFormats, TDimension>>;
|
|
590
|
+
beginRenderPass(descriptor: GPURenderPassDescriptor, callback: (pass: RenderPass) => void): void;
|
|
591
|
+
/**
|
|
592
|
+
* Creates a {@link GPURenderBundle} by recording draw commands into a
|
|
593
|
+
* {@link GPURenderBundleEncoder}. The resulting bundle can be replayed in a
|
|
594
|
+
* render pass via {@link RenderPass.executeBundles}.
|
|
595
|
+
*
|
|
596
|
+
* The caller is responsible for ensuring that the `descriptor` (e.g.
|
|
597
|
+
* `colorFormats`, `depthStencilFormat`) is compatible with the render pass
|
|
598
|
+
* in which the bundle will be executed.
|
|
599
|
+
*
|
|
600
|
+
* @param descriptor - Describes the formats the bundle must be compatible with.
|
|
601
|
+
* @param callback - A function that records draw commands into the bundle.
|
|
602
|
+
*/
|
|
603
|
+
beginRenderBundleEncoder(descriptor: GPURenderBundleEncoderDescriptor, callback: (pass: RenderBundleEncoderPass) => void): GPURenderBundle;
|
|
604
|
+
createSampler(props: WgslSamplerProps): TgpuFixedSampler;
|
|
605
|
+
createComparisonSampler(props: WgslComparisonSamplerProps): TgpuFixedComparisonSampler;
|
|
606
|
+
/**
|
|
607
|
+
* @deprecated Used to cause all commands enqueued by pipelines to be
|
|
608
|
+
* submitted to the GPU, but now commands are immediately dispatched,
|
|
609
|
+
* which makes this method unnecessary.
|
|
610
|
+
*/
|
|
611
|
+
flush(): void;
|
|
612
|
+
/** @deprecated Use `root.createComputePipeline` instead. */
|
|
613
|
+
withCompute<ComputeIn extends IORecord<AnyComputeBuiltin>>(entryFn: TgpuComputeFn<ComputeIn>): WithCompute;
|
|
614
|
+
/** @deprecated This feature is now stable, use `root.createGuardedComputePipeline`. */
|
|
615
|
+
createGuardedComputePipeline<TArgs extends number[]>(callback: (...args: TArgs) => void): TgpuGuardedComputePipeline<TArgs>;
|
|
616
|
+
/** @deprecated Use `root.createRenderPipeline` instead. */
|
|
617
|
+
withVertex<VertexIn extends TgpuVertexFn.In, VertexOut extends TgpuVertexFn.Out>(entryFn: TgpuVertexFn<VertexIn, VertexOut>, ...args: OptionalArgs<LayoutToAllowedAttribs<OmitBuiltins<VertexIn>>>): WithVertex<VertexOut>;
|
|
618
|
+
/** @deprecated This feature is now stable, use `root.pipe`. */
|
|
619
|
+
pipe(transform: (cfg: Configurable) => Configurable): WithBinding;
|
|
620
|
+
}
|
|
621
|
+
//#endregion
|
|
622
|
+
export { Configurable, ExperimentalTgpuRoot, TgpuGuardedComputePipeline, TgpuRoot, ValidateBufferSchema, ValidateStorageSchema, ValidateUniformSchema, WithBinding, WithCompute, WithFragment, WithVertex, Withable };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { TgpuNamable } from "../../shared/meta.js";
|
|
2
|
+
import { $gpuValueOf, $internal } from "../../shared/symbols.js";
|
|
3
|
+
import { WgslComparisonSampler, WgslSampler } from "../../data/sampler.js";
|
|
4
|
+
import "../../data/snippet.js";
|
|
5
|
+
import "../../unwrapper.js";
|
|
6
|
+
import "../../tgpuBindGroupLayout.js";
|
|
7
|
+
import "../../types.js";
|
|
8
|
+
import { Infer } from "../../shared/repr.js";
|
|
9
|
+
|
|
10
|
+
//#region src/core/sampler/sampler.d.ts
|
|
11
|
+
interface SamplerInternals {
|
|
12
|
+
readonly unwrap?: (() => GPUSampler) | undefined;
|
|
13
|
+
}
|
|
14
|
+
interface TgpuSampler {
|
|
15
|
+
readonly [$internal]: SamplerInternals;
|
|
16
|
+
readonly resourceType: 'sampler';
|
|
17
|
+
readonly schema: WgslSampler;
|
|
18
|
+
readonly [$gpuValueOf]: Infer<WgslSampler>;
|
|
19
|
+
value: Infer<WgslSampler>;
|
|
20
|
+
$: Infer<WgslSampler>;
|
|
21
|
+
}
|
|
22
|
+
interface TgpuComparisonSampler {
|
|
23
|
+
readonly [$internal]: SamplerInternals;
|
|
24
|
+
readonly resourceType: 'sampler-comparison';
|
|
25
|
+
readonly schema: WgslComparisonSampler;
|
|
26
|
+
readonly [$gpuValueOf]: Infer<WgslComparisonSampler>;
|
|
27
|
+
value: Infer<WgslComparisonSampler>;
|
|
28
|
+
$: Infer<WgslComparisonSampler>;
|
|
29
|
+
}
|
|
30
|
+
interface TgpuFixedSampler extends TgpuSampler, TgpuNamable {}
|
|
31
|
+
interface TgpuFixedComparisonSampler extends TgpuComparisonSampler, TgpuNamable {}
|
|
32
|
+
declare function isSampler(resource: unknown): resource is TgpuSampler;
|
|
33
|
+
declare function isComparisonSampler(resource: unknown): resource is TgpuComparisonSampler;
|
|
34
|
+
//#endregion
|
|
35
|
+
export { TgpuComparisonSampler, TgpuFixedComparisonSampler, TgpuFixedSampler, TgpuSampler, isComparisonSampler, isSampler };
|