typegpu
Version:
A thin layer between JS and WebGPU/WGSL that improves development experience and allows for faster iteration.
2 lines • 13.3 kB
JavaScript
Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2; var _class3; var _class4; var _class5; var _class6; var _class7;var _chunkUMHCZDPAcjs = require('./chunk-UMHCZDPA.cjs');function J(t,e){let r=e;try{r=t(e)}catch (e2){let o=_optionalChain([t, 'optionalAccess', _2 => _2.type]);console.warn(`Schema of type ${_nullishCoalesce(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={[_chunkUMHCZDPAcjs.a]:!0,type:"struct",$name(t){return _chunkUMHCZDPAcjs.j.call(void 0, this,t),this},toString(){return`struct:${_nullishCoalesce(_chunkUMHCZDPAcjs.i.call(void 0, this), () => ("<unnamed>"))}`}};var b=(t,e)=>{let r=e-1,o=~r;return(t&r)===0?t:(t&o)+e};var n= (_class =class{constructor(e){;_class.prototype.__init.call(this);this.type=e}__init() {this[_chunkUMHCZDPAcjs.a]=!0}}, _class),et= exports.b ={uint8:_chunkUMHCZDPAcjs.ma,uint8x2:_chunkUMHCZDPAcjs.ua,uint8x4:_chunkUMHCZDPAcjs.Ea,sint8:_chunkUMHCZDPAcjs.oa,sint8x2:_chunkUMHCZDPAcjs.ta,sint8x4:_chunkUMHCZDPAcjs.Da,unorm8:_chunkUMHCZDPAcjs.pa,unorm8x2:_chunkUMHCZDPAcjs.ra,unorm8x4:_chunkUMHCZDPAcjs.Ba,snorm8:_chunkUMHCZDPAcjs.pa,snorm8x2:_chunkUMHCZDPAcjs.ra,snorm8x4:_chunkUMHCZDPAcjs.Ba,uint16:_chunkUMHCZDPAcjs.ma,uint16x2:_chunkUMHCZDPAcjs.ua,uint16x4:_chunkUMHCZDPAcjs.Ea,sint16:_chunkUMHCZDPAcjs.oa,sint16x2:_chunkUMHCZDPAcjs.ta,sint16x4:_chunkUMHCZDPAcjs.Da,unorm16:_chunkUMHCZDPAcjs.pa,unorm16x2:_chunkUMHCZDPAcjs.ra,unorm16x4:_chunkUMHCZDPAcjs.Ba,snorm16:_chunkUMHCZDPAcjs.pa,snorm16x2:_chunkUMHCZDPAcjs.ra,snorm16x4:_chunkUMHCZDPAcjs.Ba,float16:_chunkUMHCZDPAcjs.pa,float16x2:_chunkUMHCZDPAcjs.ra,float16x4:_chunkUMHCZDPAcjs.Ba,float32:_chunkUMHCZDPAcjs.pa,float32x2:_chunkUMHCZDPAcjs.ra,float32x3:_chunkUMHCZDPAcjs.wa,float32x4:_chunkUMHCZDPAcjs.Ba,uint32:_chunkUMHCZDPAcjs.ma,uint32x2:_chunkUMHCZDPAcjs.ua,uint32x3:_chunkUMHCZDPAcjs.za,uint32x4:_chunkUMHCZDPAcjs.Ea,sint32:_chunkUMHCZDPAcjs.oa,sint32x2:_chunkUMHCZDPAcjs.ta,sint32x3:_chunkUMHCZDPAcjs.ya,sint32x4:_chunkUMHCZDPAcjs.Da,"unorm10-10-10-2":_chunkUMHCZDPAcjs.Ba,"unorm8x4-bgra":_chunkUMHCZDPAcjs.Ba},q= exports.c =Object.keys(et),_t= exports.d =new n("uint8"),Lt= exports.e =new n("uint8x2"),$t= exports.f =new n("uint8x4"),Wt= exports.g =new n("sint8"),kt= exports.h =new n("sint8x2"),Pt= exports.i =new n("sint8x4"),Ut= exports.j =new n("unorm8"),Ot= exports.k =new n("unorm8x2"),zt= exports.l =new n("unorm8x4"),Et= exports.m =new n("snorm8"),Nt= exports.n =new n("snorm8x2"),Ct= exports.o =new n("snorm8x4"),Mt= exports.p =new n("uint16"),Gt= exports.q =new n("uint16x2"),jt= exports.r =new n("uint16x4"),Rt= exports.s =new n("sint16"),Kt= exports.t =new n("sint16x2"),Ht= exports.u =new n("sint16x4"),Jt= exports.v =new n("unorm16"),qt= exports.w =new n("unorm16x2"),Qt= exports.x =new n("unorm16x4"),Xt= exports.y =new n("snorm16"),Yt= exports.z =new n("snorm16x2"),Zt= exports.A =new n("snorm16x4"),te= exports.B =new n("float16"),ee= exports.C =new n("float16x2"),ne= exports.D =new n("float16x4"),re= exports.E =new n("float32"),oe= exports.F =new n("float32x2"),ie= exports.G =new n("float32x3"),ae= exports.H =new n("float32x4"),se= exports.I =new n("uint32"),pe= exports.J =new n("uint32x2"),ue= exports.K =new n("uint32x3"),le= exports.L =new n("uint32x4"),xe= exports.M =new n("sint32"),me= exports.N =new n("sint32x2"),ce= exports.O =new n("sint32x3"),ye= exports.P =new n("sint32x4"),fe= exports.Q =new n("unorm10-10-10-2"),de= exports.R =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=_optionalChain([t, 'optionalAccess', _3 => _3.type]),r=nt[e];if(r!==void 0)return r;if(_chunkUMHCZDPAcjs.O.call(void 0, t))return Object.values(t.propTypes).map(u).reduce((o,x)=>o>x?o:x);if(_chunkUMHCZDPAcjs.N.call(void 0, t))return u(t.elementType);if(_chunkUMHCZDPAcjs._.call(void 0, t)){let o=Object.values(t.propTypes)[0];return o?_nullishCoalesce(_chunkUMHCZDPAcjs.aa.call(void 0, o), () => (1)):1}if(_chunkUMHCZDPAcjs.Z.call(void 0, t))return _nullishCoalesce(_chunkUMHCZDPAcjs.aa.call(void 0, t.elementType), () => (1));if(_chunkUMHCZDPAcjs.W.call(void 0, t)||_chunkUMHCZDPAcjs.$.call(void 0, t))return _nullishCoalesce(_chunkUMHCZDPAcjs.aa.call(void 0, 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(_chunkUMHCZDPAcjs._.call(void 0, t)){let e=Object.values(t.propTypes)[0];return e?I(e):1}return _chunkUMHCZDPAcjs.Z.call(void 0, t)?I(t.elementType):_chunkUMHCZDPAcjs.$.call(void 0, t)?_nullishCoalesce(_chunkUMHCZDPAcjs.aa.call(void 0, t), () => (I(t.inner))):_nullishCoalesce(_chunkUMHCZDPAcjs.aa.call(void 0, 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[_optionalChain([t, 'optionalAccess', _4 => _4.type])];if(e!==void 0)return e;if(_chunkUMHCZDPAcjs.O.call(void 0, t))return st(t);if(_chunkUMHCZDPAcjs._.call(void 0, t))return pt(t);if(_chunkUMHCZDPAcjs.N.call(void 0, t)){if(t.elementCount===0)return Number.NaN;let r=u(t.elementType);return b(l(t.elementType),r)*t.elementCount}if(_chunkUMHCZDPAcjs.Z.call(void 0, t)){let r=I(t.elementType);return b(l(t.elementType),r)*t.elementCount}if(_chunkUMHCZDPAcjs.W.call(void 0, t)||_chunkUMHCZDPAcjs.$.call(void 0, t))return _nullishCoalesce(_chunkUMHCZDPAcjs.ba.call(void 0, 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= (_class2 =class{constructor(e,r){;_class2.prototype.__init2.call(this);_class2.prototype.__init3.call(this);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}.`)}__init2() {this[_chunkUMHCZDPAcjs.a]=!0}__init3() {this.type="array"}toString(){return`arrayOf(${this.elementType})`}}, _class2);function xt(t,e){return new R(t,e)}var R= (_class3 =class{constructor(e,r){;_class3.prototype.__init4.call(this);_class3.prototype.__init5.call(this);this.elementType=e;this.elementCount=r;if(!Number.isInteger(r)||r<0)throw new Error(`Cannot create disarray schema with invalid element count: ${r}.`)}__init4() {this[_chunkUMHCZDPAcjs.a]=!0}__init5() {this.type="disarray"}}, _class3);function mt(t){let e=r=>r;return Object.setPrototypeOf(e,ct),e.propTypes=t,e}var ct={[_chunkUMHCZDPAcjs.a]:!0,type:"unstruct",$name(t){return _chunkUMHCZDPAcjs.j.call(void 0, this,t),this},toString(){return`unstruct:${_nullishCoalesce(_chunkUMHCZDPAcjs.i.call(void 0, this), () => ("<unnamed>"))}`}};function yt(t){return new K(t)}var K= (_class4 =class{constructor(e){;_class4.prototype.__init6.call(this);_class4.prototype.__init7.call(this);this.inner=e}__init6() {this[_chunkUMHCZDPAcjs.a]=!0}__init7() {this.type="atomic"}}, _class4);function B(t,e){return _chunkUMHCZDPAcjs.W.call(void 0, t)?new W(t.inner,[e,...t.attribs]):_chunkUMHCZDPAcjs.$.call(void 0, t)?new k(t.inner,[e,...t.attribs]):_chunkUMHCZDPAcjs.Y.call(void 0, t)?new k(t,[e]):new W(t,[e])}function ft(t,e){return B(e,{[_chunkUMHCZDPAcjs.a]:!0,type:"@align",value:t})}function dt(t,e){return B(e,{[_chunkUMHCZDPAcjs.a]:!0,type:"@size",value:t})}function Tt(t,e){return B(e,{[_chunkUMHCZDPAcjs.a]:!0,type:"@location",value:t})}function gt(t,e){return B(e,{[_chunkUMHCZDPAcjs.a]:!0,type:"@interpolate",value:t})}function Dt(t){return(_chunkUMHCZDPAcjs.W.call(void 0, t)||_chunkUMHCZDPAcjs.$.call(void 0, t))&&t.attribs.find(_chunkUMHCZDPAcjs.V)!==void 0}function Me(t){return!_chunkUMHCZDPAcjs.W.call(void 0, t)&&!_chunkUMHCZDPAcjs.$.call(void 0, t)?"":t.attribs.map(e=>`${e.type}(${e.value}) `).join("")}var $= (_class5 =class{constructor(e,r){;_class5.prototype.__init8.call(this);this.inner=e;this.attribs=r;let o=_optionalChain([r, 'access', _5 => _5.find, 'call', _6 => _6(_chunkUMHCZDPAcjs.R), 'optionalAccess', _7 => _7.value]),x=_optionalChain([r, 'access', _8 => _8.find, 'call', _9 => _9(_chunkUMHCZDPAcjs.S), 'optionalAccess', _10 => _10.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(_chunkUMHCZDPAcjs.M.call(void 0, 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}.`)}}__init8() {this[_chunkUMHCZDPAcjs.a]=!0}}, _class5),W= (_class6 =class extends ${constructor(...args) { super(...args); _class6.prototype.__init9.call(this);_class6.prototype.__init10.call(this); }__init9() {this[_chunkUMHCZDPAcjs.a]=!0}__init10() {this.type="decorated"}}, _class6),k= (_class7 =class extends ${constructor(...args2) { super(...args2); _class7.prototype.__init11.call(this);_class7.prototype.__init12.call(this); }__init11() {this[_chunkUMHCZDPAcjs.a]=!0}__init12() {this.type="loose-decorated"}}, _class7);function a(t,e){return B(t,{[_chunkUMHCZDPAcjs.a]:!0,type:"@builtin",value:e})}var bt={vertexIndex:a(_chunkUMHCZDPAcjs.ma,"vertex_index"),instanceIndex:a(_chunkUMHCZDPAcjs.ma,"instance_index"),position:a(_chunkUMHCZDPAcjs.Ba,"position"),clipDistances:a(j(_chunkUMHCZDPAcjs.ma,8),"clip_distances"),frontFacing:a(_chunkUMHCZDPAcjs.la,"front_facing"),fragDepth:a(_chunkUMHCZDPAcjs.pa,"frag_depth"),sampleIndex:a(_chunkUMHCZDPAcjs.ma,"sample_index"),sampleMask:a(_chunkUMHCZDPAcjs.ma,"sample_mask"),localInvocationId:a(_chunkUMHCZDPAcjs.za,"local_invocation_id"),localInvocationIndex:a(_chunkUMHCZDPAcjs.ma,"local_invocation_index"),globalInvocationId:a(_chunkUMHCZDPAcjs.za,"global_invocation_id"),workgroupId:a(_chunkUMHCZDPAcjs.za,"workgroup_id"),numWorkgroups:a(_chunkUMHCZDPAcjs.za,"num_workgroups"),subgroupInvocationId:a(_chunkUMHCZDPAcjs.ma,"subgroup_invocation_id"),subgroupSize:a(_chunkUMHCZDPAcjs.ma,"subgroup_size")};exports.a = b; exports.b = et; exports.c = q; exports.d = _t; exports.e = Lt; exports.f = $t; exports.g = Wt; exports.h = kt; exports.i = Pt; exports.j = Ut; exports.k = Ot; exports.l = zt; exports.m = Et; exports.n = Nt; exports.o = Ct; exports.p = Mt; exports.q = Gt; exports.r = jt; exports.s = Rt; exports.t = Kt; exports.u = Ht; exports.v = Jt; exports.w = qt; exports.x = Qt; exports.y = Xt; exports.z = Yt; exports.A = Zt; exports.B = te; exports.C = ee; exports.D = ne; exports.E = re; exports.F = oe; exports.G = ie; exports.H = ae; exports.I = se; exports.J = pe; exports.K = ue; exports.L = le; exports.M = xe; exports.N = me; exports.O = ce; exports.P = ye; exports.Q = fe; exports.R = de; exports.S = u; exports.T = I; exports.U = it; exports.V = l; exports.W = lt; exports.X = j; exports.Y = ft; exports.Z = dt; exports._ = Tt; exports.$ = gt; exports.aa = Dt; exports.ba = Me; exports.ca = J; exports.da = Z; exports.ea = xt; exports.fa = mt; exports.ga = yt; exports.ha = bt;
//# sourceMappingURL=chunk-RC26P3MP.cjs.map
;