@margoengine/shader 0.0.0-stage → 1.0.0
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/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +1919 -2
- package/dist/attribute.d.ts +28 -0
- package/dist/black-hole.d.ts +246 -0
- package/dist/black-hole.js +445 -0
- package/dist/clock-BLGNexlt.js +52 -0
- package/dist/clock.d.ts +42 -0
- package/dist/compute-CXGG9qvI.js +360 -0
- package/dist/compute-texture.d.ts +100 -0
- package/dist/compute-texture.js +131 -0
- package/dist/compute-volume.d.ts +57 -0
- package/dist/compute-volume.js +130 -0
- package/dist/compute.d.ts +200 -0
- package/dist/control-CFjkGPBk.js +201 -0
- package/dist/control.d.ts +93 -0
- package/dist/deform.d.ts +111 -0
- package/dist/deform.js +89 -0
- package/dist/display-BrJM_Qkd.js +5 -0
- package/dist/editor-model.d.ts +192 -0
- package/dist/editor-pass.d.ts +71 -0
- package/dist/editor-pass.js +216 -0
- package/dist/editor.d.ts +150 -0
- package/dist/editor.js +1071 -0
- package/dist/effects.d.ts +150 -0
- package/dist/effects.js +87 -0
- package/dist/errors-CsQwshHA.js +7 -0
- package/dist/glsl/emit.d.ts +43 -0
- package/dist/glsl/host.d.ts +55 -0
- package/dist/glsl/material.d.ts +173 -0
- package/dist/glsl/parser.d.ts +76 -0
- package/dist/glsl/preprocess.d.ts +9 -0
- package/dist/glsl/presets.d.ts +33 -0
- package/dist/glsl/program.d.ts +210 -0
- package/dist/glsl/scene.d.ts +9 -0
- package/dist/glsl-material.d.ts +82 -0
- package/dist/glsl-material.js +288 -0
- package/dist/glsl-pass.d.ts +93 -0
- package/dist/glsl-pass.js +186 -0
- package/dist/glsl.d.ts +94 -0
- package/dist/glsl.js +170 -0
- package/dist/gpu-DQJk2xAv.js +55 -0
- package/dist/graph.d.ts +82 -0
- package/dist/graph.js +365 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +103 -0
- package/dist/lighting-JU9yQPfM.js +77 -0
- package/dist/lighting.d.ts +62 -0
- package/dist/lighting.js +1 -0
- package/dist/material-C6bpqlnE.js +1184 -0
- package/dist/material-CZ8V1FeA.js +299 -0
- package/dist/material.d.ts +79 -0
- package/dist/node-B6yoIC9V.js +590 -0
- package/dist/node.d.ts +433 -0
- package/dist/noise.d.ts +38 -0
- package/dist/noise.js +107 -0
- package/dist/own-stack-D1XnXrrz.js +11 -0
- package/dist/own-stack.d.ts +12 -0
- package/dist/pass.d.ts +109 -0
- package/dist/pass.js +239 -0
- package/dist/post-DLpZ110L.js +113 -0
- package/dist/post.d.ts +69 -0
- package/dist/preprocess-CWGWlBWQ.js +1195 -0
- package/dist/raw-0AYej3Ak.js +1500 -0
- package/dist/raw.d.ts +744 -0
- package/dist/raw.js +1 -0
- package/dist/readback.d.ts +42 -0
- package/dist/readback.js +85 -0
- package/dist/scope.d.ts +21 -0
- package/dist/serialization.d.ts +11 -0
- package/dist/serialization.js +192 -0
- package/dist/shadertoy/sound.d.ts +48 -0
- package/dist/shadertoy.d.ts +249 -0
- package/dist/shadertoy.js +909 -0
- package/dist/shared/caster.d.ts +159 -0
- package/dist/shared/fog.d.ts +33 -0
- package/dist/shared/fractal.d.ts +9 -0
- package/dist/shared/msaa.d.ts +30 -0
- package/dist/shared/stack.d.ts +22 -0
- package/dist/sound-CF_dzP41.js +78 -0
- package/dist/storage-format-DWaiSxmq.js +25 -0
- package/dist/storage-format.d.ts +7 -0
- package/dist/subgroups.d.ts +97 -0
- package/dist/subgroups.js +95 -0
- package/dist/texture-BawKO_h9.js +62 -0
- package/dist/texture-array.d.ts +7 -0
- package/dist/texture-array.js +11 -0
- package/dist/texture.d.ts +16 -0
- package/dist/utils.d.ts +106 -0
- package/dist/utils.js +90 -0
- package/dist/view-rect-Bm1ac-TK.js +16 -0
- package/package.json +149 -4
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
// @margo/core-built 1.0.0
|
|
2
|
+
import {coreRequirement as __margoCoreRequirement,assertCore as __margoAssertCore} from '@margoengine/core/extension';
|
|
3
|
+
const _=(engine,version="1.0.0",source=import.meta.url)=>__margoRuntime(engine,version,source);
|
|
4
|
+
import { Ht as e, It as t, Pt as n, T as r, b as i, gn as a, l as o, o as s, tn as c } from "./node-B6yoIC9V.js";
|
|
5
|
+
import { i as l, t as u } from "./gpu-DQJk2xAv.js";
|
|
6
|
+
import { t as d } from "./clock-BLGNexlt.js";
|
|
7
|
+
import { d as f, f as p, i as m, p as h } from "./control-CFjkGPBk.js";
|
|
8
|
+
import { MargoError as g } from "@margoengine/math/errors";
|
|
9
|
+
import { engineRuntime as __margoRuntime } from "@margoengine/core/extension";
|
|
10
|
+
//#region src/compute.ts
|
|
11
|
+
var v = (e) => e instanceof s && (e.type === "u32" || e.type === "i32") ? e : r(e, "u32", "storage index"), y = /* @__PURE__ */ new WeakMap();
|
|
12
|
+
function b(e) {
|
|
13
|
+
let t = y.get(e);
|
|
14
|
+
if (!t) {
|
|
15
|
+
t = /* @__PURE__ */ new Set(), y.set(e, t);
|
|
16
|
+
let n = t;
|
|
17
|
+
e.lost.then((t) => {
|
|
18
|
+
let r = [...n];
|
|
19
|
+
n.clear(), y.delete(e);
|
|
20
|
+
for (let e of r) e(t);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return t;
|
|
24
|
+
}
|
|
25
|
+
function x(e, t) {
|
|
26
|
+
if (!e.lost) return () => {};
|
|
27
|
+
let n = b(e);
|
|
28
|
+
return n.add(t), () => n.delete(t);
|
|
29
|
+
}
|
|
30
|
+
var S = (e, t, n, r, i) => {
|
|
31
|
+
let o = new s(t, "a" + c(), [r, ...i], (t, r) => {
|
|
32
|
+
if (t.stage.kind !== "compute") throw TypeError(`${n} is only available in ComputePass nodes`);
|
|
33
|
+
let [i, ...a] = r.args.map((e) => t.expr(e)), o = t.name();
|
|
34
|
+
return t.line(`let ${o} = ${n}(&${t.resource(e)}[${i}]${a.map((e) => ", " + e).join("")});`), o;
|
|
35
|
+
}, 28);
|
|
36
|
+
return a.list?.push(o), o;
|
|
37
|
+
}, C = (e) => ({
|
|
38
|
+
old: new s(e.type, ".old", [e], (e, t) => `${e.expr(t.args[0])}.old_value`),
|
|
39
|
+
exchanged: new s("bool", ".exchanged", [e], (e, t) => `${e.expr(t.args[0])}.exchanged`)
|
|
40
|
+
}), w = class {
|
|
41
|
+
constructor(n, r, i = !1) {
|
|
42
|
+
this.data = n, this.type = r, this.atomic = i, this.prefix = "ndb", this.bindings = 1, this.id = c(), this.version = 0, this.buffers = /* @__PURE__ */ new Map(), this.lossSubscriptions = /* @__PURE__ */ new Map();
|
|
43
|
+
let a = {
|
|
44
|
+
f32: Float32Array,
|
|
45
|
+
i32: Int32Array,
|
|
46
|
+
u32: Uint32Array
|
|
47
|
+
}[t(r)];
|
|
48
|
+
if (!a || e(r) === 3 || !(n instanceof a)) throw TypeError(`Storage ${r} needs a ${a?.name ?? "f32, i32 or u32 typed array"}`);
|
|
49
|
+
if (i && r !== "u32" && r !== "i32") throw TypeError("Atomic storage must be u32 or i32; pass one of those types or drop {atomic: true}.");
|
|
50
|
+
if (this.count = n.length / e(r), !Number.isInteger(this.count) || this.count < 1) throw RangeError("Storage data length must be a positive multiple of the element size");
|
|
51
|
+
}
|
|
52
|
+
declare(e, t, n, r) {
|
|
53
|
+
return `@group(${t}) @binding(${n}) var<storage, ${r ? "read_write" : "read"}> ${e}:array<${r && this.atomic ? `atomic<${this.type}>` : this.type}>;`;
|
|
54
|
+
}
|
|
55
|
+
entries(e) {
|
|
56
|
+
return [{ buffer: this.buffer(e) }];
|
|
57
|
+
}
|
|
58
|
+
buffer(e) {
|
|
59
|
+
let t = this.buffers.get(e);
|
|
60
|
+
return t || (t = {
|
|
61
|
+
buffer: e.createBuffer({
|
|
62
|
+
label: "shader:storage",
|
|
63
|
+
size: Math.max(16, this.data.byteLength),
|
|
64
|
+
usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST | GPUBufferUsage.COPY_SRC | GPUBufferUsage.VERTEX | GPUBufferUsage.INDIRECT
|
|
65
|
+
}),
|
|
66
|
+
version: -1
|
|
67
|
+
}, this.buffers.set(e, t), this.lossSubscriptions.set(e, x(e, () => {
|
|
68
|
+
this.buffers.delete(e), this.lossSubscriptions.delete(e);
|
|
69
|
+
}))), t.version !== this.version && (e.queue.writeBuffer(t.buffer, 0, this.data), t.version = this.version), t.buffer;
|
|
70
|
+
}
|
|
71
|
+
update(t) {
|
|
72
|
+
if (!t) {
|
|
73
|
+
this.version++;
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
let { start: n, count: r } = t, i = e(this.type);
|
|
77
|
+
if (!Number.isInteger(n) || !Number.isInteger(r) || n < 0 || r < 1 || n + r > this.count) throw RangeError("Storage update range must be whole elements inside the buffer; pass start and count");
|
|
78
|
+
for (let [e, t] of this.buffers) t.version === this.version && e.queue.writeBuffer(t.buffer, n * i * 4, this.data, n * i, r * i);
|
|
79
|
+
}
|
|
80
|
+
element(e) {
|
|
81
|
+
return new s(this.type, "e" + this.id, [v(e)], (e, t) => {
|
|
82
|
+
let n = `${e.resource(this)}[${e.expr(t.args[0])}]`;
|
|
83
|
+
return this.atomic && e.stage.kind === "compute" ? `atomicLoad(&${n})` : n;
|
|
84
|
+
}, 32);
|
|
85
|
+
}
|
|
86
|
+
store(e, t) {
|
|
87
|
+
let n = {
|
|
88
|
+
buffer: this,
|
|
89
|
+
index: v(e),
|
|
90
|
+
value: r(t, this.type, "stored value")
|
|
91
|
+
};
|
|
92
|
+
return a.store?.(n), n;
|
|
93
|
+
}
|
|
94
|
+
atomicAdd(e, t) {
|
|
95
|
+
return this.rmw("atomicAdd", e, t);
|
|
96
|
+
}
|
|
97
|
+
atomicSub(e, t) {
|
|
98
|
+
return this.rmw("atomicSub", e, t);
|
|
99
|
+
}
|
|
100
|
+
atomicMax(e, t) {
|
|
101
|
+
return this.rmw("atomicMax", e, t);
|
|
102
|
+
}
|
|
103
|
+
atomicMin(e, t) {
|
|
104
|
+
return this.rmw("atomicMin", e, t);
|
|
105
|
+
}
|
|
106
|
+
atomicAnd(e, t) {
|
|
107
|
+
return this.rmw("atomicAnd", e, t);
|
|
108
|
+
}
|
|
109
|
+
atomicOr(e, t) {
|
|
110
|
+
return this.rmw("atomicOr", e, t);
|
|
111
|
+
}
|
|
112
|
+
atomicXor(e, t) {
|
|
113
|
+
return this.rmw("atomicXor", e, t);
|
|
114
|
+
}
|
|
115
|
+
atomicExchange(e, t) {
|
|
116
|
+
return this.rmw("atomicExchange", e, t);
|
|
117
|
+
}
|
|
118
|
+
atomicCompareExchange(e, t, n) {
|
|
119
|
+
return C(this.rmw("atomicCompareExchangeWeak", e, t, n));
|
|
120
|
+
}
|
|
121
|
+
atomicLoad(e) {
|
|
122
|
+
return this.rmw("atomicLoad", e);
|
|
123
|
+
}
|
|
124
|
+
atomicStore(e, t) {
|
|
125
|
+
return this.store(e, t);
|
|
126
|
+
}
|
|
127
|
+
rmw(e, t, ...n) {
|
|
128
|
+
if (!this.atomic) throw TypeError(`${e} needs storage(data, '${this.type}', {atomic: true})`);
|
|
129
|
+
return S(this, this.type, e, v(t), n.map((t) => r(t, this.type, e + " value")));
|
|
130
|
+
}
|
|
131
|
+
dispose() {
|
|
132
|
+
for (let e of this.lossSubscriptions.values()) e();
|
|
133
|
+
this.lossSubscriptions.clear();
|
|
134
|
+
for (let [e, t] of this.buffers) l(e, t.buffer);
|
|
135
|
+
this.buffers.clear();
|
|
136
|
+
}
|
|
137
|
+
[Symbol.dispose ?? Symbol()]() {
|
|
138
|
+
this.dispose();
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
function T(n, r, { atomic: i = !1 } = {}) {
|
|
142
|
+
let a = t(r), o = e(r);
|
|
143
|
+
return new w(typeof n == "number" ? new {
|
|
144
|
+
f32: Float32Array,
|
|
145
|
+
i32: Int32Array,
|
|
146
|
+
u32: Uint32Array
|
|
147
|
+
}[a](n * o) : n, r, i);
|
|
148
|
+
}
|
|
149
|
+
var E = /*@__PURE__*/ i("instanceIndex", "u32"), D = /*@__PURE__*/ i("globalId", "vec3u"), O = /*@__PURE__*/ i("localId", "vec3u"), k = /*@__PURE__*/ i("localIndex", "u32"), A = /*@__PURE__*/ i("workgroupId", "vec3u"), j = /*@__PURE__*/ i("workgroupCount", "vec3u"), M = {
|
|
150
|
+
localId: [
|
|
151
|
+
"lid",
|
|
152
|
+
"local_invocation_id",
|
|
153
|
+
"vec3u"
|
|
154
|
+
],
|
|
155
|
+
localIndex: [
|
|
156
|
+
"lix",
|
|
157
|
+
"local_invocation_index",
|
|
158
|
+
"u32"
|
|
159
|
+
],
|
|
160
|
+
workgroupId: [
|
|
161
|
+
"wid",
|
|
162
|
+
"workgroup_id",
|
|
163
|
+
"vec3u"
|
|
164
|
+
],
|
|
165
|
+
workgroupCount: [
|
|
166
|
+
"nwg",
|
|
167
|
+
"num_workgroups",
|
|
168
|
+
"vec3u"
|
|
169
|
+
],
|
|
170
|
+
subgroupSize: [
|
|
171
|
+
"sgs",
|
|
172
|
+
"subgroup_size",
|
|
173
|
+
"u32"
|
|
174
|
+
],
|
|
175
|
+
subgroupId: [
|
|
176
|
+
"sgi",
|
|
177
|
+
"subgroup_invocation_id",
|
|
178
|
+
"u32"
|
|
179
|
+
]
|
|
180
|
+
}, N = /* @__PURE__ */ new WeakSet(), P = (e) => void N.add(e), F = (e) => f(p([], (t) => {
|
|
181
|
+
if (t.stage.kind !== "compute") throw TypeError(`${e} is only available in ComputePass nodes; move it into a ComputePass body`);
|
|
182
|
+
N.add(t.program), t.line(`${e}();`), t.epoch++;
|
|
183
|
+
}), e);
|
|
184
|
+
function I() {
|
|
185
|
+
a.flush?.(), F("workgroupBarrier");
|
|
186
|
+
}
|
|
187
|
+
function L() {
|
|
188
|
+
a.flush?.(), F("storageBarrier");
|
|
189
|
+
}
|
|
190
|
+
function R() {
|
|
191
|
+
a.flush?.(), F("textureBarrier");
|
|
192
|
+
}
|
|
193
|
+
var z = class {
|
|
194
|
+
constructor(e, t, n = !1) {
|
|
195
|
+
if (this.count = e, this.type = t, this.atomic = n, this.prefix = "ndg", this.bindings = 0, this.id = c(), !Number.isInteger(e) || e < 1) throw RangeError("Workgroup memory needs a whole count of at least 1");
|
|
196
|
+
if (n && t !== "u32" && t !== "i32") throw TypeError("Atomic workgroup memory must be u32 or i32; pass one of those types or drop {atomic: true}.");
|
|
197
|
+
}
|
|
198
|
+
declare(e) {
|
|
199
|
+
return `var<workgroup> ${e}:array<${this.atomic ? `atomic<${this.type}>` : this.type}, ${this.count}>;`;
|
|
200
|
+
}
|
|
201
|
+
entries() {
|
|
202
|
+
return [];
|
|
203
|
+
}
|
|
204
|
+
element(e) {
|
|
205
|
+
return new s(this.type, "g" + this.id, [v(e)], (e, t) => {
|
|
206
|
+
if (e.stage.kind !== "compute") throw TypeError("Workgroup memory is only available in ComputePass nodes; move it into a ComputePass body");
|
|
207
|
+
let n = `${e.resource(this)}[${e.expr(t.args[0])}]`;
|
|
208
|
+
return this.atomic ? `atomicLoad(&${n})` : n;
|
|
209
|
+
}, 32);
|
|
210
|
+
}
|
|
211
|
+
store(e, t) {
|
|
212
|
+
h({
|
|
213
|
+
buffer: this,
|
|
214
|
+
index: v(e),
|
|
215
|
+
value: r(t, this.type, "stored value")
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
uniformLoad(e) {
|
|
219
|
+
if (this.atomic) throw TypeError("uniformLoad reads plain workgroup memory; use element() on atomic memory");
|
|
220
|
+
return m(new s(this.type, "g" + c(), [v(e)], (e, t) => (N.add(e.program), `workgroupUniformLoad(&${e.resource(this)}[${e.expr(t.args[0])}])`)));
|
|
221
|
+
}
|
|
222
|
+
rmw(e, t, ...n) {
|
|
223
|
+
if (!this.atomic) throw TypeError(`${e} needs workgroup(n, '${this.type}', {atomic: true})`);
|
|
224
|
+
return S(this, this.type, e, v(t), n.map((t) => r(t, this.type, e + " value")));
|
|
225
|
+
}
|
|
226
|
+
atomicAdd(e, t) {
|
|
227
|
+
return this.rmw("atomicAdd", e, t);
|
|
228
|
+
}
|
|
229
|
+
atomicSub(e, t) {
|
|
230
|
+
return this.rmw("atomicSub", e, t);
|
|
231
|
+
}
|
|
232
|
+
atomicMax(e, t) {
|
|
233
|
+
return this.rmw("atomicMax", e, t);
|
|
234
|
+
}
|
|
235
|
+
atomicMin(e, t) {
|
|
236
|
+
return this.rmw("atomicMin", e, t);
|
|
237
|
+
}
|
|
238
|
+
atomicAnd(e, t) {
|
|
239
|
+
return this.rmw("atomicAnd", e, t);
|
|
240
|
+
}
|
|
241
|
+
atomicOr(e, t) {
|
|
242
|
+
return this.rmw("atomicOr", e, t);
|
|
243
|
+
}
|
|
244
|
+
atomicXor(e, t) {
|
|
245
|
+
return this.rmw("atomicXor", e, t);
|
|
246
|
+
}
|
|
247
|
+
atomicExchange(e, t) {
|
|
248
|
+
return this.rmw("atomicExchange", e, t);
|
|
249
|
+
}
|
|
250
|
+
atomicCompareExchange(e, t, n) {
|
|
251
|
+
return C(this.rmw("atomicCompareExchangeWeak", e, t, n));
|
|
252
|
+
}
|
|
253
|
+
atomicLoad(e) {
|
|
254
|
+
return this.rmw("atomicLoad", e);
|
|
255
|
+
}
|
|
256
|
+
atomicStore(e, t) {
|
|
257
|
+
this.store(e, t);
|
|
258
|
+
}
|
|
259
|
+
}, B = (e, t, { atomic: n = !1 } = {}) => new z(e, t, n), V = 0, H = (e) => {
|
|
260
|
+
let [t, n = 1, r = 1] = typeof e == "number" ? [e] : e;
|
|
261
|
+
return [
|
|
262
|
+
t,
|
|
263
|
+
n,
|
|
264
|
+
r
|
|
265
|
+
];
|
|
266
|
+
}, U = (e) => typeof e == "number" ? 1 : e.length, W = class e {coreRequirement=__margoCoreRequirement("1.0.0",import.meta.url);
|
|
267
|
+
constructor(e, t, { workgroupSize: n = [
|
|
268
|
+
64,
|
|
269
|
+
[8, 8],
|
|
270
|
+
[
|
|
271
|
+
4,
|
|
272
|
+
4,
|
|
273
|
+
4
|
|
274
|
+
]
|
|
275
|
+
][U(e) - 1], order: r = -100, name: i = "shader:compute:" + V++, indirect: c, indirectOffset: l = 0 } = {}) {
|
|
276
|
+
this.count = e, this.program = new o(0, !0), this.last = [];
|
|
277
|
+
let u = H(e), d = H(n), f = u.map((e, t) => Math.ceil(e / d[t]));
|
|
278
|
+
if (u.some((e) => !Number.isInteger(e) || e < 1) || d.some((e) => !Number.isInteger(e) || e < 1) || d[0] * d[1] * d[2] > 256 || d[2] > 64 || !c && f.some((e) => e > 65535) || !Number.isFinite(r)) throw RangeError("ComputePass needs a whole count of at least 1 on each axis, a workgroup size of at most 256 invocations and 64 along z that dispatches at most 65535 groups per axis, and a finite order; adjust count or workgroupSize.");
|
|
279
|
+
if (c && (c.type !== "u32" || !(l >= 0) || l + 3 > c.count)) throw RangeError("indirect needs a u32 storage buffer with three elements at indirectOffset");
|
|
280
|
+
let { list: p, store: m, flush: g } = a, _ = a.list = [], v = [], y = /* @__PURE__ */ new Set();
|
|
281
|
+
a.store = (e) => v.push(e), a.flush = () => {
|
|
282
|
+
for (let e of v.splice(0)) y.add(e), h(e);
|
|
283
|
+
};
|
|
284
|
+
let b;
|
|
285
|
+
try {
|
|
286
|
+
b = t(E);
|
|
287
|
+
} finally {
|
|
288
|
+
a.list = p, a.store = m, a.flush = g;
|
|
289
|
+
}
|
|
290
|
+
let x = [b ?? []].flat(), S = x.filter((e) => !(e instanceof s));
|
|
291
|
+
if (!x.length && !_.length && !v.length || S.some((e) => !(e?.buffer instanceof w))) throw TypeError("A ComputePass body must make storage.store(...) writes, statements or atomic operations; add one to the body.");
|
|
292
|
+
let C = [.../* @__PURE__ */ new Set([...S, ...v])].filter((e) => !y.has(e)), T = [..._, ...x.filter((e) => e instanceof s)], D = this.program, O = U(e), k = /* @__PURE__ */ new Set(), A = {
|
|
293
|
+
instanceIndex: O === 1 ? "gid.x" : O === 2 ? `(gid.y * ${u[0]}u + gid.x)` : `((gid.z * ${u[1]}u + gid.y) * ${u[0]}u + gid.x)`,
|
|
294
|
+
globalId: "gid"
|
|
295
|
+
};
|
|
296
|
+
for (let e in M) A[e] = (t) => (k.add(e), t.local(M[e][0]));
|
|
297
|
+
let j = this.program.stage({
|
|
298
|
+
kind: "compute",
|
|
299
|
+
builtins: A
|
|
300
|
+
}, [...T, ...C.flatMap((e) => [e.index, e.value])]), P = T.length, F = [], I = (e) => {
|
|
301
|
+
if (C.length < 2 || !/\bnd[bg]\d|textureLoad/.test(e)) return e;
|
|
302
|
+
let t = D.name();
|
|
303
|
+
return F.push(` let ${t} = ${e};\n`), t;
|
|
304
|
+
}, L = C.map((e, t) => {
|
|
305
|
+
let n = `${D.resource(e.buffer)}[${I(j.values[P + t * 2])}]`, r = I(j.values[P + t * 2 + 1]);
|
|
306
|
+
return ` ${e.buffer.atomic ? `atomicStore(&${n}, ${r})` : `${n} = ${r}`};\n`;
|
|
307
|
+
}).join(""), R = N.has(D);
|
|
308
|
+
if (R && !c && u.some((e, t) => e % d[t])) throw RangeError("A ComputePass with a barrier runs whole workgroups, so its count must be a multiple of workgroupSize; adjust either one.");
|
|
309
|
+
let z = O === 1 ? `gid.x >= ${u[0]}u` : O === 2 ? `any(gid.xy >= vec2u(${u[0]}u, ${u[1]}u))` : `any(gid >= vec3u(${u[0]}u, ${u[1]}u, ${u[2]}u))`, B = R ? "" : ` if (${z}) { return; }\n`, W = [...k].map((e) => `, @builtin(${M[e][1]}) ${M[e][0]}:${M[e][2]}`).join(""), G = typeof n == "number" ? n : n.join(", ");
|
|
310
|
+
this.name = i, this.order = r, this.groups = f, this.indirect = c, this.indirectOffset = l, this.code = `${D.declare(0)}\n@compute @workgroup_size(${G}) fn main(@builtin(global_invocation_id) gid:vec3u${W}) {\n${B}${j.lines.map((e) => " " + e + "\n").join("")}${F.join("")}${L}}\n`;
|
|
311
|
+
}
|
|
312
|
+
static attach(t, n, r, i) {__margoAssertCore(t,__margoCoreRequirement("1.0.0",import.meta.url));
|
|
313
|
+
let a = new e(n, r, i);
|
|
314
|
+
return _(t).use(a), a;
|
|
315
|
+
}
|
|
316
|
+
setup(e) {
|
|
317
|
+
if (!e.gpu) throw new g("unsupported", "ComputePass requires WebGPU; see https://margoengine.com/errors#webgpu");
|
|
318
|
+
this.engine = e, d.hold(e, this);
|
|
319
|
+
}
|
|
320
|
+
registerPasses(e) {
|
|
321
|
+
e.add({
|
|
322
|
+
name: this.name,
|
|
323
|
+
order: this.order,
|
|
324
|
+
execute: (e) => {
|
|
325
|
+
e.backend === "webgpu" && this.dispatch(e);
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
dispatch(e) {
|
|
330
|
+
this.encode(e.device, e.encoder, {
|
|
331
|
+
width: e.width,
|
|
332
|
+
height: e.height,
|
|
333
|
+
time: d.find(this.engine)?.time ?? 0,
|
|
334
|
+
delta: e.delta
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
encode(e, t, r) {
|
|
338
|
+
this.pipeline ??= u(e, this.code, "main");
|
|
339
|
+
let i = this.program.entries(e, r);
|
|
340
|
+
(!this.group || !n(i, this.last)) && (this.last = i, this.group = e.createBindGroup({
|
|
341
|
+
layout: this.pipeline.getBindGroupLayout(0),
|
|
342
|
+
entries: i
|
|
343
|
+
}));
|
|
344
|
+
let a = t.beginComputePass();
|
|
345
|
+
a.setPipeline(this.pipeline), a.setBindGroup(0, this.group), this.indirect ? a.dispatchWorkgroupsIndirect(this.indirect.buffer(e), this.indirectOffset * 4) : a.dispatchWorkgroups(...this.groups), a.end();
|
|
346
|
+
for (let e of this.program.resources) e.resource.finish?.();
|
|
347
|
+
}
|
|
348
|
+
onDeviceRestored() {
|
|
349
|
+
this.pipeline = this.group = void 0;
|
|
350
|
+
}
|
|
351
|
+
dispose() {
|
|
352
|
+
let e = this.engine;
|
|
353
|
+
this.engine = void 0, this.onDeviceRestored(), d.release(e, this), e?.sceneOf(this)?.removePlugin(this.name);
|
|
354
|
+
}
|
|
355
|
+
[Symbol.dispose ?? Symbol()]() {
|
|
356
|
+
this.dispose();
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
//#endregion
|
|
360
|
+
export { E as a, x as c, R as d, P as f, A as g, j as h, D as i, T as l, I as m, w as n, O as o, B as p, z as r, k as s, W as t, L as u };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/// <reference lib="esnext.disposable" preserve="true" />
|
|
2
|
+
import { Node, type Builder, type NodeInput, type Resource } from './node.js';
|
|
3
|
+
import type { BindableTexture } from './texture.js';
|
|
4
|
+
import { type StorageFormat, type Texel } from './storage-format.js';
|
|
5
|
+
export type { StorageFormat, Texel } from './storage-format.js';
|
|
6
|
+
/** Options for `storageTexture` and `pingPong`. */
|
|
7
|
+
export interface StorageTextureOptions<F extends StorageFormat = StorageFormat> {
|
|
8
|
+
/** Default `'rgba16float'`: holds values outside 0..1 and can be filtered. */
|
|
9
|
+
format?: F;
|
|
10
|
+
/** First contents, row by row, `width * height * bytes per texel`; also what a device loss goes back to. Default zeros. */
|
|
11
|
+
data?: ArrayBufferView<ArrayBuffer>;
|
|
12
|
+
/** How `texture(t, uv)` filters. Default `'linear'`. */
|
|
13
|
+
filter?: 'linear' | 'nearest';
|
|
14
|
+
/** How `texture(t, uv)` treats coordinates outside 0..1. Default `'clamp-to-edge'`. */
|
|
15
|
+
wrap?: 'clamp-to-edge' | 'repeat' | 'mirror-repeat';
|
|
16
|
+
}
|
|
17
|
+
type Coord = Node<'vec2u' | 'vec2i'>;
|
|
18
|
+
interface Image {
|
|
19
|
+
texture: GPUTexture;
|
|
20
|
+
view: GPUTextureView;
|
|
21
|
+
}
|
|
22
|
+
/** What `storageTexture` and `pingPong` share: reads, writes, and being a texture for `texture()`. */
|
|
23
|
+
export declare abstract class ComputeTexture<F extends StorageFormat = StorageFormat> implements BindableTexture {
|
|
24
|
+
readonly width: number;
|
|
25
|
+
readonly height: number;
|
|
26
|
+
readonly format: F;
|
|
27
|
+
readonly data?: ArrayBufferView<ArrayBuffer>;
|
|
28
|
+
/** `width * height`: the count for a ComputePass with one invocation per texel. */
|
|
29
|
+
readonly pixels: number;
|
|
30
|
+
private readonly id;
|
|
31
|
+
private readonly filter;
|
|
32
|
+
private readonly wrap;
|
|
33
|
+
private readonly samplers;
|
|
34
|
+
/** @internal */ protected abstract readonly reader: Resource;
|
|
35
|
+
/** @internal */ protected abstract readonly writer: Resource;
|
|
36
|
+
/** @internal The image `load` and `texture()` read. */ protected abstract front(device: GPUDevice): Image;
|
|
37
|
+
/** @internal Called when a node reads (1) or writes (2) this texture. */ protected use(_b: Builder, _how: number): void;
|
|
38
|
+
constructor(width: number, height: number, options?: StorageTextureOptions<F>);
|
|
39
|
+
/** The texel at `coord` as it is at the start of the dispatch (no filtering; `texture(t, uv, 0)` filters). */
|
|
40
|
+
load(coord: Coord): Node<Texel<F>>;
|
|
41
|
+
/** @internal */ protected loaded(name: string, at: string): string;
|
|
42
|
+
/**
|
|
43
|
+
* Writes `value` to the texel at `coord`, here in the body. A number or scalar fills all four components.
|
|
44
|
+
* @throws TypeError outside a ComputePass body, or when `value` has the wrong type.
|
|
45
|
+
*/
|
|
46
|
+
store(coord: Coord, value: NodeInput<Texel<F>> | NodeInput<'f32' | 'i32' | 'u32'>): Node;
|
|
47
|
+
/** The texel that invocation `i` of a one-per-texel ComputePass owns: `(i % width, i / width)`. */
|
|
48
|
+
coord(i: Node<'u32'>): Node<'vec2u'>;
|
|
49
|
+
/** The 0..1 coordinate of the centre of a texel, for `texture(t, uv, 0)`. */
|
|
50
|
+
uv(coord: Coord): Node<'vec2f'>;
|
|
51
|
+
/** @internal `texture(t)`: what a material, NodePass or compute body samples. Formats that cannot filter have `load`. */
|
|
52
|
+
bind(device: GPUDevice): [GPUTextureView, GPUSampler];
|
|
53
|
+
/** The GPU texture holding the latest contents, to copy from or hand to other code. */
|
|
54
|
+
texture(device: GPUDevice): GPUTexture;
|
|
55
|
+
/** Destroys the GPU copies; a later use makes them again from `data`. */
|
|
56
|
+
abstract dispose(): void;
|
|
57
|
+
[Symbol.dispose]: () => void;
|
|
58
|
+
}
|
|
59
|
+
/** Options for `storageTexture`. */
|
|
60
|
+
export interface SingleStorageOptions<F extends StorageFormat = StorageFormat> extends StorageTextureOptions<F> {
|
|
61
|
+
/**
|
|
62
|
+
* Lets one pass `load` and `store` this texture in place, each invocation on its own texels. r32float, r32uint and
|
|
63
|
+
* r32sint only, and the browser must have the WGSL feature `readonly_and_readwrite_storage_textures`. Default false.
|
|
64
|
+
*/
|
|
65
|
+
readWrite?: boolean;
|
|
66
|
+
}
|
|
67
|
+
/** A texture a ComputePass writes and anything else reads. A pass either reads or writes it; {@link PingPongTexture} does both. */
|
|
68
|
+
export declare class StorageTexture<F extends StorageFormat = StorageFormat> extends ComputeTexture<F> {
|
|
69
|
+
/** True when one pass may both load and store it. */
|
|
70
|
+
readonly readWrite: boolean;
|
|
71
|
+
private readonly images;
|
|
72
|
+
private readonly passes;
|
|
73
|
+
protected readonly reader: Resource;
|
|
74
|
+
protected readonly writer: Resource;
|
|
75
|
+
constructor(width: number, height: number, options?: SingleStorageOptions<F>);
|
|
76
|
+
protected front(device: GPUDevice): Image;
|
|
77
|
+
protected use(b: Builder, how: number): void;
|
|
78
|
+
protected loaded(name: string, at: string): string;
|
|
79
|
+
dispose(): void;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Two textures of one size: `load` and `texture()` read the front one, `store` writes the back one, and they swap after
|
|
83
|
+
* each dispatch of a pass that stores, so a pass reads last step's result and writes the next. A pass must write every
|
|
84
|
+
* texel it wants kept: the back image holds the step before last.
|
|
85
|
+
*/
|
|
86
|
+
export declare class PingPongTexture<F extends StorageFormat = StorageFormat> extends ComputeTexture<F> {
|
|
87
|
+
private readonly images;
|
|
88
|
+
private current;
|
|
89
|
+
protected readonly reader: Resource;
|
|
90
|
+
protected readonly writer: Resource;
|
|
91
|
+
constructor(width: number, height: number, options?: StorageTextureOptions<F>);
|
|
92
|
+
protected front(device: GPUDevice): Image;
|
|
93
|
+
/** Swaps by hand. A pass that stores does this after each dispatch. */
|
|
94
|
+
swap(): void;
|
|
95
|
+
dispose(): void;
|
|
96
|
+
}
|
|
97
|
+
/** A texture a ComputePass writes: `const t = storageTexture(256, 256); ComputePass.attach(engine, t.pixels, i => t.store(t.coord(i), vec4(1)));`. */
|
|
98
|
+
export declare const storageTexture: <F extends StorageFormat = 'rgba16float'>(width: number, height: number, options?: SingleStorageOptions<F>) => StorageTexture<F>;
|
|
99
|
+
/** A pair a ComputePass reads and writes in steps, for simulations and repeated filters: see {@link PingPongTexture}. */
|
|
100
|
+
export declare const pingPong: <F extends StorageFormat = 'rgba16float'>(width: number, height: number, options?: StorageTextureOptions<F>) => PingPongTexture<F>;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { T as e, o as t, rn as n, sn as r, tn as i } from "./node-B6yoIC9V.js";
|
|
2
|
+
import { d as a, f as o } from "./control-CFjkGPBk.js";
|
|
3
|
+
import { c as s } from "./compute-CXGG9qvI.js";
|
|
4
|
+
import { n as c, r as l, t as u } from "./storage-format-DWaiSxmq.js";
|
|
5
|
+
import { MargoError as d } from "@margoengine/math/errors";
|
|
6
|
+
//#region src/compute-texture.ts
|
|
7
|
+
var f = (e) => {
|
|
8
|
+
if (e?.type !== "vec2u" && e?.type !== "vec2i") throw TypeError(`A texture coordinate must be vec2u or vec2i, got ${e?.type}`);
|
|
9
|
+
return e;
|
|
10
|
+
}, p = class {
|
|
11
|
+
constructor(e) {
|
|
12
|
+
this.owner = e, this.images = /* @__PURE__ */ new Map();
|
|
13
|
+
}
|
|
14
|
+
get(e) {
|
|
15
|
+
let t = this.images.get(e);
|
|
16
|
+
if (!t) {
|
|
17
|
+
let { width: n, height: r, format: i, data: a } = this.owner, o = e.createTexture({
|
|
18
|
+
label: "shader:storage-texture",
|
|
19
|
+
size: [n, r],
|
|
20
|
+
format: i,
|
|
21
|
+
usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.STORAGE_BINDING | GPUTextureUsage.COPY_SRC | GPUTextureUsage.COPY_DST
|
|
22
|
+
});
|
|
23
|
+
a && e.queue.writeTexture({ texture: o }, a, {
|
|
24
|
+
bytesPerRow: n * u[i],
|
|
25
|
+
rowsPerImage: r
|
|
26
|
+
}, [n, r]), t = {
|
|
27
|
+
image: {
|
|
28
|
+
texture: o,
|
|
29
|
+
view: o.createView()
|
|
30
|
+
},
|
|
31
|
+
stop: s(e, () => this.images.delete(e))
|
|
32
|
+
}, this.images.set(e, t);
|
|
33
|
+
}
|
|
34
|
+
return t.image;
|
|
35
|
+
}
|
|
36
|
+
dispose() {
|
|
37
|
+
for (let e of this.images.values()) e.stop(), e.image.texture.destroy();
|
|
38
|
+
this.images.clear();
|
|
39
|
+
}
|
|
40
|
+
}, m = class {
|
|
41
|
+
use(e, t) {}
|
|
42
|
+
constructor(e, t, n = {}) {
|
|
43
|
+
this.width = e, this.height = t, this.id = i(), this.samplers = /* @__PURE__ */ new WeakMap();
|
|
44
|
+
let { format: r = "rgba16float", data: a, filter: o = "linear", wrap: s = "clamp-to-edge" } = n;
|
|
45
|
+
if (!Number.isInteger(e) || !Number.isInteger(t) || e < 1 || t < 1) throw RangeError("A storage texture needs an integer width and height of at least 1");
|
|
46
|
+
if (!(r in u)) throw TypeError(`${String(r)} is not a storage format; use one of ${Object.keys(u).join(", ")}`);
|
|
47
|
+
if (a && a.byteLength !== e * t * u[r]) throw RangeError(`Storage texture data must be ${e * t * u[r]} bytes for ${e} x ${t} ${r}, got ${a.byteLength}`);
|
|
48
|
+
this.format = r, this.data = a, this.pixels = e * t, this.filter = o, this.wrap = s;
|
|
49
|
+
}
|
|
50
|
+
load(e) {
|
|
51
|
+
return new t(l(this.format), "x" + this.id, [f(e)], (e, t) => (this.use(e, 1), this.loaded(e.resource(this.reader), e.expr(t.args[0]))), 32);
|
|
52
|
+
}
|
|
53
|
+
loaded(e, t) {
|
|
54
|
+
return `textureLoad(${e}, ${t}, 0)`;
|
|
55
|
+
}
|
|
56
|
+
store(t, n) {
|
|
57
|
+
let r = l(this.format);
|
|
58
|
+
return a(o([f(t), e(n, r, "stored texel")], (e, t) => {
|
|
59
|
+
if (e.stage.kind !== "compute") throw TypeError("Storage textures are only written in ComputePass nodes; move the store into a ComputePass body");
|
|
60
|
+
this.use(e, 2);
|
|
61
|
+
let [n, r] = t.args.map((t) => e.expr(t));
|
|
62
|
+
e.line(`textureStore(${e.resource(this.writer)}, ${n}, ${r});`), e.epoch++;
|
|
63
|
+
}), "store");
|
|
64
|
+
}
|
|
65
|
+
coord(e) {
|
|
66
|
+
return n(e.mod(this.width), e.div(this.width));
|
|
67
|
+
}
|
|
68
|
+
uv(e) {
|
|
69
|
+
return r(e.toFloat().add(.5)).div(r(this.width, this.height));
|
|
70
|
+
}
|
|
71
|
+
bind(e) {
|
|
72
|
+
if (c(this.format) !== "f32" || /32float$/.test(this.format) && !e.features.has("float32-filterable")) throw new d("unsupported", `${this.format} cannot be sampled on this device; read it with load(), or use rgba16float`);
|
|
73
|
+
let t = this.samplers.get(e);
|
|
74
|
+
return t || (t = e.createSampler({
|
|
75
|
+
magFilter: this.filter,
|
|
76
|
+
minFilter: this.filter,
|
|
77
|
+
addressModeU: this.wrap,
|
|
78
|
+
addressModeV: this.wrap
|
|
79
|
+
}), this.samplers.set(e, t)), [this.front(e).view, t];
|
|
80
|
+
}
|
|
81
|
+
texture(e) {
|
|
82
|
+
return this.front(e).texture;
|
|
83
|
+
}
|
|
84
|
+
[Symbol.dispose ?? Symbol()]() {
|
|
85
|
+
this.dispose();
|
|
86
|
+
}
|
|
87
|
+
}, h = (e, t, n, r) => ({
|
|
88
|
+
prefix: e,
|
|
89
|
+
bindings: 1,
|
|
90
|
+
declare: (e, n, r) => `@group(${n}) @binding(${r}) var ${e}:${t};`,
|
|
91
|
+
entries: (e) => [n(e)],
|
|
92
|
+
finish: r
|
|
93
|
+
}), g = "readonly_and_readwrite_storage_textures", _ = class extends m {
|
|
94
|
+
constructor(e, t, n = {}) {
|
|
95
|
+
if (super(e, t, n), this.images = new p(this), this.passes = /* @__PURE__ */ new WeakMap(), this.readWrite = !!n.readWrite, this.readWrite && !/^r32/.test(this.format)) throw TypeError("readWrite needs r32float, r32uint or r32sint; use pingPong() for other formats");
|
|
96
|
+
let r = (e) => this.images.get(e).view;
|
|
97
|
+
this.writer = this.readWrite ? h("ndw", `texture_storage_2d<${this.format}, read_write>`, (e) => {
|
|
98
|
+
if (!navigator.gpu?.wgslLanguageFeatures?.has(g)) throw new d("unsupported", `This browser lacks the WGSL feature ${g}; use pingPong()`);
|
|
99
|
+
return r(e);
|
|
100
|
+
}) : h("ndw", `texture_storage_2d<${this.format}, write>`, r), this.reader = this.readWrite ? this.writer : h("ndr", `texture_2d<${c(this.format)}>`, r);
|
|
101
|
+
}
|
|
102
|
+
front(e) {
|
|
103
|
+
return this.images.get(e);
|
|
104
|
+
}
|
|
105
|
+
use(e, t) {
|
|
106
|
+
if (this.readWrite) return;
|
|
107
|
+
let n = (this.passes.get(e.program) ?? 0) | t;
|
|
108
|
+
if (this.passes.set(e.program, n), n === 3) throw TypeError("One pass cannot load and store the same storage texture; use pingPong(), or readWrite for r32 formats");
|
|
109
|
+
}
|
|
110
|
+
loaded(e, t) {
|
|
111
|
+
return this.readWrite ? `textureLoad(${e}, ${t})` : super.loaded(e, t);
|
|
112
|
+
}
|
|
113
|
+
dispose() {
|
|
114
|
+
this.images.dispose();
|
|
115
|
+
}
|
|
116
|
+
}, v = class extends m {
|
|
117
|
+
constructor(e, t, n = {}) {
|
|
118
|
+
super(e, t, n), this.images = [new p(this), new p(this)], this.current = 0, this.reader = h("ndr", `texture_2d<${c(this.format)}>`, (e) => this.front(e).view), this.writer = h("ndw", `texture_storage_2d<${this.format}, write>`, (e) => this.images[1 - this.current].get(e).view, () => this.swap());
|
|
119
|
+
}
|
|
120
|
+
front(e) {
|
|
121
|
+
return this.images[this.current].get(e);
|
|
122
|
+
}
|
|
123
|
+
swap() {
|
|
124
|
+
this.current = 1 - this.current;
|
|
125
|
+
}
|
|
126
|
+
dispose() {
|
|
127
|
+
for (let e of this.images) e.dispose();
|
|
128
|
+
}
|
|
129
|
+
}, y = (e, t, n) => new _(e, t, n), b = (e, t, n) => new v(e, t, n);
|
|
130
|
+
//#endregion
|
|
131
|
+
export { m as ComputeTexture, v as PingPongTexture, _ as StorageTexture, b as pingPong, y as storageTexture };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/// <reference lib="esnext.disposable" preserve="true" />
|
|
2
|
+
import { Node, type NodeInput } from './node.js';
|
|
3
|
+
import { type StorageFormat, type Texel } from './storage-format.js';
|
|
4
|
+
import type { StorageTextureOptions } from './compute-texture.js';
|
|
5
|
+
import type { BindableTexture } from './texture.js';
|
|
6
|
+
/** Options for a writable volume or layered image. */
|
|
7
|
+
export interface ComputeVolumeOptions<F extends StorageFormat = StorageFormat> extends StorageTextureOptions<F> {
|
|
8
|
+
/** Default '3d'. '2d-array' keeps each layer separate when sampling. */
|
|
9
|
+
dimension?: '3d' | '2d-array';
|
|
10
|
+
/** Keep two images and swap after each writing dispatch. Default false. */
|
|
11
|
+
pingPong?: boolean;
|
|
12
|
+
/** In-place r32 access, requiring readonly_and_readwrite_storage_textures. Default false. */
|
|
13
|
+
readWrite?: boolean;
|
|
14
|
+
}
|
|
15
|
+
type Coord = Node<'vec3u' | 'vec3i'>;
|
|
16
|
+
/** A storage texture with depth or array layers, usable by ComputePass, NodePass and NodeMaterial. */
|
|
17
|
+
export declare class ComputeVolume<F extends StorageFormat = StorageFormat> implements BindableTexture {
|
|
18
|
+
readonly width: number;
|
|
19
|
+
readonly height: number;
|
|
20
|
+
readonly depth: number;
|
|
21
|
+
readonly dimension: '3d' | '2d-array';
|
|
22
|
+
readonly format: F;
|
|
23
|
+
readonly data?: ArrayBufferView<ArrayBuffer>;
|
|
24
|
+
/** Width times height times depth; one invocation per voxel with coord(i). */
|
|
25
|
+
readonly pixels: number;
|
|
26
|
+
readonly pingPong: boolean;
|
|
27
|
+
readonly readWrite: boolean;
|
|
28
|
+
private readonly id;
|
|
29
|
+
private readonly devices;
|
|
30
|
+
private readonly uses;
|
|
31
|
+
private readonly reader;
|
|
32
|
+
private readonly writer;
|
|
33
|
+
private readonly filter;
|
|
34
|
+
private readonly wrap;
|
|
35
|
+
constructor(width: number, height: number, depth: number, options?: ComputeVolumeOptions<F>);
|
|
36
|
+
private images;
|
|
37
|
+
private use;
|
|
38
|
+
private at;
|
|
39
|
+
/** Unfiltered voxel or layer texel, with integer x, y, z coordinates. */
|
|
40
|
+
load(at: Coord): Node<Texel<F>>;
|
|
41
|
+
/** Writes a voxel in a ComputePass body; z selects the layer for 2d-array. */
|
|
42
|
+
store(at: Coord, value: NodeInput<Texel<F>>): Node;
|
|
43
|
+
/** Maps a linear invocation index to integer x, y, z, with x contiguous. */
|
|
44
|
+
coord(i: Node<'u32'>): Node<'vec3u'>;
|
|
45
|
+
/** Normalized voxel centre; for arrays use xy as UV and integer coord.z as the layer. */
|
|
46
|
+
uv(at: Coord): Node<'vec3f'>;
|
|
47
|
+
/** Sampling view and sampler of the latest image. Integer formats use load(). */
|
|
48
|
+
bind(device: GPUDevice): [GPUTextureView, GPUSampler];
|
|
49
|
+
/** Latest GPU image for copies or other passes. */
|
|
50
|
+
texture(device: GPUDevice): GPUTexture;
|
|
51
|
+
/** Release all device copies; later use starts again from data. */
|
|
52
|
+
dispose(): void;
|
|
53
|
+
[Symbol.dispose]: () => void;
|
|
54
|
+
}
|
|
55
|
+
/** Creates a writable 3D texture, or a 2D array with dimension: '2d-array'. */
|
|
56
|
+
export declare const storageVolume: <F extends StorageFormat = 'rgba16float'>(width: number, height: number, depth: number, options?: ComputeVolumeOptions<F>) => ComputeVolume<F>;
|
|
57
|
+
export {};
|