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
package/std/boolean.d.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { DualFn } from "../types.js";
|
|
2
|
+
import { AnyBooleanVecInstance, AnyFloatVecInstance, AnyNumericVecInstance, AnyVec2Instance, AnyVec3Instance, AnyVecInstance, v2b, v3b, v4b } from "../data/wgslTypes.js";
|
|
3
|
+
|
|
4
|
+
//#region src/std/boolean.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Checks whether `lhs == rhs` on all components.
|
|
7
|
+
* Equivalent to `all(eq(lhs, rhs))`.
|
|
8
|
+
* @example
|
|
9
|
+
* allEq(vec2f(0.0, 1.0), vec2f(0.0, 2.0)) // returns false
|
|
10
|
+
* allEq(vec3u(0, 1, 2), vec3u(0, 1, 2)) // returns true
|
|
11
|
+
*/
|
|
12
|
+
declare const allEq: DualFn<(<T extends AnyVecInstance>(lhs: T, rhs: T) => boolean)>;
|
|
13
|
+
/**
|
|
14
|
+
* Checks **component-wise** whether `lhs == rhs`.
|
|
15
|
+
* This function does **not** return `bool`, for that use-case, wrap the result in `all`, or use `allEq`.
|
|
16
|
+
* @example
|
|
17
|
+
* eq(vec2f(0.0, 1.0), vec2f(0.0, 2.0)) // returns vec2b(true, false)
|
|
18
|
+
* eq(vec3u(0, 1, 2), vec3u(2, 1, 0)) // returns vec3b(false, true, false)
|
|
19
|
+
* all(eq(vec4i(4, 3, 2, 1), vec4i(4, 3, 2, 1))) // returns true
|
|
20
|
+
* allEq(vec4i(4, 3, 2, 1), vec4i(4, 3, 2, 1)) // returns true
|
|
21
|
+
*/
|
|
22
|
+
declare const eq: DualFn<(<T extends AnyVecInstance>(lhs: T, rhs: T) => T extends AnyVec2Instance ? v2b : T extends AnyVec3Instance ? v3b : v4b)>;
|
|
23
|
+
/**
|
|
24
|
+
* Checks **component-wise** whether `lhs != rhs`.
|
|
25
|
+
* This function does **not** return `bool`, for that use-case, wrap the result in `any`.
|
|
26
|
+
* @example
|
|
27
|
+
* ne(vec2f(0.0, 1.0), vec2f(0.0, 2.0)) // returns vec2b(false, true)
|
|
28
|
+
* ne(vec3u(0, 1, 2), vec3u(2, 1, 0)) // returns vec3b(true, false, true)
|
|
29
|
+
* any(ne(vec4i(4, 3, 2, 1), vec4i(4, 2, 2, 1))) // returns true
|
|
30
|
+
*/
|
|
31
|
+
declare const ne: DualFn<(<T extends AnyVecInstance>(lhs: T, rhs: T) => T extends AnyVec2Instance ? v2b : T extends AnyVec3Instance ? v3b : v4b)>;
|
|
32
|
+
/**
|
|
33
|
+
* Checks **component-wise** whether `lhs < rhs`.
|
|
34
|
+
* This function does **not** return `bool`, for that use-case, wrap the result in `all`.
|
|
35
|
+
* @example
|
|
36
|
+
* lt(vec2f(0.0, 0.0), vec2f(0.0, 1.0)) // returns vec2b(false, true)
|
|
37
|
+
* lt(vec3u(0, 1, 2), vec3u(2, 1, 0)) // returns vec3b(true, false, false)
|
|
38
|
+
* all(lt(vec4i(1, 2, 3, 4), vec4i(2, 3, 4, 5))) // returns true
|
|
39
|
+
*/
|
|
40
|
+
declare const lt: DualFn<(<T extends AnyNumericVecInstance>(lhs: T, rhs: T) => T extends AnyVec2Instance ? v2b : T extends AnyVec3Instance ? v3b : v4b)>;
|
|
41
|
+
/**
|
|
42
|
+
* Checks **component-wise** whether `lhs <= rhs`.
|
|
43
|
+
* This function does **not** return `bool`, for that use-case, wrap the result in `all`.
|
|
44
|
+
* @example
|
|
45
|
+
* le(vec2f(0.0, 0.0), vec2f(0.0, 1.0)) // returns vec2b(true, true)
|
|
46
|
+
* le(vec3u(0, 1, 2), vec3u(2, 1, 0)) // returns vec3b(true, true, false)
|
|
47
|
+
* all(le(vec4i(1, 2, 3, 4), vec4i(2, 3, 3, 5))) // returns true
|
|
48
|
+
*/
|
|
49
|
+
declare const le: DualFn<(<T extends AnyNumericVecInstance>(lhs: T, rhs: T) => T extends AnyVec2Instance ? v2b : T extends AnyVec3Instance ? v3b : v4b)>;
|
|
50
|
+
/**
|
|
51
|
+
* Checks **component-wise** whether `lhs > rhs`.
|
|
52
|
+
* This function does **not** return `bool`, for that use-case, wrap the result in `all`.
|
|
53
|
+
* @example
|
|
54
|
+
* gt(vec2f(0.0, 0.0), vec2f(0.0, 1.0)) // returns vec2b(false, false)
|
|
55
|
+
* gt(vec3u(0, 1, 2), vec3u(2, 1, 0)) // returns vec3b(false, false, true)
|
|
56
|
+
* all(gt(vec4i(2, 3, 4, 5), vec4i(1, 2, 3, 4))) // returns true
|
|
57
|
+
*/
|
|
58
|
+
declare const gt: DualFn<(<T extends AnyNumericVecInstance>(lhs: T, rhs: T) => T extends AnyVec2Instance ? v2b : T extends AnyVec3Instance ? v3b : v4b)>;
|
|
59
|
+
/**
|
|
60
|
+
* Checks **component-wise** whether `lhs >= rhs`.
|
|
61
|
+
* This function does **not** return `bool`, for that use-case, wrap the result in `all`.
|
|
62
|
+
* @example
|
|
63
|
+
* ge(vec2f(0.0, 0.0), vec2f(0.0, 1.0)) // returns vec2b(true, false)
|
|
64
|
+
* ge(vec3u(0, 1, 2), vec3u(2, 1, 0)) // returns vec3b(false, true, true)
|
|
65
|
+
* all(ge(vec4i(2, 2, 4, 5), vec4i(1, 2, 3, 4))) // returns true
|
|
66
|
+
*/
|
|
67
|
+
declare const ge: DualFn<(<T extends AnyNumericVecInstance>(lhs: T, rhs: T) => T extends AnyVec2Instance ? v2b : T extends AnyVec3Instance ? v3b : v4b)>;
|
|
68
|
+
/**
|
|
69
|
+
* Returns **component-wise** `!value`.
|
|
70
|
+
* @example
|
|
71
|
+
* not(vec2b(false, true)) // returns vec2b(true, false)
|
|
72
|
+
* not(vec3b(true, true, false)) // returns vec3b(false, false, true)
|
|
73
|
+
*/
|
|
74
|
+
declare const not: DualFn<(<T extends AnyBooleanVecInstance>(value: T) => T)>;
|
|
75
|
+
/**
|
|
76
|
+
* Returns **component-wise** logical `or` result.
|
|
77
|
+
* @example
|
|
78
|
+
* or(vec2b(false, true), vec2b(false, false)) // returns vec2b(false, true)
|
|
79
|
+
* or(vec3b(true, true, false), vec3b(false, true, false)) // returns vec3b(true, true, false)
|
|
80
|
+
*/
|
|
81
|
+
declare const or: DualFn<(<T extends AnyBooleanVecInstance>(lhs: T, rhs: T) => T)>;
|
|
82
|
+
/**
|
|
83
|
+
* Returns **component-wise** logical `and` result.
|
|
84
|
+
* @example
|
|
85
|
+
* and(vec2b(false, true), vec2b(true, true)) // returns vec2b(false, true)
|
|
86
|
+
* and(vec3b(true, true, false), vec3b(false, true, false)) // returns vec3b(false, true, false)
|
|
87
|
+
*/
|
|
88
|
+
declare const and: DualFn<(<T extends AnyBooleanVecInstance>(lhs: T, rhs: T) => T)>;
|
|
89
|
+
/**
|
|
90
|
+
* Returns `true` if each component of `value` is true.
|
|
91
|
+
* @example
|
|
92
|
+
* all(vec2b(false, true)) // returns false
|
|
93
|
+
* all(vec3b(true, true, true)) // returns true
|
|
94
|
+
*/
|
|
95
|
+
declare const all: DualFn<(value: AnyBooleanVecInstance) => boolean>;
|
|
96
|
+
/**
|
|
97
|
+
* Returns `true` if any component of `value` is true.
|
|
98
|
+
* @example
|
|
99
|
+
* any(vec2b(false, true)) // returns true
|
|
100
|
+
* any(vec3b(false, false, false)) // returns false
|
|
101
|
+
*/
|
|
102
|
+
declare const any: DualFn<(value: AnyBooleanVecInstance) => boolean>;
|
|
103
|
+
/**
|
|
104
|
+
* Checks whether the given elements differ by at most the `precision` value.
|
|
105
|
+
* Checks all elements of `lhs` and `rhs` if arguments are vectors.
|
|
106
|
+
* @example
|
|
107
|
+
* isCloseTo(0, 0.1) // returns false
|
|
108
|
+
* isCloseTo(vec3f(0, 0, 0), vec3f(0.002, -0.009, 0)) // returns true
|
|
109
|
+
*
|
|
110
|
+
* @param {number} precision argument that specifies the maximum allowed difference, 0.01 by default.
|
|
111
|
+
*/
|
|
112
|
+
declare const isCloseTo: DualFn<(<T extends AnyFloatVecInstance | number>(lhs: T, rhs: T, precision?: number) => boolean)>;
|
|
113
|
+
declare function cpuSelect(f: boolean, t: boolean, cond: boolean): boolean;
|
|
114
|
+
declare function cpuSelect(f: number, t: number, cond: boolean): number;
|
|
115
|
+
declare function cpuSelect<T extends AnyVecInstance>(f: T, t: T, cond: boolean | (T extends AnyVec2Instance ? v2b : T extends AnyVec3Instance ? v3b : v4b)): T;
|
|
116
|
+
/**
|
|
117
|
+
* Returns `t` if `cond` is `true`, and `f` otherwise.
|
|
118
|
+
* Component-wise if `cond` is a vector.
|
|
119
|
+
* @example
|
|
120
|
+
* select(1, 2, false) // returns 1
|
|
121
|
+
* select(1, 2, true) // returns 2
|
|
122
|
+
* select(vec2i(1, 2), vec2i(3, 4), true) // returns vec2i(3, 4)
|
|
123
|
+
* select(vec2i(1, 2), vec2i(3, 4), vec2b(false, true)) // returns vec2i(1, 4)
|
|
124
|
+
*/
|
|
125
|
+
declare const select: DualFn<typeof cpuSelect>;
|
|
126
|
+
//#endregion
|
|
127
|
+
export { all, allEq, and, any, eq, ge, gt, isCloseTo, le, lt, ne, not, or, select };
|
package/std/boolean.js
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { isVecInstance } from "../data/wgslTypes.js";
|
|
2
|
+
import { isSnippetNumeric, snip } from "../data/snippet.js";
|
|
3
|
+
import { stitch } from "../core/resolve/stitch.js";
|
|
4
|
+
import { unify } from "../tgsl/conversion.js";
|
|
5
|
+
import { bool, f32 } from "../data/numeric.js";
|
|
6
|
+
import { vec2b, vec3b, vec4b } from "../data/vector.js";
|
|
7
|
+
import { dualImpl } from "../core/function/dualImpl.js";
|
|
8
|
+
import { VectorOps } from "../data/vectorOps.js";
|
|
9
|
+
import { sub } from "./operators.js";
|
|
10
|
+
|
|
11
|
+
//#region src/std/boolean.ts
|
|
12
|
+
function correspondingBooleanVectorSchema(dataType) {
|
|
13
|
+
if (dataType.type.includes("2")) return vec2b;
|
|
14
|
+
if (dataType.type.includes("3")) return vec3b;
|
|
15
|
+
return vec4b;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Checks whether `lhs == rhs` on all components.
|
|
19
|
+
* Equivalent to `all(eq(lhs, rhs))`.
|
|
20
|
+
* @example
|
|
21
|
+
* allEq(vec2f(0.0, 1.0), vec2f(0.0, 2.0)) // returns false
|
|
22
|
+
* allEq(vec3u(0, 1, 2), vec3u(0, 1, 2)) // returns true
|
|
23
|
+
*/
|
|
24
|
+
const allEq = dualImpl({
|
|
25
|
+
name: "allEq",
|
|
26
|
+
signature: (...argTypes) => ({
|
|
27
|
+
argTypes,
|
|
28
|
+
returnType: bool
|
|
29
|
+
}),
|
|
30
|
+
normalImpl: (lhs, rhs) => cpuAll(cpuEq(lhs, rhs)),
|
|
31
|
+
codegenImpl: (_ctx, [lhs, rhs]) => stitch`all(${lhs} == ${rhs})`
|
|
32
|
+
});
|
|
33
|
+
const cpuEq = (lhs, rhs) => VectorOps.eq[lhs.kind](lhs, rhs);
|
|
34
|
+
/**
|
|
35
|
+
* Checks **component-wise** whether `lhs == rhs`.
|
|
36
|
+
* This function does **not** return `bool`, for that use-case, wrap the result in `all`, or use `allEq`.
|
|
37
|
+
* @example
|
|
38
|
+
* eq(vec2f(0.0, 1.0), vec2f(0.0, 2.0)) // returns vec2b(true, false)
|
|
39
|
+
* eq(vec3u(0, 1, 2), vec3u(2, 1, 0)) // returns vec3b(false, true, false)
|
|
40
|
+
* all(eq(vec4i(4, 3, 2, 1), vec4i(4, 3, 2, 1))) // returns true
|
|
41
|
+
* allEq(vec4i(4, 3, 2, 1), vec4i(4, 3, 2, 1)) // returns true
|
|
42
|
+
*/
|
|
43
|
+
const eq = dualImpl({
|
|
44
|
+
name: "eq",
|
|
45
|
+
signature: (...argTypes) => ({
|
|
46
|
+
argTypes,
|
|
47
|
+
returnType: correspondingBooleanVectorSchema(argTypes[0])
|
|
48
|
+
}),
|
|
49
|
+
normalImpl: cpuEq,
|
|
50
|
+
codegenImpl: (_ctx, [lhs, rhs]) => stitch`(${lhs} == ${rhs})`
|
|
51
|
+
});
|
|
52
|
+
/**
|
|
53
|
+
* Checks **component-wise** whether `lhs != rhs`.
|
|
54
|
+
* This function does **not** return `bool`, for that use-case, wrap the result in `any`.
|
|
55
|
+
* @example
|
|
56
|
+
* ne(vec2f(0.0, 1.0), vec2f(0.0, 2.0)) // returns vec2b(false, true)
|
|
57
|
+
* ne(vec3u(0, 1, 2), vec3u(2, 1, 0)) // returns vec3b(true, false, true)
|
|
58
|
+
* any(ne(vec4i(4, 3, 2, 1), vec4i(4, 2, 2, 1))) // returns true
|
|
59
|
+
*/
|
|
60
|
+
const ne = dualImpl({
|
|
61
|
+
name: "ne",
|
|
62
|
+
signature: (...argTypes) => ({
|
|
63
|
+
argTypes,
|
|
64
|
+
returnType: correspondingBooleanVectorSchema(argTypes[0])
|
|
65
|
+
}),
|
|
66
|
+
normalImpl: (lhs, rhs) => cpuNot(cpuEq(lhs, rhs)),
|
|
67
|
+
codegenImpl: (_ctx, [lhs, rhs]) => stitch`(${lhs} != ${rhs})`
|
|
68
|
+
});
|
|
69
|
+
const cpuLt = (lhs, rhs) => VectorOps.lt[lhs.kind](lhs, rhs);
|
|
70
|
+
/**
|
|
71
|
+
* Checks **component-wise** whether `lhs < rhs`.
|
|
72
|
+
* This function does **not** return `bool`, for that use-case, wrap the result in `all`.
|
|
73
|
+
* @example
|
|
74
|
+
* lt(vec2f(0.0, 0.0), vec2f(0.0, 1.0)) // returns vec2b(false, true)
|
|
75
|
+
* lt(vec3u(0, 1, 2), vec3u(2, 1, 0)) // returns vec3b(true, false, false)
|
|
76
|
+
* all(lt(vec4i(1, 2, 3, 4), vec4i(2, 3, 4, 5))) // returns true
|
|
77
|
+
*/
|
|
78
|
+
const lt = dualImpl({
|
|
79
|
+
name: "lt",
|
|
80
|
+
signature: (...argTypes) => ({
|
|
81
|
+
argTypes,
|
|
82
|
+
returnType: correspondingBooleanVectorSchema(argTypes[0])
|
|
83
|
+
}),
|
|
84
|
+
normalImpl: cpuLt,
|
|
85
|
+
codegenImpl: (_ctx, [lhs, rhs]) => stitch`(${lhs} < ${rhs})`
|
|
86
|
+
});
|
|
87
|
+
/**
|
|
88
|
+
* Checks **component-wise** whether `lhs <= rhs`.
|
|
89
|
+
* This function does **not** return `bool`, for that use-case, wrap the result in `all`.
|
|
90
|
+
* @example
|
|
91
|
+
* le(vec2f(0.0, 0.0), vec2f(0.0, 1.0)) // returns vec2b(true, true)
|
|
92
|
+
* le(vec3u(0, 1, 2), vec3u(2, 1, 0)) // returns vec3b(true, true, false)
|
|
93
|
+
* all(le(vec4i(1, 2, 3, 4), vec4i(2, 3, 3, 5))) // returns true
|
|
94
|
+
*/
|
|
95
|
+
const le = dualImpl({
|
|
96
|
+
name: "le",
|
|
97
|
+
signature: (...argTypes) => ({
|
|
98
|
+
argTypes,
|
|
99
|
+
returnType: correspondingBooleanVectorSchema(argTypes[0])
|
|
100
|
+
}),
|
|
101
|
+
normalImpl: (lhs, rhs) => cpuOr(cpuLt(lhs, rhs), cpuEq(lhs, rhs)),
|
|
102
|
+
codegenImpl: (_ctx, [lhs, rhs]) => stitch`(${lhs} <= ${rhs})`
|
|
103
|
+
});
|
|
104
|
+
/**
|
|
105
|
+
* Checks **component-wise** whether `lhs > rhs`.
|
|
106
|
+
* This function does **not** return `bool`, for that use-case, wrap the result in `all`.
|
|
107
|
+
* @example
|
|
108
|
+
* gt(vec2f(0.0, 0.0), vec2f(0.0, 1.0)) // returns vec2b(false, false)
|
|
109
|
+
* gt(vec3u(0, 1, 2), vec3u(2, 1, 0)) // returns vec3b(false, false, true)
|
|
110
|
+
* all(gt(vec4i(2, 3, 4, 5), vec4i(1, 2, 3, 4))) // returns true
|
|
111
|
+
*/
|
|
112
|
+
const gt = dualImpl({
|
|
113
|
+
name: "gt",
|
|
114
|
+
signature: (...argTypes) => ({
|
|
115
|
+
argTypes,
|
|
116
|
+
returnType: correspondingBooleanVectorSchema(argTypes[0])
|
|
117
|
+
}),
|
|
118
|
+
normalImpl: (lhs, rhs) => cpuAnd(cpuNot(cpuLt(lhs, rhs)), cpuNot(cpuEq(lhs, rhs))),
|
|
119
|
+
codegenImpl: (_ctx, [lhs, rhs]) => stitch`(${lhs} > ${rhs})`
|
|
120
|
+
});
|
|
121
|
+
/**
|
|
122
|
+
* Checks **component-wise** whether `lhs >= rhs`.
|
|
123
|
+
* This function does **not** return `bool`, for that use-case, wrap the result in `all`.
|
|
124
|
+
* @example
|
|
125
|
+
* ge(vec2f(0.0, 0.0), vec2f(0.0, 1.0)) // returns vec2b(true, false)
|
|
126
|
+
* ge(vec3u(0, 1, 2), vec3u(2, 1, 0)) // returns vec3b(false, true, true)
|
|
127
|
+
* all(ge(vec4i(2, 2, 4, 5), vec4i(1, 2, 3, 4))) // returns true
|
|
128
|
+
*/
|
|
129
|
+
const ge = dualImpl({
|
|
130
|
+
name: "ge",
|
|
131
|
+
signature: (...argTypes) => ({
|
|
132
|
+
argTypes,
|
|
133
|
+
returnType: correspondingBooleanVectorSchema(argTypes[0])
|
|
134
|
+
}),
|
|
135
|
+
normalImpl: (lhs, rhs) => cpuNot(cpuLt(lhs, rhs)),
|
|
136
|
+
codegenImpl: (_ctx, [lhs, rhs]) => stitch`(${lhs} >= ${rhs})`
|
|
137
|
+
});
|
|
138
|
+
const cpuNot = (value) => VectorOps.neg[value.kind](value);
|
|
139
|
+
/**
|
|
140
|
+
* Returns **component-wise** `!value`.
|
|
141
|
+
* @example
|
|
142
|
+
* not(vec2b(false, true)) // returns vec2b(true, false)
|
|
143
|
+
* not(vec3b(true, true, false)) // returns vec3b(false, false, true)
|
|
144
|
+
*/
|
|
145
|
+
const not = dualImpl({
|
|
146
|
+
name: "not",
|
|
147
|
+
signature: (...argTypes) => ({
|
|
148
|
+
argTypes,
|
|
149
|
+
returnType: argTypes[0]
|
|
150
|
+
}),
|
|
151
|
+
normalImpl: cpuNot,
|
|
152
|
+
codegenImpl: (_ctx, [arg]) => stitch`!(${arg})`
|
|
153
|
+
});
|
|
154
|
+
const cpuOr = (lhs, rhs) => VectorOps.or[lhs.kind](lhs, rhs);
|
|
155
|
+
/**
|
|
156
|
+
* Returns **component-wise** logical `or` result.
|
|
157
|
+
* @example
|
|
158
|
+
* or(vec2b(false, true), vec2b(false, false)) // returns vec2b(false, true)
|
|
159
|
+
* or(vec3b(true, true, false), vec3b(false, true, false)) // returns vec3b(true, true, false)
|
|
160
|
+
*/
|
|
161
|
+
const or = dualImpl({
|
|
162
|
+
name: "or",
|
|
163
|
+
signature: (...argTypes) => ({
|
|
164
|
+
argTypes,
|
|
165
|
+
returnType: argTypes[0]
|
|
166
|
+
}),
|
|
167
|
+
normalImpl: cpuOr,
|
|
168
|
+
codegenImpl: (_ctx, [lhs, rhs]) => stitch`(${lhs} | ${rhs})`
|
|
169
|
+
});
|
|
170
|
+
const cpuAnd = (lhs, rhs) => cpuNot(cpuOr(cpuNot(lhs), cpuNot(rhs)));
|
|
171
|
+
/**
|
|
172
|
+
* Returns **component-wise** logical `and` result.
|
|
173
|
+
* @example
|
|
174
|
+
* and(vec2b(false, true), vec2b(true, true)) // returns vec2b(false, true)
|
|
175
|
+
* and(vec3b(true, true, false), vec3b(false, true, false)) // returns vec3b(false, true, false)
|
|
176
|
+
*/
|
|
177
|
+
const and = dualImpl({
|
|
178
|
+
name: "and",
|
|
179
|
+
signature: (...argTypes) => ({
|
|
180
|
+
argTypes,
|
|
181
|
+
returnType: argTypes[0]
|
|
182
|
+
}),
|
|
183
|
+
normalImpl: cpuAnd,
|
|
184
|
+
codegenImpl: (_ctx, [lhs, rhs]) => stitch`(${lhs} & ${rhs})`
|
|
185
|
+
});
|
|
186
|
+
const cpuAll = (value) => VectorOps.all[value.kind](value);
|
|
187
|
+
/**
|
|
188
|
+
* Returns `true` if each component of `value` is true.
|
|
189
|
+
* @example
|
|
190
|
+
* all(vec2b(false, true)) // returns false
|
|
191
|
+
* all(vec3b(true, true, true)) // returns true
|
|
192
|
+
*/
|
|
193
|
+
const all = dualImpl({
|
|
194
|
+
name: "all",
|
|
195
|
+
signature: (...argTypes) => ({
|
|
196
|
+
argTypes,
|
|
197
|
+
returnType: bool
|
|
198
|
+
}),
|
|
199
|
+
normalImpl: cpuAll,
|
|
200
|
+
codegenImpl: (_ctx, [value]) => stitch`all(${value})`
|
|
201
|
+
});
|
|
202
|
+
/**
|
|
203
|
+
* Returns `true` if any component of `value` is true.
|
|
204
|
+
* @example
|
|
205
|
+
* any(vec2b(false, true)) // returns true
|
|
206
|
+
* any(vec3b(false, false, false)) // returns false
|
|
207
|
+
*/
|
|
208
|
+
const any = dualImpl({
|
|
209
|
+
name: "any",
|
|
210
|
+
signature: (...argTypes) => ({
|
|
211
|
+
argTypes,
|
|
212
|
+
returnType: bool
|
|
213
|
+
}),
|
|
214
|
+
normalImpl: (value) => !cpuAll(cpuNot(value)),
|
|
215
|
+
codegenImpl: (_ctx, [arg]) => stitch`any(${arg})`
|
|
216
|
+
});
|
|
217
|
+
/**
|
|
218
|
+
* Checks whether the given elements differ by at most the `precision` value.
|
|
219
|
+
* Checks all elements of `lhs` and `rhs` if arguments are vectors.
|
|
220
|
+
* @example
|
|
221
|
+
* isCloseTo(0, 0.1) // returns false
|
|
222
|
+
* isCloseTo(vec3f(0, 0, 0), vec3f(0.002, -0.009, 0)) // returns true
|
|
223
|
+
*
|
|
224
|
+
* @param {number} precision argument that specifies the maximum allowed difference, 0.01 by default.
|
|
225
|
+
*/
|
|
226
|
+
const isCloseTo = dualImpl({
|
|
227
|
+
name: "isCloseTo",
|
|
228
|
+
signature: (...args) => ({
|
|
229
|
+
argTypes: args,
|
|
230
|
+
returnType: bool
|
|
231
|
+
}),
|
|
232
|
+
normalImpl: (lhs, rhs, precision = .01) => {
|
|
233
|
+
if (typeof lhs === "number" && typeof rhs === "number") return Math.abs(lhs - rhs) < precision;
|
|
234
|
+
if (isVecInstance(lhs) && isVecInstance(rhs)) return VectorOps.isCloseToZero[lhs.kind](sub(lhs, rhs), precision);
|
|
235
|
+
return false;
|
|
236
|
+
},
|
|
237
|
+
codegenImpl: (_ctx, [lhs, rhs, precision = snip(.01, f32, "constant")]) => {
|
|
238
|
+
if (isSnippetNumeric(lhs) && isSnippetNumeric(rhs)) return stitch`(abs(f32(${lhs}) - f32(${rhs})) <= ${precision})`;
|
|
239
|
+
if (!isSnippetNumeric(lhs) && !isSnippetNumeric(rhs)) return stitch`all(abs(${lhs} - ${rhs}) <= (${lhs} - ${lhs}) + ${precision})`;
|
|
240
|
+
return "false";
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
function cpuSelect(f, t, cond) {
|
|
244
|
+
if (typeof cond === "boolean") return cond ? t : f;
|
|
245
|
+
return VectorOps.select[f.kind](f, t, cond);
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Returns `t` if `cond` is `true`, and `f` otherwise.
|
|
249
|
+
* Component-wise if `cond` is a vector.
|
|
250
|
+
* @example
|
|
251
|
+
* select(1, 2, false) // returns 1
|
|
252
|
+
* select(1, 2, true) // returns 2
|
|
253
|
+
* select(vec2i(1, 2), vec2i(3, 4), true) // returns vec2i(3, 4)
|
|
254
|
+
* select(vec2i(1, 2), vec2i(3, 4), vec2b(false, true)) // returns vec2i(1, 4)
|
|
255
|
+
*/
|
|
256
|
+
const select = dualImpl({
|
|
257
|
+
name: "select",
|
|
258
|
+
signature: (f, t, cond) => {
|
|
259
|
+
const [uf, ut] = unify([f, t]) ?? [f, t];
|
|
260
|
+
return {
|
|
261
|
+
argTypes: [
|
|
262
|
+
uf,
|
|
263
|
+
ut,
|
|
264
|
+
cond
|
|
265
|
+
],
|
|
266
|
+
returnType: uf
|
|
267
|
+
};
|
|
268
|
+
},
|
|
269
|
+
normalImpl: cpuSelect,
|
|
270
|
+
codegenImpl: (_ctx, [f, t, cond]) => stitch`select(${f}, ${t}, ${cond})`
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
//#endregion
|
|
274
|
+
export { all, allEq, and, any, eq, ge, gt, isCloseTo, le, lt, ne, not, or, select };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DualFn } from "../types.js";
|
|
2
|
+
import { AnyFloat32VecInstance } from "../data/wgslTypes.js";
|
|
3
|
+
|
|
4
|
+
//#region src/std/derivative.d.ts
|
|
5
|
+
type DerivativeSignature = ((value: number) => number) & (<T extends AnyFloat32VecInstance>(value: T) => T);
|
|
6
|
+
declare const dpdx: DualFn<DerivativeSignature>;
|
|
7
|
+
declare const dpdxCoarse: DualFn<DerivativeSignature>;
|
|
8
|
+
declare const dpdxFine: DualFn<DerivativeSignature>;
|
|
9
|
+
declare const dpdy: DualFn<DerivativeSignature>;
|
|
10
|
+
declare const dpdyCoarse: DualFn<DerivativeSignature>;
|
|
11
|
+
declare const dpdyFine: DualFn<DerivativeSignature>;
|
|
12
|
+
declare const fwidth: DualFn<DerivativeSignature>;
|
|
13
|
+
declare const fwidthCoarse: DualFn<DerivativeSignature>;
|
|
14
|
+
declare const fwidthFine: DualFn<DerivativeSignature>;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { dpdx, dpdxCoarse, dpdxFine, dpdy, dpdyCoarse, dpdyFine, fwidth, fwidthCoarse, fwidthFine };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { stitch } from "../core/resolve/stitch.js";
|
|
2
|
+
import { dualImpl } from "../core/function/dualImpl.js";
|
|
3
|
+
|
|
4
|
+
//#region src/std/derivative.ts
|
|
5
|
+
const derivativeNormalError = "Derivative builtins are not allowed on the CPU";
|
|
6
|
+
const dpdx = dualImpl({
|
|
7
|
+
name: "dpdx",
|
|
8
|
+
normalImpl: derivativeNormalError,
|
|
9
|
+
signature: (value) => ({
|
|
10
|
+
argTypes: [value],
|
|
11
|
+
returnType: value
|
|
12
|
+
}),
|
|
13
|
+
codegenImpl: (_ctx, [value]) => stitch`dpdx(${value})`
|
|
14
|
+
});
|
|
15
|
+
const dpdxCoarse = dualImpl({
|
|
16
|
+
name: "dpdxCoarse",
|
|
17
|
+
normalImpl: derivativeNormalError,
|
|
18
|
+
signature: (value) => ({
|
|
19
|
+
argTypes: [value],
|
|
20
|
+
returnType: value
|
|
21
|
+
}),
|
|
22
|
+
codegenImpl: (_ctx, [value]) => stitch`dpdxCoarse(${value})`
|
|
23
|
+
});
|
|
24
|
+
const dpdxFine = dualImpl({
|
|
25
|
+
name: "dpdxFine",
|
|
26
|
+
normalImpl: derivativeNormalError,
|
|
27
|
+
signature: (value) => ({
|
|
28
|
+
argTypes: [value],
|
|
29
|
+
returnType: value
|
|
30
|
+
}),
|
|
31
|
+
codegenImpl: (_ctx, [value]) => stitch`dpdxFine(${value})`
|
|
32
|
+
});
|
|
33
|
+
const dpdy = dualImpl({
|
|
34
|
+
name: "dpdy",
|
|
35
|
+
normalImpl: derivativeNormalError,
|
|
36
|
+
signature: (value) => ({
|
|
37
|
+
argTypes: [value],
|
|
38
|
+
returnType: value
|
|
39
|
+
}),
|
|
40
|
+
codegenImpl: (_ctx, [value]) => stitch`dpdy(${value})`
|
|
41
|
+
});
|
|
42
|
+
const dpdyCoarse = dualImpl({
|
|
43
|
+
name: "dpdyCoarse",
|
|
44
|
+
normalImpl: derivativeNormalError,
|
|
45
|
+
signature: (value) => ({
|
|
46
|
+
argTypes: [value],
|
|
47
|
+
returnType: value
|
|
48
|
+
}),
|
|
49
|
+
codegenImpl: (_ctx, [value]) => stitch`dpdyCoarse(${value})`
|
|
50
|
+
});
|
|
51
|
+
const dpdyFine = dualImpl({
|
|
52
|
+
name: "dpdyFine",
|
|
53
|
+
normalImpl: derivativeNormalError,
|
|
54
|
+
signature: (value) => ({
|
|
55
|
+
argTypes: [value],
|
|
56
|
+
returnType: value
|
|
57
|
+
}),
|
|
58
|
+
codegenImpl: (_ctx, [value]) => stitch`dpdyFine(${value})`
|
|
59
|
+
});
|
|
60
|
+
const fwidth = dualImpl({
|
|
61
|
+
name: "fwidth",
|
|
62
|
+
normalImpl: derivativeNormalError,
|
|
63
|
+
signature: (value) => ({
|
|
64
|
+
argTypes: [value],
|
|
65
|
+
returnType: value
|
|
66
|
+
}),
|
|
67
|
+
codegenImpl: (_ctx, [value]) => stitch`fwidth(${value})`
|
|
68
|
+
});
|
|
69
|
+
const fwidthCoarse = dualImpl({
|
|
70
|
+
name: "fwidthCoarse",
|
|
71
|
+
normalImpl: derivativeNormalError,
|
|
72
|
+
signature: (value) => ({
|
|
73
|
+
argTypes: [value],
|
|
74
|
+
returnType: value
|
|
75
|
+
}),
|
|
76
|
+
codegenImpl: (_ctx, [value]) => stitch`fwidthCoarse(${value})`
|
|
77
|
+
});
|
|
78
|
+
const fwidthFine = dualImpl({
|
|
79
|
+
name: "fwidthFine",
|
|
80
|
+
normalImpl: derivativeNormalError,
|
|
81
|
+
signature: (value) => ({
|
|
82
|
+
argTypes: [value],
|
|
83
|
+
returnType: value
|
|
84
|
+
}),
|
|
85
|
+
codegenImpl: (_ctx, [value]) => stitch`fwidthFine(${value})`
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
//#endregion
|
|
89
|
+
export { dpdx, dpdxCoarse, dpdxFine, dpdy, dpdyCoarse, dpdyFine, fwidth, fwidthCoarse, fwidthFine };
|
package/std/discard.d.ts
ADDED
package/std/discard.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Void } from "../data/wgslTypes.js";
|
|
2
|
+
import { dualImpl } from "../core/function/dualImpl.js";
|
|
3
|
+
|
|
4
|
+
//#region src/std/discard.ts
|
|
5
|
+
const discard = dualImpl({
|
|
6
|
+
name: "discard",
|
|
7
|
+
normalImpl: "`discard` relies on GPU resources and cannot be executed outside of a draw call",
|
|
8
|
+
signature: {
|
|
9
|
+
argTypes: [],
|
|
10
|
+
returnType: Void
|
|
11
|
+
},
|
|
12
|
+
codegenImpl: () => "discard;"
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
export { discard };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { WgslExtension } from "../wgslExtensions.js";
|
|
2
|
+
import { TgpuComptime } from "../core/function/comptime.js";
|
|
3
|
+
import "../indexNamedExports.js";
|
|
4
|
+
|
|
5
|
+
//#region src/std/extensions.d.ts
|
|
6
|
+
declare const extensionEnabled: TgpuComptime<(extensionName: WgslExtension) => boolean>;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { extensionEnabled };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { getResolutionCtx } from "../execMode.js";
|
|
2
|
+
import { comptime } from "../core/function/comptime.js";
|
|
3
|
+
import { wgslExtensions } from "../wgslExtensions.js";
|
|
4
|
+
|
|
5
|
+
//#region src/std/extensions.ts
|
|
6
|
+
const extensionEnabled = comptime((extensionName) => {
|
|
7
|
+
const resolutionCtx = getResolutionCtx();
|
|
8
|
+
if (!resolutionCtx) throw new Error("Functions using `extensionEnabled` cannot be called directly. Either generate WGSL from them, or use tgpu['~unstable'].simulate(...)");
|
|
9
|
+
if (typeof extensionName !== "string" || !wgslExtensions.includes(extensionName)) throw new Error(`extensionEnabled has to be called with a string literal representing a valid WGSL extension name. Got: '${extensionName}'`);
|
|
10
|
+
return (resolutionCtx.enableExtensions ?? []).includes(extensionName);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
export { extensionEnabled };
|
package/std/index.d.ts
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { identity2, identity3, identity4, rotationX4, rotationY4, rotationZ4, scaling4, translation4 } from "../data/matrix.js";
|
|
2
|
+
import { discard } from "./discard.js";
|
|
3
|
+
import { abs, acos, acosh, asin, asinh, atan, atan2, atanh, ceil, clamp, cos, cosh, countLeadingZeros, countOneBits, countTrailingZeros, cross, degrees, determinant, distance, dot, dot4I8Packed, dot4U8Packed, exp, exp2, extractBits, faceForward, firstLeadingBit, firstTrailingBit, floor, fma, fract, frexp, insertBits, inverseSqrt, ldexp, length, log, log2, max, min, mix, modf, normalize, pow, quantizeToF16, radians, reflect, refract, reverseBits, round, saturate, sign, sin, sinh, smoothstep, sqrt, step, tan, tanh, transpose, trunc } from "./numeric.js";
|
|
4
|
+
import { add, div, mod, mul, neg, sub } from "./operators.js";
|
|
5
|
+
import { rotateX4, rotateY4, rotateZ4, scale4, translate4 } from "./matrix.js";
|
|
6
|
+
import { all, allEq, and, any, eq, ge, gt, isCloseTo, le, lt, ne, not, or, select } from "./boolean.js";
|
|
7
|
+
import { atomicAdd, atomicAnd, atomicLoad, atomicMax, atomicMin, atomicOr, atomicStore, atomicSub, atomicXor, storageBarrier, textureBarrier, workgroupBarrier } from "./atomic.js";
|
|
8
|
+
import { dpdx, dpdxCoarse, dpdxFine, dpdy, dpdyCoarse, dpdyFine, fwidth, fwidthCoarse, fwidthFine } from "./derivative.js";
|
|
9
|
+
import { arrayLength } from "./array.js";
|
|
10
|
+
import { pack2x16float, pack4x8unorm, unpack2x16float, unpack4x8unorm } from "./packing.js";
|
|
11
|
+
import { textureDimensions, textureGather, textureLoad, textureSample, textureSampleBaseClampToEdge, textureSampleBias, textureSampleCompare, textureSampleCompareLevel, textureSampleLevel, textureStore } from "./texture.js";
|
|
12
|
+
import { subgroupAdd, subgroupAll, subgroupAnd, subgroupAny, subgroupBallot, subgroupBroadcast, subgroupBroadcastFirst, subgroupElect, subgroupExclusiveAdd, subgroupExclusiveMul, subgroupInclusiveAdd, subgroupInclusiveMul, subgroupMax, subgroupMin, subgroupMul, subgroupOr, subgroupShuffle, subgroupShuffleDown, subgroupShuffleUp, subgroupShuffleXor, subgroupXor } from "./subgroup.js";
|
|
13
|
+
import { extensionEnabled } from "./extensions.js";
|
|
14
|
+
import { bitcastU32toF32, bitcastU32toI32 } from "./bitcast.js";
|
|
2
15
|
|
|
3
16
|
//#region src/std/index.d.ts
|
|
4
17
|
declare namespace index_d_exports {
|
|
5
18
|
export { abs, acos, acosh, add, all, allEq, and, any, arrayLength, asin, asinh, atan, atan2, atanh, atomicAdd, atomicAnd, atomicLoad, atomicMax, atomicMin, atomicOr, atomicStore, atomicSub, atomicXor, bitcastU32toF32, bitcastU32toI32, ceil, clamp, cos, cosh, countLeadingZeros, countOneBits, countTrailingZeros, cross, degrees, determinant, discard, distance, div, dot, dot4I8Packed, dot4U8Packed, dpdx, dpdxCoarse, dpdxFine, dpdy, dpdyCoarse, dpdyFine, eq, exp, exp2, extensionEnabled, extractBits, faceForward, firstLeadingBit, firstTrailingBit, floor, fma, fract, frexp, fwidth, fwidthCoarse, fwidthFine, ge, gt, identity2, identity3, identity4, insertBits, inverseSqrt, isCloseTo, ldexp, le, length, log, log2, lt, max, min, mix, mod, modf, mul, ne, neg, normalize, not, or, pack2x16float, pack4x8unorm, pow, quantizeToF16, radians, reflect, refract, reverseBits, rotateX4, rotateY4, rotateZ4, rotationX4, rotationY4, rotationZ4, round, saturate, scale4, scaling4, select, sign, sin, sinh, smoothstep, sqrt, step, storageBarrier, sub, subgroupAdd, subgroupAll, subgroupAnd, subgroupAny, subgroupBallot, subgroupBroadcast, subgroupBroadcastFirst, subgroupElect, subgroupExclusiveAdd, subgroupExclusiveMul, subgroupInclusiveAdd, subgroupInclusiveMul, subgroupMax, subgroupMin, subgroupMul, subgroupOr, subgroupShuffle, subgroupShuffleDown, subgroupShuffleUp, subgroupShuffleXor, subgroupXor, tan, tanh, textureBarrier, textureDimensions, textureGather, textureLoad, textureSample, textureSampleBaseClampToEdge, textureSampleBias, textureSampleCompare, textureSampleCompareLevel, textureSampleLevel, textureStore, translate4, translation4, transpose, trunc, unpack2x16float, unpack4x8unorm, workgroupBarrier };
|
|
6
19
|
}
|
|
7
20
|
//#endregion
|
|
8
|
-
export { abs, acos, acosh, add, all, allEq, and, any, arrayLength, asin, asinh, atan, atan2, atanh, atomicAdd, atomicAnd, atomicLoad, atomicMax, atomicMin, atomicOr, atomicStore, atomicSub, atomicXor, bitcastU32toF32, bitcastU32toI32, ceil, clamp, cos, cosh, countLeadingZeros, countOneBits, countTrailingZeros, cross, degrees, determinant, discard, distance, div, dot, dot4I8Packed, dot4U8Packed, dpdx, dpdxCoarse, dpdxFine, dpdy, dpdyCoarse, dpdyFine, eq, exp, exp2, extensionEnabled, extractBits, faceForward, firstLeadingBit, firstTrailingBit, floor, fma, fract, frexp, fwidth, fwidthCoarse, fwidthFine, ge, gt, identity2, identity3, identity4, insertBits, inverseSqrt, isCloseTo, ldexp, le, length, log, log2, lt, max, min, mix, mod, modf, mul, ne, neg, normalize, not, or, pack2x16float, pack4x8unorm, pow, quantizeToF16, radians, reflect, refract, reverseBits, rotateX4, rotateY4, rotateZ4, rotationX4, rotationY4, rotationZ4, round, saturate, scale4, scaling4, select, sign, sin, sinh, smoothstep, sqrt, step, storageBarrier, sub, subgroupAdd, subgroupAll, subgroupAnd, subgroupAny, subgroupBallot, subgroupBroadcast, subgroupBroadcastFirst, subgroupElect, subgroupExclusiveAdd, subgroupExclusiveMul, subgroupInclusiveAdd, subgroupInclusiveMul, subgroupMax, subgroupMin, subgroupMul, subgroupOr, subgroupShuffle, subgroupShuffleDown, subgroupShuffleUp, subgroupShuffleXor, subgroupXor,
|
|
9
|
-
//# sourceMappingURL=index.d.ts.map
|
|
21
|
+
export { abs, acos, acosh, add, all, allEq, and, any, arrayLength, asin, asinh, atan, atan2, atanh, atomicAdd, atomicAnd, atomicLoad, atomicMax, atomicMin, atomicOr, atomicStore, atomicSub, atomicXor, bitcastU32toF32, bitcastU32toI32, ceil, clamp, cos, cosh, countLeadingZeros, countOneBits, countTrailingZeros, cross, degrees, determinant, discard, distance, div, dot, dot4I8Packed, dot4U8Packed, dpdx, dpdxCoarse, dpdxFine, dpdy, dpdyCoarse, dpdyFine, eq, exp, exp2, extensionEnabled, extractBits, faceForward, firstLeadingBit, firstTrailingBit, floor, fma, fract, frexp, fwidth, fwidthCoarse, fwidthFine, ge, gt, identity2, identity3, identity4, index_d_exports, insertBits, inverseSqrt, isCloseTo, ldexp, le, length, log, log2, lt, max, min, mix, mod, modf, mul, ne, neg, normalize, not, or, pack2x16float, pack4x8unorm, pow, quantizeToF16, radians, reflect, refract, reverseBits, rotateX4, rotateY4, rotateZ4, rotationX4, rotationY4, rotationZ4, round, saturate, scale4, scaling4, select, sign, sin, sinh, smoothstep, sqrt, step, storageBarrier, sub, subgroupAdd, subgroupAll, subgroupAnd, subgroupAny, subgroupBallot, subgroupBroadcast, subgroupBroadcastFirst, subgroupElect, subgroupExclusiveAdd, subgroupExclusiveMul, subgroupInclusiveAdd, subgroupInclusiveMul, subgroupMax, subgroupMin, subgroupMul, subgroupOr, subgroupShuffle, subgroupShuffleDown, subgroupShuffleUp, subgroupShuffleXor, subgroupXor, tan, tanh, textureBarrier, textureDimensions, textureGather, textureLoad, textureSample, textureSampleBaseClampToEdge, textureSampleBias, textureSampleCompare, textureSampleCompareLevel, textureSampleLevel, textureStore, translate4, translation4, transpose, trunc, unpack2x16float, unpack4x8unorm, workgroupBarrier };
|
package/std/index.js
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { __exportAll } from "../_virtual/_rolldown/runtime.js";
|
|
2
|
+
import { identity2, identity3, identity4, rotationX4, rotationY4, rotationZ4, scaling4, translation4 } from "../data/matrix.js";
|
|
3
|
+
import { add, div, mod, mul, neg, sub } from "./operators.js";
|
|
4
|
+
import { abs, acos, acosh, asin, asinh, atan, atan2, atanh, ceil, clamp, cos, cosh, countLeadingZeros, countOneBits, countTrailingZeros, cross, degrees, determinant, distance, dot, dot4I8Packed, dot4U8Packed, exp, exp2, extractBits, faceForward, firstLeadingBit, firstTrailingBit, floor, fma, fract, frexp, insertBits, inverseSqrt, ldexp, length, log, log2, max, min, mix, modf, normalize, pow, quantizeToF16, radians, reflect, refract, reverseBits, round, saturate, sign, sin, sinh, smoothstep, sqrt, step, tan, tanh, transpose, trunc } from "./numeric.js";
|
|
5
|
+
import { arrayLength } from "./array.js";
|
|
6
|
+
import { bitcastU32toF32, bitcastU32toI32 } from "./bitcast.js";
|
|
7
|
+
import { pack2x16float, pack4x8unorm, unpack2x16float, unpack4x8unorm } from "./packing.js";
|
|
8
|
+
import { all, allEq, and, any, eq, ge, gt, isCloseTo, le, lt, ne, not, or, select } from "./boolean.js";
|
|
9
|
+
import { discard } from "./discard.js";
|
|
10
|
+
import { rotateX4, rotateY4, rotateZ4, scale4, translate4 } from "./matrix.js";
|
|
11
|
+
import { atomicAdd, atomicAnd, atomicLoad, atomicMax, atomicMin, atomicOr, atomicStore, atomicSub, atomicXor, storageBarrier, textureBarrier, workgroupBarrier } from "./atomic.js";
|
|
12
|
+
import { dpdx, dpdxCoarse, dpdxFine, dpdy, dpdyCoarse, dpdyFine, fwidth, fwidthCoarse, fwidthFine } from "./derivative.js";
|
|
13
|
+
import { textureDimensions, textureGather, textureLoad, textureSample, textureSampleBaseClampToEdge, textureSampleBias, textureSampleCompare, textureSampleCompareLevel, textureSampleLevel, textureStore } from "./texture.js";
|
|
14
|
+
import { subgroupAdd, subgroupAll, subgroupAnd, subgroupAny, subgroupBallot, subgroupBroadcast, subgroupBroadcastFirst, subgroupElect, subgroupExclusiveAdd, subgroupExclusiveMul, subgroupInclusiveAdd, subgroupInclusiveMul, subgroupMax, subgroupMin, subgroupMul, subgroupOr, subgroupShuffle, subgroupShuffleDown, subgroupShuffleUp, subgroupShuffleXor, subgroupXor } from "./subgroup.js";
|
|
15
|
+
import { extensionEnabled } from "./extensions.js";
|
|
4
16
|
|
|
5
17
|
//#region src/std/index.ts
|
|
6
18
|
var std_exports = /* @__PURE__ */ __exportAll({
|
|
@@ -162,5 +174,4 @@ var std_exports = /* @__PURE__ */ __exportAll({
|
|
|
162
174
|
});
|
|
163
175
|
|
|
164
176
|
//#endregion
|
|
165
|
-
export { abs, acos, acosh, add, all, allEq, and, any, arrayLength, asin, asinh, atan, atan2, atanh, atomicAdd, atomicAnd, atomicLoad, atomicMax, atomicMin, atomicOr, atomicStore, atomicSub, atomicXor, bitcastU32toF32, bitcastU32toI32, ceil, clamp, cos, cosh, countLeadingZeros, countOneBits, countTrailingZeros, cross, degrees, determinant, discard, distance, div, dot, dot4I8Packed, dot4U8Packed, dpdx, dpdxCoarse, dpdxFine, dpdy, dpdyCoarse, dpdyFine, eq, exp, exp2, extensionEnabled, extractBits, faceForward, firstLeadingBit, firstTrailingBit, floor, fma, fract, frexp, fwidth, fwidthCoarse, fwidthFine, ge, gt, identity2, identity3, identity4, insertBits, inverseSqrt, isCloseTo, ldexp, le, length, log, log2, lt, max, min, mix, mod, modf, mul, ne, neg, normalize, not, or, pack2x16float, pack4x8unorm, pow, quantizeToF16, radians, reflect, refract, reverseBits, rotateX4, rotateY4, rotateZ4, rotationX4, rotationY4, rotationZ4, round, saturate, scale4, scaling4, select, sign, sin, sinh, smoothstep, sqrt, step, storageBarrier, sub, subgroupAdd, subgroupAll, subgroupAnd, subgroupAny, subgroupBallot, subgroupBroadcast, subgroupBroadcastFirst, subgroupElect, subgroupExclusiveAdd, subgroupExclusiveMul, subgroupInclusiveAdd, subgroupInclusiveMul, subgroupMax, subgroupMin, subgroupMul, subgroupOr, subgroupShuffle, subgroupShuffleDown, subgroupShuffleUp, subgroupShuffleXor, subgroupXor,
|
|
166
|
-
//# sourceMappingURL=index.js.map
|
|
177
|
+
export { abs, acos, acosh, add, all, allEq, and, any, arrayLength, asin, asinh, atan, atan2, atanh, atomicAdd, atomicAnd, atomicLoad, atomicMax, atomicMin, atomicOr, atomicStore, atomicSub, atomicXor, bitcastU32toF32, bitcastU32toI32, ceil, clamp, cos, cosh, countLeadingZeros, countOneBits, countTrailingZeros, cross, degrees, determinant, discard, distance, div, dot, dot4I8Packed, dot4U8Packed, dpdx, dpdxCoarse, dpdxFine, dpdy, dpdyCoarse, dpdyFine, eq, exp, exp2, extensionEnabled, extractBits, faceForward, firstLeadingBit, firstTrailingBit, floor, fma, fract, frexp, fwidth, fwidthCoarse, fwidthFine, ge, gt, identity2, identity3, identity4, insertBits, inverseSqrt, isCloseTo, ldexp, le, length, log, log2, lt, max, min, mix, mod, modf, mul, ne, neg, normalize, not, or, pack2x16float, pack4x8unorm, pow, quantizeToF16, radians, reflect, refract, reverseBits, rotateX4, rotateY4, rotateZ4, rotationX4, rotationY4, rotationZ4, round, saturate, scale4, scaling4, select, sign, sin, sinh, smoothstep, sqrt, std_exports, step, storageBarrier, sub, subgroupAdd, subgroupAll, subgroupAnd, subgroupAny, subgroupBallot, subgroupBroadcast, subgroupBroadcastFirst, subgroupElect, subgroupExclusiveAdd, subgroupExclusiveMul, subgroupInclusiveAdd, subgroupInclusiveMul, subgroupMax, subgroupMin, subgroupMul, subgroupOr, subgroupShuffle, subgroupShuffleDown, subgroupShuffleUp, subgroupShuffleXor, subgroupXor, tan, tanh, textureBarrier, textureDimensions, textureGather, textureLoad, textureSample, textureSampleBaseClampToEdge, textureSampleBias, textureSampleCompare, textureSampleCompareLevel, textureSampleLevel, textureStore, translate4, translation4, transpose, trunc, unpack2x16float, unpack4x8unorm, workgroupBarrier };
|