/ proof-of-concept / cymsimweb
Sign in
proof-of-concept / cymsimweb
cymsimweb / src / gpu / simulator.ts
293 lines · 20.4 KBBlameHistoryRaw
1// WebGPU time loop: packs the set-up into storage buffers, compiles the four kernels and runs
2// the sub-steps of a chunk of audio samples as one command buffer. Works in a browser and under
3// Node with the `webgpu` (Dawn) package, which the tests use.
4import { HOLD_HEIGHT } from "../model/exciter.ts";
5import { strainEnergies } from "../model/forces.ts";
6import { DECIMATION_SPAN, DELAY_TAPS } from "../model/radiation.ts";
7import type { Setup } from "../model/setup.ts";
8import type { BackendOptions, BackendState, ChunkResult, Diagnostics, SimulatorBackend } from "../model/simulator.ts";
9import { CHUNK_WORDS, ELEM_STRIDE, GATHER_ELEMS, HIT_HEADER, HITU_HEADER, NODE_STRIDE, RADCOEF_STRIDE, STATE_FLOATS, SYNC_HEADER, WORKGROUP_NODES, shaderSource } from "./shaders.ts";
11// evaluated lazily: under Node the WebGPU globals are installed after this module is imported
12const storageUsage = () => GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST | GPUBufferUsage.COPY_SRC;
14/** Largest per-chunk output buffer (acceleration rows or movie frames) we allocate on the GPU. */
15const OUTPUT_BUDGET = 64e6;
17export class GpuSimulator implements SimulatorBackend {
18 readonly kind = "gpu" as const;
19 readonly setup: Setup; readonly device: GPUDevice;
20 samplesDone = 0;
21 private step = 0;
22 private readonly G: number; private readonly GE: number; private readonly HF: number; private readonly HU: number;
23 private readonly buffers: Record<string, GPUBuffer> = {};
24 private readonly pipelines: Record<string, GPUComputePipeline> = {};
25 private readonly bindGroups: Record<string, GPUBindGroup> = {};
26 private readonly chunkCapacity: number; readonly movieEvery: number; readonly dispEvery: number; readonly recordAcceleration: boolean;
27 private readonly framesCapacity: number; private readonly dispCapacity: number; private readonly accRows: number;
28 private readonly stagingPressure: GPUBuffer; private readonly stagingState: GPUBuffer; private readonly stagingHits: GPUBuffer; private readonly stagingHitsU: GPUBuffer;
29 private readonly stagingMovie: GPUBuffer | null; private readonly stagingDisp: GPUBuffer | null; private readonly stagingAcc: GPUBuffer | null;
30 private readonly radStateFloats: number; // accumulator slots, node history and the current sample's sub-step accelerations: the part of `rad` that is state
32 constructor(device: GPUDevice, setup: Setup, chunkCapacity = 8192, opts: BackendOptions | number = {}) {
33 if (typeof opts === "number") opts = { movieEvery: opts };
34 this.device = device; this.setup = setup;
35 this.movieEvery = opts.movieEvery ?? 0; this.dispEvery = opts.dispEvery ?? 0; this.recordAcceleration = opts.recordAcceleration ?? false;
36 const Nn = setup.mesh.n;
37 // a chunk's outputs (movie frames, acceleration rows) stay under the budget
38 if (this.movieEvery > 0) chunkCapacity = Math.max(128, Math.min(chunkCapacity, Math.floor((OUTPUT_BUDGET / (4 * Nn)) * this.movieEvery)));
39 if (this.recordAcceleration) chunkCapacity = Math.max(128, Math.min(chunkCapacity, Math.floor(OUTPUT_BUDGET / (4 * Nn)) - 2));
40 this.chunkCapacity = chunkCapacity;
41 this.framesCapacity = this.movieEvery > 0 ? Math.ceil(chunkCapacity / this.movieEvery) + 2 : 0;
42 this.dispCapacity = this.dispEvery > 0 ? Math.ceil(chunkCapacity / this.dispEvery) + 2 : 0;
43 this.accRows = this.recordAcceleration ? chunkCapacity + 2 : 0;
44 const { mesh, shell: sh, schedule: sc, radiation: rad, substeps: M } = setup;
45 const N = mesh.n, E = mesh.e, K = sc.K, P = sc.P, W = DECIMATION_SPAN, D = rad.ringLength, T = DELAY_TAPS;
46 this.G = Math.ceil(N / WORKGROUP_NODES); this.GE = Math.ceil(E / GATHER_ELEMS);
47 this.HF = HIT_HEADER + 5 * P; this.HU = HITU_HEADER + 3 * P;
48 const G = this.G, HF = this.HF, HU = this.HU;
49 this.radStateFloats = (W + D + M) * N;
51 // ---- pack the set-up
52 // field-major: field f of element e at f * E + e, of node n at f * N + n
53 const elemF = new Float32Array(ELEM_STRIDE * E);
54 for (let e = 0; e < E; e++) {
55 const set = (f: number, x: number) => { elemF[f * E + e] = x; };
56 for (let i = 0; i < 3; i++) { set(i, mesh.Gx[3 * e + i]); set(3 + i, mesh.Gy[3 * e + i]); }
57 set(6, mesh.area[e]); set(7, sh.z0x[e]); set(8, sh.z0y[e]);
58 set(9, sh.Cm[3 * e]); set(10, sh.Cm[3 * e + 1]); set(11, sh.Cm[3 * e + 2]);
59 set(12, 2 * setup.config.material.sigma1 * sh.rhoHA[e]);
60 // upper triangle of K_e, symmetrised in float64 (it is symmetric to round-off)
61 const K = sh.Ke.subarray(81 * e, 81 * e + 81);
62 for (let i = 0, f = 13; i < 9; i++) for (let j = i; j < 9; j++) set(f++, 0.5 * (K[9 * i + j] + K[9 * j + i]));
63 }
64 const elemU = new Uint32Array(3 * E); elemU.set(mesh.tri);
65 const nodeF = new Float32Array(NODE_STRIDE * N + W * M);
66 for (let n = 0; n < N; n++) {
67 const set = (f: number, x: number) => { nodeF[f * N + n] = x; };
68 for (let d = 0; d < 5; d++) { set(d, sh.Minv[5 * n + d]); set(5 + d, sh.M[5 * n + d]); }
69 for (let k = 0; k < 6; k++) for (let d = 0; d < 5; d++) set(10 + 5 * k + d, sh.Rm[(k * N + n) * 5 + d]);
70 for (let d = 0; d < 3; d++) set(40 + d, sh.normalNode[3 * n + d]);
71 }
72 nodeF.set(rad.taps, NODE_STRIDE * N);
73 const adj = new Uint32Array(N + 1 + sh.adjEntries.length); adj.set(sh.adjOffsets); adj.set(sh.adjEntries, N + 1);
74 const hitsF = new Float32Array(HF * K), hitsU = new Uint32Array(HU * K);
75 for (let k = 0; k < K; k++) {
76 const hf = HF * k, hu = HU * k;
77 hitsF[hf] = sc.kPoint[k]; hitsF[hf + 1] = sc.alpha[k]; hitsF[hf + 2] = sc.mass[k]; hitsF[hf + 3] = sc.gap[k];
78 hitsF[hf + 4] = sc.velocity[k]; hitsF[hf + 5] = HOLD_HEIGHT; hitsF[hf + 6] = 0; hitsF[hf + 7] = 0; hitsF[hf + 8] = 0;
79 for (let p = 0; p < P; p++) {
80 for (let i = 0; i < 3; i++) { hitsF[hf + HIT_HEADER + 3 * p + i] = sc.weights[(k * P + p) * 3 + i]; hitsU[hu + HITU_HEADER + 3 * p + i] = sc.nodes[(k * P + p) * 3 + i]; }
81 hitsF[hf + HIT_HEADER + 3 * P + p] = sc.offsets[k * P + p];
82 }
83 hitsU[hu] = sc.releaseStep[k]; hitsU[hu + 1] = 0;
84 }
85 const radCoef = new Float32Array(RADCOEF_STRIDE * E);
86 for (let e = 0; e < E; e++) {
87 const b = RADCOEF_STRIDE * e;
88 radCoef[b] = rad.coefF[e]; radCoef[b + 1] = rad.coefB[e]; radCoef[b + 2] = rad.i0F[e]; radCoef[b + 3] = rad.i0B[e];
89 for (let t = 0; t < T; t++) { radCoef[b + 4 + t] = rad.tapsF[e * T + t]; radCoef[b + 4 + T + t] = rad.tapsB[e * T + t]; }
90 }
91 const mk = (name: string, data: Float32Array | Uint32Array, usage = storageUsage()) => {
92 const buf = device.createBuffer({ label: name, size: Math.max(16, data.byteLength), usage });
93 device.queue.writeBuffer(buf, 0, data.buffer, data.byteOffset, data.byteLength);
94 this.buffers[name] = buf;
95 return buf;
96 };
97 const mkEmpty = (name: string, floats: number) => {
98 const buf = device.createBuffer({ label: name, size: Math.max(16, 4 * floats), usage: storageUsage() });
99 this.buffers[name] = buf;
100 return buf;
101 };
102 mk("elemF", elemF); mk("elemU", elemU); mk("nodeF", nodeF); mk("adj", adj); mk("radCoef", radCoef);
103 mk("hitsF", hitsF); mk("hitsU", hitsU);
104 mkEmpty("state", STATE_FLOATS * N); mkEmpty("elemForce", 15 * E);
105 mkEmpty("sync", SYNC_HEADER + 2 * G * 12); mkEmpty("rad", this.radStateFloats + this.accRows * N); mkEmpty("elemHist", D * E);
106 mkEmpty("pressure", 2 * chunkCapacity * this.GE); // one partial sum per gather workgroup
107 const uniform = (name: string) => { const b = device.createBuffer({ label: name, size: 4 * CHUNK_WORDS, usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST }); this.buffers[name] = b; return b; };
108 uniform("chunk"); uniform("chunkD");
109 const staging = (size: number) => device.createBuffer({ size: Math.max(16, size), usage: GPUBufferUsage.MAP_READ | GPUBufferUsage.COPY_DST });
110 this.stagingPressure = staging(8 * chunkCapacity * this.GE); this.stagingState = staging(STATE_FLOATS * N * 4);
111 this.stagingHits = staging(HF * K * 4); this.stagingHitsU = staging(HU * K * 4);
112 this.stagingMovie = this.framesCapacity > 0 ? (mkEmpty("movie", this.framesCapacity * N), staging(this.framesCapacity * N * 4)) : null;
113 this.stagingDisp = this.dispCapacity > 0 ? (mkEmpty("disp", this.dispCapacity * N), staging(this.dispCapacity * N * 4)) : null;
114 this.stagingAcc = this.accRows > 0 ? staging(this.accRows * N * 4) : null;
116 // ---- pipelines
117 const module = device.createShaderModule({ code: shaderSource({ N, E, K, P, M, W, D, G, T, accRows: this.accRows, dt: setup.dt, sigma0: setup.config.material.sigma0, nl: sh.nl }) });
118 type Kind = "read-only-storage" | "storage" | "uniform";
119 const bgl = (entries: [number, Kind][]) => device.createBindGroupLayout({
120 entries: entries.map(([binding, type]) => ({ binding, visibility: GPUShaderStage.COMPUTE, buffer: { type } })),
121 });
122 const L0 = bgl([[0, "read-only-storage"], [1, "read-only-storage"], [2, "read-only-storage"], [3, "storage"], [4, "storage"], [5, "read-only-storage"], [6, "storage"]]);
123 const L1 = bgl([[0, "storage"], [1, "read-only-storage"], [2, "read-only-storage"], [3, "read-only-storage"], [4, "storage"], [5, "storage"], [6, "storage"], [7, "storage"], [8, "uniform"]]);
124 const L2 = bgl([[0, "read-only-storage"], [1, "read-only-storage"], [2, "read-only-storage"], [3, "storage"], [4, "uniform"], [5, "storage"], [6, "read-only-storage"]]);
125 const L3 = bgl([[0, "read-only-storage"], [1, "storage"], [2, "uniform"], [3, "read-only-storage"]]);
126 const empty = device.createBindGroupLayout({ entries: [] });
127 const mkPipe = (entryPoint: string, layouts: GPUBindGroupLayout[]) => device.createComputePipeline({
128 label: entryPoint, layout: device.createPipelineLayout({ bindGroupLayouts: layouts }), compute: { module, entryPoint },
129 });
130 this.pipelines.element = mkPipe("elementPass", [L0]);
131 this.pipelines.node = mkPipe("nodePass", [empty, L1]);
132 this.pipelines.gather = mkPipe("gatherPass", [empty, empty, L2]);
133 if (this.framesCapacity > 0 || this.dispCapacity > 0) this.pipelines.capture = mkPipe("capturePass", [empty, empty, empty, L3]);
134 const B = this.buffers;
135 const bg = (layout: GPUBindGroupLayout, bufs: GPUBuffer[]) => device.createBindGroup({ layout, entries: bufs.map((buffer, binding) => ({ binding, resource: { buffer } })) });
136 this.bindGroups.element = bg(L0, [B.elemF, B.elemU, B.state, B.elemForce, B.hitsF, B.hitsU, B.sync]);
137 this.bindGroups.node = bg(L1, [B.state, B.elemForce, B.nodeF, B.adj, B.hitsF, B.hitsU, B.sync, B.rad, B.chunk]);
138 this.bindGroups.gather = bg(L2, [B.sync, B.rad, B.radCoef, B.pressure, B.chunk, B.elemHist, B.elemU]);
139 if (this.framesCapacity > 0) this.bindGroups.capture = bg(L3, [B.state, B.movie, B.chunk, B.sync]);
140 if (this.dispCapacity > 0) this.bindGroups.captureDisp = bg(L3, [B.state, B.disp, B.chunkD, B.sync]);
141 this.bindGroups.empty = device.createBindGroup({ layout: empty, entries: [] });
142 }
144 /** Audio sample finished by the node pass of sub-step n (the acceleration of s = n - 1), or -1 when none. */
145 private sampleDueAt(n: number): number {
146 const M = this.setup.substeps, W = DECIMATION_SPAN;
147 if (n < 1 || (n - 1) % M !== 0) return -1;
148 const j = (n - 1) / M - W / 2;
149 return j >= 0 ? j : -1;
150 }
152 get maxChunk() { return this.chunkCapacity; }
154 private capture(pass: GPUComputePassEncoder, group: GPUBindGroup) {
155 pass.setPipeline(this.pipelines.capture); pass.setBindGroup(0, this.bindGroups.empty); pass.setBindGroup(1, this.bindGroups.empty);
156 pass.setBindGroup(2, this.bindGroups.empty); pass.setBindGroup(3, group); pass.dispatchWorkgroups(this.G);
157 }
159 private async readStaging(staging: GPUBuffer, bytes: number): Promise<Float32Array> {
160 await staging.mapAsync(GPUMapMode.READ, 0, bytes);
161 const data = new Float32Array(staging.getMappedRange(0, bytes).slice(0));
162 staging.unmap();
163 return data;
164 }
166 async runChunk(nSamples: number): Promise<ChunkResult> {
167 if (nSamples > this.chunkCapacity) throw new Error("chunk larger than the pressure buffer");
168 const { device, setup } = this, M = setup.substeps, E = setup.mesh.e, K = setup.schedule.K, N = setup.mesh.n;
169 const n0 = this.step, n1 = n0 + nSamples * M;
170 let base = -1, count = 0;
171 for (let n = n0; n < n1; n++) { const j = this.sampleDueAt(n); if (j >= 0) { if (base < 0) base = j; count++; } }
172 // frames captured in this chunk: the state at the start of sub-step n where n / M is a multiple of `every`
173 const framesAt = (every: number) => { const out: number[] = []; if (every > 0) for (let n = n0; n < n1; n++) if (n % (M * every) === 0) out.push(n / M); return out; };
174 const frameSamples = framesAt(this.movieEvery), dispSamples = framesAt(this.dispEvery);
175 const frameBase = frameSamples.length ? frameSamples[0] / this.movieEvery : 0, dispBase = dispSamples.length ? dispSamples[0] / this.dispEvery : 0;
176 const accBase = base < 0 ? 0 : base, accRows = this.recordAcceleration ? Math.max(count, 0) : 0;
177 device.queue.writeBuffer(this.buffers.chunk, 0, new Int32Array([accBase, Math.max(count, 1), frameBase, Math.max(this.movieEvery, 1), accBase, accRows, 0, 0]));
178 device.queue.writeBuffer(this.buffers.chunkD, 0, new Int32Array([accBase, Math.max(count, 1), dispBase, Math.max(this.dispEvery, 1), accBase, accRows, 0, 0]));
179 const enc = device.createCommandEncoder();
180 enc.clearBuffer(this.buffers.pressure);
181 const pass = enc.beginComputePass();
182 const wgE = Math.ceil((E + K) / 64), wgN = this.G;
183 for (let n = n0; n < n1; n++) {
184 if (this.movieEvery > 0 && n % (M * this.movieEvery) === 0) this.capture(pass, this.bindGroups.capture);
185 if (this.dispEvery > 0 && n % (M * this.dispEvery) === 0) this.capture(pass, this.bindGroups.captureDisp);
186 pass.setPipeline(this.pipelines.element); pass.setBindGroup(0, this.bindGroups.element); pass.dispatchWorkgroups(wgE);
187 pass.setPipeline(this.pipelines.node); pass.setBindGroup(0, this.bindGroups.empty); pass.setBindGroup(1, this.bindGroups.node); pass.dispatchWorkgroups(wgN);
188 if (this.sampleDueAt(n) >= 0) {
189 pass.setPipeline(this.pipelines.gather); pass.setBindGroup(0, this.bindGroups.empty); pass.setBindGroup(1, this.bindGroups.empty);
190 pass.setBindGroup(2, this.bindGroups.gather); pass.dispatchWorkgroups(this.GE);
191 }
192 }
193 pass.end();
194 const GE = this.GE;
195 enc.copyBufferToBuffer(this.buffers.pressure, 0, this.stagingPressure, 0, 8 * this.chunkCapacity * GE);
196 const nFrames = frameSamples.length, nDisp = dispSamples.length;
197 if (nFrames > 0) enc.copyBufferToBuffer(this.buffers.movie, 0, this.stagingMovie!, 0, nFrames * N * 4);
198 if (nDisp > 0) enc.copyBufferToBuffer(this.buffers.disp, 0, this.stagingDisp!, 0, nDisp * N * 4);
199 if (accRows > 0) enc.copyBufferToBuffer(this.buffers.rad, this.radStateFloats * 4, this.stagingAcc!, 0, accRows * N * 4);
200 device.queue.submit([enc.finish()]);
201 this.step = n1; this.samplesDone += nSamples;
202 const partial = await this.readStaging(this.stagingPressure, 8 * this.chunkCapacity * GE);
203 const all = new Float32Array(2 * this.chunkCapacity);
204 for (let i = 0; i < 2 * Math.max(count, 1); i++) { let s = 0; for (let g = 0; g < GE; g++) s += partial[i * GE + g]; all[i] = s; }
205 const split = (data: Float32Array, k: number) => Array.from({ length: k }, (_, f) => data.slice(f * N, (f + 1) * N));
206 const frames = nFrames > 0 ? split(await this.readStaging(this.stagingMovie!, nFrames * N * 4), nFrames) : [];
207 const dispFrames = nDisp > 0 ? split(await this.readStaging(this.stagingDisp!, nDisp * N * 4), nDisp) : [];
208 const acceleration = this.recordAcceleration ? (accRows > 0 ? await this.readStaging(this.stagingAcc!, accRows * N * 4) : new Float32Array(0)) : null;
209 const size = Math.max(count, 1);
210 return { firstSample: base < 0 ? this.samplesDone : base, pressureFront: all.slice(0, count), pressureBack: all.slice(size, size + count),
211 frames, frameSamples, acceleration, dispFrames, dispSamples };
212 }
214 private async read(buffer: GPUBuffer, staging: GPUBuffer, bytes: number): Promise<ArrayBuffer> {
215 const enc = this.device.createCommandEncoder();
216 enc.copyBufferToBuffer(buffer, 0, staging, 0, bytes);
217 this.device.queue.submit([enc.finish()]);
218 await staging.mapAsync(GPUMapMode.READ, 0, bytes);
219 const out = staging.getMappedRange(0, bytes).slice(0);
220 staging.unmap();
221 return out;
222 }
224 /** Read a whole buffer through a temporary staging buffer. */
225 private async readWhole(buffer: GPUBuffer, bytes: number): Promise<ArrayBuffer> {
226 const staging = this.device.createBuffer({ size: Math.max(16, bytes), usage: GPUBufferUsage.MAP_READ | GPUBufferUsage.COPY_DST });
227 try { return await this.read(buffer, staging, bytes); } finally { staging.destroy(); }
228 }
230 async diagnostics(): Promise<Diagnostics> {
231 const { setup } = this, sh = setup.shell, N = setup.mesh.n, sc = setup.schedule, HF = this.HF, HU = this.HU;
232 const st = new Float32Array(await this.read(this.buffers.state, this.stagingState, STATE_FLOATS * N * 4));
233 const hf = new Float32Array(await this.read(this.buffers.hitsF, this.stagingHits, Math.max(16, HF * sc.K * 4)));
234 const hu = new Uint32Array(await this.read(this.buffers.hitsU, this.stagingHitsU, Math.max(16, HU * sc.K * 4)));
235 let ke = 0, woh = 0;
236 for (let i = 0; i < 5 * N; i++) ke += 0.5 * sh.M[i] * st[5 * N + i] * st[5 * N + i];
237 for (let n = 0; n < N; n++) woh = Math.max(woh, Math.abs(st[5 * n + 2] / sh.hNode[n]));
238 const { membrane, bending } = strainEnergies(sh, st.subarray(0, 5 * N));
239 let ex = 0;
240 const hits = [];
241 for (let k = 0; k < sc.K; k++) {
242 ex += 0.5 * hf[HF * k + 2] * hf[HF * k + 6] ** 2;
243 hits.push({ peakForce: hf[HF * k + 8], contactTime: hu[HU * k + 1] * setup.dt, velocity: hf[HF * k + 6], height: hf[HF * k + 5] });
244 }
245 return { time: this.step * setup.dt, kinetic: ke, membrane, bending, exciters: ex, maxWoverH: woh, hits };
246 }
248 async displacement(): Promise<Float32Array> {
249 const N = this.setup.mesh.n;
250 const st = new Float32Array(await this.read(this.buffers.state, this.stagingState, STATE_FLOATS * N * 4));
251 const w = new Float32Array(N);
252 for (let n = 0; n < N; n++) w[n] = st[5 * n + 2];
253 return w;
254 }
256 async exportState(): Promise<BackendState> {
257 const { setup } = this, N = setup.mesh.n, E = setup.mesh.e, K = setup.schedule.K, D = setup.radiation.ringLength;
258 const B = this.buffers;
259 return { kind: "gpu", step: this.step, samplesDone: this.samplesDone, arrays: {
260 state: new Float32Array(await this.readWhole(B.state, STATE_FLOATS * N * 4)),
261 sync: new Float32Array(await this.readWhole(B.sync, (SYNC_HEADER + 2 * this.G * 12) * 4)),
262 hitsF: new Float32Array(await this.readWhole(B.hitsF, Math.max(16, this.HF * K * 4))).subarray(0, this.HF * K),
263 hitsU: new Uint32Array(await this.readWhole(B.hitsU, Math.max(16, this.HU * K * 4))).subarray(0, this.HU * K),
264 rad: new Float32Array(await this.readWhole(B.rad, this.radStateFloats * 4)),
265 elemHist: new Float32Array(await this.readWhole(B.elemHist, D * E * 4)),
266 } };
267 }
269 async importState(st: BackendState): Promise<void> {
270 if (st.kind !== "gpu") throw new Error("state was written by another backend");
271 const { setup } = this, N = setup.mesh.n, E = setup.mesh.e, K = setup.schedule.K, D = setup.radiation.ringLength;
272 const expect: Record<string, number> = { state: STATE_FLOATS * N, sync: SYNC_HEADER + 2 * this.G * 12, hitsF: this.HF * K, hitsU: this.HU * K, rad: this.radStateFloats, elemHist: D * E };
273 // states written before the sub-step accelerations were kept per sample lack them; their accumulator
274 // slots already hold the sample's earlier sub-steps, so zero accelerations continue them exactly
275 const legacyRad = this.radStateFloats - setup.substeps * N;
276 for (const [name, len] of Object.entries(expect)) {
277 let a = st.arrays[name];
278 if (name === "rad" && a?.length === legacyRad) { const full = new Float32Array(len); full.set(a); a = full; }
279 if (!a || a.length !== len) throw new Error(`state array ${name} is missing or has the wrong size`);
280 this.device.queue.writeBuffer(this.buffers[name], 0, a.buffer, a.byteOffset, a.byteLength);
281 }
282 this.step = st.step; this.samplesDone = st.samplesDone;
283 }
285 /** The state buffer (q at offset 0, 5 floats per node), for a renderer that reads w directly. */
286 get stateBuffer(): GPUBuffer { return this.buffers.state; }
288 dispose() {
289 for (const b of Object.values(this.buffers)) b.destroy();
290 this.stagingPressure.destroy(); this.stagingState.destroy(); this.stagingHits.destroy(); this.stagingHitsU.destroy();
291 this.stagingMovie?.destroy(); this.stagingDisp?.destroy(); this.stagingAcc?.destroy();
292 }
↑↓ move↵openescclose