typegpu
Version:
A thin layer between JS and WebGPU/WGSL that improves development experience and allows for faster iteration.
2 lines • 9.43 kB
JavaScript
import{A as fe,B as ge,C as Se,D as be,E as we,F as $e,G as Ae,H as Ie,I as De,J as Be,K as ke,a as c,b as S,d as H,e as D,f as v,g as K,h as Q,i as ee,j as te,k as re,l as ae,m as oe,n as ne,o as ue,p as pe,q as ie,r as Te,s as de,t as se,u as me,v as le,w as ce,x as xe,y as ye,z as ve}from"../chunk-CGVYLGBG.js";import{A as s,Aa as N,B as A,Ba as F,Ca as W,Ea as M,Fa as q,Ga as C,Ha as Z,Ia as Y,Ja as j,K as T,Ka as R,L as V,La as z,N as U,Oa as i,Qa as X,da as a,ga as r,ha as E,ja as x,ka as p,la as O,ma as L,oa as I,ra as _,sa as P,wa as h,xa as G,ya as y}from"../chunk-SWJVYRFM.js";var Ve=r(()=>{throw new Error("discard() can only be used on the GPU.")},()=>a("discard;",s),"discard");var Ue=r((e,t)=>v(i.translation(t),e),(e,t)=>({value:`(${i.translation(t).value} * ${e.value})`,dataType:e.dataType}),"translate4"),Ee=r((e,t)=>v(i.scaling(t),e),(e,t)=>({value:`(${i.scaling(t).value} * ${e.value})`,dataType:e.dataType}),"scale4"),Oe=r((e,t)=>v(i.rotationX(t),e),(e,t)=>({value:`(${i.rotationX(t).value} * ${e.value})`,dataType:e.dataType}),"rotateX4"),Le=r((e,t)=>v(i.rotationY(t),e),(e,t)=>({value:`(${i.rotationY(t).value} * ${e.value})`,dataType:e.dataType}),"rotateY4"),_e=r((e,t)=>v(i.rotationZ(t),e),(e,t)=>({value:`(${i.rotationZ(t).value} * ${e.value})`,dataType:e.dataType}),"rotateZ4");function g(e){return e.dataType.type.includes("2")?P:e.dataType.type.includes("3")?G:W}var Pe=r((e,t)=>k(b(e,t)),(e,t)=>a(`all(${e.value} == ${t.value})`,x),"allEq"),b=r((e,t)=>c.eq[e.kind](e,t),(e,t)=>a(`(${e.value} == ${t.value})`,g(e)),"eq"),he=r((e,t)=>m(b(e,t)),(e,t)=>a(`(${e.value} != ${t.value})`,g(e)),"ne"),w=r((e,t)=>c.lt[e.kind](e,t),(e,t)=>a(`(${e.value} < ${t.value})`,g(e)),"lt"),Ge=r((e,t)=>B(w(e,t),b(e,t)),(e,t)=>a(`(${e.value} <= ${t.value})`,g(e)),"le"),Ne=r((e,t)=>J(m(w(e,t)),m(b(e,t))),(e,t)=>a(`(${e.value} > ${t.value})`,g(e)),"gt"),Fe=r((e,t)=>m(w(e,t)),(e,t)=>a(`(${e.value} >= ${t.value})`,g(e)),"ge"),m=r(e=>c.neg[e.kind](e),e=>a(`!(${e.value})`,e.dataType),"not"),B=r((e,t)=>c.or[e.kind](e,t),(e,t)=>a(`(${e.value} | ${t.value})`,e.dataType),"or"),J=r((e,t)=>m(B(m(e),m(t))),(e,t)=>a(`(${e.value} & ${t.value})`,e.dataType),"and"),k=r(e=>c.all[e.kind](e),e=>a(`all(${e.value})`,x),"all"),We=r(e=>!k(m(e)),e=>a(`any(${e.value})`,x),"any"),Xe=r((e,t,o=.01)=>typeof e=="number"&&typeof t=="number"?Math.abs(e-t)<o:A(e)&&A(t)?c.isCloseToZero[e.kind](D(e,t),o):!1,(e,t,o=a(.01,L))=>S(e)&&S(t)?a(`(abs(f32(${e.value}) - f32(${t.value})) <= ${o.value})`,x):!S(e)&&!S(t)?a(`all(abs(${e.value} - ${t.value}) <= (${e.value} - ${e.value}) + ${o.value})`,x):a("false",x),"isCloseTo"),Je=r((e,t,o)=>typeof o=="boolean"?o?t:e:c.select[e.kind](e,t,o),(e,t,o)=>a(`select(${e.value}, ${t.value}, ${o.value})`,e.dataType),"select");var Me=r(()=>console.warn("workgroupBarrier is a no-op outside of GPU mode."),()=>a("workgroupBarrier()",s),"workgroupBarrier"),qe=r(()=>console.warn("storageBarrier is a no-op outside of GPU mode."),()=>a("storageBarrier()",s),"storageBarrier"),Ce=r(()=>console.warn("textureBarrier is a no-op outside of GPU mode."),()=>a("textureBarrier()",s),"textureBarrier"),Ze=r(e=>{throw new Error("Atomic operations are not supported outside of GPU mode.")},e=>{if(T(e.dataType)&&e.dataType.type==="atomic")return a(`atomicLoad(&${e.value})`,e.dataType.inner);throw new Error(`Invalid atomic type: ${JSON.stringify(e.dataType,null,2)}`)},"atomicLoad"),Ye=r((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 a(`atomicStore(&${e.value}, ${t.value})`,s)},"atomicStore"),f=(e,t)=>e.dataType.type==="atomic"&&e.dataType.inner.type==="i32"?[e.dataType,O]:[e.dataType,p],je=r((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 a(`atomicAdd(&${e.value}, ${t.value})`,e.dataType.inner);throw new Error(`Invalid atomic type: ${JSON.stringify(e.dataType,null,2)}`)},"atomicAdd",f),Re=r((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 a(`atomicSub(&${e.value}, ${t.value})`,e.dataType.inner);throw new Error(`Invalid atomic type: ${JSON.stringify(e.dataType,null,2)}`)},"atomicSub",f),ze=r((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 a(`atomicMax(&${e.value}, ${t.value})`,e.dataType.inner);throw new Error(`Invalid atomic type: ${JSON.stringify(e.dataType,null,2)}`)},"atomicMax",f),He=r((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 a(`atomicMin(&${e.value}, ${t.value})`,e.dataType.inner);throw new Error(`Invalid atomic type: ${JSON.stringify(e.dataType,null,2)}`)},"atomicMin",f),Ke=r((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 a(`atomicAnd(&${e.value}, ${t.value})`,e.dataType.inner);throw new Error(`Invalid atomic type: ${JSON.stringify(e.dataType,null,2)}`)},"atomicAnd",f),Qe=r((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 a(`atomicOr(&${e.value}, ${t.value})`,e.dataType.inner);throw new Error(`Invalid atomic type: ${JSON.stringify(e.dataType,null,2)}`)},"atomicOr",f),et=r((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 a(`atomicXor(&${e.value}, ${t.value})`,e.dataType.inner);throw new Error(`Invalid atomic type: ${JSON.stringify(e.dataType,null,2)}`)},"atomicXor",f);var tt=r(e=>e.length,e=>U(e.dataType)&&V(e.dataType.inner)&&e.dataType.inner.elementCount>0?a(String(e.dataType.inner.elementCount),E):a(`arrayLength(${e.value})`,p),"arrayLength",e=>[X(e.dataType)]);import*as d from"typed-binary";var rt=r(e=>{let t=new ArrayBuffer(4);new d.BufferWriter(t).writeUint32(e);let n=new d.BufferReader(t);return I(n.readFloat16(),n.readFloat16())},e=>a(`unpack2x16float(${e.value})`,I),"unpack2x16float"),at=r(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=>a(`pack2x16float(${e.value})`,p),"pack2x16float"),ot=r(e=>{let t=new ArrayBuffer(4);new d.BufferWriter(t).writeUint32(e);let n=new d.BufferReader(t);return y(n.readUint8()/255,n.readUint8()/255,n.readUint8()/255,n.readUint8()/255)},e=>a(`unpack4x8unorm(${e.value})`,y),"unpack4x8unorm"),nt=r(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=>a(`pack4x8unorm(${e.value})`,p),"pack4x8unorm");var ut=r((e,t,o,n,u)=>{throw new Error("Texture sampling is not supported outside of GPU mode.")},(e,t,o,n,u)=>{let l=[e,t,o];return n!==void 0&&l.push(n),u!==void 0&&l.push(u),a(`textureSample(${l.map($=>$.value).join(", ")})`,y)},"textureSample"),pt=r((e,t,o,n,u)=>{throw new Error("Texture sampling is not supported outside of GPU mode.")},(e,t,o,n,u)=>{let l=[e,t,o,n];return u!==void 0&&l.push(u),a(`textureSampleLevel(${l.map($=>$.value).join(", ")})`,y)},"textureSampleLevel"),it={u32:F,i32:N,f32:y},Tt=r((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 a(`textureLoad(${n.map(l=>l.value).join(", ")})`,"texelDataType"in u?u.texelDataType:it[u.channelDataType.type])},"textureLoad"),dt=r((e,t,o,n)=>{throw new Error("Texture storing is not supported outside of GPU mode.")},(e,t,o,n)=>a(`textureStore(${[e,t,o,n].filter(u=>u!==void 0).map(u=>u.value).join(", ")})`,s),"textureStore"),st=r((e,t)=>{throw new Error("Texture dimensions are not supported outside of GPU mode.")},(e,t)=>{let o=e.dataType.dimension;return a(`textureDimensions(${e.value}${t!==void 0?`, ${t.value}`:""})`,o==="1d"?p:o==="3d"?h:_)},"textureDimensions");export{Q as abs,te as acos,re as acosh,H as add,k as all,Pe as allEq,J as and,We as any,tt as arrayLength,ae as asin,ee as atan2,je as atomicAdd,Ke as atomicAnd,Ze as atomicLoad,ze as atomicMax,He as atomicMin,Qe as atomicOr,Ye as atomicStore,Re as atomicSub,et as atomicXor,oe as ceil,ne as clamp,ue as cos,pe as cosh,ie as cross,Ve as discard,Ie as distance,K as div,Te as dot,b as eq,Se as exp,be as exp2,se as floor,me as fract,Fe as ge,Ne as gt,M as identity2,q as identity3,C as identity4,Xe as isCloseTo,Ge as le,le as length,ce as log,xe as log2,w as lt,ye as max,ve as min,$e as mix,v as mul,he as ne,De as neg,de as normalize,m as not,B as or,at as pack2x16float,nt as pack4x8unorm,we as pow,Ae as reflect,Oe as rotateX4,Le as rotateY4,_e as rotateZ4,j as rotationX4,R as rotationY4,z as rotationZ4,Ee as scale4,Y as scaling4,Je as select,fe as sign,ge as sin,Be as sqrt,qe as storageBarrier,D as sub,ke as tanh,Ce as textureBarrier,st as textureDimensions,Tt as textureLoad,ut as textureSample,pt as textureSampleLevel,dt as textureStore,Ue as translate4,Z as translation4,rt as unpack2x16float,ot as unpack4x8unorm,Me as workgroupBarrier};
//# sourceMappingURL=index.js.map