@luma.gl/webgpu 9.0.0-beta.7 → 9.0.0-beta.8

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
@@ -27,6 +27,7 @@ var __exports__ = (() => {
27
27
  }
28
28
  return to;
29
29
  };
30
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
30
31
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
31
32
  // If the importer is in node compatibility mode or this is not an ESM
32
33
  // file that has been converted to a CommonJS file using a Babel-
@@ -48,15 +49,16 @@ var __exports__ = (() => {
48
49
  }
49
50
  });
50
51
 
51
- // src/index.ts
52
- var src_exports = {};
53
- __export(src_exports, {
52
+ // bundle.ts
53
+ var bundle_exports = {};
54
+ __export(bundle_exports, {
54
55
  WebGPUBuffer: () => WebGPUBuffer,
55
56
  WebGPUDevice: () => WebGPUDevice,
56
57
  WebGPUSampler: () => WebGPUSampler,
57
58
  WebGPUShader: () => WebGPUShader,
58
59
  WebGPUTexture: () => WebGPUTexture
59
60
  });
61
+ __reExport(bundle_exports, __toESM(require_core(), 1));
60
62
 
61
63
  // src/adapter/webgpu-device.ts
62
64
  var import_core17 = __toESM(require_core(), 1);
@@ -1180,12 +1182,10 @@ var __exports__ = (() => {
1180
1182
 
1181
1183
  // ../../node_modules/@probe.gl/env/dist/lib/is-electron.js
1182
1184
  function isElectron(mockUserAgent) {
1183
- if (typeof window !== "undefined" && typeof window.process === "object" && // @ts-expect-error
1184
- window.process.type === "renderer") {
1185
+ if (typeof window !== "undefined" && typeof window.process === "object" && window.process.type === "renderer") {
1185
1186
  return true;
1186
1187
  }
1187
- if (typeof process !== "undefined" && typeof process.versions === "object" && // eslint-disable-next-line
1188
- Boolean(process.versions["electron"])) {
1188
+ if (typeof process !== "undefined" && typeof process.versions === "object" && Boolean(process.versions["electron"])) {
1189
1189
  return true;
1190
1190
  }
1191
1191
  const realUserAgent = typeof navigator === "object" && typeof navigator.userAgent === "string" && navigator.userAgent;
@@ -1198,10 +1198,7 @@ var __exports__ = (() => {
1198
1198
 
1199
1199
  // ../../node_modules/@probe.gl/env/dist/lib/is-browser.js
1200
1200
  function isBrowser() {
1201
- const isNode = (
1202
- // @ts-expect-error
1203
- typeof process === "object" && String(process) === "[object process]" && !process.browser
1204
- );
1201
+ const isNode = typeof process === "object" && String(process) === "[object process]" && !process.browser;
1205
1202
  return !isNode || isElectron();
1206
1203
  }
1207
1204
 
@@ -1656,7 +1653,7 @@ var __exports__ = (() => {
1656
1653
  };
1657
1654
  var WebGPUDevice = _WebGPUDevice;
1658
1655
  __publicField(WebGPUDevice, "type", "webgpu");
1659
- return __toCommonJS(src_exports);
1656
+ return __toCommonJS(bundle_exports);
1660
1657
  })();
1661
1658
  return __exports__;
1662
1659
  });
@@ -0,0 +1,9 @@
1
+ (function webpackUniversalModuleDefinition(root, factory) {
2
+ if (typeof exports === 'object' && typeof module === 'object')
3
+ module.exports = factory();
4
+ else if (typeof define === 'function' && define.amd) define([], factory);
5
+ else if (typeof exports === 'object') exports['luma'] = factory();
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(_);})();
8
+ return __exports__;
9
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luma.gl/webgpu",
3
- "version": "9.0.0-beta.7",
3
+ "version": "9.0.0-beta.8",
4
4
  "description": "WebGPU adapter for the luma.gl core API",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -32,16 +32,16 @@
32
32
  ],
33
33
  "sideEffects": false,
34
34
  "scripts": {
35
- "build-minified-bundle": "ocular-bundle ./src/index.ts -output=dist/dist.min.js",
36
- "build-dev-bundle": "ocular-bundle ./src/index.ts -output=dist/dist.dev.js -- --env=dev",
35
+ "build-minified-bundle": "ocular-bundle ./bundle.ts --output=dist/dist.min.js",
36
+ "build-dev-bundle": "ocular-bundle ./bundle.ts --output=dist/dist.dev.js --env=dev",
37
37
  "prepublishOnly": "npm run build-minified-bundle && npm run build-dev-bundle"
38
38
  },
39
39
  "peerDependencies": {
40
- "@luma.gl/core": "^9.0.0-beta.4"
40
+ "@luma.gl/core": "^9.0.0-beta"
41
41
  },
42
42
  "dependencies": {
43
43
  "@probe.gl/env": "^4.0.2",
44
44
  "@webgpu/types": "^0.1.34"
45
45
  },
46
- "gitHead": "e9606a88e0aab3dc27c87020cac89040ea1a8a02"
46
+ "gitHead": "b4ba7f35a5d0b5a09625c955d952cbbab9c1ad28"
47
47
  }
package/src/.DS_Store ADDED
Binary file
Binary file
package/dist.min.js DELETED
@@ -1,9 +0,0 @@
1
- (function webpackUniversalModuleDefinition(root, factory) {
2
- if (typeof exports === 'object' && typeof module === 'object')
3
- module.exports = factory();
4
- else if (typeof define === 'function' && define.amd) define([], factory);
5
- else if (typeof exports === 'object') exports['luma'] = factory();
6
- else root['luma'] = factory();})(globalThis, function () {
7
- var __exports__=(()=>{var ce=Object.create;var S=Object.defineProperty;var me=Object.getOwnPropertyDescriptor;var fe=Object.getOwnPropertyNames;var Pe=Object.getPrototypeOf,be=Object.prototype.hasOwnProperty;var ge=(i,e,t)=>e in i?S(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var ye=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports),ve=(i,e)=>{for(var t in e)S(i,t,{get:e[t],enumerable:!0})},X=(i,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of fe(e))!be.call(i,n)&&n!==t&&S(i,n,{get:()=>e[n],enumerable:!(r=me(e,n))||r.enumerable});return i};var p=(i,e,t)=>(t=i!=null?ce(Pe(i)):{},X(e||!i||!i.__esModule?S(t,"default",{value:i,enumerable:!0}):t,i)),xe=i=>X(S({},"__esModule",{value:!0}),i);var J=(i,e,t)=>(ge(i,typeof e!="symbol"?e+"":e,t),t);var a=ye((Ae,Z)=>{Z.exports=globalThis.luma});var Te={};ve(Te,{WebGPUBuffer:()=>b,WebGPUDevice:()=>T,WebGPUSampler:()=>h,WebGPUShader:()=>G,WebGPUTexture:()=>x});var l=p(a(),1);var R=p(a(),1);function Ge(i){return i.byteLength||i.data?.byteLength||0}var b=class extends R.Buffer{device;handle;byteLength;constructor(e,t){super(e,t),this.device=e,this.byteLength=Ge(t);let r=Boolean(t.data),n=Math.ceil(this.byteLength/4)*4;this.handle=this.props.handle||this.device.handle.createBuffer({size:n,usage:this.props.usage||GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST,mappedAtCreation:this.props.mappedAtCreation||r,label:this.props.id}),t.data&&this._writeMapped(t.data),r&&!t.mappedAtCreation&&this.handle.unmap()}destroy(){this.handle?.destroy(),this.handle=null}write(e,t=0){this.device.handle.queue.writeBuffer(this.handle,t,e.buffer,e.byteOffset,e.byteLength)}async readAsync(e=0,t=this.byteLength){let r=new b(this.device,{usage:R.Buffer.MAP_READ|R.Buffer.COPY_DST,byteLength:t}),n=this.device.handle.createCommandEncoder();n.copyBufferToBuffer(this.handle,e,r.handle,0,t),this.device.handle.queue.submit([n.finish()]),await r.handle.mapAsync(GPUMapMode.READ,e,t);let o=r.handle.getMappedRange().slice(0);return r.handle.unmap(),r.destroy(),new Uint8Array(o)}_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 te=p(a(),1);function v(i){if(i.includes("webgl"))throw new Error("webgl-only format");return i}var K=p(a(),1),h=class extends K.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 ee=p(a(),1),W=class extends ee.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 Ue={"1d":"1d","2d":"2d","2d-array":"2d",cube:"2d","cube-array":"2d","3d":"3d"},x=class extends te.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 W(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 h?e.sampler:new h(this.device,e.sampler),this.view=new W(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:Ue[this.props.dimension],format:v(this.props.format),usage:this.props.usage,mipLevelCount:this.props.mipLevels,sampleCount:this.props.samples})}setSampler(e){return this.sampler=e instanceof h?e:new h(this.device,e),this}setData(e){return this.setImage({source:e.data})}setImage(e){let{source:t,width:r=e.source.width,height:n=e.source.height,depth:o=1,sourceX:s=0,sourceY:u=0,mipLevel:d=0,x:g=0,y=0,z:q=0,aspect:$="all",colorSpace:z="srgb",premultipliedAlpha:he=!1}=e;return this.device.handle.queue.copyExternalImageToTexture({source:t,origin:[s,u]},{texture:this.handle,origin:[g,y,q],mipLevel:d,aspect:$,colorSpace:z,premultipliedAlpha:he},[r,n,o]),{width:r,height:n}}};var re=p(a(),1);var A=class extends re.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 h?e:new h(this.device,e),this}};var E=p(a(),1),G=class extends E.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 E.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 f=p(a(),1);function c(i){return i.depthStencil=i.depthStencil||{format:"depth24plus",stencilFront:{},stencilBack:{},depthWriteEnabled:!1,depthCompare:"less-equal"},i.depthStencil}var we={cullMode:(i,e,t)=>{t.primitive=t.primitive||{},t.primitive.cullMode=e},frontFace:(i,e,t)=>{t.primitive=t.primitive||{},t.primitive.frontFace=e},depthWriteEnabled:(i,e,t)=>{let r=c(t);r.depthWriteEnabled=e},depthCompare:(i,e,t)=>{let r=c(t);r.depthCompare=e},depthFormat:(i,e,t)=>{let r=c(t);r.format=e},depthBias:(i,e,t)=>{let r=c(t);r.depthBias=e},depthBiasSlopeScale:(i,e,t)=>{let r=c(t);r.depthBiasSlopeScale=e},depthBiasClamp:(i,e,t)=>{let r=c(t);r.depthBiasClamp=e},stencilReadMask:(i,e,t)=>{let r=c(t);r.stencilReadMask=e},stencilWriteMask:(i,e,t)=>{let r=c(t);r.stencilWriteMask=e},stencilCompare:(i,e,t)=>{let r=c(t);r.stencilFront.compare=e,r.stencilBack.compare=e},stencilPassOperation:(i,e,t)=>{let r=c(t);r.stencilFront.passOp=e,r.stencilBack.passOp=e},stencilFailOperation:(i,e,t)=>{let r=c(t);r.stencilFront.failOp=e,r.stencilBack.failOp=e},stencilDepthFailOperation:(i,e,t)=>{let r=c(t);r.stencilFront.depthFailOp=e,r.stencilBack.depthFailOp=e},sampleCount:(i,e,t)=>{t.multisample=t.multisample||{},t.multisample.count=e},sampleMask:(i,e,t)=>{t.multisample=t.multisample||{},t.multisample.mask=e},sampleAlphaToCoverageEnabled:(i,e,t)=>{t.multisample=t.multisample||{},t.multisample.alphaToCoverageEnabled=e},colorMask:(i,e,t)=>{let r=ie(t);r[0].writeMask=e},blendColorOperation:(i,e,t)=>{ie(t)}},Se={primitive:{cullMode:"back",topology:"triangle-list"},vertex:{module:void 0,entryPoint:"main"},fragment:{module:void 0,entryPoint:"main",targets:[]},layout:"auto"};function ne(i,e={}){Object.assign(i,{...Se,...i}),We(i,e)}function We(i,e){for(let[t,r]of Object.entries(e)){let n=we[t];if(!n)throw new Error(`Illegal parameter ${t}`);n(t,r,i)}}function ie(i){if(i.fragment.targets=i.fragment?.targets||[],!Array.isArray(i.fragment?.targets))throw new Error("colorstate");return i.fragment?.targets?.length===0&&i.fragment.targets?.push({}),i.fragment?.targets}var m=p(a(),1);function L(i,e,t,r){let n=Ce(r,t);return i.createBindGroup({layout:e,entries:n})}function Be(i,e){let t=i.bindings.find(r=>r.name===e||`${r.name}uniforms`===e.toLocaleLowerCase());return t||m.log.warn(`Binding ${e} not set: Not found in shader layout.`)(),t}function Ce(i,e){let t=[];for(let[r,n]of Object.entries(i)){let o=Be(e,r);o&&t.push(De(n,o.location))}return t}function De(i,e){if(i instanceof m.Buffer)return{binding:e,resource:{buffer:(0,m.cast)(i).handle}};if(i instanceof m.Sampler)return{binding:e,resource:(0,m.cast)(i).handle};if(i instanceof m.Texture)return{binding:e,resource:(0,m.cast)(i).handle.createView({label:"bind-group-auto-created"})};throw new Error("invalid binding")}var U=p(a(),1);function N(i){if(i.endsWith("-webgl"))throw new Error(`WebGPU does not support vertex format ${i}`);return i}function se(i,e){let t=[],r=new Set;for(let n of e){let o=[],s="vertex",u=0;if(n.attributes)for(let d of n.attributes){let g=d.attribute,y=oe(i,g,r);s=y.stepMode||(y.name.startsWith("instance")?"instance":"vertex"),o.push({format:N(d.format||n.format),offset:d.byteOffset,shaderLocation:y.location}),u+=(0,U.decodeVertexFormat)(n.format).byteLength}else{let d=oe(i,n.name,r);if(!d)continue;u=(0,U.decodeVertexFormat)(n.format).byteLength,s=d.stepMode||(d.name.startsWith("instance")?"instance":"vertex"),o.push({format:N(n.format),offset:0,shaderLocation:d.location})}t.push({arrayStride:n.byteStride||u,stepMode:s,attributes:o})}for(let n of i.attributes)r.has(n.name)||t.push({arrayStride:(0,U.decodeVertexFormat)("float32x3").byteLength,stepMode:n.stepMode||(n.name.startsWith("instance")?"instance":"vertex"),attributes:[{format:N("float32x3"),offset:0,shaderLocation:n.location}]});return t}function oe(i,e,t){let r=i.attributes.find(n=>n.name===e);if(!r)return U.log.warn(`Unknown attribute ${e}`)(),null;if(t.has(e))throw new Error(`Duplicate attribute ${e}`);return t.add(e),r}var F=class extends f.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();f.log.groupCollapsed(1,`new WebGPURenderPipeline(${this.id})`)(),f.log.probe(1,JSON.stringify(r,null,2))(),f.log.groupEnd(1)(),this.handle=this.device.handle.createRenderPipeline(r)}this.handle.label=this.props.id,this.vs=(0,f.cast)(t.vs),this.fs=(0,f.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||L(this.device.handle,this._bindGroupLayout,this.props.shaderLayout,this._bindings),this._bindGroup)}_getRenderPipelineDescriptor(){let e={module:(0,f.cast)(this.props.vs).handle,entryPoint:this.props.vertexEntryPoint||"main",buffers:se(this.props.shaderLayout,this.props.bufferLayout)},t={module:(0,f.cast)(this.props.fs).handle,entryPoint:this.props.fragmentEntryPoint||"main",targets:[{format:v(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 ne(r,this.props.parameters),r}};var ae=p(a(),1),w=class extends ae.Framebuffer{device;constructor(e,t){super(e,t),this.device=e,this.autoCreateAttachmentTextures()}};var de=p(a(),1);var I=class extends de.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||L(this.device.handle,this._bindGroupLayout,this.props.shaderLayout,this._bindings),this._bindGroup}};var P=p(a(),1),_=class extends P.RenderPass{device;handle;pipeline=null;constructor(e,t={}){super(e,t),this.device=e;let r=t.framebuffer||e.canvasContext.getCurrentFramebuffer(),n=this.getRenderPassDescriptor(r),o=t.timestampQuerySet;if(o&&(n.occlusionQuerySet=o.handle),e.features.has("timestamp-query")){let s=t.timestampQuerySet;n.timestampWrites=s?{querySet:s.handle,beginningOfPassWriteIndex:t.beginTimestampIndex,endOfPassWriteIndex:t.endTimestampIndex}:void 0}this.handle=this.props.handle||e.commandEncoder.beginRenderPass(n),this.handle.label=this.props.id,P.log.groupCollapsed(3,`new WebGPURenderPass(${this.id})`)(),P.log.probe(3,JSON.stringify(n,null,2))(),P.log.groupEnd(3)()}destroy(){}end(){this.handle.end()}setPipeline(e){this.pipeline=(0,P.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,n){this.handle.setIndexBuffer((0,P.cast)(e).handle,t,r,n)}setVertexBuffer(e,t,r=0){this.handle.setVertexBuffer(e,(0,P.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:n,viewport:o}=e;t&&this.handle.setBlendConstant(t),r&&this.handle.setStencilReference(r),n&&this.handle.setScissorRect(n[0],n[1],n[2],n[3]),o&&this.handle.setViewport(o[0],o[1],o[2],o[3],o[4],o[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=p(a(),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 n=t.timestampQuerySet;n&&(r={querySet:n.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 C=p(a(),1);function B(i){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=i||e;return!!(t&&t.indexOf("Electron")>=0)}function j(){return!(typeof process=="object"&&String(process)==="[object process]"&&!process.browser)||B()}var St=globalThis.self||globalThis.window||globalThis.global,Wt=globalThis.window||globalThis.self||globalThis.global,Bt=globalThis.document||{},Ct=globalThis.process||{},Dt=globalThis.console,ue=globalThis.navigator||{};var H=globalThis;function k(i){if(!i&&!j())return"Node";if(B(i))return"Electron";let e=i||ue.userAgent||"";if(e.indexOf("Edge")>-1)return"Edge";let t=e.indexOf("MSIE ")!==-1,r=e.indexOf("Trident/")!==-1;return t||r?"IE":H.chrome?"Chrome":H.safari?"Safari":H.mozInnerScreenX?"Firefox":"Unknown"}var M=class extends C.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 n=e,o=this.indexBuffer;o?.handle&&(C.log.warn("setting index buffer",o?.handle,o?.indexType)(),n.handle.setIndexBuffer(o?.handle,o?.indexType));for(let s=0;s<this.maxVertexAttributes;s++){let u=this.attributes[s];u?.handle&&(C.log.warn(`setting vertex buffer ${s}`,u?.handle)(),n.handle.setVertexBuffer(s,u?.handle))}}unbindAfterRender(e){}static isConstantAttributeZeroSupported(e){return k()==="Chrome"}};var O=p(a(),1);var D=class extends O.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 w(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:v(this.format),colorSpace:this.props.colorSpace,alphaMode:this.props.alphaMode}),O.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 le=p(a(),1),Q=class extends le.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 Y=class extends l.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");l.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();l.log.probe(2,"Adapter available",r)();let n=[],o={};if(e.requestMaxLimits){n.push(...Array.from(t.features));for(let d in t.limits)o[d]=t.limits[d];delete o.minSubgroupSize,delete o.maxSubgroupSize}let s=await t.requestDevice({requiredFeatures:n,requiredLimits:o});l.log.probe(1,"GPUDevice available")(),typeof e.canvas=="string"&&(await l.CanvasContext.pageLoaded,l.log.probe(1,"DOM is loaded")());let u=new Y(s,t,r,e);return l.log.probe(1,"Device created. For more info, set chrome://flags/#enable-webgpu-developer-features")(),l.log.table(1,u.info)(),l.log.groupEnd(1)(),u}constructor(e,t,r,n){super({...n,id:n.id||(0,l.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 o=>{let s=await this.handle.lost;this._isLost=!0,o({reason:"destroyed",message:s.message})}),this.canvasContext=new D(this,this.adapter,{canvas:n.canvas,height:n.height,width:n.width,container:n.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 x(this,e)}createExternalTexture(e){return new A(this,e)}createShader(e){return new G(this,e)}createSampler(e){return new h(this,e)}createRenderPipeline(e){return new F(this,e)}createFramebuffer(e){return new w(this,e)}createComputePipeline(e){return new I(this,e)}createVertexArray(e){return new M(this,e)}beginRenderPass(e){return this.commandEncoder=this.commandEncoder||this.handle.createCommandEncoder(),new _(this,e)}beginComputePass(e){return this.commandEncoder=this.commandEncoder||this.handle.createCommandEncoder(),new 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 D(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",n=e||"",o=t||"",s=r==="apple"?"apple":"unknown",u=this.adapterInfo.architecture||"unknown",d=this.adapterInfo.backend||"unknown",g=(this.adapterInfo.type||"").split(" ")[0].toLowerCase()||"unknown";return{type:"webgpu",vendor:r,renderer:n,version:o,gpu:s,gpuType:g,gpuBackend:d,gpuArchitecture:u,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 l.DeviceFeatures(Array.from(e),this.props.disabledFeatures)}copyExternalImageToTexture(e){let{source:t,sourceX:r=0,sourceY:n=0,texture:o,mipLevel:s=0,aspect:u="all",colorSpace:d="display-p3",premultipliedAlpha:g=!1,width:y=o.width,height:q=o.height,depth:$=1}=e,z=o;this.handle?.queue.copyExternalImageToTexture({source:t,origin:[r,n]},{texture:z.handle,origin:[0,0,0],mipLevel:s,aspect:u,colorSpace:d,premultipliedAlpha:g},[y,q,$])}},T=Y;J(T,"type","webgpu");return xe(Te);})();
8
- return __exports__;
9
- });