@luma.gl/webgpu 9.1.0-alpha.2 → 9.1.0-alpha.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/dist/adapter/helpers/convert-texture-format.d.ts +0 -1
  2. package/dist/adapter/helpers/convert-texture-format.d.ts.map +1 -1
  3. package/dist/adapter/helpers/get-bind-group.d.ts +0 -1
  4. package/dist/adapter/helpers/get-bind-group.d.ts.map +1 -1
  5. package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts +0 -1
  6. package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts.map +1 -1
  7. package/dist/adapter/helpers/webgpu-parameters.d.ts +0 -1
  8. package/dist/adapter/helpers/webgpu-parameters.d.ts.map +1 -1
  9. package/dist/adapter/resources/webgpu-buffer.d.ts +0 -1
  10. package/dist/adapter/resources/webgpu-buffer.d.ts.map +1 -1
  11. package/dist/adapter/resources/webgpu-command-encoder.d.ts +0 -1
  12. package/dist/adapter/resources/webgpu-command-encoder.d.ts.map +1 -1
  13. package/dist/adapter/resources/webgpu-compute-pass.d.ts +0 -1
  14. package/dist/adapter/resources/webgpu-compute-pass.d.ts.map +1 -1
  15. package/dist/adapter/resources/webgpu-compute-pipeline.d.ts +0 -1
  16. package/dist/adapter/resources/webgpu-compute-pipeline.d.ts.map +1 -1
  17. package/dist/adapter/resources/webgpu-external-texture.d.ts +0 -1
  18. package/dist/adapter/resources/webgpu-external-texture.d.ts.map +1 -1
  19. package/dist/adapter/resources/webgpu-query-set.d.ts +0 -1
  20. package/dist/adapter/resources/webgpu-query-set.d.ts.map +1 -1
  21. package/dist/adapter/resources/webgpu-render-pass.d.ts +0 -1
  22. package/dist/adapter/resources/webgpu-render-pass.d.ts.map +1 -1
  23. package/dist/adapter/resources/webgpu-render-pipeline.d.ts +0 -1
  24. package/dist/adapter/resources/webgpu-render-pipeline.d.ts.map +1 -1
  25. package/dist/adapter/resources/webgpu-sampler.d.ts +0 -1
  26. package/dist/adapter/resources/webgpu-sampler.d.ts.map +1 -1
  27. package/dist/adapter/resources/webgpu-shader.d.ts +0 -1
  28. package/dist/adapter/resources/webgpu-shader.d.ts.map +1 -1
  29. package/dist/adapter/resources/webgpu-texture-view.d.ts +0 -1
  30. package/dist/adapter/resources/webgpu-texture-view.d.ts.map +1 -1
  31. package/dist/adapter/resources/webgpu-texture.d.ts +2 -3
  32. package/dist/adapter/resources/webgpu-texture.d.ts.map +1 -1
  33. package/dist/adapter/resources/webgpu-texture.js +27 -3
  34. package/dist/adapter/webgpu-adapter.d.ts +13 -0
  35. package/dist/adapter/webgpu-adapter.d.ts.map +1 -0
  36. package/dist/adapter/webgpu-adapter.js +68 -0
  37. package/dist/adapter/webgpu-canvas-context.d.ts +0 -1
  38. package/dist/adapter/webgpu-canvas-context.d.ts.map +1 -1
  39. package/dist/adapter/webgpu-device.d.ts +1 -6
  40. package/dist/adapter/webgpu-device.d.ts.map +1 -1
  41. package/dist/adapter/webgpu-device.js +2 -52
  42. package/dist/dist.dev.js +101 -83
  43. package/dist/dist.min.js +1 -1
  44. package/dist/index.cjs +93 -60
  45. package/dist/index.cjs.map +4 -4
  46. package/dist/index.d.ts +2 -0
  47. package/dist/index.d.ts.map +1 -1
  48. package/dist/index.js +2 -2
  49. package/package.json +2 -2
  50. package/src/adapter/resources/webgpu-texture.ts +36 -22
  51. package/src/adapter/webgpu-adapter.ts +93 -0
  52. package/src/adapter/webgpu-device.ts +3 -72
  53. package/src/index.ts +3 -1
