UNPKG

typegpu

Version:

A thin layer between JS and WebGPU/WGSL that improves development experience and allows for faster iteration.

2 lines 7.98 kB
import{A as de,B as ie,C as me,D as se,E as le,a as l,b as f,d as J,e as I,f as C,g as M,h as q,i as j,j as R,k as X,l as z,m as Z,n as H,o as K,p as Q,q as Y,r as ee,s as te,t as re,u as ae,v as oe,w as ne,x as ue,y as pe,z as Te}from"../chunk-SLWTVY6K.js";import{Aa as h,Ga as F,I as T,J as B,L as V,ba as r,ea as a,fa as U,ha as c,ia as p,ja as k,ka as E,ma as A,pa as O,qa as _,ua as P,va as G,wa as x,y as i,ya as L,z as w,za as N}from"../chunk-L7HIBZAX.js";var ce=a(()=>{throw new Error("discard() can only be used on the GPU.")},()=>r("discard;",i));function v(e){return e.dataType.type.includes("2")?_:e.dataType.type.includes("3")?G:h}var xe=a((e,t)=>D(g(e,t)),(e,t)=>r(`all(${e.value} == ${t.value})`,c)),g=a((e,t)=>l.eq[e.kind](e,t),(e,t)=>r(`(${e.value} == ${t.value})`,v(e))),ye=a((e,t)=>m(g(e,t)),(e,t)=>r(`(${e.value} != ${t.value})`,v(e))),S=a((e,t)=>l.lt[e.kind](e,t),(e,t)=>r(`(${e.value} < ${t.value})`,v(e))),ve=a((e,t)=>$(S(e,t),g(e,t)),(e,t)=>r(`(${e.value} <= ${t.value})`,v(e))),fe=a((e,t)=>W(m(S(e,t)),m(g(e,t))),(e,t)=>r(`(${e.value} > ${t.value})`,v(e))),ge=a((e,t)=>m(S(e,t)),(e,t)=>r(`(${e.value} >= ${t.value})`,v(e))),m=a(e=>l.neg[e.kind](e),e=>r(`!(${e.value})`,e.dataType)),$=a((e,t)=>l.or[e.kind](e,t),(e,t)=>r(`(${e.value} | ${t.value})`,e.dataType)),W=a((e,t)=>m($(m(e),m(t))),(e,t)=>r(`(${e.value} & ${t.value})`,e.dataType)),D=a(e=>l.all[e.kind](e),e=>r(`all(${e.value})`,c)),Se=a(e=>!D(m(e)),e=>r(`any(${e.value})`,c)),be=a((e,t,o=.01)=>typeof e=="number"&&typeof t=="number"?Math.abs(e-t)<o:w(e)&&w(t)?l.isCloseToZero[e.kind](I(e,t),o):!1,(e,t,o=r(.01,E))=>f(e)&&f(t)?r(`(abs(f32(${e.value}) - f32(${t.value})) <= ${o.value})`,c):!f(e)&&!f(t)?r(`all(abs(${e.value} - ${t.value}) <= (${e.value} - ${e.value}) + ${o.value})`,c):r("false",c)),we=a((e,t,o)=>typeof o=="boolean"?o?t:e:l.select[e.kind](e,t,o),(e,t,o)=>r(`select(${e.value}, ${t.value}, ${o.value})`,e.dataType));var Ae=a(()=>console.warn("workgroupBarrier is a no-op outside of GPU mode."),()=>r("workgroupBarrier()",i)),Ie=a(()=>console.warn("storageBarrier is a no-op outside of GPU mode."),()=>r("storageBarrier()",i)),$e=a(()=>console.warn("textureBarrier is a no-op outside of GPU mode."),()=>r("textureBarrier()",i)),De=a(e=>{throw new Error("Atomic operations are not supported outside of GPU mode.")},e=>{if(T(e.dataType)&&e.dataType.type==="atomic")return r(`atomicLoad(&${e.value})`,e.dataType.inner);throw new Error(`Invalid atomic type: ${JSON.stringify(e.dataType,null,2)}`)}),Be=a((e,t)=>{throw new Error("Atomic operations are not supported outside of GPU mode.")},(e,t)=>{if(!T(e.dataType)||e.dataType.type!=="atomic")throw new Error(`Invalid atomic type: ${JSON.stringify(e.dataType,null,2)}`);return r(`atomicStore(&${e.value}, ${t.value})`,i)}),y=(e,t)=>e.dataType.type==="atomic"&&e.dataType.inner.type==="i32"?[e.dataType,k]:[e.dataType,p],Ve=a((e,t)=>{throw new Error("Atomic operations are not supported outside of GPU mode.")},(e,t)=>{if(T(e.dataType)&&e.dataType.type==="atomic")return r(`atomicAdd(&${e.value}, ${t.value})`,e.dataType.inner);throw new Error(`Invalid atomic type: ${JSON.stringify(e.dataType,null,2)}`)},y),Ue=a((e,t)=>{throw new Error("Atomic operations are not supported outside of GPU mode.")},(e,t)=>{if(T(e.dataType)&&e.dataType.type==="atomic")return r(`atomicSub(&${e.value}, ${t.value})`,e.dataType.inner);throw new Error(`Invalid atomic type: ${JSON.stringify(e.dataType,null,2)}`)},y),ke=a((e,t)=>{throw new Error("Atomic operations are not supported outside of GPU mode.")},(e,t)=>{if(T(e.dataType)&&e.dataType.type==="atomic")return r(`atomicMax(&${e.value}, ${t.value})`,e.dataType.inner);throw new Error(`Invalid atomic type: ${JSON.stringify(e.dataType,null,2)}`)},y),Ee=a((e,t)=>{throw new Error("Atomic operations are not supported outside of GPU mode.")},(e,t)=>{if(T(e.dataType)&&e.dataType.type==="atomic")return r(`atomicMin(&${e.value}, ${t.value})`,e.dataType.inner);throw new Error(`Invalid atomic type: ${JSON.stringify(e.dataType,null,2)}`)},y),Oe=a((e,t)=>{throw new Error("Atomic operations are not supported outside of GPU mode.")},(e,t)=>{if(T(e.dataType)&&e.dataType.type==="atomic")return r(`atomicAnd(&${e.value}, ${t.value})`,e.dataType.inner);throw new Error(`Invalid atomic type: ${JSON.stringify(e.dataType,null,2)}`)},y),_e=a((e,t)=>{throw new Error("Atomic operations are not supported outside of GPU mode.")},(e,t)=>{if(T(e.dataType)&&e.dataType.type==="atomic")return r(`atomicOr(&${e.value}, ${t.value})`,e.dataType.inner);throw new Error(`Invalid atomic type: ${JSON.stringify(e.dataType,null,2)}`)},y),Pe=a((e,t)=>{throw new Error("Atomic operations are not supported outside of GPU mode.")},(e,t)=>{if(T(e.dataType)&&e.dataType.type==="atomic")return r(`atomicXor(&${e.value}, ${t.value})`,e.dataType.inner);throw new Error(`Invalid atomic type: ${JSON.stringify(e.dataType,null,2)}`)},y);var Ge=a(e=>e.length,e=>V(e.dataType)&&B(e.dataType.inner)&&e.dataType.inner.elementCount>0?r(String(e.dataType.inner.elementCount),U):r(`arrayLength(${e.value})`,p),e=>[F(e.dataType)]);import*as d from"typed-binary";var Le=a(e=>{let t=new ArrayBuffer(4);new d.BufferWriter(t).writeUint32(e);let n=new d.BufferReader(t);return A(n.readFloat16(),n.readFloat16())},e=>r(`unpack2x16float(${e.value})`,A)),Ne=a(e=>{let t=new ArrayBuffer(4),o=new d.BufferWriter(t);o.writeFloat16(e.x),o.writeFloat16(e.y);let n=new d.BufferReader(t);return p(n.readUint32())},e=>r(`pack2x16float(${e.value})`,p)),he=a(e=>{let t=new ArrayBuffer(4);new d.BufferWriter(t).writeUint32(e);let n=new d.BufferReader(t);return x(n.readUint8()/255,n.readUint8()/255,n.readUint8()/255,n.readUint8()/255)},e=>r(`unpack4x8unorm(${e.value})`,x)),Fe=a(e=>{let t=new ArrayBuffer(4),o=new d.BufferWriter(t);o.writeUint8(e.x*255),o.writeUint8(e.y*255),o.writeUint8(e.z*255),o.writeUint8(e.w*255);let n=new d.BufferReader(t);return p(n.readUint32())},e=>r(`pack4x8unorm(${e.value})`,p));var We=a((e,t,o,n,u)=>{throw new Error("Texture sampling is not supported outside of GPU mode.")},(e,t,o,n,u)=>{let s=[e,t,o];return n!==void 0&&s.push(n),u!==void 0&&s.push(u),r(`textureSample(${s.map(b=>b.value).join(", ")})`,x)}),Je=a((e,t,o,n,u)=>{throw new Error("Texture sampling is not supported outside of GPU mode.")},(e,t,o,n,u)=>{let s=[e,t,o,n];return u!==void 0&&s.push(u),r(`textureSampleLevel(${s.map(b=>b.value).join(", ")})`,x)}),Ce={u32:N,i32:L,f32:x},Me=a((e,t,o)=>{throw new Error("Texture loading is not supported outside of GPU mode.")},(e,t,o)=>{let n=[e,t];o!==void 0&&n.push(o);let u=e.dataType;return r(`textureLoad(${n.map(s=>s.value).join(", ")})`,"texelDataType"in u?u.texelDataType:Ce[u.channelDataType.type])}),qe=a((e,t,o,n)=>{throw new Error("Texture storing is not supported outside of GPU mode.")},(e,t,o,n)=>r(`textureStore(${[e,t,o,n].filter(u=>u!==void 0).map(u=>u.value).join(", ")})`,i)),je=a((e,t)=>{throw new Error("Texture dimensions are not supported outside of GPU mode.")},(e,t)=>{let o=e.dataType.dimension;return r(`textureDimensions(${e.value}${t!==void 0?`, ${t.value}`:""})`,o==="1d"?p:o==="3d"?P:O)});export{q as abs,R as acos,J as add,D as all,xe as allEq,W as and,Se as any,Ge as arrayLength,X as asin,j as atan2,Ve as atomicAdd,Oe as atomicAnd,De as atomicLoad,ke as atomicMax,Ee as atomicMin,_e as atomicOr,Be as atomicStore,Ue as atomicSub,Pe as atomicXor,z as ceil,Z as clamp,H as cos,K as cross,ce as discard,me as distance,M as div,Q as dot,g as eq,pe as exp,ee as floor,te as fract,ge,fe as gt,be as isCloseTo,ve as le,re as length,S as lt,ae as max,oe as min,de as mix,C as mul,ye as ne,se as neg,Y as normalize,m as not,$ as or,Ne as pack2x16float,Fe as pack4x8unorm,Te as pow,ie as reflect,we as select,ne as sign,ue as sin,le as sqrt,Ie as storageBarrier,I as sub,$e as textureBarrier,je as textureDimensions,Me as textureLoad,We as textureSample,Je as textureSampleLevel,qe as textureStore,Le as unpack2x16float,he as unpack4x8unorm,Ae as workgroupBarrier}; //# sourceMappingURL=index.js.map