UNPKG

typegpu

Version:

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

2 lines 13.6 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }var _chunkTF6YPHJScjs = require('../chunk-TF6YPHJS.cjs');var _chunkV4CSEIB2cjs = require('../chunk-V4CSEIB2.cjs');var ce=_chunkV4CSEIB2cjs.ea.call(void 0, ()=>{throw new Error("discard() can only be used on the GPU.")},()=>_chunkV4CSEIB2cjs.ba.call(void 0, "discard;",_chunkV4CSEIB2cjs.y));function v(e){return e.dataType.type.includes("2")?_chunkV4CSEIB2cjs.qa:e.dataType.type.includes("3")?_chunkV4CSEIB2cjs.va:_chunkV4CSEIB2cjs.Aa}var xe=_chunkV4CSEIB2cjs.ea.call(void 0, (e,t)=>D(g(e,t)),(e,t)=>_chunkV4CSEIB2cjs.ba.call(void 0, `all(${e.value} == ${t.value})`,_chunkV4CSEIB2cjs.ha)),g= exports.eq =_chunkV4CSEIB2cjs.ea.call(void 0, (e,t)=>_chunkTF6YPHJScjs.a.eq[e.kind](e,t),(e,t)=>_chunkV4CSEIB2cjs.ba.call(void 0, `(${e.value} == ${t.value})`,v(e))),ye= exports.ne =_chunkV4CSEIB2cjs.ea.call(void 0, (e,t)=>m(g(e,t)),(e,t)=>_chunkV4CSEIB2cjs.ba.call(void 0, `(${e.value} != ${t.value})`,v(e))),S= exports.lt =_chunkV4CSEIB2cjs.ea.call(void 0, (e,t)=>_chunkTF6YPHJScjs.a.lt[e.kind](e,t),(e,t)=>_chunkV4CSEIB2cjs.ba.call(void 0, `(${e.value} < ${t.value})`,v(e))),ve= exports.le =_chunkV4CSEIB2cjs.ea.call(void 0, (e,t)=>$(S(e,t),g(e,t)),(e,t)=>_chunkV4CSEIB2cjs.ba.call(void 0, `(${e.value} <= ${t.value})`,v(e))),fe= exports.gt =_chunkV4CSEIB2cjs.ea.call(void 0, (e,t)=>W(m(S(e,t)),m(g(e,t))),(e,t)=>_chunkV4CSEIB2cjs.ba.call(void 0, `(${e.value} > ${t.value})`,v(e))),ge= exports.ge =_chunkV4CSEIB2cjs.ea.call(void 0, (e,t)=>m(S(e,t)),(e,t)=>_chunkV4CSEIB2cjs.ba.call(void 0, `(${e.value} >= ${t.value})`,v(e))),m= exports.not =_chunkV4CSEIB2cjs.ea.call(void 0, e=>_chunkTF6YPHJScjs.a.neg[e.kind](e),e=>_chunkV4CSEIB2cjs.ba.call(void 0, `!(${e.value})`,e.dataType)),$= exports.or =_chunkV4CSEIB2cjs.ea.call(void 0, (e,t)=>_chunkTF6YPHJScjs.a.or[e.kind](e,t),(e,t)=>_chunkV4CSEIB2cjs.ba.call(void 0, `(${e.value} | ${t.value})`,e.dataType)),W= exports.and =_chunkV4CSEIB2cjs.ea.call(void 0, (e,t)=>m($(m(e),m(t))),(e,t)=>_chunkV4CSEIB2cjs.ba.call(void 0, `(${e.value} & ${t.value})`,e.dataType)),D= exports.all =_chunkV4CSEIB2cjs.ea.call(void 0, e=>_chunkTF6YPHJScjs.a.all[e.kind](e),e=>_chunkV4CSEIB2cjs.ba.call(void 0, `all(${e.value})`,_chunkV4CSEIB2cjs.ha)),Se= exports.any =_chunkV4CSEIB2cjs.ea.call(void 0, e=>!D(m(e)),e=>_chunkV4CSEIB2cjs.ba.call(void 0, `any(${e.value})`,_chunkV4CSEIB2cjs.ha)),be= exports.isCloseTo =_chunkV4CSEIB2cjs.ea.call(void 0, (e,t,o=.01)=>typeof e=="number"&&typeof t=="number"?Math.abs(e-t)<o:_chunkV4CSEIB2cjs.z.call(void 0, e)&&_chunkV4CSEIB2cjs.z.call(void 0, t)?_chunkTF6YPHJScjs.a.isCloseToZero[e.kind](_chunkTF6YPHJScjs.e.call(void 0, e,t),o):!1,(e,t,o=_chunkV4CSEIB2cjs.ba.call(void 0, .01,_chunkV4CSEIB2cjs.ka))=>_chunkTF6YPHJScjs.b.call(void 0, e)&&_chunkTF6YPHJScjs.b.call(void 0, t)?_chunkV4CSEIB2cjs.ba.call(void 0, `(abs(f32(${e.value}) - f32(${t.value})) <= ${o.value})`,_chunkV4CSEIB2cjs.ha):!_chunkTF6YPHJScjs.b.call(void 0, e)&&!_chunkTF6YPHJScjs.b.call(void 0, t)?_chunkV4CSEIB2cjs.ba.call(void 0, `all(abs(${e.value} - ${t.value}) <= (${e.value} - ${e.value}) + ${o.value})`,_chunkV4CSEIB2cjs.ha):_chunkV4CSEIB2cjs.ba.call(void 0, "false",_chunkV4CSEIB2cjs.ha)),we= exports.select =_chunkV4CSEIB2cjs.ea.call(void 0, (e,t,o)=>typeof o=="boolean"?o?t:e:_chunkTF6YPHJScjs.a.select[e.kind](e,t,o),(e,t,o)=>_chunkV4CSEIB2cjs.ba.call(void 0, `select(${e.value}, ${t.value}, ${o.value})`,e.dataType));var Ae=_chunkV4CSEIB2cjs.ea.call(void 0, ()=>console.warn("workgroupBarrier is a no-op outside of GPU mode."),()=>_chunkV4CSEIB2cjs.ba.call(void 0, "workgroupBarrier()",_chunkV4CSEIB2cjs.y)),Ie= exports.storageBarrier =_chunkV4CSEIB2cjs.ea.call(void 0, ()=>console.warn("storageBarrier is a no-op outside of GPU mode."),()=>_chunkV4CSEIB2cjs.ba.call(void 0, "storageBarrier()",_chunkV4CSEIB2cjs.y)),$e= exports.textureBarrier =_chunkV4CSEIB2cjs.ea.call(void 0, ()=>console.warn("textureBarrier is a no-op outside of GPU mode."),()=>_chunkV4CSEIB2cjs.ba.call(void 0, "textureBarrier()",_chunkV4CSEIB2cjs.y)),De= exports.atomicLoad =_chunkV4CSEIB2cjs.ea.call(void 0, e=>{throw new Error("Atomic operations are not supported outside of GPU mode.")},e=>{if(_chunkV4CSEIB2cjs.I.call(void 0, e.dataType)&&e.dataType.type==="atomic")return _chunkV4CSEIB2cjs.ba.call(void 0, `atomicLoad(&${e.value})`,e.dataType.inner);throw new Error(`Invalid atomic type: ${JSON.stringify(e.dataType,null,2)}`)}),Be= exports.atomicStore =_chunkV4CSEIB2cjs.ea.call(void 0, (e,t)=>{throw new Error("Atomic operations are not supported outside of GPU mode.")},(e,t)=>{if(!_chunkV4CSEIB2cjs.I.call(void 0, e.dataType)||e.dataType.type!=="atomic")throw new Error(`Invalid atomic type: ${JSON.stringify(e.dataType,null,2)}`);return _chunkV4CSEIB2cjs.ba.call(void 0, `atomicStore(&${e.value}, ${t.value})`,_chunkV4CSEIB2cjs.y)}),y=(e,t)=>e.dataType.type==="atomic"&&e.dataType.inner.type==="i32"?[e.dataType,_chunkV4CSEIB2cjs.ja]:[e.dataType,_chunkV4CSEIB2cjs.ia],Ve= exports.atomicAdd =_chunkV4CSEIB2cjs.ea.call(void 0, (e,t)=>{throw new Error("Atomic operations are not supported outside of GPU mode.")},(e,t)=>{if(_chunkV4CSEIB2cjs.I.call(void 0, e.dataType)&&e.dataType.type==="atomic")return _chunkV4CSEIB2cjs.ba.call(void 0, `atomicAdd(&${e.value}, ${t.value})`,e.dataType.inner);throw new Error(`Invalid atomic type: ${JSON.stringify(e.dataType,null,2)}`)},y),Ue= exports.atomicSub =_chunkV4CSEIB2cjs.ea.call(void 0, (e,t)=>{throw new Error("Atomic operations are not supported outside of GPU mode.")},(e,t)=>{if(_chunkV4CSEIB2cjs.I.call(void 0, e.dataType)&&e.dataType.type==="atomic")return _chunkV4CSEIB2cjs.ba.call(void 0, `atomicSub(&${e.value}, ${t.value})`,e.dataType.inner);throw new Error(`Invalid atomic type: ${JSON.stringify(e.dataType,null,2)}`)},y),ke= exports.atomicMax =_chunkV4CSEIB2cjs.ea.call(void 0, (e,t)=>{throw new Error("Atomic operations are not supported outside of GPU mode.")},(e,t)=>{if(_chunkV4CSEIB2cjs.I.call(void 0, e.dataType)&&e.dataType.type==="atomic")return _chunkV4CSEIB2cjs.ba.call(void 0, `atomicMax(&${e.value}, ${t.value})`,e.dataType.inner);throw new Error(`Invalid atomic type: ${JSON.stringify(e.dataType,null,2)}`)},y),Ee= exports.atomicMin =_chunkV4CSEIB2cjs.ea.call(void 0, (e,t)=>{throw new Error("Atomic operations are not supported outside of GPU mode.")},(e,t)=>{if(_chunkV4CSEIB2cjs.I.call(void 0, e.dataType)&&e.dataType.type==="atomic")return _chunkV4CSEIB2cjs.ba.call(void 0, `atomicMin(&${e.value}, ${t.value})`,e.dataType.inner);throw new Error(`Invalid atomic type: ${JSON.stringify(e.dataType,null,2)}`)},y),Oe= exports.atomicAnd =_chunkV4CSEIB2cjs.ea.call(void 0, (e,t)=>{throw new Error("Atomic operations are not supported outside of GPU mode.")},(e,t)=>{if(_chunkV4CSEIB2cjs.I.call(void 0, e.dataType)&&e.dataType.type==="atomic")return _chunkV4CSEIB2cjs.ba.call(void 0, `atomicAnd(&${e.value}, ${t.value})`,e.dataType.inner);throw new Error(`Invalid atomic type: ${JSON.stringify(e.dataType,null,2)}`)},y),_e= exports.atomicOr =_chunkV4CSEIB2cjs.ea.call(void 0, (e,t)=>{throw new Error("Atomic operations are not supported outside of GPU mode.")},(e,t)=>{if(_chunkV4CSEIB2cjs.I.call(void 0, e.dataType)&&e.dataType.type==="atomic")return _chunkV4CSEIB2cjs.ba.call(void 0, `atomicOr(&${e.value}, ${t.value})`,e.dataType.inner);throw new Error(`Invalid atomic type: ${JSON.stringify(e.dataType,null,2)}`)},y),Pe= exports.atomicXor =_chunkV4CSEIB2cjs.ea.call(void 0, (e,t)=>{throw new Error("Atomic operations are not supported outside of GPU mode.")},(e,t)=>{if(_chunkV4CSEIB2cjs.I.call(void 0, e.dataType)&&e.dataType.type==="atomic")return _chunkV4CSEIB2cjs.ba.call(void 0, `atomicXor(&${e.value}, ${t.value})`,e.dataType.inner);throw new Error(`Invalid atomic type: ${JSON.stringify(e.dataType,null,2)}`)},y);var Ge=_chunkV4CSEIB2cjs.ea.call(void 0, e=>e.length,e=>_chunkV4CSEIB2cjs.L.call(void 0, e.dataType)&&_chunkV4CSEIB2cjs.J.call(void 0, e.dataType.inner)&&e.dataType.inner.elementCount>0?_chunkV4CSEIB2cjs.ba.call(void 0, String(e.dataType.inner.elementCount),_chunkV4CSEIB2cjs.fa):_chunkV4CSEIB2cjs.ba.call(void 0, `arrayLength(${e.value})`,_chunkV4CSEIB2cjs.ia),e=>[_chunkV4CSEIB2cjs.Ga.call(void 0, e.dataType)]);var _typedbinary = require('typed-binary'); var d = _interopRequireWildcard(_typedbinary);var Le=_chunkV4CSEIB2cjs.ea.call(void 0, e=>{let t=new ArrayBuffer(4);new d.BufferWriter(t).writeUint32(e);let n=new d.BufferReader(t);return _chunkV4CSEIB2cjs.ma.call(void 0, n.readFloat16(),n.readFloat16())},e=>_chunkV4CSEIB2cjs.ba.call(void 0, `unpack2x16float(${e.value})`,_chunkV4CSEIB2cjs.ma)),Ne= exports.pack2x16float =_chunkV4CSEIB2cjs.ea.call(void 0, e=>{let t=new ArrayBuffer(4),o=new d.BufferWriter(t);o.writeFloat16(e.x),o.writeFloat16(e.y);let n=new d.BufferReader(t);return _chunkV4CSEIB2cjs.ia.call(void 0, n.readUint32())},e=>_chunkV4CSEIB2cjs.ba.call(void 0, `pack2x16float(${e.value})`,_chunkV4CSEIB2cjs.ia)),he= exports.unpack4x8unorm =_chunkV4CSEIB2cjs.ea.call(void 0, e=>{let t=new ArrayBuffer(4);new d.BufferWriter(t).writeUint32(e);let n=new d.BufferReader(t);return _chunkV4CSEIB2cjs.wa.call(void 0, n.readUint8()/255,n.readUint8()/255,n.readUint8()/255,n.readUint8()/255)},e=>_chunkV4CSEIB2cjs.ba.call(void 0, `unpack4x8unorm(${e.value})`,_chunkV4CSEIB2cjs.wa)),Fe= exports.pack4x8unorm =_chunkV4CSEIB2cjs.ea.call(void 0, e=>{let t=new ArrayBuffer(4),o=new d.BufferWriter(t);o.writeUint8(e.x*255),o.writeUint8(e.y*255),o.writeUint8(e.z*255),o.writeUint8(e.w*255);let n=new d.BufferReader(t);return _chunkV4CSEIB2cjs.ia.call(void 0, n.readUint32())},e=>_chunkV4CSEIB2cjs.ba.call(void 0, `pack4x8unorm(${e.value})`,_chunkV4CSEIB2cjs.ia));var We=_chunkV4CSEIB2cjs.ea.call(void 0, (e,t,o,n,u)=>{throw new Error("Texture sampling is not supported outside of GPU mode.")},(e,t,o,n,u)=>{let s=[e,t,o];return n!==void 0&&s.push(n),u!==void 0&&s.push(u),_chunkV4CSEIB2cjs.ba.call(void 0, `textureSample(${s.map(b=>b.value).join(", ")})`,_chunkV4CSEIB2cjs.wa)}),Je= exports.textureSampleLevel =_chunkV4CSEIB2cjs.ea.call(void 0, (e,t,o,n,u)=>{throw new Error("Texture sampling is not supported outside of GPU mode.")},(e,t,o,n,u)=>{let s=[e,t,o,n];return u!==void 0&&s.push(u),_chunkV4CSEIB2cjs.ba.call(void 0, `textureSampleLevel(${s.map(b=>b.value).join(", ")})`,_chunkV4CSEIB2cjs.wa)}),Ce={u32:_chunkV4CSEIB2cjs.za,i32:_chunkV4CSEIB2cjs.ya,f32:_chunkV4CSEIB2cjs.wa},Me= exports.textureLoad =_chunkV4CSEIB2cjs.ea.call(void 0, (e,t,o)=>{throw new Error("Texture loading is not supported outside of GPU mode.")},(e,t,o)=>{let n=[e,t];o!==void 0&&n.push(o);let u=e.dataType;return _chunkV4CSEIB2cjs.ba.call(void 0, `textureLoad(${n.map(s=>s.value).join(", ")})`,"texelDataType"in u?u.texelDataType:Ce[u.channelDataType.type])}),qe= exports.textureStore =_chunkV4CSEIB2cjs.ea.call(void 0, (e,t,o,n)=>{throw new Error("Texture storing is not supported outside of GPU mode.")},(e,t,o,n)=>_chunkV4CSEIB2cjs.ba.call(void 0, `textureStore(${[e,t,o,n].filter(u=>u!==void 0).map(u=>u.value).join(", ")})`,_chunkV4CSEIB2cjs.y)),je= exports.textureDimensions =_chunkV4CSEIB2cjs.ea.call(void 0, (e,t)=>{throw new Error("Texture dimensions are not supported outside of GPU mode.")},(e,t)=>{let o=e.dataType.dimension;return _chunkV4CSEIB2cjs.ba.call(void 0, `textureDimensions(${e.value}${t!==void 0?`, ${t.value}`:""})`,o==="1d"?_chunkV4CSEIB2cjs.ia:o==="3d"?_chunkV4CSEIB2cjs.ua:_chunkV4CSEIB2cjs.pa)});exports.abs = _chunkTF6YPHJScjs.h; exports.acos = _chunkTF6YPHJScjs.j; exports.add = _chunkTF6YPHJScjs.d; exports.all = D; exports.allEq = xe; exports.and = W; exports.any = Se; exports.arrayLength = Ge; exports.asin = _chunkTF6YPHJScjs.k; exports.atan2 = _chunkTF6YPHJScjs.i; exports.atomicAdd = Ve; exports.atomicAnd = Oe; exports.atomicLoad = De; exports.atomicMax = ke; exports.atomicMin = Ee; exports.atomicOr = _e; exports.atomicStore = Be; exports.atomicSub = Ue; exports.atomicXor = Pe; exports.ceil = _chunkTF6YPHJScjs.l; exports.clamp = _chunkTF6YPHJScjs.m; exports.cos = _chunkTF6YPHJScjs.n; exports.cross = _chunkTF6YPHJScjs.o; exports.discard = ce; exports.distance = _chunkTF6YPHJScjs.C; exports.div = _chunkTF6YPHJScjs.g; exports.dot = _chunkTF6YPHJScjs.p; exports.eq = g; exports.exp = _chunkTF6YPHJScjs.y; exports.floor = _chunkTF6YPHJScjs.r; exports.fract = _chunkTF6YPHJScjs.s; exports.ge = ge; exports.gt = fe; exports.isCloseTo = be; exports.le = ve; exports.length = _chunkTF6YPHJScjs.t; exports.lt = S; exports.max = _chunkTF6YPHJScjs.u; exports.min = _chunkTF6YPHJScjs.v; exports.mix = _chunkTF6YPHJScjs.A; exports.mul = _chunkTF6YPHJScjs.f; exports.ne = ye; exports.neg = _chunkTF6YPHJScjs.D; exports.normalize = _chunkTF6YPHJScjs.q; exports.not = m; exports.or = $; exports.pack2x16float = Ne; exports.pack4x8unorm = Fe; exports.pow = _chunkTF6YPHJScjs.z; exports.reflect = _chunkTF6YPHJScjs.B; exports.select = we; exports.sign = _chunkTF6YPHJScjs.w; exports.sin = _chunkTF6YPHJScjs.x; exports.sqrt = _chunkTF6YPHJScjs.E; exports.storageBarrier = Ie; exports.sub = _chunkTF6YPHJScjs.e; exports.textureBarrier = $e; exports.textureDimensions = je; exports.textureLoad = Me; exports.textureSample = We; exports.textureSampleLevel = Je; exports.textureStore = qe; exports.unpack2x16float = Le; exports.unpack4x8unorm = he; exports.workgroupBarrier = Ae; //# sourceMappingURL=index.cjs.map