UNPKG

typegpu

Version:

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

2 lines 7.92 kB
import{$ as m,Ba as p,Da as S,Ea as F,M as P,N as v,O as A,R as U,S as O,V as z,W as y,Y as E,Z as T,_ as g,a as i,aa as D,ba as H,i as _,j as L,la as N,ma as s,oa as w,pa as c,ra as f,ta as h,ua as V,wa as C,ya as M,za as d}from"./chunk-APTRHY5Y.js";function J(t,e){let r=e;try{r=t(e)}catch{let o=t?.type;console.warn(`Schema of type ${o??"<unknown>"} is not callable.`)}return r}function Z(t){let e=r=>Object.fromEntries(Object.entries(t).map(([o,x])=>[o,J(x,r[o])]));return Object.setPrototypeOf(e,tt),e.propTypes=t,e}var tt={[i]:!0,type:"struct",$name(t){return L(this,t),this},toString(){return`struct:${_(this)??"<unnamed>"}`}};var b=(t,e)=>{let r=e-1,o=~r;return(t&r)===0?t:(t&o)+e};var n=class{constructor(e){this.type=e}[i]=!0},et={uint8:s,uint8x2:V,uint8x4:F,sint8:w,sint8x2:h,sint8x4:S,unorm8:c,unorm8x2:f,unorm8x4:p,snorm8:c,snorm8x2:f,snorm8x4:p,uint16:s,uint16x2:V,uint16x4:F,sint16:w,sint16x2:h,sint16x4:S,unorm16:c,unorm16x2:f,unorm16x4:p,snorm16:c,snorm16x2:f,snorm16x4:p,float16:c,float16x2:f,float16x4:p,float32:c,float32x2:f,float32x3:C,float32x4:p,uint32:s,uint32x2:V,uint32x3:d,uint32x4:F,sint32:w,sint32x2:h,sint32x3:M,sint32x4:S,"unorm10-10-10-2":p,"unorm8x4-bgra":p},q=Object.keys(et),_t=new n("uint8"),Lt=new n("uint8x2"),$t=new n("uint8x4"),Wt=new n("sint8"),kt=new n("sint8x2"),Pt=new n("sint8x4"),Ut=new n("unorm8"),Ot=new n("unorm8x2"),zt=new n("unorm8x4"),Et=new n("snorm8"),Nt=new n("snorm8x2"),Ct=new n("snorm8x4"),Mt=new n("uint16"),Gt=new n("uint16x2"),jt=new n("uint16x4"),Rt=new n("sint16"),Kt=new n("sint16x2"),Ht=new n("sint16x4"),Jt=new n("unorm16"),qt=new n("unorm16x2"),Qt=new n("unorm16x4"),Xt=new n("snorm16"),Yt=new n("snorm16x2"),Zt=new n("snorm16x4"),te=new n("float16"),ee=new n("float16x2"),ne=new n("float16x4"),re=new n("float32"),oe=new n("float32x2"),ie=new n("float32x3"),ae=new n("float32x4"),se=new n("uint32"),pe=new n("uint32x2"),ue=new n("uint32x3"),le=new n("uint32x4"),xe=new n("sint32"),me=new n("sint32x2"),ce=new n("sint32x3"),ye=new n("sint32x4"),fe=new n("unorm10-10-10-2"),de=new n("unorm8x4-bgra");var nt={f32:4,f16:2,i32:4,u32:4,u16:2,vec2f:8,vec2h:4,vec2i:8,vec2u:8,vec3f:16,vec3h:8,vec3i:16,vec3u:16,vec4f:16,vec4h:8,vec4i:16,vec4u:16,mat2x2f:8,mat3x3f:16,mat4x4f:16,atomic:4};function rt(t){let e=t?.type,r=nt[e];if(r!==void 0)return r;if(A(t))return Object.values(t.propTypes).map(u).reduce((o,x)=>o>x?o:x);if(v(t))return u(t.elementType);if(g(t)){let o=Object.values(t.propTypes)[0];return o?D(o)??1:1}if(T(t))return D(t.elementType)??1;if(y(t)||m(t))return D(t)??u(t.inner);if(q.includes(e))return 1;throw new Error(`Cannot determine alignment of data: ${JSON.stringify(t)}`)}function ot(t){if(g(t)){let e=Object.values(t.propTypes)[0];return e?I(e):1}return T(t)?I(t.elementType):m(t)?D(t)??I(t.inner):D(t)??1}var Q=new WeakMap,X=new WeakMap;function u(t){let e=Q.get(t);return e===void 0&&(e=rt(t),Q.set(t,e)),e}function I(t){let e=X.get(t);return e===void 0&&(e=ot(t),X.set(t,e)),e}function it(t){return u(t)}var at={f32:4,f16:2,i32:4,u32:4,u16:2,vec2f:8,vec2h:4,vec2i:8,vec2u:8,vec3f:12,vec3h:6,vec3i:12,vec3u:12,vec4f:16,vec4h:8,vec4i:16,vec4u:16,mat2x2f:16,mat3x3f:48,mat4x4f:64,uint8:1,uint8x2:2,uint8x4:4,sint8:1,sint8x2:2,sint8x4:4,unorm8:1,unorm8x2:2,unorm8x4:4,snorm8:1,snorm8x2:2,snorm8x4:4,uint16:2,uint16x2:4,uint16x4:8,sint16:2,sint16x2:4,sint16x4:8,unorm16:2,unorm16x2:4,unorm16x4:8,snorm16:2,snorm16x2:4,snorm16x4:8,float16:2,float16x2:4,float16x4:8,float32:4,float32x2:8,float32x3:12,float32x4:16,uint32:4,uint32x2:8,uint32x3:12,uint32x4:16,sint32:4,sint32x2:8,sint32x3:12,sint32x4:16,"unorm10-10-10-2":4,"unorm8x4-bgra":4,atomic:4};function st(t){let e=0;for(let r of Object.values(t.propTypes)){if(Number.isNaN(e))throw new Error("Only the last property of a struct can be unbounded");if(e=b(e,u(r)),e+=l(r),Number.isNaN(e)&&r.type!=="array")throw new Error("Cannot nest unbounded struct within another struct")}return b(e,u(t))}function pt(t){let e=0;for(let r of Object.values(t.propTypes)){let o=I(r);e=b(e,o),e+=l(r)}return e}function ut(t){let e=at[t?.type];if(e!==void 0)return e;if(A(t))return st(t);if(g(t))return pt(t);if(v(t)){if(t.elementCount===0)return Number.NaN;let r=u(t.elementType);return b(l(t.elementType),r)*t.elementCount}if(T(t)){let r=I(t.elementType);return b(l(t.elementType),r)*t.elementCount}if(y(t)||m(t))return H(t)??l(t.inner);throw new Error(`Cannot determine size of data: ${t}`)}var Y=new WeakMap;function l(t){let e=Y.get(t);return e===void 0&&(e=ut(t),Y.set(t,e)),e}function lt(t){return l(t)}function j(t,e){return new G(t,e)}var G=class{constructor(e,r){this.elementType=e;this.elementCount=r;if(Number.isNaN(l(e)))throw new Error("Cannot nest runtime sized arrays.");if(!Number.isInteger(r)||r<0)throw new Error(`Cannot create array schema with invalid element count: ${r}.`)}[i]=!0;type="array";toString(){return`arrayOf(${this.elementType})`}};function xt(t,e){return new R(t,e)}var R=class{constructor(e,r){this.elementType=e;this.elementCount=r;if(!Number.isInteger(r)||r<0)throw new Error(`Cannot create disarray schema with invalid element count: ${r}.`)}[i]=!0;type="disarray"};function mt(t){let e=r=>r;return Object.setPrototypeOf(e,ct),e.propTypes=t,e}var ct={[i]:!0,type:"unstruct",$name(t){return L(this,t),this},toString(){return`unstruct:${_(this)??"<unnamed>"}`}};function yt(t){return new K(t)}var K=class{constructor(e){this.inner=e}[i]=!0;type="atomic"};function B(t,e){return y(t)?new W(t.inner,[e,...t.attribs]):m(t)?new k(t.inner,[e,...t.attribs]):E(t)?new k(t,[e]):new W(t,[e])}function ft(t,e){return B(e,{[i]:!0,type:"@align",value:t})}function dt(t,e){return B(e,{[i]:!0,type:"@size",value:t})}function Tt(t,e){return B(e,{[i]:!0,type:"@location",value:t})}function gt(t,e){return B(e,{[i]:!0,type:"@interpolate",value:t})}function Dt(t){return(y(t)||m(t))&&t.attribs.find(z)!==void 0}function Me(t){return!y(t)&&!m(t)?"":t.attribs.map(e=>`${e.type}(${e.value}) `).join("")}var $=class{constructor(e,r){this.inner=e;this.attribs=r;let o=r.find(U)?.value,x=r.find(O)?.value;if(o!==void 0){if(o<=0)throw new Error(`Custom data alignment must be a positive number, got: ${o}.`);if(Math.log2(o)%1!==0)throw new Error(`Alignment has to be a power of 2, got: ${o}.`);if(P(this.inner)&&o%u(this.inner)!==0)throw new Error(`Custom alignment has to be a multiple of the standard data alignment. Got: ${o}, expected multiple of: ${u(this.inner)}.`)}if(x!==void 0){if(x<l(this.inner))throw new Error(`Custom data size cannot be smaller then the standard data size. Got: ${x}, expected at least: ${l(this.inner)}.`);if(x<=0)throw new Error(`Custom data size must be a positive number. Got: ${x}.`)}}[i]=!0},W=class extends ${[i]=!0;type="decorated"},k=class extends ${[i]=!0;type="loose-decorated"};function a(t,e){return B(t,{[i]:!0,type:"@builtin",value:e})}var bt={vertexIndex:a(s,"vertex_index"),instanceIndex:a(s,"instance_index"),position:a(p,"position"),clipDistances:a(j(s,8),"clip_distances"),frontFacing:a(N,"front_facing"),fragDepth:a(c,"frag_depth"),sampleIndex:a(s,"sample_index"),sampleMask:a(s,"sample_mask"),localInvocationId:a(d,"local_invocation_id"),localInvocationIndex:a(s,"local_invocation_index"),globalInvocationId:a(d,"global_invocation_id"),workgroupId:a(d,"workgroup_id"),numWorkgroups:a(d,"num_workgroups"),subgroupInvocationId:a(s,"subgroup_invocation_id"),subgroupSize:a(s,"subgroup_size")};export{b as a,et as b,q as c,_t as d,Lt as e,$t as f,Wt as g,kt as h,Pt as i,Ut as j,Ot as k,zt as l,Et as m,Nt as n,Ct as o,Mt as p,Gt as q,jt as r,Rt as s,Kt as t,Ht as u,Jt as v,qt as w,Qt as x,Xt as y,Yt as z,Zt as A,te as B,ee as C,ne as D,re as E,oe as F,ie as G,ae as H,se as I,pe as J,ue as K,le as L,xe as M,me as N,ce as O,ye as P,fe as Q,de as R,u as S,I as T,it as U,l as V,lt as W,j as X,ft as Y,dt as Z,Tt as _,gt as $,Dt as aa,Me as ba,J as ca,Z as da,xt as ea,mt as fa,yt as ga,bt as ha}; //# sourceMappingURL=chunk-S62QJDM6.js.map