typegpu 0.7.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/chunk-S27MYQ6U.js DELETED
@@ -1,10 +0,0 @@
1
- import{Aa as Te,Ba as _,C as Xe,Ca as E,Da as ge,E as fe,Ea as K,Fa as ve,Ga as Z,Ha as $,I as j,Ia as be,J as Ze,Ja as v,Ka as De,La as R,M as ae,Ma as U,N as ie,Na as we,O as A,Oa as rt,P as F,Pa as Ie,Q as xe,S as se,T as pe,U as Pe,W as de,X as C,Ya as _e,Za as Ee,_a as Re,a as c,b as qe,cb as ot,db as at,ea as et,eb as it,fb as st,gb as pt,h as Ce,ia as tt,j as P,k as ye,n as Je,na as G,o as Qe,oa as nt,pa as u,qa as X,ra as Le,sa as g,ta as x,va as S,wa as d,x as I,xa as L,ya as ue,za as h}from"./chunk-IH2QU6TV.js";import*as Ot from"tinyest";var ee=(e,t)=>{let r=t-1,n=~r;return(e&r)===0?e:(e&n)+t};var ut=["uint8","uint8x2","uint8x4","sint8","sint8x2","sint8x4","unorm8","unorm8x2","unorm8x4","snorm8","snorm8x2","snorm8x4","uint16","uint16x2","uint16x4","sint16","sint16x2","sint16x4","unorm16","unorm16x2","unorm16x4","snorm16","snorm16x2","snorm16x4","float16","float16x2","float16x4","float32","float32x2","float32x3","float32x4","uint32","uint32x2","uint32x3","uint32x4","sint32","sint32x2","sint32x3","sint32x4","unorm10-10-10-2","unorm8x4-bgra"],an={f32:"float32",vec2f:"float32x2",vec3f:"float32x3",vec4f:"float32x4",f16:"float16",vec2h:"float16x2",vec4h:"float16x4",u32:"uint32",vec2u:"uint32x2",vec3u:"uint32x3",vec4u:"uint32x4",i32:"sint32",vec2i:"sint32x2",vec3i:"sint32x3",vec4i:"sint32x4"};var It=["unstruct","disarray","loose-decorated",...ut];function te(e){return e?.[c]&&It.includes(e?.type)}function W(e){return e?.[c]&&e?.type==="disarray"}function O(e){return e?.[c]&&e?.type==="unstruct"}function V(e){return e?.[c]&&e?.type==="loose-decorated"}function ne(e){return e.attribs?.find(se)?.params[0]}function lt(e){return e.attribs?.find(pe)?.params[0]}function ln(e){return e.attribs?.find(Pe)?.params[0]}function Ue(e){return ie(e)||te(e)}var w={type:"unknown",toString(){return"unknown"}},le=class{constructor(t,r,n){this.name=t;this.lhs=r;this.operator=n}};var p=class{constructor(t){this.type=t}[c]=!0},ht={uint8:x,uint8x2:E,uint8x4:U,sint8:S,sint8x2:_,sint8x4:R,unorm8:d,unorm8x2:h,unorm8x4:v,snorm8:d,snorm8x2:h,snorm8x4:v,uint16:x,uint16x2:E,uint16x4:U,sint16:S,sint16x2:_,sint16x4:R,unorm16:d,unorm16x2:h,unorm16x4:v,snorm16:d,snorm16x2:h,snorm16x4:v,float16:d,float16x2:h,float16x4:v,float32:d,float32x2:h,float32x3:K,float32x4:v,uint32:x,uint32x2:E,uint32x3:$,uint32x4:U,sint32:S,sint32x2:_,sint32x3:Z,sint32x4:R,"unorm10-10-10-2":v,"unorm8x4-bgra":v},We=new Set(Object.keys(ht)),xn=new p("uint8"),dn=new p("uint8x2"),Tn=new p("uint8x4"),gn=new p("sint8"),vn=new p("sint8x2"),bn=new p("sint8x4"),Dn=new p("unorm8"),wn=new p("unorm8x2"),In=new p("unorm8x4"),hn=new p("snorm8"),An=new p("snorm8x2"),Sn=new p("snorm8x4"),$n=new p("uint16"),Vn=new p("uint16x2"),kn=new p("uint16x4"),Bn=new p("sint16"),Fn=new p("sint16x2"),Cn=new p("sint16x4"),Pn=new p("unorm16"),Ln=new p("unorm16x2"),_n=new p("unorm16x4"),En=new p("snorm16"),Rn=new p("snorm16x2"),Un=new p("snorm16x4"),Wn=new p("float16"),On=new p("float16x2"),Nn=new p("float16x4"),zn=new p("float32"),Mn=new p("float32x2"),jn=new p("float32x3"),Gn=new p("float32x4"),Kn=new p("uint32"),Hn=new p("uint32x2"),Yn=new p("uint32x3"),qn=new p("uint32x4"),Jn=new p("sint32"),Qn=new p("sint32x2"),Xn=new p("sint32x3"),Zn=new p("sint32x4"),er=new p("unorm10-10-10-2"),tr=new p("unorm8x4-bgra");function nr(e){return e?.[c]&&We.has(e?.type)}var At={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 St(e){let t=e?.type,r=At[t];if(r!==void 0)return r;if(F(e))return Object.values(e.propTypes).map(k).reduce((n,o)=>n>o?n:o);if(A(e))return k(e.elementType);if(O(e)){let n=Object.values(e.propTypes)[0];return n?ne(n)??1:1}if(W(e))return ne(e.elementType)??1;if(C(e)||V(e))return ne(e)??k(e.inner);if(We.has(t))return 1;throw new Error(`Cannot determine alignment of data: ${JSON.stringify(e)}`)}function $t(e){if(O(e)){let t=Object.values(e.propTypes)[0];return t?re(t):1}return W(e)?re(e.elementType):V(e)?ne(e)??re(e.inner):ne(e)??1}var ct=new WeakMap,mt=new WeakMap;function k(e){let t=ct.get(e);return t===void 0&&(t=St(e),ct.set(e,t)),t}function re(e){let t=mt.get(e);return t===void 0&&(t=$t(e),mt.set(e,t)),t}function Vt(e){return k(e)}var kt={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 Bt(e){let t=0,r=e.propTypes;for(let n of Object.values(r)){if(Number.isNaN(t))throw new Error("Only the last property of a struct can be unbounded");if(t=ee(t,k(n)),t+=B(n),Number.isNaN(t)&&n.type!=="array")throw new Error("Cannot nest unbounded struct within another struct")}return ee(t,k(e))}function Ft(e){let t=0,r=e.propTypes;for(let n of Object.values(r)){let o=re(n);t=ee(t,o),t+=B(n)}return t}function Ct(e){let t=kt[e?.type];if(t!==void 0)return t;if(F(e))return Bt(e);if(O(e))return Ft(e);if(A(e)){if(e.elementCount===0)return Number.NaN;let r=k(e.elementType);return ee(B(e.elementType),r)*e.elementCount}if(W(e)){let r=re(e.elementType);return ee(B(e.elementType),r)*e.elementCount}if(C(e)||V(e))return lt(e)??B(e.inner);throw new Error(`Cannot determine size of data: ${e}`)}var yt=new WeakMap;function B(e){let t=yt.get(e);return t===void 0&&(t=Ct(e),yt.set(e,t)),t}function Pt(e){return B(e)}function he(e,t){try{return e(t)}catch{let r=e?.type;throw new Error(`Schema of type ${r??"<unknown>"} is not callable or was called with invalid arguments.`)}}function Ae(e){try{return e()}catch{let t=e?.type;throw new Error(`Schema of type ${t??"<unknown>"} is not callable.`)}}function H(e,t){let r=n=>{if(n&&n.length!==t)throw new Error(`Array schema of ${t} elements of type ${e.type} called with ${n.length} arguments.`);return Array.from({length:t},(o,a)=>n?he(e,n[a]):Ae(e))};if(Object.setPrototypeOf(r,Lt),Number.isNaN(B(e)))throw new Error("Cannot nest runtime sized arrays.");if(r.elementType=e,!Number.isInteger(t)||t<0)throw new Error(`Cannot create array schema with invalid element count: ${t}.`);return r.elementCount=t,r}var Lt={[c]:!0,type:"array",toString(){return`arrayOf(${this.elementType}, ${this.elementCount})`}};function ft(e,t){throw new Error(`Failed to handle ${e} at ${t}`)}var _t={f:{1:d,2:h,3:K,4:v},h:{1:L,2:Te,3:ve,4:De},i:{1:S,2:_,3:Z,4:R},u:{1:x,2:E,3:$,4:U},b:{1:g,2:ge,3:be,4:we}},Et={vec2f:h,vec2h:Te,vec2i:_,vec2u:E,"vec2<bool>":ge,vec3f:K,vec3h:ve,vec3i:Z,vec3u:$,"vec3<bool>":be,vec4f:v,vec4h:De,vec4i:R,vec4u:U,"vec4<bool>":we,mat2x2f:_e,mat3x3f:Ee,mat4x4f:Re},xt={vec2f:d,vec2h:L,vec2i:S,vec2u:x,"vec2<bool>":g,vec3f:d,vec3h:L,vec3i:S,vec3u:x,"vec3<bool>":g,vec4f:d,vec4h:L,vec4i:S,vec4u:x,"vec4<bool>":g,mat2x2f:h,mat3x3f:K,mat4x4f:v};function Oe(e,t){if(F(e)||O(e))return e.propTypes[t]??w;if(e===g||ot(e))return w;let r=t.length;if(j(e)&&r>=1&&r<=4){let n=e.type.includes("bool")?"b":e.type[4],o=_t[n][r];if(o)return o}return w}function Ne(e){return A(e)||W(e)?e.elementType:e.type in xt?xt[e.type]:w}function ze(e){if(/^0x[0-9a-f]+$/i.test(e))return u(e,X);if(/^0b[01]+$/i.test(e))return u(`${Number.parseInt(e.slice(2),2)}`,X);if(/^-?(?:\d+\.\d*|\d*\.\d+)$/i.test(e))return u(e,Le);if(/^-?\d+(?:\.\d+)?e-?\d+$/i.test(e))return u(e,Le);if(/^-?\d+$/i.test(e))return u(e,X)}var Me={rank:Number.POSITIVE_INFINITY,action:"none"};function dt(e){return j(e)?rt[e.type]:void 0}function Se(e,t){let r=G(e),n=G(t);if(r.type===n.type)return{rank:0,action:"none"};if(r.type==="abstractFloat"){if(n.type==="f32")return{rank:1,action:"none"};if(n.type==="f16")return{rank:2,action:"none"}}if(r.type==="abstractInt"){if(n.type==="i32")return{rank:3,action:"none"};if(n.type==="u32")return{rank:4,action:"none"};if(n.type==="abstractFloat")return{rank:5,action:"none"};if(n.type==="f32")return{rank:6,action:"none"};if(n.type==="f16")return{rank:7,action:"none"}}if(j(r)&&j(n)){let o=dt(r),a=dt(n);if(o&&a)return Se(o,a)}return ae(r)&&ae(n)?{rank:0,action:"none"}:Me}function Rt(e,t){let r=G(e),n=G(t);if(r.type==="ptr"&&Se(r.inner,n).rank<Number.POSITIVE_INFINITY)return{rank:0,action:"deref"};if(n.type==="ptr"&&Se(r,n.inner).rank<Number.POSITIVE_INFINITY)return{rank:1,action:"ref"};let o={f32:0,f16:1,i32:2,u32:3,bool:4};if(r.type in o&&n.type in o){let a=r.type,i=n.type;if(a!==i){let s=o[a];return{rank:o[i]<s?10:20,action:"cast",targetType:n}}}return Me}function Ut(e,t,r){let n=Se(e,t);return n.rank<Number.POSITIVE_INFINITY?n:r?Rt(e,t):Me}function Tt(e,t,r){let n,o=Number.POSITIVE_INFINITY,a=new Map;for(let l of t){let y=0,T=[],z=!0;for(let Q of e){let M=Ut(Q,l,r);if(M.rank===Number.POSITIVE_INFINITY){z=!1;break}y+=M.rank,T.push(M)}z&&y<o&&(o=y,n=l,a.set(n,T))}if(!n)return;let s=a.get(n).map((l,y)=>({sourceIndex:y,action:l.action,...l.action==="cast"&&{targetType:l.targetType}})),f=s.some(l=>l.action==="cast");return{targetType:n,actions:s,hasImplicitConversions:f}}function ce(e){return e.type==="abstractFloat"?d:e.type==="abstractInt"?S:e}function gt(e,t){if(e.length===0)return;let r=[...new Set(e.map(G))],n=t?[...new Set(t.map(G))]:r,o=Tt(e,n,!1);if(o)return o;let a=Tt(e,n,!0);if(a)return a.hasImplicitConversions=a.actions.some(i=>i.action==="cast"),a}function Wt(e,t,r,n){if(r.action==="none")return u(t.value,n);let o=e.resolve(t.value);switch(r.action){case"ref":return u(`&${o}`,n);case"deref":return u(`*${o}`,n);case"cast":return u(`${e.resolve(n)}(${o})`,n);default:ft(r.action,"applyActionToSnippet")}}function Y({ctx:e,values:t,restrictTo:r,concretizeTypes:n=!1,verbose:o=!0}){let a=t.map(s=>n?ce(s.dataType):s.dataType);if(a.some(s=>s===w))return;Ce&&o&&Array.isArray(r)&&r.length===0&&console.warn("convertToCommonType was called with an empty restrictTo array, which prevents any conversions from being made. If you intend to allow all conversions, pass undefined instead. If this was intended call the function conditionally since the result will always be undefined.");let i=gt(a,r);if(i)return Ce&&o&&i.hasImplicitConversions&&console.warn(`Implicit conversions from [
2
- ${t.map(s=>` ${s.value}: ${s.dataType.type}`).join(`,
3
- `)}
4
- ] to ${i.targetType.type} are supported, but not recommended.
5
- Consider using explicit conversions instead.`),t.map((s,f)=>{let l=i.actions[f];return Je(l,"Action should not be undefined"),Wt(e,s,l,i.targetType)})}function je(e,t,r){if(r===t.dataType)return t;if(r.type==="void")throw new I(`Cannot convert value of type '${t.dataType.type}' to type 'void'`);let n=Y({ctx:e,values:[t],restrictTo:[r]});if(!n)throw new I(`Cannot convert value of type '${t.dataType.type}' to type '${r.type}'`);return n[0]}function vt(e,t,r){return Object.keys(t.propTypes).map(o=>{let a=r[o];if(!a)throw new Error(`Missing property ${o}`);let i=t.propTypes[o];return Y({ctx:e,values:[a],restrictTo:[i]})?.[0]??a})}function me(e){if(nt(e))return e;if(Xe(e))return u(e,e[qe]);if(fe(e)||Ze(e))return u(e,Et[e.kind]);if(Array.isArray(e)){let t=e.map(me).filter(Boolean),r=tt();if(!r)throw new Error("Tried to coerce array without a context");let n=Y({ctx:r,values:t}),o=gt(t.map(a=>a.dataType))?.targetType;return!n||!o?u(e,w):u(n.map(a=>a.value).join(", "),H(ce(o),e.length))}return typeof e=="string"||typeof e=="function"||typeof e=="object"||typeof e=="symbol"||typeof e>"u"||e===null?u(e,w):typeof e=="number"||typeof e=="bigint"?u(e,ze(String(e))?.dataType??w):typeof e=="boolean"?u(e,g):u(e,w)}var{NodeTypeCatalog:m}=Ot,Nt=["==","!=","<","<=",">",">=","<<",">>","+","-","*","/","%","|","^","&","&&","||"],zt=["&&","||","==","!=","<","<=",">",">="],Mt=["vec2f","vec3f","vec4f","vec2h","vec3h","vec4h","vec2i","vec3i","vec4i","vec2u","vec3u","vec4u","mat2x2f","mat3x3f","mat4x4f"],Ve={add:at,sub:it,mul:st,div:pt};function bt(e,t,r){return r?zt.includes(t)?g:t==="="?r:e:t==="!"||t==="~"?g:e}function jt(e){throw new Error(`'${JSON.stringify(e)}' was not handled by the WGSL generator.`)}function oe(e,[t,r]){e.pushBlockScope();try{e.indent();let n=r.map(o=>Ke(e,o)).join(`
6
- `);return e.dedent(),`{
7
- ${n}
8
- ${e.pre}}`}finally{e.popBlockScope()}}function Gt(e,t,r){return e.defineVariable(t,r)}function Ge(e,t){let r=e.getById(t);if(!r)throw new Error(`Identifier ${t} not found`);return r}function N(e,t,r){let n=e.expectedType;e.expectedType=r;try{let o=b(e,t);return je(e,o,r)}finally{e.expectedType=n}}function b(e,t){if(typeof t=="string")return Ge(e,t);if(typeof t=="boolean")return u(t?"true":"false",g);if(t[0]===m.logicalExpr||t[0]===m.binaryExpr||t[0]===m.assignmentExpr){let[r,n,o,a]=t,i=b(e,n),s=b(e,a),f=t[0]===m.assignmentExpr?i.dataType.type==="ptr"?[i.dataType.inner]:[i.dataType]:void 0,l=Y({ctx:e,values:[i,s],restrictTo:o==="/"?[d,L]:f,concretizeTypes:o==="/",verbose:o!=="/"}),[y,T]=l||[i,s],z=e.resolve(y.value),Q=e.resolve(T.value),M=bt(y.dataType,o,T.dataType);return u(Nt.includes(o)?`(${z} ${o} ${Q})`:`${z} ${o} ${Q}`,M)}if(t[0]===m.postUpdate){let[r,n,o]=t,a=b(e,o),i=e.resolve(a.value);return u(`${i}${n}`,a.dataType)}if(t[0]===m.unaryExpr){let[r,n,o]=t,a=b(e,o),i=e.resolve(a.value),s=bt(a.dataType,n);return u(`${n}${i}`,s)}if(t[0]===m.memberAccess){let[r,n,o]=t,a=b(e,n);if(Mt.includes(a.dataType.type)&&o in Ve)return{value:new le(o,a,Ve[o][c].gpuImpl),dataType:w};if(a.dataType.type==="unknown"){let i=a.value[o];return me(i)}return xe(a.dataType)?u(`(*${e.resolve(a.value)}).${o}`,Oe(a.dataType.inner,o)):A(a.dataType)&&o==="length"?a.dataType.elementCount===0?u(`arrayLength(&${e.resolve(a.value)})`,x):u(String(a.dataType.elementCount),X):ae(a.dataType)&&o==="columns"?u(a.value,a.dataType):j(a.dataType)&&fe(a.value)?me(a.value[o]):u(`${e.resolve(a.value)}.${o}`,Oe(a.dataType,o))}if(t[0]===m.indexAccess){let[r,n,o]=t,a=b(e,n),i=b(e,o),s=e.resolve(a.value),f=e.resolve(i.value);if(a.dataType.type==="unknown"){if(Array.isArray(o)&&o[0]===m.numericLiteral)return me(a.value[o[1]]);throw new Error(`Cannot index value ${s} of unknown type with index ${f}`)}return xe(a.dataType)?u(`(*${s})[${f}]`,Ne(a.dataType.inner)):u(`${s}[${f}]`,Ue(a.dataType)?Ne(a.dataType):w)}if(t[0]===m.numericLiteral){let r=ze(t[1]);if(!r)throw new Error(`Invalid numeric literal ${t[1]}`);return r}if(t[0]===m.call){let[r,n,o]=t,a=b(e,n);if(F(a.value)||A(a.value)){if(o.length>1)throw new I("Array and struct schemas should always be called with at most 1 argument");if(!o[0])return u(`${e.resolve(a.value)}()`,a.value);let s=N(e,o[0],a.value);return u(e.resolve(s.value),a.value)}if(a.value instanceof le){if(!o[0])throw new I(`An infix operator '${a.value.name}' was called without any arguments`);return a.value.operator(a.value.lhs,b(e,o[0]))}if(!et(a.value))throw new Error(`Function ${String(a.value)} ${P(a.value)} has not been created using TypeGPU APIs. Did you mean to wrap the function with tgpu.fn(args, return)(...) ?`);let i=a.value[c]?.argConversionHint??"keep";try{let s;if(Array.isArray(i))s=o.map((l,y)=>{let T=i[y];if(!T)throw new I(`Function '${P(a.value)}' was called with too many arguments`);return N(e,l,T)});else{let l=o.map(y=>b(e,y)).map(y=>u(e.resolve(y.value),y.dataType));i==="keep"?s=l:i==="unify"?s=Y({ctx:e,values:l})??l:s=i(...l).map((y,T)=>[y,l[T]]).map(([y,T])=>je(e,T,y))}let f=a.value(...s);return u(e.withResetIndentLevel(()=>e.resolve(f.value)),f.dataType)}catch(s){throw new Qe(s,[{toString:()=>P(a.value)}])}}if(t[0]===m.objectExpr){let r=t[1],n=e.expectedType;if(!n||!F(n))throw new I(`No target type could be inferred for object with keys [${Object.keys(r).join(", ")}], please wrap the object in the corresponding schema.`);let o=Object.fromEntries(Object.entries(n.propTypes).map(([i,s])=>{let f=r[i];if(f===void 0)throw new I(`Missing property ${i} in object literal for struct ${n}`);let l=N(e,f,s);return[i,l]})),a=vt(e,n,o);return u(`${e.resolve(n)}(${a.map(i=>e.resolve(i.value)).join(", ")})`,n)}if(t[0]===m.arrayExpr){let[r,n]=t,o=e.expectedType,a,i;if(A(o)){if(a=o.elementType,i=n.map(l=>N(e,l,a)),i.length!==o.elementCount)throw new I(`Cannot create value of type '${o}' from an array of length: ${i.length}`)}else{let l=n.map(T=>b(e,T));if(l.length===0)throw new I("Cannot infer the type of an empty array literal.");let y=Y({ctx:e,values:l});if(!y)throw new I("The given values cannot be automatically converted to a common type. Consider wrapping the array in an appropriate schema");i=y,a=ce(i[0]?.dataType)}let s=`array<${e.resolve(a)}, ${i.length}>`,f=i.map(l=>e.resolve(l.value));return u(`${s}(${f.join(", ")})`,H(a,i.length))}if(t[0]===m.stringLiteral)throw new Error("Cannot use string literals in TGSL.");if(t[0]===m.preUpdate)throw new Error("Cannot use pre-updates in TGSL.");jt(t)}function $e(e){return typeof e!="object"||e[0]!==m.block?[m.block,[e]]:e}function Ke(e,t){if(typeof t=="string")return`${e.pre}${e.resolve(Ge(e,t).value)};`;if(typeof t=="boolean")return`${e.pre}${t?"true":"false"};`;if(t[0]===m.return){let r=t[1],n=r!==void 0?e.resolve(N(e,r,e.topFunctionReturnType).value):void 0;return n?`${e.pre}return ${n};`:`${e.pre}return;`}if(t[0]===m.if){let[r,n,o,a]=t,i=e.resolve(N(e,n,g).value),s=oe(e,$e(o)),f=a?oe(e,$e(a)):void 0;return f?`${e.pre}if (${i}) ${s}
9
- ${e.pre}else ${f}`:`${e.pre}if (${i}) ${s}`}if(t[0]===m.let||t[0]===m.const){let[r,n,o]=t,a=o!==void 0?b(e,o):void 0;if(!a)throw new Error(`Cannot create variable '${n}' without an initial value.`);if(te(a.dataType))throw new Error(`Cannot create variable '${n}' with loose data type.`);Gt(e,n,ce(a.dataType));let i=e.resolve(Ge(e,n).value);return`${e.pre}var ${i} = ${e.resolve(a.value)};`}if(t[0]===m.block)return oe(e,t);if(t[0]===m.for){let[r,n,o,a,i]=t,[s,f,l]=e.withResetIndentLevel(()=>[n?Ke(e,n):void 0,o?b(e,o):void 0,a?Ke(e,a):void 0]),y=s?s.slice(0,-1):"",T=o?N(e,o,g):void 0,z=T?e.resolve(T.value):"",Q=l?l.slice(0,-1):"",M=oe(e,$e(i));return`${e.pre}for (${y}; ${z}; ${Q}) ${M}`}if(t[0]===m.while){let[r,n,o]=t,a=N(e,n,g),i=e.resolve(a.value),s=oe(e,$e(o));return`${e.pre}while (${i}) ${s}`}return t[0]===m.continue?`${e.pre}continue;`:t[0]===m.break?`${e.pre}break;`:`${e.pre}${e.resolve(b(e,t).value)};`}function jr(e,t){return oe(e,t)}function Kt(e){let t=r=>Object.fromEntries(Object.entries(e).map(([n,o])=>[n,r?he(o,r[n]):Ae(o)]));return Object.setPrototypeOf(t,Ht),t.propTypes=e,t}var Ht={[c]:!0,type:"struct",$name(e){return ye(this,e),this},toString(){return`struct:${P(this)??"<unnamed>"}`}};function Yt(e,t){return new He(e,t)}var He=class{constructor(t,r){this.elementType=t;this.elementCount=r;if(!Number.isInteger(r)||r<0)throw new Error(`Cannot create disarray schema with invalid element count: ${r}.`)}[c]=!0;type="disarray"};function qt(e){let t=r=>r;return Object.setPrototypeOf(t,Jt),t.propTypes=e,t}var Jt={[c]:!0,type:"unstruct",$name(e){return ye(this,e),this},toString(){return`unstruct:${P(this)??"<unnamed>"}`}};function Qt(e){return new Ye(e)}var Ye=class{constructor(t){this.inner=t}[c]=!0;type="atomic"};function q(e,t){return C(e)?new Be(e.inner,[t,...e.attribs]):V(e)?new Fe(e.inner,[t,...e.attribs]):te(e)?new Fe(e,[t]):new Be(e,[t])}function Xt(e,t){return q(t,{[c]:!0,type:"@align",params:[e]})}function Zt(e,t){return q(t,{[c]:!0,type:"@size",params:[e]})}function en(e,t){return q(t,{[c]:!0,type:"@location",params:[e]})}function tn(e,t){return q(t,{[c]:!0,type:"@interpolate",params:[e]})}function nn(e){if(!Dt(e))throw new Error("The @invariant attribute must only be applied to the position built-in value.");let t=C(e)||V(e)?e.attribs.find(de):void 0;if(!t||t.params[0]!=="position")throw new Error("The @invariant attribute must only be applied to the position built-in value.");return q(e,{[c]:!0,type:"@invariant",params:[]})}function Dt(e){return(C(e)||V(e))&&e.attribs.find(de)!==void 0}function po(e){return!C(e)&&!V(e)?"":e.attribs.map(t=>t.params.length===0?`${t.type} `:`${t.type}(${t.params.join(", ")}) `).join("")}var ke=class{constructor(t,r){this.inner=t;this.attribs=r;let n=r.find(se)?.params[0],o=r.find(pe)?.params[0];if(n!==void 0){if(n<=0)throw new Error(`Custom data alignment must be a positive number, got: ${n}.`);if(Math.log2(n)%1!==0)throw new Error(`Alignment has to be a power of 2, got: ${n}.`);if(ie(this.inner)&&n%k(this.inner)!==0)throw new Error(`Custom alignment has to be a multiple of the standard data alignment. Got: ${n}, expected multiple of: ${k(this.inner)}.`)}if(o!==void 0){if(o<B(this.inner))throw new Error(`Custom data size cannot be smaller then the standard data size. Got: ${o}, expected at least: ${B(this.inner)}.`);if(o<=0)throw new Error(`Custom data size must be a positive number. Got: ${o}.`)}}[c]=!0},Be=class extends ke{[c]=!0;type="decorated"},Fe=class extends ke{[c]=!0;type="loose-decorated"};function D(e,t){return q(e,{[c]:!0,type:"@builtin",params:[t]})}var rn={vertexIndex:D(x,"vertex_index"),instanceIndex:D(x,"instance_index"),position:D(v,"position"),clipDistances:D(H(x,8),"clip_distances"),frontFacing:D(g,"front_facing"),fragDepth:D(d,"frag_depth"),sampleIndex:D(x,"sample_index"),sampleMask:D(x,"sample_mask"),localInvocationId:D($,"local_invocation_id"),localInvocationIndex:D(x,"local_invocation_index"),globalInvocationId:D($,"global_invocation_id"),workgroupId:D($,"workgroup_id"),numWorkgroups:D($,"num_workgroups"),subgroupInvocationId:D(x,"subgroup_invocation_id"),subgroupSize:D(x,"subgroup_size")};function J(e,t){let r=e.prototype,n=Ve[t][c].jsImpl;r[t]=function(o){return n(this,o)}}J(ue,"add");J(ue,"sub");J(ue,"mul");J(ue,"div");J(Ie,"add");J(Ie,"sub");J(Ie,"mul");export{ee as a,ut as b,an as c,te as d,W as e,O as f,V as g,ln as h,Ue as i,w as j,ht as k,We as l,xn as m,dn as n,Tn as o,gn as p,vn as q,bn as r,Dn as s,wn as t,In as u,hn as v,An as w,Sn as x,$n as y,Vn as z,kn as A,Bn as B,Fn as C,Cn as D,Pn as E,Ln as F,_n as G,En as H,Rn as I,Un as J,Wn as K,On as L,Nn as M,zn as N,Mn as O,jn as P,Gn as Q,Kn as R,Hn as S,Yn as T,qn as U,Jn as V,Qn as W,Xn as X,Zn as Y,er as Z,tr as _,nr as $,k as aa,re as ba,Vt as ca,B as da,Pt as ea,he as fa,Ae as ga,H as ha,ft as ia,Oe as ja,me as ka,Xt as la,Zt as ma,en as na,tn as oa,nn as pa,Dt as qa,po as ra,Kt as sa,jr as ta,Yt as ua,qt as va,Qt as wa,rn as xa};
10
- //# sourceMappingURL=chunk-S27MYQ6U.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/tgsl/wgslGenerator.ts","../src/mathUtils.ts","../src/shared/vertexFormat.ts","../src/data/dataTypes.ts","../src/data/vertexFormatData.ts","../src/data/alignmentOf.ts","../src/data/sizeOf.ts","../src/data/utils.ts","../src/data/array.ts","../src/shared/utilityTypes.ts","../src/tgsl/generationHelpers.ts","../src/data/struct.ts","../src/data/disarray.ts","../src/data/unstruct.ts","../src/data/atomic.ts","../src/data/attributes.ts","../src/builtin.ts","../src/data/index.ts"],"sourcesContent":["import * as tinyest from 'tinyest';\nimport { arrayOf } from '../data/array.ts';\nimport {\n type AnyData,\n InfixDispatch,\n isData,\n isLooseData,\n UnknownData,\n} from '../data/dataTypes.ts';\nimport { snip, type Snippet } from '../data/snippet.ts';\nimport { abstractInt, bool, f16, f32, u32 } from '../data/numeric.ts';\nimport * as wgsl from '../data/wgslTypes.ts';\nimport { ResolutionError, WgslTypeError } from '../errors.ts';\nimport { getName } from '../shared/meta.ts';\nimport { $internal } from '../shared/symbols.ts';\nimport { add, div, mul, sub } from '../std/numeric.ts';\nimport { type FnArgsConversionHint, isMarkedInternal } from '../types.ts';\nimport {\n coerceToSnippet,\n concretize,\n convertStructValues,\n convertToCommonType,\n type GenerationCtx,\n getTypeForIndexAccess,\n getTypeForPropAccess,\n numericLiteralToSnippet,\n tryConvertSnippet,\n} from './generationHelpers.ts';\n\nconst { NodeTypeCatalog: NODE } = tinyest;\n\nconst parenthesizedOps = [\n '==',\n '!=',\n '<',\n '<=',\n '>',\n '>=',\n '<<',\n '>>',\n '+',\n '-',\n '*',\n '/',\n '%',\n '|',\n '^',\n '&',\n '&&',\n '||',\n];\n\nconst binaryLogicalOps = ['&&', '||', '==', '!=', '<', '<=', '>', '>='];\n\nconst infixKinds = [\n 'vec2f',\n 'vec3f',\n 'vec4f',\n 'vec2h',\n 'vec3h',\n 'vec4h',\n 'vec2i',\n 'vec3i',\n 'vec4i',\n 'vec2u',\n 'vec3u',\n 'vec4u',\n 'mat2x2f',\n 'mat3x3f',\n 'mat4x4f',\n];\n\nexport const infixOperators = {\n add,\n sub,\n mul,\n div,\n} as const;\n\nexport type InfixOperator = keyof typeof infixOperators;\n\ntype Operator =\n | tinyest.BinaryOperator\n | tinyest.AssignmentOperator\n | tinyest.LogicalOperator\n | tinyest.UnaryOperator;\n\nfunction operatorToType<\n TL extends AnyData | UnknownData,\n TR extends AnyData | UnknownData,\n>(lhs: TL, op: Operator, rhs?: TR): TL | TR | wgsl.Bool {\n if (!rhs) {\n if (op === '!' || op === '~') {\n return bool;\n }\n\n return lhs;\n }\n\n if (binaryLogicalOps.includes(op)) {\n return bool;\n }\n\n if (op === '=') {\n return rhs;\n }\n\n return lhs;\n}\n\nfunction assertExhaustive(value: never): never {\n throw new Error(\n `'${JSON.stringify(value)}' was not handled by the WGSL generator.`,\n );\n}\n\nexport function generateBlock(\n ctx: GenerationCtx,\n [_, statements]: tinyest.Block,\n): string {\n ctx.pushBlockScope();\n try {\n ctx.indent();\n const body = statements.map((statement) =>\n generateStatement(ctx, statement)\n ).join('\\n');\n ctx.dedent();\n return `{\n${body}\n${ctx.pre}}`;\n } finally {\n ctx.popBlockScope();\n }\n}\n\nexport function registerBlockVariable(\n ctx: GenerationCtx,\n id: string,\n dataType: wgsl.AnyWgslData | UnknownData,\n): Snippet {\n return ctx.defineVariable(id, dataType);\n}\n\nexport function generateIdentifier(ctx: GenerationCtx, id: string): Snippet {\n const res = ctx.getById(id);\n if (!res) {\n throw new Error(`Identifier ${id} not found`);\n }\n\n return res;\n}\n\n/**\n * A wrapper for `generateExpression` that updates `ctx.expectedType`\n * and tries to convert the result when it does not match the expected type.\n */\nexport function generateTypedExpression(\n ctx: GenerationCtx,\n expression: tinyest.Expression,\n expectedType: AnyData,\n) {\n const prevExpectedType = ctx.expectedType;\n ctx.expectedType = expectedType;\n\n try {\n const result = generateExpression(ctx, expression);\n return tryConvertSnippet(ctx, result, expectedType);\n } finally {\n ctx.expectedType = prevExpectedType;\n }\n}\n\nexport function generateExpression(\n ctx: GenerationCtx,\n expression: tinyest.Expression,\n): Snippet {\n if (typeof expression === 'string') {\n return generateIdentifier(ctx, expression);\n }\n\n if (typeof expression === 'boolean') {\n return snip(expression ? 'true' : 'false', bool);\n }\n\n if (\n expression[0] === NODE.logicalExpr ||\n expression[0] === NODE.binaryExpr ||\n expression[0] === NODE.assignmentExpr\n ) {\n // Logical/Binary/Assignment Expression\n const [_, lhs, op, rhs] = expression;\n const lhsExpr = generateExpression(ctx, lhs);\n const rhsExpr = generateExpression(ctx, rhs);\n\n const forcedType = expression[0] === NODE.assignmentExpr\n ? lhsExpr.dataType.type === 'ptr'\n ? [lhsExpr.dataType.inner as AnyData]\n : [lhsExpr.dataType as AnyData]\n : undefined;\n\n const converted = convertToCommonType({\n ctx,\n values: [lhsExpr, rhsExpr],\n restrictTo: op === '/' ? [f32, f16] : forcedType,\n concretizeTypes: op === '/',\n verbose: op !== '/',\n }) as\n | [Snippet, Snippet]\n | undefined;\n const [convLhs, convRhs] = converted || [lhsExpr, rhsExpr];\n\n const lhsStr = ctx.resolve(convLhs.value);\n const rhsStr = ctx.resolve(convRhs.value);\n const type = operatorToType(convLhs.dataType, op, convRhs.dataType);\n\n return snip(\n parenthesizedOps.includes(op)\n ? `(${lhsStr} ${op} ${rhsStr})`\n : `${lhsStr} ${op} ${rhsStr}`,\n type,\n );\n }\n\n if (expression[0] === NODE.postUpdate) {\n // Post-Update Expression\n const [_, op, arg] = expression;\n const argExpr = generateExpression(ctx, arg);\n const argStr = ctx.resolve(argExpr.value);\n\n return snip(`${argStr}${op}`, argExpr.dataType);\n }\n\n if (expression[0] === NODE.unaryExpr) {\n // Unary Expression\n const [_, op, arg] = expression;\n const argExpr = generateExpression(ctx, arg);\n const argStr = ctx.resolve(argExpr.value);\n\n const type = operatorToType(argExpr.dataType, op);\n return snip(`${op}${argStr}`, type);\n }\n\n if (expression[0] === NODE.memberAccess) {\n // Member Access\n const [_, targetNode, property] = expression;\n const target = generateExpression(ctx, targetNode);\n\n if (\n infixKinds.includes(target.dataType.type) &&\n property in infixOperators\n ) {\n return {\n value: new InfixDispatch(\n property,\n target,\n infixOperators[property as InfixOperator][$internal].gpuImpl,\n ),\n dataType: UnknownData,\n };\n }\n\n if (target.dataType.type === 'unknown') {\n // No idea what the type is, so we act on the snippet's value and try to guess\n\n // biome-ignore lint/suspicious/noExplicitAny: we're inspecting the value, and it could be any value\n const propValue = (target.value as any)[property];\n\n // We try to extract any type information based on the prop's value\n return coerceToSnippet(propValue);\n }\n\n if (wgsl.isPtr(target.dataType)) {\n return snip(\n `(*${ctx.resolve(target.value)}).${property}`,\n getTypeForPropAccess(target.dataType.inner as AnyData, property),\n );\n }\n\n if (wgsl.isWgslArray(target.dataType) && property === 'length') {\n if (target.dataType.elementCount === 0) {\n // Dynamically-sized array\n return snip(`arrayLength(&${ctx.resolve(target.value)})`, u32);\n }\n\n return snip(String(target.dataType.elementCount), abstractInt);\n }\n\n if (wgsl.isMat(target.dataType) && property === 'columns') {\n return snip(target.value, target.dataType);\n }\n\n if (\n wgsl.isVec(target.dataType) && wgsl.isVecInstance(target.value)\n ) {\n // We're operating on a vector that's known at resolution time\n // biome-ignore lint/suspicious/noExplicitAny: it's probably a swizzle\n return coerceToSnippet((target.value as any)[property]);\n }\n\n return snip(\n `${ctx.resolve(target.value)}.${property}`,\n getTypeForPropAccess(target.dataType, property),\n );\n }\n\n if (expression[0] === NODE.indexAccess) {\n // Index Access\n const [_, targetNode, propertyNode] = expression;\n const target = generateExpression(ctx, targetNode);\n const property = generateExpression(ctx, propertyNode);\n const targetStr = ctx.resolve(target.value);\n const propertyStr = ctx.resolve(property.value);\n\n if (target.dataType.type === 'unknown') {\n // No idea what the type is, so we act on the snippet's value and try to guess\n\n if (\n Array.isArray(propertyNode) && propertyNode[0] === NODE.numericLiteral\n ) {\n return coerceToSnippet(\n // biome-ignore lint/suspicious/noExplicitAny: we're inspecting the value, and it could be any value\n (target.value as any)[propertyNode[1] as number],\n );\n }\n\n throw new Error(\n `Cannot index value ${targetStr} of unknown type with index ${propertyStr}`,\n );\n }\n\n if (wgsl.isPtr(target.dataType)) {\n return snip(\n `(*${targetStr})[${propertyStr}]`,\n getTypeForIndexAccess(target.dataType.inner as AnyData),\n );\n }\n\n return snip(\n `${targetStr}[${propertyStr}]`,\n isData(target.dataType)\n ? getTypeForIndexAccess(target.dataType)\n : UnknownData,\n );\n }\n\n if (expression[0] === NODE.numericLiteral) {\n // Numeric Literal\n const type = numericLiteralToSnippet(expression[1]);\n if (!type) {\n throw new Error(`Invalid numeric literal ${expression[1]}`);\n }\n return type;\n }\n\n if (expression[0] === NODE.call) {\n // Function Call\n const [_, calleeNode, argNodes] = expression;\n const callee = generateExpression(ctx, calleeNode);\n\n if (wgsl.isWgslStruct(callee.value) || wgsl.isWgslArray(callee.value)) {\n // Struct/array schema call.\n if (argNodes.length > 1) {\n throw new WgslTypeError(\n 'Array and struct schemas should always be called with at most 1 argument',\n );\n }\n\n // No arguments `Struct()`, resolve struct name and return.\n if (!argNodes[0]) {\n return snip(\n `${ctx.resolve(callee.value)}()`,\n /* the schema becomes the data type */ callee.value,\n );\n }\n\n const arg = generateTypedExpression(ctx, argNodes[0], callee.value);\n\n // Either `Struct({ x: 1, y: 2 })`, or `Struct(otherStruct)`.\n // In both cases, we just let the argument resolve everything.\n return snip(ctx.resolve(arg.value), callee.value);\n }\n\n if (callee.value instanceof InfixDispatch) {\n // Infix operator dispatch.\n if (!argNodes[0]) {\n throw new WgslTypeError(\n `An infix operator '${callee.value.name}' was called without any arguments`,\n );\n }\n return callee.value.operator(\n callee.value.lhs,\n generateExpression(ctx, argNodes[0]),\n );\n }\n\n if (!isMarkedInternal(callee.value)) {\n throw new Error(\n `Function ${String(callee.value)} ${\n getName(callee.value)\n } has not been created using TypeGPU APIs. Did you mean to wrap the function with tgpu.fn(args, return)(...) ?`,\n );\n }\n\n // Other, including tgsl functions, std and vector/matrix schema calls.\n\n const argConversionHint = callee.value[$internal]\n ?.argConversionHint as FnArgsConversionHint ?? 'keep';\n try {\n let convertedArguments: Snippet[];\n\n if (Array.isArray(argConversionHint)) {\n // The hint is an array of schemas.\n convertedArguments = argNodes.map((arg, i) => {\n const argType = argConversionHint[i];\n if (!argType) {\n throw new WgslTypeError(\n `Function '${\n getName(callee.value)\n }' was called with too many arguments`,\n );\n }\n return generateTypedExpression(ctx, arg, argType);\n });\n } else {\n const resolvedSnippets = argNodes\n .map((arg) => generateExpression(ctx, arg))\n .map((res) => snip(ctx.resolve(res.value), res.dataType));\n\n if (argConversionHint === 'keep') {\n // The hint tells us to do nothing.\n convertedArguments = resolvedSnippets;\n } else if (argConversionHint === 'unify') {\n // The hint tells us to unify the types.\n convertedArguments =\n convertToCommonType({ ctx, values: resolvedSnippets }) ??\n resolvedSnippets;\n } else {\n // The hint is a function that converts the arguments.\n convertedArguments = argConversionHint(...resolvedSnippets)\n .map((type, i) => [type, resolvedSnippets[i] as Snippet] as const)\n .map(([type, sn]) => tryConvertSnippet(ctx, sn, type));\n }\n }\n // Assuming that `callee` is callable\n const fnRes =\n (callee.value as unknown as (...args: unknown[]) => unknown)(\n ...convertedArguments,\n ) as Snippet;\n // We need to reset the indentation level during function body resolution to ignore the indentation level of the function call\n return snip(\n ctx.withResetIndentLevel(() => ctx.resolve(fnRes.value)),\n fnRes.dataType,\n );\n } catch (error) {\n throw new ResolutionError(error, [{\n toString: () => getName(callee.value),\n }]);\n }\n }\n\n if (expression[0] === NODE.objectExpr) {\n // Object Literal\n const obj = expression[1];\n\n const structType = ctx.expectedType;\n\n if (!structType || !wgsl.isWgslStruct(structType)) {\n throw new WgslTypeError(\n `No target type could be inferred for object with keys [${\n Object.keys(obj).join(', ')\n }], please wrap the object in the corresponding schema.`,\n );\n }\n\n const entries = Object.fromEntries(\n Object.entries(structType.propTypes).map(([key, value]) => {\n const val = obj[key];\n if (val === undefined) {\n throw new WgslTypeError(\n `Missing property ${key} in object literal for struct ${structType}`,\n );\n }\n const result = generateTypedExpression(ctx, val, value as AnyData);\n return [key, result];\n }),\n );\n\n const convertedValues = convertStructValues(ctx, structType, entries);\n\n return snip(\n `${ctx.resolve(structType)}(${\n convertedValues.map((v) => ctx.resolve(v.value)).join(', ')\n })`,\n structType,\n );\n }\n\n if (expression[0] === NODE.arrayExpr) {\n const [_, valueNodes] = expression;\n // Array Expression\n const arrType = ctx.expectedType;\n let elemType: AnyData;\n let values: Snippet[];\n\n if (wgsl.isWgslArray(arrType)) {\n elemType = arrType.elementType as AnyData;\n // The array is typed, so its elements should be as well.\n values = valueNodes.map((value) =>\n generateTypedExpression(ctx, value, elemType)\n );\n // Since it's an expected type, we enforce the length\n if (values.length !== arrType.elementCount) {\n throw new WgslTypeError(\n `Cannot create value of type '${arrType}' from an array of length: ${values.length}`,\n );\n }\n } else {\n // The array is not typed, so we try to guess the types.\n const valuesSnippets = valueNodes.map((value) =>\n generateExpression(ctx, value as tinyest.Expression)\n );\n\n if (valuesSnippets.length === 0) {\n throw new WgslTypeError(\n 'Cannot infer the type of an empty array literal.',\n );\n }\n\n const maybeValues = convertToCommonType({ ctx, values: valuesSnippets });\n if (!maybeValues) {\n throw new WgslTypeError(\n 'The given values cannot be automatically converted to a common type. Consider wrapping the array in an appropriate schema',\n );\n }\n\n values = maybeValues;\n elemType = concretize(values[0]?.dataType as wgsl.AnyWgslData);\n }\n\n const arrayType = `array<${ctx.resolve(elemType)}, ${values.length}>`;\n const arrayValues = values.map((sn) => ctx.resolve(sn.value));\n\n return snip(\n `${arrayType}(${arrayValues.join(', ')})`,\n arrayOf(\n elemType as wgsl.AnyWgslData,\n values.length,\n ) as wgsl.AnyWgslData,\n );\n }\n\n if (expression[0] === NODE.stringLiteral) {\n throw new Error('Cannot use string literals in TGSL.');\n }\n\n if (expression[0] === NODE.preUpdate) {\n throw new Error('Cannot use pre-updates in TGSL.');\n }\n\n assertExhaustive(expression);\n}\n\nfunction blockifySingleStatement(statement: tinyest.Statement): tinyest.Block {\n return typeof statement !== 'object' ||\n statement[0] !== NODE.block\n ? [NODE.block, [statement]]\n : statement;\n}\n\nexport function generateStatement(\n ctx: GenerationCtx,\n statement: tinyest.Statement,\n): string {\n if (typeof statement === 'string') {\n return `${ctx.pre}${\n ctx.resolve(generateIdentifier(ctx, statement).value)\n };`;\n }\n\n if (typeof statement === 'boolean') {\n return `${ctx.pre}${statement ? 'true' : 'false'};`;\n }\n\n if (statement[0] === NODE.return) {\n const returnNode = statement[1];\n\n const returnValue = returnNode !== undefined\n ? ctx.resolve(\n generateTypedExpression(\n ctx,\n returnNode,\n ctx.topFunctionReturnType,\n ).value,\n )\n : undefined;\n\n return returnValue\n ? `${ctx.pre}return ${returnValue};`\n : `${ctx.pre}return;`;\n }\n\n if (statement[0] === NODE.if) {\n const [_, cond, cons, alt] = statement;\n const condition = ctx.resolve(\n generateTypedExpression(ctx, cond, bool).value,\n );\n\n const consequent = generateBlock(ctx, blockifySingleStatement(cons));\n const alternate = alt\n ? generateBlock(ctx, blockifySingleStatement(alt))\n : undefined;\n\n if (!alternate) {\n return `${ctx.pre}if (${condition}) ${consequent}`;\n }\n\n return `\\\n${ctx.pre}if (${condition}) ${consequent}\n${ctx.pre}else ${alternate}`;\n }\n\n if (statement[0] === NODE.let || statement[0] === NODE.const) {\n const [_, rawId, rawValue] = statement;\n const eq = rawValue !== undefined\n ? generateExpression(ctx, rawValue)\n : undefined;\n\n if (!eq) {\n throw new Error(\n `Cannot create variable '${rawId}' without an initial value.`,\n );\n }\n\n if (isLooseData(eq.dataType)) {\n throw new Error(\n `Cannot create variable '${rawId}' with loose data type.`,\n );\n }\n\n registerBlockVariable(\n ctx,\n rawId,\n concretize(eq.dataType as wgsl.AnyWgslData),\n );\n const id = ctx.resolve(generateIdentifier(ctx, rawId).value);\n\n return `${ctx.pre}var ${id} = ${ctx.resolve(eq.value)};`;\n }\n\n if (statement[0] === NODE.block) {\n return generateBlock(ctx, statement);\n }\n\n if (statement[0] === NODE.for) {\n const [_, init, condition, update, body] = statement;\n\n const [initStatement, conditionExpr, updateStatement] = ctx\n .withResetIndentLevel(\n () => [\n init ? generateStatement(ctx, init) : undefined,\n condition ? generateExpression(ctx, condition) : undefined,\n update ? generateStatement(ctx, update) : undefined,\n ],\n );\n\n const initStr = initStatement ? initStatement.slice(0, -1) : '';\n\n const condSnippet = condition\n ? generateTypedExpression(ctx, condition, bool)\n : undefined;\n const conditionStr = condSnippet ? ctx.resolve(condSnippet.value) : '';\n\n const updateStr = updateStatement ? updateStatement.slice(0, -1) : '';\n\n const bodyStr = generateBlock(ctx, blockifySingleStatement(body));\n return `${ctx.pre}for (${initStr}; ${conditionStr}; ${updateStr}) ${bodyStr}`;\n }\n\n if (statement[0] === NODE.while) {\n const [_, condition, body] = statement;\n const condSnippet = generateTypedExpression(ctx, condition, bool);\n const conditionStr = ctx.resolve(condSnippet.value);\n\n const bodyStr = generateBlock(ctx, blockifySingleStatement(body));\n return `${ctx.pre}while (${conditionStr}) ${bodyStr}`;\n }\n\n if (statement[0] === NODE.continue) {\n return `${ctx.pre}continue;`;\n }\n\n if (statement[0] === NODE.break) {\n return `${ctx.pre}break;`;\n }\n\n return `${ctx.pre}${ctx.resolve(generateExpression(ctx, statement).value)};`;\n}\n\nexport function generateFunction(\n ctx: GenerationCtx,\n body: tinyest.Block,\n): string {\n return generateBlock(ctx, body);\n}\n","/**\n * @param value\n * @param modulo has to be power of 2\n */\nexport const roundUp = (value: number, modulo: number) => {\n const bitMask = modulo - 1;\n const invBitMask = ~bitMask;\n return (value & bitMask) === 0 ? value : (value & invBitMask) + modulo;\n};\n","export const vertexFormats = [\n 'uint8',\n 'uint8x2',\n 'uint8x4',\n 'sint8',\n 'sint8x2',\n 'sint8x4',\n 'unorm8',\n 'unorm8x2',\n 'unorm8x4',\n 'snorm8',\n 'snorm8x2',\n 'snorm8x4',\n 'uint16',\n 'uint16x2',\n 'uint16x4',\n 'sint16',\n 'sint16x2',\n 'sint16x4',\n 'unorm16',\n 'unorm16x2',\n 'unorm16x4',\n 'snorm16',\n 'snorm16x2',\n 'snorm16x4',\n 'float16',\n 'float16x2',\n 'float16x4',\n 'float32',\n 'float32x2',\n 'float32x3',\n 'float32x4',\n 'uint32',\n 'uint32x2',\n 'uint32x3',\n 'uint32x4',\n 'sint32',\n 'sint32x2',\n 'sint32x3',\n 'sint32x4',\n 'unorm10-10-10-2',\n 'unorm8x4-bgra',\n] as const;\n\nexport type VertexFormat = (typeof vertexFormats)[number];\n\nexport const kindToDefaultFormatMap = {\n f32: 'float32',\n vec2f: 'float32x2',\n vec3f: 'float32x3',\n vec4f: 'float32x4',\n f16: 'float16',\n vec2h: 'float16x2',\n // vec3h has no direct equivalent in the spec\n vec4h: 'float16x4',\n u32: 'uint32',\n vec2u: 'uint32x2',\n vec3u: 'uint32x3',\n vec4u: 'uint32x4',\n i32: 'sint32',\n vec2i: 'sint32x2',\n vec3i: 'sint32x3',\n vec4i: 'sint32x4',\n} as const;\n\nexport type KindToDefaultFormatMap = typeof kindToDefaultFormatMap;\n\nexport interface TgpuVertexAttrib<TFormat extends VertexFormat = VertexFormat> {\n readonly format: TFormat;\n readonly offset: number;\n}\n\nexport type AnyVertexAttribs =\n | Record<string, TgpuVertexAttrib>\n | TgpuVertexAttrib;\n\n/**\n * All vertex attribute formats that can be interpreted as\n * an single or multi component u32 in a shader.\n * https://www.w3.org/TR/webgpu/#vertex-formats\n */\ntype U32CompatibleFormats =\n | TgpuVertexAttrib<'uint8'>\n | TgpuVertexAttrib<'uint8x2'>\n | TgpuVertexAttrib<'uint8x4'>\n | TgpuVertexAttrib<'uint16'>\n | TgpuVertexAttrib<'uint16x2'>\n | TgpuVertexAttrib<'uint16x4'>\n | TgpuVertexAttrib<'uint32'>\n | TgpuVertexAttrib<'uint32x2'>\n | TgpuVertexAttrib<'uint32x3'>\n | TgpuVertexAttrib<'uint32x4'>;\n\n/**\n * All vertex attribute formats that can be interpreted as\n * an single or multi component i32 in a shader.\n * https://www.w3.org/TR/webgpu/#vertex-formats\n */\ntype I32CompatibleFormats =\n | TgpuVertexAttrib<'sint8'>\n | TgpuVertexAttrib<'sint8x2'>\n | TgpuVertexAttrib<'sint8x4'>\n | TgpuVertexAttrib<'sint16'>\n | TgpuVertexAttrib<'sint16x2'>\n | TgpuVertexAttrib<'sint16x4'>\n | TgpuVertexAttrib<'sint32'>\n | TgpuVertexAttrib<'sint32x2'>\n | TgpuVertexAttrib<'sint32x3'>\n | TgpuVertexAttrib<'sint32x4'>;\n\n/**\n * All vertex attribute formats that can be interpreted as\n * an single or multi component f32 in a shader.\n * https://www.w3.org/TR/webgpu/#vertex-formats\n */\ntype F32CompatibleFormats =\n | TgpuVertexAttrib<'unorm8'>\n | TgpuVertexAttrib<'unorm8x2'>\n | TgpuVertexAttrib<'unorm8x4'>\n | TgpuVertexAttrib<'snorm8'>\n | TgpuVertexAttrib<'snorm8x2'>\n | TgpuVertexAttrib<'snorm8x4'>\n | TgpuVertexAttrib<'unorm16'>\n | TgpuVertexAttrib<'unorm16x2'>\n | TgpuVertexAttrib<'unorm16x4'>\n | TgpuVertexAttrib<'snorm16'>\n | TgpuVertexAttrib<'snorm16x2'>\n | TgpuVertexAttrib<'snorm16x4'>\n | TgpuVertexAttrib<'float16'>\n | TgpuVertexAttrib<'float16x2'>\n | TgpuVertexAttrib<'float16x4'>\n | TgpuVertexAttrib<'float32'>\n | TgpuVertexAttrib<'float32x2'>\n | TgpuVertexAttrib<'float32x3'>\n | TgpuVertexAttrib<'float32x4'>\n | TgpuVertexAttrib<'unorm10-10-10-2'>\n | TgpuVertexAttrib<'unorm8x4-bgra'>;\n\n/**\n * All vertex attribute formats that can be interpreted as\n * a single or multi component f16 in a shader. (same as f32 on the shader side)\n * https://www.w3.org/TR/webgpu/#vertex-formats\n */\ntype F16CompatibleFormats = F32CompatibleFormats;\n\nexport type KindToAcceptedAttribMap = {\n u32: U32CompatibleFormats;\n vec2u: U32CompatibleFormats;\n vec3u: U32CompatibleFormats;\n vec4u: U32CompatibleFormats;\n\n i32: I32CompatibleFormats;\n vec2i: I32CompatibleFormats;\n vec3i: I32CompatibleFormats;\n vec4i: I32CompatibleFormats;\n\n f16: F16CompatibleFormats;\n vec2h: F16CompatibleFormats;\n vec3h: F16CompatibleFormats;\n vec4h: F16CompatibleFormats;\n\n f32: F32CompatibleFormats;\n vec2f: F32CompatibleFormats;\n vec3f: F32CompatibleFormats;\n vec4f: F32CompatibleFormats;\n};\n","import type { TgpuNamable } from '../shared/meta.ts';\nimport type {\n Infer,\n InferGPURecord,\n InferPartial,\n InferPartialRecord,\n InferRecord,\n IsValidVertexSchema,\n MemIdentityRecord,\n} from '../shared/repr.ts';\nimport type {\n $gpuRepr,\n $invalidSchemaReason,\n $memIdent,\n $repr,\n $reprPartial,\n $validVertexSchema,\n} from '../shared/symbols.ts';\nimport { $internal } from '../shared/symbols.ts';\nimport type { Prettify } from '../shared/utilityTypes.ts';\nimport { vertexFormats } from '../shared/vertexFormat.ts';\nimport type { FnArgsConversionHint } from '../types.ts';\nimport type { MapValueToSnippet, Snippet } from './snippet.ts';\nimport type { PackedData } from './vertexFormatData.ts';\nimport * as wgsl from './wgslTypes.ts';\n\nexport type TgpuDualFn<TImpl extends (...args: never[]) => unknown> =\n & TImpl\n & {\n [$internal]: {\n jsImpl: TImpl | string;\n gpuImpl: (...args: MapValueToSnippet<Parameters<TImpl>>) => Snippet;\n argConversionHint: FnArgsConversionHint;\n };\n };\n\n/**\n * Array schema constructed via `d.disarrayOf` function.\n *\n * Useful for defining vertex buffers.\n * Elements in the schema are not aligned in respect to their `byteAlignment`,\n * unless they are explicitly decorated with the custom align attribute\n * via `d.align` function.\n */\nexport interface Disarray<TElement extends wgsl.BaseData = wgsl.BaseData>\n extends wgsl.BaseData {\n readonly type: 'disarray';\n readonly elementCount: number;\n readonly elementType: TElement;\n\n // Type-tokens, not available at runtime\n readonly [$repr]: Infer<TElement>[];\n readonly [$reprPartial]:\n | { idx: number; value: InferPartial<TElement> }[]\n | undefined;\n readonly [$validVertexSchema]: IsValidVertexSchema<TElement>;\n readonly [$invalidSchemaReason]:\n 'Disarrays are not host-shareable, use arrays instead';\n // ---\n}\n\n/**\n * Struct schema constructed via `d.unstruct` function.\n *\n * Useful for defining vertex buffers, as the standard layout restrictions do not apply.\n * Members are not aligned in respect to their `byteAlignment`,\n * unless they are explicitly decorated with the custom align attribute\n * via `d.align` function.\n */\nexport interface Unstruct<\n // biome-ignore lint/suspicious/noExplicitAny: the widest type that works with both covariance and contravariance\n TProps extends Record<string, wgsl.BaseData> = any,\n> extends wgsl.BaseData, TgpuNamable {\n (props: Prettify<InferRecord<TProps>>): Prettify<InferRecord<TProps>>;\n readonly type: 'unstruct';\n readonly propTypes: TProps;\n\n // Type-tokens, not available at runtime\n readonly [$repr]: Prettify<InferRecord<TProps>>;\n readonly [$gpuRepr]: Prettify<InferGPURecord<TProps>>;\n readonly [$memIdent]: Unstruct<Prettify<MemIdentityRecord<TProps>>>;\n readonly [$reprPartial]:\n | Prettify<Partial<InferPartialRecord<TProps>>>\n | undefined;\n readonly [$validVertexSchema]: {\n [K in keyof TProps]: IsValidVertexSchema<TProps[K]>;\n }[keyof TProps] extends true ? true : false;\n readonly [$invalidSchemaReason]:\n 'Unstructs are not host-shareable, use structs instead';\n // ---\n}\n\n/** @deprecated Just use `Unstruct` without any type parameters */\nexport type AnyUnstruct = Unstruct;\n\nexport interface LooseDecorated<\n TInner extends wgsl.BaseData = wgsl.BaseData,\n TAttribs extends unknown[] = unknown[],\n> extends wgsl.BaseData {\n readonly type: 'loose-decorated';\n readonly inner: TInner;\n readonly attribs: TAttribs;\n\n // Type-tokens, not available at runtime\n readonly [$repr]: Infer<TInner>;\n readonly [$invalidSchemaReason]:\n 'Loosely decorated schemas are not host-shareable';\n readonly [$validVertexSchema]: IsValidVertexSchema<TInner>;\n // ---\n}\n\nconst looseTypeLiterals = [\n 'unstruct',\n 'disarray',\n 'loose-decorated',\n ...vertexFormats,\n] as const;\n\nexport type LooseTypeLiteral = (typeof looseTypeLiterals)[number];\n\nexport type AnyLooseData = Disarray | Unstruct | LooseDecorated | PackedData;\n\nexport function isLooseData(data: unknown): data is AnyLooseData {\n return (\n (data as AnyLooseData)?.[$internal] &&\n looseTypeLiterals.includes((data as AnyLooseData)?.type)\n );\n}\n\n/**\n * Checks whether the passed in value is a disarray schema,\n * as opposed to, e.g., a regular array schema.\n *\n * Array schemas can be used to describe uniform and storage buffers,\n * whereas disarray schemas cannot. Disarrays are useful for\n * defining vertex buffers instead.\n *\n * @example\n * isDisarray(d.arrayOf(d.u32, 4)) // false\n * isDisarray(d.disarrayOf(d.u32, 4)) // true\n * isDisarray(d.vec3f) // false\n */\nexport function isDisarray<T extends Disarray>(\n schema: T | unknown,\n): schema is T {\n return (schema as T)?.[$internal] && (schema as T)?.type === 'disarray';\n}\n\n/**\n * Checks whether passed in value is a unstruct schema,\n * as opposed to, e.g., a struct schema.\n *\n * Struct schemas can be used to describe uniform and storage buffers,\n * whereas unstruct schemas cannot. Unstructs are useful for\n * defining vertex buffers instead.\n *\n * @example\n * isUnstruct(d.struct({ a: d.u32 })) // false\n * isUnstruct(d.unstruct({ a: d.u32 })) // true\n * isUnstruct(d.vec3f) // false\n */\nexport function isUnstruct<T extends Unstruct>(\n schema: T | unknown,\n): schema is T {\n return (schema as T)?.[$internal] && (schema as T)?.type === 'unstruct';\n}\n\nexport function isLooseDecorated<T extends LooseDecorated>(\n value: T | unknown,\n): value is T {\n return (value as T)?.[$internal] && (value as T)?.type === 'loose-decorated';\n}\n\nexport function getCustomAlignment(data: wgsl.BaseData): number | undefined {\n return (data as unknown as wgsl.Decorated | LooseDecorated).attribs?.find(\n wgsl.isAlignAttrib,\n )?.params[0];\n}\n\nexport function getCustomSize(data: wgsl.BaseData): number | undefined {\n return (data as unknown as wgsl.Decorated | LooseDecorated).attribs?.find(\n wgsl.isSizeAttrib,\n )?.params[0];\n}\n\nexport function getCustomLocation(data: wgsl.BaseData): number | undefined {\n return (data as unknown as wgsl.Decorated | LooseDecorated).attribs?.find(\n wgsl.isLocationAttrib,\n )?.params[0];\n}\n\nexport function isData(value: unknown): value is AnyData {\n return wgsl.isWgslData(value) || isLooseData(value);\n}\n\nexport type AnyData = wgsl.AnyWgslData | AnyLooseData;\nexport type AnyConcreteData = Exclude<\n AnyData,\n wgsl.AbstractInt | wgsl.AbstractFloat | wgsl.Void\n>;\n\nexport interface UnknownData {\n readonly type: 'unknown';\n}\n\nexport const UnknownData = {\n type: 'unknown' as const,\n toString() {\n return 'unknown';\n },\n} as UnknownData;\n\nexport class InfixDispatch {\n constructor(\n readonly name: string,\n readonly lhs: Snippet,\n readonly operator: (lhs: Snippet, rhs: Snippet) => Snippet,\n ) {}\n}\n","import type { Infer } from '../shared/repr.ts';\nimport { $internal } from '../shared/symbols.ts';\nimport type {\n $invalidSchemaReason,\n $repr,\n $validVertexSchema,\n} from '../shared/symbols.ts';\nimport type { VertexFormat } from '../shared/vertexFormat.ts';\nimport { f32, i32, u32 } from './numeric.ts';\nimport {\n vec2f,\n vec2i,\n vec2u,\n vec3f,\n vec3i,\n vec3u,\n vec4f,\n vec4i,\n vec4u,\n} from './vector.ts';\nimport type { BaseData } from './wgslTypes.ts';\n\nexport type FormatToWGSLType<T extends VertexFormat> =\n (typeof formatToWGSLType)[T];\n\nexport interface TgpuVertexFormatData<T extends VertexFormat> extends BaseData {\n readonly type: T;\n\n // Type-tokens, not available at runtime\n readonly [$repr]: Infer<FormatToWGSLType<T>>;\n readonly [$validVertexSchema]: true;\n readonly [$invalidSchemaReason]:\n 'Vertex formats are not host-shareable, use concrete types instead';\n // ---\n}\n\nclass TgpuVertexFormatDataImpl<T extends VertexFormat>\n implements TgpuVertexFormatData<T> {\n public readonly [$internal] = true;\n\n // Type-tokens, not available at runtime\n declare readonly [$repr]: Infer<FormatToWGSLType<T>>;\n declare readonly [$validVertexSchema]: true;\n declare readonly [$invalidSchemaReason]:\n 'Vertex formats are not host-shareable, use concrete types instead';\n // ---\n\n constructor(public readonly type: T) {}\n}\n\nexport const formatToWGSLType = {\n uint8: u32,\n uint8x2: vec2u,\n uint8x4: vec4u,\n sint8: i32,\n sint8x2: vec2i,\n sint8x4: vec4i,\n unorm8: f32,\n unorm8x2: vec2f,\n unorm8x4: vec4f,\n snorm8: f32,\n snorm8x2: vec2f,\n snorm8x4: vec4f,\n uint16: u32,\n uint16x2: vec2u,\n uint16x4: vec4u,\n sint16: i32,\n sint16x2: vec2i,\n sint16x4: vec4i,\n unorm16: f32,\n unorm16x2: vec2f,\n unorm16x4: vec4f,\n snorm16: f32,\n snorm16x2: vec2f,\n snorm16x4: vec4f,\n float16: f32,\n float16x2: vec2f,\n float16x4: vec4f,\n float32: f32,\n float32x2: vec2f,\n float32x3: vec3f,\n float32x4: vec4f,\n uint32: u32,\n uint32x2: vec2u,\n uint32x3: vec3u,\n uint32x4: vec4u,\n sint32: i32,\n sint32x2: vec2i,\n sint32x3: vec3i,\n sint32x4: vec4i,\n 'unorm10-10-10-2': vec4f,\n 'unorm8x4-bgra': vec4f,\n} as const;\n\nexport const packedFormats = new Set(Object.keys(formatToWGSLType));\n\nexport type uint8 = TgpuVertexFormatData<'uint8'>;\nexport const uint8 = new TgpuVertexFormatDataImpl('uint8') as uint8;\n\nexport type uint8x2 = TgpuVertexFormatData<'uint8x2'>;\nexport const uint8x2 = new TgpuVertexFormatDataImpl('uint8x2') as uint8x2;\n\nexport type uint8x4 = TgpuVertexFormatData<'uint8x4'>;\nexport const uint8x4 = new TgpuVertexFormatDataImpl('uint8x4') as uint8x4;\n\nexport type sint8 = TgpuVertexFormatData<'sint8'>;\nexport const sint8 = new TgpuVertexFormatDataImpl('sint8') as sint8;\n\nexport type sint8x2 = TgpuVertexFormatData<'sint8x2'>;\nexport const sint8x2 = new TgpuVertexFormatDataImpl('sint8x2') as sint8x2;\n\nexport type sint8x4 = TgpuVertexFormatData<'sint8x4'>;\nexport const sint8x4 = new TgpuVertexFormatDataImpl('sint8x4') as sint8x4;\n\nexport type unorm8 = TgpuVertexFormatData<'unorm8'>;\nexport const unorm8 = new TgpuVertexFormatDataImpl('unorm8') as unorm8;\n\nexport type unorm8x2 = TgpuVertexFormatData<'unorm8x2'>;\nexport const unorm8x2 = new TgpuVertexFormatDataImpl('unorm8x2') as unorm8x2;\n\nexport type unorm8x4 = TgpuVertexFormatData<'unorm8x4'>;\nexport const unorm8x4 = new TgpuVertexFormatDataImpl('unorm8x4') as unorm8x4;\n\nexport type snorm8 = TgpuVertexFormatData<'snorm8'>;\nexport const snorm8 = new TgpuVertexFormatDataImpl('snorm8') as snorm8;\n\nexport type snorm8x2 = TgpuVertexFormatData<'snorm8x2'>;\nexport const snorm8x2 = new TgpuVertexFormatDataImpl('snorm8x2') as snorm8x2;\n\nexport type snorm8x4 = TgpuVertexFormatData<'snorm8x4'>;\nexport const snorm8x4 = new TgpuVertexFormatDataImpl('snorm8x4') as snorm8x4;\n\nexport type uint16 = TgpuVertexFormatData<'uint16'>;\nexport const uint16 = new TgpuVertexFormatDataImpl('uint16') as uint16;\n\nexport type uint16x2 = TgpuVertexFormatData<'uint16x2'>;\nexport const uint16x2 = new TgpuVertexFormatDataImpl('uint16x2') as uint16x2;\n\nexport type uint16x4 = TgpuVertexFormatData<'uint16x4'>;\nexport const uint16x4 = new TgpuVertexFormatDataImpl('uint16x4') as uint16x4;\n\nexport type sint16 = TgpuVertexFormatData<'sint16'>;\nexport const sint16 = new TgpuVertexFormatDataImpl('sint16') as sint16;\n\nexport type sint16x2 = TgpuVertexFormatData<'sint16x2'>;\nexport const sint16x2 = new TgpuVertexFormatDataImpl('sint16x2') as sint16x2;\n\nexport type sint16x4 = TgpuVertexFormatData<'sint16x4'>;\nexport const sint16x4 = new TgpuVertexFormatDataImpl('sint16x4') as sint16x4;\n\nexport type unorm16 = TgpuVertexFormatData<'unorm16'>;\nexport const unorm16 = new TgpuVertexFormatDataImpl('unorm16') as unorm16;\n\nexport type unorm16x2 = TgpuVertexFormatData<'unorm16x2'>;\nexport const unorm16x2 = new TgpuVertexFormatDataImpl('unorm16x2') as unorm16x2;\n\nexport type unorm16x4 = TgpuVertexFormatData<'unorm16x4'>;\nexport const unorm16x4 = new TgpuVertexFormatDataImpl('unorm16x4') as unorm16x4;\n\nexport type snorm16 = TgpuVertexFormatData<'snorm16'>;\nexport const snorm16 = new TgpuVertexFormatDataImpl('snorm16') as snorm16;\n\nexport type snorm16x2 = TgpuVertexFormatData<'snorm16x2'>;\nexport const snorm16x2 = new TgpuVertexFormatDataImpl('snorm16x2') as snorm16x2;\n\nexport type snorm16x4 = TgpuVertexFormatData<'snorm16x4'>;\nexport const snorm16x4 = new TgpuVertexFormatDataImpl('snorm16x4') as snorm16x4;\n\nexport type float16 = TgpuVertexFormatData<'float16'>;\nexport const float16 = new TgpuVertexFormatDataImpl('float16') as float16;\n\nexport type float16x2 = TgpuVertexFormatData<'float16x2'>;\nexport const float16x2 = new TgpuVertexFormatDataImpl('float16x2') as float16x2;\n\nexport type float16x4 = TgpuVertexFormatData<'float16x4'>;\nexport const float16x4 = new TgpuVertexFormatDataImpl('float16x4') as float16x4;\n\nexport type float32 = TgpuVertexFormatData<'float32'>;\nexport const float32 = new TgpuVertexFormatDataImpl('float32') as float32;\n\nexport type float32x2 = TgpuVertexFormatData<'float32x2'>;\nexport const float32x2 = new TgpuVertexFormatDataImpl('float32x2') as float32x2;\n\nexport type float32x3 = TgpuVertexFormatData<'float32x3'>;\nexport const float32x3 = new TgpuVertexFormatDataImpl('float32x3') as float32x3;\n\nexport type float32x4 = TgpuVertexFormatData<'float32x4'>;\nexport const float32x4 = new TgpuVertexFormatDataImpl('float32x4') as float32x4;\n\nexport type uint32 = TgpuVertexFormatData<'uint32'>;\nexport const uint32 = new TgpuVertexFormatDataImpl('uint32') as uint32;\n\nexport type uint32x2 = TgpuVertexFormatData<'uint32x2'>;\nexport const uint32x2 = new TgpuVertexFormatDataImpl('uint32x2') as uint32x2;\n\nexport type uint32x3 = TgpuVertexFormatData<'uint32x3'>;\nexport const uint32x3 = new TgpuVertexFormatDataImpl('uint32x3') as uint32x3;\n\nexport type uint32x4 = TgpuVertexFormatData<'uint32x4'>;\nexport const uint32x4 = new TgpuVertexFormatDataImpl('uint32x4') as uint32x4;\n\nexport type sint32 = TgpuVertexFormatData<'sint32'>;\nexport const sint32 = new TgpuVertexFormatDataImpl('sint32') as sint32;\n\nexport type sint32x2 = TgpuVertexFormatData<'sint32x2'>;\nexport const sint32x2 = new TgpuVertexFormatDataImpl('sint32x2') as sint32x2;\n\nexport type sint32x3 = TgpuVertexFormatData<'sint32x3'>;\nexport const sint32x3 = new TgpuVertexFormatDataImpl('sint32x3') as sint32x3;\n\nexport type sint32x4 = TgpuVertexFormatData<'sint32x4'>;\nexport const sint32x4 = new TgpuVertexFormatDataImpl('sint32x4') as sint32x4;\n\nexport type unorm10_10_10_2 = TgpuVertexFormatData<'unorm10-10-10-2'>;\nexport const unorm10_10_10_2 = new TgpuVertexFormatDataImpl(\n 'unorm10-10-10-2',\n) as unorm10_10_10_2;\n\nexport type unorm8x4_bgra = TgpuVertexFormatData<'unorm8x4-bgra'>;\nexport const unorm8x4_bgra = new TgpuVertexFormatDataImpl(\n 'unorm8x4-bgra',\n) as unorm8x4_bgra;\n\nexport type PackedData =\n | uint8\n | uint8x2\n | uint8x4\n | sint8\n | sint8x2\n | sint8x4\n | unorm8\n | unorm8x2\n | unorm8x4\n | snorm8\n | snorm8x2\n | snorm8x4\n | uint16\n | uint16x2\n | uint16x4\n | sint16\n | sint16x2\n | sint16x4\n | unorm16\n | unorm16x2\n | unorm16x4\n | snorm16\n | snorm16x2\n | snorm16x4\n | float16\n | float16x2\n | float16x4\n | float32\n | float32x2\n | float32x3\n | float32x4\n | uint32\n | uint32x2\n | uint32x3\n | uint32x4\n | sint32\n | sint32x2\n | sint32x3\n | sint32x4\n | unorm10_10_10_2\n | unorm8x4_bgra;\n\nexport function isPackedData(\n value: unknown,\n): value is PackedData {\n return (value as PackedData)?.[$internal] &&\n packedFormats.has(\n (value as PackedData)?.type,\n );\n}\n","import {\n type AnyData,\n getCustomAlignment,\n isDisarray,\n isLooseDecorated,\n isUnstruct,\n} from './dataTypes.ts';\nimport { packedFormats } from './vertexFormatData.ts';\nimport {\n type BaseData,\n isDecorated,\n isWgslArray,\n isWgslStruct,\n} from './wgslTypes.ts';\n\nconst knownAlignmentMap: Record<string, number> = {\n f32: 4,\n f16: 2,\n i32: 4,\n u32: 4,\n u16: 2,\n vec2f: 8,\n vec2h: 4,\n vec2i: 8,\n vec2u: 8,\n vec3f: 16,\n vec3h: 8,\n vec3i: 16,\n vec3u: 16,\n vec4f: 16,\n vec4h: 8,\n vec4i: 16,\n vec4u: 16,\n mat2x2f: 8,\n mat3x3f: 16,\n mat4x4f: 16,\n atomic: 4,\n};\n\nfunction computeAlignment(data: object): number {\n const dataType = (data as BaseData)?.type;\n const knownAlignment = knownAlignmentMap[dataType];\n if (knownAlignment !== undefined) {\n return knownAlignment;\n }\n\n if (isWgslStruct(data)) {\n return Object.values(data.propTypes as Record<string, BaseData>)\n .map(alignmentOf)\n .reduce((a, b) => (a > b ? a : b));\n }\n\n if (isWgslArray(data)) {\n return alignmentOf(data.elementType);\n }\n\n if (isUnstruct(data)) {\n // A loose struct is aligned to its first property.\n const firstProp =\n Object.values(data.propTypes as Record<string, BaseData>)[0];\n return firstProp ? (getCustomAlignment(firstProp) ?? 1) : 1;\n }\n\n if (isDisarray(data)) {\n return getCustomAlignment(data.elementType) ?? 1;\n }\n\n if (isDecorated(data) || isLooseDecorated(data)) {\n return getCustomAlignment(data) ?? alignmentOf(data.inner);\n }\n\n if (packedFormats.has(dataType)) {\n return 1;\n }\n\n throw new Error(\n `Cannot determine alignment of data: ${JSON.stringify(data)}`,\n );\n}\n\nfunction computeCustomAlignment(data: BaseData): number {\n if (isUnstruct(data)) {\n // A loose struct is aligned to its first property.\n const firstProp =\n Object.values(data.propTypes as Record<string, BaseData>)[0];\n return firstProp ? customAlignmentOf(firstProp) : 1;\n }\n\n if (isDisarray(data)) {\n return customAlignmentOf(data.elementType);\n }\n\n if (isLooseDecorated(data)) {\n return getCustomAlignment(data) ?? customAlignmentOf(data.inner);\n }\n\n return getCustomAlignment(data) ?? 1;\n}\n\n/**\n * Since alignments can be inferred from data types, they are not stored on them.\n * Instead, this weak map acts as an extended property of those data types.\n */\nconst cachedAlignments = new WeakMap<object, number>();\n\nconst cachedCustomAlignments = new WeakMap<object, number>();\n\nexport function alignmentOf(data: BaseData): number {\n let alignment = cachedAlignments.get(data);\n if (alignment === undefined) {\n alignment = computeAlignment(data);\n cachedAlignments.set(data, alignment);\n }\n\n return alignment;\n}\n\nexport function customAlignmentOf(data: BaseData): number {\n let alignment = cachedCustomAlignments.get(data);\n if (alignment === undefined) {\n alignment = computeCustomAlignment(data);\n cachedCustomAlignments.set(data, alignment);\n }\n\n return alignment;\n}\n\n/**\n * Returns the alignment (in bytes) of data represented by the `schema`.\n */\nexport function PUBLIC_alignmentOf(schema: AnyData): number {\n return alignmentOf(schema);\n}\n","import { roundUp } from '../mathUtils.ts';\nimport { alignmentOf, customAlignmentOf } from './alignmentOf.ts';\nimport type { AnyData, LooseTypeLiteral, Unstruct } from './dataTypes.ts';\nimport {\n getCustomSize,\n isDisarray,\n isLooseDecorated,\n isUnstruct,\n} from './dataTypes.ts';\nimport type { BaseData, WgslStruct, WgslTypeLiteral } from './wgslTypes.ts';\nimport { isDecorated, isWgslArray, isWgslStruct } from './wgslTypes.ts';\n\nconst knownSizesMap: Record<string, number> = {\n f32: 4,\n f16: 2,\n i32: 4,\n u32: 4,\n u16: 2,\n vec2f: 8,\n vec2h: 4,\n vec2i: 8,\n vec2u: 8,\n vec3f: 12,\n vec3h: 6,\n vec3i: 12,\n vec3u: 12,\n vec4f: 16,\n vec4h: 8,\n vec4i: 16,\n vec4u: 16,\n mat2x2f: 16,\n mat3x3f: 48,\n mat4x4f: 64,\n uint8: 1,\n uint8x2: 2,\n uint8x4: 4,\n sint8: 1,\n sint8x2: 2,\n sint8x4: 4,\n unorm8: 1,\n unorm8x2: 2,\n unorm8x4: 4,\n snorm8: 1,\n snorm8x2: 2,\n snorm8x4: 4,\n uint16: 2,\n uint16x2: 4,\n uint16x4: 8,\n sint16: 2,\n sint16x2: 4,\n sint16x4: 8,\n unorm16: 2,\n unorm16x2: 4,\n unorm16x4: 8,\n snorm16: 2,\n snorm16x2: 4,\n snorm16x4: 8,\n float16: 2,\n float16x2: 4,\n float16x4: 8,\n float32: 4,\n float32x2: 8,\n float32x3: 12,\n float32x4: 16,\n uint32: 4,\n uint32x2: 8,\n uint32x3: 12,\n uint32x4: 16,\n sint32: 4,\n sint32x2: 8,\n sint32x3: 12,\n sint32x4: 16,\n 'unorm10-10-10-2': 4,\n 'unorm8x4-bgra': 4,\n atomic: 4,\n} satisfies Partial<Record<WgslTypeLiteral | LooseTypeLiteral, number>>;\n\nfunction sizeOfStruct(struct: WgslStruct) {\n let size = 0;\n const propTypes = struct.propTypes as Record<string, BaseData>;\n for (const property of Object.values(propTypes)) {\n if (Number.isNaN(size)) {\n throw new Error('Only the last property of a struct can be unbounded');\n }\n\n size = roundUp(size, alignmentOf(property));\n size += sizeOf(property);\n\n if (Number.isNaN(size) && property.type !== 'array') {\n throw new Error('Cannot nest unbounded struct within another struct');\n }\n }\n\n return roundUp(size, alignmentOf(struct));\n}\n\nfunction sizeOfUnstruct(data: Unstruct) {\n let size = 0;\n\n const propTypes = data.propTypes as Record<string, BaseData>;\n for (const property of Object.values(propTypes)) {\n const alignment = customAlignmentOf(property);\n size = roundUp(size, alignment);\n size += sizeOf(property);\n }\n\n return size;\n}\n\nfunction computeSize(data: object): number {\n const knownSize = knownSizesMap[(data as BaseData)?.type];\n\n if (knownSize !== undefined) {\n return knownSize;\n }\n\n if (isWgslStruct(data)) {\n return sizeOfStruct(data);\n }\n\n if (isUnstruct(data)) {\n return sizeOfUnstruct(data);\n }\n\n if (isWgslArray(data)) {\n if (data.elementCount === 0) {\n return Number.NaN;\n }\n\n const alignment = alignmentOf(data.elementType);\n const stride = roundUp(sizeOf(data.elementType), alignment);\n return stride * data.elementCount;\n }\n\n if (isDisarray(data)) {\n const alignment = customAlignmentOf(data.elementType);\n const stride = roundUp(sizeOf(data.elementType), alignment);\n return stride * data.elementCount;\n }\n\n if (isDecorated(data) || isLooseDecorated(data)) {\n return getCustomSize(data) ?? sizeOf(data.inner);\n }\n\n throw new Error(`Cannot determine size of data: ${data}`);\n}\n\n/**\n * Since sizes can be inferred from data types, they are not stored on them.\n * Instead, this weak map acts as an extended property of those data types.\n */\nconst cachedSizes = new WeakMap<BaseData, number>();\n\nexport function sizeOf(schema: BaseData): number {\n let size = cachedSizes.get(schema);\n\n if (size === undefined) {\n size = computeSize(schema);\n cachedSizes.set(schema, size);\n }\n\n return size;\n}\n\n/**\n * Returns the size (in bytes) of data represented by the `schema`.\n */\nexport function PUBLIC_sizeOf(schema: AnyData): number {\n return sizeOf(schema);\n}\n","/**\n * A wrapper for `schema(item)` call.\n * Throws an error if the schema is not callable.\n */\nexport function schemaCloneWrapper<T>(schema: unknown, item: T): T {\n try {\n return (schema as unknown as ((item: T) => T))(item);\n } catch {\n const maybeType = (schema as { type: string })?.type;\n throw new Error(\n `Schema of type ${\n maybeType ?? '<unknown>'\n } is not callable or was called with invalid arguments.`,\n );\n }\n}\n\n/**\n * A wrapper for `schema()` call.\n * Throws an error if the schema is not callable.\n */\nexport function schemaDefaultWrapper<T>(schema: unknown): T {\n try {\n return (schema as unknown as (() => T))();\n } catch {\n const maybeType = (schema as { type: string })?.type;\n throw new Error(\n `Schema of type ${maybeType ?? '<unknown>'} is not callable.`,\n );\n }\n}\n","import { $internal } from '../shared/symbols.ts';\nimport { sizeOf } from './sizeOf.ts';\nimport { schemaCloneWrapper, schemaDefaultWrapper } from './utils.ts';\nimport type { AnyWgslData, WgslArray } from './wgslTypes.ts';\n\n// ----------\n// Public API\n// ----------\n\n/**\n * Creates an array schema that can be used to construct gpu buffers.\n * Describes arrays with fixed-size length, storing elements of the same type.\n *\n * @example\n * const LENGTH = 3;\n * const array = d.arrayOf(d.u32, LENGTH);\n *\n * @param elementType The type of elements in the array.\n * @param elementCount The number of elements in the array.\n */\nexport function arrayOf<TElement extends AnyWgslData>(\n elementType: TElement,\n elementCount: number,\n): WgslArray<TElement> {\n // In the schema call, create and return a deep copy\n // by wrapping all the values in `elementType` schema calls.\n const arraySchema = (elements?: TElement[]) => {\n if (elements && elements.length !== elementCount) {\n throw new Error(\n `Array schema of ${elementCount} elements of type ${elementType.type} called with ${elements.length} arguments.`,\n );\n }\n\n return Array.from(\n { length: elementCount },\n (_, i) =>\n elements\n ? schemaCloneWrapper(elementType, elements[i])\n : schemaDefaultWrapper(elementType),\n );\n };\n Object.setPrototypeOf(arraySchema, WgslArrayImpl);\n\n if (Number.isNaN(sizeOf(elementType))) {\n throw new Error('Cannot nest runtime sized arrays.');\n }\n arraySchema.elementType = elementType;\n\n if (!Number.isInteger(elementCount) || elementCount < 0) {\n throw new Error(\n `Cannot create array schema with invalid element count: ${elementCount}.`,\n );\n }\n arraySchema.elementCount = elementCount;\n\n return arraySchema as unknown as WgslArray<TElement>;\n}\n\n// --------------\n// Implementation\n// --------------\n\nconst WgslArrayImpl = {\n [$internal]: true,\n type: 'array',\n\n toString(this: WgslArray): string {\n return `arrayOf(${this.elementType}, ${this.elementCount})`;\n },\n};\n","export type Default<T, TDefault> = unknown extends T ? TDefault\n : T extends undefined ? TDefault\n : T;\n\nexport type SwapNever<T, Replacement> = [T] extends [never] ? Replacement : T;\n\nexport type UnionToIntersection<U> =\n // biome-ignore lint/suspicious/noExplicitAny: <had to be done>\n (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I\n : never;\n\nexport type Prettify<T> =\n & {\n [K in keyof T]: T[K];\n }\n & {};\n\n/**\n * Removes properties from record type that extend `Prop`\n */\nexport type OmitProps<T extends Record<string, unknown>, Prop> = Pick<\n T,\n {\n [Key in keyof T]: T[Key] extends Prop ? never : Key;\n }[keyof T]\n>;\n\n/**\n * Removes properties from record type that equal `Prop`\n */\nexport type OmitPropsExact<T extends Record<string, unknown>, Prop> = Pick<\n T,\n {\n [Key in keyof T]: [T[Key], Prop] extends [Prop, T[Key]] ? never : Key;\n }[keyof T]\n>;\n\nexport type NullableToOptional<T> =\n & {\n // Props where the value extends `null` -> make them optional and remove null from the type\n [K in keyof T as T[K] extends null ? K : never]?: T[K];\n }\n & {\n // All other props remain unchanged\n [K in keyof T as T[K] extends null ? never : K]: T[K];\n };\n\n/**\n * The opposite of Readonly<T>\n */\nexport type Mutable<T> = {\n -readonly [P in keyof T]: T[P];\n};\n\n/**\n * Any typed array\n */\nexport type TypedArray =\n | Uint8Array\n | Uint16Array\n | Uint32Array\n | Int32Array\n | Float32Array\n | Float64Array;\n\nexport function assertExhaustive(x: never, location: string): never {\n throw new Error(`Failed to handle ${x} at ${location}`);\n}\n","import { arrayOf } from '../data/array.ts';\nimport {\n type AnyData,\n isDisarray,\n isUnstruct,\n UnknownData,\n} from '../data/dataTypes.ts';\nimport { isSnippet, snip, type Snippet } from '../data/snippet.ts';\nimport { mat2x2f, mat3x3f, mat4x4f } from '../data/matrix.ts';\nimport {\n abstractFloat,\n abstractInt,\n bool,\n f16,\n f32,\n i32,\n u32,\n} from '../data/numeric.ts';\nimport {\n vec2b,\n vec2f,\n vec2h,\n vec2i,\n vec2u,\n vec3b,\n vec3f,\n vec3h,\n vec3i,\n vec3u,\n vec4b,\n vec4f,\n vec4h,\n vec4i,\n vec4u,\n vecTypeToPrimitive,\n} from '../data/vector.ts';\nimport {\n type AnyWgslData,\n type F16,\n type F32,\n hasInternalDataType,\n type I32,\n isMat,\n isMatInstance,\n isVec,\n isVecInstance,\n isWgslArray,\n isWgslStruct,\n type U32,\n type WgslStruct,\n} from '../data/wgslTypes.ts';\nimport { invariant, WgslTypeError } from '../errors.ts';\nimport { getResolutionCtx } from '../execMode.ts';\nimport { DEV } from '../shared/env.ts';\nimport { $wgslDataType } from '../shared/symbols.ts';\nimport { assertExhaustive } from '../shared/utilityTypes.ts';\nimport { isNumericSchema } from '../std/numeric.ts';\nimport type { ResolutionCtx } from '../types.ts';\nimport { undecorate } from '../data/decorateUtils.ts';\n\ntype SwizzleableType = 'f' | 'h' | 'i' | 'u' | 'b';\ntype SwizzleLength = 1 | 2 | 3 | 4;\n\nconst swizzleLenToType: Record<\n SwizzleableType,\n Record<SwizzleLength, AnyData>\n> = {\n f: {\n 1: f32,\n 2: vec2f,\n 3: vec3f,\n 4: vec4f,\n },\n h: {\n 1: f16,\n 2: vec2h,\n 3: vec3h,\n 4: vec4h,\n },\n i: {\n 1: i32,\n 2: vec2i,\n 3: vec3i,\n 4: vec4i,\n },\n u: {\n 1: u32,\n 2: vec2u,\n 3: vec3u,\n 4: vec4u,\n },\n b: {\n 1: bool,\n 2: vec2b,\n 3: vec3b,\n 4: vec4b,\n },\n} as const;\n\nconst kindToSchema = {\n vec2f: vec2f,\n vec2h: vec2h,\n vec2i: vec2i,\n vec2u: vec2u,\n 'vec2<bool>': vec2b,\n vec3f: vec3f,\n vec3h: vec3h,\n vec3i: vec3i,\n vec3u: vec3u,\n 'vec3<bool>': vec3b,\n vec4f: vec4f,\n vec4h: vec4h,\n vec4i: vec4i,\n vec4u: vec4u,\n 'vec4<bool>': vec4b,\n mat2x2f: mat2x2f,\n mat3x3f: mat3x3f,\n mat4x4f: mat4x4f,\n} as const;\n\nconst indexableTypeToResult = {\n vec2f: f32,\n vec2h: f16,\n vec2i: i32,\n vec2u: u32,\n 'vec2<bool>': bool,\n vec3f: f32,\n vec3h: f16,\n vec3i: i32,\n vec3u: u32,\n 'vec3<bool>': bool,\n vec4f: f32,\n vec4h: f16,\n vec4i: i32,\n vec4u: u32,\n 'vec4<bool>': bool,\n mat2x2f: vec2f,\n mat3x3f: vec3f,\n mat4x4f: vec4f,\n} as const;\n\nexport function getTypeForPropAccess(\n targetType: AnyData,\n propName: string,\n): AnyData | UnknownData {\n if (isWgslStruct(targetType) || isUnstruct(targetType)) {\n return targetType.propTypes[propName] as AnyData ?? UnknownData;\n }\n\n if (targetType === bool || isNumericSchema(targetType)) {\n // No props to be accessed here\n return UnknownData;\n }\n\n const propLength = propName.length;\n if (\n isVec(targetType) &&\n propLength >= 1 &&\n propLength <= 4\n ) {\n const swizzleTypeChar = targetType.type.includes('bool')\n ? 'b'\n : (targetType.type[4] as SwizzleableType);\n const swizzleType =\n swizzleLenToType[swizzleTypeChar][propLength as SwizzleLength];\n if (swizzleType) {\n return swizzleType;\n }\n }\n\n return UnknownData;\n}\n\nexport function getTypeForIndexAccess(\n dataType: AnyData,\n): AnyData | UnknownData {\n // array\n if (isWgslArray(dataType) || isDisarray(dataType)) {\n return dataType.elementType as AnyData;\n }\n\n // vector or matrix\n if (dataType.type in indexableTypeToResult) {\n return indexableTypeToResult[\n dataType.type as keyof typeof indexableTypeToResult\n ];\n }\n\n return UnknownData;\n}\n\nexport function numericLiteralToSnippet(value: string): Snippet | undefined {\n // Hex literals\n if (/^0x[0-9a-f]+$/i.test(value)) {\n return snip(value, abstractInt);\n }\n\n // Binary literals\n if (/^0b[01]+$/i.test(value)) {\n return snip(`${Number.parseInt(value.slice(2), 2)}`, abstractInt);\n }\n\n // Floating point literals\n if (/^-?(?:\\d+\\.\\d*|\\d*\\.\\d+)$/i.test(value)) {\n return snip(value, abstractFloat);\n }\n\n // Floating point literals with scientific notation\n if (/^-?\\d+(?:\\.\\d+)?e-?\\d+$/i.test(value)) {\n return snip(value, abstractFloat);\n }\n\n // Integer literals\n if (/^-?\\d+$/i.test(value)) {\n return snip(value, abstractInt);\n }\n\n return undefined;\n}\n\ntype ConversionAction = 'ref' | 'deref' | 'cast' | 'none';\n\ntype ConversionRankInfo =\n | { rank: number; action: 'cast'; targetType: AnyData }\n | { rank: number; action: Exclude<ConversionAction, 'cast'> };\n\nconst INFINITE_RANK: ConversionRankInfo = {\n rank: Number.POSITIVE_INFINITY,\n action: 'none',\n};\n\nfunction getVectorComponent(type: AnyData): AnyData | undefined {\n return isVec(type) ? vecTypeToPrimitive[type.type] : undefined;\n}\n\nfunction getAutoConversionRank(\n src: AnyData,\n dest: AnyData,\n): ConversionRankInfo {\n const trueSrc = undecorate(src);\n const trueDst = undecorate(dest);\n\n if (trueSrc.type === trueDst.type) {\n return { rank: 0, action: 'none' };\n }\n\n if (trueSrc.type === 'abstractFloat') {\n if (trueDst.type === 'f32') return { rank: 1, action: 'none' };\n if (trueDst.type === 'f16') return { rank: 2, action: 'none' };\n }\n\n if (trueSrc.type === 'abstractInt') {\n if (trueDst.type === 'i32') return { rank: 3, action: 'none' };\n if (trueDst.type === 'u32') return { rank: 4, action: 'none' };\n if (trueDst.type === 'abstractFloat') return { rank: 5, action: 'none' };\n if (trueDst.type === 'f32') return { rank: 6, action: 'none' };\n if (trueDst.type === 'f16') return { rank: 7, action: 'none' };\n }\n\n if (isVec(trueSrc) && isVec(trueDst)) {\n const compSrc = getVectorComponent(trueSrc);\n const compDest = getVectorComponent(trueDst);\n if (compSrc && compDest) {\n return getAutoConversionRank(compSrc, compDest);\n }\n }\n\n if (isMat(trueSrc) && isMat(trueDst)) {\n // Matrix conversion rank depends only on component type (always f32 for now)\n return { rank: 0, action: 'none' };\n }\n\n return INFINITE_RANK;\n}\n\nfunction getImplicitConversionRank(\n src: AnyData,\n dest: AnyData,\n): ConversionRankInfo {\n const trueSrc = undecorate(src);\n const trueDst = undecorate(dest);\n\n if (\n trueSrc.type === 'ptr' &&\n getAutoConversionRank(trueSrc.inner as AnyData, trueDst).rank <\n Number.POSITIVE_INFINITY\n ) {\n return { rank: 0, action: 'deref' };\n }\n\n if (\n trueDst.type === 'ptr' &&\n getAutoConversionRank(trueSrc, trueDst.inner as AnyData).rank <\n Number.POSITIVE_INFINITY\n ) {\n return { rank: 1, action: 'ref' };\n }\n\n const primitivePreference = {\n f32: 0,\n f16: 1,\n i32: 2,\n u32: 3,\n bool: 4,\n } as const;\n type PrimitiveType = keyof typeof primitivePreference;\n\n if (\n trueSrc.type in primitivePreference &&\n trueDst.type in primitivePreference\n ) {\n const srcType = trueSrc.type as PrimitiveType;\n const destType = trueDst.type as PrimitiveType;\n\n if (srcType !== destType) {\n const srcPref = primitivePreference[srcType];\n const destPref = primitivePreference[destType];\n\n const rank = destPref < srcPref ? 10 : 20;\n\n return { rank: rank, action: 'cast', targetType: trueDst };\n }\n }\n\n return INFINITE_RANK;\n}\n\nfunction getConversionRank(\n src: AnyData,\n dest: AnyData,\n allowImplicit: boolean,\n): ConversionRankInfo {\n const autoRank = getAutoConversionRank(src, dest);\n if (autoRank.rank < Number.POSITIVE_INFINITY) {\n return autoRank;\n }\n if (allowImplicit) {\n return getImplicitConversionRank(src, dest);\n }\n return INFINITE_RANK;\n}\n\nexport type ConversionResultAction = {\n sourceIndex: number;\n action: ConversionAction;\n targetType?: U32 | F32 | I32 | F16;\n};\n\nexport type ConversionResult = {\n targetType: AnyData;\n actions: ConversionResultAction[];\n hasImplicitConversions?: boolean;\n};\n\nfunction findBestType(\n types: AnyData[],\n uniqueTypes: AnyData[],\n allowImplicit: boolean,\n): ConversionResult | undefined {\n let bestType: AnyData | undefined;\n let minSum = Number.POSITIVE_INFINITY;\n const conversionDetails = new Map<AnyData, ConversionRankInfo[]>();\n\n for (const targetType of uniqueTypes) {\n let currentSum = 0;\n const currentDetails: ConversionRankInfo[] = [];\n let possible = true;\n\n for (const sourceType of types) {\n const conversion = getConversionRank(\n sourceType,\n targetType,\n allowImplicit,\n );\n if (conversion.rank === Number.POSITIVE_INFINITY) {\n possible = false;\n break;\n }\n currentSum += conversion.rank;\n currentDetails.push(conversion);\n }\n\n if (possible && currentSum < minSum) {\n minSum = currentSum;\n bestType = targetType;\n conversionDetails.set(bestType, currentDetails);\n }\n }\n\n if (!bestType) {\n return undefined;\n }\n\n const bestDetails = conversionDetails.get(bestType) as ConversionRankInfo[];\n const actions: ConversionResultAction[] = bestDetails.map(\n (detail, index) => ({\n sourceIndex: index,\n action: detail.action,\n ...(detail.action === 'cast' && {\n targetType: detail.targetType as U32 | F32 | I32 | F16,\n }),\n }),\n );\n\n const hasCasts = actions.some((action) => action.action === 'cast');\n\n return { targetType: bestType, actions, hasImplicitConversions: hasCasts };\n}\n\nexport function concretize(type: AnyWgslData): AnyWgslData {\n if (type.type === 'abstractFloat') {\n return f32;\n }\n\n if (type.type === 'abstractInt') {\n return i32;\n }\n\n return type;\n}\n\nexport function getBestConversion(\n types: AnyData[],\n targetTypes?: AnyData[],\n): ConversionResult | undefined {\n if (types.length === 0) return undefined;\n\n const uniqueTypes = [...new Set(types.map(undecorate))];\n const uniqueTargetTypes = targetTypes\n ? [...new Set(targetTypes.map(undecorate))]\n : uniqueTypes;\n\n const explicitResult = findBestType(types, uniqueTargetTypes, false);\n if (explicitResult) {\n return explicitResult;\n }\n\n const implicitResult = findBestType(types, uniqueTargetTypes, true);\n if (implicitResult) {\n implicitResult.hasImplicitConversions = implicitResult.actions.some(\n (action) => action.action === 'cast',\n );\n return implicitResult;\n }\n\n return undefined;\n}\n\nexport function convertType(\n sourceType: AnyData,\n targetType: AnyData,\n allowImplicit = true,\n): ConversionResult | undefined {\n const conversion = getConversionRank(sourceType, targetType, allowImplicit);\n\n if (conversion.rank < Number.POSITIVE_INFINITY) {\n const actionDetail: ConversionResultAction = {\n sourceIndex: 0,\n action: conversion.action,\n };\n if (conversion.action === 'cast') {\n actionDetail.targetType = conversion.targetType as U32 | F32 | I32 | F16;\n }\n return {\n targetType: undecorate(targetType),\n actions: [actionDetail],\n hasImplicitConversions: conversion.action === 'cast',\n };\n }\n\n return undefined;\n}\n\nexport type GenerationCtx = ResolutionCtx & {\n readonly pre: string;\n /**\n * Used by `generateTypedExpression` to signal downstream\n * expression resolution what type is expected of them.\n *\n * It is used exclusively for inferring the types of structs and arrays.\n * It is modified exclusively by `generateTypedExpression` function.\n */\n expectedType: AnyData | undefined;\n readonly topFunctionReturnType: AnyData;\n indent(): string;\n dedent(): string;\n withResetIndentLevel<T>(callback: () => T): T;\n pushBlockScope(): void;\n popBlockScope(): void;\n getById(id: string): Snippet | null;\n defineVariable(id: string, dataType: AnyWgslData | UnknownData): Snippet;\n};\n\nfunction applyActionToSnippet(\n ctx: GenerationCtx,\n value: Snippet,\n action: ConversionResultAction,\n targetType: AnyData,\n): Snippet {\n if (action.action === 'none') {\n return snip(value.value, targetType);\n }\n\n const resolvedValue = ctx.resolve(value.value);\n\n switch (action.action) {\n case 'ref':\n return snip(`&${resolvedValue}`, targetType);\n case 'deref':\n return snip(`*${resolvedValue}`, targetType);\n case 'cast': {\n return snip(`${ctx.resolve(targetType)}(${resolvedValue})`, targetType);\n }\n default: {\n assertExhaustive(action.action, 'applyActionToSnippet');\n }\n }\n}\n\nexport type ConvertToCommonTypeOptions = {\n ctx: GenerationCtx;\n values: Snippet[];\n restrictTo?: AnyData[] | undefined;\n concretizeTypes?: boolean | undefined;\n verbose?: boolean | undefined;\n};\n\nexport function convertToCommonType({\n ctx,\n values,\n restrictTo,\n concretizeTypes = false,\n verbose = true,\n}: ConvertToCommonTypeOptions): Snippet[] | undefined {\n const types = values.map((value) =>\n concretizeTypes ? concretize(value.dataType as AnyWgslData) : value.dataType\n );\n\n if (types.some((type) => type === UnknownData)) {\n return undefined;\n }\n\n if (DEV && verbose && Array.isArray(restrictTo) && restrictTo.length === 0) {\n console.warn(\n 'convertToCommonType was called with an empty restrictTo array, which prevents any conversions from being made. If you intend to allow all conversions, pass undefined instead. If this was intended call the function conditionally since the result will always be undefined.',\n );\n }\n\n const conversion = getBestConversion(types as AnyData[], restrictTo);\n if (!conversion) {\n return undefined;\n }\n\n if (DEV && verbose && conversion.hasImplicitConversions) {\n console.warn(\n `Implicit conversions from [\\n${\n values\n .map((v) => ` ${v.value}: ${v.dataType.type}`)\n .join(\n ',\\n',\n )\n }\\n] to ${conversion.targetType.type} are supported, but not recommended.\nConsider using explicit conversions instead.`,\n );\n }\n\n return values.map((value, index) => {\n const action = conversion.actions[index];\n invariant(action, 'Action should not be undefined');\n return applyActionToSnippet(ctx, value, action, conversion.targetType);\n });\n}\n\nexport function tryConvertSnippet(\n ctx: GenerationCtx,\n value: Snippet,\n targetDataType: AnyData,\n): Snippet {\n if (targetDataType === value.dataType) {\n return value;\n }\n\n if (targetDataType.type === 'void') {\n throw new WgslTypeError(\n `Cannot convert value of type '${value.dataType.type}' to type 'void'`,\n );\n }\n\n const converted = convertToCommonType({\n ctx,\n values: [value],\n restrictTo: [targetDataType],\n });\n\n if (!converted) {\n throw new WgslTypeError(\n `Cannot convert value of type '${value.dataType.type}' to type '${targetDataType.type}'`,\n );\n }\n\n return converted[0] as Snippet;\n}\n\nexport function convertStructValues(\n ctx: GenerationCtx,\n structType: WgslStruct,\n values: Record<string, Snippet>,\n): Snippet[] {\n const propKeys = Object.keys(structType.propTypes);\n\n return propKeys.map((key) => {\n const val = values[key];\n if (!val) {\n throw new Error(`Missing property ${key}`);\n }\n\n const targetType = structType.propTypes[key];\n const converted = convertToCommonType({\n ctx,\n values: [val],\n restrictTo: [targetType as AnyData],\n });\n return converted?.[0] ?? val;\n });\n}\n\nexport function coerceToSnippet(value: unknown): Snippet {\n if (isSnippet(value)) {\n // Already a snippet\n return value;\n }\n\n if (hasInternalDataType(value)) {\n // The value knows better about what type it is\n return snip(value, value[$wgslDataType] as AnyData);\n }\n\n if (isVecInstance(value) || isMatInstance(value)) {\n return snip(value, kindToSchema[value.kind]);\n }\n\n if (Array.isArray(value)) {\n const coerced = value.map(coerceToSnippet).filter(Boolean);\n const context = getResolutionCtx() as GenerationCtx | undefined;\n if (!context) {\n throw new Error('Tried to coerce array without a context');\n }\n\n const converted = convertToCommonType({\n ctx: context,\n values: coerced as Snippet[],\n });\n const commonType = getBestConversion(\n coerced.map((v) => v.dataType as AnyData),\n )?.targetType as AnyWgslData | undefined;\n\n if (!converted || !commonType) {\n return snip(value, UnknownData);\n }\n\n return snip(\n converted.map((v) => v.value).join(', '),\n arrayOf(concretize(commonType), value.length),\n );\n }\n\n if (\n typeof value === 'string' || typeof value === 'function' ||\n typeof value === 'object' || typeof value === 'symbol' ||\n typeof value === 'undefined' || value === null\n ) {\n // Nothing representable in WGSL as-is, so unknown\n return snip(value, UnknownData);\n }\n\n if (typeof value === 'number' || typeof value === 'bigint') {\n return snip(\n value,\n numericLiteralToSnippet(String(value))?.dataType ?? UnknownData,\n );\n }\n\n if (typeof value === 'boolean') {\n return snip(value, bool);\n }\n\n return snip(value, UnknownData);\n}\n","import { getName, setName } from '../shared/meta.ts';\nimport { $internal } from '../shared/symbols.ts';\nimport { schemaCloneWrapper, schemaDefaultWrapper } from './utils.ts';\nimport type { AnyWgslData, WgslStruct } from './wgslTypes.ts';\n\n// ----------\n// Public API\n// ----------\n\n/**\n * Creates a struct schema that can be used to construct GPU buffers.\n * Ensures proper alignment and padding of properties (as opposed to a `d.unstruct` schema).\n * The order of members matches the passed in properties object.\n *\n * @example\n * const CircleStruct = d.struct({ radius: d.f32, pos: d.vec3f });\n *\n * @param props Record with `string` keys and `TgpuData` values,\n * each entry describing one struct member.\n */\nexport function struct<TProps extends Record<string, AnyWgslData>>(\n props: TProps,\n): WgslStruct<TProps> {\n // In the schema call, create and return a deep copy\n // by wrapping all the values in corresponding schema calls.\n const structSchema = (instanceProps?: TProps) =>\n Object.fromEntries(\n Object.entries(props).map(([key, schema]) => [\n key,\n instanceProps\n ? schemaCloneWrapper(schema, instanceProps[key])\n : schemaDefaultWrapper(schema),\n ]),\n );\n Object.setPrototypeOf(structSchema, WgslStructImpl);\n structSchema.propTypes = props;\n\n return structSchema as WgslStruct<TProps>;\n}\n\n// --------------\n// Implementation\n// --------------\n\nconst WgslStructImpl = {\n [$internal]: true,\n type: 'struct',\n\n $name(label: string) {\n setName(this, label);\n return this;\n },\n\n toString(): string {\n return `struct:${getName(this) ?? '<unnamed>'}`;\n },\n};\n","import type {\n Infer,\n InferPartial,\n IsValidVertexSchema,\n} from '../shared/repr.ts';\nimport { $internal } from '../shared/symbols.ts';\nimport type {\n $invalidSchemaReason,\n $repr,\n $reprPartial,\n $validVertexSchema,\n} from '../shared/symbols.ts';\nimport type { AnyData, Disarray } from './dataTypes.ts';\n\n// ----------\n// Public API\n// ----------\n\n/**\n * Creates an array schema that can be used to construct vertex buffers.\n * Describes arrays with fixed-size length, storing elements of the same type.\n *\n * Elements in the schema are not aligned in respect to their `byteAlignment`,\n * unless they are explicitly decorated with the custom align attribute\n * via `d.align` function.\n *\n * @example\n * const disarray = d.disarrayOf(d.vec3f, 3); // packed array of vec3f\n *\n * @example\n * const disarray = d.disarrayOf(d.align(16, d.vec3f), 3);\n *\n * @param elementType The type of elements in the array.\n * @param count The number of elements in the array.\n */\nexport function disarrayOf<TElement extends AnyData>(\n elementType: TElement,\n count: number,\n): Disarray<TElement> {\n return new DisarrayImpl(elementType, count);\n}\n\n// --------------\n// Implementation\n// --------------\n\nclass DisarrayImpl<TElement extends AnyData> implements Disarray<TElement> {\n public readonly [$internal] = true;\n public readonly type = 'disarray';\n\n // Type-tokens, not available at runtime\n declare readonly [$repr]: Infer<TElement>[];\n declare readonly [$reprPartial]: {\n idx: number;\n value: InferPartial<TElement>;\n }[];\n declare readonly [$validVertexSchema]: IsValidVertexSchema<TElement>;\n declare readonly [$invalidSchemaReason]:\n Disarray[typeof $invalidSchemaReason];\n // ---\n\n constructor(\n public readonly elementType: TElement,\n public readonly elementCount: number,\n ) {\n if (!Number.isInteger(elementCount) || elementCount < 0) {\n throw new Error(\n `Cannot create disarray schema with invalid element count: ${elementCount}.`,\n );\n }\n }\n}\n","import { getName, setName } from '../shared/meta.ts';\nimport { $internal } from '../shared/symbols.ts';\nimport type { Unstruct } from './dataTypes.ts';\nimport type { BaseData } from './wgslTypes.ts';\n\n// ----------\n// Public API\n// ----------\n\n/**\n * Creates a loose struct schema that can be used to construct vertex buffers.\n * Describes structs with members of both loose and non-loose types.\n *\n * The order of members matches the passed in properties object.\n * Members are not aligned in respect to their `byteAlignment`,\n * unless they are explicitly decorated with the custom align attribute\n * via `d.align` function.\n *\n * @example\n * const CircleStruct = d.unstruct({ radius: d.f32, pos: d.vec3f }); // packed struct with no padding\n *\n * @example\n * const CircleStruct = d.unstruct({ radius: d.f32, pos: d.align(16, d.vec3f) });\n *\n * @param properties Record with `string` keys and `TgpuData` or `TgpuLooseData` values,\n * each entry describing one struct member.\n */\nexport function unstruct<TProps extends Record<string, BaseData>>(\n properties: TProps,\n): Unstruct<TProps> {\n const unstruct = <T>(props: T) => props;\n Object.setPrototypeOf(unstruct, UnstructImpl);\n unstruct.propTypes = properties;\n\n return unstruct as unknown as Unstruct<TProps>;\n}\n\n// --------------\n// Implementation\n// --------------\n\nconst UnstructImpl = {\n [$internal]: true,\n type: 'unstruct',\n\n $name(label: string) {\n setName(this, label);\n return this;\n },\n\n toString(): string {\n return `unstruct:${getName(this) ?? '<unnamed>'}`;\n },\n};\n","import type { Infer, MemIdentity } from '../shared/repr.ts';\nimport { $internal } from '../shared/symbols.ts';\nimport type {\n $gpuRepr,\n $memIdent,\n $repr,\n $validStorageSchema,\n $validUniformSchema,\n $validVertexSchema,\n} from '../shared/symbols.ts';\nimport type { Atomic, atomicI32, atomicU32, I32, U32 } from './wgslTypes.ts';\n\n// ----------\n// Public API\n// ----------\n\n/**\n * Marks a concrete integer scalar type schema (u32 or i32) as a WGSL atomic.\n *\n * @example\n * const atomicU32 = d.atomic(d.u32);\n * const atomicI32 = d.atomic(d.i32);\n *\n * @param data Underlying type schema.\n */\nexport function atomic<TSchema extends U32 | I32>(\n data: TSchema,\n): Atomic<TSchema> {\n return new AtomicImpl(data);\n}\n\n// --------------\n// Implementation\n// --------------\n\nclass AtomicImpl<TSchema extends U32 | I32> implements Atomic<TSchema> {\n public readonly [$internal] = true;\n public readonly type = 'atomic';\n\n // Type-tokens, not available at runtime\n declare readonly [$repr]: Infer<TSchema>;\n declare readonly [$memIdent]: MemIdentity<TSchema>;\n declare readonly [$gpuRepr]: TSchema extends U32 ? atomicU32 : atomicI32;\n declare readonly [$validStorageSchema]: true;\n declare readonly [$validUniformSchema]: true;\n declare readonly [$validVertexSchema]: true;\n // ---\n\n constructor(public readonly inner: TSchema) {}\n}\n","import type {\n Infer,\n InferGPU,\n InferPartial,\n IsValidStorageSchema,\n IsValidUniformSchema,\n IsValidVertexSchema,\n MemIdentity,\n} from '../shared/repr.ts';\nimport { $internal } from '../shared/symbols.ts';\nimport type {\n $gpuRepr,\n $invalidSchemaReason,\n $memIdent,\n $repr,\n $reprPartial,\n $validStorageSchema,\n $validUniformSchema,\n $validVertexSchema,\n} from '../shared/symbols.ts';\nimport { alignmentOf } from './alignmentOf.ts';\nimport {\n type AnyData,\n type AnyLooseData,\n isLooseData,\n isLooseDecorated,\n type LooseDecorated,\n type LooseTypeLiteral,\n} from './dataTypes.ts';\nimport type { Undecorate } from './decorateUtils.ts';\nimport { sizeOf } from './sizeOf.ts';\nimport {\n type Align,\n type AnyWgslData,\n type BaseData,\n type Builtin,\n type Decorated,\n type FlatInterpolatableData,\n type FlatInterpolationType,\n type Interpolate,\n type InterpolationType,\n type Invariant,\n isAlignAttrib,\n isBuiltinAttrib,\n isDecorated,\n isSizeAttrib,\n isWgslData,\n type Location,\n type PerspectiveOrLinearInterpolatableData,\n type PerspectiveOrLinearInterpolationType,\n type Size,\n type Vec4f,\n type WgslTypeLiteral,\n} from './wgslTypes.ts';\n\n// ----------\n// Public API\n// ----------\n\nexport const builtinNames = [\n 'vertex_index',\n 'instance_index',\n 'position',\n 'clip_distances',\n 'front_facing',\n 'frag_depth',\n 'sample_index',\n 'sample_mask',\n 'fragment',\n 'local_invocation_id',\n 'local_invocation_index',\n 'global_invocation_id',\n 'workgroup_id',\n 'num_workgroups',\n 'subgroup_invocation_id',\n 'subgroup_size',\n] as const;\n\nexport type BuiltinName = (typeof builtinNames)[number];\n\nexport type AnyAttribute<\n AllowedBuiltins extends Builtin<BuiltinName> = Builtin<BuiltinName>,\n> =\n | Align<number>\n | Size<number>\n | Location<number>\n | Interpolate<InterpolationType>\n | Invariant\n | AllowedBuiltins;\n\nexport type ExtractAttributes<T> = T extends {\n readonly attribs: unknown[];\n} ? T['attribs']\n : [];\n\n/**\n * Decorates a data-type `TData` with an attribute `TAttrib`.\n *\n * - if `TData` is loose\n * - if `TData` is already `LooseDecorated`\n * - Prepend `TAttrib` to the existing attribute tuple.\n * - else\n * - Wrap `TData` with `LooseDecorated` and a single attribute `[TAttrib]`\n * - else\n * - if `TData` is already `Decorated`\n * - Prepend `TAttrib` to the existing attribute tuple.\n * - else\n * - Wrap `TData` with `Decorated` and a single attribute `[TAttrib]`\n */\nexport type Decorate<\n TData extends BaseData,\n TAttrib extends AnyAttribute,\n> = TData['type'] extends WgslTypeLiteral\n ? Decorated<Undecorate<TData>, [TAttrib, ...ExtractAttributes<TData>]>\n : TData['type'] extends LooseTypeLiteral\n ? LooseDecorated<Undecorate<TData>, [TAttrib, ...ExtractAttributes<TData>]>\n : never;\n\nexport type IsBuiltin<T> = ExtractAttributes<T>[number] extends [] ? false\n : ExtractAttributes<T>[number] extends Builtin<BuiltinName> ? true\n : false;\n\nexport type HasCustomLocation<T> = ExtractAttributes<T>[number] extends []\n ? false\n : ExtractAttributes<T>[number] extends Location ? true\n : false;\n\nexport function attribute<TData extends BaseData, TAttrib extends AnyAttribute>(\n data: TData,\n attrib: TAttrib,\n): Decorated | LooseDecorated {\n if (isDecorated(data)) {\n return new DecoratedImpl(data.inner, [\n attrib,\n ...data.attribs,\n ]) as Decorated;\n }\n\n if (isLooseDecorated(data)) {\n return new LooseDecoratedImpl(data.inner, [\n attrib,\n ...data.attribs,\n ]) as LooseDecorated;\n }\n\n if (isLooseData(data)) {\n return new LooseDecoratedImpl(data, [attrib]) as unknown as LooseDecorated;\n }\n\n return new DecoratedImpl(data, [attrib]) as unknown as Decorated;\n}\n\n/**\n * Gives the wrapped data-type a custom byte alignment. Useful in order to\n * fulfill uniform alignment requirements.\n *\n * @example\n * const Data = d.struct({\n * a: u32, // takes up 4 bytes\n * // 12 bytes of padding, because `b` is custom aligned to multiples of 16 bytes\n * b: d.align(16, u32),\n * });\n *\n * @param alignment The multiple of bytes this data should align itself to.\n * @param data The data-type to align.\n */\nexport function align<TAlign extends number, TData extends AnyData>(\n alignment: TAlign,\n data: TData,\n): Decorate<TData, Align<TAlign>> {\n return attribute(data, {\n [$internal]: true,\n type: '@align',\n params: [alignment],\n // biome-ignore lint/suspicious/noExplicitAny: <tired of lying to types>\n }) as any;\n}\n\n/**\n * Adds padding bytes after the wrapped data-type, until the whole value takes up `size` bytes.\n *\n * @example\n * const Data = d.struct({\n * a: d.size(16, u32), // takes up 16 bytes, instead of 4\n * b: u32, // starts at byte 16, because `a` has a custom size\n * });\n *\n * @param size The amount of bytes that should be reserved for this data-type.\n * @param data The data-type to wrap.\n */\nexport function size<TSize extends number, TData extends AnyData>(\n size: TSize,\n data: TData,\n): Decorate<TData, Size<TSize>> {\n return attribute(data, {\n [$internal]: true,\n type: '@size',\n params: [size],\n // biome-ignore lint/suspicious/noExplicitAny: <tired of lying to types>\n }) as any;\n}\n\n/**\n * Assigns an explicit numeric location to a struct member or a parameter that has this type.\n *\n * @example\n * const VertexOutput = {\n * a: d.u32, // has implicit location 0\n * b: d.location(5, d.u32),\n * c: d.u32, // has implicit location 6\n * };\n *\n * @param location The explicit numeric location.\n * @param data The data-type to wrap.\n */\nexport function location<TLocation extends number, TData extends AnyData>(\n location: TLocation,\n data: TData,\n): Decorate<TData, Location<TLocation>> {\n return attribute(data, {\n [$internal]: true,\n type: '@location',\n params: [location],\n // biome-ignore lint/suspicious/noExplicitAny: <tired of lying to types>\n }) as any;\n}\n\n/**\n * Specifies how user-defined vertex shader output (fragment shader input)\n * must be interpolated.\n *\n * Tip: Integer outputs cannot be interpolated.\n *\n * @example\n * const VertexOutput = {\n * a: d.f32, // has implicit 'perspective, center' interpolation\n * b: d.interpolate('linear, sample', d.f32),\n * };\n *\n * @param interpolationType How data should be interpolated.\n * @param data The data-type to wrap.\n */\nexport function interpolate<\n TInterpolation extends PerspectiveOrLinearInterpolationType,\n TData extends PerspectiveOrLinearInterpolatableData,\n>(\n interpolationType: TInterpolation,\n data: TData,\n): Decorate<TData, Interpolate<TInterpolation>>;\n\n/**\n * Specifies how user-defined vertex shader output (fragment shader input)\n * must be interpolated.\n *\n * Tip: Default sampling method of `flat` is `first`. Unless you specifically\n * need deterministic behavior provided by `'flat, first'`, prefer explicit\n * `'flat, either'` as it could be slightly faster in hardware.\n *\n * @example\n * const VertexOutput = {\n * a: d.f32, // has implicit 'perspective, center' interpolation\n * b: d.interpolate('flat, either', d.u32), // integer outputs cannot interpolate\n * };\n *\n * @param interpolationType How data should be interpolated.\n * @param data The data-type to wrap.\n */\nexport function interpolate<\n TInterpolation extends FlatInterpolationType,\n TData extends FlatInterpolatableData,\n>(\n interpolationType: TInterpolation,\n data: TData,\n): Decorate<TData, Interpolate<TInterpolation>>;\n\nexport function interpolate<\n TInterpolation extends InterpolationType,\n TData extends AnyData,\n>(\n interpolationType: TInterpolation,\n data: TData,\n): Decorate<TData, Interpolate<TInterpolation>> {\n return attribute(data, {\n [$internal]: true,\n type: '@interpolate',\n params: [interpolationType],\n // biome-ignore lint/suspicious/noExplicitAny: <tired of lying to types>\n }) as any;\n}\n\n/**\n * Marks a position built-in output value as invariant in vertex shaders.\n * If the data and control flow match for two position outputs in different\n * entry points, then the result values are guaranteed to be the same.\n *\n * Must only be applied to the position built-in value.\n *\n * @example\n * const VertexOutput = {\n * pos: d.invariant(d.builtin.position),\n * };\n *\n * @param data The position built-in data-type to mark as invariant.\n */\nexport function invariant(\n data: Decorated<Vec4f, [Builtin<'position'>]>,\n): Decorated<Vec4f, [Builtin<'position'>, Invariant]> {\n // Validate that invariant is only applied to position built-in\n if (!isBuiltin(data)) {\n throw new Error(\n 'The @invariant attribute must only be applied to the position built-in value.',\n );\n }\n\n // Find the builtin attribute to check if it's position\n const builtinAttrib = (isDecorated(data) || isLooseDecorated(data))\n ? data.attribs.find(isBuiltinAttrib)\n : undefined;\n\n if (!builtinAttrib || builtinAttrib.params[0] !== 'position') {\n throw new Error(\n 'The @invariant attribute must only be applied to the position built-in value.',\n );\n }\n\n return attribute(data, {\n [$internal]: true,\n type: '@invariant',\n params: [],\n // biome-ignore lint/suspicious/noExplicitAny: <tired of lying to types>\n }) as any;\n}\n\nexport function isBuiltin<\n T extends\n | Decorated<AnyWgslData, AnyAttribute[]>\n | LooseDecorated<AnyLooseData, AnyAttribute[]>,\n>(value: T | unknown): value is T {\n return (\n (isDecorated(value) || isLooseDecorated(value)) &&\n value.attribs.find(isBuiltinAttrib) !== undefined\n );\n}\n\nexport function getAttributesString<T extends BaseData>(field: T): string {\n if (!isDecorated(field) && !isLooseDecorated(field)) {\n return '';\n }\n\n return (field.attribs as AnyAttribute[])\n .map((attrib) => {\n if (attrib.params.length === 0) {\n return `${attrib.type} `;\n }\n return `${attrib.type}(${attrib.params.join(', ')}) `;\n })\n .join('');\n}\n\n// --------------\n// Implementation\n// --------------\n\nclass BaseDecoratedImpl<TInner extends BaseData, TAttribs extends unknown[]> {\n public readonly [$internal] = true;\n\n // Type-tokens, not available at runtime\n declare readonly [$repr]: Infer<TInner>;\n declare readonly [$gpuRepr]: InferGPU<TInner>;\n declare readonly [$reprPartial]: InferPartial<TInner>;\n // ---\n\n constructor(\n public readonly inner: TInner,\n public readonly attribs: TAttribs,\n ) {\n const alignAttrib = attribs.find(isAlignAttrib)?.params[0];\n const sizeAttrib = attribs.find(isSizeAttrib)?.params[0];\n\n if (alignAttrib !== undefined) {\n if (alignAttrib <= 0) {\n throw new Error(\n `Custom data alignment must be a positive number, got: ${alignAttrib}.`,\n );\n }\n\n if (Math.log2(alignAttrib) % 1 !== 0) {\n throw new Error(\n `Alignment has to be a power of 2, got: ${alignAttrib}.`,\n );\n }\n\n if (isWgslData(this.inner)) {\n if (alignAttrib % alignmentOf(this.inner) !== 0) {\n throw new Error(\n `Custom alignment has to be a multiple of the standard data alignment. Got: ${alignAttrib}, expected multiple of: ${\n alignmentOf(this.inner)\n }.`,\n );\n }\n }\n }\n\n if (sizeAttrib !== undefined) {\n if (sizeAttrib < sizeOf(this.inner)) {\n throw new Error(\n `Custom data size cannot be smaller then the standard data size. Got: ${sizeAttrib}, expected at least: ${\n sizeOf(this.inner)\n }.`,\n );\n }\n\n if (sizeAttrib <= 0) {\n throw new Error(\n `Custom data size must be a positive number. Got: ${sizeAttrib}.`,\n );\n }\n }\n }\n}\n\nclass DecoratedImpl<TInner extends BaseData, TAttribs extends unknown[]>\n extends BaseDecoratedImpl<TInner, TAttribs>\n implements Decorated<TInner, TAttribs> {\n public readonly [$internal] = true;\n public readonly type = 'decorated';\n\n // Type-tokens, not available at runtime\n declare readonly [$memIdent]: TAttribs extends Location[]\n ? MemIdentity<TInner> | Decorated<MemIdentity<TInner>, TAttribs>\n : Decorated<MemIdentity<TInner>, TAttribs>;\n declare readonly [$invalidSchemaReason]:\n Decorated[typeof $invalidSchemaReason];\n declare readonly [$validStorageSchema]: IsValidStorageSchema<TInner>;\n declare readonly [$validUniformSchema]: IsValidUniformSchema<TInner>;\n declare readonly [$validVertexSchema]: IsValidVertexSchema<TInner>;\n // ---\n}\n\nclass LooseDecoratedImpl<TInner extends BaseData, TAttribs extends unknown[]>\n extends BaseDecoratedImpl<TInner, TAttribs>\n implements LooseDecorated<TInner, TAttribs> {\n public readonly [$internal] = true;\n public readonly type = 'loose-decorated';\n\n // Type-tokens, not available at runtime\n declare readonly [$invalidSchemaReason]:\n LooseDecorated[typeof $invalidSchemaReason];\n declare readonly [$validVertexSchema]: IsValidVertexSchema<TInner>;\n // ---\n}\n","import { arrayOf } from './data/array.ts';\nimport { attribute } from './data/attributes.ts';\nimport type { LooseDecorated } from './data/dataTypes.ts';\nimport { bool, f32, u32 } from './data/numeric.ts';\nimport { vec3u, vec4f } from './data/vector.ts';\nimport type {\n AnyWgslData,\n BaseData,\n Bool,\n Builtin,\n Decorated,\n F32,\n U32,\n Vec3u,\n Vec4f,\n WgslArray,\n} from './data/wgslTypes.ts';\nimport { $internal } from './shared/symbols.ts';\n\n// ----------\n// Public API\n// ----------\n\nexport type BuiltinVertexIndex = Decorated<U32, [Builtin<'vertex_index'>]>;\nexport type BuiltinInstanceIndex = Decorated<U32, [Builtin<'instance_index'>]>;\nexport type BuiltinPosition = Decorated<Vec4f, [Builtin<'position'>]>;\nexport type BuiltinClipDistances = Decorated<\n WgslArray<U32>,\n [Builtin<'clip_distances'>]\n>;\nexport type BuiltinFrontFacing = Decorated<Bool, [Builtin<'front_facing'>]>;\nexport type BuiltinFragDepth = Decorated<F32, [Builtin<'frag_depth'>]>;\nexport type BuiltinSampleIndex = Decorated<U32, [Builtin<'sample_index'>]>;\nexport type BuiltinSampleMask = Decorated<U32, [Builtin<'sample_mask'>]>;\nexport type BuiltinLocalInvocationId = Decorated<\n Vec3u,\n [Builtin<'local_invocation_id'>]\n>;\nexport type BuiltinLocalInvocationIndex = Decorated<\n U32,\n [Builtin<'local_invocation_index'>]\n>;\nexport type BuiltinGlobalInvocationId = Decorated<\n Vec3u,\n [Builtin<'global_invocation_id'>]\n>;\nexport type BuiltinWorkgroupId = Decorated<Vec3u, [Builtin<'workgroup_id'>]>;\nexport type BuiltinNumWorkgroups = Decorated<\n Vec3u,\n [Builtin<'num_workgroups'>]\n>;\nexport type BuiltinSubgroupInvocationId = Decorated<\n U32,\n [Builtin<'subgroup_invocation_id'>]\n>;\nexport type BuiltinSubgroupSize = Decorated<U32, [Builtin<'subgroup_size'>]>;\n\nfunction defineBuiltin<T extends Decorated | LooseDecorated>(\n dataType: AnyWgslData,\n value: T['attribs'][0] extends { params: [infer TValue] } ? TValue : never,\n): T {\n return attribute(dataType, {\n [$internal]: true,\n type: '@builtin',\n // biome-ignore lint/suspicious/noExplicitAny: it's fine\n params: [value as any],\n }) as T;\n}\n\nexport const builtin = {\n vertexIndex: defineBuiltin<BuiltinVertexIndex>(u32, 'vertex_index'),\n instanceIndex: defineBuiltin<BuiltinInstanceIndex>(u32, 'instance_index'),\n position: defineBuiltin<BuiltinPosition>(vec4f, 'position'),\n clipDistances: defineBuiltin<BuiltinClipDistances>(\n arrayOf(u32, 8),\n 'clip_distances',\n ),\n frontFacing: defineBuiltin<BuiltinFrontFacing>(bool, 'front_facing'),\n fragDepth: defineBuiltin<BuiltinFragDepth>(f32, 'frag_depth'),\n sampleIndex: defineBuiltin<BuiltinSampleIndex>(u32, 'sample_index'),\n sampleMask: defineBuiltin<BuiltinSampleMask>(u32, 'sample_mask'),\n localInvocationId: defineBuiltin<BuiltinLocalInvocationId>(\n vec3u,\n 'local_invocation_id',\n ),\n localInvocationIndex: defineBuiltin<BuiltinLocalInvocationIndex>(\n u32,\n 'local_invocation_index',\n ),\n globalInvocationId: defineBuiltin<BuiltinGlobalInvocationId>(\n vec3u,\n 'global_invocation_id',\n ),\n workgroupId: defineBuiltin<BuiltinWorkgroupId>(vec3u, 'workgroup_id'),\n numWorkgroups: defineBuiltin<BuiltinNumWorkgroups>(vec3u, 'num_workgroups'),\n subgroupInvocationId: defineBuiltin<BuiltinSubgroupInvocationId>(\n u32,\n 'subgroup_invocation_id',\n ),\n subgroupSize: defineBuiltin<BuiltinSubgroupSize>(u32, 'subgroup_size'),\n} as const;\n\nexport type AnyBuiltin = (typeof builtin)[keyof typeof builtin];\nexport type AnyComputeBuiltin =\n | BuiltinLocalInvocationId\n | BuiltinLocalInvocationIndex\n | BuiltinGlobalInvocationId\n | BuiltinWorkgroupId\n | BuiltinNumWorkgroups\n | BuiltinSubgroupInvocationId\n | BuiltinSubgroupSize;\nexport type AnyVertexInputBuiltin = BuiltinVertexIndex | BuiltinInstanceIndex;\nexport type AnyVertexOutputBuiltin = BuiltinClipDistances | BuiltinPosition;\nexport type AnyFragmentInputBuiltin =\n | BuiltinPosition\n | BuiltinFrontFacing\n | BuiltinSampleIndex\n | BuiltinSampleMask\n | BuiltinSubgroupInvocationId\n | BuiltinSubgroupSize;\nexport type AnyFragmentOutputBuiltin = BuiltinFragDepth | BuiltinSampleMask;\n\nexport type OmitBuiltins<S> = S extends AnyBuiltin ? never\n : S extends BaseData ? S\n : {\n [Key in keyof S as S[Key] extends AnyBuiltin ? never : Key]: S[Key];\n };\n","/**\n * @module typegpu/data\n */\n\nimport { type InfixOperator, infixOperators } from '../tgsl/wgslGenerator.ts';\nimport { $internal } from '../shared/symbols.ts';\nimport { MatBase } from './matrix.ts';\nimport { VecBase } from './vectorImpl.ts';\n\nfunction assignInfixOperator<T extends typeof VecBase | typeof MatBase>(\n object: T,\n operator: InfixOperator,\n) {\n type Instance = InstanceType<T>;\n\n const proto = object.prototype as {\n [K in InfixOperator]?: (this: Instance, other: unknown) => unknown;\n };\n const opImpl = infixOperators[operator][$internal].jsImpl as (\n lhs: Instance,\n rhs: unknown,\n ) => unknown;\n\n proto[operator] = function (this: Instance, other: unknown): unknown {\n return opImpl(this, other);\n };\n}\n\nassignInfixOperator(VecBase, 'add');\nassignInfixOperator(VecBase, 'sub');\nassignInfixOperator(VecBase, 'mul');\nassignInfixOperator(VecBase, 'div');\nassignInfixOperator(MatBase, 'add');\nassignInfixOperator(MatBase, 'sub');\nassignInfixOperator(MatBase, 'mul');\n\nexport { bool, f16, f32, i32, u16, u32 } from './numeric.ts';\nexport {\n isAlignAttrib,\n isAtomic,\n isBuiltinAttrib,\n isDecorated,\n isInterpolateAttrib,\n isLocationAttrib,\n isPtr,\n isSizeAttrib,\n isWgslArray,\n isWgslData,\n isWgslStruct,\n Void,\n} from './wgslTypes.ts';\nexport type {\n Align,\n AnyVecInstance,\n AnyWgslData,\n AnyWgslStruct,\n Atomic,\n BaseData,\n BaseData as BaseWgslData,\n Bool,\n Builtin,\n Decorated,\n F16,\n F32,\n I32,\n Interpolate,\n Location,\n m2x2f,\n m3x3f,\n m4x4f,\n Mat2x2f,\n Mat3x3f,\n Mat4x4f,\n Ptr,\n Size,\n U16,\n U32,\n v2b,\n v2f,\n v2i,\n v2u,\n v3b,\n v3f,\n v3i,\n v3u,\n v4b,\n v4f,\n v4i,\n v4u,\n Vec2b,\n Vec2f,\n Vec2h,\n Vec2i,\n Vec2u,\n Vec3b,\n Vec3f,\n Vec3h,\n Vec3i,\n Vec3u,\n Vec4b,\n Vec4f,\n Vec4h,\n Vec4i,\n Vec4u,\n WgslArray,\n WgslStruct,\n} from './wgslTypes.ts';\nexport { struct } from './struct.ts';\nexport { arrayOf } from './array.ts';\nexport {\n ptrFn,\n ptrHandle,\n ptrPrivate,\n ptrStorage,\n ptrUniform,\n ptrWorkgroup,\n} from './ptr.ts';\nexport type {\n AnyData,\n AnyLooseData,\n Disarray,\n LooseDecorated,\n Unstruct,\n} from './dataTypes.ts';\nexport {\n vec2b,\n vec2f,\n vec2h,\n vec2i,\n vec2u,\n vec3b,\n vec3f,\n vec3h,\n vec3i,\n vec3u,\n vec4b,\n vec4f,\n vec4h,\n vec4i,\n vec4u,\n} from './vector.ts';\nexport { disarrayOf } from './disarray.ts';\nexport { unstruct } from './unstruct.ts';\nexport { mat2x2f, mat3x3f, mat4x4f, matToArray } from './matrix.ts';\nexport * from './vertexFormatData.ts';\nexport { atomic } from './atomic.ts';\nexport {\n align,\n type AnyAttribute,\n type HasCustomLocation,\n interpolate,\n invariant,\n type IsBuiltin,\n isBuiltin,\n location,\n size,\n} from './attributes.ts';\nexport {\n isData,\n isDisarray,\n isLooseData,\n isLooseDecorated,\n isUnstruct,\n} from './dataTypes.ts';\nexport { PUBLIC_sizeOf as sizeOf } from './sizeOf.ts';\nexport { PUBLIC_alignmentOf as alignmentOf } from './alignmentOf.ts';\nexport { builtin } from '../builtin.ts';\nexport type {\n AnyBuiltin,\n BuiltinClipDistances,\n BuiltinFragDepth,\n BuiltinFrontFacing,\n BuiltinGlobalInvocationId,\n BuiltinInstanceIndex,\n BuiltinLocalInvocationId,\n BuiltinLocalInvocationIndex,\n BuiltinNumWorkgroups,\n BuiltinPosition,\n BuiltinSampleIndex,\n BuiltinSampleMask,\n BuiltinVertexIndex,\n BuiltinWorkgroupId,\n} from '../builtin.ts';\nexport type { Infer, InferGPU, InferPartial } from '../shared/repr.ts';\n"],"mappings":"+gBAAA,UAAYA,OAAa,UCIlB,IAAMC,GAAU,CAACC,EAAeC,IAAmB,CACxD,IAAMC,EAAUD,EAAS,EACnBE,EAAa,CAACD,EACpB,OAAQF,EAAQE,KAAa,EAAIF,GAASA,EAAQG,GAAcF,CAClE,ECRO,IAAMG,GAAgB,CAC3B,QACA,UACA,UACA,QACA,UACA,UACA,SACA,WACA,WACA,SACA,WACA,WACA,SACA,WACA,WACA,SACA,WACA,WACA,UACA,YACA,YACA,UACA,YACA,YACA,UACA,YACA,YACA,UACA,YACA,YACA,YACA,SACA,WACA,WACA,WACA,SACA,WACA,WACA,WACA,kBACA,eACF,EAIaC,GAAyB,CACpC,IAAK,UACL,MAAO,YACP,MAAO,YACP,MAAO,YACP,IAAK,UACL,MAAO,YAEP,MAAO,YACP,IAAK,SACL,MAAO,W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SAASM,EACPC,EACAC,EACA,CAGA,IAAMC,EAAQF,EAAO,UAGfG,EAASC,GAAeH,CAAQ,EAAEI,CAAS,EAAE,OAKnDH,EAAMD,CAAQ,EAAI,SAA0BK,EAAyB,CACnE,OAAOH,EAAO,KAAMG,CAAK,CAC3B,CACF,CAEAP,EAAoBQ,GAAS,KAAK,EAClCR,EAAoBQ,GAAS,KAAK,EAClCR,EAAoBQ,GAAS,KAAK,EAClCR,EAAoBQ,GAAS,KAAK,EAClCR,EAAoBS,GAAS,KAAK,EAClCT,EAAoBS,GAAS,KAAK,EAClCT,EAAoBS,GAAS,KAAK","names":["tinyest","roundUp","value","modulo","bitMask","invBitMask","vertexFormats","kindToDefaultFormatMap","looseTypeLiterals","vertexFormats","isLooseData","data","$internal","isDisarray","schema","isUnstruct","isLooseDecorated","value","getCustomAlignment","isAlignAttrib","getCustomSize","isSizeAttrib","getCustomLocation","isLocationAttrib","isData","isWgslData","UnknownData","InfixDispatch","name","lhs","operator","TgpuVertexFormatDataImpl","type","$internal","formatToWGSLType","u32","vec2u","vec4u","i32","vec2i","vec4i","f32","vec2f","vec4f","vec3f","vec3u","vec3i","packedFormats","uint8","uint8x2","uint8x4","sint8","sint8x2","sint8x4","unorm8","unorm8x2","unorm8x4","snorm8","snorm8x2","snorm8x4","uint16","uint16x2","uint16x4","sint16","sint16x2","sint16x4","unorm16","unorm16x2","unorm16x4","snorm16","snorm16x2","snorm16x4","float16","float16x2","float16x4","float32","float32x2","float32x3","float32x4","uint32","uint32x2","uint32x3","uint32x4","sint32","sint32x2","sint32x3","sint32x4","unorm10_10_10_2","unorm8x4_bgra","isPackedData","value","knownAlignmentMap","computeAlignment","data","dataType","knownAlignment","isWgslStruct","alignmentOf","a","b","isWgslArray","isUnstruct","firstProp","getCustomAlignment","isDisarray","isDecorated","isLooseDecorated","packedFormats","computeCustomAlignment","customAlignmentOf","cachedAlignments","cachedCustomAlignments","alignment","PUBLIC_alignmentOf","schema","knownSizesMap","sizeOfStruct","struct","size","propTypes","property","roundUp","alignmentOf","sizeOf","sizeOfUnstruct","data","alignment","customAlignmentOf","computeSize","knownSize","isWgslStruct","isUnstruct","isWgslArray","isDisarray","isDecorated","isLooseDecorated","getCustomSize","cachedSizes","schema","PUBLIC_sizeOf","schemaCloneWrapper","schema","item","maybeType","schemaDefaultWrapper","arrayOf","elementType","elementCount","arraySchema","elements","_","i","schemaCloneWrapper","schemaDefaultWrapper","WgslArrayImpl","sizeOf","$internal","assertExhaustive","x","location","swizzleLenToType","f32","vec2f","vec3f","vec4f","f16","vec2h","vec3h","vec4h","i32","vec2i","vec3i","vec4i","u32","vec2u","vec3u","vec4u","bool","vec2b","vec3b","vec4b","kindToSchema","mat2x2f","mat3x3f","mat4x4f","indexableTypeToResult","getTypeForPropAccess","targetType","propName","isWgslStruct","isUnstruct","UnknownData","isNumericSchema","propLength","isVec","swizzleTypeChar","swizzleType","getTypeForIndexAccess","dataType","isWgslArray","isDisarray","numericLiteralToSnippet","value","snip","abstractInt","abstractFloat","INFINITE_RANK","getVectorComponent","type","vecTypeToPrimitive","getAutoConversionRank","src","dest","trueSrc","undecorate","trueDst","compSrc","compDest","isMat","getImplicitConversionRank","primitivePreference","srcType","destType","srcPref","getConversionRank","allowImplicit","autoRank","findBestType","types","uniqueTypes","bestType","minSum","conversionDetails","currentSum","currentDetails","possible","sourceType","conversion","actions","detail","index","hasCasts","action","concretize","getBestConversion","targetTypes","uniqueTargetTypes","explicitResult","implicitResult","applyActionToSnippet","ctx","value","action","targetType","snip","resolvedValue","assertExhaustive","convertToCommonType","values","restrictTo","concretizeTypes","verbose","types","concretize","type","UnknownData","DEV","conversion","getBestConversion","v","index","invariant","tryConvertSnippet","targetDataType","WgslTypeError","converted","convertStructValues","structType","key","val","coerceToSnippet","isSnippet","hasInternalDataType","$wgslDataType","isVecInstance","isMatInstance","kindToSchema","coerced","context","getResolutionCtx","commonType","arrayOf","numericLiteralToSnippet","bool","NODE","tinyest","parenthesizedOps","binaryLogicalOps","infixKinds","infixOperators","add","sub","mul","div","operatorToType","lhs","op","rhs","bool","assertExhaustive","value","generateBlock","ctx","_","statements","body","statement","generateStatement","registerBlockVariable","id","dataType","generateIdentifier","res","generateTypedExpression","expression","expectedType","prevExpectedType","result","generateExpression","tryConvertSnippet","snip","lhsExpr","rhsExpr","forcedType","converted","convertToCommonType","f32","f16","convLhs","convRhs","lhsStr","rhsStr","type","arg","argExpr","argStr","targetNode","property","target","InfixDispatch","$internal","UnknownData","propValue","coerceToSnippet","isPtr","getTypeForPropAccess","isWgslArray","u32","abstractInt","isMat","isVec","isVecInstance","propertyNode","targetStr","propertyStr","getTypeForIndexAccess","isData","numericLiteralToSnippet","calleeNode","argNodes","callee","isWgslStruct","WgslTypeError","isMarkedInternal","getName","argConversionHint","convertedArguments","i","argType","resolvedSnippets","sn","fnRes","error","ResolutionError","obj","structType","entries","key","val","convertedValues","convertStructValues","v","valueNodes","arrType","elemType","values","valuesSnippets","maybeValues","concretize","arrayType","arrayValues","arrayOf","blockifySingleStatement","returnNode","returnValue","cond","cons","alt","condition","consequent","alternate","rawId","rawValue","eq","isLooseData","init","update","initStatement","conditionExpr","updateStatement","initStr","condSnippet","conditionStr","updateStr","bodyStr","generateFunction","struct","props","structSchema","instanceProps","key","schema","schemaCloneWrapper","schemaDefaultWrapper","WgslStructImpl","$internal","label","setName","getName","disarrayOf","elementType","count","DisarrayImpl","elementCount","$internal","unstruct","properties","props","UnstructImpl","$internal","label","setName","getName","atomic","data","AtomicImpl","inner","$internal","attribute","data","attrib","isDecorated","DecoratedImpl","isLooseDecorated","LooseDecoratedImpl","isLooseData","align","alignment","$internal","size","location","interpolate","interpolationType","invariant","isBuiltin","builtinAttrib","isBuiltinAttrib","value","getAttributesString","field","BaseDecoratedImpl","inner","attribs","alignAttrib","isAlignAttrib","sizeAttrib","isSizeAttrib","isWgslData","alignmentOf","sizeOf","defineBuiltin","dataType","value","attribute","$internal","builtin","u32","vec4f","arrayOf","bool","f32","vec3u","assignInfixOperator","object","operator","proto","opImpl","infixOperators","$internal","other","VecBase","MatBase"]}