@luma.gl/effects 9.3.0-alpha.10 → 9.3.0-alpha.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/dist.dev.js CHANGED
@@ -1473,12 +1473,51 @@ var __exports__ = (() => {
1473
1473
  }
1474
1474
  return `${dataType}x${components}`;
1475
1475
  case "snorm8":
1476
+ if (components === 1) {
1477
+ return "snorm8";
1478
+ }
1479
+ if (components === 3) {
1480
+ return "snorm8x3-webgl";
1481
+ }
1482
+ return `${dataType}x${components}`;
1476
1483
  case "uint8":
1477
1484
  case "sint8":
1485
+ if (components === 1 || components === 3) {
1486
+ throw new Error(`size: ${components}`);
1487
+ }
1488
+ return `${dataType}x${components}`;
1478
1489
  case "uint16":
1490
+ if (components === 1) {
1491
+ return "uint16";
1492
+ }
1493
+ if (components === 3) {
1494
+ return "uint16x3-webgl";
1495
+ }
1496
+ return `${dataType}x${components}`;
1479
1497
  case "sint16":
1498
+ if (components === 1) {
1499
+ return "sint16";
1500
+ }
1501
+ if (components === 3) {
1502
+ return "sint16x3-webgl";
1503
+ }
1504
+ return `${dataType}x${components}`;
1480
1505
  case "unorm16":
1506
+ if (components === 1) {
1507
+ return "unorm16";
1508
+ }
1509
+ if (components === 3) {
1510
+ return "unorm16x3-webgl";
1511
+ }
1512
+ return `${dataType}x${components}`;
1481
1513
  case "snorm16":
1514
+ if (components === 1) {
1515
+ return "snorm16";
1516
+ }
1517
+ if (components === 3) {
1518
+ return "snorm16x3-webgl";
1519
+ }
1520
+ return `${dataType}x${components}`;
1482
1521
  case "float16":
1483
1522
  if (components === 1 || components === 3) {
1484
1523
  throw new Error(`size: ${components}`);
@@ -2181,7 +2220,7 @@ or create a device with the 'debug: true' prop.`;
2181
2220
  throw new Error("_createBindGroupLayoutWebGPU() not implemented");
2182
2221
  }
2183
2222
  /** Internal WebGPU-only helper for creating a native bind group. */
2184
- _createBindGroupWebGPU(_bindGroupLayout, _shaderLayout, _bindings, _group) {
2223
+ _createBindGroupWebGPU(_bindGroupLayout, _shaderLayout, _bindings, _group, _label) {
2185
2224
  throw new Error("_createBindGroupWebGPU() not implemented");
2186
2225
  }
2187
2226
  /**
@@ -4395,12 +4434,14 @@ ${numberedLines}${positionIndicator}${message.type.toUpperCase()}: ${message.mes
4395
4434
  for (const group of getBindGroupIndicesUpToMax(pipeline.shaderLayout.bindings)) {
4396
4435
  const groupBindings = bindingsByGroup[group];
4397
4436
  const bindGroupLayout = this._getBindGroupLayout(pipeline, group);
4437
+ const bindGroupLabel = getBindGroupLabel(pipeline, pipeline.shaderLayout, group);
4398
4438
  if (!groupBindings || Object.keys(groupBindings).length === 0) {
4399
4439
  if (!hasBindingsInGroup(pipeline.shaderLayout.bindings, group)) {
4400
4440
  resolvedBindGroups[group] = this._getEmptyBindGroup(
4401
4441
  bindGroupLayout,
4402
4442
  pipeline.shaderLayout,
4403
- group
4443
+ group,
4444
+ bindGroupLabel
4404
4445
  );
4405
4446
  }
4406
4447
  continue;
@@ -4416,7 +4457,8 @@ ${numberedLines}${positionIndicator}${message.type.toUpperCase()}: ${message.mes
4416
4457
  bindGroupLayout,
4417
4458
  pipeline.shaderLayout,
4418
4459
  groupBindings,
4419
- group
4460
+ group,
4461
+ bindGroupLabel
4420
4462
  );
4421
4463
  layoutCache.bindGroupsBySource.set(bindGroupCacheKey, bindGroup);
4422
4464
  resolvedBindGroups[group] = bindGroup;
@@ -4425,7 +4467,8 @@ ${numberedLines}${positionIndicator}${message.type.toUpperCase()}: ${message.mes
4425
4467
  bindGroupLayout,
4426
4468
  pipeline.shaderLayout,
4427
4469
  groupBindings,
4428
- group
4470
+ group,
4471
+ bindGroupLabel
4429
4472
  );
4430
4473
  }
4431
4474
  }
@@ -4440,9 +4483,9 @@ ${numberedLines}${positionIndicator}${message.type.toUpperCase()}: ${message.mes
4440
4483
  layoutCache[group] ||= this.device._createBindGroupLayoutWebGPU(pipeline, group);
4441
4484
  return layoutCache[group];
4442
4485
  }
4443
- _getEmptyBindGroup(bindGroupLayout, shaderLayout, group) {
4486
+ _getEmptyBindGroup(bindGroupLayout, shaderLayout, group, label) {
4444
4487
  const layoutCache = this._getLayoutBindGroupCache(bindGroupLayout);
4445
- layoutCache.emptyBindGroup ||= this.device._createBindGroupWebGPU(bindGroupLayout, shaderLayout, {}, group) || null;
4488
+ layoutCache.emptyBindGroup ||= this.device._createBindGroupWebGPU(bindGroupLayout, shaderLayout, {}, group, label) || null;
4446
4489
  return layoutCache.emptyBindGroup;
4447
4490
  }
4448
4491
  _getLayoutBindGroupCache(bindGroupLayout) {
@@ -4468,6 +4511,11 @@ ${numberedLines}${positionIndicator}${message.type.toUpperCase()}: ${message.mes
4468
4511
  function hasBindingsInGroup(bindings, group) {
4469
4512
  return bindings.some((binding) => binding.group === group);
4470
4513
  }
4514
+ function getBindGroupLabel(pipeline, shaderLayout, group) {
4515
+ const bindingNames = shaderLayout.bindings.filter((binding) => binding.group === group).sort((left, right) => left.location - right.location).map((binding) => binding.name);
4516
+ const bindingSuffix = bindingNames.length > 0 ? bindingNames.join(",") : "empty";
4517
+ return `${pipeline.id}/group${group}[${bindingSuffix}]`;
4518
+ }
4471
4519
 
4472
4520
  // ../core/src/adapter/resources/render-pass.ts
4473
4521
  var _RenderPass = class extends Resource {
package/dist/dist.min.js CHANGED
@@ -4,17 +4,17 @@
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
- "use strict";var __exports__=(()=>{var Br=Object.create;var K=Object.defineProperty;var Mr=Object.getOwnPropertyDescriptor;var Dr=Object.getOwnPropertyNames;var Ir=Object.getPrototypeOf,$r=Object.prototype.hasOwnProperty;var kr=(r,e,t)=>e in r?K(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var Ur=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),Or=(r,e)=>{for(var t in e)K(r,t,{get:e[t],enumerable:!0})},we=(r,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Dr(e))!$r.call(r,s)&&s!==t&&K(r,s,{get:()=>e[s],enumerable:!(i=Mr(e,s))||i.enumerable});return r},ve=(r,e,t)=>(we(r,e,"default"),t&&we(t,e,"default")),Fr=(r,e,t)=>(t=r!=null?Br(Ir(r)):{},we(e||!r||!r.__esModule?K(t,"default",{value:r,enumerable:!0}):t,r)),Gr=r=>we(K({},"__esModule",{value:!0}),r);var u=(r,e,t)=>(kr(r,typeof e!="symbol"?e+"":e,t),t);var Lr=Ur((jc,Rr)=>{Rr.exports=globalThis.luma});var _e={};Or(_e,{Adapter:()=>Ge,Buffer:()=>p,CanvasContext:()=>se,CommandBuffer:()=>de,CommandEncoder:()=>fe,ComputePass:()=>le,ComputePipeline:()=>D,Device:()=>O,DeviceFeatures:()=>ke,DeviceLimits:()=>$e,ExternalTexture:()=>oe,Fence:()=>be,Framebuffer:()=>ae,PipelineFactory:()=>ce,PipelineLayout:()=>ye,PresentationContext:()=>Ne,QuerySet:()=>ge,RenderPass:()=>I,RenderPipeline:()=>T,Resource:()=>l,Sampler:()=>F,Shader:()=>G,ShaderBlockWriter:()=>Y,ShaderFactory:()=>ue,SharedRenderPipeline:()=>je,Texture:()=>g,TextureView:()=>ne,TransformFeedback:()=>pe,UniformBlock:()=>X,UniformStore:()=>Ke,VertexArray:()=>me,_getDefaultBindGroupFactory:()=>pr,_getTextureFormatDefinition:()=>re,_getTextureFormatTable:()=>Me,assert:()=>ze,assertDefined:()=>He,dataTypeDecoder:()=>L,flattenBindingsByGroup:()=>mr,getAttributeInfosFromLayouts:()=>Mt,getAttributeShaderTypeInfo:()=>Bt,getExternalImageSize:()=>Ie,getScratchArray:()=>Pr,getShaderLayoutBinding:()=>Tt,getTextureImageView:()=>Wt,getTypedArrayConstructor:()=>yr,getVariableShaderTypeInfo:()=>he,isExternalImage:()=>De,log:()=>d,luma:()=>cr,makeShaderBlockLayout:()=>qe,normalizeBindingsByGroup:()=>Qe,readPixel:()=>Ar,setTextureImageData:()=>Cr,shaderTypeDecoder:()=>Xe,textureFormatDecoder:()=>x,vertexFormatDecoder:()=>B,writePixel:()=>Er});function Z(){let r;if(typeof window<"u"&&window.performance)r=window.performance.now();else if(typeof process<"u"&&process.hrtime){let e=process.hrtime();r=e[0]*1e3+e[1]/1e6}else r=Date.now();return r}var k=class{constructor(e,t){this.sampleSize=1,this.time=0,this.count=0,this.samples=0,this.lastTiming=0,this.lastSampleTime=0,this.lastSampleCount=0,this._count=0,this._time=0,this._samples=0,this._startTime=0,this._timerPending=!1,this.name=e,this.type=t,this.reset()}reset(){return this.time=0,this.count=0,this.samples=0,this.lastTiming=0,this.lastSampleTime=0,this.lastSampleCount=0,this._count=0,this._time=0,this._samples=0,this._startTime=0,this._timerPending=!1,this}setSampleSize(e){return this.sampleSize=e,this}incrementCount(){return this.addCount(1),this}decrementCount(){return this.subtractCount(1),this}addCount(e){return this._count+=e,this._samples++,this._checkSampling(),this}subtractCount(e){return this._count-=e,this._samples++,this._checkSampling(),this}addTime(e){return this._time+=e,this.lastTiming=e,this._samples++,this._checkSampling(),this}timeStart(){return this._startTime=Z(),this._timerPending=!0,this}timeEnd(){return this._timerPending?(this.addTime(Z()-this._startTime),this._timerPending=!1,this._checkSampling(),this):this}getSampleAverageCount(){return this.sampleSize>0?this.lastSampleCount/this.sampleSize:0}getSampleAverageTime(){return this.sampleSize>0?this.lastSampleTime/this.sampleSize:0}getSampleHz(){return this.lastSampleTime>0?this.sampleSize/(this.lastSampleTime/1e3):0}getAverageCount(){return this.samples>0?this.count/this.samples:0}getAverageTime(){return this.samples>0?this.time/this.samples:0}getHz(){return this.time>0?this.samples/(this.time/1e3):0}_checkSampling(){this._samples===this.sampleSize&&(this.lastSampleTime=this._time,this.lastSampleCount=this._count,this.count+=this._count,this.time+=this._time,this.samples+=this._samples,this._time=0,this._count=0,this._samples=0)}};var H=class{constructor(e){this.stats={},this.id=e.id,this.stats={},this._initializeStats(e.stats),Object.seal(this)}get(e,t="count"){return this._getOrCreate({name:e,type:t})}get size(){return Object.keys(this.stats).length}reset(){for(let e of Object.values(this.stats))e.reset();return this}forEach(e){for(let t of Object.values(this.stats))e(t)}getTable(){let e={};return this.forEach(t=>{e[t.name]={time:t.time||0,count:t.count||0,average:t.getAverageTime()||0,hz:t.getHz()||0}}),e}_initializeStats(e=[]){e.forEach(t=>this._getOrCreate(t))}_getOrCreate(e){let{name:t,type:i}=e,s=this.stats[t];return s||(e instanceof k?s=e:s=new k(t,i),this.stats[t]=s),s}};var Wr="GPU Time and Memory",zr=["Adapter","GPU","GPU Type","GPU Backend","Frame Rate","CPU Time","GPU Time","GPU Memory","Buffer Memory","Texture Memory","Referenced Buffer Memory","Referenced Texture Memory","Swap Chain Texture"],zt=new WeakMap,Ht=new WeakMap,et=class{stats=new Map;getStats(e){return this.get(e)}get(e){this.stats.has(e)||this.stats.set(e,new H({id:e}));let t=this.stats.get(e);return e===Wr&&Hr(t,zr),t}},Pe=new et;function Hr(r,e){let t=r.stats,i=!1;for(let c of e)t[c]||(r.get(c),i=!0);let s=Object.keys(t).length,n=zt.get(r);if(!i&&n?.orderedStatNames===e&&n.statCount===s)return;let o={},a=Ht.get(e);a||(a=new Set(e),Ht.set(e,a));for(let c of e)t[c]&&(o[c]=t[c]);for(let[c,f]of Object.entries(t))a.has(c)||(o[c]=f);for(let c of Object.keys(t))delete t[c];Object.assign(t,o),zt.set(r,{orderedStatNames:e,statCount:s})}var Se=globalThis,Nr=globalThis.document||{},Te=globalThis.process||{},Vr=globalThis.console,Ts=globalThis.navigator||{};function Nt(r){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=r||e;return Boolean(t&&t.indexOf("Electron")>=0)}function v(){return!(typeof process=="object"&&String(process)==="[object process]"&&!process?.browser)||Nt()}var tt="4.1.1";function N(r,e){if(!r)throw new Error(e||"Assertion failed")}function rt(r){if(!r)return 0;let e;switch(typeof r){case"number":e=r;break;case"object":e=r.logLevel||r.priority||0;break;default:return 0}return N(Number.isFinite(e)&&e>=0),e}function Vt(r){let{logLevel:e,message:t}=r;r.logLevel=rt(e);let i=r.args?Array.from(r.args):[];for(;i.length&&i.shift()!==t;);switch(typeof e){case"string":case"function":t!==void 0&&i.unshift(t),r.message=e;break;case"object":Object.assign(r,e);break;default:}typeof r.message=="function"&&(r.message=r.message());let s=typeof r.message;return N(s==="string"||s==="object"),Object.assign(r,{args:i},r.opts)}var U=()=>{},Ce=class{constructor({level:e=0}={}){this.userData={},this._onceCache=new Set,this._level=e}set level(e){this.setLevel(e)}get level(){return this.getLevel()}setLevel(e){return this._level=e,this}getLevel(){return this._level}warn(e,...t){return this._log("warn",0,e,t,{once:!0})}error(e,...t){return this._log("error",0,e,t)}log(e,t,...i){return this._log("log",e,t,i)}info(e,t,...i){return this._log("info",e,t,i)}once(e,t,...i){return this._log("once",e,t,i,{once:!0})}_log(e,t,i,s,n={}){let o=Vt({logLevel:t,message:i,args:this._buildArgs(t,i,s),opts:n});return this._createLogFunction(e,o,n)}_buildArgs(e,t,i){return[e,t,...i]}_createLogFunction(e,t,i){if(!this._shouldLog(t.logLevel))return U;let s=this._getOnceTag(i.tag??t.tag??t.message);if((i.once||t.once)&&s!==void 0){if(this._onceCache.has(s))return U;this._onceCache.add(s)}return this._emit(e,t)}_shouldLog(e){return this.getLevel()>=rt(e)}_getOnceTag(e){if(e!==void 0)try{return typeof e=="string"?e:String(e)}catch{return}}};function Qr(r){try{let e=window[r],t="__storage_test__";return e.setItem(t,t),e.removeItem(t),e}catch{return null}}var Ae=class{constructor(e,t,i="sessionStorage"){this.storage=Qr(i),this.id=e,this.config=t,this._loadConfiguration()}getConfiguration(){return this.config}setConfiguration(e){if(Object.assign(this.config,e),this.storage){let t=JSON.stringify(this.config);this.storage.setItem(this.id,t)}}_loadConfiguration(){let e={};if(this.storage){let t=this.storage.getItem(this.id);e=t?JSON.parse(t):{}}return Object.assign(this.config,e),this}};function jt(r){let e;return r<10?e=`${r.toFixed(2)}ms`:r<100?e=`${r.toFixed(1)}ms`:r<1e3?e=`${r.toFixed(0)}ms`:e=`${(r/1e3).toFixed(2)}s`,e}function Qt(r,e=8){let t=Math.max(e-r.length,0);return`${" ".repeat(t)}${r}`}var Ee;(function(r){r[r.BLACK=30]="BLACK",r[r.RED=31]="RED",r[r.GREEN=32]="GREEN",r[r.YELLOW=33]="YELLOW",r[r.BLUE=34]="BLUE",r[r.MAGENTA=35]="MAGENTA",r[r.CYAN=36]="CYAN",r[r.WHITE=37]="WHITE",r[r.BRIGHT_BLACK=90]="BRIGHT_BLACK",r[r.BRIGHT_RED=91]="BRIGHT_RED",r[r.BRIGHT_GREEN=92]="BRIGHT_GREEN",r[r.BRIGHT_YELLOW=93]="BRIGHT_YELLOW",r[r.BRIGHT_BLUE=94]="BRIGHT_BLUE",r[r.BRIGHT_MAGENTA=95]="BRIGHT_MAGENTA",r[r.BRIGHT_CYAN=96]="BRIGHT_CYAN",r[r.BRIGHT_WHITE=97]="BRIGHT_WHITE"})(Ee||(Ee={}));var Yr=10;function Yt(r){return typeof r!="string"?r:(r=r.toUpperCase(),Ee[r]||Ee.WHITE)}function Xt(r,e,t){return!v&&typeof r=="string"&&(e&&(r=`\x1B[${Yt(e)}m${r}\x1B[39m`),t&&(r=`\x1B[${Yt(t)+Yr}m${r}\x1B[49m`)),r}function qt(r,e=["constructor"]){let t=Object.getPrototypeOf(r),i=Object.getOwnPropertyNames(t),s=r;for(let n of i){let o=s[n];typeof o=="function"&&(e.find(a=>n===a)||(s[n]=o.bind(r)))}}function V(){let r;if(v()&&Se.performance)r=Se?.performance?.now?.();else if("hrtime"in Te){let e=Te?.hrtime?.();r=e[0]*1e3+e[1]/1e6}else r=Date.now();return r}var j={debug:v()&&console.debug||console.log,log:console.log,info:console.info,warn:console.warn,error:console.error},it={enabled:!0,level:0},A=class extends Ce{constructor({id:e}={id:""}){super({level:0}),this.VERSION=tt,this._startTs=V(),this._deltaTs=V(),this.userData={},this.LOG_THROTTLE_TIMEOUT=0,this.id=e,this.userData={},this._storage=new Ae(`__probe-${this.id}__`,{[this.id]:it}),this.timeStamp(`${this.id} started`),qt(this),Object.seal(this)}isEnabled(){return this._getConfiguration().enabled}getLevel(){return this._getConfiguration().level}getTotal(){return Number((V()-this._startTs).toPrecision(10))}getDelta(){return Number((V()-this._deltaTs).toPrecision(10))}set priority(e){this.level=e}get priority(){return this.level}getPriority(){return this.level}enable(e=!0){return this._updateConfiguration({enabled:e}),this}setLevel(e){return this._updateConfiguration({level:e}),this}get(e){return this._getConfiguration()[e]}set(e,t){this._updateConfiguration({[e]:t})}settings(){console.table?console.table(this._storage.config):console.log(this._storage.config)}assert(e,t){if(!e)throw new Error(t||"Assertion failed")}warn(e,...t){return this._log("warn",0,e,t,{method:j.warn,once:!0})}error(e,...t){return this._log("error",0,e,t,{method:j.error})}deprecated(e,t){return this.warn(`\`${e}\` is deprecated and will be removed in a later version. Use \`${t}\` instead`)}removed(e,t){return this.error(`\`${e}\` has been removed. Use \`${t}\` instead`)}probe(e,t,...i){return this._log("log",e,t,i,{method:j.log,time:!0,once:!0})}log(e,t,...i){return this._log("log",e,t,i,{method:j.debug})}info(e,t,...i){return this._log("info",e,t,i,{method:console.info})}once(e,t,...i){return this._log("once",e,t,i,{method:j.debug||j.info,once:!0})}table(e,t,i){return t?this._log("table",e,t,i&&[i]||[],{method:console.table||U,tag:qr(t)}):U}time(e,t){return this._log("time",e,t,[],{method:console.time?console.time:console.info})}timeEnd(e,t){return this._log("time",e,t,[],{method:console.timeEnd?console.timeEnd:console.info})}timeStamp(e,t){return this._log("time",e,t,[],{method:console.timeStamp||U})}group(e,t,i={collapsed:!1}){let s=(i.collapsed?console.groupCollapsed:console.group)||console.info;return this._log("group",e,t,[],{method:s})}groupCollapsed(e,t,i={}){return this.group(e,t,Object.assign({},i,{collapsed:!0}))}groupEnd(e){return this._log("groupEnd",e,"",[],{method:console.groupEnd||U})}withGroup(e,t,i){this.group(e,t)();try{i()}finally{this.groupEnd(e)()}}trace(){console.trace&&console.trace()}_shouldLog(e){return this.isEnabled()&&super._shouldLog(e)}_emit(e,t){let i=t.method;N(i),t.total=this.getTotal(),t.delta=this.getDelta(),this._deltaTs=V();let s=Xr(this.id,t.message,t);return i.bind(console,s,...t.args)}_getConfiguration(){return this._storage.config[this.id]||this._updateConfiguration(it),this._storage.config[this.id]}_updateConfiguration(e){let t=this._storage.config[this.id]||{...it};this._storage.setConfiguration({[this.id]:{...t,...e}})}};A.VERSION=tt;function Xr(r,e,t){if(typeof e=="string"){let i=t.time?Qt(jt(t.total)):"";e=t.time?`${r}: ${i} ${e}`:`${r}: ${e}`,e=Xt(e,t.color,t.background)}return e}function qr(r){for(let e in r)for(let t in r[e])return t||"untitled";return"empty"}globalThis.probe={};var tn=new A({id:"@probe.gl/log"});var d=new A({id:"luma.gl"});var st={};function P(r="id"){st[r]=st[r]||1;let e=st[r]++;return`${r}-${e}`}var Jr="cpu-hotspot-profiler",Jt="GPU Resource Counts",Kt="Resource Counts",Zt="GPU Time and Memory",Kr=["Resources","Buffers","Textures","Samplers","TextureViews","Framebuffers","QuerySets","Shaders","RenderPipelines","ComputePipelines","PipelineLayouts","VertexArrays","RenderPasss","ComputePasss","CommandEncoders","CommandBuffers"],Zr=["Resources","Buffers","Textures","Samplers","TextureViews","Framebuffers","QuerySets","Shaders","RenderPipelines","SharedRenderPipelines","ComputePipelines","PipelineLayouts","VertexArrays","RenderPasss","ComputePasss","CommandEncoders","CommandBuffers"],ei=Kr.flatMap(r=>[`${r} Created`,`${r} Active`]),ti=Zr.flatMap(r=>[`${r} Created`,`${r} Active`]),er=new WeakMap,tr=new WeakMap,l=class{toString(){return`${this[Symbol.toStringTag]||this.constructor.name}:"${this.id}"`}id;props;userData={};_device;destroyed=!1;allocatedBytes=0;allocatedBytesName=null;_attachedResources=new Set;constructor(e,t,i){if(!e)throw new Error("no device");this._device=e,this.props=ri(t,i);let s=this.props.id!=="undefined"?this.props.id:P(this[Symbol.toStringTag]);this.props.id=s,this.id=s,this.userData=this.props.userData||{},this.addStats()}destroy(){this.destroyed||this.destroyResource()}delete(){return this.destroy(),this}getProps(){return this.props}attachResource(e){this._attachedResources.add(e)}detachResource(e){this._attachedResources.delete(e)}destroyAttachedResource(e){this._attachedResources.delete(e)&&e.destroy()}destroyAttachedResources(){for(let e of this._attachedResources)e.destroy();this._attachedResources=new Set}destroyResource(){this.destroyed||(this.destroyAttachedResources(),this.removeStats(),this.destroyed=!0)}removeStats(){let e=ee(this._device),t=e?R():0,i=[this._device.statsManager.getStats(Jt),this._device.statsManager.getStats(Kt)],s=ir(this._device);for(let o of i)rr(o,s);let n=this.getStatsName();for(let o of i)o.get("Resources Active").decrementCount(),o.get(`${n}s Active`).decrementCount();e&&(e.statsBookkeepingCalls=(e.statsBookkeepingCalls||0)+1,e.statsBookkeepingTimeMs=(e.statsBookkeepingTimeMs||0)+(R()-t))}trackAllocatedMemory(e,t=this.getStatsName()){let i=ee(this._device),s=i?R():0,n=this._device.statsManager.getStats(Zt);this.allocatedBytes>0&&this.allocatedBytesName&&(n.get("GPU Memory").subtractCount(this.allocatedBytes),n.get(`${this.allocatedBytesName} Memory`).subtractCount(this.allocatedBytes)),n.get("GPU Memory").addCount(e),n.get(`${t} Memory`).addCount(e),i&&(i.statsBookkeepingCalls=(i.statsBookkeepingCalls||0)+1,i.statsBookkeepingTimeMs=(i.statsBookkeepingTimeMs||0)+(R()-s)),this.allocatedBytes=e,this.allocatedBytesName=t}trackReferencedMemory(e,t=this.getStatsName()){this.trackAllocatedMemory(e,`Referenced ${t}`)}trackDeallocatedMemory(e=this.getStatsName()){if(this.allocatedBytes===0){this.allocatedBytesName=null;return}let t=ee(this._device),i=t?R():0,s=this._device.statsManager.getStats(Zt);s.get("GPU Memory").subtractCount(this.allocatedBytes),s.get(`${this.allocatedBytesName||e} Memory`).subtractCount(this.allocatedBytes),t&&(t.statsBookkeepingCalls=(t.statsBookkeepingCalls||0)+1,t.statsBookkeepingTimeMs=(t.statsBookkeepingTimeMs||0)+(R()-i)),this.allocatedBytes=0,this.allocatedBytesName=null}trackDeallocatedReferencedMemory(e=this.getStatsName()){this.trackDeallocatedMemory(`Referenced ${e}`)}addStats(){let e=this.getStatsName(),t=ee(this._device),i=t?R():0,s=[this._device.statsManager.getStats(Jt),this._device.statsManager.getStats(Kt)],n=ir(this._device);for(let o of s)rr(o,n);for(let o of s)o.get("Resources Created").incrementCount(),o.get("Resources Active").incrementCount(),o.get(`${e}s Created`).incrementCount(),o.get(`${e}s Active`).incrementCount();t&&(t.statsBookkeepingCalls=(t.statsBookkeepingCalls||0)+1,t.statsBookkeepingTimeMs=(t.statsBookkeepingTimeMs||0)+(R()-i)),ii(this._device,e)}getStatsName(){return si(this)}};u(l,"defaultProps",{id:"undefined",handle:void 0,userData:void 0});function ri(r,e){let t={...e};for(let i in r)r[i]!==void 0&&(t[i]=r[i]);return t}function rr(r,e){let t=r.stats,i=!1;for(let c of e)t[c]||(r.get(c),i=!0);let s=Object.keys(t).length,n=er.get(r);if(!i&&n?.orderedStatNames===e&&n.statCount===s)return;let o={},a=tr.get(e);a||(a=new Set(e),tr.set(e,a));for(let c of e)t[c]&&(o[c]=t[c]);for(let[c,f]of Object.entries(t))a.has(c)||(o[c]=f);for(let c of Object.keys(t))delete t[c];Object.assign(t,o),er.set(r,{orderedStatNames:e,statCount:s})}function ir(r){return r.type==="webgl"?ti:ei}function ee(r){let e=r.userData[Jr];return e?.enabled?e:null}function R(){return globalThis.performance?.now?.()??Date.now()}function ii(r,e){let t=ee(r);if(!(!t||!t.activeDefaultFramebufferAcquireDepth))switch(t.transientCanvasResourceCreates=(t.transientCanvasResourceCreates||0)+1,e){case"Texture":t.transientCanvasTextureCreates=(t.transientCanvasTextureCreates||0)+1;break;case"TextureView":t.transientCanvasTextureViewCreates=(t.transientCanvasTextureViewCreates||0)+1;break;case"Sampler":t.transientCanvasSamplerCreates=(t.transientCanvasSamplerCreates||0)+1;break;case"Framebuffer":t.transientCanvasFramebufferCreates=(t.transientCanvasFramebufferCreates||0)+1;break;default:break}}function si(r){let e=Object.getPrototypeOf(r);for(;e;){let t=Object.getPrototypeOf(e);if(!t||t===l.prototype)return ni(e)||r[Symbol.toStringTag]||r.constructor.name;e=t}return r[Symbol.toStringTag]||r.constructor.name}function ni(r){let e=Object.getOwnPropertyDescriptor(r,Symbol.toStringTag);return typeof e?.get=="function"?e.get.call(r):typeof e?.value=="string"?e.value:null}var te=class extends l{get[Symbol.toStringTag](){return"Buffer"}usage;indexType;updateTimestamp;constructor(e,t){let i={...t};(t.usage||0)&te.INDEX&&!t.indexType&&(t.data instanceof Uint32Array?i.indexType="uint32":t.data instanceof Uint16Array?i.indexType="uint16":t.data instanceof Uint8Array&&(i.indexType="uint8")),delete i.data,super(e,i,te.defaultProps),this.usage=i.usage||0,this.indexType=i.indexType,this.updateTimestamp=e.incrementTimestamp()}clone(e){return this.device.createBuffer({...this.props,...e})}debugData=new ArrayBuffer(0);_setDebugData(e,t,i){let s=null,n;ArrayBuffer.isView(e)?(s=e,n=e.buffer):n=e;let o=Math.min(e?e.byteLength:i,te.DEBUG_DATA_MAX_LENGTH);if(n===null)this.debugData=new ArrayBuffer(o);else{let a=Math.min(s?.byteOffset||0,n.byteLength),c=Math.max(0,n.byteLength-a),f=Math.min(o,c);this.debugData=new Uint8Array(n,a,f).slice().buffer}}},p=te;u(p,"INDEX",16),u(p,"VERTEX",32),u(p,"UNIFORM",64),u(p,"STORAGE",128),u(p,"INDIRECT",256),u(p,"QUERY_RESOLVE",512),u(p,"MAP_READ",1),u(p,"MAP_WRITE",2),u(p,"COPY_SRC",4),u(p,"COPY_DST",8),u(p,"DEBUG_DATA_MAX_LENGTH",32),u(p,"defaultProps",{...l.defaultProps,usage:0,byteLength:0,byteOffset:0,data:null,indexType:"uint16",onMapped:void 0});var ot=class{getDataTypeInfo(e){let[t,i,s]=nt[e],n=e.includes("norm"),o=!n&&!e.startsWith("float"),a=e.startsWith("s");return{signedType:t,primitiveType:i,byteLength:s,normalized:n,integer:o,signed:a}}getNormalizedDataType(e){let t=e;switch(t){case"uint8":return"unorm8";case"sint8":return"snorm8";case"uint16":return"unorm16";case"sint16":return"snorm16";default:return t}}alignTo(e,t){switch(t){case 1:return e;case 2:return e+e%2;default:return e+(4-e%4)%4}}getDataType(e){let t=ArrayBuffer.isView(e)?e.constructor:e;if(t===Uint8ClampedArray)return"uint8";let i=Object.values(nt).find(s=>t===s[4]);if(!i)throw new Error(t.name);return i[0]}getTypedArrayConstructor(e){let[,,,,t]=nt[e];return t}},L=new ot,nt={uint8:["uint8","u32",1,!1,Uint8Array],sint8:["sint8","i32",1,!1,Int8Array],unorm8:["uint8","f32",1,!0,Uint8Array],snorm8:["sint8","f32",1,!0,Int8Array],uint16:["uint16","u32",2,!1,Uint16Array],sint16:["sint16","i32",2,!1,Int16Array],unorm16:["uint16","u32",2,!0,Uint16Array],snorm16:["sint16","i32",2,!0,Int16Array],float16:["float16","f16",2,!1,Uint16Array],float32:["float32","f32",4,!1,Float32Array],uint32:["uint32","u32",4,!1,Uint32Array],sint32:["sint32","i32",4,!1,Int32Array]};var at=class{getVertexFormatInfo(e){let t;e.endsWith("-webgl")&&(e.replace("-webgl",""),t=!0);let[i,s]=e.split("x"),n=i,o=s?parseInt(s):1,a=L.getDataTypeInfo(n),c={type:n,components:o,byteLength:a.byteLength*o,integer:a.integer,signed:a.signed,normalized:a.normalized};return t&&(c.webglOnly=!0),c}makeVertexFormat(e,t,i){let s=i?L.getNormalizedDataType(e):e;switch(s){case"unorm8":return t===1?"unorm8":t===3?"unorm8x3-webgl":`${s}x${t}`;case"snorm8":case"uint8":case"sint8":case"uint16":case"sint16":case"unorm16":case"snorm16":case"float16":if(t===1||t===3)throw new Error(`size: ${t}`);return`${s}x${t}`;default:return t===1?s:`${s}x${t}`}}getVertexFormatFromAttribute(e,t,i){if(!t||t>4)throw new Error(`size ${t}`);let s=t,n=L.getDataType(e);return this.makeVertexFormat(n,s,i)}getCompatibleVertexFormat(e){let t;switch(e.primitiveType){case"f32":t="float32";break;case"i32":t="sint32";break;case"u32":t="uint32";break;case"f16":return e.components<=2?"float16x2":"float16x4"}return e.components===1?t:`${t}x${e.components}`}},B=new at;var y="texture-compression-bc",m="texture-compression-astc",S="texture-compression-etc2",oi="texture-compression-etc1-webgl",Re="texture-compression-pvrtc-webgl",ct="texture-compression-atc-webgl",Le="float32-renderable-webgl",ut="float16-renderable-webgl",ai="rgb9e5ufloat-renderable-webgl",lt="snorm8-renderable-webgl",M="norm16-webgl",ft="norm16-renderable-webgl",dt="snorm16-renderable-webgl",Be="float32-filterable",sr="float16-filterable-webgl";function re(r){let e=nr[r];if(!e)throw new Error(`Unsupported texture format ${r}`);return e}function Me(){return nr}var ci={r8unorm:{},rg8unorm:{},"rgb8unorm-webgl":{},rgba8unorm:{},"rgba8unorm-srgb":{},r8snorm:{render:lt},rg8snorm:{render:lt},"rgb8snorm-webgl":{},rgba8snorm:{render:lt},r8uint:{},rg8uint:{},rgba8uint:{},r8sint:{},rg8sint:{},rgba8sint:{},bgra8unorm:{},"bgra8unorm-srgb":{},r16unorm:{f:M,render:ft},rg16unorm:{f:M,render:ft},"rgb16unorm-webgl":{f:M,render:!1},rgba16unorm:{f:M,render:ft},r16snorm:{f:M,render:dt},rg16snorm:{f:M,render:dt},"rgb16snorm-webgl":{f:M,render:!1},rgba16snorm:{f:M,render:dt},r16uint:{},rg16uint:{},rgba16uint:{},r16sint:{},rg16sint:{},rgba16sint:{},r16float:{render:ut,filter:"float16-filterable-webgl"},rg16float:{render:ut,filter:sr},rgba16float:{render:ut,filter:sr},r32uint:{},rg32uint:{},rgba32uint:{},r32sint:{},rg32sint:{},rgba32sint:{},r32float:{render:Le,filter:Be},rg32float:{render:!1,filter:Be},"rgb32float-webgl":{render:Le,filter:Be},rgba32float:{render:Le,filter:Be},"rgba4unorm-webgl":{channels:"rgba",bitsPerChannel:[4,4,4,4],packed:!0},"rgb565unorm-webgl":{channels:"rgb",bitsPerChannel:[5,6,5,0],packed:!0},"rgb5a1unorm-webgl":{channels:"rgba",bitsPerChannel:[5,5,5,1],packed:!0},rgb9e5ufloat:{channels:"rgb",packed:!0,render:ai},rg11b10ufloat:{channels:"rgb",bitsPerChannel:[11,11,10,0],packed:!0,p:1,render:Le},rgb10a2unorm:{channels:"rgba",bitsPerChannel:[10,10,10,2],packed:!0,p:1},rgb10a2uint:{channels:"rgba",bitsPerChannel:[10,10,10,2],packed:!0,p:1},stencil8:{attachment:"stencil",bitsPerChannel:[8,0,0,0],dataType:"uint8"},depth16unorm:{attachment:"depth",bitsPerChannel:[16,0,0,0],dataType:"uint16"},depth24plus:{attachment:"depth",bitsPerChannel:[24,0,0,0],dataType:"uint32"},depth32float:{attachment:"depth",bitsPerChannel:[32,0,0,0],dataType:"float32"},"depth24plus-stencil8":{attachment:"depth-stencil",bitsPerChannel:[24,8,0,0],packed:!0},"depth32float-stencil8":{attachment:"depth-stencil",bitsPerChannel:[32,8,0,0],packed:!0}},ui={"bc1-rgb-unorm-webgl":{f:y},"bc1-rgb-unorm-srgb-webgl":{f:y},"bc1-rgba-unorm":{f:y},"bc1-rgba-unorm-srgb":{f:y},"bc2-rgba-unorm":{f:y},"bc2-rgba-unorm-srgb":{f:y},"bc3-rgba-unorm":{f:y},"bc3-rgba-unorm-srgb":{f:y},"bc4-r-unorm":{f:y},"bc4-r-snorm":{f:y},"bc5-rg-unorm":{f:y},"bc5-rg-snorm":{f:y},"bc6h-rgb-ufloat":{f:y},"bc6h-rgb-float":{f:y},"bc7-rgba-unorm":{f:y},"bc7-rgba-unorm-srgb":{f:y},"etc2-rgb8unorm":{f:S},"etc2-rgb8unorm-srgb":{f:S},"etc2-rgb8a1unorm":{f:S},"etc2-rgb8a1unorm-srgb":{f:S},"etc2-rgba8unorm":{f:S},"etc2-rgba8unorm-srgb":{f:S},"eac-r11unorm":{f:S},"eac-r11snorm":{f:S},"eac-rg11unorm":{f:S},"eac-rg11snorm":{f:S},"astc-4x4-unorm":{f:m},"astc-4x4-unorm-srgb":{f:m},"astc-5x4-unorm":{f:m},"astc-5x4-unorm-srgb":{f:m},"astc-5x5-unorm":{f:m},"astc-5x5-unorm-srgb":{f:m},"astc-6x5-unorm":{f:m},"astc-6x5-unorm-srgb":{f:m},"astc-6x6-unorm":{f:m},"astc-6x6-unorm-srgb":{f:m},"astc-8x5-unorm":{f:m},"astc-8x5-unorm-srgb":{f:m},"astc-8x6-unorm":{f:m},"astc-8x6-unorm-srgb":{f:m},"astc-8x8-unorm":{f:m},"astc-8x8-unorm-srgb":{f:m},"astc-10x5-unorm":{f:m},"astc-10x5-unorm-srgb":{f:m},"astc-10x6-unorm":{f:m},"astc-10x6-unorm-srgb":{f:m},"astc-10x8-unorm":{f:m},"astc-10x8-unorm-srgb":{f:m},"astc-10x10-unorm":{f:m},"astc-10x10-unorm-srgb":{f:m},"astc-12x10-unorm":{f:m},"astc-12x10-unorm-srgb":{f:m},"astc-12x12-unorm":{f:m},"astc-12x12-unorm-srgb":{f:m},"pvrtc-rgb4unorm-webgl":{f:Re},"pvrtc-rgba4unorm-webgl":{f:Re},"pvrtc-rgb2unorm-webgl":{f:Re},"pvrtc-rgba2unorm-webgl":{f:Re},"etc1-rbg-unorm-webgl":{f:oi},"atc-rgb-unorm-webgl":{f:ct},"atc-rgba-unorm-webgl":{f:ct},"atc-rgbai-unorm-webgl":{f:ct}},nr={...ci,...ui};var li=/^(r|rg|rgb|rgba|bgra)([0-9]*)([a-z]*)(-srgb)?(-webgl)?$/,fi=["rgb","rgba","bgra"],di=["depth","stencil"],hi=["bc1","bc2","bc3","bc4","bc5","bc6","bc7","etc1","etc2","eac","atc","astc","pvrtc"],ht=class{isColor(e){return fi.some(t=>e.startsWith(t))}isDepthStencil(e){return di.some(t=>e.startsWith(t))}isCompressed(e){return hi.some(t=>e.startsWith(t))}getInfo(e){return or(e)}getCapabilities(e){return pi(e)}computeMemoryLayout(e){return mi(e)}},x=new ht;function mi({format:r,width:e,height:t,depth:i,byteAlignment:s}){let n=x.getInfo(r),{bytesPerPixel:o,bytesPerBlock:a=o,blockWidth:c=1,blockHeight:f=1,compressed:h=!1}=n,b=h?Math.ceil(e/c):e,z=h?Math.ceil(t/f):t,Ze=b*a,w=Math.ceil(Ze/s)*s,q=z,J=w*q*i;return{bytesPerPixel:o,bytesPerRow:w,rowsPerImage:q,depthOrArrayLayers:i,bytesPerImage:w*q,byteLength:J}}function pi(r){let e=re(r),t={format:r,create:e.f??!0,render:e.render??!0,filter:e.filter??!0,blend:e.blend??!0,store:e.store??!0},i=or(r),s=r.startsWith("depth")||r.startsWith("stencil"),n=i?.signed,o=i?.integer,a=i?.webgl,c=Boolean(i?.compressed);return t.render&&=!s&&!c,t.filter&&=!s&&!n&&!o&&!a,t}function or(r){let e=gi(r);if(x.isCompressed(r)){e.channels="rgb",e.components=3,e.bytesPerPixel=1,e.srgb=!1,e.compressed=!0,e.bytesPerBlock=yi(r);let i=bi(r);i&&(e.blockWidth=i.blockWidth,e.blockHeight=i.blockHeight)}let t=e.packed?null:li.exec(r);if(t){let[,i,s,n,o,a]=t,c=`${n}${s}`,f=L.getDataTypeInfo(c),h=f.byteLength*8,b=i?.length??1,z=[h,b>=2?h:0,b>=3?h:0,b>=4?h:0];e={format:r,attachment:e.attachment,dataType:f.signedType,components:b,channels:i,integer:f.integer,signed:f.signed,normalized:f.normalized,bitsPerChannel:z,bytesPerPixel:f.byteLength*b,packed:e.packed,srgb:e.srgb},a==="-webgl"&&(e.webgl=!0),o==="-srgb"&&(e.srgb=!0)}return r.endsWith("-webgl")&&(e.webgl=!0),r.endsWith("-srgb")&&(e.srgb=!0),e}function gi(r){let e=re(r),t=e.bytesPerPixel||1,i=e.bitsPerChannel||[8,8,8,8];return delete e.bitsPerChannel,delete e.bytesPerPixel,delete e.f,delete e.render,delete e.filter,delete e.blend,delete e.store,{...e,format:r,attachment:e.attachment||"color",channels:e.channels||"r",components:e.components||e.channels?.length||1,bytesPerPixel:t,bitsPerChannel:i,dataType:e.dataType||"uint8",srgb:e.srgb??!1,packed:e.packed??!1,webgl:e.webgl??!1,integer:e.integer??!1,signed:e.signed??!1,normalized:e.normalized??!1,compressed:e.compressed??!1}}function bi(r){let t=/.*-(\d+)x(\d+)-.*/.exec(r);if(t){let[,i,s]=t;return{blockWidth:Number(i),blockHeight:Number(s)}}return r.startsWith("bc")||r.startsWith("etc1")||r.startsWith("etc2")||r.startsWith("eac")||r.startsWith("atc")?{blockWidth:4,blockHeight:4}:r.startsWith("pvrtc-rgb4")||r.startsWith("pvrtc-rgba4")?{blockWidth:4,blockHeight:4}:r.startsWith("pvrtc-rgb2")||r.startsWith("pvrtc-rgba2")?{blockWidth:8,blockHeight:4}:null}function yi(r){return r.startsWith("bc1")||r.startsWith("bc4")||r.startsWith("etc1")||r.startsWith("etc2-rgb8")||r.startsWith("etc2-rgb8a1")||r.startsWith("eac-r11")||r==="atc-rgb-unorm-webgl"?8:r.startsWith("bc2")||r.startsWith("bc3")||r.startsWith("bc5")||r.startsWith("bc6h")||r.startsWith("bc7")||r.startsWith("etc2-rgba8")||r.startsWith("eac-rg11")||r.startsWith("astc")||r==="atc-rgba-unorm-webgl"||r==="atc-rgbai-unorm-webgl"?16:r.startsWith("pvrtc")?8:16}function De(r){return typeof ImageData<"u"&&r instanceof ImageData||typeof ImageBitmap<"u"&&r instanceof ImageBitmap||typeof HTMLImageElement<"u"&&r instanceof HTMLImageElement||typeof HTMLVideoElement<"u"&&r instanceof HTMLVideoElement||typeof VideoFrame<"u"&&r instanceof VideoFrame||typeof HTMLCanvasElement<"u"&&r instanceof HTMLCanvasElement||typeof OffscreenCanvas<"u"&&r instanceof OffscreenCanvas}function Ie(r){if(typeof ImageData<"u"&&r instanceof ImageData||typeof ImageBitmap<"u"&&r instanceof ImageBitmap||typeof HTMLCanvasElement<"u"&&r instanceof HTMLCanvasElement||typeof OffscreenCanvas<"u"&&r instanceof OffscreenCanvas)return{width:r.width,height:r.height};if(typeof HTMLImageElement<"u"&&r instanceof HTMLImageElement)return{width:r.naturalWidth,height:r.naturalHeight};if(typeof HTMLVideoElement<"u"&&r instanceof HTMLVideoElement)return{width:r.videoWidth,height:r.videoHeight};if(typeof VideoFrame<"u"&&r instanceof VideoFrame)return{width:r.displayWidth,height:r.displayHeight};throw new Error("Unknown image type")}var $e=class{};function xi(r,e){let t=mt(r),i=e.map(mt).filter(s=>s!==void 0);return[t,...i].filter(s=>s!==void 0)}function mt(r){if(r!==void 0){if(r===null||typeof r=="string"||typeof r=="number"||typeof r=="boolean")return r;if(r instanceof Error)return r.message;if(Array.isArray(r))return r.map(mt);if(typeof r=="object"){if(_i(r)){let e=String(r);if(e!=="[object Object]")return e}return wi(r)?vi(r):r.constructor?.name||"Object"}return String(r)}}function _i(r){return"toString"in r&&typeof r.toString=="function"&&r.toString!==Object.prototype.toString}function wi(r){return"message"in r&&"type"in r}function vi(r){let e=typeof r.type=="string"?r.type:"message",t=typeof r.message=="string"?r.message:"",i=typeof r.lineNum=="number"?r.lineNum:null,s=typeof r.linePos=="number"?r.linePos:null,n=i!==null&&s!==null?` @ ${i}:${s}`:i!==null?` @ ${i}`:"";return`${e}${n}: ${t}`.trim()}var ke=class{features;disabledFeatures;constructor(e=[],t){this.features=new Set(e),this.disabledFeatures=t||{}}*[Symbol.iterator](){yield*this.features}has(e){return!this.disabledFeatures?.[e]&&this.features.has(e)}},pt=class{get[Symbol.toStringTag](){return"Device"}toString(){return`Device(${this.id})`}id;props;userData={};statsManager=Pe;_factories={};timestamp=0;_reused=!1;_moduleData={};_textureCaps={};_debugGPUTimeQuery=null;constructor(e){this.props={...pt.defaultProps,...e},this.id=this.props.id||P(this[Symbol.toStringTag].toLowerCase())}getVertexFormatInfo(e){return B.getVertexFormatInfo(e)}isVertexFormatSupported(e){return!0}getTextureFormatInfo(e){return x.getInfo(e)}getTextureFormatCapabilities(e){let t=this._textureCaps[e];if(!t){let i=this._getDeviceTextureFormatCapabilities(e);t=this._getDeviceSpecificTextureFormatCapabilities(i),this._textureCaps[e]=t}return t}getMipLevelCount(e,t,i=1){let s=Math.max(e,t,i);return 1+Math.floor(Math.log2(s))}isExternalImage(e){return De(e)}getExternalImageSize(e){return Ie(e)}isTextureFormatSupported(e){return this.getTextureFormatCapabilities(e).create}isTextureFormatFilterable(e){return this.getTextureFormatCapabilities(e).filter}isTextureFormatRenderable(e){return this.getTextureFormatCapabilities(e).render}isTextureFormatCompressed(e){return x.isCompressed(e)}getSupportedCompressedTextureFormats(){let e=[];for(let t of Object.keys(Me()))this.isTextureFormatCompressed(t)&&this.isTextureFormatSupported(t)&&e.push(t);return e}pushDebugGroup(e){this.commandEncoder.pushDebugGroup(e)}popDebugGroup(){this.commandEncoder?.popDebugGroup()}insertDebugMarker(e){this.commandEncoder?.insertDebugMarker(e)}loseDevice(){return!1}incrementTimestamp(){return this.timestamp++}reportError(e,t,...i){if(!this.props.onError(e,t)){let n=xi(t,i);return d.error(this.type==="webgl"?"%cWebGL":"%cWebGPU","color: white; background: red; padding: 2px 6px; border-radius: 3px;",e.message,...n)}return()=>{}}debug(){if(this.props.debug)debugger;else{let e=`'Type luma.log.set({debug: true}) in console to enable debug breakpoints',
8
- or create a device with the 'debug: true' prop.`;d.once(0,e)()}}getDefaultCanvasContext(){if(!this.canvasContext)throw new Error("Device has no default CanvasContext. See props.createCanvasContext");return this.canvasContext}createFence(){throw new Error("createFence() not implemented")}beginRenderPass(e){return this.commandEncoder.beginRenderPass(e)}beginComputePass(e){return this.commandEncoder.beginComputePass(e)}generateMipmapsWebGPU(e){throw new Error("not implemented")}_createSharedRenderPipelineWebGL(e){throw new Error("_createSharedRenderPipelineWebGL() not implemented")}_createBindGroupLayoutWebGPU(e,t){throw new Error("_createBindGroupLayoutWebGPU() not implemented")}_createBindGroupWebGPU(e,t,i,s){throw new Error("_createBindGroupWebGPU() not implemented")}_supportsDebugGPUTime(){return this.features.has("timestamp-query")&&Boolean(this.props.debug||this.props.debugGPUTime)}_enableDebugGPUTime(e=256){if(!this._supportsDebugGPUTime())return null;if(this._debugGPUTimeQuery)return this._debugGPUTimeQuery;try{this._debugGPUTimeQuery=this.createQuerySet({type:"timestamp",count:e}),this.commandEncoder=this.createCommandEncoder({id:this.commandEncoder.props.id,timeProfilingQuerySet:this._debugGPUTimeQuery})}catch{this._debugGPUTimeQuery=null}return this._debugGPUTimeQuery}_disableDebugGPUTime(){this._debugGPUTimeQuery&&(this.commandEncoder.getTimeProfilingQuerySet()===this._debugGPUTimeQuery&&(this.commandEncoder=this.createCommandEncoder({id:this.commandEncoder.props.id})),this._debugGPUTimeQuery.destroy(),this._debugGPUTimeQuery=null)}_isDebugGPUTimeEnabled(){return this._debugGPUTimeQuery!==null}getCanvasContext(){return this.getDefaultCanvasContext()}readPixelsToArrayWebGL(e,t){throw new Error("not implemented")}readPixelsToBufferWebGL(e,t){throw new Error("not implemented")}setParametersWebGL(e){throw new Error("not implemented")}getParametersWebGL(e){throw new Error("not implemented")}withParametersWebGL(e,t){throw new Error("not implemented")}clearWebGL(e){throw new Error("not implemented")}resetWebGL(){throw new Error("not implemented")}getModuleData(e){return this._moduleData[e]||={},this._moduleData[e]}static _getCanvasContextProps(e){return e.createCanvasContext===!0?{}:e.createCanvasContext}_getDeviceTextureFormatCapabilities(e){let t=x.getCapabilities(e),i=n=>(typeof n=="string"?this.features.has(n):n)??!0,s=i(t.create);return{format:e,create:s,render:s&&i(t.render),filter:s&&i(t.filter),blend:s&&i(t.blend),store:s&&i(t.store)}}_normalizeBufferProps(e){(e instanceof ArrayBuffer||ArrayBuffer.isView(e))&&(e={data:e});let t={...e};if((e.usage||0)&p.INDEX&&(e.indexType||(e.data instanceof Uint32Array?t.indexType="uint32":e.data instanceof Uint16Array?t.indexType="uint16":e.data instanceof Uint8Array&&(t.data=new Uint16Array(e.data),t.indexType="uint16")),!t.indexType))throw new Error("indices buffer content must be of type uint16 or uint32");return t}},O=pt;u(O,"defaultProps",{id:null,powerPreference:"high-performance",failIfMajorPerformanceCaveat:!1,createCanvasContext:void 0,webgl:{},onError:(e,t)=>{},onResize:(e,t)=>{let[i,s]=e.getDevicePixelSize();d.log(1,`${e} resized => ${i}x${s}px`)()},onPositionChange:(e,t)=>{let[i,s]=e.getPosition();d.log(1,`${e} repositioned => ${i},${s}`)()},onVisibilityChange:e=>d.log(1,`${e} Visibility changed ${e.isVisible}`)(),onDevicePixelRatioChange:(e,t)=>d.log(1,`${e} DPR changed ${t.oldRatio} => ${e.devicePixelRatio}`)(),debug:Si(),debugGPUTime:!1,debugShaders:d.get("debug-shaders")||void 0,debugFramebuffers:Boolean(d.get("debug-framebuffers")),debugFactories:Boolean(d.get("debug-factories")),debugWebGL:Boolean(d.get("debug-webgl")),debugSpectorJS:void 0,debugSpectorJSUrl:void 0,_reuseDevices:!1,_requestMaxLimits:!0,_cacheShaders:!0,_destroyShaders:!1,_cachePipelines:!0,_sharePipelines:!0,_destroyPipelines:!1,_initializeFeatures:!0,_disabledFeatures:{"compilation-status-async-webgl":!0},_handle:void 0});function Pi(r,e){return r!=null?Boolean(r):e!==void 0?e!=="production":!1}function Si(){return Pi(d.get("debug"),Ti())}function Ti(){let r=globalThis.process;if(r?.env)return r.env.NODE_ENV}var Ci="set luma.log.level=1 (or higher) to trace rendering",ar="No matching device found. Ensure `@luma.gl/webgl` and/or `@luma.gl/webgpu` modules are imported.",Oe=class{stats=Pe;log=d;VERSION="9.3.0-alpha.10";spector;preregisteredAdapters=new Map;constructor(){if(globalThis.luma){if(globalThis.luma.VERSION!==this.VERSION)throw d.error(`Found luma.gl ${globalThis.luma.VERSION} while initialzing ${this.VERSION}`)(),d.error("'yarn why @luma.gl/core' can help identify the source of the conflict")(),new Error("luma.gl - multiple versions detected: see console log");d.error("This version of luma.gl has already been initialized")()}d.log(1,`${this.VERSION} - ${Ci}`)(),globalThis.luma=this}async createDevice(e={}){let t={...Oe.defaultProps,...e},i=this.selectAdapter(t.type,t.adapters);if(!i)throw new Error(ar);return t.waitForPageLoad&&await i.pageLoaded,await i.create(t)}async attachDevice(e,t){let i=this._getTypeFromHandle(e,t.adapters),s=i&&this.selectAdapter(i,t.adapters);if(!s)throw new Error(ar);return await s?.attach?.(e,t)}registerAdapters(e){for(let t of e)this.preregisteredAdapters.set(t.type,t)}getSupportedAdapters(e=[]){let t=this._getAdapterMap(e);return Array.from(t).map(([,i])=>i).filter(i=>i.isSupported?.()).map(i=>i.type)}getBestAvailableAdapterType(e=[]){let t=["webgpu","webgl","null"],i=this._getAdapterMap(e);for(let s of t)if(i.get(s)?.isSupported?.())return s;return null}selectAdapter(e,t=[]){let i=e;e==="best-available"&&(i=this.getBestAvailableAdapterType(t));let s=this._getAdapterMap(t);return i&&s.get(i)||null}enforceWebGL2(e=!0,t=[]){let s=this._getAdapterMap(t).get("webgl");s||d.warn("enforceWebGL2: webgl adapter not found")(),s?.enforceWebGL2?.(e)}setDefaultDeviceProps(e){Object.assign(Oe.defaultProps,e)}_getAdapterMap(e=[]){let t=new Map(this.preregisteredAdapters);for(let i of e)t.set(i.type,i);return t}_getTypeFromHandle(e,t=[]){return e instanceof WebGL2RenderingContext?"webgl":typeof GPUDevice<"u"&&e instanceof GPUDevice||e?.queue?"webgpu":e===null?"null":(e instanceof WebGLRenderingContext?d.warn("WebGL1 is not supported",e)():d.warn("Unknown handle type",e)(),null)}},Ue=Oe;u(Ue,"defaultProps",{...O.defaultProps,type:"best-available",adapters:void 0,waitForPageLoad:!0});var cr=new Ue;var Ge=class{get pageLoaded(){return Ri()}},Ai=v()&&typeof document<"u",Ei=()=>Ai&&document.readyState==="complete",Fe=null;function Ri(){return Fe||(Ei()||typeof window>"u"?Fe=Promise.resolve():Fe=new Promise(r=>window.addEventListener("load",()=>r()))),Fe}var We=class{props;_resizeObserver;_intersectionObserver;_observeDevicePixelRatioTimeout=null;_observeDevicePixelRatioMediaQuery=null;_handleDevicePixelRatioChange=()=>this._refreshDevicePixelRatio();_trackPositionInterval=null;_started=!1;get started(){return this._started}constructor(e){this.props=e}start(){if(!(this._started||!this.props.canvas)){this._started=!0,this._intersectionObserver||=new IntersectionObserver(e=>this.props.onIntersection(e)),this._resizeObserver||=new ResizeObserver(e=>this.props.onResize(e)),this._intersectionObserver.observe(this.props.canvas);try{this._resizeObserver.observe(this.props.canvas,{box:"device-pixel-content-box"})}catch{this._resizeObserver.observe(this.props.canvas,{box:"content-box"})}this._observeDevicePixelRatioTimeout=setTimeout(()=>this._refreshDevicePixelRatio(),0),this.props.trackPosition&&this._trackPosition()}}stop(){this._started&&(this._started=!1,this._observeDevicePixelRatioTimeout&&(clearTimeout(this._observeDevicePixelRatioTimeout),this._observeDevicePixelRatioTimeout=null),this._observeDevicePixelRatioMediaQuery&&(this._observeDevicePixelRatioMediaQuery.removeEventListener("change",this._handleDevicePixelRatioChange),this._observeDevicePixelRatioMediaQuery=null),this._trackPositionInterval&&(clearInterval(this._trackPositionInterval),this._trackPositionInterval=null),this._resizeObserver?.disconnect(),this._intersectionObserver?.disconnect())}_refreshDevicePixelRatio(){this._started&&(this.props.onDevicePixelRatioChange(),this._observeDevicePixelRatioMediaQuery?.removeEventListener("change",this._handleDevicePixelRatioChange),this._observeDevicePixelRatioMediaQuery=matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`),this._observeDevicePixelRatioMediaQuery.addEventListener("change",this._handleDevicePixelRatioChange,{once:!0}))}_trackPosition(e=100){this._trackPositionInterval||(this._trackPositionInterval=setInterval(()=>{this._started?this.props.onPositionChange():this._trackPositionInterval&&(clearInterval(this._trackPositionInterval),this._trackPositionInterval=null)},e))}};function ur(){let r,e;return{promise:new Promise((i,s)=>{r=i,e=s}),resolve:r,reject:e}}function ze(r,e){if(!r){let t=new Error(e??"luma.gl assertion failed.");throw Error.captureStackTrace?.(t,ze),t}}function He(r,e){return ze(r,e),r}var ie=class{static isHTMLCanvas(e){return typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement}static isOffscreenCanvas(e){return typeof OffscreenCanvas<"u"&&e instanceof OffscreenCanvas}id;props;canvas;htmlCanvas;offscreenCanvas;type;initialized;isInitialized=!1;isVisible=!0;cssWidth;cssHeight;devicePixelRatio;devicePixelWidth;devicePixelHeight;drawingBufferWidth;drawingBufferHeight;_initializedResolvers=ur();_canvasObserver;_position=[0,0];destroyed=!1;_needsDrawingBufferResize=!0;toString(){return`${this[Symbol.toStringTag]}(${this.id})`}constructor(e){this.props={...ie.defaultProps,...e},e=this.props,this.initialized=this._initializedResolvers.promise,v()?e.canvas?typeof e.canvas=="string"?this.canvas=Bi(e.canvas):this.canvas=e.canvas:this.canvas=Mi(e):this.canvas={width:e.width||1,height:e.height||1},ie.isHTMLCanvas(this.canvas)?(this.id=e.id||this.canvas.id,this.type="html-canvas",this.htmlCanvas=this.canvas):ie.isOffscreenCanvas(this.canvas)?(this.id=e.id||"offscreen-canvas",this.type="offscreen-canvas",this.offscreenCanvas=this.canvas):(this.id=e.id||"node-canvas-context",this.type="node"),this.cssWidth=this.htmlCanvas?.clientWidth||this.canvas.width,this.cssHeight=this.htmlCanvas?.clientHeight||this.canvas.height,this.devicePixelWidth=this.canvas.width,this.devicePixelHeight=this.canvas.height,this.drawingBufferWidth=this.canvas.width,this.drawingBufferHeight=this.canvas.height,this.devicePixelRatio=globalThis.devicePixelRatio||1,this._position=[0,0],this._canvasObserver=new We({canvas:this.htmlCanvas,trackPosition:this.props.trackPosition,onResize:t=>this._handleResize(t),onIntersection:t=>this._handleIntersection(t),onDevicePixelRatioChange:()=>this._observeDevicePixelRatio(),onPositionChange:()=>this.updatePosition()})}destroy(){this.destroyed||(this.destroyed=!0,this._stopObservers(),this.device=null)}setProps(e){return"useDevicePixels"in e&&(this.props.useDevicePixels=e.useDevicePixels||!1,this._updateDrawingBufferSize()),this}getCurrentFramebuffer(e){return this._resizeDrawingBufferIfNeeded(),this._getCurrentFramebuffer(e)}getCSSSize(){return[this.cssWidth,this.cssHeight]}getPosition(){return this._position}getDevicePixelSize(){return[this.devicePixelWidth,this.devicePixelHeight]}getDrawingBufferSize(){return[this.drawingBufferWidth,this.drawingBufferHeight]}getMaxDrawingBufferSize(){let e=this.device.limits.maxTextureDimension2D;return[e,e]}setDrawingBufferSize(e,t){e=Math.floor(e),t=Math.floor(t),!(this.drawingBufferWidth===e&&this.drawingBufferHeight===t)&&(this.drawingBufferWidth=e,this.drawingBufferHeight=t,this._needsDrawingBufferResize=!0)}getDevicePixelRatio(){return typeof window<"u"&&window.devicePixelRatio||1}cssToDevicePixels(e,t=!0){let i=this.cssToDeviceRatio(),[s,n]=this.getDrawingBufferSize();return Di(e,i,s,n,t)}getPixelSize(){return this.getDevicePixelSize()}getAspect(){let[e,t]=this.getDrawingBufferSize();return e>0&&t>0?e/t:1}cssToDeviceRatio(){try{let[e]=this.getDrawingBufferSize(),[t]=this.getCSSSize();return t?e/t:1}catch{return 1}}resize(e){this.setDrawingBufferSize(e.width,e.height)}_setAutoCreatedCanvasId(e){this.htmlCanvas?.id==="lumagl-auto-created-canvas"&&(this.htmlCanvas.id=e)}_startObservers(){this.destroyed||this._canvasObserver.start()}_stopObservers(){this._canvasObserver.stop()}_handleIntersection(e){if(this.destroyed)return;let t=e.find(s=>s.target===this.canvas);if(!t)return;let i=t.isIntersecting;this.isVisible!==i&&(this.isVisible=i,this.device.props.onVisibilityChange(this))}_handleResize(e){if(this.destroyed)return;let t=e.find(f=>f.target===this.canvas);if(!t)return;let i=He(t.contentBoxSize?.[0]);this.cssWidth=i.inlineSize,this.cssHeight=i.blockSize;let s=this.getDevicePixelSize(),n=t.devicePixelContentBoxSize?.[0]?.inlineSize||i.inlineSize*devicePixelRatio,o=t.devicePixelContentBoxSize?.[0]?.blockSize||i.blockSize*devicePixelRatio,[a,c]=this.getMaxDrawingBufferSize();this.devicePixelWidth=Math.max(1,Math.min(n,a)),this.devicePixelHeight=Math.max(1,Math.min(o,c)),this._updateDrawingBufferSize(),this.device.props.onResize(this,{oldPixelSize:s})}_updateDrawingBufferSize(){if(this.props.autoResize)if(typeof this.props.useDevicePixels=="number"){let e=this.props.useDevicePixels;this.setDrawingBufferSize(this.cssWidth*e,this.cssHeight*e)}else this.props.useDevicePixels?this.setDrawingBufferSize(this.devicePixelWidth,this.devicePixelHeight):this.setDrawingBufferSize(this.cssWidth,this.cssHeight);this._initializedResolvers.resolve(),this.isInitialized=!0,this.updatePosition()}_resizeDrawingBufferIfNeeded(){this._needsDrawingBufferResize&&(this._needsDrawingBufferResize=!1,(this.drawingBufferWidth!==this.canvas.width||this.drawingBufferHeight!==this.canvas.height)&&(this.canvas.width=this.drawingBufferWidth,this.canvas.height=this.drawingBufferHeight,this._configureDevice()))}_observeDevicePixelRatio(){if(this.destroyed||!this._canvasObserver.started)return;let e=this.devicePixelRatio;this.devicePixelRatio=window.devicePixelRatio,this.updatePosition(),this.device.props.onDevicePixelRatioChange?.(this,{oldRatio:e})}updatePosition(){if(this.destroyed)return;let e=this.htmlCanvas?.getBoundingClientRect();if(e){let t=[e.left,e.top];if(this._position??=t,t[0]!==this._position[0]||t[1]!==this._position[1]){let s=this._position;this._position=t,this.device.props.onPositionChange?.(this,{oldPosition:s})}}}},E=ie;u(E,"defaultProps",{id:void 0,canvas:null,width:800,height:600,useDevicePixels:!0,autoResize:!0,container:null,visible:!0,alphaMode:"opaque",colorSpace:"srgb",trackPosition:!1});function Li(r){if(typeof r=="string"){let e=document.getElementById(r);if(!e)throw new Error(`${r} is not an HTML element`);return e}return r||document.body}function Bi(r){let e=document.getElementById(r);if(!E.isHTMLCanvas(e))throw new Error("Object is not a canvas element");return e}function Mi(r){let{width:e,height:t}=r,i=document.createElement("canvas");i.id=P("lumagl-auto-created-canvas"),i.width=e||1,i.height=t||1,i.style.width=Number.isFinite(e)?`${e}px`:"100%",i.style.height=Number.isFinite(t)?`${t}px`:"100%",r?.visible||(i.style.visibility="hidden");let s=Li(r?.container||null);return s.insertBefore(i,s.firstChild),i}function Di(r,e,t,i,s){let n=r,o=lr(n[0],e,t),a=fr(n[1],e,i,s),c=lr(n[0]+1,e,t),f=c===t-1?c:c-1;c=fr(n[1]+1,e,i,s);let h;return s?(c=c===0?c:c+1,h=a,a=c):h=c===i-1?c:c-1,{x:o,y:a,width:Math.max(f-o+1,1),height:Math.max(h-a+1,1)}}function lr(r,e,t){return Math.min(Math.round(r*e),t-1)}function fr(r,e,t,i){return i?Math.max(0,t-1-Math.round(r*e)):Math.min(Math.round(r*e),t-1)}var se=class extends E{};u(se,"defaultProps",E.defaultProps);var Ne=class extends E{};var Ve=class extends l{get[Symbol.toStringTag](){return"Sampler"}constructor(e,t){t=Ve.normalizeProps(e,t),super(e,t,Ve.defaultProps)}static normalizeProps(e,t){return t}},F=Ve;u(F,"defaultProps",{...l.defaultProps,type:"color-sampler",addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge",addressModeW:"clamp-to-edge",magFilter:"nearest",minFilter:"nearest",mipmapFilter:"none",lodMinClamp:0,lodMaxClamp:32,compare:"less-equal",maxAnisotropy:1});var Ii={"1d":"1d","2d":"2d","2d-array":"2d",cube:"2d","cube-array":"2d","3d":"3d"},_=class extends l{dimension;baseDimension;format;width;height;depth;mipLevels;samples;byteAlignment;ready=Promise.resolve(this);isReady=!0;updateTimestamp;get[Symbol.toStringTag](){return"Texture"}toString(){return`Texture(${this.id},${this.format},${this.width}x${this.height})`}constructor(e,t,i){if(t=_.normalizeProps(e,t),super(e,t,_.defaultProps),this.dimension=this.props.dimension,this.baseDimension=Ii[this.dimension],this.format=this.props.format,this.width=this.props.width,this.height=this.props.height,this.depth=this.props.depth,this.mipLevels=this.props.mipLevels,this.samples=this.props.samples||1,this.dimension==="cube"&&(this.depth=6),this.props.width===void 0||this.props.height===void 0)if(e.isExternalImage(t.data)){let s=e.getExternalImageSize(t.data);this.width=s?.width||1,this.height=s?.height||1}else this.width=1,this.height=1,(this.props.width===void 0||this.props.height===void 0)&&d.warn(`${this} created with undefined width or height. This is deprecated. Use DynamicTexture instead.`)();this.byteAlignment=i?.byteAlignment||1,this.updateTimestamp=e.incrementTimestamp()}clone(e){return this.device.createTexture({...this.props,...e})}setSampler(e){this.sampler=e instanceof F?e:this.device.createSampler(e)}copyImageData(e){let{data:t,depth:i,...s}=e;this.writeData(t,{...s,depthOrArrayLayers:s.depthOrArrayLayers??i})}computeMemoryLayout(e={}){let t=this._normalizeTextureReadOptions(e),{width:i=this.width,height:s=this.height,depthOrArrayLayers:n=this.depth}=t,{format:o,byteAlignment:a}=this;return x.computeMemoryLayout({format:o,width:i,height:s,depth:n,byteAlignment:a})}readBuffer(e,t){throw new Error("readBuffer not implemented")}readDataAsync(e){throw new Error("readBuffer not implemented")}writeBuffer(e,t){throw new Error("readBuffer not implemented")}writeData(e,t){throw new Error("readBuffer not implemented")}readDataSyncWebGL(e){throw new Error("readDataSyncWebGL not available")}generateMipmapsWebGL(){throw new Error("generateMipmapsWebGL not available")}static normalizeProps(e,t){let i={...t},{width:s,height:n}=i;return typeof s=="number"&&(i.width=Math.max(1,Math.ceil(s))),typeof n=="number"&&(i.height=Math.max(1,Math.ceil(n))),i}_initializeData(e){this.device.isExternalImage(e)?this.copyExternalImage({image:e,width:this.width,height:this.height,depth:this.depth,mipLevel:0,x:0,y:0,z:0,aspect:"all",colorSpace:"srgb",premultipliedAlpha:!1,flipY:!1}):e&&this.copyImageData({data:e,mipLevel:0,x:0,y:0,z:0,aspect:"all"})}_normalizeCopyImageDataOptions(e){let{data:t,depth:i,...s}=e,n=this._normalizeTextureWriteOptions({...s,depthOrArrayLayers:s.depthOrArrayLayers??i});return{data:t,depth:n.depthOrArrayLayers,...n}}_normalizeCopyExternalImageOptions(e){let t=_._omitUndefined(e),i=t.mipLevel??0,s=this._getMipLevelSize(i),n=this.device.getExternalImageSize(e.image),o={..._.defaultCopyExternalImageOptions,...s,...n,...t};return o.width=Math.min(o.width,s.width-o.x),o.height=Math.min(o.height,s.height-o.y),o.depth=Math.min(o.depth,s.depthOrArrayLayers-o.z),o}_normalizeTextureReadOptions(e){let t=_._omitUndefined(e),i=t.mipLevel??0,s=this._getMipLevelSize(i),n={..._.defaultTextureReadOptions,...s,...t};return n.width=Math.min(n.width,s.width-n.x),n.height=Math.min(n.height,s.height-n.y),n.depthOrArrayLayers=Math.min(n.depthOrArrayLayers,s.depthOrArrayLayers-n.z),n}_getSupportedColorReadOptions(e){let t=this._normalizeTextureReadOptions(e),i=x.getInfo(this.format);switch(this._validateColorReadAspect(t),this._validateColorReadFormat(i),this.dimension){case"2d":case"cube":case"cube-array":case"2d-array":case"3d":return t;default:throw new Error(`${this} color readback does not support ${this.dimension} textures`)}}_validateColorReadAspect(e){if(e.aspect!=="all")throw new Error(`${this} color readback only supports aspect 'all'`)}_validateColorReadFormat(e){if(e.compressed)throw new Error(`${this} color readback does not support compressed formats (${this.format})`);switch(e.attachment){case"color":return;case"depth":throw new Error(`${this} color readback does not support depth formats (${this.format})`);case"stencil":throw new Error(`${this} color readback does not support stencil formats (${this.format})`);case"depth-stencil":throw new Error(`${this} color readback does not support depth-stencil formats (${this.format})`);default:throw new Error(`${this} color readback does not support format ${this.format}`)}}_normalizeTextureWriteOptions(e){let t=_._omitUndefined(e),i=t.mipLevel??0,s=this._getMipLevelSize(i),n={..._.defaultTextureWriteOptions,...s,...t};n.width=Math.min(n.width,s.width-n.x),n.height=Math.min(n.height,s.height-n.y),n.depthOrArrayLayers=Math.min(n.depthOrArrayLayers,s.depthOrArrayLayers-n.z);let o=x.computeMemoryLayout({format:this.format,width:n.width,height:n.height,depth:n.depthOrArrayLayers,byteAlignment:this.byteAlignment}),a=o.bytesPerPixel*n.width;if(n.bytesPerRow=t.bytesPerRow??o.bytesPerRow,n.rowsPerImage=t.rowsPerImage??n.height,n.bytesPerRow<a)throw new Error(`bytesPerRow (${n.bytesPerRow}) must be at least ${a} for ${this.format}`);if(n.rowsPerImage<n.height)throw new Error(`rowsPerImage (${n.rowsPerImage}) must be at least ${n.height} for ${this.format}`);let c=this.device.getTextureFormatInfo(this.format).bytesPerPixel;if(c&&n.bytesPerRow%c!==0)throw new Error(`bytesPerRow (${n.bytesPerRow}) must be a multiple of bytesPerPixel (${c}) for ${this.format}`);return n}_getMipLevelSize(e){let t=Math.max(1,this.width>>e),i=this.baseDimension==="1d"?1:Math.max(1,this.height>>e),s=this.dimension==="3d"?Math.max(1,this.depth>>e):this.depth;return{width:t,height:i,depthOrArrayLayers:s}}getAllocatedByteLength(){let e=0;for(let t=0;t<this.mipLevels;t++){let{width:i,height:s,depthOrArrayLayers:n}=this._getMipLevelSize(t);e+=x.computeMemoryLayout({format:this.format,width:i,height:s,depth:n,byteAlignment:1}).byteLength}return e*this.samples}static _omitUndefined(e){return Object.fromEntries(Object.entries(e).filter(([,t])=>t!==void 0))}},g=_;u(g,"SAMPLE",4),u(g,"STORAGE",8),u(g,"RENDER",16),u(g,"COPY_SRC",1),u(g,"COPY_DST",2),u(g,"TEXTURE",4),u(g,"RENDER_ATTACHMENT",16),u(g,"defaultProps",{...l.defaultProps,data:null,dimension:"2d",format:"rgba8unorm",usage:_.SAMPLE|_.RENDER|_.COPY_DST,width:void 0,height:void 0,depth:1,mipLevels:1,samples:void 0,sampler:{},view:void 0}),u(g,"defaultCopyDataOptions",{data:void 0,byteOffset:0,bytesPerRow:void 0,rowsPerImage:void 0,width:void 0,height:void 0,depthOrArrayLayers:void 0,depth:1,mipLevel:0,x:0,y:0,z:0,aspect:"all"}),u(g,"defaultCopyExternalImageOptions",{image:void 0,sourceX:0,sourceY:0,width:void 0,height:void 0,depth:1,mipLevel:0,x:0,y:0,z:0,aspect:"all",colorSpace:"srgb",premultipliedAlpha:!1,flipY:!1}),u(g,"defaultTextureReadOptions",{x:0,y:0,z:0,width:void 0,height:void 0,depthOrArrayLayers:1,mipLevel:0,aspect:"all"}),u(g,"defaultTextureWriteOptions",{byteOffset:0,bytesPerRow:void 0,rowsPerImage:void 0,x:0,y:0,z:0,width:void 0,height:void 0,depthOrArrayLayers:1,mipLevel:0,aspect:"all"});var gt=class extends l{get[Symbol.toStringTag](){return"TextureView"}constructor(e,t){super(e,t,gt.defaultProps)}},ne=gt;u(ne,"defaultProps",{...l.defaultProps,format:void 0,dimension:void 0,aspect:"all",baseMipLevel:0,mipLevelCount:void 0,baseArrayLayer:0,arrayLayerCount:void 0});var bt=class extends l{get[Symbol.toStringTag](){return"ExternalTexture"}constructor(e,t){super(e,t,bt.defaultProps)}},oe=bt;u(oe,"defaultProps",{...l.defaultProps,source:void 0,colorSpace:"srgb"});function dr(r,e,t){let i="",s=e.split(/\r?\n/),n=r.slice().sort((o,a)=>o.lineNum-a.lineNum);switch(t?.showSourceCode||"no"){case"all":let o=0;for(let a=1;a<=s.length;a++){let c=s[a-1],f=n[o];for(c&&f&&(i+=hr(c,a,t));n.length>o&&f.lineNum===a;){let h=n[o++];h&&(i+=yt(h,s,h.lineNum,{...t,inlineSource:!1}))}}for(;n.length>o;){let a=n[o++];a&&(i+=yt(a,[],0,{...t,inlineSource:!1}))}return i;case"issues":case"no":for(let a of r)i+=yt(a,s,a.lineNum,{inlineSource:t?.showSourceCode!=="no"});return i}}function yt(r,e,t,i){if(i?.inlineSource){let n=$i(e,t),o=r.linePos>0?`${" ".repeat(r.linePos+5)}^^^
7
+ "use strict";var __exports__=(()=>{var Br=Object.create;var K=Object.defineProperty;var Mr=Object.getOwnPropertyDescriptor;var Dr=Object.getOwnPropertyNames;var $r=Object.getPrototypeOf,Ir=Object.prototype.hasOwnProperty;var kr=(r,e,t)=>e in r?K(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var Ur=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),Or=(r,e)=>{for(var t in e)K(r,t,{get:e[t],enumerable:!0})},_e=(r,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Dr(e))!Ir.call(r,s)&&s!==t&&K(r,s,{get:()=>e[s],enumerable:!(i=Mr(e,s))||i.enumerable});return r},ve=(r,e,t)=>(_e(r,e,"default"),t&&_e(t,e,"default")),Gr=(r,e,t)=>(t=r!=null?Br($r(r)):{},_e(e||!r||!r.__esModule?K(t,"default",{value:r,enumerable:!0}):t,r)),Fr=r=>_e(K({},"__esModule",{value:!0}),r);var u=(r,e,t)=>(kr(r,typeof e!="symbol"?e+"":e,t),t);var Lr=Ur((Qc,Rr)=>{Rr.exports=globalThis.luma});var we={};Or(we,{Adapter:()=>Fe,Buffer:()=>p,CanvasContext:()=>se,CommandBuffer:()=>de,CommandEncoder:()=>fe,ComputePass:()=>le,ComputePipeline:()=>$,Device:()=>G,DeviceFeatures:()=>ke,DeviceLimits:()=>Ie,ExternalTexture:()=>oe,Fence:()=>be,Framebuffer:()=>ae,PipelineFactory:()=>ce,PipelineLayout:()=>ye,PresentationContext:()=>He,QuerySet:()=>ge,RenderPass:()=>I,RenderPipeline:()=>T,Resource:()=>l,Sampler:()=>F,Shader:()=>W,ShaderBlockWriter:()=>Y,ShaderFactory:()=>ue,SharedRenderPipeline:()=>je,Texture:()=>g,TextureView:()=>ne,TransformFeedback:()=>pe,UniformBlock:()=>X,UniformStore:()=>Ke,VertexArray:()=>me,_getDefaultBindGroupFactory:()=>pr,_getTextureFormatDefinition:()=>re,_getTextureFormatTable:()=>Me,assert:()=>ze,assertDefined:()=>Ne,dataTypeDecoder:()=>B,flattenBindingsByGroup:()=>mr,getAttributeInfosFromLayouts:()=>Mt,getAttributeShaderTypeInfo:()=>Bt,getExternalImageSize:()=>$e,getScratchArray:()=>Pr,getShaderLayoutBinding:()=>Tt,getTextureImageView:()=>Wt,getTypedArrayConstructor:()=>yr,getVariableShaderTypeInfo:()=>he,isExternalImage:()=>De,log:()=>d,luma:()=>cr,makeShaderBlockLayout:()=>qe,normalizeBindingsByGroup:()=>Qe,readPixel:()=>Ar,setTextureImageData:()=>Cr,shaderTypeDecoder:()=>Xe,textureFormatDecoder:()=>x,vertexFormatDecoder:()=>M,writePixel:()=>Er});function Z(){let r;if(typeof window<"u"&&window.performance)r=window.performance.now();else if(typeof process<"u"&&process.hrtime){let e=process.hrtime();r=e[0]*1e3+e[1]/1e6}else r=Date.now();return r}var U=class{constructor(e,t){this.sampleSize=1,this.time=0,this.count=0,this.samples=0,this.lastTiming=0,this.lastSampleTime=0,this.lastSampleCount=0,this._count=0,this._time=0,this._samples=0,this._startTime=0,this._timerPending=!1,this.name=e,this.type=t,this.reset()}reset(){return this.time=0,this.count=0,this.samples=0,this.lastTiming=0,this.lastSampleTime=0,this.lastSampleCount=0,this._count=0,this._time=0,this._samples=0,this._startTime=0,this._timerPending=!1,this}setSampleSize(e){return this.sampleSize=e,this}incrementCount(){return this.addCount(1),this}decrementCount(){return this.subtractCount(1),this}addCount(e){return this._count+=e,this._samples++,this._checkSampling(),this}subtractCount(e){return this._count-=e,this._samples++,this._checkSampling(),this}addTime(e){return this._time+=e,this.lastTiming=e,this._samples++,this._checkSampling(),this}timeStart(){return this._startTime=Z(),this._timerPending=!0,this}timeEnd(){return this._timerPending?(this.addTime(Z()-this._startTime),this._timerPending=!1,this._checkSampling(),this):this}getSampleAverageCount(){return this.sampleSize>0?this.lastSampleCount/this.sampleSize:0}getSampleAverageTime(){return this.sampleSize>0?this.lastSampleTime/this.sampleSize:0}getSampleHz(){return this.lastSampleTime>0?this.sampleSize/(this.lastSampleTime/1e3):0}getAverageCount(){return this.samples>0?this.count/this.samples:0}getAverageTime(){return this.samples>0?this.time/this.samples:0}getHz(){return this.time>0?this.samples/(this.time/1e3):0}_checkSampling(){this._samples===this.sampleSize&&(this.lastSampleTime=this._time,this.lastSampleCount=this._count,this.count+=this._count,this.time+=this._time,this.samples+=this._samples,this._time=0,this._count=0,this._samples=0)}};var N=class{constructor(e){this.stats={},this.id=e.id,this.stats={},this._initializeStats(e.stats),Object.seal(this)}get(e,t="count"){return this._getOrCreate({name:e,type:t})}get size(){return Object.keys(this.stats).length}reset(){for(let e of Object.values(this.stats))e.reset();return this}forEach(e){for(let t of Object.values(this.stats))e(t)}getTable(){let e={};return this.forEach(t=>{e[t.name]={time:t.time||0,count:t.count||0,average:t.getAverageTime()||0,hz:t.getHz()||0}}),e}_initializeStats(e=[]){e.forEach(t=>this._getOrCreate(t))}_getOrCreate(e){let{name:t,type:i}=e,s=this.stats[t];return s||(e instanceof U?s=e:s=new U(t,i),this.stats[t]=s),s}};var Wr="GPU Time and Memory",zr=["Adapter","GPU","GPU Type","GPU Backend","Frame Rate","CPU Time","GPU Time","GPU Memory","Buffer Memory","Texture Memory","Referenced Buffer Memory","Referenced Texture Memory","Swap Chain Texture"],zt=new WeakMap,Nt=new WeakMap,et=class{stats=new Map;getStats(e){return this.get(e)}get(e){this.stats.has(e)||this.stats.set(e,new N({id:e}));let t=this.stats.get(e);return e===Wr&&Nr(t,zr),t}},Pe=new et;function Nr(r,e){let t=r.stats,i=!1;for(let c of e)t[c]||(r.get(c),i=!0);let s=Object.keys(t).length,n=zt.get(r);if(!i&&n?.orderedStatNames===e&&n.statCount===s)return;let o={},a=Nt.get(e);a||(a=new Set(e),Nt.set(e,a));for(let c of e)t[c]&&(o[c]=t[c]);for(let[c,f]of Object.entries(t))a.has(c)||(o[c]=f);for(let c of Object.keys(t))delete t[c];Object.assign(t,o),zt.set(r,{orderedStatNames:e,statCount:s})}var Se=globalThis,Hr=globalThis.document||{},Te=globalThis.process||{},Vr=globalThis.console,Cs=globalThis.navigator||{};function Ht(r){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=r||e;return Boolean(t&&t.indexOf("Electron")>=0)}function v(){return!(typeof process=="object"&&String(process)==="[object process]"&&!process?.browser)||Ht()}var tt="4.1.1";function H(r,e){if(!r)throw new Error(e||"Assertion failed")}function rt(r){if(!r)return 0;let e;switch(typeof r){case"number":e=r;break;case"object":e=r.logLevel||r.priority||0;break;default:return 0}return H(Number.isFinite(e)&&e>=0),e}function Vt(r){let{logLevel:e,message:t}=r;r.logLevel=rt(e);let i=r.args?Array.from(r.args):[];for(;i.length&&i.shift()!==t;);switch(typeof e){case"string":case"function":t!==void 0&&i.unshift(t),r.message=e;break;case"object":Object.assign(r,e);break;default:}typeof r.message=="function"&&(r.message=r.message());let s=typeof r.message;return H(s==="string"||s==="object"),Object.assign(r,{args:i},r.opts)}var O=()=>{},Ce=class{constructor({level:e=0}={}){this.userData={},this._onceCache=new Set,this._level=e}set level(e){this.setLevel(e)}get level(){return this.getLevel()}setLevel(e){return this._level=e,this}getLevel(){return this._level}warn(e,...t){return this._log("warn",0,e,t,{once:!0})}error(e,...t){return this._log("error",0,e,t)}log(e,t,...i){return this._log("log",e,t,i)}info(e,t,...i){return this._log("info",e,t,i)}once(e,t,...i){return this._log("once",e,t,i,{once:!0})}_log(e,t,i,s,n={}){let o=Vt({logLevel:t,message:i,args:this._buildArgs(t,i,s),opts:n});return this._createLogFunction(e,o,n)}_buildArgs(e,t,i){return[e,t,...i]}_createLogFunction(e,t,i){if(!this._shouldLog(t.logLevel))return O;let s=this._getOnceTag(i.tag??t.tag??t.message);if((i.once||t.once)&&s!==void 0){if(this._onceCache.has(s))return O;this._onceCache.add(s)}return this._emit(e,t)}_shouldLog(e){return this.getLevel()>=rt(e)}_getOnceTag(e){if(e!==void 0)try{return typeof e=="string"?e:String(e)}catch{return}}};function Qr(r){try{let e=window[r],t="__storage_test__";return e.setItem(t,t),e.removeItem(t),e}catch{return null}}var Ae=class{constructor(e,t,i="sessionStorage"){this.storage=Qr(i),this.id=e,this.config=t,this._loadConfiguration()}getConfiguration(){return this.config}setConfiguration(e){if(Object.assign(this.config,e),this.storage){let t=JSON.stringify(this.config);this.storage.setItem(this.id,t)}}_loadConfiguration(){let e={};if(this.storage){let t=this.storage.getItem(this.id);e=t?JSON.parse(t):{}}return Object.assign(this.config,e),this}};function jt(r){let e;return r<10?e=`${r.toFixed(2)}ms`:r<100?e=`${r.toFixed(1)}ms`:r<1e3?e=`${r.toFixed(0)}ms`:e=`${(r/1e3).toFixed(2)}s`,e}function Qt(r,e=8){let t=Math.max(e-r.length,0);return`${" ".repeat(t)}${r}`}var Ee;(function(r){r[r.BLACK=30]="BLACK",r[r.RED=31]="RED",r[r.GREEN=32]="GREEN",r[r.YELLOW=33]="YELLOW",r[r.BLUE=34]="BLUE",r[r.MAGENTA=35]="MAGENTA",r[r.CYAN=36]="CYAN",r[r.WHITE=37]="WHITE",r[r.BRIGHT_BLACK=90]="BRIGHT_BLACK",r[r.BRIGHT_RED=91]="BRIGHT_RED",r[r.BRIGHT_GREEN=92]="BRIGHT_GREEN",r[r.BRIGHT_YELLOW=93]="BRIGHT_YELLOW",r[r.BRIGHT_BLUE=94]="BRIGHT_BLUE",r[r.BRIGHT_MAGENTA=95]="BRIGHT_MAGENTA",r[r.BRIGHT_CYAN=96]="BRIGHT_CYAN",r[r.BRIGHT_WHITE=97]="BRIGHT_WHITE"})(Ee||(Ee={}));var Yr=10;function Yt(r){return typeof r!="string"?r:(r=r.toUpperCase(),Ee[r]||Ee.WHITE)}function Xt(r,e,t){return!v&&typeof r=="string"&&(e&&(r=`\x1B[${Yt(e)}m${r}\x1B[39m`),t&&(r=`\x1B[${Yt(t)+Yr}m${r}\x1B[49m`)),r}function qt(r,e=["constructor"]){let t=Object.getPrototypeOf(r),i=Object.getOwnPropertyNames(t),s=r;for(let n of i){let o=s[n];typeof o=="function"&&(e.find(a=>n===a)||(s[n]=o.bind(r)))}}function V(){let r;if(v()&&Se.performance)r=Se?.performance?.now?.();else if("hrtime"in Te){let e=Te?.hrtime?.();r=e[0]*1e3+e[1]/1e6}else r=Date.now();return r}var j={debug:v()&&console.debug||console.log,log:console.log,info:console.info,warn:console.warn,error:console.error},it={enabled:!0,level:0},E=class extends Ce{constructor({id:e}={id:""}){super({level:0}),this.VERSION=tt,this._startTs=V(),this._deltaTs=V(),this.userData={},this.LOG_THROTTLE_TIMEOUT=0,this.id=e,this.userData={},this._storage=new Ae(`__probe-${this.id}__`,{[this.id]:it}),this.timeStamp(`${this.id} started`),qt(this),Object.seal(this)}isEnabled(){return this._getConfiguration().enabled}getLevel(){return this._getConfiguration().level}getTotal(){return Number((V()-this._startTs).toPrecision(10))}getDelta(){return Number((V()-this._deltaTs).toPrecision(10))}set priority(e){this.level=e}get priority(){return this.level}getPriority(){return this.level}enable(e=!0){return this._updateConfiguration({enabled:e}),this}setLevel(e){return this._updateConfiguration({level:e}),this}get(e){return this._getConfiguration()[e]}set(e,t){this._updateConfiguration({[e]:t})}settings(){console.table?console.table(this._storage.config):console.log(this._storage.config)}assert(e,t){if(!e)throw new Error(t||"Assertion failed")}warn(e,...t){return this._log("warn",0,e,t,{method:j.warn,once:!0})}error(e,...t){return this._log("error",0,e,t,{method:j.error})}deprecated(e,t){return this.warn(`\`${e}\` is deprecated and will be removed in a later version. Use \`${t}\` instead`)}removed(e,t){return this.error(`\`${e}\` has been removed. Use \`${t}\` instead`)}probe(e,t,...i){return this._log("log",e,t,i,{method:j.log,time:!0,once:!0})}log(e,t,...i){return this._log("log",e,t,i,{method:j.debug})}info(e,t,...i){return this._log("info",e,t,i,{method:console.info})}once(e,t,...i){return this._log("once",e,t,i,{method:j.debug||j.info,once:!0})}table(e,t,i){return t?this._log("table",e,t,i&&[i]||[],{method:console.table||O,tag:qr(t)}):O}time(e,t){return this._log("time",e,t,[],{method:console.time?console.time:console.info})}timeEnd(e,t){return this._log("time",e,t,[],{method:console.timeEnd?console.timeEnd:console.info})}timeStamp(e,t){return this._log("time",e,t,[],{method:console.timeStamp||O})}group(e,t,i={collapsed:!1}){let s=(i.collapsed?console.groupCollapsed:console.group)||console.info;return this._log("group",e,t,[],{method:s})}groupCollapsed(e,t,i={}){return this.group(e,t,Object.assign({},i,{collapsed:!0}))}groupEnd(e){return this._log("groupEnd",e,"",[],{method:console.groupEnd||O})}withGroup(e,t,i){this.group(e,t)();try{i()}finally{this.groupEnd(e)()}}trace(){console.trace&&console.trace()}_shouldLog(e){return this.isEnabled()&&super._shouldLog(e)}_emit(e,t){let i=t.method;H(i),t.total=this.getTotal(),t.delta=this.getDelta(),this._deltaTs=V();let s=Xr(this.id,t.message,t);return i.bind(console,s,...t.args)}_getConfiguration(){return this._storage.config[this.id]||this._updateConfiguration(it),this._storage.config[this.id]}_updateConfiguration(e){let t=this._storage.config[this.id]||{...it};this._storage.setConfiguration({[this.id]:{...t,...e}})}};E.VERSION=tt;function Xr(r,e,t){if(typeof e=="string"){let i=t.time?Qt(jt(t.total)):"";e=t.time?`${r}: ${i} ${e}`:`${r}: ${e}`,e=Xt(e,t.color,t.background)}return e}function qr(r){for(let e in r)for(let t in r[e])return t||"untitled";return"empty"}globalThis.probe={};var rn=new E({id:"@probe.gl/log"});var d=new E({id:"luma.gl"});var st={};function P(r="id"){st[r]=st[r]||1;let e=st[r]++;return`${r}-${e}`}var Jr="cpu-hotspot-profiler",Jt="GPU Resource Counts",Kt="Resource Counts",Zt="GPU Time and Memory",Kr=["Resources","Buffers","Textures","Samplers","TextureViews","Framebuffers","QuerySets","Shaders","RenderPipelines","ComputePipelines","PipelineLayouts","VertexArrays","RenderPasss","ComputePasss","CommandEncoders","CommandBuffers"],Zr=["Resources","Buffers","Textures","Samplers","TextureViews","Framebuffers","QuerySets","Shaders","RenderPipelines","SharedRenderPipelines","ComputePipelines","PipelineLayouts","VertexArrays","RenderPasss","ComputePasss","CommandEncoders","CommandBuffers"],ei=Kr.flatMap(r=>[`${r} Created`,`${r} Active`]),ti=Zr.flatMap(r=>[`${r} Created`,`${r} Active`]),er=new WeakMap,tr=new WeakMap,l=class{toString(){return`${this[Symbol.toStringTag]||this.constructor.name}:"${this.id}"`}id;props;userData={};_device;destroyed=!1;allocatedBytes=0;allocatedBytesName=null;_attachedResources=new Set;constructor(e,t,i){if(!e)throw new Error("no device");this._device=e,this.props=ri(t,i);let s=this.props.id!=="undefined"?this.props.id:P(this[Symbol.toStringTag]);this.props.id=s,this.id=s,this.userData=this.props.userData||{},this.addStats()}destroy(){this.destroyed||this.destroyResource()}delete(){return this.destroy(),this}getProps(){return this.props}attachResource(e){this._attachedResources.add(e)}detachResource(e){this._attachedResources.delete(e)}destroyAttachedResource(e){this._attachedResources.delete(e)&&e.destroy()}destroyAttachedResources(){for(let e of this._attachedResources)e.destroy();this._attachedResources=new Set}destroyResource(){this.destroyed||(this.destroyAttachedResources(),this.removeStats(),this.destroyed=!0)}removeStats(){let e=ee(this._device),t=e?L():0,i=[this._device.statsManager.getStats(Jt),this._device.statsManager.getStats(Kt)],s=ir(this._device);for(let o of i)rr(o,s);let n=this.getStatsName();for(let o of i)o.get("Resources Active").decrementCount(),o.get(`${n}s Active`).decrementCount();e&&(e.statsBookkeepingCalls=(e.statsBookkeepingCalls||0)+1,e.statsBookkeepingTimeMs=(e.statsBookkeepingTimeMs||0)+(L()-t))}trackAllocatedMemory(e,t=this.getStatsName()){let i=ee(this._device),s=i?L():0,n=this._device.statsManager.getStats(Zt);this.allocatedBytes>0&&this.allocatedBytesName&&(n.get("GPU Memory").subtractCount(this.allocatedBytes),n.get(`${this.allocatedBytesName} Memory`).subtractCount(this.allocatedBytes)),n.get("GPU Memory").addCount(e),n.get(`${t} Memory`).addCount(e),i&&(i.statsBookkeepingCalls=(i.statsBookkeepingCalls||0)+1,i.statsBookkeepingTimeMs=(i.statsBookkeepingTimeMs||0)+(L()-s)),this.allocatedBytes=e,this.allocatedBytesName=t}trackReferencedMemory(e,t=this.getStatsName()){this.trackAllocatedMemory(e,`Referenced ${t}`)}trackDeallocatedMemory(e=this.getStatsName()){if(this.allocatedBytes===0){this.allocatedBytesName=null;return}let t=ee(this._device),i=t?L():0,s=this._device.statsManager.getStats(Zt);s.get("GPU Memory").subtractCount(this.allocatedBytes),s.get(`${this.allocatedBytesName||e} Memory`).subtractCount(this.allocatedBytes),t&&(t.statsBookkeepingCalls=(t.statsBookkeepingCalls||0)+1,t.statsBookkeepingTimeMs=(t.statsBookkeepingTimeMs||0)+(L()-i)),this.allocatedBytes=0,this.allocatedBytesName=null}trackDeallocatedReferencedMemory(e=this.getStatsName()){this.trackDeallocatedMemory(`Referenced ${e}`)}addStats(){let e=this.getStatsName(),t=ee(this._device),i=t?L():0,s=[this._device.statsManager.getStats(Jt),this._device.statsManager.getStats(Kt)],n=ir(this._device);for(let o of s)rr(o,n);for(let o of s)o.get("Resources Created").incrementCount(),o.get("Resources Active").incrementCount(),o.get(`${e}s Created`).incrementCount(),o.get(`${e}s Active`).incrementCount();t&&(t.statsBookkeepingCalls=(t.statsBookkeepingCalls||0)+1,t.statsBookkeepingTimeMs=(t.statsBookkeepingTimeMs||0)+(L()-i)),ii(this._device,e)}getStatsName(){return si(this)}};u(l,"defaultProps",{id:"undefined",handle:void 0,userData:void 0});function ri(r,e){let t={...e};for(let i in r)r[i]!==void 0&&(t[i]=r[i]);return t}function rr(r,e){let t=r.stats,i=!1;for(let c of e)t[c]||(r.get(c),i=!0);let s=Object.keys(t).length,n=er.get(r);if(!i&&n?.orderedStatNames===e&&n.statCount===s)return;let o={},a=tr.get(e);a||(a=new Set(e),tr.set(e,a));for(let c of e)t[c]&&(o[c]=t[c]);for(let[c,f]of Object.entries(t))a.has(c)||(o[c]=f);for(let c of Object.keys(t))delete t[c];Object.assign(t,o),er.set(r,{orderedStatNames:e,statCount:s})}function ir(r){return r.type==="webgl"?ti:ei}function ee(r){let e=r.userData[Jr];return e?.enabled?e:null}function L(){return globalThis.performance?.now?.()??Date.now()}function ii(r,e){let t=ee(r);if(!(!t||!t.activeDefaultFramebufferAcquireDepth))switch(t.transientCanvasResourceCreates=(t.transientCanvasResourceCreates||0)+1,e){case"Texture":t.transientCanvasTextureCreates=(t.transientCanvasTextureCreates||0)+1;break;case"TextureView":t.transientCanvasTextureViewCreates=(t.transientCanvasTextureViewCreates||0)+1;break;case"Sampler":t.transientCanvasSamplerCreates=(t.transientCanvasSamplerCreates||0)+1;break;case"Framebuffer":t.transientCanvasFramebufferCreates=(t.transientCanvasFramebufferCreates||0)+1;break;default:break}}function si(r){let e=Object.getPrototypeOf(r);for(;e;){let t=Object.getPrototypeOf(e);if(!t||t===l.prototype)return ni(e)||r[Symbol.toStringTag]||r.constructor.name;e=t}return r[Symbol.toStringTag]||r.constructor.name}function ni(r){let e=Object.getOwnPropertyDescriptor(r,Symbol.toStringTag);return typeof e?.get=="function"?e.get.call(r):typeof e?.value=="string"?e.value:null}var te=class extends l{get[Symbol.toStringTag](){return"Buffer"}usage;indexType;updateTimestamp;constructor(e,t){let i={...t};(t.usage||0)&te.INDEX&&!t.indexType&&(t.data instanceof Uint32Array?i.indexType="uint32":t.data instanceof Uint16Array?i.indexType="uint16":t.data instanceof Uint8Array&&(i.indexType="uint8")),delete i.data,super(e,i,te.defaultProps),this.usage=i.usage||0,this.indexType=i.indexType,this.updateTimestamp=e.incrementTimestamp()}clone(e){return this.device.createBuffer({...this.props,...e})}debugData=new ArrayBuffer(0);_setDebugData(e,t,i){let s=null,n;ArrayBuffer.isView(e)?(s=e,n=e.buffer):n=e;let o=Math.min(e?e.byteLength:i,te.DEBUG_DATA_MAX_LENGTH);if(n===null)this.debugData=new ArrayBuffer(o);else{let a=Math.min(s?.byteOffset||0,n.byteLength),c=Math.max(0,n.byteLength-a),f=Math.min(o,c);this.debugData=new Uint8Array(n,a,f).slice().buffer}}},p=te;u(p,"INDEX",16),u(p,"VERTEX",32),u(p,"UNIFORM",64),u(p,"STORAGE",128),u(p,"INDIRECT",256),u(p,"QUERY_RESOLVE",512),u(p,"MAP_READ",1),u(p,"MAP_WRITE",2),u(p,"COPY_SRC",4),u(p,"COPY_DST",8),u(p,"DEBUG_DATA_MAX_LENGTH",32),u(p,"defaultProps",{...l.defaultProps,usage:0,byteLength:0,byteOffset:0,data:null,indexType:"uint16",onMapped:void 0});var ot=class{getDataTypeInfo(e){let[t,i,s]=nt[e],n=e.includes("norm"),o=!n&&!e.startsWith("float"),a=e.startsWith("s");return{signedType:t,primitiveType:i,byteLength:s,normalized:n,integer:o,signed:a}}getNormalizedDataType(e){let t=e;switch(t){case"uint8":return"unorm8";case"sint8":return"snorm8";case"uint16":return"unorm16";case"sint16":return"snorm16";default:return t}}alignTo(e,t){switch(t){case 1:return e;case 2:return e+e%2;default:return e+(4-e%4)%4}}getDataType(e){let t=ArrayBuffer.isView(e)?e.constructor:e;if(t===Uint8ClampedArray)return"uint8";let i=Object.values(nt).find(s=>t===s[4]);if(!i)throw new Error(t.name);return i[0]}getTypedArrayConstructor(e){let[,,,,t]=nt[e];return t}},B=new ot,nt={uint8:["uint8","u32",1,!1,Uint8Array],sint8:["sint8","i32",1,!1,Int8Array],unorm8:["uint8","f32",1,!0,Uint8Array],snorm8:["sint8","f32",1,!0,Int8Array],uint16:["uint16","u32",2,!1,Uint16Array],sint16:["sint16","i32",2,!1,Int16Array],unorm16:["uint16","u32",2,!0,Uint16Array],snorm16:["sint16","i32",2,!0,Int16Array],float16:["float16","f16",2,!1,Uint16Array],float32:["float32","f32",4,!1,Float32Array],uint32:["uint32","u32",4,!1,Uint32Array],sint32:["sint32","i32",4,!1,Int32Array]};var at=class{getVertexFormatInfo(e){let t;e.endsWith("-webgl")&&(e.replace("-webgl",""),t=!0);let[i,s]=e.split("x"),n=i,o=s?parseInt(s):1,a=B.getDataTypeInfo(n),c={type:n,components:o,byteLength:a.byteLength*o,integer:a.integer,signed:a.signed,normalized:a.normalized};return t&&(c.webglOnly=!0),c}makeVertexFormat(e,t,i){let s=i?B.getNormalizedDataType(e):e;switch(s){case"unorm8":return t===1?"unorm8":t===3?"unorm8x3-webgl":`${s}x${t}`;case"snorm8":return t===1?"snorm8":t===3?"snorm8x3-webgl":`${s}x${t}`;case"uint8":case"sint8":if(t===1||t===3)throw new Error(`size: ${t}`);return`${s}x${t}`;case"uint16":return t===1?"uint16":t===3?"uint16x3-webgl":`${s}x${t}`;case"sint16":return t===1?"sint16":t===3?"sint16x3-webgl":`${s}x${t}`;case"unorm16":return t===1?"unorm16":t===3?"unorm16x3-webgl":`${s}x${t}`;case"snorm16":return t===1?"snorm16":t===3?"snorm16x3-webgl":`${s}x${t}`;case"float16":if(t===1||t===3)throw new Error(`size: ${t}`);return`${s}x${t}`;default:return t===1?s:`${s}x${t}`}}getVertexFormatFromAttribute(e,t,i){if(!t||t>4)throw new Error(`size ${t}`);let s=t,n=B.getDataType(e);return this.makeVertexFormat(n,s,i)}getCompatibleVertexFormat(e){let t;switch(e.primitiveType){case"f32":t="float32";break;case"i32":t="sint32";break;case"u32":t="uint32";break;case"f16":return e.components<=2?"float16x2":"float16x4"}return e.components===1?t:`${t}x${e.components}`}},M=new at;var y="texture-compression-bc",m="texture-compression-astc",S="texture-compression-etc2",oi="texture-compression-etc1-webgl",Re="texture-compression-pvrtc-webgl",ct="texture-compression-atc-webgl",Le="float32-renderable-webgl",ut="float16-renderable-webgl",ai="rgb9e5ufloat-renderable-webgl",lt="snorm8-renderable-webgl",D="norm16-webgl",ft="norm16-renderable-webgl",dt="snorm16-renderable-webgl",Be="float32-filterable",sr="float16-filterable-webgl";function re(r){let e=nr[r];if(!e)throw new Error(`Unsupported texture format ${r}`);return e}function Me(){return nr}var ci={r8unorm:{},rg8unorm:{},"rgb8unorm-webgl":{},rgba8unorm:{},"rgba8unorm-srgb":{},r8snorm:{render:lt},rg8snorm:{render:lt},"rgb8snorm-webgl":{},rgba8snorm:{render:lt},r8uint:{},rg8uint:{},rgba8uint:{},r8sint:{},rg8sint:{},rgba8sint:{},bgra8unorm:{},"bgra8unorm-srgb":{},r16unorm:{f:D,render:ft},rg16unorm:{f:D,render:ft},"rgb16unorm-webgl":{f:D,render:!1},rgba16unorm:{f:D,render:ft},r16snorm:{f:D,render:dt},rg16snorm:{f:D,render:dt},"rgb16snorm-webgl":{f:D,render:!1},rgba16snorm:{f:D,render:dt},r16uint:{},rg16uint:{},rgba16uint:{},r16sint:{},rg16sint:{},rgba16sint:{},r16float:{render:ut,filter:"float16-filterable-webgl"},rg16float:{render:ut,filter:sr},rgba16float:{render:ut,filter:sr},r32uint:{},rg32uint:{},rgba32uint:{},r32sint:{},rg32sint:{},rgba32sint:{},r32float:{render:Le,filter:Be},rg32float:{render:!1,filter:Be},"rgb32float-webgl":{render:Le,filter:Be},rgba32float:{render:Le,filter:Be},"rgba4unorm-webgl":{channels:"rgba",bitsPerChannel:[4,4,4,4],packed:!0},"rgb565unorm-webgl":{channels:"rgb",bitsPerChannel:[5,6,5,0],packed:!0},"rgb5a1unorm-webgl":{channels:"rgba",bitsPerChannel:[5,5,5,1],packed:!0},rgb9e5ufloat:{channels:"rgb",packed:!0,render:ai},rg11b10ufloat:{channels:"rgb",bitsPerChannel:[11,11,10,0],packed:!0,p:1,render:Le},rgb10a2unorm:{channels:"rgba",bitsPerChannel:[10,10,10,2],packed:!0,p:1},rgb10a2uint:{channels:"rgba",bitsPerChannel:[10,10,10,2],packed:!0,p:1},stencil8:{attachment:"stencil",bitsPerChannel:[8,0,0,0],dataType:"uint8"},depth16unorm:{attachment:"depth",bitsPerChannel:[16,0,0,0],dataType:"uint16"},depth24plus:{attachment:"depth",bitsPerChannel:[24,0,0,0],dataType:"uint32"},depth32float:{attachment:"depth",bitsPerChannel:[32,0,0,0],dataType:"float32"},"depth24plus-stencil8":{attachment:"depth-stencil",bitsPerChannel:[24,8,0,0],packed:!0},"depth32float-stencil8":{attachment:"depth-stencil",bitsPerChannel:[32,8,0,0],packed:!0}},ui={"bc1-rgb-unorm-webgl":{f:y},"bc1-rgb-unorm-srgb-webgl":{f:y},"bc1-rgba-unorm":{f:y},"bc1-rgba-unorm-srgb":{f:y},"bc2-rgba-unorm":{f:y},"bc2-rgba-unorm-srgb":{f:y},"bc3-rgba-unorm":{f:y},"bc3-rgba-unorm-srgb":{f:y},"bc4-r-unorm":{f:y},"bc4-r-snorm":{f:y},"bc5-rg-unorm":{f:y},"bc5-rg-snorm":{f:y},"bc6h-rgb-ufloat":{f:y},"bc6h-rgb-float":{f:y},"bc7-rgba-unorm":{f:y},"bc7-rgba-unorm-srgb":{f:y},"etc2-rgb8unorm":{f:S},"etc2-rgb8unorm-srgb":{f:S},"etc2-rgb8a1unorm":{f:S},"etc2-rgb8a1unorm-srgb":{f:S},"etc2-rgba8unorm":{f:S},"etc2-rgba8unorm-srgb":{f:S},"eac-r11unorm":{f:S},"eac-r11snorm":{f:S},"eac-rg11unorm":{f:S},"eac-rg11snorm":{f:S},"astc-4x4-unorm":{f:m},"astc-4x4-unorm-srgb":{f:m},"astc-5x4-unorm":{f:m},"astc-5x4-unorm-srgb":{f:m},"astc-5x5-unorm":{f:m},"astc-5x5-unorm-srgb":{f:m},"astc-6x5-unorm":{f:m},"astc-6x5-unorm-srgb":{f:m},"astc-6x6-unorm":{f:m},"astc-6x6-unorm-srgb":{f:m},"astc-8x5-unorm":{f:m},"astc-8x5-unorm-srgb":{f:m},"astc-8x6-unorm":{f:m},"astc-8x6-unorm-srgb":{f:m},"astc-8x8-unorm":{f:m},"astc-8x8-unorm-srgb":{f:m},"astc-10x5-unorm":{f:m},"astc-10x5-unorm-srgb":{f:m},"astc-10x6-unorm":{f:m},"astc-10x6-unorm-srgb":{f:m},"astc-10x8-unorm":{f:m},"astc-10x8-unorm-srgb":{f:m},"astc-10x10-unorm":{f:m},"astc-10x10-unorm-srgb":{f:m},"astc-12x10-unorm":{f:m},"astc-12x10-unorm-srgb":{f:m},"astc-12x12-unorm":{f:m},"astc-12x12-unorm-srgb":{f:m},"pvrtc-rgb4unorm-webgl":{f:Re},"pvrtc-rgba4unorm-webgl":{f:Re},"pvrtc-rgb2unorm-webgl":{f:Re},"pvrtc-rgba2unorm-webgl":{f:Re},"etc1-rbg-unorm-webgl":{f:oi},"atc-rgb-unorm-webgl":{f:ct},"atc-rgba-unorm-webgl":{f:ct},"atc-rgbai-unorm-webgl":{f:ct}},nr={...ci,...ui};var li=/^(r|rg|rgb|rgba|bgra)([0-9]*)([a-z]*)(-srgb)?(-webgl)?$/,fi=["rgb","rgba","bgra"],di=["depth","stencil"],hi=["bc1","bc2","bc3","bc4","bc5","bc6","bc7","etc1","etc2","eac","atc","astc","pvrtc"],ht=class{isColor(e){return fi.some(t=>e.startsWith(t))}isDepthStencil(e){return di.some(t=>e.startsWith(t))}isCompressed(e){return hi.some(t=>e.startsWith(t))}getInfo(e){return or(e)}getCapabilities(e){return pi(e)}computeMemoryLayout(e){return mi(e)}},x=new ht;function mi({format:r,width:e,height:t,depth:i,byteAlignment:s}){let n=x.getInfo(r),{bytesPerPixel:o,bytesPerBlock:a=o,blockWidth:c=1,blockHeight:f=1,compressed:h=!1}=n,b=h?Math.ceil(e/c):e,A=h?Math.ceil(t/f):t,Ze=b*a,_=Math.ceil(Ze/s)*s,q=A,J=_*q*i;return{bytesPerPixel:o,bytesPerRow:_,rowsPerImage:q,depthOrArrayLayers:i,bytesPerImage:_*q,byteLength:J}}function pi(r){let e=re(r),t={format:r,create:e.f??!0,render:e.render??!0,filter:e.filter??!0,blend:e.blend??!0,store:e.store??!0},i=or(r),s=r.startsWith("depth")||r.startsWith("stencil"),n=i?.signed,o=i?.integer,a=i?.webgl,c=Boolean(i?.compressed);return t.render&&=!s&&!c,t.filter&&=!s&&!n&&!o&&!a,t}function or(r){let e=gi(r);if(x.isCompressed(r)){e.channels="rgb",e.components=3,e.bytesPerPixel=1,e.srgb=!1,e.compressed=!0,e.bytesPerBlock=yi(r);let i=bi(r);i&&(e.blockWidth=i.blockWidth,e.blockHeight=i.blockHeight)}let t=e.packed?null:li.exec(r);if(t){let[,i,s,n,o,a]=t,c=`${n}${s}`,f=B.getDataTypeInfo(c),h=f.byteLength*8,b=i?.length??1,A=[h,b>=2?h:0,b>=3?h:0,b>=4?h:0];e={format:r,attachment:e.attachment,dataType:f.signedType,components:b,channels:i,integer:f.integer,signed:f.signed,normalized:f.normalized,bitsPerChannel:A,bytesPerPixel:f.byteLength*b,packed:e.packed,srgb:e.srgb},a==="-webgl"&&(e.webgl=!0),o==="-srgb"&&(e.srgb=!0)}return r.endsWith("-webgl")&&(e.webgl=!0),r.endsWith("-srgb")&&(e.srgb=!0),e}function gi(r){let e=re(r),t=e.bytesPerPixel||1,i=e.bitsPerChannel||[8,8,8,8];return delete e.bitsPerChannel,delete e.bytesPerPixel,delete e.f,delete e.render,delete e.filter,delete e.blend,delete e.store,{...e,format:r,attachment:e.attachment||"color",channels:e.channels||"r",components:e.components||e.channels?.length||1,bytesPerPixel:t,bitsPerChannel:i,dataType:e.dataType||"uint8",srgb:e.srgb??!1,packed:e.packed??!1,webgl:e.webgl??!1,integer:e.integer??!1,signed:e.signed??!1,normalized:e.normalized??!1,compressed:e.compressed??!1}}function bi(r){let t=/.*-(\d+)x(\d+)-.*/.exec(r);if(t){let[,i,s]=t;return{blockWidth:Number(i),blockHeight:Number(s)}}return r.startsWith("bc")||r.startsWith("etc1")||r.startsWith("etc2")||r.startsWith("eac")||r.startsWith("atc")?{blockWidth:4,blockHeight:4}:r.startsWith("pvrtc-rgb4")||r.startsWith("pvrtc-rgba4")?{blockWidth:4,blockHeight:4}:r.startsWith("pvrtc-rgb2")||r.startsWith("pvrtc-rgba2")?{blockWidth:8,blockHeight:4}:null}function yi(r){return r.startsWith("bc1")||r.startsWith("bc4")||r.startsWith("etc1")||r.startsWith("etc2-rgb8")||r.startsWith("etc2-rgb8a1")||r.startsWith("eac-r11")||r==="atc-rgb-unorm-webgl"?8:r.startsWith("bc2")||r.startsWith("bc3")||r.startsWith("bc5")||r.startsWith("bc6h")||r.startsWith("bc7")||r.startsWith("etc2-rgba8")||r.startsWith("eac-rg11")||r.startsWith("astc")||r==="atc-rgba-unorm-webgl"||r==="atc-rgbai-unorm-webgl"?16:r.startsWith("pvrtc")?8:16}function De(r){return typeof ImageData<"u"&&r instanceof ImageData||typeof ImageBitmap<"u"&&r instanceof ImageBitmap||typeof HTMLImageElement<"u"&&r instanceof HTMLImageElement||typeof HTMLVideoElement<"u"&&r instanceof HTMLVideoElement||typeof VideoFrame<"u"&&r instanceof VideoFrame||typeof HTMLCanvasElement<"u"&&r instanceof HTMLCanvasElement||typeof OffscreenCanvas<"u"&&r instanceof OffscreenCanvas}function $e(r){if(typeof ImageData<"u"&&r instanceof ImageData||typeof ImageBitmap<"u"&&r instanceof ImageBitmap||typeof HTMLCanvasElement<"u"&&r instanceof HTMLCanvasElement||typeof OffscreenCanvas<"u"&&r instanceof OffscreenCanvas)return{width:r.width,height:r.height};if(typeof HTMLImageElement<"u"&&r instanceof HTMLImageElement)return{width:r.naturalWidth,height:r.naturalHeight};if(typeof HTMLVideoElement<"u"&&r instanceof HTMLVideoElement)return{width:r.videoWidth,height:r.videoHeight};if(typeof VideoFrame<"u"&&r instanceof VideoFrame)return{width:r.displayWidth,height:r.displayHeight};throw new Error("Unknown image type")}var Ie=class{};function xi(r,e){let t=mt(r),i=e.map(mt).filter(s=>s!==void 0);return[t,...i].filter(s=>s!==void 0)}function mt(r){if(r!==void 0){if(r===null||typeof r=="string"||typeof r=="number"||typeof r=="boolean")return r;if(r instanceof Error)return r.message;if(Array.isArray(r))return r.map(mt);if(typeof r=="object"){if(wi(r)){let e=String(r);if(e!=="[object Object]")return e}return _i(r)?vi(r):r.constructor?.name||"Object"}return String(r)}}function wi(r){return"toString"in r&&typeof r.toString=="function"&&r.toString!==Object.prototype.toString}function _i(r){return"message"in r&&"type"in r}function vi(r){let e=typeof r.type=="string"?r.type:"message",t=typeof r.message=="string"?r.message:"",i=typeof r.lineNum=="number"?r.lineNum:null,s=typeof r.linePos=="number"?r.linePos:null,n=i!==null&&s!==null?` @ ${i}:${s}`:i!==null?` @ ${i}`:"";return`${e}${n}: ${t}`.trim()}var ke=class{features;disabledFeatures;constructor(e=[],t){this.features=new Set(e),this.disabledFeatures=t||{}}*[Symbol.iterator](){yield*this.features}has(e){return!this.disabledFeatures?.[e]&&this.features.has(e)}},pt=class{get[Symbol.toStringTag](){return"Device"}toString(){return`Device(${this.id})`}id;props;userData={};statsManager=Pe;_factories={};timestamp=0;_reused=!1;_moduleData={};_textureCaps={};_debugGPUTimeQuery=null;constructor(e){this.props={...pt.defaultProps,...e},this.id=this.props.id||P(this[Symbol.toStringTag].toLowerCase())}getVertexFormatInfo(e){return M.getVertexFormatInfo(e)}isVertexFormatSupported(e){return!0}getTextureFormatInfo(e){return x.getInfo(e)}getTextureFormatCapabilities(e){let t=this._textureCaps[e];if(!t){let i=this._getDeviceTextureFormatCapabilities(e);t=this._getDeviceSpecificTextureFormatCapabilities(i),this._textureCaps[e]=t}return t}getMipLevelCount(e,t,i=1){let s=Math.max(e,t,i);return 1+Math.floor(Math.log2(s))}isExternalImage(e){return De(e)}getExternalImageSize(e){return $e(e)}isTextureFormatSupported(e){return this.getTextureFormatCapabilities(e).create}isTextureFormatFilterable(e){return this.getTextureFormatCapabilities(e).filter}isTextureFormatRenderable(e){return this.getTextureFormatCapabilities(e).render}isTextureFormatCompressed(e){return x.isCompressed(e)}getSupportedCompressedTextureFormats(){let e=[];for(let t of Object.keys(Me()))this.isTextureFormatCompressed(t)&&this.isTextureFormatSupported(t)&&e.push(t);return e}pushDebugGroup(e){this.commandEncoder.pushDebugGroup(e)}popDebugGroup(){this.commandEncoder?.popDebugGroup()}insertDebugMarker(e){this.commandEncoder?.insertDebugMarker(e)}loseDevice(){return!1}incrementTimestamp(){return this.timestamp++}reportError(e,t,...i){if(!this.props.onError(e,t)){let n=xi(t,i);return d.error(this.type==="webgl"?"%cWebGL":"%cWebGPU","color: white; background: red; padding: 2px 6px; border-radius: 3px;",e.message,...n)}return()=>{}}debug(){if(this.props.debug)debugger;else{let e=`'Type luma.log.set({debug: true}) in console to enable debug breakpoints',
8
+ or create a device with the 'debug: true' prop.`;d.once(0,e)()}}getDefaultCanvasContext(){if(!this.canvasContext)throw new Error("Device has no default CanvasContext. See props.createCanvasContext");return this.canvasContext}createFence(){throw new Error("createFence() not implemented")}beginRenderPass(e){return this.commandEncoder.beginRenderPass(e)}beginComputePass(e){return this.commandEncoder.beginComputePass(e)}generateMipmapsWebGPU(e){throw new Error("not implemented")}_createSharedRenderPipelineWebGL(e){throw new Error("_createSharedRenderPipelineWebGL() not implemented")}_createBindGroupLayoutWebGPU(e,t){throw new Error("_createBindGroupLayoutWebGPU() not implemented")}_createBindGroupWebGPU(e,t,i,s,n){throw new Error("_createBindGroupWebGPU() not implemented")}_supportsDebugGPUTime(){return this.features.has("timestamp-query")&&Boolean(this.props.debug||this.props.debugGPUTime)}_enableDebugGPUTime(e=256){if(!this._supportsDebugGPUTime())return null;if(this._debugGPUTimeQuery)return this._debugGPUTimeQuery;try{this._debugGPUTimeQuery=this.createQuerySet({type:"timestamp",count:e}),this.commandEncoder=this.createCommandEncoder({id:this.commandEncoder.props.id,timeProfilingQuerySet:this._debugGPUTimeQuery})}catch{this._debugGPUTimeQuery=null}return this._debugGPUTimeQuery}_disableDebugGPUTime(){this._debugGPUTimeQuery&&(this.commandEncoder.getTimeProfilingQuerySet()===this._debugGPUTimeQuery&&(this.commandEncoder=this.createCommandEncoder({id:this.commandEncoder.props.id})),this._debugGPUTimeQuery.destroy(),this._debugGPUTimeQuery=null)}_isDebugGPUTimeEnabled(){return this._debugGPUTimeQuery!==null}getCanvasContext(){return this.getDefaultCanvasContext()}readPixelsToArrayWebGL(e,t){throw new Error("not implemented")}readPixelsToBufferWebGL(e,t){throw new Error("not implemented")}setParametersWebGL(e){throw new Error("not implemented")}getParametersWebGL(e){throw new Error("not implemented")}withParametersWebGL(e,t){throw new Error("not implemented")}clearWebGL(e){throw new Error("not implemented")}resetWebGL(){throw new Error("not implemented")}getModuleData(e){return this._moduleData[e]||={},this._moduleData[e]}static _getCanvasContextProps(e){return e.createCanvasContext===!0?{}:e.createCanvasContext}_getDeviceTextureFormatCapabilities(e){let t=x.getCapabilities(e),i=n=>(typeof n=="string"?this.features.has(n):n)??!0,s=i(t.create);return{format:e,create:s,render:s&&i(t.render),filter:s&&i(t.filter),blend:s&&i(t.blend),store:s&&i(t.store)}}_normalizeBufferProps(e){(e instanceof ArrayBuffer||ArrayBuffer.isView(e))&&(e={data:e});let t={...e};if((e.usage||0)&p.INDEX&&(e.indexType||(e.data instanceof Uint32Array?t.indexType="uint32":e.data instanceof Uint16Array?t.indexType="uint16":e.data instanceof Uint8Array&&(t.data=new Uint16Array(e.data),t.indexType="uint16")),!t.indexType))throw new Error("indices buffer content must be of type uint16 or uint32");return t}},G=pt;u(G,"defaultProps",{id:null,powerPreference:"high-performance",failIfMajorPerformanceCaveat:!1,createCanvasContext:void 0,webgl:{},onError:(e,t)=>{},onResize:(e,t)=>{let[i,s]=e.getDevicePixelSize();d.log(1,`${e} resized => ${i}x${s}px`)()},onPositionChange:(e,t)=>{let[i,s]=e.getPosition();d.log(1,`${e} repositioned => ${i},${s}`)()},onVisibilityChange:e=>d.log(1,`${e} Visibility changed ${e.isVisible}`)(),onDevicePixelRatioChange:(e,t)=>d.log(1,`${e} DPR changed ${t.oldRatio} => ${e.devicePixelRatio}`)(),debug:Si(),debugGPUTime:!1,debugShaders:d.get("debug-shaders")||void 0,debugFramebuffers:Boolean(d.get("debug-framebuffers")),debugFactories:Boolean(d.get("debug-factories")),debugWebGL:Boolean(d.get("debug-webgl")),debugSpectorJS:void 0,debugSpectorJSUrl:void 0,_reuseDevices:!1,_requestMaxLimits:!0,_cacheShaders:!0,_destroyShaders:!1,_cachePipelines:!0,_sharePipelines:!0,_destroyPipelines:!1,_initializeFeatures:!0,_disabledFeatures:{"compilation-status-async-webgl":!0},_handle:void 0});function Pi(r,e){return r!=null?Boolean(r):e!==void 0?e!=="production":!1}function Si(){return Pi(d.get("debug"),Ti())}function Ti(){let r=globalThis.process;if(r?.env)return r.env.NODE_ENV}var Ci="set luma.log.level=1 (or higher) to trace rendering",ar="No matching device found. Ensure `@luma.gl/webgl` and/or `@luma.gl/webgpu` modules are imported.",Oe=class{stats=Pe;log=d;VERSION="9.3.0-alpha.11";spector;preregisteredAdapters=new Map;constructor(){if(globalThis.luma){if(globalThis.luma.VERSION!==this.VERSION)throw d.error(`Found luma.gl ${globalThis.luma.VERSION} while initialzing ${this.VERSION}`)(),d.error("'yarn why @luma.gl/core' can help identify the source of the conflict")(),new Error("luma.gl - multiple versions detected: see console log");d.error("This version of luma.gl has already been initialized")()}d.log(1,`${this.VERSION} - ${Ci}`)(),globalThis.luma=this}async createDevice(e={}){let t={...Oe.defaultProps,...e},i=this.selectAdapter(t.type,t.adapters);if(!i)throw new Error(ar);return t.waitForPageLoad&&await i.pageLoaded,await i.create(t)}async attachDevice(e,t){let i=this._getTypeFromHandle(e,t.adapters),s=i&&this.selectAdapter(i,t.adapters);if(!s)throw new Error(ar);return await s?.attach?.(e,t)}registerAdapters(e){for(let t of e)this.preregisteredAdapters.set(t.type,t)}getSupportedAdapters(e=[]){let t=this._getAdapterMap(e);return Array.from(t).map(([,i])=>i).filter(i=>i.isSupported?.()).map(i=>i.type)}getBestAvailableAdapterType(e=[]){let t=["webgpu","webgl","null"],i=this._getAdapterMap(e);for(let s of t)if(i.get(s)?.isSupported?.())return s;return null}selectAdapter(e,t=[]){let i=e;e==="best-available"&&(i=this.getBestAvailableAdapterType(t));let s=this._getAdapterMap(t);return i&&s.get(i)||null}enforceWebGL2(e=!0,t=[]){let s=this._getAdapterMap(t).get("webgl");s||d.warn("enforceWebGL2: webgl adapter not found")(),s?.enforceWebGL2?.(e)}setDefaultDeviceProps(e){Object.assign(Oe.defaultProps,e)}_getAdapterMap(e=[]){let t=new Map(this.preregisteredAdapters);for(let i of e)t.set(i.type,i);return t}_getTypeFromHandle(e,t=[]){return e instanceof WebGL2RenderingContext?"webgl":typeof GPUDevice<"u"&&e instanceof GPUDevice||e?.queue?"webgpu":e===null?"null":(e instanceof WebGLRenderingContext?d.warn("WebGL1 is not supported",e)():d.warn("Unknown handle type",e)(),null)}},Ue=Oe;u(Ue,"defaultProps",{...G.defaultProps,type:"best-available",adapters:void 0,waitForPageLoad:!0});var cr=new Ue;var Fe=class{get pageLoaded(){return Ri()}},Ai=v()&&typeof document<"u",Ei=()=>Ai&&document.readyState==="complete",Ge=null;function Ri(){return Ge||(Ei()||typeof window>"u"?Ge=Promise.resolve():Ge=new Promise(r=>window.addEventListener("load",()=>r()))),Ge}var We=class{props;_resizeObserver;_intersectionObserver;_observeDevicePixelRatioTimeout=null;_observeDevicePixelRatioMediaQuery=null;_handleDevicePixelRatioChange=()=>this._refreshDevicePixelRatio();_trackPositionInterval=null;_started=!1;get started(){return this._started}constructor(e){this.props=e}start(){if(!(this._started||!this.props.canvas)){this._started=!0,this._intersectionObserver||=new IntersectionObserver(e=>this.props.onIntersection(e)),this._resizeObserver||=new ResizeObserver(e=>this.props.onResize(e)),this._intersectionObserver.observe(this.props.canvas);try{this._resizeObserver.observe(this.props.canvas,{box:"device-pixel-content-box"})}catch{this._resizeObserver.observe(this.props.canvas,{box:"content-box"})}this._observeDevicePixelRatioTimeout=setTimeout(()=>this._refreshDevicePixelRatio(),0),this.props.trackPosition&&this._trackPosition()}}stop(){this._started&&(this._started=!1,this._observeDevicePixelRatioTimeout&&(clearTimeout(this._observeDevicePixelRatioTimeout),this._observeDevicePixelRatioTimeout=null),this._observeDevicePixelRatioMediaQuery&&(this._observeDevicePixelRatioMediaQuery.removeEventListener("change",this._handleDevicePixelRatioChange),this._observeDevicePixelRatioMediaQuery=null),this._trackPositionInterval&&(clearInterval(this._trackPositionInterval),this._trackPositionInterval=null),this._resizeObserver?.disconnect(),this._intersectionObserver?.disconnect())}_refreshDevicePixelRatio(){this._started&&(this.props.onDevicePixelRatioChange(),this._observeDevicePixelRatioMediaQuery?.removeEventListener("change",this._handleDevicePixelRatioChange),this._observeDevicePixelRatioMediaQuery=matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`),this._observeDevicePixelRatioMediaQuery.addEventListener("change",this._handleDevicePixelRatioChange,{once:!0}))}_trackPosition(e=100){this._trackPositionInterval||(this._trackPositionInterval=setInterval(()=>{this._started?this.props.onPositionChange():this._trackPositionInterval&&(clearInterval(this._trackPositionInterval),this._trackPositionInterval=null)},e))}};function ur(){let r,e;return{promise:new Promise((i,s)=>{r=i,e=s}),resolve:r,reject:e}}function ze(r,e){if(!r){let t=new Error(e??"luma.gl assertion failed.");throw Error.captureStackTrace?.(t,ze),t}}function Ne(r,e){return ze(r,e),r}var ie=class{static isHTMLCanvas(e){return typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement}static isOffscreenCanvas(e){return typeof OffscreenCanvas<"u"&&e instanceof OffscreenCanvas}id;props;canvas;htmlCanvas;offscreenCanvas;type;initialized;isInitialized=!1;isVisible=!0;cssWidth;cssHeight;devicePixelRatio;devicePixelWidth;devicePixelHeight;drawingBufferWidth;drawingBufferHeight;_initializedResolvers=ur();_canvasObserver;_position=[0,0];destroyed=!1;_needsDrawingBufferResize=!0;toString(){return`${this[Symbol.toStringTag]}(${this.id})`}constructor(e){this.props={...ie.defaultProps,...e},e=this.props,this.initialized=this._initializedResolvers.promise,v()?e.canvas?typeof e.canvas=="string"?this.canvas=Bi(e.canvas):this.canvas=e.canvas:this.canvas=Mi(e):this.canvas={width:e.width||1,height:e.height||1},ie.isHTMLCanvas(this.canvas)?(this.id=e.id||this.canvas.id,this.type="html-canvas",this.htmlCanvas=this.canvas):ie.isOffscreenCanvas(this.canvas)?(this.id=e.id||"offscreen-canvas",this.type="offscreen-canvas",this.offscreenCanvas=this.canvas):(this.id=e.id||"node-canvas-context",this.type="node"),this.cssWidth=this.htmlCanvas?.clientWidth||this.canvas.width,this.cssHeight=this.htmlCanvas?.clientHeight||this.canvas.height,this.devicePixelWidth=this.canvas.width,this.devicePixelHeight=this.canvas.height,this.drawingBufferWidth=this.canvas.width,this.drawingBufferHeight=this.canvas.height,this.devicePixelRatio=globalThis.devicePixelRatio||1,this._position=[0,0],this._canvasObserver=new We({canvas:this.htmlCanvas,trackPosition:this.props.trackPosition,onResize:t=>this._handleResize(t),onIntersection:t=>this._handleIntersection(t),onDevicePixelRatioChange:()=>this._observeDevicePixelRatio(),onPositionChange:()=>this.updatePosition()})}destroy(){this.destroyed||(this.destroyed=!0,this._stopObservers(),this.device=null)}setProps(e){return"useDevicePixels"in e&&(this.props.useDevicePixels=e.useDevicePixels||!1,this._updateDrawingBufferSize()),this}getCurrentFramebuffer(e){return this._resizeDrawingBufferIfNeeded(),this._getCurrentFramebuffer(e)}getCSSSize(){return[this.cssWidth,this.cssHeight]}getPosition(){return this._position}getDevicePixelSize(){return[this.devicePixelWidth,this.devicePixelHeight]}getDrawingBufferSize(){return[this.drawingBufferWidth,this.drawingBufferHeight]}getMaxDrawingBufferSize(){let e=this.device.limits.maxTextureDimension2D;return[e,e]}setDrawingBufferSize(e,t){e=Math.floor(e),t=Math.floor(t),!(this.drawingBufferWidth===e&&this.drawingBufferHeight===t)&&(this.drawingBufferWidth=e,this.drawingBufferHeight=t,this._needsDrawingBufferResize=!0)}getDevicePixelRatio(){return typeof window<"u"&&window.devicePixelRatio||1}cssToDevicePixels(e,t=!0){let i=this.cssToDeviceRatio(),[s,n]=this.getDrawingBufferSize();return Di(e,i,s,n,t)}getPixelSize(){return this.getDevicePixelSize()}getAspect(){let[e,t]=this.getDrawingBufferSize();return e>0&&t>0?e/t:1}cssToDeviceRatio(){try{let[e]=this.getDrawingBufferSize(),[t]=this.getCSSSize();return t?e/t:1}catch{return 1}}resize(e){this.setDrawingBufferSize(e.width,e.height)}_setAutoCreatedCanvasId(e){this.htmlCanvas?.id==="lumagl-auto-created-canvas"&&(this.htmlCanvas.id=e)}_startObservers(){this.destroyed||this._canvasObserver.start()}_stopObservers(){this._canvasObserver.stop()}_handleIntersection(e){if(this.destroyed)return;let t=e.find(s=>s.target===this.canvas);if(!t)return;let i=t.isIntersecting;this.isVisible!==i&&(this.isVisible=i,this.device.props.onVisibilityChange(this))}_handleResize(e){if(this.destroyed)return;let t=e.find(f=>f.target===this.canvas);if(!t)return;let i=Ne(t.contentBoxSize?.[0]);this.cssWidth=i.inlineSize,this.cssHeight=i.blockSize;let s=this.getDevicePixelSize(),n=t.devicePixelContentBoxSize?.[0]?.inlineSize||i.inlineSize*devicePixelRatio,o=t.devicePixelContentBoxSize?.[0]?.blockSize||i.blockSize*devicePixelRatio,[a,c]=this.getMaxDrawingBufferSize();this.devicePixelWidth=Math.max(1,Math.min(n,a)),this.devicePixelHeight=Math.max(1,Math.min(o,c)),this._updateDrawingBufferSize(),this.device.props.onResize(this,{oldPixelSize:s})}_updateDrawingBufferSize(){if(this.props.autoResize)if(typeof this.props.useDevicePixels=="number"){let e=this.props.useDevicePixels;this.setDrawingBufferSize(this.cssWidth*e,this.cssHeight*e)}else this.props.useDevicePixels?this.setDrawingBufferSize(this.devicePixelWidth,this.devicePixelHeight):this.setDrawingBufferSize(this.cssWidth,this.cssHeight);this._initializedResolvers.resolve(),this.isInitialized=!0,this.updatePosition()}_resizeDrawingBufferIfNeeded(){this._needsDrawingBufferResize&&(this._needsDrawingBufferResize=!1,(this.drawingBufferWidth!==this.canvas.width||this.drawingBufferHeight!==this.canvas.height)&&(this.canvas.width=this.drawingBufferWidth,this.canvas.height=this.drawingBufferHeight,this._configureDevice()))}_observeDevicePixelRatio(){if(this.destroyed||!this._canvasObserver.started)return;let e=this.devicePixelRatio;this.devicePixelRatio=window.devicePixelRatio,this.updatePosition(),this.device.props.onDevicePixelRatioChange?.(this,{oldRatio:e})}updatePosition(){if(this.destroyed)return;let e=this.htmlCanvas?.getBoundingClientRect();if(e){let t=[e.left,e.top];if(this._position??=t,t[0]!==this._position[0]||t[1]!==this._position[1]){let s=this._position;this._position=t,this.device.props.onPositionChange?.(this,{oldPosition:s})}}}},R=ie;u(R,"defaultProps",{id:void 0,canvas:null,width:800,height:600,useDevicePixels:!0,autoResize:!0,container:null,visible:!0,alphaMode:"opaque",colorSpace:"srgb",trackPosition:!1});function Li(r){if(typeof r=="string"){let e=document.getElementById(r);if(!e)throw new Error(`${r} is not an HTML element`);return e}return r||document.body}function Bi(r){let e=document.getElementById(r);if(!R.isHTMLCanvas(e))throw new Error("Object is not a canvas element");return e}function Mi(r){let{width:e,height:t}=r,i=document.createElement("canvas");i.id=P("lumagl-auto-created-canvas"),i.width=e||1,i.height=t||1,i.style.width=Number.isFinite(e)?`${e}px`:"100%",i.style.height=Number.isFinite(t)?`${t}px`:"100%",r?.visible||(i.style.visibility="hidden");let s=Li(r?.container||null);return s.insertBefore(i,s.firstChild),i}function Di(r,e,t,i,s){let n=r,o=lr(n[0],e,t),a=fr(n[1],e,i,s),c=lr(n[0]+1,e,t),f=c===t-1?c:c-1;c=fr(n[1]+1,e,i,s);let h;return s?(c=c===0?c:c+1,h=a,a=c):h=c===i-1?c:c-1,{x:o,y:a,width:Math.max(f-o+1,1),height:Math.max(h-a+1,1)}}function lr(r,e,t){return Math.min(Math.round(r*e),t-1)}function fr(r,e,t,i){return i?Math.max(0,t-1-Math.round(r*e)):Math.min(Math.round(r*e),t-1)}var se=class extends R{};u(se,"defaultProps",R.defaultProps);var He=class extends R{};var Ve=class extends l{get[Symbol.toStringTag](){return"Sampler"}constructor(e,t){t=Ve.normalizeProps(e,t),super(e,t,Ve.defaultProps)}static normalizeProps(e,t){return t}},F=Ve;u(F,"defaultProps",{...l.defaultProps,type:"color-sampler",addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge",addressModeW:"clamp-to-edge",magFilter:"nearest",minFilter:"nearest",mipmapFilter:"none",lodMinClamp:0,lodMaxClamp:32,compare:"less-equal",maxAnisotropy:1});var $i={"1d":"1d","2d":"2d","2d-array":"2d",cube:"2d","cube-array":"2d","3d":"3d"},w=class extends l{dimension;baseDimension;format;width;height;depth;mipLevels;samples;byteAlignment;ready=Promise.resolve(this);isReady=!0;updateTimestamp;get[Symbol.toStringTag](){return"Texture"}toString(){return`Texture(${this.id},${this.format},${this.width}x${this.height})`}constructor(e,t,i){if(t=w.normalizeProps(e,t),super(e,t,w.defaultProps),this.dimension=this.props.dimension,this.baseDimension=$i[this.dimension],this.format=this.props.format,this.width=this.props.width,this.height=this.props.height,this.depth=this.props.depth,this.mipLevels=this.props.mipLevels,this.samples=this.props.samples||1,this.dimension==="cube"&&(this.depth=6),this.props.width===void 0||this.props.height===void 0)if(e.isExternalImage(t.data)){let s=e.getExternalImageSize(t.data);this.width=s?.width||1,this.height=s?.height||1}else this.width=1,this.height=1,(this.props.width===void 0||this.props.height===void 0)&&d.warn(`${this} created with undefined width or height. This is deprecated. Use DynamicTexture instead.`)();this.byteAlignment=i?.byteAlignment||1,this.updateTimestamp=e.incrementTimestamp()}clone(e){return this.device.createTexture({...this.props,...e})}setSampler(e){this.sampler=e instanceof F?e:this.device.createSampler(e)}copyImageData(e){let{data:t,depth:i,...s}=e;this.writeData(t,{...s,depthOrArrayLayers:s.depthOrArrayLayers??i})}computeMemoryLayout(e={}){let t=this._normalizeTextureReadOptions(e),{width:i=this.width,height:s=this.height,depthOrArrayLayers:n=this.depth}=t,{format:o,byteAlignment:a}=this;return x.computeMemoryLayout({format:o,width:i,height:s,depth:n,byteAlignment:a})}readBuffer(e,t){throw new Error("readBuffer not implemented")}readDataAsync(e){throw new Error("readBuffer not implemented")}writeBuffer(e,t){throw new Error("readBuffer not implemented")}writeData(e,t){throw new Error("readBuffer not implemented")}readDataSyncWebGL(e){throw new Error("readDataSyncWebGL not available")}generateMipmapsWebGL(){throw new Error("generateMipmapsWebGL not available")}static normalizeProps(e,t){let i={...t},{width:s,height:n}=i;return typeof s=="number"&&(i.width=Math.max(1,Math.ceil(s))),typeof n=="number"&&(i.height=Math.max(1,Math.ceil(n))),i}_initializeData(e){this.device.isExternalImage(e)?this.copyExternalImage({image:e,width:this.width,height:this.height,depth:this.depth,mipLevel:0,x:0,y:0,z:0,aspect:"all",colorSpace:"srgb",premultipliedAlpha:!1,flipY:!1}):e&&this.copyImageData({data:e,mipLevel:0,x:0,y:0,z:0,aspect:"all"})}_normalizeCopyImageDataOptions(e){let{data:t,depth:i,...s}=e,n=this._normalizeTextureWriteOptions({...s,depthOrArrayLayers:s.depthOrArrayLayers??i});return{data:t,depth:n.depthOrArrayLayers,...n}}_normalizeCopyExternalImageOptions(e){let t=w._omitUndefined(e),i=t.mipLevel??0,s=this._getMipLevelSize(i),n=this.device.getExternalImageSize(e.image),o={...w.defaultCopyExternalImageOptions,...s,...n,...t};return o.width=Math.min(o.width,s.width-o.x),o.height=Math.min(o.height,s.height-o.y),o.depth=Math.min(o.depth,s.depthOrArrayLayers-o.z),o}_normalizeTextureReadOptions(e){let t=w._omitUndefined(e),i=t.mipLevel??0,s=this._getMipLevelSize(i),n={...w.defaultTextureReadOptions,...s,...t};return n.width=Math.min(n.width,s.width-n.x),n.height=Math.min(n.height,s.height-n.y),n.depthOrArrayLayers=Math.min(n.depthOrArrayLayers,s.depthOrArrayLayers-n.z),n}_getSupportedColorReadOptions(e){let t=this._normalizeTextureReadOptions(e),i=x.getInfo(this.format);switch(this._validateColorReadAspect(t),this._validateColorReadFormat(i),this.dimension){case"2d":case"cube":case"cube-array":case"2d-array":case"3d":return t;default:throw new Error(`${this} color readback does not support ${this.dimension} textures`)}}_validateColorReadAspect(e){if(e.aspect!=="all")throw new Error(`${this} color readback only supports aspect 'all'`)}_validateColorReadFormat(e){if(e.compressed)throw new Error(`${this} color readback does not support compressed formats (${this.format})`);switch(e.attachment){case"color":return;case"depth":throw new Error(`${this} color readback does not support depth formats (${this.format})`);case"stencil":throw new Error(`${this} color readback does not support stencil formats (${this.format})`);case"depth-stencil":throw new Error(`${this} color readback does not support depth-stencil formats (${this.format})`);default:throw new Error(`${this} color readback does not support format ${this.format}`)}}_normalizeTextureWriteOptions(e){let t=w._omitUndefined(e),i=t.mipLevel??0,s=this._getMipLevelSize(i),n={...w.defaultTextureWriteOptions,...s,...t};n.width=Math.min(n.width,s.width-n.x),n.height=Math.min(n.height,s.height-n.y),n.depthOrArrayLayers=Math.min(n.depthOrArrayLayers,s.depthOrArrayLayers-n.z);let o=x.computeMemoryLayout({format:this.format,width:n.width,height:n.height,depth:n.depthOrArrayLayers,byteAlignment:this.byteAlignment}),a=o.bytesPerPixel*n.width;if(n.bytesPerRow=t.bytesPerRow??o.bytesPerRow,n.rowsPerImage=t.rowsPerImage??n.height,n.bytesPerRow<a)throw new Error(`bytesPerRow (${n.bytesPerRow}) must be at least ${a} for ${this.format}`);if(n.rowsPerImage<n.height)throw new Error(`rowsPerImage (${n.rowsPerImage}) must be at least ${n.height} for ${this.format}`);let c=this.device.getTextureFormatInfo(this.format).bytesPerPixel;if(c&&n.bytesPerRow%c!==0)throw new Error(`bytesPerRow (${n.bytesPerRow}) must be a multiple of bytesPerPixel (${c}) for ${this.format}`);return n}_getMipLevelSize(e){let t=Math.max(1,this.width>>e),i=this.baseDimension==="1d"?1:Math.max(1,this.height>>e),s=this.dimension==="3d"?Math.max(1,this.depth>>e):this.depth;return{width:t,height:i,depthOrArrayLayers:s}}getAllocatedByteLength(){let e=0;for(let t=0;t<this.mipLevels;t++){let{width:i,height:s,depthOrArrayLayers:n}=this._getMipLevelSize(t);e+=x.computeMemoryLayout({format:this.format,width:i,height:s,depth:n,byteAlignment:1}).byteLength}return e*this.samples}static _omitUndefined(e){return Object.fromEntries(Object.entries(e).filter(([,t])=>t!==void 0))}},g=w;u(g,"SAMPLE",4),u(g,"STORAGE",8),u(g,"RENDER",16),u(g,"COPY_SRC",1),u(g,"COPY_DST",2),u(g,"TEXTURE",4),u(g,"RENDER_ATTACHMENT",16),u(g,"defaultProps",{...l.defaultProps,data:null,dimension:"2d",format:"rgba8unorm",usage:w.SAMPLE|w.RENDER|w.COPY_DST,width:void 0,height:void 0,depth:1,mipLevels:1,samples:void 0,sampler:{},view:void 0}),u(g,"defaultCopyDataOptions",{data:void 0,byteOffset:0,bytesPerRow:void 0,rowsPerImage:void 0,width:void 0,height:void 0,depthOrArrayLayers:void 0,depth:1,mipLevel:0,x:0,y:0,z:0,aspect:"all"}),u(g,"defaultCopyExternalImageOptions",{image:void 0,sourceX:0,sourceY:0,width:void 0,height:void 0,depth:1,mipLevel:0,x:0,y:0,z:0,aspect:"all",colorSpace:"srgb",premultipliedAlpha:!1,flipY:!1}),u(g,"defaultTextureReadOptions",{x:0,y:0,z:0,width:void 0,height:void 0,depthOrArrayLayers:1,mipLevel:0,aspect:"all"}),u(g,"defaultTextureWriteOptions",{byteOffset:0,bytesPerRow:void 0,rowsPerImage:void 0,x:0,y:0,z:0,width:void 0,height:void 0,depthOrArrayLayers:1,mipLevel:0,aspect:"all"});var gt=class extends l{get[Symbol.toStringTag](){return"TextureView"}constructor(e,t){super(e,t,gt.defaultProps)}},ne=gt;u(ne,"defaultProps",{...l.defaultProps,format:void 0,dimension:void 0,aspect:"all",baseMipLevel:0,mipLevelCount:void 0,baseArrayLayer:0,arrayLayerCount:void 0});var bt=class extends l{get[Symbol.toStringTag](){return"ExternalTexture"}constructor(e,t){super(e,t,bt.defaultProps)}},oe=bt;u(oe,"defaultProps",{...l.defaultProps,source:void 0,colorSpace:"srgb"});function dr(r,e,t){let i="",s=e.split(/\r?\n/),n=r.slice().sort((o,a)=>o.lineNum-a.lineNum);switch(t?.showSourceCode||"no"){case"all":let o=0;for(let a=1;a<=s.length;a++){let c=s[a-1],f=n[o];for(c&&f&&(i+=hr(c,a,t));n.length>o&&f.lineNum===a;){let h=n[o++];h&&(i+=yt(h,s,h.lineNum,{...t,inlineSource:!1}))}}for(;n.length>o;){let a=n[o++];a&&(i+=yt(a,[],0,{...t,inlineSource:!1}))}return i;case"issues":case"no":for(let a of r)i+=yt(a,s,a.lineNum,{inlineSource:t?.showSourceCode!=="no"});return i}}function yt(r,e,t,i){if(i?.inlineSource){let n=Ii(e,t),o=r.linePos>0?`${" ".repeat(r.linePos+5)}^^^
9
9
  `:"";return`
10
10
  ${n}${o}${r.type.toUpperCase()}: ${r.message}
11
11
 
12
- `}let s=r.type==="error"?"red":"orange";return i?.html?`<div class='luma-compiler-log-${r.type}' style="color:${s};"><b> ${r.type.toUpperCase()}: ${r.message}</b></div>`:`${r.type.toUpperCase()}: ${r.message}`}function $i(r,e,t){let i="";for(let s=e-2;s<=e;s++){let n=r[s-1];n!==void 0&&(i+=hr(n,e,t))}return i}function hr(r,e,t){let i=t?.html?Ui(r):r;return`${ki(String(e),4)}: ${i}${t?.html?"<br/>":`
12
+ `}let s=r.type==="error"?"red":"orange";return i?.html?`<div class='luma-compiler-log-${r.type}' style="color:${s};"><b> ${r.type.toUpperCase()}: ${r.message}</b></div>`:`${r.type.toUpperCase()}: ${r.message}`}function Ii(r,e,t){let i="";for(let s=e-2;s<=e;s++){let n=r[s-1];n!==void 0&&(i+=hr(n,e,t))}return i}function hr(r,e,t){let i=t?.html?Ui(r):r;return`${ki(String(e),4)}: ${i}${t?.html?"<br/>":`
13
13
  `}`}function ki(r,e){let t="";for(let i=r.length;i<e;++i)t+=" ";return t+r}function Ui(r){return r.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;").replaceAll('"',"&quot;").replaceAll("'","&#039;")}var xt=class extends l{get[Symbol.toStringTag](){return"Shader"}stage;source;compilationStatus="pending";constructor(e,t){t={...t,debugShaders:t.debugShaders||e.props.debugShaders||"errors"},super(e,{id:Oi(t),...t},xt.defaultProps),this.stage=this.props.stage,this.source=this.props.source}getCompilationInfoSync(){return null}getTranslatedSource(){return null}async debugShader(){let e=this.props.debugShaders;switch(e){case"never":return;case"errors":if(this.compilationStatus==="success")return;break;case"warnings":case"always":break}let t=await this.getCompilationInfo();e==="warnings"&&t?.length===0||this._displayShaderLog(t,this.id)}_displayShaderLog(e,t){if(typeof document>"u"||!document?.createElement)return;let i=t,s=`${this.stage} shader "${i}"`,n=dr(e,this.source,{showSourceCode:"all",html:!0}),o=this.getTranslatedSource(),a=document.createElement("div");a.innerHTML=`<h1>Compilation error in ${s}</h1>
14
14
  <div style="display:flex;position:fixed;top:10px;right:20px;gap:2px;">
15
15
  <button id="copy">Copy source</button><br/>
16
16
  <button id="close">Close</button>
17
17
  </div>
18
- <code><pre>${n}</pre></code>`,o&&(a.innerHTML+=`<br /><h1>Translated Source</h1><br /><br /><code><pre>${o}</pre></code>`),a.style.top="0",a.style.left="0",a.style.background="white",a.style.position="fixed",a.style.zIndex="9999",a.style.maxWidth="100vw",a.style.maxHeight="100vh",a.style.overflowY="auto",document.body.appendChild(a),a.querySelector(".luma-compiler-log-error")?.scrollIntoView(),a.querySelector("button#close").onclick=()=>{a.remove()},a.querySelector("button#copy").onclick=()=>{navigator.clipboard.writeText(this.source)}}},G=xt;u(G,"defaultProps",{...l.defaultProps,language:"auto",stage:void 0,source:"",sourceMap:null,entryPoint:"main",debugShaders:void 0});function Oi(r){return Fi(r.source)||r.id||P(`unnamed ${r.stage}-shader`)}function Fi(r,e="unnamed"){return/#define[\s*]SHADER_NAME[\s*]([A-Za-z0-9_-]+)[\s*]/.exec(r)?.[1]??e}var _t=class extends l{get[Symbol.toStringTag](){return"Framebuffer"}width;height;constructor(e,t={}){super(e,t,_t.defaultProps),this.width=this.props.width,this.height=this.props.height}clone(e){let t=this.colorAttachments.map(s=>s.texture.clone(e)),i=this.depthStencilAttachment&&this.depthStencilAttachment.texture.clone(e);return this.device.createFramebuffer({...this.props,...e,colorAttachments:t,depthStencilAttachment:i})}resize(e){let t=!e;if(e){let[i,s]=Array.isArray(e)?e:[e.width,e.height];t=t||s!==this.height||i!==this.width,this.width=i,this.height=s}t&&(d.log(2,`Resizing framebuffer ${this.id} to ${this.width}x${this.height}`)(),this.resizeAttachments(this.width,this.height))}autoCreateAttachmentTextures(){if(this.props.colorAttachments.length===0&&!this.props.depthStencilAttachment)throw new Error("Framebuffer has noattachments");this.colorAttachments=this.props.colorAttachments.map((t,i)=>{if(typeof t=="string"){let s=this.createColorTexture(t,i);return this.attachResource(s),s.view}return t instanceof g?t.view:t});let e=this.props.depthStencilAttachment;if(e)if(typeof e=="string"){let t=this.createDepthStencilTexture(e);this.attachResource(t),this.depthStencilAttachment=t.view}else e instanceof g?this.depthStencilAttachment=e.view:this.depthStencilAttachment=e}createColorTexture(e,t){return this.device.createTexture({id:`${this.id}-color-attachment-${t}`,usage:g.RENDER_ATTACHMENT,format:e,width:this.width,height:this.height,sampler:{magFilter:"linear",minFilter:"linear"}})}createDepthStencilTexture(e){return this.device.createTexture({id:`${this.id}-depth-stencil-attachment`,usage:g.RENDER_ATTACHMENT,format:e,width:this.width,height:this.height})}resizeAttachments(e,t){if(this.colorAttachments.forEach((i,s)=>{let n=i.texture.clone({width:e,height:t});this.destroyAttachedResource(i),this.colorAttachments[s]=n.view,this.attachResource(n.view)}),this.depthStencilAttachment){let i=this.depthStencilAttachment.texture.clone({width:e,height:t});this.destroyAttachedResource(this.depthStencilAttachment),this.depthStencilAttachment=i.view,this.attachResource(i)}this.updateAttachments()}},ae=_t;u(ae,"defaultProps",{...l.defaultProps,width:1,height:1,colorAttachments:[],depthStencilAttachment:null});var wt=class extends l{get[Symbol.toStringTag](){return"RenderPipeline"}shaderLayout;bufferLayout;linkStatus="pending";hash="";sharedRenderPipeline=null;get isPending(){return this.linkStatus==="pending"||this.vs.compilationStatus==="pending"||this.fs?.compilationStatus==="pending"}get isErrored(){return this.linkStatus==="error"||this.vs.compilationStatus==="error"||this.fs?.compilationStatus==="error"}constructor(e,t){super(e,t,wt.defaultProps),this.shaderLayout=this.props.shaderLayout,this.bufferLayout=this.props.bufferLayout||[],this.sharedRenderPipeline=this.props._sharedRenderPipeline||null}},T=wt;u(T,"defaultProps",{...l.defaultProps,vs:null,vertexEntryPoint:"vertexMain",vsConstants:{},fs:null,fragmentEntryPoint:"fragmentMain",fsConstants:{},shaderLayout:null,bufferLayout:[],topology:"triangle-list",colorAttachmentFormats:void 0,depthStencilAttachmentFormat:void 0,parameters:{},varyings:void 0,bufferMode:void 0,disableWarnings:!1,_sharedRenderPipeline:void 0,bindings:void 0,bindGroups:void 0});var je=class extends l{get[Symbol.toStringTag](){return"SharedRenderPipeline"}constructor(e,t){super(e,t,{...l.defaultProps,handle:void 0,vs:void 0,fs:void 0,varyings:void 0,bufferMode:void 0})}};var vt=class extends l{get[Symbol.toStringTag](){return"ComputePipeline"}hash="";shaderLayout;constructor(e,t){super(e,t,vt.defaultProps),this.shaderLayout=t.shaderLayout}},D=vt;u(D,"defaultProps",{...l.defaultProps,shader:void 0,entryPoint:void 0,constants:{},shaderLayout:void 0});var Pt=class{static getDefaultPipelineFactory(e){let t=e.getModuleData("@luma.gl/core");return t.defaultPipelineFactory||=new Pt(e),t.defaultPipelineFactory}device;_hashCounter=0;_hashes={};_renderPipelineCache={};_computePipelineCache={};_sharedRenderPipelineCache={};get[Symbol.toStringTag](){return"PipelineFactory"}toString(){return`PipelineFactory(${this.device.id})`}constructor(e){this.device=e}createRenderPipeline(e){if(!this.device.props._cachePipelines)return this.device.createRenderPipeline(e);let t={...T.defaultProps,...e},i=this._renderPipelineCache,s=this._hashRenderPipeline(t),n=i[s]?.resource;if(n)i[s].useCount++,this.device.props.debugFactories&&d.log(3,`${this}: ${i[s].resource} reused, count=${i[s].useCount}, (id=${e.id})`)();else{let o=this.device.type==="webgl"&&this.device.props._sharePipelines?this.createSharedRenderPipeline(t):void 0;n=this.device.createRenderPipeline({...t,id:t.id?`${t.id}-cached`:P("unnamed-cached"),_sharedRenderPipeline:o}),n.hash=s,i[s]={resource:n,useCount:1},this.device.props.debugFactories&&d.log(3,`${this}: ${n} created, count=${i[s].useCount}`)()}return n}createComputePipeline(e){if(!this.device.props._cachePipelines)return this.device.createComputePipeline(e);let t={...D.defaultProps,...e},i=this._computePipelineCache,s=this._hashComputePipeline(t),n=i[s]?.resource;return n?(i[s].useCount++,this.device.props.debugFactories&&d.log(3,`${this}: ${i[s].resource} reused, count=${i[s].useCount}, (id=${e.id})`)()):(n=this.device.createComputePipeline({...t,id:t.id?`${t.id}-cached`:void 0}),n.hash=s,i[s]={resource:n,useCount:1},this.device.props.debugFactories&&d.log(3,`${this}: ${n} created, count=${i[s].useCount}`)()),n}release(e){if(!this.device.props._cachePipelines){e.destroy();return}let t=this._getCache(e),i=e.hash;t[i].useCount--,t[i].useCount===0?(this._destroyPipeline(e),this.device.props.debugFactories&&d.log(3,`${this}: ${e} released and destroyed`)()):t[i].useCount<0?(d.error(`${this}: ${e} released, useCount < 0, resetting`)(),t[i].useCount=0):this.device.props.debugFactories&&d.log(3,`${this}: ${e} released, count=${t[i].useCount}`)()}createSharedRenderPipeline(e){let t=this._hashSharedRenderPipeline(e),i=this._sharedRenderPipelineCache[t];return i||(i={resource:this.device._createSharedRenderPipelineWebGL(e),useCount:0},this._sharedRenderPipelineCache[t]=i),i.useCount++,i.resource}releaseSharedRenderPipeline(e){if(!e.sharedRenderPipeline)return;let t=this._hashSharedRenderPipeline(e.sharedRenderPipeline.props),i=this._sharedRenderPipelineCache[t];i&&(i.useCount--,i.useCount===0&&(i.resource.destroy(),delete this._sharedRenderPipelineCache[t]))}_destroyPipeline(e){let t=this._getCache(e);return this.device.props._destroyPipelines?(delete t[e.hash],e.destroy(),e instanceof T&&this.releaseSharedRenderPipeline(e),!0):!1}_getCache(e){let t;if(e instanceof D&&(t=this._computePipelineCache),e instanceof T&&(t=this._renderPipelineCache),!t)throw new Error(`${this}`);if(!t[e.hash])throw new Error(`${this}: ${e} matched incorrect entry`);return t}_hashComputePipeline(e){let{type:t}=this.device,i=this._getHash(e.shader.source),s=this._getHash(JSON.stringify(e.shaderLayout));return`${t}/C/${i}SL${s}`}_hashRenderPipeline(e){let t=e.vs?this._getHash(e.vs.source):0,i=e.fs?this._getHash(e.fs.source):0,s=this._getWebGLVaryingHash(e),n=this._getHash(JSON.stringify(e.shaderLayout)),o=this._getHash(JSON.stringify(e.bufferLayout)),{type:a}=this.device;switch(a){case"webgl":let c=this._getHash(JSON.stringify(e.parameters));return`${a}/R/${t}/${i}V${s}T${e.topology}P${c}SL${n}BL${o}`;case"webgpu":default:let f=this._getHash(JSON.stringify({vertexEntryPoint:e.vertexEntryPoint,fragmentEntryPoint:e.fragmentEntryPoint})),h=this._getHash(JSON.stringify(e.parameters)),b=this._getWebGPUAttachmentHash(e);return`${a}/R/${t}/${i}V${s}T${e.topology}EP${f}P${h}SL${n}BL${o}A${b}`}}_hashSharedRenderPipeline(e){let t=e.vs?this._getHash(e.vs.source):0,i=e.fs?this._getHash(e.fs.source):0,s=this._getWebGLVaryingHash(e);return`webgl/S/${t}/${i}V${s}`}_getHash(e){return this._hashes[e]===void 0&&(this._hashes[e]=this._hashCounter++),this._hashes[e]}_getWebGLVaryingHash(e){let{varyings:t=[],bufferMode:i=null}=e;return this._getHash(JSON.stringify({varyings:t,bufferMode:i}))}_getWebGPUAttachmentHash(e){let t=e.colorAttachmentFormats??[this.device.preferredColorFormat],i=e.parameters?.depthWriteEnabled?e.depthStencilAttachmentFormat||this.device.preferredDepthFormat:null;return this._getHash(JSON.stringify({colorAttachmentFormats:t,depthStencilAttachmentFormat:i}))}},ce=Pt;u(ce,"defaultProps",{...T.defaultProps});var St=class{static getDefaultShaderFactory(e){let t=e.getModuleData("@luma.gl/core");return t.defaultShaderFactory||=new St(e),t.defaultShaderFactory}device;_cache={};get[Symbol.toStringTag](){return"ShaderFactory"}toString(){return`${this[Symbol.toStringTag]}(${this.device.id})`}constructor(e){this.device=e}createShader(e){if(!this.device.props._cacheShaders)return this.device.createShader(e);let t=this._hashShader(e),i=this._cache[t];if(i)i.useCount++,this.device.props.debugFactories&&d.log(3,`${this}: Reusing shader ${i.resource.id} count=${i.useCount}`)();else{let s=this.device.createShader({...e,id:e.id?`${e.id}-cached`:void 0});this._cache[t]=i={resource:s,useCount:1},this.device.props.debugFactories&&d.log(3,`${this}: Created new shader ${s.id}`)()}return i.resource}release(e){if(!this.device.props._cacheShaders){e.destroy();return}let t=this._hashShader(e),i=this._cache[t];if(i)if(i.useCount--,i.useCount===0)this.device.props._destroyShaders&&(delete this._cache[t],i.resource.destroy(),this.device.props.debugFactories&&d.log(3,`${this}: Releasing shader ${e.id}, destroyed`)());else{if(i.useCount<0)throw new Error(`ShaderFactory: Shader ${e.id} released too many times`);this.device.props.debugFactories&&d.log(3,`${this}: Releasing shader ${e.id} count=${i.useCount}`)()}}_hashShader(e){return`${e.stage}:${e.source}`}},ue=St;u(ue,"defaultProps",{...G.defaultProps});function Tt(r,e,t){let i=r.bindings.find(s=>s.name===e||`${s.name.toLocaleLowerCase()}uniforms`===e.toLocaleLowerCase());return!i&&!t?.ignoreWarnings&&d.warn(`Binding ${e} not set: Not found in shader layout.`)(),i||null}function Qe(r,e){if(!e)return{};if(Gi(e))return Object.fromEntries(Object.entries(e).map(([s,n])=>[Number(s),{...n}]));let t={};for(let[i,s]of Object.entries(e)){let o=Tt(r,i)?.group??0;t[o]||={},t[o][i]=s}return t}function mr(r){let e={};for(let t of Object.values(r))Object.assign(e,t);return e}function Gi(r){let e=Object.keys(r);return e.length>0&&e.every(t=>/^\d+$/.test(t))}var Ct=class{device;_layoutCacheByPipeline=new WeakMap;_bindGroupCacheByLayout=new WeakMap;constructor(e){this.device=e}getBindGroups(e,t,i){if(this.device.type!=="webgpu"||e.shaderLayout.bindings.length===0)return{};let s=Qe(e.shaderLayout,t),n={};for(let o of Wi(e.shaderLayout.bindings)){let a=s[o],c=this._getBindGroupLayout(e,o);if(!a||Object.keys(a).length===0){zi(e.shaderLayout.bindings,o)||(n[o]=this._getEmptyBindGroup(c,e.shaderLayout,o));continue}let f=i?.[o];if(f){let h=this._getLayoutBindGroupCache(c);if(h.bindGroupsBySource.has(f)){n[o]=h.bindGroupsBySource.get(f)||null;continue}let b=this.device._createBindGroupWebGPU(c,e.shaderLayout,a,o);h.bindGroupsBySource.set(f,b),n[o]=b}else n[o]=this.device._createBindGroupWebGPU(c,e.shaderLayout,a,o)}return n}_getBindGroupLayout(e,t){let i=this._layoutCacheByPipeline.get(e);return i||(i={},this._layoutCacheByPipeline.set(e,i)),i[t]||=this.device._createBindGroupLayoutWebGPU(e,t),i[t]}_getEmptyBindGroup(e,t,i){let s=this._getLayoutBindGroupCache(e);return s.emptyBindGroup||=this.device._createBindGroupWebGPU(e,t,{},i)||null,s.emptyBindGroup}_getLayoutBindGroupCache(e){let t=this._bindGroupCacheByLayout.get(e);return t||(t={bindGroupsBySource:new WeakMap},this._bindGroupCacheByLayout.set(e,t)),t}};function pr(r){return r._factories.bindGroupFactory||=new Ct(r),r._factories.bindGroupFactory}function Wi(r){let e=r.reduce((t,i)=>Math.max(t,i.group),-1);return Array.from({length:e+1},(t,i)=>i)}function zi(r,e){return r.some(t=>t.group===e)}var W=class extends l{get[Symbol.toStringTag](){return"RenderPass"}constructor(e,t){t=W.normalizeProps(e,t),super(e,t,W.defaultProps)}static normalizeProps(e,t){return t}},I=W;u(I,"defaultClearColor",[0,0,0,1]),u(I,"defaultClearDepth",1),u(I,"defaultClearStencil",0),u(I,"defaultProps",{...l.defaultProps,framebuffer:null,parameters:void 0,clearColor:W.defaultClearColor,clearColors:void 0,clearDepth:W.defaultClearDepth,clearStencil:W.defaultClearStencil,depthReadOnly:!1,stencilReadOnly:!1,discard:!1,occlusionQuerySet:void 0,timestampQuerySet:void 0,beginTimestampIndex:void 0,endTimestampIndex:void 0});var At=class extends l{constructor(e,t){super(e,t,At.defaultProps)}get[Symbol.toStringTag](){return"ComputePass"}},le=At;u(le,"defaultProps",{...l.defaultProps,timestampQuerySet:void 0,beginTimestampIndex:void 0,endTimestampIndex:void 0});var Et=class extends l{get[Symbol.toStringTag](){return"CommandEncoder"}_timeProfilingQuerySet=null;_timeProfilingSlotCount=0;_gpuTimeMs;constructor(e,t){super(e,t,Et.defaultProps),this._timeProfilingQuerySet=t.timeProfilingQuerySet??null,this._timeProfilingSlotCount=0,this._gpuTimeMs=void 0}async resolveTimeProfilingQuerySet(){if(this._gpuTimeMs=void 0,!this._timeProfilingQuerySet)return;let e=Math.floor(this._timeProfilingSlotCount/2);if(e<=0)return;let t=e*2,i=await this._timeProfilingQuerySet.readResults({firstQuery:0,queryCount:t}),s=0n;for(let n=0;n<t;n+=2)s+=i[n+1]-i[n];this._gpuTimeMs=Number(s)/1e6}getTimeProfilingSlotCount(){return this._timeProfilingSlotCount}getTimeProfilingQuerySet(){return this._timeProfilingQuerySet}_applyTimeProfilingToPassProps(e){let t=e||{};if(!this._supportsTimestampQueries()||!this._timeProfilingQuerySet||t.timestampQuerySet!==void 0||t.beginTimestampIndex!==void 0||t.endTimestampIndex!==void 0)return t;let i=this._timeProfilingSlotCount;return i+1>=this._timeProfilingQuerySet.props.count?t:(this._timeProfilingSlotCount+=2,{...t,timestampQuerySet:this._timeProfilingQuerySet,beginTimestampIndex:i,endTimestampIndex:i+1})}_supportsTimestampQueries(){return this.device.features.has("timestamp-query")}},fe=Et;u(fe,"defaultProps",{...l.defaultProps,measureExecutionTime:void 0,timeProfilingQuerySet:void 0});var Rt=class extends l{get[Symbol.toStringTag](){return"CommandBuffer"}constructor(e,t){super(e,t,Rt.defaultProps)}},de=Rt;u(de,"defaultProps",{...l.defaultProps});function he(r){let e=Ye(r),t=ji[e];if(!t)throw new Error(`Unsupported variable shader type: ${r}`);return t}function Bt(r){let e=gr(r),t=Vi[e];if(!t)throw new Error(`Unsupported attribute shader type: ${r}`);let[i,s]=t,n=i==="i32"||i==="u32",o=i!=="u32",a=Ni[i]*s;return{primitiveType:i,components:s,byteLength:a,integer:n,signed:o}}var Lt=class{getVariableShaderTypeInfo(e){return he(e)}getAttributeShaderTypeInfo(e){return Bt(e)}makeShaderAttributeType(e,t){return Hi(e,t)}resolveAttributeShaderTypeAlias(e){return gr(e)}resolveVariableShaderTypeAlias(e){return Ye(e)}};function Hi(r,e){return e===1?r:`vec${e}<${r}>`}function gr(r){return Qi[r]||r}function Ye(r){return Yi[r]||r}var Xe=new Lt,Ni={f32:4,f16:2,i32:4,u32:4},Vi={f32:["f32",1],"vec2<f32>":["f32",2],"vec3<f32>":["f32",3],"vec4<f32>":["f32",4],f16:["f16",1],"vec2<f16>":["f16",2],"vec3<f16>":["f16",3],"vec4<f16>":["f16",4],i32:["i32",1],"vec2<i32>":["i32",2],"vec3<i32>":["i32",3],"vec4<i32>":["i32",4],u32:["u32",1],"vec2<u32>":["u32",2],"vec3<u32>":["u32",3],"vec4<u32>":["u32",4]},ji={f32:{type:"f32",components:1},f16:{type:"f16",components:1},i32:{type:"i32",components:1},u32:{type:"u32",components:1},"vec2<f32>":{type:"f32",components:2},"vec3<f32>":{type:"f32",components:3},"vec4<f32>":{type:"f32",components:4},"vec2<f16>":{type:"f16",components:2},"vec3<f16>":{type:"f16",components:3},"vec4<f16>":{type:"f16",components:4},"vec2<i32>":{type:"i32",components:2},"vec3<i32>":{type:"i32",components:3},"vec4<i32>":{type:"i32",components:4},"vec2<u32>":{type:"u32",components:2},"vec3<u32>":{type:"u32",components:3},"vec4<u32>":{type:"u32",components:4},"mat2x2<f32>":{type:"f32",components:4},"mat2x3<f32>":{type:"f32",components:6},"mat2x4<f32>":{type:"f32",components:8},"mat3x2<f32>":{type:"f32",components:6},"mat3x3<f32>":{type:"f32",components:9},"mat3x4<f32>":{type:"f32",components:12},"mat4x2<f32>":{type:"f32",components:8},"mat4x3<f32>":{type:"f32",components:12},"mat4x4<f32>":{type:"f32",components:16},"mat2x2<f16>":{type:"f16",components:4},"mat2x3<f16>":{type:"f16",components:6},"mat2x4<f16>":{type:"f16",components:8},"mat3x2<f16>":{type:"f16",components:6},"mat3x3<f16>":{type:"f16",components:9},"mat3x4<f16>":{type:"f16",components:12},"mat4x2<f16>":{type:"f16",components:8},"mat4x3<f16>":{type:"f16",components:12},"mat4x4<f16>":{type:"f16",components:16},"mat2x2<i32>":{type:"i32",components:4},"mat2x3<i32>":{type:"i32",components:6},"mat2x4<i32>":{type:"i32",components:8},"mat3x2<i32>":{type:"i32",components:6},"mat3x3<i32>":{type:"i32",components:9},"mat3x4<i32>":{type:"i32",components:12},"mat4x2<i32>":{type:"i32",components:8},"mat4x3<i32>":{type:"i32",components:12},"mat4x4<i32>":{type:"i32",components:16},"mat2x2<u32>":{type:"u32",components:4},"mat2x3<u32>":{type:"u32",components:6},"mat2x4<u32>":{type:"u32",components:8},"mat3x2<u32>":{type:"u32",components:6},"mat3x3<u32>":{type:"u32",components:9},"mat3x4<u32>":{type:"u32",components:12},"mat4x2<u32>":{type:"u32",components:8},"mat4x3<u32>":{type:"u32",components:12},"mat4x4<u32>":{type:"u32",components:16}},Qi={vec2i:"vec2<i32>",vec3i:"vec3<i32>",vec4i:"vec4<i32>",vec2u:"vec2<u32>",vec3u:"vec3<u32>",vec4u:"vec4<u32>",vec2f:"vec2<f32>",vec3f:"vec3<f32>",vec4f:"vec4<f32>",vec2h:"vec2<f16>",vec3h:"vec3<f16>",vec4h:"vec4<f16>"},Yi={vec2i:"vec2<i32>",vec3i:"vec3<i32>",vec4i:"vec4<i32>",vec2u:"vec2<u32>",vec3u:"vec3<u32>",vec4u:"vec4<u32>",vec2f:"vec2<f32>",vec3f:"vec3<f32>",vec4f:"vec4<f32>",vec2h:"vec2<f16>",vec3h:"vec3<f16>",vec4h:"vec4<f16>",mat2x2f:"mat2x2<f32>",mat2x3f:"mat2x3<f32>",mat2x4f:"mat2x4<f32>",mat3x2f:"mat3x2<f32>",mat3x3f:"mat3x3<f32>",mat3x4f:"mat3x4<f32>",mat4x2f:"mat4x2<f32>",mat4x3f:"mat4x3<f32>",mat4x4f:"mat4x4<f32>",mat2x2i:"mat2x2<i32>",mat2x3i:"mat2x3<i32>",mat2x4i:"mat2x4<i32>",mat3x2i:"mat3x2<i32>",mat3x3i:"mat3x3<i32>",mat3x4i:"mat3x4<i32>",mat4x2i:"mat4x2<i32>",mat4x3i:"mat4x3<i32>",mat4x4i:"mat4x4<i32>",mat2x2u:"mat2x2<u32>",mat2x3u:"mat2x3<u32>",mat2x4u:"mat2x4<u32>",mat3x2u:"mat3x2<u32>",mat3x3u:"mat3x3<u32>",mat3x4u:"mat3x4<u32>",mat4x2u:"mat4x2<u32>",mat4x3u:"mat4x3<u32>",mat4x4u:"mat4x4<u32>",mat2x2h:"mat2x2<f16>",mat2x3h:"mat2x3<f16>",mat2x4h:"mat2x4<f16>",mat3x2h:"mat3x2<f16>",mat3x3h:"mat3x3<f16>",mat3x4h:"mat3x4<f16>",mat4x2h:"mat4x2<f16>",mat4x3h:"mat4x3<f16>",mat4x4h:"mat4x4<f16>"};function Mt(r,e){let t={};for(let i of r.attributes){let s=Xi(r,e,i.name);s&&(t[i.name]=s)}return t}function br(r,e,t=16){let i=Mt(r,e),s=new Array(t).fill(null);for(let n of Object.values(i))s[n.location]=n;return s}function Xi(r,e,t){let i=qi(r,t),s=Ji(e,t);if(!i)return null;let n=Xe.getAttributeShaderTypeInfo(i.type),o=B.getCompatibleVertexFormat(n),a=s?.vertexFormat||o,c=B.getVertexFormatInfo(a);return{attributeName:s?.attributeName||i.name,bufferName:s?.bufferName||i.name,location:i.location,shaderType:i.type,primitiveType:n.primitiveType,shaderComponents:n.components,vertexFormat:a,bufferDataType:c.type,bufferComponents:c.components,normalized:c.normalized,integer:n.integer,stepMode:s?.stepMode||i.stepMode||"vertex",byteOffset:s?.byteOffset||0,byteStride:s?.byteStride||0}}function qi(r,e){let t=r.attributes.find(i=>i.name===e);return t||d.warn(`shader layout attribute "${e}" not present in shader`),t||null}function Ji(r,e){Ki(r);let t=Zi(r,e);return t||(t=es(r,e),t)?t:(d.warn(`layout for attribute "${e}" not present in buffer layout`),null)}function Ki(r){for(let e of r)(e.attributes&&e.format||!e.attributes&&!e.format)&&d.warn(`BufferLayout ${name} must have either 'attributes' or 'format' field`)}function Zi(r,e){for(let t of r)if(t.format&&t.name===e)return{attributeName:t.name,bufferName:e,stepMode:t.stepMode,vertexFormat:t.format,byteOffset:0,byteStride:t.byteStride||0};return null}function es(r,e){for(let t of r){let i=t.byteStride;if(typeof t.byteStride!="number")for(let n of t.attributes||[]){let o=B.getVertexFormatInfo(n.format);i+=o.byteLength}let s=t.attributes?.find(n=>n.attribute===e);if(s)return{attributeName:s.attribute,bufferName:t.name,stepMode:t.stepMode,vertexFormat:s.format,byteOffset:s.byteOffset,byteStride:i}}return null}var Dt=class extends l{get[Symbol.toStringTag](){return"VertexArray"}maxVertexAttributes;attributeInfos;indexBuffer=null;attributes;constructor(e,t){super(e,t,Dt.defaultProps),this.maxVertexAttributes=e.limits.maxVertexAttributes,this.attributes=new Array(this.maxVertexAttributes).fill(null),this.attributeInfos=br(t.shaderLayout,t.bufferLayout,this.maxVertexAttributes)}setConstantWebGL(e,t){this.device.reportError(new Error("constant attributes not supported"),this)()}},me=Dt;u(me,"defaultProps",{...l.defaultProps,shaderLayout:void 0,bufferLayout:[]});var It=class extends l{get[Symbol.toStringTag](){return"TransformFeedback"}constructor(e,t){super(e,t,It.defaultProps)}},pe=It;u(pe,"defaultProps",{...l.defaultProps,layout:void 0,buffers:{}});var $t=class extends l{get[Symbol.toStringTag](){return"QuerySet"}constructor(e,t){super(e,t,$t.defaultProps)}},ge=$t;u(ge,"defaultProps",{...l.defaultProps,type:void 0,count:void 0});var kt=class extends l{get[Symbol.toStringTag](){return"Fence"}constructor(e,t={}){super(e,t,kt.defaultProps)}},be=kt;u(be,"defaultProps",{...l.defaultProps});var Ut=class extends l{get[Symbol.toStringTag](){return"PipelineLayout"}constructor(e,t){super(e,t,Ut.defaultProps)}},ye=Ut;u(ye,"defaultProps",{...l.defaultProps,shaderLayout:{attributes:[],bindings:[]}});function C(r,e){switch(e){case 1:return r;case 2:return r+r%2;default:return r+(4-r%4)%4}}function yr(r){let[,,,,e]=ts[r];return e}var ts={uint8:["uint8","u32",1,!1,Uint8Array],sint8:["sint8","i32",1,!1,Int8Array],unorm8:["uint8","f32",1,!0,Uint8Array],snorm8:["sint8","f32",1,!0,Int8Array],uint16:["uint16","u32",2,!1,Uint16Array],sint16:["sint16","i32",2,!1,Int16Array],unorm16:["uint16","u32",2,!0,Uint16Array],snorm16:["sint16","i32",2,!0,Int16Array],float16:["float16","f16",2,!1,Uint16Array],float32:["float32","f32",4,!1,Float32Array],uint32:["uint32","u32",4,!1,Uint32Array],sint32:["sint32","i32",4,!1,Int32Array]};function qe(r,e={}){let t={...r},i=e.layout??"std140",s={},n=0;for(let[o,a]of Object.entries(t))n=Ot(s,o,a,n,i);return n=C(n,$(t,i)),{layout:i,byteLength:n*4,uniformTypes:t,fields:s}}function xe(r,e){let t=Ye(r),i=he(t),s=/^mat(\d)x(\d)<.+>$/.exec(t);if(s){let o=Number(s[1]),a=Number(s[2]),c=xr(a,t,i.type,e),f=is(c.size,c.alignment,e);return{alignment:c.alignment,size:o*f,components:o*a,columns:o,rows:a,columnStride:f,shaderType:t,type:i.type}}let n=/^vec(\d)<.+>$/.exec(t);return n?xr(Number(n[1]),t,i.type,e):{alignment:1,size:1,components:1,columns:1,rows:1,columnStride:1,shaderType:t,type:i.type}}function Ft(r){return Boolean(r)&&typeof r=="object"&&!Array.isArray(r)}function Ot(r,e,t,i,s){if(typeof t=="string"){let n=xe(t,s),o=C(i,n.alignment);return r[e]={offset:o,...n},o+n.size}if(Array.isArray(t)){if(Array.isArray(t[0]))throw new Error(`Nested arrays are not supported for ${e}`);let n=t[0],o=t[1],a=wr(n,s),c=C(i,$(t,s));for(let f=0;f<o;f++)Ot(r,`${e}[${f}]`,n,c+f*a,s);return c+a*o}if(Ft(t)){let n=$(t,s),o=C(i,n);for(let[a,c]of Object.entries(t))o=Ot(r,`${e}.${a}`,c,o,s);return C(o,n)}throw new Error(`Unsupported CompositeShaderType for ${e}`)}function _r(r,e){if(typeof r=="string")return xe(r,e).size;if(Array.isArray(r)){let i=r[0],s=r[1];if(Array.isArray(i))throw new Error("Nested arrays are not supported");return wr(i,e)*s}let t=0;for(let i of Object.values(r)){let s=i;t=C(t,$(s,e)),t+=_r(s,e)}return C(t,$(r,e))}function $(r,e){if(typeof r=="string")return xe(r,e).alignment;if(Array.isArray(r)){let i=r[0],s=$(i,e);return vr(e)?Math.max(s,4):s}let t=1;for(let i of Object.values(r)){let s=$(i,e);t=Math.max(t,s)}return ss(e)?Math.max(t,4):t}function xr(r,e,t,i){return{alignment:r===2?2:4,size:r===3?3:r,components:r,columns:1,rows:r,columnStride:r===3?3:r,shaderType:e,type:t}}function wr(r,e){let t=_r(r,e),i=$(r,e);return rs(t,i,e)}function rs(r,e,t){return C(r,vr(t)?4:e)}function is(r,e,t){return t==="std140"?4:C(r,e)}function vr(r){return r==="std140"||r==="wgsl-uniform"}function ss(r){return r==="std140"||r==="wgsl-uniform"}var Je;function Gt(r){return(!Je||Je.byteLength<r)&&(Je=new ArrayBuffer(r)),Je}function Pr(r,e){let t=Gt(r.BYTES_PER_ELEMENT*e);return new r(t,0,e)}function ns(r){return ArrayBuffer.isView(r)&&!(r instanceof DataView)}function Q(r){return Array.isArray(r)?r.length===0||typeof r[0]=="number":ns(r)}var Y=class{layout;constructor(e){this.layout=e}has(e){return Boolean(this.layout.fields[e])}get(e){let t=this.layout.fields[e];return t?{offset:t.offset,size:t.size}:void 0}getFlatUniformValues(e){let t={};for(let[i,s]of Object.entries(e)){let n=this.layout.uniformTypes[i];n?this._flattenCompositeValue(t,i,n,s):this.layout.fields[i]&&(t[i]=s)}return t}getData(e){let t=Gt(this.layout.byteLength);new Uint8Array(t,0,this.layout.byteLength).fill(0);let i={i32:new Int32Array(t),u32:new Uint32Array(t),f32:new Float32Array(t),f16:new Uint16Array(t)},s=this.getFlatUniformValues(e);for(let[n,o]of Object.entries(s))this._writeLeafValue(i,n,o);return new Uint8Array(t,0,this.layout.byteLength)}_flattenCompositeValue(e,t,i,s){if(s!==void 0){if(typeof i=="string"||this.layout.fields[t]){e[t]=s;return}if(Array.isArray(i)){let n=i[0],o=i[1];if(Array.isArray(n))throw new Error(`Nested arrays are not supported for ${t}`);if(typeof n=="string"&&Q(s)){this._flattenPackedArray(e,t,n,o,s);return}if(!Array.isArray(s)){d.warn(`Unsupported uniform array value for ${t}:`,s)();return}for(let a=0;a<Math.min(s.length,o);a++){let c=s[a];c!==void 0&&this._flattenCompositeValue(e,`${t}[${a}]`,n,c)}return}if(Ft(i)&&os(s)){for(let[n,o]of Object.entries(s)){if(o===void 0)continue;let a=`${t}.${n}`;this._flattenCompositeValue(e,a,i[n],o)}return}d.warn(`Unsupported uniform value for ${t}:`,s)()}}_flattenPackedArray(e,t,i,s,n){let o=n,c=xe(i,this.layout.layout).components;for(let f=0;f<s;f++){let h=f*c;if(h>=o.length)break;c===1?e[`${t}[${f}]`]=Number(o[h]):e[`${t}[${f}]`]=as(n,h,h+c)}}_writeLeafValue(e,t,i){let s=this.layout.fields[t];if(!s){d.warn(`Uniform ${t} not found in layout`)();return}let{type:n,components:o,columns:a,rows:c,offset:f,columnStride:h}=s,b=e[n];if(o===1){b[f]=Number(i);return}let z=i;if(a===1){for(let w=0;w<o;w++)b[f+w]=Number(z[w]??0);return}let Ze=0;for(let w=0;w<a;w++){let q=f+w*h;for(let J=0;J<c;J++)b[q+J]=Number(z[Ze++]??0)}}};function os(r){return Boolean(r)&&typeof r=="object"&&!Array.isArray(r)&&!ArrayBuffer.isView(r)}function as(r,e,t){return Array.prototype.slice.call(r,e,t)}var cs=128;function Sr(r,e,t=16){if(r===e)return!0;let i=r,s=e;if(!Q(i)||!Q(s)||i.length!==s.length)return!1;let n=Math.min(t,cs);if(i.length>n)return!1;for(let o=0;o<i.length;++o)if(s[o]!==i[o])return!1;return!0}function Tr(r){return Q(r)?r.slice():r}var X=class{name;uniforms={};modifiedUniforms={};modified=!0;bindingLayout={};needsRedraw="initialized";constructor(e){if(this.name=e?.name||"unnamed",e?.name&&e?.shaderLayout){let t=e?.shaderLayout.bindings?.find(s=>s.type==="uniform"&&s.name===e?.name);if(!t)throw new Error(e?.name);let i=t;for(let s of i.uniforms||[])this.bindingLayout[s.name]=s}}setUniforms(e){for(let[t,i]of Object.entries(e))this._setUniform(t,i),this.needsRedraw||this.setNeedsRedraw(`${this.name}.${t}=${i}`)}setNeedsRedraw(e){this.needsRedraw=this.needsRedraw||e}getAllUniforms(){return this.modifiedUniforms={},this.needsRedraw=!1,this.uniforms||{}}_setUniform(e,t){Sr(this.uniforms[e],t)||(this.uniforms[e]=Tr(t),this.modifiedUniforms[e]=!0,this.modified=!0)}};var us=1024,Ke=class{device;uniformBlocks=new Map;shaderBlockLayouts=new Map;shaderBlockWriters=new Map;uniformBuffers=new Map;constructor(e,t){this.device=e;for(let[i,s]of Object.entries(t)){let n=i,o=qe(s.uniformTypes??{},{layout:s.layout??ls(e)}),a=new Y(o);this.shaderBlockLayouts.set(n,o),this.shaderBlockWriters.set(n,a);let c=new X({name:i});c.setUniforms(a.getFlatUniformValues(s.defaultUniforms||{})),this.uniformBlocks.set(n,c)}}destroy(){for(let e of this.uniformBuffers.values())e.destroy()}setUniforms(e){for(let[t,i]of Object.entries(e)){let s=t,o=this.shaderBlockWriters.get(s)?.getFlatUniformValues(i||{});this.uniformBlocks.get(s)?.setUniforms(o||{})}this.updateUniformBuffers()}getUniformBufferByteLength(e){let t=this.shaderBlockLayouts.get(e)?.byteLength||0;return Math.max(t,us)}getUniformBufferData(e){let t=this.uniformBlocks.get(e)?.getAllUniforms()||{};return this.shaderBlockWriters.get(e)?.getData(t)||new Uint8Array(0)}createUniformBuffer(e,t){t&&this.setUniforms(t);let i=this.getUniformBufferByteLength(e),s=this.device.createBuffer({usage:p.UNIFORM|p.COPY_DST,byteLength:i}),n=this.getUniformBufferData(e);return s.write(n),s}getManagedUniformBuffer(e){if(!this.uniformBuffers.get(e)){let t=this.getUniformBufferByteLength(e),i=this.device.createBuffer({usage:p.UNIFORM|p.COPY_DST,byteLength:t});this.uniformBuffers.set(e,i)}return this.uniformBuffers.get(e)}updateUniformBuffers(){let e=!1;for(let t of this.uniformBlocks.keys()){let i=this.updateUniformBuffer(t);e||=i}return e&&d.log(3,`UniformStore.updateUniformBuffers(): ${e}`)(),e}updateUniformBuffer(e){let t=this.uniformBlocks.get(e),i=this.uniformBuffers.get(e),s=!1;if(i&&t?.needsRedraw){s||=t.needsRedraw;let n=this.getUniformBufferData(e);i=this.uniformBuffers.get(e),i?.write(n);let o=this.uniformBlocks.get(e)?.getAllUniforms();d.log(4,`Writing to uniform buffer ${String(e)}`,n,o)()}return s}};function ls(r){return r.type==="webgpu"?"wgsl-uniform":"std140"}function Wt(r,e,t,i=0){let s=x.getInfo(t),n=s.bytesPerPixel/s.components,{bytesPerImage:o}=e,a=o*i,c=e.bytesPerImage/n;switch(t){case"rgba8unorm":case"bgra8unorm":case"rgba8uint":return new Uint8Array(r,a,c);case"r8unorm":return new Uint8Array(r,a,c);case"r16uint":case"rgba16uint":return new Uint16Array(r,a,c);case"r32uint":case"rgba32uint":return new Uint32Array(r,a,c);case"r32float":return new Float32Array(r,a,c);case"rgba16float":return new Uint16Array(r,a,c);case"rgba32float":return new Float32Array(r,a,c);default:throw new Error(`Unsupported format: ${t}`)}}function Cr(r,e,t,i,s=0){let o=e.bytesPerImage/e.bytesPerPixel,a=i.subarray(0,o);Wt(r,e,t,s).set(a,0)}function Ar(r,e,t,i){if(e<0||e>=r.width||t<0||t>=r.height)throw new Error("Coordinates out of bounds.");let s=t*r.bytesPerRow+e*r.bytesPerPixel,n=new DataView(r.arrayBuffer,s,r.bytesPerPixel),o=0,a=[];for(let c=0;c<4;c++){let f=i[c]??0;if(f<=0)a.push(0);else{let h=fs(n,o,f);a.push(h),o+=f}}return[a[0]??0,a[1]??0,a[2]??0,a[3]??0]}function Er(r,e,t,i){let s=e;for(let n=0;n<4;n++){let o=t[n]??0,a=(1<<o)-1,c=(i[n]??0)&a;ds(r,s,o,c),s+=o}}function fs(r,e,t){if(e%8===0){let s=e/8;if(t===8&&s+1<=r.byteLength)return r.getUint8(s);if(t===16&&s+2<=r.byteLength)return r.getUint16(s,!1);if(t===32&&s+4<=r.byteLength)return r.getUint32(s,!1)}let i=0;for(let s=0;s<t;s++){let n=e+s,o=Math.floor(n/8),a=n%8,f=r.getUint8(o)>>7-a&1;i=i<<1|f}return i}function ds(r,e,t,i){if(e%8===0){let s=e/8;if(t===8&&s+1<=r.byteLength){r.setUint8(s,i&255);return}else if(t===16&&s+2<=r.byteLength){r.setUint16(s,i&65535,!1);return}else if(t===32&&s+4<=r.byteLength){r.setUint32(s,i,!1);return}}for(let s=0;s<t;s++){let n=e+s,o=Math.floor(n/8),c=1<<7-n%8,f=i>>t-1-s&1,h=r.getUint8(o);h&=~c,f&&(h|=c),r.setUint8(o,h)}}ve(_e,Fr(Lr(),1));return Gr(_e);})();
18
+ <code><pre>${n}</pre></code>`,o&&(a.innerHTML+=`<br /><h1>Translated Source</h1><br /><br /><code><pre>${o}</pre></code>`),a.style.top="0",a.style.left="0",a.style.background="white",a.style.position="fixed",a.style.zIndex="9999",a.style.maxWidth="100vw",a.style.maxHeight="100vh",a.style.overflowY="auto",document.body.appendChild(a),a.querySelector(".luma-compiler-log-error")?.scrollIntoView(),a.querySelector("button#close").onclick=()=>{a.remove()},a.querySelector("button#copy").onclick=()=>{navigator.clipboard.writeText(this.source)}}},W=xt;u(W,"defaultProps",{...l.defaultProps,language:"auto",stage:void 0,source:"",sourceMap:null,entryPoint:"main",debugShaders:void 0});function Oi(r){return Gi(r.source)||r.id||P(`unnamed ${r.stage}-shader`)}function Gi(r,e="unnamed"){return/#define[\s*]SHADER_NAME[\s*]([A-Za-z0-9_-]+)[\s*]/.exec(r)?.[1]??e}var wt=class extends l{get[Symbol.toStringTag](){return"Framebuffer"}width;height;constructor(e,t={}){super(e,t,wt.defaultProps),this.width=this.props.width,this.height=this.props.height}clone(e){let t=this.colorAttachments.map(s=>s.texture.clone(e)),i=this.depthStencilAttachment&&this.depthStencilAttachment.texture.clone(e);return this.device.createFramebuffer({...this.props,...e,colorAttachments:t,depthStencilAttachment:i})}resize(e){let t=!e;if(e){let[i,s]=Array.isArray(e)?e:[e.width,e.height];t=t||s!==this.height||i!==this.width,this.width=i,this.height=s}t&&(d.log(2,`Resizing framebuffer ${this.id} to ${this.width}x${this.height}`)(),this.resizeAttachments(this.width,this.height))}autoCreateAttachmentTextures(){if(this.props.colorAttachments.length===0&&!this.props.depthStencilAttachment)throw new Error("Framebuffer has noattachments");this.colorAttachments=this.props.colorAttachments.map((t,i)=>{if(typeof t=="string"){let s=this.createColorTexture(t,i);return this.attachResource(s),s.view}return t instanceof g?t.view:t});let e=this.props.depthStencilAttachment;if(e)if(typeof e=="string"){let t=this.createDepthStencilTexture(e);this.attachResource(t),this.depthStencilAttachment=t.view}else e instanceof g?this.depthStencilAttachment=e.view:this.depthStencilAttachment=e}createColorTexture(e,t){return this.device.createTexture({id:`${this.id}-color-attachment-${t}`,usage:g.RENDER_ATTACHMENT,format:e,width:this.width,height:this.height,sampler:{magFilter:"linear",minFilter:"linear"}})}createDepthStencilTexture(e){return this.device.createTexture({id:`${this.id}-depth-stencil-attachment`,usage:g.RENDER_ATTACHMENT,format:e,width:this.width,height:this.height})}resizeAttachments(e,t){if(this.colorAttachments.forEach((i,s)=>{let n=i.texture.clone({width:e,height:t});this.destroyAttachedResource(i),this.colorAttachments[s]=n.view,this.attachResource(n.view)}),this.depthStencilAttachment){let i=this.depthStencilAttachment.texture.clone({width:e,height:t});this.destroyAttachedResource(this.depthStencilAttachment),this.depthStencilAttachment=i.view,this.attachResource(i)}this.updateAttachments()}},ae=wt;u(ae,"defaultProps",{...l.defaultProps,width:1,height:1,colorAttachments:[],depthStencilAttachment:null});var _t=class extends l{get[Symbol.toStringTag](){return"RenderPipeline"}shaderLayout;bufferLayout;linkStatus="pending";hash="";sharedRenderPipeline=null;get isPending(){return this.linkStatus==="pending"||this.vs.compilationStatus==="pending"||this.fs?.compilationStatus==="pending"}get isErrored(){return this.linkStatus==="error"||this.vs.compilationStatus==="error"||this.fs?.compilationStatus==="error"}constructor(e,t){super(e,t,_t.defaultProps),this.shaderLayout=this.props.shaderLayout,this.bufferLayout=this.props.bufferLayout||[],this.sharedRenderPipeline=this.props._sharedRenderPipeline||null}},T=_t;u(T,"defaultProps",{...l.defaultProps,vs:null,vertexEntryPoint:"vertexMain",vsConstants:{},fs:null,fragmentEntryPoint:"fragmentMain",fsConstants:{},shaderLayout:null,bufferLayout:[],topology:"triangle-list",colorAttachmentFormats:void 0,depthStencilAttachmentFormat:void 0,parameters:{},varyings:void 0,bufferMode:void 0,disableWarnings:!1,_sharedRenderPipeline:void 0,bindings:void 0,bindGroups:void 0});var je=class extends l{get[Symbol.toStringTag](){return"SharedRenderPipeline"}constructor(e,t){super(e,t,{...l.defaultProps,handle:void 0,vs:void 0,fs:void 0,varyings:void 0,bufferMode:void 0})}};var vt=class extends l{get[Symbol.toStringTag](){return"ComputePipeline"}hash="";shaderLayout;constructor(e,t){super(e,t,vt.defaultProps),this.shaderLayout=t.shaderLayout}},$=vt;u($,"defaultProps",{...l.defaultProps,shader:void 0,entryPoint:void 0,constants:{},shaderLayout:void 0});var Pt=class{static getDefaultPipelineFactory(e){let t=e.getModuleData("@luma.gl/core");return t.defaultPipelineFactory||=new Pt(e),t.defaultPipelineFactory}device;_hashCounter=0;_hashes={};_renderPipelineCache={};_computePipelineCache={};_sharedRenderPipelineCache={};get[Symbol.toStringTag](){return"PipelineFactory"}toString(){return`PipelineFactory(${this.device.id})`}constructor(e){this.device=e}createRenderPipeline(e){if(!this.device.props._cachePipelines)return this.device.createRenderPipeline(e);let t={...T.defaultProps,...e},i=this._renderPipelineCache,s=this._hashRenderPipeline(t),n=i[s]?.resource;if(n)i[s].useCount++,this.device.props.debugFactories&&d.log(3,`${this}: ${i[s].resource} reused, count=${i[s].useCount}, (id=${e.id})`)();else{let o=this.device.type==="webgl"&&this.device.props._sharePipelines?this.createSharedRenderPipeline(t):void 0;n=this.device.createRenderPipeline({...t,id:t.id?`${t.id}-cached`:P("unnamed-cached"),_sharedRenderPipeline:o}),n.hash=s,i[s]={resource:n,useCount:1},this.device.props.debugFactories&&d.log(3,`${this}: ${n} created, count=${i[s].useCount}`)()}return n}createComputePipeline(e){if(!this.device.props._cachePipelines)return this.device.createComputePipeline(e);let t={...$.defaultProps,...e},i=this._computePipelineCache,s=this._hashComputePipeline(t),n=i[s]?.resource;return n?(i[s].useCount++,this.device.props.debugFactories&&d.log(3,`${this}: ${i[s].resource} reused, count=${i[s].useCount}, (id=${e.id})`)()):(n=this.device.createComputePipeline({...t,id:t.id?`${t.id}-cached`:void 0}),n.hash=s,i[s]={resource:n,useCount:1},this.device.props.debugFactories&&d.log(3,`${this}: ${n} created, count=${i[s].useCount}`)()),n}release(e){if(!this.device.props._cachePipelines){e.destroy();return}let t=this._getCache(e),i=e.hash;t[i].useCount--,t[i].useCount===0?(this._destroyPipeline(e),this.device.props.debugFactories&&d.log(3,`${this}: ${e} released and destroyed`)()):t[i].useCount<0?(d.error(`${this}: ${e} released, useCount < 0, resetting`)(),t[i].useCount=0):this.device.props.debugFactories&&d.log(3,`${this}: ${e} released, count=${t[i].useCount}`)()}createSharedRenderPipeline(e){let t=this._hashSharedRenderPipeline(e),i=this._sharedRenderPipelineCache[t];return i||(i={resource:this.device._createSharedRenderPipelineWebGL(e),useCount:0},this._sharedRenderPipelineCache[t]=i),i.useCount++,i.resource}releaseSharedRenderPipeline(e){if(!e.sharedRenderPipeline)return;let t=this._hashSharedRenderPipeline(e.sharedRenderPipeline.props),i=this._sharedRenderPipelineCache[t];i&&(i.useCount--,i.useCount===0&&(i.resource.destroy(),delete this._sharedRenderPipelineCache[t]))}_destroyPipeline(e){let t=this._getCache(e);return this.device.props._destroyPipelines?(delete t[e.hash],e.destroy(),e instanceof T&&this.releaseSharedRenderPipeline(e),!0):!1}_getCache(e){let t;if(e instanceof $&&(t=this._computePipelineCache),e instanceof T&&(t=this._renderPipelineCache),!t)throw new Error(`${this}`);if(!t[e.hash])throw new Error(`${this}: ${e} matched incorrect entry`);return t}_hashComputePipeline(e){let{type:t}=this.device,i=this._getHash(e.shader.source),s=this._getHash(JSON.stringify(e.shaderLayout));return`${t}/C/${i}SL${s}`}_hashRenderPipeline(e){let t=e.vs?this._getHash(e.vs.source):0,i=e.fs?this._getHash(e.fs.source):0,s=this._getWebGLVaryingHash(e),n=this._getHash(JSON.stringify(e.shaderLayout)),o=this._getHash(JSON.stringify(e.bufferLayout)),{type:a}=this.device;switch(a){case"webgl":let c=this._getHash(JSON.stringify(e.parameters));return`${a}/R/${t}/${i}V${s}T${e.topology}P${c}SL${n}BL${o}`;case"webgpu":default:let f=this._getHash(JSON.stringify({vertexEntryPoint:e.vertexEntryPoint,fragmentEntryPoint:e.fragmentEntryPoint})),h=this._getHash(JSON.stringify(e.parameters)),b=this._getWebGPUAttachmentHash(e);return`${a}/R/${t}/${i}V${s}T${e.topology}EP${f}P${h}SL${n}BL${o}A${b}`}}_hashSharedRenderPipeline(e){let t=e.vs?this._getHash(e.vs.source):0,i=e.fs?this._getHash(e.fs.source):0,s=this._getWebGLVaryingHash(e);return`webgl/S/${t}/${i}V${s}`}_getHash(e){return this._hashes[e]===void 0&&(this._hashes[e]=this._hashCounter++),this._hashes[e]}_getWebGLVaryingHash(e){let{varyings:t=[],bufferMode:i=null}=e;return this._getHash(JSON.stringify({varyings:t,bufferMode:i}))}_getWebGPUAttachmentHash(e){let t=e.colorAttachmentFormats??[this.device.preferredColorFormat],i=e.parameters?.depthWriteEnabled?e.depthStencilAttachmentFormat||this.device.preferredDepthFormat:null;return this._getHash(JSON.stringify({colorAttachmentFormats:t,depthStencilAttachmentFormat:i}))}},ce=Pt;u(ce,"defaultProps",{...T.defaultProps});var St=class{static getDefaultShaderFactory(e){let t=e.getModuleData("@luma.gl/core");return t.defaultShaderFactory||=new St(e),t.defaultShaderFactory}device;_cache={};get[Symbol.toStringTag](){return"ShaderFactory"}toString(){return`${this[Symbol.toStringTag]}(${this.device.id})`}constructor(e){this.device=e}createShader(e){if(!this.device.props._cacheShaders)return this.device.createShader(e);let t=this._hashShader(e),i=this._cache[t];if(i)i.useCount++,this.device.props.debugFactories&&d.log(3,`${this}: Reusing shader ${i.resource.id} count=${i.useCount}`)();else{let s=this.device.createShader({...e,id:e.id?`${e.id}-cached`:void 0});this._cache[t]=i={resource:s,useCount:1},this.device.props.debugFactories&&d.log(3,`${this}: Created new shader ${s.id}`)()}return i.resource}release(e){if(!this.device.props._cacheShaders){e.destroy();return}let t=this._hashShader(e),i=this._cache[t];if(i)if(i.useCount--,i.useCount===0)this.device.props._destroyShaders&&(delete this._cache[t],i.resource.destroy(),this.device.props.debugFactories&&d.log(3,`${this}: Releasing shader ${e.id}, destroyed`)());else{if(i.useCount<0)throw new Error(`ShaderFactory: Shader ${e.id} released too many times`);this.device.props.debugFactories&&d.log(3,`${this}: Releasing shader ${e.id} count=${i.useCount}`)()}}_hashShader(e){return`${e.stage}:${e.source}`}},ue=St;u(ue,"defaultProps",{...W.defaultProps});function Tt(r,e,t){let i=r.bindings.find(s=>s.name===e||`${s.name.toLocaleLowerCase()}uniforms`===e.toLocaleLowerCase());return!i&&!t?.ignoreWarnings&&d.warn(`Binding ${e} not set: Not found in shader layout.`)(),i||null}function Qe(r,e){if(!e)return{};if(Fi(e))return Object.fromEntries(Object.entries(e).map(([s,n])=>[Number(s),{...n}]));let t={};for(let[i,s]of Object.entries(e)){let o=Tt(r,i)?.group??0;t[o]||={},t[o][i]=s}return t}function mr(r){let e={};for(let t of Object.values(r))Object.assign(e,t);return e}function Fi(r){let e=Object.keys(r);return e.length>0&&e.every(t=>/^\d+$/.test(t))}var Ct=class{device;_layoutCacheByPipeline=new WeakMap;_bindGroupCacheByLayout=new WeakMap;constructor(e){this.device=e}getBindGroups(e,t,i){if(this.device.type!=="webgpu"||e.shaderLayout.bindings.length===0)return{};let s=Qe(e.shaderLayout,t),n={};for(let o of Wi(e.shaderLayout.bindings)){let a=s[o],c=this._getBindGroupLayout(e,o),f=Ni(e,e.shaderLayout,o);if(!a||Object.keys(a).length===0){zi(e.shaderLayout.bindings,o)||(n[o]=this._getEmptyBindGroup(c,e.shaderLayout,o,f));continue}let h=i?.[o];if(h){let b=this._getLayoutBindGroupCache(c);if(b.bindGroupsBySource.has(h)){n[o]=b.bindGroupsBySource.get(h)||null;continue}let A=this.device._createBindGroupWebGPU(c,e.shaderLayout,a,o,f);b.bindGroupsBySource.set(h,A),n[o]=A}else n[o]=this.device._createBindGroupWebGPU(c,e.shaderLayout,a,o,f)}return n}_getBindGroupLayout(e,t){let i=this._layoutCacheByPipeline.get(e);return i||(i={},this._layoutCacheByPipeline.set(e,i)),i[t]||=this.device._createBindGroupLayoutWebGPU(e,t),i[t]}_getEmptyBindGroup(e,t,i,s){let n=this._getLayoutBindGroupCache(e);return n.emptyBindGroup||=this.device._createBindGroupWebGPU(e,t,{},i,s)||null,n.emptyBindGroup}_getLayoutBindGroupCache(e){let t=this._bindGroupCacheByLayout.get(e);return t||(t={bindGroupsBySource:new WeakMap},this._bindGroupCacheByLayout.set(e,t)),t}};function pr(r){return r._factories.bindGroupFactory||=new Ct(r),r._factories.bindGroupFactory}function Wi(r){let e=r.reduce((t,i)=>Math.max(t,i.group),-1);return Array.from({length:e+1},(t,i)=>i)}function zi(r,e){return r.some(t=>t.group===e)}function Ni(r,e,t){let i=e.bindings.filter(n=>n.group===t).sort((n,o)=>n.location-o.location).map(n=>n.name),s=i.length>0?i.join(","):"empty";return`${r.id}/group${t}[${s}]`}var z=class extends l{get[Symbol.toStringTag](){return"RenderPass"}constructor(e,t){t=z.normalizeProps(e,t),super(e,t,z.defaultProps)}static normalizeProps(e,t){return t}},I=z;u(I,"defaultClearColor",[0,0,0,1]),u(I,"defaultClearDepth",1),u(I,"defaultClearStencil",0),u(I,"defaultProps",{...l.defaultProps,framebuffer:null,parameters:void 0,clearColor:z.defaultClearColor,clearColors:void 0,clearDepth:z.defaultClearDepth,clearStencil:z.defaultClearStencil,depthReadOnly:!1,stencilReadOnly:!1,discard:!1,occlusionQuerySet:void 0,timestampQuerySet:void 0,beginTimestampIndex:void 0,endTimestampIndex:void 0});var At=class extends l{constructor(e,t){super(e,t,At.defaultProps)}get[Symbol.toStringTag](){return"ComputePass"}},le=At;u(le,"defaultProps",{...l.defaultProps,timestampQuerySet:void 0,beginTimestampIndex:void 0,endTimestampIndex:void 0});var Et=class extends l{get[Symbol.toStringTag](){return"CommandEncoder"}_timeProfilingQuerySet=null;_timeProfilingSlotCount=0;_gpuTimeMs;constructor(e,t){super(e,t,Et.defaultProps),this._timeProfilingQuerySet=t.timeProfilingQuerySet??null,this._timeProfilingSlotCount=0,this._gpuTimeMs=void 0}async resolveTimeProfilingQuerySet(){if(this._gpuTimeMs=void 0,!this._timeProfilingQuerySet)return;let e=Math.floor(this._timeProfilingSlotCount/2);if(e<=0)return;let t=e*2,i=await this._timeProfilingQuerySet.readResults({firstQuery:0,queryCount:t}),s=0n;for(let n=0;n<t;n+=2)s+=i[n+1]-i[n];this._gpuTimeMs=Number(s)/1e6}getTimeProfilingSlotCount(){return this._timeProfilingSlotCount}getTimeProfilingQuerySet(){return this._timeProfilingQuerySet}_applyTimeProfilingToPassProps(e){let t=e||{};if(!this._supportsTimestampQueries()||!this._timeProfilingQuerySet||t.timestampQuerySet!==void 0||t.beginTimestampIndex!==void 0||t.endTimestampIndex!==void 0)return t;let i=this._timeProfilingSlotCount;return i+1>=this._timeProfilingQuerySet.props.count?t:(this._timeProfilingSlotCount+=2,{...t,timestampQuerySet:this._timeProfilingQuerySet,beginTimestampIndex:i,endTimestampIndex:i+1})}_supportsTimestampQueries(){return this.device.features.has("timestamp-query")}},fe=Et;u(fe,"defaultProps",{...l.defaultProps,measureExecutionTime:void 0,timeProfilingQuerySet:void 0});var Rt=class extends l{get[Symbol.toStringTag](){return"CommandBuffer"}constructor(e,t){super(e,t,Rt.defaultProps)}},de=Rt;u(de,"defaultProps",{...l.defaultProps});function he(r){let e=Ye(r),t=Qi[e];if(!t)throw new Error(`Unsupported variable shader type: ${r}`);return t}function Bt(r){let e=gr(r),t=ji[e];if(!t)throw new Error(`Unsupported attribute shader type: ${r}`);let[i,s]=t,n=i==="i32"||i==="u32",o=i!=="u32",a=Vi[i]*s;return{primitiveType:i,components:s,byteLength:a,integer:n,signed:o}}var Lt=class{getVariableShaderTypeInfo(e){return he(e)}getAttributeShaderTypeInfo(e){return Bt(e)}makeShaderAttributeType(e,t){return Hi(e,t)}resolveAttributeShaderTypeAlias(e){return gr(e)}resolveVariableShaderTypeAlias(e){return Ye(e)}};function Hi(r,e){return e===1?r:`vec${e}<${r}>`}function gr(r){return Yi[r]||r}function Ye(r){return Xi[r]||r}var Xe=new Lt,Vi={f32:4,f16:2,i32:4,u32:4},ji={f32:["f32",1],"vec2<f32>":["f32",2],"vec3<f32>":["f32",3],"vec4<f32>":["f32",4],f16:["f16",1],"vec2<f16>":["f16",2],"vec3<f16>":["f16",3],"vec4<f16>":["f16",4],i32:["i32",1],"vec2<i32>":["i32",2],"vec3<i32>":["i32",3],"vec4<i32>":["i32",4],u32:["u32",1],"vec2<u32>":["u32",2],"vec3<u32>":["u32",3],"vec4<u32>":["u32",4]},Qi={f32:{type:"f32",components:1},f16:{type:"f16",components:1},i32:{type:"i32",components:1},u32:{type:"u32",components:1},"vec2<f32>":{type:"f32",components:2},"vec3<f32>":{type:"f32",components:3},"vec4<f32>":{type:"f32",components:4},"vec2<f16>":{type:"f16",components:2},"vec3<f16>":{type:"f16",components:3},"vec4<f16>":{type:"f16",components:4},"vec2<i32>":{type:"i32",components:2},"vec3<i32>":{type:"i32",components:3},"vec4<i32>":{type:"i32",components:4},"vec2<u32>":{type:"u32",components:2},"vec3<u32>":{type:"u32",components:3},"vec4<u32>":{type:"u32",components:4},"mat2x2<f32>":{type:"f32",components:4},"mat2x3<f32>":{type:"f32",components:6},"mat2x4<f32>":{type:"f32",components:8},"mat3x2<f32>":{type:"f32",components:6},"mat3x3<f32>":{type:"f32",components:9},"mat3x4<f32>":{type:"f32",components:12},"mat4x2<f32>":{type:"f32",components:8},"mat4x3<f32>":{type:"f32",components:12},"mat4x4<f32>":{type:"f32",components:16},"mat2x2<f16>":{type:"f16",components:4},"mat2x3<f16>":{type:"f16",components:6},"mat2x4<f16>":{type:"f16",components:8},"mat3x2<f16>":{type:"f16",components:6},"mat3x3<f16>":{type:"f16",components:9},"mat3x4<f16>":{type:"f16",components:12},"mat4x2<f16>":{type:"f16",components:8},"mat4x3<f16>":{type:"f16",components:12},"mat4x4<f16>":{type:"f16",components:16},"mat2x2<i32>":{type:"i32",components:4},"mat2x3<i32>":{type:"i32",components:6},"mat2x4<i32>":{type:"i32",components:8},"mat3x2<i32>":{type:"i32",components:6},"mat3x3<i32>":{type:"i32",components:9},"mat3x4<i32>":{type:"i32",components:12},"mat4x2<i32>":{type:"i32",components:8},"mat4x3<i32>":{type:"i32",components:12},"mat4x4<i32>":{type:"i32",components:16},"mat2x2<u32>":{type:"u32",components:4},"mat2x3<u32>":{type:"u32",components:6},"mat2x4<u32>":{type:"u32",components:8},"mat3x2<u32>":{type:"u32",components:6},"mat3x3<u32>":{type:"u32",components:9},"mat3x4<u32>":{type:"u32",components:12},"mat4x2<u32>":{type:"u32",components:8},"mat4x3<u32>":{type:"u32",components:12},"mat4x4<u32>":{type:"u32",components:16}},Yi={vec2i:"vec2<i32>",vec3i:"vec3<i32>",vec4i:"vec4<i32>",vec2u:"vec2<u32>",vec3u:"vec3<u32>",vec4u:"vec4<u32>",vec2f:"vec2<f32>",vec3f:"vec3<f32>",vec4f:"vec4<f32>",vec2h:"vec2<f16>",vec3h:"vec3<f16>",vec4h:"vec4<f16>"},Xi={vec2i:"vec2<i32>",vec3i:"vec3<i32>",vec4i:"vec4<i32>",vec2u:"vec2<u32>",vec3u:"vec3<u32>",vec4u:"vec4<u32>",vec2f:"vec2<f32>",vec3f:"vec3<f32>",vec4f:"vec4<f32>",vec2h:"vec2<f16>",vec3h:"vec3<f16>",vec4h:"vec4<f16>",mat2x2f:"mat2x2<f32>",mat2x3f:"mat2x3<f32>",mat2x4f:"mat2x4<f32>",mat3x2f:"mat3x2<f32>",mat3x3f:"mat3x3<f32>",mat3x4f:"mat3x4<f32>",mat4x2f:"mat4x2<f32>",mat4x3f:"mat4x3<f32>",mat4x4f:"mat4x4<f32>",mat2x2i:"mat2x2<i32>",mat2x3i:"mat2x3<i32>",mat2x4i:"mat2x4<i32>",mat3x2i:"mat3x2<i32>",mat3x3i:"mat3x3<i32>",mat3x4i:"mat3x4<i32>",mat4x2i:"mat4x2<i32>",mat4x3i:"mat4x3<i32>",mat4x4i:"mat4x4<i32>",mat2x2u:"mat2x2<u32>",mat2x3u:"mat2x3<u32>",mat2x4u:"mat2x4<u32>",mat3x2u:"mat3x2<u32>",mat3x3u:"mat3x3<u32>",mat3x4u:"mat3x4<u32>",mat4x2u:"mat4x2<u32>",mat4x3u:"mat4x3<u32>",mat4x4u:"mat4x4<u32>",mat2x2h:"mat2x2<f16>",mat2x3h:"mat2x3<f16>",mat2x4h:"mat2x4<f16>",mat3x2h:"mat3x2<f16>",mat3x3h:"mat3x3<f16>",mat3x4h:"mat3x4<f16>",mat4x2h:"mat4x2<f16>",mat4x3h:"mat4x3<f16>",mat4x4h:"mat4x4<f16>"};function Mt(r,e){let t={};for(let i of r.attributes){let s=qi(r,e,i.name);s&&(t[i.name]=s)}return t}function br(r,e,t=16){let i=Mt(r,e),s=new Array(t).fill(null);for(let n of Object.values(i))s[n.location]=n;return s}function qi(r,e,t){let i=Ji(r,t),s=Ki(e,t);if(!i)return null;let n=Xe.getAttributeShaderTypeInfo(i.type),o=M.getCompatibleVertexFormat(n),a=s?.vertexFormat||o,c=M.getVertexFormatInfo(a);return{attributeName:s?.attributeName||i.name,bufferName:s?.bufferName||i.name,location:i.location,shaderType:i.type,primitiveType:n.primitiveType,shaderComponents:n.components,vertexFormat:a,bufferDataType:c.type,bufferComponents:c.components,normalized:c.normalized,integer:n.integer,stepMode:s?.stepMode||i.stepMode||"vertex",byteOffset:s?.byteOffset||0,byteStride:s?.byteStride||0}}function Ji(r,e){let t=r.attributes.find(i=>i.name===e);return t||d.warn(`shader layout attribute "${e}" not present in shader`),t||null}function Ki(r,e){Zi(r);let t=es(r,e);return t||(t=ts(r,e),t)?t:(d.warn(`layout for attribute "${e}" not present in buffer layout`),null)}function Zi(r){for(let e of r)(e.attributes&&e.format||!e.attributes&&!e.format)&&d.warn(`BufferLayout ${name} must have either 'attributes' or 'format' field`)}function es(r,e){for(let t of r)if(t.format&&t.name===e)return{attributeName:t.name,bufferName:e,stepMode:t.stepMode,vertexFormat:t.format,byteOffset:0,byteStride:t.byteStride||0};return null}function ts(r,e){for(let t of r){let i=t.byteStride;if(typeof t.byteStride!="number")for(let n of t.attributes||[]){let o=M.getVertexFormatInfo(n.format);i+=o.byteLength}let s=t.attributes?.find(n=>n.attribute===e);if(s)return{attributeName:s.attribute,bufferName:t.name,stepMode:t.stepMode,vertexFormat:s.format,byteOffset:s.byteOffset,byteStride:i}}return null}var Dt=class extends l{get[Symbol.toStringTag](){return"VertexArray"}maxVertexAttributes;attributeInfos;indexBuffer=null;attributes;constructor(e,t){super(e,t,Dt.defaultProps),this.maxVertexAttributes=e.limits.maxVertexAttributes,this.attributes=new Array(this.maxVertexAttributes).fill(null),this.attributeInfos=br(t.shaderLayout,t.bufferLayout,this.maxVertexAttributes)}setConstantWebGL(e,t){this.device.reportError(new Error("constant attributes not supported"),this)()}},me=Dt;u(me,"defaultProps",{...l.defaultProps,shaderLayout:void 0,bufferLayout:[]});var $t=class extends l{get[Symbol.toStringTag](){return"TransformFeedback"}constructor(e,t){super(e,t,$t.defaultProps)}},pe=$t;u(pe,"defaultProps",{...l.defaultProps,layout:void 0,buffers:{}});var It=class extends l{get[Symbol.toStringTag](){return"QuerySet"}constructor(e,t){super(e,t,It.defaultProps)}},ge=It;u(ge,"defaultProps",{...l.defaultProps,type:void 0,count:void 0});var kt=class extends l{get[Symbol.toStringTag](){return"Fence"}constructor(e,t={}){super(e,t,kt.defaultProps)}},be=kt;u(be,"defaultProps",{...l.defaultProps});var Ut=class extends l{get[Symbol.toStringTag](){return"PipelineLayout"}constructor(e,t){super(e,t,Ut.defaultProps)}},ye=Ut;u(ye,"defaultProps",{...l.defaultProps,shaderLayout:{attributes:[],bindings:[]}});function C(r,e){switch(e){case 1:return r;case 2:return r+r%2;default:return r+(4-r%4)%4}}function yr(r){let[,,,,e]=rs[r];return e}var rs={uint8:["uint8","u32",1,!1,Uint8Array],sint8:["sint8","i32",1,!1,Int8Array],unorm8:["uint8","f32",1,!0,Uint8Array],snorm8:["sint8","f32",1,!0,Int8Array],uint16:["uint16","u32",2,!1,Uint16Array],sint16:["sint16","i32",2,!1,Int16Array],unorm16:["uint16","u32",2,!0,Uint16Array],snorm16:["sint16","i32",2,!0,Int16Array],float16:["float16","f16",2,!1,Uint16Array],float32:["float32","f32",4,!1,Float32Array],uint32:["uint32","u32",4,!1,Uint32Array],sint32:["sint32","i32",4,!1,Int32Array]};function qe(r,e={}){let t={...r},i=e.layout??"std140",s={},n=0;for(let[o,a]of Object.entries(t))n=Ot(s,o,a,n,i);return n=C(n,k(t,i)),{layout:i,byteLength:n*4,uniformTypes:t,fields:s}}function xe(r,e){let t=Ye(r),i=he(t),s=/^mat(\d)x(\d)<.+>$/.exec(t);if(s){let o=Number(s[1]),a=Number(s[2]),c=xr(a,t,i.type,e),f=ss(c.size,c.alignment,e);return{alignment:c.alignment,size:o*f,components:o*a,columns:o,rows:a,columnStride:f,shaderType:t,type:i.type}}let n=/^vec(\d)<.+>$/.exec(t);return n?xr(Number(n[1]),t,i.type,e):{alignment:1,size:1,components:1,columns:1,rows:1,columnStride:1,shaderType:t,type:i.type}}function Gt(r){return Boolean(r)&&typeof r=="object"&&!Array.isArray(r)}function Ot(r,e,t,i,s){if(typeof t=="string"){let n=xe(t,s),o=C(i,n.alignment);return r[e]={offset:o,...n},o+n.size}if(Array.isArray(t)){if(Array.isArray(t[0]))throw new Error(`Nested arrays are not supported for ${e}`);let n=t[0],o=t[1],a=_r(n,s),c=C(i,k(t,s));for(let f=0;f<o;f++)Ot(r,`${e}[${f}]`,n,c+f*a,s);return c+a*o}if(Gt(t)){let n=k(t,s),o=C(i,n);for(let[a,c]of Object.entries(t))o=Ot(r,`${e}.${a}`,c,o,s);return C(o,n)}throw new Error(`Unsupported CompositeShaderType for ${e}`)}function wr(r,e){if(typeof r=="string")return xe(r,e).size;if(Array.isArray(r)){let i=r[0],s=r[1];if(Array.isArray(i))throw new Error("Nested arrays are not supported");return _r(i,e)*s}let t=0;for(let i of Object.values(r)){let s=i;t=C(t,k(s,e)),t+=wr(s,e)}return C(t,k(r,e))}function k(r,e){if(typeof r=="string")return xe(r,e).alignment;if(Array.isArray(r)){let i=r[0],s=k(i,e);return vr(e)?Math.max(s,4):s}let t=1;for(let i of Object.values(r)){let s=k(i,e);t=Math.max(t,s)}return ns(e)?Math.max(t,4):t}function xr(r,e,t,i){return{alignment:r===2?2:4,size:r===3?3:r,components:r,columns:1,rows:r,columnStride:r===3?3:r,shaderType:e,type:t}}function _r(r,e){let t=wr(r,e),i=k(r,e);return is(t,i,e)}function is(r,e,t){return C(r,vr(t)?4:e)}function ss(r,e,t){return t==="std140"?4:C(r,e)}function vr(r){return r==="std140"||r==="wgsl-uniform"}function ns(r){return r==="std140"||r==="wgsl-uniform"}var Je;function Ft(r){return(!Je||Je.byteLength<r)&&(Je=new ArrayBuffer(r)),Je}function Pr(r,e){let t=Ft(r.BYTES_PER_ELEMENT*e);return new r(t,0,e)}function os(r){return ArrayBuffer.isView(r)&&!(r instanceof DataView)}function Q(r){return Array.isArray(r)?r.length===0||typeof r[0]=="number":os(r)}var Y=class{layout;constructor(e){this.layout=e}has(e){return Boolean(this.layout.fields[e])}get(e){let t=this.layout.fields[e];return t?{offset:t.offset,size:t.size}:void 0}getFlatUniformValues(e){let t={};for(let[i,s]of Object.entries(e)){let n=this.layout.uniformTypes[i];n?this._flattenCompositeValue(t,i,n,s):this.layout.fields[i]&&(t[i]=s)}return t}getData(e){let t=Ft(this.layout.byteLength);new Uint8Array(t,0,this.layout.byteLength).fill(0);let i={i32:new Int32Array(t),u32:new Uint32Array(t),f32:new Float32Array(t),f16:new Uint16Array(t)},s=this.getFlatUniformValues(e);for(let[n,o]of Object.entries(s))this._writeLeafValue(i,n,o);return new Uint8Array(t,0,this.layout.byteLength)}_flattenCompositeValue(e,t,i,s){if(s!==void 0){if(typeof i=="string"||this.layout.fields[t]){e[t]=s;return}if(Array.isArray(i)){let n=i[0],o=i[1];if(Array.isArray(n))throw new Error(`Nested arrays are not supported for ${t}`);if(typeof n=="string"&&Q(s)){this._flattenPackedArray(e,t,n,o,s);return}if(!Array.isArray(s)){d.warn(`Unsupported uniform array value for ${t}:`,s)();return}for(let a=0;a<Math.min(s.length,o);a++){let c=s[a];c!==void 0&&this._flattenCompositeValue(e,`${t}[${a}]`,n,c)}return}if(Gt(i)&&as(s)){for(let[n,o]of Object.entries(s)){if(o===void 0)continue;let a=`${t}.${n}`;this._flattenCompositeValue(e,a,i[n],o)}return}d.warn(`Unsupported uniform value for ${t}:`,s)()}}_flattenPackedArray(e,t,i,s,n){let o=n,c=xe(i,this.layout.layout).components;for(let f=0;f<s;f++){let h=f*c;if(h>=o.length)break;c===1?e[`${t}[${f}]`]=Number(o[h]):e[`${t}[${f}]`]=cs(n,h,h+c)}}_writeLeafValue(e,t,i){let s=this.layout.fields[t];if(!s){d.warn(`Uniform ${t} not found in layout`)();return}let{type:n,components:o,columns:a,rows:c,offset:f,columnStride:h}=s,b=e[n];if(o===1){b[f]=Number(i);return}let A=i;if(a===1){for(let _=0;_<o;_++)b[f+_]=Number(A[_]??0);return}let Ze=0;for(let _=0;_<a;_++){let q=f+_*h;for(let J=0;J<c;J++)b[q+J]=Number(A[Ze++]??0)}}};function as(r){return Boolean(r)&&typeof r=="object"&&!Array.isArray(r)&&!ArrayBuffer.isView(r)}function cs(r,e,t){return Array.prototype.slice.call(r,e,t)}var us=128;function Sr(r,e,t=16){if(r===e)return!0;let i=r,s=e;if(!Q(i)||!Q(s)||i.length!==s.length)return!1;let n=Math.min(t,us);if(i.length>n)return!1;for(let o=0;o<i.length;++o)if(s[o]!==i[o])return!1;return!0}function Tr(r){return Q(r)?r.slice():r}var X=class{name;uniforms={};modifiedUniforms={};modified=!0;bindingLayout={};needsRedraw="initialized";constructor(e){if(this.name=e?.name||"unnamed",e?.name&&e?.shaderLayout){let t=e?.shaderLayout.bindings?.find(s=>s.type==="uniform"&&s.name===e?.name);if(!t)throw new Error(e?.name);let i=t;for(let s of i.uniforms||[])this.bindingLayout[s.name]=s}}setUniforms(e){for(let[t,i]of Object.entries(e))this._setUniform(t,i),this.needsRedraw||this.setNeedsRedraw(`${this.name}.${t}=${i}`)}setNeedsRedraw(e){this.needsRedraw=this.needsRedraw||e}getAllUniforms(){return this.modifiedUniforms={},this.needsRedraw=!1,this.uniforms||{}}_setUniform(e,t){Sr(this.uniforms[e],t)||(this.uniforms[e]=Tr(t),this.modifiedUniforms[e]=!0,this.modified=!0)}};var ls=1024,Ke=class{device;uniformBlocks=new Map;shaderBlockLayouts=new Map;shaderBlockWriters=new Map;uniformBuffers=new Map;constructor(e,t){this.device=e;for(let[i,s]of Object.entries(t)){let n=i,o=qe(s.uniformTypes??{},{layout:s.layout??fs(e)}),a=new Y(o);this.shaderBlockLayouts.set(n,o),this.shaderBlockWriters.set(n,a);let c=new X({name:i});c.setUniforms(a.getFlatUniformValues(s.defaultUniforms||{})),this.uniformBlocks.set(n,c)}}destroy(){for(let e of this.uniformBuffers.values())e.destroy()}setUniforms(e){for(let[t,i]of Object.entries(e)){let s=t,o=this.shaderBlockWriters.get(s)?.getFlatUniformValues(i||{});this.uniformBlocks.get(s)?.setUniforms(o||{})}this.updateUniformBuffers()}getUniformBufferByteLength(e){let t=this.shaderBlockLayouts.get(e)?.byteLength||0;return Math.max(t,ls)}getUniformBufferData(e){let t=this.uniformBlocks.get(e)?.getAllUniforms()||{};return this.shaderBlockWriters.get(e)?.getData(t)||new Uint8Array(0)}createUniformBuffer(e,t){t&&this.setUniforms(t);let i=this.getUniformBufferByteLength(e),s=this.device.createBuffer({usage:p.UNIFORM|p.COPY_DST,byteLength:i}),n=this.getUniformBufferData(e);return s.write(n),s}getManagedUniformBuffer(e){if(!this.uniformBuffers.get(e)){let t=this.getUniformBufferByteLength(e),i=this.device.createBuffer({usage:p.UNIFORM|p.COPY_DST,byteLength:t});this.uniformBuffers.set(e,i)}return this.uniformBuffers.get(e)}updateUniformBuffers(){let e=!1;for(let t of this.uniformBlocks.keys()){let i=this.updateUniformBuffer(t);e||=i}return e&&d.log(3,`UniformStore.updateUniformBuffers(): ${e}`)(),e}updateUniformBuffer(e){let t=this.uniformBlocks.get(e),i=this.uniformBuffers.get(e),s=!1;if(i&&t?.needsRedraw){s||=t.needsRedraw;let n=this.getUniformBufferData(e);i=this.uniformBuffers.get(e),i?.write(n);let o=this.uniformBlocks.get(e)?.getAllUniforms();d.log(4,`Writing to uniform buffer ${String(e)}`,n,o)()}return s}};function fs(r){return r.type==="webgpu"?"wgsl-uniform":"std140"}function Wt(r,e,t,i=0){let s=x.getInfo(t),n=s.bytesPerPixel/s.components,{bytesPerImage:o}=e,a=o*i,c=e.bytesPerImage/n;switch(t){case"rgba8unorm":case"bgra8unorm":case"rgba8uint":return new Uint8Array(r,a,c);case"r8unorm":return new Uint8Array(r,a,c);case"r16uint":case"rgba16uint":return new Uint16Array(r,a,c);case"r32uint":case"rgba32uint":return new Uint32Array(r,a,c);case"r32float":return new Float32Array(r,a,c);case"rgba16float":return new Uint16Array(r,a,c);case"rgba32float":return new Float32Array(r,a,c);default:throw new Error(`Unsupported format: ${t}`)}}function Cr(r,e,t,i,s=0){let o=e.bytesPerImage/e.bytesPerPixel,a=i.subarray(0,o);Wt(r,e,t,s).set(a,0)}function Ar(r,e,t,i){if(e<0||e>=r.width||t<0||t>=r.height)throw new Error("Coordinates out of bounds.");let s=t*r.bytesPerRow+e*r.bytesPerPixel,n=new DataView(r.arrayBuffer,s,r.bytesPerPixel),o=0,a=[];for(let c=0;c<4;c++){let f=i[c]??0;if(f<=0)a.push(0);else{let h=ds(n,o,f);a.push(h),o+=f}}return[a[0]??0,a[1]??0,a[2]??0,a[3]??0]}function Er(r,e,t,i){let s=e;for(let n=0;n<4;n++){let o=t[n]??0,a=(1<<o)-1,c=(i[n]??0)&a;hs(r,s,o,c),s+=o}}function ds(r,e,t){if(e%8===0){let s=e/8;if(t===8&&s+1<=r.byteLength)return r.getUint8(s);if(t===16&&s+2<=r.byteLength)return r.getUint16(s,!1);if(t===32&&s+4<=r.byteLength)return r.getUint32(s,!1)}let i=0;for(let s=0;s<t;s++){let n=e+s,o=Math.floor(n/8),a=n%8,f=r.getUint8(o)>>7-a&1;i=i<<1|f}return i}function hs(r,e,t,i){if(e%8===0){let s=e/8;if(t===8&&s+1<=r.byteLength){r.setUint8(s,i&255);return}else if(t===16&&s+2<=r.byteLength){r.setUint16(s,i&65535,!1);return}else if(t===32&&s+4<=r.byteLength){r.setUint32(s,i,!1);return}}for(let s=0;s<t;s++){let n=e+s,o=Math.floor(n/8),c=1<<7-n%8,f=i>>t-1-s&1,h=r.getUint8(o);h&=~c,f&&(h|=c),r.setUint8(o,h)}}ve(we,Gr(Lr(),1));return Fr(we);})();
19
19
  return __exports__;
20
20
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luma.gl/effects",
3
- "version": "9.3.0-alpha.10",
3
+ "version": "9.3.0-alpha.11",
4
4
  "description": "Post-processing effects for luma.gl",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -52,5 +52,5 @@
52
52
  "@math.gl/core": "^4.1.0",
53
53
  "@math.gl/types": "^4.1.0"
54
54
  },
55
- "gitHead": "ca3a841517106f8608ce392440fa7f324863a84f"
55
+ "gitHead": "06f489c5d0681bdf7bb0956ca37ce5ad56b85084"
56
56
  }