dcgrid 0.2.1 → 0.3.1
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/README.md +33 -19
- package/dist/dcgrid.mjs +1 -1
- package/dist/dcgrid.wasm +0 -0
- package/dist/index.d.ts +61 -9
- package/dist/index.js +197 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,19 +2,36 @@
|
|
|
2
2
|
|
|
3
3
|
Adaptive-grid smoke simulation on WebGPU: [DCGrid](https://graphics.tudelft.nl/~klaus/papers/DCGrid.pdf) compiled to WebAssembly, on a `GPUDevice` you own.
|
|
4
4
|
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
*The "Clouds over mountains" preset after 300 steps: the render (left) and the resolution view (right), where each checkerboard square is one grid cell. The grid refines where the flow needs it. [Try it in the browser](https://dcgrid.vercel.app).*
|
|
8
|
+
|
|
5
9
|
```ts
|
|
6
|
-
import { DCGrid } from "dcgrid";
|
|
7
|
-
|
|
8
|
-
const adapter = await navigator.gpu.requestAdapter();
|
|
9
|
-
const device = await adapter!.requestDevice({
|
|
10
|
-
requiredLimits: {
|
|
11
|
-
maxStorageBuffersPerShaderStage: adapter!.limits.maxStorageBuffersPerShaderStage,
|
|
12
|
-
maxStorageBufferBindingSize: adapter!.limits.maxStorageBufferBindingSize,
|
|
13
|
-
maxBufferSize: adapter!.limits.maxBufferSize,
|
|
14
|
-
},
|
|
15
|
-
});
|
|
10
|
+
import { DCGrid, orbitCamera, sceneOrbit } from "dcgrid";
|
|
16
11
|
|
|
12
|
+
const device = await DCGrid.requestDevice(); // the limits large grids need (DCGrid.requiredLimits)
|
|
17
13
|
const dcgrid = await DCGrid.load();
|
|
14
|
+
|
|
15
|
+
const context = canvas.getContext("webgpu")!;
|
|
16
|
+
context.configure({ device, format: navigator.gpu.getPreferredCanvasFormat() });
|
|
17
|
+
|
|
18
|
+
const scene = dcgrid.describeScene("Open plume", 64);
|
|
19
|
+
const sim = dcgrid.create(device, scene.desc);
|
|
20
|
+
sim.applyScene("Open plume");
|
|
21
|
+
const renderer = sim.createRenderer();
|
|
22
|
+
await renderer.whenReady();
|
|
23
|
+
|
|
24
|
+
for (;;) {
|
|
25
|
+
sim.poll();
|
|
26
|
+
if (sim.stepsInFlight < 2) sim.step();
|
|
27
|
+
if (!renderer.busy) renderer.render(orbitCamera(sceneOrbit(scene.view)), scene.render, context);
|
|
28
|
+
await new Promise(requestAnimationFrame);
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
[examples/basic](../examples/basic) is this as a Vite app. Your own scene instead of a preset:
|
|
33
|
+
|
|
34
|
+
```ts
|
|
18
35
|
const sim = dcgrid.create(device, {
|
|
19
36
|
size: [128, 256, 128], // cells
|
|
20
37
|
cellSize: 40, // meters
|
|
@@ -22,12 +39,6 @@ const sim = dcgrid.create(device, {
|
|
|
22
39
|
faces: { "-y": { type: "inflow", velocity: [0, 100, 0], density: 0.002 } },
|
|
23
40
|
});
|
|
24
41
|
await sim.whenReady();
|
|
25
|
-
|
|
26
|
-
for (;;) {
|
|
27
|
-
sim.poll();
|
|
28
|
-
if (sim.stepsInFlight < 2) sim.step();
|
|
29
|
-
await new Promise(requestAnimationFrame);
|
|
30
|
-
}
|
|
31
42
|
```
|
|
32
43
|
|
|
33
44
|
## Scenes
|
|
@@ -36,18 +47,21 @@ for (;;) {
|
|
|
36
47
|
- **Solids**: `sim.setSolids({ size, data })`, a signed distance in meters (negative inside).
|
|
37
48
|
- **Sources**: `sim.setSources(density, velocity)`, rates per second added every step.
|
|
38
49
|
|
|
39
|
-
Volumes span the domain at any resolution, x fastest, with voxels on the domain's corners. `dcgrid.describeScene(
|
|
50
|
+
Volumes span the domain at any resolution, x fastest, with voxels on the domain's corners. `dcgrid.describeScene(scene, resolution)` and `sim.applyScene(scene)` load the five preset scenes of the demo by index or by name (`dcgrid.scenes`: sphere obstacle, open plume, wind over hills, wildfire, clouds over mountains; the last two use the weather extension). A preset scene's inflow maps follow later changes to their faces' velocity and density in `sim.setStepParams`; maps you set with `setInflowMap` are kept as given.
|
|
40
51
|
|
|
41
52
|
## Output
|
|
42
53
|
|
|
43
54
|
- `await sim.sampleField("density" | "velocity" | "fluidity" | "cell_size", texture)` resamples a field into a 3D `GPUTexture` (`r32float`, `rgba16float` or `rgba32float` with `STORAGE_BINDING`) for your own renderer.
|
|
44
|
-
- `sim.createRenderer()` is the optional raymarcher of the demo
|
|
55
|
+
- `sim.createRenderer()` is the optional raymarcher of the demo. `renderer.render(camera, settings, context, { scale })` draws into a canvas over `settings.backgroundColor`, raymarching at `scale` times the canvas size. `renderer.render(camera, settings, texture)` writes into an `rgba8unorm` texture with `STORAGE_BINDING` instead, with alpha for your own compositing. Renders are asynchronous: skip a frame while `renderer.busy`.
|
|
56
|
+
- Cameras: `orbitCamera({ target, distance, yaw, pitch }, { fov })` builds the `Camera` the renderer takes, and `sceneOrbit(scene.view)` frames a preset scene.
|
|
45
57
|
|
|
46
58
|
## Behavior
|
|
47
59
|
|
|
48
60
|
Nothing blocks. `create` and `reset` return at once; `whenReady()` resolves once the pipelines are compiled and the grid is initialized. `step()` submits to the device queue without waiting. The adaptive grid reads refinement scores back asynchronously and applies them in a later step; `stepsInFlight` counts a step until its readback has arrived. Errors are `DCGridError`s with a `code` (`invalid_argument`, `unsupported`, `not_ready`, `device`).
|
|
49
61
|
|
|
50
|
-
`dcgrid.wasm` is loaded from next to `dcgrid.mjs` (bundlers that handle `new URL(..., import.meta.url)` pick it up; Vite needs `optimizeDeps.exclude: ["dcgrid"]
|
|
62
|
+
`dcgrid.wasm` is loaded from next to `dcgrid.mjs` (bundlers that handle `new URL(..., import.meta.url)` pick it up; Vite needs `optimizeDeps.exclude: ["dcgrid"]`, see [the example's config](../examples/basic/vite.config.ts)). `DCGrid.load({ wasm })` takes another URL or the bytes.
|
|
63
|
+
|
|
64
|
+
The adaptive grid binds 9 storage buffers per shader stage and the uniform grid 5, above WebGPU's default of 8 for the adaptive grid; `DCGrid.requestDevice(adapter?)` and `DCGrid.requiredLimits(adapter)` request what the adapter allows.
|
|
51
65
|
|
|
52
66
|
## Building
|
|
53
67
|
|
package/dist/dcgrid.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
async function createDCGridModule(moduleArg={}){var Module=moduleArg;var ENVIRONMENT_IS_WEB=!!globalThis.window;var ENVIRONMENT_IS_WORKER=!!globalThis.WorkerGlobalScope;var ENVIRONMENT_IS_NODE=globalThis.process?.versions?.node&&globalThis.process?.type!="renderer";if(ENVIRONMENT_IS_NODE){const{createRequire}=await(import("node:module"));var require=createRequire(import.meta.url)}var thisProgram="./this.program";var quit_=(status,toThrow)=>{throw toThrow};var _scriptName=import.meta.url;var scriptDirectory="";function locateFile(path){if(Module["locateFile"])return Module["locateFile"](path,scriptDirectory);return scriptDirectory+path}var readAsync,readBinary;if(ENVIRONMENT_IS_NODE){var fs=require("node:fs");if(_scriptName.startsWith("file:"))scriptDirectory=require("node:path").dirname(require("node:url").fileURLToPath(_scriptName))+"/";readBinary=filename=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename);return ret};readAsync=async(filename,binary=true)=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename,binary?void 0:"utf8");return ret};if(process.argv.length>1)thisProgram=process.argv[1].replace(/\\/g,"/");process.argv.slice(2);quit_=(status,toThrow)=>{process.exitCode=status;throw toThrow}}else if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){try{scriptDirectory=new URL(".",_scriptName).href}catch{}if(ENVIRONMENT_IS_WORKER)readBinary=url=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.responseType="arraybuffer";xhr.send(null);return new Uint8Array(xhr.response)};readAsync=async url=>{var response=await fetch(url,{credentials:"same-origin"});if(response.ok)return response.arrayBuffer();throw new Error(response.status+" : "+response.url)}}console.log.bind(console);var err=console.error.bind(console);var ABORT=false;var EXITSTATUS;function assert(condition,text){if(!condition)abort(text)}var isFileURI=filename=>filename.startsWith("file://");var runtimeInitialized=false;function getMemoryBuffer(){return wasmMemory.buffer}function updateMemoryViews(){if(HEAP8?.buffer?.resizable)return;var b=getMemoryBuffer();HEAP8=new Int8Array(b);Module["HEAPU8"]=HEAPU8=new Uint8Array(b);HEAPU16=new Uint16Array(b);HEAP32=new Int32Array(b);HEAPU32=new Uint32Array(b);Module["HEAPF32"]=HEAPF32=new Float32Array(b);HEAPF64=new Float64Array(b);HEAP64=new BigInt64Array(b)}function preRun(){var preRun=Module["preRun"];if(preRun){if(typeof preRun==="function")preRun=[preRun];onPreRuns.push(...preRun)}callRuntimeCallbacks(onPreRuns)}function initRuntime(){runtimeInitialized=true;wasmExports["W"]()}function postRun(){var postRun=Module["postRun"];if(postRun){if(typeof postRun==="function")postRun=[postRun];onPostRuns.push(...postRun)}callRuntimeCallbacks(onPostRuns)}function abort(what){Module["onAbort"]?.(what);what=`Aborted(${what})`;err(what);ABORT=true;what+=". Build with -sASSERTIONS for more info.";if(runtimeInitialized)___trap();throw new WebAssembly.RuntimeError(what)}var wasmBinaryFile;function findWasmBinary(){if(Module["locateFile"])return locateFile("dcgrid.wasm");return new URL("dcgrid.wasm",import.meta.url).href}function getBinarySync(file){if(readBinary)return readBinary(file);throw"both async and sync fetching of the wasm failed"}async function getWasmBinary(binaryFile){if(true)try{return await readAsync(binaryFile)}catch{}return getBinarySync(binaryFile)}async function instantiateArrayBuffer(binaryFile,imports){try{var binary=await getWasmBinary(binaryFile);var instance=await WebAssembly.instantiate(binary,imports);return instance}catch(reason){err(`failed to asynchronously prepare wasm: ${reason}`);abort(reason)}}async function instantiateAsync(binary,binaryFile,imports){if(!binary&&!ENVIRONMENT_IS_NODE)try{var response=fetch(binaryFile,{credentials:"same-origin"});var instantiationResult=await WebAssembly.instantiateStreaming(response,imports);return instantiationResult}catch(reason){err(`wasm streaming compile failed: ${reason}`);err("falling back to ArrayBuffer instantiation")}return instantiateArrayBuffer(binaryFile,imports)}function getWasmImports(){var imports={a:wasmImports};return imports}class ExitStatus{name="ExitStatus";constructor(status){this.message=`Program terminated with exit(${status})`;this.status=status}}var HEAP8;var callRuntimeCallbacks=callbacks=>{while(callbacks.length>0)callbacks.shift()(Module)};var onPostRuns=[];var onPreRuns=[];var noExitRuntime=true;var HEAP32;var HEAPU32;var HEAPU8;var stringToUTF8Array=(str,heap,outIdx,maxBytesToWrite)=>{if(!(maxBytesToWrite>0))return 0;var startIdx=outIdx;var endIdx=outIdx+maxBytesToWrite-1;for(var i=0;i<str.length;++i){var u=str.codePointAt(i);if(u<=127){if(outIdx>=endIdx)break;heap[outIdx++]=u}else if(u<=2047){if(outIdx+1>=endIdx)break;heap[outIdx++]=192|u>>6;heap[outIdx++]=128|u&63}else if(u<=65535){if(outIdx+2>=endIdx)break;heap[outIdx++]=224|u>>12;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63}else{if(outIdx+3>=endIdx)break;heap[outIdx++]=240|u>>18;heap[outIdx++]=128|u>>12&63;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63;i++}}heap[outIdx]=0;return outIdx-startIdx};var stringToUTF8=(str,outPtr,maxBytesToWrite)=>stringToUTF8Array(str,HEAPU8,outPtr,maxBytesToWrite);var HEAP64;var bigintToI53Checked=num=>num<-9007199254740992||num>9007199254740992?NaN:Number(num);var checkWasiClock=clock_id=>clock_id>=0&&clock_id<=3;var _emscripten_date_now=()=>Date.now();var _emscripten_get_now=()=>performance.now();var alignMemory=(size,alignment)=>Math.ceil(size/alignment)*alignment;var getHeapMax=()=>2147483648;var growMemory=size=>{var oldHeapSize=wasmMemory.buffer.byteLength;var pages=(size-oldHeapSize+65535)/65536|0;try{wasmMemory.grow(pages);updateMemoryViews();return 1}catch(e){}};var HEAPF32;var HEAPF64;var UTF8Decoder=globalThis.TextDecoder&&new TextDecoder;var findStringEnd=(heapOrArray,idx,maxBytesToRead,ignoreNul)=>{var maxIdx=idx+maxBytesToRead;if(ignoreNul)return maxIdx;while(heapOrArray[idx]&&!(idx>=maxIdx))++idx;return idx};var UTF8ArrayToString=(heapOrArray,idx=0,maxBytesToRead,ignoreNul)=>{var endPtr=findStringEnd(heapOrArray,idx,maxBytesToRead,ignoreNul);if(endPtr-idx>16&&heapOrArray.buffer&&UTF8Decoder)return UTF8Decoder.decode(heapOrArray.subarray(idx,endPtr));var str="";while(idx<endPtr){var u0=heapOrArray[idx++];if(!(u0&128)){str+=String.fromCharCode(u0);continue}var u1=heapOrArray[idx++]&63;if((u0&224)==192){str+=String.fromCharCode((u0&31)<<6|u1);continue}var u2=heapOrArray[idx++]&63;if((u0&240)==224)u0=(u0&15)<<12|u1<<6|u2;else u0=(u0&7)<<18|u1<<12|u2<<6|heapOrArray[idx++]&63;if(u0<65536)str+=String.fromCharCode(u0);else{var ch=u0-65536;str+=String.fromCharCode(55296|ch>>10,56320|ch&1023)}}return str};var UTF8ToString_cache={};var UTF8ToString=(ptr,maxBytesToRead,ignoreNul)=>{var useCache=maxBytesToRead==null&&ptr>=1024&&ptr<148984;if(useCache){var rtn=UTF8ToString_cache[ptr];if(rtn!=null)return rtn}rtn=ptr?UTF8ArrayToString(HEAPU8,ptr,maxBytesToRead,ignoreNul):"";if(useCache)UTF8ToString_cache[ptr]=rtn;return rtn};var wasmTableMirror=[];var getWasmTableEntry=funcPtr=>{var func=wasmTableMirror[funcPtr];if(!func)wasmTableMirror[funcPtr]=func=wasmTable.get(funcPtr);return func};var lengthBytesUTF8=str=>{var len=0;for(var i=0;i<str.length;++i){var u=str.codePointAt(i);if(u<=127)len++;else if(u<=2047)len+=2;else if(u<=65535)len+=3;else{len+=4;i++}}return len};var readI53FromI64=ptr=>HEAPU32[ptr>>2]+HEAP32[ptr+4>>2]*4294967296;var stackRestore=val=>__emscripten_stack_restore(val);var stackSave=()=>_emscripten_stack_get_current();var stringToNewUTF8=str=>{var size=lengthBytesUTF8(str)+1;var ret=_malloc(size);if(ret)stringToUTF8(str,ret,size);return ret};var stackAlloc=sz=>__emscripten_stack_alloc(sz);var stringToUTF8OnStack=str=>{var size=lengthBytesUTF8(str)+1;var ret=stackAlloc(size);stringToUTF8(str,ret,size);return ret};var writeI53ToI64=(ptr,num)=>{HEAPU32[ptr>>2]=num;var lower=HEAPU32[ptr>>2];HEAPU32[ptr+4>>2]=(num-lower)/4294967296};var WebGPU={Internals:{jsObjects:[],jsObjectInsert:(ptr,jsObject)=>{ptr>>>=0;WebGPU.Internals.jsObjects[ptr]=jsObject},bufferOnUnmaps:[],futures:[],futureInsert:()=>{}},getJsObject:ptr=>{if(!ptr)return;ptr>>>=0;return WebGPU.Internals.jsObjects[ptr]},importJsAdapter:(obj,parentPtr=0)=>{var ptr=_emwgpuCreateAdapter(parentPtr);WebGPU.Internals.jsObjects[ptr]=obj;return ptr},importJsBindGroup:(obj,parentPtr=0)=>{var ptr=_emwgpuCreateBindGroup(parentPtr);WebGPU.Internals.jsObjects[ptr]=obj;return ptr},importJsBindGroupLayout:(obj,parentPtr=0)=>{var ptr=_emwgpuCreateBindGroupLayout(parentPtr);WebGPU.Internals.jsObjects[ptr]=obj;return ptr},importJsBuffer:(buffer,parentPtr=0)=>{assert(buffer.mapState==="unmapped");var bufferPtr=_emwgpuImportBuffer(parentPtr);WebGPU.Internals.jsObjectInsert(bufferPtr,buffer);return bufferPtr},importJsCommandBuffer:(obj,parentPtr=0)=>{var ptr=_emwgpuCreateCommandBuffer(parentPtr);WebGPU.Internals.jsObjects[ptr]=obj;return ptr},importJsCommandEncoder:(obj,parentPtr=0)=>{var ptr=_emwgpuCreateCommandEncoder(parentPtr);WebGPU.Internals.jsObjects[ptr]=obj;return ptr},importJsComputePassEncoder:(obj,parentPtr=0)=>{var ptr=_emwgpuCreateComputePassEncoder(parentPtr);WebGPU.Internals.jsObjects[ptr]=obj;return ptr},importJsComputePipeline:(obj,parentPtr=0)=>{var ptr=_emwgpuCreateComputePipeline(parentPtr);WebGPU.Internals.jsObjects[ptr]=obj;return ptr},importJsDevice:(device,parentPtr=0)=>{var queuePtr=_emwgpuCreateQueue(parentPtr);var devicePtr=_emwgpuCreateDevice(parentPtr,queuePtr);WebGPU.Internals.jsObjectInsert(queuePtr,device.queue);WebGPU.Internals.jsObjectInsert(devicePtr,device);return devicePtr},importJsExternalTexture:(obj,parentPtr=0)=>{var ptr=_emwgpuCreateExternalTexture(parentPtr);WebGPU.Internals.jsObjects[ptr]=obj;return ptr},importJsPipelineLayout:(obj,parentPtr=0)=>{var ptr=_emwgpuCreatePipelineLayout(parentPtr);WebGPU.Internals.jsObjects[ptr]=obj;return ptr},importJsQuerySet:(obj,parentPtr=0)=>{var ptr=_emwgpuCreateQuerySet(parentPtr);WebGPU.Internals.jsObjects[ptr]=obj;return ptr},importJsQueue:(obj,parentPtr=0)=>{var ptr=_emwgpuCreateQueue(parentPtr);WebGPU.Internals.jsObjects[ptr]=obj;return ptr},importJsRenderBundle:(obj,parentPtr=0)=>{var ptr=_emwgpuCreateRenderBundle(parentPtr);WebGPU.Internals.jsObjects[ptr]=obj;return ptr},importJsRenderBundleEncoder:(obj,parentPtr=0)=>{var ptr=_emwgpuCreateRenderBundleEncoder(parentPtr);WebGPU.Internals.jsObjects[ptr]=obj;return ptr},importJsRenderPassEncoder:(obj,parentPtr=0)=>{var ptr=_emwgpuCreateRenderPassEncoder(parentPtr);WebGPU.Internals.jsObjects[ptr]=obj;return ptr},importJsRenderPipeline:(obj,parentPtr=0)=>{var ptr=_emwgpuCreateRenderPipeline(parentPtr);WebGPU.Internals.jsObjects[ptr]=obj;return ptr},importJsSampler:(obj,parentPtr=0)=>{var ptr=_emwgpuCreateSampler(parentPtr);WebGPU.Internals.jsObjects[ptr]=obj;return ptr},importJsShaderModule:(obj,parentPtr=0)=>{var ptr=_emwgpuCreateShaderModule(parentPtr);WebGPU.Internals.jsObjects[ptr]=obj;return ptr},importJsSurface:(obj,parentPtr=0)=>{var ptr=_emwgpuCreateSurface(parentPtr);WebGPU.Internals.jsObjects[ptr]=obj;return ptr},importJsTexture:(obj,parentPtr=0)=>{var ptr=_emwgpuCreateTexture(parentPtr);WebGPU.Internals.jsObjects[ptr]=obj;return ptr},importJsTextureView:(obj,parentPtr=0)=>{var ptr=_emwgpuCreateTextureView(parentPtr);WebGPU.Internals.jsObjects[ptr]=obj;return ptr},errorCallback:(callback,type,message,userdata)=>{var sp=stackSave();var messagePtr=stringToUTF8OnStack(message);getWasmTableEntry(callback)(type,messagePtr,userdata);stackRestore(sp)},iterateExtensions:(root,handlers)=>{for(var ptr=HEAPU32[root>>2];ptr;ptr=HEAPU32[ptr>>2]){var sType=HEAP32[ptr+4>>2];handlers[sType](ptr)}},setStringView:(ptr,data,length)=>{HEAPU32[ptr>>2]=data;HEAPU32[ptr+4>>2]=length},makeStringFromStringView:stringViewPtr=>{var ptr=HEAPU32[stringViewPtr>>2];var length=HEAPU32[stringViewPtr+4>>2];return UTF8ToString(ptr,length)},makeStringFromOptionalStringView:stringViewPtr=>{var ptr=HEAPU32[stringViewPtr>>2];var length=HEAPU32[stringViewPtr+4>>2];if(!ptr){if(length===0)return"";return}return UTF8ToString(ptr,length)},makeColor:ptr=>({r:HEAPF64[ptr>>3],g:HEAPF64[ptr+8>>3],b:HEAPF64[ptr+16>>3],a:HEAPF64[ptr+24>>3]}),makeExtent3D:ptr=>({width:HEAPU32[ptr>>2],height:HEAPU32[ptr+4>>2],depthOrArrayLayers:HEAPU32[ptr+8>>2]}),makeOrigin3D:ptr=>({x:HEAPU32[ptr>>2],y:HEAPU32[ptr+4>>2],z:HEAPU32[ptr+8>>2]}),makeTexelCopyTextureInfo:ptr=>({texture:WebGPU.getJsObject(HEAPU32[ptr>>2]),mipLevel:HEAPU32[ptr+4>>2],origin:WebGPU.makeOrigin3D(ptr+8),aspect:WebGPU.TextureAspect[HEAP32[ptr+20>>2]]}),makeTexelCopyBufferLayout:ptr=>{var bytesPerRow=HEAPU32[ptr+8>>2];var rowsPerImage=HEAPU32[ptr+12>>2];return{offset:readI53FromI64(ptr),bytesPerRow:bytesPerRow===4294967295?void 0:bytesPerRow,rowsPerImage:rowsPerImage===4294967295?void 0:rowsPerImage}},makeTexelCopyBufferInfo:ptr=>{var layoutPtr=ptr+0;var bufferCopyView=WebGPU.makeTexelCopyBufferLayout(layoutPtr);bufferCopyView["buffer"]=WebGPU.getJsObject(HEAPU32[ptr+16>>2]);return bufferCopyView},makePassTimestampWrites:ptr=>{if(ptr===0)return;return{querySet:WebGPU.getJsObject(HEAPU32[ptr+4>>2]),beginningOfPassWriteIndex:HEAPU32[ptr+8>>2],endOfPassWriteIndex:HEAPU32[ptr+12>>2]}},makePipelineConstants:(constantCount,constantsPtr)=>{if(!constantCount)return;var constants={};for(var i=0;i<constantCount;++i){var entryPtr=constantsPtr+24*i;var key=WebGPU.makeStringFromStringView(entryPtr+4);constants[key]=HEAPF64[entryPtr+16>>3]}return constants},makePipelineLayout:layoutPtr=>{if(!layoutPtr)return"auto";return WebGPU.getJsObject(layoutPtr)},makeComputeState:ptr=>{if(!ptr)return;var desc={module:WebGPU.getJsObject(HEAPU32[ptr+4>>2]),constants:WebGPU.makePipelineConstants(HEAPU32[ptr+16>>2],HEAPU32[ptr+20>>2]),entryPoint:WebGPU.makeStringFromOptionalStringView(ptr+8)};return desc},makeComputePipelineDesc:descriptor=>{var desc={label:WebGPU.makeStringFromOptionalStringView(descriptor+4),layout:WebGPU.makePipelineLayout(HEAPU32[descriptor+12>>2]),compute:WebGPU.makeComputeState(descriptor+16)};return desc},makeRenderPipelineDesc:descriptor=>{function makeBlendComponent(bdPtr){if(!bdPtr)return;return{operation:WebGPU.BlendOperation[HEAP32[bdPtr>>2]],srcFactor:WebGPU.BlendFactor[HEAP32[bdPtr+4>>2]],dstFactor:WebGPU.BlendFactor[HEAP32[bdPtr+8>>2]]}}function makeBlendState(bsPtr){if(!bsPtr)return;return{alpha:makeBlendComponent(bsPtr+12),color:makeBlendComponent(bsPtr+0)}}function makeColorState(csPtr){var format=WebGPU.TextureFormat[HEAP32[csPtr+4>>2]];return format?{format,blend:makeBlendState(HEAPU32[csPtr+8>>2]),writeMask:HEAPU32[csPtr+16>>2]}:void 0}function makeColorStates(count,csArrayPtr){var states=[];for(var i=0;i<count;++i)states.push(makeColorState(csArrayPtr+24*i));return states}function makeStencilStateFace(ssfPtr){return{compare:WebGPU.CompareFunction[HEAP32[ssfPtr>>2]],failOp:WebGPU.StencilOperation[HEAP32[ssfPtr+4>>2]],depthFailOp:WebGPU.StencilOperation[HEAP32[ssfPtr+8>>2]],passOp:WebGPU.StencilOperation[HEAP32[ssfPtr+12>>2]]}}function makeVertexAttribute(vaPtr){return{format:WebGPU.VertexFormat[HEAP32[vaPtr+4>>2]],offset:readI53FromI64(vaPtr+8),shaderLocation:HEAPU32[vaPtr+16>>2]}}function makeVertexAttributes(count,vaArrayPtr){var vas=[];for(var i=0;i<count;++i)vas.push(makeVertexAttribute(vaArrayPtr+i*24));return vas}function makeVertexBuffer(vbPtr){if(!vbPtr)return;var stepMode=WebGPU.VertexStepMode[HEAP32[vbPtr+4>>2]];var attributeCount=HEAPU32[vbPtr+16>>2];if(!stepMode&&!attributeCount)return null;return{arrayStride:readI53FromI64(vbPtr+8),stepMode,attributes:makeVertexAttributes(attributeCount,HEAPU32[vbPtr+20>>2])}}function makeVertexBuffers(count,vbArrayPtr){if(!count)return;var vbs=[];for(var i=0;i<count;++i)vbs.push(makeVertexBuffer(vbArrayPtr+i*24));return vbs}var desc={label:WebGPU.makeStringFromOptionalStringView(descriptor+4),layout:WebGPU.makePipelineLayout(HEAPU32[descriptor+12>>2]),vertex:function(viPtr){if(!viPtr)return;var desc={module:WebGPU.getJsObject(HEAPU32[viPtr+4>>2]),constants:WebGPU.makePipelineConstants(HEAPU32[viPtr+16>>2],HEAPU32[viPtr+20>>2]),buffers:makeVertexBuffers(HEAPU32[viPtr+24>>2],HEAPU32[viPtr+28>>2]),entryPoint:WebGPU.makeStringFromOptionalStringView(viPtr+8)};return desc}(descriptor+16),primitive:function(psPtr){if(!psPtr)return;return{topology:WebGPU.PrimitiveTopology[HEAP32[psPtr+4>>2]],stripIndexFormat:WebGPU.IndexFormat[HEAP32[psPtr+8>>2]],frontFace:WebGPU.FrontFace[HEAP32[psPtr+12>>2]],cullMode:WebGPU.CullMode[HEAP32[psPtr+16>>2]],unclippedDepth:!!HEAPU32[psPtr+20>>2]}}(descriptor+48),depthStencil:function(dssPtr){if(!dssPtr)return;return{format:WebGPU.TextureFormat[HEAP32[dssPtr+4>>2]],depthWriteEnabled:!!HEAPU32[dssPtr+8>>2],depthCompare:WebGPU.CompareFunction[HEAP32[dssPtr+12>>2]],stencilFront:makeStencilStateFace(dssPtr+16),stencilBack:makeStencilStateFace(dssPtr+32),stencilReadMask:HEAPU32[dssPtr+48>>2],stencilWriteMask:HEAPU32[dssPtr+52>>2],depthBias:HEAP32[dssPtr+56>>2],depthBiasSlopeScale:HEAPF32[dssPtr+60>>2],depthBiasClamp:HEAPF32[dssPtr+64>>2]}}(HEAPU32[descriptor+72>>2]),multisample:function(msPtr){if(!msPtr)return;return{count:HEAPU32[msPtr+4>>2],mask:HEAPU32[msPtr+8>>2],alphaToCoverageEnabled:!!HEAPU32[msPtr+12>>2]}}(descriptor+76),fragment:function(fsPtr){if(!fsPtr)return;var desc={module:WebGPU.getJsObject(HEAPU32[fsPtr+4>>2]),constants:WebGPU.makePipelineConstants(HEAPU32[fsPtr+16>>2],HEAPU32[fsPtr+20>>2]),targets:makeColorStates(HEAPU32[fsPtr+24>>2],HEAPU32[fsPtr+28>>2]),entryPoint:WebGPU.makeStringFromOptionalStringView(fsPtr+8)};return desc}(HEAPU32[descriptor+92>>2])};return desc},fillLimitStruct:(limits,limitsOutPtr)=>{var nextInChainPtr=HEAPU32[limitsOutPtr>>2];function setLimitValueU32(name,basePtr,limitOffset,fallbackValue=0){var limitValue=limits[name]??fallbackValue;HEAPU32[basePtr+limitOffset>>2]=limitValue}function setLimitValueU64(name,basePtr,limitOffset,fallbackValue=0){var limitValue=limits[name]??fallbackValue;writeI53ToI64(basePtr+limitOffset,limitValue)}setLimitValueU32("maxTextureDimension1D",limitsOutPtr,4);setLimitValueU32("maxTextureDimension2D",limitsOutPtr,8);setLimitValueU32("maxTextureDimension3D",limitsOutPtr,12);setLimitValueU32("maxTextureArrayLayers",limitsOutPtr,16);setLimitValueU32("maxBindGroups",limitsOutPtr,20);setLimitValueU32("maxBindGroupsPlusVertexBuffers",limitsOutPtr,24);setLimitValueU32("maxBindingsPerBindGroup",limitsOutPtr,28);setLimitValueU32("maxDynamicUniformBuffersPerPipelineLayout",limitsOutPtr,32);setLimitValueU32("maxDynamicStorageBuffersPerPipelineLayout",limitsOutPtr,36);setLimitValueU32("maxSampledTexturesPerShaderStage",limitsOutPtr,40);setLimitValueU32("maxSamplersPerShaderStage",limitsOutPtr,44);setLimitValueU32("maxStorageBuffersPerShaderStage",limitsOutPtr,48);setLimitValueU32("maxStorageTexturesPerShaderStage",limitsOutPtr,52);setLimitValueU32("maxUniformBuffersPerShaderStage",limitsOutPtr,56);setLimitValueU32("minUniformBufferOffsetAlignment",limitsOutPtr,80);setLimitValueU32("minStorageBufferOffsetAlignment",limitsOutPtr,84);setLimitValueU64("maxUniformBufferBindingSize",limitsOutPtr,64);setLimitValueU64("maxStorageBufferBindingSize",limitsOutPtr,72);setLimitValueU32("maxVertexBuffers",limitsOutPtr,88);setLimitValueU64("maxBufferSize",limitsOutPtr,96);setLimitValueU32("maxVertexAttributes",limitsOutPtr,104);setLimitValueU32("maxVertexBufferArrayStride",limitsOutPtr,108);setLimitValueU32("maxInterStageShaderVariables",limitsOutPtr,112);setLimitValueU32("maxColorAttachments",limitsOutPtr,116);setLimitValueU32("maxColorAttachmentBytesPerSample",limitsOutPtr,120);setLimitValueU32("maxComputeWorkgroupStorageSize",limitsOutPtr,124);setLimitValueU32("maxComputeInvocationsPerWorkgroup",limitsOutPtr,128);setLimitValueU32("maxComputeWorkgroupSizeX",limitsOutPtr,132);setLimitValueU32("maxComputeWorkgroupSizeY",limitsOutPtr,136);setLimitValueU32("maxComputeWorkgroupSizeZ",limitsOutPtr,140);setLimitValueU32("maxComputeWorkgroupsPerDimension",limitsOutPtr,144);setLimitValueU32("maxImmediateSize",limitsOutPtr,148);if(nextInChainPtr!==0){HEAP32[nextInChainPtr+4>>2];var compatibilityModeLimitsPtr=nextInChainPtr;setLimitValueU32("maxStorageBuffersInVertexStage",compatibilityModeLimitsPtr,8,limits.maxStorageBuffersPerShaderStage);setLimitValueU32("maxStorageBuffersInFragmentStage",compatibilityModeLimitsPtr,16,limits.maxStorageBuffersPerShaderStage);setLimitValueU32("maxStorageTexturesInVertexStage",compatibilityModeLimitsPtr,12,limits.maxStorageTexturesPerShaderStage);setLimitValueU32("maxStorageTexturesInFragmentStage",compatibilityModeLimitsPtr,20,limits.maxStorageTexturesPerShaderStage)}},fillAdapterInfoStruct:(info,infoStruct)=>{HEAPU32[infoStruct+52>>2]=info.subgroupMinSize;HEAPU32[infoStruct+56>>2]=info.subgroupMaxSize;var strs=info.vendor+info.architecture+info.device+info.description;var strPtr=stringToNewUTF8(strs);var vendorLen=lengthBytesUTF8(info.vendor);WebGPU.setStringView(infoStruct+4,strPtr,vendorLen);strPtr+=vendorLen;var architectureLen=lengthBytesUTF8(info.architecture);WebGPU.setStringView(infoStruct+12,strPtr,architectureLen);strPtr+=architectureLen;var deviceLen=lengthBytesUTF8(info.device);WebGPU.setStringView(infoStruct+20,strPtr,deviceLen);strPtr+=deviceLen;var descriptionLen=lengthBytesUTF8(info.description);WebGPU.setStringView(infoStruct+28,strPtr,descriptionLen);strPtr+=descriptionLen;HEAP32[infoStruct+36>>2]=2;var adapterType=info.isFallbackAdapter?3:4;HEAP32[infoStruct+40>>2]=adapterType;HEAPU32[infoStruct+44>>2]=0;HEAPU32[infoStruct+48>>2]=0;WebGPU.iterateExtensions(infoStruct,{327739:ext=>{let configCount=0;let configsPtr=0;if(info.subgroupMatrixConfigs){configCount=info.subgroupMatrixConfigs.length;configsPtr=_malloc(configCount*28);for(const[i,cfg]of info.subgroupMatrixConfigs.entries()){const ptr=configsPtr+i*28;const componentType=WebGPU.SubgroupMatrixComponentType.indexOf(cfg.componentType);const resultComponentType=WebGPU.SubgroupMatrixComponentType.indexOf(cfg.resultComponentType);HEAP32[ptr>>2]=componentType;HEAP32[ptr+4>>2]=resultComponentType;HEAPU32[ptr+8>>2]=cfg.M;HEAPU32[ptr+12>>2]=cfg.N;HEAPU32[ptr+16>>2]=cfg.K}}HEAPU32[ext+12>>2]=configsPtr;HEAPU32[ext+8>>2]=configCount}})},AddressMode:[,"clamp-to-edge","repeat","mirror-repeat"],BlendFactor:[,"zero","one","src","one-minus-src","src-alpha","one-minus-src-alpha","dst","one-minus-dst","dst-alpha","one-minus-dst-alpha","src-alpha-saturated","constant","one-minus-constant","src1","one-minus-src1","src1-alpha","one-minus-src1-alpha"],BlendOperation:[,"add","subtract","reverse-subtract","min","max"],BufferBindingType:[,,"uniform","storage","read-only-storage"],BufferMapState:[,"unmapped","pending","mapped"],CompareFunction:[,"never","less","equal","less-equal","greater","not-equal","greater-equal","always"],CompilationInfoRequestStatus:[,"success","callback-cancelled"],ComponentSwizzle:[,"0","1","r","g","b","a"],CompositeAlphaMode:[,"opaque","premultiplied","unpremultiplied","inherit"],CullMode:[,"none","front","back"],ErrorFilter:[,"validation","out-of-memory","internal"],FeatureLevel:[,"compatibility","core"],FeatureName:{1:"core-features-and-limits",2:"depth-clip-control",3:"depth32float-stencil8",4:"texture-compression-bc",5:"texture-compression-bc-sliced-3d",6:"texture-compression-etc2",7:"texture-compression-astc",8:"texture-compression-astc-sliced-3d",9:"timestamp-query",10:"indirect-first-instance",11:"shader-f16",12:"rg11b10ufloat-renderable",13:"bgra8unorm-storage",14:"float32-filterable",15:"float32-blendable",16:"clip-distances",17:"dual-source-blending",18:"subgroups",19:"texture-formats-tier1",20:"texture-formats-tier2",21:"primitive-index",22:"texture-component-swizzle",23:"subgroup-size-control",24:"texture-compression-unaligned",25:"atomic-vec2u-min-max",327692:"chromium-experimental-unorm16-texture-formats",327729:"chromium-experimental-multi-draw-indirect",327732:"chromium-experimental-subgroup-matrix"},FilterMode:[,"nearest","linear"],FrontFace:[,"ccw","cw"],IndexFormat:[,"uint16","uint32"],InstanceFeatureName:[,"timed-wait-any","shader-source-spirv","multiple-devices-per-adapter"],LoadOp:[,"load","clear"],MipmapFilterMode:[,"nearest","linear"],OptionalBool:["false","true"],PowerPreference:[,"low-power","high-performance"],PredefinedColorSpace:[,"srgb","display-p3"],PrimitiveTopology:[,"point-list","line-list","line-strip","triangle-list","triangle-strip"],QueryType:[,"occlusion","timestamp"],SamplerBindingType:[,,"filtering","non-filtering","comparison"],Status:[,"success","error"],StencilOperation:[,"keep","zero","replace","invert","increment-clamp","decrement-clamp","increment-wrap","decrement-wrap"],StorageTextureAccess:[,,"write-only","read-only","read-write"],StoreOp:[,"store","discard"],SubgroupMatrixComponentType:[,"f32","f16","u32","i32","u8","i8"],SurfaceGetCurrentTextureStatus:[,"success-optimal","success-suboptimal","timeout","outdated","lost","error"],TextureAspect:[,"all","stencil-only","depth-only"],TextureDimension:[,"1d","2d","3d"],TextureFormat:[,"r8unorm","r8snorm","r8uint","r8sint","r16unorm","r16snorm","r16uint","r16sint","r16float","rg8unorm","rg8snorm","rg8uint","rg8sint","r32float","r32uint","r32sint","rg16unorm","rg16snorm","rg16uint","rg16sint","rg16float","rgba8unorm","rgba8unorm-srgb","rgba8snorm","rgba8uint","rgba8sint","bgra8unorm","bgra8unorm-srgb","rgb10a2uint","rgb10a2unorm","rg11b10ufloat","rgb9e5ufloat","rg32float","rg32uint","rg32sint","rgba16unorm","rgba16snorm","rgba16uint","rgba16sint","rgba16float","rgba32float","rgba32uint","rgba32sint","stencil8","depth16unorm","depth24plus","depth24plus-stencil8","depth32float","depth32float-stencil8","bc1-rgba-unorm","bc1-rgba-unorm-srgb","bc2-rgba-unorm","bc2-rgba-unorm-srgb","bc3-rgba-unorm","bc3-rgba-unorm-srgb","bc4-r-unorm","bc4-r-snorm","bc5-rg-unorm","bc5-rg-snorm","bc6h-rgb-ufloat","bc6h-rgb-float","bc7-rgba-unorm","bc7-rgba-unorm-srgb","etc2-rgb8unorm","etc2-rgb8unorm-srgb","etc2-rgb8a1unorm","etc2-rgb8a1unorm-srgb","etc2-rgba8unorm","etc2-rgba8unorm-srgb","eac-r11unorm","eac-r11snorm","eac-rg11unorm","eac-rg11snorm","astc-4x4-unorm","astc-4x4-unorm-srgb","astc-5x4-unorm","astc-5x4-unorm-srgb","astc-5x5-unorm","astc-5x5-unorm-srgb","astc-6x5-unorm","astc-6x5-unorm-srgb","astc-6x6-unorm","astc-6x6-unorm-srgb","astc-8x5-unorm","astc-8x5-unorm-srgb","astc-8x6-unorm","astc-8x6-unorm-srgb","astc-8x8-unorm","astc-8x8-unorm-srgb","astc-10x5-unorm","astc-10x5-unorm-srgb","astc-10x6-unorm","astc-10x6-unorm-srgb","astc-10x8-unorm","astc-10x8-unorm-srgb","astc-10x10-unorm","astc-10x10-unorm-srgb","astc-12x10-unorm","astc-12x10-unorm-srgb","astc-12x12-unorm","astc-12x12-unorm-srgb"],TextureSampleType:[,,"float","unfilterable-float","depth","sint","uint"],TextureViewDimension:[,"1d","2d","2d-array","cube","cube-array","3d"],ToneMappingMode:[,"standard","extended"],VertexFormat:[,"uint8","uint8x2","uint8x4","sint8","sint8x2","sint8x4","unorm8","unorm8x2","unorm8x4","snorm8","snorm8x2","snorm8x4","uint16","uint16x2","uint16x4","sint16","sint16x2","sint16x4","unorm16","unorm16x2","unorm16x4","snorm16","snorm16x2","snorm16x4","float16","float16x2","float16x4","float32","float32x2","float32x3","float32x4","uint32","uint32x2","uint32x3","uint32x4","sint32","sint32x2","sint32x3","sint32x4","unorm10-10-10-2","unorm8x4-bgra","snorm10-10-10-2"],VertexStepMode:[,"vertex","instance"],WGSLLanguageFeatureName:[,"readonly_and_readwrite_storage_textures","packed_4x8_integer_dot_product","unrestricted_pointer_parameters","pointer_composite_access","uniform_buffer_standard_layout","subgroup_id","texture_and_sampler_let","subgroup_uniformity","texture_formats_tier1","linear_indexing","immediate_address_space","buffer_view","swizzle_assignment","fragment_depth"]};var handleException=e=>{if(e instanceof ExitStatus||e=="unwind")return EXITSTATUS;quit_(1,e)};var keepRuntimeAlive=()=>noExitRuntime||0>0;var _proc_exit=code=>{EXITSTATUS=code;if(!keepRuntimeAlive()){Module["onExit"]?.(code);ABORT=true}quit_(code,new ExitStatus(code))};var maybeExit=()=>{if(!keepRuntimeAlive())try{_exit(EXITSTATUS)}catch(e){handleException(e)}};var callUserCallback=(func,...args)=>{if(ABORT)return;try{return func(...args)}catch(e){handleException(e)}finally{maybeExit()}};var emwgpuStringToInt_CompilationMessageType={error:1,warning:2,info:3};var ENV={};var getExecutableName=()=>thisProgram;var getEnvStrings=()=>{if(!getEnvStrings.strings){var lang=(globalThis.navigator?.language??"C").replace("-","_")+".UTF-8";var env={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:lang,_:getExecutableName()};for(var x in ENV)if(ENV[x]===void 0)delete env[x];else env[x]=ENV[x];var strings=[];for(var x in env)strings.push(`${x}=${env[x]}`);getEnvStrings.strings=strings}return getEnvStrings.strings};var HEAPU16;var _exit=status=>{EXITSTATUS=status;_proc_exit(status)};if(Module["noExitRuntime"])noExitRuntime=Module["noExitRuntime"];if(Module["print"])Module["print"];if(Module["printErr"])err=Module["printErr"];if(Module["arguments"])Module["arguments"];if(Module["thisProgram"])thisProgram=Module["thisProgram"];var preInit=Module["preInit"];if(preInit){if(typeof preInit==="function")Module["preInit"]=preInit=[preInit];while(preInit.length>0)preInit.shift()()}Module["UTF8ToString"]=UTF8ToString;Module["stringToNewUTF8"]=stringToNewUTF8;var _malloc,_emwgpuCreateBindGroup,_emwgpuCreateBindGroupLayout,_emwgpuCreateCommandBuffer,_emwgpuCreateCommandEncoder,_emwgpuCreateComputePassEncoder,_emwgpuCreateComputePipeline,_emwgpuCreateExternalTexture,_emwgpuCreatePipelineLayout,_emwgpuCreateQuerySet,_emwgpuCreateRenderBundle,_emwgpuCreateRenderBundleEncoder,_emwgpuCreateRenderPassEncoder,_emwgpuCreateRenderPipeline,_emwgpuCreateSampler,_emwgpuCreateSurface,_emwgpuCreateTexture,_emwgpuCreateTextureView,_emwgpuCreateAdapter,_emwgpuImportBuffer,_emwgpuCreateDevice,_emwgpuCreateQueue,_emwgpuCreateShaderModule,_emwgpuOnCompilationInfoCompleted,_emwgpuOnCreateComputePipelineCompleted,_emwgpuOnMapAsyncCompleted,_emwgpuOnWorkDoneCompleted,_free,_memalign,___trap,__emscripten_stack_restore,__emscripten_stack_alloc,_emscripten_stack_get_current,wasmMemory,wasmTable;function assignWasmExports(wasmExports){Module["_dcgridJsInstance"]=wasmExports["X"];Module["_dcgridJsLastError"]=wasmExports["Y"];Module["_dcgridJsCreate"]=wasmExports["Z"];Module["_dcgridJsDefaults"]=wasmExports["$"];_malloc=Module["_malloc"]=wasmExports["aa"];Module["_dcgridJsDescribeScene"]=wasmExports["ba"];Module["_dcgridJsDesc"]=wasmExports["ca"];Module["_dcgridJsSetStepParams"]=wasmExports["da"];Module["_dcgridJsStats"]=wasmExports["ea"];Module["_dcgridJsSetVolume"]=wasmExports["fa"];Module["_dcgridJsCreateRenderer"]=wasmExports["ga"];Module["_dcgridJsRender"]=wasmExports["ha"];Module["_wgpuTextureRelease"]=wasmExports["ia"];Module["_wgpuDeviceRelease"]=wasmExports["ja"];Module["_dcgridSampleFieldWebGPU"]=wasmExports["ka"];Module["_dcgridFlush"]=wasmExports["la"];Module["_dcgridRendererDestroy"]=wasmExports["ma"];Module["_dcgridRendererIsReady"]=wasmExports["na"];Module["_dcgridRendererInvalidate"]=wasmExports["oa"];Module["_dcgridRendererBusy"]=wasmExports["pa"];Module["_dcgridDestroy"]=wasmExports["qa"];Module["_dcgridPoll"]=wasmExports["ra"];Module["_dcgridIsReady"]=wasmExports["sa"];Module["_dcgridGetStatus"]=wasmExports["ta"];Module["_dcgridReset"]=wasmExports["ua"];Module["_dcgridStep"]=wasmExports["va"];Module["_dcgridStepsInFlight"]=wasmExports["wa"];Module["_dcgridSetInflowMap"]=wasmExports["xa"];Module["_dcgridSceneCount"]=wasmExports["ya"];Module["_dcgridSceneName"]=wasmExports["za"];Module["_dcgridSceneApply"]=wasmExports["Aa"];_emwgpuCreateBindGroup=wasmExports["Ba"];_emwgpuCreateBindGroupLayout=wasmExports["Ca"];_emwgpuCreateCommandBuffer=wasmExports["Da"];_emwgpuCreateCommandEncoder=wasmExports["Ea"];_emwgpuCreateComputePassEncoder=wasmExports["Fa"];_emwgpuCreateComputePipeline=wasmExports["Ga"];_emwgpuCreateExternalTexture=wasmExports["Ha"];_emwgpuCreatePipelineLayout=wasmExports["Ia"];_emwgpuCreateQuerySet=wasmExports["Ja"];_emwgpuCreateRenderBundle=wasmExports["Ka"];_emwgpuCreateRenderBundleEncoder=wasmExports["La"];_emwgpuCreateRenderPassEncoder=wasmExports["Ma"];_emwgpuCreateRenderPipeline=wasmExports["Na"];_emwgpuCreateSampler=wasmExports["Oa"];_emwgpuCreateSurface=wasmExports["Pa"];_emwgpuCreateTexture=Module["_emwgpuCreateTexture"]=wasmExports["Qa"];_emwgpuCreateTextureView=wasmExports["Ra"];_emwgpuCreateAdapter=wasmExports["Sa"];_emwgpuImportBuffer=wasmExports["Ta"];_emwgpuCreateDevice=Module["_emwgpuCreateDevice"]=wasmExports["Ua"];_emwgpuCreateQueue=Module["_emwgpuCreateQueue"]=wasmExports["Va"];_emwgpuCreateShaderModule=wasmExports["Wa"];_emwgpuOnCompilationInfoCompleted=wasmExports["Xa"];_emwgpuOnCreateComputePipelineCompleted=wasmExports["Ya"];_emwgpuOnMapAsyncCompleted=wasmExports["Za"];_emwgpuOnWorkDoneCompleted=wasmExports["_a"];_free=Module["_free"]=wasmExports["$a"];_memalign=wasmExports["ab"];___trap=wasmExports["bb"];__emscripten_stack_restore=wasmExports["cb"];__emscripten_stack_alloc=wasmExports["db"];_emscripten_stack_get_current=wasmExports["eb"];wasmMemory=wasmExports["V"];wasmTable=wasmExports["_"]}var wasmImports={x:()=>abort(""),u:(timezone,daylight,std_name,dst_name)=>{var currentYear=(new Date).getFullYear();var winter=new Date(currentYear,0,1);var summer=new Date(currentYear,6,1);var winterOffset=winter.getTimezoneOffset();var summerOffset=summer.getTimezoneOffset();var stdTimezoneOffset=Math.max(winterOffset,summerOffset);HEAPU32[timezone>>2]=stdTimezoneOffset*60;HEAP32[daylight>>2]=Number(winterOffset!=summerOffset);var extractZone=timezoneOffset=>{var sign=timezoneOffset>=0?"-":"+";var absOffset=Math.abs(timezoneOffset);var hours=String(Math.floor(absOffset/60)).padStart(2,"0");var minutes=String(absOffset%60).padStart(2,"0");return`UTC${sign}${hours}${minutes}`};var winterName=extractZone(winterOffset);var summerName=extractZone(summerOffset);if(summerOffset<winterOffset){stringToUTF8(winterName,std_name,17);stringToUTF8(summerName,dst_name,17)}else{stringToUTF8(winterName,dst_name,17);stringToUTF8(summerName,std_name,17)}},v:function(clk_id,ignored_precision,ptime){ignored_precision=bigintToI53Checked(ignored_precision);if(!checkWasiClock(clk_id))return 28;var now;if(clk_id===0)now=_emscripten_date_now();else if(1)now=_emscripten_get_now();else return 52;var nsec=Math.round(now*1e6);HEAP64[ptime>>3]=BigInt(nsec);return 0},w:requestedSize=>{var oldSize=HEAPU8.length;requestedSize>>>=0;var maxHeapSize=getHeapMax();if(requestedSize>maxHeapSize)return false;for(var cutDown=1;cutDown<=4;cutDown*=2){var overGrownHeapSize=oldSize*(1+.2/cutDown);overGrownHeapSize=Math.min(overGrownHeapSize,requestedSize+100663296);var newSize=Math.min(maxHeapSize,alignMemory(Math.max(requestedSize,overGrownHeapSize),65536));var replacement=growMemory(newSize);if(replacement)return true}return false},I:bufferPtr=>{var buffer=WebGPU.getJsObject(bufferPtr);var onUnmap=WebGPU.Internals.bufferOnUnmaps[bufferPtr];if(onUnmap){for(var i=0;i<onUnmap.length;++i)onUnmap[i]();delete WebGPU.Internals.bufferOnUnmaps[bufferPtr]}buffer.destroy()},H:(bufferPtr,offset,size)=>{var buffer=WebGPU.getJsObject(bufferPtr);if(size==-1)size=void 0;var mapped;try{mapped=buffer.getMappedRange(offset,size)}catch(ex){return 0}var data=_memalign(16,mapped.byteLength);HEAPU8.set(new Uint8Array(mapped),data);WebGPU.Internals.bufferOnUnmaps[bufferPtr].push(()=>_free(data));return data},G:(bufferPtr,offset,size)=>{var buffer=WebGPU.getJsObject(bufferPtr);if(size==-1)size=void 0;var mapped;try{mapped=buffer.getMappedRange(offset,size)}catch(ex){return 0}var data=_memalign(16,mapped.byteLength);HEAPU8.fill(0,data,mapped.byteLength);WebGPU.Internals.bufferOnUnmaps[bufferPtr].push(()=>{new Uint8Array(mapped).set(HEAPU8.subarray(data,data+mapped.byteLength));_free(data)});return data},F:function(bufferPtr,futureId,mode,offset,size){futureId=bigintToI53Checked(futureId);mode=bigintToI53Checked(mode);var buffer=WebGPU.getJsObject(bufferPtr);WebGPU.Internals.bufferOnUnmaps[bufferPtr]=[];if(size==-1)size=void 0;WebGPU.Internals.futureInsert(futureId,buffer.mapAsync(mode,offset,size).then(()=>{callUserCallback(()=>{_emwgpuOnMapAsyncCompleted(futureId,1,0)})},ex=>{callUserCallback(()=>{stackSave();var messagePtr=stringToUTF8OnStack(ex.message);var status=ex.name==="AbortError"?4:ex.name==="OperationError"?3:0;_emwgpuOnMapAsyncCompleted(futureId,status,messagePtr);delete WebGPU.Internals.bufferOnUnmaps[bufferPtr]})}))},E:bufferPtr=>{var buffer=WebGPU.getJsObject(bufferPtr);var onUnmap=WebGPU.Internals.bufferOnUnmaps[bufferPtr];if(!onUnmap)return;for(var i=0;i<onUnmap.length;++i)onUnmap[i]();delete WebGPU.Internals.bufferOnUnmaps[bufferPtr];buffer.unmap()},a:ptr=>{delete WebGPU.Internals.jsObjects[ptr]},B:(devicePtr,descriptor,bufferPtr)=>{var mappedAtCreation=!!HEAPU32[descriptor+32>>2];var desc={label:WebGPU.makeStringFromOptionalStringView(descriptor+4),usage:HEAPU32[descriptor+16>>2],size:readI53FromI64(descriptor+24),mappedAtCreation};var device=WebGPU.getJsObject(devicePtr);var buffer;try{buffer=device.createBuffer(desc)}catch(ex){return false}WebGPU.Internals.jsObjectInsert(bufferPtr,buffer);if(mappedAtCreation)WebGPU.Internals.bufferOnUnmaps[bufferPtr]=[];return true},A:function(devicePtr,futureId,descriptor,pipelinePtr){futureId=bigintToI53Checked(futureId);var desc=WebGPU.makeComputePipelineDesc(descriptor);var device=WebGPU.getJsObject(devicePtr);WebGPU.Internals.futureInsert(futureId,device.createComputePipelineAsync(desc).then(pipeline=>{callUserCallback(()=>{WebGPU.Internals.jsObjectInsert(pipelinePtr,pipeline);_emwgpuOnCreateComputePipelineCompleted(futureId,1,pipelinePtr,0)})},pipelineError=>{callUserCallback(()=>{var sp=stackSave();var messagePtr=stringToUTF8OnStack(pipelineError.message);var status=pipelineError.reason==="validation"?3:pipelineError.reason==="internal"?4:0;_emwgpuOnCreateComputePipelineCompleted(futureId,status,pipelinePtr,messagePtr);stackRestore(sp)})}))},z:(devicePtr,descriptor,shaderModulePtr)=>{var nextInChainPtr=HEAPU32[descriptor>>2];var sType=HEAP32[nextInChainPtr+4>>2];var desc={label:WebGPU.makeStringFromOptionalStringView(descriptor+4),code:""};switch(sType){case 2:desc["code"]=WebGPU.makeStringFromStringView(nextInChainPtr+8);break}var device=WebGPU.getJsObject(devicePtr);WebGPU.Internals.jsObjectInsert(shaderModulePtr,device.createShaderModule(desc))},D:devicePtr=>{const device=WebGPU.getJsObject(devicePtr);device.onuncapturederror=null;device.destroy()},y:function(queuePtr,futureId){futureId=bigintToI53Checked(futureId);var queue=WebGPU.getJsObject(queuePtr);WebGPU.Internals.futureInsert(futureId,queue.onSubmittedWorkDone().then(()=>{callUserCallback(()=>{_emwgpuOnWorkDoneCompleted(futureId,1)})}))},C:function(shaderModulePtr,futureId,compilationInfoPtr){futureId=bigintToI53Checked(futureId);var shaderModule=WebGPU.getJsObject(shaderModulePtr);WebGPU.Internals.futureInsert(futureId,shaderModule.getCompilationInfo().then(compilationInfo=>{callUserCallback(()=>{const messageCount=compilationInfo.messages.length;HEAPU32[compilationInfoPtr+4>>2]=messageCount;if(messageCount){var totalMessagesSize=1;var messageLengths=[];for(var i=0;i<messageCount;++i){var messageLength=lengthBytesUTF8(compilationInfo.messages[i].message);totalMessagesSize+=messageLength;messageLengths.push(messageLength)}var messagesPtr=_malloc(totalMessagesSize);var compilationMessagesPtr=_malloc(48*messageCount);HEAPU32[compilationInfoPtr+8>>2]=compilationMessagesPtr;var utf16sPtr=_malloc(32*messageCount);for(i=0;i<messageCount;++i){var compilationMessage=compilationInfo.messages[i];var compilationMessagePtr=compilationMessagesPtr+48*i;var utf16Ptr=utf16sPtr+32*i;WebGPU.setStringView(compilationMessagePtr+4,messagesPtr,messageLengths[i]);HEAPU32[compilationMessagePtr>>2]=utf16Ptr;HEAP32[compilationMessagePtr+12>>2]=emwgpuStringToInt_CompilationMessageType[compilationMessage.type];HEAP64[compilationMessagePtr+16>>3]=BigInt(compilationMessage.lineNum);HEAP64[compilationMessagePtr+24>>3]=BigInt(compilationMessage.linePos);HEAP64[compilationMessagePtr+32>>3]=BigInt(compilationMessage.offset);HEAP64[compilationMessagePtr+40>>3]=BigInt(compilationMessage.length);HEAPU32[utf16Ptr>>2]=0;HEAP32[utf16Ptr+4>>2]=327743;HEAP64[utf16Ptr+8>>3]=BigInt(compilationMessage.linePos);HEAP64[utf16Ptr+16>>3]=BigInt(compilationMessage.offset);HEAP64[utf16Ptr+24>>3]=BigInt(compilationMessage.length);stringToUTF8(compilationMessage.message,messagesPtr,messageLengths[i]+1);messagesPtr+=messageLengths[i]}}_emwgpuOnCompilationInfoCompleted(futureId,1,compilationInfoPtr)})},()=>{abort("Unexpected failure in GPUShaderModule.getCompilationInfo().")}))},s:(__environ,environ_buf)=>{var bufSize=0;var envp=0;for(var string of getEnvStrings()){var ptr=environ_buf+bufSize;HEAPU32[__environ+envp>>2]=ptr;bufSize+=stringToUTF8(string,ptr,1/0)+1;envp+=4}return 0},t:(penviron_count,penviron_buf_size)=>{var strings=getEnvStrings();HEAPU32[penviron_count>>2]=strings.length;var bufSize=0;for(var string of strings)bufSize+=lengthBytesUTF8(string)+1;HEAPU32[penviron_buf_size>>2]=bufSize;return 0},j:(encoderPtr,descriptor)=>{var desc;if(descriptor)desc={label:WebGPU.makeStringFromOptionalStringView(descriptor+4),timestampWrites:WebGPU.makePassTimestampWrites(HEAPU32[descriptor+12>>2])};var commandEncoder=WebGPU.getJsObject(encoderPtr);var ptr=_emwgpuCreateComputePassEncoder(0);WebGPU.Internals.jsObjectInsert(ptr,commandEncoder.beginComputePass(desc));return ptr},S:function(encoderPtr,bufferPtr,offset,size){offset=bigintToI53Checked(offset);size=bigintToI53Checked(size);var commandEncoder=WebGPU.getJsObject(encoderPtr);if(size==-1)size=void 0;var buffer=WebGPU.getJsObject(bufferPtr);commandEncoder.clearBuffer(buffer,offset,size)},f:function(encoderPtr,srcPtr,srcOffset,dstPtr,dstOffset,size){srcOffset=bigintToI53Checked(srcOffset);dstOffset=bigintToI53Checked(dstOffset);size=bigintToI53Checked(size);var commandEncoder=WebGPU.getJsObject(encoderPtr);var src=WebGPU.getJsObject(srcPtr);var dst=WebGPU.getJsObject(dstPtr);commandEncoder.copyBufferToBuffer(src,srcOffset,dst,dstOffset,size)},P:encoderPtr=>{var commandEncoder=WebGPU.getJsObject(encoderPtr);var ptr=_emwgpuCreateCommandBuffer(0);WebGPU.Internals.jsObjectInsert(ptr,commandEncoder.finish());return ptr},R:function(encoderPtr,querySetPtr,firstQuery,queryCount,destinationPtr,destinationOffset){destinationOffset=bigintToI53Checked(destinationOffset);var commandEncoder=WebGPU.getJsObject(encoderPtr);var querySet=WebGPU.getJsObject(querySetPtr);var destination=WebGPU.getJsObject(destinationPtr);commandEncoder.resolveQuerySet(querySet,firstQuery,queryCount,destination,destinationOffset)},T:(passPtr,x,y,z)=>{var pass=WebGPU.getJsObject(passPtr);pass.dispatchWorkgroups(x,y,z)},e:passPtr=>{var pass=WebGPU.getJsObject(passPtr);pass.end()},i:(passPtr,groupIndex,groupPtr,dynamicOffsetCount,dynamicOffsetsPtr)=>{var pass=WebGPU.getJsObject(passPtr);var group=WebGPU.getJsObject(groupPtr);if(dynamicOffsetCount==0)pass.setBindGroup(groupIndex,group);else pass.setBindGroup(groupIndex,group,HEAPU32,dynamicOffsetsPtr>>2,dynamicOffsetCount)},q:(passPtr,pipelinePtr)=>{var pass=WebGPU.getJsObject(passPtr);var pipeline=WebGPU.getJsObject(pipelinePtr);pass.setPipeline(pipeline)},h:(devicePtr,descriptor)=>{function makeEntry(entryPtr){var bufferPtr=HEAPU32[entryPtr+8>>2];var samplerPtr=HEAPU32[entryPtr+32>>2];var textureViewPtr=HEAPU32[entryPtr+36>>2];var externalTexturePtr=0;WebGPU.iterateExtensions(entryPtr,{14:ptr=>{externalTexturePtr=HEAPU32[ptr+8>>2]}});var resource;if(bufferPtr){var size=readI53FromI64(entryPtr+24);if(size==-1)size=void 0;resource={buffer:WebGPU.getJsObject(bufferPtr),offset:readI53FromI64(entryPtr+16),size}}else resource=WebGPU.getJsObject(samplerPtr||textureViewPtr||externalTexturePtr);return{binding:HEAPU32[entryPtr+4>>2],resource}}var desc={label:WebGPU.makeStringFromOptionalStringView(descriptor+4),layout:WebGPU.getJsObject(HEAPU32[descriptor+12>>2]),entries:function(count,entriesPtrs){var entries=[];for(var i=0;i<count;++i)entries.push(makeEntry(entriesPtrs+40*i));return entries}(HEAPU32[descriptor+16>>2],HEAPU32[descriptor+20>>2])};var device=WebGPU.getJsObject(devicePtr);var ptr=_emwgpuCreateBindGroup(0);WebGPU.Internals.jsObjectInsert(ptr,device.createBindGroup(desc));return ptr},c:(devicePtr,descriptor)=>{function makeBufferEntry(substructPtr){var typeInt=HEAPU32[substructPtr+4>>2];if(!typeInt)return;return{type:WebGPU.BufferBindingType[typeInt],hasDynamicOffset:!!HEAPU32[substructPtr+8>>2],minBindingSize:readI53FromI64(substructPtr+16)}}function makeSamplerEntry(substructPtr){var typeInt=HEAPU32[substructPtr+4>>2];if(!typeInt)return;return{type:WebGPU.SamplerBindingType[typeInt]}}function makeTextureEntry(substructPtr){var sampleTypeInt=HEAPU32[substructPtr+4>>2];if(!sampleTypeInt)return;return{sampleType:WebGPU.TextureSampleType[sampleTypeInt],viewDimension:WebGPU.TextureViewDimension[HEAP32[substructPtr+8>>2]],multisampled:!!HEAPU32[substructPtr+12>>2]}}function makeStorageTextureEntry(substructPtr){var accessInt=HEAPU32[substructPtr+4>>2];if(!accessInt)return;return{access:WebGPU.StorageTextureAccess[accessInt],format:WebGPU.TextureFormat[HEAP32[substructPtr+8>>2]],viewDimension:WebGPU.TextureViewDimension[HEAP32[substructPtr+12>>2]]}}function makeEntry(entryPtr){var entry={binding:HEAPU32[entryPtr+4>>2],visibility:HEAPU32[entryPtr+8>>2],buffer:makeBufferEntry(entryPtr+24),sampler:makeSamplerEntry(entryPtr+48),texture:makeTextureEntry(entryPtr+56),storageTexture:makeStorageTextureEntry(entryPtr+72)};WebGPU.iterateExtensions(entryPtr,{13:()=>{entry["externalTexture"]={}}});return entry}var desc={label:WebGPU.makeStringFromOptionalStringView(descriptor+4),entries:function(count,entriesPtrs){var entries=[];for(var i=0;i<count;++i)entries.push(makeEntry(entriesPtrs+88*i));return entries}(HEAPU32[descriptor+12>>2],HEAPU32[descriptor+16>>2])};var device=WebGPU.getJsObject(devicePtr);var ptr=_emwgpuCreateBindGroupLayout(0);WebGPU.Internals.jsObjectInsert(ptr,device.createBindGroupLayout(desc));return ptr},d:(devicePtr,descriptor)=>{var desc;if(descriptor)desc={label:WebGPU.makeStringFromOptionalStringView(descriptor+4)};var device=WebGPU.getJsObject(devicePtr);var ptr=_emwgpuCreateCommandEncoder(0);WebGPU.Internals.jsObjectInsert(ptr,device.createCommandEncoder(desc));return ptr},p:(devicePtr,descriptor)=>{var bglCount=HEAPU32[descriptor+12>>2];var bglPtr=HEAPU32[descriptor+16>>2];var bgls=[];for(var i=0;i<bglCount;++i)bgls.push(WebGPU.getJsObject(HEAPU32[bglPtr+4*i>>2]));var desc={label:WebGPU.makeStringFromOptionalStringView(descriptor+4),bindGroupLayouts:bgls,immediateSize:HEAPU32[descriptor+20>>2]};var device=WebGPU.getJsObject(devicePtr);var ptr=_emwgpuCreatePipelineLayout(0);WebGPU.Internals.jsObjectInsert(ptr,device.createPipelineLayout(desc));return ptr},r:(devicePtr,descriptor)=>{var desc={type:WebGPU.QueryType[HEAP32[descriptor+12>>2]],count:HEAPU32[descriptor+16>>2]};var device=WebGPU.getJsObject(devicePtr);var ptr=_emwgpuCreateQuerySet(0);WebGPU.Internals.jsObjectInsert(ptr,device.createQuerySet(desc));return ptr},o:(devicePtr,descriptor)=>{var desc;if(descriptor)desc={label:WebGPU.makeStringFromOptionalStringView(descriptor+4),addressModeU:WebGPU.AddressMode[HEAP32[descriptor+12>>2]],addressModeV:WebGPU.AddressMode[HEAP32[descriptor+16>>2]],addressModeW:WebGPU.AddressMode[HEAP32[descriptor+20>>2]],magFilter:WebGPU.FilterMode[HEAP32[descriptor+24>>2]],minFilter:WebGPU.FilterMode[HEAP32[descriptor+28>>2]],mipmapFilter:WebGPU.MipmapFilterMode[HEAP32[descriptor+32>>2]],lodMinClamp:HEAPF32[descriptor+36>>2],lodMaxClamp:HEAPF32[descriptor+40>>2],compare:WebGPU.CompareFunction[HEAP32[descriptor+44>>2]],maxAnisotropy:HEAPU16[descriptor+48>>1]};var device=WebGPU.getJsObject(devicePtr);var ptr=_emwgpuCreateSampler(0);WebGPU.Internals.jsObjectInsert(ptr,device.createSampler(desc));return ptr},U:(devicePtr,descriptor)=>{var nextInChainPtr=HEAPU32[descriptor>>2];var textureBindingViewDimension;if(nextInChainPtr!==0){HEAP32[nextInChainPtr+4>>2];var textureBindingViewDimensionDescriptor=nextInChainPtr;textureBindingViewDimension=WebGPU.TextureViewDimension[HEAP32[textureBindingViewDimensionDescriptor+8>>2]]}var desc={label:WebGPU.makeStringFromOptionalStringView(descriptor+4),size:WebGPU.makeExtent3D(descriptor+28),mipLevelCount:HEAPU32[descriptor+44>>2],sampleCount:HEAPU32[descriptor+48>>2],dimension:WebGPU.TextureDimension[HEAP32[descriptor+24>>2]],format:WebGPU.TextureFormat[HEAP32[descriptor+40>>2]],usage:HEAPU32[descriptor+16>>2],textureBindingViewDimension};var viewFormatCount=HEAPU32[descriptor+52>>2];if(viewFormatCount){var viewFormatsPtr=HEAPU32[descriptor+56>>2];desc["viewFormats"]=Array.from(HEAP32.subarray(viewFormatsPtr>>2,viewFormatsPtr+viewFormatCount*4>>2),format=>WebGPU.TextureFormat[format])}var device=WebGPU.getJsObject(devicePtr);var ptr=_emwgpuCreateTexture(0);WebGPU.Internals.jsObjectInsert(ptr,device.createTexture(desc));return ptr},M:(devicePtr,limitsOutPtr)=>{var device=WebGPU.getJsObject(devicePtr);WebGPU.fillLimitStruct(device.limits,limitsOutPtr);return 1},N:(devicePtr,featureEnumValue)=>{var device=WebGPU.getJsObject(devicePtr);return device.features.has(WebGPU.FeatureName[featureEnumValue])},O:(queuePtr,commandCount,commands)=>{var queue=WebGPU.getJsObject(queuePtr);var cmds=Array.from(HEAP32.subarray(commands>>2,commands+commandCount*4>>2),id=>WebGPU.getJsObject(id));queue.submit(cmds)},Q:function(queuePtr,bufferPtr,bufferOffset,data,size){bufferOffset=bigintToI53Checked(bufferOffset);var queue=WebGPU.getJsObject(queuePtr);var buffer=WebGPU.getJsObject(bufferPtr);var subarray=HEAPU8.subarray(data,data+size);queue.writeBuffer(buffer,bufferOffset,subarray,0,size)},b:(queuePtr,destinationPtr,data,dataSize,dataLayoutPtr,writeSizePtr)=>{var queue=WebGPU.getJsObject(queuePtr);var destination=WebGPU.makeTexelCopyTextureInfo(destinationPtr);var dataLayout=WebGPU.makeTexelCopyBufferLayout(dataLayoutPtr);var writeSize=WebGPU.makeExtent3D(writeSizePtr);var subarray=HEAPU8.subarray(data,data+dataSize);queue.writeTexture(destination,subarray,dataLayout,writeSize)},g:(texturePtr,descriptor)=>{var desc;if(descriptor){var swizzle;var nextInChainPtr=HEAPU32[descriptor>>2];if(nextInChainPtr!==0){HEAP32[nextInChainPtr+4>>2];var swizzleDescriptor=nextInChainPtr;var swizzlePtr=swizzleDescriptor+8;var r=WebGPU.ComponentSwizzle[HEAP32[swizzlePtr>>2]]||"r";var g=WebGPU.ComponentSwizzle[HEAP32[swizzlePtr+4>>2]]||"g";var b=WebGPU.ComponentSwizzle[HEAP32[swizzlePtr+8>>2]]||"b";var a=WebGPU.ComponentSwizzle[HEAP32[swizzlePtr+12>>2]]||"a";swizzle=`${r}${g}${b}${a}`}var mipLevelCount=HEAPU32[descriptor+24>>2];var arrayLayerCount=HEAPU32[descriptor+32>>2];desc={label:WebGPU.makeStringFromOptionalStringView(descriptor+4),format:WebGPU.TextureFormat[HEAP32[descriptor+12>>2]],dimension:WebGPU.TextureViewDimension[HEAP32[descriptor+16>>2]],baseMipLevel:HEAPU32[descriptor+20>>2],mipLevelCount:mipLevelCount===4294967295?void 0:mipLevelCount,baseArrayLayer:HEAPU32[descriptor+28>>2],arrayLayerCount:arrayLayerCount===4294967295?void 0:arrayLayerCount,aspect:WebGPU.TextureAspect[HEAP32[descriptor+36>>2]],usage:HEAPU32[descriptor+40>>2],swizzle}}var texture=WebGPU.getJsObject(texturePtr);var ptr=_emwgpuCreateTextureView(0);WebGPU.Internals.jsObjectInsert(ptr,texture.createView(desc));return ptr},L:texturePtr=>{WebGPU.getJsObject(texturePtr).destroy()},J:texturePtr=>{var texture=WebGPU.getJsObject(texturePtr);return texture.depthOrArrayLayers},K:texturePtr=>{var texture=WebGPU.getJsObject(texturePtr);return WebGPU.TextureDimension.indexOf(texture.dimension)},n:texturePtr=>{var texture=WebGPU.getJsObject(texturePtr);return WebGPU.TextureFormat.indexOf(texture.format)},k:texturePtr=>{var texture=WebGPU.getJsObject(texturePtr);return texture.height},m:function(texturePtr){var ret=(()=>{var texture=WebGPU.getJsObject(texturePtr);return texture.usage})();return BigInt(ret)},l:texturePtr=>{var texture=WebGPU.getJsObject(texturePtr);return texture.width}};var wasmExports;wasmExports=await async function(){function receiveInstance(instance){wasmExports=instance.exports;assignWasmExports(wasmExports);updateMemoryViews();return wasmExports}var info=getWasmImports();var instantiateWasm=Module["instantiateWasm"];if(instantiateWasm)return new Promise(resolve=>{instantiateWasm(info,inst=>resolve(receiveInstance(inst)))});wasmBinaryFile??=findWasmBinary();var result=await instantiateAsync(void 0,wasmBinaryFile,info);var exports=function(result){return receiveInstance(result["instance"])}(result);return exports}();await async function(){preRun();var setStatus=Module["setStatus"];if(setStatus){setStatus("Running...");await new Promise(resolve=>setTimeout(resolve,1));setTimeout(setStatus,1,"")}if(ABORT)return;initRuntime();Module["onRuntimeInitialized"]?.();postRun()}();Module["importDevice"]=(device,parent)=>WebGPU.importJsDevice(device,parent);Module["importTexture"]=(texture,parent)=>WebGPU.importJsTexture(texture,parent);
|
|
1
|
+
async function createDCGridModule(moduleArg={}){var Module=moduleArg;var ENVIRONMENT_IS_WEB=!!globalThis.window;var ENVIRONMENT_IS_WORKER=!!globalThis.WorkerGlobalScope;var ENVIRONMENT_IS_NODE=globalThis.process?.versions?.node&&globalThis.process?.type!="renderer";if(ENVIRONMENT_IS_NODE){const{createRequire}=await(import("node:module"));var require=createRequire(import.meta.url)}var thisProgram="./this.program";var quit_=(status,toThrow)=>{throw toThrow};var _scriptName=import.meta.url;var scriptDirectory="";function locateFile(path){if(Module["locateFile"])return Module["locateFile"](path,scriptDirectory);return scriptDirectory+path}var readAsync,readBinary;if(ENVIRONMENT_IS_NODE){var fs=require("node:fs");if(_scriptName.startsWith("file:"))scriptDirectory=require("node:path").dirname(require("node:url").fileURLToPath(_scriptName))+"/";readBinary=filename=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename);return ret};readAsync=async(filename,binary=true)=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename,binary?void 0:"utf8");return ret};if(process.argv.length>1)thisProgram=process.argv[1].replace(/\\/g,"/");process.argv.slice(2);quit_=(status,toThrow)=>{process.exitCode=status;throw toThrow}}else if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){try{scriptDirectory=new URL(".",_scriptName).href}catch{}if(ENVIRONMENT_IS_WORKER)readBinary=url=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.responseType="arraybuffer";xhr.send(null);return new Uint8Array(xhr.response)};readAsync=async url=>{var response=await fetch(url,{credentials:"same-origin"});if(response.ok)return response.arrayBuffer();throw new Error(response.status+" : "+response.url)}}console.log.bind(console);var err=console.error.bind(console);var ABORT=false;var EXITSTATUS;function assert(condition,text){if(!condition)abort(text)}var isFileURI=filename=>filename.startsWith("file://");var runtimeInitialized=false;function getMemoryBuffer(){return wasmMemory.buffer}function updateMemoryViews(){if(HEAP8?.buffer?.resizable)return;var b=getMemoryBuffer();HEAP8=new Int8Array(b);Module["HEAPU8"]=HEAPU8=new Uint8Array(b);HEAPU16=new Uint16Array(b);HEAP32=new Int32Array(b);HEAPU32=new Uint32Array(b);Module["HEAPF32"]=HEAPF32=new Float32Array(b);HEAPF64=new Float64Array(b);HEAP64=new BigInt64Array(b)}function preRun(){var preRun=Module["preRun"];if(preRun){if(typeof preRun==="function")preRun=[preRun];onPreRuns.push(...preRun)}callRuntimeCallbacks(onPreRuns)}function initRuntime(){runtimeInitialized=true;wasmExports["W"]()}function postRun(){var postRun=Module["postRun"];if(postRun){if(typeof postRun==="function")postRun=[postRun];onPostRuns.push(...postRun)}callRuntimeCallbacks(onPostRuns)}function abort(what){Module["onAbort"]?.(what);what=`Aborted(${what})`;err(what);ABORT=true;what+=". Build with -sASSERTIONS for more info.";if(runtimeInitialized)___trap();throw new WebAssembly.RuntimeError(what)}var wasmBinaryFile;function findWasmBinary(){if(Module["locateFile"])return locateFile("dcgrid.wasm");return new URL("dcgrid.wasm",import.meta.url).href}function getBinarySync(file){if(readBinary)return readBinary(file);throw"both async and sync fetching of the wasm failed"}async function getWasmBinary(binaryFile){if(true)try{return await readAsync(binaryFile)}catch{}return getBinarySync(binaryFile)}async function instantiateArrayBuffer(binaryFile,imports){try{var binary=await getWasmBinary(binaryFile);var instance=await WebAssembly.instantiate(binary,imports);return instance}catch(reason){err(`failed to asynchronously prepare wasm: ${reason}`);abort(reason)}}async function instantiateAsync(binary,binaryFile,imports){if(!binary&&!ENVIRONMENT_IS_NODE)try{var response=fetch(binaryFile,{credentials:"same-origin"});var instantiationResult=await WebAssembly.instantiateStreaming(response,imports);return instantiationResult}catch(reason){err(`wasm streaming compile failed: ${reason}`);err("falling back to ArrayBuffer instantiation")}return instantiateArrayBuffer(binaryFile,imports)}function getWasmImports(){var imports={a:wasmImports};return imports}class ExitStatus{name="ExitStatus";constructor(status){this.message=`Program terminated with exit(${status})`;this.status=status}}var HEAP8;var callRuntimeCallbacks=callbacks=>{while(callbacks.length>0)callbacks.shift()(Module)};var onPostRuns=[];var onPreRuns=[];var noExitRuntime=true;var HEAP32;var HEAPU32;var HEAPU8;var stringToUTF8Array=(str,heap,outIdx,maxBytesToWrite)=>{if(!(maxBytesToWrite>0))return 0;var startIdx=outIdx;var endIdx=outIdx+maxBytesToWrite-1;for(var i=0;i<str.length;++i){var u=str.codePointAt(i);if(u<=127){if(outIdx>=endIdx)break;heap[outIdx++]=u}else if(u<=2047){if(outIdx+1>=endIdx)break;heap[outIdx++]=192|u>>6;heap[outIdx++]=128|u&63}else if(u<=65535){if(outIdx+2>=endIdx)break;heap[outIdx++]=224|u>>12;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63}else{if(outIdx+3>=endIdx)break;heap[outIdx++]=240|u>>18;heap[outIdx++]=128|u>>12&63;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63;i++}}heap[outIdx]=0;return outIdx-startIdx};var stringToUTF8=(str,outPtr,maxBytesToWrite)=>stringToUTF8Array(str,HEAPU8,outPtr,maxBytesToWrite);var HEAP64;var bigintToI53Checked=num=>num<-9007199254740992||num>9007199254740992?NaN:Number(num);var checkWasiClock=clock_id=>clock_id>=0&&clock_id<=3;var _emscripten_date_now=()=>Date.now();var _emscripten_get_now=()=>performance.now();var alignMemory=(size,alignment)=>Math.ceil(size/alignment)*alignment;var getHeapMax=()=>2147483648;var growMemory=size=>{var oldHeapSize=wasmMemory.buffer.byteLength;var pages=(size-oldHeapSize+65535)/65536|0;try{wasmMemory.grow(pages);updateMemoryViews();return 1}catch(e){}};var HEAPF32;var HEAPF64;var UTF8Decoder=globalThis.TextDecoder&&new TextDecoder;var findStringEnd=(heapOrArray,idx,maxBytesToRead,ignoreNul)=>{var maxIdx=idx+maxBytesToRead;if(ignoreNul)return maxIdx;while(heapOrArray[idx]&&!(idx>=maxIdx))++idx;return idx};var UTF8ArrayToString=(heapOrArray,idx=0,maxBytesToRead,ignoreNul)=>{var endPtr=findStringEnd(heapOrArray,idx,maxBytesToRead,ignoreNul);if(endPtr-idx>16&&heapOrArray.buffer&&UTF8Decoder)return UTF8Decoder.decode(heapOrArray.subarray(idx,endPtr));var str="";while(idx<endPtr){var u0=heapOrArray[idx++];if(!(u0&128)){str+=String.fromCharCode(u0);continue}var u1=heapOrArray[idx++]&63;if((u0&224)==192){str+=String.fromCharCode((u0&31)<<6|u1);continue}var u2=heapOrArray[idx++]&63;if((u0&240)==224)u0=(u0&15)<<12|u1<<6|u2;else u0=(u0&7)<<18|u1<<12|u2<<6|heapOrArray[idx++]&63;if(u0<65536)str+=String.fromCharCode(u0);else{var ch=u0-65536;str+=String.fromCharCode(55296|ch>>10,56320|ch&1023)}}return str};var UTF8ToString_cache={};var UTF8ToString=(ptr,maxBytesToRead,ignoreNul)=>{var useCache=maxBytesToRead==null&&ptr>=1024&&ptr<149688;if(useCache){var rtn=UTF8ToString_cache[ptr];if(rtn!=null)return rtn}rtn=ptr?UTF8ArrayToString(HEAPU8,ptr,maxBytesToRead,ignoreNul):"";if(useCache)UTF8ToString_cache[ptr]=rtn;return rtn};var wasmTableMirror=[];var getWasmTableEntry=funcPtr=>{var func=wasmTableMirror[funcPtr];if(!func)wasmTableMirror[funcPtr]=func=wasmTable.get(funcPtr);return func};var lengthBytesUTF8=str=>{var len=0;for(var i=0;i<str.length;++i){var u=str.codePointAt(i);if(u<=127)len++;else if(u<=2047)len+=2;else if(u<=65535)len+=3;else{len+=4;i++}}return len};var readI53FromI64=ptr=>HEAPU32[ptr>>2]+HEAP32[ptr+4>>2]*4294967296;var stackRestore=val=>__emscripten_stack_restore(val);var stackSave=()=>_emscripten_stack_get_current();var stringToNewUTF8=str=>{var size=lengthBytesUTF8(str)+1;var ret=_malloc(size);if(ret)stringToUTF8(str,ret,size);return ret};var stackAlloc=sz=>__emscripten_stack_alloc(sz);var stringToUTF8OnStack=str=>{var size=lengthBytesUTF8(str)+1;var ret=stackAlloc(size);stringToUTF8(str,ret,size);return ret};var writeI53ToI64=(ptr,num)=>{HEAPU32[ptr>>2]=num;var lower=HEAPU32[ptr>>2];HEAPU32[ptr+4>>2]=(num-lower)/4294967296};var WebGPU={Internals:{jsObjects:[],jsObjectInsert:(ptr,jsObject)=>{ptr>>>=0;WebGPU.Internals.jsObjects[ptr]=jsObject},bufferOnUnmaps:[],futures:[],futureInsert:()=>{}},getJsObject:ptr=>{if(!ptr)return;ptr>>>=0;return WebGPU.Internals.jsObjects[ptr]},importJsAdapter:(obj,parentPtr=0)=>{var ptr=_emwgpuCreateAdapter(parentPtr);WebGPU.Internals.jsObjects[ptr]=obj;return ptr},importJsBindGroup:(obj,parentPtr=0)=>{var ptr=_emwgpuCreateBindGroup(parentPtr);WebGPU.Internals.jsObjects[ptr]=obj;return ptr},importJsBindGroupLayout:(obj,parentPtr=0)=>{var ptr=_emwgpuCreateBindGroupLayout(parentPtr);WebGPU.Internals.jsObjects[ptr]=obj;return ptr},importJsBuffer:(buffer,parentPtr=0)=>{assert(buffer.mapState==="unmapped");var bufferPtr=_emwgpuImportBuffer(parentPtr);WebGPU.Internals.jsObjectInsert(bufferPtr,buffer);return bufferPtr},importJsCommandBuffer:(obj,parentPtr=0)=>{var ptr=_emwgpuCreateCommandBuffer(parentPtr);WebGPU.Internals.jsObjects[ptr]=obj;return ptr},importJsCommandEncoder:(obj,parentPtr=0)=>{var ptr=_emwgpuCreateCommandEncoder(parentPtr);WebGPU.Internals.jsObjects[ptr]=obj;return ptr},importJsComputePassEncoder:(obj,parentPtr=0)=>{var ptr=_emwgpuCreateComputePassEncoder(parentPtr);WebGPU.Internals.jsObjects[ptr]=obj;return ptr},importJsComputePipeline:(obj,parentPtr=0)=>{var ptr=_emwgpuCreateComputePipeline(parentPtr);WebGPU.Internals.jsObjects[ptr]=obj;return ptr},importJsDevice:(device,parentPtr=0)=>{var queuePtr=_emwgpuCreateQueue(parentPtr);var devicePtr=_emwgpuCreateDevice(parentPtr,queuePtr);WebGPU.Internals.jsObjectInsert(queuePtr,device.queue);WebGPU.Internals.jsObjectInsert(devicePtr,device);return devicePtr},importJsExternalTexture:(obj,parentPtr=0)=>{var ptr=_emwgpuCreateExternalTexture(parentPtr);WebGPU.Internals.jsObjects[ptr]=obj;return ptr},importJsPipelineLayout:(obj,parentPtr=0)=>{var ptr=_emwgpuCreatePipelineLayout(parentPtr);WebGPU.Internals.jsObjects[ptr]=obj;return ptr},importJsQuerySet:(obj,parentPtr=0)=>{var ptr=_emwgpuCreateQuerySet(parentPtr);WebGPU.Internals.jsObjects[ptr]=obj;return ptr},importJsQueue:(obj,parentPtr=0)=>{var ptr=_emwgpuCreateQueue(parentPtr);WebGPU.Internals.jsObjects[ptr]=obj;return ptr},importJsRenderBundle:(obj,parentPtr=0)=>{var ptr=_emwgpuCreateRenderBundle(parentPtr);WebGPU.Internals.jsObjects[ptr]=obj;return ptr},importJsRenderBundleEncoder:(obj,parentPtr=0)=>{var ptr=_emwgpuCreateRenderBundleEncoder(parentPtr);WebGPU.Internals.jsObjects[ptr]=obj;return ptr},importJsRenderPassEncoder:(obj,parentPtr=0)=>{var ptr=_emwgpuCreateRenderPassEncoder(parentPtr);WebGPU.Internals.jsObjects[ptr]=obj;return ptr},importJsRenderPipeline:(obj,parentPtr=0)=>{var ptr=_emwgpuCreateRenderPipeline(parentPtr);WebGPU.Internals.jsObjects[ptr]=obj;return ptr},importJsSampler:(obj,parentPtr=0)=>{var ptr=_emwgpuCreateSampler(parentPtr);WebGPU.Internals.jsObjects[ptr]=obj;return ptr},importJsShaderModule:(obj,parentPtr=0)=>{var ptr=_emwgpuCreateShaderModule(parentPtr);WebGPU.Internals.jsObjects[ptr]=obj;return ptr},importJsSurface:(obj,parentPtr=0)=>{var ptr=_emwgpuCreateSurface(parentPtr);WebGPU.Internals.jsObjects[ptr]=obj;return ptr},importJsTexture:(obj,parentPtr=0)=>{var ptr=_emwgpuCreateTexture(parentPtr);WebGPU.Internals.jsObjects[ptr]=obj;return ptr},importJsTextureView:(obj,parentPtr=0)=>{var ptr=_emwgpuCreateTextureView(parentPtr);WebGPU.Internals.jsObjects[ptr]=obj;return ptr},errorCallback:(callback,type,message,userdata)=>{var sp=stackSave();var messagePtr=stringToUTF8OnStack(message);getWasmTableEntry(callback)(type,messagePtr,userdata);stackRestore(sp)},iterateExtensions:(root,handlers)=>{for(var ptr=HEAPU32[root>>2];ptr;ptr=HEAPU32[ptr>>2]){var sType=HEAP32[ptr+4>>2];handlers[sType](ptr)}},setStringView:(ptr,data,length)=>{HEAPU32[ptr>>2]=data;HEAPU32[ptr+4>>2]=length},makeStringFromStringView:stringViewPtr=>{var ptr=HEAPU32[stringViewPtr>>2];var length=HEAPU32[stringViewPtr+4>>2];return UTF8ToString(ptr,length)},makeStringFromOptionalStringView:stringViewPtr=>{var ptr=HEAPU32[stringViewPtr>>2];var length=HEAPU32[stringViewPtr+4>>2];if(!ptr){if(length===0)return"";return}return UTF8ToString(ptr,length)},makeColor:ptr=>({r:HEAPF64[ptr>>3],g:HEAPF64[ptr+8>>3],b:HEAPF64[ptr+16>>3],a:HEAPF64[ptr+24>>3]}),makeExtent3D:ptr=>({width:HEAPU32[ptr>>2],height:HEAPU32[ptr+4>>2],depthOrArrayLayers:HEAPU32[ptr+8>>2]}),makeOrigin3D:ptr=>({x:HEAPU32[ptr>>2],y:HEAPU32[ptr+4>>2],z:HEAPU32[ptr+8>>2]}),makeTexelCopyTextureInfo:ptr=>({texture:WebGPU.getJsObject(HEAPU32[ptr>>2]),mipLevel:HEAPU32[ptr+4>>2],origin:WebGPU.makeOrigin3D(ptr+8),aspect:WebGPU.TextureAspect[HEAP32[ptr+20>>2]]}),makeTexelCopyBufferLayout:ptr=>{var bytesPerRow=HEAPU32[ptr+8>>2];var rowsPerImage=HEAPU32[ptr+12>>2];return{offset:readI53FromI64(ptr),bytesPerRow:bytesPerRow===4294967295?void 0:bytesPerRow,rowsPerImage:rowsPerImage===4294967295?void 0:rowsPerImage}},makeTexelCopyBufferInfo:ptr=>{var layoutPtr=ptr+0;var bufferCopyView=WebGPU.makeTexelCopyBufferLayout(layoutPtr);bufferCopyView["buffer"]=WebGPU.getJsObject(HEAPU32[ptr+16>>2]);return bufferCopyView},makePassTimestampWrites:ptr=>{if(ptr===0)return;return{querySet:WebGPU.getJsObject(HEAPU32[ptr+4>>2]),beginningOfPassWriteIndex:HEAPU32[ptr+8>>2],endOfPassWriteIndex:HEAPU32[ptr+12>>2]}},makePipelineConstants:(constantCount,constantsPtr)=>{if(!constantCount)return;var constants={};for(var i=0;i<constantCount;++i){var entryPtr=constantsPtr+24*i;var key=WebGPU.makeStringFromStringView(entryPtr+4);constants[key]=HEAPF64[entryPtr+16>>3]}return constants},makePipelineLayout:layoutPtr=>{if(!layoutPtr)return"auto";return WebGPU.getJsObject(layoutPtr)},makeComputeState:ptr=>{if(!ptr)return;var desc={module:WebGPU.getJsObject(HEAPU32[ptr+4>>2]),constants:WebGPU.makePipelineConstants(HEAPU32[ptr+16>>2],HEAPU32[ptr+20>>2]),entryPoint:WebGPU.makeStringFromOptionalStringView(ptr+8)};return desc},makeComputePipelineDesc:descriptor=>{var desc={label:WebGPU.makeStringFromOptionalStringView(descriptor+4),layout:WebGPU.makePipelineLayout(HEAPU32[descriptor+12>>2]),compute:WebGPU.makeComputeState(descriptor+16)};return desc},makeRenderPipelineDesc:descriptor=>{function makeBlendComponent(bdPtr){if(!bdPtr)return;return{operation:WebGPU.BlendOperation[HEAP32[bdPtr>>2]],srcFactor:WebGPU.BlendFactor[HEAP32[bdPtr+4>>2]],dstFactor:WebGPU.BlendFactor[HEAP32[bdPtr+8>>2]]}}function makeBlendState(bsPtr){if(!bsPtr)return;return{alpha:makeBlendComponent(bsPtr+12),color:makeBlendComponent(bsPtr+0)}}function makeColorState(csPtr){var format=WebGPU.TextureFormat[HEAP32[csPtr+4>>2]];return format?{format,blend:makeBlendState(HEAPU32[csPtr+8>>2]),writeMask:HEAPU32[csPtr+16>>2]}:void 0}function makeColorStates(count,csArrayPtr){var states=[];for(var i=0;i<count;++i)states.push(makeColorState(csArrayPtr+24*i));return states}function makeStencilStateFace(ssfPtr){return{compare:WebGPU.CompareFunction[HEAP32[ssfPtr>>2]],failOp:WebGPU.StencilOperation[HEAP32[ssfPtr+4>>2]],depthFailOp:WebGPU.StencilOperation[HEAP32[ssfPtr+8>>2]],passOp:WebGPU.StencilOperation[HEAP32[ssfPtr+12>>2]]}}function makeVertexAttribute(vaPtr){return{format:WebGPU.VertexFormat[HEAP32[vaPtr+4>>2]],offset:readI53FromI64(vaPtr+8),shaderLocation:HEAPU32[vaPtr+16>>2]}}function makeVertexAttributes(count,vaArrayPtr){var vas=[];for(var i=0;i<count;++i)vas.push(makeVertexAttribute(vaArrayPtr+i*24));return vas}function makeVertexBuffer(vbPtr){if(!vbPtr)return;var stepMode=WebGPU.VertexStepMode[HEAP32[vbPtr+4>>2]];var attributeCount=HEAPU32[vbPtr+16>>2];if(!stepMode&&!attributeCount)return null;return{arrayStride:readI53FromI64(vbPtr+8),stepMode,attributes:makeVertexAttributes(attributeCount,HEAPU32[vbPtr+20>>2])}}function makeVertexBuffers(count,vbArrayPtr){if(!count)return;var vbs=[];for(var i=0;i<count;++i)vbs.push(makeVertexBuffer(vbArrayPtr+i*24));return vbs}var desc={label:WebGPU.makeStringFromOptionalStringView(descriptor+4),layout:WebGPU.makePipelineLayout(HEAPU32[descriptor+12>>2]),vertex:function(viPtr){if(!viPtr)return;var desc={module:WebGPU.getJsObject(HEAPU32[viPtr+4>>2]),constants:WebGPU.makePipelineConstants(HEAPU32[viPtr+16>>2],HEAPU32[viPtr+20>>2]),buffers:makeVertexBuffers(HEAPU32[viPtr+24>>2],HEAPU32[viPtr+28>>2]),entryPoint:WebGPU.makeStringFromOptionalStringView(viPtr+8)};return desc}(descriptor+16),primitive:function(psPtr){if(!psPtr)return;return{topology:WebGPU.PrimitiveTopology[HEAP32[psPtr+4>>2]],stripIndexFormat:WebGPU.IndexFormat[HEAP32[psPtr+8>>2]],frontFace:WebGPU.FrontFace[HEAP32[psPtr+12>>2]],cullMode:WebGPU.CullMode[HEAP32[psPtr+16>>2]],unclippedDepth:!!HEAPU32[psPtr+20>>2]}}(descriptor+48),depthStencil:function(dssPtr){if(!dssPtr)return;return{format:WebGPU.TextureFormat[HEAP32[dssPtr+4>>2]],depthWriteEnabled:!!HEAPU32[dssPtr+8>>2],depthCompare:WebGPU.CompareFunction[HEAP32[dssPtr+12>>2]],stencilFront:makeStencilStateFace(dssPtr+16),stencilBack:makeStencilStateFace(dssPtr+32),stencilReadMask:HEAPU32[dssPtr+48>>2],stencilWriteMask:HEAPU32[dssPtr+52>>2],depthBias:HEAP32[dssPtr+56>>2],depthBiasSlopeScale:HEAPF32[dssPtr+60>>2],depthBiasClamp:HEAPF32[dssPtr+64>>2]}}(HEAPU32[descriptor+72>>2]),multisample:function(msPtr){if(!msPtr)return;return{count:HEAPU32[msPtr+4>>2],mask:HEAPU32[msPtr+8>>2],alphaToCoverageEnabled:!!HEAPU32[msPtr+12>>2]}}(descriptor+76),fragment:function(fsPtr){if(!fsPtr)return;var desc={module:WebGPU.getJsObject(HEAPU32[fsPtr+4>>2]),constants:WebGPU.makePipelineConstants(HEAPU32[fsPtr+16>>2],HEAPU32[fsPtr+20>>2]),targets:makeColorStates(HEAPU32[fsPtr+24>>2],HEAPU32[fsPtr+28>>2]),entryPoint:WebGPU.makeStringFromOptionalStringView(fsPtr+8)};return desc}(HEAPU32[descriptor+92>>2])};return desc},fillLimitStruct:(limits,limitsOutPtr)=>{var nextInChainPtr=HEAPU32[limitsOutPtr>>2];function setLimitValueU32(name,basePtr,limitOffset,fallbackValue=0){var limitValue=limits[name]??fallbackValue;HEAPU32[basePtr+limitOffset>>2]=limitValue}function setLimitValueU64(name,basePtr,limitOffset,fallbackValue=0){var limitValue=limits[name]??fallbackValue;writeI53ToI64(basePtr+limitOffset,limitValue)}setLimitValueU32("maxTextureDimension1D",limitsOutPtr,4);setLimitValueU32("maxTextureDimension2D",limitsOutPtr,8);setLimitValueU32("maxTextureDimension3D",limitsOutPtr,12);setLimitValueU32("maxTextureArrayLayers",limitsOutPtr,16);setLimitValueU32("maxBindGroups",limitsOutPtr,20);setLimitValueU32("maxBindGroupsPlusVertexBuffers",limitsOutPtr,24);setLimitValueU32("maxBindingsPerBindGroup",limitsOutPtr,28);setLimitValueU32("maxDynamicUniformBuffersPerPipelineLayout",limitsOutPtr,32);setLimitValueU32("maxDynamicStorageBuffersPerPipelineLayout",limitsOutPtr,36);setLimitValueU32("maxSampledTexturesPerShaderStage",limitsOutPtr,40);setLimitValueU32("maxSamplersPerShaderStage",limitsOutPtr,44);setLimitValueU32("maxStorageBuffersPerShaderStage",limitsOutPtr,48);setLimitValueU32("maxStorageTexturesPerShaderStage",limitsOutPtr,52);setLimitValueU32("maxUniformBuffersPerShaderStage",limitsOutPtr,56);setLimitValueU32("minUniformBufferOffsetAlignment",limitsOutPtr,80);setLimitValueU32("minStorageBufferOffsetAlignment",limitsOutPtr,84);setLimitValueU64("maxUniformBufferBindingSize",limitsOutPtr,64);setLimitValueU64("maxStorageBufferBindingSize",limitsOutPtr,72);setLimitValueU32("maxVertexBuffers",limitsOutPtr,88);setLimitValueU64("maxBufferSize",limitsOutPtr,96);setLimitValueU32("maxVertexAttributes",limitsOutPtr,104);setLimitValueU32("maxVertexBufferArrayStride",limitsOutPtr,108);setLimitValueU32("maxInterStageShaderVariables",limitsOutPtr,112);setLimitValueU32("maxColorAttachments",limitsOutPtr,116);setLimitValueU32("maxColorAttachmentBytesPerSample",limitsOutPtr,120);setLimitValueU32("maxComputeWorkgroupStorageSize",limitsOutPtr,124);setLimitValueU32("maxComputeInvocationsPerWorkgroup",limitsOutPtr,128);setLimitValueU32("maxComputeWorkgroupSizeX",limitsOutPtr,132);setLimitValueU32("maxComputeWorkgroupSizeY",limitsOutPtr,136);setLimitValueU32("maxComputeWorkgroupSizeZ",limitsOutPtr,140);setLimitValueU32("maxComputeWorkgroupsPerDimension",limitsOutPtr,144);setLimitValueU32("maxImmediateSize",limitsOutPtr,148);if(nextInChainPtr!==0){HEAP32[nextInChainPtr+4>>2];var compatibilityModeLimitsPtr=nextInChainPtr;setLimitValueU32("maxStorageBuffersInVertexStage",compatibilityModeLimitsPtr,8,limits.maxStorageBuffersPerShaderStage);setLimitValueU32("maxStorageBuffersInFragmentStage",compatibilityModeLimitsPtr,16,limits.maxStorageBuffersPerShaderStage);setLimitValueU32("maxStorageTexturesInVertexStage",compatibilityModeLimitsPtr,12,limits.maxStorageTexturesPerShaderStage);setLimitValueU32("maxStorageTexturesInFragmentStage",compatibilityModeLimitsPtr,20,limits.maxStorageTexturesPerShaderStage)}},fillAdapterInfoStruct:(info,infoStruct)=>{HEAPU32[infoStruct+52>>2]=info.subgroupMinSize;HEAPU32[infoStruct+56>>2]=info.subgroupMaxSize;var strs=info.vendor+info.architecture+info.device+info.description;var strPtr=stringToNewUTF8(strs);var vendorLen=lengthBytesUTF8(info.vendor);WebGPU.setStringView(infoStruct+4,strPtr,vendorLen);strPtr+=vendorLen;var architectureLen=lengthBytesUTF8(info.architecture);WebGPU.setStringView(infoStruct+12,strPtr,architectureLen);strPtr+=architectureLen;var deviceLen=lengthBytesUTF8(info.device);WebGPU.setStringView(infoStruct+20,strPtr,deviceLen);strPtr+=deviceLen;var descriptionLen=lengthBytesUTF8(info.description);WebGPU.setStringView(infoStruct+28,strPtr,descriptionLen);strPtr+=descriptionLen;HEAP32[infoStruct+36>>2]=2;var adapterType=info.isFallbackAdapter?3:4;HEAP32[infoStruct+40>>2]=adapterType;HEAPU32[infoStruct+44>>2]=0;HEAPU32[infoStruct+48>>2]=0;WebGPU.iterateExtensions(infoStruct,{327739:ext=>{let configCount=0;let configsPtr=0;if(info.subgroupMatrixConfigs){configCount=info.subgroupMatrixConfigs.length;configsPtr=_malloc(configCount*28);for(const[i,cfg]of info.subgroupMatrixConfigs.entries()){const ptr=configsPtr+i*28;const componentType=WebGPU.SubgroupMatrixComponentType.indexOf(cfg.componentType);const resultComponentType=WebGPU.SubgroupMatrixComponentType.indexOf(cfg.resultComponentType);HEAP32[ptr>>2]=componentType;HEAP32[ptr+4>>2]=resultComponentType;HEAPU32[ptr+8>>2]=cfg.M;HEAPU32[ptr+12>>2]=cfg.N;HEAPU32[ptr+16>>2]=cfg.K}}HEAPU32[ext+12>>2]=configsPtr;HEAPU32[ext+8>>2]=configCount}})},AddressMode:[,"clamp-to-edge","repeat","mirror-repeat"],BlendFactor:[,"zero","one","src","one-minus-src","src-alpha","one-minus-src-alpha","dst","one-minus-dst","dst-alpha","one-minus-dst-alpha","src-alpha-saturated","constant","one-minus-constant","src1","one-minus-src1","src1-alpha","one-minus-src1-alpha"],BlendOperation:[,"add","subtract","reverse-subtract","min","max"],BufferBindingType:[,,"uniform","storage","read-only-storage"],BufferMapState:[,"unmapped","pending","mapped"],CompareFunction:[,"never","less","equal","less-equal","greater","not-equal","greater-equal","always"],CompilationInfoRequestStatus:[,"success","callback-cancelled"],ComponentSwizzle:[,"0","1","r","g","b","a"],CompositeAlphaMode:[,"opaque","premultiplied","unpremultiplied","inherit"],CullMode:[,"none","front","back"],ErrorFilter:[,"validation","out-of-memory","internal"],FeatureLevel:[,"compatibility","core"],FeatureName:{1:"core-features-and-limits",2:"depth-clip-control",3:"depth32float-stencil8",4:"texture-compression-bc",5:"texture-compression-bc-sliced-3d",6:"texture-compression-etc2",7:"texture-compression-astc",8:"texture-compression-astc-sliced-3d",9:"timestamp-query",10:"indirect-first-instance",11:"shader-f16",12:"rg11b10ufloat-renderable",13:"bgra8unorm-storage",14:"float32-filterable",15:"float32-blendable",16:"clip-distances",17:"dual-source-blending",18:"subgroups",19:"texture-formats-tier1",20:"texture-formats-tier2",21:"primitive-index",22:"texture-component-swizzle",23:"subgroup-size-control",24:"texture-compression-unaligned",25:"atomic-vec2u-min-max",327692:"chromium-experimental-unorm16-texture-formats",327729:"chromium-experimental-multi-draw-indirect",327732:"chromium-experimental-subgroup-matrix"},FilterMode:[,"nearest","linear"],FrontFace:[,"ccw","cw"],IndexFormat:[,"uint16","uint32"],InstanceFeatureName:[,"timed-wait-any","shader-source-spirv","multiple-devices-per-adapter"],LoadOp:[,"load","clear"],MipmapFilterMode:[,"nearest","linear"],OptionalBool:["false","true"],PowerPreference:[,"low-power","high-performance"],PredefinedColorSpace:[,"srgb","display-p3"],PrimitiveTopology:[,"point-list","line-list","line-strip","triangle-list","triangle-strip"],QueryType:[,"occlusion","timestamp"],SamplerBindingType:[,,"filtering","non-filtering","comparison"],Status:[,"success","error"],StencilOperation:[,"keep","zero","replace","invert","increment-clamp","decrement-clamp","increment-wrap","decrement-wrap"],StorageTextureAccess:[,,"write-only","read-only","read-write"],StoreOp:[,"store","discard"],SubgroupMatrixComponentType:[,"f32","f16","u32","i32","u8","i8"],SurfaceGetCurrentTextureStatus:[,"success-optimal","success-suboptimal","timeout","outdated","lost","error"],TextureAspect:[,"all","stencil-only","depth-only"],TextureDimension:[,"1d","2d","3d"],TextureFormat:[,"r8unorm","r8snorm","r8uint","r8sint","r16unorm","r16snorm","r16uint","r16sint","r16float","rg8unorm","rg8snorm","rg8uint","rg8sint","r32float","r32uint","r32sint","rg16unorm","rg16snorm","rg16uint","rg16sint","rg16float","rgba8unorm","rgba8unorm-srgb","rgba8snorm","rgba8uint","rgba8sint","bgra8unorm","bgra8unorm-srgb","rgb10a2uint","rgb10a2unorm","rg11b10ufloat","rgb9e5ufloat","rg32float","rg32uint","rg32sint","rgba16unorm","rgba16snorm","rgba16uint","rgba16sint","rgba16float","rgba32float","rgba32uint","rgba32sint","stencil8","depth16unorm","depth24plus","depth24plus-stencil8","depth32float","depth32float-stencil8","bc1-rgba-unorm","bc1-rgba-unorm-srgb","bc2-rgba-unorm","bc2-rgba-unorm-srgb","bc3-rgba-unorm","bc3-rgba-unorm-srgb","bc4-r-unorm","bc4-r-snorm","bc5-rg-unorm","bc5-rg-snorm","bc6h-rgb-ufloat","bc6h-rgb-float","bc7-rgba-unorm","bc7-rgba-unorm-srgb","etc2-rgb8unorm","etc2-rgb8unorm-srgb","etc2-rgb8a1unorm","etc2-rgb8a1unorm-srgb","etc2-rgba8unorm","etc2-rgba8unorm-srgb","eac-r11unorm","eac-r11snorm","eac-rg11unorm","eac-rg11snorm","astc-4x4-unorm","astc-4x4-unorm-srgb","astc-5x4-unorm","astc-5x4-unorm-srgb","astc-5x5-unorm","astc-5x5-unorm-srgb","astc-6x5-unorm","astc-6x5-unorm-srgb","astc-6x6-unorm","astc-6x6-unorm-srgb","astc-8x5-unorm","astc-8x5-unorm-srgb","astc-8x6-unorm","astc-8x6-unorm-srgb","astc-8x8-unorm","astc-8x8-unorm-srgb","astc-10x5-unorm","astc-10x5-unorm-srgb","astc-10x6-unorm","astc-10x6-unorm-srgb","astc-10x8-unorm","astc-10x8-unorm-srgb","astc-10x10-unorm","astc-10x10-unorm-srgb","astc-12x10-unorm","astc-12x10-unorm-srgb","astc-12x12-unorm","astc-12x12-unorm-srgb"],TextureSampleType:[,,"float","unfilterable-float","depth","sint","uint"],TextureViewDimension:[,"1d","2d","2d-array","cube","cube-array","3d"],ToneMappingMode:[,"standard","extended"],VertexFormat:[,"uint8","uint8x2","uint8x4","sint8","sint8x2","sint8x4","unorm8","unorm8x2","unorm8x4","snorm8","snorm8x2","snorm8x4","uint16","uint16x2","uint16x4","sint16","sint16x2","sint16x4","unorm16","unorm16x2","unorm16x4","snorm16","snorm16x2","snorm16x4","float16","float16x2","float16x4","float32","float32x2","float32x3","float32x4","uint32","uint32x2","uint32x3","uint32x4","sint32","sint32x2","sint32x3","sint32x4","unorm10-10-10-2","unorm8x4-bgra","snorm10-10-10-2"],VertexStepMode:[,"vertex","instance"],WGSLLanguageFeatureName:[,"readonly_and_readwrite_storage_textures","packed_4x8_integer_dot_product","unrestricted_pointer_parameters","pointer_composite_access","uniform_buffer_standard_layout","subgroup_id","texture_and_sampler_let","subgroup_uniformity","texture_formats_tier1","linear_indexing","immediate_address_space","buffer_view","swizzle_assignment","fragment_depth"]};var handleException=e=>{if(e instanceof ExitStatus||e=="unwind")return EXITSTATUS;quit_(1,e)};var keepRuntimeAlive=()=>noExitRuntime||0>0;var _proc_exit=code=>{EXITSTATUS=code;if(!keepRuntimeAlive()){Module["onExit"]?.(code);ABORT=true}quit_(code,new ExitStatus(code))};var maybeExit=()=>{if(!keepRuntimeAlive())try{_exit(EXITSTATUS)}catch(e){handleException(e)}};var callUserCallback=(func,...args)=>{if(ABORT)return;try{return func(...args)}catch(e){handleException(e)}finally{maybeExit()}};var emwgpuStringToInt_CompilationMessageType={error:1,warning:2,info:3};var ENV={};var getExecutableName=()=>thisProgram;var getEnvStrings=()=>{if(!getEnvStrings.strings){var lang=(globalThis.navigator?.language??"C").replace("-","_")+".UTF-8";var env={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:lang,_:getExecutableName()};for(var x in ENV)if(ENV[x]===void 0)delete env[x];else env[x]=ENV[x];var strings=[];for(var x in env)strings.push(`${x}=${env[x]}`);getEnvStrings.strings=strings}return getEnvStrings.strings};var HEAPU16;var _exit=status=>{EXITSTATUS=status;_proc_exit(status)};if(Module["noExitRuntime"])noExitRuntime=Module["noExitRuntime"];if(Module["print"])Module["print"];if(Module["printErr"])err=Module["printErr"];if(Module["arguments"])Module["arguments"];if(Module["thisProgram"])thisProgram=Module["thisProgram"];var preInit=Module["preInit"];if(preInit){if(typeof preInit==="function")Module["preInit"]=preInit=[preInit];while(preInit.length>0)preInit.shift()()}Module["UTF8ToString"]=UTF8ToString;Module["stringToNewUTF8"]=stringToNewUTF8;var _malloc,_emwgpuCreateBindGroup,_emwgpuCreateBindGroupLayout,_emwgpuCreateCommandBuffer,_emwgpuCreateCommandEncoder,_emwgpuCreateComputePassEncoder,_emwgpuCreateComputePipeline,_emwgpuCreateExternalTexture,_emwgpuCreatePipelineLayout,_emwgpuCreateQuerySet,_emwgpuCreateRenderBundle,_emwgpuCreateRenderBundleEncoder,_emwgpuCreateRenderPassEncoder,_emwgpuCreateRenderPipeline,_emwgpuCreateSampler,_emwgpuCreateSurface,_emwgpuCreateTexture,_emwgpuCreateTextureView,_emwgpuCreateAdapter,_emwgpuImportBuffer,_emwgpuCreateDevice,_emwgpuCreateQueue,_emwgpuCreateShaderModule,_emwgpuOnCompilationInfoCompleted,_emwgpuOnCreateComputePipelineCompleted,_emwgpuOnMapAsyncCompleted,_emwgpuOnWorkDoneCompleted,_free,_memalign,___trap,__emscripten_stack_restore,__emscripten_stack_alloc,_emscripten_stack_get_current,wasmMemory,wasmTable;function assignWasmExports(wasmExports){Module["_dcgridJsInstance"]=wasmExports["X"];Module["_dcgridJsLastError"]=wasmExports["Y"];Module["_dcgridJsCreate"]=wasmExports["Z"];Module["_dcgridJsDefaults"]=wasmExports["$"];_malloc=Module["_malloc"]=wasmExports["aa"];Module["_dcgridJsDescribeScene"]=wasmExports["ba"];Module["_dcgridJsDesc"]=wasmExports["ca"];Module["_dcgridJsSetStepParams"]=wasmExports["da"];Module["_dcgridJsStats"]=wasmExports["ea"];Module["_dcgridJsSetVolume"]=wasmExports["fa"];Module["_dcgridJsCreateRenderer"]=wasmExports["ga"];Module["_dcgridJsRender"]=wasmExports["ha"];Module["_wgpuTextureRelease"]=wasmExports["ia"];Module["_wgpuDeviceRelease"]=wasmExports["ja"];Module["_dcgridSampleFieldWebGPU"]=wasmExports["ka"];Module["_dcgridFlush"]=wasmExports["la"];Module["_dcgridRendererDestroy"]=wasmExports["ma"];Module["_dcgridRendererIsReady"]=wasmExports["na"];Module["_dcgridRendererInvalidate"]=wasmExports["oa"];Module["_dcgridRendererBusy"]=wasmExports["pa"];Module["_dcgridDestroy"]=wasmExports["qa"];Module["_dcgridPoll"]=wasmExports["ra"];Module["_dcgridIsReady"]=wasmExports["sa"];Module["_dcgridGetStatus"]=wasmExports["ta"];Module["_dcgridReset"]=wasmExports["ua"];Module["_dcgridStep"]=wasmExports["va"];Module["_dcgridStepsInFlight"]=wasmExports["wa"];Module["_dcgridSetInflowMap"]=wasmExports["xa"];Module["_dcgridSceneCount"]=wasmExports["ya"];Module["_dcgridSceneName"]=wasmExports["za"];Module["_dcgridSceneApply"]=wasmExports["Aa"];_emwgpuCreateBindGroup=wasmExports["Ba"];_emwgpuCreateBindGroupLayout=wasmExports["Ca"];_emwgpuCreateCommandBuffer=wasmExports["Da"];_emwgpuCreateCommandEncoder=wasmExports["Ea"];_emwgpuCreateComputePassEncoder=wasmExports["Fa"];_emwgpuCreateComputePipeline=wasmExports["Ga"];_emwgpuCreateExternalTexture=wasmExports["Ha"];_emwgpuCreatePipelineLayout=wasmExports["Ia"];_emwgpuCreateQuerySet=wasmExports["Ja"];_emwgpuCreateRenderBundle=wasmExports["Ka"];_emwgpuCreateRenderBundleEncoder=wasmExports["La"];_emwgpuCreateRenderPassEncoder=wasmExports["Ma"];_emwgpuCreateRenderPipeline=wasmExports["Na"];_emwgpuCreateSampler=wasmExports["Oa"];_emwgpuCreateSurface=wasmExports["Pa"];_emwgpuCreateTexture=Module["_emwgpuCreateTexture"]=wasmExports["Qa"];_emwgpuCreateTextureView=wasmExports["Ra"];_emwgpuCreateAdapter=wasmExports["Sa"];_emwgpuImportBuffer=wasmExports["Ta"];_emwgpuCreateDevice=Module["_emwgpuCreateDevice"]=wasmExports["Ua"];_emwgpuCreateQueue=Module["_emwgpuCreateQueue"]=wasmExports["Va"];_emwgpuCreateShaderModule=wasmExports["Wa"];_emwgpuOnCompilationInfoCompleted=wasmExports["Xa"];_emwgpuOnCreateComputePipelineCompleted=wasmExports["Ya"];_emwgpuOnMapAsyncCompleted=wasmExports["Za"];_emwgpuOnWorkDoneCompleted=wasmExports["_a"];_free=Module["_free"]=wasmExports["$a"];_memalign=wasmExports["ab"];___trap=wasmExports["bb"];__emscripten_stack_restore=wasmExports["cb"];__emscripten_stack_alloc=wasmExports["db"];_emscripten_stack_get_current=wasmExports["eb"];wasmMemory=wasmExports["V"];wasmTable=wasmExports["_"]}var wasmImports={x:()=>abort(""),u:(timezone,daylight,std_name,dst_name)=>{var currentYear=(new Date).getFullYear();var winter=new Date(currentYear,0,1);var summer=new Date(currentYear,6,1);var winterOffset=winter.getTimezoneOffset();var summerOffset=summer.getTimezoneOffset();var stdTimezoneOffset=Math.max(winterOffset,summerOffset);HEAPU32[timezone>>2]=stdTimezoneOffset*60;HEAP32[daylight>>2]=Number(winterOffset!=summerOffset);var extractZone=timezoneOffset=>{var sign=timezoneOffset>=0?"-":"+";var absOffset=Math.abs(timezoneOffset);var hours=String(Math.floor(absOffset/60)).padStart(2,"0");var minutes=String(absOffset%60).padStart(2,"0");return`UTC${sign}${hours}${minutes}`};var winterName=extractZone(winterOffset);var summerName=extractZone(summerOffset);if(summerOffset<winterOffset){stringToUTF8(winterName,std_name,17);stringToUTF8(summerName,dst_name,17)}else{stringToUTF8(winterName,dst_name,17);stringToUTF8(summerName,std_name,17)}},v:function(clk_id,ignored_precision,ptime){ignored_precision=bigintToI53Checked(ignored_precision);if(!checkWasiClock(clk_id))return 28;var now;if(clk_id===0)now=_emscripten_date_now();else if(1)now=_emscripten_get_now();else return 52;var nsec=Math.round(now*1e6);HEAP64[ptime>>3]=BigInt(nsec);return 0},w:requestedSize=>{var oldSize=HEAPU8.length;requestedSize>>>=0;var maxHeapSize=getHeapMax();if(requestedSize>maxHeapSize)return false;for(var cutDown=1;cutDown<=4;cutDown*=2){var overGrownHeapSize=oldSize*(1+.2/cutDown);overGrownHeapSize=Math.min(overGrownHeapSize,requestedSize+100663296);var newSize=Math.min(maxHeapSize,alignMemory(Math.max(requestedSize,overGrownHeapSize),65536));var replacement=growMemory(newSize);if(replacement)return true}return false},I:bufferPtr=>{var buffer=WebGPU.getJsObject(bufferPtr);var onUnmap=WebGPU.Internals.bufferOnUnmaps[bufferPtr];if(onUnmap){for(var i=0;i<onUnmap.length;++i)onUnmap[i]();delete WebGPU.Internals.bufferOnUnmaps[bufferPtr]}buffer.destroy()},H:(bufferPtr,offset,size)=>{var buffer=WebGPU.getJsObject(bufferPtr);if(size==-1)size=void 0;var mapped;try{mapped=buffer.getMappedRange(offset,size)}catch(ex){return 0}var data=_memalign(16,mapped.byteLength);HEAPU8.set(new Uint8Array(mapped),data);WebGPU.Internals.bufferOnUnmaps[bufferPtr].push(()=>_free(data));return data},G:(bufferPtr,offset,size)=>{var buffer=WebGPU.getJsObject(bufferPtr);if(size==-1)size=void 0;var mapped;try{mapped=buffer.getMappedRange(offset,size)}catch(ex){return 0}var data=_memalign(16,mapped.byteLength);HEAPU8.fill(0,data,mapped.byteLength);WebGPU.Internals.bufferOnUnmaps[bufferPtr].push(()=>{new Uint8Array(mapped).set(HEAPU8.subarray(data,data+mapped.byteLength));_free(data)});return data},F:function(bufferPtr,futureId,mode,offset,size){futureId=bigintToI53Checked(futureId);mode=bigintToI53Checked(mode);var buffer=WebGPU.getJsObject(bufferPtr);WebGPU.Internals.bufferOnUnmaps[bufferPtr]=[];if(size==-1)size=void 0;WebGPU.Internals.futureInsert(futureId,buffer.mapAsync(mode,offset,size).then(()=>{callUserCallback(()=>{_emwgpuOnMapAsyncCompleted(futureId,1,0)})},ex=>{callUserCallback(()=>{stackSave();var messagePtr=stringToUTF8OnStack(ex.message);var status=ex.name==="AbortError"?4:ex.name==="OperationError"?3:0;_emwgpuOnMapAsyncCompleted(futureId,status,messagePtr);delete WebGPU.Internals.bufferOnUnmaps[bufferPtr]})}))},E:bufferPtr=>{var buffer=WebGPU.getJsObject(bufferPtr);var onUnmap=WebGPU.Internals.bufferOnUnmaps[bufferPtr];if(!onUnmap)return;for(var i=0;i<onUnmap.length;++i)onUnmap[i]();delete WebGPU.Internals.bufferOnUnmaps[bufferPtr];buffer.unmap()},a:ptr=>{delete WebGPU.Internals.jsObjects[ptr]},B:(devicePtr,descriptor,bufferPtr)=>{var mappedAtCreation=!!HEAPU32[descriptor+32>>2];var desc={label:WebGPU.makeStringFromOptionalStringView(descriptor+4),usage:HEAPU32[descriptor+16>>2],size:readI53FromI64(descriptor+24),mappedAtCreation};var device=WebGPU.getJsObject(devicePtr);var buffer;try{buffer=device.createBuffer(desc)}catch(ex){return false}WebGPU.Internals.jsObjectInsert(bufferPtr,buffer);if(mappedAtCreation)WebGPU.Internals.bufferOnUnmaps[bufferPtr]=[];return true},A:function(devicePtr,futureId,descriptor,pipelinePtr){futureId=bigintToI53Checked(futureId);var desc=WebGPU.makeComputePipelineDesc(descriptor);var device=WebGPU.getJsObject(devicePtr);WebGPU.Internals.futureInsert(futureId,device.createComputePipelineAsync(desc).then(pipeline=>{callUserCallback(()=>{WebGPU.Internals.jsObjectInsert(pipelinePtr,pipeline);_emwgpuOnCreateComputePipelineCompleted(futureId,1,pipelinePtr,0)})},pipelineError=>{callUserCallback(()=>{var sp=stackSave();var messagePtr=stringToUTF8OnStack(pipelineError.message);var status=pipelineError.reason==="validation"?3:pipelineError.reason==="internal"?4:0;_emwgpuOnCreateComputePipelineCompleted(futureId,status,pipelinePtr,messagePtr);stackRestore(sp)})}))},z:(devicePtr,descriptor,shaderModulePtr)=>{var nextInChainPtr=HEAPU32[descriptor>>2];var sType=HEAP32[nextInChainPtr+4>>2];var desc={label:WebGPU.makeStringFromOptionalStringView(descriptor+4),code:""};switch(sType){case 2:desc["code"]=WebGPU.makeStringFromStringView(nextInChainPtr+8);break}var device=WebGPU.getJsObject(devicePtr);WebGPU.Internals.jsObjectInsert(shaderModulePtr,device.createShaderModule(desc))},D:devicePtr=>{const device=WebGPU.getJsObject(devicePtr);device.onuncapturederror=null;device.destroy()},y:function(queuePtr,futureId){futureId=bigintToI53Checked(futureId);var queue=WebGPU.getJsObject(queuePtr);WebGPU.Internals.futureInsert(futureId,queue.onSubmittedWorkDone().then(()=>{callUserCallback(()=>{_emwgpuOnWorkDoneCompleted(futureId,1)})}))},C:function(shaderModulePtr,futureId,compilationInfoPtr){futureId=bigintToI53Checked(futureId);var shaderModule=WebGPU.getJsObject(shaderModulePtr);WebGPU.Internals.futureInsert(futureId,shaderModule.getCompilationInfo().then(compilationInfo=>{callUserCallback(()=>{const messageCount=compilationInfo.messages.length;HEAPU32[compilationInfoPtr+4>>2]=messageCount;if(messageCount){var totalMessagesSize=1;var messageLengths=[];for(var i=0;i<messageCount;++i){var messageLength=lengthBytesUTF8(compilationInfo.messages[i].message);totalMessagesSize+=messageLength;messageLengths.push(messageLength)}var messagesPtr=_malloc(totalMessagesSize);var compilationMessagesPtr=_malloc(48*messageCount);HEAPU32[compilationInfoPtr+8>>2]=compilationMessagesPtr;var utf16sPtr=_malloc(32*messageCount);for(i=0;i<messageCount;++i){var compilationMessage=compilationInfo.messages[i];var compilationMessagePtr=compilationMessagesPtr+48*i;var utf16Ptr=utf16sPtr+32*i;WebGPU.setStringView(compilationMessagePtr+4,messagesPtr,messageLengths[i]);HEAPU32[compilationMessagePtr>>2]=utf16Ptr;HEAP32[compilationMessagePtr+12>>2]=emwgpuStringToInt_CompilationMessageType[compilationMessage.type];HEAP64[compilationMessagePtr+16>>3]=BigInt(compilationMessage.lineNum);HEAP64[compilationMessagePtr+24>>3]=BigInt(compilationMessage.linePos);HEAP64[compilationMessagePtr+32>>3]=BigInt(compilationMessage.offset);HEAP64[compilationMessagePtr+40>>3]=BigInt(compilationMessage.length);HEAPU32[utf16Ptr>>2]=0;HEAP32[utf16Ptr+4>>2]=327743;HEAP64[utf16Ptr+8>>3]=BigInt(compilationMessage.linePos);HEAP64[utf16Ptr+16>>3]=BigInt(compilationMessage.offset);HEAP64[utf16Ptr+24>>3]=BigInt(compilationMessage.length);stringToUTF8(compilationMessage.message,messagesPtr,messageLengths[i]+1);messagesPtr+=messageLengths[i]}}_emwgpuOnCompilationInfoCompleted(futureId,1,compilationInfoPtr)})},()=>{abort("Unexpected failure in GPUShaderModule.getCompilationInfo().")}))},s:(__environ,environ_buf)=>{var bufSize=0;var envp=0;for(var string of getEnvStrings()){var ptr=environ_buf+bufSize;HEAPU32[__environ+envp>>2]=ptr;bufSize+=stringToUTF8(string,ptr,1/0)+1;envp+=4}return 0},t:(penviron_count,penviron_buf_size)=>{var strings=getEnvStrings();HEAPU32[penviron_count>>2]=strings.length;var bufSize=0;for(var string of strings)bufSize+=lengthBytesUTF8(string)+1;HEAPU32[penviron_buf_size>>2]=bufSize;return 0},j:(encoderPtr,descriptor)=>{var desc;if(descriptor)desc={label:WebGPU.makeStringFromOptionalStringView(descriptor+4),timestampWrites:WebGPU.makePassTimestampWrites(HEAPU32[descriptor+12>>2])};var commandEncoder=WebGPU.getJsObject(encoderPtr);var ptr=_emwgpuCreateComputePassEncoder(0);WebGPU.Internals.jsObjectInsert(ptr,commandEncoder.beginComputePass(desc));return ptr},S:function(encoderPtr,bufferPtr,offset,size){offset=bigintToI53Checked(offset);size=bigintToI53Checked(size);var commandEncoder=WebGPU.getJsObject(encoderPtr);if(size==-1)size=void 0;var buffer=WebGPU.getJsObject(bufferPtr);commandEncoder.clearBuffer(buffer,offset,size)},f:function(encoderPtr,srcPtr,srcOffset,dstPtr,dstOffset,size){srcOffset=bigintToI53Checked(srcOffset);dstOffset=bigintToI53Checked(dstOffset);size=bigintToI53Checked(size);var commandEncoder=WebGPU.getJsObject(encoderPtr);var src=WebGPU.getJsObject(srcPtr);var dst=WebGPU.getJsObject(dstPtr);commandEncoder.copyBufferToBuffer(src,srcOffset,dst,dstOffset,size)},P:encoderPtr=>{var commandEncoder=WebGPU.getJsObject(encoderPtr);var ptr=_emwgpuCreateCommandBuffer(0);WebGPU.Internals.jsObjectInsert(ptr,commandEncoder.finish());return ptr},R:function(encoderPtr,querySetPtr,firstQuery,queryCount,destinationPtr,destinationOffset){destinationOffset=bigintToI53Checked(destinationOffset);var commandEncoder=WebGPU.getJsObject(encoderPtr);var querySet=WebGPU.getJsObject(querySetPtr);var destination=WebGPU.getJsObject(destinationPtr);commandEncoder.resolveQuerySet(querySet,firstQuery,queryCount,destination,destinationOffset)},T:(passPtr,x,y,z)=>{var pass=WebGPU.getJsObject(passPtr);pass.dispatchWorkgroups(x,y,z)},e:passPtr=>{var pass=WebGPU.getJsObject(passPtr);pass.end()},i:(passPtr,groupIndex,groupPtr,dynamicOffsetCount,dynamicOffsetsPtr)=>{var pass=WebGPU.getJsObject(passPtr);var group=WebGPU.getJsObject(groupPtr);if(dynamicOffsetCount==0)pass.setBindGroup(groupIndex,group);else pass.setBindGroup(groupIndex,group,HEAPU32,dynamicOffsetsPtr>>2,dynamicOffsetCount)},q:(passPtr,pipelinePtr)=>{var pass=WebGPU.getJsObject(passPtr);var pipeline=WebGPU.getJsObject(pipelinePtr);pass.setPipeline(pipeline)},h:(devicePtr,descriptor)=>{function makeEntry(entryPtr){var bufferPtr=HEAPU32[entryPtr+8>>2];var samplerPtr=HEAPU32[entryPtr+32>>2];var textureViewPtr=HEAPU32[entryPtr+36>>2];var externalTexturePtr=0;WebGPU.iterateExtensions(entryPtr,{14:ptr=>{externalTexturePtr=HEAPU32[ptr+8>>2]}});var resource;if(bufferPtr){var size=readI53FromI64(entryPtr+24);if(size==-1)size=void 0;resource={buffer:WebGPU.getJsObject(bufferPtr),offset:readI53FromI64(entryPtr+16),size}}else resource=WebGPU.getJsObject(samplerPtr||textureViewPtr||externalTexturePtr);return{binding:HEAPU32[entryPtr+4>>2],resource}}var desc={label:WebGPU.makeStringFromOptionalStringView(descriptor+4),layout:WebGPU.getJsObject(HEAPU32[descriptor+12>>2]),entries:function(count,entriesPtrs){var entries=[];for(var i=0;i<count;++i)entries.push(makeEntry(entriesPtrs+40*i));return entries}(HEAPU32[descriptor+16>>2],HEAPU32[descriptor+20>>2])};var device=WebGPU.getJsObject(devicePtr);var ptr=_emwgpuCreateBindGroup(0);WebGPU.Internals.jsObjectInsert(ptr,device.createBindGroup(desc));return ptr},c:(devicePtr,descriptor)=>{function makeBufferEntry(substructPtr){var typeInt=HEAPU32[substructPtr+4>>2];if(!typeInt)return;return{type:WebGPU.BufferBindingType[typeInt],hasDynamicOffset:!!HEAPU32[substructPtr+8>>2],minBindingSize:readI53FromI64(substructPtr+16)}}function makeSamplerEntry(substructPtr){var typeInt=HEAPU32[substructPtr+4>>2];if(!typeInt)return;return{type:WebGPU.SamplerBindingType[typeInt]}}function makeTextureEntry(substructPtr){var sampleTypeInt=HEAPU32[substructPtr+4>>2];if(!sampleTypeInt)return;return{sampleType:WebGPU.TextureSampleType[sampleTypeInt],viewDimension:WebGPU.TextureViewDimension[HEAP32[substructPtr+8>>2]],multisampled:!!HEAPU32[substructPtr+12>>2]}}function makeStorageTextureEntry(substructPtr){var accessInt=HEAPU32[substructPtr+4>>2];if(!accessInt)return;return{access:WebGPU.StorageTextureAccess[accessInt],format:WebGPU.TextureFormat[HEAP32[substructPtr+8>>2]],viewDimension:WebGPU.TextureViewDimension[HEAP32[substructPtr+12>>2]]}}function makeEntry(entryPtr){var entry={binding:HEAPU32[entryPtr+4>>2],visibility:HEAPU32[entryPtr+8>>2],buffer:makeBufferEntry(entryPtr+24),sampler:makeSamplerEntry(entryPtr+48),texture:makeTextureEntry(entryPtr+56),storageTexture:makeStorageTextureEntry(entryPtr+72)};WebGPU.iterateExtensions(entryPtr,{13:()=>{entry["externalTexture"]={}}});return entry}var desc={label:WebGPU.makeStringFromOptionalStringView(descriptor+4),entries:function(count,entriesPtrs){var entries=[];for(var i=0;i<count;++i)entries.push(makeEntry(entriesPtrs+88*i));return entries}(HEAPU32[descriptor+12>>2],HEAPU32[descriptor+16>>2])};var device=WebGPU.getJsObject(devicePtr);var ptr=_emwgpuCreateBindGroupLayout(0);WebGPU.Internals.jsObjectInsert(ptr,device.createBindGroupLayout(desc));return ptr},d:(devicePtr,descriptor)=>{var desc;if(descriptor)desc={label:WebGPU.makeStringFromOptionalStringView(descriptor+4)};var device=WebGPU.getJsObject(devicePtr);var ptr=_emwgpuCreateCommandEncoder(0);WebGPU.Internals.jsObjectInsert(ptr,device.createCommandEncoder(desc));return ptr},p:(devicePtr,descriptor)=>{var bglCount=HEAPU32[descriptor+12>>2];var bglPtr=HEAPU32[descriptor+16>>2];var bgls=[];for(var i=0;i<bglCount;++i)bgls.push(WebGPU.getJsObject(HEAPU32[bglPtr+4*i>>2]));var desc={label:WebGPU.makeStringFromOptionalStringView(descriptor+4),bindGroupLayouts:bgls,immediateSize:HEAPU32[descriptor+20>>2]};var device=WebGPU.getJsObject(devicePtr);var ptr=_emwgpuCreatePipelineLayout(0);WebGPU.Internals.jsObjectInsert(ptr,device.createPipelineLayout(desc));return ptr},r:(devicePtr,descriptor)=>{var desc={type:WebGPU.QueryType[HEAP32[descriptor+12>>2]],count:HEAPU32[descriptor+16>>2]};var device=WebGPU.getJsObject(devicePtr);var ptr=_emwgpuCreateQuerySet(0);WebGPU.Internals.jsObjectInsert(ptr,device.createQuerySet(desc));return ptr},o:(devicePtr,descriptor)=>{var desc;if(descriptor)desc={label:WebGPU.makeStringFromOptionalStringView(descriptor+4),addressModeU:WebGPU.AddressMode[HEAP32[descriptor+12>>2]],addressModeV:WebGPU.AddressMode[HEAP32[descriptor+16>>2]],addressModeW:WebGPU.AddressMode[HEAP32[descriptor+20>>2]],magFilter:WebGPU.FilterMode[HEAP32[descriptor+24>>2]],minFilter:WebGPU.FilterMode[HEAP32[descriptor+28>>2]],mipmapFilter:WebGPU.MipmapFilterMode[HEAP32[descriptor+32>>2]],lodMinClamp:HEAPF32[descriptor+36>>2],lodMaxClamp:HEAPF32[descriptor+40>>2],compare:WebGPU.CompareFunction[HEAP32[descriptor+44>>2]],maxAnisotropy:HEAPU16[descriptor+48>>1]};var device=WebGPU.getJsObject(devicePtr);var ptr=_emwgpuCreateSampler(0);WebGPU.Internals.jsObjectInsert(ptr,device.createSampler(desc));return ptr},U:(devicePtr,descriptor)=>{var nextInChainPtr=HEAPU32[descriptor>>2];var textureBindingViewDimension;if(nextInChainPtr!==0){HEAP32[nextInChainPtr+4>>2];var textureBindingViewDimensionDescriptor=nextInChainPtr;textureBindingViewDimension=WebGPU.TextureViewDimension[HEAP32[textureBindingViewDimensionDescriptor+8>>2]]}var desc={label:WebGPU.makeStringFromOptionalStringView(descriptor+4),size:WebGPU.makeExtent3D(descriptor+28),mipLevelCount:HEAPU32[descriptor+44>>2],sampleCount:HEAPU32[descriptor+48>>2],dimension:WebGPU.TextureDimension[HEAP32[descriptor+24>>2]],format:WebGPU.TextureFormat[HEAP32[descriptor+40>>2]],usage:HEAPU32[descriptor+16>>2],textureBindingViewDimension};var viewFormatCount=HEAPU32[descriptor+52>>2];if(viewFormatCount){var viewFormatsPtr=HEAPU32[descriptor+56>>2];desc["viewFormats"]=Array.from(HEAP32.subarray(viewFormatsPtr>>2,viewFormatsPtr+viewFormatCount*4>>2),format=>WebGPU.TextureFormat[format])}var device=WebGPU.getJsObject(devicePtr);var ptr=_emwgpuCreateTexture(0);WebGPU.Internals.jsObjectInsert(ptr,device.createTexture(desc));return ptr},M:(devicePtr,limitsOutPtr)=>{var device=WebGPU.getJsObject(devicePtr);WebGPU.fillLimitStruct(device.limits,limitsOutPtr);return 1},N:(devicePtr,featureEnumValue)=>{var device=WebGPU.getJsObject(devicePtr);return device.features.has(WebGPU.FeatureName[featureEnumValue])},O:(queuePtr,commandCount,commands)=>{var queue=WebGPU.getJsObject(queuePtr);var cmds=Array.from(HEAP32.subarray(commands>>2,commands+commandCount*4>>2),id=>WebGPU.getJsObject(id));queue.submit(cmds)},Q:function(queuePtr,bufferPtr,bufferOffset,data,size){bufferOffset=bigintToI53Checked(bufferOffset);var queue=WebGPU.getJsObject(queuePtr);var buffer=WebGPU.getJsObject(bufferPtr);var subarray=HEAPU8.subarray(data,data+size);queue.writeBuffer(buffer,bufferOffset,subarray,0,size)},b:(queuePtr,destinationPtr,data,dataSize,dataLayoutPtr,writeSizePtr)=>{var queue=WebGPU.getJsObject(queuePtr);var destination=WebGPU.makeTexelCopyTextureInfo(destinationPtr);var dataLayout=WebGPU.makeTexelCopyBufferLayout(dataLayoutPtr);var writeSize=WebGPU.makeExtent3D(writeSizePtr);var subarray=HEAPU8.subarray(data,data+dataSize);queue.writeTexture(destination,subarray,dataLayout,writeSize)},g:(texturePtr,descriptor)=>{var desc;if(descriptor){var swizzle;var nextInChainPtr=HEAPU32[descriptor>>2];if(nextInChainPtr!==0){HEAP32[nextInChainPtr+4>>2];var swizzleDescriptor=nextInChainPtr;var swizzlePtr=swizzleDescriptor+8;var r=WebGPU.ComponentSwizzle[HEAP32[swizzlePtr>>2]]||"r";var g=WebGPU.ComponentSwizzle[HEAP32[swizzlePtr+4>>2]]||"g";var b=WebGPU.ComponentSwizzle[HEAP32[swizzlePtr+8>>2]]||"b";var a=WebGPU.ComponentSwizzle[HEAP32[swizzlePtr+12>>2]]||"a";swizzle=`${r}${g}${b}${a}`}var mipLevelCount=HEAPU32[descriptor+24>>2];var arrayLayerCount=HEAPU32[descriptor+32>>2];desc={label:WebGPU.makeStringFromOptionalStringView(descriptor+4),format:WebGPU.TextureFormat[HEAP32[descriptor+12>>2]],dimension:WebGPU.TextureViewDimension[HEAP32[descriptor+16>>2]],baseMipLevel:HEAPU32[descriptor+20>>2],mipLevelCount:mipLevelCount===4294967295?void 0:mipLevelCount,baseArrayLayer:HEAPU32[descriptor+28>>2],arrayLayerCount:arrayLayerCount===4294967295?void 0:arrayLayerCount,aspect:WebGPU.TextureAspect[HEAP32[descriptor+36>>2]],usage:HEAPU32[descriptor+40>>2],swizzle}}var texture=WebGPU.getJsObject(texturePtr);var ptr=_emwgpuCreateTextureView(0);WebGPU.Internals.jsObjectInsert(ptr,texture.createView(desc));return ptr},L:texturePtr=>{WebGPU.getJsObject(texturePtr).destroy()},J:texturePtr=>{var texture=WebGPU.getJsObject(texturePtr);return texture.depthOrArrayLayers},K:texturePtr=>{var texture=WebGPU.getJsObject(texturePtr);return WebGPU.TextureDimension.indexOf(texture.dimension)},n:texturePtr=>{var texture=WebGPU.getJsObject(texturePtr);return WebGPU.TextureFormat.indexOf(texture.format)},k:texturePtr=>{var texture=WebGPU.getJsObject(texturePtr);return texture.height},m:function(texturePtr){var ret=(()=>{var texture=WebGPU.getJsObject(texturePtr);return texture.usage})();return BigInt(ret)},l:texturePtr=>{var texture=WebGPU.getJsObject(texturePtr);return texture.width}};var wasmExports;wasmExports=await async function(){function receiveInstance(instance){wasmExports=instance.exports;assignWasmExports(wasmExports);updateMemoryViews();return wasmExports}var info=getWasmImports();var instantiateWasm=Module["instantiateWasm"];if(instantiateWasm)return new Promise(resolve=>{instantiateWasm(info,inst=>resolve(receiveInstance(inst)))});wasmBinaryFile??=findWasmBinary();var result=await instantiateAsync(void 0,wasmBinaryFile,info);var exports=function(result){return receiveInstance(result["instance"])}(result);return exports}();await async function(){preRun();var setStatus=Module["setStatus"];if(setStatus){setStatus("Running...");await new Promise(resolve=>setTimeout(resolve,1));setTimeout(setStatus,1,"")}if(ABORT)return;initRuntime();Module["onRuntimeInitialized"]?.();postRun()}();Module["importDevice"]=(device,parent)=>WebGPU.importJsDevice(device,parent);Module["importTexture"]=(texture,parent)=>WebGPU.importJsTexture(texture,parent);
|
|
2
2
|
;return Module}export default createDCGridModule;
|
package/dist/dcgrid.wasm
CHANGED
|
Binary file
|
package/dist/index.d.ts
CHANGED
|
@@ -101,6 +101,7 @@ export interface RenderSettings {
|
|
|
101
101
|
antialiasing: number;
|
|
102
102
|
shadowSamples: number;
|
|
103
103
|
ambient: number;
|
|
104
|
+
/** Behind the scene when rendering into a canvas (texture targets get alpha instead). */
|
|
104
105
|
backgroundColor: Vec3;
|
|
105
106
|
floorColor: Vec3;
|
|
106
107
|
smokeColor: Vec3;
|
|
@@ -123,6 +124,27 @@ export interface SceneInfo {
|
|
|
123
124
|
};
|
|
124
125
|
render: RenderSettings;
|
|
125
126
|
}
|
|
127
|
+
/** A preset scene by index or by name (one of `DCGrid.scenes`). */
|
|
128
|
+
export type SceneRef = number | string;
|
|
129
|
+
/** A camera orbiting `target` (meters) at `distance`; yaw about +y and pitch above the horizon in radians. */
|
|
130
|
+
export interface Orbit {
|
|
131
|
+
target: Vec3;
|
|
132
|
+
distance: number;
|
|
133
|
+
yaw: number;
|
|
134
|
+
pitch: number;
|
|
135
|
+
}
|
|
136
|
+
/** The sunlight direction of the preset scenes. */
|
|
137
|
+
export declare const DEFAULT_SUN_DIRECTION: Vec3;
|
|
138
|
+
/**
|
|
139
|
+
* The render camera of an orbit. `fov` is the field of view in degrees along the longer image side
|
|
140
|
+
* (default 100, as in the demo).
|
|
141
|
+
*/
|
|
142
|
+
export declare function orbitCamera(orbit: Orbit, options?: {
|
|
143
|
+
fov?: number;
|
|
144
|
+
sunDirection?: Vec3;
|
|
145
|
+
}): Camera;
|
|
146
|
+
/** The orbit that frames a preset scene (`SceneInfo.view`), for a field of view of 100°. */
|
|
147
|
+
export declare function sceneOrbit(view: SceneInfo["view"]): Orbit;
|
|
126
148
|
export type ErrorCode = "invalid_argument" | "unsupported" | "not_ready" | "device";
|
|
127
149
|
export declare class DCGridError extends Error {
|
|
128
150
|
readonly code: ErrorCode;
|
|
@@ -150,18 +172,31 @@ export declare class DCGrid {
|
|
|
150
172
|
static load(options?: {
|
|
151
173
|
wasm?: string | URL | ArrayBuffer;
|
|
152
174
|
}): Promise<DCGrid>;
|
|
175
|
+
/**
|
|
176
|
+
* Device limits to request for the largest grids the adapter can run: its own maximum storage
|
|
177
|
+
* buffers per shader stage (the adaptive grid needs 9, the uniform grid 5), storage binding size
|
|
178
|
+
* and buffer size.
|
|
179
|
+
*/
|
|
180
|
+
static requiredLimits(adapter: GPUAdapter): Record<string, number>;
|
|
181
|
+
/**
|
|
182
|
+
* Requests a high-performance adapter (unless one is given) and a device with `requiredLimits`.
|
|
183
|
+
* Throws an "unsupported" DCGridError without WebGPU.
|
|
184
|
+
*/
|
|
185
|
+
static requestDevice(adapter?: GPUAdapter): Promise<GPUDevice>;
|
|
153
186
|
/** Default description and render settings: 128³ cells of 78 m, adaptive, 40000 blocks, no-slip walls. */
|
|
154
187
|
defaults(): {
|
|
155
188
|
desc: Required<SimulationDesc>;
|
|
156
189
|
render: RenderSettings;
|
|
157
190
|
};
|
|
158
191
|
/**
|
|
159
|
-
* A preset scene at `resolution` cells per 10 km. `base` keeps grid, maxBlocks, criterion and
|
|
192
|
+
* A preset scene (index or name) at `resolution` cells per 10 km. `base` keeps grid, maxBlocks, criterion and
|
|
160
193
|
* densityScale (other settings come from the scene).
|
|
161
194
|
*/
|
|
162
|
-
describeScene(scene:
|
|
195
|
+
describeScene(scene: SceneRef, resolution: number, base?: Partial<SimulationDesc>): SceneInfo;
|
|
163
196
|
/** Creates a simulation on `device`; it builds in the background (see Simulation.whenReady). */
|
|
164
197
|
create(device: GPUDevice, desc: SimulationDesc): Simulation;
|
|
198
|
+
/** The index of a preset scene; throws an "invalid_argument" DCGridError for unknown ones. */
|
|
199
|
+
sceneIndex(scene: SceneRef): number;
|
|
165
200
|
/** @internal */
|
|
166
201
|
get module(): Module;
|
|
167
202
|
/** @internal */
|
|
@@ -183,12 +218,14 @@ export declare class Simulation {
|
|
|
183
218
|
private readonly dcgrid;
|
|
184
219
|
/** @internal */ readonly ptr: number;
|
|
185
220
|
/** @internal */ readonly device: number;
|
|
221
|
+
/** The device the simulation records into. */ readonly gpuDevice: GPUDevice;
|
|
186
222
|
private sources;
|
|
187
223
|
private destroyed;
|
|
188
224
|
/** @internal */
|
|
189
225
|
constructor(dcgrid: DCGrid,
|
|
190
226
|
/** @internal */ ptr: number,
|
|
191
|
-
/** @internal */ device: number
|
|
227
|
+
/** @internal */ device: number,
|
|
228
|
+
/** The device the simulation records into. */ gpuDevice: GPUDevice);
|
|
192
229
|
private get m();
|
|
193
230
|
/** Processes finished GPU work: advances building, resetting and the adaptation. Call once per frame. */
|
|
194
231
|
poll(): void;
|
|
@@ -219,8 +256,11 @@ export declare class Simulation {
|
|
|
219
256
|
* first axis fastest. null returns to the face's uniform values.
|
|
220
257
|
*/
|
|
221
258
|
setInflowMap(face: FaceName, values: Float32Array | null): void;
|
|
222
|
-
/**
|
|
223
|
-
|
|
259
|
+
/**
|
|
260
|
+
* Uploads a preset scene's solids, sources and inflow maps (for a simulation described by it).
|
|
261
|
+
* The scene's inflow maps follow later changes to their faces' velocity and density.
|
|
262
|
+
*/
|
|
263
|
+
applyScene(scene: SceneRef): void;
|
|
224
264
|
stats(): Stats;
|
|
225
265
|
/**
|
|
226
266
|
* Resamples a field into a 3D texture (r32float, rgba16float or rgba32float with STORAGE_BINDING),
|
|
@@ -239,21 +279,33 @@ export declare class Renderer {
|
|
|
239
279
|
private readonly sim;
|
|
240
280
|
private readonly ptr;
|
|
241
281
|
private destroyed;
|
|
282
|
+
/** Canvas output: the raymarched image and the pipeline drawing it, per canvas format. */
|
|
283
|
+
private image;
|
|
284
|
+
private present;
|
|
285
|
+
private presentResources;
|
|
286
|
+
private defaultBackground;
|
|
242
287
|
/** @internal */
|
|
243
288
|
constructor(dcgrid: DCGrid, sim: Simulation, ptr: number);
|
|
244
289
|
private get m();
|
|
245
290
|
get ready(): boolean;
|
|
246
291
|
whenReady(): Promise<void>;
|
|
247
292
|
/**
|
|
248
|
-
* Records and submits a render
|
|
249
|
-
*
|
|
250
|
-
*
|
|
293
|
+
* Records and submits a render. Settings not given take their defaults. Throws a "not_ready"
|
|
294
|
+
* DCGridError until the simulation and the render pipelines are ready.
|
|
295
|
+
*
|
|
296
|
+
* - A texture target (rgba8unorm with STORAGE_BINDING) receives the image with alpha: 0 where the
|
|
297
|
+
* view sees only background. `backgroundColor` does not apply.
|
|
298
|
+
* - A canvas context (configured on the simulation's device) receives the image over
|
|
299
|
+
* `backgroundColor`, raymarched at `scale` times the canvas size (default 1) and scaled up.
|
|
251
300
|
*/
|
|
252
|
-
render(camera: Camera, settings: Partial<RenderSettings>, target: GPUTexture
|
|
301
|
+
render(camera: Camera, settings: Partial<RenderSettings>, target: GPUTexture | GPUCanvasContext, options?: {
|
|
302
|
+
scale?: number;
|
|
303
|
+
}): void;
|
|
253
304
|
/** The last submitted render is still running on the GPU. */
|
|
254
305
|
get busy(): boolean;
|
|
255
306
|
/** Recomputes the sun transmittance volume at the next render. */
|
|
256
307
|
invalidate(): void;
|
|
257
308
|
destroy(): void;
|
|
309
|
+
private renderToCanvas;
|
|
258
310
|
}
|
|
259
311
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
* await sim.whenReady();
|
|
7
7
|
* sim.step();
|
|
8
8
|
*
|
|
9
|
+
* To draw into a canvas: `sim.createRenderer().render(orbitCamera(orbit), settings, canvasContext)`.
|
|
10
|
+
*
|
|
9
11
|
* Nothing blocks: creating and resetting a simulation return at once and `whenReady()` resolves once
|
|
10
12
|
* the pipelines are compiled and the grid is initialized. Steps are submitted to the device queue
|
|
11
13
|
* without waiting; the adaptive grid reads its refinement scores back asynchronously.
|
|
@@ -13,6 +15,65 @@
|
|
|
13
15
|
import createDCGridModule from "./dcgrid.mjs";
|
|
14
16
|
export const FACE_NAMES = ["-x", "+x", "-y", "+y", "-z", "+z"];
|
|
15
17
|
const FIELDS = ["density", "velocity", "fluidity", "cell_size"];
|
|
18
|
+
/** The sunlight direction of the preset scenes. */
|
|
19
|
+
export const DEFAULT_SUN_DIRECTION = (() => {
|
|
20
|
+
const p = -2.5, y = -2.1;
|
|
21
|
+
return [-Math.cos(p) * Math.cos(y), -Math.sin(p), -Math.cos(p) * Math.sin(y)];
|
|
22
|
+
})();
|
|
23
|
+
const sub = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
|
24
|
+
const cross = (a, b) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
|
|
25
|
+
const normalize = (a) => {
|
|
26
|
+
const l = Math.hypot(...a) || 1;
|
|
27
|
+
return [a[0] / l, a[1] / l, a[2] / l];
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* The render camera of an orbit. `fov` is the field of view in degrees along the longer image side
|
|
31
|
+
* (default 100, as in the demo).
|
|
32
|
+
*/
|
|
33
|
+
export function orbitCamera(orbit, options = {}) {
|
|
34
|
+
const { fov = 100, sunDirection = DEFAULT_SUN_DIRECTION } = options;
|
|
35
|
+
const cp = Math.cos(orbit.pitch);
|
|
36
|
+
const offset = [cp * Math.sin(orbit.yaw), Math.sin(orbit.pitch), cp * Math.cos(orbit.yaw)];
|
|
37
|
+
const eye = orbit.target.map((t, i) => t + orbit.distance * offset[i]);
|
|
38
|
+
const forward = normalize(sub(orbit.target, eye));
|
|
39
|
+
const right = normalize(cross(forward, [0, 1, 0]));
|
|
40
|
+
const up = cross(right, forward);
|
|
41
|
+
return { eye, right, up, forward, sunDirection, fovScale: Math.sin((fov / 2) * (Math.PI / 180)) };
|
|
42
|
+
}
|
|
43
|
+
/** The orbit that frames a preset scene (`SceneInfo.view`), for a field of view of 100°. */
|
|
44
|
+
export function sceneOrbit(view) {
|
|
45
|
+
const domain = view.shape.map((s) => s * 10000); // meters
|
|
46
|
+
return {
|
|
47
|
+
target: [domain[0] / 2, domain[1] / 2, domain[2] / 2],
|
|
48
|
+
distance: (view.zoom * Math.max(domain[0], domain[1])) / Math.sin((50 * Math.PI) / 180),
|
|
49
|
+
yaw: view.yaw,
|
|
50
|
+
pitch: view.pitch,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
// ------------------------------------------------------------------ canvas output
|
|
54
|
+
/** Draws an rgba8unorm render over a background color into a canvas texture. */
|
|
55
|
+
const PRESENT_WGSL = /* wgsl */ `
|
|
56
|
+
@group(0) @binding(0) var tex: texture_2d<f32>;
|
|
57
|
+
@group(0) @binding(1) var samp: sampler;
|
|
58
|
+
@group(0) @binding(2) var<uniform> background: vec4f;
|
|
59
|
+
|
|
60
|
+
struct VOut { @builtin(position) pos: vec4f, @location(0) uv: vec2f }
|
|
61
|
+
|
|
62
|
+
@vertex
|
|
63
|
+
fn vs(@builtin(vertex_index) i: u32) -> VOut {
|
|
64
|
+
let p = vec2f(f32((i << 1u) & 2u), f32(i & 2u));
|
|
65
|
+
var o: VOut;
|
|
66
|
+
o.pos = vec4f(p * 2.0 - 1.0, 0.0, 1.0);
|
|
67
|
+
o.uv = vec2f(p.x, 1.0 - p.y);
|
|
68
|
+
return o;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
@fragment
|
|
72
|
+
fn fs(in: VOut) -> @location(0) vec4f {
|
|
73
|
+
let c = textureSample(tex, samp, in.uv);
|
|
74
|
+
return vec4f(c.rgb * c.a + background.rgb * (1.0 - c.a), 1.0);
|
|
75
|
+
}
|
|
76
|
+
`;
|
|
16
77
|
const CODES = { 1: "invalid_argument", 2: "unsupported", 3: "not_ready", 4: "device" };
|
|
17
78
|
export class DCGridError extends Error {
|
|
18
79
|
code;
|
|
@@ -40,22 +101,59 @@ export class DCGrid {
|
|
|
40
101
|
*/
|
|
41
102
|
static async load(options = {}) {
|
|
42
103
|
const settings = {};
|
|
43
|
-
|
|
44
|
-
|
|
104
|
+
// Emscripten's wasmBinary setting is ignored by this build's glue (it fetches dcgrid.wasm anyway);
|
|
105
|
+
// instantiateWasm hands it the instance instead
|
|
106
|
+
const bytes = options.wasm;
|
|
107
|
+
// The hook cannot report a failure, so a rejected instantiation rejects load() directly
|
|
108
|
+
let fail = () => { };
|
|
109
|
+
const failed = new Promise((_, reject) => (fail = reject));
|
|
110
|
+
if (bytes instanceof ArrayBuffer)
|
|
111
|
+
settings.instantiateWasm = (imports, receive) => {
|
|
112
|
+
WebAssembly.instantiate(bytes, imports).then((r) => receive(r.instance), fail);
|
|
113
|
+
return {};
|
|
114
|
+
};
|
|
45
115
|
else if (options.wasm)
|
|
46
116
|
settings.locateFile = (file) => (file.endsWith(".wasm") ? String(options.wasm) : file);
|
|
47
|
-
return new DCGrid((await createDCGridModule(settings)));
|
|
117
|
+
return new DCGrid((await Promise.race([createDCGridModule(settings), failed])));
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Device limits to request for the largest grids the adapter can run: its own maximum storage
|
|
121
|
+
* buffers per shader stage (the adaptive grid needs 9, the uniform grid 5), storage binding size
|
|
122
|
+
* and buffer size.
|
|
123
|
+
*/
|
|
124
|
+
static requiredLimits(adapter) {
|
|
125
|
+
const L = adapter.limits;
|
|
126
|
+
return {
|
|
127
|
+
maxStorageBuffersPerShaderStage: L.maxStorageBuffersPerShaderStage,
|
|
128
|
+
maxStorageBufferBindingSize: L.maxStorageBufferBindingSize,
|
|
129
|
+
maxBufferSize: L.maxBufferSize,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Requests a high-performance adapter (unless one is given) and a device with `requiredLimits`.
|
|
134
|
+
* Throws an "unsupported" DCGridError without WebGPU.
|
|
135
|
+
*/
|
|
136
|
+
static async requestDevice(adapter) {
|
|
137
|
+
if (!adapter) {
|
|
138
|
+
if (typeof navigator === "undefined" || !navigator.gpu)
|
|
139
|
+
throw new DCGridError("WebGPU is not available", "unsupported");
|
|
140
|
+
adapter = (await navigator.gpu.requestAdapter({ powerPreference: "high-performance" })) ?? undefined;
|
|
141
|
+
if (!adapter)
|
|
142
|
+
throw new DCGridError("No WebGPU adapter found", "unsupported");
|
|
143
|
+
}
|
|
144
|
+
return adapter.requestDevice({ requiredLimits: DCGrid.requiredLimits(adapter) });
|
|
48
145
|
}
|
|
49
146
|
/** Default description and render settings: 128³ cells of 78 m, adaptive, 40000 blocks, no-slip walls. */
|
|
50
147
|
defaults() {
|
|
51
148
|
return this.json(this.m._dcgridJsDefaults());
|
|
52
149
|
}
|
|
53
150
|
/**
|
|
54
|
-
* A preset scene at `resolution` cells per 10 km. `base` keeps grid, maxBlocks, criterion and
|
|
151
|
+
* A preset scene (index or name) at `resolution` cells per 10 km. `base` keeps grid, maxBlocks, criterion and
|
|
55
152
|
* densityScale (other settings come from the scene).
|
|
56
153
|
*/
|
|
57
154
|
describeScene(scene, resolution, base = {}) {
|
|
58
|
-
const
|
|
155
|
+
const index = this.sceneIndex(scene);
|
|
156
|
+
const ptr = this.withString(JSON.stringify(base), (s) => this.m._dcgridJsDescribeScene(index, resolution, s));
|
|
59
157
|
if (!ptr)
|
|
60
158
|
throw this.error(1);
|
|
61
159
|
return this.json(ptr);
|
|
@@ -66,7 +164,14 @@ export class DCGrid {
|
|
|
66
164
|
const ptr = this.withString(JSON.stringify(desc), (s) => this.m._dcgridJsCreate(devicePtr, s));
|
|
67
165
|
if (!ptr)
|
|
68
166
|
throw this.error(1);
|
|
69
|
-
return new Simulation(this, ptr, devicePtr);
|
|
167
|
+
return new Simulation(this, ptr, devicePtr, device);
|
|
168
|
+
}
|
|
169
|
+
/** The index of a preset scene; throws an "invalid_argument" DCGridError for unknown ones. */
|
|
170
|
+
sceneIndex(scene) {
|
|
171
|
+
const index = typeof scene === "number" ? scene : this.scenes.indexOf(scene);
|
|
172
|
+
if (!Number.isInteger(index) || index < 0 || index >= this.scenes.length)
|
|
173
|
+
throw new DCGridError(`Unknown scene ${JSON.stringify(scene)} (scenes: ${this.scenes.join(", ")})`, "invalid_argument");
|
|
174
|
+
return index;
|
|
70
175
|
}
|
|
71
176
|
// ---------------------------------------------------------------- internals for Simulation/Renderer
|
|
72
177
|
/** @internal */
|
|
@@ -138,15 +243,18 @@ export class Simulation {
|
|
|
138
243
|
dcgrid;
|
|
139
244
|
ptr;
|
|
140
245
|
device;
|
|
246
|
+
gpuDevice;
|
|
141
247
|
sources = { density: null, velocity: null };
|
|
142
248
|
destroyed = false;
|
|
143
249
|
/** @internal */
|
|
144
250
|
constructor(dcgrid,
|
|
145
251
|
/** @internal */ ptr,
|
|
146
|
-
/** @internal */ device
|
|
252
|
+
/** @internal */ device,
|
|
253
|
+
/** The device the simulation records into. */ gpuDevice) {
|
|
147
254
|
this.dcgrid = dcgrid;
|
|
148
255
|
this.ptr = ptr;
|
|
149
256
|
this.device = device;
|
|
257
|
+
this.gpuDevice = gpuDevice;
|
|
150
258
|
}
|
|
151
259
|
get m() {
|
|
152
260
|
return this.dcgrid.module;
|
|
@@ -223,9 +331,12 @@ export class Simulation {
|
|
|
223
331
|
const f = FACE_NAMES.indexOf(face);
|
|
224
332
|
this.dcgrid.check(this.dcgrid.withFloats(values, (p) => this.m._dcgridSetInflowMap(this.ptr, f, p)));
|
|
225
333
|
}
|
|
226
|
-
/**
|
|
334
|
+
/**
|
|
335
|
+
* Uploads a preset scene's solids, sources and inflow maps (for a simulation described by it).
|
|
336
|
+
* The scene's inflow maps follow later changes to their faces' velocity and density.
|
|
337
|
+
*/
|
|
227
338
|
applyScene(scene) {
|
|
228
|
-
this.dcgrid.check(this.m._dcgridSceneApply(this.ptr, scene));
|
|
339
|
+
this.dcgrid.check(this.m._dcgridSceneApply(this.ptr, this.dcgrid.sceneIndex(scene)));
|
|
229
340
|
this.sources = { density: null, velocity: null };
|
|
230
341
|
}
|
|
231
342
|
stats() {
|
|
@@ -284,6 +395,11 @@ export class Renderer {
|
|
|
284
395
|
sim;
|
|
285
396
|
ptr;
|
|
286
397
|
destroyed = false;
|
|
398
|
+
/** Canvas output: the raymarched image and the pipeline drawing it, per canvas format. */
|
|
399
|
+
image = null;
|
|
400
|
+
present = null;
|
|
401
|
+
presentResources = null;
|
|
402
|
+
defaultBackground = null;
|
|
287
403
|
/** @internal */
|
|
288
404
|
constructor(dcgrid, sim, ptr) {
|
|
289
405
|
this.dcgrid = dcgrid;
|
|
@@ -307,11 +423,19 @@ export class Renderer {
|
|
|
307
423
|
}
|
|
308
424
|
}
|
|
309
425
|
/**
|
|
310
|
-
* Records and submits a render
|
|
311
|
-
*
|
|
312
|
-
*
|
|
426
|
+
* Records and submits a render. Settings not given take their defaults. Throws a "not_ready"
|
|
427
|
+
* DCGridError until the simulation and the render pipelines are ready.
|
|
428
|
+
*
|
|
429
|
+
* - A texture target (rgba8unorm with STORAGE_BINDING) receives the image with alpha: 0 where the
|
|
430
|
+
* view sees only background. `backgroundColor` does not apply.
|
|
431
|
+
* - A canvas context (configured on the simulation's device) receives the image over
|
|
432
|
+
* `backgroundColor`, raymarched at `scale` times the canvas size (default 1) and scaled up.
|
|
313
433
|
*/
|
|
314
|
-
render(camera, settings, target) {
|
|
434
|
+
render(camera, settings, target, options = {}) {
|
|
435
|
+
if ("getCurrentTexture" in target) {
|
|
436
|
+
this.renderToCanvas(camera, settings, target, options.scale ?? 1);
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
315
439
|
const c = new Float32Array([...camera.eye, ...camera.right, ...camera.up, ...camera.forward, camera.fovScale, ...camera.sunDirection]);
|
|
316
440
|
const code = this.dcgrid.withFloats(c, (cam) => this.dcgrid.withString(JSON.stringify(settings), (s) => this.dcgrid.withTexture(target, this.sim.device, (t) => this.m._dcgridJsRender(this.ptr, cam, s, t))));
|
|
317
441
|
this.dcgrid.check(code);
|
|
@@ -329,5 +453,65 @@ export class Renderer {
|
|
|
329
453
|
return;
|
|
330
454
|
this.destroyed = true;
|
|
331
455
|
this.m._dcgridRendererDestroy(this.ptr);
|
|
456
|
+
this.image?.destroy();
|
|
457
|
+
this.presentResources?.background.destroy();
|
|
458
|
+
}
|
|
459
|
+
renderToCanvas(camera, settings, context, scale) {
|
|
460
|
+
const device = this.sim.gpuDevice;
|
|
461
|
+
const canvas = context.canvas;
|
|
462
|
+
const w = Math.max(1, Math.round(canvas.width * scale));
|
|
463
|
+
const h = Math.max(1, Math.round(canvas.height * scale));
|
|
464
|
+
const format = context.getConfiguration?.()?.format ?? navigator.gpu.getPreferredCanvasFormat();
|
|
465
|
+
if (!this.image || this.image.width !== w || this.image.height !== h) {
|
|
466
|
+
this.image?.destroy();
|
|
467
|
+
this.image = device.createTexture({
|
|
468
|
+
label: "dcgrid render",
|
|
469
|
+
size: [w, h],
|
|
470
|
+
format: "rgba8unorm",
|
|
471
|
+
usage: GPUTextureUsage.STORAGE_BINDING | GPUTextureUsage.TEXTURE_BINDING,
|
|
472
|
+
});
|
|
473
|
+
if (this.present)
|
|
474
|
+
this.present.bindGroup = null;
|
|
475
|
+
}
|
|
476
|
+
this.render(camera, settings, this.image);
|
|
477
|
+
if (!this.presentResources)
|
|
478
|
+
this.presentResources = {
|
|
479
|
+
sampler: device.createSampler({ magFilter: "linear", minFilter: "linear" }),
|
|
480
|
+
background: device.createBuffer({ size: 16, usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST }),
|
|
481
|
+
};
|
|
482
|
+
if (this.present?.format !== format) {
|
|
483
|
+
const module = device.createShaderModule({ code: PRESENT_WGSL });
|
|
484
|
+
this.present = {
|
|
485
|
+
format,
|
|
486
|
+
pipeline: device.createRenderPipeline({
|
|
487
|
+
label: "dcgrid present",
|
|
488
|
+
layout: "auto",
|
|
489
|
+
vertex: { module, entryPoint: "vs" },
|
|
490
|
+
fragment: { module, entryPoint: "fs", targets: [{ format }] },
|
|
491
|
+
}),
|
|
492
|
+
bindGroup: null,
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
const present = this.present;
|
|
496
|
+
present.bindGroup ??= device.createBindGroup({
|
|
497
|
+
layout: present.pipeline.getBindGroupLayout(0),
|
|
498
|
+
entries: [
|
|
499
|
+
{ binding: 0, resource: this.image.createView() },
|
|
500
|
+
{ binding: 1, resource: this.presentResources.sampler },
|
|
501
|
+
{ binding: 2, resource: { buffer: this.presentResources.background } },
|
|
502
|
+
],
|
|
503
|
+
});
|
|
504
|
+
this.defaultBackground ??= this.dcgrid.defaults().render.backgroundColor;
|
|
505
|
+
const background = settings.backgroundColor ?? this.defaultBackground;
|
|
506
|
+
device.queue.writeBuffer(this.presentResources.background, 0, new Float32Array([...background, 1]));
|
|
507
|
+
const encoder = device.createCommandEncoder();
|
|
508
|
+
const pass = encoder.beginRenderPass({
|
|
509
|
+
colorAttachments: [{ view: context.getCurrentTexture().createView(), loadOp: "clear", storeOp: "store", clearValue: [0, 0, 0, 1] }],
|
|
510
|
+
});
|
|
511
|
+
pass.setPipeline(present.pipeline);
|
|
512
|
+
pass.setBindGroup(0, present.bindGroup);
|
|
513
|
+
pass.draw(3);
|
|
514
|
+
pass.end();
|
|
515
|
+
device.queue.submit([encoder.finish()]);
|
|
332
516
|
}
|
|
333
517
|
}
|