@luma.gl/webgpu 9.0.11 → 9.1.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/LICENSE +34 -0
  2. package/dist/adapter/helpers/get-bind-group.d.ts +1 -1
  3. package/dist/adapter/helpers/get-bind-group.d.ts.map +1 -1
  4. package/dist/adapter/helpers/get-bind-group.js +5 -5
  5. package/dist/adapter/helpers/get-vertex-buffer-layout.d.ts.map +1 -1
  6. package/dist/adapter/helpers/get-vertex-buffer-layout.js +11 -7
  7. package/dist/adapter/helpers/webgpu-parameters.d.ts.map +1 -1
  8. package/dist/adapter/helpers/webgpu-parameters.js +27 -12
  9. package/dist/adapter/resources/webgpu-command-encoder.js +5 -5
  10. package/dist/adapter/resources/webgpu-compute-pass.d.ts.map +1 -1
  11. package/dist/adapter/resources/webgpu-compute-pass.js +1 -0
  12. package/dist/adapter/resources/webgpu-compute-pipeline.d.ts.map +1 -1
  13. package/dist/adapter/resources/webgpu-compute-pipeline.js +1 -1
  14. package/dist/adapter/resources/webgpu-external-texture.d.ts.map +1 -1
  15. package/dist/adapter/resources/webgpu-external-texture.js +1 -0
  16. package/dist/adapter/resources/webgpu-framebuffer.d.ts +3 -0
  17. package/dist/adapter/resources/webgpu-framebuffer.d.ts.map +1 -1
  18. package/dist/adapter/resources/webgpu-framebuffer.js +2 -0
  19. package/dist/adapter/resources/webgpu-render-pass.d.ts +3 -2
  20. package/dist/adapter/resources/webgpu-render-pass.d.ts.map +1 -1
  21. package/dist/adapter/resources/webgpu-render-pass.js +8 -5
  22. package/dist/adapter/resources/webgpu-render-pipeline.d.ts +2 -2
  23. package/dist/adapter/resources/webgpu-render-pipeline.d.ts.map +1 -1
  24. package/dist/adapter/resources/webgpu-render-pipeline.js +11 -17
  25. package/dist/adapter/resources/webgpu-sampler.d.ts.map +1 -1
  26. package/dist/adapter/resources/webgpu-sampler.js +2 -0
  27. package/dist/adapter/resources/webgpu-texture-view.d.ts.map +1 -1
  28. package/dist/adapter/resources/webgpu-texture.d.ts +10 -1
  29. package/dist/adapter/resources/webgpu-texture.d.ts.map +1 -1
  30. package/dist/adapter/resources/webgpu-texture.js +29 -10
  31. package/dist/adapter/resources/webgpu-vertex-array.d.ts +1 -1
  32. package/dist/adapter/resources/webgpu-vertex-array.d.ts.map +1 -1
  33. package/dist/adapter/resources/webgpu-vertex-array.js +3 -1
  34. package/dist/adapter/webgpu-canvas-context.d.ts +2 -2
  35. package/dist/adapter/webgpu-canvas-context.d.ts.map +1 -1
  36. package/dist/adapter/webgpu-device.d.ts.map +1 -1
  37. package/dist/adapter/webgpu-device.js +18 -6
  38. package/dist/dist.dev.js +114 -87
  39. package/dist/dist.min.js +1 -1
  40. package/dist/index.cjs +99 -54
  41. package/dist/index.cjs.map +2 -2
  42. package/package.json +4 -4
  43. package/src/adapter/helpers/get-bind-group.ts +6 -6
  44. package/src/adapter/helpers/get-vertex-buffer-layout.ts +14 -8
  45. package/src/adapter/helpers/webgpu-parameters.ts +29 -12
  46. package/src/adapter/resources/webgpu-command-encoder.ts +7 -7
  47. package/src/adapter/resources/webgpu-compute-pass.ts +1 -0
  48. package/src/adapter/resources/webgpu-compute-pipeline.ts +1 -6
  49. package/src/adapter/resources/webgpu-external-texture.ts +1 -0
  50. package/src/adapter/resources/webgpu-framebuffer.ts +4 -0
  51. package/src/adapter/resources/webgpu-render-pass.ts +16 -10
  52. package/src/adapter/resources/webgpu-render-pipeline.ts +11 -23
  53. package/src/adapter/resources/webgpu-sampler.ts +3 -0
  54. package/src/adapter/resources/webgpu-texture-view.ts +15 -0
  55. package/src/adapter/resources/webgpu-texture.ts +55 -11
  56. package/src/adapter/resources/webgpu-vertex-array.ts +2 -1
  57. package/src/adapter/webgpu-canvas-context.ts +1 -1
  58. package/src/adapter/webgpu-device.ts +23 -6
package/dist/dist.min.js CHANGED
@@ -4,6 +4,6 @@
4
4
  else if (typeof define === 'function' && define.amd) define([], factory);
5
5
  else if (typeof exports === 'object') exports['luma'] = factory();
