@gasm-compiler/core 0.1.0

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.
@@ -0,0 +1,76 @@
1
+ import { IGPUExecutor, ExecutorConfig, BufferData, ExecuteOptions } from './executor.js';
2
+
3
+ /**
4
+ * Browser WebGPU Executor Implementation
5
+ *
6
+ * Executes WGSL compute shaders using browser's native WebGPU support.
7
+ * Handles shader compilation, buffer management, and result readback.
8
+ */
9
+
10
+ declare class BrowserGPUExecutor implements IGPUExecutor {
11
+ private config;
12
+ private device;
13
+ private queue;
14
+ private initialized;
15
+ private pipelineCache;
16
+ private gpuBufferCache;
17
+ private stagingBuffer;
18
+ private stagingBufferSize;
19
+ private _animBindGroup;
20
+ private _animInputBuffer;
21
+ private _animInputSize;
22
+ private _animPipeline;
23
+ private _animStagingSize;
24
+ private _animStagingBuffer;
25
+ private _animResultBuffer;
26
+ private _animResultType;
27
+ private _animCopyU8Src;
28
+ private _animCopyU8Dst;
29
+ /**
30
+ * Zero-allocation animation fast path.
31
+ *
32
+ * Unlike execute(), this method:
33
+ * - Caches bind group, pipeline, buffers across frames
34
+ * - Creates NO Maps, arrays, Object.entries, template literals per frame
35
+ * - Only updates buffer contents via writeBuffer (4 bytes for time)
36
+ * - Returns a pre-allocated result buffer (same reference every frame)
37
+ *
38
+ * Call prepareAnimation() once before the loop, then executeFrame() each frame.
39
+ */
40
+ prepareAnimation(wgslCode: string, inputData: Float32Array | Int32Array | Uint32Array, inputType: "f32" | "i32" | "u32", outputSize: number, outputType: "f32" | "i32" | "u32", workgroupCount: [number, number, number], entryPoint?: string): Promise<void>;
41
+ private _animWorkgroupCount;
42
+ /**
43
+ * Execute one animation frame — ZERO JS object allocations.
44
+ *
45
+ * @param inputData The typed array whose contents to upload. Only the
46
+ * portion you've modified needs to be current (e.g. write time at offset 0).
47
+ * @returns The same pre-allocated result buffer every frame.
48
+ */
49
+ executeFrame(inputData: Float32Array | Int32Array | Uint32Array): Promise<Float32Array | Int32Array | Uint32Array>;
50
+ constructor(config?: ExecutorConfig);
51
+ /**
52
+ * Initialize GPU device and queue (lazy initialization).
53
+ */
54
+ private ensureInitialized;
55
+ private resultBufferCache;
56
+ /**
57
+ * Get or create a GPU buffer. Buffers with the same label+size+usage are reused
58
+ * across calls (contents are updated via writeBuffer) to avoid per-frame allocation.
59
+ */
60
+ private getOrCreateBuffer;
61
+ /**
62
+ * Read back data from a GPU buffer into a pre-allocated result buffer.
63
+ * The same output TypedArray is reused across frames — no per-frame allocation.
64
+ */
65
+ private readBuffer;
66
+ /**
67
+ * Execute a WGSL compute shader with the provided inputs.
68
+ */
69
+ execute(wgslCode: string, inputs: Record<string, BufferData>, outputs: string[], options?: ExecuteOptions): Promise<Record<string, BufferData>>;
70
+ /**
71
+ * Release GPU resources. Call when done with executor.
72
+ */
73
+ destroy(): Promise<void>;
74
+ }
75
+
76
+ export { BrowserGPUExecutor };
@@ -0,0 +1 @@
1
+ import{a}from"./chunk-G6YRZSKB.js";import"./chunk-STDXBN5E.js";export{a as BrowserGPUExecutor};
@@ -0,0 +1,20 @@
1
+ import { C as CompileDiagnostics, D as DispatchInfo, a as CompileOptions } from './parser-Q0YamOJY.js';
2
+ export { b as CompileError, i as isCompileError, d as isParseError, c as parseWasmModule } from './parser-Q0YamOJY.js';
3
+ export { BrowserGPUExecutor } from './browser-executor.js';
4
+ export { BufferData, ExecuteOptions, ExecutionError, ExecutorConfig, IGPUExecutor, OutputBufferSpec, isExecutionError } from './executor.js';
5
+
6
+ declare function disassembleToWAT(wasmBytes: Uint8Array): Promise<string>;
7
+
8
+ type CompileWithDiagnosticsResult = {
9
+ ok: true;
10
+ wgsl: string;
11
+ diagnostics: CompileDiagnostics;
12
+ dispatchInfo: DispatchInfo;
13
+ } | {
14
+ ok: false;
15
+ diagnostics: CompileDiagnostics;
16
+ };
17
+ declare function compileWithDiagnostics(wasmBytes: Uint8Array, options?: CompileOptions): CompileWithDiagnosticsResult;
18
+ declare function compile(wasmBytes: Uint8Array, options?: CompileOptions): string;
19
+
20
+ export { CompileDiagnostics, CompileOptions, type CompileWithDiagnosticsResult, DispatchInfo, compile, compileWithDiagnostics, disassembleToWAT };
@@ -0,0 +1 @@
1
+ import{A as I,B as R,C as S,a as d,b as N,d as l,e as m,f as g,g as h,p as E,q as C,r as x,s as y,x as w,y as D,z as A}from"./chunk-BRCWMQF4.js";import{a as M}from"./chunk-G6YRZSKB.js";import{a as b,b as W}from"./chunk-STDXBN5E.js";async function $(s){try{let r=(await(await import("wabt")).default()).readWasm(s,{readDebugNames:!0});r.generateNames(),r.applyNames();let c=r.toText({foldExprs:!1,inlineExport:!1});return r.destroy(),c}catch(o){return`; Error disassembling WAT: ${o instanceof Error?o.message:String(o)}`}}function O(s,o={}){let e=R(),r=l(s);if(m(r))return e.errors.push({severity:"error",code:"ERR_PARSE",message:r.message,functionName:r.functionName}),{ok:!1,diagnostics:e};let i=g(r);if(h(i))return e.errors.push({severity:"error",code:"ERR_VALIDATION",message:i.message,functionName:i.functionName}),{ok:!1,diagnostics:e};let u=i,a=S(u,o);if(e.warnings.push(...a.diagnostics.warnings),e.errors.push(...a.diagnostics.errors),e.demotions.push(...a.diagnostics.demotions),e.featuresUsed=a.diagnostics.featuresUsed,e.errors.length>0)return{ok:!1,diagnostics:e};let n=w(u);o.optimize!==!1&&(n=A(n,{verbose:o.verbose??!1}));let t=I(n);t=E(t),o.optimize!==!1&&(t=C(t));let p=x();if(o.optimize!==!1){let f=y(t);t=f.module,p=f.dispatchInfo}return{ok:!0,wgsl:D(t,o,s,p),diagnostics:e,dispatchInfo:p}}function j(s,o={}){let e=O(s,o);if(!e.ok){let r=e.diagnostics.errors[0];throw d(r?.message??"Compilation failed",{functionName:r?.functionName,instructionName:r?.code})}return e.wgsl}export{M as BrowserGPUExecutor,b as ExecutionError,j as compile,O as compileWithDiagnostics,$ as disassembleToWAT,N as isCompileError,W as isExecutionError,m as isParseError,l as parseWasmModule};