@gasm-compiler/core 0.3.2 → 0.5.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.
- package/LICENSE +17 -0
- package/README.md +107 -2
- package/dist/browser.d.ts +27 -3
- package/dist/browser.js +8 -8
- package/dist/chunk-MBWDLAL5.js +5 -0
- package/dist/chunk-TICBJF7F.js +9 -0
- package/dist/compiler.js +1 -1
- package/dist/{error_codes-D6RsiZ33.d.ts → error_codes-5zCZDwFZ.d.ts} +134 -14
- package/dist/gasm_core_rs.wasm +0 -0
- package/dist/mod.d.ts +27 -3
- package/dist/mod.js +1 -1
- package/package.json +11 -12
- package/dist/chunk-PS4NV6ZB.js +0 -5
- package/dist/chunk-VSCQDCQR.js +0 -9
package/LICENSE
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Copyright (c) 2025-present Gasm Compiler Authors
|
|
2
|
+
|
|
3
|
+
All rights reserved.
|
|
4
|
+
|
|
5
|
+
This software and associated documentation files (the "Software") are the
|
|
6
|
+
proprietary property of the copyright holder(s). No permission is granted to
|
|
7
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
8
|
+
of the Software, except as expressly permitted in a separate written license
|
|
9
|
+
agreement with the copyright holder(s).
|
|
10
|
+
|
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
12
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
13
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
14
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
15
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
16
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
17
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
Transform WebAssembly binaries into WGSL (WebGPU Shading Language) compute shaders. Write your GPU kernels in any language that compiles to WebAssembly (C, C++, Rust, Go, AssemblyScript, or hand-written WAT), then run them on the GPU via WebGPU.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Gasm v0.2 is the default through the Rust/Wasm compiler backend. Archived
|
|
8
|
+
Gasm v0.1 behavior remains available through an explicit compatibility option.
|
|
8
9
|
|
|
9
10
|
---
|
|
10
11
|
|
|
@@ -49,6 +50,107 @@ const shaderModule = device.createShaderModule({ code: wgslCode });
|
|
|
49
50
|
|
|
50
51
|
## Usage
|
|
51
52
|
|
|
53
|
+
### Specification Versions
|
|
54
|
+
|
|
55
|
+
Gasm v0.2 is the default:
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
const wgsl = compile(wasmBytes);
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The default enables strict v0.2 validation and lowering. Existing consumers can
|
|
62
|
+
keep the archived v0.1 compiler behavior explicitly:
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
const wgsl = compile(wasmBytes, { specVersion: "0.1" });
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Compile a v0.2 artifact and metadata sidecar through the Rust/Wasm compiler:
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
import {
|
|
72
|
+
compileToArtifact,
|
|
73
|
+
validateGasmMetadataSchema,
|
|
74
|
+
} from "@gasm-compiler/core";
|
|
75
|
+
|
|
76
|
+
const result = compileToArtifact(wasmBytes);
|
|
77
|
+
if (!result.ok) {
|
|
78
|
+
throw new Error(
|
|
79
|
+
`${result.diagnostics.errors[0]?.code}: ` +
|
|
80
|
+
`${result.diagnostics.errors[0]?.message}`,
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const schema = validateGasmMetadataSchema(result.metadata);
|
|
85
|
+
if (!schema.valid) throw new Error(schema.errors.join(", "));
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Gasm v0.2 semantics are implemented only in `packages/core-rs` and distributed
|
|
89
|
+
through its Wasm artifact. The TypeScript compiler implementation is retained
|
|
90
|
+
at v0.1 for compatibility. Deno remains the runtime for the CLI and the live
|
|
91
|
+
core/CLI test suites, including headless WebGPU execution.
|
|
92
|
+
|
|
93
|
+
The CLI also defaults to v0.2:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
gasm-compiler compile input.wasm \
|
|
97
|
+
--output output.wgsl \
|
|
98
|
+
--metadata output.gasm.json
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Use `--spec-version 0.1` when compiling archived v0.1 inputs.
|
|
102
|
+
|
|
103
|
+
#### Migrating from 0.3.x
|
|
104
|
+
|
|
105
|
+
- Compilation now defaults to strict Gasm v0.2 validation.
|
|
106
|
+
- Pass `{ specVersion: "0.1" }` to retain archived v0.1 behavior.
|
|
107
|
+
- Gasm v0.2 extensions must be declared in the module's
|
|
108
|
+
`gasm.extensions` custom section.
|
|
109
|
+
- Math extension scalar imports use explicit type suffixes such as
|
|
110
|
+
`sin_f32`. Legacy unsuffixed imports remain accepted for compatibility.
|
|
111
|
+
|
|
112
|
+
Required extensions are declared by the module's `gasm.extensions` custom
|
|
113
|
+
section. The CLI does not inject extensions, so validation reflects the exact
|
|
114
|
+
module that will be distributed.
|
|
115
|
+
|
|
116
|
+
### Integrator Workflow
|
|
117
|
+
|
|
118
|
+
Playgrounds, compiler backends, and other embedders can prepare transient Wasm
|
|
119
|
+
without modifying their producer toolchain:
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
import {
|
|
123
|
+
compileWithRuntimeInfo,
|
|
124
|
+
prepareModule,
|
|
125
|
+
} from "@gasm-compiler/core/browser";
|
|
126
|
+
|
|
127
|
+
const prepared = prepareModule(wasmBytes, {
|
|
128
|
+
demotionPolicy: { f64: "allow", i64: "allow-lossy" },
|
|
129
|
+
});
|
|
130
|
+
if (prepared.errors.length > 0) {
|
|
131
|
+
throw new Error(prepared.errors[0].message);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const result = compileWithRuntimeInfo(prepared.wasmBytes, {
|
|
135
|
+
...prepared.compileOptions,
|
|
136
|
+
mode: "strict",
|
|
137
|
+
});
|
|
138
|
+
if (!result.ok) throw new Error(result.diagnostics.errors[0].message);
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
`prepareModule()` defaults to integrator mode. It infers required extensions,
|
|
142
|
+
merges a stable `gasm.extensions` section, and returns binding and mutable-global
|
|
143
|
+
initialization data. Modules with undeclared mutable defined globals use the
|
|
144
|
+
v0.1 private-global compatibility path to avoid shared-storage races.
|
|
145
|
+
|
|
146
|
+
Use `{ mode: "strict" }` to analyze a distribution artifact without changing
|
|
147
|
+
its bytes. Strict compilation through `compile()` and
|
|
148
|
+
`compileWithDiagnostics()` remains unchanged and never injects extensions.
|
|
149
|
+
|
|
150
|
+
`compileWithRuntimeInfo()` is also available from the main and browser entry
|
|
151
|
+
points. It combines preparation, compilation, binding metadata, dispatch
|
|
152
|
+
information, and mutable-global initialization into one result.
|
|
153
|
+
|
|
52
154
|
### Basic Compilation
|
|
53
155
|
|
|
54
156
|
```typescript
|
|
@@ -82,7 +184,10 @@ const wgslCode = compile(wasmBytes, {
|
|
|
82
184
|
});
|
|
83
185
|
```
|
|
84
186
|
|
|
85
|
-
When enabled, WebAssembly imports like
|
|
187
|
+
When enabled, WebAssembly imports like
|
|
188
|
+
`(import "gasm" "sin_f32" (func ...))` compile to direct WGSL built-in calls
|
|
189
|
+
(`sin(...)`) with zero overhead. Unsuffixed scalar names such as `sin` remain
|
|
190
|
+
accepted as legacy aliases.
|
|
86
191
|
|
|
87
192
|
**Math Levels:**
|
|
88
193
|
- **M0 (Core):** sin, cos, sqrt, abs, min, max, clamp, floor, ceil, etc.
|
package/dist/browser.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as CompileDiagnostics, D as DispatchInfo$1, a as CompileOptions } from './error_codes-
|
|
2
|
-
export {
|
|
1
|
+
import { C as CompileDiagnostics, D as DispatchInfo$1, G as GasmMetadata, a as GasmBinding, P as PreparedModule, b as CompileOptions, c as PrepareModuleOptions } from './error_codes-5zCZDwFZ.js';
|
|
2
|
+
export { d as CompileError, h as DEFAULT_SPEC_VERSION, e as DemotionPolicy, f as Diagnostic, g as DiagnosticRecovery, o as ErrorCode, E as ErrorCodes, u as GasmMetadataEntryPoint, M as MutableGlobalsInit, x as PrepareMode, j as SPEC_VERSION_V01, k as SPEC_VERSION_V02, S as SpecVersion, w as buildBindingTable, s as buildGasmMetadata, l as isCompileError, n as isParseError, i as isV02Mode, m as parseWasmModule, p as prepareModule, r as resolveSpecVersion, v as validateGasmMetadataSchema } from './error_codes-5zCZDwFZ.js';
|
|
3
3
|
export { BrowserGPUExecutor } from './browser-executor.js';
|
|
4
4
|
export { BufferData, ExecuteOptions, ExecutionError, ExecutorConfig, IGPUExecutor, OutputBufferSpec, isExecutionError } from './executor.js';
|
|
5
5
|
|
|
@@ -67,6 +67,28 @@ type CompileWithDiagnosticsResult = {
|
|
|
67
67
|
ok: false;
|
|
68
68
|
diagnostics: CompileDiagnostics;
|
|
69
69
|
};
|
|
70
|
+
type CompileArtifactResult = {
|
|
71
|
+
ok: true;
|
|
72
|
+
wgsl: string;
|
|
73
|
+
metadata: GasmMetadata;
|
|
74
|
+
diagnostics: CompileDiagnostics;
|
|
75
|
+
dispatchInfo: DispatchInfo;
|
|
76
|
+
} | {
|
|
77
|
+
ok: false;
|
|
78
|
+
diagnostics: CompileDiagnostics;
|
|
79
|
+
};
|
|
80
|
+
type CompileWithRuntimeInfoResult = {
|
|
81
|
+
ok: true;
|
|
82
|
+
wgsl: string;
|
|
83
|
+
diagnostics: CompileDiagnostics;
|
|
84
|
+
dispatchInfo: DispatchInfo;
|
|
85
|
+
bindings: GasmBinding[];
|
|
86
|
+
metadata: GasmMetadata;
|
|
87
|
+
mutableGlobalsInit?: PreparedModule["mutableGlobalsInit"];
|
|
88
|
+
} | {
|
|
89
|
+
ok: false;
|
|
90
|
+
diagnostics: CompileDiagnostics;
|
|
91
|
+
};
|
|
70
92
|
interface BackendMismatchDetails {
|
|
71
93
|
kind: "wgsl" | "ok_mismatch" | "rust_error" | "diagnostics";
|
|
72
94
|
message: string;
|
|
@@ -88,6 +110,8 @@ interface BackendComparisonResult {
|
|
|
88
110
|
}
|
|
89
111
|
|
|
90
112
|
declare function compileWithDiagnostics(wasmBytes: Uint8Array, options?: CompileOptions): CompileWithDiagnosticsResult;
|
|
113
|
+
declare function compileToArtifact(wasmBytes: Uint8Array, options?: CompileOptions): CompileArtifactResult;
|
|
114
|
+
declare function compileWithRuntimeInfo(wasmBytes: Uint8Array, options?: PrepareModuleOptions): CompileWithRuntimeInfoResult;
|
|
91
115
|
declare function compileWithDiagnosticsAsync(wasmBytes: Uint8Array, options?: CompileOptions, initOptions?: InitRustCompilerOptions): Promise<CompileWithDiagnosticsResult>;
|
|
92
116
|
declare function compileWithBackendComparison(wasmBytes: Uint8Array, options?: CompileOptions, compareOptions?: {
|
|
93
117
|
funcName?: string;
|
|
@@ -98,4 +122,4 @@ declare function compileWithBackendComparisonAsync(wasmBytes: Uint8Array, option
|
|
|
98
122
|
declare function compile(wasmBytes: Uint8Array, options?: CompileOptions): string;
|
|
99
123
|
declare function compileAsync(wasmBytes: Uint8Array, options?: CompileOptions, initOptions?: InitRustCompilerOptions): Promise<string>;
|
|
100
124
|
|
|
101
|
-
export { type BackendComparisonResult, type BackendMismatchDetails, type BrowserCompilerBackend, CompileDiagnostics, CompileOptions, type CompileWithDiagnosticsResult, type DispatchInfo, type InitRustCompilerOptions, type WgslComparisonSummary, type WgslDiffOptions, compile, compileAsync, compileWithBackendComparison, compileWithBackendComparisonAsync, compileWithDiagnostics, compileWithDiagnosticsAsync, disassembleToWAT, exportWgslFunctionSnippet, formatUnifiedDiff, getBrowserCompilerBackend, initRustCompiler, isRustCompilerInitialized, normalizeWgslForComparison, preloadCompiler, setBrowserCompilerBackend, summarizeWgslComparison, waitForRustCompilerInit };
|
|
125
|
+
export { type BackendComparisonResult, type BackendMismatchDetails, type BrowserCompilerBackend, type CompileArtifactResult, CompileDiagnostics, CompileOptions, type CompileWithDiagnosticsResult, type CompileWithRuntimeInfoResult, type DispatchInfo, GasmBinding, GasmMetadata, type InitRustCompilerOptions, PrepareModuleOptions, PreparedModule, type WgslComparisonSummary, type WgslDiffOptions, compile, compileAsync, compileToArtifact, compileWithBackendComparison, compileWithBackendComparisonAsync, compileWithDiagnostics, compileWithDiagnosticsAsync, compileWithRuntimeInfo, disassembleToWAT, exportWgslFunctionSnippet, formatUnifiedDiff, getBrowserCompilerBackend, initRustCompiler, isRustCompilerInitialized, normalizeWgslForComparison, preloadCompiler, setBrowserCompilerBackend, summarizeWgslComparison, waitForRustCompilerInit };
|