6
6
  else root['luma'] = factory();})(globalThis, function () {
7
- var __exports__=(()=>{var me=Object.create;var B=Object.defineProperty;var ge=Object.getOwnPropertyDescriptor;var be=Object.getOwnPropertyNames;var xe=Object.getPrototypeOf,we=Object.prototype.hasOwnProperty;var ye=(n,e,t)=>e in n?B(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var ve=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),Se=(n,e)=>{for(var t in e)B(n,t,{get:e[t],enumerable:!0})},I=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of be(e))!we.call(n,i)&&i!==t&&B(n,i,{get:()=>e[i],enumerable:!(r=ge(e,i))||r.enumerable});return n},M=(n,e,t)=>(I(n,e,"default"),t&&I(t,e,"default")),h=(n,e,t)=>(t=n!=null?me(xe(n)):{},I(e||!n||!n.__esModule?B(t,"default",{value:n,enumerable:!0}):t,n)),Ce=n=>I(B({},"__esModule",{value:!0}),n);var K=(n,e,t)=>(ye(n,typeof e!="symbol"?e+"":e,t),t);var o=ve((Me,ee)=>{ee.exports=globalThis.luma});var _={};Se(_,{WebGPUBuffer:()=>b,WebGPUDevice:()=>L,WebGPUSampler:()=>u,WebGPUShader:()=>S,WebGPUTexture:()=>v});M(_,h(o(),1));var p=h(o(),1);var O=h(o(),1);function Pe(n){return n.byteLength||n.data?.byteLength||0}var b=class extends O.Buffer{device;handle;byteLength;constructor(e,t){super(e,t),this.device=e,this.byteLength=Pe(t);let r=Boolean(t.data),i=Math.ceil(this.byteLength/4)*4;this.handle=this.props.handle||this.device.handle.createBuffer({size:i,usage:this.props.usage||GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST,mappedAtCreation:this.props.mappedAtCreation||r,label:this.props.id}),t.data&&this._writeMapped(t.data),r&&!t.mappedAtCreation&&this.handle.unmap()}destroy(){this.handle?.destroy(),this.handle=null}write(e,t=0){this.device.handle.queue.writeBuffer(this.handle,t,e.buffer,e.byteOffset,e.byteLength)}async readAsync(e=0,t=this.byteLength){let r=new b(this.device,{usage:O.Buffer.MAP_READ|O.Buffer.COPY_DST,byteLength:t}),i=this.device.handle.createCommandEncoder();i.copyBufferToBuffer(this.handle,e,r.handle,0,t),this.device.handle.queue.submit([i.finish()]),await r.handle.mapAsync(GPUMapMode.READ,e,t);let s=r.handle.getMappedRange().slice(0);return r.handle.unmap(),r.destroy(),new Uint8Array(s)}_writeMapped(e){let t=this.handle.getMappedRange();new e.constructor(t).set(e)}mapAsync(e,t=0,r){return this.handle.mapAsync(e,t,r)}getMappedRange(e=0,t){return this.handle.getMappedRange(e,t)}unmap(){this.handle.unmap()}};var ne=h(o(),1);function y(n){if(n.includes("webgl"))throw new Error("webgl-only format");return n}var te=h(o(),1),u=class extends te.Sampler{device;handle;constructor(e,t){super(e,t),this.device=e;let r={...this.props};r.type!=="comparison-sampler"&&delete r.compare,this.handle=this.handle||this.device.handle.createSampler(r),this.handle.label=this.props.id}destroy(){this.handle=null}};var re=h(o(),1),E=class extends re.TextureView{device;handle;texture;constructor(e,t){super(e,t),this.device=e,this.texture=t.texture,this.handle=this.handle||this.texture.handle.createView({format:t.format||this.texture.format,dimension:t.dimension||this.texture.dimension,aspect:t.aspect,baseMipLevel:t.baseMipLevel,mipLevelCount:t.mipLevelCount,baseArrayLayer:t.baseArrayLayer,arrayLayerCount:t.arrayLayerCount}),this.handle.label=this.props.id}destroy(){this.handle=null}};var Be={"1d":"1d","2d":"2d","2d-array":"2d",cube:"2d","cube-array":"2d","3d":"3d"},v=class extends ne.Texture{device;handle;height=1;width=1;sampler;view;constructor(e,t){if(super(e,t),this.device=e,t.data instanceof Promise){t.data.then(r=>{this.props={...t,data:r},this.initialize(this.props)});return}this.initialize(t)}destroy(){this.handle?.destroy(),this.handle=null}createView(e){return new E(this.device,{...e,texture:this})}initialize(e){this.handle=this.props.handle||this.createHandle(),this.handle.label||=this.id,this.props.data&&this.setData({data:this.props.data}),this.width=this.handle.width,this.height=this.handle.height,this.sampler=e.sampler instanceof u?e.sampler:new u(this.device,e.sampler),this.view=new E(this.device,{...this.props,texture:this})}createHandle(){let e=this.props.width||this.props.data?.width||1,t=this.props.height||this.props.data?.height||1;return this.device.handle.createTexture({label:this.id,size:{width:e,height:t,depthOrArrayLayers:this.props.depth},dimension:Be[this.props.dimension],format:y(this.props.format),usage:this.props.usage,mipLevelCount:this.props.mipLevels,sampleCount:this.props.samples})}setSampler(e){return this.sampler=e instanceof u?e:new u(this.device,e),this}setData(e){return this.setImage({source:e.data})}setImage(e){let{source:t,width:r=e.source.width,height:i=e.source.height,depth:s=1,sourceX:a=0,sourceY:l=0,mipLevel:d=0,x=0,y:w=0,z:N=0,aspect:j="all",colorSpace:H="srgb",premultipliedAlpha:fe=!1}=e;return this.device.handle.queue.copyExternalImageToTexture({source:t,origin:[a,l]},{texture:this.handle,origin:[x,w,N],mipLevel:d,aspect:j,colorSpace:H,premultipliedAlpha:fe},[r,i,s]),{width:r,height:i}}};var ie=h(o(),1);var R=class extends ie.ExternalTexture{device;handle;sampler;constructor(e,t){super(e,t),this.device=e,this.handle=this.props.handle||this.device.handle.importExternalTexture({source:t.source,colorSpace:t.colorSpace}),this.sampler=null}destroy(){this.handle=null}setSampler(e){return this.sampler=e instanceof u?e:new u(this.device,e),this}};var D=h(o(),1),S=class extends D.Shader{device;handle;constructor(e,t){super(e,t),this.device=e,this.device.handle.pushErrorScope("validation"),this.handle=this.props.handle||this.createHandle(),this.handle.label=this.props.id,this._checkCompilationError(this.device.handle.popErrorScope())}async _checkCompilationError(e){let t=await e;if(t){this.debugShader();let r=await this.getCompilationInfo();throw D.log.error(`Shader compilation error: ${t.message}`,r)(),new Error(`Shader compilation error: ${t.message}`)}}destroy(){this.handle=null}async getCompilationInfo(){return(await this.handle.getCompilationInfo()).messages}createHandle(){let{source:e}=this.props,t=e.includes("#version");if(this.props.language==="glsl"||t)throw new Error("GLSL shaders are not supported in WebGPU");return this.device.handle.createShaderModule({code:e})}};var m=h(o(),1);function c(n){return n.depthStencil=n.depthStencil||{format:"depth24plus",stencilFront:{},stencilBack:{},depthWriteEnabled:!1,depthCompare:"less-equal"},n.depthStencil}var Ee={cullMode:(n,e,t)=>{t.primitive=t.primitive||{},t.primitive.cullMode=e},frontFace:(n,e,t)=>{t.primitive=t.primitive||{},t.primitive.frontFace=e},depthWriteEnabled:(n,e,t)=>{let r=c(t);r.depthWriteEnabled=e},depthCompare:(n,e,t)=>{let r=c(t);r.depthCompare=e},depthFormat:(n,e,t)=>{let r=c(t);r.format=e},depthBias:(n,e,t)=>{let r=c(t);r.depthBias=e},depthBiasSlopeScale:(n,e,t)=>{let r=c(t);r.depthBiasSlopeScale=e},depthBiasClamp:(n,e,t)=>{let r=c(t);r.depthBiasClamp=e},stencilReadMask:(n,e,t)=>{let r=c(t);r.stencilReadMask=e},stencilWriteMask:(n,e,t)=>{let r=c(t);r.stencilWriteMask=e},stencilCompare:(n,e,t)=>{let r=c(t);r.stencilFront.compare=e,r.stencilBack.compare=e},stencilPassOperation:(n,e,t)=>{let r=c(t);r.stencilFront.passOp=e,r.stencilBack.passOp=e},stencilFailOperation:(n,e,t)=>{let r=c(t);r.stencilFront.failOp=e,r.stencilBack.failOp=e},stencilDepthFailOperation:(n,e,t)=>{let r=c(t);r.stencilFront.depthFailOp=e,r.stencilBack.depthFailOp=e},sampleCount:(n,e,t)=>{t.multisample=t.multisample||{},t.multisample.count=e},sampleMask:(n,e,t)=>{t.multisample=t.multisample||{},t.multisample.mask=e},sampleAlphaToCoverageEnabled:(n,e,t)=>{t.multisample=t.multisample||{},t.multisample.alphaToCoverageEnabled=e},colorMask:(n,e,t)=>{let r=se(t);r[0].writeMask=e},blendColorOperation:(n,e,t)=>{se(t)}},Ae={primitive:{cullMode:"back",topology:"triangle-list"},vertex:{module:void 0,entryPoint:"main"},fragment:{module:void 0,entryPoint:"main",targets:[]},layout:"auto"};function ae(n,e={}){Object.assign(n,{...Ae,...n}),Te(n,e)}function Te(n,e){for(let[t,r]of Object.entries(e)){let i=Ee[t];if(!i)throw new Error(`Illegal parameter ${t}`);i(t,r,n)}}function se(n){if(n.fragment.targets=n.fragment?.targets||[],!Array.isArray(n.fragment?.targets))throw new Error("colorstate");return n.fragment?.targets?.length===0&&n.fragment.targets?.push({}),n.fragment?.targets}var f=h(o(),1);function F(n,e,t,r){let i=Le(r,t);return n.createBindGroup({layout:e,entries:i})}function Ge(n,e){let t=n.bindings.find(r=>r.name===e||`${r.name}uniforms`===e.toLocaleLowerCase());return t||f.log.warn(`Binding ${e} not set: Not found in shader layout.`)(),t}function Le(n,e){let t=[];for(let[r,i]of Object.entries(n)){let s=Ge(e,r);s&&t.push(_e(i,s.location))}return t}function _e(n,e){if(n instanceof f.Buffer)return{binding:e,resource:{buffer:(0,f.cast)(n).handle}};if(n instanceof f.Sampler)return{binding:e,resource:(0,f.cast)(n).handle};if(n instanceof f.Texture)return{binding:e,resource:(0,f.cast)(n).handle.createView({label:"bind-group-auto-created"})};throw new Error("invalid binding")}var C=h(o(),1);function Y(n){if(n.endsWith("-webgl"))throw new Error(`WebGPU does not support vertex format ${n}`);return n}function he(n,e){let t=[],r=new Set;for(let i of e){let s=[],a="vertex",l=0;if(i.attributes)for(let d of i.attributes){let x=d.attribute,w=oe(n,x,r);a=w.stepMode||(w.name.startsWith("instance")?"instance":"vertex"),s.push({format:Y(d.format||i.format),offset:d.byteOffset,shaderLocation:w.location}),l+=(0,C.decodeVertexFormat)(i.format).byteLength}else{let d=oe(n,i.name,r);if(!d)continue;l=(0,C.decodeVertexFormat)(i.format).byteLength,a=d.stepMode||(d.name.startsWith("instance")?"instance":"vertex"),s.push({format:Y(i.format),offset:0,shaderLocation:d.location})}t.push({arrayStride:i.byteStride||l,stepMode:a,attributes:s})}for(let i of n.attributes)r.has(i.name)||t.push({arrayStride:(0,C.decodeVertexFormat)("float32x3").byteLength,stepMode:i.stepMode||(i.name.startsWith("instance")?"instance":"vertex"),attributes:[{format:Y("float32x3"),offset:0,shaderLocation:i.location}]});return t}function oe(n,e,t){let r=n.attributes.find(i=>i.name===e);if(!r)return C.log.warn(`Unknown attribute ${e}`)(),null;if(t.has(e))throw new Error(`Duplicate attribute ${e}`);return t.add(e),r}var W=class extends m.RenderPipeline{device;handle;vs;fs=null;_bindings;_bindGroupLayout=null;_bindGroup=null;constructor(e,t){if(super(e,t),this.device=e,this.handle=this.props.handle,!this.handle){let r=this._getRenderPipelineDescriptor();m.log.groupCollapsed(1,`new WebGPURenderPipeline(${this.id})`)(),m.log.probe(1,JSON.stringify(r,null,2))(),m.log.groupEnd(1)(),this.handle=this.device.handle.createRenderPipeline(r)}this.handle.label=this.props.id,this.vs=(0,m.cast)(t.vs),this.fs=(0,m.cast)(t.fs),this._bindings={...this.props.bindings}}destroy(){this.handle=null}setBindings(e){Object.assign(this._bindings,e)}draw(e){let t=e.renderPass;t.handle.setPipeline(this.handle);let r=this._getBindGroup();return r&&t.handle.setBindGroup(0,r),e.vertexArray.bindBeforeRender(e.renderPass),e.indexCount?t.handle.drawIndexed(e.indexCount,e.instanceCount,e.firstIndex,e.baseVertex,e.firstInstance):t.handle.draw(e.vertexCount||0,e.instanceCount||1,e.firstInstance),e.vertexArray.unbindAfterRender(e.renderPass),!0}_getBindGroup(){return this.props.shaderLayout.bindings.length===0?null:(this._bindGroupLayout=this._bindGroupLayout||this.handle.getBindGroupLayout(0),this._bindGroup=this._bindGroup||F(this.device.handle,this._bindGroupLayout,this.props.shaderLayout,this._bindings),this._bindGroup)}_getRenderPipelineDescriptor(){let e={module:(0,m.cast)(this.props.vs).handle,entryPoint:this.props.vertexEntryPoint||"main",buffers:he(this.props.shaderLayout,this.props.bufferLayout)},t={module:(0,m.cast)(this.props.fs).handle,entryPoint:this.props.fragmentEntryPoint||"main",targets:[{format:y(this.device?.canvasContext?.format)}]};switch(this.props.topology){case"triangle-fan-webgl":case"line-loop-webgl":throw new Error(`WebGPU does not support primitive topology ${this.props.topology}`);default:}let r={vertex:e,fragment:t,primitive:{topology:this.props.topology},layout:"auto"};return ae(r,this.props.parameters),r}};var de=h(o(),1),P=class extends de.Framebuffer{device;constructor(e,t){super(e,t),this.device=e,this.autoCreateAttachmentTextures()}};var le=h(o(),1);var k=class extends le.ComputePipeline{device;handle;_bindGroupLayout=null;_bindGroup=null;_bindings={};constructor(e,t){super(e,t),this.device=e;let r=this.props.shader;this.handle=this.props.handle||this.device.handle.createComputePipeline({label:this.props.id,compute:{module:r.handle,entryPoint:this.props.entryPoint,constants:this.props.constants},layout:"auto"})}setBindings(e){Object.assign(this._bindings,e)}_getBindGroup(){return this._bindGroupLayout=this._bindGroupLayout||this.handle.getBindGroupLayout(0),this._bindGroup=this._bindGroup||F(this.device.handle,this._bindGroupLayout,this.props.shaderLayout,this._bindings),this._bindGroup}};var g=h(o(),1),U=class extends g.RenderPass{device;handle;pipeline=null;constructor(e,t={}){super(e,t),this.device=e;let r=t.framebuffer||e.canvasContext.getCurrentFramebuffer(),i=this.getRenderPassDescriptor(r),s=t.timestampQuerySet;if(s&&(i.occlusionQuerySet=s.handle),e.features.has("timestamp-query")){let a=t.timestampQuerySet;i.timestampWrites=a?{querySet:a.handle,beginningOfPassWriteIndex:t.beginTimestampIndex,endOfPassWriteIndex:t.endTimestampIndex}:void 0}this.handle=this.props.handle||e.commandEncoder.beginRenderPass(i),this.handle.label=this.props.id,g.log.groupCollapsed(3,`new WebGPURenderPass(${this.id})`)(),g.log.probe(3,JSON.stringify(i,null,2))(),g.log.groupEnd(3)()}destroy(){}end(){this.handle.end()}setPipeline(e){this.pipeline=(0,g.cast)(e),this.handle.setPipeline(this.pipeline.handle)}setBindings(e){this.pipeline?.setBindings(e);let t=this.pipeline?._getBindGroup();t&&this.handle.setBindGroup(0,t)}setIndexBuffer(e,t,r=0,i){this.handle.setIndexBuffer((0,g.cast)(e).handle,t,r,i)}setVertexBuffer(e,t,r=0){this.handle.setVertexBuffer(e,(0,g.cast)(t).handle,r)}draw(e){e.indexCount?this.handle.drawIndexed(e.indexCount,e.instanceCount,e.firstIndex,e.baseVertex,e.firstInstance):this.handle.draw(e.vertexCount||0,e.instanceCount||1,e.firstIndex,e.firstInstance)}drawIndirect(){}setParameters(e){let{blendConstant:t,stencilReference:r,scissorRect:i,viewport:s}=e;t&&this.handle.setBlendConstant(t),r&&this.handle.setStencilReference(r),i&&this.handle.setScissorRect(i[0],i[1],i[2],i[3]),s&&this.handle.setViewport(s[0],s[1],s[2],s[3],s[4],s[5])}pushDebugGroup(e){this.handle.pushDebugGroup(e)}popDebugGroup(){this.handle.popDebugGroup()}insertDebugMarker(e){this.handle.insertDebugMarker(e)}beginOcclusionQuery(e){this.handle.beginOcclusionQuery(e)}endOcclusionQuery(){this.handle.endOcclusionQuery()}getRenderPassDescriptor(e){let t={colorAttachments:[]};if(t.colorAttachments=e.colorAttachments.map(r=>({loadOp:this.props.clearColor!==!1?"clear":"load",colorClearValue:this.props.clearColor||[0,0,0,0],storeOp:this.props.discard?"discard":"store",view:r.handle})),e.depthStencilAttachment){t.depthStencilAttachment={view:e.depthStencilAttachment.handle};let{depthStencilAttachment:r}=t;this.props.depthReadOnly&&(r.depthReadOnly=!0),r.depthClearValue=this.props.clearDepth||0,!0&&(r.depthLoadOp=this.props.clearDepth!==!1?"clear":"load",r.depthStoreOp="store"),!1&&(r.stencilLoadOp=this.props.clearStencil!==!1?"clear":"load",r.stencilStoreOp="store")}return t}};var pe=h(o(),1),V=class extends pe.ComputePass{device;handle;_webgpuPipeline=null;constructor(e,t){super(e,t),this.device=e;let r;if(e.features.has("timestamp-query")){let i=t.timestampQuerySet;i&&(r={querySet:i.handle,beginningOfPassWriteIndex:t.beginTimestampIndex,endOfPassWriteIndex:t.endTimestampIndex})}this.handle=this.props.handle||e.commandEncoder?.beginComputePass({label:this.props.id,timestampWrites:r})}destroy(){}end(){this.handle.end()}setPipeline(e){let t=e;this.handle.setPipeline(t.handle),this._webgpuPipeline=t,this.setBindings([])}setBindings(e){let t=this._webgpuPipeline._getBindGroup();this.handle.setBindGroup(0,t)}dispatch(e,t,r){this.handle.dispatchWorkgroups(e,t,r)}dispatchIndirect(e,t=0){let r=e;this.handle.dispatchWorkgroupsIndirect(r.handle,t)}pushDebugGroup(e){this.handle.pushDebugGroup(e)}popDebugGroup(){this.handle.popDebugGroup()}insertDebugMarker(e){this.handle.insertDebugMarker(e)}};var T=h(o(),1);function A(n){if(typeof window<"u"&&typeof window.process=="object"&&window.process.type==="renderer"||typeof process<"u"&&typeof process.versions=="object"&&Boolean(process.versions.electron))return!0;let e=typeof navigator=="object"&&typeof navigator.userAgent=="string"&&navigator.userAgent,t=n||e;return!!(t&&t.indexOf("Electron")>=0)}function X(){return!(typeof process=="object"&&String(process)==="[object process]"&&!process.browser)||A()}var ot=globalThis.self||globalThis.window||globalThis.global,ht=globalThis.window||globalThis.self||globalThis.global,dt=globalThis.document||{},lt=globalThis.process||{},pt=globalThis.console,ue=globalThis.navigator||{};var J=globalThis;function q(n){if(!n&&!X())return"Node";if(A(n))return"Electron";let e=n||ue.userAgent||"";if(e.indexOf("Edge")>-1)return"Edge";let t=e.indexOf("MSIE ")!==-1,r=e.indexOf("Trident/")!==-1;return t||r?"IE":J.chrome?"Chrome":J.safari?"Safari":J.mozInnerScreenX?"Firefox":"Unknown"}var $=class extends T.VertexArray{get[Symbol.toStringTag](){return"WebGPUVertexArray"}device;handle;constructor(e,t){super(e,t),this.device=e}destroy(){}setIndexBuffer(e){this.indexBuffer=e}setBuffer(e,t){this.attributes[e]=t}bindBeforeRender(e,t,r){let i=e,s=this.indexBuffer;s?.handle&&(T.log.warn("setting index buffer",s?.handle,s?.indexType)(),i.handle.setIndexBuffer(s?.handle,s?.indexType));for(let a=0;a<this.maxVertexAttributes;a++){let l=this.attributes[a];l?.handle&&(T.log.warn(`setting vertex buffer ${a}`,l?.handle)(),i.handle.setVertexBuffer(a,l?.handle))}}unbindAfterRender(e){}static isConstantAttributeZeroSupported(e){return q()==="Chrome"}};var z=h(o(),1);var G=class extends z.CanvasContext{device;gpuCanvasContext;format=navigator.gpu.getPreferredCanvasFormat();depthStencilFormat="depth24plus";depthStencilAttachment=null;constructor(e,t,r){super(r),this.device=e,this.width=-1,this.height=-1,this._setAutoCreatedCanvasId(`${this.device.id}-canvas`),this.gpuCanvasContext=this.canvas.getContext("webgpu"),this.format="bgra8unorm"}destroy(){this.gpuCanvasContext.unconfigure()}getCurrentFramebuffer(){this.update();let e=this.getCurrentTexture();return this.width=e.width,this.height=e.height,this._createDepthStencilAttachment(),new P(this.device,{colorAttachments:[e],depthStencilAttachment:this.depthStencilAttachment})}update(){let[e,t]=this.getPixelSize();(e!==this.width||t!==this.height)&&(this.width=e,this.height=t,this.depthStencilAttachment&&(this.depthStencilAttachment.destroy(),this.depthStencilAttachment=null),this.gpuCanvasContext.configure({device:this.device.handle,format:y(this.format),colorSpace:this.props.colorSpace,alphaMode:this.props.alphaMode}),z.log.log(1,`Resized to ${this.width}x${this.height}px`)())}resize(e){this.update()}getCurrentTexture(){return this.device._createTexture({id:`${this.id}#color-texture`,handle:this.gpuCanvasContext.getCurrentTexture(),format:this.format})}_createDepthStencilAttachment(){return this.depthStencilAttachment||(this.depthStencilAttachment=this.device.createTexture({id:`${this.id}#depth-stencil-texture`,format:this.depthStencilFormat,width:this.width,height:this.height,usage:GPUTextureUsage.RENDER_ATTACHMENT})),this.depthStencilAttachment}};var ce=h(o(),1),Q=class extends ce.QuerySet{device;handle;constructor(e,t){super(e,t),this.device=e,this.handle=this.props.handle||this.device.handle.createQuerySet({type:this.props.type,count:this.props.count}),this.handle.label=this.props.id}destroy(){this.handle?.destroy(),this.handle=null}};var Z=class extends p.Device{type="webgpu";handle;adapter;adapterInfo;features;info;limits;lost;canvasContext=null;_isLost=!1;commandEncoder=null;renderPass=null;static isSupported(){return Boolean(typeof navigator<"u"&&navigator.gpu)}static async create(e){if(!navigator.gpu)throw new Error("WebGPU not available. Open in Chrome Canary and turn on chrome://flags/#enable-unsafe-webgpu");p.log.groupCollapsed(1,"WebGPUDevice created")();let t=await navigator.gpu.requestAdapter({powerPreference:"high-performance"});if(!t)throw new Error("Failed to request WebGPU adapter");let r=await t.requestAdapterInfo();p.log.probe(2,"Adapter available",r)();let i=[],s={};if(e.requestMaxLimits){i.push(...Array.from(t.features));for(let d in t.limits)s[d]=t.limits[d];delete s.minSubgroupSize,delete s.maxSubgroupSize}let a=await t.requestDevice({requiredFeatures:i,requiredLimits:s});p.log.probe(1,"GPUDevice available")(),typeof e.canvas=="string"&&(await p.CanvasContext.pageLoaded,p.log.probe(1,"DOM is loaded")());let l=new Z(a,t,r,e);return p.log.probe(1,"Device created. For more info, set chrome://flags/#enable-webgpu-developer-features")(),p.log.table(1,l.info)(),p.log.groupEnd(1)(),l}constructor(e,t,r,i){super({...i,id:i.id||(0,p.uid)("webgpu-device")}),this.handle=e,this.adapter=t,this.adapterInfo=r,this.info=this._getInfo(),this.features=this._getFeatures(),this.limits=this.handle.limits,this.lost=new Promise(async s=>{let a=await this.handle.lost;this._isLost=!0,s({reason:"destroyed",message:a.message})}),this.canvasContext=new G(this,this.adapter,{canvas:i.canvas,height:i.height,width:i.width,container:i.container})}destroy(){this.handle.destroy()}isTextureFormatSupported(e){return!e.includes("webgl")}isTextureFormatFilterable(e){return this.isTextureFormatSupported(e)&&!e.startsWith("depth")&&!e.startsWith("stencil")}isTextureFormatRenderable(e){return this.isTextureFormatSupported(e)}get isLost(){return this._isLost}createBuffer(e){let t=this._getBufferProps(e);return new b(this,t)}_createTexture(e){return new v(this,e)}createExternalTexture(e){return new R(this,e)}createShader(e){return new S(this,e)}createSampler(e){return new u(this,e)}createRenderPipeline(e){return new W(this,e)}createFramebuffer(e){return new P(this,e)}createComputePipeline(e){return new k(this,e)}createVertexArray(e){return new $(this,e)}beginRenderPass(e){return this.commandEncoder=this.commandEncoder||this.handle.createCommandEncoder(),new U(this,e)}beginComputePass(e){return this.commandEncoder=this.commandEncoder||this.handle.createCommandEncoder(),new V(this,e)}createTransformFeedback(e){throw new Error("Transform feedback not supported in WebGPU")}createQuerySet(e){return new Q(this,e)}createCanvasContext(e){return new G(this,this.adapter,e)}submit(){let e=this.commandEncoder?.finish();e&&this.handle.queue.submit([e]),this.commandEncoder=null}_getInfo(){let[e,t]=(this.adapterInfo.driver||"").split(" Version "),r=this.adapterInfo.vendor||this.adapter.__brand||"unknown",i=e||"",s=t||"",a=r==="apple"?"apple":"unknown",l=this.adapterInfo.architecture||"unknown",d=this.adapterInfo.backend||"unknown",x=(this.adapterInfo.type||"").split(" ")[0].toLowerCase()||"unknown";return{type:"webgpu",vendor:r,renderer:i,version:s,gpu:a,gpuType:x,gpuBackend:d,gpuArchitecture:l,shadingLanguage:"wgsl",shadingLanguageVersion:100}}_getFeatures(){let e=new Set(this.handle.features);e.has("depth-clamping")&&(e.delete("depth-clamping"),e.add("depth-clip-control")),e.has("texture-compression-bc")&&e.add("texture-compression-bc5-webgl");let t=["timer-query-webgl","compilation-status-async-webgl","float32-renderable-webgl","float16-renderable-webgl","norm16-renderable-webgl","texture-filterable-anisotropic-webgl","shader-noperspective-interpolation-webgl"];for(let r of t)e.add(r);return new p.DeviceFeatures(Array.from(e),this.props.disabledFeatures)}copyExternalImageToTexture(e){let{source:t,sourceX:r=0,sourceY:i=0,texture:s,mipLevel:a=0,aspect:l="all",colorSpace:d="display-p3",premultipliedAlpha:x=!1,width:w=s.width,height:N=s.height,depth:j=1}=e,H=s;this.handle?.queue.copyExternalImageToTexture({source:t,origin:[r,i]},{texture:H.handle,origin:[0,0,0],mipLevel:a,aspect:l,colorSpace:d,premultipliedAlpha:x},[w,N,j])}},L=Z;K(L,"type","webgpu");return Ce(_);})();
7
+ var __exports__=(()=>{var ge=Object.create;var A=Object.defineProperty;var be=Object.getOwnPropertyDescriptor;var xe=Object.getOwnPropertyNames;var we=Object.getPrototypeOf,ye=Object.prototype.hasOwnProperty;var ve=(n,e,t)=>e in n?A(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var Se=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),Ce=(n,e)=>{for(var t in e)A(n,t,{get:e[t],enumerable:!0})},I=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of xe(e))!ye.call(n,i)&&i!==t&&A(n,i,{get:()=>e[i],enumerable:!(r=be(e,i))||r.enumerable});return n},F=(n,e,t)=>(I(n,e,"default"),t&&I(t,e,"default")),d=(n,e,t)=>(t=n!=null?ge(we(n)):{},I(e||!n||!n.__esModule?A(t,"default",{value:n,enumerable:!0}):t,n)),Pe=n=>I(A({},"__esModule",{value:!0}),n);var ee=(n,e,t)=>(ve(n,typeof e!="symbol"?e+"":e,t),t);var o=Se((Fe,te)=>{te.exports=globalThis.luma});var D={};Ce(D,{WebGPUBuffer:()=>b,WebGPUDevice:()=>_,WebGPUSampler:()=>u,WebGPUShader:()=>v,WebGPUTexture:()=>y});F(D,d(o(),1));var p=d(o(),1);var O=d(o(),1);function Ee(n){return n.byteLength||n.data?.byteLength||0}var b=class extends O.Buffer{device;handle;byteLength;constructor(e,t){super(e,t),this.device=e,this.byteLength=Ee(t);let r=Boolean(t.data),i=Math.ceil(this.byteLength/4)*4;this.handle=this.props.handle||this.device.handle.createBuffer({size:i,usage:this.props.usage||GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST,mappedAtCreation:this.props.mappedAtCreation||r,label:this.props.id}),t.data&&this._writeMapped(t.data),r&&!t.mappedAtCreation&&this.handle.unmap()}destroy(){this.handle?.destroy(),this.handle=null}write(e,t=0){this.device.handle.queue.writeBuffer(this.handle,t,e.buffer,e.byteOffset,e.byteLength)}async readAsync(e=0,t=this.byteLength){let r=new b(this.device,{usage:O.Buffer.MAP_READ|O.Buffer.COPY_DST,byteLength:t}),i=this.device.handle.createCommandEncoder();i.copyBufferToBuffer(this.handle,e,r.handle,0,t),this.device.handle.queue.submit([i.finish()]),await r.handle.mapAsync(GPUMapMode.READ,e,t);let s=r.handle.getMappedRange().slice(0);return r.handle.unmap(),r.destroy(),new Uint8Array(s)}_writeMapped(e){let t=this.handle.getMappedRange();new e.constructor(t).set(e)}mapAsync(e,t=0,r){return this.handle.mapAsync(e,t,r)}getMappedRange(e=0,t){return this.handle.getMappedRange(e,t)}unmap(){this.handle.unmap()}};var R=d(o(),1);function w(n){if(n.includes("webgl"))throw new Error("webgl-only format");return n}var re=d(o(),1),u=class extends re.Sampler{device;handle;constructor(e,t){super(e,t),this.device=e;let r={...this.props};r.type!=="comparison-sampler"&&delete r.compare,this.handle=this.handle||this.device.handle.createSampler(r),this.handle.label=this.props.id}destroy(){this.handle=null}};var ne=d(o(),1),T=class extends ne.TextureView{device;handle;texture;constructor(e,t){super(e,t),this.device=e,this.texture=t.texture,this.handle=this.handle||this.texture.handle.createView({format:t.format||this.texture.format,dimension:t.dimension||this.texture.dimension,aspect:t.aspect,baseMipLevel:t.baseMipLevel,mipLevelCount:t.mipLevelCount,baseArrayLayer:t.baseArrayLayer,arrayLayerCount:t.arrayLayerCount}),this.handle.label=this.props.id}destroy(){this.handle=null}};var Be={"1d":"1d","2d":"2d","2d-array":"2d",cube:"2d","cube-array":"2d","3d":"3d"},y=class extends R.Texture{device;handle;height=1;width=1;sampler;view;constructor(e,t){if(super(e,t),this.device=e,t.data instanceof Promise){t.data.then(r=>{this.props={...this.props,data:r},this.initialize(this.props)});return}this.initialize(t)}destroy(){this.handle?.destroy(),this.handle=null}createView(e){return new T(this.device,{...e,texture:this})}initialize(e){this.handle=this.props.handle||this.createHandle(),this.handle.label||=this.id,this.props.data&&this.setData({data:this.props.data}),this.width=this.handle.width,this.height=this.handle.height,this.sampler=e.sampler instanceof u?e.sampler:new u(this.device,e.sampler||{}),this.view=new T(this.device,{...this.props,texture:this})}createHandle(){let e=this.props.width||this.props.data?.width||1,t=this.props.height||this.props.data?.height||1;return this.device.handle.createTexture({label:this.id,size:{width:e,height:t,depthOrArrayLayers:this.depth},usage:this.props.usage||R.Texture.TEXTURE|R.Texture.COPY_DST,dimension:Be[this.dimension],format:w(this.format),mipLevelCount:this.mipLevels,sampleCount:this.props.samples})}createGPUTextureView(){return this.handle.createView({label:this.id})}setSampler(e){return this.sampler=e instanceof u?e:new u(this.device,e),this}setTexture1DData(e){throw new Error("not implemented")}setTexture2DData(e,t,r){throw new Error("not implemented")}setTexture3DData(e,t,r){throw new Error("not implemented")}setTextureCubeData(e,t){throw new Error("not implemented")}setTextureArrayData(e){throw new Error("not implemented")}setTextureCubeArrayData(e){throw new Error("not implemented")}setData(e){return this.setImage({source:e.data})}setImage(e){let{source:t,width:r=e.source.width,height:i=e.source.height,depth:s=1,sourceX:a=0,sourceY:l=0,mipLevel:c=0,x:h=0,y:g=0,z:m=0,aspect:B="all",colorSpace:X="srgb",premultipliedAlpha:fe=!1}=e;return this.device.handle.queue.copyExternalImageToTexture({source:t,origin:[a,l]},{texture:this.handle,origin:[h,g,m],mipLevel:c,aspect:B,colorSpace:X,premultipliedAlpha:fe},[r,i,s]),{width:r,height:i}}};var ie=d(o(),1);var M=class extends ie.ExternalTexture{device;handle;sampler;constructor(e,t){super(e,t),this.device=e,this.handle=this.props.handle||this.device.handle.importExternalTexture({source:t.source,colorSpace:t.colorSpace}),this.sampler=null}destroy(){this.handle=null}setSampler(e){return this.sampler=e instanceof u?e:new u(this.device,e),this}};var W=d(o(),1),v=class extends W.Shader{device;handle;constructor(e,t){super(e,t),this.device=e,this.device.handle.pushErrorScope("validation"),this.handle=this.props.handle||this.createHandle(),this.handle.label=this.props.id,this._checkCompilationError(this.device.handle.popErrorScope())}async _checkCompilationError(e){let t=await e;if(t){this.debugShader();let r=await this.getCompilationInfo();throw W.log.error(`Shader compilation error: ${t.message}`,r)(),new Error(`Shader compilation error: ${t.message}`)}}destroy(){this.handle=null}async getCompilationInfo(){return(await this.handle.getCompilationInfo()).messages}createHandle(){let{source:e}=this.props,t=e.includes("#version");if(this.props.language==="glsl"||t)throw new Error("GLSL shaders are not supported in WebGPU");return this.device.handle.createShaderModule({code:e})}};var C=d(o(),1);function f(n){return n.depthStencil=n.depthStencil||{format:"depth24plus",stencilFront:{},stencilBack:{},depthWriteEnabled:!1,depthCompare:"less-equal"},n.depthStencil}function k(n){return f(n).stencilFront}function U(n){return f(n).stencilBack}var Ae={cullMode:(n,e,t)=>{t.primitive=t.primitive||{},t.primitive.cullMode=e},frontFace:(n,e,t)=>{t.primitive=t.primitive||{},t.primitive.frontFace=e},depthWriteEnabled:(n,e,t)=>{let r=f(t);r.depthWriteEnabled=e},depthCompare:(n,e,t)=>{let r=f(t);r.depthCompare=e},depthFormat:(n,e,t)=>{let r=f(t);r.format=e},depthBias:(n,e,t)=>{let r=f(t);r.depthBias=e},depthBiasSlopeScale:(n,e,t)=>{let r=f(t);r.depthBiasSlopeScale=e},depthBiasClamp:(n,e,t)=>{let r=f(t);r.depthBiasClamp=e},stencilReadMask:(n,e,t)=>{let r=f(t);r.stencilReadMask=e},stencilWriteMask:(n,e,t)=>{let r=f(t);r.stencilWriteMask=e},stencilCompare:(n,e,t)=>{let r=k(t),i=U(t);r.compare=e,i.compare=e},stencilPassOperation:(n,e,t)=>{let r=k(t),i=U(t);r.passOp=e,i.passOp=e},stencilFailOperation:(n,e,t)=>{let r=k(t),i=U(t);r.failOp=e,i.failOp=e},stencilDepthFailOperation:(n,e,t)=>{let r=k(t),i=U(t);r.depthFailOp=e,i.depthFailOp=e},sampleCount:(n,e,t)=>{t.multisample=t.multisample||{},t.multisample.count=e},sampleMask:(n,e,t)=>{t.multisample=t.multisample||{},t.multisample.mask=e},sampleAlphaToCoverageEnabled:(n,e,t)=>{t.multisample=t.multisample||{},t.multisample.alphaToCoverageEnabled=e},colorMask:(n,e,t)=>{let r=se(t);r[0].writeMask=e},blendColorOperation:(n,e,t)=>{se(t)}},Te={primitive:{cullMode:"back",topology:"triangle-list"},vertex:{module:void 0,entryPoint:"main"},fragment:{module:void 0,entryPoint:"main",targets:[]},layout:"auto"};function ae(n,e={}){Object.assign(n,{...Te,...n}),Ge(n,e)}function Ge(n,e){for(let[t,r]of Object.entries(e)){let i=Ae[t];if(!i)throw new Error(`Illegal parameter ${t}`);i(t,r,n)}}function se(n){if(n.fragment.targets=n.fragment?.targets||[],!Array.isArray(n.fragment?.targets))throw new Error("colorstate");return n.fragment?.targets?.length===0&&n.fragment.targets?.push({}),n.fragment?.targets}var x=d(o(),1);function V(n,e,t,r){let i=_e(r,t);return n.createBindGroup({layout:e,entries:i})}function Le(n,e){let t=n.bindings.find(r=>r.name===e||`${r.name}uniforms`===e.toLocaleLowerCase());return t||x.log.warn(`Binding ${e} not set: Not found in shader layout.`)(),t||null}function _e(n,e){let t=[];for(let[r,i]of Object.entries(n)){let s=Le(e,r);s&&t.push(De(i,s.location))}return t}function De(n,e){if(n instanceof x.Buffer)return{binding:e,resource:{buffer:n.handle}};if(n instanceof x.Sampler)return{binding:e,resource:n.handle};if(n instanceof x.Texture)return{binding:e,resource:n.handle.createView({label:"bind-group-auto-created"})};throw new Error("invalid binding")}var S=d(o(),1);function J(n){if(n.endsWith("-webgl"))throw new Error(`WebGPU does not support vertex format ${n}`);return n}function he(n,e){let t=[],r=new Set;for(let i of e){let s=[],a="vertex",l=0,c=i.format;if(i.attributes)for(let h of i.attributes){let g=h.attribute,m=oe(n,g,r),B=m?.location;a=m?.stepMode||(m?.name.startsWith("instance")?"instance":"vertex"),s.push({format:J(h.format||i.format),offset:h.byteOffset,shaderLocation:B}),l+=(0,S.decodeVertexFormat)(c).byteLength}else{let h=oe(n,i.name,r);if(!h)continue;l=(0,S.decodeVertexFormat)(c).byteLength,a=h.stepMode||(h.name.startsWith("instance")?"instance":"vertex"),s.push({format:J(c),offset:0,shaderLocation:h.location})}t.push({arrayStride:i.byteStride||l,stepMode:a,attributes:s})}for(let i of n.attributes)r.has(i.name)||t.push({arrayStride:(0,S.decodeVertexFormat)("float32x3").byteLength,stepMode:i.stepMode||(i.name.startsWith("instance")?"instance":"vertex"),attributes:[{format:J("float32x3"),offset:0,shaderLocation:i.location}]});return t}function oe(n,e,t){let r=n.attributes.find(i=>i.name===e);if(!r)return S.log.warn(`Unknown attribute ${e}`)(),null;if(t.has(e))throw new Error(`Duplicate attribute ${e}`);return t.add(e),r}var q=class extends C.RenderPipeline{device;handle;vs;fs=null;_bindings;_bindGroupLayout=null;_bindGroup=null;constructor(e,t){if(super(e,t),this.device=e,this.handle=this.props.handle,!this.handle){let r=this._getRenderPipelineDescriptor();C.log.groupCollapsed(1,`new WebGPURenderPipeline(${this.id})`)(),C.log.probe(1,JSON.stringify(r,null,2))(),C.log.groupEnd(1)(),this.handle=this.device.handle.createRenderPipeline(r)}this.handle.label=this.props.id,this.vs=t.vs,this.fs=t.fs,this._bindings={...this.props.bindings}}destroy(){this.handle=null}setBindings(e){Object.assign(this._bindings,e)}draw(e){let t=e.renderPass;t.handle.setPipeline(this.handle);let r=this._getBindGroup();return r&&t.handle.setBindGroup(0,r),e.vertexArray.bindBeforeRender(e.renderPass),e.indexCount?t.handle.drawIndexed(e.indexCount,e.instanceCount,e.firstIndex,e.baseVertex,e.firstInstance):t.handle.draw(e.vertexCount||0,e.instanceCount||1,e.firstInstance),e.vertexArray.unbindAfterRender(e.renderPass),!0}_getBindGroup(){return this.shaderLayout.bindings.length===0?null:(this._bindGroupLayout=this._bindGroupLayout||this.handle.getBindGroupLayout(0),this._bindGroup=this._bindGroup||V(this.device.handle,this._bindGroupLayout,this.shaderLayout,this._bindings),this._bindGroup)}_getRenderPipelineDescriptor(){let e={module:this.props.vs.handle,entryPoint:this.props.vertexEntryPoint||"main",buffers:he(this.shaderLayout,this.props.bufferLayout)},t={module:this.props.fs.handle,entryPoint:this.props.fragmentEntryPoint||"main",targets:[{format:w(this.device.getCanvasContext().format)}]},r={vertex:e,fragment:t,primitive:{topology:this.props.topology},layout:"auto"};return ae(r,this.props.parameters),r}};var de=d(o(),1),P=class extends de.Framebuffer{device;colorAttachments=[];depthStencilAttachment=null;constructor(e,t){super(e,t),this.device=e,this.autoCreateAttachmentTextures()}};var le=d(o(),1);var $=class extends le.ComputePipeline{device;handle;_bindGroupLayout=null;_bindGroup=null;_bindings={};constructor(e,t){super(e,t),this.device=e;let r=this.props.shader;this.handle=this.props.handle||this.device.handle.createComputePipeline({label:this.props.id,compute:{module:r.handle,entryPoint:this.props.entryPoint,constants:this.props.constants},layout:"auto"})}setBindings(e){Object.assign(this._bindings,e)}_getBindGroup(){return this._bindGroupLayout=this._bindGroupLayout||this.handle.getBindGroupLayout(0),this._bindGroup=this._bindGroup||V(this.device.handle,this._bindGroupLayout,this.shaderLayout,this._bindings),this._bindGroup}};var E=d(o(),1),z=class extends E.RenderPass{device;handle;pipeline=null;constructor(e,t={}){super(e,t),this.device=e;let r=t.framebuffer||e.getCanvasContext().getCurrentFramebuffer(),i=this.getRenderPassDescriptor(r),s=t.timestampQuerySet;if(s&&(i.occlusionQuerySet=s.handle),e.features.has("timestamp-query")){let a=t.timestampQuerySet;i.timestampWrites=a?{querySet:a.handle,beginningOfPassWriteIndex:t.beginTimestampIndex,endOfPassWriteIndex:t.endTimestampIndex}:void 0}if(!e.commandEncoder)throw new Error("commandEncoder not available");this.handle=this.props.handle||e.commandEncoder.beginRenderPass(i),this.handle.label=this.props.id,E.log.groupCollapsed(3,`new WebGPURenderPass(${this.id})`)(),E.log.probe(3,JSON.stringify(i,null,2))(),E.log.groupEnd(3)()}destroy(){}end(){this.handle.end()}setPipeline(e){this.pipeline=e,this.handle.setPipeline(this.pipeline.handle)}setBindings(e){this.pipeline?.setBindings(e);let t=this.pipeline?._getBindGroup();t&&this.handle.setBindGroup(0,t)}setIndexBuffer(e,t,r=0,i){this.handle.setIndexBuffer(e.handle,t,r,i)}setVertexBuffer(e,t,r=0){this.handle.setVertexBuffer(e,t.handle,r)}draw(e){e.indexCount?this.handle.drawIndexed(e.indexCount,e.instanceCount,e.firstIndex,e.baseVertex,e.firstInstance):this.handle.draw(e.vertexCount||0,e.instanceCount||1,e.firstIndex,e.firstInstance)}drawIndirect(){}setParameters(e){let{blendConstant:t,stencilReference:r,scissorRect:i,viewport:s}=e;t&&this.handle.setBlendConstant(t),r&&this.handle.setStencilReference(r),i&&this.handle.setScissorRect(i[0],i[1],i[2],i[3]),s&&this.handle.setViewport(s[0],s[1],s[2],s[3],s[4],s[5])}pushDebugGroup(e){this.handle.pushDebugGroup(e)}popDebugGroup(){this.handle.popDebugGroup()}insertDebugMarker(e){this.handle.insertDebugMarker(e)}beginOcclusionQuery(e){this.handle.beginOcclusionQuery(e)}endOcclusionQuery(){this.handle.endOcclusionQuery()}getRenderPassDescriptor(e){let t={colorAttachments:[]};if(t.colorAttachments=e.colorAttachments.map(r=>({loadOp:this.props.clearColor!==!1?"clear":"load",colorClearValue:this.props.clearColor||[0,0,0,0],storeOp:this.props.discard?"discard":"store",view:r.handle})),e.depthStencilAttachment){t.depthStencilAttachment={view:e.depthStencilAttachment.handle};let{depthStencilAttachment:r}=t;this.props.depthReadOnly&&(r.depthReadOnly=!0),r.depthClearValue=this.props.clearDepth||0,!0&&(r.depthLoadOp=this.props.clearDepth!==!1?"clear":"load",r.depthStoreOp="store"),!1&&(r.stencilLoadOp=this.props.clearStencil!==!1?"clear":"load",r.stencilStoreOp="store")}return t}};var ue=d(o(),1),Q=class extends ue.ComputePass{device;handle;_webgpuPipeline=null;constructor(e,t){super(e,t),this.device=e;let r;if(e.features.has("timestamp-query")){let i=t.timestampQuerySet;i&&(r={querySet:i.handle,beginningOfPassWriteIndex:t.beginTimestampIndex,endOfPassWriteIndex:t.endTimestampIndex})}this.handle=this.props.handle||e.commandEncoder?.beginComputePass({label:this.props.id,timestampWrites:r})}destroy(){}end(){this.handle.end()}setPipeline(e){let t=e;this.handle.setPipeline(t.handle),this._webgpuPipeline=t,this.setBindings([])}setBindings(e){let t=this._webgpuPipeline._getBindGroup();this.handle.setBindGroup(0,t)}dispatch(e,t,r){this.handle.dispatchWorkgroups(e,t,r)}dispatchIndirect(e,t=0){let r=e;this.handle.dispatchWorkgroupsIndirect(r.handle,t)}pushDebugGroup(e){this.handle.pushDebugGroup(e)}popDebugGroup(){this.handle.popDebugGroup()}insertDebugMarker(e){this.handle.insertDebugMarker(e)}};var G=d(o(),1);var st=globalThis.document||{},at=globalThis.process||{},ot=globalThis.console,pe=globalThis.navigator||{};function N(n){if(typeof window<"u"&&window.process?.type==="renderer"||typeof process<"u"&&Boolean(process.versions?.electron))return!0;let e=typeof navigator<"u"&&navigator.userAgent,t=n||e;return Boolean(t&&t.indexOf("Electron")>=0)}function ce(){return!(typeof process=="object"&&String(process)==="[object process]"&&!process?.browser)||N()}function Z(n){return!n&&!ce()?"Node":N(n)?"Electron":(n||pe.userAgent||"").indexOf("Edge")>-1?"Edge":globalThis.chrome?"Chrome":globalThis.safari?"Safari":globalThis.mozInnerScreenX?"Firefox":"Unknown"}var j=class extends G.VertexArray{get[Symbol.toStringTag](){return"WebGPUVertexArray"}device;handle;constructor(e,t){super(e,t),this.device=e}destroy(){}setIndexBuffer(e){this.indexBuffer=e}setBuffer(e,t){this.attributes[e]=t}bindBeforeRender(e,t,r){let i=e,s=this.indexBuffer;s?.handle&&(G.log.warn("setting index buffer",s?.handle,s?.indexType)(),i.handle.setIndexBuffer(s?.handle,s?.indexType));for(let a=0;a<this.maxVertexAttributes;a++){let l=this.attributes[a];l?.handle&&(G.log.warn(`setting vertex buffer ${a}`,l?.handle)(),i.handle.setVertexBuffer(a,l?.handle))}}unbindAfterRender(e){}static isConstantAttributeZeroSupported(e){return Z()==="Chrome"}};var Y=d(o(),1);var L=class extends Y.CanvasContext{device;gpuCanvasContext;format=navigator.gpu.getPreferredCanvasFormat();depthStencilFormat="depth24plus";depthStencilAttachment=null;constructor(e,t,r){super(r),this.device=e,this.width=-1,this.height=-1,this._setAutoCreatedCanvasId(`${this.device.id}-canvas`),this.gpuCanvasContext=this.canvas.getContext("webgpu"),this.format="bgra8unorm"}destroy(){this.gpuCanvasContext.unconfigure()}getCurrentFramebuffer(){this.update();let e=this.getCurrentTexture();return this.width=e.width,this.height=e.height,this._createDepthStencilAttachment(),new P(this.device,{colorAttachments:[e],depthStencilAttachment:this.depthStencilAttachment})}update(){let[e,t]=this.getPixelSize();(e!==this.width||t!==this.height)&&(this.width=e,this.height=t,this.depthStencilAttachment&&(this.depthStencilAttachment.destroy(),this.depthStencilAttachment=null),this.gpuCanvasContext.configure({device:this.device.handle,format:w(this.format),colorSpace:this.props.colorSpace,alphaMode:this.props.alphaMode}),Y.log.log(1,`Resized to ${this.width}x${this.height}px`)())}resize(e){this.update()}getCurrentTexture(){return this.device._createTexture({id:`${this.id}#color-texture`,handle:this.gpuCanvasContext.getCurrentTexture(),format:this.format})}_createDepthStencilAttachment(){return this.depthStencilAttachment||(this.depthStencilAttachment=this.device.createTexture({id:`${this.id}#depth-stencil-texture`,format:this.depthStencilFormat,width:this.width,height:this.height,usage:GPUTextureUsage.RENDER_ATTACHMENT})),this.depthStencilAttachment}};var me=d(o(),1),H=class extends me.QuerySet{device;handle;constructor(e,t){super(e,t),this.device=e,this.handle=this.props.handle||this.device.handle.createQuerySet({type:this.props.type,count:this.props.count}),this.handle.label=this.props.id}destroy(){this.handle?.destroy(),this.handle=null}};var K=class extends p.Device{type="webgpu";handle;adapter;adapterInfo;features;info;limits;lost;canvasContext=null;_isLost=!1;commandEncoder=null;renderPass=null;static isSupported(){return Boolean(typeof navigator<"u"&&navigator.gpu)}static async create(e){if(!navigator.gpu)throw new Error("WebGPU not available. Open in Chrome Canary and turn on chrome://flags/#enable-unsafe-webgpu");p.log.groupCollapsed(1,"WebGPUDevice created")();let t=await navigator.gpu.requestAdapter({powerPreference:"high-performance"});if(!t)throw new Error("Failed to request WebGPU adapter");let r=await t.requestAdapterInfo();p.log.probe(2,"Adapter available",r)();let i=[],s={};if(e.requestMaxLimits){i.push(...Array.from(t.features));let c=Object.keys(t.limits).filter(h=>!["minSubgroupSize","maxSubgroupSize"].includes(h));for(let h of c){let g=h,m=t.limits[g];typeof m=="number"&&(s[g]=m)}}let a=await t.requestDevice({requiredFeatures:i,requiredLimits:s});p.log.probe(1,"GPUDevice available")(),typeof e.canvas=="string"&&(await p.CanvasContext.pageLoaded,p.log.probe(1,"DOM is loaded")());let l=new K(a,t,r,e);return p.log.probe(1,"Device created. For more info, set chrome://flags/#enable-webgpu-developer-features")(),p.log.table(1,l.info)(),p.log.groupEnd(1)(),l}constructor(e,t,r,i){super({...i,id:i.id||"webgpu-device"}),this.handle=e,this.adapter=t,this.adapterInfo=r,this.info=this._getInfo(),this.features=this._getFeatures(),this.limits=this.handle.limits,e.addEventListener("uncapturederror",s=>{let a=s instanceof GPUUncapturedErrorEvent?s.error.message:"Unknown error";this.error(new Error(a))}),this.lost=new Promise(async s=>{let a=await this.handle.lost;this._isLost=!0,s({reason:"destroyed",message:a.message})}),this.canvasContext=new L(this,this.adapter,{canvas:i.canvas,height:i.height,width:i.width,container:i.container})}destroy(){this.handle.destroy()}isTextureFormatSupported(e){return!e.includes("webgl")}isTextureFormatFilterable(e){return this.isTextureFormatSupported(e)&&!e.startsWith("depth")&&!e.startsWith("stencil")}isTextureFormatRenderable(e){return this.isTextureFormatSupported(e)}get isLost(){return this._isLost}createBuffer(e){let t=this._getBufferProps(e);return new b(this,t)}_createTexture(e){return new y(this,e)}createExternalTexture(e){return new M(this,e)}createShader(e){return new v(this,e)}createSampler(e){return new u(this,e)}createRenderPipeline(e){return new q(this,e)}createFramebuffer(e){return new P(this,e)}createComputePipeline(e){return new $(this,e)}createVertexArray(e){return new j(this,e)}beginRenderPass(e){return this.commandEncoder=this.commandEncoder||this.handle.createCommandEncoder(),new z(this,e)}beginComputePass(e){return this.commandEncoder=this.commandEncoder||this.handle.createCommandEncoder(),new Q(this,e)}createTransformFeedback(e){throw new Error("Transform feedback not supported in WebGPU")}createQuerySet(e){return new H(this,e)}createCanvasContext(e){return new L(this,this.adapter,e)}submit(){let e=this.commandEncoder?.finish();e&&this.handle.queue.submit([e]),this.commandEncoder=null}_getInfo(){let[e,t]=(this.adapterInfo.driver||"").split(" Version "),r=this.adapterInfo.vendor||this.adapter.__brand||"unknown",i=e||"",s=t||"",a=r==="apple"?"apple":"unknown",l=this.adapterInfo.architecture||"unknown",c=this.adapterInfo.backend||"unknown",h=(this.adapterInfo.type||"").split(" ")[0].toLowerCase()||"unknown";return{type:"webgpu",vendor:r,renderer:i,version:s,gpu:a,gpuType:h,gpuBackend:c,gpuArchitecture:l,shadingLanguage:"wgsl",shadingLanguageVersion:100}}_getFeatures(){let e=new Set(this.handle.features);e.has("depth-clamping")&&(e.delete("depth-clamping"),e.add("depth-clip-control")),e.has("texture-compression-bc")&&e.add("texture-compression-bc5-webgl");let t=["timer-query-webgl","compilation-status-async-webgl","float32-renderable-webgl","float16-renderable-webgl","norm16-renderable-webgl","texture-filterable-anisotropic-webgl","shader-noperspective-interpolation-webgl"];for(let r of t)e.add(r);return new p.DeviceFeatures(Array.from(e),this.props.disabledFeatures)}copyExternalImageToTexture(e){let{source:t,sourceX:r=0,sourceY:i=0,texture:s,mipLevel:a=0,aspect:l="all",colorSpace:c="display-p3",premultipliedAlpha:h=!1,width:g=s.width,height:m=s.height,depth:B=1}=e,X=s;this.handle?.queue.copyExternalImageToTexture({source:t,origin:[r,i]},{texture:X.handle,origin:[0,0,0],mipLevel:a,aspect:l,colorSpace:c,premultipliedAlpha:h},[g,m,B])}},_=K;ee(_,"type","webgpu");return Pe(D);})();
8
8
  return __exports__;
