// This code implements the `-sMODULARIZE` settings by taking the generated // JS program code (INNER_JS_CODE) and wrapping it in a factory function. // When targeting node and ES6 we use `await import ..` in the generated code // so the outer function needs to be marked as async. async function ModuleFactory(moduleArg = {}) { var moduleRtn; // include: shell.js // include: minimum_runtime_check.js // end include: minimum_runtime_check.js // The Module object: Our interface to the outside world. We import // and export values on it. There are various ways Module can be used: // 1. Not defined. We create it here // 2. A function parameter, function(moduleArg) => Promise // 3. pre-run appended it, var Module = {}; ..generated code.. // 4. External script tag defines var Module. // We need to check if Module already exists (e.g. case 3 above). // Substitution will be replaced with actual code on later stage of the build, // this way Closure Compiler will not mangle it (e.g. case 4. above). // Note that if you want to run closure, and also to use Module // after the generated code, you will need to define var Module = {}; // before the code. Then that object will be used in the code, and you // can continue to use Module afterwards as well. var Module = moduleArg; // Determine the runtime environment we are in. You can customize this by // setting the ENVIRONMENT setting at compile time (see settings.js). // Attempt to auto-detect the environment var ENVIRONMENT_IS_WEB = !!globalThis.window; var ENVIRONMENT_IS_WORKER = !!globalThis.WorkerGlobalScope; // N.b. Electron.js environment is simultaneously a NODE-environment, but // also a web environment. var ENVIRONMENT_IS_NODE = globalThis.process?.versions?.node && globalThis.process?.type != "renderer"; if (ENVIRONMENT_IS_NODE) { // When building an ES module `require` is not normally available. // We need to use `createRequire()` to construct the require()` function. const {createRequire} = await import("node:module"); /** @suppress{duplicate} */ var require = createRequire(import.meta.url); } // --pre-jses are emitted after the Module integration code, so that they can // refer to Module (if they choose; they can also define Module) var arguments_ = []; var thisProgram = "./this.program"; var quit_ = (status, toThrow) => { throw toThrow; }; var _scriptName = import.meta.url; // `/` should be present at the end if `scriptDirectory` is not empty var scriptDirectory = ""; function locateFile(path) { if (Module["locateFile"]) { return Module["locateFile"](path, scriptDirectory); } return scriptDirectory + path; } // Hooks that are implemented differently in different runtime environments. var readAsync, readBinary; if (ENVIRONMENT_IS_NODE) { // These modules will usually be used on Node.js. Load them eagerly to avoid // the complexity of lazy-loading. var fs = require("node:fs"); if (_scriptName.startsWith("file:")) { scriptDirectory = require("node:path").dirname(require("node:url").fileURLToPath(_scriptName)) + "/"; } // include: node_shell_read.js readBinary = filename => { // We need to re-wrap `file://` strings to URLs. filename = isFileURI(filename) ? new URL(filename) : filename; var ret = fs.readFileSync(filename); return ret; }; readAsync = async (filename, binary = true) => { // See the comment in the `readBinary` function. filename = isFileURI(filename) ? new URL(filename) : filename; var ret = fs.readFileSync(filename, binary ? undefined : "utf8"); return ret; }; // end include: node_shell_read.js if (process.argv.length > 1) { thisProgram = process.argv[1].replace(/\\/g, "/"); } arguments_ = process.argv.slice(2); quit_ = (status, toThrow) => { process.exitCode = status; throw toThrow; }; } else // Note that this includes Node.js workers when relevant (pthreads is enabled). // Node.js workers are detected as a combination of ENVIRONMENT_IS_WORKER and // ENVIRONMENT_IS_NODE. if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) { try { scriptDirectory = new URL(".", _scriptName).href; } catch {} { // include: web_or_worker_shell_read.js if (ENVIRONMENT_IS_WORKER) { readBinary = url => { var xhr = new XMLHttpRequest; xhr.open("GET", url, false); xhr.responseType = "arraybuffer"; xhr.send(null); return new Uint8Array(/** @type{!ArrayBuffer} */ (xhr.response)); }; } readAsync = async url => { // Fetch has some additional restrictions over XHR, like it can't be used on a file:// url. // See https://github.com/github/fetch/pull/92#issuecomment-140665932 // Cordova or Electron apps are typically loaded from a file:// url. // So use XHR on webview if URL is a file URL. if (isFileURI(url)) { return new Promise((resolve, reject) => { var xhr = new XMLHttpRequest; xhr.open("GET", url, true); xhr.responseType = "arraybuffer"; xhr.onload = () => { if (xhr.status == 200 || (xhr.status == 0 && xhr.response)) { // file URLs can return 0 resolve(xhr.response); return; } reject(xhr.status); }; xhr.onerror = reject; xhr.send(null); }); } var response = await fetch(url, { credentials: "same-origin" }); if (response.ok) { return response.arrayBuffer(); } throw new Error(response.status + " : " + response.url); }; } } else {} var out = console.log.bind(console); var err = console.error.bind(console); // end include: shell.js // include: preamble.js // === Preamble library stuff === // Documentation for the public APIs defined in this file must be updated in: // site/source/docs/api_reference/preamble.js.rst // A prebuilt local version of the documentation is available at: // site/build/text/docs/api_reference/preamble.js.txt // You can also build docs locally as HTML or other formats in site/ // An online HTML version (which may be of a different version of Emscripten) // is up at http://kripken.github.io/emscripten-site/docs/api_reference/preamble.js.html var wasmBinary; // Wasm globals //======================================== // Runtime essentials //======================================== // whether we are quitting the application. no code should run after this. // set in exit() and abort() var ABORT = false; // set by exit() and abort(). Passed to 'onExit' handler. // NOTE: This is also used as the process return code in shell environments // but only when noExitRuntime is false. var EXITSTATUS; // In STRICT mode, we only define assert() when ASSERTIONS is set. i.e. we // don't define it at all in release modes. This matches the behaviour of // MINIMAL_RUNTIME. // TODO(sbc): Make this the default even without STRICT enabled. /** @type {function(*, string=)} */ function assert(condition, text) { if (!condition) { // This build was created without ASSERTIONS defined. `assert()` should not // ever be called in this configuration but in case there are callers in // the wild leave this simple abort() implementation here for now. abort(text); } } /** * Indicates whether filename is delivered via file protocol (as opposed to http/https) * @noinline */ var isFileURI = filename => filename.startsWith("file://"); // include: runtime_common.js // include: runtime_stack_check.js // end include: runtime_stack_check.js // include: runtime_exceptions.js // end include: runtime_exceptions.js // include: runtime_debug.js // end include: runtime_debug.js var readyPromiseResolve, readyPromiseReject; // Memory management var /** @type {!Int8Array} */ HEAP8, /** @type {!Uint8Array} */ HEAPU8, /** @type {!Int16Array} */ HEAP16, /** @type {!Uint16Array} */ HEAPU16, /** @type {!Int32Array} */ HEAP32, /** @type {!Uint32Array} */ HEAPU32, /** @type {!Float32Array} */ HEAPF32, /** @type {!Float64Array} */ HEAPF64; var runtimeInitialized = false; function updateMemoryViews() { var b = wasmMemory.buffer; HEAP8 = new Int8Array(b); HEAP16 = new Int16Array(b); Module["HEAPU8"] = HEAPU8 = new Uint8Array(b); HEAPU16 = new Uint16Array(b); HEAP32 = new Int32Array(b); Module["HEAPU32"] = HEAPU32 = new Uint32Array(b); Module["HEAPF32"] = HEAPF32 = new Float32Array(b); Module["HEAPF64"] = HEAPF64 = new Float64Array(b); } // include: memoryprofiler.js // end include: memoryprofiler.js // end include: runtime_common.js function preRun() { if (Module["preRun"]) { if (typeof Module["preRun"] == "function") Module["preRun"] = [ Module["preRun"] ]; while (Module["preRun"].length) { addOnPreRun(Module["preRun"].shift()); } } // Begin ATPRERUNS hooks callRuntimeCallbacks(onPreRuns); } function initRuntime() { runtimeInitialized = true; // Begin ATINITS hooks if (!Module["noFSInit"] && !FS.initialized) FS.init(); TTY.init(); // End ATINITS hooks wasmExports["jd"](); // Begin ATPOSTCTORS hooks FS.ignorePermissions = false; } function postRun() { // PThreads reuse the runtime from the main thread. if (Module["postRun"]) { if (typeof Module["postRun"] == "function") Module["postRun"] = [ Module["postRun"] ]; while (Module["postRun"].length) { addOnPostRun(Module["postRun"].shift()); } } // Begin ATPOSTRUNS hooks callRuntimeCallbacks(onPostRuns); } /** @param {string|number=} what */ function abort(what) { Module["onAbort"]?.(what); what = "Aborted(" + what + ")"; // TODO(sbc): Should we remove printing and leave it up to whoever // catches the exception? err(what); ABORT = true; what += ". Build with -sASSERTIONS for more info."; // Use a wasm runtime error, because a JS error might be seen as a foreign // exception, which means we'd run destructors on it. We need the error to // simply make the program stop. // FIXME This approach does not work in Wasm EH because it currently does not assume // all RuntimeErrors are from traps; it decides whether a RuntimeError is from // a trap or not based on a hidden field within the object. So at the moment // we don't have a way of throwing a wasm trap from JS. TODO Make a JS API that // allows this in the wasm spec. // Suppress closure compiler warning here. Closure compiler's builtin extern // definition for WebAssembly.RuntimeError claims it takes no arguments even // though it can. // TODO(https://github.com/google/closure-compiler/pull/3913): Remove if/when upstream closure gets fixed. /** @suppress {checkTypes} */ var e = new WebAssembly.RuntimeError(what); readyPromiseReject?.(e); // Throw the error whether or not MODULARIZE is set because abort is used // in code paths apart from instantiation where an exception is expected // to be thrown when abort is called. throw e; } var wasmBinaryFile; function findWasmBinary() { if (Module["locateFile"]) { return locateFile("vision_wasm_module_internal.wasm"); } // Use bundler-friendly `new URL(..., import.meta.url)` pattern; works in browsers too. return new URL("vision_wasm_module_internal.wasm", import.meta.url).href; } function getBinarySync(file) { if (file == wasmBinaryFile && wasmBinary) { return new Uint8Array(wasmBinary); } if (readBinary) { return readBinary(file); } // Throwing a plain string here, even though it not normally advisable since // this gets turning into an `abort` in instantiateArrayBuffer. throw "both async and sync fetching of the wasm failed"; } async function getWasmBinary(binaryFile) { // If we don't have the binary yet, load it asynchronously using readAsync. if (!wasmBinary) { // Fetch the binary using readAsync try { var response = await readAsync(binaryFile); return new Uint8Array(response); } catch {} } // Otherwise, getBinarySync should be able to get it synchronously 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 && !isFileURI(binaryFile) && !ENVIRONMENT_IS_NODE) { try { var response = fetch(binaryFile, { credentials: "same-origin" }); var instantiationResult = await WebAssembly.instantiateStreaming(response, imports); return instantiationResult; } catch (reason) { // We expect the most common failure cause to be a bad MIME type for the binary, // in which case falling back to ArrayBuffer instantiation should work. err(`wasm streaming compile failed: ${reason}`); err("falling back to ArrayBuffer instantiation"); } } return instantiateArrayBuffer(binaryFile, imports); } function getWasmImports() { // prepare imports var imports = { "a": wasmImports }; return imports; } // Create the wasm instance. // Receives the wasm imports, returns the exports. async function createWasm() { // Load the wasm module and create an instance of using native support in the JS engine. // handle a generated wasm instance, receiving its exports and // performing other necessary setup /** @param {WebAssembly.Module=} module*/ function receiveInstance(instance, module) { wasmExports = instance.exports; assignWasmExports(wasmExports); updateMemoryViews(); return wasmExports; } // Prefer streaming instantiation if available. function receiveInstantiationResult(result) { // 'result' is a ResultObject object which has both the module and instance. // receiveInstance() will swap in the exports (to Module.asm) so they can be called // TODO: Due to Closure regression https://github.com/google/closure-compiler/issues/3193, the above line no longer optimizes out down to the following line. // When the regression is fixed, can restore the above PTHREADS-enabled path. return receiveInstance(result["instance"]); } var info = getWasmImports(); // User shell pages can write their own Module.instantiateWasm = function(imports, successCallback) callback // to manually instantiate the Wasm module themselves. This allows pages to // run the instantiation parallel to any other async startup actions they are // performing. // Also pthreads and wasm workers initialize the wasm instance through this // path. if (Module["instantiateWasm"]) { return new Promise((resolve, reject) => { Module["instantiateWasm"](info, (inst, mod) => { resolve(receiveInstance(inst, mod)); }); }); } wasmBinaryFile ??= findWasmBinary(); var result = await instantiateAsync(wasmBinary, wasmBinaryFile, info); var exports = receiveInstantiationResult(result); return exports; } // Globals used by JS i64 conversions (see makeSetValue) var tempDouble; var tempI64; // end include: preamble.js // Begin JS library code var handleException = e => { // Certain exception types we do not treat as errors since they are used for // internal control flow. // 1. ExitStatus, which is thrown by exit() // 2. "unwind", which is thrown by emscripten_unwind_to_js_event_loop() and others // that wish to return to JS event loop. if (e instanceof ExitStatus || e == "unwind") { return EXITSTATUS; } quit_(1, e); }; class ExitStatus { name="ExitStatus"; constructor(status) { this.message = `Program terminated with exit(${status})`; this.status = status; } } var runtimeKeepaliveCounter = 0; var keepRuntimeAlive = () => noExitRuntime || runtimeKeepaliveCounter > 0; var _proc_exit = code => { EXITSTATUS = code; if (!keepRuntimeAlive()) { Module["onExit"]?.(code); ABORT = true; } quit_(code, new ExitStatus(code)); }; /** @param {boolean|number=} implicit */ var exitJS = (status, implicit) => { EXITSTATUS = status; _proc_exit(status); }; var _exit = exitJS; var maybeExit = () => { if (!keepRuntimeAlive()) { try { _exit(EXITSTATUS); } catch (e) { handleException(e); } } }; var callUserCallback = func => { if (ABORT) { return; } try { return func(); } catch (e) { handleException(e); } finally { maybeExit(); } }; function getFullscreenElement() { return document.fullscreenElement || document.mozFullScreenElement || document.webkitFullscreenElement || document.webkitCurrentFullScreenElement || document.msFullscreenElement; } /** @param {number=} timeout */ var safeSetTimeout = (func, timeout) => setTimeout(() => { callUserCallback(func); }, timeout); var warnOnce = text => { warnOnce.shown ||= {}; if (!warnOnce.shown[text]) { warnOnce.shown[text] = 1; if (ENVIRONMENT_IS_NODE) text = "warning: " + text; err(text); } }; var preloadPlugins = []; var Browser = { useWebGL: false, isFullscreen: false, pointerLock: false, moduleContextCreatedCallbacks: [], workers: [], preloadedImages: {}, preloadedAudios: {}, getCanvas: () => Module["canvas"], init() { if (Browser.initted) return; Browser.initted = true; // Support for plugins that can process preloaded files. You can add more of these to // your app by creating and appending to preloadPlugins. // Each plugin is asked if it can handle a file based on the file's name. If it can, // it is given the file's raw data. When it is done, it calls a callback with the file's // (possibly modified) data. For example, a plugin might decompress a file, or it // might create some side data structure for use later (like an Image element, etc.). var imagePlugin = {}; imagePlugin["canHandle"] = name => !Module["noImageDecoding"] && /\.(jpg|jpeg|png|bmp|webp)$/i.test(name); imagePlugin["handle"] = async (byteArray, name) => { var b = new Blob([ byteArray ], { type: Browser.getMimetype(name) }); if (b.size !== byteArray.length) { // Safari bug #118630 // Safari's Blob can only take an ArrayBuffer b = new Blob([ (new Uint8Array(byteArray)).buffer ], { type: Browser.getMimetype(name) }); } var url = URL.createObjectURL(b); return new Promise((resolve, reject) => { var img = new Image; img.onload = () => { var canvas = /** @type {!HTMLCanvasElement} */ (document.createElement("canvas")); canvas.width = img.width; canvas.height = img.height; var ctx = canvas.getContext("2d"); ctx.drawImage(img, 0, 0); Browser.preloadedImages[name] = canvas; URL.revokeObjectURL(url); resolve(byteArray); }; img.onerror = event => { err(`Image ${url} could not be decoded`); reject(); }; img.src = url; }); }; preloadPlugins.push(imagePlugin); var audioPlugin = {}; audioPlugin["canHandle"] = name => !Module["noAudioDecoding"] && name.slice(-4) in { ".ogg": 1, ".wav": 1, ".mp3": 1 }; audioPlugin["handle"] = async (byteArray, name) => new Promise((resolve, reject) => { var done = false; function finish(audio) { if (done) return; done = true; Browser.preloadedAudios[name] = audio; resolve(byteArray); } var b = new Blob([ byteArray ], { type: Browser.getMimetype(name) }); var url = URL.createObjectURL(b); // XXX we never revoke this! var audio = new Audio; audio.addEventListener("canplaythrough", () => finish(audio), false); // use addEventListener due to chromium bug 124926 audio.onerror = event => { if (done) return; err(`warning: browser could not fully decode audio ${name}, trying slower base64 approach`); function encode64(data) { var BASE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; var PAD = "="; var ret = ""; var leftchar = 0; var leftbits = 0; for (var i = 0; i < data.length; i++) { leftchar = (leftchar << 8) | data[i]; leftbits += 8; while (leftbits >= 6) { var curr = (leftchar >> (leftbits - 6)) & 63; leftbits -= 6; ret += BASE[curr]; } } if (leftbits == 2) { ret += BASE[(leftchar & 3) << 4]; ret += PAD + PAD; } else if (leftbits == 4) { ret += BASE[(leftchar & 15) << 2]; ret += PAD; } return ret; } audio.src = "data:audio/x-" + name.slice(-3) + ";base64," + encode64(byteArray); finish(audio); }; audio.src = url; // workaround for chrome bug 124926 - we do not always get oncanplaythrough or onerror safeSetTimeout(() => { finish(audio); }, 1e4); }); preloadPlugins.push(audioPlugin); // Canvas event setup function pointerLockChange() { var canvas = Browser.getCanvas(); Browser.pointerLock = document.pointerLockElement === canvas; } var canvas = Browser.getCanvas(); if (canvas) { // forced aspect ratio can be enabled by defining 'forcedAspectRatio' on Module // Module['forcedAspectRatio'] = 4 / 3; document.addEventListener("pointerlockchange", pointerLockChange, false); if (Module["elementPointerLock"]) { canvas.addEventListener("click", ev => { if (!Browser.pointerLock && Browser.getCanvas().requestPointerLock) { Browser.getCanvas().requestPointerLock(); ev.preventDefault(); } }, false); } } }, createContext(/** @type {HTMLCanvasElement} */ canvas, useWebGL, setInModule, webGLContextAttributes) { if (useWebGL && Module["ctx"] && canvas == Browser.getCanvas()) return Module["ctx"]; // no need to recreate GL context if it's already been created for this canvas. var ctx; var contextHandle; if (useWebGL) { // For GLES2/desktop GL compatibility, adjust a few defaults to be different to WebGL defaults, so that they align better with the desktop defaults. var contextAttributes = { antialias: false, alpha: false, majorVersion: (typeof WebGL2RenderingContext != "undefined") ? 2 : 1 }; if (webGLContextAttributes) { for (var attribute in webGLContextAttributes) { contextAttributes[attribute] = webGLContextAttributes[attribute]; } } // This check of existence of GL is here to satisfy Closure compiler, which yells if variable GL is referenced below but GL object is not // actually compiled in because application is not doing any GL operations. TODO: Ideally if GL is not being used, this function // Browser.createContext() should not even be emitted. if (typeof GL != "undefined") { contextHandle = GL.createContext(canvas, contextAttributes); if (contextHandle) { ctx = GL.getContext(contextHandle).GLctx; } } } else { ctx = canvas.getContext("2d"); } if (!ctx) return null; if (setInModule) { Module["ctx"] = ctx; if (useWebGL) GL.makeContextCurrent(contextHandle); Browser.useWebGL = useWebGL; Browser.moduleContextCreatedCallbacks.forEach(callback => callback()); Browser.init(); } return ctx; }, fullscreenHandlersInstalled: false, lockPointer: undefined, resizeCanvas: undefined, requestFullscreen(lockPointer, resizeCanvas) { Browser.lockPointer = lockPointer; Browser.resizeCanvas = resizeCanvas; if (typeof Browser.lockPointer == "undefined") Browser.lockPointer = true; if (typeof Browser.resizeCanvas == "undefined") Browser.resizeCanvas = false; var canvas = Browser.getCanvas(); function fullscreenChange() { Browser.isFullscreen = false; var canvasContainer = canvas.parentNode; if (getFullscreenElement() === canvasContainer) { canvas.exitFullscreen = Browser.exitFullscreen; if (Browser.lockPointer) canvas.requestPointerLock(); Browser.isFullscreen = true; if (Browser.resizeCanvas) { Browser.setFullscreenCanvasSize(); } else { Browser.updateCanvasDimensions(canvas); } } else { // remove the full screen specific parent of the canvas again to restore the HTML structure from before going full screen canvasContainer.parentNode.insertBefore(canvas, canvasContainer); canvasContainer.parentNode.removeChild(canvasContainer); if (Browser.resizeCanvas) { Browser.setWindowedCanvasSize(); } else { Browser.updateCanvasDimensions(canvas); } } Module["onFullScreen"]?.(Browser.isFullscreen); Module["onFullscreen"]?.(Browser.isFullscreen); } if (!Browser.fullscreenHandlersInstalled) { Browser.fullscreenHandlersInstalled = true; document.addEventListener("fullscreenchange", fullscreenChange, false); document.addEventListener("mozfullscreenchange", fullscreenChange, false); document.addEventListener("webkitfullscreenchange", fullscreenChange, false); document.addEventListener("MSFullscreenChange", fullscreenChange, false); } // create a new parent to ensure the canvas has no siblings. this allows browsers to optimize full screen performance when its parent is the full screen root var canvasContainer = document.createElement("div"); canvas.parentNode.insertBefore(canvasContainer, canvas); canvasContainer.appendChild(canvas); // use parent of canvas as full screen root to allow aspect ratio correction (Firefox stretches the root to screen size) canvasContainer.requestFullscreen = canvasContainer["requestFullscreen"] || canvasContainer["mozRequestFullScreen"] || canvasContainer["msRequestFullscreen"] || (canvasContainer["webkitRequestFullscreen"] ? () => canvasContainer["webkitRequestFullscreen"](Element["ALLOW_KEYBOARD_INPUT"]) : null) || (canvasContainer["webkitRequestFullScreen"] ? () => canvasContainer["webkitRequestFullScreen"](Element["ALLOW_KEYBOARD_INPUT"]) : null); canvasContainer.requestFullscreen(); }, exitFullscreen() { // This is workaround for chrome. Trying to exit from fullscreen // not in fullscreen state will cause "TypeError: Document not active" // in chrome. See https://github.com/emscripten-core/emscripten/pull/8236 if (!Browser.isFullscreen) { return false; } var CFS = document["exitFullscreen"] || document["cancelFullScreen"] || document["mozCancelFullScreen"] || document["msExitFullscreen"] || document["webkitCancelFullScreen"] || (() => {}); CFS.apply(document, []); return true; }, safeSetTimeout(func, timeout) { // Legacy function, this is used by the SDL2 port so we need to keep it // around at least until that is updated. // See https://github.com/libsdl-org/SDL/pull/6304 return safeSetTimeout(func, timeout); }, getMimetype(name) { return { "jpg": "image/jpeg", "jpeg": "image/jpeg", "png": "image/png", "bmp": "image/bmp", "ogg": "audio/ogg", "wav": "audio/wav", "mp3": "audio/mpeg" }[name.slice(name.lastIndexOf(".") + 1)]; }, getUserMedia(func) { window.getUserMedia ||= navigator["getUserMedia"] || navigator["mozGetUserMedia"]; window.getUserMedia(func); }, getMovementX(event) { return event["movementX"] || event["mozMovementX"] || event["webkitMovementX"] || 0; }, getMovementY(event) { return event["movementY"] || event["mozMovementY"] || event["webkitMovementY"] || 0; }, getMouseWheelDelta(event) { var delta = 0; switch (event.type) { case "DOMMouseScroll": // 3 lines make up a step delta = event.detail / 3; break; case "mousewheel": // 120 units make up a step delta = event.wheelDelta / 120; break; case "wheel": delta = event.deltaY; switch (event.deltaMode) { case 0: // DOM_DELTA_PIXEL: 100 pixels make up a step delta /= 100; break; case 1: // DOM_DELTA_LINE: 3 lines make up a step delta /= 3; break; case 2: // DOM_DELTA_PAGE: A page makes up 80 steps delta *= 80; break; default: abort("unrecognized mouse wheel delta mode: " + event.deltaMode); } break; default: abort("unrecognized mouse wheel event: " + event.type); } return delta; }, mouseX: 0, mouseY: 0, mouseMovementX: 0, mouseMovementY: 0, touches: {}, lastTouches: {}, calculateMouseCoords(pageX, pageY) { // Calculate the movement based on the changes // in the coordinates. var canvas = Browser.getCanvas(); var rect = canvas.getBoundingClientRect(); // Neither .scrollX or .pageXOffset are defined in a spec, but // we prefer .scrollX because it is currently in a spec draft. // (see: http://www.w3.org/TR/2013/WD-cssom-view-20131217/) var scrollX = ((typeof window.scrollX != "undefined") ? window.scrollX : window.pageXOffset); var scrollY = ((typeof window.scrollY != "undefined") ? window.scrollY : window.pageYOffset); var adjustedX = pageX - (scrollX + rect.left); var adjustedY = pageY - (scrollY + rect.top); // the canvas might be CSS-scaled compared to its backbuffer; // SDL-using content will want mouse coordinates in terms // of backbuffer units. adjustedX = adjustedX * (canvas.width / rect.width); adjustedY = adjustedY * (canvas.height / rect.height); return { x: adjustedX, y: adjustedY }; }, setMouseCoords(pageX, pageY) { const {x, y} = Browser.calculateMouseCoords(pageX, pageY); Browser.mouseMovementX = x - Browser.mouseX; Browser.mouseMovementY = y - Browser.mouseY; Browser.mouseX = x; Browser.mouseY = y; }, calculateMouseEvent(event) { // event should be mousemove, mousedown or mouseup if (Browser.pointerLock) { // When the pointer is locked, calculate the coordinates // based on the movement of the mouse. // Workaround for Firefox bug 764498 if (event.type != "mousemove" && ("mozMovementX" in event)) { Browser.mouseMovementX = Browser.mouseMovementY = 0; } else { Browser.mouseMovementX = Browser.getMovementX(event); Browser.mouseMovementY = Browser.getMovementY(event); } // add the mouse delta to the current absolute mouse position Browser.mouseX += Browser.mouseMovementX; Browser.mouseY += Browser.mouseMovementY; } else { if (event.type === "touchstart" || event.type === "touchend" || event.type === "touchmove") { var touch = event.touch; if (touch === undefined) { return; } var coords = Browser.calculateMouseCoords(touch.pageX, touch.pageY); if (event.type === "touchstart") { Browser.lastTouches[touch.identifier] = coords; Browser.touches[touch.identifier] = coords; } else if (event.type === "touchend" || event.type === "touchmove") { var last = Browser.touches[touch.identifier]; last ||= coords; Browser.lastTouches[touch.identifier] = last; Browser.touches[touch.identifier] = coords; } return; } Browser.setMouseCoords(event.pageX, event.pageY); } }, resizeListeners: [], updateResizeListeners() { var canvas = Browser.getCanvas(); Browser.resizeListeners.forEach(listener => listener(canvas.width, canvas.height)); }, setCanvasSize(width, height, noUpdates) { var canvas = Browser.getCanvas(); Browser.updateCanvasDimensions(canvas, width, height); if (!noUpdates) Browser.updateResizeListeners(); }, windowedWidth: 0, windowedHeight: 0, setFullscreenCanvasSize() { // check if SDL is available if (typeof SDL != "undefined") { var flags = HEAPU32[((SDL.screen) >> 2)]; flags = flags | 8388608; // set SDL_FULLSCREEN flag HEAP32[((SDL.screen) >> 2)] = flags; } Browser.updateCanvasDimensions(Browser.getCanvas()); Browser.updateResizeListeners(); }, setWindowedCanvasSize() { // check if SDL is available if (typeof SDL != "undefined") { var flags = HEAPU32[((SDL.screen) >> 2)]; flags = flags & ~8388608; // clear SDL_FULLSCREEN flag HEAP32[((SDL.screen) >> 2)] = flags; } Browser.updateCanvasDimensions(Browser.getCanvas()); Browser.updateResizeListeners(); }, updateCanvasDimensions(canvas, wNative, hNative) { if (wNative && hNative) { canvas.widthNative = wNative; canvas.heightNative = hNative; } else { wNative = canvas.widthNative; hNative = canvas.heightNative; } var w = wNative; var h = hNative; if (Module["forcedAspectRatio"] > 0) { if (w / h < Module["forcedAspectRatio"]) { w = Math.round(h * Module["forcedAspectRatio"]); } else { h = Math.round(w / Module["forcedAspectRatio"]); } } if ((getFullscreenElement() === canvas.parentNode) && (typeof screen != "undefined")) { var factor = Math.min(screen.width / w, screen.height / h); w = Math.round(w * factor); h = Math.round(h * factor); } if (Browser.resizeCanvas) { if (canvas.width != w) canvas.width = w; if (canvas.height != h) canvas.height = h; if (typeof canvas.style != "undefined") { canvas.style.removeProperty("width"); canvas.style.removeProperty("height"); } } else { if (canvas.width != wNative) canvas.width = wNative; if (canvas.height != hNative) canvas.height = hNative; if (typeof canvas.style != "undefined") { if (w != wNative || h != hNative) { canvas.style.setProperty("width", w + "px", "important"); canvas.style.setProperty("height", h + "px", "important"); } else { canvas.style.removeProperty("width"); canvas.style.removeProperty("height"); } } } } }; var callRuntimeCallbacks = callbacks => { while (callbacks.length > 0) { // Pass the module as the first argument. callbacks.shift()(Module); } }; var onPostRuns = []; var addOnPostRun = cb => onPostRuns.push(cb); var onPreRuns = []; var addOnPreRun = cb => onPreRuns.push(cb); var noExitRuntime = true; var stackRestore = val => __emscripten_stack_restore(val); var stackSave = () => _emscripten_stack_get_current(); class ExceptionInfo { // excPtr - Thrown object pointer to wrap. Metadata pointer is calculated from it. constructor(excPtr) { this.excPtr = excPtr; this.ptr = excPtr - 24; } set_type(type) { HEAPU32[(((this.ptr) + (4)) >> 2)] = type; } get_type() { return HEAPU32[(((this.ptr) + (4)) >> 2)]; } set_destructor(destructor) { HEAPU32[(((this.ptr) + (8)) >> 2)] = destructor; } get_destructor() { return HEAPU32[(((this.ptr) + (8)) >> 2)]; } set_caught(caught) { caught = caught ? 1 : 0; HEAP8[(this.ptr) + (12)] = caught; } get_caught() { return HEAP8[(this.ptr) + (12)] != 0; } set_rethrown(rethrown) { rethrown = rethrown ? 1 : 0; HEAP8[(this.ptr) + (13)] = rethrown; } get_rethrown() { return HEAP8[(this.ptr) + (13)] != 0; } // Initialize native structure fields. Should be called once after allocated. init(type, destructor) { this.set_adjusted_ptr(0); this.set_type(type); this.set_destructor(destructor); } set_adjusted_ptr(adjustedPtr) { HEAPU32[(((this.ptr) + (16)) >> 2)] = adjustedPtr; } get_adjusted_ptr() { return HEAPU32[(((this.ptr) + (16)) >> 2)]; } } var exceptionLast = 0; var uncaughtExceptionCount = 0; var ___cxa_throw = (ptr, type, destructor) => { var info = new ExceptionInfo(ptr); // Initialize ExceptionInfo content after it was allocated in __cxa_allocate_exception. info.init(type, destructor); exceptionLast = ptr; uncaughtExceptionCount++; throw exceptionLast; }; var PATH = { isAbs: path => path.charAt(0) === "/", splitPath: filename => { var splitPathRe = /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/; return splitPathRe.exec(filename).slice(1); }, normalizeArray: (parts, allowAboveRoot) => { // if the path tries to go above the root, `up` ends up > 0 var up = 0; for (var i = parts.length - 1; i >= 0; i--) { var last = parts[i]; if (last === ".") { parts.splice(i, 1); } else if (last === "..") { parts.splice(i, 1); up++; } else if (up) { parts.splice(i, 1); up--; } } // if the path is allowed to go above the root, restore leading ..s if (allowAboveRoot) { for (;up; up--) { parts.unshift(".."); } } return parts; }, normalize: path => { var isAbsolute = PATH.isAbs(path), trailingSlash = path.slice(-1) === "/"; // Normalize the path path = PATH.normalizeArray(path.split("/").filter(p => !!p), !isAbsolute).join("/"); if (!path && !isAbsolute) { path = "."; } if (path && trailingSlash) { path += "/"; } return (isAbsolute ? "/" : "") + path; }, dirname: path => { var result = PATH.splitPath(path), root = result[0], dir = result[1]; if (!root && !dir) { // No dirname whatsoever return "."; } if (dir) { // It has a dirname, strip trailing slash dir = dir.slice(0, -1); } return root + dir; }, basename: path => path && path.match(/([^\/]+|\/)\/*$/)[1], join: (...paths) => PATH.normalize(paths.join("/")), join2: (l, r) => PATH.normalize(l + "/" + r) }; var initRandomFill = () => { // This block is not needed on v19+ since crypto.getRandomValues is builtin if (ENVIRONMENT_IS_NODE) { var nodeCrypto = require("node:crypto"); return view => nodeCrypto.randomFillSync(view); } return view => crypto.getRandomValues(view); }; var randomFill = view => { // Lazily init on the first invocation. (randomFill = initRandomFill())(view); }; var PATH_FS = { resolve: (...args) => { var resolvedPath = "", resolvedAbsolute = false; for (var i = args.length - 1; i >= -1 && !resolvedAbsolute; i--) { var path = (i >= 0) ? args[i] : FS.cwd(); // Skip empty and invalid entries if (typeof path != "string") { throw new TypeError("Arguments to path.resolve must be strings"); } else if (!path) { return ""; } resolvedPath = path + "/" + resolvedPath; resolvedAbsolute = PATH.isAbs(path); } // At this point the path should be resolved to a full absolute path, but // handle relative paths to be safe (might happen when process.cwd() fails) resolvedPath = PATH.normalizeArray(resolvedPath.split("/").filter(p => !!p), !resolvedAbsolute).join("/"); return ((resolvedAbsolute ? "/" : "") + resolvedPath) || "."; }, relative: (from, to) => { from = PATH_FS.resolve(from).slice(1); to = PATH_FS.resolve(to).slice(1); function trim(arr) { var start = 0; for (;start < arr.length; start++) { if (arr[start] !== "") break; } var end = arr.length - 1; for (;end >= 0; end--) { if (arr[end] !== "") break; } if (start > end) return []; return arr.slice(start, end - start + 1); } var fromParts = trim(from.split("/")); var toParts = trim(to.split("/")); var length = Math.min(fromParts.length, toParts.length); var samePartsLength = length; for (var i = 0; i < length; i++) { if (fromParts[i] !== toParts[i]) { samePartsLength = i; break; } } var outputParts = []; for (var i = samePartsLength; i < fromParts.length; i++) { outputParts.push(".."); } outputParts = outputParts.concat(toParts.slice(samePartsLength)); return outputParts.join("/"); } }; var UTF8Decoder = new TextDecoder; var findStringEnd = (heapOrArray, idx, maxBytesToRead, ignoreNul) => { var maxIdx = idx + maxBytesToRead; if (ignoreNul) return maxIdx; // TextDecoder needs to know the byte length in advance, it doesn't stop on // null terminator by itself. // As a tiny code save trick, compare idx against maxIdx using a negation, // so that maxBytesToRead=undefined/NaN means Infinity. while (heapOrArray[idx] && !(idx >= maxIdx)) ++idx; return idx; }; /** * Given a pointer 'idx' to a null-terminated UTF8-encoded string in the given * array that contains uint8 values, returns a copy of that string as a * Javascript String object. * heapOrArray is either a regular array, or a JavaScript typed array view. * @param {number=} idx * @param {number=} maxBytesToRead * @param {boolean=} ignoreNul - If true, the function will not stop on a NUL character. * @return {string} */ var UTF8ArrayToString = (heapOrArray, idx = 0, maxBytesToRead, ignoreNul) => { var endPtr = findStringEnd(heapOrArray, idx, maxBytesToRead, ignoreNul); return UTF8Decoder.decode(heapOrArray.buffer ? heapOrArray.subarray(idx, endPtr) : new Uint8Array(heapOrArray.slice(idx, endPtr))); }; var FS_stdin_getChar_buffer = []; var lengthBytesUTF8 = str => { var len = 0; for (var i = 0; i < str.length; ++i) { // Gotcha: charCodeAt returns a 16-bit word that is a UTF-16 encoded code // unit, not a Unicode code point of the character! So decode // UTF16->UTF32->UTF8. // See http://unicode.org/faq/utf_bom.html#utf16-3 var c = str.charCodeAt(i); // possibly a lead surrogate if (c <= 127) { len++; } else if (c <= 2047) { len += 2; } else if (c >= 55296 && c <= 57343) { len += 4; ++i; } else { len += 3; } } return len; }; var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => { // Parameter maxBytesToWrite is not optional. Negative values, 0, null, // undefined and false each don't write out any bytes. if (!(maxBytesToWrite > 0)) return 0; var startIdx = outIdx; var endIdx = outIdx + maxBytesToWrite - 1; // -1 for string null terminator. for (var i = 0; i < str.length; ++i) { // For UTF8 byte structure, see http://en.wikipedia.org/wiki/UTF-8#Description // and https://www.ietf.org/rfc/rfc2279.txt // and https://tools.ietf.org/html/rfc3629 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); // Gotcha: if codePoint is over 0xFFFF, it is represented as a surrogate pair in UTF-16. // We need to manually skip over the second code unit for correct iteration. i++; } } // Null-terminate the pointer to the buffer. heap[outIdx] = 0; return outIdx - startIdx; }; /** @type {function(string, boolean=, number=)} */ var intArrayFromString = (stringy, dontAddNull, length) => { var len = length > 0 ? length : lengthBytesUTF8(stringy) + 1; var u8array = new Array(len); var numBytesWritten = stringToUTF8Array(stringy, u8array, 0, u8array.length); if (dontAddNull) u8array.length = numBytesWritten; return u8array; }; var FS_stdin_getChar = () => { if (!FS_stdin_getChar_buffer.length) { var result = null; if (ENVIRONMENT_IS_NODE) { // we will read data by chunks of BUFSIZE var BUFSIZE = 256; var buf = Buffer.alloc(BUFSIZE); var bytesRead = 0; // For some reason we must suppress a closure warning here, even though // fd definitely exists on process.stdin, and is even the proper way to // get the fd of stdin, // https://github.com/nodejs/help/issues/2136#issuecomment-523649904 // This started to happen after moving this logic out of library_tty.js, // so it is related to the surrounding code in some unclear manner. /** @suppress {missingProperties} */ var fd = process.stdin.fd; try { bytesRead = fs.readSync(fd, buf, 0, BUFSIZE); } catch (e) { // Cross-platform differences: on Windows, reading EOF throws an // exception, but on other OSes, reading EOF returns 0. Uniformize // behavior by treating the EOF exception to return 0. if (e.toString().includes("EOF")) bytesRead = 0; else throw e; } if (bytesRead > 0) { result = buf.slice(0, bytesRead).toString("utf-8"); } } else if (globalThis.window?.prompt) { // Browser. result = window.prompt("Input: "); // returns null on cancel if (result !== null) { result += "\n"; } } else {} if (!result) { return null; } FS_stdin_getChar_buffer = intArrayFromString(result, true); } return FS_stdin_getChar_buffer.shift(); }; var TTY = { ttys: [], init() {}, shutdown() {}, register(dev, ops) { TTY.ttys[dev] = { input: [], output: [], ops }; FS.registerDevice(dev, TTY.stream_ops); }, stream_ops: { open(stream) { var tty = TTY.ttys[stream.node.rdev]; if (!tty) { throw new FS.ErrnoError(43); } stream.tty = tty; stream.seekable = false; }, close(stream) { // flush any pending line data stream.tty.ops.fsync(stream.tty); }, fsync(stream) { stream.tty.ops.fsync(stream.tty); }, read(stream, buffer, offset, length, pos) { if (!stream.tty || !stream.tty.ops.get_char) { throw new FS.ErrnoError(60); } var bytesRead = 0; for (var i = 0; i < length; i++) { var result; try { result = stream.tty.ops.get_char(stream.tty); } catch (e) { throw new FS.ErrnoError(29); } if (result === undefined && bytesRead === 0) { throw new FS.ErrnoError(6); } if (result === null || result === undefined) break; bytesRead++; buffer[offset + i] = result; } if (bytesRead) { stream.node.atime = Date.now(); } return bytesRead; }, write(stream, buffer, offset, length, pos) { if (!stream.tty || !stream.tty.ops.put_char) { throw new FS.ErrnoError(60); } try { for (var i = 0; i < length; i++) { stream.tty.ops.put_char(stream.tty, buffer[offset + i]); } } catch (e) { throw new FS.ErrnoError(29); } if (length) { stream.node.mtime = stream.node.ctime = Date.now(); } return i; } }, default_tty_ops: { get_char(tty) { return FS_stdin_getChar(); }, put_char(tty, val) { if (val === null || val === 10) { out(UTF8ArrayToString(tty.output)); tty.output = []; } else { if (val != 0) tty.output.push(val); } }, fsync(tty) { if (tty.output?.length > 0) { out(UTF8ArrayToString(tty.output)); tty.output = []; } }, ioctl_tcgets(tty) { // typical setting return { c_iflag: 25856, c_oflag: 5, c_cflag: 191, c_lflag: 35387, c_cc: [ 3, 28, 127, 21, 4, 0, 1, 0, 17, 19, 26, 0, 18, 15, 23, 22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] }; }, ioctl_tcsets(tty, optional_actions, data) { // currently just ignore return 0; }, ioctl_tiocgwinsz(tty) { return [ 24, 80 ]; } }, default_tty1_ops: { put_char(tty, val) { if (val === null || val === 10) { err(UTF8ArrayToString(tty.output)); tty.output = []; } else { if (val != 0) tty.output.push(val); } }, fsync(tty) { if (tty.output?.length > 0) { err(UTF8ArrayToString(tty.output)); tty.output = []; } } } }; var zeroMemory = (ptr, size) => HEAPU8.fill(0, ptr, ptr + size); var alignMemory = (size, alignment) => Math.ceil(size / alignment) * alignment; var mmapAlloc = size => { size = alignMemory(size, 65536); var ptr = _emscripten_builtin_memalign(65536, size); if (ptr) zeroMemory(ptr, size); return ptr; }; var MEMFS = { ops_table: null, mount(mount) { return MEMFS.createNode(null, "/", 16895, 0); }, createNode(parent, name, mode, dev) { if (FS.isBlkdev(mode) || FS.isFIFO(mode)) { // not supported throw new FS.ErrnoError(63); } MEMFS.ops_table ||= { dir: { node: { getattr: MEMFS.node_ops.getattr, setattr: MEMFS.node_ops.setattr, lookup: MEMFS.node_ops.lookup, mknod: MEMFS.node_ops.mknod, rename: MEMFS.node_ops.rename, unlink: MEMFS.node_ops.unlink, rmdir: MEMFS.node_ops.rmdir, readdir: MEMFS.node_ops.readdir, symlink: MEMFS.node_ops.symlink }, stream: { llseek: MEMFS.stream_ops.llseek } }, file: { node: { getattr: MEMFS.node_ops.getattr, setattr: MEMFS.node_ops.setattr }, stream: { llseek: MEMFS.stream_ops.llseek, read: MEMFS.stream_ops.read, write: MEMFS.stream_ops.write, mmap: MEMFS.stream_ops.mmap, msync: MEMFS.stream_ops.msync } }, link: { node: { getattr: MEMFS.node_ops.getattr, setattr: MEMFS.node_ops.setattr, readlink: MEMFS.node_ops.readlink }, stream: {} }, chrdev: { node: { getattr: MEMFS.node_ops.getattr, setattr: MEMFS.node_ops.setattr }, stream: FS.chrdev_stream_ops } }; var node = FS.createNode(parent, name, mode, dev); if (FS.isDir(node.mode)) { node.node_ops = MEMFS.ops_table.dir.node; node.stream_ops = MEMFS.ops_table.dir.stream; node.contents = {}; } else if (FS.isFile(node.mode)) { node.node_ops = MEMFS.ops_table.file.node; node.stream_ops = MEMFS.ops_table.file.stream; node.usedBytes = 0; // The actual number of bytes used in the typed array, as opposed to contents.length which gives the whole capacity. // When the byte data of the file is populated, this will point to either a typed array, or a normal JS array. Typed arrays are preferred // for performance, and used by default. However, typed arrays are not resizable like normal JS arrays are, so there is a small disk size // penalty involved for appending file writes that continuously grow a file similar to std::vector capacity vs used -scheme. node.contents = null; } else if (FS.isLink(node.mode)) { node.node_ops = MEMFS.ops_table.link.node; node.stream_ops = MEMFS.ops_table.link.stream; } else if (FS.isChrdev(node.mode)) { node.node_ops = MEMFS.ops_table.chrdev.node; node.stream_ops = MEMFS.ops_table.chrdev.stream; } node.atime = node.mtime = node.ctime = Date.now(); // add the new node to the parent if (parent) { parent.contents[name] = node; parent.atime = parent.mtime = parent.ctime = node.atime; } return node; }, getFileDataAsTypedArray(node) { if (!node.contents) return new Uint8Array(0); if (node.contents.subarray) return node.contents.subarray(0, node.usedBytes); // Make sure to not return excess unused bytes. return new Uint8Array(node.contents); }, expandFileStorage(node, newCapacity) { var prevCapacity = node.contents ? node.contents.length : 0; if (prevCapacity >= newCapacity) return; // No need to expand, the storage was already large enough. // Don't expand strictly to the given requested limit if it's only a very small increase, but instead geometrically grow capacity. // For small filesizes (<1MB), perform size*2 geometric increase, but for large sizes, do a much more conservative size*1.125 increase to // avoid overshooting the allocation cap by a very large margin. var CAPACITY_DOUBLING_MAX = 1024 * 1024; newCapacity = Math.max(newCapacity, (prevCapacity * (prevCapacity < CAPACITY_DOUBLING_MAX ? 2 : 1.125)) >>> 0); if (prevCapacity != 0) newCapacity = Math.max(newCapacity, 256); // At minimum allocate 256b for each file when expanding. var oldContents = node.contents; node.contents = new Uint8Array(newCapacity); // Allocate new storage. if (node.usedBytes > 0) node.contents.set(oldContents.subarray(0, node.usedBytes), 0); }, resizeFileStorage(node, newSize) { if (node.usedBytes == newSize) return; if (newSize == 0) { node.contents = null; // Fully decommit when requesting a resize to zero. node.usedBytes = 0; } else { var oldContents = node.contents; node.contents = new Uint8Array(newSize); // Allocate new storage. if (oldContents) { node.contents.set(oldContents.subarray(0, Math.min(newSize, node.usedBytes))); } node.usedBytes = newSize; } }, node_ops: { getattr(node) { var attr = {}; // device numbers reuse inode numbers. attr.dev = FS.isChrdev(node.mode) ? node.id : 1; attr.ino = node.id; attr.mode = node.mode; attr.nlink = 1; attr.uid = 0; attr.gid = 0; attr.rdev = node.rdev; if (FS.isDir(node.mode)) { attr.size = 4096; } else if (FS.isFile(node.mode)) { attr.size = node.usedBytes; } else if (FS.isLink(node.mode)) { attr.size = node.link.length; } else { attr.size = 0; } attr.atime = new Date(node.atime); attr.mtime = new Date(node.mtime); attr.ctime = new Date(node.ctime); // NOTE: In our implementation, st_blocks = Math.ceil(st_size/st_blksize), // but this is not required by the standard. attr.blksize = 4096; attr.blocks = Math.ceil(attr.size / attr.blksize); return attr; }, setattr(node, attr) { for (const key of [ "mode", "atime", "mtime", "ctime" ]) { if (attr[key] != null) { node[key] = attr[key]; } } if (attr.size !== undefined) { MEMFS.resizeFileStorage(node, attr.size); } }, lookup(parent, name) { // This error may happen quite a bit. To avoid overhead we reuse it (and // suffer a lack of stack info). if (!MEMFS.doesNotExistError) { MEMFS.doesNotExistError = new FS.ErrnoError(44); /** @suppress {checkTypes} */ MEMFS.doesNotExistError.stack = ""; } throw MEMFS.doesNotExistError; }, mknod(parent, name, mode, dev) { return MEMFS.createNode(parent, name, mode, dev); }, rename(old_node, new_dir, new_name) { var new_node; try { new_node = FS.lookupNode(new_dir, new_name); } catch (e) {} if (new_node) { if (FS.isDir(old_node.mode)) { // if we're overwriting a directory at new_name, make sure it's empty. for (var i in new_node.contents) { throw new FS.ErrnoError(55); } } FS.hashRemoveNode(new_node); } // do the internal rewiring delete old_node.parent.contents[old_node.name]; new_dir.contents[new_name] = old_node; old_node.name = new_name; new_dir.ctime = new_dir.mtime = old_node.parent.ctime = old_node.parent.mtime = Date.now(); }, unlink(parent, name) { delete parent.contents[name]; parent.ctime = parent.mtime = Date.now(); }, rmdir(parent, name) { var node = FS.lookupNode(parent, name); for (var i in node.contents) { throw new FS.ErrnoError(55); } delete parent.contents[name]; parent.ctime = parent.mtime = Date.now(); }, readdir(node) { return [ ".", "..", ...Object.keys(node.contents) ]; }, symlink(parent, newname, oldpath) { var node = MEMFS.createNode(parent, newname, 511 | 40960, 0); node.link = oldpath; return node; }, readlink(node) { if (!FS.isLink(node.mode)) { throw new FS.ErrnoError(28); } return node.link; } }, stream_ops: { read(stream, buffer, offset, length, position) { var contents = stream.node.contents; if (position >= stream.node.usedBytes) return 0; var size = Math.min(stream.node.usedBytes - position, length); if (size > 8 && contents.subarray) { // non-trivial, and typed array buffer.set(contents.subarray(position, position + size), offset); } else { for (var i = 0; i < size; i++) buffer[offset + i] = contents[position + i]; } return size; }, write(stream, buffer, offset, length, position, canOwn) { // If the buffer is located in main memory (HEAP), and if // memory can grow, we can't hold on to references of the // memory buffer, as they may get invalidated. That means we // need to copy its contents. if (buffer.buffer === HEAP8.buffer) { canOwn = false; } if (!length) return 0; var node = stream.node; node.mtime = node.ctime = Date.now(); if (buffer.subarray && (!node.contents || node.contents.subarray)) { // This write is from a typed array to a typed array? if (canOwn) { node.contents = buffer.subarray(offset, offset + length); node.usedBytes = length; return length; } else if (node.usedBytes === 0 && position === 0) { // If this is a simple first write to an empty file, do a fast set since we don't need to care about old data. node.contents = buffer.slice(offset, offset + length); node.usedBytes = length; return length; } else if (position + length <= node.usedBytes) { // Writing to an already allocated and used subrange of the file? node.contents.set(buffer.subarray(offset, offset + length), position); return length; } } // Appending to an existing file and we need to reallocate, or source data did not come as a typed array. MEMFS.expandFileStorage(node, position + length); if (node.contents.subarray && buffer.subarray) { // Use typed array write which is available. node.contents.set(buffer.subarray(offset, offset + length), position); } else { for (var i = 0; i < length; i++) { node.contents[position + i] = buffer[offset + i]; } } node.usedBytes = Math.max(node.usedBytes, position + length); return length; }, llseek(stream, offset, whence) { var position = offset; if (whence === 1) { position += stream.position; } else if (whence === 2) { if (FS.isFile(stream.node.mode)) { position += stream.node.usedBytes; } } if (position < 0) { throw new FS.ErrnoError(28); } return position; }, mmap(stream, length, position, prot, flags) { if (!FS.isFile(stream.node.mode)) { throw new FS.ErrnoError(43); } var ptr; var allocated; var contents = stream.node.contents; // Only make a new copy when MAP_PRIVATE is specified. if (!(flags & 2) && contents && contents.buffer === HEAP8.buffer) { // We can't emulate MAP_SHARED when the file is not backed by the // buffer we're mapping to (e.g. the HEAP buffer). allocated = false; ptr = contents.byteOffset; } else { allocated = true; ptr = mmapAlloc(length); if (!ptr) { throw new FS.ErrnoError(48); } if (contents) { // Try to avoid unnecessary slices. if (position > 0 || position + length < contents.length) { if (contents.subarray) { contents = contents.subarray(position, position + length); } else { contents = Array.prototype.slice.call(contents, position, position + length); } } HEAP8.set(contents, ptr); } } return { ptr, allocated }; }, msync(stream, buffer, offset, length, mmapFlags) { MEMFS.stream_ops.write(stream, buffer, 0, length, offset, false); // should we check if bytesWritten and length are the same? return 0; } } }; var FS_modeStringToFlags = str => { var flagModes = { "r": 0, "r+": 2, "w": 512 | 64 | 1, "w+": 512 | 64 | 2, "a": 1024 | 64 | 1, "a+": 1024 | 64 | 2 }; var flags = flagModes[str]; if (typeof flags == "undefined") { throw new Error(`Unknown file open mode: ${str}`); } return flags; }; var FS_getMode = (canRead, canWrite) => { var mode = 0; if (canRead) mode |= 292 | 73; if (canWrite) mode |= 146; return mode; }; var asyncLoad = async url => { var arrayBuffer = await readAsync(url); return new Uint8Array(arrayBuffer); }; var FS_createDataFile = (...args) => FS.createDataFile(...args); var getUniqueRunDependency = id => id; var runDependencies = 0; var dependenciesFulfilled = null; var removeRunDependency = id => { runDependencies--; Module["monitorRunDependencies"]?.(runDependencies); if (runDependencies == 0) { if (dependenciesFulfilled) { var callback = dependenciesFulfilled; dependenciesFulfilled = null; callback(); } } }; var addRunDependency = id => { runDependencies++; Module["monitorRunDependencies"]?.(runDependencies); }; var FS_handledByPreloadPlugin = async (byteArray, fullname) => { // Ensure plugins are ready. if (typeof Browser != "undefined") Browser.init(); for (var plugin of preloadPlugins) { if (plugin["canHandle"](fullname)) { return plugin["handle"](byteArray, fullname); } } // If no plugin handled this file then return the original/unmodified // byteArray. return byteArray; }; var FS_preloadFile = async (parent, name, url, canRead, canWrite, dontCreateFile, canOwn, preFinish) => { // TODO we should allow people to just pass in a complete filename instead // of parent and name being that we just join them anyways var fullname = name ? PATH_FS.resolve(PATH.join2(parent, name)) : parent; var dep = getUniqueRunDependency(`cp ${fullname}`); // might have several active requests for the same fullname addRunDependency(dep); try { var byteArray = url; if (typeof url == "string") { byteArray = await asyncLoad(url); } byteArray = await FS_handledByPreloadPlugin(byteArray, fullname); preFinish?.(); if (!dontCreateFile) { FS_createDataFile(parent, name, byteArray, canRead, canWrite, canOwn); } } finally { removeRunDependency(dep); } }; var FS_createPreloadedFile = (parent, name, url, canRead, canWrite, onload, onerror, dontCreateFile, canOwn, preFinish) => { FS_preloadFile(parent, name, url, canRead, canWrite, dontCreateFile, canOwn, preFinish).then(onload).catch(onerror); }; var FS = { root: null, mounts: [], devices: {}, streams: [], nextInode: 1, nameTable: null, currentPath: "/", initialized: false, ignorePermissions: true, filesystems: null, syncFSRequests: 0, ErrnoError: class { name="ErrnoError"; // We set the `name` property to be able to identify `FS.ErrnoError` // - the `name` is a standard ECMA-262 property of error objects. Kind of good to have it anyway. // - when using PROXYFS, an error can come from an underlying FS // as different FS objects have their own FS.ErrnoError each, // the test `err instanceof FS.ErrnoError` won't detect an error coming from another filesystem, causing bugs. // we'll use the reliable test `err.name == "ErrnoError"` instead constructor(errno) { this.errno = errno; } }, FSStream: class { shared={}; get object() { return this.node; } set object(val) { this.node = val; } get isRead() { return (this.flags & 2097155) !== 1; } get isWrite() { return (this.flags & 2097155) !== 0; } get isAppend() { return (this.flags & 1024); } get flags() { return this.shared.flags; } set flags(val) { this.shared.flags = val; } get position() { return this.shared.position; } set position(val) { this.shared.position = val; } }, FSNode: class { node_ops={}; stream_ops={}; readMode=292 | 73; writeMode=146; mounted=null; constructor(parent, name, mode, rdev) { if (!parent) { parent = this; } this.parent = parent; this.mount = parent.mount; this.id = FS.nextInode++; this.name = name; this.mode = mode; this.rdev = rdev; this.atime = this.mtime = this.ctime = Date.now(); } get read() { return (this.mode & this.readMode) === this.readMode; } set read(val) { val ? this.mode |= this.readMode : this.mode &= ~this.readMode; } get write() { return (this.mode & this.writeMode) === this.writeMode; } set write(val) { val ? this.mode |= this.writeMode : this.mode &= ~this.writeMode; } get isFolder() { return FS.isDir(this.mode); } get isDevice() { return FS.isChrdev(this.mode); } }, lookupPath(path, opts = {}) { if (!path) { throw new FS.ErrnoError(44); } opts.follow_mount ??= true; if (!PATH.isAbs(path)) { path = FS.cwd() + "/" + path; } // limit max consecutive symlinks to 40 (SYMLOOP_MAX). linkloop: for (var nlinks = 0; nlinks < 40; nlinks++) { // split the absolute path var parts = path.split("/").filter(p => !!p); // start at the root var current = FS.root; var current_path = "/"; for (var i = 0; i < parts.length; i++) { var islast = (i === parts.length - 1); if (islast && opts.parent) { // stop resolving break; } if (parts[i] === ".") { continue; } if (parts[i] === "..") { current_path = PATH.dirname(current_path); if (FS.isRoot(current)) { path = current_path + "/" + parts.slice(i + 1).join("/"); // We're making progress here, don't let many consecutive ..'s // lead to ELOOP nlinks--; continue linkloop; } else { current = current.parent; } continue; } current_path = PATH.join2(current_path, parts[i]); try { current = FS.lookupNode(current, parts[i]); } catch (e) { // if noent_okay is true, suppress a ENOENT in the last component // and return an object with an undefined node. This is needed for // resolving symlinks in the path when creating a file. if ((e?.errno === 44) && islast && opts.noent_okay) { return { path: current_path }; } throw e; } // jump to the mount's root node if this is a mountpoint if (FS.isMountpoint(current) && (!islast || opts.follow_mount)) { current = current.mounted.root; } // by default, lookupPath will not follow a symlink if it is the final path component. // setting opts.follow = true will override this behavior. if (FS.isLink(current.mode) && (!islast || opts.follow)) { if (!current.node_ops.readlink) { throw new FS.ErrnoError(52); } var link = current.node_ops.readlink(current); if (!PATH.isAbs(link)) { link = PATH.dirname(current_path) + "/" + link; } path = link + "/" + parts.slice(i + 1).join("/"); continue linkloop; } } return { path: current_path, node: current }; } throw new FS.ErrnoError(32); }, getPath(node) { var path; while (true) { if (FS.isRoot(node)) { var mount = node.mount.mountpoint; if (!path) return mount; return mount[mount.length - 1] !== "/" ? `${mount}/${path}` : mount + path; } path = path ? `${node.name}/${path}` : node.name; node = node.parent; } }, hashName(parentid, name) { var hash = 0; for (var i = 0; i < name.length; i++) { hash = ((hash << 5) - hash + name.charCodeAt(i)) | 0; } return ((parentid + hash) >>> 0) % FS.nameTable.length; }, hashAddNode(node) { var hash = FS.hashName(node.parent.id, node.name); node.name_next = FS.nameTable[hash]; FS.nameTable[hash] = node; }, hashRemoveNode(node) { var hash = FS.hashName(node.parent.id, node.name); if (FS.nameTable[hash] === node) { FS.nameTable[hash] = node.name_next; } else { var current = FS.nameTable[hash]; while (current) { if (current.name_next === node) { current.name_next = node.name_next; break; } current = current.name_next; } } }, lookupNode(parent, name) { var errCode = FS.mayLookup(parent); if (errCode) { throw new FS.ErrnoError(errCode); } var hash = FS.hashName(parent.id, name); for (var node = FS.nameTable[hash]; node; node = node.name_next) { var nodeName = node.name; if (node.parent.id === parent.id && nodeName === name) { return node; } } // if we failed to find it in the cache, call into the VFS return FS.lookup(parent, name); }, createNode(parent, name, mode, rdev) { var node = new FS.FSNode(parent, name, mode, rdev); FS.hashAddNode(node); return node; }, destroyNode(node) { FS.hashRemoveNode(node); }, isRoot(node) { return node === node.parent; }, isMountpoint(node) { return !!node.mounted; }, isFile(mode) { return (mode & 61440) === 32768; }, isDir(mode) { return (mode & 61440) === 16384; }, isLink(mode) { return (mode & 61440) === 40960; }, isChrdev(mode) { return (mode & 61440) === 8192; }, isBlkdev(mode) { return (mode & 61440) === 24576; }, isFIFO(mode) { return (mode & 61440) === 4096; }, isSocket(mode) { return (mode & 49152) === 49152; }, flagsToPermissionString(flag) { var perms = [ "r", "w", "rw" ][flag & 3]; if ((flag & 512)) { perms += "w"; } return perms; }, nodePermissions(node, perms) { if (FS.ignorePermissions) { return 0; } // return 0 if any user, group or owner bits are set. if (perms.includes("r") && !(node.mode & 292)) { return 2; } if (perms.includes("w") && !(node.mode & 146)) { return 2; } if (perms.includes("x") && !(node.mode & 73)) { return 2; } return 0; }, mayLookup(dir) { if (!FS.isDir(dir.mode)) return 54; var errCode = FS.nodePermissions(dir, "x"); if (errCode) return errCode; if (!dir.node_ops.lookup) return 2; return 0; }, mayCreate(dir, name) { if (!FS.isDir(dir.mode)) { return 54; } try { var node = FS.lookupNode(dir, name); return 20; } catch (e) {} return FS.nodePermissions(dir, "wx"); }, mayDelete(dir, name, isdir) { var node; try { node = FS.lookupNode(dir, name); } catch (e) { return e.errno; } var errCode = FS.nodePermissions(dir, "wx"); if (errCode) { return errCode; } if (isdir) { if (!FS.isDir(node.mode)) { return 54; } if (FS.isRoot(node) || FS.getPath(node) === FS.cwd()) { return 10; } } else if (FS.isDir(node.mode)) { return 31; } return 0; }, mayOpen(node, flags) { if (!node) { return 44; } if (FS.isLink(node.mode)) { return 32; } var mode = FS.flagsToPermissionString(flags); if (FS.isDir(node.mode)) { // opening for write // TODO: check for O_SEARCH? (== search for dir only) if (mode !== "r" || (flags & (512 | 64))) { return 31; } } return FS.nodePermissions(node, mode); }, checkOpExists(op, err) { if (!op) { throw new FS.ErrnoError(err); } return op; }, MAX_OPEN_FDS: 4096, nextfd() { for (var fd = 0; fd <= FS.MAX_OPEN_FDS; fd++) { if (!FS.streams[fd]) { return fd; } } throw new FS.ErrnoError(33); }, getStreamChecked(fd) { var stream = FS.getStream(fd); if (!stream) { throw new FS.ErrnoError(8); } return stream; }, getStream: fd => FS.streams[fd], createStream(stream, fd = -1) { // clone it, so we can return an instance of FSStream stream = Object.assign(new FS.FSStream, stream); if (fd == -1) { fd = FS.nextfd(); } stream.fd = fd; FS.streams[fd] = stream; return stream; }, closeStream(fd) { FS.streams[fd] = null; }, dupStream(origStream, fd = -1) { var stream = FS.createStream(origStream, fd); stream.stream_ops?.dup?.(stream); return stream; }, doSetAttr(stream, node, attr) { var setattr = stream?.stream_ops.setattr; var arg = setattr ? stream : node; setattr ??= node.node_ops.setattr; FS.checkOpExists(setattr, 63); setattr(arg, attr); }, chrdev_stream_ops: { open(stream) { var device = FS.getDevice(stream.node.rdev); // override node's stream ops with the device's stream.stream_ops = device.stream_ops; // forward the open call stream.stream_ops.open?.(stream); }, llseek() { throw new FS.ErrnoError(70); } }, major: dev => ((dev) >> 8), minor: dev => ((dev) & 255), makedev: (ma, mi) => ((ma) << 8 | (mi)), registerDevice(dev, ops) { FS.devices[dev] = { stream_ops: ops }; }, getDevice: dev => FS.devices[dev], getMounts(mount) { var mounts = []; var check = [ mount ]; while (check.length) { var m = check.pop(); mounts.push(m); check.push(...m.mounts); } return mounts; }, syncfs(populate, callback) { if (typeof populate == "function") { callback = populate; populate = false; } FS.syncFSRequests++; if (FS.syncFSRequests > 1) { err(`warning: ${FS.syncFSRequests} FS.syncfs operations in flight at once, probably just doing extra work`); } var mounts = FS.getMounts(FS.root.mount); var completed = 0; function doCallback(errCode) { FS.syncFSRequests--; return callback(errCode); } function done(errCode) { if (errCode) { if (!done.errored) { done.errored = true; return doCallback(errCode); } return; } if (++completed >= mounts.length) { doCallback(null); } } // sync all mounts for (var mount of mounts) { if (mount.type.syncfs) { mount.type.syncfs(mount, populate, done); } else { done(null); } } }, mount(type, opts, mountpoint) { var root = mountpoint === "/"; var pseudo = !mountpoint; var node; if (root && FS.root) { throw new FS.ErrnoError(10); } else if (!root && !pseudo) { var lookup = FS.lookupPath(mountpoint, { follow_mount: false }); mountpoint = lookup.path; // use the absolute path node = lookup.node; if (FS.isMountpoint(node)) { throw new FS.ErrnoError(10); } if (!FS.isDir(node.mode)) { throw new FS.ErrnoError(54); } } var mount = { type, opts, mountpoint, mounts: [] }; // create a root node for the fs var mountRoot = type.mount(mount); mountRoot.mount = mount; mount.root = mountRoot; if (root) { FS.root = mountRoot; } else if (node) { // set as a mountpoint node.mounted = mount; // add the new mount to the current mount's children if (node.mount) { node.mount.mounts.push(mount); } } return mountRoot; }, unmount(mountpoint) { var lookup = FS.lookupPath(mountpoint, { follow_mount: false }); if (!FS.isMountpoint(lookup.node)) { throw new FS.ErrnoError(28); } // destroy the nodes for this mount, and all its child mounts var node = lookup.node; var mount = node.mounted; var mounts = FS.getMounts(mount); for (var [hash, current] of Object.entries(FS.nameTable)) { while (current) { var next = current.name_next; if (mounts.includes(current.mount)) { FS.destroyNode(current); } current = next; } } // no longer a mountpoint node.mounted = null; // remove this mount from the child mounts var idx = node.mount.mounts.indexOf(mount); node.mount.mounts.splice(idx, 1); }, lookup(parent, name) { return parent.node_ops.lookup(parent, name); }, mknod(path, mode, dev) { var lookup = FS.lookupPath(path, { parent: true }); var parent = lookup.node; var name = PATH.basename(path); if (!name) { throw new FS.ErrnoError(28); } if (name === "." || name === "..") { throw new FS.ErrnoError(20); } var errCode = FS.mayCreate(parent, name); if (errCode) { throw new FS.ErrnoError(errCode); } if (!parent.node_ops.mknod) { throw new FS.ErrnoError(63); } return parent.node_ops.mknod(parent, name, mode, dev); }, statfs(path) { return FS.statfsNode(FS.lookupPath(path, { follow: true }).node); }, statfsStream(stream) { // We keep a separate statfsStream function because noderawfs overrides // it. In noderawfs, stream.node is sometimes null. Instead, we need to // look at stream.path. return FS.statfsNode(stream.node); }, statfsNode(node) { // NOTE: None of the defaults here are true. We're just returning safe and // sane values. Currently nodefs and rawfs replace these defaults, // other file systems leave them alone. var rtn = { bsize: 4096, frsize: 4096, blocks: 1e6, bfree: 5e5, bavail: 5e5, files: FS.nextInode, ffree: FS.nextInode - 1, fsid: 42, flags: 2, namelen: 255 }; if (node.node_ops.statfs) { Object.assign(rtn, node.node_ops.statfs(node.mount.opts.root)); } return rtn; }, create(path, mode = 438) { mode &= 4095; mode |= 32768; return FS.mknod(path, mode, 0); }, mkdir(path, mode = 511) { mode &= 511 | 512; mode |= 16384; return FS.mknod(path, mode, 0); }, mkdirTree(path, mode) { var dirs = path.split("/"); var d = ""; for (var dir of dirs) { if (!dir) continue; if (d || PATH.isAbs(path)) d += "/"; d += dir; try { FS.mkdir(d, mode); } catch (e) { if (e.errno != 20) throw e; } } }, mkdev(path, mode, dev) { if (typeof dev == "undefined") { dev = mode; mode = 438; } mode |= 8192; return FS.mknod(path, mode, dev); }, symlink(oldpath, newpath) { if (!PATH_FS.resolve(oldpath)) { throw new FS.ErrnoError(44); } var lookup = FS.lookupPath(newpath, { parent: true }); var parent = lookup.node; if (!parent) { throw new FS.ErrnoError(44); } var newname = PATH.basename(newpath); var errCode = FS.mayCreate(parent, newname); if (errCode) { throw new FS.ErrnoError(errCode); } if (!parent.node_ops.symlink) { throw new FS.ErrnoError(63); } return parent.node_ops.symlink(parent, newname, oldpath); }, rename(old_path, new_path) { var old_dirname = PATH.dirname(old_path); var new_dirname = PATH.dirname(new_path); var old_name = PATH.basename(old_path); var new_name = PATH.basename(new_path); // parents must exist var lookup, old_dir, new_dir; // let the errors from non existent directories percolate up lookup = FS.lookupPath(old_path, { parent: true }); old_dir = lookup.node; lookup = FS.lookupPath(new_path, { parent: true }); new_dir = lookup.node; if (!old_dir || !new_dir) throw new FS.ErrnoError(44); // need to be part of the same mount if (old_dir.mount !== new_dir.mount) { throw new FS.ErrnoError(75); } // source must exist var old_node = FS.lookupNode(old_dir, old_name); // old path should not be an ancestor of the new path var relative = PATH_FS.relative(old_path, new_dirname); if (relative.charAt(0) !== ".") { throw new FS.ErrnoError(28); } // new path should not be an ancestor of the old path relative = PATH_FS.relative(new_path, old_dirname); if (relative.charAt(0) !== ".") { throw new FS.ErrnoError(55); } // see if the new path already exists var new_node; try { new_node = FS.lookupNode(new_dir, new_name); } catch (e) {} // early out if nothing needs to change if (old_node === new_node) { return; } // we'll need to delete the old entry var isdir = FS.isDir(old_node.mode); var errCode = FS.mayDelete(old_dir, old_name, isdir); if (errCode) { throw new FS.ErrnoError(errCode); } // need delete permissions if we'll be overwriting. // need create permissions if new doesn't already exist. errCode = new_node ? FS.mayDelete(new_dir, new_name, isdir) : FS.mayCreate(new_dir, new_name); if (errCode) { throw new FS.ErrnoError(errCode); } if (!old_dir.node_ops.rename) { throw new FS.ErrnoError(63); } if (FS.isMountpoint(old_node) || (new_node && FS.isMountpoint(new_node))) { throw new FS.ErrnoError(10); } // if we are going to change the parent, check write permissions if (new_dir !== old_dir) { errCode = FS.nodePermissions(old_dir, "w"); if (errCode) { throw new FS.ErrnoError(errCode); } } // remove the node from the lookup hash FS.hashRemoveNode(old_node); // do the underlying fs rename try { old_dir.node_ops.rename(old_node, new_dir, new_name); // update old node (we do this here to avoid each backend // needing to) old_node.parent = new_dir; } catch (e) { throw e; } finally { // add the node back to the hash (in case node_ops.rename // changed its name) FS.hashAddNode(old_node); } }, rmdir(path) { var lookup = FS.lookupPath(path, { parent: true }); var parent = lookup.node; var name = PATH.basename(path); var node = FS.lookupNode(parent, name); var errCode = FS.mayDelete(parent, name, true); if (errCode) { throw new FS.ErrnoError(errCode); } if (!parent.node_ops.rmdir) { throw new FS.ErrnoError(63); } if (FS.isMountpoint(node)) { throw new FS.ErrnoError(10); } parent.node_ops.rmdir(parent, name); FS.destroyNode(node); }, readdir(path) { var lookup = FS.lookupPath(path, { follow: true }); var node = lookup.node; var readdir = FS.checkOpExists(node.node_ops.readdir, 54); return readdir(node); }, unlink(path) { var lookup = FS.lookupPath(path, { parent: true }); var parent = lookup.node; if (!parent) { throw new FS.ErrnoError(44); } var name = PATH.basename(path); var node = FS.lookupNode(parent, name); var errCode = FS.mayDelete(parent, name, false); if (errCode) { // According to POSIX, we should map EISDIR to EPERM, but // we instead do what Linux does (and we must, as we use // the musl linux libc). throw new FS.ErrnoError(errCode); } if (!parent.node_ops.unlink) { throw new FS.ErrnoError(63); } if (FS.isMountpoint(node)) { throw new FS.ErrnoError(10); } parent.node_ops.unlink(parent, name); FS.destroyNode(node); }, readlink(path) { var lookup = FS.lookupPath(path); var link = lookup.node; if (!link) { throw new FS.ErrnoError(44); } if (!link.node_ops.readlink) { throw new FS.ErrnoError(28); } return link.node_ops.readlink(link); }, stat(path, dontFollow) { var lookup = FS.lookupPath(path, { follow: !dontFollow }); var node = lookup.node; var getattr = FS.checkOpExists(node.node_ops.getattr, 63); return getattr(node); }, fstat(fd) { var stream = FS.getStreamChecked(fd); var node = stream.node; var getattr = stream.stream_ops.getattr; var arg = getattr ? stream : node; getattr ??= node.node_ops.getattr; FS.checkOpExists(getattr, 63); return getattr(arg); }, lstat(path) { return FS.stat(path, true); }, doChmod(stream, node, mode, dontFollow) { FS.doSetAttr(stream, node, { mode: (mode & 4095) | (node.mode & ~4095), ctime: Date.now(), dontFollow }); }, chmod(path, mode, dontFollow) { var node; if (typeof path == "string") { var lookup = FS.lookupPath(path, { follow: !dontFollow }); node = lookup.node; } else { node = path; } FS.doChmod(null, node, mode, dontFollow); }, lchmod(path, mode) { FS.chmod(path, mode, true); }, fchmod(fd, mode) { var stream = FS.getStreamChecked(fd); FS.doChmod(stream, stream.node, mode, false); }, doChown(stream, node, dontFollow) { FS.doSetAttr(stream, node, { timestamp: Date.now(), dontFollow }); }, chown(path, uid, gid, dontFollow) { var node; if (typeof path == "string") { var lookup = FS.lookupPath(path, { follow: !dontFollow }); node = lookup.node; } else { node = path; } FS.doChown(null, node, dontFollow); }, lchown(path, uid, gid) { FS.chown(path, uid, gid, true); }, fchown(fd, uid, gid) { var stream = FS.getStreamChecked(fd); FS.doChown(stream, stream.node, false); }, doTruncate(stream, node, len) { if (FS.isDir(node.mode)) { throw new FS.ErrnoError(31); } if (!FS.isFile(node.mode)) { throw new FS.ErrnoError(28); } var errCode = FS.nodePermissions(node, "w"); if (errCode) { throw new FS.ErrnoError(errCode); } FS.doSetAttr(stream, node, { size: len, timestamp: Date.now() }); }, truncate(path, len) { if (len < 0) { throw new FS.ErrnoError(28); } var node; if (typeof path == "string") { var lookup = FS.lookupPath(path, { follow: true }); node = lookup.node; } else { node = path; } FS.doTruncate(null, node, len); }, ftruncate(fd, len) { var stream = FS.getStreamChecked(fd); if (len < 0 || (stream.flags & 2097155) === 0) { throw new FS.ErrnoError(28); } FS.doTruncate(stream, stream.node, len); }, utime(path, atime, mtime) { var lookup = FS.lookupPath(path, { follow: true }); var node = lookup.node; var setattr = FS.checkOpExists(node.node_ops.setattr, 63); setattr(node, { atime, mtime }); }, open(path, flags, mode = 438) { if (path === "") { throw new FS.ErrnoError(44); } flags = typeof flags == "string" ? FS_modeStringToFlags(flags) : flags; if ((flags & 64)) { mode = (mode & 4095) | 32768; } else { mode = 0; } var node; var isDirPath; if (typeof path == "object") { node = path; } else { isDirPath = path.endsWith("/"); // noent_okay makes it so that if the final component of the path // doesn't exist, lookupPath returns `node: undefined`. `path` will be // updated to point to the target of all symlinks. var lookup = FS.lookupPath(path, { follow: !(flags & 131072), noent_okay: true }); node = lookup.node; path = lookup.path; } // perhaps we need to create the node var created = false; if ((flags & 64)) { if (node) { // if O_CREAT and O_EXCL are set, error out if the node already exists if ((flags & 128)) { throw new FS.ErrnoError(20); } } else if (isDirPath) { throw new FS.ErrnoError(31); } else { // node doesn't exist, try to create it // Ignore the permission bits here to ensure we can `open` this new // file below. We use chmod below to apply the permissions once the // file is open. node = FS.mknod(path, mode | 511, 0); created = true; } } if (!node) { throw new FS.ErrnoError(44); } // can't truncate a device if (FS.isChrdev(node.mode)) { flags &= ~512; } // if asked only for a directory, then this must be one if ((flags & 65536) && !FS.isDir(node.mode)) { throw new FS.ErrnoError(54); } // check permissions, if this is not a file we just created now (it is ok to // create and write to a file with read-only permissions; it is read-only // for later use) if (!created) { var errCode = FS.mayOpen(node, flags); if (errCode) { throw new FS.ErrnoError(errCode); } } // do truncation if necessary if ((flags & 512) && !created) { FS.truncate(node, 0); } // we've already handled these, don't pass down to the underlying vfs flags &= ~(128 | 512 | 131072); // register the stream with the filesystem var stream = FS.createStream({ node, path: FS.getPath(node), // we want the absolute path to the node flags, seekable: true, position: 0, stream_ops: node.stream_ops, // used by the file family libc calls (fopen, fwrite, ferror, etc.) ungotten: [], error: false }); // call the new stream's open function if (stream.stream_ops.open) { stream.stream_ops.open(stream); } if (created) { FS.chmod(node, mode & 511); } return stream; }, close(stream) { if (FS.isClosed(stream)) { throw new FS.ErrnoError(8); } if (stream.getdents) stream.getdents = null; // free readdir state try { if (stream.stream_ops.close) { stream.stream_ops.close(stream); } } catch (e) { throw e; } finally { FS.closeStream(stream.fd); } stream.fd = null; }, isClosed(stream) { return stream.fd === null; }, llseek(stream, offset, whence) { if (FS.isClosed(stream)) { throw new FS.ErrnoError(8); } if (!stream.seekable || !stream.stream_ops.llseek) { throw new FS.ErrnoError(70); } if (whence != 0 && whence != 1 && whence != 2) { throw new FS.ErrnoError(28); } stream.position = stream.stream_ops.llseek(stream, offset, whence); stream.ungotten = []; return stream.position; }, read(stream, buffer, offset, length, position) { if (length < 0 || position < 0) { throw new FS.ErrnoError(28); } if (FS.isClosed(stream)) { throw new FS.ErrnoError(8); } if ((stream.flags & 2097155) === 1) { throw new FS.ErrnoError(8); } if (FS.isDir(stream.node.mode)) { throw new FS.ErrnoError(31); } if (!stream.stream_ops.read) { throw new FS.ErrnoError(28); } var seeking = typeof position != "undefined"; if (!seeking) { position = stream.position; } else if (!stream.seekable) { throw new FS.ErrnoError(70); } var bytesRead = stream.stream_ops.read(stream, buffer, offset, length, position); if (!seeking) stream.position += bytesRead; return bytesRead; }, write(stream, buffer, offset, length, position, canOwn) { if (length < 0 || position < 0) { throw new FS.ErrnoError(28); } if (FS.isClosed(stream)) { throw new FS.ErrnoError(8); } if ((stream.flags & 2097155) === 0) { throw new FS.ErrnoError(8); } if (FS.isDir(stream.node.mode)) { throw new FS.ErrnoError(31); } if (!stream.stream_ops.write) { throw new FS.ErrnoError(28); } if (stream.seekable && stream.flags & 1024) { // seek to the end before writing in append mode FS.llseek(stream, 0, 2); } var seeking = typeof position != "undefined"; if (!seeking) { position = stream.position; } else if (!stream.seekable) { throw new FS.ErrnoError(70); } var bytesWritten = stream.stream_ops.write(stream, buffer, offset, length, position, canOwn); if (!seeking) stream.position += bytesWritten; return bytesWritten; }, mmap(stream, length, position, prot, flags) { // User requests writing to file (prot & PROT_WRITE != 0). // Checking if we have permissions to write to the file unless // MAP_PRIVATE flag is set. According to POSIX spec it is possible // to write to file opened in read-only mode with MAP_PRIVATE flag, // as all modifications will be visible only in the memory of // the current process. if ((prot & 2) !== 0 && (flags & 2) === 0 && (stream.flags & 2097155) !== 2) { throw new FS.ErrnoError(2); } if ((stream.flags & 2097155) === 1) { throw new FS.ErrnoError(2); } if (!stream.stream_ops.mmap) { throw new FS.ErrnoError(43); } if (!length) { throw new FS.ErrnoError(28); } return stream.stream_ops.mmap(stream, length, position, prot, flags); }, msync(stream, buffer, offset, length, mmapFlags) { if (!stream.stream_ops.msync) { return 0; } return stream.stream_ops.msync(stream, buffer, offset, length, mmapFlags); }, ioctl(stream, cmd, arg) { if (!stream.stream_ops.ioctl) { throw new FS.ErrnoError(59); } return stream.stream_ops.ioctl(stream, cmd, arg); }, readFile(path, opts = {}) { opts.flags = opts.flags || 0; opts.encoding = opts.encoding || "binary"; if (opts.encoding !== "utf8" && opts.encoding !== "binary") { abort(`Invalid encoding type "${opts.encoding}"`); } var stream = FS.open(path, opts.flags); var stat = FS.stat(path); var length = stat.size; var buf = new Uint8Array(length); FS.read(stream, buf, 0, length, 0); if (opts.encoding === "utf8") { buf = UTF8ArrayToString(buf); } FS.close(stream); return buf; }, writeFile(path, data, opts = {}) { opts.flags = opts.flags || 577; var stream = FS.open(path, opts.flags, opts.mode); if (typeof data == "string") { data = new Uint8Array(intArrayFromString(data, true)); } if (ArrayBuffer.isView(data)) { FS.write(stream, data, 0, data.byteLength, undefined, opts.canOwn); } else { abort("Unsupported data type"); } FS.close(stream); }, cwd: () => FS.currentPath, chdir(path) { var lookup = FS.lookupPath(path, { follow: true }); if (lookup.node === null) { throw new FS.ErrnoError(44); } if (!FS.isDir(lookup.node.mode)) { throw new FS.ErrnoError(54); } var errCode = FS.nodePermissions(lookup.node, "x"); if (errCode) { throw new FS.ErrnoError(errCode); } FS.currentPath = lookup.path; }, createDefaultDirectories() { FS.mkdir("/tmp"); FS.mkdir("/home"); FS.mkdir("/home/web_user"); }, createDefaultDevices() { // create /dev FS.mkdir("/dev"); // setup /dev/null FS.registerDevice(FS.makedev(1, 3), { read: () => 0, write: (stream, buffer, offset, length, pos) => length, llseek: () => 0 }); FS.mkdev("/dev/null", FS.makedev(1, 3)); // setup /dev/tty and /dev/tty1 // stderr needs to print output using err() rather than out() // so we register a second tty just for it. TTY.register(FS.makedev(5, 0), TTY.default_tty_ops); TTY.register(FS.makedev(6, 0), TTY.default_tty1_ops); FS.mkdev("/dev/tty", FS.makedev(5, 0)); FS.mkdev("/dev/tty1", FS.makedev(6, 0)); // setup /dev/[u]random // use a buffer to avoid overhead of individual crypto calls per byte var randomBuffer = new Uint8Array(1024), randomLeft = 0; var randomByte = () => { if (randomLeft === 0) { randomFill(randomBuffer); randomLeft = randomBuffer.byteLength; } return randomBuffer[--randomLeft]; }; FS.createDevice("/dev", "random", randomByte); FS.createDevice("/dev", "urandom", randomByte); // we're not going to emulate the actual shm device, // just create the tmp dirs that reside in it commonly FS.mkdir("/dev/shm"); FS.mkdir("/dev/shm/tmp"); }, createSpecialDirectories() { // create /proc/self/fd which allows /proc/self/fd/6 => readlink gives the // name of the stream for fd 6 (see test_unistd_ttyname) FS.mkdir("/proc"); var proc_self = FS.mkdir("/proc/self"); FS.mkdir("/proc/self/fd"); FS.mount({ mount() { var node = FS.createNode(proc_self, "fd", 16895, 73); node.stream_ops = { llseek: MEMFS.stream_ops.llseek }; node.node_ops = { lookup(parent, name) { var fd = +name; var stream = FS.getStreamChecked(fd); var ret = { parent: null, mount: { mountpoint: "fake" }, node_ops: { readlink: () => stream.path }, id: fd + 1 }; ret.parent = ret; // make it look like a simple root node return ret; }, readdir() { return Array.from(FS.streams.entries()).filter(([k, v]) => v).map(([k, v]) => k.toString()); } }; return node; } }, {}, "/proc/self/fd"); }, createStandardStreams(input, output, error) { // TODO deprecate the old functionality of a single // input / output callback and that utilizes FS.createDevice // and instead require a unique set of stream ops // by default, we symlink the standard streams to the // default tty devices. however, if the standard streams // have been overwritten we create a unique device for // them instead. if (input) { FS.createDevice("/dev", "stdin", input); } else { FS.symlink("/dev/tty", "/dev/stdin"); } if (output) { FS.createDevice("/dev", "stdout", null, output); } else { FS.symlink("/dev/tty", "/dev/stdout"); } if (error) { FS.createDevice("/dev", "stderr", null, error); } else { FS.symlink("/dev/tty1", "/dev/stderr"); } // open default streams for the stdin, stdout and stderr devices var stdin = FS.open("/dev/stdin", 0); var stdout = FS.open("/dev/stdout", 1); var stderr = FS.open("/dev/stderr", 1); }, staticInit() { FS.nameTable = new Array(4096); FS.mount(MEMFS, {}, "/"); FS.createDefaultDirectories(); FS.createDefaultDevices(); FS.createSpecialDirectories(); FS.filesystems = { "MEMFS": MEMFS }; }, init(input, output, error) { FS.initialized = true; // Allow Module.stdin etc. to provide defaults, if none explicitly passed to us here input ??= Module["stdin"]; output ??= Module["stdout"]; error ??= Module["stderr"]; FS.createStandardStreams(input, output, error); }, quit() { FS.initialized = false; // force-flush all streams, so we get musl std streams printed out // close all of our streams for (var stream of FS.streams) { if (stream) { FS.close(stream); } } }, findObject(path, dontResolveLastLink) { var ret = FS.analyzePath(path, dontResolveLastLink); if (!ret.exists) { return null; } return ret.object; }, analyzePath(path, dontResolveLastLink) { // operate from within the context of the symlink's target try { var lookup = FS.lookupPath(path, { follow: !dontResolveLastLink }); path = lookup.path; } catch (e) {} var ret = { isRoot: false, exists: false, error: 0, name: null, path: null, object: null, parentExists: false, parentPath: null, parentObject: null }; try { var lookup = FS.lookupPath(path, { parent: true }); ret.parentExists = true; ret.parentPath = lookup.path; ret.parentObject = lookup.node; ret.name = PATH.basename(path); lookup = FS.lookupPath(path, { follow: !dontResolveLastLink }); ret.exists = true; ret.path = lookup.path; ret.object = lookup.node; ret.name = lookup.node.name; ret.isRoot = lookup.path === "/"; } catch (e) { ret.error = e.errno; } return ret; }, createPath(parent, path, canRead, canWrite) { parent = typeof parent == "string" ? parent : FS.getPath(parent); var parts = path.split("/").reverse(); while (parts.length) { var part = parts.pop(); if (!part) continue; var current = PATH.join2(parent, part); try { FS.mkdir(current); } catch (e) { if (e.errno != 20) throw e; } parent = current; } return current; }, createFile(parent, name, properties, canRead, canWrite) { var path = PATH.join2(typeof parent == "string" ? parent : FS.getPath(parent), name); var mode = FS_getMode(canRead, canWrite); return FS.create(path, mode); }, createDataFile(parent, name, data, canRead, canWrite, canOwn) { var path = name; if (parent) { parent = typeof parent == "string" ? parent : FS.getPath(parent); path = name ? PATH.join2(parent, name) : parent; } var mode = FS_getMode(canRead, canWrite); var node = FS.create(path, mode); if (data) { if (typeof data == "string") { var arr = new Array(data.length); for (var i = 0, len = data.length; i < len; ++i) arr[i] = data.charCodeAt(i); data = arr; } // make sure we can write to the file FS.chmod(node, mode | 146); var stream = FS.open(node, 577); FS.write(stream, data, 0, data.length, 0, canOwn); FS.close(stream); FS.chmod(node, mode); } }, createDevice(parent, name, input, output) { var path = PATH.join2(typeof parent == "string" ? parent : FS.getPath(parent), name); var mode = FS_getMode(!!input, !!output); FS.createDevice.major ??= 64; var dev = FS.makedev(FS.createDevice.major++, 0); // Create a fake device that a set of stream ops to emulate // the old behavior. FS.registerDevice(dev, { open(stream) { stream.seekable = false; }, close(stream) { // flush any pending line data if (output?.buffer?.length) { output(10); } }, read(stream, buffer, offset, length, pos) { var bytesRead = 0; for (var i = 0; i < length; i++) { var result; try { result = input(); } catch (e) { throw new FS.ErrnoError(29); } if (result === undefined && bytesRead === 0) { throw new FS.ErrnoError(6); } if (result === null || result === undefined) break; bytesRead++; buffer[offset + i] = result; } if (bytesRead) { stream.node.atime = Date.now(); } return bytesRead; }, write(stream, buffer, offset, length, pos) { for (var i = 0; i < length; i++) { try { output(buffer[offset + i]); } catch (e) { throw new FS.ErrnoError(29); } } if (length) { stream.node.mtime = stream.node.ctime = Date.now(); } return i; } }); return FS.mkdev(path, mode, dev); }, forceLoadFile(obj) { if (obj.isDevice || obj.isFolder || obj.link || obj.contents) return true; if (globalThis.XMLHttpRequest) { abort("Lazy loading should have been performed (contents set) in createLazyFile, but it was not. Lazy loading only works in web workers. Use --embed-file or --preload-file in emcc on the main thread."); } else { // Command-line. try { obj.contents = readBinary(obj.url); } catch (e) { throw new FS.ErrnoError(29); } } }, createLazyFile(parent, name, url, canRead, canWrite) { // Lazy chunked Uint8Array (implements get and length from Uint8Array). // Actual getting is abstracted away for eventual reuse. class LazyUint8Array { lengthKnown=false; chunks=[]; // Loaded chunks. Index is the chunk number get(idx) { if (idx > this.length - 1 || idx < 0) { return undefined; } var chunkOffset = idx % this.chunkSize; var chunkNum = (idx / this.chunkSize) | 0; return this.getter(chunkNum)[chunkOffset]; } setDataGetter(getter) { this.getter = getter; } cacheLength() { // Find length var xhr = new XMLHttpRequest; xhr.open("HEAD", url, false); xhr.send(null); if (!(xhr.status >= 200 && xhr.status < 300 || xhr.status === 304)) abort("Couldn't load " + url + ". Status: " + xhr.status); var datalength = Number(xhr.getResponseHeader("Content-length")); var header; var hasByteServing = (header = xhr.getResponseHeader("Accept-Ranges")) && header === "bytes"; var usesGzip = (header = xhr.getResponseHeader("Content-Encoding")) && header === "gzip"; var chunkSize = 1024 * 1024; // Chunk size in bytes if (!hasByteServing) chunkSize = datalength; // Function to get a range from the remote URL. var doXHR = (from, to) => { if (from > to) abort("invalid range (" + from + ", " + to + ") or no bytes requested!"); if (to > datalength - 1) abort("only " + datalength + " bytes available! programmer error!"); // TODO: Use mozResponseArrayBuffer, responseStream, etc. if available. var xhr = new XMLHttpRequest; xhr.open("GET", url, false); if (datalength !== chunkSize) xhr.setRequestHeader("Range", "bytes=" + from + "-" + to); // Some hints to the browser that we want binary data. xhr.responseType = "arraybuffer"; if (xhr.overrideMimeType) { xhr.overrideMimeType("text/plain; charset=x-user-defined"); } xhr.send(null); if (!(xhr.status >= 200 && xhr.status < 300 || xhr.status === 304)) abort("Couldn't load " + url + ". Status: " + xhr.status); if (xhr.response !== undefined) { return new Uint8Array(/** @type{Array} */ (xhr.response || [])); } return intArrayFromString(xhr.responseText || "", true); }; var lazyArray = this; lazyArray.setDataGetter(chunkNum => { var start = chunkNum * chunkSize; var end = (chunkNum + 1) * chunkSize - 1; // including this byte end = Math.min(end, datalength - 1); // if datalength-1 is selected, this is the last block if (typeof lazyArray.chunks[chunkNum] == "undefined") { lazyArray.chunks[chunkNum] = doXHR(start, end); } if (typeof lazyArray.chunks[chunkNum] == "undefined") abort("doXHR failed!"); return lazyArray.chunks[chunkNum]; }); if (usesGzip || !datalength) { // if the server uses gzip or doesn't supply the length, we have to download the whole file to get the (uncompressed) length chunkSize = datalength = 1; // this will force getter(0)/doXHR do download the whole file datalength = this.getter(0).length; chunkSize = datalength; out("LazyFiles on gzip forces download of the whole file when length is accessed"); } this._length = datalength; this._chunkSize = chunkSize; this.lengthKnown = true; } get length() { if (!this.lengthKnown) { this.cacheLength(); } return this._length; } get chunkSize() { if (!this.lengthKnown) { this.cacheLength(); } return this._chunkSize; } } if (globalThis.XMLHttpRequest) { if (!ENVIRONMENT_IS_WORKER) abort("Cannot do synchronous binary XHRs outside webworkers in modern browsers. Use --embed-file or --preload-file in emcc"); var lazyArray = new LazyUint8Array; var properties = { isDevice: false, contents: lazyArray }; } else { var properties = { isDevice: false, url }; } var node = FS.createFile(parent, name, properties, canRead, canWrite); // This is a total hack, but I want to get this lazy file code out of the // core of MEMFS. If we want to keep this lazy file concept I feel it should // be its own thin LAZYFS proxying calls to MEMFS. if (properties.contents) { node.contents = properties.contents; } else if (properties.url) { node.contents = null; node.url = properties.url; } // Add a function that defers querying the file size until it is asked the first time. Object.defineProperties(node, { usedBytes: { get: function() { return this.contents.length; } } }); // override each stream op with one that tries to force load the lazy file first var stream_ops = {}; for (const [key, fn] of Object.entries(node.stream_ops)) { stream_ops[key] = (...args) => { FS.forceLoadFile(node); return fn(...args); }; } function writeChunks(stream, buffer, offset, length, position) { var contents = stream.node.contents; if (position >= contents.length) return 0; var size = Math.min(contents.length - position, length); if (contents.slice) { // normal array for (var i = 0; i < size; i++) { buffer[offset + i] = contents[position + i]; } } else { for (var i = 0; i < size; i++) { // LazyUint8Array from sync binary XHR buffer[offset + i] = contents.get(position + i); } } return size; } // use a custom read function stream_ops.read = (stream, buffer, offset, length, position) => { FS.forceLoadFile(node); return writeChunks(stream, buffer, offset, length, position); }; // use a custom mmap function stream_ops.mmap = (stream, length, position, prot, flags) => { FS.forceLoadFile(node); var ptr = mmapAlloc(length); if (!ptr) { throw new FS.ErrnoError(48); } writeChunks(stream, HEAP8, ptr, length, position); return { ptr, allocated: true }; }; node.stream_ops = stream_ops; return node; } }; /** * Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the * emscripten HEAP, returns a copy of that string as a Javascript String object. * * @param {number} ptr * @param {number=} maxBytesToRead - An optional length that specifies the * maximum number of bytes to read. You can omit this parameter to scan the * string until the first 0 byte. If maxBytesToRead is passed, and the string * at [ptr, ptr+maxBytesToReadr[ contains a null byte in the middle, then the * string will cut short at that byte index. * @param {boolean=} ignoreNul - If true, the function will not stop on a NUL character. * @return {string} */ var UTF8ToString = (ptr, maxBytesToRead, ignoreNul) => { if (!ptr) return ""; var end = findStringEnd(HEAPU8, ptr, maxBytesToRead, ignoreNul); return UTF8Decoder.decode(HEAPU8.subarray(ptr, end)); }; var SYSCALLS = { calculateAt(dirfd, path, allowEmpty) { if (PATH.isAbs(path)) { return path; } // relative path var dir; if (dirfd === -100) { dir = FS.cwd(); } else { var dirstream = SYSCALLS.getStreamFromFD(dirfd); dir = dirstream.path; } if (path.length == 0) { if (!allowEmpty) { throw new FS.ErrnoError(44); } return dir; } return dir + "/" + path; }, writeStat(buf, stat) { HEAPU32[((buf) >> 2)] = stat.dev; HEAPU32[(((buf) + (4)) >> 2)] = stat.mode; HEAPU32[(((buf) + (8)) >> 2)] = stat.nlink; HEAPU32[(((buf) + (12)) >> 2)] = stat.uid; HEAPU32[(((buf) + (16)) >> 2)] = stat.gid; HEAPU32[(((buf) + (20)) >> 2)] = stat.rdev; (tempI64 = [ stat.size >>> 0, (tempDouble = stat.size, (+(Math.abs(tempDouble))) >= 1 ? (tempDouble > 0 ? (+(Math.floor((tempDouble) / 4294967296))) >>> 0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble))) >>> 0)) / 4294967296))))) >>> 0) : 0) ], HEAP32[(((buf) + (24)) >> 2)] = tempI64[0], HEAP32[(((buf) + (28)) >> 2)] = tempI64[1]); HEAP32[(((buf) + (32)) >> 2)] = 4096; HEAP32[(((buf) + (36)) >> 2)] = stat.blocks; var atime = stat.atime.getTime(); var mtime = stat.mtime.getTime(); var ctime = stat.ctime.getTime(); (tempI64 = [ Math.floor(atime / 1e3) >>> 0, (tempDouble = Math.floor(atime / 1e3), (+(Math.abs(tempDouble))) >= 1 ? (tempDouble > 0 ? (+(Math.floor((tempDouble) / 4294967296))) >>> 0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble))) >>> 0)) / 4294967296))))) >>> 0) : 0) ], HEAP32[(((buf) + (40)) >> 2)] = tempI64[0], HEAP32[(((buf) + (44)) >> 2)] = tempI64[1]); HEAPU32[(((buf) + (48)) >> 2)] = (atime % 1e3) * 1e3 * 1e3; (tempI64 = [ Math.floor(mtime / 1e3) >>> 0, (tempDouble = Math.floor(mtime / 1e3), (+(Math.abs(tempDouble))) >= 1 ? (tempDouble > 0 ? (+(Math.floor((tempDouble) / 4294967296))) >>> 0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble))) >>> 0)) / 4294967296))))) >>> 0) : 0) ], HEAP32[(((buf) + (56)) >> 2)] = tempI64[0], HEAP32[(((buf) + (60)) >> 2)] = tempI64[1]); HEAPU32[(((buf) + (64)) >> 2)] = (mtime % 1e3) * 1e3 * 1e3; (tempI64 = [ Math.floor(ctime / 1e3) >>> 0, (tempDouble = Math.floor(ctime / 1e3), (+(Math.abs(tempDouble))) >= 1 ? (tempDouble > 0 ? (+(Math.floor((tempDouble) / 4294967296))) >>> 0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble))) >>> 0)) / 4294967296))))) >>> 0) : 0) ], HEAP32[(((buf) + (72)) >> 2)] = tempI64[0], HEAP32[(((buf) + (76)) >> 2)] = tempI64[1]); HEAPU32[(((buf) + (80)) >> 2)] = (ctime % 1e3) * 1e3 * 1e3; (tempI64 = [ stat.ino >>> 0, (tempDouble = stat.ino, (+(Math.abs(tempDouble))) >= 1 ? (tempDouble > 0 ? (+(Math.floor((tempDouble) / 4294967296))) >>> 0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble))) >>> 0)) / 4294967296))))) >>> 0) : 0) ], HEAP32[(((buf) + (88)) >> 2)] = tempI64[0], HEAP32[(((buf) + (92)) >> 2)] = tempI64[1]); return 0; }, writeStatFs(buf, stats) { HEAPU32[(((buf) + (4)) >> 2)] = stats.bsize; HEAPU32[(((buf) + (60)) >> 2)] = stats.bsize; (tempI64 = [ stats.blocks >>> 0, (tempDouble = stats.blocks, (+(Math.abs(tempDouble))) >= 1 ? (tempDouble > 0 ? (+(Math.floor((tempDouble) / 4294967296))) >>> 0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble))) >>> 0)) / 4294967296))))) >>> 0) : 0) ], HEAP32[(((buf) + (8)) >> 2)] = tempI64[0], HEAP32[(((buf) + (12)) >> 2)] = tempI64[1]); (tempI64 = [ stats.bfree >>> 0, (tempDouble = stats.bfree, (+(Math.abs(tempDouble))) >= 1 ? (tempDouble > 0 ? (+(Math.floor((tempDouble) / 4294967296))) >>> 0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble))) >>> 0)) / 4294967296))))) >>> 0) : 0) ], HEAP32[(((buf) + (16)) >> 2)] = tempI64[0], HEAP32[(((buf) + (20)) >> 2)] = tempI64[1]); (tempI64 = [ stats.bavail >>> 0, (tempDouble = stats.bavail, (+(Math.abs(tempDouble))) >= 1 ? (tempDouble > 0 ? (+(Math.floor((tempDouble) / 4294967296))) >>> 0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble))) >>> 0)) / 4294967296))))) >>> 0) : 0) ], HEAP32[(((buf) + (24)) >> 2)] = tempI64[0], HEAP32[(((buf) + (28)) >> 2)] = tempI64[1]); (tempI64 = [ stats.files >>> 0, (tempDouble = stats.files, (+(Math.abs(tempDouble))) >= 1 ? (tempDouble > 0 ? (+(Math.floor((tempDouble) / 4294967296))) >>> 0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble))) >>> 0)) / 4294967296))))) >>> 0) : 0) ], HEAP32[(((buf) + (32)) >> 2)] = tempI64[0], HEAP32[(((buf) + (36)) >> 2)] = tempI64[1]); (tempI64 = [ stats.ffree >>> 0, (tempDouble = stats.ffree, (+(Math.abs(tempDouble))) >= 1 ? (tempDouble > 0 ? (+(Math.floor((tempDouble) / 4294967296))) >>> 0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble))) >>> 0)) / 4294967296))))) >>> 0) : 0) ], HEAP32[(((buf) + (40)) >> 2)] = tempI64[0], HEAP32[(((buf) + (44)) >> 2)] = tempI64[1]); HEAPU32[(((buf) + (48)) >> 2)] = stats.fsid; HEAPU32[(((buf) + (64)) >> 2)] = stats.flags; // ST_NOSUID HEAPU32[(((buf) + (56)) >> 2)] = stats.namelen; }, doMsync(addr, stream, len, flags, offset) { if (!FS.isFile(stream.node.mode)) { throw new FS.ErrnoError(43); } if (flags & 2) { // MAP_PRIVATE calls need not to be synced back to underlying fs return 0; } var buffer = HEAPU8.slice(addr, addr + len); FS.msync(stream, buffer, offset, len, flags); }, getStreamFromFD(fd) { var stream = FS.getStreamChecked(fd); return stream; }, varargs: undefined, getStr(ptr) { var ret = UTF8ToString(ptr); return ret; } }; function ___syscall_dup(fd) { try { var old = SYSCALLS.getStreamFromFD(fd); return FS.dupStream(old).fd; } catch (e) { if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e; return -e.errno; } } function ___syscall_faccessat(dirfd, path, amode, flags) { try { path = SYSCALLS.getStr(path); path = SYSCALLS.calculateAt(dirfd, path); if (amode & ~7) { // need a valid mode return -28; } var lookup = FS.lookupPath(path, { follow: true }); var node = lookup.node; if (!node) { return -44; } var perms = ""; if (amode & 4) perms += "r"; if (amode & 2) perms += "w"; if (amode & 1) perms += "x"; if (perms && FS.nodePermissions(node, perms)) { return -2; } return 0; } catch (e) { if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e; return -e.errno; } } var syscallGetVarargI = () => { // the `+` prepended here is necessary to convince the JSCompiler that varargs is indeed a number. var ret = HEAP32[((+SYSCALLS.varargs) >> 2)]; SYSCALLS.varargs += 4; return ret; }; var syscallGetVarargP = syscallGetVarargI; function ___syscall_fcntl64(fd, cmd, varargs) { SYSCALLS.varargs = varargs; try { var stream = SYSCALLS.getStreamFromFD(fd); switch (cmd) { case 0: { var arg = syscallGetVarargI(); if (arg < 0) { return -28; } while (FS.streams[arg]) { arg++; } var newStream; newStream = FS.dupStream(stream, arg); return newStream.fd; } case 1: case 2: return 0; // FD_CLOEXEC makes no sense for a single process. case 3: return stream.flags; case 4: { var arg = syscallGetVarargI(); stream.flags |= arg; return 0; } case 12: { var arg = syscallGetVarargP(); var offset = 0; // We're always unlocked. HEAP16[(((arg) + (offset)) >> 1)] = 2; return 0; } case 13: case 14: // Pretend that the locking is successful. These are process-level locks, // and Emscripten programs are a single process. If we supported linking a // filesystem between programs, we'd need to do more here. // See https://github.com/emscripten-core/emscripten/issues/23697 return 0; } return -28; } catch (e) { if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e; return -e.errno; } } function ___syscall_fstat64(fd, buf) { try { return SYSCALLS.writeStat(buf, FS.fstat(fd)); } catch (e) { if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e; return -e.errno; } } var convertI32PairToI53Checked = (lo, hi) => ((hi + 2097152) >>> 0 < 4194305 - !!lo) ? (lo >>> 0) + hi * 4294967296 : NaN; function ___syscall_ftruncate64(fd, length_low, length_high) { var length = convertI32PairToI53Checked(length_low, length_high); try { if (isNaN(length)) return -61; FS.ftruncate(fd, length); return 0; } catch (e) { if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e; return -e.errno; } } function ___syscall_ioctl(fd, op, varargs) { SYSCALLS.varargs = varargs; try { var stream = SYSCALLS.getStreamFromFD(fd); switch (op) { case 21509: { if (!stream.tty) return -59; return 0; } case 21505: { if (!stream.tty) return -59; if (stream.tty.ops.ioctl_tcgets) { var termios = stream.tty.ops.ioctl_tcgets(stream); var argp = syscallGetVarargP(); HEAP32[((argp) >> 2)] = termios.c_iflag || 0; HEAP32[(((argp) + (4)) >> 2)] = termios.c_oflag || 0; HEAP32[(((argp) + (8)) >> 2)] = termios.c_cflag || 0; HEAP32[(((argp) + (12)) >> 2)] = termios.c_lflag || 0; for (var i = 0; i < 32; i++) { HEAP8[(argp + i) + (17)] = termios.c_cc[i] || 0; } return 0; } return 0; } case 21510: case 21511: case 21512: { if (!stream.tty) return -59; return 0; } case 21506: case 21507: case 21508: { if (!stream.tty) return -59; if (stream.tty.ops.ioctl_tcsets) { var argp = syscallGetVarargP(); var c_iflag = HEAP32[((argp) >> 2)]; var c_oflag = HEAP32[(((argp) + (4)) >> 2)]; var c_cflag = HEAP32[(((argp) + (8)) >> 2)]; var c_lflag = HEAP32[(((argp) + (12)) >> 2)]; var c_cc = []; for (var i = 0; i < 32; i++) { c_cc.push(HEAP8[(argp + i) + (17)]); } return stream.tty.ops.ioctl_tcsets(stream.tty, op, { c_iflag, c_oflag, c_cflag, c_lflag, c_cc }); } return 0; } case 21519: { if (!stream.tty) return -59; var argp = syscallGetVarargP(); HEAP32[((argp) >> 2)] = 0; return 0; } case 21520: { if (!stream.tty) return -59; return -28; } case 21537: case 21531: { var argp = syscallGetVarargP(); return FS.ioctl(stream, op, argp); } case 21523: { // TODO: in theory we should write to the winsize struct that gets // passed in, but for now musl doesn't read anything on it if (!stream.tty) return -59; if (stream.tty.ops.ioctl_tiocgwinsz) { var winsize = stream.tty.ops.ioctl_tiocgwinsz(stream.tty); var argp = syscallGetVarargP(); HEAP16[((argp) >> 1)] = winsize[0]; HEAP16[(((argp) + (2)) >> 1)] = winsize[1]; } return 0; } case 21524: { // TODO: technically, this ioctl call should change the window size. // but, since emscripten doesn't have any concept of a terminal window // yet, we'll just silently throw it away as we do TIOCGWINSZ if (!stream.tty) return -59; return 0; } case 21515: { if (!stream.tty) return -59; return 0; } default: return -28; } } catch (e) { if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e; return -e.errno; } } function ___syscall_lstat64(path, buf) { try { path = SYSCALLS.getStr(path); return SYSCALLS.writeStat(buf, FS.lstat(path)); } catch (e) { if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e; return -e.errno; } } function ___syscall_newfstatat(dirfd, path, buf, flags) { try { path = SYSCALLS.getStr(path); var nofollow = flags & 256; var allowEmpty = flags & 4096; flags = flags & (~6400); path = SYSCALLS.calculateAt(dirfd, path, allowEmpty); return SYSCALLS.writeStat(buf, nofollow ? FS.lstat(path) : FS.stat(path)); } catch (e) { if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e; return -e.errno; } } function ___syscall_openat(dirfd, path, flags, varargs) { SYSCALLS.varargs = varargs; try { path = SYSCALLS.getStr(path); path = SYSCALLS.calculateAt(dirfd, path); var mode = varargs ? syscallGetVarargI() : 0; return FS.open(path, flags, mode).fd; } catch (e) { if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e; return -e.errno; } } function ___syscall_stat64(path, buf) { try { path = SYSCALLS.getStr(path); return SYSCALLS.writeStat(buf, FS.stat(path)); } catch (e) { if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e; return -e.errno; } } var __abort_js = () => abort(""); var __embind_register_bigint = (primitiveType, name, size, minRange, maxRange) => {}; var AsciiToString = ptr => { var str = ""; while (1) { var ch = HEAPU8[ptr++]; if (!ch) return str; str += String.fromCharCode(ch); } }; var awaitingDependencies = {}; var registeredTypes = {}; var typeDependencies = {}; var BindingError = class BindingError extends Error { constructor(message) { super(message); this.name = "BindingError"; } }; var throwBindingError = message => { throw new BindingError(message); }; /** @param {Object=} options */ function sharedRegisterType(rawType, registeredInstance, options = {}) { var name = registeredInstance.name; if (!rawType) { throwBindingError(`type "${name}" must have a positive integer typeid pointer`); } if (registeredTypes.hasOwnProperty(rawType)) { if (options.ignoreDuplicateRegistrations) { return; } else { throwBindingError(`Cannot register type '${name}' twice`); } } registeredTypes[rawType] = registeredInstance; delete typeDependencies[rawType]; if (awaitingDependencies.hasOwnProperty(rawType)) { var callbacks = awaitingDependencies[rawType]; delete awaitingDependencies[rawType]; callbacks.forEach(cb => cb()); } } /** @param {Object=} options */ function registerType(rawType, registeredInstance, options = {}) { return sharedRegisterType(rawType, registeredInstance, options); } /** @suppress {globalThis} */ var __embind_register_bool = (rawType, name, trueValue, falseValue) => { name = AsciiToString(name); registerType(rawType, { name, fromWireType: function(wt) { // ambiguous emscripten ABI: sometimes return values are // true or false, and sometimes integers (0 or 1) return !!wt; }, toWireType: function(destructors, o) { return o ? trueValue : falseValue; }, readValueFromPointer: function(pointer) { return this.fromWireType(HEAPU8[pointer]); }, destructorFunction: null }); }; var emval_freelist = []; var emval_handles = [ 0, 1, , 1, null, 1, true, 1, false, 1 ]; var __emval_decref = handle => { if (handle > 9 && 0 === --emval_handles[handle + 1]) { emval_handles[handle] = undefined; emval_freelist.push(handle); } }; var Emval = { toValue: handle => { if (!handle) { throwBindingError(`Cannot use deleted val. handle = ${handle}`); } return emval_handles[handle]; }, toHandle: value => { switch (value) { case undefined: return 2; case null: return 4; case true: return 6; case false: return 8; default: { const handle = emval_freelist.pop() || emval_handles.length; emval_handles[handle] = value; emval_handles[handle + 1] = 1; return handle; } } } }; /** @suppress {globalThis} */ function readPointer(pointer) { return this.fromWireType(HEAPU32[((pointer) >> 2)]); } var EmValType = { name: "emscripten::val", fromWireType: handle => { var rv = Emval.toValue(handle); __emval_decref(handle); return rv; }, toWireType: (destructors, value) => Emval.toHandle(value), readValueFromPointer: readPointer, destructorFunction: null }; var __embind_register_emval = rawType => registerType(rawType, EmValType); var floatReadValueFromPointer = (name, width) => { switch (width) { case 4: return function(pointer) { return this.fromWireType(HEAPF32[((pointer) >> 2)]); }; case 8: return function(pointer) { return this.fromWireType(HEAPF64[((pointer) >> 3)]); }; default: throw new TypeError(`invalid float width (${width}): ${name}`); } }; var __embind_register_float = (rawType, name, size) => { name = AsciiToString(name); registerType(rawType, { name, fromWireType: value => value, toWireType: (destructors, value) => value, readValueFromPointer: floatReadValueFromPointer(name, size), destructorFunction: null }); }; var integerReadValueFromPointer = (name, width, signed) => { // integers are quite common, so generate very specialized functions switch (width) { case 1: return signed ? pointer => HEAP8[pointer] : pointer => HEAPU8[pointer]; case 2: return signed ? pointer => HEAP16[((pointer) >> 1)] : pointer => HEAPU16[((pointer) >> 1)]; case 4: return signed ? pointer => HEAP32[((pointer) >> 2)] : pointer => HEAPU32[((pointer) >> 2)]; default: throw new TypeError(`invalid integer width (${width}): ${name}`); } }; /** @suppress {globalThis} */ var __embind_register_integer = (primitiveType, name, size, minRange, maxRange) => { name = AsciiToString(name); const isUnsignedType = minRange === 0; let fromWireType = value => value; if (isUnsignedType) { var bitshift = 32 - 8 * size; fromWireType = value => (value << bitshift) >>> bitshift; maxRange = fromWireType(maxRange); } registerType(primitiveType, { name, fromWireType, toWireType: (destructors, value) => value, readValueFromPointer: integerReadValueFromPointer(name, size, minRange !== 0), destructorFunction: null }); }; var __embind_register_memory_view = (rawType, dataTypeIndex, name) => { var typeMapping = [ Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array ]; var TA = typeMapping[dataTypeIndex]; function decodeMemoryView(handle) { var size = HEAPU32[((handle) >> 2)]; var data = HEAPU32[(((handle) + (4)) >> 2)]; return new TA(HEAP8.buffer, data, size); } name = AsciiToString(name); registerType(rawType, { name, fromWireType: decodeMemoryView, readValueFromPointer: decodeMemoryView }, { ignoreDuplicateRegistrations: true }); }; var stringToUTF8 = (str, outPtr, maxBytesToWrite) => stringToUTF8Array(str, HEAPU8, outPtr, maxBytesToWrite); var __embind_register_std_string = (rawType, name) => { name = AsciiToString(name); var stdStringIsUTF8 = true; registerType(rawType, { name, // For some method names we use string keys here since they are part of // the public/external API and/or used by the runtime-generated code. fromWireType(value) { var length = HEAPU32[((value) >> 2)]; var payload = value + 4; var str; if (stdStringIsUTF8) { str = UTF8ToString(payload, length, true); } else { str = ""; for (var i = 0; i < length; ++i) { str += String.fromCharCode(HEAPU8[payload + i]); } } _free(value); return str; }, toWireType(destructors, value) { if (value instanceof ArrayBuffer) { value = new Uint8Array(value); } var length; var valueIsOfTypeString = (typeof value == "string"); // We accept `string` or array views with single byte elements if (!(valueIsOfTypeString || (ArrayBuffer.isView(value) && value.BYTES_PER_ELEMENT == 1))) { throwBindingError("Cannot pass non-string to std::string"); } if (stdStringIsUTF8 && valueIsOfTypeString) { length = lengthBytesUTF8(value); } else { length = value.length; } // assumes POINTER_SIZE alignment var base = _malloc(4 + length + 1); var ptr = base + 4; HEAPU32[((base) >> 2)] = length; if (valueIsOfTypeString) { if (stdStringIsUTF8) { stringToUTF8(value, ptr, length + 1); } else { for (var i = 0; i < length; ++i) { var charCode = value.charCodeAt(i); if (charCode > 255) { _free(base); throwBindingError("String has UTF-16 code units that do not fit in 8 bits"); } HEAPU8[ptr + i] = charCode; } } } else { HEAPU8.set(value, ptr); } if (destructors !== null) { destructors.push(_free, base); } return base; }, readValueFromPointer: readPointer, destructorFunction(ptr) { _free(ptr); } }); }; var UTF16Decoder = new TextDecoder("utf-16le"); var UTF16ToString = (ptr, maxBytesToRead, ignoreNul) => { var idx = ((ptr) >> 1); var endIdx = findStringEnd(HEAPU16, idx, maxBytesToRead / 2, ignoreNul); return UTF16Decoder.decode(HEAPU16.subarray(idx, endIdx)); }; var stringToUTF16 = (str, outPtr, maxBytesToWrite) => { // Backwards compatibility: if max bytes is not specified, assume unsafe unbounded write is allowed. maxBytesToWrite ??= 2147483647; if (maxBytesToWrite < 2) return 0; maxBytesToWrite -= 2; // Null terminator. var startPtr = outPtr; var numCharsToWrite = (maxBytesToWrite < str.length * 2) ? (maxBytesToWrite / 2) : str.length; for (var i = 0; i < numCharsToWrite; ++i) { // charCodeAt returns a UTF-16 encoded code unit, so it can be directly written to the HEAP. var codeUnit = str.charCodeAt(i); // possibly a lead surrogate HEAP16[((outPtr) >> 1)] = codeUnit; outPtr += 2; } // Null-terminate the pointer to the HEAP. HEAP16[((outPtr) >> 1)] = 0; return outPtr - startPtr; }; var lengthBytesUTF16 = str => str.length * 2; var UTF32ToString = (ptr, maxBytesToRead, ignoreNul) => { var str = ""; var startIdx = ((ptr) >> 2); // If maxBytesToRead is not passed explicitly, it will be undefined, and this // will always evaluate to true. This saves on code size. for (var i = 0; !(i >= maxBytesToRead / 4); i++) { var utf32 = HEAPU32[startIdx + i]; if (!utf32 && !ignoreNul) break; str += String.fromCodePoint(utf32); } return str; }; var stringToUTF32 = (str, outPtr, maxBytesToWrite) => { // Backwards compatibility: if max bytes is not specified, assume unsafe unbounded write is allowed. maxBytesToWrite ??= 2147483647; if (maxBytesToWrite < 4) return 0; var startPtr = outPtr; var endPtr = startPtr + maxBytesToWrite - 4; for (var i = 0; i < str.length; ++i) { var codePoint = str.codePointAt(i); // Gotcha: if codePoint is over 0xFFFF, it is represented as a surrogate pair in UTF-16. // We need to manually skip over the second code unit for correct iteration. if (codePoint > 65535) { i++; } HEAP32[((outPtr) >> 2)] = codePoint; outPtr += 4; if (outPtr + 4 > endPtr) break; } // Null-terminate the pointer to the HEAP. HEAP32[((outPtr) >> 2)] = 0; return outPtr - startPtr; }; var lengthBytesUTF32 = str => { var len = 0; for (var i = 0; i < str.length; ++i) { var codePoint = str.codePointAt(i); // Gotcha: if codePoint is over 0xFFFF, it is represented as a surrogate pair in UTF-16. // We need to manually skip over the second code unit for correct iteration. if (codePoint > 65535) { i++; } len += 4; } return len; }; var __embind_register_std_wstring = (rawType, charSize, name) => { name = AsciiToString(name); var decodeString, encodeString, lengthBytesUTF; if (charSize === 2) { decodeString = UTF16ToString; encodeString = stringToUTF16; lengthBytesUTF = lengthBytesUTF16; } else { decodeString = UTF32ToString; encodeString = stringToUTF32; lengthBytesUTF = lengthBytesUTF32; } registerType(rawType, { name, fromWireType: value => { // Code mostly taken from _embind_register_std_string fromWireType var length = HEAPU32[((value) >> 2)]; var str = decodeString(value + 4, length * charSize, true); _free(value); return str; }, toWireType: (destructors, value) => { if (!(typeof value == "string")) { throwBindingError(`Cannot pass non-string to C++ string type ${name}`); } // assumes POINTER_SIZE alignment var length = lengthBytesUTF(value); var ptr = _malloc(4 + length + charSize); HEAPU32[((ptr) >> 2)] = length / charSize; encodeString(value, ptr + 4, length + charSize); if (destructors !== null) { destructors.push(_free, ptr); } return ptr; }, readValueFromPointer: readPointer, destructorFunction(ptr) { _free(ptr); } }); }; var __embind_register_void = (rawType, name) => { name = AsciiToString(name); registerType(rawType, { isVoid: true, // void return values can be optimized out sometimes name, fromWireType: () => undefined, // TODO: assert if anything else is given? toWireType: (destructors, o) => undefined }); }; var emval_methodCallers = []; var emval_addMethodCaller = caller => { var id = emval_methodCallers.length; emval_methodCallers.push(caller); return id; }; var getTypeName = type => { var ptr = ___getTypeName(type); var rv = AsciiToString(ptr); _free(ptr); return rv; }; var requireRegisteredType = (rawType, humanName) => { var impl = registeredTypes[rawType]; if (undefined === impl) { throwBindingError(`${humanName} has unknown type ${getTypeName(rawType)}`); } return impl; }; var emval_lookupTypes = (argCount, argTypes) => { var a = new Array(argCount); for (var i = 0; i < argCount; ++i) { a[i] = requireRegisteredType(HEAPU32[(((argTypes) + (i * 4)) >> 2)], `parameter ${i}`); } return a; }; var createNamedFunction = (name, func) => Object.defineProperty(func, "name", { value: name }); var emval_returnValue = (toReturnWire, destructorsRef, handle) => { var destructors = []; var result = toReturnWire(destructors, handle); if (destructors.length) { // void, primitives and any other types w/o destructors don't need to allocate a handle HEAPU32[((destructorsRef) >> 2)] = Emval.toHandle(destructors); } return result; }; var emval_symbols = {}; var getStringOrSymbol = address => { var symbol = emval_symbols[address]; if (symbol === undefined) { return AsciiToString(address); } return symbol; }; var __emval_create_invoker = (argCount, argTypesPtr, kind) => { var GenericWireTypeSize = 8; var [retType, ...argTypes] = emval_lookupTypes(argCount, argTypesPtr); var toReturnWire = retType.toWireType.bind(retType); var argFromPtr = argTypes.map(type => type.readValueFromPointer.bind(type)); argCount--; // remove the extracted return type var argN = new Array(argCount); var invokerFunction = (handle, methodName, destructorsRef, args) => { var offset = 0; for (var i = 0; i < argCount; ++i) { argN[i] = argFromPtr[i](args + offset); offset += GenericWireTypeSize; } var rv; switch (kind) { case 0: rv = Emval.toValue(handle).apply(null, argN); break; case 2: rv = Reflect.construct(Emval.toValue(handle), argN); break; case 3: // no-op, just return the argument rv = argN[0]; break; case 1: rv = Emval.toValue(handle)[getStringOrSymbol(methodName)](...argN); break; } return emval_returnValue(toReturnWire, destructorsRef, rv); }; var functionName = `methodCaller<(${argTypes.map(t => t.name)}) => ${retType.name}>`; return emval_addMethodCaller(createNamedFunction(functionName, invokerFunction)); }; var __emval_get_global = name => { if (!name) { return Emval.toHandle(globalThis); } name = getStringOrSymbol(name); return Emval.toHandle(globalThis[name]); }; var __emval_get_property = (handle, key) => { handle = Emval.toValue(handle); key = Emval.toValue(key); return Emval.toHandle(handle[key]); }; var __emval_incref = handle => { if (handle > 9) { emval_handles[handle + 1] += 1; } }; var __emval_instanceof = (object, constructor) => { object = Emval.toValue(object); constructor = Emval.toValue(constructor); return object instanceof constructor; }; var __emval_invoke = (caller, handle, methodName, destructorsRef, args) => emval_methodCallers[caller](handle, methodName, destructorsRef, args); var __emval_new_cstring = v => Emval.toHandle(getStringOrSymbol(v)); var runDestructors = destructors => { while (destructors.length) { var ptr = destructors.pop(); var del = destructors.pop(); del(ptr); } }; var __emval_run_destructors = handle => { var destructors = Emval.toValue(handle); runDestructors(destructors); __emval_decref(handle); }; var __emval_set_property = (handle, key, value) => { handle = Emval.toValue(handle); key = Emval.toValue(key); value = Emval.toValue(value); handle[key] = value; }; var __emval_typeof = handle => { handle = Emval.toValue(handle); return Emval.toHandle(typeof handle); }; function __gmtime_js(time_low, time_high, tmPtr) { var time = convertI32PairToI53Checked(time_low, time_high); var date = new Date(time * 1e3); HEAP32[((tmPtr) >> 2)] = date.getUTCSeconds(); HEAP32[(((tmPtr) + (4)) >> 2)] = date.getUTCMinutes(); HEAP32[(((tmPtr) + (8)) >> 2)] = date.getUTCHours(); HEAP32[(((tmPtr) + (12)) >> 2)] = date.getUTCDate(); HEAP32[(((tmPtr) + (16)) >> 2)] = date.getUTCMonth(); HEAP32[(((tmPtr) + (20)) >> 2)] = date.getUTCFullYear() - 1900; HEAP32[(((tmPtr) + (24)) >> 2)] = date.getUTCDay(); var start = Date.UTC(date.getUTCFullYear(), 0, 1, 0, 0, 0, 0); var yday = ((date.getTime() - start) / (1e3 * 60 * 60 * 24)) | 0; HEAP32[(((tmPtr) + (28)) >> 2)] = yday; } var isLeapYear = year => year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0); var MONTH_DAYS_LEAP_CUMULATIVE = [ 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 ]; var MONTH_DAYS_REGULAR_CUMULATIVE = [ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 ]; var ydayFromDate = date => { var leap = isLeapYear(date.getFullYear()); var monthDaysCumulative = (leap ? MONTH_DAYS_LEAP_CUMULATIVE : MONTH_DAYS_REGULAR_CUMULATIVE); var yday = monthDaysCumulative[date.getMonth()] + date.getDate() - 1; // -1 since it's days since Jan 1 return yday; }; function __localtime_js(time_low, time_high, tmPtr) { var time = convertI32PairToI53Checked(time_low, time_high); var date = new Date(time * 1e3); HEAP32[((tmPtr) >> 2)] = date.getSeconds(); HEAP32[(((tmPtr) + (4)) >> 2)] = date.getMinutes(); HEAP32[(((tmPtr) + (8)) >> 2)] = date.getHours(); HEAP32[(((tmPtr) + (12)) >> 2)] = date.getDate(); HEAP32[(((tmPtr) + (16)) >> 2)] = date.getMonth(); HEAP32[(((tmPtr) + (20)) >> 2)] = date.getFullYear() - 1900; HEAP32[(((tmPtr) + (24)) >> 2)] = date.getDay(); var yday = ydayFromDate(date) | 0; HEAP32[(((tmPtr) + (28)) >> 2)] = yday; HEAP32[(((tmPtr) + (36)) >> 2)] = -(date.getTimezoneOffset() * 60); // Attention: DST is in December in South, and some regions don't have DST at all. var start = new Date(date.getFullYear(), 0, 1); var summerOffset = new Date(date.getFullYear(), 6, 1).getTimezoneOffset(); var winterOffset = start.getTimezoneOffset(); var dst = (summerOffset != winterOffset && date.getTimezoneOffset() == Math.min(winterOffset, summerOffset)) | 0; HEAP32[(((tmPtr) + (32)) >> 2)] = dst; } var setTempRet0 = val => __emscripten_tempret_set(val); var __mktime_js = function(tmPtr) { var ret = (() => { var date = new Date(HEAP32[(((tmPtr) + (20)) >> 2)] + 1900, HEAP32[(((tmPtr) + (16)) >> 2)], HEAP32[(((tmPtr) + (12)) >> 2)], HEAP32[(((tmPtr) + (8)) >> 2)], HEAP32[(((tmPtr) + (4)) >> 2)], HEAP32[((tmPtr) >> 2)], 0); // There's an ambiguous hour when the time goes back; the tm_isdst field is // used to disambiguate it. Date() basically guesses, so we fix it up if it // guessed wrong, or fill in tm_isdst with the guess if it's -1. var dst = HEAP32[(((tmPtr) + (32)) >> 2)]; var guessedOffset = date.getTimezoneOffset(); var start = new Date(date.getFullYear(), 0, 1); var summerOffset = new Date(date.getFullYear(), 6, 1).getTimezoneOffset(); var winterOffset = start.getTimezoneOffset(); var dstOffset = Math.min(winterOffset, summerOffset); // DST is in December in South if (dst < 0) { // Attention: some regions don't have DST at all. HEAP32[(((tmPtr) + (32)) >> 2)] = Number(summerOffset != winterOffset && dstOffset == guessedOffset); } else if ((dst > 0) != (dstOffset == guessedOffset)) { var nonDstOffset = Math.max(winterOffset, summerOffset); var trueOffset = dst > 0 ? dstOffset : nonDstOffset; // Don't try setMinutes(date.getMinutes() + ...) -- it's messed up. date.setTime(date.getTime() + (trueOffset - guessedOffset) * 6e4); } HEAP32[(((tmPtr) + (24)) >> 2)] = date.getDay(); var yday = ydayFromDate(date) | 0; HEAP32[(((tmPtr) + (28)) >> 2)] = yday; // To match expected behavior, update fields from date HEAP32[((tmPtr) >> 2)] = date.getSeconds(); HEAP32[(((tmPtr) + (4)) >> 2)] = date.getMinutes(); HEAP32[(((tmPtr) + (8)) >> 2)] = date.getHours(); HEAP32[(((tmPtr) + (12)) >> 2)] = date.getDate(); HEAP32[(((tmPtr) + (16)) >> 2)] = date.getMonth(); HEAP32[(((tmPtr) + (20)) >> 2)] = date.getYear(); var timeMs = date.getTime(); if (isNaN(timeMs)) { return -1; } // Return time in microseconds return timeMs / 1e3; })(); return (setTempRet0((tempDouble = ret, (+(Math.abs(tempDouble))) >= 1 ? (tempDouble > 0 ? (+(Math.floor((tempDouble) / 4294967296))) >>> 0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble))) >>> 0)) / 4294967296))))) >>> 0) : 0)), ret >>> 0); }; function __mmap_js(len, prot, flags, fd, offset_low, offset_high, allocated, addr) { var offset = convertI32PairToI53Checked(offset_low, offset_high); try { var stream = SYSCALLS.getStreamFromFD(fd); var res = FS.mmap(stream, len, offset, prot, flags); var ptr = res.ptr; HEAP32[((allocated) >> 2)] = res.allocated; HEAPU32[((addr) >> 2)] = ptr; return 0; } catch (e) { if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e; return -e.errno; } } function __munmap_js(addr, len, prot, flags, fd, offset_low, offset_high) { var offset = convertI32PairToI53Checked(offset_low, offset_high); try { var stream = SYSCALLS.getStreamFromFD(fd); if (prot & 2) { SYSCALLS.doMsync(addr, stream, len, flags, offset); } } catch (e) { if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e; return -e.errno; } } var __tzset_js = (timezone, daylight, std_name, dst_name) => { // TODO: Use (malleable) environment variables instead of system settings. 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(); // Local standard timezone offset. Local standard time is not adjusted for // daylight savings. This code uses the fact that getTimezoneOffset returns // a greater value during Standard Time versus Daylight Saving Time (DST). // Thus it determines the expected output during Standard Time, and it // compares whether the output of the given date the same (Standard) or less // (DST). var stdTimezoneOffset = Math.max(winterOffset, summerOffset); // timezone is specified as seconds west of UTC ("The external variable // `timezone` shall be set to the difference, in seconds, between // Coordinated Universal Time (UTC) and local standard time."), the same // as returned by stdTimezoneOffset. // See http://pubs.opengroup.org/onlinepubs/009695399/functions/tzset.html HEAPU32[((timezone) >> 2)] = stdTimezoneOffset * 60; HEAP32[((daylight) >> 2)] = Number(winterOffset != summerOffset); var extractZone = timezoneOffset => { // Why inverse sign? // Read here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getTimezoneOffset 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) { // Northern hemisphere stringToUTF8(winterName, std_name, 17); stringToUTF8(summerName, dst_name, 17); } else { stringToUTF8(winterName, dst_name, 17); stringToUTF8(summerName, std_name, 17); } }; var _emscripten_get_now = () => performance.now(); var _emscripten_date_now = () => Date.now(); var nowIsMonotonic = 1; var checkWasiClock = clock_id => clock_id >= 0 && clock_id <= 3; function _clock_time_get(clk_id, ignored_precision_low, ignored_precision_high, ptime) { var ignored_precision = convertI32PairToI53Checked(ignored_precision_low, ignored_precision_high); if (!checkWasiClock(clk_id)) { return 28; } var now; // all wasi clocks but realtime are monotonic if (clk_id === 0) { now = _emscripten_date_now(); } else if (nowIsMonotonic) { now = _emscripten_get_now(); } else { return 52; } // "now" is in ms, and wasi times are in ns. var nsec = Math.round(now * 1e3 * 1e3); (tempI64 = [ nsec >>> 0, (tempDouble = nsec, (+(Math.abs(tempDouble))) >= 1 ? (tempDouble > 0 ? (+(Math.floor((tempDouble) / 4294967296))) >>> 0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble))) >>> 0)) / 4294967296))))) >>> 0) : 0) ], HEAP32[((ptime) >> 2)] = tempI64[0], HEAP32[(((ptime) + (4)) >> 2)] = tempI64[1]); return 0; } var readEmAsmArgsArray = []; var readEmAsmArgs = (sigPtr, buf) => { readEmAsmArgsArray.length = 0; var ch; // Most arguments are i32s, so shift the buffer pointer so it is a plain // index into HEAP32. while (ch = HEAPU8[sigPtr++]) { // Floats are always passed as doubles, so all types except for 'i' // are 8 bytes and require alignment. var wide = (ch != 105); wide &= (ch != 112); buf += wide && (buf % 8) ? 4 : 0; readEmAsmArgsArray.push(// Special case for pointers under wasm64 or CAN_ADDRESS_2GB mode. ch == 112 ? HEAPU32[((buf) >> 2)] : ch == 105 ? HEAP32[((buf) >> 2)] : HEAPF64[((buf) >> 3)]); buf += wide ? 8 : 4; } return readEmAsmArgsArray; }; var runEmAsmFunction = (code, sigPtr, argbuf) => { var args = readEmAsmArgs(sigPtr, argbuf); return ASM_CONSTS[code](...args); }; var _emscripten_asm_const_int = (code, sigPtr, argbuf) => runEmAsmFunction(code, sigPtr, argbuf); var _emscripten_asm_const_ptr = (code, sigPtr, argbuf) => runEmAsmFunction(code, sigPtr, argbuf); var _emscripten_errn = (str, len) => err(UTF8ToString(str, len)); var getHeapMax = () => // Stay one Wasm page short of 4GB: while e.g. Chrome is able to allocate // full 4GB Wasm memories, the size will wrap back to 0 bytes in Wasm side // for any code that deals with heap sizes, which would require special // casing all heap size related code to treat 0 specially. 2147483648; var _emscripten_get_heap_max = () => getHeapMax(); var _emscripten_has_asyncify = () => 0; var _emscripten_outn = (str, len) => out(UTF8ToString(str, len)); var UNWIND_CACHE = {}; var stringToNewUTF8 = str => { var size = lengthBytesUTF8(str) + 1; var ret = _malloc(size); if (ret) stringToUTF8(str, ret, size); return ret; }; /** @returns {number} */ var convertFrameToPC = frame => { var match; if (match = /\bwasm-function\[\d+\]:(0x[0-9a-f]+)/.exec(frame)) { // Wasm engines give the binary offset directly, so we use that as return address return +match[1]; } else if (match = /:(\d+):\d+(?:\)|$)/.exec(frame)) { // If we are in js, we can use the js line number as the "return address". // This should work for wasm2js. We tag the high bit to distinguish this // from wasm addresses. return 2147483648 | +match[1]; } // return 0 if we can't find any return 0; }; var saveInUnwindCache = callstack => { for (var line of callstack) { var pc = convertFrameToPC(line); if (pc) { UNWIND_CACHE[pc] = line; } } }; var jsStackTrace = () => (new Error).stack.toString(); var _emscripten_stack_snapshot = () => { var callstack = jsStackTrace().split("\n"); if (callstack[0] == "Error") { callstack.shift(); } saveInUnwindCache(callstack); // Caches the stack snapshot so that emscripten_stack_unwind_buffer() can // unwind from this spot. UNWIND_CACHE.last_addr = convertFrameToPC(callstack[3]); UNWIND_CACHE.last_stack = callstack; return UNWIND_CACHE.last_addr; }; var _emscripten_pc_get_function = pc => { var frame = UNWIND_CACHE[pc]; if (!frame) return 0; var name; var match; // First try to match foo.wasm.sym files explcitly. e.g. // at test_return_address.wasm.main (wasm://wasm/test_return_address.wasm-0012cc2a:wasm-function[26]:0x9f3 // Then match JS symbols which don't include that module name: // at invokeEntryPoint (.../test_return_address.js:1500:42) // Finally match firefox format: // Object._main@http://server.com:4324:12' if (match = /^\s+at .*\.wasm\.(.*) \(.*\)$/.exec(frame)) { name = match[1]; } else if (match = /^\s+at (.*) \(.*\)$/.exec(frame)) { name = match[1]; } else if (match = /^(.+?)@/.exec(frame)) { name = match[1]; } else { return 0; } _free(_emscripten_pc_get_function.ret ?? 0); _emscripten_pc_get_function.ret = stringToNewUTF8(name); return _emscripten_pc_get_function.ret; }; var growMemory = size => { var oldHeapSize = wasmMemory.buffer.byteLength; var pages = ((size - oldHeapSize + 65535) / 65536) | 0; try { // round size grow request up to wasm page size (fixed 64KB per spec) wasmMemory.grow(pages); // .grow() takes a delta compared to the previous size updateMemoryViews(); return 1; } catch (e) {} }; var _emscripten_resize_heap = requestedSize => { var oldSize = HEAPU8.length; // With CAN_ADDRESS_2GB or MEMORY64, pointers are already unsigned. requestedSize >>>= 0; // With multithreaded builds, races can happen (another thread might increase the size // in between), so return a failure, and let the caller retry. // Memory resize rules: // 1. Always increase heap size to at least the requested size, rounded up // to next page multiple. // 2a. If MEMORY_GROWTH_LINEAR_STEP == -1, excessively resize the heap // geometrically: increase the heap size according to // MEMORY_GROWTH_GEOMETRIC_STEP factor (default +20%), At most // overreserve by MEMORY_GROWTH_GEOMETRIC_CAP bytes (default 96MB). // 2b. If MEMORY_GROWTH_LINEAR_STEP != -1, excessively resize the heap // linearly: increase the heap size by at least // MEMORY_GROWTH_LINEAR_STEP bytes. // 3. Max size for the heap is capped at 2048MB-WASM_PAGE_SIZE, or by // MAXIMUM_MEMORY, or by ASAN limit, depending on which is smallest // 4. If we were unable to allocate as much memory, it may be due to // over-eager decision to excessively reserve due to (3) above. // Hence if an allocation fails, cut down on the amount of excess // growth, in an attempt to succeed to perform a smaller allocation. // A limit is set for how much we can grow. We should not exceed that // (the wasm binary specifies it, so if we tried, we'd fail anyhow). var maxHeapSize = getHeapMax(); if (requestedSize > maxHeapSize) { return false; } // Loop through potential heap size increases. If we attempt a too eager // reservation that fails, cut down on the attempted size and reserve a // smaller bump instead. (max 3 times, chosen somewhat arbitrarily) for (var cutDown = 1; cutDown <= 4; cutDown *= 2) { var overGrownHeapSize = oldSize * (1 + .2 / cutDown); // ensure geometric growth // but limit overreserving (default to capping at +96MB overgrowth at most) 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; }; var _emscripten_stack_unwind_buffer = (addr, buffer, count) => { var stack; if (UNWIND_CACHE.last_addr == addr) { stack = UNWIND_CACHE.last_stack; } else { stack = jsStackTrace().split("\n"); if (stack[0] == "Error") { stack.shift(); } saveInUnwindCache(stack); } var offset = 3; while (stack[offset] && convertFrameToPC(stack[offset]) != addr) { ++offset; } for (var i = 0; i < count && stack[i + offset]; ++i) { HEAP32[(((buffer) + (i * 4)) >> 2)] = convertFrameToPC(stack[i + offset]); } return i; }; var GLctx; var webgl_enable_ANGLE_instanced_arrays = ctx => { // Extension available in WebGL 1 from Firefox 26 and Google Chrome 30 onwards. Core feature in WebGL 2. var ext = ctx.getExtension("ANGLE_instanced_arrays"); // Because this extension is a core function in WebGL 2, assign the extension entry points in place of // where the core functions will reside in WebGL 2. This way the calling code can call these without // having to dynamically branch depending if running against WebGL 1 or WebGL 2. if (ext) { ctx["vertexAttribDivisor"] = (index, divisor) => ext["vertexAttribDivisorANGLE"](index, divisor); ctx["drawArraysInstanced"] = (mode, first, count, primcount) => ext["drawArraysInstancedANGLE"](mode, first, count, primcount); ctx["drawElementsInstanced"] = (mode, count, type, indices, primcount) => ext["drawElementsInstancedANGLE"](mode, count, type, indices, primcount); return 1; } }; var webgl_enable_OES_vertex_array_object = ctx => { // Extension available in WebGL 1 from Firefox 25 and WebKit 536.28/desktop Safari 6.0.3 onwards. Core feature in WebGL 2. var ext = ctx.getExtension("OES_vertex_array_object"); if (ext) { ctx["createVertexArray"] = () => ext["createVertexArrayOES"](); ctx["deleteVertexArray"] = vao => ext["deleteVertexArrayOES"](vao); ctx["bindVertexArray"] = vao => ext["bindVertexArrayOES"](vao); ctx["isVertexArray"] = vao => ext["isVertexArrayOES"](vao); return 1; } }; var webgl_enable_WEBGL_draw_buffers = ctx => { // Extension available in WebGL 1 from Firefox 28 onwards. Core feature in WebGL 2. var ext = ctx.getExtension("WEBGL_draw_buffers"); if (ext) { ctx["drawBuffers"] = (n, bufs) => ext["drawBuffersWEBGL"](n, bufs); return 1; } }; var webgl_enable_WEBGL_draw_instanced_base_vertex_base_instance = ctx => // Closure is expected to be allowed to minify the '.dibvbi' property, so not accessing it quoted. !!(ctx.dibvbi = ctx.getExtension("WEBGL_draw_instanced_base_vertex_base_instance")); var webgl_enable_WEBGL_multi_draw_instanced_base_vertex_base_instance = ctx => !!(ctx.mdibvbi = ctx.getExtension("WEBGL_multi_draw_instanced_base_vertex_base_instance")); var webgl_enable_EXT_polygon_offset_clamp = ctx => !!(ctx.extPolygonOffsetClamp = ctx.getExtension("EXT_polygon_offset_clamp")); var webgl_enable_EXT_clip_control = ctx => !!(ctx.extClipControl = ctx.getExtension("EXT_clip_control")); var webgl_enable_WEBGL_polygon_mode = ctx => !!(ctx.webglPolygonMode = ctx.getExtension("WEBGL_polygon_mode")); var webgl_enable_WEBGL_multi_draw = ctx => // Closure is expected to be allowed to minify the '.multiDrawWebgl' property, so not accessing it quoted. !!(ctx.multiDrawWebgl = ctx.getExtension("WEBGL_multi_draw")); var getEmscriptenSupportedExtensions = ctx => { // Restrict the list of advertised extensions to those that we actually // support. var supportedExtensions = [ // WebGL 1 extensions "ANGLE_instanced_arrays", "EXT_blend_minmax", "EXT_disjoint_timer_query", "EXT_frag_depth", "EXT_shader_texture_lod", "EXT_sRGB", "OES_element_index_uint", "OES_fbo_render_mipmap", "OES_standard_derivatives", "OES_texture_float", "OES_texture_half_float", "OES_texture_half_float_linear", "OES_vertex_array_object", "WEBGL_color_buffer_float", "WEBGL_depth_texture", "WEBGL_draw_buffers", // WebGL 2 extensions "EXT_color_buffer_float", "EXT_conservative_depth", "EXT_disjoint_timer_query_webgl2", "EXT_texture_norm16", "NV_shader_noperspective_interpolation", "WEBGL_clip_cull_distance", // WebGL 1 and WebGL 2 extensions "EXT_clip_control", "EXT_color_buffer_half_float", "EXT_depth_clamp", "EXT_float_blend", "EXT_polygon_offset_clamp", "EXT_texture_compression_bptc", "EXT_texture_compression_rgtc", "EXT_texture_filter_anisotropic", "KHR_parallel_shader_compile", "OES_texture_float_linear", "WEBGL_blend_func_extended", "WEBGL_compressed_texture_astc", "WEBGL_compressed_texture_etc", "WEBGL_compressed_texture_etc1", "WEBGL_compressed_texture_s3tc", "WEBGL_compressed_texture_s3tc_srgb", "WEBGL_debug_renderer_info", "WEBGL_debug_shaders", "WEBGL_lose_context", "WEBGL_multi_draw", "WEBGL_polygon_mode" ]; // .getSupportedExtensions() can return null if context is lost, so coerce to empty array. return (ctx.getSupportedExtensions() || []).filter(ext => supportedExtensions.includes(ext)); }; var registerPreMainLoop = f => { // Does nothing unless $MainLoop is included/used. typeof MainLoop != "undefined" && MainLoop.preMainLoop.push(f); }; var GL = { counter: 1, buffers: [], mappedBuffers: {}, programs: [], framebuffers: [], renderbuffers: [], textures: [], shaders: [], vaos: [], contexts: [], offscreenCanvases: {}, queries: [], samplers: [], transformFeedbacks: [], syncs: [], byteSizeByTypeRoot: 5120, byteSizeByType: [ 1, 1, 2, 2, 4, 4, 4, 2, 3, 4, 8 ], stringCache: {}, stringiCache: {}, unpackAlignment: 4, unpackRowLength: 0, recordError: errorCode => { if (!GL.lastError) { GL.lastError = errorCode; } }, getNewId: table => { var ret = GL.counter++; for (var i = table.length; i < ret; i++) { table[i] = null; } // Skip over any non-null elements that might have been created by // glBindBuffer. while (table[ret]) { ret = GL.counter++; } return ret; }, genObject: (n, buffers, createFunction, objectTable) => { for (var i = 0; i < n; i++) { var buffer = GLctx[createFunction](); var id = buffer && GL.getNewId(objectTable); if (buffer) { buffer.name = id; objectTable[id] = buffer; } else { GL.recordError(1282); } HEAP32[(((buffers) + (i * 4)) >> 2)] = id; } }, MAX_TEMP_BUFFER_SIZE: 2097152, numTempVertexBuffersPerSize: 64, log2ceilLookup: i => 32 - Math.clz32(i === 0 ? 0 : i - 1), generateTempBuffers: (quads, context) => { var largestIndex = GL.log2ceilLookup(GL.MAX_TEMP_BUFFER_SIZE); context.tempVertexBufferCounters1 = []; context.tempVertexBufferCounters2 = []; context.tempVertexBufferCounters1.length = context.tempVertexBufferCounters2.length = largestIndex + 1; context.tempVertexBuffers1 = []; context.tempVertexBuffers2 = []; context.tempVertexBuffers1.length = context.tempVertexBuffers2.length = largestIndex + 1; context.tempIndexBuffers = []; context.tempIndexBuffers.length = largestIndex + 1; for (var i = 0; i <= largestIndex; ++i) { context.tempIndexBuffers[i] = null; // Created on-demand context.tempVertexBufferCounters1[i] = context.tempVertexBufferCounters2[i] = 0; var ringbufferLength = GL.numTempVertexBuffersPerSize; context.tempVertexBuffers1[i] = []; context.tempVertexBuffers2[i] = []; var ringbuffer1 = context.tempVertexBuffers1[i]; var ringbuffer2 = context.tempVertexBuffers2[i]; ringbuffer1.length = ringbuffer2.length = ringbufferLength; for (var j = 0; j < ringbufferLength; ++j) { ringbuffer1[j] = ringbuffer2[j] = null; } } if (quads) { // GL_QUAD indexes can be precalculated context.tempQuadIndexBuffer = GLctx.createBuffer(); context.GLctx.bindBuffer(34963, context.tempQuadIndexBuffer); var numIndexes = GL.MAX_TEMP_BUFFER_SIZE >> 1; var quadIndexes = new Uint16Array(numIndexes); var i = 0, v = 0; while (1) { quadIndexes[i++] = v; if (i >= numIndexes) break; quadIndexes[i++] = v + 1; if (i >= numIndexes) break; quadIndexes[i++] = v + 2; if (i >= numIndexes) break; quadIndexes[i++] = v; if (i >= numIndexes) break; quadIndexes[i++] = v + 2; if (i >= numIndexes) break; quadIndexes[i++] = v + 3; if (i >= numIndexes) break; v += 4; } context.GLctx.bufferData(34963, quadIndexes, 35044); context.GLctx.bindBuffer(34963, null); } }, getTempVertexBuffer: sizeBytes => { var idx = GL.log2ceilLookup(sizeBytes); var ringbuffer = GL.currentContext.tempVertexBuffers1[idx]; var nextFreeBufferIndex = GL.currentContext.tempVertexBufferCounters1[idx]; GL.currentContext.tempVertexBufferCounters1[idx] = (GL.currentContext.tempVertexBufferCounters1[idx] + 1) & (GL.numTempVertexBuffersPerSize - 1); var vbo = ringbuffer[nextFreeBufferIndex]; if (vbo) { return vbo; } var prevVBO = GLctx.getParameter(34964); ringbuffer[nextFreeBufferIndex] = GLctx.createBuffer(); GLctx.bindBuffer(34962, ringbuffer[nextFreeBufferIndex]); GLctx.bufferData(34962, 1 << idx, 35048); GLctx.bindBuffer(34962, prevVBO); return ringbuffer[nextFreeBufferIndex]; }, getTempIndexBuffer: sizeBytes => { var idx = GL.log2ceilLookup(sizeBytes); var ibo = GL.currentContext.tempIndexBuffers[idx]; if (ibo) { return ibo; } var prevIBO = GLctx.getParameter(34965); GL.currentContext.tempIndexBuffers[idx] = GLctx.createBuffer(); GLctx.bindBuffer(34963, GL.currentContext.tempIndexBuffers[idx]); GLctx.bufferData(34963, 1 << idx, 35048); GLctx.bindBuffer(34963, prevIBO); return GL.currentContext.tempIndexBuffers[idx]; }, newRenderingFrameStarted: () => { if (!GL.currentContext) { return; } var vb = GL.currentContext.tempVertexBuffers1; GL.currentContext.tempVertexBuffers1 = GL.currentContext.tempVertexBuffers2; GL.currentContext.tempVertexBuffers2 = vb; vb = GL.currentContext.tempVertexBufferCounters1; GL.currentContext.tempVertexBufferCounters1 = GL.currentContext.tempVertexBufferCounters2; GL.currentContext.tempVertexBufferCounters2 = vb; var largestIndex = GL.log2ceilLookup(GL.MAX_TEMP_BUFFER_SIZE); for (var i = 0; i <= largestIndex; ++i) { GL.currentContext.tempVertexBufferCounters1[i] = 0; } }, getSource: (shader, count, string, length) => { var source = ""; for (var i = 0; i < count; ++i) { var len = length ? HEAPU32[(((length) + (i * 4)) >> 2)] : undefined; source += UTF8ToString(HEAPU32[(((string) + (i * 4)) >> 2)], len); } return source; }, calcBufLength: (size, type, stride, count) => { if (stride > 0) { return count * stride; } var typeSize = GL.byteSizeByType[type - GL.byteSizeByTypeRoot]; return size * typeSize * count; }, usedTempBuffers: [], preDrawHandleClientVertexAttribBindings: count => { GL.resetBufferBinding = false; // TODO: initial pass to detect ranges we need to upload, might not need // an upload per attrib for (var i = 0; i < GL.currentContext.maxVertexAttribs; ++i) { var cb = GL.currentContext.clientBuffers[i]; if (!cb.clientside || !cb.enabled) continue; GL.resetBufferBinding = true; var size = GL.calcBufLength(cb.size, cb.type, cb.stride, count); var buf = GL.getTempVertexBuffer(size); GLctx.bindBuffer(34962, buf); GLctx.bufferSubData(34962, 0, HEAPU8.subarray(cb.ptr, cb.ptr + size)); cb.vertexAttribPointerAdaptor.call(GLctx, i, cb.size, cb.type, cb.normalized, cb.stride, 0); } }, postDrawHandleClientVertexAttribBindings: () => { if (GL.resetBufferBinding) { GLctx.bindBuffer(34962, GL.buffers[GLctx.currentArrayBufferBinding]); } }, createContext: (/** @type {HTMLCanvasElement} */ canvas, webGLContextAttributes) => { // BUG: Workaround Safari WebGL issue: After successfully acquiring WebGL // context on a canvas, calling .getContext() will always return that // context independent of which 'webgl' or 'webgl2' // context version was passed. See: // https://webkit.org/b/222758 // and: // https://github.com/emscripten-core/emscripten/issues/13295. // TODO: Once the bug is fixed and shipped in Safari, adjust the Safari // version field in above check. if (!canvas.getContextSafariWebGL2Fixed) { canvas.getContextSafariWebGL2Fixed = canvas.getContext; /** @type {function(this:HTMLCanvasElement, string, (Object|null)=): (Object|null)} */ function fixedGetContext(ver, attrs) { var gl = canvas.getContextSafariWebGL2Fixed(ver, attrs); return ((ver == "webgl") == (gl instanceof WebGLRenderingContext)) ? gl : null; } canvas.getContext = fixedGetContext; } var ctx = (webGLContextAttributes.majorVersion > 1) ? canvas.getContext("webgl2", webGLContextAttributes) : canvas.getContext("webgl", webGLContextAttributes); if (!ctx) return 0; var handle = GL.registerContext(ctx, webGLContextAttributes); return handle; }, registerContext: (ctx, webGLContextAttributes) => { // without pthreads a context is just an integer ID var handle = GL.getNewId(GL.contexts); var context = { handle, attributes: webGLContextAttributes, version: webGLContextAttributes.majorVersion, GLctx: ctx }; // Store the created context object so that we can access the context // given a canvas without having to pass the parameters again. if (ctx.canvas) ctx.canvas.GLctxObject = context; GL.contexts[handle] = context; if (typeof webGLContextAttributes.enableExtensionsByDefault == "undefined" || webGLContextAttributes.enableExtensionsByDefault) { GL.initExtensions(context); } context.maxVertexAttribs = context.GLctx.getParameter(34921); context.clientBuffers = []; for (var i = 0; i < context.maxVertexAttribs; i++) { context.clientBuffers[i] = { enabled: false, clientside: false, size: 0, type: 0, normalized: 0, stride: 0, ptr: 0, vertexAttribPointerAdaptor: null }; } GL.generateTempBuffers(false, context); return handle; }, makeContextCurrent: contextHandle => { // Active Emscripten GL layer context object. GL.currentContext = GL.contexts[contextHandle]; // Active WebGL context object. Module["ctx"] = GLctx = GL.currentContext?.GLctx; return !(contextHandle && !GLctx); }, getContext: contextHandle => GL.contexts[contextHandle], deleteContext: contextHandle => { if (GL.currentContext === GL.contexts[contextHandle]) { GL.currentContext = null; } if (typeof JSEvents == "object") { // Release all JS event handlers on the DOM element that the GL context is // associated with since the context is now deleted. JSEvents.removeAllHandlersOnTarget(GL.contexts[contextHandle].GLctx.canvas); } // Make sure the canvas object no longer refers to the context object so // there are no GC surprises. if (GL.contexts[contextHandle]?.GLctx.canvas) { GL.contexts[contextHandle].GLctx.canvas.GLctxObject = undefined; } GL.contexts[contextHandle] = null; }, initExtensions: context => { // If this function is called without a specific context object, init the // extensions of the currently active context. context ||= GL.currentContext; if (context.initExtensionsDone) return; context.initExtensionsDone = true; var GLctx = context.GLctx; // Detect the presence of a few extensions manually, since the GL interop // layer itself will need to know if they exist. // Extensions that are available in both WebGL 1 and WebGL 2 webgl_enable_WEBGL_multi_draw(GLctx); webgl_enable_EXT_polygon_offset_clamp(GLctx); webgl_enable_EXT_clip_control(GLctx); webgl_enable_WEBGL_polygon_mode(GLctx); // Extensions that are only available in WebGL 1 (the calls will be no-ops // if called on a WebGL 2 context active) webgl_enable_ANGLE_instanced_arrays(GLctx); webgl_enable_OES_vertex_array_object(GLctx); webgl_enable_WEBGL_draw_buffers(GLctx); // Extensions that are available from WebGL >= 2 (no-op if called on a WebGL 1 context active) webgl_enable_WEBGL_draw_instanced_base_vertex_base_instance(GLctx); webgl_enable_WEBGL_multi_draw_instanced_base_vertex_base_instance(GLctx); // On WebGL 2, EXT_disjoint_timer_query is replaced with an alternative // that's based on core APIs, and exposes only the queryCounterEXT() // entrypoint. if (context.version >= 2) { GLctx.disjointTimerQueryExt = GLctx.getExtension("EXT_disjoint_timer_query_webgl2"); } // However, Firefox exposes the WebGL 1 version on WebGL 2 as well and // thus we look for the WebGL 1 version again if the WebGL 2 version // isn't present. https://bugzil.la/1328882 if (context.version < 2 || !GLctx.disjointTimerQueryExt) { GLctx.disjointTimerQueryExt = GLctx.getExtension("EXT_disjoint_timer_query"); } for (var ext of getEmscriptenSupportedExtensions(GLctx)) { // WEBGL_lose_context, WEBGL_debug_renderer_info and WEBGL_debug_shaders // are not enabled by default. if (!ext.includes("lose_context") && !ext.includes("debug")) { // Call .getExtension() to enable that extension permanently. GLctx.getExtension(ext); } } } }; var webglPowerPreferences = [ "default", "low-power", "high-performance" ]; /** @type {Object} */ var specialHTMLTargets = [ 0, globalThis.document ?? 0, globalThis.window ?? 0 ]; var findEventTarget = target => { // The sensible "default" target varies between events, but use window as the default // since DOM events mostly can default to that. Specific callback registrations // override their own defaults. if (!target) return window; if (typeof target == "number") target = specialHTMLTargets[target] || UTF8ToString(target); if (target === "#window") return window; else if (target === "#document") return document; else if (target === "#screen") return screen; else if (target === "#canvas") return Module["canvas"]; else if (typeof target == "string") return globalThis.document?.getElementById(target); return target; }; var findCanvasEventTarget = target => { if (typeof target == "number") target = UTF8ToString(target); if (!target || target === "#canvas") { if (typeof GL != "undefined" && GL.offscreenCanvases["canvas"]) return GL.offscreenCanvases["canvas"]; // TODO: Remove this line, target '#canvas' should refer only to Module['canvas'], not to GL.offscreenCanvases['canvas'] - but need stricter tests to be able to remove this line. return Module["canvas"]; } if (typeof GL != "undefined" && GL.offscreenCanvases[target]) return GL.offscreenCanvases[target]; return findEventTarget(target); }; var _emscripten_webgl_do_create_context = (target, attributes) => { var attr32 = ((attributes) >> 2); var powerPreference = HEAP32[attr32 + (8 >> 2)]; var contextAttributes = { "alpha": !!HEAP8[attributes + 0], "depth": !!HEAP8[attributes + 1], "stencil": !!HEAP8[attributes + 2], "antialias": !!HEAP8[attributes + 3], "premultipliedAlpha": !!HEAP8[attributes + 4], "preserveDrawingBuffer": !!HEAP8[attributes + 5], "powerPreference": webglPowerPreferences[powerPreference], "failIfMajorPerformanceCaveat": !!HEAP8[attributes + 12], // The following are not predefined WebGL context attributes in the WebGL specification, so the property names can be minified by Closure. majorVersion: HEAP32[attr32 + (16 >> 2)], minorVersion: HEAP32[attr32 + (20 >> 2)], enableExtensionsByDefault: HEAP8[attributes + 24], explicitSwapControl: HEAP8[attributes + 25], proxyContextToMainThread: HEAP32[attr32 + (28 >> 2)], renderViaOffscreenBackBuffer: HEAP8[attributes + 32] }; var canvas = findCanvasEventTarget(target); if (!canvas) { return 0; } if (contextAttributes.explicitSwapControl) { return 0; } var contextHandle = GL.createContext(canvas, contextAttributes); return contextHandle; }; var _emscripten_webgl_create_context = _emscripten_webgl_do_create_context; var _emscripten_webgl_destroy_context = contextHandle => { if (GL.currentContext == contextHandle) GL.currentContext = 0; GL.deleteContext(contextHandle); }; var _emscripten_webgl_get_context_attributes = (c, a) => { if (!a) return -5; c = GL.contexts[c]; if (!c) return -3; var t = c.GLctx?.getContextAttributes(); if (!t) return -3; HEAP8[a] = t.alpha; HEAP8[(a) + (1)] = t.depth; HEAP8[(a) + (2)] = t.stencil; HEAP8[(a) + (3)] = t.antialias; HEAP8[(a) + (4)] = t.premultipliedAlpha; HEAP8[(a) + (5)] = t.preserveDrawingBuffer; var power = t["powerPreference"] && webglPowerPreferences.indexOf(t["powerPreference"]); HEAP32[(((a) + (8)) >> 2)] = power; HEAP8[(a) + (12)] = t.failIfMajorPerformanceCaveat; HEAP32[(((a) + (16)) >> 2)] = c.version; HEAP32[(((a) + (20)) >> 2)] = 0; HEAP8[(a) + (24)] = c.attributes.enableExtensionsByDefault; return 0; }; var _emscripten_webgl_do_get_current_context = () => GL.currentContext ? GL.currentContext.handle : 0; var _emscripten_webgl_get_current_context = _emscripten_webgl_do_get_current_context; var _emscripten_webgl_make_context_current = contextHandle => { var success = GL.makeContextCurrent(contextHandle); return success ? 0 : -5; }; 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 readI53FromI64 = ptr => HEAPU32[((ptr) >> 2)] + HEAP32[(((ptr) + (4)) >> 2)] * 4294967296; var wasmTableMirror = []; var getWasmTableEntry = funcPtr => { var func = wasmTableMirror[funcPtr]; if (!func) { /** @suppress {checkTypes} */ wasmTableMirror[funcPtr] = func = wasmTable.get(funcPtr); } return func; }; var WebGPU = { Internals: { jsObjects: [], jsObjectInsert: (ptr, jsObject) => { ptr >>>= 0; WebGPU.Internals.jsObjects[ptr] = jsObject; }, bufferOnUnmaps: [], futures: [], futureInsert: (futureId, promise) => {} }, getJsObject: ptr => { if (!ptr) return undefined; 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) => { // At the moment, we do not allow importing pending buffers. 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)]; // This will crash if there's no handler indicating either a bogus // sType, or one we haven't implemented yet. var handler = 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)]; // UTF8ToString stops at the first null terminator character in the // string regardless of the length. return UTF8ToString(ptr, length); }, makeStringFromOptionalStringView: stringViewPtr => { var ptr = HEAPU32[((stringViewPtr) >> 2)]; var length = HEAPU32[(((stringViewPtr) + (4)) >> 2)]; // If we don't have a valid string pointer, just return undefined when // optional. if (!ptr) { if (length === 0) { return ""; } return undefined; } // UTF8ToString stops at the first null terminator character in the // string regardless of the length. 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 ? undefined : bytesPerRow, "rowsPerImage": rowsPerImage === 4294967295 ? undefined : 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 undefined; 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 undefined; 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 makePrimitiveState(psPtr) { if (!psPtr) return undefined; 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)]) }; } function makeBlendComponent(bdPtr) { if (!bdPtr) return undefined; 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 undefined; return { "alpha": makeBlendComponent(bsPtr + 12), "color": makeBlendComponent(bsPtr + 0) }; } function makeColorState(csPtr) { var format = WebGPU.TextureFormat[HEAP32[(((csPtr) + (4)) >> 2)]]; return format ? { "format": format, "blend": makeBlendState(HEAPU32[(((csPtr) + (8)) >> 2)]), "writeMask": HEAPU32[(((csPtr) + (16)) >> 2)] } : undefined; } 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 makeDepthStencilState(dssPtr) { if (!dssPtr) return undefined; 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)] }; } 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 undefined; 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": stepMode, "attributes": makeVertexAttributes(attributeCount, HEAPU32[(((vbPtr) + (20)) >> 2)]) }; } function makeVertexBuffers(count, vbArrayPtr) { if (!count) return undefined; var vbs = []; for (var i = 0; i < count; ++i) { vbs.push(makeVertexBuffer(vbArrayPtr + i * 24)); } return vbs; } function makeVertexState(viPtr) { if (!viPtr) return undefined; 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; } function makeMultisampleState(msPtr) { if (!msPtr) return undefined; return { "count": HEAPU32[(((msPtr) + (4)) >> 2)], "mask": HEAPU32[(((msPtr) + (8)) >> 2)], "alphaToCoverageEnabled": !!(HEAPU32[(((msPtr) + (12)) >> 2)]) }; } function makeFragmentState(fsPtr) { if (!fsPtr) return undefined; 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; } var desc = { "label": WebGPU.makeStringFromOptionalStringView(descriptor + 4), "layout": WebGPU.makePipelineLayout(HEAPU32[(((descriptor) + (12)) >> 2)]), "vertex": makeVertexState(descriptor + 16), "primitive": makePrimitiveState(descriptor + 48), "depthStencil": makeDepthStencilState(HEAPU32[(((descriptor) + (72)) >> 2)]), "multisample": makeMultisampleState(descriptor + 76), "fragment": makeFragmentState(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; // Limits are integer-valued JS `Number`s, so they fit in 'i53'. 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); // Note this limit is new and won't be present in all browsers for a while. Fall back to 0. setLimitValueU32("maxImmediateSize", limitsOutPtr, 148); if (nextInChainPtr !== 0) { var sType = HEAP32[(((nextInChainPtr) + (4)) >> 2)]; var compatibilityModeLimitsPtr = nextInChainPtr; // Note these limits are new and won't be present in all browsers for a while. Fall back to exposing the PerShaderStage limit. 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) => { // Populate subgroup limits. HEAPU32[(((infoStruct) + (52)) >> 2)] = info.subgroupMinSize; HEAPU32[(((infoStruct) + (56)) >> 2)] = info.subgroupMaxSize; // Append all the strings together to condense into a single malloc. 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; }, 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", 327692: "chromium-experimental-unorm16-texture-formats", 327729: "chromium-experimental-multi-draw-indirect" }, 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" ], 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" ], 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" ] }; var _emscripten_webgpu_get_device = () => { if (WebGPU.preinitializedDeviceId === undefined) { WebGPU.preinitializedDeviceId = WebGPU.importJsDevice(Module["preinitializedWebGPUDevice"]); // Some users depend on this keeping the device alive, so we add an // additional reference when we first initialize it. _wgpuDeviceAddRef(WebGPU.preinitializedDeviceId); } _wgpuDeviceAddRef(WebGPU.preinitializedDeviceId); return WebGPU.preinitializedDeviceId; }; var _emwgpuBufferDestroy = 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(); }; var _emwgpuBufferGetMappedRange = (bufferPtr, offset, size) => { var buffer = WebGPU.getJsObject(bufferPtr); if (size == -1) size = undefined; 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; }; var _emwgpuBufferUnmap = bufferPtr => { var buffer = WebGPU.getJsObject(bufferPtr); var onUnmap = WebGPU.Internals.bufferOnUnmaps[bufferPtr]; if (!onUnmap) { // Already unmapped return; } for (var i = 0; i < onUnmap.length; ++i) { onUnmap[i](); } delete WebGPU.Internals.bufferOnUnmaps[bufferPtr]; buffer.unmap(); }; var _emwgpuDelete = ptr => { delete WebGPU.Internals.jsObjects[ptr]; }; var _emwgpuDeviceCreateBuffer = (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": mappedAtCreation }; var device = WebGPU.getJsObject(devicePtr); var buffer; try { buffer = device.createBuffer(desc); } catch (ex) { // The only exception should be RangeError if mapping at creation ran out of memory. return false; } WebGPU.Internals.jsObjectInsert(bufferPtr, buffer); if (mappedAtCreation) { WebGPU.Internals.bufferOnUnmaps[bufferPtr] = []; } return true; }; var _emwgpuDeviceCreateComputePipelineAsync = function(devicePtr, futureId_low, futureId_high, descriptor, pipelinePtr) { var futureId = convertI32PairToI53Checked(futureId_low, futureId_high); var desc = WebGPU.makeComputePipelineDesc(descriptor); var device = WebGPU.getJsObject(devicePtr); // createComputePipelineAsync WebGPU.Internals.futureInsert(futureId, device.createComputePipelineAsync(desc).then(pipeline => { // createComputePipelineAsync fulfilled callUserCallback(() => { WebGPU.Internals.jsObjectInsert(pipelinePtr, pipeline); _emwgpuOnCreateComputePipelineCompleted(futureId, 1, pipelinePtr, 0); }); }, pipelineError => { // createComputePipelineAsync rejected 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); }); })); }; var _emwgpuDeviceCreateRenderPipelineAsync = function(devicePtr, futureId_low, futureId_high, descriptor, pipelinePtr) { var futureId = convertI32PairToI53Checked(futureId_low, futureId_high); var desc = WebGPU.makeRenderPipelineDesc(descriptor); var device = WebGPU.getJsObject(devicePtr); // createRenderPipelineAsync WebGPU.Internals.futureInsert(futureId, device.createRenderPipelineAsync(desc).then(pipeline => { // createRenderPipelineAsync fulfilled callUserCallback(() => { WebGPU.Internals.jsObjectInsert(pipelinePtr, pipeline); _emwgpuOnCreateRenderPipelineCompleted(futureId, 1, pipelinePtr, 0); }); }, pipelineError => { // createRenderPipelineAsync rejected callUserCallback(() => { var sp = stackSave(); var messagePtr = stringToUTF8OnStack(pipelineError.message); var status = pipelineError.reason === "validation" ? 3 : pipelineError.reason === "internal" ? 4 : 0; _emwgpuOnCreateRenderPipelineCompleted(futureId, status, pipelinePtr, messagePtr); stackRestore(sp); }); })); }; var _emwgpuDeviceCreateShaderModule = (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)); }; var _emwgpuDeviceDestroy = devicePtr => { const device = WebGPU.getJsObject(devicePtr); // Remove the onuncapturederror handler which holds a pointer to the WGPUDevice. device.onuncapturederror = null; device.destroy(); }; var _emwgpuWaitAny = (futurePtr, futureCount, timeoutMSPtr) => { abort("TODO: Implement asyncify-free WaitAny for timeout=0"); }; var ENV = {}; var getExecutableName = () => thisProgram || "./this.program"; var getEnvStrings = () => { if (!getEnvStrings.strings) { // Default values. // Browser language detection #8751 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() }; // Apply the user-provided values, if any. for (var x in ENV) { // x is a key in ENV; if ENV[x] is undefined, that means it was // explicitly set to be so. We allow user code to do that to // force variables with default values to remain unset. if (ENV[x] === undefined) 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 _environ_get = (__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, Infinity) + 1; envp += 4; } return 0; }; var _environ_sizes_get = (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; }; function _fd_close(fd) { try { var stream = SYSCALLS.getStreamFromFD(fd); FS.close(stream); return 0; } catch (e) { if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e; return e.errno; } } /** @param {number=} offset */ var doReadv = (stream, iov, iovcnt, offset) => { var ret = 0; for (var i = 0; i < iovcnt; i++) { var ptr = HEAPU32[((iov) >> 2)]; var len = HEAPU32[(((iov) + (4)) >> 2)]; iov += 8; var curr = FS.read(stream, HEAP8, ptr, len, offset); if (curr < 0) return -1; ret += curr; if (curr < len) break; // nothing more to read if (typeof offset != "undefined") { offset += curr; } } return ret; }; function _fd_read(fd, iov, iovcnt, pnum) { try { var stream = SYSCALLS.getStreamFromFD(fd); var num = doReadv(stream, iov, iovcnt); HEAPU32[((pnum) >> 2)] = num; return 0; } catch (e) { if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e; return e.errno; } } function _fd_seek(fd, offset_low, offset_high, whence, newOffset) { var offset = convertI32PairToI53Checked(offset_low, offset_high); try { if (isNaN(offset)) return 61; var stream = SYSCALLS.getStreamFromFD(fd); FS.llseek(stream, offset, whence); (tempI64 = [ stream.position >>> 0, (tempDouble = stream.position, (+(Math.abs(tempDouble))) >= 1 ? (tempDouble > 0 ? (+(Math.floor((tempDouble) / 4294967296))) >>> 0 : (~~((+(Math.ceil((tempDouble - +(((~~(tempDouble))) >>> 0)) / 4294967296))))) >>> 0) : 0) ], HEAP32[((newOffset) >> 2)] = tempI64[0], HEAP32[(((newOffset) + (4)) >> 2)] = tempI64[1]); if (stream.getdents && offset === 0 && whence === 0) stream.getdents = null; // reset readdir state return 0; } catch (e) { if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e; return e.errno; } } /** @param {number=} offset */ var doWritev = (stream, iov, iovcnt, offset) => { var ret = 0; for (var i = 0; i < iovcnt; i++) { var ptr = HEAPU32[((iov) >> 2)]; var len = HEAPU32[(((iov) + (4)) >> 2)]; iov += 8; var curr = FS.write(stream, HEAP8, ptr, len, offset); if (curr < 0) return -1; ret += curr; if (curr < len) { // No more space to write. break; } if (typeof offset != "undefined") { offset += curr; } } return ret; }; function _fd_write(fd, iov, iovcnt, pnum) { try { var stream = SYSCALLS.getStreamFromFD(fd); var num = doWritev(stream, iov, iovcnt); HEAPU32[((pnum) >> 2)] = num; return 0; } catch (e) { if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e; return e.errno; } } var _emscripten_glActiveTexture = x0 => GLctx.activeTexture(x0); var _glActiveTexture = _emscripten_glActiveTexture; var _emscripten_glAttachShader = (program, shader) => { GLctx.attachShader(GL.programs[program], GL.shaders[shader]); }; var _glAttachShader = _emscripten_glAttachShader; var _emscripten_glBindAttribLocation = (program, index, name) => { GLctx.bindAttribLocation(GL.programs[program], index, UTF8ToString(name)); }; var _glBindAttribLocation = _emscripten_glBindAttribLocation; var _emscripten_glBindBuffer = (target, buffer) => { // Calling glBindBuffer with an unknown buffer will implicitly create a // new one. Here we bypass `GL.counter` and directly using the ID passed // in. if (buffer && !GL.buffers[buffer]) { var b = GLctx.createBuffer(); b.name = buffer; GL.buffers[buffer] = b; } if (target == 34962) { GLctx.currentArrayBufferBinding = buffer; } else if (target == 34963) { GLctx.currentElementArrayBufferBinding = buffer; } if (target == 35051) { // In WebGL 2 glReadPixels entry point, we need to use a different WebGL 2 // API function call when a buffer is bound to // GL_PIXEL_PACK_BUFFER_BINDING point, so must keep track whether that // binding point is non-null to know what is the proper API function to // call. GLctx.currentPixelPackBufferBinding = buffer; } else if (target == 35052) { // In WebGL 2 gl(Compressed)Tex(Sub)Image[23]D entry points, we need to // use a different WebGL 2 API function call when a buffer is bound to // GL_PIXEL_UNPACK_BUFFER_BINDING point, so must keep track whether that // binding point is non-null to know what is the proper API function to // call. GLctx.currentPixelUnpackBufferBinding = buffer; } GLctx.bindBuffer(target, GL.buffers[buffer]); }; var _glBindBuffer = _emscripten_glBindBuffer; var _emscripten_glBindBufferBase = (target, index, buffer) => { GLctx.bindBufferBase(target, index, GL.buffers[buffer]); }; var _glBindBufferBase = _emscripten_glBindBufferBase; var _emscripten_glBindFramebuffer = (target, framebuffer) => { GLctx.bindFramebuffer(target, GL.framebuffers[framebuffer]); }; var _glBindFramebuffer = _emscripten_glBindFramebuffer; var _emscripten_glBindTexture = (target, texture) => { GLctx.bindTexture(target, GL.textures[texture]); }; var _glBindTexture = _emscripten_glBindTexture; var _emscripten_glBindVertexArray = vao => { GLctx.bindVertexArray(GL.vaos[vao]); var ibo = GLctx.getParameter(34965); GLctx.currentElementArrayBufferBinding = ibo ? (ibo.name | 0) : 0; }; var _glBindVertexArray = _emscripten_glBindVertexArray; var _emscripten_glBlendEquation = x0 => GLctx.blendEquation(x0); var _glBlendEquation = _emscripten_glBlendEquation; var _emscripten_glBlendFunc = (x0, x1) => GLctx.blendFunc(x0, x1); var _glBlendFunc = _emscripten_glBlendFunc; var _emscripten_glBufferData = (target, size, data, usage) => { if (GL.currentContext.version >= 2) { // If size is zero, WebGL would interpret uploading the whole input // arraybuffer (starting from given offset), which would not make sense in // WebAssembly, so avoid uploading if size is zero. However we must still // call bufferData to establish a backing storage of zero bytes. if (data && size) { GLctx.bufferData(target, HEAPU8, usage, data, size); } else { GLctx.bufferData(target, size, usage); } return; } // N.b. here first form specifies a heap subarray, second form an integer // size, so the ?: code here is polymorphic. It is advised to avoid // randomly mixing both uses in calling code, to avoid any potential JS // engine JIT issues. GLctx.bufferData(target, data ? HEAPU8.subarray(data, data + size) : size, usage); }; var _glBufferData = _emscripten_glBufferData; var _emscripten_glClear = x0 => GLctx.clear(x0); var _glClear = _emscripten_glClear; var _emscripten_glClearColor = (x0, x1, x2, x3) => GLctx.clearColor(x0, x1, x2, x3); var _glClearColor = _emscripten_glClearColor; var convertI32PairToI53 = (lo, hi) => (lo >>> 0) + hi * 4294967296; var _emscripten_glClientWaitSync = (sync, flags, timeout_low, timeout_high) => { // WebGL2 vs GLES3 differences: in GLES3, the timeout parameter is a uint64, where 0xFFFFFFFFFFFFFFFFULL means GL_TIMEOUT_IGNORED. // In JS, there's no 64-bit value types, so instead timeout is taken to be signed, and GL_TIMEOUT_IGNORED is given value -1. // Inherently the value accepted in the timeout is lossy, and can't take in arbitrary u64 bit pattern (but most likely doesn't matter) // See https://www.khronos.org/registry/webgl/specs/latest/2.0/#5.15 var timeout = convertI32PairToI53(timeout_low, timeout_high); return GLctx.clientWaitSync(GL.syncs[sync], flags, timeout); }; var _glClientWaitSync = _emscripten_glClientWaitSync; var _emscripten_glColorMask = (red, green, blue, alpha) => { GLctx.colorMask(!!red, !!green, !!blue, !!alpha); }; var _glColorMask = _emscripten_glColorMask; var _emscripten_glCompileShader = shader => { GLctx.compileShader(GL.shaders[shader]); }; var _glCompileShader = _emscripten_glCompileShader; var _emscripten_glCreateProgram = () => { var id = GL.getNewId(GL.programs); var program = GLctx.createProgram(); // Store additional information needed for each shader program: program.name = id; // Lazy cache results of // glGetProgramiv(GL_ACTIVE_UNIFORM_MAX_LENGTH/GL_ACTIVE_ATTRIBUTE_MAX_LENGTH/GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH) program.maxUniformLength = program.maxAttributeLength = program.maxUniformBlockNameLength = 0; program.uniformIdCounter = 1; GL.programs[id] = program; return id; }; var _glCreateProgram = _emscripten_glCreateProgram; var _emscripten_glCreateShader = shaderType => { var id = GL.getNewId(GL.shaders); GL.shaders[id] = GLctx.createShader(shaderType); return id; }; var _glCreateShader = _emscripten_glCreateShader; var _emscripten_glDeleteBuffers = (n, buffers) => { for (var i = 0; i < n; i++) { var id = HEAP32[(((buffers) + (i * 4)) >> 2)]; var buffer = GL.buffers[id]; // From spec: "glDeleteBuffers silently ignores 0's and names that do not // correspond to existing buffer objects." if (!buffer) continue; GLctx.deleteBuffer(buffer); buffer.name = 0; GL.buffers[id] = null; if (id == GLctx.currentArrayBufferBinding) GLctx.currentArrayBufferBinding = 0; if (id == GLctx.currentElementArrayBufferBinding) GLctx.currentElementArrayBufferBinding = 0; if (id == GLctx.currentPixelPackBufferBinding) GLctx.currentPixelPackBufferBinding = 0; if (id == GLctx.currentPixelUnpackBufferBinding) GLctx.currentPixelUnpackBufferBinding = 0; } }; var _glDeleteBuffers = _emscripten_glDeleteBuffers; var _emscripten_glDeleteFramebuffers = (n, framebuffers) => { for (var i = 0; i < n; ++i) { var id = HEAP32[(((framebuffers) + (i * 4)) >> 2)]; var framebuffer = GL.framebuffers[id]; if (!framebuffer) continue; // GL spec: "glDeleteFramebuffers silently ignores 0s and names that do not correspond to existing framebuffer objects". GLctx.deleteFramebuffer(framebuffer); framebuffer.name = 0; GL.framebuffers[id] = null; } }; var _glDeleteFramebuffers = _emscripten_glDeleteFramebuffers; var _emscripten_glDeleteProgram = id => { if (!id) return; var program = GL.programs[id]; if (!program) { // glDeleteProgram actually signals an error when deleting a nonexisting // object, unlike some other GL delete functions. GL.recordError(1281); return; } GLctx.deleteProgram(program); program.name = 0; GL.programs[id] = null; }; var _glDeleteProgram = _emscripten_glDeleteProgram; var _emscripten_glDeleteShader = id => { if (!id) return; var shader = GL.shaders[id]; if (!shader) { // glDeleteShader actually signals an error when deleting a nonexisting // object, unlike some other GL delete functions. GL.recordError(1281); return; } GLctx.deleteShader(shader); GL.shaders[id] = null; }; var _glDeleteShader = _emscripten_glDeleteShader; var _emscripten_glDeleteSync = id => { if (!id) return; var sync = GL.syncs[id]; if (!sync) { // glDeleteSync signals an error when deleting a nonexisting object, unlike some other GL delete functions. GL.recordError(1281); return; } GLctx.deleteSync(sync); sync.name = 0; GL.syncs[id] = null; }; var _glDeleteSync = _emscripten_glDeleteSync; var _emscripten_glDeleteTextures = (n, textures) => { for (var i = 0; i < n; i++) { var id = HEAP32[(((textures) + (i * 4)) >> 2)]; var texture = GL.textures[id]; // GL spec: "glDeleteTextures silently ignores 0s and names that do not // correspond to existing textures". if (!texture) continue; GLctx.deleteTexture(texture); texture.name = 0; GL.textures[id] = null; } }; var _glDeleteTextures = _emscripten_glDeleteTextures; var _emscripten_glDeleteVertexArrays = (n, vaos) => { for (var i = 0; i < n; i++) { var id = HEAP32[(((vaos) + (i * 4)) >> 2)]; GLctx.deleteVertexArray(GL.vaos[id]); GL.vaos[id] = null; } }; var _glDeleteVertexArrays = _emscripten_glDeleteVertexArrays; var _emscripten_glDetachShader = (program, shader) => { GLctx.detachShader(GL.programs[program], GL.shaders[shader]); }; var _glDetachShader = _emscripten_glDetachShader; var _emscripten_glDisable = x0 => GLctx.disable(x0); var _glDisable = _emscripten_glDisable; var _emscripten_glDisableVertexAttribArray = index => { var cb = GL.currentContext.clientBuffers[index]; cb.enabled = false; GLctx.disableVertexAttribArray(index); }; var _glDisableVertexAttribArray = _emscripten_glDisableVertexAttribArray; var _emscripten_glDrawArrays = (mode, first, count) => { // bind any client-side buffers GL.preDrawHandleClientVertexAttribBindings(first + count); GLctx.drawArrays(mode, first, count); GL.postDrawHandleClientVertexAttribBindings(); }; var _glDrawArrays = _emscripten_glDrawArrays; var tempFixedLengthArray = []; var _emscripten_glDrawBuffers = (n, bufs) => { var bufArray = tempFixedLengthArray[n]; for (var i = 0; i < n; i++) { bufArray[i] = HEAP32[(((bufs) + (i * 4)) >> 2)]; } GLctx.drawBuffers(bufArray); }; var _glDrawBuffers = _emscripten_glDrawBuffers; var _emscripten_glEnable = x0 => GLctx.enable(x0); var _glEnable = _emscripten_glEnable; var _emscripten_glEnableVertexAttribArray = index => { var cb = GL.currentContext.clientBuffers[index]; cb.enabled = true; GLctx.enableVertexAttribArray(index); }; var _glEnableVertexAttribArray = _emscripten_glEnableVertexAttribArray; var _emscripten_glFenceSync = (condition, flags) => { var sync = GLctx.fenceSync(condition, flags); if (sync) { var id = GL.getNewId(GL.syncs); sync.name = id; GL.syncs[id] = sync; return id; } return 0; }; var _glFenceSync = _emscripten_glFenceSync; var _emscripten_glFinish = () => GLctx.finish(); var _glFinish = _emscripten_glFinish; var _emscripten_glFlush = () => GLctx.flush(); var _glFlush = _emscripten_glFlush; var _emscripten_glFramebufferTexture2D = (target, attachment, textarget, texture, level) => { GLctx.framebufferTexture2D(target, attachment, textarget, GL.textures[texture], level); }; var _glFramebufferTexture2D = _emscripten_glFramebufferTexture2D; var _emscripten_glFramebufferTextureLayer = (target, attachment, texture, level, layer) => { GLctx.framebufferTextureLayer(target, attachment, GL.textures[texture], level, layer); }; var _glFramebufferTextureLayer = _emscripten_glFramebufferTextureLayer; var _emscripten_glGenBuffers = (n, buffers) => { GL.genObject(n, buffers, "createBuffer", GL.buffers); }; var _glGenBuffers = _emscripten_glGenBuffers; var _emscripten_glGenFramebuffers = (n, ids) => { GL.genObject(n, ids, "createFramebuffer", GL.framebuffers); }; var _glGenFramebuffers = _emscripten_glGenFramebuffers; var _emscripten_glGenTextures = (n, textures) => { GL.genObject(n, textures, "createTexture", GL.textures); }; var _glGenTextures = _emscripten_glGenTextures; var _emscripten_glGenVertexArrays = (n, arrays) => { GL.genObject(n, arrays, "createVertexArray", GL.vaos); }; var _glGenVertexArrays = _emscripten_glGenVertexArrays; var _emscripten_glGetAttribLocation = (program, name) => GLctx.getAttribLocation(GL.programs[program], UTF8ToString(name)); var _glGetAttribLocation = _emscripten_glGetAttribLocation; var _emscripten_glGetError = () => { var error = GLctx.getError() || GL.lastError; GL.lastError = 0; return error; }; var _glGetError = _emscripten_glGetError; var webglGetExtensions = () => { var exts = getEmscriptenSupportedExtensions(GLctx); exts = exts.concat(exts.map(e => "GL_" + e)); return exts; }; var emscriptenWebGLGet = (name_, p, type) => { // Guard against user passing a null pointer. // Note that GLES2 spec does not say anything about how passing a null // pointer should be treated. Testing on desktop core GL 3, the application // crashes on glGetIntegerv to a null pointer, but better to report an error // instead of doing anything random. if (!p) { GL.recordError(1281); return; } var ret = undefined; switch (name_) { // Handle a few trivial GLES values case 36346: // GL_SHADER_COMPILER ret = 1; break; case 36344: // GL_SHADER_BINARY_FORMATS if (type != 0 && type != 1) { GL.recordError(1280); } // Do not write anything to the out pointer, since no binary formats are // supported. return; case 34814: // GL_NUM_PROGRAM_BINARY_FORMATS case 36345: // GL_NUM_SHADER_BINARY_FORMATS ret = 0; break; case 34466: // GL_NUM_COMPRESSED_TEXTURE_FORMATS // WebGL doesn't have GL_NUM_COMPRESSED_TEXTURE_FORMATS (it's obsolete // since GL_COMPRESSED_TEXTURE_FORMATS returns a JS array that can be // queried for length), so implement it ourselves to allow C++ GLES2 // code to get the length. var formats = GLctx.getParameter(34467); ret = formats ? formats.length : 0; break; case 33309: // GL_NUM_EXTENSIONS if (GL.currentContext.version < 2) { // Calling GLES3/WebGL2 function with a GLES2/WebGL1 context GL.recordError(1282); return; } ret = webglGetExtensions().length; break; case 33307: // GL_MAJOR_VERSION case 33308: // GL_MINOR_VERSION if (GL.currentContext.version < 2) { GL.recordError(1280); // GL_INVALID_ENUM return; } ret = name_ == 33307 ? 3 : 0; // return version 3.0 break; } if (ret === undefined) { var result = GLctx.getParameter(name_); switch (typeof result) { case "number": ret = result; break; case "boolean": ret = result ? 1 : 0; break; case "string": GL.recordError(1280); // GL_INVALID_ENUM return; case "object": if (result === null) { // null is a valid result for some (e.g., which buffer is bound - // perhaps nothing is bound), but otherwise can mean an invalid // name_, which we need to report as an error switch (name_) { case 34964: // ARRAY_BUFFER_BINDING case 35725: // CURRENT_PROGRAM case 34965: // ELEMENT_ARRAY_BUFFER_BINDING case 36006: // FRAMEBUFFER_BINDING or DRAW_FRAMEBUFFER_BINDING case 36007: // RENDERBUFFER_BINDING case 32873: // TEXTURE_BINDING_2D case 34229: // WebGL 2 GL_VERTEX_ARRAY_BINDING, or WebGL 1 extension OES_vertex_array_object GL_VERTEX_ARRAY_BINDING_OES case 36662: // COPY_READ_BUFFER_BINDING or COPY_READ_BUFFER case 36663: // COPY_WRITE_BUFFER_BINDING or COPY_WRITE_BUFFER case 35053: // PIXEL_PACK_BUFFER_BINDING case 35055: // PIXEL_UNPACK_BUFFER_BINDING case 36010: // READ_FRAMEBUFFER_BINDING case 35097: // SAMPLER_BINDING case 35869: // TEXTURE_BINDING_2D_ARRAY case 32874: // TEXTURE_BINDING_3D case 36389: // TRANSFORM_FEEDBACK_BINDING case 35983: // TRANSFORM_FEEDBACK_BUFFER_BINDING case 35368: // UNIFORM_BUFFER_BINDING case 34068: { // TEXTURE_BINDING_CUBE_MAP ret = 0; break; } default: { GL.recordError(1280); // GL_INVALID_ENUM return; } } } else if (result instanceof Float32Array || result instanceof Uint32Array || result instanceof Int32Array || result instanceof Array) { for (var i = 0; i < result.length; ++i) { switch (type) { case 0: HEAP32[(((p) + (i * 4)) >> 2)] = result[i]; break; case 2: HEAPF32[(((p) + (i * 4)) >> 2)] = result[i]; break; case 4: HEAP8[(p) + (i)] = result[i] ? 1 : 0; break; } } return; } else { try { ret = result.name | 0; } catch (e) { GL.recordError(1280); // GL_INVALID_ENUM err(`GL_INVALID_ENUM in glGet${type}v: Unknown object returned from WebGL getParameter(${name_})! (error: ${e})`); return; } } break; default: GL.recordError(1280); // GL_INVALID_ENUM err(`GL_INVALID_ENUM in glGet${type}v: Native code calling glGet${type}v(${name_}) and it returns ${result} of type ${typeof (result)}!`); return; } } switch (type) { case 1: writeI53ToI64(p, ret); break; case 0: HEAP32[((p) >> 2)] = ret; break; case 2: HEAPF32[((p) >> 2)] = ret; break; case 4: HEAP8[p] = ret ? 1 : 0; break; } }; var _emscripten_glGetFloatv = (name_, p) => emscriptenWebGLGet(name_, p, 2); var _glGetFloatv = _emscripten_glGetFloatv; var _emscripten_glGetIntegerv = (name_, p) => emscriptenWebGLGet(name_, p, 0); var _glGetIntegerv = _emscripten_glGetIntegerv; var _emscripten_glGetProgramiv = (program, pname, p) => { if (!p) { // GLES2 specification does not specify how to behave if p is a null // pointer. Since calling this function does not make sense if p == null, // issue a GL error to notify user about it. GL.recordError(1281); return; } if (program >= GL.counter) { GL.recordError(1281); return; } program = GL.programs[program]; if (pname == 35716) { // GL_INFO_LOG_LENGTH var log = GLctx.getProgramInfoLog(program); if (log === null) log = "(unknown error)"; HEAP32[((p) >> 2)] = log.length + 1; } else if (pname == 35719) { if (!program.maxUniformLength) { var numActiveUniforms = GLctx.getProgramParameter(program, 35718); for (var i = 0; i < numActiveUniforms; ++i) { program.maxUniformLength = Math.max(program.maxUniformLength, GLctx.getActiveUniform(program, i).name.length + 1); } } HEAP32[((p) >> 2)] = program.maxUniformLength; } else if (pname == 35722) { if (!program.maxAttributeLength) { var numActiveAttributes = GLctx.getProgramParameter(program, 35721); for (var i = 0; i < numActiveAttributes; ++i) { program.maxAttributeLength = Math.max(program.maxAttributeLength, GLctx.getActiveAttrib(program, i).name.length + 1); } } HEAP32[((p) >> 2)] = program.maxAttributeLength; } else if (pname == 35381) { if (!program.maxUniformBlockNameLength) { var numActiveUniformBlocks = GLctx.getProgramParameter(program, 35382); for (var i = 0; i < numActiveUniformBlocks; ++i) { program.maxUniformBlockNameLength = Math.max(program.maxUniformBlockNameLength, GLctx.getActiveUniformBlockName(program, i).length + 1); } } HEAP32[((p) >> 2)] = program.maxUniformBlockNameLength; } else { HEAP32[((p) >> 2)] = GLctx.getProgramParameter(program, pname); } }; var _glGetProgramiv = _emscripten_glGetProgramiv; var _emscripten_glGetShaderInfoLog = (shader, maxLength, length, infoLog) => { var log = GLctx.getShaderInfoLog(GL.shaders[shader]); if (log === null) log = "(unknown error)"; var numBytesWrittenExclNull = (maxLength > 0 && infoLog) ? stringToUTF8(log, infoLog, maxLength) : 0; if (length) HEAP32[((length) >> 2)] = numBytesWrittenExclNull; }; var _glGetShaderInfoLog = _emscripten_glGetShaderInfoLog; var _emscripten_glGetShaderiv = (shader, pname, p) => { if (!p) { // GLES2 specification does not specify how to behave if p is a null // pointer. Since calling this function does not make sense if p == null, // issue a GL error to notify user about it. GL.recordError(1281); return; } if (pname == 35716) { // GL_INFO_LOG_LENGTH var log = GLctx.getShaderInfoLog(GL.shaders[shader]); if (log === null) log = "(unknown error)"; // The GLES2 specification says that if the shader has an empty info log, // a value of 0 is returned. Otherwise the log has a null char appended. // (An empty string is falsey, so we can just check that instead of // looking at log.length.) var logLength = log ? log.length + 1 : 0; HEAP32[((p) >> 2)] = logLength; } else if (pname == 35720) { // GL_SHADER_SOURCE_LENGTH var source = GLctx.getShaderSource(GL.shaders[shader]); // source may be a null, or the empty string, both of which are falsey // values that we report a 0 length for. var sourceLength = source ? source.length + 1 : 0; HEAP32[((p) >> 2)] = sourceLength; } else { HEAP32[((p) >> 2)] = GLctx.getShaderParameter(GL.shaders[shader], pname); } }; var _glGetShaderiv = _emscripten_glGetShaderiv; var _emscripten_glGetString = name_ => { var ret = GL.stringCache[name_]; if (!ret) { switch (name_) { case 7939: ret = stringToNewUTF8(webglGetExtensions().join(" ")); break; case 7936: case 7937: case 37445: case 37446: var s = GLctx.getParameter(name_); if (!s) { GL.recordError(1280); } ret = s ? stringToNewUTF8(s) : 0; break; case 7938: var webGLVersion = GLctx.getParameter(7938); // return GLES version string corresponding to the version of the WebGL context var glVersion = `OpenGL ES 2.0 (${webGLVersion})`; if (GL.currentContext.version >= 2) glVersion = `OpenGL ES 3.0 (${webGLVersion})`; ret = stringToNewUTF8(glVersion); break; case 35724: var glslVersion = GLctx.getParameter(35724); // extract the version number 'N.M' from the string 'WebGL GLSL ES N.M ...' var ver_re = /^WebGL GLSL ES ([0-9]\.[0-9][0-9]?)(?:$| .*)/; var ver_num = glslVersion.match(ver_re); if (ver_num !== null) { if (ver_num[1].length == 3) ver_num[1] = ver_num[1] + "0"; // ensure minor version has 2 digits glslVersion = `OpenGL ES GLSL ES ${ver_num[1]} (${glslVersion})`; } ret = stringToNewUTF8(glslVersion); break; default: GL.recordError(1280); } GL.stringCache[name_] = ret; } return ret; }; var _glGetString = _emscripten_glGetString; var _emscripten_glGetUniformBlockIndex = (program, uniformBlockName) => GLctx.getUniformBlockIndex(GL.programs[program], UTF8ToString(uniformBlockName)); var _glGetUniformBlockIndex = _emscripten_glGetUniformBlockIndex; /** @suppress {checkTypes} */ var jstoi_q = str => parseInt(str); /** @noinline */ var webglGetLeftBracePos = name => name.slice(-1) == "]" && name.lastIndexOf("["); var webglPrepareUniformLocationsBeforeFirstUse = program => { var uniformLocsById = program.uniformLocsById, // Maps GLuint -> WebGLUniformLocation uniformSizeAndIdsByName = program.uniformSizeAndIdsByName, // Maps name -> [uniform array length, GLuint] i, j; // On the first time invocation of glGetUniformLocation on this shader program: // initialize cache data structures and discover which uniforms are arrays. if (!uniformLocsById) { // maps GLint integer locations to WebGLUniformLocations program.uniformLocsById = uniformLocsById = {}; // maps integer locations back to uniform name strings, so that we can lazily fetch uniform array locations program.uniformArrayNamesById = {}; var numActiveUniforms = GLctx.getProgramParameter(program, 35718); for (i = 0; i < numActiveUniforms; ++i) { var u = GLctx.getActiveUniform(program, i); var nm = u.name; var sz = u.size; var lb = webglGetLeftBracePos(nm); var arrayName = lb > 0 ? nm.slice(0, lb) : nm; // Assign a new location. var id = program.uniformIdCounter; program.uniformIdCounter += sz; // Eagerly get the location of the uniformArray[0] base element. // The remaining indices >0 will be left for lazy evaluation to // improve performance. Those may never be needed to fetch, if the // application fills arrays always in full starting from the first // element of the array. uniformSizeAndIdsByName[arrayName] = [ sz, id ]; // Store placeholder integers in place that highlight that these // >0 index locations are array indices pending population. for (j = 0; j < sz; ++j) { uniformLocsById[id] = j; program.uniformArrayNamesById[id++] = arrayName; } } } }; var _emscripten_glGetUniformLocation = (program, name) => { name = UTF8ToString(name); if (program = GL.programs[program]) { webglPrepareUniformLocationsBeforeFirstUse(program); var uniformLocsById = program.uniformLocsById; // Maps GLuint -> WebGLUniformLocation var arrayIndex = 0; var uniformBaseName = name; // Invariant: when populating integer IDs for uniform locations, we must // maintain the precondition that arrays reside in contiguous addresses, // i.e. for a 'vec4 colors[10];', colors[4] must be at location // colors[0]+4. However, user might call glGetUniformLocation(program, // "colors") for an array, so we cannot discover based on the user input // arguments whether the uniform we are dealing with is an array. The only // way to discover which uniforms are arrays is to enumerate over all the // active uniforms in the program. var leftBrace = webglGetLeftBracePos(name); // If user passed an array accessor "[index]", parse the array index off the accessor. if (leftBrace > 0) { arrayIndex = jstoi_q(name.slice(leftBrace + 1)) >>> 0; // "index]", coerce parseInt(']') with >>>0 to treat "foo[]" as "foo[0]" and foo[-1] as unsigned out-of-bounds. uniformBaseName = name.slice(0, leftBrace); } // Have we cached the location of this uniform before? // A pair [array length, GLint of the uniform location] var sizeAndId = program.uniformSizeAndIdsByName[uniformBaseName]; // If a uniform with this name exists, and if its index is within the // array limits (if it's even an array), query the WebGLlocation, or // return an existing cached location. if (sizeAndId && arrayIndex < sizeAndId[0]) { arrayIndex += sizeAndId[1]; // Add the base location of the uniform to the array index offset. if ((uniformLocsById[arrayIndex] = uniformLocsById[arrayIndex] || GLctx.getUniformLocation(program, name))) { return arrayIndex; } } } else { // N.b. we are currently unable to distinguish between GL program IDs that // never existed vs GL program IDs that have been deleted, so report // GL_INVALID_VALUE in both cases. GL.recordError(1281); } return -1; }; var _glGetUniformLocation = _emscripten_glGetUniformLocation; var _emscripten_glLineWidth = x0 => GLctx.lineWidth(x0); var _glLineWidth = _emscripten_glLineWidth; var _emscripten_glLinkProgram = program => { program = GL.programs[program]; GLctx.linkProgram(program); // Invalidate earlier computed uniform->ID mappings, those have now become stale program.uniformLocsById = 0; // Mark as null-like so that glGetUniformLocation() knows to populate this again. program.uniformSizeAndIdsByName = {}; }; var _glLinkProgram = _emscripten_glLinkProgram; var _emscripten_glPixelStorei = (pname, param) => { if (pname == 3317) { GL.unpackAlignment = param; } else if (pname == 3314) { GL.unpackRowLength = param; } GLctx.pixelStorei(pname, param); }; var _glPixelStorei = _emscripten_glPixelStorei; var computeUnpackAlignedImageSize = (width, height, sizePerPixel) => { function roundedToNextMultipleOf(x, y) { return (x + y - 1) & -y; } var plainRowSize = (GL.unpackRowLength || width) * sizePerPixel; var alignedRowSize = roundedToNextMultipleOf(plainRowSize, GL.unpackAlignment); return height * alignedRowSize; }; var colorChannelsInGlTextureFormat = format => { // Micro-optimizations for size: map format to size by subtracting smallest // enum value (0x1902) from all values first. Also omit the most common // size value (1) from the list, which is assumed by formats not on the // list. var colorChannels = { // 0x1902 /* GL_DEPTH_COMPONENT */ - 0x1902: 1, // 0x1906 /* GL_ALPHA */ - 0x1902: 1, 5: 3, 6: 4, // 0x1909 /* GL_LUMINANCE */ - 0x1902: 1, 8: 2, 29502: 3, 29504: 4, // 0x1903 /* GL_RED */ - 0x1902: 1, 26917: 2, 26918: 2, // 0x8D94 /* GL_RED_INTEGER */ - 0x1902: 1, 29846: 3, 29847: 4 }; return colorChannels[format - 6402] || 1; }; var heapObjectForWebGLType = type => { // Micro-optimization for size: Subtract lowest GL enum number (0x1400/* GL_BYTE */) from type to compare // smaller values for the heap, for shorter generated code size. // Also the type HEAPU16 is not tested for explicitly, but any unrecognized type will return out HEAPU16. // (since most types are HEAPU16) type -= 5120; if (type == 0) return HEAP8; if (type == 1) return HEAPU8; if (type == 2) return HEAP16; if (type == 4) return HEAP32; if (type == 6) return HEAPF32; if (type == 5 || type == 28922 || type == 28520 || type == 30779 || type == 30782) return HEAPU32; return HEAPU16; }; var toTypedArrayIndex = (pointer, heap) => pointer >>> (31 - Math.clz32(heap.BYTES_PER_ELEMENT)); var emscriptenWebGLGetTexPixelData = (type, format, width, height, pixels, internalFormat) => { var heap = heapObjectForWebGLType(type); var sizePerPixel = colorChannelsInGlTextureFormat(format) * heap.BYTES_PER_ELEMENT; var bytes = computeUnpackAlignedImageSize(width, height, sizePerPixel); return heap.subarray(toTypedArrayIndex(pixels, heap), toTypedArrayIndex(pixels + bytes, heap)); }; var _emscripten_glReadPixels = (x, y, width, height, format, type, pixels) => { if (GL.currentContext.version >= 2) { if (GLctx.currentPixelPackBufferBinding) { GLctx.readPixels(x, y, width, height, format, type, pixels); return; } var heap = heapObjectForWebGLType(type); var target = toTypedArrayIndex(pixels, heap); GLctx.readPixels(x, y, width, height, format, type, heap, target); return; } var pixelData = emscriptenWebGLGetTexPixelData(type, format, width, height, pixels, format); if (!pixelData) { GL.recordError(1280); return; } GLctx.readPixels(x, y, width, height, format, type, pixelData); }; var _glReadPixels = _emscripten_glReadPixels; var _emscripten_glShaderSource = (shader, count, string, length) => { var source = GL.getSource(shader, count, string, length); GLctx.shaderSource(GL.shaders[shader], source); }; var _glShaderSource = _emscripten_glShaderSource; var _emscripten_glTexImage2D = (target, level, internalFormat, width, height, border, format, type, pixels) => { if (GL.currentContext.version >= 2) { if (GLctx.currentPixelUnpackBufferBinding) { GLctx.texImage2D(target, level, internalFormat, width, height, border, format, type, pixels); return; } if (pixels) { var heap = heapObjectForWebGLType(type); var index = toTypedArrayIndex(pixels, heap); GLctx.texImage2D(target, level, internalFormat, width, height, border, format, type, heap, index); return; } } var pixelData = pixels ? emscriptenWebGLGetTexPixelData(type, format, width, height, pixels, internalFormat) : null; GLctx.texImage2D(target, level, internalFormat, width, height, border, format, type, pixelData); }; var _glTexImage2D = _emscripten_glTexImage2D; var _emscripten_glTexParameterf = (x0, x1, x2) => GLctx.texParameterf(x0, x1, x2); var _glTexParameterf = _emscripten_glTexParameterf; var _emscripten_glTexParameterfv = (target, pname, params) => { var param = HEAPF32[((params) >> 2)]; GLctx.texParameterf(target, pname, param); }; var _glTexParameterfv = _emscripten_glTexParameterfv; var _emscripten_glTexParameteri = (x0, x1, x2) => GLctx.texParameteri(x0, x1, x2); var _glTexParameteri = _emscripten_glTexParameteri; var _emscripten_glTexStorage2D = (x0, x1, x2, x3, x4) => GLctx.texStorage2D(x0, x1, x2, x3, x4); var _glTexStorage2D = _emscripten_glTexStorage2D; var _emscripten_glTexStorage3D = (x0, x1, x2, x3, x4, x5) => GLctx.texStorage3D(x0, x1, x2, x3, x4, x5); var _glTexStorage3D = _emscripten_glTexStorage3D; var _emscripten_glTexSubImage2D = (target, level, xoffset, yoffset, width, height, format, type, pixels) => { if (GL.currentContext.version >= 2) { if (GLctx.currentPixelUnpackBufferBinding) { GLctx.texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels); return; } if (pixels) { var heap = heapObjectForWebGLType(type); GLctx.texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, heap, toTypedArrayIndex(pixels, heap)); return; } } var pixelData = pixels ? emscriptenWebGLGetTexPixelData(type, format, width, height, pixels, 0) : null; GLctx.texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixelData); }; var _glTexSubImage2D = _emscripten_glTexSubImage2D; var _emscripten_glTexSubImage3D = (target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels) => { if (GLctx.currentPixelUnpackBufferBinding) { GLctx.texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels); } else if (pixels) { var heap = heapObjectForWebGLType(type); GLctx.texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, heap, toTypedArrayIndex(pixels, heap)); } else { GLctx.texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, null); } }; var _glTexSubImage3D = _emscripten_glTexSubImage3D; var webglGetUniformLocation = location => { var p = GLctx.currentProgram; if (p) { var webglLoc = p.uniformLocsById[location]; // p.uniformLocsById[location] stores either an integer, or a // WebGLUniformLocation. // If an integer, we have not yet bound the location, so do it now. The // integer value specifies the array index we should bind to. if (typeof webglLoc == "number") { p.uniformLocsById[location] = webglLoc = GLctx.getUniformLocation(p, p.uniformArrayNamesById[location] + (webglLoc > 0 ? `[${webglLoc}]` : "")); } // Else an already cached WebGLUniformLocation, return it. return webglLoc; } else { GL.recordError(1282); } }; var _emscripten_glUniform1f = (location, v0) => { GLctx.uniform1f(webglGetUniformLocation(location), v0); }; var _glUniform1f = _emscripten_glUniform1f; var miniTempWebGLFloatBuffers = []; var _emscripten_glUniform1fv = (location, count, value) => { if (GL.currentContext.version >= 2) { count && GLctx.uniform1fv(webglGetUniformLocation(location), HEAPF32, ((value) >> 2), count); return; } if (count <= 288) { // avoid allocation when uploading few enough uniforms var view = miniTempWebGLFloatBuffers[count]; for (var i = 0; i < count; ++i) { view[i] = HEAPF32[(((value) + (4 * i)) >> 2)]; } } else { var view = HEAPF32.subarray((((value) >> 2)), ((value + count * 4) >> 2)); } GLctx.uniform1fv(webglGetUniformLocation(location), view); }; var _glUniform1fv = _emscripten_glUniform1fv; var _emscripten_glUniform1i = (location, v0) => { GLctx.uniform1i(webglGetUniformLocation(location), v0); }; var _glUniform1i = _emscripten_glUniform1i; var _emscripten_glUniform2f = (location, v0, v1) => { GLctx.uniform2f(webglGetUniformLocation(location), v0, v1); }; var _glUniform2f = _emscripten_glUniform2f; var _emscripten_glUniform2fv = (location, count, value) => { if (GL.currentContext.version >= 2) { count && GLctx.uniform2fv(webglGetUniformLocation(location), HEAPF32, ((value) >> 2), count * 2); return; } if (count <= 144) { // avoid allocation when uploading few enough uniforms count *= 2; var view = miniTempWebGLFloatBuffers[count]; for (var i = 0; i < count; i += 2) { view[i] = HEAPF32[(((value) + (4 * i)) >> 2)]; view[i + 1] = HEAPF32[(((value) + (4 * i + 4)) >> 2)]; } } else { var view = HEAPF32.subarray((((value) >> 2)), ((value + count * 8) >> 2)); } GLctx.uniform2fv(webglGetUniformLocation(location), view); }; var _glUniform2fv = _emscripten_glUniform2fv; var _emscripten_glUniform3f = (location, v0, v1, v2) => { GLctx.uniform3f(webglGetUniformLocation(location), v0, v1, v2); }; var _glUniform3f = _emscripten_glUniform3f; var _emscripten_glUniform4f = (location, v0, v1, v2, v3) => { GLctx.uniform4f(webglGetUniformLocation(location), v0, v1, v2, v3); }; var _glUniform4f = _emscripten_glUniform4f; var _emscripten_glUniform4fv = (location, count, value) => { if (GL.currentContext.version >= 2) { count && GLctx.uniform4fv(webglGetUniformLocation(location), HEAPF32, ((value) >> 2), count * 4); return; } if (count <= 72) { // avoid allocation when uploading few enough uniforms var view = miniTempWebGLFloatBuffers[4 * count]; // hoist the heap out of the loop for size and for pthreads+growth. var heap = HEAPF32; value = ((value) >> 2); count *= 4; for (var i = 0; i < count; i += 4) { var dst = value + i; view[i] = heap[dst]; view[i + 1] = heap[dst + 1]; view[i + 2] = heap[dst + 2]; view[i + 3] = heap[dst + 3]; } } else { var view = HEAPF32.subarray((((value) >> 2)), ((value + count * 16) >> 2)); } GLctx.uniform4fv(webglGetUniformLocation(location), view); }; var _glUniform4fv = _emscripten_glUniform4fv; var miniTempWebGLIntBuffers = []; var _emscripten_glUniform4iv = (location, count, value) => { if (GL.currentContext.version >= 2) { count && GLctx.uniform4iv(webglGetUniformLocation(location), HEAP32, ((value) >> 2), count * 4); return; } if (count <= 72) { // avoid allocation when uploading few enough uniforms count *= 4; var view = miniTempWebGLIntBuffers[count]; for (var i = 0; i < count; i += 4) { view[i] = HEAP32[(((value) + (4 * i)) >> 2)]; view[i + 1] = HEAP32[(((value) + (4 * i + 4)) >> 2)]; view[i + 2] = HEAP32[(((value) + (4 * i + 8)) >> 2)]; view[i + 3] = HEAP32[(((value) + (4 * i + 12)) >> 2)]; } } else { var view = HEAP32.subarray((((value) >> 2)), ((value + count * 16) >> 2)); } GLctx.uniform4iv(webglGetUniformLocation(location), view); }; var _glUniform4iv = _emscripten_glUniform4iv; var _emscripten_glUniformBlockBinding = (program, uniformBlockIndex, uniformBlockBinding) => { program = GL.programs[program]; GLctx.uniformBlockBinding(program, uniformBlockIndex, uniformBlockBinding); }; var _glUniformBlockBinding = _emscripten_glUniformBlockBinding; var _emscripten_glUniformMatrix2fv = (location, count, transpose, value) => { if (GL.currentContext.version >= 2) { count && GLctx.uniformMatrix2fv(webglGetUniformLocation(location), !!transpose, HEAPF32, ((value) >> 2), count * 4); return; } if (count <= 72) { // avoid allocation when uploading few enough uniforms count *= 4; var view = miniTempWebGLFloatBuffers[count]; for (var i = 0; i < count; i += 4) { view[i] = HEAPF32[(((value) + (4 * i)) >> 2)]; view[i + 1] = HEAPF32[(((value) + (4 * i + 4)) >> 2)]; view[i + 2] = HEAPF32[(((value) + (4 * i + 8)) >> 2)]; view[i + 3] = HEAPF32[(((value) + (4 * i + 12)) >> 2)]; } } else { var view = HEAPF32.subarray((((value) >> 2)), ((value + count * 16) >> 2)); } GLctx.uniformMatrix2fv(webglGetUniformLocation(location), !!transpose, view); }; var _glUniformMatrix2fv = _emscripten_glUniformMatrix2fv; var _emscripten_glUniformMatrix3fv = (location, count, transpose, value) => { if (GL.currentContext.version >= 2) { count && GLctx.uniformMatrix3fv(webglGetUniformLocation(location), !!transpose, HEAPF32, ((value) >> 2), count * 9); return; } if (count <= 32) { // avoid allocation when uploading few enough uniforms count *= 9; var view = miniTempWebGLFloatBuffers[count]; for (var i = 0; i < count; i += 9) { view[i] = HEAPF32[(((value) + (4 * i)) >> 2)]; view[i + 1] = HEAPF32[(((value) + (4 * i + 4)) >> 2)]; view[i + 2] = HEAPF32[(((value) + (4 * i + 8)) >> 2)]; view[i + 3] = HEAPF32[(((value) + (4 * i + 12)) >> 2)]; view[i + 4] = HEAPF32[(((value) + (4 * i + 16)) >> 2)]; view[i + 5] = HEAPF32[(((value) + (4 * i + 20)) >> 2)]; view[i + 6] = HEAPF32[(((value) + (4 * i + 24)) >> 2)]; view[i + 7] = HEAPF32[(((value) + (4 * i + 28)) >> 2)]; view[i + 8] = HEAPF32[(((value) + (4 * i + 32)) >> 2)]; } } else { var view = HEAPF32.subarray((((value) >> 2)), ((value + count * 36) >> 2)); } GLctx.uniformMatrix3fv(webglGetUniformLocation(location), !!transpose, view); }; var _glUniformMatrix3fv = _emscripten_glUniformMatrix3fv; var _emscripten_glUniformMatrix4fv = (location, count, transpose, value) => { if (GL.currentContext.version >= 2) { count && GLctx.uniformMatrix4fv(webglGetUniformLocation(location), !!transpose, HEAPF32, ((value) >> 2), count * 16); return; } if (count <= 18) { // avoid allocation when uploading few enough uniforms var view = miniTempWebGLFloatBuffers[16 * count]; // hoist the heap out of the loop for size and for pthreads+growth. var heap = HEAPF32; value = ((value) >> 2); count *= 16; for (var i = 0; i < count; i += 16) { var dst = value + i; view[i] = heap[dst]; view[i + 1] = heap[dst + 1]; view[i + 2] = heap[dst + 2]; view[i + 3] = heap[dst + 3]; view[i + 4] = heap[dst + 4]; view[i + 5] = heap[dst + 5]; view[i + 6] = heap[dst + 6]; view[i + 7] = heap[dst + 7]; view[i + 8] = heap[dst + 8]; view[i + 9] = heap[dst + 9]; view[i + 10] = heap[dst + 10]; view[i + 11] = heap[dst + 11]; view[i + 12] = heap[dst + 12]; view[i + 13] = heap[dst + 13]; view[i + 14] = heap[dst + 14]; view[i + 15] = heap[dst + 15]; } } else { var view = HEAPF32.subarray((((value) >> 2)), ((value + count * 64) >> 2)); } GLctx.uniformMatrix4fv(webglGetUniformLocation(location), !!transpose, view); }; var _glUniformMatrix4fv = _emscripten_glUniformMatrix4fv; var _emscripten_glUseProgram = program => { program = GL.programs[program]; GLctx.useProgram(program); // Record the currently active program so that we can access the uniform // mapping table of that program. GLctx.currentProgram = program; }; var _glUseProgram = _emscripten_glUseProgram; var _emscripten_glVertexAttribPointer = (index, size, type, normalized, stride, ptr) => { var cb = GL.currentContext.clientBuffers[index]; if (!GLctx.currentArrayBufferBinding) { cb.size = size; cb.type = type; cb.normalized = normalized; cb.stride = stride; cb.ptr = ptr; cb.clientside = true; cb.vertexAttribPointerAdaptor = function(index, size, type, normalized, stride, ptr) { this.vertexAttribPointer(index, size, type, normalized, stride, ptr); }; return; } cb.clientside = false; GLctx.vertexAttribPointer(index, size, type, !!normalized, stride, ptr); }; var _glVertexAttribPointer = _emscripten_glVertexAttribPointer; var _emscripten_glViewport = (x0, x1, x2, x3) => GLctx.viewport(x0, x1, x2, x3); var _glViewport = _emscripten_glViewport; function _mediapipe_find_canvas_event_target(canvasSelector) { let target = findCanvasEventTarget(canvasSelector); // WebGPU-on-worker uses this function to try to grab the canvas, but // doesn't have a DOM element to find. So as a quick patch, if the default // behavior is unsuccessful here then we try a webgpu canvas property // which is set by the user directly on the Module, much like how our old // pipeline used the Module.canvas property. See b/265271517 for details. if (Module && !target) { target = Module.canvasWebGpu; } return Emval.toHandle(target); } function _mediapipe_webgl_tex_image_drawable(drawableHandle) { const drawable = Emval.toValue(drawableHandle); GLctx.texImage2D(GLctx.TEXTURE_2D, 0, GLctx.RGBA, GLctx.RGBA, GLctx.UNSIGNED_BYTE, drawable); } function _random_get(buffer, size) { try { randomFill(HEAPU8.subarray(buffer, buffer + size)); return 0; } catch (e) { if (typeof FS == "undefined" || !(e.name === "ErrnoError")) throw e; return e.errno; } } var _wgpuCommandEncoderBeginComputePass = (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; }; var _wgpuCommandEncoderBeginRenderPass = (encoderPtr, descriptor) => { function makeColorAttachment(caPtr) { var viewPtr = HEAPU32[(((caPtr) + (4)) >> 2)]; if (viewPtr === 0) { // Null `view` means no attachment in this slot. return undefined; } var depthSlice = HEAPU32[(((caPtr) + (8)) >> 2)]; if (depthSlice == 4294967295) depthSlice = undefined; return { "view": WebGPU.getJsObject(viewPtr), "depthSlice": depthSlice, "resolveTarget": WebGPU.getJsObject(HEAPU32[(((caPtr) + (12)) >> 2)]), "clearValue": WebGPU.makeColor(caPtr + 24), "loadOp": WebGPU.LoadOp[HEAP32[(((caPtr) + (16)) >> 2)]], "storeOp": WebGPU.StoreOp[HEAP32[(((caPtr) + (20)) >> 2)]] }; } function makeColorAttachments(count, caPtr) { var attachments = []; for (var i = 0; i < count; ++i) { attachments.push(makeColorAttachment(caPtr + 56 * i)); } return attachments; } function makeDepthStencilAttachment(dsaPtr) { if (dsaPtr === 0) return undefined; return { "view": WebGPU.getJsObject(HEAPU32[(((dsaPtr) + (4)) >> 2)]), "depthClearValue": HEAPF32[(((dsaPtr) + (16)) >> 2)], "depthLoadOp": WebGPU.LoadOp[HEAP32[(((dsaPtr) + (8)) >> 2)]], "depthStoreOp": WebGPU.StoreOp[HEAP32[(((dsaPtr) + (12)) >> 2)]], "depthReadOnly": !!(HEAPU32[(((dsaPtr) + (20)) >> 2)]), "stencilClearValue": HEAPU32[(((dsaPtr) + (32)) >> 2)], "stencilLoadOp": WebGPU.LoadOp[HEAP32[(((dsaPtr) + (24)) >> 2)]], "stencilStoreOp": WebGPU.StoreOp[HEAP32[(((dsaPtr) + (28)) >> 2)]], "stencilReadOnly": !!(HEAPU32[(((dsaPtr) + (36)) >> 2)]) }; } function makeRenderPassDescriptor(descriptor) { var nextInChainPtr = HEAPU32[((descriptor) >> 2)]; var maxDrawCount = undefined; if (nextInChainPtr !== 0) { var sType = HEAP32[(((nextInChainPtr) + (4)) >> 2)]; var renderPassMaxDrawCount = nextInChainPtr; // Note: The user could have passed a really huge value here, which is technically valid in // C but will not be allowed by WebGPU in JS because of [EnforceRange]. We intentionally // ignore that case because it's not useful - apps can just pick a smaller maxDrawCount. maxDrawCount = readI53FromI64((renderPassMaxDrawCount) + (8)); } var desc = { "label": WebGPU.makeStringFromOptionalStringView(descriptor + 4), "colorAttachments": makeColorAttachments(HEAPU32[(((descriptor) + (12)) >> 2)], HEAPU32[(((descriptor) + (16)) >> 2)]), "depthStencilAttachment": makeDepthStencilAttachment(HEAPU32[(((descriptor) + (20)) >> 2)]), "occlusionQuerySet": WebGPU.getJsObject(HEAPU32[(((descriptor) + (24)) >> 2)]), "timestampWrites": WebGPU.makePassTimestampWrites(HEAPU32[(((descriptor) + (28)) >> 2)]), "maxDrawCount": maxDrawCount }; return desc; } var desc = makeRenderPassDescriptor(descriptor); var commandEncoder = WebGPU.getJsObject(encoderPtr); var ptr = _emwgpuCreateRenderPassEncoder(0); WebGPU.Internals.jsObjectInsert(ptr, commandEncoder.beginRenderPass(desc)); return ptr; }; var _wgpuCommandEncoderCopyBufferToTexture = (encoderPtr, srcPtr, dstPtr, copySizePtr) => { var commandEncoder = WebGPU.getJsObject(encoderPtr); var copySize = WebGPU.makeExtent3D(copySizePtr); commandEncoder.copyBufferToTexture(WebGPU.makeTexelCopyBufferInfo(srcPtr), WebGPU.makeTexelCopyTextureInfo(dstPtr), copySize); }; var _wgpuCommandEncoderCopyTextureToBuffer = (encoderPtr, srcPtr, dstPtr, copySizePtr) => { var commandEncoder = WebGPU.getJsObject(encoderPtr); var copySize = WebGPU.makeExtent3D(copySizePtr); commandEncoder.copyTextureToBuffer(WebGPU.makeTexelCopyTextureInfo(srcPtr), WebGPU.makeTexelCopyBufferInfo(dstPtr), copySize); }; var _wgpuCommandEncoderCopyTextureToTexture = (encoderPtr, srcPtr, dstPtr, copySizePtr) => { var commandEncoder = WebGPU.getJsObject(encoderPtr); var copySize = WebGPU.makeExtent3D(copySizePtr); commandEncoder.copyTextureToTexture(WebGPU.makeTexelCopyTextureInfo(srcPtr), WebGPU.makeTexelCopyTextureInfo(dstPtr), copySize); }; var _wgpuCommandEncoderFinish = (encoderPtr, descriptor) => { // TODO: Use the descriptor. var commandEncoder = WebGPU.getJsObject(encoderPtr); var ptr = _emwgpuCreateCommandBuffer(0); WebGPU.Internals.jsObjectInsert(ptr, commandEncoder.finish()); return ptr; }; var _wgpuComputePassEncoderDispatchWorkgroups = (passPtr, x, y, z) => { var pass = WebGPU.getJsObject(passPtr); pass.dispatchWorkgroups(x, y, z); }; var _wgpuComputePassEncoderEnd = passPtr => { var pass = WebGPU.getJsObject(passPtr); pass.end(); }; var _wgpuComputePassEncoderSetBindGroup = (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); } }; var _wgpuComputePassEncoderSetPipeline = (passPtr, pipelinePtr) => { var pass = WebGPU.getJsObject(passPtr); var pipeline = WebGPU.getJsObject(pipelinePtr); pass.setPipeline(pipeline); }; var _wgpuComputePipelineGetBindGroupLayout = (pipelinePtr, groupIndex) => { var pipeline = WebGPU.getJsObject(pipelinePtr); var ptr = _emwgpuCreateBindGroupLayout(0); WebGPU.Internals.jsObjectInsert(ptr, pipeline.getBindGroupLayout(groupIndex)); return ptr; }; var _wgpuDeviceCreateBindGroup = (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) { // Note the sentinel UINT64_MAX will be read as -1. var size = readI53FromI64((entryPtr) + (24)); if (size == -1) size = undefined; resource = { "buffer": WebGPU.getJsObject(bufferPtr), "offset": readI53FromI64((entryPtr) + (16)), "size": size }; } else { resource = WebGPU.getJsObject(samplerPtr || textureViewPtr || externalTexturePtr); } return { "binding": HEAPU32[(((entryPtr) + (4)) >> 2)], "resource": resource }; } function makeEntries(count, entriesPtrs) { var entries = []; for (var i = 0; i < count; ++i) { entries.push(makeEntry(entriesPtrs + 40 * i)); } return entries; } var desc = { "label": WebGPU.makeStringFromOptionalStringView(descriptor + 4), "layout": WebGPU.getJsObject(HEAPU32[(((descriptor) + (12)) >> 2)]), "entries": makeEntries(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; }; var _wgpuDeviceCreateBindGroupLayout = (devicePtr, descriptor) => { function makeBufferEntry(substructPtr) { var typeInt = HEAPU32[(((substructPtr) + (4)) >> 2)]; if (!typeInt) return undefined; 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 undefined; return { "type": WebGPU.SamplerBindingType[typeInt] }; } function makeTextureEntry(substructPtr) { var sampleTypeInt = HEAPU32[(((substructPtr) + (4)) >> 2)]; if (!sampleTypeInt) return undefined; 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 undefined; 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: ptr => { entry["externalTexture"] = {}; } }); return entry; } function makeEntries(count, entriesPtrs) { var entries = []; for (var i = 0; i < count; ++i) { entries.push(makeEntry(entriesPtrs + 88 * i)); } return entries; } var desc = { "label": WebGPU.makeStringFromOptionalStringView(descriptor + 4), "entries": makeEntries(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; }; var _wgpuDeviceCreateCommandEncoder = (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; }; var _wgpuDeviceCreateComputePipeline = (devicePtr, descriptor) => { var desc = WebGPU.makeComputePipelineDesc(descriptor); var device = WebGPU.getJsObject(devicePtr); var ptr = _emwgpuCreateComputePipeline(0); WebGPU.Internals.jsObjectInsert(ptr, device.createComputePipeline(desc)); return ptr; }; var _wgpuDeviceCreatePipelineLayout = (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 }; var device = WebGPU.getJsObject(devicePtr); var ptr = _emwgpuCreatePipelineLayout(0); WebGPU.Internals.jsObjectInsert(ptr, device.createPipelineLayout(desc)); return ptr; }; var _wgpuDeviceCreateRenderPipeline = (devicePtr, descriptor) => { var desc = WebGPU.makeRenderPipelineDesc(descriptor); var device = WebGPU.getJsObject(devicePtr); var ptr = _emwgpuCreateRenderPipeline(0); WebGPU.Internals.jsObjectInsert(ptr, device.createRenderPipeline(desc)); return ptr; }; var _wgpuDeviceCreateSampler = (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; }; var _wgpuDeviceCreateTexture = (devicePtr, descriptor) => { var nextInChainPtr = HEAPU32[((descriptor) >> 2)]; var textureBindingViewDimension; if (nextInChainPtr !== 0) { var sType = 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": textureBindingViewDimension }; var viewFormatCount = HEAPU32[(((descriptor) + (52)) >> 2)]; if (viewFormatCount) { var viewFormatsPtr = HEAPU32[(((descriptor) + (56)) >> 2)]; // viewFormatsPtr pointer to an array of TextureFormat which is an enum of size uint32_t 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; }; var _wgpuQueueSubmit = (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); }; function _wgpuQueueWriteBuffer(queuePtr, bufferPtr, bufferOffset_low, bufferOffset_high, data, size) { var bufferOffset = convertI32PairToI53Checked(bufferOffset_low, bufferOffset_high); var queue = WebGPU.getJsObject(queuePtr); var buffer = WebGPU.getJsObject(bufferPtr); // There is a size limitation for ArrayBufferView. Work around by passing in a subarray // instead of the whole heap. crbug.com/1201109 var subarray = HEAPU8.subarray(data, data + size); queue.writeBuffer(buffer, bufferOffset, subarray, 0, size); } var _wgpuQueueWriteTexture = (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); // This subarray isn't strictly necessary, but helps work around an issue // where Chromium makes a copy of the entire heap. crbug.com/1134457 var subarray = HEAPU8.subarray(data, data + dataSize); queue.writeTexture(destination, subarray, dataLayout, writeSize); }; var _wgpuRenderPassEncoderDraw = (passPtr, vertexCount, instanceCount, firstVertex, firstInstance) => { firstVertex >>>= 0; firstInstance >>>= 0; var pass = WebGPU.getJsObject(passPtr); pass.draw(vertexCount, instanceCount, firstVertex, firstInstance); }; var _wgpuRenderPassEncoderEnd = encoderPtr => { var encoder = WebGPU.getJsObject(encoderPtr); encoder.end(); }; var _wgpuRenderPassEncoderSetBindGroup = (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); } }; var _wgpuRenderPassEncoderSetPipeline = (passPtr, pipelinePtr) => { var pass = WebGPU.getJsObject(passPtr); var pipeline = WebGPU.getJsObject(pipelinePtr); pass.setPipeline(pipeline); }; var _wgpuRenderPipelineGetBindGroupLayout = (pipelinePtr, groupIndex) => { var pipeline = WebGPU.getJsObject(pipelinePtr); var ptr = _emwgpuCreateBindGroupLayout(0); WebGPU.Internals.jsObjectInsert(ptr, pipeline.getBindGroupLayout(groupIndex)); return ptr; }; var _wgpuTextureCreateView = (texturePtr, descriptor) => { var desc; if (descriptor) { var swizzle; var nextInChainPtr = HEAPU32[((descriptor) >> 2)]; if (nextInChainPtr !== 0) { var sType = 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 ? undefined : mipLevelCount, "baseArrayLayer": HEAPU32[(((descriptor) + (28)) >> 2)], "arrayLayerCount": arrayLayerCount === 4294967295 ? undefined : arrayLayerCount, "aspect": WebGPU.TextureAspect[HEAP32[(((descriptor) + (36)) >> 2)]], "usage": HEAPU32[(((descriptor) + (40)) >> 2)], "swizzle": swizzle }; } var texture = WebGPU.getJsObject(texturePtr); var ptr = _emwgpuCreateTextureView(0); WebGPU.Internals.jsObjectInsert(ptr, texture.createView(desc)); return ptr; }; var _wgpuTextureDestroy = texturePtr => { WebGPU.getJsObject(texturePtr).destroy(); }; var _wgpuTextureGetFormat = texturePtr => { var texture = WebGPU.getJsObject(texturePtr); // Should return the enum integer instead of string. return WebGPU.TextureFormat.indexOf(texture.format); }; var getCFunc = ident => { var func = Module["_" + ident]; // closure exported function return func; }; var writeArrayToMemory = (array, buffer) => { HEAP8.set(array, buffer); }; /** * @param {string|null=} returnType * @param {Array=} argTypes * @param {Array=} args * @param {Object=} opts */ var ccall = (ident, returnType, argTypes, args, opts) => { // For fast lookup of conversion functions var toC = { "string": str => { var ret = 0; if (str !== null && str !== undefined && str !== 0) { // null string ret = stringToUTF8OnStack(str); } return ret; }, "array": arr => { var ret = stackAlloc(arr.length); writeArrayToMemory(arr, ret); return ret; } }; function convertReturnValue(ret) { if (returnType === "string") { return UTF8ToString(ret); } if (returnType === "boolean") return Boolean(ret); return ret; } var func = getCFunc(ident); var cArgs = []; var stack = 0; if (args) { for (var i = 0; i < args.length; i++) { var converter = toC[argTypes[i]]; if (converter) { if (stack === 0) stack = stackSave(); cArgs[i] = converter(args[i]); } else { cArgs[i] = args[i]; } } } var ret = func(...cArgs); function onDone(ret) { if (stack !== 0) stackRestore(stack); return convertReturnValue(ret); } ret = onDone(ret); return ret; }; var FS_createPath = (...args) => FS.createPath(...args); var FS_unlink = (...args) => FS.unlink(...args); var FS_createLazyFile = (...args) => FS.createLazyFile(...args); var FS_createDevice = (...args) => FS.createDevice(...args); FS.createPreloadedFile = FS_createPreloadedFile; FS.preloadFile = FS_preloadFile; FS.staticInit(); // Signal GL rendering layer that processing of a new frame is about to // start. This helps it optimize VBO double-buffering and reduce GPU stalls. registerPreMainLoop(() => GL.newRenderingFrameStarted()); for (let i = 0; i < 32; ++i) tempFixedLengthArray.push(new Array(i)); var miniTempWebGLFloatBuffersStorage = new Float32Array(288); // Create GL_POOL_TEMP_BUFFERS_SIZE+1 temporary buffers, for uploads of size 0 through GL_POOL_TEMP_BUFFERS_SIZE inclusive for (/**@suppress{duplicate}*/ var i = 0; i <= 288; ++i) { miniTempWebGLFloatBuffers[i] = miniTempWebGLFloatBuffersStorage.subarray(0, i); } var miniTempWebGLIntBuffersStorage = new Int32Array(288); // Create GL_POOL_TEMP_BUFFERS_SIZE+1 temporary buffers, for uploads of size 0 through GL_POOL_TEMP_BUFFERS_SIZE inclusive for (/**@suppress{duplicate}*/ var i = 0; i <= 288; ++i) { miniTempWebGLIntBuffers[i] = miniTempWebGLIntBuffersStorage.subarray(0, i); } // End JS library code // include: postlibrary.js // This file is included after the automatically-generated JS library code // but before the wasm module is created. { // Begin ATMODULES hooks if (Module["preloadPlugins"]) preloadPlugins = Module["preloadPlugins"]; if (Module["noExitRuntime"]) noExitRuntime = Module["noExitRuntime"]; if (Module["print"]) out = Module["print"]; if (Module["printErr"]) err = Module["printErr"]; if (Module["wasmBinary"]) wasmBinary = Module["wasmBinary"]; // End ATMODULES hooks if (Module["arguments"]) arguments_ = Module["arguments"]; if (Module["thisProgram"]) thisProgram = Module["thisProgram"]; if (Module["preInit"]) { if (typeof Module["preInit"] == "function") Module["preInit"] = [ Module["preInit"] ]; while (Module["preInit"].length > 0) { Module["preInit"].shift()(); } } } // Begin runtime exports Module["addRunDependency"] = addRunDependency; Module["removeRunDependency"] = removeRunDependency; Module["ccall"] = ccall; Module["stringToNewUTF8"] = stringToNewUTF8; Module["FS_preloadFile"] = FS_preloadFile; Module["FS_unlink"] = FS_unlink; Module["FS_createPath"] = FS_createPath; Module["FS_createDevice"] = FS_createDevice; Module["FS_createDataFile"] = FS_createDataFile; Module["FS_createLazyFile"] = FS_createLazyFile; // End runtime exports // Begin JS library exports // End JS library exports // end include: postlibrary.js var ASM_CONSTS = { 1484179: $0 => { const canvas = Emval.toValue($0); const context = canvas.getContext("webgpu"); return WebGPU.importJsTexture(context.getCurrentTexture()); }, 1484322: ($0, $1, $2, $3, $4) => { const drawable = Emval.toValue($0); const device = WebGPU.getJsObject($1); const texture = WebGPU.getJsObject($2); const width = $3; const height = $4; device.queue.copyExternalImageToTexture({ source: drawable }, { texture }, [ width, height ]); }, 1484581: ($0, $1, $2, $3) => { const sourceExtTex = Emval.toValue($0); const device = WebGPU.getJsObject($1); const sampler = WebGPU.getJsObject($2); const bgLayout = WebGPU.getJsObject($3); const bindGroup = device.createBindGroup({ layout: bgLayout, entries: [ { binding: 0, resource: sampler }, { binding: 1, resource: sourceExtTex } ] }); return WebGPU.importJsBindGroup(bindGroup); }, 1484951: ($0, $1) => { const input = Emval.toValue($0); const output = Emval.toValue($1); const ctx = output.getContext("2d"); ctx.drawImage(input, 0, 0, output.width, output.height); }, 1485116: ($0, $1) => { const inputArray = Emval.toValue($0); const output = Emval.toValue($1); const ctx = output.getContext("2d"); const image_data = new ImageData(inputArray, output.width, output.height); ctx.putImageData(image_data, 0, 0); }, 1485340: ($0, $1) => { const input = Emval.toValue($0); const outputArray = Emval.toValue($1); const ctx = input.getContext("2d"); const data = ctx.getImageData(0, 0, input.width, input.height); outputArray.set(data.data); }, 1485544: () => (typeof HTMLCanvasElement !== "undefined"), 1485599: () => !!Module["preinitializedWebGPUDevice"], 1485650: () => { specialHTMLTargets["#canvas"] = Module.canvas; } }; function BeginGlQueryTiming(calc_name, num_repetitions) { const gl = Module.canvas.getContext("webgl2"); const query = gl.createQuery(); Module.WEBGL_SHADER_CALC_METRICS = Module.WEBGL_SHADER_CALC_METRICS || {}; Module.WEBGL_SHADER_CALC_METRICS[UTF8ToString(calc_name)] = { query, repetitions: num_repetitions }; Module.WEBGL_QUERY_TIMER_EXT = Module.WEBGL_QUERY_TIMER_EXT || gl.getExtension("EXT_disjoint_timer_query_webgl2"); gl.beginQuery(Module.WEBGL_QUERY_TIMER_EXT.TIME_ELAPSED_EXT, query); } function EndGlQueryTiming(calc_name) { const gl = Module.canvas.getContext("webgl2"); gl.endQuery(Module.WEBGL_QUERY_TIMER_EXT.TIME_ELAPSED_EXT, Module.WEBGL_SHADER_CALC_METRICS[UTF8ToString(calc_name)].query); } function JsWrapImageConverter() { if (!Module._imageConverter) { Module._imageConverter = (binaryPtr, binarySize, width, height, numChannels, makeDeepCopy, outputType) => { const imageData = new outputType(makeDeepCopy ? Module.HEAPU8.slice(binaryPtr, binaryPtr + binarySize).buffer : Module.HEAPU8.buffer, binaryPtr, width * height * numChannels); return { data: imageData, width, height }; }; } } function JsOnUint8ArrayImageListener(output_stream_name, binary_ptr, binary_size, width, height, num_channels, make_deep_copy, timestamp_ms) { const image = Module._imageConverter(binary_ptr, binary_size, width, height, num_channels, make_deep_copy, Uint8Array); Module._wrapSimpleListenerOutput(output_stream_name, image, timestamp_ms); } function JsOnFloat32ArrayImageListener(output_stream_name, binary_ptr, binary_size, width, height, num_channels, make_deep_copy, timestamp_ms) { const image = Module._imageConverter(binary_ptr, binary_size, width, height, num_channels, make_deep_copy, Float32Array); Module._wrapSimpleListenerOutput(output_stream_name, image, timestamp_ms); } function JsOnWebGLTextureListener(output_stream_name, name, width, height, timestamp_ms) { Module._wrapSimpleListenerOutput(output_stream_name, { data: GL.textures[name], width, height }, timestamp_ms); } function JsOnUint8ArrayImageVectorListener(output_stream_name, binary_ptr, binary_size, width, height, num_channels, make_deep_copy, timestamp_ms) { const image = Module._imageConverter(binary_ptr, binary_size, width, height, num_channels, make_deep_copy, Uint8Array); Module._wrapSimpleListenerOutput(output_stream_name, image, false, timestamp_ms); } function JsOnFloat32ArrayImageVectorListener(output_stream_name, binary_ptr, binary_size, width, height, num_channels, make_deep_copy, timestamp_ms) { const image = Module._imageConverter(binary_ptr, binary_size, width, height, num_channels, make_deep_copy, Float32Array); Module._wrapSimpleListenerOutput(output_stream_name, image, false, timestamp_ms); } function JsOnWebGLTextureVectorListener(output_stream_name, name, width, height, timestamp_ms) { Module._wrapSimpleListenerOutput(output_stream_name, { data: GL.textures[name], width, height }, false, timestamp_ms); } function JsOnEmptyPacketListener(output_stream_name, timestamp) { Module._wrapEmptyPacketListenerOutput(output_stream_name, timestamp); } function JsOnVectorFinishedListener(output_stream_name, timestamp) { Module._wrapSimpleListenerOutput(output_stream_name, undefined, true, timestamp); } function JsOnSimpleListenerBool(output_stream_name, out_data, timestamp) { Module._wrapSimpleListenerOutput(output_stream_name, out_data, timestamp); } function JsOnVectorListenerBool(output_stream_name, out_data, timestamp) { Module._wrapSimpleListenerOutput(output_stream_name, out_data, false, timestamp); } function JsOnSimpleListenerInt(output_stream_name, out_data, timestamp) { Module._wrapSimpleListenerOutput(output_stream_name, out_data, timestamp); } function JsOnVectorListenerInt(output_stream_name, out_data, timestamp) { Module._wrapSimpleListenerOutput(output_stream_name, out_data, false, timestamp); } function JsOnSimpleListenerUint(output_stream_name, out_data, timestamp) { Module._wrapSimpleListenerOutput(output_stream_name, out_data, timestamp); } function JsOnVectorListenerUint(output_stream_name, out_data, timestamp) { Module._wrapSimpleListenerOutput(output_stream_name, out_data, false, timestamp); } function JsOnSimpleListenerDouble(output_stream_name, out_data, timestamp) { Module._wrapSimpleListenerOutput(output_stream_name, out_data, timestamp); } function JsOnVectorListenerDouble(output_stream_name, out_data, timestamp) { Module._wrapSimpleListenerOutput(output_stream_name, out_data, false, timestamp); } function JsOnSimpleListenerFloat(output_stream_name, out_data, timestamp) { Module._wrapSimpleListenerOutput(output_stream_name, out_data, timestamp); } function JsOnVectorListenerFloat(output_stream_name, out_data, timestamp) { Module._wrapSimpleListenerOutput(output_stream_name, out_data, false, timestamp); } function JsOnSimpleListenerString(output_stream_name, out_data, timestamp) { Module._wrapSimpleListenerOutput(output_stream_name, UTF8ToString(out_data), timestamp); } function JsOnVectorListenerString(output_stream_name, out_data, timestamp) { Module._wrapSimpleListenerOutput(output_stream_name, UTF8ToString(out_data), false, timestamp); } function JsOnVectorListenerProto(output_stream_name, proto_ptr, proto_size, make_deep_copy, timestamp) { const newProtoArray = make_deep_copy ? Module.HEAPU8.slice(proto_ptr, proto_ptr + proto_size) : new Uint8Array(Module.HEAPU8.buffer, proto_ptr, proto_size); Module._wrapSimpleListenerOutput(output_stream_name, newProtoArray, false, timestamp); } function JsWrapSimpleListeners() { if (!Module._wrapSimpleListenerOutput) { Module._wrapSimpleListenerOutput = (outputStreamName, ...args) => { if (Module.simpleListeners) { const streamName = UTF8ToString(outputStreamName); if (Module.simpleListeners[streamName]) { Module.simpleListeners[streamName](...args); } } }; } if (!Module._wrapEmptyPacketListenerOutput) { Module._wrapEmptyPacketListenerOutput = (outputStreamName, timestamp) => { if (Module.emptyPacketListeners) { const streamName = UTF8ToString(outputStreamName); if (Module.emptyPacketListeners[streamName]) { Module.emptyPacketListeners[streamName](timestamp); } } }; } } function JsOnSimpleListenerBinaryArray(output_stream_name, binary_ptr, binary_size, make_deep_copy, timestamp) { const newProtoArray = make_deep_copy ? Module.HEAPU8.slice(binary_ptr, binary_ptr + binary_size) : new Uint8Array(Module.HEAPU8.buffer, binary_ptr, binary_size); Module._wrapSimpleListenerOutput(output_stream_name, newProtoArray, timestamp); } function mediapipe_import_external_texture(device_handle, source_handle) { const device = WebGPU.getJsObject(device_handle); const source = Emval.toValue(source_handle); const externalTexture = device.importExternalTexture({ source }); return Emval.toHandle(externalTexture); } function mediapipe_create_utility_canvas2d() { let canvas; if (typeof HTMLCanvasElement !== "undefined") { canvas = document.createElement("canvas"); canvas.style.display = "none"; } else { canvas = new OffscreenCanvas(0, 0); } return Emval.toHandle(canvas); } function GetAdapterArchitecture() { const device = Module["preinitializedWebGPUDevice"]; const architecture = device.adapterInfo ? device.adapterInfo.architecture : "Unknown"; return stringToNewUTF8(architecture); } function GetAdapterDescription() { const device = Module["preinitializedWebGPUDevice"]; const description = device.adapterInfo ? device.adapterInfo.description : "Unknown"; return stringToNewUTF8(description); } function GetAdapterDeviceName() { const device = Module["preinitializedWebGPUDevice"]; const deviceName = device.adapterInfo ? device.adapterInfo.device : "Unknown"; return stringToNewUTF8(deviceName); } function GetAdapterVendor() { const device = Module["preinitializedWebGPUDevice"]; const vendor = device.adapterInfo ? device.adapterInfo.vendor : "Unknown"; return stringToNewUTF8(vendor); } function __asyncjs__mediapipe_map_buffer_jspi(buffer_handle, data) { return Asyncify.handleAsync(async () => { const buffer = WebGPU.getJsObject(buffer_handle); if ("mapSync" in buffer) { buffer.mapSync(GPUMapMode.READ); } else { await buffer.mapAsync(GPUMapMode.READ); } const mapped = buffer.getMappedRange(); HEAPU8.set(new Uint8Array(mapped), data); buffer.unmap(); }); } function hardware_concurrency() { var concurrency = 1; try { concurrency = self.navigator.hardwareConcurrency; } catch (e) {} return concurrency; } function JsWrapErrorListener(code, message) { if (Module.errorListener) { const stringMessage = UTF8ToString(message); Module.errorListener(code, stringMessage); } } function UseBottomLeftGpuOrigin() { return (Module && Module.gpuOriginForWebTexturesIsBottomLeft); } function custom_emscripten_dbgn(str, len) { if (typeof (dbg) !== "undefined") { dbg(UTF8ToString(str, len)); } else { if (typeof (custom_dbg) === "undefined") { function custom_dbg(text) { console.warn.apply(console, arguments); } } custom_dbg(UTF8ToString(str, len)); } } // Imports from the Wasm binary. var _free, _malloc, _wgpuDeviceAddRef, _addBoundTextureAsImageToStream, _attachImageListener, _attachImageVectorListener, _registerModelResourcesGraphService, _bindTextureToStream, _addBoundTextureToStream, _addDoubleToInputStream, _addFloatToInputStream, _addBoolToInputStream, _addIntToInputStream, _addUintToInputStream, _addStringToInputStream, _addRawDataSpanToInputStream, _allocateBoolVector, _allocateFloatVector, _allocateDoubleVector, _allocateIntVector, _allocateUintVector, _allocateStringVector, _addBoolVectorEntry, _addFloatVectorEntry, _addDoubleVectorEntry, _addIntVectorEntry, _addUintVectorEntry, _addStringVectorEntry, _addBoolVectorToInputStream, _addFloatVectorToInputStream, _addDoubleVectorToInputStream, _addIntVectorToInputStream, _addUintVectorToInputStream, _addStringVectorToInputStream, _addFlatHashMapToInputStream, _addProtoToInputStream, _addEmptyPacketToInputStream, _addBoolToInputSidePacket, _addDoubleToInputSidePacket, _addFloatToInputSidePacket, _addIntToInputSidePacket, _addUintToInputSidePacket, _addStringToInputSidePacket, _addRawDataSpanToInputSidePacket, _addProtoToInputSidePacket, _addBoolVectorToInputSidePacket, _addDoubleVectorToInputSidePacket, _addFloatVectorToInputSidePacket, _addIntVectorToInputSidePacket, _addUintVectorToInputSidePacket, _addStringVectorToInputSidePacket, _attachBoolListener, _attachBoolVectorListener, _attachDoubleListener, _attachDoubleVectorListener, _attachFloatListener, _attachFloatVectorListener, _attachIntListener, _attachIntVectorListener, _attachUintListener, _attachUintVectorListener, _attachStringListener, _attachStringVectorListener, _attachProtoListener, _attachProtoVectorListener, _getGraphConfig, ___getTypeName, _emwgpuCreateBindGroup, _emwgpuCreateBindGroupLayout, _emwgpuCreateCommandBuffer, _emwgpuCreateCommandEncoder, _emwgpuCreateComputePassEncoder, _emwgpuCreateComputePipeline, _emwgpuCreateExternalTexture, _emwgpuCreatePipelineLayout, _emwgpuCreateQuerySet, _emwgpuCreateRenderBundle, _emwgpuCreateRenderBundleEncoder, _emwgpuCreateRenderPassEncoder, _emwgpuCreateRenderPipeline, _emwgpuCreateSampler, _emwgpuCreateSurface, _emwgpuCreateTexture, _emwgpuCreateTextureView, _emwgpuCreateAdapter, _emwgpuImportBuffer, _emwgpuCreateDevice, _emwgpuCreateQueue, _emwgpuCreateShaderModule, _emwgpuOnCreateComputePipelineCompleted, _emwgpuOnCreateRenderPipelineCompleted, _clearSubgraphs, _pushBinarySubgraph, _pushTextSubgraph, _changeBinaryGraph, _changeTextGraph, _processGl, _process, _bindTextureToCanvas, _requestShaderRefreshOnGraphChange, _waitUntilIdle, _closeGraph, _setAutoRenderToScreen, _emscripten_builtin_memalign, _memalign, __emscripten_tempret_set, __emscripten_stack_restore, __emscripten_stack_alloc, _emscripten_stack_get_current, dynCall_ji, dynCall_jii, dynCall_iiiijij, dynCall_viiji, dynCall_viji, dynCall_iiiji, dynCall_jjj, dynCall_iiiijj, dynCall_viijj, dynCall_viiijjj, dynCall_vij, dynCall_viijii, dynCall_viiiji, dynCall_vijjj, dynCall_vj, dynCall_viij, dynCall_jiji, dynCall_iiiiij, dynCall_iiiiijj, dynCall_iiiiiijj, memory, _kVersionStampBuildChangelistStr, _kVersionStampCitcSnapshotStr, _kVersionStampCitcWorkspaceIdStr, _kVersionStampSourceUriStr, _kVersionStampBuildClientStr, _kVersionStampBuildClientMintStatusStr, _kVersionStampBuildCompilerStr, _kVersionStampBuildDateTimePstStr, _kVersionStampBuildDepotPathStr, _kVersionStampBuildIdStr, _kVersionStampBuildInfoStr, _kVersionStampBuildLabelStr, _kVersionStampBuildTargetStr, _kVersionStampBuildTimestampStr, _kVersionStampBuildToolStr, _kVersionStampG3BuildTargetStr, _kVersionStampVerifiableStr, _kVersionStampBuildFdoTypeStr, _kVersionStampBuildBaselineChangelistStr, _kVersionStampBuildLtoTypeStr, _kVersionStampBuildPropellerTypeStr, _kVersionStampBuildPghoTypeStr, _kVersionStampBuildUsernameStr, _kVersionStampBuildHostnameStr, _kVersionStampBuildDirectoryStr, _kVersionStampBuildChangelistInt, _kVersionStampCitcSnapshotInt, _kVersionStampBuildClientMintStatusInt, _kVersionStampBuildTimestampInt, _kVersionStampVerifiableInt, _kVersionStampBuildCoverageEnabledInt, _kVersionStampBuildBaselineChangelistInt, _kVersionStampPrecookedTimestampStr, _kVersionStampPrecookedClientInfoStr, __indirect_function_table, wasmMemory, wasmTable; function assignWasmExports(wasmExports) { _free = Module["_free"] = wasmExports["Td"]; _malloc = Module["_malloc"] = wasmExports["Ud"]; _wgpuDeviceAddRef = wasmExports["Vd"]; _addBoundTextureAsImageToStream = Module["_addBoundTextureAsImageToStream"] = wasmExports["Wd"]; _attachImageListener = Module["_attachImageListener"] = wasmExports["Xd"]; _attachImageVectorListener = Module["_attachImageVectorListener"] = wasmExports["Yd"]; _registerModelResourcesGraphService = Module["_registerModelResourcesGraphService"] = wasmExports["Zd"]; _bindTextureToStream = Module["_bindTextureToStream"] = wasmExports["_d"]; _addBoundTextureToStream = Module["_addBoundTextureToStream"] = wasmExports["$d"]; _addDoubleToInputStream = Module["_addDoubleToInputStream"] = wasmExports["ae"]; _addFloatToInputStream = Module["_addFloatToInputStream"] = wasmExports["be"]; _addBoolToInputStream = Module["_addBoolToInputStream"] = wasmExports["ce"]; _addIntToInputStream = Module["_addIntToInputStream"] = wasmExports["de"]; _addUintToInputStream = Module["_addUintToInputStream"] = wasmExports["ee"]; _addStringToInputStream = Module["_addStringToInputStream"] = wasmExports["fe"]; _addRawDataSpanToInputStream = Module["_addRawDataSpanToInputStream"] = wasmExports["ge"]; _allocateBoolVector = Module["_allocateBoolVector"] = wasmExports["he"]; _allocateFloatVector = Module["_allocateFloatVector"] = wasmExports["ie"]; _allocateDoubleVector = Module["_allocateDoubleVector"] = wasmExports["je"]; _allocateIntVector = Module["_allocateIntVector"] = wasmExports["ke"]; _allocateUintVector = Module["_allocateUintVector"] = wasmExports["le"]; _allocateStringVector = Module["_allocateStringVector"] = wasmExports["me"]; _addBoolVectorEntry = Module["_addBoolVectorEntry"] = wasmExports["ne"]; _addFloatVectorEntry = Module["_addFloatVectorEntry"] = wasmExports["oe"]; _addDoubleVectorEntry = Module["_addDoubleVectorEntry"] = wasmExports["pe"]; _addIntVectorEntry = Module["_addIntVectorEntry"] = wasmExports["qe"]; _addUintVectorEntry = Module["_addUintVectorEntry"] = wasmExports["re"]; _addStringVectorEntry = Module["_addStringVectorEntry"] = wasmExports["se"]; _addBoolVectorToInputStream = Module["_addBoolVectorToInputStream"] = wasmExports["te"]; _addFloatVectorToInputStream = Module["_addFloatVectorToInputStream"] = wasmExports["ue"]; _addDoubleVectorToInputStream = Module["_addDoubleVectorToInputStream"] = wasmExports["ve"]; _addIntVectorToInputStream = Module["_addIntVectorToInputStream"] = wasmExports["we"]; _addUintVectorToInputStream = Module["_addUintVectorToInputStream"] = wasmExports["xe"]; _addStringVectorToInputStream = Module["_addStringVectorToInputStream"] = wasmExports["ye"]; _addFlatHashMapToInputStream = Module["_addFlatHashMapToInputStream"] = wasmExports["ze"]; _addProtoToInputStream = Module["_addProtoToInputStream"] = wasmExports["Ae"]; _addEmptyPacketToInputStream = Module["_addEmptyPacketToInputStream"] = wasmExports["Be"]; _addBoolToInputSidePacket = Module["_addBoolToInputSidePacket"] = wasmExports["Ce"]; _addDoubleToInputSidePacket = Module["_addDoubleToInputSidePacket"] = wasmExports["De"]; _addFloatToInputSidePacket = Module["_addFloatToInputSidePacket"] = wasmExports["Ee"]; _addIntToInputSidePacket = Module["_addIntToInputSidePacket"] = wasmExports["Fe"]; _addUintToInputSidePacket = Module["_addUintToInputSidePacket"] = wasmExports["Ge"]; _addStringToInputSidePacket = Module["_addStringToInputSidePacket"] = wasmExports["He"]; _addRawDataSpanToInputSidePacket = Module["_addRawDataSpanToInputSidePacket"] = wasmExports["Ie"]; _addProtoToInputSidePacket = Module["_addProtoToInputSidePacket"] = wasmExports["Je"]; _addBoolVectorToInputSidePacket = Module["_addBoolVectorToInputSidePacket"] = wasmExports["Ke"]; _addDoubleVectorToInputSidePacket = Module["_addDoubleVectorToInputSidePacket"] = wasmExports["Le"]; _addFloatVectorToInputSidePacket = Module["_addFloatVectorToInputSidePacket"] = wasmExports["Me"]; _addIntVectorToInputSidePacket = Module["_addIntVectorToInputSidePacket"] = wasmExports["Ne"]; _addUintVectorToInputSidePacket = Module["_addUintVectorToInputSidePacket"] = wasmExports["Oe"]; _addStringVectorToInputSidePacket = Module["_addStringVectorToInputSidePacket"] = wasmExports["Pe"]; _attachBoolListener = Module["_attachBoolListener"] = wasmExports["Qe"]; _attachBoolVectorListener = Module["_attachBoolVectorListener"] = wasmExports["Re"]; _attachDoubleListener = Module["_attachDoubleListener"] = wasmExports["Se"]; _attachDoubleVectorListener = Module["_attachDoubleVectorListener"] = wasmExports["Te"]; _attachFloatListener = Module["_attachFloatListener"] = wasmExports["Ue"]; _attachFloatVectorListener = Module["_attachFloatVectorListener"] = wasmExports["Ve"]; _attachIntListener = Module["_attachIntListener"] = wasmExports["We"]; _attachIntVectorListener = Module["_attachIntVectorListener"] = wasmExports["Xe"]; _attachUintListener = Module["_attachUintListener"] = wasmExports["Ye"]; _attachUintVectorListener = Module["_attachUintVectorListener"] = wasmExports["Ze"]; _attachStringListener = Module["_attachStringListener"] = wasmExports["_e"]; _attachStringVectorListener = Module["_attachStringVectorListener"] = wasmExports["$e"]; _attachProtoListener = Module["_attachProtoListener"] = wasmExports["af"]; _attachProtoVectorListener = Module["_attachProtoVectorListener"] = wasmExports["bf"]; _getGraphConfig = Module["_getGraphConfig"] = wasmExports["cf"]; ___getTypeName = wasmExports["df"]; _emwgpuCreateBindGroup = wasmExports["ef"]; _emwgpuCreateBindGroupLayout = wasmExports["ff"]; _emwgpuCreateCommandBuffer = wasmExports["gf"]; _emwgpuCreateCommandEncoder = wasmExports["hf"]; _emwgpuCreateComputePassEncoder = wasmExports["jf"]; _emwgpuCreateComputePipeline = wasmExports["kf"]; _emwgpuCreateExternalTexture = wasmExports["lf"]; _emwgpuCreatePipelineLayout = wasmExports["mf"]; _emwgpuCreateQuerySet = wasmExports["nf"]; _emwgpuCreateRenderBundle = wasmExports["of"]; _emwgpuCreateRenderBundleEncoder = wasmExports["pf"]; _emwgpuCreateRenderPassEncoder = wasmExports["qf"]; _emwgpuCreateRenderPipeline = wasmExports["rf"]; _emwgpuCreateSampler = wasmExports["sf"]; _emwgpuCreateSurface = wasmExports["tf"]; _emwgpuCreateTexture = wasmExports["uf"]; _emwgpuCreateTextureView = wasmExports["vf"]; _emwgpuCreateAdapter = wasmExports["wf"]; _emwgpuImportBuffer = wasmExports["xf"]; _emwgpuCreateDevice = wasmExports["yf"]; _emwgpuCreateQueue = wasmExports["zf"]; _emwgpuCreateShaderModule = wasmExports["Af"]; _emwgpuOnCreateComputePipelineCompleted = wasmExports["Bf"]; _emwgpuOnCreateRenderPipelineCompleted = wasmExports["Cf"]; _clearSubgraphs = Module["_clearSubgraphs"] = wasmExports["Df"]; _pushBinarySubgraph = Module["_pushBinarySubgraph"] = wasmExports["Ef"]; _pushTextSubgraph = Module["_pushTextSubgraph"] = wasmExports["Ff"]; _changeBinaryGraph = Module["_changeBinaryGraph"] = wasmExports["Gf"]; _changeTextGraph = Module["_changeTextGraph"] = wasmExports["Hf"]; _processGl = Module["_processGl"] = wasmExports["If"]; _process = Module["_process"] = wasmExports["Jf"]; _bindTextureToCanvas = Module["_bindTextureToCanvas"] = wasmExports["Kf"]; _requestShaderRefreshOnGraphChange = Module["_requestShaderRefreshOnGraphChange"] = wasmExports["Lf"]; _waitUntilIdle = Module["_waitUntilIdle"] = wasmExports["Mf"]; _closeGraph = Module["_closeGraph"] = wasmExports["Nf"]; _setAutoRenderToScreen = Module["_setAutoRenderToScreen"] = wasmExports["Of"]; _emscripten_builtin_memalign = wasmExports["Pf"]; _memalign = wasmExports["Qf"]; __emscripten_tempret_set = wasmExports["Rf"]; __emscripten_stack_restore = wasmExports["Sf"]; __emscripten_stack_alloc = wasmExports["Tf"]; _emscripten_stack_get_current = wasmExports["Uf"]; dynCall_ji = wasmExports["dynCall_ji"]; dynCall_jii = wasmExports["dynCall_jii"]; dynCall_iiiijij = wasmExports["dynCall_iiiijij"]; dynCall_viiji = wasmExports["dynCall_viiji"]; dynCall_viji = wasmExports["dynCall_viji"]; dynCall_iiiji = wasmExports["dynCall_iiiji"]; dynCall_jjj = wasmExports["dynCall_jjj"]; dynCall_iiiijj = wasmExports["dynCall_iiiijj"]; dynCall_viijj = wasmExports["dynCall_viijj"]; dynCall_viiijjj = wasmExports["dynCall_viiijjj"]; dynCall_vij = wasmExports["dynCall_vij"]; dynCall_viijii = wasmExports["dynCall_viijii"]; dynCall_viiiji = wasmExports["dynCall_viiiji"]; dynCall_vijjj = wasmExports["dynCall_vijjj"]; dynCall_vj = wasmExports["dynCall_vj"]; dynCall_viij = wasmExports["dynCall_viij"]; dynCall_jiji = wasmExports["dynCall_jiji"]; dynCall_iiiiij = wasmExports["dynCall_iiiiij"]; dynCall_iiiiijj = wasmExports["dynCall_iiiiijj"]; dynCall_iiiiiijj = wasmExports["dynCall_iiiiiijj"]; memory = wasmMemory = wasmExports["id"]; _kVersionStampBuildChangelistStr = Module["_kVersionStampBuildChangelistStr"] = wasmExports["kd"].value; _kVersionStampCitcSnapshotStr = Module["_kVersionStampCitcSnapshotStr"] = wasmExports["ld"].value; _kVersionStampCitcWorkspaceIdStr = Module["_kVersionStampCitcWorkspaceIdStr"] = wasmExports["md"].value; _kVersionStampSourceUriStr = Module["_kVersionStampSourceUriStr"] = wasmExports["nd"].value; _kVersionStampBuildClientStr = Module["_kVersionStampBuildClientStr"] = wasmExports["od"].value; _kVersionStampBuildClientMintStatusStr = Module["_kVersionStampBuildClientMintStatusStr"] = wasmExports["pd"].value; _kVersionStampBuildCompilerStr = Module["_kVersionStampBuildCompilerStr"] = wasmExports["qd"].value; _kVersionStampBuildDateTimePstStr = Module["_kVersionStampBuildDateTimePstStr"] = wasmExports["rd"].value; _kVersionStampBuildDepotPathStr = Module["_kVersionStampBuildDepotPathStr"] = wasmExports["sd"].value; _kVersionStampBuildIdStr = Module["_kVersionStampBuildIdStr"] = wasmExports["td"].value; _kVersionStampBuildInfoStr = Module["_kVersionStampBuildInfoStr"] = wasmExports["ud"].value; _kVersionStampBuildLabelStr = Module["_kVersionStampBuildLabelStr"] = wasmExports["vd"].value; _kVersionStampBuildTargetStr = Module["_kVersionStampBuildTargetStr"] = wasmExports["wd"].value; _kVersionStampBuildTimestampStr = Module["_kVersionStampBuildTimestampStr"] = wasmExports["xd"].value; _kVersionStampBuildToolStr = Module["_kVersionStampBuildToolStr"] = wasmExports["yd"].value; _kVersionStampG3BuildTargetStr = Module["_kVersionStampG3BuildTargetStr"] = wasmExports["zd"].value; _kVersionStampVerifiableStr = Module["_kVersionStampVerifiableStr"] = wasmExports["Ad"].value; _kVersionStampBuildFdoTypeStr = Module["_kVersionStampBuildFdoTypeStr"] = wasmExports["Bd"].value; _kVersionStampBuildBaselineChangelistStr = Module["_kVersionStampBuildBaselineChangelistStr"] = wasmExports["Cd"].value; _kVersionStampBuildLtoTypeStr = Module["_kVersionStampBuildLtoTypeStr"] = wasmExports["Dd"].value; _kVersionStampBuildPropellerTypeStr = Module["_kVersionStampBuildPropellerTypeStr"] = wasmExports["Ed"].value; _kVersionStampBuildPghoTypeStr = Module["_kVersionStampBuildPghoTypeStr"] = wasmExports["Fd"].value; _kVersionStampBuildUsernameStr = Module["_kVersionStampBuildUsernameStr"] = wasmExports["Gd"].value; _kVersionStampBuildHostnameStr = Module["_kVersionStampBuildHostnameStr"] = wasmExports["Hd"].value; _kVersionStampBuildDirectoryStr = Module["_kVersionStampBuildDirectoryStr"] = wasmExports["Id"].value; _kVersionStampBuildChangelistInt = Module["_kVersionStampBuildChangelistInt"] = wasmExports["Jd"].value; _kVersionStampCitcSnapshotInt = Module["_kVersionStampCitcSnapshotInt"] = wasmExports["Kd"].value; _kVersionStampBuildClientMintStatusInt = Module["_kVersionStampBuildClientMintStatusInt"] = wasmExports["Ld"].value; _kVersionStampBuildTimestampInt = Module["_kVersionStampBuildTimestampInt"] = wasmExports["Md"].value; _kVersionStampVerifiableInt = Module["_kVersionStampVerifiableInt"] = wasmExports["Nd"].value; _kVersionStampBuildCoverageEnabledInt = Module["_kVersionStampBuildCoverageEnabledInt"] = wasmExports["Od"].value; _kVersionStampBuildBaselineChangelistInt = Module["_kVersionStampBuildBaselineChangelistInt"] = wasmExports["Pd"].value; _kVersionStampPrecookedTimestampStr = Module["_kVersionStampPrecookedTimestampStr"] = wasmExports["Qd"].value; _kVersionStampPrecookedClientInfoStr = Module["_kVersionStampPrecookedClientInfoStr"] = wasmExports["Rd"].value; __indirect_function_table = wasmTable = wasmExports["Sd"]; } var wasmImports = { /** @export */ hd: BeginGlQueryTiming, /** @export */ gd: EndGlQueryTiming, /** @export */ fd: GetAdapterArchitecture, /** @export */ ed: GetAdapterDescription, /** @export */ dd: GetAdapterDeviceName, /** @export */ cd: GetAdapterVendor, /** @export */ bd: JsOnEmptyPacketListener, /** @export */ ad: JsOnFloat32ArrayImageListener, /** @export */ $c: JsOnFloat32ArrayImageVectorListener, /** @export */ pb: JsOnSimpleListenerBinaryArray, /** @export */ _c: JsOnSimpleListenerBool, /** @export */ Zc: JsOnSimpleListenerDouble, /** @export */ Yc: JsOnSimpleListenerFloat, /** @export */ Xc: JsOnSimpleListenerInt, /** @export */ Wc: JsOnSimpleListenerString, /** @export */ Vc: JsOnSimpleListenerUint, /** @export */ Uc: JsOnUint8ArrayImageListener, /** @export */ Tc: JsOnUint8ArrayImageVectorListener, /** @export */ O: JsOnVectorFinishedListener, /** @export */ Sc: JsOnVectorListenerBool, /** @export */ Rc: JsOnVectorListenerDouble, /** @export */ Qc: JsOnVectorListenerFloat, /** @export */ Pc: JsOnVectorListenerInt, /** @export */ Oc: JsOnVectorListenerProto, /** @export */ Nc: JsOnVectorListenerString, /** @export */ Mc: JsOnVectorListenerUint, /** @export */ Lc: JsOnWebGLTextureListener, /** @export */ Kc: JsOnWebGLTextureVectorListener, /** @export */ Pa: JsWrapErrorListener, /** @export */ ob: JsWrapImageConverter, /** @export */ u: JsWrapSimpleListeners, /** @export */ nb: UseBottomLeftGpuOrigin, /** @export */ yb: __asyncjs__mediapipe_map_buffer_jspi, /** @export */ r: ___cxa_throw, /** @export */ Jc: ___syscall_dup, /** @export */ Ic: ___syscall_faccessat, /** @export */ mb: ___syscall_fcntl64, /** @export */ Hc: ___syscall_fstat64, /** @export */ Mb: ___syscall_ftruncate64, /** @export */ Gc: ___syscall_ioctl, /** @export */ Fc: ___syscall_lstat64, /** @export */ Ec: ___syscall_newfstatat, /** @export */ lb: ___syscall_openat, /** @export */ Dc: ___syscall_stat64, /** @export */ yc: __abort_js, /** @export */ Jb: __embind_register_bigint, /** @export */ xc: __embind_register_bool, /** @export */ wc: __embind_register_emval, /** @export */ jb: __embind_register_float, /** @export */ I: __embind_register_integer, /** @export */ q: __embind_register_memory_view, /** @export */ vc: __embind_register_std_string, /** @export */ Ma: __embind_register_std_wstring, /** @export */ uc: __embind_register_void, /** @export */ $: __emval_create_invoker, /** @export */ p: __emval_decref, /** @export */ La: __emval_get_global, /** @export */ ib: __emval_get_property, /** @export */ ja: __emval_incref, /** @export */ Ka: __emval_instanceof, /** @export */ _: __emval_invoke, /** @export */ ua: __emval_new_cstring, /** @export */ Z: __emval_run_destructors, /** @export */ hb: __emval_set_property, /** @export */ tc: __emval_typeof, /** @export */ Ib: __gmtime_js, /** @export */ Hb: __localtime_js, /** @export */ Gb: __mktime_js, /** @export */ Fb: __mmap_js, /** @export */ Eb: __munmap_js, /** @export */ sc: __tzset_js, /** @export */ Lb: _clock_time_get, /** @export */ rc: custom_emscripten_dbgn, /** @export */ Y: _emscripten_asm_const_int, /** @export */ gb: _emscripten_asm_const_ptr, /** @export */ Ja: _emscripten_errn, /** @export */ qc: _emscripten_get_heap_max, /** @export */ y: _emscripten_get_now, /** @export */ ia: _emscripten_has_asyncify, /** @export */ pc: _emscripten_outn, /** @export */ oc: _emscripten_pc_get_function, /** @export */ nc: _emscripten_resize_heap, /** @export */ fb: _emscripten_stack_snapshot, /** @export */ mc: _emscripten_stack_unwind_buffer, /** @export */ lc: _emscripten_webgl_create_context, /** @export */ kc: _emscripten_webgl_destroy_context, /** @export */ jc: _emscripten_webgl_get_context_attributes, /** @export */ ha: _emscripten_webgl_get_current_context, /** @export */ ic: _emscripten_webgl_make_context_current, /** @export */ Q: _emscripten_webgpu_get_device, /** @export */ hc: _emwgpuBufferDestroy, /** @export */ gc: _emwgpuBufferGetMappedRange, /** @export */ fc: _emwgpuBufferUnmap, /** @export */ x: _emwgpuDelete, /** @export */ ec: _emwgpuDeviceCreateBuffer, /** @export */ Db: _emwgpuDeviceCreateComputePipelineAsync, /** @export */ Cb: _emwgpuDeviceCreateRenderPipelineAsync, /** @export */ dc: _emwgpuDeviceCreateShaderModule, /** @export */ cc: _emwgpuDeviceDestroy, /** @export */ bc: _emwgpuWaitAny, /** @export */ Cc: _environ_get, /** @export */ Bc: _environ_sizes_get, /** @export */ eb: _exit, /** @export */ Oa: _fd_close, /** @export */ kb: _fd_read, /** @export */ Kb: _fd_seek, /** @export */ Na: _fd_write, /** @export */ b: _glActiveTexture, /** @export */ ta: _glAttachShader, /** @export */ ac: _glBindAttribLocation, /** @export */ c: _glBindBuffer, /** @export */ db: _glBindBufferBase, /** @export */ t: _glBindFramebuffer, /** @export */ a: _glBindTexture, /** @export */ m: _glBindVertexArray, /** @export */ cb: _glBlendEquation, /** @export */ $b: _glBlendFunc, /** @export */ j: _glBufferData, /** @export */ H: _glClear, /** @export */ X: _glClearColor, /** @export */ da: _glClientWaitSync, /** @export */ ga: _glColorMask, /** @export */ bb: _glCompileShader, /** @export */ ab: _glCreateProgram, /** @export */ $a: _glCreateShader, /** @export */ o: _glDeleteBuffers, /** @export */ P: _glDeleteFramebuffers, /** @export */ h: _glDeleteProgram, /** @export */ sa: _glDeleteShader, /** @export */ ra: _glDeleteSync, /** @export */ D: _glDeleteTextures, /** @export */ A: _glDeleteVertexArrays, /** @export */ _a: _glDetachShader, /** @export */ G: _glDisable, /** @export */ n: _glDisableVertexAttribArray, /** @export */ i: _glDrawArrays, /** @export */ fa: _glDrawBuffers, /** @export */ _b: _glEnable, /** @export */ l: _glEnableVertexAttribArray, /** @export */ Za: _glFenceSync, /** @export */ qa: _glFinish, /** @export */ v: _glFlush, /** @export */ C: _glFramebufferTexture2D, /** @export */ Ya: _glFramebufferTextureLayer, /** @export */ s: _glGenBuffers, /** @export */ W: _glGenFramebuffers, /** @export */ F: _glGenTextures, /** @export */ B: _glGenVertexArrays, /** @export */ Xa: _glGetAttribLocation, /** @export */ ea: _glGetError, /** @export */ Zb: _glGetFloatv, /** @export */ w: _glGetIntegerv, /** @export */ Yb: _glGetProgramiv, /** @export */ Xb: _glGetShaderInfoLog, /** @export */ Wb: _glGetShaderiv, /** @export */ N: _glGetString, /** @export */ Vb: _glGetUniformBlockIndex, /** @export */ d: _glGetUniformLocation, /** @export */ Ub: _glLineWidth, /** @export */ Wa: _glLinkProgram, /** @export */ pa: _glPixelStorei, /** @export */ oa: _glReadPixels, /** @export */ Va: _glShaderSource, /** @export */ E: _glTexImage2D, /** @export */ na: _glTexParameterf, /** @export */ Ua: _glTexParameterfv, /** @export */ f: _glTexParameteri, /** @export */ ma: _glTexStorage2D, /** @export */ Tb: _glTexStorage3D, /** @export */ V: _glTexSubImage2D, /** @export */ Sb: _glTexSubImage3D, /** @export */ M: _glUniform1f, /** @export */ la: _glUniform1fv, /** @export */ e: _glUniform1i, /** @export */ U: _glUniform2f, /** @export */ Rb: _glUniform2fv, /** @export */ Ia: _glUniform3f, /** @export */ Ta: _glUniform4f, /** @export */ T: _glUniform4fv, /** @export */ Qb: _glUniform4iv, /** @export */ Pb: _glUniformBlockBinding, /** @export */ Ob: _glUniformMatrix2fv, /** @export */ Nb: _glUniformMatrix3fv, /** @export */ Ha: _glUniformMatrix4fv, /** @export */ g: _glUseProgram, /** @export */ k: _glVertexAttribPointer, /** @export */ S: _glViewport, /** @export */ Ga: hardware_concurrency, /** @export */ Bb: mediapipe_create_utility_canvas2d, /** @export */ Ab: _mediapipe_find_canvas_event_target, /** @export */ zb: mediapipe_import_external_texture, /** @export */ xb: _mediapipe_webgl_tex_image_drawable, /** @export */ Ac: _proc_exit, /** @export */ zc: _random_get, /** @export */ Fa: _wgpuCommandEncoderBeginComputePass, /** @export */ Ea: _wgpuCommandEncoderBeginRenderPass, /** @export */ wb: _wgpuCommandEncoderCopyBufferToTexture, /** @export */ vb: _wgpuCommandEncoderCopyTextureToBuffer, /** @export */ ub: _wgpuCommandEncoderCopyTextureToTexture, /** @export */ L: _wgpuCommandEncoderFinish, /** @export */ Da: _wgpuComputePassEncoderDispatchWorkgroups, /** @export */ Ca: _wgpuComputePassEncoderEnd, /** @export */ Ba: _wgpuComputePassEncoderSetBindGroup, /** @export */ Aa: _wgpuComputePassEncoderSetPipeline, /** @export */ za: _wgpuComputePipelineGetBindGroupLayout, /** @export */ ca: _wgpuDeviceCreateBindGroup, /** @export */ tb: _wgpuDeviceCreateBindGroupLayout, /** @export */ K: _wgpuDeviceCreateCommandEncoder, /** @export */ sb: _wgpuDeviceCreateComputePipeline, /** @export */ rb: _wgpuDeviceCreatePipelineLayout, /** @export */ Sa: _wgpuDeviceCreateRenderPipeline, /** @export */ R: _wgpuDeviceCreateSampler, /** @export */ ba: _wgpuDeviceCreateTexture, /** @export */ J: _wgpuQueueSubmit, /** @export */ ka: _wgpuQueueWriteBuffer, /** @export */ qb: _wgpuQueueWriteTexture, /** @export */ ya: _wgpuRenderPassEncoderDraw, /** @export */ xa: _wgpuRenderPassEncoderEnd, /** @export */ wa: _wgpuRenderPassEncoderSetBindGroup, /** @export */ va: _wgpuRenderPassEncoderSetPipeline, /** @export */ Ra: _wgpuRenderPipelineGetBindGroupLayout, /** @export */ z: _wgpuTextureCreateView, /** @export */ Qa: _wgpuTextureDestroy, /** @export */ aa: _wgpuTextureGetFormat }; // include: postamble.js // === Auto-generated postamble setup entry stuff === function run() { if (runDependencies > 0) { dependenciesFulfilled = run; return; } preRun(); // a preRun added a dependency, run will be called later if (runDependencies > 0) { dependenciesFulfilled = run; return; } function doRun() { // run may have just been called through dependencies being fulfilled just in this very frame, // or while the async setStatus time below was happening Module["calledRun"] = true; if (ABORT) return; initRuntime(); readyPromiseResolve?.(Module); Module["onRuntimeInitialized"]?.(); postRun(); } if (Module["setStatus"]) { Module["setStatus"]("Running..."); setTimeout(() => { setTimeout(() => Module["setStatus"](""), 1); doRun(); }, 1); } else { doRun(); } } var wasmExports; // In modularize mode the generated code is within a factory function so we // can use await here (since it's not top-level-await). wasmExports = await (createWasm()); run(); // end include: postamble.js // include: postamble_modularize.js // In MODULARIZE mode we wrap the generated code in a factory function // and return either the Module itself, or a promise of the module. // We assign to the `moduleRtn` global here and configure closure to see // this as an extern so it won't get minified. if (runtimeInitialized) { moduleRtn = Module; } else { // Set up the promise that indicates the Module is initialized moduleRtn = new Promise((resolve, reject) => { readyPromiseResolve = resolve; readyPromiseReject = reject; }); } return moduleRtn; } // Export using a UMD style export, or ES6 exports if selected export default ModuleFactory;