typegpu 0.10.1 → 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-BagDrrks.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-DdtWpk2t.js +0 -818
- package/builtin-DdtWpk2t.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-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
package/builtin.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { BaseData, Bool, Builtin, Decorated, F32, U32, Vec3u, Vec4f, WgslArray } from "./data/wgslTypes.js";
|
|
2
|
+
|
|
3
|
+
//#region src/builtin.d.ts
|
|
4
|
+
type BuiltinVertexIndex = Decorated<U32, [Builtin<'vertex_index'>]>;
|
|
5
|
+
type BuiltinInstanceIndex = Decorated<U32, [Builtin<'instance_index'>]>;
|
|
6
|
+
type BuiltinClipDistances = Decorated<WgslArray<U32>, [Builtin<'clip_distances'>]>;
|
|
7
|
+
type BuiltinPosition = Decorated<Vec4f, [Builtin<'position'>]>;
|
|
8
|
+
type BuiltinFrontFacing = Decorated<Bool, [Builtin<'front_facing'>]>;
|
|
9
|
+
type BuiltinFragDepth = Decorated<F32, [Builtin<'frag_depth'>]>;
|
|
10
|
+
type BuiltinPrimitiveIndex = Decorated<U32, [Builtin<'primitive_index'>]>;
|
|
11
|
+
type BuiltinSampleIndex = Decorated<U32, [Builtin<'sample_index'>]>;
|
|
12
|
+
type BuiltinSampleMask = Decorated<U32, [Builtin<'sample_mask'>]>;
|
|
13
|
+
type BuiltinLocalInvocationId = Decorated<Vec3u, [Builtin<'local_invocation_id'>]>;
|
|
14
|
+
type BuiltinLocalInvocationIndex = Decorated<U32, [Builtin<'local_invocation_index'>]>;
|
|
15
|
+
type BuiltinGlobalInvocationId = Decorated<Vec3u, [Builtin<'global_invocation_id'>]>;
|
|
16
|
+
type BuiltinWorkgroupId = Decorated<Vec3u, [Builtin<'workgroup_id'>]>;
|
|
17
|
+
type BuiltinNumWorkgroups = Decorated<Vec3u, [Builtin<'num_workgroups'>]>;
|
|
18
|
+
type BuiltinSubgroupInvocationId = Decorated<U32, [Builtin<'subgroup_invocation_id'>]>;
|
|
19
|
+
type BuiltinSubgroupSize = Decorated<U32, [Builtin<'subgroup_size'>]>;
|
|
20
|
+
type BuiltinSubgroupId = Decorated<U32, [Builtin<'subgroup_id'>]>;
|
|
21
|
+
type BuiltinNumSubgroups = Decorated<U32, [Builtin<'num_subgroups'>]>;
|
|
22
|
+
declare const builtin: {
|
|
23
|
+
readonly vertexIndex: BuiltinVertexIndex;
|
|
24
|
+
readonly instanceIndex: BuiltinInstanceIndex;
|
|
25
|
+
readonly clipDistances: BuiltinClipDistances;
|
|
26
|
+
readonly position: BuiltinPosition;
|
|
27
|
+
readonly frontFacing: BuiltinFrontFacing;
|
|
28
|
+
readonly fragDepth: BuiltinFragDepth;
|
|
29
|
+
readonly primitiveIndex: BuiltinPrimitiveIndex;
|
|
30
|
+
readonly sampleIndex: BuiltinSampleIndex;
|
|
31
|
+
readonly sampleMask: BuiltinSampleMask;
|
|
32
|
+
readonly localInvocationId: BuiltinLocalInvocationId;
|
|
33
|
+
readonly localInvocationIndex: BuiltinLocalInvocationIndex;
|
|
34
|
+
readonly globalInvocationId: BuiltinGlobalInvocationId;
|
|
35
|
+
readonly workgroupId: BuiltinWorkgroupId;
|
|
36
|
+
readonly numWorkgroups: BuiltinNumWorkgroups;
|
|
37
|
+
readonly subgroupInvocationId: BuiltinSubgroupInvocationId;
|
|
38
|
+
readonly subgroupSize: BuiltinSubgroupSize;
|
|
39
|
+
readonly subgroupId: BuiltinSubgroupId;
|
|
40
|
+
readonly numSubgroups: BuiltinNumSubgroups;
|
|
41
|
+
};
|
|
42
|
+
type AnyBuiltin = (typeof builtin)[keyof typeof builtin];
|
|
43
|
+
type AnyComputeBuiltin = BuiltinLocalInvocationId | BuiltinLocalInvocationIndex | BuiltinGlobalInvocationId | BuiltinWorkgroupId | BuiltinNumWorkgroups | BuiltinSubgroupInvocationId | BuiltinSubgroupSize | BuiltinSubgroupId | BuiltinNumSubgroups;
|
|
44
|
+
type AnyVertexInputBuiltin = BuiltinVertexIndex | BuiltinInstanceIndex;
|
|
45
|
+
type AnyVertexOutputBuiltin = BuiltinClipDistances | BuiltinPosition;
|
|
46
|
+
type AnyFragmentInputBuiltin = BuiltinPosition | BuiltinFrontFacing | BuiltinPrimitiveIndex | BuiltinSampleIndex | BuiltinSampleMask | BuiltinSubgroupInvocationId | BuiltinSubgroupSize;
|
|
47
|
+
type AnyFragmentOutputBuiltin = BuiltinFragDepth | BuiltinSampleMask;
|
|
48
|
+
type OmitBuiltins<S> = S extends AnyBuiltin ? never : S extends BaseData ? S : { [Key in keyof S as S[Key] extends AnyBuiltin ? never : Key extends `$${string}` ? never : Key]: S[Key] };
|
|
49
|
+
//#endregion
|
|
50
|
+
export { AnyBuiltin, AnyComputeBuiltin, AnyFragmentInputBuiltin, AnyFragmentOutputBuiltin, AnyVertexInputBuiltin, AnyVertexOutputBuiltin, BuiltinClipDistances, BuiltinFragDepth, BuiltinFrontFacing, BuiltinGlobalInvocationId, BuiltinInstanceIndex, BuiltinLocalInvocationId, BuiltinLocalInvocationIndex, BuiltinNumWorkgroups, BuiltinPosition, BuiltinPrimitiveIndex, BuiltinSampleIndex, BuiltinSampleMask, BuiltinSubgroupInvocationId, BuiltinSubgroupSize, BuiltinVertexIndex, BuiltinWorkgroupId, OmitBuiltins, builtin };
|
package/builtin.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { $internal } from "./shared/symbols.js";
|
|
2
|
+
import { bool, f32, u32 } from "./data/numeric.js";
|
|
3
|
+
import { vec3u, vec4f } from "./data/vector.js";
|
|
4
|
+
import { attribute } from "./data/attributes.js";
|
|
5
|
+
import { arrayOf } from "./data/array.js";
|
|
6
|
+
|
|
7
|
+
//#region src/builtin.ts
|
|
8
|
+
function defineBuiltin(dataType, value) {
|
|
9
|
+
return attribute(dataType, {
|
|
10
|
+
[$internal]: true,
|
|
11
|
+
type: "@builtin",
|
|
12
|
+
params: [value]
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
const builtin = {
|
|
16
|
+
vertexIndex: defineBuiltin(u32, "vertex_index"),
|
|
17
|
+
instanceIndex: defineBuiltin(u32, "instance_index"),
|
|
18
|
+
clipDistances: defineBuiltin(arrayOf(u32, 8), "clip_distances"),
|
|
19
|
+
position: defineBuiltin(vec4f, "position"),
|
|
20
|
+
frontFacing: defineBuiltin(bool, "front_facing"),
|
|
21
|
+
fragDepth: defineBuiltin(f32, "frag_depth"),
|
|
22
|
+
primitiveIndex: defineBuiltin(u32, "primitive_index"),
|
|
23
|
+
sampleIndex: defineBuiltin(u32, "sample_index"),
|
|
24
|
+
sampleMask: defineBuiltin(u32, "sample_mask"),
|
|
25
|
+
localInvocationId: defineBuiltin(vec3u, "local_invocation_id"),
|
|
26
|
+
localInvocationIndex: defineBuiltin(u32, "local_invocation_index"),
|
|
27
|
+
globalInvocationId: defineBuiltin(vec3u, "global_invocation_id"),
|
|
28
|
+
workgroupId: defineBuiltin(vec3u, "workgroup_id"),
|
|
29
|
+
numWorkgroups: defineBuiltin(vec3u, "num_workgroups"),
|
|
30
|
+
subgroupInvocationId: defineBuiltin(u32, "subgroup_invocation_id"),
|
|
31
|
+
subgroupSize: defineBuiltin(u32, "subgroup_size"),
|
|
32
|
+
subgroupId: defineBuiltin(u32, "subgroup_id"),
|
|
33
|
+
numSubgroups: defineBuiltin(u32, "num_subgroups")
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
export { builtin };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { TgpuVertexFn } from "../core/function/tgpuVertexFn.js";
|
|
2
|
+
import { Vec2f } from "../data/wgslTypes.js";
|
|
3
|
+
import "../indexNamedExports.js";
|
|
4
|
+
|
|
5
|
+
//#region src/common/fullScreenTriangle.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* A vertex function that defines a single full-screen triangle out
|
|
8
|
+
* of three points.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { common } from 'typegpu';
|
|
13
|
+
*
|
|
14
|
+
* const pipeline = root.createRenderPipeline({
|
|
15
|
+
* vertex: common.fullScreenTriangle,
|
|
16
|
+
* fragment: yourFragmentShader,
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* pipeline.draw(3);
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
declare const fullScreenTriangle: TgpuVertexFn<{}, {
|
|
23
|
+
uv: Vec2f;
|
|
24
|
+
}>;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { fullScreenTriangle };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { vec2f } from "../data/vector.js";
|
|
2
|
+
import { builtin } from "../builtin.js";
|
|
3
|
+
import { vertexFn } from "../core/function/tgpuVertexFn.js";
|
|
4
|
+
|
|
5
|
+
//#region src/common/fullScreenTriangle.ts
|
|
6
|
+
/**
|
|
7
|
+
* A vertex function that defines a single full-screen triangle out
|
|
8
|
+
* of three points.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { common } from 'typegpu';
|
|
13
|
+
*
|
|
14
|
+
* const pipeline = root.createRenderPipeline({
|
|
15
|
+
* vertex: common.fullScreenTriangle,
|
|
16
|
+
* fragment: yourFragmentShader,
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* pipeline.draw(3);
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
const fullScreenTriangle = vertexFn({
|
|
23
|
+
in: { vertexIndex: builtin.vertexIndex },
|
|
24
|
+
out: {
|
|
25
|
+
pos: builtin.position,
|
|
26
|
+
uv: vec2f
|
|
27
|
+
}
|
|
28
|
+
})`{
|
|
29
|
+
const pos = array<vec2f, 3>(vec2f(-1, -1), vec2f(3, -1), vec2f(-1, 3));
|
|
30
|
+
const uv = array<vec2f, 3>(vec2f(0, 1), vec2f(2, 1), vec2f(0, -1));
|
|
31
|
+
|
|
32
|
+
return Out(vec4f(pos[in.vertexIndex], 0, 1), uv[in.vertexIndex]);
|
|
33
|
+
}`;
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
export { fullScreenTriangle };
|
package/common/index.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { fullScreenTriangle } from "./fullScreenTriangle.js";
|
|
2
2
|
|
|
3
3
|
//#region src/common/index.d.ts
|
|
4
4
|
declare namespace index_d_exports {
|
|
5
5
|
export { fullScreenTriangle };
|
|
6
6
|
}
|
|
7
7
|
//#endregion
|
|
8
|
-
export { fullScreenTriangle, index_d_exports
|
|
9
|
-
//# sourceMappingURL=index.d.ts.map
|
|
8
|
+
export { fullScreenTriangle, index_d_exports };
|
package/common/index.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { fullScreenTriangle } from "./fullScreenTriangle.js";
|
|
3
3
|
|
|
4
4
|
//#region src/common/index.ts
|
|
5
5
|
var common_exports = /* @__PURE__ */ __exportAll({ fullScreenTriangle: () => fullScreenTriangle });
|
|
6
6
|
|
|
7
7
|
//#endregion
|
|
8
|
-
export {
|
|
9
|
-
//# sourceMappingURL=index.js.map
|
|
8
|
+
export { common_exports, fullScreenTriangle };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { TgpuNamable } from "../../shared/meta.js";
|
|
2
|
+
import { $internal } from "../../shared/symbols.js";
|
|
3
|
+
import { Prettify, UnionToIntersection } from "../../shared/utilityTypes.js";
|
|
4
|
+
import { StorageFlag } from "../../extension.js";
|
|
5
|
+
import { TgpuBufferMutable, TgpuBufferReadonly, TgpuBufferUniform, TgpuFixedBufferUsage } from "./bufferUsage.js";
|
|
6
|
+
import "../root/rootTypes.js";
|
|
7
|
+
import { BaseData } from "../../data/wgslTypes.js";
|
|
8
|
+
import { Infer, InferPartial, IsValidIndexSchema, IsValidStorageSchema, IsValidUniformSchema, IsValidVertexSchema, MemIdentity } from "../../shared/repr.js";
|
|
9
|
+
import "../../data/dataTypes.js";
|
|
10
|
+
|
|
11
|
+
//#region src/core/buffer/buffer.d.ts
|
|
12
|
+
interface UniformFlag {
|
|
13
|
+
usableAsUniform: true;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated Use UniformFlag instead.
|
|
17
|
+
*/
|
|
18
|
+
type Uniform = UniformFlag;
|
|
19
|
+
interface VertexFlag {
|
|
20
|
+
usableAsVertex: true;
|
|
21
|
+
}
|
|
22
|
+
interface IndexFlag {
|
|
23
|
+
usableAsIndex: true;
|
|
24
|
+
}
|
|
25
|
+
interface IndirectFlag {
|
|
26
|
+
usableAsIndirect: true;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* @deprecated Use VertexFlag instead.
|
|
30
|
+
*/
|
|
31
|
+
type Vertex = VertexFlag;
|
|
32
|
+
type UsageLiteral = 'uniform' | 'storage' | 'vertex' | 'index' | 'indirect';
|
|
33
|
+
type LiteralToUsageType<T extends UsageLiteral> = T extends 'uniform' ? UniformFlag : T extends 'storage' ? StorageFlag : T extends 'vertex' ? VertexFlag : T extends 'index' ? IndexFlag : T extends 'indirect' ? IndirectFlag : never;
|
|
34
|
+
type ViewUsages<TBuffer extends TgpuBuffer<BaseData>> = (boolean extends TBuffer['usableAsUniform'] ? never : 'uniform') | (boolean extends TBuffer['usableAsStorage'] ? never : 'readonly' | 'mutable');
|
|
35
|
+
type UsageTypeToBufferUsage<TData extends BaseData> = {
|
|
36
|
+
uniform: TgpuBufferUniform<TData> & TgpuFixedBufferUsage<TData>;
|
|
37
|
+
mutable: TgpuBufferMutable<TData> & TgpuFixedBufferUsage<TData>;
|
|
38
|
+
readonly: TgpuBufferReadonly<TData> & TgpuFixedBufferUsage<TData>;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Done as an object to later Prettify it
|
|
42
|
+
*/
|
|
43
|
+
type InnerValidUsagesFor<T> = {
|
|
44
|
+
usage: (IsValidStorageSchema<T> extends true ? 'storage' : never) | (IsValidUniformSchema<T> extends true ? 'uniform' : never) | (IsValidVertexSchema<T> extends true ? 'vertex' : never) | (IsValidIndexSchema<T> extends true ? 'index' : never) | 'indirect';
|
|
45
|
+
};
|
|
46
|
+
type ValidUsagesFor<T> = InnerValidUsagesFor<T>['usage'];
|
|
47
|
+
interface TgpuBuffer<TData extends BaseData> extends TgpuNamable {
|
|
48
|
+
readonly [$internal]: true;
|
|
49
|
+
readonly resourceType: 'buffer';
|
|
50
|
+
readonly dataType: TData;
|
|
51
|
+
readonly initial?: Infer<TData> | undefined;
|
|
52
|
+
readonly buffer: GPUBuffer;
|
|
53
|
+
readonly destroyed: boolean;
|
|
54
|
+
usableAsUniform: boolean;
|
|
55
|
+
usableAsStorage: boolean;
|
|
56
|
+
usableAsVertex: boolean;
|
|
57
|
+
usableAsIndex: boolean;
|
|
58
|
+
usableAsIndirect: boolean;
|
|
59
|
+
$usage<T extends [Prettify<InnerValidUsagesFor<TData>>['usage'], ...Prettify<InnerValidUsagesFor<TData>>['usage'][]]>(...usages: T): this & UnionToIntersection<LiteralToUsageType<T[number]>>;
|
|
60
|
+
$addFlags(flags: GPUBufferUsageFlags): this;
|
|
61
|
+
as<T extends ViewUsages<this>>(usage: T): UsageTypeToBufferUsage<TData>[T];
|
|
62
|
+
compileWriter(): void;
|
|
63
|
+
write(data: Infer<TData>): void;
|
|
64
|
+
writePartial(data: InferPartial<TData>): void;
|
|
65
|
+
clear(): void;
|
|
66
|
+
copyFrom(srcBuffer: TgpuBuffer<MemIdentity<TData>>): void;
|
|
67
|
+
read(): Promise<Infer<TData>>;
|
|
68
|
+
destroy(): void;
|
|
69
|
+
toString(): string;
|
|
70
|
+
}
|
|
71
|
+
declare function isBuffer(value: unknown): value is TgpuBuffer<BaseData>;
|
|
72
|
+
declare function isUsableAsVertex<T extends TgpuBuffer<BaseData>>(buffer: T): buffer is T & VertexFlag;
|
|
73
|
+
//#endregion
|
|
74
|
+
export { IndexFlag, IndirectFlag, TgpuBuffer, Uniform, UniformFlag, ValidUsagesFor, Vertex, VertexFlag, isBuffer, isUsableAsVertex };
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { $internal } from "../../shared/symbols.js";
|
|
2
|
+
import { getName, setName } from "../../shared/meta.js";
|
|
3
|
+
import { isWgslData } from "../../data/wgslTypes.js";
|
|
4
|
+
import { isGPUBuffer } from "../../types.js";
|
|
5
|
+
import { sizeOf } from "../../data/sizeOf.js";
|
|
6
|
+
import { getCompiledWriterForSchema } from "../../data/compiledIO.js";
|
|
7
|
+
import { readData, writeData } from "../../data/dataIO.js";
|
|
8
|
+
import { getWriteInstructions } from "../../data/partialIO.js";
|
|
9
|
+
import { mutable, readonly, uniform } from "./bufferUsage.js";
|
|
10
|
+
import { BufferReader, BufferWriter, getSystemEndianness } from "typed-binary";
|
|
11
|
+
|
|
12
|
+
//#region src/core/buffer/buffer.ts
|
|
13
|
+
const usageToUsageConstructor = {
|
|
14
|
+
uniform,
|
|
15
|
+
mutable,
|
|
16
|
+
readonly
|
|
17
|
+
};
|
|
18
|
+
function INTERNAL_createBuffer(group, typeSchema, initialOrBuffer) {
|
|
19
|
+
if (!isWgslData(typeSchema)) return new TgpuBufferImpl(group, typeSchema, initialOrBuffer, ["storage", "uniform"]);
|
|
20
|
+
return new TgpuBufferImpl(group, typeSchema, initialOrBuffer);
|
|
21
|
+
}
|
|
22
|
+
function isBuffer(value) {
|
|
23
|
+
return value.resourceType === "buffer";
|
|
24
|
+
}
|
|
25
|
+
function isUsableAsVertex(buffer) {
|
|
26
|
+
return !!buffer.usableAsVertex;
|
|
27
|
+
}
|
|
28
|
+
const endianness = getSystemEndianness();
|
|
29
|
+
var TgpuBufferImpl = class {
|
|
30
|
+
[$internal] = true;
|
|
31
|
+
resourceType = "buffer";
|
|
32
|
+
flags = GPUBufferUsage.COPY_DST | GPUBufferUsage.COPY_SRC;
|
|
33
|
+
#device;
|
|
34
|
+
_buffer = null;
|
|
35
|
+
_ownBuffer;
|
|
36
|
+
_destroyed = false;
|
|
37
|
+
_hostBuffer;
|
|
38
|
+
initial;
|
|
39
|
+
usableAsUniform = false;
|
|
40
|
+
usableAsStorage = false;
|
|
41
|
+
usableAsVertex = false;
|
|
42
|
+
usableAsIndex = false;
|
|
43
|
+
usableAsIndirect = false;
|
|
44
|
+
constructor(root, dataType, initialOrBuffer, _disallowedUsages) {
|
|
45
|
+
this.dataType = dataType;
|
|
46
|
+
this.initialOrBuffer = initialOrBuffer;
|
|
47
|
+
this._disallowedUsages = _disallowedUsages;
|
|
48
|
+
this.#device = root.device;
|
|
49
|
+
if (isGPUBuffer(initialOrBuffer)) {
|
|
50
|
+
this._ownBuffer = false;
|
|
51
|
+
this._buffer = initialOrBuffer;
|
|
52
|
+
} else {
|
|
53
|
+
this._ownBuffer = true;
|
|
54
|
+
this.initial = initialOrBuffer;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
get buffer() {
|
|
58
|
+
if (this._destroyed) throw new Error("This buffer has been destroyed");
|
|
59
|
+
if (!this._buffer) {
|
|
60
|
+
this._buffer = this.#device.createBuffer({
|
|
61
|
+
size: sizeOf(this.dataType),
|
|
62
|
+
usage: this.flags,
|
|
63
|
+
mappedAtCreation: !!this.initial,
|
|
64
|
+
label: getName(this) ?? "<unnamed>"
|
|
65
|
+
});
|
|
66
|
+
if (this.initial) {
|
|
67
|
+
this._writeToTarget(this._buffer.getMappedRange(), this.initial);
|
|
68
|
+
this._buffer.unmap();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return this._buffer;
|
|
72
|
+
}
|
|
73
|
+
get destroyed() {
|
|
74
|
+
return this._destroyed;
|
|
75
|
+
}
|
|
76
|
+
$name(label) {
|
|
77
|
+
setName(this, label);
|
|
78
|
+
if (this._buffer) this._buffer.label = label;
|
|
79
|
+
return this;
|
|
80
|
+
}
|
|
81
|
+
$usage(...usages) {
|
|
82
|
+
for (const usage of usages) {
|
|
83
|
+
if (this._disallowedUsages?.includes(usage)) throw new Error(`Buffer of type ${this.dataType.type} cannot be used as ${usage}`);
|
|
84
|
+
this.flags |= usage === "uniform" ? GPUBufferUsage.UNIFORM : 0;
|
|
85
|
+
this.flags |= usage === "storage" ? GPUBufferUsage.STORAGE : 0;
|
|
86
|
+
this.flags |= usage === "vertex" ? GPUBufferUsage.VERTEX : 0;
|
|
87
|
+
this.flags |= usage === "index" ? GPUBufferUsage.INDEX : 0;
|
|
88
|
+
this.flags |= usage === "indirect" ? GPUBufferUsage.INDIRECT : 0;
|
|
89
|
+
this.usableAsUniform = this.usableAsUniform || usage === "uniform";
|
|
90
|
+
this.usableAsStorage = this.usableAsStorage || usage === "storage";
|
|
91
|
+
this.usableAsVertex = this.usableAsVertex || usage === "vertex";
|
|
92
|
+
this.usableAsIndex = this.usableAsIndex || usage === "index";
|
|
93
|
+
this.usableAsIndirect = this.usableAsIndirect || usage === "indirect";
|
|
94
|
+
}
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
$addFlags(flags) {
|
|
98
|
+
if (!this._ownBuffer) throw new Error("Cannot add flags to a buffer that is not managed by TypeGPU.");
|
|
99
|
+
if (flags & GPUBufferUsage.MAP_READ) {
|
|
100
|
+
this.flags = GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ;
|
|
101
|
+
return this;
|
|
102
|
+
}
|
|
103
|
+
if (flags & GPUBufferUsage.MAP_WRITE) {
|
|
104
|
+
this.flags = GPUBufferUsage.COPY_SRC | GPUBufferUsage.MAP_WRITE;
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
this.flags |= flags;
|
|
108
|
+
return this;
|
|
109
|
+
}
|
|
110
|
+
compileWriter() {
|
|
111
|
+
getCompiledWriterForSchema(this.dataType);
|
|
112
|
+
}
|
|
113
|
+
_writeToTarget(target, data) {
|
|
114
|
+
const compiledWriter = getCompiledWriterForSchema(this.dataType);
|
|
115
|
+
if (compiledWriter) try {
|
|
116
|
+
compiledWriter(new DataView(target), 0, data, endianness === "little");
|
|
117
|
+
return;
|
|
118
|
+
} catch (error) {
|
|
119
|
+
console.error(`Error when using compiled writer for buffer ${getName(this) ?? "<unnamed>"} - this is likely a bug, please submit an issue at https://github.com/software-mansion/TypeGPU/issues\nUsing fallback writer instead.`, error);
|
|
120
|
+
}
|
|
121
|
+
writeData(new BufferWriter(target), this.dataType, data);
|
|
122
|
+
}
|
|
123
|
+
write(data) {
|
|
124
|
+
const gpuBuffer = this.buffer;
|
|
125
|
+
if (gpuBuffer.mapState === "mapped") {
|
|
126
|
+
const mapped = gpuBuffer.getMappedRange();
|
|
127
|
+
this._writeToTarget(mapped, data);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
const size = sizeOf(this.dataType);
|
|
131
|
+
if (!this._hostBuffer) this._hostBuffer = new ArrayBuffer(size);
|
|
132
|
+
this._writeToTarget(this._hostBuffer, data);
|
|
133
|
+
this.#device.queue.writeBuffer(gpuBuffer, 0, this._hostBuffer, 0, size);
|
|
134
|
+
}
|
|
135
|
+
writePartial(data) {
|
|
136
|
+
const gpuBuffer = this.buffer;
|
|
137
|
+
const instructions = getWriteInstructions(this.dataType, data);
|
|
138
|
+
if (gpuBuffer.mapState === "mapped") {
|
|
139
|
+
const mappedRange = gpuBuffer.getMappedRange();
|
|
140
|
+
const mappedView = new Uint8Array(mappedRange);
|
|
141
|
+
for (const instruction of instructions) mappedView.set(instruction.data, instruction.data.byteOffset);
|
|
142
|
+
} else for (const instruction of instructions) this.#device.queue.writeBuffer(gpuBuffer, instruction.data.byteOffset, instruction.data, 0, instruction.data.byteLength);
|
|
143
|
+
}
|
|
144
|
+
clear() {
|
|
145
|
+
const gpuBuffer = this.buffer;
|
|
146
|
+
if (gpuBuffer.mapState === "mapped") {
|
|
147
|
+
new Uint8Array(gpuBuffer.getMappedRange()).fill(0);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const encoder = this.#device.createCommandEncoder();
|
|
151
|
+
encoder.clearBuffer(gpuBuffer);
|
|
152
|
+
this.#device.queue.submit([encoder.finish()]);
|
|
153
|
+
}
|
|
154
|
+
copyFrom(srcBuffer) {
|
|
155
|
+
if (this.buffer.mapState === "mapped") throw new Error("Cannot copy to a mapped buffer.");
|
|
156
|
+
const size = sizeOf(this.dataType);
|
|
157
|
+
const encoder = this.#device.createCommandEncoder();
|
|
158
|
+
encoder.copyBufferToBuffer(srcBuffer.buffer, 0, this.buffer, 0, size);
|
|
159
|
+
this.#device.queue.submit([encoder.finish()]);
|
|
160
|
+
}
|
|
161
|
+
async read() {
|
|
162
|
+
const gpuBuffer = this.buffer;
|
|
163
|
+
if (gpuBuffer.mapState === "mapped") return readData(new BufferReader(gpuBuffer.getMappedRange()), this.dataType);
|
|
164
|
+
if (gpuBuffer.usage & GPUBufferUsage.MAP_READ) {
|
|
165
|
+
await gpuBuffer.mapAsync(GPUMapMode.READ);
|
|
166
|
+
const res = readData(new BufferReader(gpuBuffer.getMappedRange()), this.dataType);
|
|
167
|
+
gpuBuffer.unmap();
|
|
168
|
+
return res;
|
|
169
|
+
}
|
|
170
|
+
const stagingBuffer = this.#device.createBuffer({
|
|
171
|
+
size: sizeOf(this.dataType),
|
|
172
|
+
usage: GPUBufferUsage.COPY_DST | GPUBufferUsage.MAP_READ
|
|
173
|
+
});
|
|
174
|
+
const commandEncoder = this.#device.createCommandEncoder();
|
|
175
|
+
commandEncoder.copyBufferToBuffer(gpuBuffer, 0, stagingBuffer, 0, sizeOf(this.dataType));
|
|
176
|
+
this.#device.queue.submit([commandEncoder.finish()]);
|
|
177
|
+
await stagingBuffer.mapAsync(GPUMapMode.READ, 0, sizeOf(this.dataType));
|
|
178
|
+
const res = readData(new BufferReader(stagingBuffer.getMappedRange()), this.dataType);
|
|
179
|
+
stagingBuffer.unmap();
|
|
180
|
+
stagingBuffer.destroy();
|
|
181
|
+
return res;
|
|
182
|
+
}
|
|
183
|
+
as(usage) {
|
|
184
|
+
return usageToUsageConstructor[usage]?.(this);
|
|
185
|
+
}
|
|
186
|
+
destroy() {
|
|
187
|
+
if (this._destroyed) return;
|
|
188
|
+
this._destroyed = true;
|
|
189
|
+
if (this._ownBuffer) this._buffer?.destroy();
|
|
190
|
+
}
|
|
191
|
+
toString() {
|
|
192
|
+
return `buffer:${getName(this) ?? "<unnamed>"}`;
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
//#endregion
|
|
197
|
+
export { INTERNAL_createBuffer, isBuffer, isUsableAsVertex };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { TgpuNamable } from "../../shared/meta.js";
|
|
2
|
+
import { $gpuValueOf, $internal } from "../../shared/symbols.js";
|
|
3
|
+
import { StorageFlag } from "../../extension.js";
|
|
4
|
+
import "../../data/snippet.js";
|
|
5
|
+
import { TgpuBuffer, UniformFlag } from "./buffer.js";
|
|
6
|
+
import "../../types.js";
|
|
7
|
+
import { BaseData } from "../../data/wgslTypes.js";
|
|
8
|
+
import { Infer, InferGPU, InferPartial } from "../../shared/repr.js";
|
|
9
|
+
|
|
10
|
+
//#region src/core/buffer/bufferShorthand.d.ts
|
|
11
|
+
interface TgpuBufferShorthandBase<TData extends BaseData> extends TgpuNamable {
|
|
12
|
+
readonly [$internal]: true;
|
|
13
|
+
write(data: Infer<TData>): void;
|
|
14
|
+
writePartial(data: InferPartial<TData>): void;
|
|
15
|
+
read(): Promise<Infer<TData>>;
|
|
16
|
+
readonly [$gpuValueOf]: InferGPU<TData>;
|
|
17
|
+
}
|
|
18
|
+
interface TgpuMutable<out TData extends BaseData> extends TgpuBufferShorthandBase<TData> {
|
|
19
|
+
readonly resourceType: 'mutable';
|
|
20
|
+
readonly buffer: TgpuBuffer<TData> & StorageFlag;
|
|
21
|
+
/**
|
|
22
|
+
* @deprecated Use `.$` instead, works the same way.
|
|
23
|
+
*/
|
|
24
|
+
value: InferGPU<TData>;
|
|
25
|
+
$: InferGPU<TData>;
|
|
26
|
+
}
|
|
27
|
+
interface TgpuReadonly<out TData extends BaseData> extends TgpuBufferShorthandBase<TData> {
|
|
28
|
+
readonly resourceType: 'readonly';
|
|
29
|
+
readonly buffer: TgpuBuffer<TData> & StorageFlag;
|
|
30
|
+
/**
|
|
31
|
+
* @deprecated Use `.$` instead, works the same way.
|
|
32
|
+
*/
|
|
33
|
+
readonly value: InferGPU<TData>;
|
|
34
|
+
readonly $: InferGPU<TData>;
|
|
35
|
+
}
|
|
36
|
+
interface TgpuUniform<out TData extends BaseData> extends TgpuBufferShorthandBase<TData> {
|
|
37
|
+
readonly resourceType: 'uniform';
|
|
38
|
+
readonly buffer: TgpuBuffer<TData> & UniformFlag;
|
|
39
|
+
/**
|
|
40
|
+
* @deprecated Use `.$` instead, works the same way.
|
|
41
|
+
*/
|
|
42
|
+
readonly value: InferGPU<TData>;
|
|
43
|
+
readonly $: InferGPU<TData>;
|
|
44
|
+
}
|
|
45
|
+
type TgpuBufferShorthand<TData extends BaseData> = TgpuMutable<TData> | TgpuReadonly<TData> | TgpuUniform<TData>;
|
|
46
|
+
declare function isBufferShorthand<TData extends BaseData>(value: unknown): value is TgpuBufferShorthand<TData>;
|
|
47
|
+
//#endregion
|
|
48
|
+
export { TgpuBufferShorthand, TgpuMutable, TgpuReadonly, TgpuUniform, isBufferShorthand };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { $getNameForward, $gpuValueOf, $internal, $resolve } from "../../shared/symbols.js";
|
|
2
|
+
import { getName, setName } from "../../shared/meta.js";
|
|
3
|
+
|
|
4
|
+
//#region src/core/buffer/bufferShorthand.ts
|
|
5
|
+
function isBufferShorthand(value) {
|
|
6
|
+
return value instanceof TgpuBufferShorthandImpl;
|
|
7
|
+
}
|
|
8
|
+
var TgpuBufferShorthandImpl = class {
|
|
9
|
+
[$internal] = true;
|
|
10
|
+
[$getNameForward];
|
|
11
|
+
#usage;
|
|
12
|
+
constructor(resourceType, buffer) {
|
|
13
|
+
this.resourceType = resourceType;
|
|
14
|
+
this.buffer = buffer;
|
|
15
|
+
this[$getNameForward] = buffer;
|
|
16
|
+
this.#usage = this.buffer.as(this.resourceType);
|
|
17
|
+
}
|
|
18
|
+
$name(label) {
|
|
19
|
+
setName(this, label);
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
write(data) {
|
|
23
|
+
this.buffer.write(data);
|
|
24
|
+
}
|
|
25
|
+
writePartial(data) {
|
|
26
|
+
this.buffer.writePartial(data);
|
|
27
|
+
}
|
|
28
|
+
read() {
|
|
29
|
+
return this.buffer.read();
|
|
30
|
+
}
|
|
31
|
+
get [$gpuValueOf]() {
|
|
32
|
+
return this.#usage.$;
|
|
33
|
+
}
|
|
34
|
+
get $() {
|
|
35
|
+
return this.#usage.$;
|
|
36
|
+
}
|
|
37
|
+
get value() {
|
|
38
|
+
return this.$;
|
|
39
|
+
}
|
|
40
|
+
toString() {
|
|
41
|
+
return `${this.resourceType}BufferShorthand:${getName(this) ?? "<unnamed>"}`;
|
|
42
|
+
}
|
|
43
|
+
[$resolve](ctx) {
|
|
44
|
+
return ctx.resolve(this.#usage);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
export { TgpuBufferShorthandImpl, isBufferShorthand };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { TgpuNamable } from "../../shared/meta.js";
|
|
2
|
+
import { $gpuValueOf, $internal, $repr } from "../../shared/symbols.js";
|
|
3
|
+
import "../../data/snippet.js";
|
|
4
|
+
import "../../tgpuBindGroupLayout.js";
|
|
5
|
+
import { TgpuBuffer, UniformFlag } from "./buffer.js";
|
|
6
|
+
import { BindableBufferUsage } from "../../types.js";
|
|
7
|
+
import { BaseData } from "../../data/wgslTypes.js";
|
|
8
|
+
import { Infer, InferGPU } from "../../shared/repr.js";
|
|
9
|
+
|
|
10
|
+
//#region src/core/buffer/bufferUsage.d.ts
|
|
11
|
+
interface TgpuBufferUsage<TData extends BaseData = BaseData, TUsage extends BindableBufferUsage = BindableBufferUsage> {
|
|
12
|
+
readonly resourceType: 'buffer-usage';
|
|
13
|
+
readonly usage: TUsage;
|
|
14
|
+
readonly [$repr]: Infer<TData>;
|
|
15
|
+
readonly [$gpuValueOf]: InferGPU<TData>;
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated Use `.$` instead, works the same way.
|
|
18
|
+
*/
|
|
19
|
+
value: InferGPU<TData>;
|
|
20
|
+
$: InferGPU<TData>;
|
|
21
|
+
readonly [$internal]: {
|
|
22
|
+
readonly dataType: TData;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
interface TgpuBufferUniform<TData extends BaseData> extends TgpuBufferUsage<TData, 'uniform'> {
|
|
26
|
+
/**
|
|
27
|
+
* @deprecated Use `.$` instead, works the same way.
|
|
28
|
+
*/
|
|
29
|
+
readonly value: InferGPU<TData>;
|
|
30
|
+
readonly $: InferGPU<TData>;
|
|
31
|
+
}
|
|
32
|
+
interface TgpuBufferReadonly<TData extends BaseData> extends TgpuBufferUsage<TData, 'readonly'> {
|
|
33
|
+
/**
|
|
34
|
+
* @deprecated Use `.$` instead, works the same way.
|
|
35
|
+
*/
|
|
36
|
+
readonly value: InferGPU<TData>;
|
|
37
|
+
readonly $: InferGPU<TData>;
|
|
38
|
+
}
|
|
39
|
+
interface TgpuFixedBufferUsage<TData extends BaseData> extends TgpuNamable {
|
|
40
|
+
readonly buffer: TgpuBuffer<TData>;
|
|
41
|
+
}
|
|
42
|
+
interface TgpuBufferMutable<TData extends BaseData> extends TgpuBufferUsage<TData, 'mutable'> {}
|
|
43
|
+
declare function isUsableAsUniform<T extends TgpuBuffer<BaseData>>(buffer: T): buffer is T & UniformFlag;
|
|
44
|
+
//#endregion
|
|
45
|
+
export { TgpuBufferMutable, TgpuBufferReadonly, TgpuBufferUniform, TgpuBufferUsage, TgpuFixedBufferUsage, isUsableAsUniform };
|