9
9
  });
package/dist/index.cjs CHANGED
@@ -191,7 +191,7 @@ var WebGPUTexture = class extends import_core4.Texture {
191
191
  this.device = device;
192
192
  if (props.data instanceof Promise) {
193
193
  props.data.then((resolvedImageData) => {
194
- this.props = { ...props, data: resolvedImageData };
194
+ this.props = { ...this.props, data: resolvedImageData };
195
195
  this.initialize(this.props);
196
196
  });
197
197
  return;
@@ -214,7 +214,7 @@ var WebGPUTexture = class extends import_core4.Texture {
214
214
  }
215
215
  this.width = this.handle.width;
216
216
  this.height = this.handle.height;
217
- this.sampler = props.sampler instanceof WebGPUSampler ? props.sampler : new WebGPUSampler(this.device, props.sampler);
217
+ this.sampler = props.sampler instanceof WebGPUSampler ? props.sampler : new WebGPUSampler(this.device, props.sampler || {});
218
218
  this.view = new WebGPUTextureView(this.device, { ...this.props, texture: this });
219
219
  }
220
220
  createHandle() {
@@ -226,15 +226,19 @@ var WebGPUTexture = class extends import_core4.Texture {
226
226
  size: {
227
227
  width,
228
228
  height,
229
- depthOrArrayLayers: this.props.depth
229
+ depthOrArrayLayers: this.depth
230
230
  },
231
- dimension: BASE_DIMENSIONS[this.props.dimension],
232
- format: getWebGPUTextureFormat(this.props.format),
233
- usage: this.props.usage,
234
- mipLevelCount: this.props.mipLevels,
231
+ usage: this.props.usage || import_core4.Texture.TEXTURE | import_core4.Texture.COPY_DST,
232
+ dimension: BASE_DIMENSIONS[this.dimension],
233
+ format: getWebGPUTextureFormat(this.format),
234
+ mipLevelCount: this.mipLevels,
235
235
  sampleCount: this.props.samples
236
236
  });
237
237
  }
