UNPKG

typegpu

Version:

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

2 lines 13 kB
"use strict";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 _chunkV4CSEIB2cjs = require('./chunk-V4CSEIB2.cjs');function X(t){let e=r=>r;return Object.setPrototypeOf(e,Y),e.propTypes=t,e}var Y={[_chunkV4CSEIB2cjs.a]:!0,type:"struct",$name(t){return _chunkV4CSEIB2cjs.f.call(void 0, this,t),this},toString(){return`struct:${_nullishCoalesce(_chunkV4CSEIB2cjs.e.call(void 0, this), () => ("<unnamed>"))}`}};var b=(t,e)=>{let r=e-1,i=~r;return(t&r)===0?t:(t&i)+e};var n= (_class =class{constructor(e){;_class.prototype.__init.call(this);this.type=e}__init() {this[_chunkV4CSEIB2cjs.a]=!0}}, _class),Z= exports.b ={uint8:_chunkV4CSEIB2cjs.ia,uint8x2:_chunkV4CSEIB2cjs.pa,uint8x4:_chunkV4CSEIB2cjs.za,sint8:_chunkV4CSEIB2cjs.ja,sint8x2:_chunkV4CSEIB2cjs.oa,sint8x4:_chunkV4CSEIB2cjs.ya,unorm8:_chunkV4CSEIB2cjs.ka,unorm8x2:_chunkV4CSEIB2cjs.ma,unorm8x4:_chunkV4CSEIB2cjs.wa,snorm8:_chunkV4CSEIB2cjs.ka,snorm8x2:_chunkV4CSEIB2cjs.ma,snorm8x4:_chunkV4CSEIB2cjs.wa,uint16:_chunkV4CSEIB2cjs.ia,uint16x2:_chunkV4CSEIB2cjs.pa,uint16x4:_chunkV4CSEIB2cjs.za,sint16:_chunkV4CSEIB2cjs.ja,sint16x2:_chunkV4CSEIB2cjs.oa,sint16x4:_chunkV4CSEIB2cjs.ya,unorm16:_chunkV4CSEIB2cjs.ka,unorm16x2:_chunkV4CSEIB2cjs.ma,unorm16x4:_chunkV4CSEIB2cjs.wa,snorm16:_chunkV4CSEIB2cjs.ka,snorm16x2:_chunkV4CSEIB2cjs.ma,snorm16x4:_chunkV4CSEIB2cjs.wa,float16:_chunkV4CSEIB2cjs.ka,float16x2:_chunkV4CSEIB2cjs.ma,float16x4:_chunkV4CSEIB2cjs.wa,float32:_chunkV4CSEIB2cjs.ka,float32x2:_chunkV4CSEIB2cjs.ma,float32x3:_chunkV4CSEIB2cjs.ra,float32x4:_chunkV4CSEIB2cjs.wa,uint32:_chunkV4CSEIB2cjs.ia,uint32x2:_chunkV4CSEIB2cjs.pa,uint32x3:_chunkV4CSEIB2cjs.ua,uint32x4:_chunkV4CSEIB2cjs.za,sint32:_chunkV4CSEIB2cjs.ja,sint32x2:_chunkV4CSEIB2cjs.oa,sint32x3:_chunkV4CSEIB2cjs.ta,sint32x4:_chunkV4CSEIB2cjs.ya,"unorm10-10-10-2":_chunkV4CSEIB2cjs.wa,"unorm8x4-bgra":_chunkV4CSEIB2cjs.wa},H= exports.c =Object.keys(Z),Vt= exports.d =new n("uint8"),Ft= exports.e =new n("uint8x2"),St= exports.f =new n("uint8x4"),_t= exports.g =new n("sint8"),ht= exports.h =new n("sint8x2"),Lt= exports.i =new n("sint8x4"),Wt= exports.j =new n("unorm8"),kt= exports.k =new n("unorm8x2"),Pt= exports.l =new n("unorm8x4"),zt= exports.m =new n("snorm8"),Ut= exports.n =new n("snorm8x2"),Ot= exports.o =new n("snorm8x4"),$t= exports.p =new n("uint16"),Et= exports.q =new n("uint16x2"),Nt= exports.r =new n("uint16x4"),Mt= exports.s =new n("sint16"),Ct= exports.t =new n("sint16x2"),Gt= exports.u =new n("sint16x4"),jt= exports.v =new n("unorm16"),Rt= exports.w =new n("unorm16x2"),Kt= exports.x =new n("unorm16x4"),Ht= exports.y =new n("snorm16"),Jt= exports.z =new n("snorm16x2"),qt= exports.A =new n("snorm16x4"),Qt= exports.B =new n("float16"),Xt= exports.C =new n("float16x2"),Yt= exports.D =new n("float16x4"),Zt= exports.E =new n("float32"),te= exports.F =new n("float32x2"),ee= exports.G =new n("float32x3"),ne= exports.H =new n("float32x4"),re= exports.I =new n("uint32"),oe= exports.J =new n("uint32x2"),ie= exports.K =new n("uint32x3"),ae= exports.L =new n("uint32x4"),se= exports.M =new n("sint32"),ue= exports.N =new n("sint32x2"),pe= exports.O =new n("sint32x3"),xe= exports.P =new n("sint32x4"),le= exports.Q =new n("unorm10-10-10-2"),me= exports.R =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=_optionalChain([t, 'optionalAccess', _2 => _2.type]),r=tt[e];if(r!==void 0)return r;if(_chunkV4CSEIB2cjs.K.call(void 0, t))return Object.values(t.propTypes).map(x).reduce((i,y)=>i>y?i:y);if(_chunkV4CSEIB2cjs.J.call(void 0, t))return x(t.elementType);if(_chunkV4CSEIB2cjs.W.call(void 0, t)){let i=Object.values(t.propTypes)[0];return i?_nullishCoalesce(_chunkV4CSEIB2cjs.Y.call(void 0, i), () => (1)):1}if(_chunkV4CSEIB2cjs.V.call(void 0, t))return _nullishCoalesce(_chunkV4CSEIB2cjs.Y.call(void 0, t.elementType), () => (1));if(_chunkV4CSEIB2cjs.S.call(void 0, t)||_chunkV4CSEIB2cjs.X.call(void 0, t))return _nullishCoalesce(_chunkV4CSEIB2cjs.Y.call(void 0, 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(_chunkV4CSEIB2cjs.W.call(void 0, t)){let e=Object.values(t.propTypes)[0];return e?I(e):1}return _chunkV4CSEIB2cjs.V.call(void 0, t)?I(t.elementType):_chunkV4CSEIB2cjs.X.call(void 0, t)?_nullishCoalesce(_chunkV4CSEIB2cjs.Y.call(void 0, t), () => (I(t.inner))):_nullishCoalesce(_chunkV4CSEIB2cjs.Y.call(void 0, 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[_optionalChain([t, 'optionalAccess', _3 => _3.type])];if(e!==void 0)return e;if(_chunkV4CSEIB2cjs.K.call(void 0, t))return it(t);if(_chunkV4CSEIB2cjs.W.call(void 0, t))return at(t);if(_chunkV4CSEIB2cjs.J.call(void 0, t)){if(t.elementCount===0)return Number.NaN;let r=x(t.elementType);return b(l(t.elementType),r)*t.elementCount}if(_chunkV4CSEIB2cjs.V.call(void 0, t)){let r=I(t.elementType);return b(l(t.elementType),r)*t.elementCount}if(_chunkV4CSEIB2cjs.S.call(void 0, t)||_chunkV4CSEIB2cjs.X.call(void 0, t))return _nullishCoalesce(_chunkV4CSEIB2cjs.Z.call(void 0, 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= (_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[_chunkV4CSEIB2cjs.a]=!0}__init3() {this.type="array"}toString(){return`arrayOf(${this.elementType})`}}, _class2);function pt(t,e){return new j(t,e)}var j= (_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[_chunkV4CSEIB2cjs.a]=!0}__init5() {this.type="disarray"}}, _class3);function xt(t){let e=r=>r;return Object.setPrototypeOf(e,lt),e.propTypes=t,e}var lt={[_chunkV4CSEIB2cjs.a]:!0,type:"unstruct",$name(t){return _chunkV4CSEIB2cjs.f.call(void 0, this,t),this},toString(){return`unstruct:${_nullishCoalesce(_chunkV4CSEIB2cjs.e.call(void 0, this), () => ("<unnamed>"))}`}};function mt(t){return new R(t)}var R= (_class4 =class{constructor(e){;_class4.prototype.__init6.call(this);_class4.prototype.__init7.call(this);this.inner=e}__init6() {this[_chunkV4CSEIB2cjs.a]=!0}__init7() {this.type="atomic"}}, _class4);function B(t,e){return _chunkV4CSEIB2cjs.S.call(void 0, t)?new k(t.inner,[e,...t.attribs]):_chunkV4CSEIB2cjs.X.call(void 0, t)?new P(t.inner,[e,...t.attribs]):_chunkV4CSEIB2cjs.U.call(void 0, t)?new P(t,[e]):new k(t,[e])}function ct(t,e){return B(e,{[_chunkV4CSEIB2cjs.a]:!0,type:"@align",value:t})}function yt(t,e){return B(e,{[_chunkV4CSEIB2cjs.a]:!0,type:"@size",value:t})}function ft(t,e){return B(e,{[_chunkV4CSEIB2cjs.a]:!0,type:"@location",value:t})}function dt(t,e){return B(e,{[_chunkV4CSEIB2cjs.a]:!0,type:"@interpolate",value:t})}function Tt(t){return(_chunkV4CSEIB2cjs.S.call(void 0, t)||_chunkV4CSEIB2cjs.X.call(void 0, t))&&t.attribs.find(_chunkV4CSEIB2cjs.R)!==void 0}function $e(t){return!_chunkV4CSEIB2cjs.S.call(void 0, t)&&!_chunkV4CSEIB2cjs.X.call(void 0, t)?"":t.attribs.map(e=>`${e.type}(${e.value}) `).join("")}var W= (_class5 =class{constructor(e,r){;_class5.prototype.__init8.call(this);this.inner=e;this.attribs=r;let i=_optionalChain([r, 'access', _4 => _4.find, 'call', _5 => _5(_chunkV4CSEIB2cjs.N), 'optionalAccess', _6 => _6.value]),y=_optionalChain([r, 'access', _7 => _7.find, 'call', _8 => _8(_chunkV4CSEIB2cjs.O), 'optionalAccess', _9 => _9.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(_chunkV4CSEIB2cjs.I.call(void 0, 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}.`)}}__init8() {this[_chunkV4CSEIB2cjs.a]=!0}}, _class5),k= (_class6 =class extends W{constructor(...args) { super(...args); _class6.prototype.__init9.call(this);_class6.prototype.__init10.call(this); }__init9() {this[_chunkV4CSEIB2cjs.a]=!0}__init10() {this.type="decorated"}}, _class6),P= (_class7 =class extends W{constructor(...args2) { super(...args2); _class7.prototype.__init11.call(this);_class7.prototype.__init12.call(this); }__init11() {this[_chunkV4CSEIB2cjs.a]=!0}__init12() {this.type="loose-decorated"}}, _class7);function a(t,e){return B(t,{[_chunkV4CSEIB2cjs.a]:!0,type:"@builtin",value:e})}var gt={vertexIndex:a(_chunkV4CSEIB2cjs.ia,"vertex_index"),instanceIndex:a(_chunkV4CSEIB2cjs.ia,"instance_index"),position:a(_chunkV4CSEIB2cjs.wa,"position"),clipDistances:a(G(_chunkV4CSEIB2cjs.ia,8),"clip_distances"),frontFacing:a(_chunkV4CSEIB2cjs.ka,"front_facing"),fragDepth:a(_chunkV4CSEIB2cjs.ka,"frag_depth"),sampleIndex:a(_chunkV4CSEIB2cjs.ia,"sample_index"),sampleMask:a(_chunkV4CSEIB2cjs.ia,"sample_mask"),localInvocationId:a(_chunkV4CSEIB2cjs.ua,"local_invocation_id"),localInvocationIndex:a(_chunkV4CSEIB2cjs.ia,"local_invocation_index"),globalInvocationId:a(_chunkV4CSEIB2cjs.ua,"global_invocation_id"),workgroupId:a(_chunkV4CSEIB2cjs.ua,"workgroup_id"),numWorkgroups:a(_chunkV4CSEIB2cjs.ua,"num_workgroups"),subgroupInvocationId:a(_chunkV4CSEIB2cjs.ia,"subgroup_invocation_id"),subgroupSize:a(_chunkV4CSEIB2cjs.ia,"subgroup_size")};exports.a = b; exports.b = Z; exports.c = H; exports.d = Vt; exports.e = Ft; exports.f = St; exports.g = _t; exports.h = ht; exports.i = Lt; exports.j = Wt; exports.k = kt; exports.l = Pt; exports.m = zt; exports.n = Ut; exports.o = Ot; exports.p = $t; exports.q = Et; exports.r = Nt; exports.s = Mt; exports.t = Ct; exports.u = Gt; exports.v = jt; exports.w = Rt; exports.x = Kt; exports.y = Ht; exports.z = Jt; exports.A = qt; exports.B = Qt; exports.C = Xt; exports.D = Yt; exports.E = Zt; exports.F = te; exports.G = ee; exports.H = ne; exports.I = re; exports.J = oe; exports.K = ie; exports.L = ae; exports.M = se; exports.N = ue; exports.O = pe; exports.P = xe; exports.Q = le; exports.R = me; exports.S = x; exports.T = I; exports.U = rt; exports.V = l; exports.W = ut; exports.X = G; exports.Y = ct; exports.Z = yt; exports._ = ft; exports.$ = dt; exports.aa = Tt; exports.ba = $e; exports.ca = X; exports.da = pt; exports.ea = xt; exports.fa = mt; exports.ga = gt; //# sourceMappingURL=chunk-7ACLI4JY.cjs.map