{"version":3,"file":"webgpu-D1RC9WhT.cjs","names":[],"sources":["../../src/target/node/webgpu.js"],"sourcesContent":["let gpuInitPromise;\n\n/**\n * @internal\n * @summary Initialize a WebGPU implementation in Node.js.\n *\n * @description\n * Creates a singleton WebGPU instance using the native `webgpu` package when\n * one does not already exist on `globalThis.navigator.gpu`. The initialized\n * instance is cached so repeated calls return the same promise.\n *\n * The `webgpu` package is ESM-only and MUST be loaded via dynamic `import()`.\n * A static import compiles to a top-level CommonJS require of the package\n * in the CJS build, which throws ERR_REQUIRE_ESM on Node < 22.12.\n *\n * @async\n * @function initWebGPU\n * @returns {Promise<GPU>} The initialized WebGPU implementation.\n * @since 0.2.0\n */\nexport async function initWebGPU() {\n  if (globalThis.navigator?.gpu) return globalThis.navigator.gpu;\n  if (!gpuInitPromise) {\n    gpuInitPromise = (async () => {\n      const { create } = await import(\"webgpu\");\n      const nativeGpu = create([\"backend=vulkan\"]);\n      globalThis.navigator ??= {};\n      globalThis.navigator.gpu = nativeGpu;\n      return nativeGpu;\n    })();\n  }\n  return gpuInitPromise;\n}\n\n/**\n * @internal\n * @summary Release the Node.js WebGPU singleton.\n *\n * @description\n * Removes references to the native WebGPU implementation from the global\n * object and clears the module-level initialization cache. A short delay is\n * introduced to allow the underlying native implementation to finish\n * asynchronous cleanup before process termination.\n *\n * @async\n * @function destroyWebGPU\n * @returns {Promise<void>}\n * @since 0.2.0\n */\nexport async function destroyWebGPU() {\n  // 2. Sever the native reference links so Dawn can drop its ref counts\n  if (globalThis.navigator?.gpu) {\n    delete globalThis.navigator.gpu;\n    if (Object.keys(globalThis.navigator).length === 0) {\n      delete globalThis.navigator;\n    }\n  }\n\n  // 3. Reset our internal module-level promise cache\n  gpuInitPromise = null;\n\n  // 4. CRITICAL: Yield to the event loop. This gives Dawn's native engine\n  // a small time window to notice the reference count hit 0, dismantle its\n  // background threads, and flush outstanding callbacks BEFORE the process terminates.\n  await new Promise((resolve) => setTimeout(resolve, 50));\n}\n"],"mappings":";AAAA,IAAI;;;;;;;;;;;;;;;;;;;AAoBJ,eAAsB,aAAa;CACjC,IAAI,WAAW,WAAW,KAAK,OAAO,WAAW,UAAU;CAC3D,IAAI,CAAC,gBACH,kBAAkB,YAAY;EAC5B,MAAM,EAAE,WAAW,MAAM,OAAO;EAChC,MAAM,YAAY,OAAO,CAAC,gBAAgB,CAAC;EAC3C,WAAW,cAAc,CAAC;EAC1B,WAAW,UAAU,MAAM;EAC3B,OAAO;CACT,EAAA,CAAG;CAEL,OAAO;AACT;;;;;;;;;;;;;;;;AAiBA,eAAsB,gBAAgB;CAEpC,IAAI,WAAW,WAAW,KAAK;EAC7B,OAAO,WAAW,UAAU;EAC5B,IAAI,OAAO,KAAK,WAAW,SAAS,CAAC,CAAC,WAAW,GAC/C,OAAO,WAAW;CAEtB;CAGA,iBAAiB;CAKjB,MAAM,IAAI,SAAS,YAAY,WAAW,SAAS,EAAE,CAAC;AACxD"}