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,116 @@
|
|
|
1
|
+
import { $gpuValueOf, $internal, $ownSnippet, $resolve } from "../../shared/symbols.js";
|
|
2
|
+
import { getName, setName } from "../../shared/meta.js";
|
|
3
|
+
import { snip } from "../../data/snippet.js";
|
|
4
|
+
import { inCodegenMode } from "../../execMode.js";
|
|
5
|
+
import { valueProxyHandler } from "../valueProxyUtils.js";
|
|
6
|
+
import { comparisonSampler, sampler } from "../../data/sampler.js";
|
|
7
|
+
|
|
8
|
+
//#region src/core/sampler/sampler.ts
|
|
9
|
+
function INTERNAL_createSampler(props, branch) {
|
|
10
|
+
return new TgpuFixedSamplerImpl(sampler(), props, branch);
|
|
11
|
+
}
|
|
12
|
+
function INTERNAL_createComparisonSampler(props, branch) {
|
|
13
|
+
return new TgpuFixedSamplerImpl(comparisonSampler(), props, branch);
|
|
14
|
+
}
|
|
15
|
+
function isSampler(resource) {
|
|
16
|
+
const maybe = resource;
|
|
17
|
+
return maybe?.resourceType === "sampler" && !!maybe[$internal];
|
|
18
|
+
}
|
|
19
|
+
function isComparisonSampler(resource) {
|
|
20
|
+
const maybe = resource;
|
|
21
|
+
return maybe?.resourceType === "sampler-comparison" && !!maybe[$internal];
|
|
22
|
+
}
|
|
23
|
+
var TgpuLaidOutSamplerImpl = class {
|
|
24
|
+
[$internal] = { unwrap: void 0 };
|
|
25
|
+
resourceType;
|
|
26
|
+
#membership;
|
|
27
|
+
constructor(schema, membership) {
|
|
28
|
+
this.schema = schema;
|
|
29
|
+
this.#membership = membership;
|
|
30
|
+
this.resourceType = schema.type === "sampler_comparison" ? "sampler-comparison" : "sampler";
|
|
31
|
+
setName(this, membership.key);
|
|
32
|
+
}
|
|
33
|
+
[$resolve](ctx) {
|
|
34
|
+
const id = ctx.getUniqueName(this);
|
|
35
|
+
const group = ctx.allocateLayoutEntry(this.#membership.layout);
|
|
36
|
+
ctx.addDeclaration(`@group(${group}) @binding(${this.#membership.idx}) var ${id}: ${ctx.resolve(this.schema).value};`);
|
|
37
|
+
return snip(id, this.schema, "handle");
|
|
38
|
+
}
|
|
39
|
+
get [$gpuValueOf]() {
|
|
40
|
+
const schema = this.schema;
|
|
41
|
+
return new Proxy({
|
|
42
|
+
[$internal]: true,
|
|
43
|
+
get [$ownSnippet]() {
|
|
44
|
+
return snip(this, schema, "handle");
|
|
45
|
+
},
|
|
46
|
+
[$resolve]: (ctx) => ctx.resolve(this),
|
|
47
|
+
toString: () => `${this.toString()}.$`
|
|
48
|
+
}, valueProxyHandler);
|
|
49
|
+
}
|
|
50
|
+
get $() {
|
|
51
|
+
if (inCodegenMode()) return this[$gpuValueOf];
|
|
52
|
+
throw new Error("Direct access to sampler values is possible only as part of a compute dispatch or draw call.");
|
|
53
|
+
}
|
|
54
|
+
get value() {
|
|
55
|
+
return this.$;
|
|
56
|
+
}
|
|
57
|
+
toString() {
|
|
58
|
+
return `${this.resourceType}:${getName(this) ?? "<unnamed>"}`;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
var TgpuFixedSamplerImpl = class {
|
|
62
|
+
[$internal];
|
|
63
|
+
resourceType;
|
|
64
|
+
#filtering;
|
|
65
|
+
#sampler = null;
|
|
66
|
+
#props;
|
|
67
|
+
#branch;
|
|
68
|
+
constructor(schema, props, branch) {
|
|
69
|
+
this.schema = schema;
|
|
70
|
+
this.#props = props;
|
|
71
|
+
this.#branch = branch;
|
|
72
|
+
this.resourceType = schema.type === "sampler_comparison" ? "sampler-comparison" : "sampler";
|
|
73
|
+
this[$internal] = { unwrap: () => {
|
|
74
|
+
if (!this.#sampler) this.#sampler = this.#branch.device.createSampler({
|
|
75
|
+
...this.#props,
|
|
76
|
+
label: getName(this) ?? "<unnamed>"
|
|
77
|
+
});
|
|
78
|
+
return this.#sampler;
|
|
79
|
+
} };
|
|
80
|
+
this.#filtering = props.minFilter === "linear" || props.magFilter === "linear" || props.mipmapFilter === "linear";
|
|
81
|
+
}
|
|
82
|
+
[$resolve](ctx) {
|
|
83
|
+
const id = ctx.getUniqueName(this);
|
|
84
|
+
const { group, binding } = ctx.allocateFixedEntry(this.schema.type === "sampler_comparison" ? { sampler: "comparison" } : { sampler: this.#filtering ? "filtering" : "non-filtering" }, this);
|
|
85
|
+
ctx.addDeclaration(`@group(${group}) @binding(${binding}) var ${id}: ${ctx.resolve(this.schema).value};`);
|
|
86
|
+
return snip(id, this.schema, "handle");
|
|
87
|
+
}
|
|
88
|
+
get [$gpuValueOf]() {
|
|
89
|
+
const schema = this.schema;
|
|
90
|
+
return new Proxy({
|
|
91
|
+
[$internal]: true,
|
|
92
|
+
get [$ownSnippet]() {
|
|
93
|
+
return snip(this, schema, "handle");
|
|
94
|
+
},
|
|
95
|
+
[$resolve]: (ctx) => ctx.resolve(this),
|
|
96
|
+
toString: () => `${this.toString()}.$`
|
|
97
|
+
}, valueProxyHandler);
|
|
98
|
+
}
|
|
99
|
+
get $() {
|
|
100
|
+
if (inCodegenMode()) return this[$gpuValueOf];
|
|
101
|
+
throw new Error("Direct access to sampler values is possible only as part of a compute dispatch or draw call.");
|
|
102
|
+
}
|
|
103
|
+
get value() {
|
|
104
|
+
return this.$;
|
|
105
|
+
}
|
|
106
|
+
$name(label) {
|
|
107
|
+
setName(this, label);
|
|
108
|
+
return this;
|
|
109
|
+
}
|
|
110
|
+
toString() {
|
|
111
|
+
return `${this.resourceType}:${getName(this) ?? "<unnamed>"}`;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
//#endregion
|
|
116
|
+
export { INTERNAL_createComparisonSampler, INTERNAL_createSampler, TgpuLaidOutSamplerImpl, isComparisonSampler, isSampler };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { TgpuVar } from "../variable/tgpuVariable.js";
|
|
2
|
+
import { TgpuBuffer } from "../buffer/buffer.js";
|
|
3
|
+
import { BaseData } from "../../data/wgslTypes.js";
|
|
4
|
+
|
|
5
|
+
//#region src/core/simulate/tgpuSimulate.d.ts
|
|
6
|
+
interface SimulationResult<T> {
|
|
7
|
+
value: T;
|
|
8
|
+
buffers: Map<TgpuBuffer<BaseData>, unknown>;
|
|
9
|
+
privateVars: Map<TgpuVar<'private'>, unknown>[][][];
|
|
10
|
+
workgroupVars: Map<TgpuVar<'workgroup'>, unknown>[][][];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Runs the provided callback in a simulated environment, giving
|
|
14
|
+
* it access to buffers and variables as if it were running on the GPU.
|
|
15
|
+
*
|
|
16
|
+
* The result of the simulation is returned, and does not affect the actual GPU state,
|
|
17
|
+
* nor does it carry over to other simulations.
|
|
18
|
+
*
|
|
19
|
+
* @param callback The callback to run in the simulated environment.
|
|
20
|
+
* @returns An object containing the result of the simulation, and
|
|
21
|
+
* the final state of the environment.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* const counter = tgpu.privateVar(d.u32);
|
|
25
|
+
*
|
|
26
|
+
* const result = tgpu.simulate(() => {
|
|
27
|
+
* counter.$ += 1;
|
|
28
|
+
* counter.$ += 2;
|
|
29
|
+
* return counter.$;
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* console.log(result.value); // 3
|
|
33
|
+
*/
|
|
34
|
+
declare function simulate<T>(callback: () => T): SimulationResult<T>;
|
|
35
|
+
//#endregion
|
|
36
|
+
export { simulate };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { SimulationState } from "../../types.js";
|
|
2
|
+
import { getResolutionCtx, provideCtx } from "../../execMode.js";
|
|
3
|
+
import { namespace } from "../resolve/namespace.js";
|
|
4
|
+
import wgslGenerator from "../../tgsl/wgslGenerator.js";
|
|
5
|
+
import { ResolutionCtxImpl } from "../../resolutionCtx.js";
|
|
6
|
+
|
|
7
|
+
//#region src/core/simulate/tgpuSimulate.ts
|
|
8
|
+
/**
|
|
9
|
+
* Runs the provided callback in a simulated environment, giving
|
|
10
|
+
* it access to buffers and variables as if it were running on the GPU.
|
|
11
|
+
*
|
|
12
|
+
* The result of the simulation is returned, and does not affect the actual GPU state,
|
|
13
|
+
* nor does it carry over to other simulations.
|
|
14
|
+
*
|
|
15
|
+
* @param callback The callback to run in the simulated environment.
|
|
16
|
+
* @returns An object containing the result of the simulation, and
|
|
17
|
+
* the final state of the environment.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const counter = tgpu.privateVar(d.u32);
|
|
21
|
+
*
|
|
22
|
+
* const result = tgpu.simulate(() => {
|
|
23
|
+
* counter.$ += 1;
|
|
24
|
+
* counter.$ += 2;
|
|
25
|
+
* return counter.$;
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* console.log(result.value); // 3
|
|
29
|
+
*/
|
|
30
|
+
function simulate(callback) {
|
|
31
|
+
const ctx = getResolutionCtx() ?? new ResolutionCtxImpl({
|
|
32
|
+
namespace: namespace(),
|
|
33
|
+
shaderGenerator: wgslGenerator
|
|
34
|
+
});
|
|
35
|
+
const workgroups = [
|
|
36
|
+
1,
|
|
37
|
+
1,
|
|
38
|
+
1
|
|
39
|
+
];
|
|
40
|
+
const workgroupSize = [
|
|
41
|
+
1,
|
|
42
|
+
1,
|
|
43
|
+
1
|
|
44
|
+
];
|
|
45
|
+
const threads = [
|
|
46
|
+
workgroups[0] * workgroupSize[0],
|
|
47
|
+
workgroups[1] * workgroupSize[1],
|
|
48
|
+
workgroups[2] * workgroupSize[2]
|
|
49
|
+
];
|
|
50
|
+
const buffers = /* @__PURE__ */ new Map();
|
|
51
|
+
const workgroupVars = Array.from({ length: workgroups[0] }, () => Array.from({ length: workgroups[1] }, () => Array.from({ length: workgroups[2] }, () => /* @__PURE__ */ new Map())));
|
|
52
|
+
const privateVars = Array.from({ length: threads[0] }, () => Array.from({ length: threads[1] }, () => Array.from({ length: threads[2] }, () => /* @__PURE__ */ new Map())));
|
|
53
|
+
const simStates = Array.from({ length: threads[0] }, (_, i) => Array.from({ length: threads[1] }, (_, j) => Array.from({ length: threads[2] }, (_, k) => {
|
|
54
|
+
const wi = Math.floor(i / workgroupSize[0]);
|
|
55
|
+
const wj = Math.floor(j / workgroupSize[1]);
|
|
56
|
+
const wk = Math.floor(k / workgroupSize[2]);
|
|
57
|
+
return new SimulationState(buffers, {
|
|
58
|
+
private: privateVars[i][j][k],
|
|
59
|
+
workgroup: workgroupVars[wi][wj][wk]
|
|
60
|
+
});
|
|
61
|
+
})));
|
|
62
|
+
ctx.pushMode(simStates[0][0][0]);
|
|
63
|
+
try {
|
|
64
|
+
return {
|
|
65
|
+
value: provideCtx(ctx, callback),
|
|
66
|
+
buffers,
|
|
67
|
+
privateVars,
|
|
68
|
+
workgroupVars
|
|
69
|
+
};
|
|
70
|
+
} finally {
|
|
71
|
+
ctx.popMode("simulate");
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
//#endregion
|
|
76
|
+
export { simulate };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import "../../data/snippet.js";
|
|
2
|
+
import { TgpuAccessor, TgpuMutableAccessor } from "./slotTypes.js";
|
|
3
|
+
import { UnwrapRuntimeConstructor } from "../../tgpuBindGroupLayout.js";
|
|
4
|
+
import "../../types.js";
|
|
5
|
+
import "../../data/wgslTypes.js";
|
|
6
|
+
import "../../shared/repr.js";
|
|
7
|
+
import { AnyData } from "../../data/dataTypes.js";
|
|
8
|
+
|
|
9
|
+
//#region src/core/slot/accessor.d.ts
|
|
10
|
+
declare function accessor<T extends AnyData | ((count: number) => AnyData)>(schemaOrConstructor: T, defaultValue?: TgpuAccessor.In<NoInfer<T>>): TgpuAccessor<UnwrapRuntimeConstructor<T>>;
|
|
11
|
+
declare function mutableAccessor<T extends AnyData | ((count: number) => AnyData)>(schemaOrConstructor: T, defaultValue?: TgpuMutableAccessor.In<NoInfer<T>>): TgpuMutableAccessor<UnwrapRuntimeConstructor<T>>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { accessor, mutableAccessor };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { $getNameForward, $gpuValueOf, $internal, $ownSnippet, $resolve } from "../../shared/symbols.js";
|
|
2
|
+
import { getName, hasTinyestMetadata, setName } from "../../shared/meta.js";
|
|
3
|
+
import { isData } from "../../data/dataTypes.js";
|
|
4
|
+
import { isSnippet, snip } from "../../data/snippet.js";
|
|
5
|
+
import { NormalState, getOwnSnippet } from "../../types.js";
|
|
6
|
+
import { getResolutionCtx, inCodegenMode } from "../../execMode.js";
|
|
7
|
+
import { schemaCallWrapper } from "../../data/schemaCallWrapper.js";
|
|
8
|
+
import { getGpuValueRecursively, valueProxyHandler } from "../valueProxyUtils.js";
|
|
9
|
+
import { isTgpuFn } from "../function/tgpuFn.js";
|
|
10
|
+
import { slot } from "./slot.js";
|
|
11
|
+
|
|
12
|
+
//#region src/core/slot/accessor.ts
|
|
13
|
+
function accessor(schemaOrConstructor, defaultValue) {
|
|
14
|
+
return new TgpuAccessorImpl(schemaOrConstructor, defaultValue);
|
|
15
|
+
}
|
|
16
|
+
function mutableAccessor(schemaOrConstructor, defaultValue) {
|
|
17
|
+
return new TgpuMutableAccessorImpl(schemaOrConstructor, defaultValue);
|
|
18
|
+
}
|
|
19
|
+
var AccessorBase = class {
|
|
20
|
+
[$internal] = true;
|
|
21
|
+
[$getNameForward];
|
|
22
|
+
slot;
|
|
23
|
+
schema;
|
|
24
|
+
defaultValue;
|
|
25
|
+
constructor(schemaOrConstructor, defaultValue = void 0) {
|
|
26
|
+
this.schema = isData(schemaOrConstructor) ? schemaOrConstructor : schemaOrConstructor(0);
|
|
27
|
+
this.defaultValue = defaultValue;
|
|
28
|
+
this.slot = slot(defaultValue);
|
|
29
|
+
this[$getNameForward] = this.slot;
|
|
30
|
+
}
|
|
31
|
+
get [$gpuValueOf]() {
|
|
32
|
+
return new Proxy({
|
|
33
|
+
[$internal]: true,
|
|
34
|
+
[$ownSnippet]: this.#createSnippet(),
|
|
35
|
+
[$resolve]: (ctx) => ctx.resolve(this),
|
|
36
|
+
toString: () => `${this.resourceType}:${getName(this) ?? "<unnamed>"}.$`
|
|
37
|
+
}, valueProxyHandler);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @returns A snippet representing the accessor.
|
|
41
|
+
*/
|
|
42
|
+
#createSnippet() {
|
|
43
|
+
const ctx = getResolutionCtx();
|
|
44
|
+
let value = getGpuValueRecursively(ctx.unwrap(this.slot));
|
|
45
|
+
while (typeof value === "function" && !isTgpuFn(value) && !hasTinyestMetadata(value)) {
|
|
46
|
+
value = value();
|
|
47
|
+
if (isSnippet(value)) value = value.value;
|
|
48
|
+
}
|
|
49
|
+
const ownSnippet = getOwnSnippet(value);
|
|
50
|
+
if (ownSnippet) return ownSnippet;
|
|
51
|
+
if (isTgpuFn(value) || hasTinyestMetadata(value)) return ctx.withResetIndentLevel(() => snip(`${ctx.resolve(value).value}()`, this.schema, "runtime"));
|
|
52
|
+
ctx.pushMode(new NormalState());
|
|
53
|
+
try {
|
|
54
|
+
return snip(schemaCallWrapper(this.schema, value), this.schema, "constant");
|
|
55
|
+
} finally {
|
|
56
|
+
ctx.popMode("normal");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
$name(label) {
|
|
60
|
+
setName(this, label);
|
|
61
|
+
if (this.defaultValue && typeof this.defaultValue === "function" && !getName(this.defaultValue)) setName(this.defaultValue, label);
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
toString() {
|
|
65
|
+
return `${this.resourceType}:${getName(this) ?? "<unnamed>"}`;
|
|
66
|
+
}
|
|
67
|
+
get value() {
|
|
68
|
+
return this.$;
|
|
69
|
+
}
|
|
70
|
+
[$resolve](ctx) {
|
|
71
|
+
const snippet = this.#createSnippet();
|
|
72
|
+
return snip(ctx.resolve(snippet.value, snippet.dataType).value, snippet.dataType, snippet.origin);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
var TgpuAccessorImpl = class extends AccessorBase {
|
|
76
|
+
resourceType = "accessor";
|
|
77
|
+
constructor(schemaOrConstructor, defaultValue = void 0) {
|
|
78
|
+
super(schemaOrConstructor, defaultValue);
|
|
79
|
+
}
|
|
80
|
+
get $() {
|
|
81
|
+
if (inCodegenMode()) return this[$gpuValueOf];
|
|
82
|
+
throw new Error("`tgpu.accessor` relies on GPU resources and cannot be accessed outside of a compute dispatch or draw call");
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
var TgpuMutableAccessorImpl = class extends AccessorBase {
|
|
86
|
+
resourceType = "mutable-accessor";
|
|
87
|
+
constructor(schemaOrConstructor, defaultValue = void 0) {
|
|
88
|
+
super(schemaOrConstructor, defaultValue);
|
|
89
|
+
}
|
|
90
|
+
get $() {
|
|
91
|
+
if (inCodegenMode()) return this[$gpuValueOf];
|
|
92
|
+
throw new Error("`tgpu.mutableAccessor` relies on GPU resources and cannot be accessed outside of a compute dispatch or draw call");
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
//#endregion
|
|
97
|
+
export { accessor, mutableAccessor };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { $gpuValueOf, $internal, $providing } from "../../shared/symbols.js";
|
|
2
|
+
import { isAccessor, isMutableAccessor } from "./slotTypes.js";
|
|
3
|
+
import { getResolutionCtx } from "../../execMode.js";
|
|
4
|
+
import { getGpuValueRecursively } from "../valueProxyUtils.js";
|
|
5
|
+
|
|
6
|
+
//#region src/core/slot/lazy.ts
|
|
7
|
+
function lazy(compute) {
|
|
8
|
+
if (getResolutionCtx()) throw new Error("Cannot create tgpu.lazy objects during shader resolution.");
|
|
9
|
+
return new TgpuLazyImpl(compute, void 0);
|
|
10
|
+
}
|
|
11
|
+
var TgpuLazyImpl = class TgpuLazyImpl {
|
|
12
|
+
[$internal];
|
|
13
|
+
[$providing];
|
|
14
|
+
constructor(compute, providing) {
|
|
15
|
+
this[$internal] = { compute };
|
|
16
|
+
this[$providing] = providing;
|
|
17
|
+
}
|
|
18
|
+
get [$gpuValueOf]() {
|
|
19
|
+
const ctx = getResolutionCtx();
|
|
20
|
+
if (!ctx) throw new Error(`Cannot access tgpu.lazy's value outside of resolution.`);
|
|
21
|
+
return getGpuValueRecursively(ctx.unwrap(this));
|
|
22
|
+
}
|
|
23
|
+
get value() {
|
|
24
|
+
return this[$gpuValueOf];
|
|
25
|
+
}
|
|
26
|
+
get $() {
|
|
27
|
+
return this[$gpuValueOf];
|
|
28
|
+
}
|
|
29
|
+
toString() {
|
|
30
|
+
return "lazy";
|
|
31
|
+
}
|
|
32
|
+
with(slot, value) {
|
|
33
|
+
return new TgpuLazyImpl(this[$internal].compute.bind(this), {
|
|
34
|
+
inner: this[$providing]?.inner ?? this,
|
|
35
|
+
pairs: [...this[$providing]?.pairs ?? [], [isAccessor(slot) || isMutableAccessor(slot) ? slot.slot : slot, value]]
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
TgpuLazyImpl.prototype.resourceType = "lazy";
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
export { lazy };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { $gpuValueOf, $internal } from "../../shared/symbols.js";
|
|
2
|
+
import { getName, setName } from "../../shared/meta.js";
|
|
3
|
+
import { getResolutionCtx } from "../../execMode.js";
|
|
4
|
+
import { getGpuValueRecursively } from "../valueProxyUtils.js";
|
|
5
|
+
|
|
6
|
+
//#region src/core/slot/slot.ts
|
|
7
|
+
function slot(defaultValue) {
|
|
8
|
+
return new TgpuSlotImpl(defaultValue);
|
|
9
|
+
}
|
|
10
|
+
var TgpuSlotImpl = class {
|
|
11
|
+
[$internal] = true;
|
|
12
|
+
resourceType = "slot";
|
|
13
|
+
constructor(defaultValue = void 0) {
|
|
14
|
+
this.defaultValue = defaultValue;
|
|
15
|
+
}
|
|
16
|
+
$name(label) {
|
|
17
|
+
setName(this, label);
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
areEqual(a, b) {
|
|
21
|
+
return Object.is(a, b);
|
|
22
|
+
}
|
|
23
|
+
toString() {
|
|
24
|
+
return `slot:${getName(this) ?? "<unnamed>"}`;
|
|
25
|
+
}
|
|
26
|
+
get [$gpuValueOf]() {
|
|
27
|
+
const ctx = getResolutionCtx();
|
|
28
|
+
if (!ctx) throw new Error(`Cannot access tgpu.slot's value outside of resolution.`);
|
|
29
|
+
return getGpuValueRecursively(ctx.unwrap(this));
|
|
30
|
+
}
|
|
31
|
+
get value() {
|
|
32
|
+
return this[$gpuValueOf];
|
|
33
|
+
}
|
|
34
|
+
get $() {
|
|
35
|
+
return this.value;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
export { slot };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { TgpuNamable } from "../../shared/meta.js";
|
|
2
|
+
import { $gpuValueOf, $internal, $providing } from "../../shared/symbols.js";
|
|
3
|
+
import { TgpuBufferUsage } from "../buffer/bufferUsage.js";
|
|
4
|
+
import { TgpuBufferShorthand } from "../buffer/bufferShorthand.js";
|
|
5
|
+
import { TgpuVar, VariableScope } from "../variable/tgpuVariable.js";
|
|
6
|
+
import { UnwrapRuntimeConstructor } from "../../tgpuBindGroupLayout.js";
|
|
7
|
+
import { Withable } from "../root/rootTypes.js";
|
|
8
|
+
import { BaseData } from "../../data/wgslTypes.js";
|
|
9
|
+
import { WgslStorageTexture, WgslTexture } from "../../data/texture.js";
|
|
10
|
+
import { TgpuTextureView } from "../texture/texture.js";
|
|
11
|
+
import { GPUValueOf, Infer, InferGPU } from "../../shared/repr.js";
|
|
12
|
+
import { TgpuConst } from "../constant/tgpuConstant.js";
|
|
13
|
+
|
|
14
|
+
//#region src/core/slot/slotTypes.d.ts
|
|
15
|
+
interface TgpuSlot<T> extends TgpuNamable {
|
|
16
|
+
readonly [$internal]: true;
|
|
17
|
+
readonly resourceType: 'slot';
|
|
18
|
+
readonly defaultValue: T | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Used to determine if code generated using either value `a` or `b` in place
|
|
21
|
+
* of the slot will be equivalent. Defaults to `Object.is`.
|
|
22
|
+
*/
|
|
23
|
+
areEqual(a: T, b: T): boolean;
|
|
24
|
+
readonly [$gpuValueOf]: GPUValueOf<T>;
|
|
25
|
+
/**
|
|
26
|
+
* @deprecated Use `.$` instead, works the same way.
|
|
27
|
+
*/
|
|
28
|
+
readonly value: GPUValueOf<T>;
|
|
29
|
+
readonly $: GPUValueOf<T>;
|
|
30
|
+
toString(): string;
|
|
31
|
+
}
|
|
32
|
+
interface TgpuLazy<out T> extends Withable<TgpuLazy<T>> {
|
|
33
|
+
readonly [$internal]: {
|
|
34
|
+
compute(): T;
|
|
35
|
+
};
|
|
36
|
+
readonly resourceType: 'lazy';
|
|
37
|
+
readonly [$gpuValueOf]: GPUValueOf<T>;
|
|
38
|
+
/**
|
|
39
|
+
* @deprecated Use `.$` instead, works the same way.
|
|
40
|
+
*/
|
|
41
|
+
readonly value: GPUValueOf<T>;
|
|
42
|
+
readonly $: GPUValueOf<T>;
|
|
43
|
+
readonly [$providing]?: Providing | undefined;
|
|
44
|
+
}
|
|
45
|
+
interface TgpuAccessor<T extends BaseData = BaseData> extends TgpuNamable {
|
|
46
|
+
readonly [$internal]: true;
|
|
47
|
+
readonly resourceType: 'accessor';
|
|
48
|
+
readonly schema: T;
|
|
49
|
+
readonly defaultValue: TgpuAccessor.In<T> | undefined;
|
|
50
|
+
readonly slot: TgpuSlot<TgpuAccessor.In<T>>;
|
|
51
|
+
readonly [$gpuValueOf]: InferGPU<T>;
|
|
52
|
+
/**
|
|
53
|
+
* @deprecated Use `.$` instead, works the same way.
|
|
54
|
+
*/
|
|
55
|
+
readonly value: InferGPU<T>;
|
|
56
|
+
readonly $: InferGPU<T>;
|
|
57
|
+
}
|
|
58
|
+
type DataAccessorIn<T extends BaseData> = (() => DataAccessorIn<T>) | TgpuBufferUsage<T> | TgpuBufferShorthand<T> | TgpuVar<VariableScope, T> | TgpuConst<T> | Infer<T>;
|
|
59
|
+
type TextureAccessorIn<T extends WgslTexture | WgslStorageTexture> = (() => TextureAccessorIn<T>) | Infer<T> | TgpuTextureView<T>;
|
|
60
|
+
declare namespace TgpuAccessor {
|
|
61
|
+
type In<T extends BaseData | ((count: number) => BaseData)> = UnwrapRuntimeConstructor<T> extends WgslTexture | WgslStorageTexture ? TextureAccessorIn<UnwrapRuntimeConstructor<T>> : DataAccessorIn<UnwrapRuntimeConstructor<T>>;
|
|
62
|
+
}
|
|
63
|
+
interface TgpuMutableAccessor<T extends BaseData = BaseData> extends TgpuNamable {
|
|
64
|
+
readonly [$internal]: true;
|
|
65
|
+
readonly resourceType: 'mutable-accessor';
|
|
66
|
+
readonly schema: T;
|
|
67
|
+
readonly defaultValue: TgpuMutableAccessor.In<T> | undefined;
|
|
68
|
+
readonly slot: TgpuSlot<TgpuMutableAccessor.In<T>>;
|
|
69
|
+
readonly [$gpuValueOf]: InferGPU<T>;
|
|
70
|
+
value: InferGPU<T>;
|
|
71
|
+
$: InferGPU<T>;
|
|
72
|
+
}
|
|
73
|
+
type MutableDataAccessorIn<T extends BaseData> = (() => Infer<T> | MutableDataAccessorIn<T>) | TgpuBufferUsage<T> | TgpuBufferShorthand<T> | TgpuVar<VariableScope, T>;
|
|
74
|
+
type MutableTextureAccessorIn<T extends WgslTexture | WgslStorageTexture> = (() => Infer<T> | TgpuTextureView<T> | MutableTextureAccessorIn<T>) | TgpuTextureView<T>;
|
|
75
|
+
declare namespace TgpuMutableAccessor {
|
|
76
|
+
type In<T extends BaseData | ((count: number) => BaseData)> = UnwrapRuntimeConstructor<T> extends WgslTexture | WgslStorageTexture ? MutableTextureAccessorIn<UnwrapRuntimeConstructor<T>> : MutableDataAccessorIn<UnwrapRuntimeConstructor<T>>;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Represents a value that is available at resolution time.
|
|
80
|
+
*/
|
|
81
|
+
type Eventual<T> = T | TgpuSlot<T> | TgpuLazy<T>;
|
|
82
|
+
type SlotValuePair<T = unknown> = [TgpuSlot<T>, T];
|
|
83
|
+
type Providing = {
|
|
84
|
+
inner: object;
|
|
85
|
+
pairs: SlotValuePair[];
|
|
86
|
+
};
|
|
87
|
+
declare function isSlot<T>(value: unknown): value is TgpuSlot<T>;
|
|
88
|
+
declare function isLazy<T>(value: unknown): value is TgpuLazy<T>;
|
|
89
|
+
declare function isAccessor<T extends BaseData>(value: unknown): value is TgpuAccessor<T>;
|
|
90
|
+
declare function isMutableAccessor<T extends BaseData>(value: unknown): value is TgpuMutableAccessor<T>;
|
|
91
|
+
//#endregion
|
|
92
|
+
export { Eventual, Providing, SlotValuePair, TgpuAccessor, TgpuLazy, TgpuMutableAccessor, TgpuSlot, isAccessor, isLazy, isMutableAccessor, isSlot };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { $providing } from "../../shared/symbols.js";
|
|
2
|
+
|
|
3
|
+
//#region src/core/slot/slotTypes.ts
|
|
4
|
+
function isSlot(value) {
|
|
5
|
+
return value?.resourceType === "slot";
|
|
6
|
+
}
|
|
7
|
+
function isLazy(value) {
|
|
8
|
+
return value?.resourceType === "lazy";
|
|
9
|
+
}
|
|
10
|
+
function isProviding(value) {
|
|
11
|
+
return value?.[$providing] !== void 0;
|
|
12
|
+
}
|
|
13
|
+
function isAccessor(value) {
|
|
14
|
+
return value?.resourceType === "accessor";
|
|
15
|
+
}
|
|
16
|
+
function isMutableAccessor(value) {
|
|
17
|
+
return value?.resourceType === "mutable-accessor";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
export { isAccessor, isLazy, isMutableAccessor, isProviding, isSlot };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import "../../data/snippet.js";
|
|
2
|
+
import "../../tgpuBindGroupLayout.js";
|
|
3
|
+
import "../../types.js";
|
|
4
|
+
import "../../data/texture.js";
|
|
5
|
+
import "../../shared/repr.js";
|
|
6
|
+
|
|
7
|
+
//#region src/core/texture/externalTexture.d.ts
|
|
8
|
+
interface TgpuExternalTexture {
|
|
9
|
+
readonly resourceType: 'external-texture';
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { TgpuExternalTexture };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { $gpuValueOf, $internal, $ownSnippet, $resolve } from "../../shared/symbols.js";
|
|
2
|
+
import { getName, setName } from "../../shared/meta.js";
|
|
3
|
+
import { snip } from "../../data/snippet.js";
|
|
4
|
+
import { inCodegenMode } from "../../execMode.js";
|
|
5
|
+
import { valueProxyHandler } from "../valueProxyUtils.js";
|
|
6
|
+
import { textureExternal } from "../../data/texture.js";
|
|
7
|
+
|
|
8
|
+
//#region src/core/texture/externalTexture.ts
|
|
9
|
+
var TgpuExternalTextureImpl = class {
|
|
10
|
+
resourceType = "external-texture";
|
|
11
|
+
[$internal] = true;
|
|
12
|
+
#membership;
|
|
13
|
+
constructor(schema, membership) {
|
|
14
|
+
this.schema = schema;
|
|
15
|
+
this.#membership = membership;
|
|
16
|
+
setName(this, membership.key);
|
|
17
|
+
}
|
|
18
|
+
[$resolve](ctx) {
|
|
19
|
+
const id = ctx.getUniqueName(this);
|
|
20
|
+
const group = ctx.allocateLayoutEntry(this.#membership.layout);
|
|
21
|
+
ctx.addDeclaration(`@group(${group}) @binding(${this.#membership.idx}) var ${id}: ${ctx.resolve(this.schema).value};`);
|
|
22
|
+
return snip(id, textureExternal(), "handle");
|
|
23
|
+
}
|
|
24
|
+
get [$gpuValueOf]() {
|
|
25
|
+
const schema = this.schema;
|
|
26
|
+
return new Proxy({
|
|
27
|
+
[$internal]: true,
|
|
28
|
+
get [$ownSnippet]() {
|
|
29
|
+
return snip(this, schema, "handle");
|
|
30
|
+
},
|
|
31
|
+
[$resolve]: (ctx) => ctx.resolve(this),
|
|
32
|
+
toString: () => `textureExternal:${getName(this) ?? "<unnamed>"}.$`
|
|
33
|
+
}, valueProxyHandler);
|
|
34
|
+
}
|
|
35
|
+
get $() {
|
|
36
|
+
if (inCodegenMode()) return this[$gpuValueOf];
|
|
37
|
+
throw new Error("Direct access to texture views values is possible only as part of a compute dispatch or draw call. Try .read() or .write() instead");
|
|
38
|
+
}
|
|
39
|
+
get value() {
|
|
40
|
+
return this.$;
|
|
41
|
+
}
|
|
42
|
+
toString() {
|
|
43
|
+
return `textureExternal:${getName(this) ?? "<unnamed>"}`;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
//#endregion
|
|
48
|
+
export { TgpuExternalTextureImpl };
|