package/dist/dist.dev.js CHANGED
@@ -11,7 +11,6 @@ var __exports__ = (() => {
11
11
  var __getOwnPropNames = Object.getOwnPropertyNames;
12
12
  var __getProtoOf = Object.getPrototypeOf;
13
13
  var __hasOwnProp = Object.prototype.hasOwnProperty;
14
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
15
14
  var __commonJS = (cb, mod) => function __require() {
16
15
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
17
16
  };
@@ -37,10 +36,6 @@ var __exports__ = (() => {
37
36
  mod
38
37
  ));
39
38
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
40
- var __publicField = (obj, key, value) => {
41
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
42
- return value;
43
- };
44
39
 
45
40
  // external-global-plugin:@luma.gl/core
46
41
  var require_core = __commonJS({
@@ -56,10 +51,14 @@ var __exports__ = (() => {
56
51
  WebGPUDevice: () => WebGPUDevice,
57
52
  WebGPUSampler: () => WebGPUSampler,
58
53
  WebGPUShader: () => WebGPUShader,
59
- WebGPUTexture: () => WebGPUTexture
54
+ WebGPUTexture: () => WebGPUTexture,
55
+ webgpuAdapter: () => webgpuAdapter
60
56
  });
61
57
  __reExport(bundle_exports, __toESM(require_core(), 1));
62
58
 
59
+ // src/adapter/webgpu-adapter.ts
60
+ var import_core18 = __toESM(require_core(), 1);
61
+
63
62
  // src/adapter/webgpu-device.ts
64
63
  var import_core17 = __toESM(require_core(), 1);
65
64
 
@@ -241,7 +240,11 @@ var __exports__ = (() => {
241
240
  this.handle = this.props.handle || this.createHandle();
242
241
  this.handle.label ||= this.id;
243
242
  if (this.props.data) {
244
- this.setData({ data: this.props.data });
243
+ if (import_core4.Texture.isExternalImage(this.props.data)) {
244
+ this.setImage({ source: this.props.data });
245
+ } else {
246
+ this.setData({ data: this.props.data });
247
+ }
245
248
  }
246
249
  this.width = this.handle.width;
247
250
  this.height = this.handle.height;
@@ -296,14 +299,32 @@ var __exports__ = (() => {
296
299
  throw new Error("not implemented");
297
300
  }
298
301
  setData(options) {
299
- return this.setImage({ source: options.data });
300
- }
302
+ let source = options.data;
303
+ if (ArrayBuffer.isView(options.data)) {
304
+ const clampedArray = new Uint8ClampedArray(options.data.buffer);
305
+ source = new ImageData(clampedArray, this.width, this.height);
306
+ }
307
+ return this.setImage({ source });
308
+ }
309
+ // setDataFromTypedArray(data): this {
310
+ // const textureDataBuffer = this.device.handle.createBuffer({
311
+ // size: data.byteLength,
312
+ // usage: Buffer.COPY_DST | Buffer.COPY_SRC,
313
+ // mappedAtCreation: true
314
+ // });
315
+ // new Uint8Array(textureDataBuffer.getMappedRange()).set(data);
316
+ // textureDataBuffer.unmap();
317
+ // this.setBuffer(textureDataBuffer);
318
+ // textureDataBuffer.destroy();
319
+ // return this;
320
+ // }
301
321
  /** Set image */
302
322
  setImage(options) {
323
+ const size = import_core4.Texture.getExternalImageSize(options.source);
303
324
  const {
304
325
  source,
305
- width = options.source.width,
306
- height = options.source.height,
326
+ width = size.width,
327
+ height = size.height,
307
328
  depth = 1,
308
329
  sourceX = 0,
309
330
  sourceY = 0,
@@ -381,21 +402,6 @@ var __exports__ = (() => {
381
402
  return this;
382
403
  }
383
404
 
384
- setData(data): this {
385
- const textureDataBuffer = this.device.handle.createBuffer({
386
- size: data.byteLength,
387
- usage: Buffer.COPY_DST | Buffer.COPY_SRC,
388
- mappedAtCreation: true
389
- });
390
- new Uint8Array(textureDataBuffer.getMappedRange()).set(data);
391
- textureDataBuffer.unmap();
392
-
393
- this.setBuffer(textureDataBuffer);
394
-
395
- textureDataBuffer.destroy();
396
- return this;
397
- }
398
-
399
405
  setBuffer(textureDataBuffer, {bytesPerRow}): this {
400
406
  const commandEncoder = this.device.handle.createCommandEncoder();
401
407
  commandEncoder.copyBufferToTexture(
@@ -1418,7 +1424,7 @@ var __exports__ = (() => {
1418
1424
  };
1419
1425
 
1420
1426
  // src/adapter/webgpu-device.ts
1421
- var _WebGPUDevice = class extends import_core17.Device {
1427
+ var WebGPUDevice = class extends import_core17.Device {
1422
1428
  /** type of this device */
1423
1429
  type = "webgpu";
1424
1430
  /** The underlying WebGPU device */
@@ -1435,60 +1441,7 @@ var __exports__ = (() => {
1435
1441
  _isLost = false;
1436
1442
  commandEncoder = null;
1437
1443
  renderPass = null;
1438
- /** Check if WebGPU is available */
1439
- static isSupported() {
1440
- return Boolean(typeof navigator !== "undefined" && navigator.gpu);
1441
- }
1442
- static async create(props) {
1443
- if (!navigator.gpu) {
1444
- throw new Error(
1445
- "WebGPU not available. Open in Chrome Canary and turn on chrome://flags/#enable-unsafe-webgpu"
1446
- );
1447
- }
1448
- import_core17.log.groupCollapsed(1, "WebGPUDevice created")();
1449
- const adapter = await navigator.gpu.requestAdapter({
1450
- powerPreference: "high-performance"
1451
- // forceSoftware: false
1452
- });
1453
- if (!adapter) {
1454
- throw new Error("Failed to request WebGPU adapter");
1455
- }
1456
- const adapterInfo = await adapter.requestAdapterInfo();
1457
- import_core17.log.probe(2, "Adapter available", adapterInfo)();
1458
- const requiredFeatures = [];
1459
- const requiredLimits = {};
1460
- if (props.requestMaxLimits) {
1461
- requiredFeatures.push(...Array.from(adapter.features));
1462
- const limits = Object.keys(adapter.limits).filter(
1463
- (key) => !["minSubgroupSize", "maxSubgroupSize"].includes(key)
1464
- );
1465
- for (const key of limits) {
1466
- const limit = key;
1467
- const value = adapter.limits[limit];
1468
- if (typeof value === "number") {
1469
- requiredLimits[limit] = value;
1470
- }
1471
- }
1472
- }
1473
- const gpuDevice = await adapter.requestDevice({
1474
- requiredFeatures,
1475
- requiredLimits
1476
- });
1477
- import_core17.log.probe(1, "GPUDevice available")();
1478
- if (typeof props.canvas === "string") {
1479
- await import_core17.CanvasContext.pageLoaded;
1480
- import_core17.log.probe(1, "DOM is loaded")();
1481
- }
1482
- const device = new _WebGPUDevice(gpuDevice, adapter, adapterInfo, props);
1483
- import_core17.log.probe(
1484
- 1,
1485
- "Device created. For more info, set chrome://flags/#enable-webgpu-developer-features"
1486
- )();
1487
- import_core17.log.table(1, device.info)();
1488
- import_core17.log.groupEnd(1)();
1489
- return device;
1490
- }
1491
- constructor(device, adapter, adapterInfo, props) {
1444
+ constructor(props, device, adapter, adapterInfo) {
1492
1445
  super({ ...props, id: props.id || "webgpu-device" });
1493
1446
  this.handle = device;
1494
1447
  this.adapter = adapter;
@@ -1678,8 +1631,73 @@ var __exports__ = (() => {
1678
1631
  );
1679
1632
  }
1680
1633
  };
1681
- var WebGPUDevice = _WebGPUDevice;
1682
- __publicField(WebGPUDevice, "type", "webgpu");
1634
+
1635
+ // src/adapter/webgpu-adapter.ts
1636
+ var WebGPUAdapter = class extends import_core18.Adapter {
1637
+ /** type of device's created by this adapter */
1638
+ type = "webgpu";
1639
+ constructor() {
1640
+ super();
1641
+ WebGPUDevice.adapter = this;
1642
+ }
1643
+ /** Check if WebGPU is available */
1644
+ isSupported() {
1645
+ return Boolean(typeof navigator !== "undefined" && navigator.gpu);
1646
+ }
1647
+ async create(props) {
1648
+ if (!navigator.gpu) {
1649
+ throw new Error(
1650
+ "WebGPU not available. Open in Chrome Canary and turn on chrome://flags/#enable-unsafe-webgpu"
1651
+ );
1652
+ }
1653
+ import_core18.log.groupCollapsed(1, "WebGPUDevice created")();
1654
+ const adapter = await navigator.gpu.requestAdapter({
1655
+ powerPreference: "high-performance"
1656
+ // forceSoftware: false
1657
+ });
1658
+ if (!adapter) {
1659
+ throw new Error("Failed to request WebGPU adapter");
1660
+ }
1661
+ const adapterInfo = await adapter.requestAdapterInfo();
1662
+ import_core18.log.probe(2, "Adapter available", adapterInfo)();
1663
+ const requiredFeatures = [];
1664
+ const requiredLimits = {};
1665
+ if (props.requestMaxLimits) {
1666
+ requiredFeatures.push(...Array.from(adapter.features));
1667
+ const limits = Object.keys(adapter.limits).filter(
1668
+ (key) => !["minSubgroupSize", "maxSubgroupSize"].includes(key)
1669
+ );
1670
+ for (const key of limits) {
1671
+ const limit = key;
1672
+ const value = adapter.limits[limit];
1673
+ if (typeof value === "number") {
1674
+ requiredLimits[limit] = value;
1675
+ }
1676
+ }
1677
+ }
1678
+ const gpuDevice = await adapter.requestDevice({
1679
+ requiredFeatures,
1680
+ requiredLimits
1681
+ });
1682
+ import_core18.log.probe(1, "GPUDevice available")();
1683
+ if (typeof props.canvas === "string") {
1684
+ await import_core18.CanvasContext.pageLoaded;
1685
+ import_core18.log.probe(1, "DOM is loaded")();
1686
+ }
1687
+ const device = new WebGPUDevice(props, gpuDevice, adapter, adapterInfo);
1688
+ import_core18.log.probe(
1689
+ 1,
1690
+ "Device created. For more info, set chrome://flags/#enable-webgpu-developer-features"
1691
+ )();
1692
+ import_core18.log.table(1, device.info)();
1693
+ import_core18.log.groupEnd(1)();
1694
+ return device;
1695
+ }
1696
+ async attach(handle) {
1697
+ throw new Error("WebGPUAdapter.attach() not implemented");
1698
+ }
1699
+ };
1700
+ var webgpuAdapter = new WebGPUAdapter();
1683
1701
  return __toCommonJS(bundle_exports);
1684
1702
  })();
1685
1703
  return __exports__;
package/dist/dist.min.js CHANGED
@@ -4,6 +4,6 @@
4
4
  else if (typeof define === 'function' && define.amd) define([], factory);
5
5
  else if (typeof exports === 'object') exports['luma'] = factory();
6
6
  else root['luma'] = factory();})(globalThis, function () {
7
- var __exports__=(()=>{var ge=Object.create;var A=Object.defineProperty;var be=Object.getOwnPropertyDescriptor;var xe=Object.getOwnPropertyNames;var we=Object.getPrototypeOf,ye=Object.prototype.hasOwnProperty;var ve=(n,e,t)=>e in n?A(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var Se=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),Ce=(n,e)=>{for(var t in e)A(n,t,{get:e[t],enumerable:!0})},I=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of xe(e))!ye.call(n,i)&&i!==t&&A(n,i,{get:()=>e[i],enumerable:!(r=be(e,i))||r.enumerable});return n},F=(n,e,t)=>(I(n,e,"default"),t&&I(t,e,"default")),d=(n,e,t)=>(t=n!=null?ge(we(n)):{},I(e||!n||!n.__esModule?A(t,"default",{value:n,enumerable:!0}):t,n)),Pe=n=>I(A({},"__esModule",{value:!0}),n);var ee=(n,e,t)=>(ve(n,typeof e!="symbol"?e+"":e,t),t);var o=Se((Fe,te)=>{te.exports=globalThis.luma});var D={};Ce(D,{WebGPUBuffer:()=>b,WebGPUDevice:()=>_,WebGPUSampler:()=>u,WebGPUShader:()=>v,WebGPUTexture:()=>y});F(D,d(o(),1));var p=d(o(),1);var O=d(o(),1);function Ee(n){return n.byteLength||n.data?.byteLength||0}var b=class extends O.Buffer{device;handle;byteLength;constructor(e,t){super(e,t),this.device=e,this.byteLength=Ee(t);let r=Boolean(t.data),i=Math.ceil(this.byteLength/4)*4;this.handle=this.props.handle||this.device.handle.createBuffer({size:i,usage:this.props.usage||GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST,mappedAtCreation:this.props.mappedAtCreation||r,label:this.props.id}),t.data&&this._writeMapped(t.data),r&&!t.mappedAtCreation&&this.handle.unmap()}destroy(){this.handle?.destroy(),this.handle=null}write(e,t=0){this.device.handle.queue.writeBuffer(this.handle,t,e.buffer,e.byteOffset,e.byteLength)}async readAsync(e=0,t=this.byteLength){let r=new b(this.device,{usage:O.Buffer.MAP_READ|O.Buffer.COPY_DST,byteLength:t}),i=this.device.handle.createCommandEncoder();i.copyBufferToBuffer(this.handle,e,r.handle,0,t),this.device.handle.queue.submit([i.finish()]),await r.handle.mapAsync(GPUMapMode.READ,e,t);let s=r.handle.getMappedRange().slice(0);return r.handle.unmap(),r.destroy(),new Uint8Array(s)}_writeMapped(e){let t=this.handle.getMappedRange();new e.constructor(t).set(e)}mapAsync(e,t=0,r){return this.handle.mapAsync(e,t,r)}getMappedRange(e=0,t){return this.handle.getMappedRange(e,t)}unmap(){this.handle.unmap()}};var R=d(o(),1);function w(n){if(n.includes("webgl"))throw new Error("webgl-only format");return n}var re=d(o(),1),u=class extends re.Sampler{device;handle;constructor(e,t){super(e,t),this.device=e;let r={...this.props};r.type!=="comparison-sampler"&&delete r.compare,this.handle=this.handle||this.device.handle.createSampler(r),this.handle.label=this.props.id}destroy(){this.handle=null}};var ne=d(o(),1),T=class extends ne.TextureView{device;handle;texture;constructor(e,t){super(e,t),this.device=e,this.texture=t.texture,this.handle=this.handle||this.texture.handle.createView({format:t.format||this.texture.format,dimension:t.dimension||this.texture.dimension,aspect:t.aspect,baseMipLevel:t.baseMipLevel,mipLevelCount:t.mipLevelCount,baseArrayLayer:t.baseArrayLayer,arrayLayerCount:t.arrayLayerCount}),this.handle.label=this.props.id}destroy(){this.handle=null}};var Be={"1d":"1d","2d":"2d","2d-array":"2d",cube:"2d","cube-array":"2d","3d":"3d"},y=class extends R.Texture{device;handle;height=1;width=1;sampler;view;constructor(e,t){if(super(e,t),this.device=e,t.data instanceof Promise){t.data.then(r=>{this.props={...this.props,data:r},this.initialize(this.props)});return}this.initialize(t)}destroy(){this.handle?.destroy(),this.handle=null}createView(e){return new T(this.device,{...e,texture:this})}initialize(e){this.handle=this.props.handle||this.createHandle(),this.handle.label||=this.id,this.props.data&&this.setData({data:this.props.data}),this.width=this.handle.width,this.height=this.handle.height,this.sampler=e.sampler instanceof u?e.sampler:new u(this.device,e.sampler||{}),this.view=new T(this.device,{...this.props,texture:this})}createHandle(){let e=this.props.width||this.props.data?.width||1,t=this.props.height||this.props.data?.height||1;return this.device.handle.createTexture({label:this.id,size:{width:e,height:t,depthOrArrayLayers:this.depth},usage:this.props.usage||R.Texture.TEXTURE|R.Texture.COPY_DST,dimension:Be[this.dimension],format:w(this.format),mipLevelCount:this.mipLevels,sampleCount:this.props.samples})}createGPUTextureView(){return this.handle.createView({label:this.id})}setSampler(e){return this.sampler=e instanceof u?e:new u(this.device,e),this}setTexture1DData(e){throw new Error("not implemented")}setTexture2DData(e,t,r){throw new Error("not implemented")}setTexture3DData(e,t,r){throw new Error("not implemented")}setTextureCubeData(e,t){throw new Error("not implemented")}setTextureArrayData(e){throw new Error("not implemented")}setTextureCubeArrayData(e){throw new Error("not implemented")}setData(e){return this.setImage({source:e.data})}setImage(e){let{source:t,width:r=e.source.width,height:i=e.source.height,depth:s=1,sourceX:a=0,sourceY:l=0,mipLevel:c=0,x:h=0,y:g=0,z:m=0,aspect:B="all",colorSpace:X="srgb",premultipliedAlpha:fe=!1}=e;return this.device.handle.queue.copyExternalImageToTexture({source:t,origin:[a,l]},{texture:this.handle,origin:[h,g,m],mipLevel:c,aspect:B,colorSpace:X,premultipliedAlpha:fe},[r,i,s]),{width:r,height:i}}};var ie=d(o(),1);var M=class extends ie.ExternalTexture{device;handle;sampler;constructor(e,t){super(e,t),this.device=e,this.handle=this.props.handle||this.device.handle.importExternalTexture({source:t.source,colorSpace:t.colorSpace}),this.sampler=null}destroy(){this.handle=null}setSampler(e){return this.sampler=e instanceof u?e:new u(this.device,e),this}};var W=d(o(),1),v=class extends W.Shader{device;handle;constructor(e,t){super(e,t),this.device=e,this.device.handle.pushErrorScope("validation"),this.handle=this.props.handle||this.createHandle(),this.handle.label=this.props.id,this._checkCompilationError(this.device.handle.popErrorScope())}async _checkCompilationError(e){let t=await e;if(t){this.debugShader();let r=await this.getCompilationInfo();throw W.log.error(`Shader compilation error: ${t.message}`,r)(),new Error(`Shader compilation error: ${t.message}`)}}destroy(){this.handle=null}async getCompilationInfo(){return(await this.handle.getCompilationInfo()).messages}createHandle(){let{source:e}=this.props,t=e.includes("#version");if(this.props.language==="glsl"||t)throw new Error("GLSL shaders are not supported in WebGPU");return this.device.handle.createShaderModule({code:e})}};var C=d(o(),1);function f(n){return n.depthStencil=n.depthStencil||{format:"depth24plus",stencilFront:{},stencilBack:{},depthWriteEnabled:!1,depthCompare:"less-equal"},n.depthStencil}function k(n){return f(n).stencilFront}function U(n){return f(n).stencilBack}var Ae={cullMode:(n,e,t)=>{t.primitive=t.primitive||{},t.primitive.cullMode=e},frontFace:(n,e,t)=>{t.primitive=t.primitive||{},t.primitive.frontFace=e},depthWriteEnabled:(n,e,t)=>{let r=f(t);r.depthWriteEnabled=e},depthCompare:(n,e,t)=>{let r=f(t);r.depthCompare=e},depthFormat:(n,e,t)=>{let r=f(t);r.format=e},depthBias:(n,e,t)=>{let r=f(t);r.depthBias=e},depthBiasSlopeScale:(n,e,t)=>{let r=f(t);r.depthBiasSlopeScale=e},depthBiasClamp:(n,e,t)=>{let r=f(t);r.depthBiasClamp=e},stencilReadMask:(n,e,t)=>{let r=f(t);r.stencilReadMask=e},stencilWriteMask:(n,e,t)=>{let r=f(t);r.stencilWriteMask=e},stencilCompare:(n,e,t)=>{let r=k(t),i=U(t);r.compare=e,i.compare=e},stencilPassOperation:(n,e,t)=>{let r=k(t),i=U(t);r.passOp=e,i.passOp=e},stencilFailOperation:(n,e,t)=>{let r=k(t),i=U(t);r.failOp=e,i.failOp=e},stencilDepthFailOperation:(n,e,t)=>{let r=k(t),i=U(t);r.depthFailOp=e,i.depthFailOp=e},sampleCount:(n,e,t)=>{t.multisample=t.multisample||{},t.multisample.count=e},sampleMask:(n,e,t)=>{t.multisample=t.multisample||{},t.multisample.mask=e},sampleAlphaToCoverageEnabled:(n,e,t)=>{t.multisample=t.multisample||{},t.multisample.alphaToCoverageEnabled=e},colorMask:(n,e,t)=>{let r=se(t);r[0].writeMask=e},blendColorOperation:(n,e,t)=>{se(t)}},Te={primitive:{cullMode:"back",topology:"triangle-list"},vertex:{module:void 0,entryPoint:"main"},fragment:{module:void 0,entryPoint:"main",targets:[]},layout:"auto"};function ae(n,e={}){Object.assign(n,{...Te,...n}),Ge(n,e)}function Ge(n,e){for(let[t,r]of Object.entries(e)){let i=Ae[t];if(!i)throw new Error(`Illegal parameter ${t}`);i(t,r,n)}}function se(n){if(n.fragment.targets=n.fragment?.targets||[],!Array.isArray(n.fragment?.targets))throw new Error("colorstate");return n.fragment?.targets?.length===0&&n.fragment.targets?.push({}),n.fragment?.targets}var x=d(o(),1);function V(n,e,t,r){let i=_e(r,t);return n.createBindGroup({layout:e,entries:i})}function Le(n,e){let t=n.bindings.find(r=>r.name===e||`${r.name}uniforms`===e.toLocaleLowerCase());return t||x.log.warn(`Binding ${e} not set: Not found in shader layout.`)(),t||null}function _e(n,e){let t=[];for(let[r,i]of Object.entries(n)){let s=Le(e,r);s&&t.push(De(i,s.location))}return t}function De(n,e){if(n instanceof x.Buffer)return{binding:e,resource:{buffer:n.handle}};if(n instanceof x.Sampler)return{binding:e,resource:n.handle};if(n instanceof x.Texture)return{binding:e,resource:n.handle.createView({label:"bind-group-auto-created"})};throw new Error("invalid binding")}var S=d(o(),1);function J(n){if(n.endsWith("-webgl"))throw new Error(`WebGPU does not support vertex format ${n}`);return n}function he(n,e){let t=[],r=new Set;for(let i of e){let s=[],a="vertex",l=0,c=i.format;if(i.attributes)for(let h of i.attributes){let g=h.attribute,m=oe(n,g,r),B=m?.location;a=m?.stepMode||(m?.name.startsWith("instance")?"instance":"vertex"),s.push({format:J(h.format||i.format),offset:h.byteOffset,shaderLocation:B}),l+=(0,S.decodeVertexFormat)(c).byteLength}else{let h=oe(n,i.name,r);if(!h)continue;l=(0,S.decodeVertexFormat)(c).byteLength,a=h.stepMode||(h.name.startsWith("instance")?"instance":"vertex"),s.push({format:J(c),offset:0,shaderLocation:h.location})}t.push({arrayStride:i.byteStride||l,stepMode:a,attributes:s})}for(let i of n.attributes)r.has(i.name)||t.push({arrayStride:(0,S.decodeVertexFormat)("float32x3").byteLength,stepMode:i.stepMode||(i.name.startsWith("instance")?"instance":"vertex"),attributes:[{format:J("float32x3"),offset:0,shaderLocation:i.location}]});return t}function oe(n,e,t){let r=n.attributes.find(i=>i.name===e);if(!r)return S.log.warn(`Unknown attribute ${e}`)(),null;if(t.has(e))throw new Error(`Duplicate attribute ${e}`);return t.add(e),r}var q=class extends C.RenderPipeline{device;handle;vs;fs=null;_bindings;_bindGroupLayout=null;_bindGroup=null;constructor(e,t){if(super(e,t),this.device=e,this.handle=this.props.handle,!this.handle){let r=this._getRenderPipelineDescriptor();C.log.groupCollapsed(1,`new WebGPURenderPipeline(${this.id})`)(),C.log.probe(1,JSON.stringify(r,null,2))(),C.log.groupEnd(1)(),this.handle=this.device.handle.createRenderPipeline(r)}this.handle.label=this.props.id,this.vs=t.vs,this.fs=t.fs,this._bindings={...this.props.bindings}}destroy(){this.handle=null}setBindings(e){Object.assign(this._bindings,e)}draw(e){let t=e.renderPass;t.handle.setPipeline(this.handle);let r=this._getBindGroup();return r&&t.handle.setBindGroup(0,r),e.vertexArray.bindBeforeRender(e.renderPass),e.indexCount?t.handle.drawIndexed(e.indexCount,e.instanceCount,e.firstIndex,e.baseVertex,e.firstInstance):t.handle.draw(e.vertexCount||0,e.instanceCount||1,e.firstInstance),e.vertexArray.unbindAfterRender(e.renderPass),!0}_getBindGroup(){return this.shaderLayout.bindings.length===0?null:(this._bindGroupLayout=this._bindGroupLayout||this.handle.getBindGroupLayout(0),this._bindGroup=this._bindGroup||V(this.device.handle,this._bindGroupLayout,this.shaderLayout,this._bindings),this._bindGroup)}_getRenderPipelineDescriptor(){let e={module:this.props.vs.handle,entryPoint:this.props.vertexEntryPoint||"main",buffers:he(this.shaderLayout,this.props.bufferLayout)},t={module:this.props.fs.handle,entryPoint:this.props.fragmentEntryPoint||"main",targets:[{format:w(this.device.getCanvasContext().format)}]},r={vertex:e,fragment:t,primitive:{topology:this.props.topology},layout:"auto"};return ae(r,this.props.parameters),r}};var de=d(o(),1),P=class extends de.Framebuffer{device;colorAttachments=[];depthStencilAttachment=null;constructor(e,t){super(e,t),this.device=e,this.autoCreateAttachmentTextures()}};var le=d(o(),1);var $=class extends le.ComputePipeline{device;handle;_bindGroupLayout=null;_bindGroup=null;_bindings={};constructor(e,t){super(e,t),this.device=e;let r=this.props.shader;this.handle=this.props.handle||this.device.handle.createComputePipeline({label:this.props.id,compute:{module:r.handle,entryPoint:this.props.entryPoint,constants:this.props.constants},layout:"auto"})}setBindings(e){Object.assign(this._bindings,e)}_getBindGroup(){return this._bindGroupLayout=this._bindGroupLayout||this.handle.getBindGroupLayout(0),this._bindGroup=this._bindGroup||V(this.device.handle,this._bindGroupLayout,this.shaderLayout,this._bindings),this._bindGroup}};var E=d(o(),1),z=class extends E.RenderPass{device;handle;pipeline=null;constructor(e,t={}){super(e,t),this.device=e;let r=t.framebuffer||e.getCanvasContext().getCurrentFramebuffer(),i=this.getRenderPassDescriptor(r),s=t.timestampQuerySet;if(s&&(i.occlusionQuerySet=s.handle),e.features.has("timestamp-query")){let a=t.timestampQuerySet;i.timestampWrites=a?{querySet:a.handle,beginningOfPassWriteIndex:t.beginTimestampIndex,endOfPassWriteIndex:t.endTimestampIndex}:void 0}if(!e.commandEncoder)throw new Error("commandEncoder not available");this.handle=this.props.handle||e.commandEncoder.beginRenderPass(i),this.handle.label=this.props.id,E.log.groupCollapsed(3,`new WebGPURenderPass(${this.id})`)(),E.log.probe(3,JSON.stringify(i,null,2))(),E.log.groupEnd(3)()}destroy(){}end(){this.handle.end()}setPipeline(e){this.pipeline=e,this.handle.setPipeline(this.pipeline.handle)}setBindings(e){this.pipeline?.setBindings(e);let t=this.pipeline?._getBindGroup();t&&this.handle.setBindGroup(0,t)}setIndexBuffer(e,t,r=0,i){this.handle.setIndexBuffer(e.handle,t,r,i)}setVertexBuffer(e,t,r=0){this.handle.setVertexBuffer(e,t.handle,r)}draw(e){e.indexCount?this.handle.drawIndexed(e.indexCount,e.instanceCount,e.firstIndex,e.baseVertex,e.firstInstance):this.handle.draw(e.vertexCount||0,e.instanceCount||1,e.firstIndex,e.firstInstance)}drawIndirect(){}setParameters(e){let{blendConstant:t,stencilReference:r,scissorRect:i,viewport:s}=e;t&&this.handle.setBlendConstant(t),r&&this.handle.setStencilReference(r),i&&this.handle.setScissorRect(i[0],i[1],i[2],i[3]),s&&this.handle.setViewport(s[0],s[1],s[2],s[3],s[4],s[5])}pushDebugGroup(e){this.handle.pushDebugGroup(e)}popDebugGroup(){this.handle.popDebugGroup()}insertDebugMarker(e){this.handle.insertDebugMarker(e)}beginOcclusionQuery(e){this.handle.beginOcclusionQuery(e)}endOcclusionQuery(){this.handle.endOcclusionQuery()}getRenderPassDescriptor(e){let t={colorAttachments:[]};if(t.colorAttachments=e.colorAttachments.map(r=>({loadOp:this.props.clearColor!==!1?"clear":"load",colorClearValue:this.props.clearColor||[0,0,0,0],storeOp:this.props.discard?"discard":"store",view:r.handle})),e.depthStencilAttachment){t.depthStencilAttachment={view:e.depthStencilAttachment.handle};let{depthStencilAttachment:r}=t;this.props.depthReadOnly&&(r.depthReadOnly=!0),r.depthClearValue=this.props.clearDepth||0,!0&&(r.depthLoadOp=this.props.clearDepth!==!1?"clear":"load",r.depthStoreOp="store"),!1&&(r.stencilLoadOp=this.props.clearStencil!==!1?"clear":"load",r.stencilStoreOp="store")}return t}};var ue=d(o(),1),Q=class extends ue.ComputePass{device;handle;_webgpuPipeline=null;constructor(e,t){super(e,t),this.device=e;let r;if(e.features.has("timestamp-query")){let i=t.timestampQuerySet;i&&(r={querySet:i.handle,beginningOfPassWriteIndex:t.beginTimestampIndex,endOfPassWriteIndex:t.endTimestampIndex})}this.handle=this.props.handle||e.commandEncoder?.beginComputePass({label:this.props.id,timestampWrites:r})}destroy(){}end(){this.handle.end()}setPipeline(e){let t=e;this.handle.setPipeline(t.handle),this._webgpuPipeline=t,this.setBindings([])}setBindings(e){let t=this._webgpuPipeline._getBindGroup();this.handle.setBindGroup(0,t)}dispatch(e,t,r){this.handle.dispatchWorkgroups(e,t,r)}dispatchIndirect(e,t=0){let r=e;this.handle.dispatchWorkgroupsIndirect(r.handle,t)}pushDebugGroup(e){this.handle.pushDebugGroup(e)}popDebugGroup(){this.handle.popDebugGroup()}insertDebugMarker(e){this.handle.insertDebugMarker(e)}};var G=d(o(),1);var st=globalThis.document||{},at=globalThis.process||{},ot=globalThis.console,pe=globalThis.navigator||{};function N(n){if(typeof window<"u"&&window.process?.type==="renderer"||typeof process<"u"&&Boolean(process.versions?.electron))return!0;let e=typeof navigator<"u"&&navigator.userAgent,t=n||e;return Boolean(t&&t.indexOf("Electron")>=0)}function ce(){return!(typeof process=="object"&&String(process)==="[object process]"&&!process?.browser)||N()}function Z(n){return!n&&!ce()?"Node":N(n)?"Electron":(n||pe.userAgent||"").indexOf("Edge")>-1?"Edge":globalThis.chrome?"Chrome":globalThis.safari?"Safari":globalThis.mozInnerScreenX?"Firefox":"Unknown"}var j=class extends G.VertexArray{get[Symbol.toStringTag](){return"WebGPUVertexArray"}device;handle;constructor(e,t){super(e,t),this.device=e}destroy(){}setIndexBuffer(e){this.indexBuffer=e}setBuffer(e,t){this.attributes[e]=t}bindBeforeRender(e,t,r){let i=e,s=this.indexBuffer;s?.handle&&(G.log.warn("setting index buffer",s?.handle,s?.indexType)(),i.handle.setIndexBuffer(s?.handle,s?.indexType));for(let a=0;a<this.maxVertexAttributes;a++){let l=this.attributes[a];l?.handle&&(G.log.warn(`setting vertex buffer ${a}`,l?.handle)(),i.handle.setVertexBuffer(a,l?.handle))}}unbindAfterRender(e){}static isConstantAttributeZeroSupported(e){return Z()==="Chrome"}};var Y=d(o(),1);var L=class extends Y.CanvasContext{device;gpuCanvasContext;format=navigator.gpu.getPreferredCanvasFormat();depthStencilFormat="depth24plus";depthStencilAttachment=null;constructor(e,t,r){super(r),this.device=e,this.width=-1,this.height=-1,this._setAutoCreatedCanvasId(`${this.device.id}-canvas`),this.gpuCanvasContext=this.canvas.getContext("webgpu"),this.format="bgra8unorm"}destroy(){this.gpuCanvasContext.unconfigure()}getCurrentFramebuffer(){this.update();let e=this.getCurrentTexture();return this.width=e.width,this.height=e.height,this._createDepthStencilAttachment(),new P(this.device,{colorAttachments:[e],depthStencilAttachment:this.depthStencilAttachment})}update(){let[e,t]=this.getPixelSize();(e!==this.width||t!==this.height)&&(this.width=e,this.height=t,this.depthStencilAttachment&&(this.depthStencilAttachment.destroy(),this.depthStencilAttachment=null),this.gpuCanvasContext.configure({device:this.device.handle,format:w(this.format),colorSpace:this.props.colorSpace,alphaMode:this.props.alphaMode}),Y.log.log(1,`Resized to ${this.width}x${this.height}px`)())}resize(e){this.update()}getCurrentTexture(){return this.device._createTexture({id:`${this.id}#color-texture`,handle:this.gpuCanvasContext.getCurrentTexture(),format:this.format})}_createDepthStencilAttachment(){return this.depthStencilAttachment||(this.depthStencilAttachment=this.device.createTexture({id:`${this.id}#depth-stencil-texture`,format:this.depthStencilFormat,width:this.width,height:this.height,usage:GPUTextureUsage.RENDER_ATTACHMENT})),this.depthStencilAttachment}};var me=d(o(),1),H=class extends me.QuerySet{device;handle;constructor(e,t){super(e,t),this.device=e,this.handle=this.props.handle||this.device.handle.createQuerySet({type:this.props.type,count:this.props.count}),this.handle.label=this.props.id}destroy(){this.handle?.destroy(),this.handle=null}};var K=class extends p.Device{type="webgpu";handle;adapter;adapterInfo;features;info;limits;lost;canvasContext=null;_isLost=!1;commandEncoder=null;renderPass=null;static isSupported(){return Boolean(typeof navigator<"u"&&navigator.gpu)}static async create(e){if(!navigator.gpu)throw new Error("WebGPU not available. Open in Chrome Canary and turn on chrome://flags/#enable-unsafe-webgpu");p.log.groupCollapsed(1,"WebGPUDevice created")();let t=await navigator.gpu.requestAdapter({powerPreference:"high-performance"});if(!t)throw new Error("Failed to request WebGPU adapter");let r=await t.requestAdapterInfo();p.log.probe(2,"Adapter available",r)();let i=[],s={};if(e.requestMaxLimits){i.push(...Array.from(t.features));let c=Object.keys(t.limits).filter(h=>!["minSubgroupSize","maxSubgroupSize"].includes(h));for(let h of c){let g=h,m=t.limits[g];typeof m=="number"&&(s[g]=m)}}let a=await t.requestDevice({requiredFeatures:i,requiredLimits:s});p.log.probe(1,"GPUDevice available")(),typeof e.canvas=="string"&&(await p.CanvasContext.pageLoaded,p.log.probe(1,"DOM is loaded")());let l=new K(a,t,r,e);return p.log.probe(1,"Device created. For more info, set chrome://flags/#enable-webgpu-developer-features")(),p.log.table(1,l.info)(),p.log.groupEnd(1)(),l}constructor(e,t,r,i){super({...i,id:i.id||"webgpu-device"}),this.handle=e,this.adapter=t,this.adapterInfo=r,this.info=this._getInfo(),this.features=this._getFeatures(),this.limits=this.handle.limits,e.addEventListener("uncapturederror",s=>{let a=s instanceof GPUUncapturedErrorEvent?s.error.message:"Unknown error";this.error(new Error(a))}),this.lost=new Promise(async s=>{let a=await this.handle.lost;this._isLost=!0,s({reason:"destroyed",message:a.message})}),this.canvasContext=new L(this,this.adapter,{canvas:i.canvas,height:i.height,width:i.width,container:i.container})}destroy(){this.handle.destroy()}isTextureFormatSupported(e){return!e.includes("webgl")}isTextureFormatFilterable(e){return this.isTextureFormatSupported(e)&&!e.startsWith("depth")&&!e.startsWith("stencil")}isTextureFormatRenderable(e){return this.isTextureFormatSupported(e)}get isLost(){return this._isLost}createBuffer(e){let t=this._getBufferProps(e);return new b(this,t)}_createTexture(e){return new y(this,e)}createExternalTexture(e){return new M(this,e)}createShader(e){return new v(this,e)}createSampler(e){return new u(this,e)}createRenderPipeline(e){return new q(this,e)}createFramebuffer(e){return new P(this,e)}createComputePipeline(e){return new $(this,e)}createVertexArray(e){return new j(this,e)}beginRenderPass(e){return this.commandEncoder=this.commandEncoder||this.handle.createCommandEncoder(),new z(this,e)}beginComputePass(e){return this.commandEncoder=this.commandEncoder||this.handle.createCommandEncoder(),new Q(this,e)}createTransformFeedback(e){throw new Error("Transform feedback not supported in WebGPU")}createQuerySet(e){return new H(this,e)}createCanvasContext(e){return new L(this,this.adapter,e)}submit(){let e=this.commandEncoder?.finish();e&&this.handle.queue.submit([e]),this.commandEncoder=null}_getInfo(){let[e,t]=(this.adapterInfo.driver||"").split(" Version "),r=this.adapterInfo.vendor||this.adapter.__brand||"unknown",i=e||"",s=t||"",a=r==="apple"?"apple":"unknown",l=this.adapterInfo.architecture||"unknown",c=this.adapterInfo.backend||"unknown",h=(this.adapterInfo.type||"").split(" ")[0].toLowerCase()||"unknown";return{type:"webgpu",vendor:r,renderer:i,version:s,gpu:a,gpuType:h,gpuBackend:c,gpuArchitecture:l,shadingLanguage:"wgsl",shadingLanguageVersion:100}}_getFeatures(){let e=new Set(this.handle.features);e.has("depth-clamping")&&(e.delete("depth-clamping"),e.add("depth-clip-control")),e.has("texture-compression-bc")&&e.add("texture-compression-bc5-webgl");let t=["timer-query-webgl","compilation-status-async-webgl","float32-renderable-webgl","float16-renderable-webgl","norm16-renderable-webgl","texture-filterable-anisotropic-webgl","shader-noperspective-interpolation-webgl"];for(let r of t)e.add(r);return new p.DeviceFeatures(Array.from(e),this.props.disabledFeatures)}copyExternalImageToTexture(e){let{source:t,sourceX:r=0,sourceY:i=0,texture:s,mipLevel:a=0,aspect:l="all",colorSpace:c="display-p3",premultipliedAlpha:h=!1,width:g=s.width,height:m=s.height,depth:B=1}=e,X=s;this.handle?.queue.copyExternalImageToTexture({source:t,origin:[r,i]},{texture:X.handle,origin:[0,0,0],mipLevel:a,aspect:l,colorSpace:c,premultipliedAlpha:h},[g,m,B])}},_=K;ee(_,"type","webgpu");return Pe(D);})();
7
+ var __exports__=(()=>{var xe=Object.create;var F=Object.defineProperty;var we=Object.getOwnPropertyDescriptor;var ye=Object.getOwnPropertyNames;var ve=Object.getPrototypeOf,Se=Object.prototype.hasOwnProperty;var Ce=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),Pe=(n,e)=>{for(var t in e)F(n,t,{get:e[t],enumerable:!0})},I=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of ye(e))!Se.call(n,i)&&i!==t&&F(n,i,{get:()=>e[i],enumerable:!(r=we(e,i))||r.enumerable});return n},O=(n,e,t)=>(I(n,e,"default"),t&&I(t,e,"default")),h=(n,e,t)=>(t=n!=null?xe(ve(n)):{},I(e||!n||!n.__esModule?F(t,"default",{value:n,enumerable:!0}):t,n)),Ee=n=>I(F({},"__esModule",{value:!0}),n);var o=Ce((Oe,te)=>{te.exports=globalThis.luma});var D={};Pe(D,{WebGPUBuffer:()=>b,WebGPUDevice:()=>w,WebGPUSampler:()=>p,WebGPUShader:()=>C,WebGPUTexture:()=>S,webgpuAdapter:()=>fe});O(D,h(o(),1));var u=h(o(),1);var X=h(o(),1);var R=h(o(),1);function Be(n){return n.byteLength||n.data?.byteLength||0}var b=class extends R.Buffer{device;handle;byteLength;constructor(e,t){super(e,t),this.device=e,this.byteLength=Be(t);let r=Boolean(t.data),i=Math.ceil(this.byteLength/4)*4;this.handle=this.props.handle||this.device.handle.createBuffer({size:i,usage:this.props.usage||GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST,mappedAtCreation:this.props.mappedAtCreation||r,label:this.props.id}),t.data&&this._writeMapped(t.data),r&&!t.mappedAtCreation&&this.handle.unmap()}destroy(){this.handle?.destroy(),this.handle=null}write(e,t=0){this.device.handle.queue.writeBuffer(this.handle,t,e.buffer,e.byteOffset,e.byteLength)}async readAsync(e=0,t=this.byteLength){let r=new b(this.device,{usage:R.Buffer.MAP_READ|R.Buffer.COPY_DST,byteLength:t}),i=this.device.handle.createCommandEncoder();i.copyBufferToBuffer(this.handle,e,r.handle,0,t),this.device.handle.queue.submit([i.finish()]),await r.handle.mapAsync(GPUMapMode.READ,e,t);let s=r.handle.getMappedRange().slice(0);return r.handle.unmap(),r.destroy(),new Uint8Array(s)}_writeMapped(e){let t=this.handle.getMappedRange();new e.constructor(t).set(e)}mapAsync(e,t=0,r){return this.handle.mapAsync(e,t,r)}getMappedRange(e=0,t){return this.handle.getMappedRange(e,t)}unmap(){this.handle.unmap()}};var v=h(o(),1);function y(n){if(n.includes("webgl"))throw new Error("webgl-only format");return n}var re=h(o(),1),p=class extends re.Sampler{device;handle;constructor(e,t){super(e,t),this.device=e;let r={...this.props};r.type!=="comparison-sampler"&&delete r.compare,this.handle=this.handle||this.device.handle.createSampler(r),this.handle.label=this.props.id}destroy(){this.handle=null}};var ne=h(o(),1),G=class extends ne.TextureView{device;handle;texture;constructor(e,t){super(e,t),this.device=e,this.texture=t.texture,this.handle=this.handle||this.texture.handle.createView({format:t.format||this.texture.format,dimension:t.dimension||this.texture.dimension,aspect:t.aspect,baseMipLevel:t.baseMipLevel,mipLevelCount:t.mipLevelCount,baseArrayLayer:t.baseArrayLayer,arrayLayerCount:t.arrayLayerCount}),this.handle.label=this.props.id}destroy(){this.handle=null}};var Ae={"1d":"1d","2d":"2d","2d-array":"2d",cube:"2d","cube-array":"2d","3d":"3d"},S=class extends v.Texture{device;handle;height=1;width=1;sampler;view;constructor(e,t){if(super(e,t),this.device=e,t.data instanceof Promise){t.data.then(r=>{this.props={...this.props,data:r},this.initialize(this.props)});return}this.initialize(t)}destroy(){this.handle?.destroy(),this.handle=null}createView(e){return new G(this.device,{...e,texture:this})}initialize(e){this.handle=this.props.handle||this.createHandle(),this.handle.label||=this.id,this.props.data&&(v.Texture.isExternalImage(this.props.data)?this.setImage({source:this.props.data}):this.setData({data:this.props.data})),this.width=this.handle.width,this.height=this.handle.height,this.sampler=e.sampler instanceof p?e.sampler:new p(this.device,e.sampler||{}),this.view=new G(this.device,{...this.props,texture:this})}createHandle(){let e=this.props.width||this.props.data?.width||1,t=this.props.height||this.props.data?.height||1;return this.device.handle.createTexture({label:this.id,size:{width:e,height:t,depthOrArrayLayers:this.depth},usage:this.props.usage||v.Texture.TEXTURE|v.Texture.COPY_DST,dimension:Ae[this.dimension],format:y(this.format),mipLevelCount:this.mipLevels,sampleCount:this.props.samples})}createGPUTextureView(){return this.handle.createView({label:this.id})}setSampler(e){return this.sampler=e instanceof p?e:new p(this.device,e),this}setTexture1DData(e){throw new Error("not implemented")}setTexture2DData(e,t,r){throw new Error("not implemented")}setTexture3DData(e,t,r){throw new Error("not implemented")}setTextureCubeData(e,t){throw new Error("not implemented")}setTextureArrayData(e){throw new Error("not implemented")}setTextureCubeArrayData(e){throw new Error("not implemented")}setData(e){let t=e.data;if(ArrayBuffer.isView(e.data)){let r=new Uint8ClampedArray(e.data.buffer);t=new ImageData(r,this.width,this.height)}return this.setImage({source:t})}setImage(e){let t=v.Texture.getExternalImageSize(e.source),{source:r,width:i=t.width,height:s=t.height,depth:a=1,sourceX:l=0,sourceY:c=0,mipLevel:d=0,x:g=0,y:m=0,z:T=0,aspect:J="all",colorSpace:ge="srgb",premultipliedAlpha:be=!1}=e;return this.device.handle.queue.copyExternalImageToTexture({source:r,origin:[l,c]},{texture:this.handle,origin:[g,m,T],mipLevel:d,aspect:J,colorSpace:ge,premultipliedAlpha:be},[i,s,a]),{width:i,height:s}}};var ie=h(o(),1);var M=class extends ie.ExternalTexture{device;handle;sampler;constructor(e,t){super(e,t),this.device=e,this.handle=this.props.handle||this.device.handle.importExternalTexture({source:t.source,colorSpace:t.colorSpace}),this.sampler=null}destroy(){this.handle=null}setSampler(e){return this.sampler=e instanceof p?e:new p(this.device,e),this}};var W=h(o(),1),C=class extends W.Shader{device;handle;constructor(e,t){super(e,t),this.device=e,this.device.handle.pushErrorScope("validation"),this.handle=this.props.handle||this.createHandle(),this.handle.label=this.props.id,this._checkCompilationError(this.device.handle.popErrorScope())}async _checkCompilationError(e){let t=await e;if(t){this.debugShader();let r=await this.getCompilationInfo();throw W.log.error(`Shader compilation error: ${t.message}`,r)(),new Error(`Shader compilation error: ${t.message}`)}}destroy(){this.handle=null}async getCompilationInfo(){return(await this.handle.getCompilationInfo()).messages}createHandle(){let{source:e}=this.props,t=e.includes("#version");if(this.props.language==="glsl"||t)throw new Error("GLSL shaders are not supported in WebGPU");return this.device.handle.createShaderModule({code:e})}};var E=h(o(),1);function f(n){return n.depthStencil=n.depthStencil||{format:"depth24plus",stencilFront:{},stencilBack:{},depthWriteEnabled:!1,depthCompare:"less-equal"},n.depthStencil}function U(n){return f(n).stencilFront}function k(n){return f(n).stencilBack}var Te={cullMode:(n,e,t)=>{t.primitive=t.primitive||{},t.primitive.cullMode=e},frontFace:(n,e,t)=>{t.primitive=t.primitive||{},t.primitive.frontFace=e},depthWriteEnabled:(n,e,t)=>{let r=f(t);r.depthWriteEnabled=e},depthCompare:(n,e,t)=>{let r=f(t);r.depthCompare=e},depthFormat:(n,e,t)=>{let r=f(t);r.format=e},depthBias:(n,e,t)=>{let r=f(t);r.depthBias=e},depthBiasSlopeScale:(n,e,t)=>{let r=f(t);r.depthBiasSlopeScale=e},depthBiasClamp:(n,e,t)=>{let r=f(t);r.depthBiasClamp=e},stencilReadMask:(n,e,t)=>{let r=f(t);r.stencilReadMask=e},stencilWriteMask:(n,e,t)=>{let r=f(t);r.stencilWriteMask=e},stencilCompare:(n,e,t)=>{let r=U(t),i=k(t);r.compare=e,i.compare=e},stencilPassOperation:(n,e,t)=>{let r=U(t),i=k(t);r.passOp=e,i.passOp=e},stencilFailOperation:(n,e,t)=>{let r=U(t),i=k(t);r.failOp=e,i.failOp=e},stencilDepthFailOperation:(n,e,t)=>{let r=U(t),i=k(t);r.depthFailOp=e,i.depthFailOp=e},sampleCount:(n,e,t)=>{t.multisample=t.multisample||{},t.multisample.count=e},sampleMask:(n,e,t)=>{t.multisample=t.multisample||{},t.multisample.mask=e},sampleAlphaToCoverageEnabled:(n,e,t)=>{t.multisample=t.multisample||{},t.multisample.alphaToCoverageEnabled=e},colorMask:(n,e,t)=>{let r=se(t);r[0].writeMask=e},blendColorOperation:(n,e,t)=>{se(t)}},Ge={primitive:{cullMode:"back",topology:"triangle-list"},vertex:{module:void 0,entryPoint:"main"},fragment:{module:void 0,entryPoint:"main",targets:[]},layout:"auto"};function ae(n,e={}){Object.assign(n,{...Ge,...n}),Le(n,e)}function Le(n,e){for(let[t,r]of Object.entries(e)){let i=Te[t];if(!i)throw new Error(`Illegal parameter ${t}`);i(t,r,n)}}function se(n){if(n.fragment.targets=n.fragment?.targets||[],!Array.isArray(n.fragment?.targets))throw new Error("colorstate");return n.fragment?.targets?.length===0&&n.fragment.targets?.push({}),n.fragment?.targets}var x=h(o(),1);function V(n,e,t,r){let i=De(r,t);return n.createBindGroup({layout:e,entries:i})}function _e(n,e){let t=n.bindings.find(r=>r.name===e||`${r.name}uniforms`===e.toLocaleLowerCase());return t||x.log.warn(`Binding ${e} not set: Not found in shader layout.`)(),t||null}function De(n,e){let t=[];for(let[r,i]of Object.entries(n)){let s=_e(e,r);s&&t.push(Ie(i,s.location))}return t}function Ie(n,e){if(n instanceof x.Buffer)return{binding:e,resource:{buffer:n.handle}};if(n instanceof x.Sampler)return{binding:e,resource:n.handle};if(n instanceof x.Texture)return{binding:e,resource:n.handle.createView({label:"bind-group-auto-created"})};throw new Error("invalid binding")}var P=h(o(),1);function Z(n){if(n.endsWith("-webgl"))throw new Error(`WebGPU does not support vertex format ${n}`);return n}function he(n,e){let t=[],r=new Set;for(let i of e){let s=[],a="vertex",l=0,c=i.format;if(i.attributes)for(let d of i.attributes){let g=d.attribute,m=oe(n,g,r),T=m?.location;a=m?.stepMode||(m?.name.startsWith("instance")?"instance":"vertex"),s.push({format:Z(d.format||i.format),offset:d.byteOffset,shaderLocation:T}),l+=(0,P.decodeVertexFormat)(c).byteLength}else{let d=oe(n,i.name,r);if(!d)continue;l=(0,P.decodeVertexFormat)(c).byteLength,a=d.stepMode||(d.name.startsWith("instance")?"instance":"vertex"),s.push({format:Z(c),offset:0,shaderLocation:d.location})}t.push({arrayStride:i.byteStride||l,stepMode:a,attributes:s})}for(let i of n.attributes)r.has(i.name)||t.push({arrayStride:(0,P.decodeVertexFormat)("float32x3").byteLength,stepMode:i.stepMode||(i.name.startsWith("instance")?"instance":"vertex"),attributes:[{format:Z("float32x3"),offset:0,shaderLocation:i.location}]});return t}function oe(n,e,t){let r=n.attributes.find(i=>i.name===e);if(!r)return P.log.warn(`Unknown attribute ${e}`)(),null;if(t.has(e))throw new Error(`Duplicate attribute ${e}`);return t.add(e),r}var q=class extends E.RenderPipeline{device;handle;vs;fs=null;_bindings;_bindGroupLayout=null;_bindGroup=null;constructor(e,t){if(super(e,t),this.device=e,this.handle=this.props.handle,!this.handle){let r=this._getRenderPipelineDescriptor();E.log.groupCollapsed(1,`new WebGPURenderPipeline(${this.id})`)(),E.log.probe(1,JSON.stringify(r,null,2))(),E.log.groupEnd(1)(),this.handle=this.device.handle.createRenderPipeline(r)}this.handle.label=this.props.id,this.vs=t.vs,this.fs=t.fs,this._bindings={...this.props.bindings}}destroy(){this.handle=null}setBindings(e){Object.assign(this._bindings,e)}draw(e){let t=e.renderPass;t.handle.setPipeline(this.handle);let r=this._getBindGroup();return r&&t.handle.setBindGroup(0,r),e.vertexArray.bindBeforeRender(e.renderPass),e.indexCount?t.handle.drawIndexed(e.indexCount,e.instanceCount,e.firstIndex,e.baseVertex,e.firstInstance):t.handle.draw(e.vertexCount||0,e.instanceCount||1,e.firstInstance),e.vertexArray.unbindAfterRender(e.renderPass),!0}_getBindGroup(){return this.shaderLayout.bindings.length===0?null:(this._bindGroupLayout=this._bindGroupLayout||this.handle.getBindGroupLayout(0),this._bindGroup=this._bindGroup||V(this.device.handle,this._bindGroupLayout,this.shaderLayout,this._bindings),this._bindGroup)}_getRenderPipelineDescriptor(){let e={module:this.props.vs.handle,entryPoint:this.props.vertexEntryPoint||"main",buffers:he(this.shaderLayout,this.props.bufferLayout)},t={module:this.props.fs.handle,entryPoint:this.props.fragmentEntryPoint||"main",targets:[{format:y(this.device.getCanvasContext().format)}]},r={vertex:e,fragment:t,primitive:{topology:this.props.topology},layout:"auto"};return ae(r,this.props.parameters),r}};var de=h(o(),1),B=class extends de.Framebuffer{device;colorAttachments=[];depthStencilAttachment=null;constructor(e,t){super(e,t),this.device=e,this.autoCreateAttachmentTextures()}};var le=h(o(),1);var z=class extends le.ComputePipeline{device;handle;_bindGroupLayout=null;_bindGroup=null;_bindings={};constructor(e,t){super(e,t),this.device=e;let r=this.props.shader;this.handle=this.props.handle||this.device.handle.createComputePipeline({label:this.props.id,compute:{module:r.handle,entryPoint:this.props.entryPoint,constants:this.props.constants},layout:"auto"})}setBindings(e){Object.assign(this._bindings,e)}_getBindGroup(){return this._bindGroupLayout=this._bindGroupLayout||this.handle.getBindGroupLayout(0),this._bindGroup=this._bindGroup||V(this.device.handle,this._bindGroupLayout,this.shaderLayout,this._bindings),this._bindGroup}};var A=h(o(),1),$=class extends A.RenderPass{device;handle;pipeline=null;constructor(e,t={}){super(e,t),this.device=e;let r=t.framebuffer||e.getCanvasContext().getCurrentFramebuffer(),i=this.getRenderPassDescriptor(r),s=t.timestampQuerySet;if(s&&(i.occlusionQuerySet=s.handle),e.features.has("timestamp-query")){let a=t.timestampQuerySet;i.timestampWrites=a?{querySet:a.handle,beginningOfPassWriteIndex:t.beginTimestampIndex,endOfPassWriteIndex:t.endTimestampIndex}:void 0}if(!e.commandEncoder)throw new Error("commandEncoder not available");this.handle=this.props.handle||e.commandEncoder.beginRenderPass(i),this.handle.label=this.props.id,A.log.groupCollapsed(3,`new WebGPURenderPass(${this.id})`)(),A.log.probe(3,JSON.stringify(i,null,2))(),A.log.groupEnd(3)()}destroy(){}end(){this.handle.end()}setPipeline(e){this.pipeline=e,this.handle.setPipeline(this.pipeline.handle)}setBindings(e){this.pipeline?.setBindings(e);let t=this.pipeline?._getBindGroup();t&&this.handle.setBindGroup(0,t)}setIndexBuffer(e,t,r=0,i){this.handle.setIndexBuffer(e.handle,t,r,i)}setVertexBuffer(e,t,r=0){this.handle.setVertexBuffer(e,t.handle,r)}draw(e){e.indexCount?this.handle.drawIndexed(e.indexCount,e.instanceCount,e.firstIndex,e.baseVertex,e.firstInstance):this.handle.draw(e.vertexCount||0,e.instanceCount||1,e.firstIndex,e.firstInstance)}drawIndirect(){}setParameters(e){let{blendConstant:t,stencilReference:r,scissorRect:i,viewport:s}=e;t&&this.handle.setBlendConstant(t),r&&this.handle.setStencilReference(r),i&&this.handle.setScissorRect(i[0],i[1],i[2],i[3]),s&&this.handle.setViewport(s[0],s[1],s[2],s[3],s[4],s[5])}pushDebugGroup(e){this.handle.pushDebugGroup(e)}popDebugGroup(){this.handle.popDebugGroup()}insertDebugMarker(e){this.handle.insertDebugMarker(e)}beginOcclusionQuery(e){this.handle.beginOcclusionQuery(e)}endOcclusionQuery(){this.handle.endOcclusionQuery()}getRenderPassDescriptor(e){let t={colorAttachments:[]};if(t.colorAttachments=e.colorAttachments.map(r=>({loadOp:this.props.clearColor!==!1?"clear":"load",colorClearValue:this.props.clearColor||[0,0,0,0],storeOp:this.props.discard?"discard":"store",view:r.handle})),e.depthStencilAttachment){t.depthStencilAttachment={view:e.depthStencilAttachment.handle};let{depthStencilAttachment:r}=t;this.props.depthReadOnly&&(r.depthReadOnly=!0),r.depthClearValue=this.props.clearDepth||0,!0&&(r.depthLoadOp=this.props.clearDepth!==!1?"clear":"load",r.depthStoreOp="store"),!1&&(r.stencilLoadOp=this.props.clearStencil!==!1?"clear":"load",r.stencilStoreOp="store")}return t}};var pe=h(o(),1),Q=class extends pe.ComputePass{device;handle;_webgpuPipeline=null;constructor(e,t){super(e,t),this.device=e;let r;if(e.features.has("timestamp-query")){let i=t.timestampQuerySet;i&&(r={querySet:i.handle,beginningOfPassWriteIndex:t.beginTimestampIndex,endOfPassWriteIndex:t.endTimestampIndex})}this.handle=this.props.handle||e.commandEncoder?.beginComputePass({label:this.props.id,timestampWrites:r})}destroy(){}end(){this.handle.end()}setPipeline(e){let t=e;this.handle.setPipeline(t.handle),this._webgpuPipeline=t,this.setBindings([])}setBindings(e){let t=this._webgpuPipeline._getBindGroup();this.handle.setBindGroup(0,t)}dispatch(e,t,r){this.handle.dispatchWorkgroups(e,t,r)}dispatchIndirect(e,t=0){let r=e;this.handle.dispatchWorkgroupsIndirect(r.handle,t)}pushDebugGroup(e){this.handle.pushDebugGroup(e)}popDebugGroup(){this.handle.popDebugGroup()}insertDebugMarker(e){this.handle.insertDebugMarker(e)}};var L=h(o(),1);var at=globalThis.document||{},ot=globalThis.process||{},ht=globalThis.console,ue=globalThis.navigator||{};function N(n){if(typeof window<"u"&&window.process?.type==="renderer"||typeof process<"u"&&Boolean(process.versions?.electron))return!0;let e=typeof navigator<"u"&&navigator.userAgent,t=n||e;return Boolean(t&&t.indexOf("Electron")>=0)}function ce(){return!(typeof process=="object"&&String(process)==="[object process]"&&!process?.browser)||N()}function K(n){return!n&&!ce()?"Node":N(n)?"Electron":(n||ue.userAgent||"").indexOf("Edge")>-1?"Edge":globalThis.chrome?"Chrome":globalThis.safari?"Safari":globalThis.mozInnerScreenX?"Firefox":"Unknown"}var j=class extends L.VertexArray{get[Symbol.toStringTag](){return"WebGPUVertexArray"}device;handle;constructor(e,t){super(e,t),this.device=e}destroy(){}setIndexBuffer(e){this.indexBuffer=e}setBuffer(e,t){this.attributes[e]=t}bindBeforeRender(e,t,r){let i=e,s=this.indexBuffer;s?.handle&&(L.log.warn("setting index buffer",s?.handle,s?.indexType)(),i.handle.setIndexBuffer(s?.handle,s?.indexType));for(let a=0;a<this.maxVertexAttributes;a++){let l=this.attributes[a];l?.handle&&(L.log.warn(`setting vertex buffer ${a}`,l?.handle)(),i.handle.setVertexBuffer(a,l?.handle))}}unbindAfterRender(e){}static isConstantAttributeZeroSupported(e){return K()==="Chrome"}};var Y=h(o(),1);var _=class extends Y.CanvasContext{device;gpuCanvasContext;format=navigator.gpu.getPreferredCanvasFormat();depthStencilFormat="depth24plus";depthStencilAttachment=null;constructor(e,t,r){super(r),this.device=e,this.width=-1,this.height=-1,this._setAutoCreatedCanvasId(`${this.device.id}-canvas`),this.gpuCanvasContext=this.canvas.getContext("webgpu"),this.format="bgra8unorm"}destroy(){this.gpuCanvasContext.unconfigure()}getCurrentFramebuffer(){this.update();let e=this.getCurrentTexture();return this.width=e.width,this.height=e.height,this._createDepthStencilAttachment(),new B(this.device,{colorAttachments:[e],depthStencilAttachment:this.depthStencilAttachment})}update(){let[e,t]=this.getPixelSize();(e!==this.width||t!==this.height)&&(this.width=e,this.height=t,this.depthStencilAttachment&&(this.depthStencilAttachment.destroy(),this.depthStencilAttachment=null),this.gpuCanvasContext.configure({device:this.device.handle,format:y(this.format),colorSpace:this.props.colorSpace,alphaMode:this.props.alphaMode}),Y.log.log(1,`Resized to ${this.width}x${this.height}px`)())}resize(e){this.update()}getCurrentTexture(){return this.device._createTexture({id:`${this.id}#color-texture`,handle:this.gpuCanvasContext.getCurrentTexture(),format:this.format})}_createDepthStencilAttachment(){return this.depthStencilAttachment||(this.depthStencilAttachment=this.device.createTexture({id:`${this.id}#depth-stencil-texture`,format:this.depthStencilFormat,width:this.width,height:this.height,usage:GPUTextureUsage.RENDER_ATTACHMENT})),this.depthStencilAttachment}};var me=h(o(),1),H=class extends me.QuerySet{device;handle;constructor(e,t){super(e,t),this.device=e,this.handle=this.props.handle||this.device.handle.createQuerySet({type:this.props.type,count:this.props.count}),this.handle.label=this.props.id}destroy(){this.handle?.destroy(),this.handle=null}};var w=class extends X.Device{type="webgpu";handle;adapter;adapterInfo;features;info;limits;lost;canvasContext=null;_isLost=!1;commandEncoder=null;renderPass=null;constructor(e,t,r,i){super({...e,id:e.id||"webgpu-device"}),this.handle=t,this.adapter=r,this.adapterInfo=i,this.info=this._getInfo(),this.features=this._getFeatures(),this.limits=this.handle.limits,t.addEventListener("uncapturederror",s=>{let a=s instanceof GPUUncapturedErrorEvent?s.error.message:"Unknown error";this.error(new Error(a))}),this.lost=new Promise(async s=>{let a=await this.handle.lost;this._isLost=!0,s({reason:"destroyed",message:a.message})}),this.canvasContext=new _(this,this.adapter,{canvas:e.canvas,height:e.height,width:e.width,container:e.container})}destroy(){this.handle.destroy()}isTextureFormatSupported(e){return!e.includes("webgl")}isTextureFormatFilterable(e){return this.isTextureFormatSupported(e)&&!e.startsWith("depth")&&!e.startsWith("stencil")}isTextureFormatRenderable(e){return this.isTextureFormatSupported(e)}get isLost(){return this._isLost}createBuffer(e){let t=this._getBufferProps(e);return new b(this,t)}_createTexture(e){return new S(this,e)}createExternalTexture(e){return new M(this,e)}createShader(e){return new C(this,e)}createSampler(e){return new p(this,e)}createRenderPipeline(e){return new q(this,e)}createFramebuffer(e){return new B(this,e)}createComputePipeline(e){return new z(this,e)}createVertexArray(e){return new j(this,e)}beginRenderPass(e){return this.commandEncoder=this.commandEncoder||this.handle.createCommandEncoder(),new $(this,e)}beginComputePass(e){return this.commandEncoder=this.commandEncoder||this.handle.createCommandEncoder(),new Q(this,e)}createTransformFeedback(e){throw new Error("Transform feedback not supported in WebGPU")}createQuerySet(e){return new H(this,e)}createCanvasContext(e){return new _(this,this.adapter,e)}submit(){let e=this.commandEncoder?.finish();e&&this.handle.queue.submit([e]),this.commandEncoder=null}_getInfo(){let[e,t]=(this.adapterInfo.driver||"").split(" Version "),r=this.adapterInfo.vendor||this.adapter.__brand||"unknown",i=e||"",s=t||"",a=r==="apple"?"apple":"unknown",l=this.adapterInfo.architecture||"unknown",c=this.adapterInfo.backend||"unknown",d=(this.adapterInfo.type||"").split(" ")[0].toLowerCase()||"unknown";return{type:"webgpu",vendor:r,renderer:i,version:s,gpu:a,gpuType:d,gpuBackend:c,gpuArchitecture:l,shadingLanguage:"wgsl",shadingLanguageVersion:100}}_getFeatures(){let e=new Set(this.handle.features);e.has("depth-clamping")&&(e.delete("depth-clamping"),e.add("depth-clip-control")),e.has("texture-compression-bc")&&e.add("texture-compression-bc5-webgl");let t=["timer-query-webgl","compilation-status-async-webgl","float32-renderable-webgl","float16-renderable-webgl","norm16-renderable-webgl","texture-filterable-anisotropic-webgl","shader-noperspective-interpolation-webgl"];for(let r of t)e.add(r);return new X.DeviceFeatures(Array.from(e),this.props.disabledFeatures)}copyExternalImageToTexture(e){let{source:t,sourceX:r=0,sourceY:i=0,texture:s,mipLevel:a=0,aspect:l="all",colorSpace:c="display-p3",premultipliedAlpha:d=!1,width:g=s.width,height:m=s.height,depth:T=1}=e,J=s;this.handle?.queue.copyExternalImageToTexture({source:t,origin:[r,i]},{texture:J.handle,origin:[0,0,0],mipLevel:a,aspect:l,colorSpace:c,premultipliedAlpha:d},[g,m,T])}};var ee=class extends u.Adapter{type="webgpu";constructor(){super(),w.adapter=this}isSupported(){return Boolean(typeof navigator<"u"&&navigator.gpu)}async create(e){if(!navigator.gpu)throw new Error("WebGPU not available. Open in Chrome Canary and turn on chrome://flags/#enable-unsafe-webgpu");u.log.groupCollapsed(1,"WebGPUDevice created")();let t=await navigator.gpu.requestAdapter({powerPreference:"high-performance"});if(!t)throw new Error("Failed to request WebGPU adapter");let r=await t.requestAdapterInfo();u.log.probe(2,"Adapter available",r)();let i=[],s={};if(e.requestMaxLimits){i.push(...Array.from(t.features));let c=Object.keys(t.limits).filter(d=>!["minSubgroupSize","maxSubgroupSize"].includes(d));for(let d of c){let g=d,m=t.limits[g];typeof m=="number"&&(s[g]=m)}}let a=await t.requestDevice({requiredFeatures:i,requiredLimits:s});u.log.probe(1,"GPUDevice available")(),typeof e.canvas=="string"&&(await u.CanvasContext.pageLoaded,u.log.probe(1,"DOM is loaded")());let l=new w(e,a,t,r);return u.log.probe(1,"Device created. For more info, set chrome://flags/#enable-webgpu-developer-features")(),u.log.table(1,l.info)(),u.log.groupEnd(1)(),l}async attach(e){throw new Error("WebGPUAdapter.attach() not implemented")}},fe=new ee;return Ee(D);})();
8
8
  return __exports__;
9
9
  });
package/dist/index.cjs CHANGED
@@ -2,7 +2,6 @@ var __defProp = Object.defineProperty;
2
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
5
  var __export = (target, all) => {
7
6
  for (var name in all)
8
7
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -16,10 +15,6 @@ var __copyProps = (to, from, except, desc) => {
16
15
  return to;
17
16
  };
18
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var __publicField = (obj, key, value) => {
20
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
21
- return value;
22
- };
23
18
 
24
19
  // dist/index.js
25
20
  var dist_exports = {};
@@ -28,10 +23,14 @@ __export(dist_exports, {
28
23
  WebGPUDevice: () => WebGPUDevice,
29
24
  WebGPUSampler: () => WebGPUSampler,
30
25
  WebGPUShader: () => WebGPUShader,
31
- WebGPUTexture: () => WebGPUTexture
26
+ WebGPUTexture: () => WebGPUTexture,
27
+ webgpuAdapter: () => webgpuAdapter
32
28
  });
33
29
  module.exports = __toCommonJS(dist_exports);
34
30
 
31
+ // dist/adapter/webgpu-adapter.js
32
+ var import_core18 = require("@luma.gl/core");
33
+
35
34
  // dist/adapter/webgpu-device.js
36
35
  var import_core17 = require("@luma.gl/core");
37
36
 
@@ -210,7 +209,11 @@ var WebGPUTexture = class extends import_core4.Texture {
210
209
  this.handle = this.props.handle || this.createHandle();
211
210
  this.handle.label ||= this.id;
212
211
  if (this.props.data) {
213
- this.setData({ data: this.props.data });
212
+ if (import_core4.Texture.isExternalImage(this.props.data)) {
213
+ this.setImage({ source: this.props.data });
214
+ } else {
215
+ this.setData({ data: this.props.data });
216
+ }
214
217
  }
215
218
  this.width = this.handle.width;
216
219
  this.height = this.handle.height;
@@ -266,11 +269,29 @@ var WebGPUTexture = class extends import_core4.Texture {
266
269
  throw new Error("not implemented");
267
270
  }
268
271
  setData(options) {
269
- return this.setImage({ source: options.data });
270
- }
272
+ let source = options.data;
273
+ if (ArrayBuffer.isView(options.data)) {
274
+ const clampedArray = new Uint8ClampedArray(options.data.buffer);
275
+ source = new ImageData(clampedArray, this.width, this.height);
276
+ }
277
+ return this.setImage({ source });
278
+ }
279
+ // setDataFromTypedArray(data): this {
280
+ // const textureDataBuffer = this.device.handle.createBuffer({
281
+ // size: data.byteLength,
282
+ // usage: Buffer.COPY_DST | Buffer.COPY_SRC,
283
+ // mappedAtCreation: true
284
+ // });
285
+ // new Uint8Array(textureDataBuffer.getMappedRange()).set(data);
286
+ // textureDataBuffer.unmap();
287
+ // this.setBuffer(textureDataBuffer);
288
+ // textureDataBuffer.destroy();
289
+ // return this;
290
+ // }
271
291
  /** Set image */
272
292
  setImage(options) {
273
- const { source, width = options.source.width, height = options.source.height, depth = 1, sourceX = 0, sourceY = 0, mipLevel = 0, x = 0, y = 0, z = 0, aspect = "all", colorSpace = "srgb", premultipliedAlpha = false } = options;
293
+ const size = import_core4.Texture.getExternalImageSize(options.source);
294
+ const { source, width = size.width, height = size.height, depth = 1, sourceX = 0, sourceY = 0, mipLevel = 0, x = 0, y = 0, z = 0, aspect = "all", colorSpace = "srgb", premultipliedAlpha = false } = options;
274
295
  this.device.handle.queue.copyExternalImageToTexture(
275
296
  // source: GPUImageCopyExternalImage
276
297
  {
@@ -1217,7 +1238,7 @@ var WebGPUQuerySet = class extends import_core16.QuerySet {
1217
1238
  };
1218
1239
 
1219
1240
  // dist/adapter/webgpu-device.js
1220
- var _WebGPUDevice = class extends import_core17.Device {
1241
+ var WebGPUDevice = class extends import_core17.Device {
1221
1242
  /** type of this device */
1222
1243
  type = "webgpu";
1223
1244
  /** The underlying WebGPU device */
@@ -1234,53 +1255,7 @@ var _WebGPUDevice = class extends import_core17.Device {
1234
1255
  _isLost = false;
1235
1256
  commandEncoder = null;
1236
1257
  renderPass = null;
1237
- /** Check if WebGPU is available */
1238
- static isSupported() {
1239
- return Boolean(typeof navigator !== "undefined" && navigator.gpu);
1240
- }
1241
- static async create(props) {
1242
- if (!navigator.gpu) {
1243
- throw new Error("WebGPU not available. Open in Chrome Canary and turn on chrome://flags/#enable-unsafe-webgpu");
1244
- }
1245
- import_core17.log.groupCollapsed(1, "WebGPUDevice created")();
1246
- const adapter = await navigator.gpu.requestAdapter({
1247
- powerPreference: "high-performance"
1248
- // forceSoftware: false
1249
- });
1250
- if (!adapter) {
1251
- throw new Error("Failed to request WebGPU adapter");
1252
- }
1253
- const adapterInfo = await adapter.requestAdapterInfo();
1254
- import_core17.log.probe(2, "Adapter available", adapterInfo)();
1255
- const requiredFeatures = [];
1256
- const requiredLimits = {};
1257
- if (props.requestMaxLimits) {
1258
- requiredFeatures.push(...Array.from(adapter.features));
1259
- const limits = Object.keys(adapter.limits).filter((key) => !["minSubgroupSize", "maxSubgroupSize"].includes(key));
1260
- for (const key of limits) {
1261
- const limit = key;
1262
- const value = adapter.limits[limit];
1263
- if (typeof value === "number") {
1264
- requiredLimits[limit] = value;
1265
- }
1266
- }
1267
- }
1268
- const gpuDevice = await adapter.requestDevice({
1269
- requiredFeatures,
1270
- requiredLimits
1271
- });
1272
- import_core17.log.probe(1, "GPUDevice available")();
1273
- if (typeof props.canvas === "string") {
1274
- await import_core17.CanvasContext.pageLoaded;
1275
- import_core17.log.probe(1, "DOM is loaded")();
1276
- }
1277
- const device = new _WebGPUDevice(gpuDevice, adapter, adapterInfo, props);
1278
- import_core17.log.probe(1, "Device created. For more info, set chrome://flags/#enable-webgpu-developer-features")();
1279
- import_core17.log.table(1, device.info)();
1280
- import_core17.log.groupEnd(1)();
1281
- return device;
1282
- }
1283
- constructor(device, adapter, adapterInfo, props) {
1258
+ constructor(props, device, adapter, adapterInfo) {
1284
1259
  super({ ...props, id: props.id || "webgpu-device" });
1285
1260
  this.handle = device;
1286
1261
  this.adapter = adapter;
@@ -1472,6 +1447,64 @@ var _WebGPUDevice = class extends import_core17.Device {
1472
1447
  );
1473
1448
  }
1474
1449
  };
1475
- var WebGPUDevice = _WebGPUDevice;
1476
- __publicField(WebGPUDevice, "type", "webgpu");
1450
+
1451
+ // dist/adapter/webgpu-adapter.js
1452
+ var WebGPUAdapter = class extends import_core18.Adapter {
1453
+ /** type of device's created by this adapter */
1454
+ type = "webgpu";
1455
+ constructor() {
1456
+ super();
1457
+ WebGPUDevice.adapter = this;
1458
+ }
1459
+ /** Check if WebGPU is available */
1460
+ isSupported() {
1461
+ return Boolean(typeof navigator !== "undefined" && navigator.gpu);
1462
+ }
1463
+ async create(props) {
1464
+ if (!navigator.gpu) {
1465
+ throw new Error("WebGPU not available. Open in Chrome Canary and turn on chrome://flags/#enable-unsafe-webgpu");
1466
+ }
1467
+ import_core18.log.groupCollapsed(1, "WebGPUDevice created")();
1468
+ const adapter = await navigator.gpu.requestAdapter({
1469
+ powerPreference: "high-performance"
1470
+ // forceSoftware: false
1471
+ });
1472
+ if (!adapter) {
1473
+ throw new Error("Failed to request WebGPU adapter");
1474
+ }
1475
+ const adapterInfo = await adapter.requestAdapterInfo();
1476
+ import_core18.log.probe(2, "Adapter available", adapterInfo)();
1477
+ const requiredFeatures = [];
1478
+ const requiredLimits = {};
1479
+ if (props.requestMaxLimits) {
1480
+ requiredFeatures.push(...Array.from(adapter.features));
1481
+ const limits = Object.keys(adapter.limits).filter((key) => !["minSubgroupSize", "maxSubgroupSize"].includes(key));
1482
+ for (const key of limits) {
1483
+ const limit = key;
1484
+ const value = adapter.limits[limit];
1485
+ if (typeof value === "number") {
1486
+ requiredLimits[limit] = value;
1487
+ }
1488
+ }
1489
+ }
1490
+ const gpuDevice = await adapter.requestDevice({
1491
+ requiredFeatures,
1492
+ requiredLimits
1493
+ });
1494
+ import_core18.log.probe(1, "GPUDevice available")();
1495
+ if (typeof props.canvas === "string") {
1496
+ await import_core18.CanvasContext.pageLoaded;
1497
+ import_core18.log.probe(1, "DOM is loaded")();
1498
+ }
1499
+ const device = new WebGPUDevice(props, gpuDevice, adapter, adapterInfo);
1500
+ import_core18.log.probe(1, "Device created. For more info, set chrome://flags/#enable-webgpu-developer-features")();
1501
+ import_core18.log.table(1, device.info)();
1502
+ import_core18.log.groupEnd(1)();
1503
+ return device;
1504
+ }
1505
+ async attach(handle) {
1506
+ throw new Error("WebGPUAdapter.attach() not implemented");
1507
+ }
1508
+ };
1509
+ var webgpuAdapter = new WebGPUAdapter();
1477
1510
  //# sourceMappingURL=index.cjs.map