UNPKG

typegpu

Version:

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

2 lines 7.76 kB
import{I as z,J as v,K as A,N as U,O,R as $,S as c,U as E,V as T,W as g,X as m,Y as D,Z as K,a as o,e as h,f as L,ia as s,ja as w,ka as p,ma as f,oa as V,pa as F,ra as N,ta as M,ua as d,wa as u,ya as S,za as _}from"./chunk-L7HIBZAX.js";function X(t){let e=r=>r;return Object.setPrototypeOf(e,Y),e.propTypes=t,e}var Y={[o]:!0,type:"struct",$name(t){return L(this,t),this},toString(){return`struct:${h(this)??"<unnamed>"}`}};var b=(t,e)=>{let r=e-1,i=~r;return(t&r)===0?t:(t&i)+e};var n=class{constructor(e){this.type=e}[o]=!0},Z={uint8:s,uint8x2:F,uint8x4:_,sint8:w,sint8x2:V,sint8x4:S,unorm8:p,unorm8x2:f,unorm8x4:u,snorm8:p,snorm8x2:f,snorm8x4:u,uint16:s,uint16x2:F,uint16x4:_,sint16:w,sint16x2:V,sint16x4:S,unorm16:p,unorm16x2:f,unorm16x4:u,snorm16:p,snorm16x2:f,snorm16x4:u,float16:p,float16x2:f,float16x4:u,float32:p,float32x2:f,float32x3:N,float32x4:u,uint32:s,uint32x2:F,uint32x3:d,uint32x4:_,sint32:w,sint32x2:V,sint32x3:M,sint32x4:S,"unorm10-10-10-2":u,"unorm8x4-bgra":u},H=Object.keys(Z),Vt=new n("uint8"),Ft=new n("uint8x2"),St=new n("uint8x4"),_t=new n("sint8"),ht=new n("sint8x2"),Lt=new n("sint8x4"),Wt=new n("unorm8"),kt=new n("unorm8x2"),Pt=new n("unorm8x4"),zt=new n("snorm8"),Ut=new n("snorm8x2"),Ot=new n("snorm8x4"),$t=new n("uint16"),Et=new n("uint16x2"),Nt=new n("uint16x4"),Mt=new n("sint16"),Ct=new n("sint16x2"),Gt=new n("sint16x4"),jt=new n("unorm16"),Rt=new n("unorm16x2"),Kt=new n("unorm16x4"),Ht=new n("snorm16"),Jt=new n("snorm16x2"),qt=new n("snorm16x4"),Qt=new n("float16"),Xt=new n("float16x2"),Yt=new n("float16x4"),Zt=new n("float32"),te=new n("float32x2"),ee=new n("float32x3"),ne=new n("float32x4"),re=new n("uint32"),oe=new n("uint32x2"),ie=new n("uint32x3"),ae=new n("uint32x4"),se=new n("sint32"),ue=new n("sint32x2"),pe=new n("sint32x3"),xe=new n("sint32x4"),le=new n("unorm10-10-10-2"),me=new n("unorm8x4-bgra");var tt={f32:4,f16:2,i32:4,u32:4,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 et(t){let e=t?.type,r=tt[e];if(r!==void 0)return r;if(A(t))return Object.values(t.propTypes).map(x).reduce((i,y)=>i>y?i:y);if(v(t))return x(t.elementType);if(g(t)){let i=Object.values(t.propTypes)[0];return i?D(i)??1:1}if(T(t))return D(t.elementType)??1;if(c(t)||m(t))return D(t)??x(t.inner);if(H.includes(e))return 1;throw new Error(`Cannot determine alignment of data: ${JSON.stringify(t)}`)}function nt(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 J=new WeakMap,q=new WeakMap;function x(t){let e=J.get(t);return e===void 0&&(e=et(t),J.set(t,e)),e}function I(t){let e=q.get(t);return e===void 0&&(e=nt(t),q.set(t,e)),e}function rt(t){return x(t)}var ot={f32:4,f16:2,i32:4,u32:4,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 it(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,x(r)),e+=l(r),Number.isNaN(e)&&r.type!=="array")throw new Error("Cannot nest unbounded struct within another struct")}return b(e,x(t))}function at(t){let e=0;for(let r of Object.values(t.propTypes)){let i=I(r);e=b(e,i),e+=l(r)}return e}function st(t){let e=ot[t?.type];if(e!==void 0)return e;if(A(t))return it(t);if(g(t))return at(t);if(v(t)){if(t.elementCount===0)return Number.NaN;let r=x(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(c(t)||m(t))return K(t)??l(t.inner);throw new Error(`Cannot determine size of data: ${t}`)}var Q=new WeakMap;function l(t){let e=Q.get(t);return e===void 0&&(e=st(t),Q.set(t,e)),e}function ut(t){return l(t)}function G(t,e){return new C(t,e)}var C=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}.`)}[o]=!0;type="array";toString(){return`arrayOf(${this.elementType})`}};function pt(t,e){return new j(t,e)}var j=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}.`)}[o]=!0;type="disarray";"~reprPartial"};function xt(t){let e=r=>r;return Object.setPrototypeOf(e,lt),e.propTypes=t,e}var lt={[o]:!0,type:"unstruct",$name(t){return L(this,t),this},toString(){return`unstruct:${h(this)??"<unnamed>"}`}};function mt(t){return new R(t)}var R=class{constructor(e){this.inner=e}[o]=!0;type="atomic";"~memIdent";"~gpuRepr"};function B(t,e){return c(t)?new k(t.inner,[e,...t.attribs]):m(t)?new P(t.inner,[e,...t.attribs]):E(t)?new P(t,[e]):new k(t,[e])}function ct(t,e){return B(e,{[o]:!0,type:"@align",value:t})}function yt(t,e){return B(e,{[o]:!0,type:"@size",value:t})}function ft(t,e){return B(e,{[o]:!0,type:"@location",value:t})}function dt(t,e){return B(e,{[o]:!0,type:"@interpolate",value:t})}function Tt(t){return(c(t)||m(t))&&t.attribs.find($)!==void 0}function $e(t){return!c(t)&&!m(t)?"":t.attribs.map(e=>`${e.type}(${e.value}) `).join("")}var W=class{constructor(e,r){this.inner=e;this.attribs=r;let i=r.find(U)?.value,y=r.find(O)?.value;if(i!==void 0){if(i<=0)throw new Error(`Custom data alignment must be a positive number, got: ${i}.`);if(Math.log2(i)%1!==0)throw new Error(`Alignment has to be a power of 2, got: ${i}.`);if(z(this.inner)&&i%x(this.inner)!==0)throw new Error(`Custom alignment has to be a multiple of the standard data alignment. Got: ${i}, expected multiple of: ${x(this.inner)}.`)}if(y!==void 0){if(y<l(this.inner))throw new Error(`Custom data size cannot be smaller then the standard data size. Got: ${y}, expected at least: ${l(this.inner)}.`);if(y<=0)throw new Error(`Custom data size must be a positive number. Got: ${y}.`)}}[o]=!0},k=class extends W{[o]=!0;type="decorated";"~gpuRepr";"~reprPartial";"~memIdent"},P=class extends W{[o]=!0;type="loose-decorated"};function a(t,e){return B(t,{[o]:!0,type:"@builtin",value:e})}var gt={vertexIndex:a(s,"vertex_index"),instanceIndex:a(s,"instance_index"),position:a(u,"position"),clipDistances:a(G(s,8),"clip_distances"),frontFacing:a(p,"front_facing"),fragDepth:a(p,"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,Z as b,H as c,Vt as d,Ft as e,St as f,_t as g,ht as h,Lt as i,Wt as j,kt as k,Pt as l,zt as m,Ut as n,Ot as o,$t as p,Et as q,Nt as r,Mt as s,Ct as t,Gt as u,jt as v,Rt as w,Kt as x,Ht as y,Jt as z,qt as A,Qt as B,Xt as C,Yt as D,Zt as E,te as F,ee as G,ne as H,re as I,oe as J,ie as K,ae as L,se as M,ue as N,pe as O,xe as P,le as Q,me as R,x as S,I as T,rt as U,l as V,ut as W,G as X,ct as Y,yt as Z,ft as _,dt as $,Tt as aa,$e as ba,X as ca,pt as da,xt as ea,mt as fa,gt as ga}; //# sourceMappingURL=chunk-SFECI7OX.js.map