238
+ /** @deprecated - intention is to use the createView public API */
239
+ createGPUTextureView() {
240
+ return this.handle.createView({ label: this.id });
241
+ }
238
242
  /**
239
243
  * Set default sampler
240
244
  * Accept a sampler instance or set of props;
@@ -243,6 +247,24 @@ var WebGPUTexture = class extends import_core4.Texture {
243
247
  this.sampler = sampler instanceof WebGPUSampler ? sampler : new WebGPUSampler(this.device, sampler);
244
248
  return this;
245
249
  }
250
+ setTexture1DData(data) {
251
+ throw new Error("not implemented");
252
+ }
253
+ setTexture2DData(lodData, depth, target) {
254
+ throw new Error("not implemented");
255
+ }
256
+ setTexture3DData(lodData, depth, target) {
257
+ throw new Error("not implemented");
258
+ }
259
+ setTextureCubeData(data, depth) {
260
+ throw new Error("not implemented");
261
+ }
262
+ setTextureArrayData(data) {
263
+ throw new Error("not implemented");
264
+ }
265
+ setTextureCubeArrayData(data) {
266
+ throw new Error("not implemented");
267
+ }
246
268
  setData(options) {
247
269
  return this.setImage({ source: options.data });
248
270
  }
@@ -353,6 +375,14 @@ function addDepthStencil(descriptor) {
353
375
  };
354
376
  return descriptor.depthStencil;
355
377
  }
378
+ function addDepthStencilFront(descriptor) {
379
+ const depthStencil = addDepthStencil(descriptor);
380
+ return depthStencil.stencilFront;
381
+ }
382
+ function addDepthStencilBack(descriptor) {
383
+ const depthStencil = addDepthStencil(descriptor);
384
+ return depthStencil.stencilBack;
385
+ }
356
386
  var PARAMETER_TABLE = {
357
387
  // RASTERIZATION PARAMETERS
358
388
  cullMode: (parameter, value, descriptor) => {
@@ -398,24 +428,28 @@ var PARAMETER_TABLE = {
398
428
  depthStencil.stencilWriteMask = value;
399
429
  },
400
430
  stencilCompare: (parameter, value, descriptor) => {
401
- const depthStencil = addDepthStencil(descriptor);
402
- depthStencil.stencilFront.compare = value;
403
- depthStencil.stencilBack.compare = value;
431
+ const stencilFront = addDepthStencilFront(descriptor);
432
+ const stencilBack = addDepthStencilBack(descriptor);
433
+ stencilFront.compare = value;
434
+ stencilBack.compare = value;
404
435
  },
405
436
  stencilPassOperation: (parameter, value, descriptor) => {
406
- const depthStencil = addDepthStencil(descriptor);
407
- depthStencil.stencilFront.passOp = value;
408
- depthStencil.stencilBack.passOp = value;
437
+ const stencilFront = addDepthStencilFront(descriptor);
438
+ const stencilBack = addDepthStencilBack(descriptor);
439
+ stencilFront.passOp = value;
440
+ stencilBack.passOp = value;
409
441
  },
410
442
  stencilFailOperation: (parameter, value, descriptor) => {
411
- const depthStencil = addDepthStencil(descriptor);
412
- depthStencil.stencilFront.failOp = value;
413
- depthStencil.stencilBack.failOp = value;
443
+ const stencilFront = addDepthStencilFront(descriptor);
444
+ const stencilBack = addDepthStencilBack(descriptor);
445
+ stencilFront.failOp = value;
446
+ stencilBack.failOp = value;
414
447
  },
415
448
  stencilDepthFailOperation: (parameter, value, descriptor) => {
416
- const depthStencil = addDepthStencil(descriptor);
417
- depthStencil.stencilFront.depthFailOp = value;
418
- depthStencil.stencilBack.depthFailOp = value;
449
+ const stencilFront = addDepthStencilFront(descriptor);
450
+ const stencilBack = addDepthStencilBack(descriptor);
451
+ stencilFront.depthFailOp = value;
452
+ stencilBack.depthFailOp = value;
419
453
  },
420
454
  // MULTISAMPLE
421
455
  sampleCount: (parameter, value, descriptor) => {
@@ -539,7 +573,7 @@ function getShaderLayoutBinding(shaderLayout, bindingName) {
539
573
  if (!bindingLayout) {
540
574
  import_core7.log.warn(`Binding ${bindingName} not set: Not found in shader layout.`)();
541
575
  }
542
- return bindingLayout;
576
+ return bindingLayout || null;
543
577
  }
544
578
  function getBindGroupEntries(bindings, shaderLayout) {
545
579
  const entries = [];
@@ -556,19 +590,19 @@ function getBindGroupEntry(binding, index) {
556
590
  return {
557
591
  binding: index,
558
592
  resource: {
559
- buffer: (0, import_core7.cast)(binding).handle
593
+ buffer: binding.handle
560
594
  }
561
595
  };
562
596
  }
563
597
  if (binding instanceof import_core7.Sampler) {
564
598
  return {
565
599
  binding: index,
566
- resource: (0, import_core7.cast)(binding).handle
600
+ resource: binding.handle
567
601
  };
568
602
  } else if (binding instanceof import_core7.Texture) {
569
603
  return {
570
604
  binding: index,
571
- resource: (0, import_core7.cast)(binding).handle.createView({ label: "bind-group-auto-created" })
605
+ resource: binding.handle.createView({ label: "bind-group-auto-created" })
572
606
  };
573
607
  }
574
608
  throw new Error("invalid binding");
@@ -589,27 +623,29 @@ function getVertexBufferLayout(shaderLayout, bufferLayout) {
589
623
  const vertexAttributes = [];
590
624
  let stepMode = "vertex";
591
625
  let byteStride = 0;
626
+ const format = mapping.format;
592
627
  if (mapping.attributes) {
593
628
  for (const attributeMapping of mapping.attributes) {
594
629
  const attributeName = attributeMapping.attribute;
595
630
  const attributeLayout = findAttributeLayout(shaderLayout, attributeName, usedAttributes);
596
- stepMode = attributeLayout.stepMode || (attributeLayout.name.startsWith("instance") ? "instance" : "vertex");
631
+ const location = attributeLayout == null ? void 0 : attributeLayout.location;
632
+ stepMode = (attributeLayout == null ? void 0 : attributeLayout.stepMode) || ((attributeLayout == null ? void 0 : attributeLayout.name.startsWith("instance")) ? "instance" : "vertex");
597
633
  vertexAttributes.push({
598
634
  format: getWebGPUVertexFormat(attributeMapping.format || mapping.format),
599
635
  offset: attributeMapping.byteOffset,
600
- shaderLocation: attributeLayout.location
636
+ shaderLocation: location
601
637
  });
602
- byteStride += (0, import_core8.decodeVertexFormat)(mapping.format).byteLength;
638
+ byteStride += (0, import_core8.decodeVertexFormat)(format).byteLength;
603
639
  }
604
640
  } else {
605
641
  const attributeLayout = findAttributeLayout(shaderLayout, mapping.name, usedAttributes);
606
642
  if (!attributeLayout) {
607
643
  continue;
608
644
  }
609
- byteStride = (0, import_core8.decodeVertexFormat)(mapping.format).byteLength;
645
+ byteStride = (0, import_core8.decodeVertexFormat)(format).byteLength;
610
646
  stepMode = attributeLayout.stepMode || (attributeLayout.name.startsWith("instance") ? "instance" : "vertex");
611
647
  vertexAttributes.push({
612
- format: getWebGPUVertexFormat(mapping.format),
648
+ format: getWebGPUVertexFormat(format),
613
649
  // We only support 0 offset for non-interleaved buffer layouts
614
650
  offset: 0,
615
651
  shaderLocation: attributeLayout.location
@@ -673,8 +709,8 @@ var WebGPURenderPipeline = class extends import_core9.RenderPipeline {
673
709
  this.handle = this.device.handle.createRenderPipeline(descriptor);
674
710
  }
675
711
  this.handle.label = this.props.id;
676
- this.vs = (0, import_core9.cast)(props.vs);
677
- this.fs = (0, import_core9.cast)(props.fs);
712
+ this.vs = props.vs;
713
+ this.fs = props.fs;
678
714
  this._bindings = { ...this.props.bindings };
679
715
  }
680
716
  destroy() {
@@ -711,39 +747,32 @@ var WebGPURenderPipeline = class extends import_core9.RenderPipeline {
711
747
  }
712
748
  /** Return a bind group created by setBindings */
