WasmSimd
Loader and memory manager for the wasm emission kernels (web target).
The kernels are embedded as base64 (see kernel.c / build.sh) and
instantiated asynchronously at startup: until ready is true, callers
fall back to the plain js batched path. Feature detection picks the
SIMD build when the engine supports wasm SIMD (all evergreen browsers
since 2021, Safari 16.4+), the scalar wasm build otherwise.
Memory model: this class owns the module's linear memory and hands out
regions through a simple bump allocator (alloc). The GL batcher
allocates its staging buffers as views over this memory, so the kernels
write in place and gl.bufferData(view) uploads with zero extra
copies. Per-part source copies (vertices/colors/uvs/indices into the
scratch regions) are done with typed-array set where possible, which
is nearly free browser-side.
Growing the memory detaches every existing view: memoryGeneration is
bumped on growth and view holders (the batcher, the scratch views here)
must re-derive their views from their stored offsets when it changes.
Static Members
ready: BoolTrue once the module is instantiated and usable.
usingSimd: BoolTrue when the SIMD build of the kernels is in use.
memoryGeneration: IntBumped every time the wasm memory grows (views must be re-derived).
memoryBuffer: js.lib.ArrayBufferThe wasm memory's ArrayBuffer (compare with a view's buffer to know if it is wasm-backed).
vertsScratch: js.lib.Float32ArrayScratch views (valid after requireScratch, until the next memory growth).
colorsScratch: js.lib.Float32ArraypackedScratch: js.lib.Uint32ArrayuvsScratch: js.lib.Float32ArrayindicesScratch: js.lib.Int32ArrayvertsScratchByteOffset: IntScratch byte offsets (stable across growth).
colorsScratchByteOffset: IntuvsScratchByteOffset: IntindicesScratchByteOffset: Intinit(): VoidStarts loading the kernels. Safe to call multiple times.
Allocates bytes from the module memory (16-byte aligned).
Returns the byte offset, or -1 if the memory limit was reached
(in which case the whole wasm path is permanently disabled and
callers keep using the plain js path). Regions are never freed.
| Name | Type |
|---|---|
bytes |
Int |
| Returns |
|---|
| Int |
Scratch source regions for one mesh part, sized for at least
numVertFloats position floats, numColorFloats color floats,
numUvFloats uv floats and numIndices indices. Views are reused
across parts within a frame and re-derived after memory growth.
| Name | Type |
|---|---|
numVertFloats |
Int |
numColorFloats |
Int |
numUvFloats |
Int |
numIndices |
Int |
| Returns |
|---|
| Bool |
meshPartF32(posByteOffset: Int, posStride: Int, colByteOffset: Int, uvByteOffset: Int, idxByteOffset: Int, idxBase: Int, vertsByteOffset: Int, vertStride: Int, floatColorsByteOffset: Int, packedColorsByteOffset: Int, uvsByteOffset: Int, indicesByteOffset: Int, start: Int, end: Int, a: Float, b: Float, c: Float, d: Float, tx: Float, ty: Float, z: Float, textureSlot: Float, writeSlot: Bool, colorMode: Int, singleR: Float, singleG: Float, singleB: Float, singleA: Float, globalAlpha: Float, premultiply: Bool, zeroAlpha: Bool, hasUvs: Bool, ufx: Float, ufy: Float, srcAttrCount: Int, dstAttrCount: Int): VoidRuns the fused mesh-part kernel. All offsets are byte offsets into the module memory; see kernel.c for parameter semantics.
| Name | Type |
|---|---|
posByteOffset |
Int |
posStride |
Int |
colByteOffset |
Int |
uvByteOffset |
Int |
idxByteOffset |
Int |
idxBase |
Int |
vertsByteOffset |
Int |
vertStride |
Int |
floatColorsByteOffset |
Int |
packedColorsByteOffset |
Int |
uvsByteOffset |
Int |
indicesByteOffset |
Int |
start |
Int |
end |
Int |
a |
Float |
b |
Float |
c |
Float |
d |
Float |
tx |
Float |
ty |
Float |
z |
Float |
textureSlot |
Float |
writeSlot |
Bool |
colorMode |
Int |
singleR |
Float |
singleG |
Float |
singleB |
Float |
singleA |
Float |
globalAlpha |
Float |
premultiply |
Bool |
zeroAlpha |
Bool |
hasUvs |
Bool |
ufx |
Float |
ufy |
Float |
srcAttrCount |
Int |
dstAttrCount |
Int |
Private Members
memory: DynamicmeshPartF32Fn: DynamicbumpOffset: IntmemoryBytes: IntvertsScratchOffset: IntvertsScratchFloats: IntcolorsScratchOffset: IntcolorsScratchFloats: IntuvsScratchOffset: IntuvsScratchFloats: IntindicesScratchOffset: IntindicesScratchInts: IntvertsScratchView: js.lib.Float32ArraycolorsScratchView: js.lib.Float32ArraypackedScratchView: js.lib.Uint32ArrayuvsScratchView: js.lib.Float32ArrayindicesScratchView: js.lib.Int32ArrayscratchGeneration: Int| Name | Type |
|---|---|
needed |
Int |
| Returns |
|---|
| Bool |
| Name | Type |
|---|---|
v |
Int |
| Returns |
|---|
| Int |