miniray 0.2.2 → 0.3.1
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/README.md +71 -1
- package/esm/browser.js +38 -1
- package/lib/browser.js +21 -0
- package/lib/main.d.ts +63 -0
- package/lib/main.js +21 -0
- package/miniray.wasm +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -60,7 +60,7 @@ console.log(result.code);
|
|
|
60
60
|
|
|
61
61
|
### `initialize(options)`
|
|
62
62
|
|
|
63
|
-
Initialize the WASM module. Must be called before `minify()` or `
|
|
63
|
+
Initialize the WASM module. Must be called before `minify()`, `reflect()`, or `validate()`.
|
|
64
64
|
|
|
65
65
|
```typescript
|
|
66
66
|
interface InitializeOptions {
|
|
@@ -170,6 +170,76 @@ Memory layouts follow the WGSL specification:
|
|
|
170
170
|
- Struct members are aligned to their natural alignment
|
|
171
171
|
- Struct size is rounded up to struct alignment
|
|
172
172
|
|
|
173
|
+
### `validate(source, options?)`
|
|
174
|
+
|
|
175
|
+
Validate WGSL source for semantic errors, type mismatches, and uniformity violations.
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
interface ValidateOptions {
|
|
179
|
+
strictMode?: boolean; // Treat warnings as errors
|
|
180
|
+
diagnosticFilters?: Record<string, 'error' | 'warning' | 'info' | 'off'>;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
interface ValidateResult {
|
|
184
|
+
valid: boolean; // true if no errors
|
|
185
|
+
diagnostics: DiagnosticInfo[];
|
|
186
|
+
errorCount: number;
|
|
187
|
+
warningCount: number;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
interface DiagnosticInfo {
|
|
191
|
+
severity: 'error' | 'warning' | 'info' | 'note';
|
|
192
|
+
code?: string; // e.g., "E0200"
|
|
193
|
+
message: string;
|
|
194
|
+
line: number; // 1-based
|
|
195
|
+
column: number; // 1-based
|
|
196
|
+
endLine?: number;
|
|
197
|
+
endColumn?: number;
|
|
198
|
+
specRef?: string; // WGSL spec reference
|
|
199
|
+
}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
**Example:**
|
|
203
|
+
|
|
204
|
+
```javascript
|
|
205
|
+
const result = validate(`
|
|
206
|
+
fn foo() -> f32 {
|
|
207
|
+
var x: i32 = 1;
|
|
208
|
+
return x; // Error: returning i32 from f32 function
|
|
209
|
+
}
|
|
210
|
+
`);
|
|
211
|
+
|
|
212
|
+
console.log(result.valid); // false
|
|
213
|
+
console.log(result.errorCount); // 1
|
|
214
|
+
console.log(result.diagnostics[0]);
|
|
215
|
+
// {
|
|
216
|
+
// severity: "error",
|
|
217
|
+
// code: "E0200",
|
|
218
|
+
// message: "cannot return 'i32' from function returning 'f32'",
|
|
219
|
+
// line: 4,
|
|
220
|
+
// column: 5
|
|
221
|
+
// }
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
**With options:**
|
|
225
|
+
|
|
226
|
+
```javascript
|
|
227
|
+
const result = validate(source, {
|
|
228
|
+
strictMode: true, // Treat warnings as errors
|
|
229
|
+
diagnosticFilters: {
|
|
230
|
+
derivative_uniformity: 'off', // Disable uniformity warnings
|
|
231
|
+
},
|
|
232
|
+
});
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
**Validation checks:**
|
|
236
|
+
- Type mismatches (assignments, returns, function calls)
|
|
237
|
+
- Undefined symbols (variables, functions, types)
|
|
238
|
+
- Invalid operations (operators, indexing, member access)
|
|
239
|
+
- Entry point requirements
|
|
240
|
+
- Uniformity analysis (textureSample, derivatives)
|
|
241
|
+
- WGSL spec compliance
|
|
242
|
+
|
|
173
243
|
### `isInitialized()`
|
|
174
244
|
|
|
175
245
|
Returns `true` if the WASM module is initialized.
|
package/esm/browser.js
CHANGED
|
@@ -138,6 +138,43 @@ export function minify(source, options) {
|
|
|
138
138
|
return globalThis.__miniray.minify(source, options || {});
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
+
/**
|
|
142
|
+
* Reflect WGSL source to extract binding and struct information.
|
|
143
|
+
* @param {string} source - WGSL source code
|
|
144
|
+
* @returns {Object} Reflection result with bindings, structs, entryPoints, and errors
|
|
145
|
+
*/
|
|
146
|
+
export function reflect(source) {
|
|
147
|
+
if (!_initialized) {
|
|
148
|
+
throw new Error('miniray not initialized. Call initialize() first.');
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (typeof source !== 'string') {
|
|
152
|
+
throw new Error('source must be a string');
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return globalThis.__miniray.reflect(source);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Validate WGSL source code.
|
|
160
|
+
* @param {string} source - WGSL source code
|
|
161
|
+
* @param {Object} [options] - Validation options
|
|
162
|
+
* @param {boolean} [options.strictMode] - Treat warnings as errors
|
|
163
|
+
* @param {Object} [options.diagnosticFilters] - Map of rule name to severity
|
|
164
|
+
* @returns {Object} Validation result with valid, diagnostics, errorCount, warningCount
|
|
165
|
+
*/
|
|
166
|
+
export function validate(source, options) {
|
|
167
|
+
if (!_initialized) {
|
|
168
|
+
throw new Error('miniray not initialized. Call initialize() first.');
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (typeof source !== 'string') {
|
|
172
|
+
throw new Error('source must be a string');
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return globalThis.__miniray.validate(source, options || {});
|
|
176
|
+
}
|
|
177
|
+
|
|
141
178
|
/**
|
|
142
179
|
* Check if initialized.
|
|
143
180
|
* @returns {boolean}
|
|
@@ -163,4 +200,4 @@ export const version = (() => {
|
|
|
163
200
|
})();
|
|
164
201
|
|
|
165
202
|
// Default export for convenience
|
|
166
|
-
export default { initialize, minify, isInitialized, version };
|
|
203
|
+
export default { initialize, minify, reflect, validate, isInitialized, version };
|
package/lib/browser.js
CHANGED
|
@@ -166,6 +166,26 @@
|
|
|
166
166
|
return globalThis.__miniray.reflect(source);
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
+
/**
|
|
170
|
+
* Validate WGSL source code.
|
|
171
|
+
* @param {string} source - WGSL source code
|
|
172
|
+
* @param {Object} [options] - Validation options
|
|
173
|
+
* @param {boolean} [options.strictMode] - Treat warnings as errors
|
|
174
|
+
* @param {Object} [options.diagnosticFilters] - Map of rule name to severity
|
|
175
|
+
* @returns {Object} Validation result with valid, diagnostics, errorCount, warningCount
|
|
176
|
+
*/
|
|
177
|
+
function validate(source, options) {
|
|
178
|
+
if (!_initialized) {
|
|
179
|
+
throw new Error('miniray not initialized. Call initialize() first.');
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (typeof source !== 'string') {
|
|
183
|
+
throw new Error('source must be a string');
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return globalThis.__miniray.validate(source, options || {});
|
|
187
|
+
}
|
|
188
|
+
|
|
169
189
|
/**
|
|
170
190
|
* Check if initialized.
|
|
171
191
|
* @returns {boolean}
|
|
@@ -189,6 +209,7 @@
|
|
|
189
209
|
initialize: initialize,
|
|
190
210
|
minify: minify,
|
|
191
211
|
reflect: reflect,
|
|
212
|
+
validate: validate,
|
|
192
213
|
isInitialized: isInitialized,
|
|
193
214
|
get version() { return getVersion(); }
|
|
194
215
|
};
|
package/lib/main.d.ts
CHANGED
|
@@ -151,6 +151,60 @@ export interface EntryPointInfo {
|
|
|
151
151
|
workgroupSize: [number, number, number] | null;
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
+
/**
|
|
155
|
+
* Options for WGSL validation.
|
|
156
|
+
*/
|
|
157
|
+
export interface ValidateOptions {
|
|
158
|
+
/**
|
|
159
|
+
* Treat warnings as errors.
|
|
160
|
+
* @default false
|
|
161
|
+
*/
|
|
162
|
+
strictMode?: boolean;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Map of diagnostic rule names to their severity override.
|
|
166
|
+
* Rules: "derivative_uniformity", "subgroup_uniformity"
|
|
167
|
+
* Severities: "error", "warning", "info", "off"
|
|
168
|
+
*/
|
|
169
|
+
diagnosticFilters?: Record<string, "error" | "warning" | "info" | "off">;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* A single validation diagnostic message.
|
|
174
|
+
*/
|
|
175
|
+
export interface DiagnosticInfo {
|
|
176
|
+
/** Severity: "error", "warning", "info", or "note" */
|
|
177
|
+
severity: "error" | "warning" | "info" | "note";
|
|
178
|
+
/** Error code (e.g., "E0200" for type mismatch) */
|
|
179
|
+
code?: string;
|
|
180
|
+
/** Human-readable error message */
|
|
181
|
+
message: string;
|
|
182
|
+
/** Line number (1-based) */
|
|
183
|
+
line: number;
|
|
184
|
+
/** Column number (1-based) */
|
|
185
|
+
column: number;
|
|
186
|
+
/** End line number (1-based), if available */
|
|
187
|
+
endLine?: number;
|
|
188
|
+
/** End column number (1-based), if available */
|
|
189
|
+
endColumn?: number;
|
|
190
|
+
/** Reference to WGSL spec section */
|
|
191
|
+
specRef?: string;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Result of WGSL validation.
|
|
196
|
+
*/
|
|
197
|
+
export interface ValidateResult {
|
|
198
|
+
/** Whether the shader is valid (no errors) */
|
|
199
|
+
valid: boolean;
|
|
200
|
+
/** All validation diagnostics */
|
|
201
|
+
diagnostics: DiagnosticInfo[];
|
|
202
|
+
/** Number of error-level diagnostics */
|
|
203
|
+
errorCount: number;
|
|
204
|
+
/** Number of warning-level diagnostics */
|
|
205
|
+
warningCount: number;
|
|
206
|
+
}
|
|
207
|
+
|
|
154
208
|
/**
|
|
155
209
|
* Options for initializing the WASM module.
|
|
156
210
|
*/
|
|
@@ -189,6 +243,15 @@ export function minify(source: string, options?: MinifyOptions): MinifyResult;
|
|
|
189
243
|
*/
|
|
190
244
|
export function reflect(source: string): ReflectResult;
|
|
191
245
|
|
|
246
|
+
/**
|
|
247
|
+
* Validate WGSL source code for errors and warnings.
|
|
248
|
+
* Performs full semantic validation compatible with the Dawn Tint compiler.
|
|
249
|
+
* @param source - WGSL source code to validate
|
|
250
|
+
* @param options - Validation options
|
|
251
|
+
* @returns Validation result with valid flag, diagnostics, and counts
|
|
252
|
+
*/
|
|
253
|
+
export function validate(source: string, options?: ValidateOptions): ValidateResult;
|
|
254
|
+
|
|
192
255
|
/**
|
|
193
256
|
* Check if the WASM module is initialized.
|
|
194
257
|
*/
|
package/lib/main.js
CHANGED
|
@@ -158,6 +158,26 @@ function reflect(source) {
|
|
|
158
158
|
return global.__miniray.reflect(source);
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
+
/**
|
|
162
|
+
* Validate WGSL source code.
|
|
163
|
+
* @param {string} source - WGSL source code
|
|
164
|
+
* @param {Object} [options] - Validation options
|
|
165
|
+
* @param {boolean} [options.strictMode] - Treat warnings as errors
|
|
166
|
+
* @param {Object} [options.diagnosticFilters] - Map of rule name to severity ("error", "warning", "info", "off")
|
|
167
|
+
* @returns {Object} Validation result with valid, diagnostics, errorCount, warningCount
|
|
168
|
+
*/
|
|
169
|
+
function validate(source, options) {
|
|
170
|
+
if (!_initialized) {
|
|
171
|
+
throw new Error('miniray not initialized. Call initialize() first.');
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (typeof source !== 'string') {
|
|
175
|
+
throw new Error('source must be a string');
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return global.__miniray.validate(source, options || {});
|
|
179
|
+
}
|
|
180
|
+
|
|
161
181
|
/**
|
|
162
182
|
* Check if initialized.
|
|
163
183
|
* @returns {boolean}
|
|
@@ -181,6 +201,7 @@ module.exports = {
|
|
|
181
201
|
initialize,
|
|
182
202
|
minify,
|
|
183
203
|
reflect,
|
|
204
|
+
validate,
|
|
184
205
|
isInitialized,
|
|
185
206
|
get version() { return getVersion(); }
|
|
186
207
|
};
|
package/miniray.wasm
CHANGED
|
Binary file
|