713
749
  _getBindGroup() {
714
- if (this.props.shaderLayout.bindings.length === 0) {
750
+ if (this.shaderLayout.bindings.length === 0) {
715
751
  return null;
716
752
  }
717
753
  this._bindGroupLayout = this._bindGroupLayout || this.handle.getBindGroupLayout(0);
718
- this._bindGroup = this._bindGroup || getBindGroup(this.device.handle, this._bindGroupLayout, this.props.shaderLayout, this._bindings);
754
+ this._bindGroup = this._bindGroup || getBindGroup(this.device.handle, this._bindGroupLayout, this.shaderLayout, this._bindings);
719
755
  return this._bindGroup;
720
756
  }
721
757
  /**
722
758
  * Populate the complex WebGPU GPURenderPipelineDescriptor
723
759
  */
724
760
  _getRenderPipelineDescriptor() {
725
- var _a, _b;
726
761
  const vertex = {
727
- module: (0, import_core9.cast)(this.props.vs).handle,
762
+ module: this.props.vs.handle,
728
763
  entryPoint: this.props.vertexEntryPoint || "main",
729
- buffers: getVertexBufferLayout(this.props.shaderLayout, this.props.bufferLayout)
764
+ buffers: getVertexBufferLayout(this.shaderLayout, this.props.bufferLayout)
730
765
  };
731
766
  const fragment = {
732
- module: (0, import_core9.cast)(this.props.fs).handle,
767
+ module: this.props.fs.handle,
733
768
  entryPoint: this.props.fragmentEntryPoint || "main",
734
769
  targets: [
735
770
  {
736
771
  // TODO exclamation mark hack!
737
- format: getWebGPUTextureFormat((_b = (_a = this.device) == null ? void 0 : _a.canvasContext) == null ? void 0 : _b.format)
772
+ format: getWebGPUTextureFormat(this.device.getCanvasContext().format)
738
773
  }
739
774
  ]
740
775
  };
741
- switch (this.props.topology) {
742
- case "triangle-fan-webgl":
743
- case "line-loop-webgl":
744
- throw new Error(`WebGPU does not support primitive topology ${this.props.topology}`);
745
- default:
746
- }
747
776
  const descriptor = {
748
777
  vertex,
749
778
  fragment,
@@ -761,6 +790,8 @@ var WebGPURenderPipeline = class extends import_core9.RenderPipeline {
761
790
  var import_core10 = require("@luma.gl/core");
762
791
  var WebGPUFramebuffer = class extends import_core10.Framebuffer {
763
792
  device;
793
+ colorAttachments = [];
794
+ depthStencilAttachment = null;
764
795
  constructor(device, props) {
765
796
  super(device, props);
766
797
  this.device = device;
@@ -802,7 +833,7 @@ var WebGPUComputePipeline = class extends import_core11.ComputePipeline {
802
833
  /** Return a bind group created by setBindings */
803
834
  _getBindGroup() {
804
835
  this._bindGroupLayout = this._bindGroupLayout || this.handle.getBindGroupLayout(0);
805
- this._bindGroup = this._bindGroup || getBindGroup(this.device.handle, this._bindGroupLayout, this.props.shaderLayout, this._bindings);
836
+ this._bindGroup = this._bindGroup || getBindGroup(this.device.handle, this._bindGroupLayout, this.shaderLayout, this._bindings);
806
837
  return this._bindGroup;
807
838
  }
808
839
  };
@@ -817,7 +848,7 @@ var WebGPURenderPass = class extends import_core12.RenderPass {
817
848
  constructor(device, props = {}) {
818
849
  super(device, props);
819
850
  this.device = device;
820
- const framebuffer = props.framebuffer || device.canvasContext.getCurrentFramebuffer();
851
+ const framebuffer = props.framebuffer || device.getCanvasContext().getCurrentFramebuffer();
821
852
  const renderPassDescriptor = this.getRenderPassDescriptor(framebuffer);
822
853
  const webgpuQuerySet = props.timestampQuerySet;
823
854
  if (webgpuQuerySet) {
@@ -831,6 +862,9 @@ var WebGPURenderPass = class extends import_core12.RenderPass {
831
862
  endOfPassWriteIndex: props.endTimestampIndex
832
863
  } : void 0;
833
864
  }
865
+ if (!device.commandEncoder) {
866
+ throw new Error("commandEncoder not available");
867
+ }
834
868
  this.handle = this.props.handle || device.commandEncoder.beginRenderPass(renderPassDescriptor);
835
869
  this.handle.label = this.props.id;
836
870
  import_core12.log.groupCollapsed(3, `new WebGPURenderPass(${this.id})`)();
@@ -843,7 +877,7 @@ var WebGPURenderPass = class extends import_core12.RenderPass {
843
877
  this.handle.end();
844
878
  }
845
879
  setPipeline(pipeline) {
846
- this.pipeline = (0, import_core12.cast)(pipeline);
880
+ this.pipeline = pipeline;
847
881
  this.handle.setPipeline(this.pipeline.handle);
848
882
  }
849
883
  /** Sets an array of bindings (uniform buffers, samplers, textures, ...) */
@@ -856,10 +890,10 @@ var WebGPURenderPass = class extends import_core12.RenderPass {
856
890
  }
857
891
  }
858
892
  setIndexBuffer(buffer, indexFormat, offset = 0, size) {
859
- this.handle.setIndexBuffer((0, import_core12.cast)(buffer).handle, indexFormat, offset, size);
893
+ this.handle.setIndexBuffer(buffer.handle, indexFormat, offset, size);
860
894
  }
861
895
  setVertexBuffer(slot, buffer, offset = 0) {
862
- this.handle.setVertexBuffer(slot, (0, import_core12.cast)(buffer).handle, offset);
896
+ this.handle.setVertexBuffer(slot, buffer.handle, offset);
863
897
  }
864
898
  draw(options) {
865
899
  if (options.indexCount) {
@@ -1052,7 +1086,11 @@ var WebGPUVertexArray = class extends import_core14.VertexArray {
1052
1086
  const webgpuIndexBuffer = this.indexBuffer;
1053
1087
  if (webgpuIndexBuffer == null ? void 0 : webgpuIndexBuffer.handle) {
1054
1088
  import_core14.log.warn("setting index buffer", webgpuIndexBuffer == null ? void 0 : webgpuIndexBuffer.handle, webgpuIndexBuffer == null ? void 0 : webgpuIndexBuffer.indexType)();
1055
- webgpuRenderPass.handle.setIndexBuffer(webgpuIndexBuffer == null ? void 0 : webgpuIndexBuffer.handle, webgpuIndexBuffer == null ? void 0 : webgpuIndexBuffer.indexType);
1089
+ webgpuRenderPass.handle.setIndexBuffer(
1090
+ webgpuIndexBuffer == null ? void 0 : webgpuIndexBuffer.handle,
1091
+ // @ts-expect-error TODO - we must enforce type
1092
+ webgpuIndexBuffer == null ? void 0 : webgpuIndexBuffer.indexType
1093
+ );
1056
1094
  }
1057
1095
  for (let location = 0; location < this.maxVertexAttributes; location++) {
1058
1096
  const webgpuBuffer = this.attributes[location];
@@ -1218,11 +1256,14 @@ var _WebGPUDevice = class extends import_core17.Device {
1218
1256
  const requiredLimits = {};
1219
1257
  if (props.requestMaxLimits) {
1220
1258
  requiredFeatures.push(...Array.from(adapter.features));
1221
- for (const key in adapter.limits) {
1222
- requiredLimits[key] = adapter.limits[key];
1259
+ const limits = Object.keys(adapter.limits).filter((key) => !["minSubgroupSize", "maxSubgroupSize"].includes(key));
1260
+ for (const key of limits) {
1261
+ const limit = key;
1262
+ const value = adapter.limits[limit];
1263
+ if (typeof value === "number") {
1264
+ requiredLimits[limit] = value;
1265
+ }
1223
1266
  }
1224
- delete requiredLimits.minSubgroupSize;
1225
- delete requiredLimits.maxSubgroupSize;
1226
1267
  }
1227
1268
  const gpuDevice = await adapter.requestDevice({
1228
1269
  requiredFeatures,
@@ -1240,13 +1281,17 @@ var _WebGPUDevice = class extends import_core17.Device {
1240
1281
  return device;
1241
1282
  }
1242
1283
  constructor(device, adapter, adapterInfo, props) {
1243
- super({ ...props, id: props.id || (0, import_core17.uid)("webgpu-device") });
1284
+ super({ ...props, id: props.id || "webgpu-device" });
1244
1285
  this.handle = device;
1245
1286
  this.adapter = adapter;
1246
1287
  this.adapterInfo = adapterInfo;
1247
1288
  this.info = this._getInfo();
1248
1289
  this.features = this._getFeatures();
1249
1290
  this.limits = this.handle.limits;
1291
+ device.addEventListener("uncapturederror", (event) => {
1292
+ const errorMessage = event instanceof GPUUncapturedErrorEvent ? event.error.message : "Unknown error";
1293
+ this.error(new Error(errorMessage));
1294
+ });
1250
1295
  this.lost = new Promise(async (resolve) => {
1251
1296
  const lostInfo = await this.handle.lost;
1252
1297
  this._isLost = true;