@derschmale/tiny-helix 0.1.0 → 0.2.0

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.
@@ -1,2 +1,2 @@
1
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.TinyHelix=e():t.TinyHelix=e()}(this,()=>(()=>{"use strict";var t,e,r,s,i,n,a,o,c,h,u,l,m={d:(t,e)=>{for(var r in e)m.o(e,r)&&!m.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},_={};m.d(_,{default:()=>st}),function(t){t.sRGB="srgb",t.DisplayP3="display-p3"}(t||(t={})),function(t){t.Nearest="nearest",t.Linear="linear"}(e||(e={})),function(t){t.ClampToEdge="clamp-to-edge",t.Repeat="repeat",t.MirrorRepeat="mirror-repeat"}(r||(r={})),function(t){t.None="none",t.Front="front",t.Back="back"}(s||(s={})),function(t){t.R8Unorm="r8unorm",t.R8Snorm="r8snorm",t.R8Uint="r8uint",t.R8Sint="r8sint",t.R16Unorm="r16unorm",t.R16Snorm="r16snorm",t.R16Uint="r16uint",t.R16Sint="r16sint",t.R16Float="r16float",t.RG8Unorm="rg8unorm",t.RG8Snorm="rg8snorm",t.RG8Uint="rg8uint",t.RG8Sint="rg8sint",t.R32Uint="r32uint",t.R32Sint="r32sint",t.R32Float="r32float",t.RG16Unorm="rg16unorm",t.RG16Snorm="rg16snorm",t.RG16Uint="rg16uint",t.RG16Sint="rg16sint",t.RG16Float="rg16float",t.Rgba8Unorm="rgba8unorm",t.Rgba8UnormSrgb="rgba8unorm-srgb",t.Rgba8Snorm="rgba8snorm",t.Rgba8Uint="rgba8uint",t.Rgba8Sint="rgba8sint",t.Bgra8Unorm="bgra8unorm",t.Bgra8UnormSrgb="bgra8unorm-srgb",t.Rgb9e5Ufloat="rgb9e5ufloat",t.Rgb10a2Uint="rgb10a2uint",t.Rgb10a2Unorm="rgb10a2unorm",t.Rg11b10Ufloat="rg11b10ufloat",t.RG32Uint="rg32uint",t.RG32Sint="rg32sint",t.RG32Float="rg32float",t.Rgba16Unorm="rgba16unorm",t.Rgba16Snorm="rgba16snorm",t.Rgba16Uint="rgba16uint",t.Rgba16Sint="rgba16sint",t.Rgba16Float="rgba16float",t.Rgba32Uint="rgba32uint",t.Rgba32Sint="rgba32sint",t.Rgba32Float="rgba32float",t.Stencil8="stencil8",t.Depth16Unorm="depth16unorm",t.Depth24Plus="depth24plus",t.Depth24PlusStencil8="depth24plus-stencil8",t.Depth32Float="depth32float",t.Depth32FloatStencil8="depth32float-stencil8",t.Bc1RgbaUnorm="bc1-rgba-unorm",t.Bc1RgbaUnormSrgb="bc1-rgba-unorm-srgb",t.Bc2RgbaUnorm="bc2-rgba-unorm",t.Bc2RgbaUnormSrgb="bc2-rgba-unorm-srgb",t.Bc3RgbaUnorm="bc3-rgba-unorm",t.Bc3RgbaUnormSrgb="bc3-rgba-unorm-srgb",t.Bc4RUnorm="bc4-r-unorm",t.Bc4RSnorm="bc4-r-snorm",t.Bc5RgUnorm="bc5-rg-unorm",t.Bc5RgSnorm="bc5-rg-snorm",t.Bc6hRgbUfloat="bc6h-rgb-ufloat",t.Bc6hRgbFloat="bc6h-rgb-float",t.Bc7RgbaUnorm="bc7-rgba-unorm",t.Bc7RgbaUnormSrgb="bc7-rgba-unorm-srgb",t.Etc2Rgb8Unorm="etc2-rgb8unorm",t.Etc2Rgb8UnormSrgb="etc2-rgb8unorm-srgb",t.Etc2Rgb8A1Unorm="etc2-rgb8a1unorm",t.Etc2Rgb8A1UnormSrgb="etc2-rgb8a1unorm-srgb",t.Etc2Rgba8Unorm="etc2-rgba8unorm",t.Etc2Rgba8UnormSrgb="etc2-rgba8unorm-srgb",t.EacR11Unorm="eac-r11unorm",t.EacR11Snorm="eac-r11snorm",t.EacRg11Unorm="eac-rg11unorm",t.EacRg11Snorm="eac-rg11snorm",t.Astc4x4Unorm="astc-4x4-unorm",t.Astc4x4UnormSrgb="astc-4x4-unorm-srgb",t.Astc5x4Unorm="astc-5x4-unorm",t.Astc5x4UnormSrgb="astc-5x4-unorm-srgb",t.Astc5x5Unorm="astc-5x5-unorm",t.Astc5x5UnormSrgb="astc-5x5-unorm-srgb",t.Astc6x5Unorm="astc-6x5-unorm",t.Astc6x5UnormSrgb="astc-6x5-unorm-srgb",t.Astc6x6Unorm="astc-6x6-unorm",t.Astc6x6UnormSrgb="astc-6x6-unorm-srgb",t.Astc8x5Unorm="astc-8x5-unorm",t.Astc8x5UnormSrgb="astc-8x5-unorm-srgb",t.Astc8x6Unorm="astc-8x6-unorm",t.Astc8x6UnormSrgb="astc-8x6-unorm-srgb",t.Astc8x8Unorm="astc-8x8-unorm",t.Astc8x8UnormSrgb="astc-8x8-unorm-srgb",t.Astc10x5Unorm="astc-10x5-unorm",t.Astc10x5UnormSrgb="astc-10x5-unorm-srgb",t.Astc10x6Unorm="astc-10x6-unorm",t.Astc10x6UnormSrgb="astc-10x6-unorm-srgb",t.Astc10x8Unorm="astc-10x8-unorm",t.Astc10x8UnormSrgb="astc-10x8-unorm-srgb",t.Astc10x10Unorm="astc-10x10-unorm",t.Astc10x10UnormSrgb="astc-10x10-unorm-srgb",t.Astc12x10Unorm="astc-12x10-unorm",t.Astc12x10UnormSrgb="astc-12x10-unorm-srgb",t.Astc12x12Unorm="astc-12x12-unorm",t.Astc12x12UnormSrgb="astc-12x12-unorm-srgb"}(i||(i={})),function(t){t.Zero="zero",t.One="one",t.SrcColor="src",t.OneMinusSrcColor="one-minus-src",t.SrcAlpha="src-alpha",t.OneMinusSrcAlpha="one-minus-src-alpha",t.DstColor="dst",t.OneMinusDstColor="one-minus-dst",t.DstAlpha="dst-alpha",t.OneMinusDstAlpha="one-minus-dst-alpha",t.SrcAlphaSaturated="src-alpha-saturated",t.Constant="constant",t.OneMinusConstant="one-minus-constant",t.Src1Color="src1",t.OneMinusSrc1Color="one-minus-src1",t.Src1Alpha="src1-alpha",t.OneMinusSrc1Alpha="one-minus-src1-alpha"}(n||(n={})),function(t){t.Never="never",t.Less="less",t.Equal="equal",t.LessEqual="less-equal",t.Greater="greater",t.NotEqual="not-equal",t.GreaterEqual="greater-equal",t.Always="always"}(a||(a={})),function(t){t.ReadWrite="read-write",t.Read="read-only",t.Write="write-only"}(o||(o={}));class g{constructor(){this._adapter=null,this._device=null,this._context=null,this._format=i.Rgba8UnormSrgb,this._canvas=null,this._colorSpace=t.sRGB}get adapter(){return this._adapter}get device(){return this._device}get context(){return this._context}get format(){return this._format}get colorSpace(){return this._colorSpace}get canvas(){return this._canvas}static isSupported(){return"undefined"!=typeof navigator&&"gpu"in navigator}async initialize(e={}){if(!g.isSupported())throw new Error("WebGPU is not supported in this browser");if(this._adapter=await navigator.gpu.requestAdapter({powerPreference:e.powerPreference??"high-performance"}),!this._adapter)throw new Error("Failed to get WebGPU adapter");if(this._device=await this._adapter.requestDevice({requiredFeatures:e.requiredFeatures,requiredLimits:e.requiredLimits}),!this._device)throw new Error("Failed to get WebGPU device");if(this._device.lost.then(t=>{console.error("WebGPU device lost:",t.message),"destroyed"!==t.reason&&this.initialize(e).catch(t=>{console.error("Failed to reinitialize WebGPU context:",t)})}),e.canvas){if(this._canvas=e.canvas,this._context=this._canvas.getContext("webgpu"),!this._context)throw new Error("Failed to get WebGPU context from canvas");const r=window.matchMedia("(color-gamut: p3)").matches;this._colorSpace=e.colorSpace??t.sRGB,this._colorSpace!==t.DisplayP3||r||(this._colorSpace=t.sRGB,console.warn("DisplayP3 not supported, falling back to sRGB")),this._format=navigator.gpu.getPreferredCanvasFormat(),this._context.configure({device:this._device,format:this._format,colorSpace:this._colorSpace,alphaMode:"premultiplied"})}else console.warn("No canvas provided!")}getCurrentTexture(){return this._context.getCurrentTexture()}destroy(){this._device&&(this._device.destroy(),this._device=null),this._adapter=null,this._context=null,this._canvas=null}}function d(t,e){if(void 0!==t)return e(t)}class b{constructor(t){this._numVertices=0,this._numIndices=0,this._inner=t}setPipeline(t){return this._renderPipeline!=t&&(this._inner.setPipeline(t._inner),this._renderPipeline=t),this}setMesh(t){for(let e=0;e<t.numStreams;++e){const r=t.getVertexBuffer(e);this._inner.setVertexBuffer(e,r._inner)}this._numVertices=t.numVertices;const e=t.indexBuffer;return e?(this._inner.setIndexBuffer(e._inner,t.indexFormat),this._numIndices=t.numIndices):this._numIndices=0,this}setBindGroup(t,e){return this._inner.setBindGroup(t,e._inner),this}draw(){return this._numIndices?this._inner.drawIndexed(this._numIndices,1,0,0,0):this._inner.draw(this._numVertices,1,0,0),this}end(){this._inner.end()}}class f{constructor(t,e,r,s){this._colorTargets=[],this._clearColors=[],this._encoder=t,this._defaultTarget=r,this._defaultDepthTarget=s,this._globalBindGroups=e}withLabel(t){return this._label=t,this}withColorTarget(t){return this._colorTargets.push(t),this}withDepthStencilTarget(t){return this._depthTarget=t,this}withClearColor(t,e,r,s){let i;return i=void 0===t?[0,0,0,1]:"number"==typeof t?[t,e??0,r??0,s??1]:[t[0],t[1],t[2],t[3]??1],0===this._colorTargets.length?this._clearColors[0]=i:this._clearColors[this._colorTargets.length-1]=i,this}withClearStencil(t){return this._clearStencil=t,this}withClearDepth(t){return this._clearDepth=t,this}build(){let t,e,r,s,n;this._colorTargets.length||this._depthTarget?(t=this._colorTargets,e=this._depthTarget):(t=[this._defaultTarget],e=this._defaultDepthTarget),e?.format!==i.Depth32FloatStencil8&&e?.format!==i.Depth24PlusStencil8||(r=null!=this._clearStencil?"clear":"load",s=d(this._clearStencil,()=>"store"),n=this._clearStencil);const a={colorAttachments:t.map((t,e)=>({view:t._inner,loadOp:this._clearColors[e]?"clear":"load",storeOp:"store",clearValue:this._clearColors[e]})),depthStencilAttachment:d(e,t=>({view:t._inner,depthClearValue:this._clearDepth,depthLoadOp:null!=this._clearDepth?"clear":"load",depthStoreOp:d(this._clearDepth,()=>"store"),stencilClearValue:n,stencilLoadOp:r,stencilStoreOp:s})),label:this._label},o=new b(this._encoder.beginRenderPass(a));return this._globalBindGroups.forEach((t,e)=>o.setBindGroup(e,t)),o}}class p{constructor(t){this._inner=t}setPipeline(t){return this._inner.setPipeline(t._inner),this}dispatch(t,e,r){return this._inner.dispatchWorkgroups(t,e,r),this}dispatchIndirect(t,e){return this._inner.dispatchWorkgroupsIndirect(t._inner,e),this}setBindGroup(t,e){return this._inner.setBindGroup(t,e._inner),this}end(){this._inner.end()}}class x{constructor(t,e){this._encoder=t,this._globalBindGroups=e}withLabel(t){return this._label=t,this}build(){const t={label:this._label},e=new p(this._encoder.beginComputePass(t));for(let t=0;t<this._globalBindGroups.length;++t)e.setBindGroup(t,this._globalBindGroups[t]);return e}}class U{constructor(t,e,r,s,i){this._commandBuffer=null;const n=r.device;this._queue=n.queue,this._backbufferTarget=t,this._depthStencilTarget=s,this._globalBindGroups=e,this._encoder=n.createCommandEncoder({label:i})}clearBuffer(t,e,r){return this._encoder.clearBuffer(t._inner,e,r),this}createRenderPass(){return new f(this._encoder,this._globalBindGroups,this._backbufferTarget,this._depthStencilTarget)}createComputePass(){return new x(this._encoder,this._globalBindGroups)}finish(){this._commandBuffer||(this._commandBuffer=this._encoder.finish())}submit(){this.finish(),this._queue.submit([this._commandBuffer])}}class S{static from_webgpu(t,e){return new S(t,e)}constructor(t,e){this._inner=t,this._format=e}createView(){return new A(this)}get format(){return this._format}_getBufferResource(){return this._inner.createView()}}class w{constructor(t){this._size=[1,1,1],this._data=void 0,this._format=i.Rgba8UnormSrgb,this._usage=GPUTextureUsage.TEXTURE_BINDING,this._ctx=t}withSize(t,e,r=1){return this._size=[t,e,r],this}withData(t){return this._data=t,this}withFormat(t){return this._format=t,this}withImage(t){return this._data=t,this._size=[t.width,t.height,1],this}withUsage(t){return this._usage|=t,this}build(){this._data&&(this._usage|=GPUTextureUsage.COPY_DST);const t=this._ctx.device.createTexture({format:this._format,size:this._size,usage:this._usage});if(this._data instanceof ImageBitmap)this._ctx.device.queue.copyExternalImageToTexture({source:this._data},{texture:t},[this._size[0],this._size[1],1]);else if(this._data){const[e,r,s]=this._size,n=function(t){if(function(t){switch(t){case i.Bc1RgbaUnorm:case i.Bc1RgbaUnormSrgb:case i.Bc2RgbaUnorm:case i.Bc2RgbaUnormSrgb:case i.Bc3RgbaUnorm:case i.Bc3RgbaUnormSrgb:case i.Bc4RUnorm:case i.Bc4RSnorm:case i.Bc5RgUnorm:case i.Bc5RgSnorm:case i.Bc6hRgbUfloat:case i.Bc6hRgbFloat:case i.Bc7RgbaUnorm:case i.Bc7RgbaUnormSrgb:return!0;default:return!1}}(t)||function(t){switch(t){case i.Etc2Rgb8Unorm:case i.Etc2Rgb8UnormSrgb:case i.Etc2Rgb8A1Unorm:case i.Etc2Rgb8A1UnormSrgb:case i.Etc2Rgba8Unorm:case i.Etc2Rgba8UnormSrgb:case i.EacR11Unorm:case i.EacR11Snorm:case i.EacRg11Unorm:case i.EacRg11Snorm:return!0;default:return!1}}(t))return 4;switch(t){case i.Astc4x4Unorm:case i.Astc4x4UnormSrgb:return 4;case i.Astc5x4Unorm:case i.Astc5x4UnormSrgb:case i.Astc5x5Unorm:case i.Astc5x5UnormSrgb:return 5;case i.Astc6x5Unorm:case i.Astc6x5UnormSrgb:case i.Astc6x6Unorm:case i.Astc6x6UnormSrgb:return 6;case i.Astc8x5Unorm:case i.Astc8x5UnormSrgb:case i.Astc8x6Unorm:case i.Astc8x6UnormSrgb:case i.Astc8x8Unorm:case i.Astc8x8UnormSrgb:return 8;case i.Astc10x5Unorm:case i.Astc10x5UnormSrgb:case i.Astc10x6Unorm:case i.Astc10x6UnormSrgb:case i.Astc10x8Unorm:case i.Astc10x8UnormSrgb:case i.Astc10x10Unorm:case i.Astc10x10UnormSrgb:return 10;case i.Astc12x10Unorm:case i.Astc12x10UnormSrgb:case i.Astc12x12Unorm:case i.Astc12x12UnormSrgb:return 12;default:return 1}}(this._format),a=Math.ceil(e/n)*function(t){switch(t){case i.R8Unorm:case i.R8Snorm:case i.R8Uint:case i.R8Sint:case i.Stencil8:return 1;case i.R16Uint:case i.R16Sint:case i.R16Unorm:case i.R16Snorm:case i.R16Float:case i.RG8Unorm:case i.RG8Snorm:case i.RG8Uint:case i.RG8Sint:case i.Depth16Unorm:return 2;case i.R32Uint:case i.R32Sint:case i.R32Float:case i.RG16Uint:case i.RG16Sint:case i.RG16Unorm:case i.RG16Snorm:case i.RG16Float:case i.Rgba8Unorm:case i.Rgba8UnormSrgb:case i.Rgba8Snorm:case i.Rgba8Uint:case i.Rgba8Sint:case i.Bgra8Unorm:case i.Bgra8UnormSrgb:case i.Rgb9e5Ufloat:case i.Rgb10a2Uint:case i.Rgb10a2Unorm:case i.Depth24Plus:case i.Depth24PlusStencil8:case i.Depth32Float:return 4;case i.Rg11b10Ufloat:case i.RG32Uint:case i.RG32Sint:case i.RG32Float:case i.Rgba16Uint:case i.Rgba16Sint:case i.Rgba16Unorm:case i.Rgba16Snorm:case i.Rgba16Float:case i.Depth32FloatStencil8:case i.Bc1RgbaUnorm:case i.Bc1RgbaUnormSrgb:case i.Bc4RUnorm:case i.Bc4RSnorm:case i.Etc2Rgb8Unorm:case i.Etc2Rgb8UnormSrgb:case i.Etc2Rgb8A1Unorm:case i.Etc2Rgb8A1UnormSrgb:case i.EacR11Unorm:case i.EacR11Snorm:return 8;case i.Rgba32Uint:case i.Rgba32Sint:case i.Rgba32Float:case i.Bc2RgbaUnorm:case i.Bc2RgbaUnormSrgb:case i.Bc3RgbaUnorm:case i.Bc3RgbaUnormSrgb:case i.Bc5RgUnorm:case i.Bc5RgSnorm:case i.Bc6hRgbUfloat:case i.Bc6hRgbFloat:case i.Bc7RgbaUnorm:case i.Bc7RgbaUnormSrgb:case i.Etc2Rgba8Unorm:case i.Etc2Rgba8UnormSrgb:case i.EacRg11Unorm:case i.EacRg11Snorm:case i.Astc4x4Unorm:case i.Astc4x4UnormSrgb:case i.Astc5x4Unorm:case i.Astc5x4UnormSrgb:case i.Astc5x5Unorm:case i.Astc5x5UnormSrgb:case i.Astc6x5Unorm:case i.Astc6x5UnormSrgb:case i.Astc6x6Unorm:case i.Astc6x6UnormSrgb:case i.Astc8x5Unorm:case i.Astc8x5UnormSrgb:case i.Astc8x6Unorm:case i.Astc8x6UnormSrgb:case i.Astc8x8Unorm:case i.Astc8x8UnormSrgb:case i.Astc10x5Unorm:case i.Astc10x5UnormSrgb:case i.Astc10x6Unorm:case i.Astc10x6UnormSrgb:case i.Astc10x8Unorm:case i.Astc10x8UnormSrgb:case i.Astc10x10Unorm:case i.Astc10x10UnormSrgb:case i.Astc12x10Unorm:case i.Astc12x10UnormSrgb:case i.Astc12x12Unorm:case i.Astc12x12UnormSrgb:case i.Bc2RgbaUnorm:return 16;default:throw new Error(`Unsupported texture format: ${t}`)}}(this._format);this._ctx.device.queue.writeTexture({texture:t},this._data,{bytesPerRow:a},{width:e,height:r,depthOrArrayLayers:s})}return new S(t,this._format)}}class R{constructor(t){this._inner=t}}class A{constructor(t){this._desc={},this._texture=t}withSingleMip(t){return this._desc.baseMipLevel=t,this._desc.mipLevelCount=1,this}withMipRange(t,e){return this._desc.baseMipLevel=t,this._desc.mipLevelCount=e-t,this}withSingleLayer(t){return this._desc.baseArrayLayer=t,this._desc.arrayLayerCount=1,this}withLayerRange(t,e){return this._desc.baseArrayLayer=t,this._desc.arrayLayerCount=e,this}build(){return new R(this._texture._inner.createView(this._desc))}}class y{constructor(t,e){this._inner=t,this._format=e}get format(){return this._format}}class B{constructor(t){this._baseMipLevel=0,this._baseArrayLayer=0,this._texture=t}withMipLevel(t){return this._baseMipLevel=t,this}withArrayLayer(t){return this._baseArrayLayer=t,this}build(){const t=this._texture._inner,e={format:t.format,dimension:t.dimension,aspect:"all",baseMipLevel:this._baseMipLevel,mipLevelCount:1,baseArrayLayer:this._baseArrayLayer,arrayLayerCount:1};return new y(this._texture._inner.createView(e),this._texture.format)}}!function(t){t[t.MapRead=GPUBufferUsage.MAP_READ]="MapRead",t[t.MapWrite=GPUBufferUsage.MAP_WRITE]="MapWrite",t[t.CopySrc=GPUBufferUsage.COPY_SRC]="CopySrc",t[t.CopyDst=GPUBufferUsage.COPY_DST]="CopyDst",t[t.Index=GPUBufferUsage.INDEX]="Index",t[t.Vertex=GPUBufferUsage.VERTEX]="Vertex",t[t.Uniform=GPUBufferUsage.UNIFORM]="Uniform",t[t.Storage=GPUBufferUsage.STORAGE]="Storage",t[t.Indirect=GPUBufferUsage.INDIRECT]="Indirect",t[t.QueryResolve=GPUBufferUsage.QUERY_RESOLVE]="QueryResolve"}(c||(c={})),function(t){t[t.CopySrc=GPUTextureUsage.COPY_SRC]="CopySrc",t[t.CopyDst=GPUTextureUsage.COPY_DST]="CopyDst",t[t.TextureBinding=GPUTextureUsage.TEXTURE_BINDING]="TextureBinding",t[t.StorageBinding=GPUTextureUsage.STORAGE_BINDING]="StorageBinding",t[t.RenderAttachment=GPUTextureUsage.RENDER_ATTACHMENT]="RenderAttachment"}(h||(h={}));class F{constructor(t){this._size=0,this._keepData=!1,this._usage=0,this._ctx=t}withUsage(t){return this._usage|=t,this}withData(t,e=!1){return this._data=t,this._size=t.byteLength,this._keepData=e,this._usage|=c.CopyDst,this}withSize(t){return this._size=t,this}build(){const t=d(this._data,t=>function(t){const e=4*Math.ceil(t.byteLength/4);if(e===t.byteLength)return t;const r=t instanceof ArrayBuffer?new ArrayBuffer(e):new SharedArrayBuffer(e),s=new Uint8Array(t);return new Uint8Array(r).set(s),r}(t)),e=this._ctx.device.createBuffer({size:t?t.byteLength:this._size,usage:this._usage});return t&&this._ctx.device.queue.writeBuffer(e,0,t),new v(e,this._keepData?this._data:void 0)}}class v{constructor(t,e){this._inner=t,this.data=e}get size(){return this._inner.size}_uploadData(t){this.data?t.device.queue.writeBuffer(this._inner,0,this.data):console.warn("Buffer has no data to upload.")}_getBufferResource(){return{buffer:this._inner}}}function T(t){const e=new Float32Array(1);e[0]=t;const r=new Uint32Array(e.buffer)[0],s=r>>16&32768,i=(r>>23&255)-127;return i<=-15?s:i>16?31744|s:s|i+15<<10|(8388607&r)>>13}function G(t){switch(t){case u.Float16:return 2;case u.Float32:return 4;case u.Boolean:return 1;default:throw new Error("Unknown BaseType.")}}!function(t){t[t.Float16=0]="Float16",t[t.Float32=1]="Float32",t[t.Uint=2]="Uint",t[t.Sint=3]="Sint",t[t.Boolean=4]="Boolean"}(u||(u={})),function(t){t[t.Scalar=0]="Scalar",t[t.Vec=1]="Vec",t[t.Matrix=2]="Matrix",t[t.Array=3]="Array"}(l||(l={}));class E{constructor(t,e,r,s){if(this.numRows=1,this.numCols=1,e===l.Scalar&&1!==r&&1!==s)throw new Error("Scalar member must have numRows = 1.");this.baseType=t,this.containerType=e,this.numRows=r,this.numCols=s}get size(){const t=this.numCols>1&&3===this.numRows?4:this.numRows;return G(this.baseType)*t*this.numCols}get alignment(){const t=3===this.numRows?4:this.numRows;return G(this.baseType)*t}}class M{constructor(){this._size=0,this._members=new Map}withSize(t){if(0!==this._size)throw new Error("Size already set.");return this._size=t,this}pushScalar(t,e){return this._pushField(t,e,l.Scalar)}pushVec2(t,e){return this._pushField(t,e,l.Vec,2)}pushVec3(t,e){return this._pushField(t,e,l.Vec,3)}pushVec4(t,e){return this._pushField(t,e,l.Vec,4)}pushMatrix(t,e,r,s){if(!Number.isInteger(e)||!Number.isInteger(r))throw new Error("Matrix dimensions must be integers");if(e<2||e>4||r<2||r>4)throw new Error("Matrix dimensions must be between 2 and 4 (inclusive)");return this._pushField(t,s,l.Matrix,e,r)}build(){return this._size=16*Math.ceil(this._size/16),new C(this._size,this._members)}_pushField(t,e,r,s=1,i=1){const n=new E(t,r,s,i),a=n.alignment,o=Math.ceil(this._size/a)*a;return this._members.set(e,{offset:o,type:n}),this._size=o+n.size,this}}class C{constructor(t,e){this.size=t,this._members=e}_createDataViews(t){const e=new Map;for(const[r,s]of this._members){let i;const n=s.type.size;let a=4;switch(s.type.baseType){case u.Float16:a=2,i=Uint16Array;break;case u.Float32:i=Float32Array;break;case u.Uint:case u.Boolean:i=Uint32Array;break;case u.Sint:i=Int32Array}e.set(r,[s,new i(t,s.offset,n/a)])}return e}_getMemberOrThrow(t){const e=this._members.get(t);if(!e)throw new Error(`Member ${t} not found in layout.`);return e}}class L{constructor(t,e){this._dataViews=new Map;const r=new ArrayBuffer(t.size);this._buffer=new F(e).withUsage(GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST).withData(r,!0).build(),this._data=this._buffer.data,this._dataViews=t._createDataViews(this._data),this._ctx=e}setScalar(t,e){const[r,s]=this._dataViews.get(t);return r.type.baseType===u.Float16?s[0]=T(e):s[0]=e,this}setVec(t,e){const[r,s]=this._dataViews.get(t);if(r.type.baseType==u.Float16)for(let t=0;t<e.length;++t)s[t]=T(e[t]);else for(let t=0;t<e.length;++t)s[t]=e[t];return this}setMatrix(t,e){const[r,s]=this._dataViews.get(t),i=r.type.numCols,n=r.type.numRows,a=3===n;let o=0;if(r.type.baseType===u.Float16)for(let t=0;t<i;++t){for(let t=0;t<n;++t)s[o]=T(e[o]),++o;a&&++o}else for(let t=0;t<i;++t){for(let t=0;t<n;++t)s[o]=e[o],++o;a&&++o}return this}upload(){return this._buffer._uploadData(this._ctx),this}_getBufferResource(){return{buffer:this._buffer._inner}}}class P{constructor(t){this._inner=t}}class D{constructor(t,e){this._entries=[],this._ctx=t,this._layout=e}withLabel(t){return this._label=t,this}withBuffer(t,e){const r=this._layout._getBindingIndex(t);return this._entries[r]={binding:r,resource:e._getBufferResource()},this}withTexture(t,e){const r=this._layout._getBindingIndex(t);return this._entries[r]={binding:r,resource:e._inner},this}withSampler(t,e){const r=this._layout._getBindingIndex(t);return this._entries[r]={binding:r,resource:e._inner},this}build(){const t=this._ctx.device.createBindGroup({label:this._label,entries:this._entries,layout:this._layout._inner});return new P(t)}}class O{constructor(t,e,r,s){this._inner=t,this._indices=r,this._uboLayouts=s,this._ctx=e}getUniformBufferLayout(t){return this._uboLayouts.get(t)}createUniformBuffer(t){return d(this._uboLayouts.get(t),t=>new L(t,this._ctx))}_getBindingIndex(t){const e=this._indices.get(t);if(void 0===e)throw`No field name found for ${t} in bind group layout.`;return e}}const V=class{constructor(t){this._entries=[],this._indices=new Map,this._uboLayouts=new Map,this._ctx=t}withLabel(t){return this._label=t,this}withUniformBuffer(t,e,r,s){return this._entries[t]={binding:t,visibility:s??GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT|GPUShaderStage.COMPUTE,buffer:{type:"uniform"}},this._indices.set(e,t),this._uboLayouts.set(e,r),this}withStorageBuffer(t,e,r,s){let i="storage";return r===o.Read&&(i="read-only-storage"),this._entries[t]={binding:t,visibility:s??GPUShaderStage.FRAGMENT|GPUShaderStage.COMPUTE,buffer:{type:i,hasDynamicOffset:!1,minBindingSize:4}},this._indices.set(e,t),this}withStorageTexture(t,e,r,s,i){return this._entries[t]={binding:t,visibility:i??GPUShaderStage.FRAGMENT|GPUShaderStage.COMPUTE,storageTexture:{access:s,format:r}},this._indices.set(e,t),this}withTexture(t,e,r){return this._entries[t]={binding:t,visibility:r??GPUShaderStage.FRAGMENT|GPUShaderStage.COMPUTE,texture:{sampleType:"float"}},this._indices.set(e,t),this}withSampler(t,e,r){return this._entries[t]={binding:t,visibility:r??GPUShaderStage.FRAGMENT|GPUShaderStage.COMPUTE,sampler:{type:"filtering"}},this._indices.set(e,t),this}build(){const t=this._ctx.device.createBindGroupLayout({label:this._label,entries:this._entries});return new O(t,this._ctx,this._indices,this._uboLayouts)}};class I{constructor(t,e,r,s){this._inner=t,this._ctx=e,this._vertexAttributes=r,this._bindGroupLayouts=s}getVertexAttributeLocation(t){return this._vertexAttributes.get(t)??void 0}hasVertexAttribute(t){return this._vertexAttributes.has(t)}createBindGroup(t){return new D(this._ctx,this._bindGroupLayouts[t])}}class z{constructor(t){this._vertexAttributes=new Map,this._includes=new Map,this._ctx=t}withLabel(t){return this._label=t,this}withCode(t){return this._code=t,this}withInclude(t,e){return this._includes.set(t,e),this}withVertexAttribute(t,e){return this._vertexAttributes.set(t,e),this}withBindGroup(t,e){if(this._bindGroupLayouts=this._bindGroupLayouts??[],e instanceof O)this._bindGroupLayouts[t]=e;else{const r=new V(this._ctx);e(r),this._bindGroupLayouts[t]=r.build()}return this}build(){if(!this._code)throw new Error("Shader code not specified. Use withCode() to set the shader source.");let t=this._code;for(const[e,r]of this._includes){const s=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),i=new RegExp(`#\\s*include\\s*<\\s*${s}\\s*>`,"g");t=t.replace(i,r)}const e=this._ctx.device.createShaderModule({label:this._label,code:t});return new I(e,this._ctx,this._vertexAttributes,this._bindGroupLayouts)}}class k{constructor(t,e){this._inner=t,this._shader=e}getVertexAttributeLocation(t){return this._shader.getVertexAttributeLocation(t)}}class N{constructor(t,e){this._colorTargets=[],this._vertexEntry=void 0,this._fragmentEntry=void 0,this._label=void 0,this._overrideConstants={},this._cullMode=s.Back,this._mesh=void 0,this._ctx=t,this._defaultColorState=[{format:t.format,blend:void 0,writeMask:GPUColorWrite.ALL}],this._defaultDepthState=d(e,t=>({format:t,depthWriteEnabled:!0,depthCompare:"less"}))}withLabel(t){return this._label=t,this}withCullMode(t){return this._cullMode=t,this}withMesh(t){return this._mesh=t,this}withShader(t){return this._shader=t,this}withVertexShader(t){return this._vertexEntry=t,this}withFragmentShader(t){return this._fragmentEntry=t,this}withColorTarget(t){return this._colorTargets.push({format:t,blend:void 0,writeMask:GPUColorWrite.ALL}),this}withDepthTarget(t){return this._depthState={format:t,...this._defaultDepthState},this}withDepthCompare(t){const e=this._depthState??this._defaultDepthState;return e?e.depthCompare=t:console.warn("No depth target set. Setting depth compare function has no effect."),this}withDepthWrite(t){const e=this._depthState??this._defaultDepthState;return e?e.depthWriteEnabled=t:console.warn("No depth target set. Setting depth write enabled has no effect."),this}withOverrideConstant(t,e){return this._overrideConstants[t]=e,this}withBlendMode(t){return this.lastColorTarget.blend=t._inner,this}build(){if(!this._shader)throw new Error("Shader not specified. Use withShader() to set the shader to use.");const t=this._shader;if(void 0===this._vertexEntry)throw new Error("Shader does not contain a vertex entry point. Use ShaderBuilder.withVertexShader() to set one.");let e,r;this._colorTargets.length||this._depthState?(e=this._colorTargets,r=this._depthState):(e=this._defaultColorState,r=this._defaultDepthState);const s=d(this._mesh,t=>({topology:t.topology,frontFace:t.frontFace,cullMode:this._cullMode})),i=d(this._mesh,e=>{const r=[];for(let s=0;s<e.numStreams;++s){const i=e.getStreamAttributes(s).filter(e=>t.hasVertexAttribute(e.name)).map(e=>({shaderLocation:t.getVertexAttributeLocation(e.name),offset:e.offset,format:e.format}));r.push({arrayStride:e.getStreamStride(s),stepMode:"vertex",attributes:i})}return r}),n=d(t._bindGroupLayouts,t=>this._ctx.device.createPipelineLayout({bindGroupLayouts:t.map(t=>t._inner),label:this._label}))??"auto",a={label:this._label,layout:n,primitive:s,depthStencil:r,vertex:{buffers:i,module:t._inner,entryPoint:this._vertexEntry,constants:this._overrideConstants},fragment:d(this._fragmentEntry,r=>({module:t._inner,entryPoint:r,targets:e,constants:this._overrideConstants}))},o=this._ctx.device.createRenderPipeline(a);return new k(o,t)}get lastColorTarget(){return this._colorTargets.length?this._colorTargets[this._colorTargets.length-1]:this._defaultColorState[0]}}var W,q,Y,H;!function(t){t.Uint16="uint16",t.Uint32="uint32"}(W||(W={}));class ${constructor(t,e,r=!1){const s=t.BYTES_PER_ELEMENT;this.format=2===s?W.Uint16:W.Uint32,this.count=t.length,this.buffer=new F(e).withData(t.buffer,r).withUsage(c.CopyDst|c.Index).build()}}!function(t){t.TriangleList="triangle-list",t.TriangleStrip="triangle-strip",t.LineList="line-list",t.LineStrip="line-strip",t.PointList="point-list"}(q||(q={})),function(t){t.Clockwise="cw",t.CounterClockwise="ccw"}(Y||(Y={})),function(t){t.Uint8="uint8",t.Uint8x2="uint8x2",t.Uint8x4="uint8x4",t.Sint8="sint8",t.Sint8x2="sint8x2",t.Sint8x4="sint8x4",t.Unorm8="unorm8",t.Unorm8x2="unorm8x2",t.Unorm8x4="unorm8x4",t.Snorm8="snorm8",t.Snorm8x2="snorm8x2",t.Snorm8x4="snorm8x4",t.Uint16="uint16",t.Uint16x2="uint16x2",t.Uint16x4="uint16x4",t.Sint16="sint16",t.Sint16x2="sint16x2",t.Sint16x4="sint16x4",t.Unorm16="unorm16",t.Unorm16x2="unorm16x2",t.Unorm16x4="unorm16x4",t.Snorm16="snorm16",t.Snorm16x2="snorm16x2",t.Snorm16x4="snorm16x4",t.Float16="float16",t.Float16x2="float16x2",t.Float16x4="float16x4",t.Float32="float32",t.Float32x2="float32x2",t.Float32x3="float32x3",t.Float32x4="float32x4",t.Uint32="uint32",t.Uint32x2="uint32x2",t.Uint32x3="uint32x3",t.Uint32x4="uint32x4",t.Sint32="sint32",t.Sint32x2="sint32x2",t.Sint32x3="sint32x3",t.Sint32x4="sint32x4",t.Unorm10_10_10_2="unorm10-10-10-2",t.Unorm8x4_bgra="unorm8x4-bgra"}(H||(H={}));class j{constructor(t,e,r,s){this._streams=[],this._topology=t,this._frontFace=e,this._streams=r,this._indexBuffer=s,this._numVertices=this._streams[0].numVertices,this._streams.forEach(t=>console.assert(t.numVertices===this._numVertices,"All vertex streams must have the same number of vertices."))}get topology(){return this._topology}get frontFace(){return this._frontFace}get numStreams(){return this._streams.length}get numVertices(){return this._numVertices}getVertexBuffer(t){return this._streams[t].buffer}getStreamStride(t){return this._streams[t].stride}getStreamAttributes(t){return this._streams[t].attributes}get indexBuffer(){return this._indexBuffer?.buffer}get indexFormat(){return this._indexBuffer?.format??W.Uint16}get numIndices(){return this._indexBuffer?.count??0}}class X{constructor(){this.stride=0,this.attributes=[]}pushAttribute(t,e){this.attributes.push({name:t,format:e,offset:this.stride}),this.stride+=function(t){switch(t){case H.Uint8:case H.Sint8:case H.Unorm8:case H.Snorm8:return 1;case H.Uint8x2:case H.Sint8x2:case H.Unorm8x2:case H.Snorm8x2:case H.Uint16:case H.Sint16:case H.Unorm16:case H.Snorm16:case H.Float16:return 2;case H.Uint8x4:case H.Sint8x4:case H.Unorm8x4:case H.Snorm8x4:case H.Uint16x2:case H.Sint16x2:case H.Unorm16x2:case H.Snorm16x2:case H.Float16x2:case H.Float32:case H.Uint32:case H.Sint32:case H.Unorm10_10_10_2:case H.Unorm8x4_bgra:return 4;case H.Uint16x4:case H.Sint16x4:case H.Unorm16x4:case H.Snorm16x4:case H.Float16x4:case H.Float32x2:case H.Uint32x2:case H.Sint32x2:return 8;case H.Float32x3:case H.Uint32x3:case H.Sint32x3:return 12;case H.Float32x4:case H.Uint32x4:case H.Sint32x4:return 16}}(e)}get numVertices(){return this.buffer.size/this.stride}}class Q{constructor(t,e){this._stream=t,this._ctx=e}pushAttribute(t,e){return this._stream.pushAttribute(t,e),this}withData(t,e=!1){this._stream.buffer=new F(this._ctx).withData(t,e).withUsage(c.Vertex|c.CopyDst).build()}}class Z{constructor(t){this._topology=q.TriangleList,this._frontFace=Y.CounterClockwise,this._streams=[],this._ctx=t}pushStream(t){const e=new X;return t(new Q(e,this._ctx)),console.assert(void 0!==e.buffer,"Vertex stream must have a buffer. Did you forget to call withData()?"),this._streams.push(e),this}withFrontFace(t){return this._frontFace=t,this}withTopology(t){return this._topology=t,this}withIndexData(t,e=!1){return this._indexBuffer=d(t,t=>new $(t,this._ctx,e)),this}build(){return console.assert(this._streams.length>0,"Mesh must have at least one vertex stream."),new j(this._topology,this._frontFace,this._streams,this._indexBuffer)}}class K{constructor(t){this._inner=t}}class J{constructor(t){this._ctx=t}withAddressMode(t,e,r){return this._addressModeU=t,this._addressModeV=e??t,this._addressModeW=r??t,this}withFiltering(t,e,r){return this._minFilter=t,this._magFilter=e??t,this._mipmapFilter=r??t,this}withTrilinearFiltering(){return this.withFiltering(e.Linear),this}withNearestFiltering(){return this.withFiltering(e.Nearest),this}withAnisotropicFiltering(t){return this.withFiltering(e.Linear),this._maxAnisotropy=t,this}withMinMipLevel(t){return this._minMipLevel=t,this}withMaxMipLevel(t){return this._maxMipLevel=t,this}withCompareFunction(t){return this._compare=t,this}build(){return new K(this._ctx.device.createSampler({addressModeU:this._addressModeU,addressModeV:this._addressModeV,addressModeW:this._addressModeW,magFilter:this._magFilter,minFilter:this._minFilter,mipmapFilter:this._mipmapFilter,lodMinClamp:this._minMipLevel,lodMaxClamp:this._maxMipLevel,compare:this._compare,maxAnisotropy:this._maxAnisotropy}))}}class tt{constructor(t){this._inner=t}}class et{constructor(t){this._ctx=t}withLabel(t){return this._label=t,this}withShader(t,e){return this._shader=t,this._entry=e,this}build(){const t=this._shader,e=d(t._bindGroupLayouts,t=>this._ctx.device.createPipelineLayout({bindGroupLayouts:t.map(t=>t._inner),label:this._label}))??"auto",r={label:this._label,compute:{module:t._inner,entryPoint:this._entry},layout:e};return new tt(this._ctx.device.createComputePipeline(r))}}class rt{get srcFactor(){return this._inner.color.srcFactor}set srcFactor(t){this._inner.color.srcFactor=t}get dstFactor(){return this._inner.color.dstFactor}set dstFactor(t){this._inner.color.dstFactor=t}get alphaSrcFactor(){return this._inner.alpha.srcFactor}set alphaSrcFactor(t){this._inner.alpha.srcFactor=t}get alphaDstFactor(){return this._inner.alpha.dstFactor}set alphaDstFactor(t){this._inner.alpha.dstFactor=t}constructor(t,e,r,s){this._inner={color:{srcFactor:n.SrcAlpha,dstFactor:n.OneMinusSrcAlpha},alpha:{srcFactor:n.One,dstFactor:n.OneMinusSrcAlpha}},this.srcFactor=t,this.dstFactor=e,this.alphaSrcFactor=r,this.alphaDstFactor=s}}rt.ALPHA=new rt(n.SrcAlpha,n.OneMinusSrcAlpha,n.One,n.OneMinusSrcAlpha),rt.ADDITIVE=new rt(n.SrcAlpha,n.One,n.One,n.One),rt.MULTIPLY=new rt(n.DstColor,n.Zero,n.Zero,n.One),rt.SCREEN=new rt(n.One,n.OneMinusSrcColor,n.One,n.OneMinusSrcAlpha),rt.OVERLAY=new rt(n.SrcAlpha,n.OneMinusSrcAlpha,n.One,n.OneMinusSrcAlpha),rt.DARKEN=new rt(n.One,n.OneMinusSrcColor,n.One,n.OneMinusSrcAlpha),rt.LIGHTEN=new rt(n.OneMinusSrcColor,n.One,n.One,n.OneMinusSrcAlpha);const st=class{constructor(t){this._options={},this._shaderIncludes=new Map,this._globalBindBufferLayouts=[],this._globalBindBuffers=[],this._context=new g,this._canvas=t}async initialize(t={}){t.canvas=this._canvas,this._options=t,await this._context.initialize(t),this._createDepthStencil()}resize(t,e){this._canvas.width=t,this._canvas.height=e,this._createDepthStencil()}addShaderInclude(t,e){return this._shaderIncludes.set(t,e),this}get depthStencilFormat(){return this._options.depthStencilFormat}get backbuffer(){if(!this._backbuffer)throw new Error("Backbuffer not initialized. Did you forget to call startFrame()?");return this._backbuffer}get backbufferTarget(){if(!this._backbufferTarget)throw new Error("Backbuffer not initialized. Did you forget to call startFrame()?");return this._backbufferTarget}get colorSpace(){return this._context.colorSpace}get backbufferFormat(){return this._context.format}get backbufferWidth(){return this._canvas.width}get backbufferHeight(){return this._canvas.height}startFrame(){this._backbuffer=S.from_webgpu(this._context.getCurrentTexture(),this._context.format),this._backbufferTarget=this.createRenderTarget(this._backbuffer).build()}createRenderTarget(t){return new B(t)}createShader(){let t=new z(this._context);return this._shaderIncludes.forEach((e,r)=>t=t.withInclude(r,e)),this._globalBindBufferLayouts.forEach((e,r)=>t.withBindGroup(r,e)),t}createBindGroupLayout(){return new V(this._context)}createBindGroup(t){return new D(this._context,t)}createMesh(){return new Z(this._context)}createRenderPipeline(){return new N(this._context,this._options.depthStencilFormat)}createComputePipeline(){return new et(this._context)}createSampler(){return new J(this._context)}createTexture(){return new w(this._context)}createCommandEncoder(t){return new U(this.backbufferTarget,this._globalBindBuffers,this._context,this._depthStencilTarget,t)}createUniformBufferLayout(){return new M}createUniformBuffer(t){return new L(t,this._context)}createBuffer(){return new F(this._context)}setGlobalBindGroup(t,e,r){return this._globalBindBufferLayouts[t]=e,this._globalBindBuffers[t]=r,this}destroy(){this._context.destroy()}depthStencilTexture(){return this._depthStencil}depthStencilTarget(){return this._depthStencilTarget}_createDepthStencil(){this._depthStencil=d(this._options.depthStencilFormat,t=>this.createTexture().withFormat(t).withSize(this._canvas.width,this._canvas.height).withUsage(GPUTextureUsage.RENDER_ATTACHMENT).build()),this._depthStencilTarget=d(this._depthStencil,t=>this.createRenderTarget(t).build())}};return _.default})());
1
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.TinyHelix=e():t.TinyHelix=e()}(this,()=>(()=>{"use strict";var t,e,r,s,i,n,a,o,c,h,u,l,d,_,m,g,p,b,f,x={d:(t,e)=>{for(var r in e)x.o(e,r)&&!x.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},S={};x.d(S,{default:()=>_t}),function(t){t.sRGB="srgb",t.DisplayP3="display-p3"}(t||(t={})),function(t){t.Nearest="nearest",t.Linear="linear"}(e||(e={})),function(t){t.ClampToEdge="clamp-to-edge",t.Repeat="repeat",t.MirrorRepeat="mirror-repeat"}(r||(r={})),function(t){t.None="none",t.Front="front",t.Back="back"}(s||(s={})),function(t){t.R8Unorm="r8unorm",t.R8Snorm="r8snorm",t.R8Uint="r8uint",t.R8Sint="r8sint",t.R16Unorm="r16unorm",t.R16Snorm="r16snorm",t.R16Uint="r16uint",t.R16Sint="r16sint",t.R16Float="r16float",t.RG8Unorm="rg8unorm",t.RG8Snorm="rg8snorm",t.RG8Uint="rg8uint",t.RG8Sint="rg8sint",t.R32Uint="r32uint",t.R32Sint="r32sint",t.R32Float="r32float",t.RG16Unorm="rg16unorm",t.RG16Snorm="rg16snorm",t.RG16Uint="rg16uint",t.RG16Sint="rg16sint",t.RG16Float="rg16float",t.Rgba8Unorm="rgba8unorm",t.Rgba8UnormSrgb="rgba8unorm-srgb",t.Rgba8Snorm="rgba8snorm",t.Rgba8Uint="rgba8uint",t.Rgba8Sint="rgba8sint",t.Bgra8Unorm="bgra8unorm",t.Bgra8UnormSrgb="bgra8unorm-srgb",t.Rgb9e5Ufloat="rgb9e5ufloat",t.Rgb10a2Uint="rgb10a2uint",t.Rgb10a2Unorm="rgb10a2unorm",t.Rg11b10Ufloat="rg11b10ufloat",t.RG32Uint="rg32uint",t.RG32Sint="rg32sint",t.RG32Float="rg32float",t.Rgba16Unorm="rgba16unorm",t.Rgba16Snorm="rgba16snorm",t.Rgba16Uint="rgba16uint",t.Rgba16Sint="rgba16sint",t.Rgba16Float="rgba16float",t.Rgba32Uint="rgba32uint",t.Rgba32Sint="rgba32sint",t.Rgba32Float="rgba32float",t.Stencil8="stencil8",t.Depth16Unorm="depth16unorm",t.Depth24Plus="depth24plus",t.Depth24PlusStencil8="depth24plus-stencil8",t.Depth32Float="depth32float",t.Depth32FloatStencil8="depth32float-stencil8",t.Bc1RgbaUnorm="bc1-rgba-unorm",t.Bc1RgbaUnormSrgb="bc1-rgba-unorm-srgb",t.Bc2RgbaUnorm="bc2-rgba-unorm",t.Bc2RgbaUnormSrgb="bc2-rgba-unorm-srgb",t.Bc3RgbaUnorm="bc3-rgba-unorm",t.Bc3RgbaUnormSrgb="bc3-rgba-unorm-srgb",t.Bc4RUnorm="bc4-r-unorm",t.Bc4RSnorm="bc4-r-snorm",t.Bc5RgUnorm="bc5-rg-unorm",t.Bc5RgSnorm="bc5-rg-snorm",t.Bc6hRgbUfloat="bc6h-rgb-ufloat",t.Bc6hRgbFloat="bc6h-rgb-float",t.Bc7RgbaUnorm="bc7-rgba-unorm",t.Bc7RgbaUnormSrgb="bc7-rgba-unorm-srgb",t.Etc2Rgb8Unorm="etc2-rgb8unorm",t.Etc2Rgb8UnormSrgb="etc2-rgb8unorm-srgb",t.Etc2Rgb8A1Unorm="etc2-rgb8a1unorm",t.Etc2Rgb8A1UnormSrgb="etc2-rgb8a1unorm-srgb",t.Etc2Rgba8Unorm="etc2-rgba8unorm",t.Etc2Rgba8UnormSrgb="etc2-rgba8unorm-srgb",t.EacR11Unorm="eac-r11unorm",t.EacR11Snorm="eac-r11snorm",t.EacRg11Unorm="eac-rg11unorm",t.EacRg11Snorm="eac-rg11snorm",t.Astc4x4Unorm="astc-4x4-unorm",t.Astc4x4UnormSrgb="astc-4x4-unorm-srgb",t.Astc5x4Unorm="astc-5x4-unorm",t.Astc5x4UnormSrgb="astc-5x4-unorm-srgb",t.Astc5x5Unorm="astc-5x5-unorm",t.Astc5x5UnormSrgb="astc-5x5-unorm-srgb",t.Astc6x5Unorm="astc-6x5-unorm",t.Astc6x5UnormSrgb="astc-6x5-unorm-srgb",t.Astc6x6Unorm="astc-6x6-unorm",t.Astc6x6UnormSrgb="astc-6x6-unorm-srgb",t.Astc8x5Unorm="astc-8x5-unorm",t.Astc8x5UnormSrgb="astc-8x5-unorm-srgb",t.Astc8x6Unorm="astc-8x6-unorm",t.Astc8x6UnormSrgb="astc-8x6-unorm-srgb",t.Astc8x8Unorm="astc-8x8-unorm",t.Astc8x8UnormSrgb="astc-8x8-unorm-srgb",t.Astc10x5Unorm="astc-10x5-unorm",t.Astc10x5UnormSrgb="astc-10x5-unorm-srgb",t.Astc10x6Unorm="astc-10x6-unorm",t.Astc10x6UnormSrgb="astc-10x6-unorm-srgb",t.Astc10x8Unorm="astc-10x8-unorm",t.Astc10x8UnormSrgb="astc-10x8-unorm-srgb",t.Astc10x10Unorm="astc-10x10-unorm",t.Astc10x10UnormSrgb="astc-10x10-unorm-srgb",t.Astc12x10Unorm="astc-12x10-unorm",t.Astc12x10UnormSrgb="astc-12x10-unorm-srgb",t.Astc12x12Unorm="astc-12x12-unorm",t.Astc12x12UnormSrgb="astc-12x12-unorm-srgb"}(i||(i={})),function(t){t.Zero="zero",t.One="one",t.SrcColor="src",t.OneMinusSrcColor="one-minus-src",t.SrcAlpha="src-alpha",t.OneMinusSrcAlpha="one-minus-src-alpha",t.DstColor="dst",t.OneMinusDstColor="one-minus-dst",t.DstAlpha="dst-alpha",t.OneMinusDstAlpha="one-minus-dst-alpha",t.SrcAlphaSaturated="src-alpha-saturated",t.Constant="constant",t.OneMinusConstant="one-minus-constant",t.Src1Color="src1",t.OneMinusSrc1Color="one-minus-src1",t.Src1Alpha="src1-alpha",t.OneMinusSrc1Alpha="one-minus-src1-alpha"}(n||(n={})),function(t){t.Never="never",t.Less="less",t.Equal="equal",t.LessEqual="less-equal",t.Greater="greater",t.NotEqual="not-equal",t.GreaterEqual="greater-equal",t.Always="always"}(a||(a={})),function(t){t.ReadWrite="read-write",t.Read="read-only",t.Write="write-only"}(o||(o={})),function(t){t.Float="float",t.Sint="sint",t.Uint="uint",t.UnfilterableFloat="unfilterable-float",t.Depth="depth"}(c||(c={})),function(t){t.Filtering="filtering",t.NonFiltering="non-filtering",t.Comparison="comparison"}(h||(h={})),function(t){t[t.Red=GPUColorWrite.RED]="Red",t[t.Green=GPUColorWrite.GREEN]="Green",t[t.Blue=GPUColorWrite.BLUE]="Blue"}(u||(u={})),function(t){t.D1="1d",t.D2="2d",t.D3="3d"}(l||(l={})),function(t){t.D1="1d",t.D2="2d",t.D2Array="2d-array",t.Cube="cube",t.CubeArray="cube-array",t.D3="3d"}(d||(d={})),function(t){t[t.Vertex=GPUShaderStage.VERTEX]="Vertex",t[t.Fragment=GPUShaderStage.FRAGMENT]="Fragment",t[t.Compute=GPUShaderStage.COMPUTE]="Compute"}(_||(_={})),function(t){t.Store="store",t.Discard="discard"}(m||(m={}));class U{constructor(){this._adapter=null,this._device=null,this._context=null,this._format=i.Rgba8UnormSrgb,this._canvas=null,this._colorSpace=t.sRGB,this._shaderF16Supported=!1,this._floatFilteringSupported=!1}get adapter(){return this._adapter}get device(){return this._device}get context(){return this._context}get format(){return this._format}get colorSpace(){return this._colorSpace}get canvas(){return this._canvas}static isSupported(){return"undefined"!=typeof navigator&&"gpu"in navigator}async initialize(e={}){if(!U.isSupported())throw new Error("WebGPU is not supported in this browser");if(this._adapter=await navigator.gpu.requestAdapter({powerPreference:e.powerPreference??"high-performance"}),!this._adapter)throw new Error("Failed to get WebGPU adapter");this._shaderF16Supported=this._adapter.features.has("shader-f16"),this._floatFilteringSupported=this._adapter.features.has("float32-filterable");const r=e.requiredFeatures?.includes("shader-f16");if(this._shaderF16Supported)r||(e.requiredFeatures=e.requiredFeatures??[],e.requiredFeatures?.push("shader-f16"));else{if(r)throw new Error("shader-f16 feature requested but not available");console.warn("WebGPU adapter does not support shader-f16 feature. Performance may be suboptimal for certain workloads.")}if(this._floatFilteringSupported&&!e.requiredFeatures?.includes("float32-filterable")&&(e.requiredFeatures=e.requiredFeatures??[],e.requiredFeatures?.push("float32-filterable")),this._device=await this._adapter.requestDevice({requiredFeatures:e.requiredFeatures,requiredLimits:e.requiredLimits}),!this._device)throw new Error("Failed to get WebGPU device");if(this._device.lost.then(t=>{console.error("WebGPU device lost:",t.message,"\nReason:",t.reason),"destroyed"!==t.reason&&this.initialize(e).catch(t=>{console.error("Failed to reinitialize WebGPU context:",t)})}),e.canvas){if(this._canvas=e.canvas,this._context=this._canvas.getContext("webgpu"),!this._context)throw new Error("Failed to get WebGPU context from canvas");const r=window.matchMedia("(color-gamut: p3)").matches;this._colorSpace=e.colorSpace??t.sRGB,this._colorSpace!==t.DisplayP3||r||(this._colorSpace=t.sRGB,console.warn("DisplayP3 not supported, falling back to sRGB")),this._format=navigator.gpu.getPreferredCanvasFormat(),this._context.configure({device:this._device,format:this._format,colorSpace:this._colorSpace,alphaMode:"premultiplied"})}else console.warn("No canvas provided!")}get shaderF16Supported(){return this._shaderF16Supported}get floatFilteringSupported(){return this._floatFilteringSupported}getCurrentTexture(){return this._context.getCurrentTexture()}destroy(){this._device&&(this._device.destroy(),this._device=null),this._adapter=null,this._context=null,this._canvas=null}}function w(t,e){if(void 0!==t)return e(t)}class R{constructor(t){this._numVertices=0,this._numIndices=0,this._inner=t}setPipeline(t){return this._renderPipeline!=t&&(this._inner.setPipeline(t._inner),this._renderPipeline=t),this}setMesh(t){for(let e=0;e<t.numStreams;++e){const r=t.getVertexBuffer(e);this._inner.setVertexBuffer(e,r._inner)}this._numVertices=t.numVertices;const e=t.indexBuffer;return e?(this._inner.setIndexBuffer(e._inner,t.indexFormat),this._numIndices=t.numIndices):this._numIndices=0,this}setBindGroup(t,e){return this._inner.setBindGroup(t,e._inner),this}draw(t=1){return this._numIndices?this._inner.drawIndexed(this._numIndices,t,0,0,0):this._inner.draw(this._numVertices,t,0,0),this}drawIndirect(t,e=0){return this._numIndices?this._inner.drawIndexedIndirect(t._inner,e):this._inner.drawIndirect(t._inner,e),this}end(){this._inner.end()}}class y{constructor(t,e,r,s){this._colorTargets=[],this._clearColors=[],this._storeOps=[],this._encoder=t,this._defaultTarget=r,this._defaultDepthTarget=s,this._globalBindGroups=e}withLabel(t){return this._label=t,this}withColorTarget(t){return this._colorTargets.push(t),this}withDepthStencilTarget(t){return this._depthTarget=t,this}withClearColor(t,e,r,s){let i;return i=void 0===t?[0,0,0,1]:"number"==typeof t?[t,e??0,r??0,s??1]:[t[0],t[1],t[2],t[3]??1],0===this._colorTargets.length?this._clearColors[0]=i:this._clearColors[this._colorTargets.length-1]=i,this}withStoreOp(t){return 0===this._colorTargets.length?this._storeOps[0]=t:this._storeOps[this._colorTargets.length-1]=t,this}withClearStencil(t){return this._clearStencil=t,this}withClearDepth(t){return this._clearDepth=t,this}build(){let t,e,r,s,n;this._colorTargets.length||this._depthTarget?(t=this._colorTargets,e=this._depthTarget):(t=[this._defaultTarget],e=this._defaultDepthTarget),e?.format!==i.Depth32FloatStencil8&&e?.format!==i.Depth24PlusStencil8||(r=null!=this._clearStencil?"clear":"load",s=w(this._clearStencil,()=>"store"),n=this._clearStencil);const a={colorAttachments:t.map((t,e)=>({view:t._inner,loadOp:this._clearColors[e]?"clear":"load",storeOp:this._storeOps[e]??"store",clearValue:this._clearColors[e]})),depthStencilAttachment:w(e,t=>({view:t._inner,depthClearValue:this._clearDepth,depthLoadOp:null!=this._clearDepth?"clear":"load",depthStoreOp:w(this._clearDepth,()=>"store"),stencilClearValue:n,stencilLoadOp:r,stencilStoreOp:s})),label:this._label},o=new R(this._encoder.beginRenderPass(a));return this._globalBindGroups.forEach((t,e)=>o.setBindGroup(e,t)),o}}class v{constructor(t){this._inner=t}setPipeline(t){return this._inner.setPipeline(t._inner),this}dispatch(t,e,r){return this._inner.dispatchWorkgroups(t,e,r),this}dispatchIndirect(t,e){return this._inner.dispatchWorkgroupsIndirect(t._inner,e),this}setBindGroup(t,e){return this._inner.setBindGroup(t,e._inner),this}end(){this._inner.end()}}class A{constructor(t,e){this._encoder=t,this._globalBindGroups=e}withLabel(t){return this._label=t,this}build(){const t={label:this._label},e=new v(this._encoder.beginComputePass(t));for(let t=0;t<this._globalBindGroups.length;++t)e.setBindGroup(t,this._globalBindGroups[t]);return e}}class B{constructor(t,e,r,s,i){this._commandBuffer=null;const n=r.device;this._queue=n.queue,this._backbufferTarget=t,this._depthStencilTarget=s,this._globalBindGroups=e,this._encoder=n.createCommandEncoder({label:i})}clearBuffer(t,e,r){return this._encoder.clearBuffer(t._inner,e,r),this}createRenderPass(){return new y(this._encoder,this._globalBindGroups,this._backbufferTarget,this._depthStencilTarget)}createComputePass(){return new A(this._encoder,this._globalBindGroups)}finish(){this._commandBuffer||(this._commandBuffer=this._encoder.finish())}submit(){this.finish(),this._queue.submit([this._commandBuffer])}}!function(t){t[t.MapRead=GPUBufferUsage.MAP_READ]="MapRead",t[t.MapWrite=GPUBufferUsage.MAP_WRITE]="MapWrite",t[t.CopySrc=GPUBufferUsage.COPY_SRC]="CopySrc",t[t.CopyDst=GPUBufferUsage.COPY_DST]="CopyDst",t[t.Index=GPUBufferUsage.INDEX]="Index",t[t.Vertex=GPUBufferUsage.VERTEX]="Vertex",t[t.Uniform=GPUBufferUsage.UNIFORM]="Uniform",t[t.Storage=GPUBufferUsage.STORAGE]="Storage",t[t.Indirect=GPUBufferUsage.INDIRECT]="Indirect",t[t.QueryResolve=GPUBufferUsage.QUERY_RESOLVE]="QueryResolve"}(g||(g={})),function(t){t[t.CopySrc=GPUTextureUsage.COPY_SRC]="CopySrc",t[t.CopyDst=GPUTextureUsage.COPY_DST]="CopyDst",t[t.TextureBinding=GPUTextureUsage.TEXTURE_BINDING]="TextureBinding",t[t.StorageBinding=GPUTextureUsage.STORAGE_BINDING]="StorageBinding",t[t.RenderAttachment=GPUTextureUsage.RENDER_ATTACHMENT]="RenderAttachment"}(p||(p={}));class F{constructor(t){this._size=0,this._keepData=!1,this._usage=0,this._dataOffset=0,this._ctx=t}withUsage(t){return this._usage|=t,this}withData(t,e=!1,r=0,s=t.byteLength){return this._data=t,this._size=s??t.byteLength-r,this._keepData=e,this._dataOffset=r,this._usage|=g.CopyDst,this}withSize(t){return this._size=t,this}build(){const t=w(this._data,t=>function(t,e,r,s){const i=4*Math.ceil(s/4);if(0===r&&s===t.byteLength&&i===s)return t;const n=t instanceof ArrayBuffer?new ArrayBuffer(i):new SharedArrayBuffer(i),a=new Uint8Array(t,r,s);return new Uint8Array(n).set(a),n}(t,0,this._dataOffset,this._size));this._keepData&&t&&(this._data=t),this._size=t?.byteLength??this._size;const e=this._ctx.device.createBuffer({size:this._size,usage:this._usage});return t&&this._ctx.device.queue.writeBuffer(e,0,t),new C(e,this._keepData?this._data:void 0)}}class C{constructor(t,e){this._inner=t,this.data=e}get size(){return this._inner.size}_uploadData(t){this.data?t.device.queue.writeBuffer(this._inner,0,this.data):console.warn("Buffer has no data to upload.")}_getBufferResource(){return{buffer:this._inner}}}class G{constructor(t,r,s){this._bindgroups=[],this._views=[],this._passDescs=[],this._ctx=t;const i=t.device.createSampler({label:"MipRenderer Bilinear Sampler",magFilter:e.Linear,minFilter:e.Linear,mipmapFilter:e.Nearest});this._bindgroupLayout=t.device.createBindGroupLayout({label:"MipRenderer BindGroup Layout",entries:[{binding:0,visibility:GPUShaderStage.FRAGMENT,texture:{sampleType:"float",viewDimension:s.dimension(),multisampled:!1}},{binding:1,visibility:GPUShaderStage.FRAGMENT,sampler:{type:"filtering"}}]}),this._pipeline=t.device.createRenderPipeline({label:"MipRenderer Pipeline",layout:t.device.createPipelineLayout({label:"MipRenderer Pipeline Layout",bindGroupLayouts:[this._bindgroupLayout]}),vertex:{module:r,entryPoint:"vs_main"},fragment:{module:r,entryPoint:"fs_main",targets:[{format:s.format}]},primitive:{topology:"triangle-list",stripIndexFormat:void 0,frontFace:"ccw",cullMode:"none"}});for(let e=0;e<s.mipLevelCount;++e)this._views.push(s.createView().withSingleMip(e).withUsage(p.RenderAttachment).withUsage(p.TextureBinding).build()._inner),0!==e&&(this._bindgroups.push(t.device.createBindGroup({label:`MipRenderer BindGroup Mip ${e}`,layout:this._bindgroupLayout,entries:[{binding:0,resource:this._views[e-1]},{binding:1,resource:i}]})),this._passDescs.push({label:`MipRenderer Render Pass mip ${e}`,colorAttachments:[{view:this._views[e],loadOp:"clear",storeOp:"store",clearValue:{r:0,g:0,b:0,a:0}}]}))}render(){const t=this._ctx.device.createCommandEncoder({label:"MipRenderer Command Encoder"});this._passDescs.forEach((e,r)=>{const s=t.beginRenderPass(e);s.setPipeline(this._pipeline),s.setBindGroup(0,this._bindgroups[r]),s.draw(3,1,0,0),s.end()}),this._ctx.device.queue.submit([t.finish()])}}class T{static from_webgpu(t,e,r,s){return new T(t,e,r,s)}constructor(t,e,r,s){this._inner=t,this._format=e,this._ctx=r,this._mipper=w(s,t=>new G(r,t,this))}createView(){return new M(this)}get format(){return this._format}get mipLevelCount(){return this._inner.mipLevelCount}get width(){return this._inner.width}get height(){return this._inner.height}get depthOrArrayLayers(){return this._inner.depthOrArrayLayers}_getBufferResource(){return this._inner.createView()}uploadImage(t,e=0){this._ctx.device.queue.copyExternalImageToTexture({source:t},{texture:this._inner,mipLevel:e},[t.width,t.height,1])}uploadData(t,e=0){const r=Math.max(this._inner.width>>e,1),s=Math.max(this._inner.height>>e,1),i=Math.max(this._inner.depthOrArrayLayers>>e,1),n=D.getBlockWidth(this._format),a=Math.ceil(r/n)*D.bytesPerBlock(this._format);this._ctx.device.queue.writeTexture({texture:this._inner,mipLevel:e},t,{bytesPerRow:a,rowsPerImage:s},{width:r,height:s,depthOrArrayLayers:i})}generateMipmaps(){if(this._inner.dimension!==l.D2)throw new Error("generateMipmaps currently only supports 2D textures.");this._mipper.render()}dimension(){switch(this._inner.dimension){case"1d":return l.D1;case"2d":return l.D2;case"3d":return l.D3;default:throw new Error(`Unknown texture dimension: ${this._inner.dimension}`)}}}class E{constructor(t,e){this._size=[1,1,1],this._format=i.Rgba8UnormSrgb,this._usage=GPUTextureUsage.TEXTURE_BINDING,this._dimension=l.D2,this._mipLevelCount=1,this._generateMips=!1,this._mipShader=e,this._ctx=t}withSize(t,e,r=1){return this._size=[t,e,r],r>1&&(this._dimension=l.D3),this}withDimension(t){return this._dimension=t,this}withMipLevels(t){return this._mipLevelCount=t??-1,this}withFormat(t){return this._format=t,this}withData(t,e=0){return this._data=this._data??[],this._data[e]=t,this._mipLevelCount=Math.max(this._mipLevelCount,e+1),this}withImage(t,e=0){return this._data=this._data??[],this._data[e]=t,0===e&&(this._size=[t.width,t.height,1]),this._mipLevelCount=Math.max(this._mipLevelCount,e+1),this}withGeneratedMipmaps(){return this._mipLevelCount=-1,this._generateMips=!0,this}withUsage(t){return this._usage|=t,this}build(){if(this._data&&(this._usage|=GPUTextureUsage.COPY_DST),this._generateMips&&(this._usage|=GPUTextureUsage.RENDER_ATTACHMENT),-1==this._mipLevelCount){const t=Math.max(this._size[0],this._size[1],this._size[2]);this._mipLevelCount=Math.floor(Math.log2(t))+1}const t=this._ctx.device.createTexture({format:this._format,size:this._size,usage:this._usage,dimension:this._dimension,mipLevelCount:this._mipLevelCount}),e=new T(t,this._format,this._ctx,this._generateMips?this._mipShader:void 0);if(this._data){const t=this._generateMips?1:this._mipLevelCount;for(let r=0;r<t;r++){const t=this._data[r];if(!t)throw new Error(`TextureBuilder: Missing data for mip level ${r}`);t instanceof ImageBitmap?e.uploadImage(t,r):e.uploadData(t,r)}this._generateMips&&e.generateMipmaps()}return e}}class L{constructor(t){this._inner=t}}class M{constructor(t){this._desc={},this._texture=t}withUsage(t){return void 0===this._desc.usage&&(this._desc.usage=0),this._desc.usage|=t,this}withSingleMip(t){return this._desc.baseMipLevel=t,this._desc.mipLevelCount=1,this}withMipRange(t,e){return this._desc.baseMipLevel=t,this._desc.mipLevelCount=e-t,this}withSingleLayer(t){return this._desc.baseArrayLayer=t,this._desc.arrayLayerCount=1,this}withLayerRange(t,e){return this._desc.baseArrayLayer=t,this._desc.arrayLayerCount=e,this}withDimension(t){return this._desc.dimension=t,this}build(){return new L(this._texture._inner.createView(this._desc))}}class D{static isBc(t){switch(t){case i.Bc1RgbaUnorm:case i.Bc1RgbaUnormSrgb:case i.Bc2RgbaUnorm:case i.Bc2RgbaUnormSrgb:case i.Bc3RgbaUnorm:case i.Bc3RgbaUnormSrgb:case i.Bc4RUnorm:case i.Bc4RSnorm:case i.Bc5RgUnorm:case i.Bc5RgSnorm:case i.Bc6hRgbUfloat:case i.Bc6hRgbFloat:case i.Bc7RgbaUnorm:case i.Bc7RgbaUnormSrgb:return!0;default:return!1}}static isEtc(t){switch(t){case i.Etc2Rgb8Unorm:case i.Etc2Rgb8UnormSrgb:case i.Etc2Rgb8A1Unorm:case i.Etc2Rgb8A1UnormSrgb:case i.Etc2Rgba8Unorm:case i.Etc2Rgba8UnormSrgb:case i.EacR11Unorm:case i.EacR11Snorm:case i.EacRg11Unorm:case i.EacRg11Snorm:return!0;default:return!1}}static getBlockWidth(t){if(D.isBc(t)||D.isEtc(t))return 4;switch(t){case i.Astc4x4Unorm:case i.Astc4x4UnormSrgb:return 4;case i.Astc5x4Unorm:case i.Astc5x4UnormSrgb:case i.Astc5x5Unorm:case i.Astc5x5UnormSrgb:return 5;case i.Astc6x5Unorm:case i.Astc6x5UnormSrgb:case i.Astc6x6Unorm:case i.Astc6x6UnormSrgb:return 6;case i.Astc8x5Unorm:case i.Astc8x5UnormSrgb:case i.Astc8x6Unorm:case i.Astc8x6UnormSrgb:case i.Astc8x8Unorm:case i.Astc8x8UnormSrgb:return 8;case i.Astc10x5Unorm:case i.Astc10x5UnormSrgb:case i.Astc10x6Unorm:case i.Astc10x6UnormSrgb:case i.Astc10x8Unorm:case i.Astc10x8UnormSrgb:case i.Astc10x10Unorm:case i.Astc10x10UnormSrgb:return 10;case i.Astc12x10Unorm:case i.Astc12x10UnormSrgb:case i.Astc12x12Unorm:case i.Astc12x12UnormSrgb:return 12;default:return 1}}static bytesPerBlock(t){switch(t){case i.R8Unorm:case i.R8Snorm:case i.R8Uint:case i.R8Sint:case i.Stencil8:return 1;case i.R16Uint:case i.R16Sint:case i.R16Unorm:case i.R16Snorm:case i.R16Float:case i.RG8Unorm:case i.RG8Snorm:case i.RG8Uint:case i.RG8Sint:case i.Depth16Unorm:return 2;case i.R32Uint:case i.R32Sint:case i.R32Float:case i.RG16Uint:case i.RG16Sint:case i.RG16Unorm:case i.RG16Snorm:case i.RG16Float:case i.Rgba8Unorm:case i.Rgba8UnormSrgb:case i.Rgba8Snorm:case i.Rgba8Uint:case i.Rgba8Sint:case i.Bgra8Unorm:case i.Bgra8UnormSrgb:case i.Rgb9e5Ufloat:case i.Rgb10a2Uint:case i.Rgb10a2Unorm:case i.Depth24Plus:case i.Depth24PlusStencil8:case i.Depth32Float:return 4;case i.Rg11b10Ufloat:case i.RG32Uint:case i.RG32Sint:case i.RG32Float:case i.Rgba16Uint:case i.Rgba16Sint:case i.Rgba16Unorm:case i.Rgba16Snorm:case i.Rgba16Float:case i.Depth32FloatStencil8:case i.Bc1RgbaUnorm:case i.Bc1RgbaUnormSrgb:case i.Bc4RUnorm:case i.Bc4RSnorm:case i.Etc2Rgb8Unorm:case i.Etc2Rgb8UnormSrgb:case i.Etc2Rgb8A1Unorm:case i.Etc2Rgb8A1UnormSrgb:case i.EacR11Unorm:case i.EacR11Snorm:return 8;case i.Rgba32Uint:case i.Rgba32Sint:case i.Rgba32Float:case i.Bc2RgbaUnorm:case i.Bc2RgbaUnormSrgb:case i.Bc3RgbaUnorm:case i.Bc3RgbaUnormSrgb:case i.Bc5RgUnorm:case i.Bc5RgSnorm:case i.Bc6hRgbUfloat:case i.Bc6hRgbFloat:case i.Bc7RgbaUnorm:case i.Bc7RgbaUnormSrgb:case i.Etc2Rgba8Unorm:case i.Etc2Rgba8UnormSrgb:case i.EacRg11Unorm:case i.EacRg11Snorm:case i.Astc4x4Unorm:case i.Astc4x4UnormSrgb:case i.Astc5x4Unorm:case i.Astc5x4UnormSrgb:case i.Astc5x5Unorm:case i.Astc5x5UnormSrgb:case i.Astc6x5Unorm:case i.Astc6x5UnormSrgb:case i.Astc6x6Unorm:case i.Astc6x6UnormSrgb:case i.Astc8x5Unorm:case i.Astc8x5UnormSrgb:case i.Astc8x6Unorm:case i.Astc8x6UnormSrgb:case i.Astc8x8Unorm:case i.Astc8x8UnormSrgb:case i.Astc10x5Unorm:case i.Astc10x5UnormSrgb:case i.Astc10x6Unorm:case i.Astc10x6UnormSrgb:case i.Astc10x8Unorm:case i.Astc10x8UnormSrgb:case i.Astc10x10Unorm:case i.Astc10x10UnormSrgb:case i.Astc12x10Unorm:case i.Astc12x10UnormSrgb:case i.Astc12x12Unorm:case i.Astc12x12UnormSrgb:case i.Bc2RgbaUnorm:return 16;default:throw new Error(`Unsupported texture format: ${t}`)}}}class P{constructor(t,e){this._inner=t,this._format=e}get format(){return this._format}}class O{constructor(t){this._baseMipLevel=0,this._baseArrayLayer=0,this._texture=t}withMipLevel(t){return this._baseMipLevel=t,this}withArrayLayer(t){return this._baseArrayLayer=t,this}build(){const t=this._texture._inner,e=this._texture._inner.createView({format:t.format,dimension:t.dimension,aspect:"all",baseMipLevel:this._baseMipLevel,mipLevelCount:1,baseArrayLayer:this._baseArrayLayer,arrayLayerCount:1,usage:GPUTextureUsage.RENDER_ATTACHMENT});return new P(e,this._texture.format)}}function V(t){const e=new Float32Array(1);e[0]=t;const r=new Uint32Array(e.buffer)[0],s=r>>16&32768,i=(r>>23&255)-127;return i<=-15?s:i>16?31744|s:s|i+15<<10|(8388607&r)>>13}function I(t){switch(t){case b.Float16:return 2;case b.Float32:case b.Uint:case b.Sint:return 4;case b.Boolean:return 1;default:throw new Error("Unknown BaseType.")}}!function(t){t[t.Float16=0]="Float16",t[t.Float32=1]="Float32",t[t.Uint=2]="Uint",t[t.Sint=3]="Sint",t[t.Boolean=4]="Boolean"}(b||(b={})),function(t){t[t.Scalar=0]="Scalar",t[t.Vec=1]="Vec",t[t.Matrix=2]="Matrix",t[t.Array=3]="Array"}(f||(f={}));class k{constructor(t,e,r,s){if(this.numRows=1,this.numCols=1,e===f.Scalar&&1!==r&&1!==s)throw new Error("Scalar member must have numRows = 1.");this.baseType=t,this.containerType=e,this.numRows=r,this.numCols=s}get size(){const t=this.numCols>1&&3===this.numRows?4:this.numRows;return I(this.baseType)*t*this.numCols}get alignment(){const t=3===this.numRows?4:this.numRows;return I(this.baseType)*t}}class z{constructor(){this._size=0,this._members=new Map}withSize(t){if(0!==this._size)throw new Error("Size already set.");return this._size=t,this}pushScalar(t,e){return this._pushField(t,e,f.Scalar)}pushVec2(t,e){return this._pushField(t,e,f.Vec,2)}pushVec3(t,e){return this._pushField(t,e,f.Vec,3)}pushVec4(t,e){return this._pushField(t,e,f.Vec,4)}pushMatrix(t,e,r,s){if(!Number.isInteger(e)||!Number.isInteger(r))throw new Error("Matrix dimensions must be integers");if(e<2||e>4||r<2||r>4)throw new Error("Matrix dimensions must be between 2 and 4 (inclusive)");return this._pushField(t,s,f.Matrix,e,r)}build(){return this._size=16*Math.ceil(this._size/16),new N(this._size,this._members)}_pushField(t,e,r,s=1,i=1){const n=new k(t,r,s,i),a=n.alignment,o=Math.ceil(this._size/a)*a;return this._members.set(e,{offset:o,type:n}),this._size=o+n.size,this}}class N{constructor(t,e){this.size=t,this._members=e}_createDataViews(t){const e=new Map;for(const[r,s]of this._members){let i;const n=s.type.size;let a=4;switch(s.type.baseType){case b.Float16:a=2,i=Uint16Array;break;case b.Float32:i=Float32Array;break;case b.Uint:case b.Boolean:i=Uint32Array;break;case b.Sint:i=Int32Array}e.set(r,[s,new i(t,s.offset,n/a)])}return e}_getMemberOrThrow(t){const e=this._members.get(t);if(!e)throw new Error(`Member ${t} not found in layout.`);return e}}class W{constructor(t,e){this._dataViews=new Map;const r=new ArrayBuffer(t.size);this._buffer=new F(e).withUsage(GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST).withData(r,!0).build(),this._data=this._buffer.data,this._dataViews=t._createDataViews(this._data),this._ctx=e}setScalar(t,e){const[r,s]=this._dataViews.get(t);return r.type.baseType===b.Float16?s[0]=V(e):s[0]=e,this}setVec(t,e){const[r,s]=this._dataViews.get(t);for(let t=0;t<s.length;++t)s[t]=0;if(r.type.baseType==b.Float16)for(let t=0;t<e.length;++t)s[t]=V(e[t]);else for(let t=0;t<e.length;++t)s[t]=e[t];return this}setMatrix(t,e){const[r,s]=this._dataViews.get(t),i=r.type.numCols,n=r.type.numRows,a=3===n;for(let t=0;t<s.length;++t)s[t]=0;let o=0;if(r.type.baseType===b.Float16)for(let t=0;t<i;++t){for(let t=0;t<n;++t)s[o]=V(e[o]),++o;a&&++o}else for(let t=0;t<i;++t){for(let t=0;t<n;++t)s[o]=e[o],++o;a&&++o}return this}upload(){return this._buffer._uploadData(this._ctx),this}_getBufferResource(){return{buffer:this._buffer._inner}}}class q{constructor(t){this._inner=t}}class H{constructor(t,e){this._entries=[],this._ctx=t,this._layout=e}withLabel(t){return this._label=t,this}withBuffer(t,e){const r=this._layout._getBindingIndex(t);return this._entries[r]={binding:r,resource:e._getBufferResource()},this}withTexture(t,e){const r=this._layout._getBindingIndex(t);return this._entries[r]={binding:r,resource:e._inner},this}withSampler(t,e){const r=this._layout._getBindingIndex(t);return this._entries[r]={binding:r,resource:e._inner},this}build(){const t=this._ctx.device.createBindGroup({label:this._label,entries:this._entries,layout:this._layout._inner});return new q(t)}}class Y{constructor(t,e,r,s){this._inner=t,this._indices=r,this._uboLayouts=s,this._ctx=e}getUniformBufferLayout(t){return this._uboLayouts.get(t)}createUniformBuffer(t){return w(this._uboLayouts.get(t),t=>new W(t,this._ctx))}_getBindingIndex(t){const e=this._indices.get(t);if(void 0===e)throw`No field name found for ${t} in bind group layout.`;return e}}const $=class{constructor(t){this._entries=[],this._indices=new Map,this._uboLayouts=new Map,this._ctx=t}withLabel(t){return this._label=t,this}withUniformBuffer(t,e,r,s){return this._entries[t]={binding:t,visibility:s??_.Vertex|_.Fragment|_.Compute,buffer:{type:"uniform"}},this._indices.set(e,t),this._uboLayouts.set(e,r),this}withStorageBuffer(t,e,r,s=4,i){let n="storage";return r===o.Read&&(n="read-only-storage"),this._entries[t]={binding:t,visibility:i??_.Fragment|_.Compute,buffer:{type:n,hasDynamicOffset:!1,minBindingSize:s}},this._indices.set(e,t),this}withStorageTexture(t,e,r,s,i,n){return this._entries[t]={binding:t,visibility:i??_.Fragment|_.Compute,storageTexture:{access:s,format:r,viewDimension:n??"2d"}},this._indices.set(e,t),this}withTexture(t,e,r,s,i=c.Float){return this._entries[t]={binding:t,visibility:r??_.Fragment|_.Compute,texture:{sampleType:i,viewDimension:s??"2d"}},this._indices.set(e,t),this}withSampler(t,e,r=h.Filtering,s){return this._entries[t]={binding:t,visibility:s??_.Fragment|_.Compute,sampler:{type:r}},this._indices.set(e,t),this}build(){const t=this._ctx.device.createBindGroupLayout({label:this._label,entries:this._entries});return new Y(t,this._ctx,this._indices,this._uboLayouts)}};class X{constructor(t,e,r,s){this._inner=t,this._ctx=e,this._vertexAttributes=r,this._bindGroupLayouts=s}getCompilationInfo(){return this._inner.getCompilationInfo()}getVertexAttributeLocation(t){return this._vertexAttributes.get(t)??void 0}hasVertexAttribute(t){return this._vertexAttributes.has(t)}createBindGroup(t){return new H(this._ctx,this._bindGroupLayouts[t])}}class j{constructor(t){this._vertexAttributes=new Map,this._includes=new Map,this._ctx=t}withLabel(t){return this._label=t,this}withCode(t){return this._code=t,this}withInclude(t,e){return this._includes.set(t,e),this}withVertexAttribute(t,e){return this._vertexAttributes.set(e,t),this}withBindGroup(t,e){if(this._bindGroupLayouts=this._bindGroupLayouts??[],e instanceof Y)this._bindGroupLayouts[t]=e;else{const r=new $(this._ctx);e(r),this._bindGroupLayouts[t]=r.build()}return this}build(){if(!this._code)throw new Error("Shader code not specified. Use withCode() to set the shader source.");let t=(this._ctx.shaderF16Supported?"enable f16;\n alias half = f16;\n alias vec2h = vec2<f16>;\n alias vec3h = vec3<f16>;\n alias vec4h = vec4<f16>;\n ":"alias half = f32;\n alias vec2h = vec2<f32>; \n alias vec3h = vec3<f32>;\n alias vec4h = vec4<f32>;\n ")+"\n\n"+this._code;for(const[e,r]of this._includes){const s=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),i=new RegExp(`#\\s*include\\s*<\\s*${s}\\s*>`,"g");t=t.replace(i,r)}const e=this._ctx.device.createShaderModule({label:this._label,code:t});return new X(e,this._ctx,this._vertexAttributes,this._bindGroupLayouts)}}class Q{constructor(t,e){this._inner=t,this._shader=e}getVertexAttributeLocation(t){return this._shader.getVertexAttributeLocation(t)}}class Z{constructor(t,e){this._colorTargets=[],this._vertexEntry=void 0,this._fragmentEntry=void 0,this._label=void 0,this._overrideConstants={},this._cullMode=s.Back,this._mesh=void 0,this._ctx=t,this._defaultColorState=[{format:t.format,blend:void 0,writeMask:GPUColorWrite.ALL}],this._defaultDepthState=w(e,t=>({format:t,depthWriteEnabled:!0,depthCompare:"less"}))}withLabel(t){return this._label=t,this}withCullMode(t){return this._cullMode=t,this}withMesh(t){return this._mesh=t,this}withShader(t){return this._shader=t,this}withVertexShader(t){return this._vertexEntry=t,this}withFragmentShader(t){return this._fragmentEntry=t,this}withColorTarget(t){return this._colorTargets.push({format:t,blend:void 0,writeMask:GPUColorWrite.ALL}),this}withDepthTarget(t){return this._depthState={format:t,...this._defaultDepthState},this}withDepthCompare(t){const e=this._depthState??this._defaultDepthState;return e?e.depthCompare=t:console.warn("No depth target set. Setting depth compare function has no effect."),this}withDepthBias(t,e,r){const s=this._depthState??this._defaultDepthState;return s?(s.depthBias=t,s.depthBiasSlopeScale=e,s.depthBiasClamp=r):console.warn("No depth target set. Setting depth compare function has no effect."),this}withDepthWrite(t){const e=this._depthState??this._defaultDepthState;return e?e.depthWriteEnabled=t:console.warn("No depth target set. Setting depth write enabled has no effect."),this}withOverrideConstant(t,e,r){return r&GPUShaderStage.VERTEX&&(this._overrideConstants[_.Vertex]=this._overrideConstants[_.Vertex]||{},this._overrideConstants[_.Vertex][t]=e),r&GPUShaderStage.FRAGMENT&&(this._overrideConstants[_.Fragment]=this._overrideConstants[_.Fragment]||{},this._overrideConstants[_.Fragment][t]=e),this}withBlendMode(t){return this.lastColorTarget.blend=t._inner,this}withColorWrite(t,e,r,s){return e??(e=t),r??(r=e),s??(s=r),this.lastColorTarget.writeMask=(t?GPUColorWrite.RED:0)|(e?GPUColorWrite.GREEN:0)|(r?GPUColorWrite.BLUE:0)|(s?GPUColorWrite.ALPHA:0),this}build(){if(!this._shader)throw new Error("Shader not specified. Use withShader() to set the shader to use.");const t=this._shader;if(void 0===this._vertexEntry)throw new Error("Shader does not contain a vertex entry point. Use ShaderBuilder.withVertexShader() to set one.");let e,r;this._colorTargets.length||this._depthState?(e=this._colorTargets,r=this._depthState):(e=this._defaultColorState,r=this._defaultDepthState);const s=w(this._mesh,t=>({topology:t.topology,frontFace:t.frontFace,cullMode:this._cullMode})),i=w(this._mesh,e=>{const r=[];for(let s=0;s<e.numStreams;++s){const i=e.getStreamAttributes(s).filter(e=>t.hasVertexAttribute(e.name)).map(e=>({shaderLocation:t.getVertexAttributeLocation(e.name),offset:e.offset,format:e.format}));r.push({arrayStride:e.getStreamStride(s),stepMode:"vertex",attributes:i})}return r}),n=w(t._bindGroupLayouts,t=>this._ctx.device.createPipelineLayout({bindGroupLayouts:t.map(t=>t._inner),label:this._label}))??"auto",a={label:this._label,layout:n,primitive:s,depthStencil:r,vertex:{buffers:i,module:t._inner,entryPoint:this._vertexEntry,constants:this._overrideConstants[_.Vertex]},fragment:w(this._fragmentEntry,r=>({module:t._inner,entryPoint:r,targets:e,constants:this._overrideConstants[_.Fragment]}))},o=this._ctx.device.createRenderPipeline(a);return new Q(o,t)}get lastColorTarget(){return this._colorTargets.length?this._colorTargets[this._colorTargets.length-1]:this._defaultColorState[0]}}var K,J,tt,et;!function(t){t.Uint16="uint16",t.Uint32="uint32"}(K||(K={}));class rt{constructor(t,e,r=!1){const s=t.BYTES_PER_ELEMENT;this.format=2===s?K.Uint16:K.Uint32,this.count=t.length,this.buffer=new F(e).withData(t.buffer,r,t.byteOffset,t.byteLength).withUsage(g.CopyDst|g.Index).build()}}!function(t){t.TriangleList="triangle-list",t.TriangleStrip="triangle-strip",t.LineList="line-list",t.LineStrip="line-strip",t.PointList="point-list"}(J||(J={})),function(t){t.Clockwise="cw",t.CounterClockwise="ccw"}(tt||(tt={})),function(t){t.Uint8="uint8",t.Uint8x2="uint8x2",t.Uint8x4="uint8x4",t.Sint8="sint8",t.Sint8x2="sint8x2",t.Sint8x4="sint8x4",t.Unorm8="unorm8",t.Unorm8x2="unorm8x2",t.Unorm8x4="unorm8x4",t.Snorm8="snorm8",t.Snorm8x2="snorm8x2",t.Snorm8x4="snorm8x4",t.Uint16="uint16",t.Uint16x2="uint16x2",t.Uint16x4="uint16x4",t.Sint16="sint16",t.Sint16x2="sint16x2",t.Sint16x4="sint16x4",t.Unorm16="unorm16",t.Unorm16x2="unorm16x2",t.Unorm16x4="unorm16x4",t.Snorm16="snorm16",t.Snorm16x2="snorm16x2",t.Snorm16x4="snorm16x4",t.Float16="float16",t.Float16x2="float16x2",t.Float16x4="float16x4",t.Float32="float32",t.Float32x2="float32x2",t.Float32x3="float32x3",t.Float32x4="float32x4",t.Uint32="uint32",t.Uint32x2="uint32x2",t.Uint32x3="uint32x3",t.Uint32x4="uint32x4",t.Sint32="sint32",t.Sint32x2="sint32x2",t.Sint32x3="sint32x3",t.Sint32x4="sint32x4",t.Unorm10_10_10_2="unorm10-10-10-2",t.Unorm8x4_bgra="unorm8x4-bgra"}(et||(et={}));class st{constructor(t,e,r,s){this._streams=[],this._topology=t,this._frontFace=e,this._streams=r,this._indexBuffer=s,this._numVertices=this._streams[0].numVertices,this._streams.forEach(t=>console.assert(t.numVertices===this._numVertices,"All vertex streams must have the same number of vertices."))}get topology(){return this._topology}get frontFace(){return this._frontFace}get numStreams(){return this._streams.length}get numVertices(){return this._numVertices}getVertexBuffer(t){return this._streams[t].buffer}getStreamStride(t){return this._streams[t].stride}getStreamAttributes(t){return this._streams[t].attributes}get indexBuffer(){return this._indexBuffer?.buffer}get indexFormat(){return this._indexBuffer?.format??K.Uint16}get numIndices(){return this._indexBuffer?.count??0}}class it{constructor(){this.stride=0,this.attributes=[]}pushAttribute(t,e){this.attributes.push({name:t,format:e,offset:this.stride}),this.stride+=function(t){switch(t){case et.Uint8:case et.Sint8:case et.Unorm8:case et.Snorm8:return 1;case et.Uint8x2:case et.Sint8x2:case et.Unorm8x2:case et.Snorm8x2:case et.Uint16:case et.Sint16:case et.Unorm16:case et.Snorm16:case et.Float16:return 2;case et.Uint8x4:case et.Sint8x4:case et.Unorm8x4:case et.Snorm8x4:case et.Uint16x2:case et.Sint16x2:case et.Unorm16x2:case et.Snorm16x2:case et.Float16x2:case et.Float32:case et.Uint32:case et.Sint32:case et.Unorm10_10_10_2:case et.Unorm8x4_bgra:return 4;case et.Uint16x4:case et.Sint16x4:case et.Unorm16x4:case et.Snorm16x4:case et.Float16x4:case et.Float32x2:case et.Uint32x2:case et.Sint32x2:return 8;case et.Float32x3:case et.Uint32x3:case et.Sint32x3:return 12;case et.Float32x4:case et.Uint32x4:case et.Sint32x4:return 16}}(e)}get numVertices(){return this.buffer.size/this.stride}}class nt{constructor(t,e){this._stream=t,this._ctx=e}pushAttribute(t,e){return this._stream.pushAttribute(t,e),this}withData(t,e=0,r,s=!1){r=r??t.byteLength-e,this._stream.buffer=new F(this._ctx).withData(t,s,e,r).withUsage(g.Vertex|g.CopyDst).build()}}class at{constructor(t){this._topology=J.TriangleList,this._frontFace=tt.CounterClockwise,this._streams=[],this._ctx=t}pushStream(t){const e=new it;return t(new nt(e,this._ctx)),console.assert(void 0!==e.buffer,"Vertex stream must have a buffer. Did you forget to call withData()?"),this._streams.push(e),this}withFrontFace(t){return this._frontFace=t,this}withTopology(t){return this._topology=t,this}withIndexData(t,e=!1){return this._indexBuffer=w(t,t=>new rt(t,this._ctx,e)),this}build(){return console.assert(this._streams.length>0,"Mesh must have at least one vertex stream."),new st(this._topology,this._frontFace,this._streams,this._indexBuffer)}}class ot{constructor(t){this._inner=t}}class ct{constructor(t){this._desc={},this._ctx=t}withLabel(t){return this._desc.label=t,this}withAddressMode(t,e,r){return this._desc.addressModeU=t,this._desc.addressModeV=e??t,this._desc.addressModeW=r??t,this}withFiltering(t,e,r){return this._desc.minFilter=t,this._desc.magFilter=e??t,this._desc.mipmapFilter=r??t,this}withTrilinearFiltering(){return this.withFiltering(e.Linear),this}withNearestFiltering(){return this.withFiltering(e.Nearest),this}withAnisotropicFiltering(t){return this.withFiltering(e.Linear),this._desc.maxAnisotropy=t,this}withMinMipLevel(t){return this._desc.lodMinClamp=t,this}withMaxMipLevel(t){return this._desc.lodMaxClamp=t,this}withCompareFunction(t){return this._desc.compare=t,this}build(){return new ot(this._ctx.device.createSampler(this._desc))}}class ht{constructor(t){this._inner=t}}class ut{constructor(t){this._overrideConstants={},this._ctx=t}withLabel(t){return this._label=t,this}withOverrideConstant(t,e){return this._overrideConstants[t]=e,this}withShader(t,e){return this._shader=t,this._entry=e,this}build(){const t=this._shader,e=w(t._bindGroupLayouts,t=>this._ctx.device.createPipelineLayout({bindGroupLayouts:t.map(t=>t._inner),label:this._label}))??"auto",r={label:this._label,compute:{module:t._inner,entryPoint:this._entry,constants:this._overrideConstants},layout:e};return new ht(this._ctx.device.createComputePipeline(r))}}class lt{constructor(t){this._parent=null,this._options={},this._shaderIncludes=new Map,this._globalBindGroupLayouts=[],this._globalBindGroups=[],t instanceof lt?(this._context=t._context,this._canvas=t._canvas,this._mipShader=t._mipShader,this._depthStencil=t._depthStencil,this._depthStencilTarget=t._depthStencilTarget):(this._context=new U,this._canvas=t)}get shaderF16Supported(){return this._context.shaderF16Supported}get floatFilteringSupported(){return this._context.floatFilteringSupported}get adapter(){return this._context.adapter}get device(){return this._context.device}get context(){return this._context.context}copyIncludesFrom(t){return t._shaderIncludes.forEach((t,e)=>this._shaderIncludes.set(e,t)),this}copyGlobalBindGroupsFrom(t){if(this._context!=t._context)throw new Error("Cannot copy global bind groups from another TinyHelix instance with a different WebGPU context.");if(this._globalBindGroups.length>0||this._globalBindGroupLayouts.length>0)throw new Error("Cannot copy global bind groups from another TinyHelix instance if this instance already has global bind groups set.");return this._globalBindGroupLayouts=[...t._globalBindGroupLayouts],this._globalBindGroups=[...t._globalBindGroups],this}async initialize(t={}){t.canvas=this._canvas,this._options=t,await this._context.initialize(t),this._createDepthStencil(),this._mipShader=this._context.device.createShaderModule({code:"@group(0) @binding(0) var source_tex: texture_2d<f32>;\n@group(0) @binding(1) var bilinear_sampler: sampler;\n\nstruct VertexOutput {\n @builtin(position) position: vec4f,\n @location(0) uv: vec2f,\n}\n\n@vertex\nfn vs_main(@builtin(vertex_index) i: u32) -> VertexOutput {\n var output: VertexOutput;\n\n // Full-screen triangle\n let x = f32((i << 1u) & 2u);\n let y = f32(i & 2u);\n\n output.position = vec4f(x * 2.0 - 1.0, 1.0 - y * 2.0, 0.0, 1.0);\n output.uv = vec2f(x, y);\n\n return output;\n}\n\n@fragment\nfn fs_main(input: VertexOutput) -> @location(0) vec4f {\n return textureSample(source_tex, bilinear_sampler, input.uv);\n}\n\n",label:"MipRenderer Shader Module"})}resize(t,e){this._canvas.width=t,this._canvas.height=e,this._createDepthStencil()}addShaderInclude(t,e){return this._shaderIncludes.set(t,e),this}get depthStencilFormat(){return this._options.depthStencilFormat}get backbuffer(){if(!this._backbuffer)throw new Error("Backbuffer not initialized. Did you forget to call startFrame()?");return this._backbuffer}get backbufferTarget(){if(!this._backbufferTarget)throw new Error("Backbuffer not initialized. Did you forget to call startFrame()?");return this._backbufferTarget}get colorSpace(){return this._context.colorSpace}get backbufferFormat(){return this._context.format}get backbufferWidth(){return this._canvas.width}get backbufferHeight(){return this._canvas.height}startFrame(){if(this._parent)return this._backbuffer=this._parent.backbuffer,void(this._backbufferTarget=this._parent.backbufferTarget);this._backbuffer=T.from_webgpu(this._context.getCurrentTexture(),this._context.format,this._context),this._backbufferTarget=this.createRenderTarget(this._backbuffer).withMipLevel(0).build()}createRenderTarget(t){return new O(t)}createShader(){let t=new j(this._context);return this._shaderIncludes.forEach((e,r)=>t=t.withInclude(r,e)),this._globalBindGroupLayouts.forEach((e,r)=>t.withBindGroup(r,e)),t}createBindGroupLayout(){return new $(this._context)}createBindGroup(t){return new H(this._context,t)}createMesh(){return new at(this._context)}createRenderPipeline(){return new Z(this._context,this._options.depthStencilFormat)}createComputePipeline(){return new ut(this._context)}createSampler(){return new ct(this._context)}createTexture(){return new E(this._context,this._mipShader)}createCommandEncoder(t){return new B(this.backbufferTarget,this._globalBindGroups,this._context,this._depthStencilTarget,t)}createUniformBufferLayout(){return new z}createUniformBuffer(t){return new W(t,this._context)}createBuffer(){return new F(this._context)}setGlobalBindGroup(t,e,r){return this._globalBindGroupLayouts[t]=e,this._globalBindGroups[t]=r,this}destroy(){this._context.destroy()}depthStencilTexture(){return this._depthStencil}depthStencilTarget(){return this._depthStencilTarget}_createDepthStencil(){this._depthStencil=w(this._options.depthStencilFormat,t=>this.createTexture().withFormat(t).withSize(this._canvas.width,this._canvas.height).withUsage(GPUTextureUsage.RENDER_ATTACHMENT).build()),this._depthStencilTarget=w(this._depthStencil,t=>this.createRenderTarget(t).build())}}class dt{get srcFactor(){return this._inner.color.srcFactor}set srcFactor(t){this._inner.color.srcFactor=t}get dstFactor(){return this._inner.color.dstFactor}set dstFactor(t){this._inner.color.dstFactor=t}get alphaSrcFactor(){return this._inner.alpha.srcFactor}set alphaSrcFactor(t){this._inner.alpha.srcFactor=t}get alphaDstFactor(){return this._inner.alpha.dstFactor}set alphaDstFactor(t){this._inner.alpha.dstFactor=t}constructor(t,e,r,s){this._inner={color:{srcFactor:n.SrcAlpha,dstFactor:n.OneMinusSrcAlpha},alpha:{srcFactor:n.One,dstFactor:n.OneMinusSrcAlpha}},this.srcFactor=t,this.dstFactor=e,this.alphaSrcFactor=r,this.alphaDstFactor=s}}dt.ALPHA=new dt(n.SrcAlpha,n.OneMinusSrcAlpha,n.One,n.OneMinusSrcAlpha),dt.ADDITIVE=new dt(n.SrcAlpha,n.One,n.One,n.One),dt.MULTIPLY=new dt(n.DstColor,n.Zero,n.Zero,n.One),dt.SCREEN=new dt(n.One,n.OneMinusSrcColor,n.One,n.OneMinusSrcAlpha),dt.OVERLAY=new dt(n.SrcAlpha,n.OneMinusSrcAlpha,n.One,n.OneMinusSrcAlpha),dt.DARKEN=new dt(n.One,n.OneMinusSrcColor,n.One,n.OneMinusSrcAlpha),dt.LIGHTEN=new dt(n.OneMinusSrcColor,n.One,n.One,n.OneMinusSrcAlpha);const _t=lt;return S.default})());
2
2
  //# sourceMappingURL=tiny-helix.js.map