diff --git a/dist/index.js b/dist/index.js index e968602..bd9064a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,2 +1,2 @@ -export*from"./wasm/index.js";export*from"./scalar.js";export*from"./types.js"; -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiLi4vanMvaW5kZXgudHMiXSwic291cmNlc0NvbnRlbnQiOlsiLyoqXG4gKiBNaW5pbWFsaXN0aWMgbnVtZXJpY2FsIGxpYnJhcnkgZm9yIGhpZ2gtcGVyZm9ybWFuY2UgM0QgbWF0aCwgcG93ZXJlZCBieSBSdXN0IFdlYkFzc2VtYmx5IGJpbmRpbmdzLlxuICogQHBhY2thZ2VEb2N1bWVudGF0aW9uXG4gKi9cblxuZXhwb3J0ICogZnJvbSAnLi93YXNtL2luZGV4LnRzJztcbmV4cG9ydCAqIGZyb20gJy4vc2NhbGFyLnRzJztcbmV4cG9ydCAqIGZyb20gJy4vdHlwZXMudHMnO1xuIl0sIm1hcHBpbmdzIjoiIiwiaWdub3JlTGlzdCI6W119 \ No newline at end of file +export*from"./wasm/index.js";export*from"./memory.js";export*from"./scalar.js";export*from"./types.js"; +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiLi4vanMvaW5kZXgudHMiXSwic291cmNlc0NvbnRlbnQiOlsiLyoqXG4gKiBNaW5pbWFsaXN0aWMgbnVtZXJpY2FsIGxpYnJhcnkgZm9yIGhpZ2gtcGVyZm9ybWFuY2UgM0QgbWF0aCwgcG93ZXJlZCBieSBSdXN0IFdlYkFzc2VtYmx5IGJpbmRpbmdzLlxuICogQHBhY2thZ2VEb2N1bWVudGF0aW9uXG4gKi9cblxuZXhwb3J0ICogZnJvbSAnLi93YXNtL2luZGV4LnRzJztcbmV4cG9ydCAqIGZyb20gJy4vbWVtb3J5LnRzJztcbmV4cG9ydCAqIGZyb20gJy4vc2NhbGFyLnRzJztcbmV4cG9ydCAqIGZyb20gJy4vdHlwZXMudHMnO1xuIl0sIm1hcHBpbmdzIjoiIiwiaWdub3JlTGlzdCI6W119 \ No newline at end of file diff --git a/dist/memory.js b/dist/memory.js new file mode 100644 index 0000000..20a6471 --- /dev/null +++ b/dist/memory.js @@ -0,0 +1,2 @@ +const BYTES_PER_FLOAT64=8;let memoryManager;export function setMemoryManager(manager){memoryManager=manager}let usingFinalizationRegistry=true;export function useFinalizationRegistry(use){usingFinalizationRegistry=use}const registry=global.FinalizationRegistry&&new FinalizationRegistry(([ptr,size])=>memoryManager.free(ptr,size));function register(arr){usingFinalizationRegistry&®istry?.register(arr,[arr.byteOffset,arr.length],arr)}function unregister(arr){usingFinalizationRegistry&®istry?.unregister(arr)}export class ManagedFloat64Array{constructor(byteOffset){this.byteOffset=byteOffset;register(this)}*[Symbol.iterator](){if(!this.valid){return}const view=memoryManager.view;const offset=this.byteOffset/BYTES_PER_FLOAT64|0;for(let i=0;i=this.length){return}return memoryManager.view.at(this.byteOffset/BYTES_PER_FLOAT64+index|0)}copy(from,offset=0,length=Math.min(from.length,this.length-offset)){const start=from.byteOffset/BYTES_PER_FLOAT64|0;memoryManager.view.copyWithin(this.byteOffset/BYTES_PER_FLOAT64+offset|0,start,start+length)}set(array,offset=0){memoryManager.view.set(array,this.byteOffset/BYTES_PER_FLOAT64+offset|0)}free(){if(this.byteOffset>0){memoryManager.free(this.byteOffset,this.length);unregister(this);this.byteOffset=-Infinity}}get buffer(){return memoryManager.buffer}get byteLength(){return this.length*BYTES_PER_FLOAT64}get valid(){return this.byteOffset>=0}} +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJCWVRFU19QRVJfRkxPQVQ2NCIsIm1lbW9yeU1hbmFnZXIiLCJzZXRNZW1vcnlNYW5hZ2VyIiwibWFuYWdlciIsInVzaW5nRmluYWxpemF0aW9uUmVnaXN0cnkiLCJ1c2VGa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9yZUxpc3QiOltdfQ== \ No newline at end of file diff --git a/dist/wasm/index.js b/dist/wasm/index.js index 64b521c..4b3a578 100644 --- a/dist/wasm/index.js +++ b/dist/wasm/index.js @@ -1,2 +1,2 @@ -export*from"./mat.js";export*from"./memory.js";export*from"./quat.js";export*from"./transform.js";export*from"./vec.js"; -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiLi4vLi4vanMvd2FzbS9pbmRleC50cyJdLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgKiBmcm9tICcuL21hdC50cyc7XG5leHBvcnQgKiBmcm9tICcuL21lbW9yeS50cyc7XG5leHBvcnQgKiBmcm9tICcuL3F1YXQudHMnO1xuZXhwb3J0ICogZnJvbSAnLi90cmFuc2Zvcm0udHMnO1xuZXhwb3J0ICogZnJvbSAnLi92ZWMudHMnO1xuIl0sIm1hcHBpbmdzIjoiIiwiaWdub3JlTGlzdCI6W119 \ No newline at end of file +export*from"./mat.js";export*from"./quat.js";export*from"./transform.js";export*from"./vec.js"; +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6W10sInNvdXJjZXMiOlsiLi4vLi4vanMvd2FzbS9pbmRleC50cyJdLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgKiBmcm9tICcuL21hdC50cyc7XG5leHBvcnQgKiBmcm9tICcuL3F1YXQudHMnO1xuZXhwb3J0ICogZnJvbSAnLi90cmFuc2Zvcm0udHMnO1xuZXhwb3J0ICogZnJvbSAnLi92ZWMudHMnO1xuIl0sIm1hcHBpbmdzIjoiIiwiaWdub3JlTGlzdCI6W119 \ No newline at end of file diff --git a/dist/wasm/memory.js b/dist/wasm/memory.js index 165fb65..7a22911 100644 --- a/dist/wasm/memory.js +++ b/dist/wasm/memory.js @@ -1,2 +1,2 @@ -import{free,memory}from"../../wasm/index.js";const BYTES_PER_FLOAT64=8;const registry=global.FinalizationRegistry&&new FinalizationRegistry(([ptr,size])=>free(ptr,size));function register(arr){registry?.register(arr,[arr.byteOffset,arr.length],arr)}function unregister(arr){registry?.unregister(arr)}let view=new Float64Array(memory.buffer);export function getMemoryView(){if(view.buffer!==memory.buffer){view=new Float64Array(memory.buffer)}return view}export class ManagedFloat64Array{constructor(byteOffset){this.byteOffset=byteOffset;register(this)}*[Symbol.iterator](){const view=getMemoryView();const offset=this.byteOffset/BYTES_PER_FLOAT64|0;for(let i=0;i0){free(this.byteOffset,this.length);unregister(this);this.byteOffset=-Infinity}}get buffer(){return memory.buffer}get byteLength(){return this.length*BYTES_PER_FLOAT64}get valid(){return this.byteOffset>0}} -//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJmcmVlIiwibWVtb3J5IiwiQllURVNfUEVSX0ZMT0FUNjQiLCJyZWdpc3RyeSIsImdsb2JhbCIsIkZpbmFsaXphdGlvblJlZ2lzdHJ5IiwicHRyIiwic2l6ZSIsInJlZ2lzdGVyIiwiYXJyIiwiYnl0ZU9mZnNldCIsImxlbmd0aCIsInVucmVnaXN0ZXIiLCJ2aWV3IiwiRmxvYXQ2NEFycmF5IiwiYnVmZmVyIiwiZ2V0TWVtb3J5VmlldyIsIk1hbmFnZWRGbG9hdDY0QXJyYXkiLCJjb25zdHJ1Y3RvciIsIlN5bWJvbCIsIml0ZXJhdG9yIiwib2Zmc2V0IiwiaSIsImRpc3Bvc2UiLCJhdCIsImluZGV4IiwiY29weSIsImZyb20iLCJNYXRoIiwibWluIiwic3RhcnQiLCJjb3B5V2l0aGluIiwic2V0IiwiYXJyYXkiLCJJbmZpbml0eSIsImJ5dGVMZW5ndGgiLCJ2YWxpZCJdLCJzb3VyY2VzIjpbIi4uLy4uL2pzL3dhc20vbWVtb3J5LnRzIl0sInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IGZyZWUsIG1lbW9yeSB9IGZyb20gJy4uLy4uL3dhc20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25DLE1BQU8sQ0FBQWQsTUFBTSxDQUFDYyxNQUNoQixDQUVBLEdBQVcsQ0FBQW9CLFVBQVVBLENBQUEsQ0FBVyxDQUM5QixNQUFPLEtBQUksQ0FBQ3hCLE1BQU0sQ0FBR1QsaUJBQ3ZCLENBRUEsR0FBVyxDQUFBa0MsS0FBS0EsQ0FBQSxDQUFZLENBQzFCLE1BQU8sS0FBSSxDQUFDMUIsVUFBVSxDQUFHLENBQzNCLENBR0YiLCJpZ25vcmVMaXN0IjpbXX0= \ No newline at end of file +import{create,free,memory}from"../../wasm/index.js";import{ManagedFloat64Array,setMemoryManager}from"../memory.js";let view=new Float64Array(memory.buffer);export const memoryManager={get buffer(){return memory.buffer},get view(){if(view.buffer!==memory.buffer){view=new Float64Array(memory.buffer)}return view},create:function(size){return create(size)},free:function(byteOffset,size){free(byteOffset,size)}};setMemoryManager(memoryManager);export{ManagedFloat64Array}; +//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJjcmVhdGUiLCJmcmVlIiwibWVtb3J5IiwiTWFuYWdlZEZsb2F0NjRBcnJheSIsInNldE1lbW9yeU1hbmFnZXIiLCJ2aWV3IiwiRmxvYXQ2NEFycmF5IiwiYnVmZmVyIiwibWVtb3J5TWFuYWdlciIsInNpemUiLCJieXRlT2Zmc2V0Il0sInNvdXJjZXMiOlsiLi4vLi4vanMvd2FzbS9tZW1vcnkudHMiXSwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHsgY3JlYXRlLCBmcmVlLCBtZW1vcnkgfSBmcm9tICcuLi8uLi93YXNtL2luZGV4LmpzJztcbmltcG9ydCB7IE1hbmFnZWRGbG9hdDY0QXJyYXksIE1lbW9yeU1hbmFnZXIsIHNldE1lbW9yeU1hbmFnZXIgfSBmcm9tICcuLi9tZW1vcnkudHMnO1xuXG5sZXQgdmlldyA9IG5ldyBGbG9hdDY0QXJyYXkobWVtb3J5LmJ1ZmZlcik7XG5cbm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UFBSSxDQUFDRSxNQUFNLEdBQUtMLE1BQU0sQ0FBQ0ssTUFBTSxDQUFFLENBQ2pDRixJQUFJLENBQUcsR0FBSSxDQUFBQyxZQUFZLENBQUNKLE1BQU0sQ0FBQ0ssTUFBTSxDQUN2QyxDQUNBLE1BQU8sQ0FBQUYsSUFDVCxDQUFDLENBQ0RMLE1BQU0sQ0FBRSxRQUFBQSxDQUFVUyxJQUFZLENBQVUsQ0FDdEMsTUFBTyxDQUFBVCxNQUFNLENBQUNTLElBQUksQ0FDcEIsQ0FBQyxDQUNEUixJQUFJLENBQUUsUUFBQUEsQ0FBVVMsVUFBa0IsQ0FBRUQsSUFBWSxDQUFRLENBQ3REUixJQUFJLENBQUNTLFVBQVUsQ0FBRUQsSUFBSSxDQUN2QixDQUNGLENBQUMsQ0FFREwsZ0JBQWdCLENBQUNJLGFBQWEsQ0FBQyxDQUUvQixPQUFTTCxtQkFBbUIiLCJpZ25vcmVMaXN0IjpbXX0= \ No newline at end of file diff --git a/js/index.ts b/js/index.ts index 38935fa..22797d0 100644 --- a/js/index.ts +++ b/js/index.ts @@ -4,5 +4,6 @@ */ export * from './wasm/index.ts'; +export * from './memory.ts'; export * from './scalar.ts'; export * from './types.ts'; diff --git a/js/js/index.ts b/js/js/index.ts index 751d87f..3f15145 100644 --- a/js/js/index.ts +++ b/js/js/index.ts @@ -1,5 +1,5 @@ /** - * Pure JS implementation of munum. + * WIP: Pure JS implementation of munum. * @packageDocumentation */ diff --git a/js/memory.ts b/js/memory.ts new file mode 100644 index 0000000..80b9c3f --- /dev/null +++ b/js/memory.ts @@ -0,0 +1,115 @@ +const BYTES_PER_FLOAT64 = 8; + +/** A linear memory manager. */ +export interface MemoryManager { + /** The active memory buffer. */ + readonly buffer: ArrayBufferLike; + + /** The active float64 memory view. */ + readonly view: Float64Array; + + /** Allocates given size of memory in the number of float64 and returns the byteOffset pointing to the new memory. */ + create(size: number): number; + + /** Frees the memory at given byteOffset and size in the number of float64. */ + free(byteOffset: number, size: number): void; +} + +/** The {@link MemoryManager} to use. */ +let memoryManager: MemoryManager; + +/** Sets the {@link MemoryManager} to use. */ +export function setMemoryManager(manager: MemoryManager): void { + memoryManager = manager; +} + +let usingFinalizationRegistry = true; + +/** Sets if FinalizationRegistry should be used for automatic memory cleanup. */ +export function useFinalizationRegistry(use: boolean): void { + usingFinalizationRegistry = use; +} + +const registry = global.FinalizationRegistry && + new FinalizationRegistry(([ptr, size]: [number, number]) => memoryManager.free(ptr, size)); + +function register(arr: ManagedBufferView): void { + usingFinalizationRegistry && registry?.register(arr, [arr.byteOffset, arr.length], arr); +} + +function unregister(arr: ManagedBufferView): void { + usingFinalizationRegistry && registry?.unregister(arr); +} + +/** A wrapped TypedArray that requires explicit memory management. */ +export interface ManagedBufferView extends ArrayBufferView, Disposable { + /** Whether the array is still valid. */ + readonly valid: boolean; + + /** The length of the array. */ + readonly length: N; + + /** Frees the array. */ + free(): void; +} + +/** A managed Float64Array. */ +export abstract class ManagedFloat64Array + implements ManagedBufferView, Iterable { + + public constructor(public byteOffset: number) { + register(this); + } + + public *[Symbol.iterator](): Iterator { + if (!this.valid) { return; } + const view = memoryManager.view; + const offset = (this.byteOffset / BYTES_PER_FLOAT64) | 0; + for (let i = 0; i < this.length && offset + i < view.length; i++) { + yield view[offset + i]; + } + } + + public [Symbol.dispose](): void { + this.free(); + } + + /** Gets the value at given index. */ + public at(index: number): number | undefined { + if (index < 0 || index >= this.length) { return; } + return memoryManager.view.at((this.byteOffset / BYTES_PER_FLOAT64 + index) | 0); + } + + /** Copies a managed array to this. */ + public copy(from: ManagedFloat64Array, offset = 0, length = Math.min(from.length, this.length - offset)) { + const start = (from.byteOffset / BYTES_PER_FLOAT64) | 0; + memoryManager.view.copyWithin((this.byteOffset / BYTES_PER_FLOAT64 + offset) | 0, start, start + length); + } + + /** Copies an array to this. */ + public set(array: ArrayLike, offset = 0) { + memoryManager.view.set(array, (this.byteOffset / BYTES_PER_FLOAT64 + offset) | 0); + } + + public free(): void { + if (this.byteOffset > 0) { + memoryManager.free(this.byteOffset, this.length); + unregister(this); + this.byteOffset = -Infinity; + } + } + + public get buffer(): ArrayBufferLike { + return memoryManager.buffer; + } + + public get byteLength(): number { + return this.length * BYTES_PER_FLOAT64; + } + + public get valid(): boolean { + return this.byteOffset >= 0; + } + + public abstract readonly length: N; +} diff --git a/js/wasm/__tests__/vec.spec.ts b/js/wasm/__tests__/vec.spec.ts index f7a4298..8d027ec 100644 --- a/js/wasm/__tests__/vec.spec.ts +++ b/js/wasm/__tests__/vec.spec.ts @@ -1,6 +1,6 @@ import { expectArrayEqual } from '../../__tests__/test-utils.ts'; import { Mat2, Mat3, Mat4 } from '../mat.ts'; -import { getMemoryView } from '../memory.ts'; +import { memoryManager } from '../memory.ts'; import { Vec2, Vec3, Vec4 } from '../vec.ts'; describe('Vec2', () => { @@ -20,7 +20,7 @@ describe('Vec2', () => { test('ArrayBufferView', () => { const v = new Vec2(1, 2); expect(v.byteLength).toBe(16); - expect(v.buffer).toBe(getMemoryView().buffer); + expect(v.buffer).toBe(memoryManager.buffer); }); test('copy', () => { diff --git a/js/wasm/index.ts b/js/wasm/index.ts index cccb143..cd4ef38 100644 --- a/js/wasm/index.ts +++ b/js/wasm/index.ts @@ -1,5 +1,4 @@ export * from './mat.ts'; -export * from './memory.ts'; export * from './quat.ts'; export * from './transform.ts'; export * from './vec.ts'; diff --git a/js/wasm/memory.ts b/js/wasm/memory.ts index 08238ca..638959a 100644 --- a/js/wasm/memory.ts +++ b/js/wasm/memory.ts @@ -1,95 +1,26 @@ -import { free, memory } from '../../wasm/index.js'; - -const BYTES_PER_FLOAT64 = 8; - -const registry = global.FinalizationRegistry && - new FinalizationRegistry(([ptr, size]: [number, number]) => free(ptr, size)); - -function register(arr: ManagedBufferView): void { - registry?.register(arr, [arr.byteOffset, arr.length], arr); -} - -function unregister(arr: ManagedBufferView): void { - registry?.unregister(arr); -} +import { create, free, memory } from '../../wasm/index.js'; +import { ManagedFloat64Array, MemoryManager, setMemoryManager } from '../memory.ts'; let view = new Float64Array(memory.buffer); -export function getMemoryView(): Float64Array { - if (view.buffer !== memory.buffer) { - view = new Float64Array(memory.buffer); - } - return view; -} - -/** A wrapped TypedArray that requires explicit memory management. */ -export interface ManagedBufferView extends ArrayBufferView, Disposable { - /** Whether the array is still valid. */ - readonly valid: boolean; - - /** The length of the array. */ - readonly length: N; - - /** Frees the array. */ - free(): void; -} -/** A managed Float64Array. */ -export abstract class ManagedFloat64Array - implements ManagedBufferView, Iterable { - - public constructor(public byteOffset: number) { - register(this); - } - - public *[Symbol.iterator](): Iterator { - if (!this.valid) { return; } - const view = getMemoryView(); - const offset = (this.byteOffset / BYTES_PER_FLOAT64) | 0; - for (let i = 0; i < this.length && offset + i < view.length; i++) { - yield view[offset + i]; - } - } - - public [Symbol.dispose](): void { - this.free(); - } - - /** Gets the value at given index. */ - public at(index: number): number | undefined { - if (index < 0 || index >= this.length) { return; } - return getMemoryView().at((this.byteOffset / BYTES_PER_FLOAT64 + index) | 0); - } - - /** Copies a managed array to this. */ - public copy(from: ManagedFloat64Array, offset = 0, length = Math.min(from.length, this.length - offset)) { - const start = (from.byteOffset / BYTES_PER_FLOAT64) | 0; - getMemoryView().copyWithin((this.byteOffset / BYTES_PER_FLOAT64 + offset) | 0, start, start + length); - } - - /** Copies an array to this. */ - public set(array: ArrayLike, offset = 0) { - getMemoryView().set(array, (this.byteOffset / BYTES_PER_FLOAT64 + offset) | 0); - } - - public free(): void { - if (this.byteOffset > 0) { - free(this.byteOffset, this.length); - unregister(this); - this.byteOffset = -Infinity; - } - } - - public get buffer(): ArrayBufferLike { +export const memoryManager: MemoryManager = { + get buffer() { return memory.buffer; + }, + get view() { + if (view.buffer !== memory.buffer) { + view = new Float64Array(memory.buffer); + } + return view; + }, + create: function (size: number): number { + return create(size); + }, + free: function (byteOffset: number, size: number): void { + free(byteOffset, size); } +}; - public get byteLength(): number { - return this.length * BYTES_PER_FLOAT64; - } - - public get valid(): boolean { - return this.byteOffset >= 0; - } +setMemoryManager(memoryManager); - public abstract readonly length: N; -} +export { ManagedFloat64Array };