wgsl-test 0.2.22 → 0.2.24
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/dist/runTestCli.js +34 -215
- package/dist/runTestCli.js.map +1 -1
- package/package.json +4 -4
package/dist/runTestCli.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node --experimental-strip-types
|
|
2
|
-
import "
|
|
3
|
-
import "@reactively/decorate";
|
|
2
|
+
import { copyBuffer, elementStride } from "thimbleberry";
|
|
4
3
|
import * as path$1 from "node:path";
|
|
5
4
|
import path, { posix, win32 } from "node:path";
|
|
6
5
|
import { URL as URL$1, fileURLToPath, pathToFileURL } from "node:url";
|
|
@@ -202,7 +201,7 @@ var ErrorWithData = class extends Error {
|
|
|
202
201
|
//#endregion
|
|
203
202
|
//#region ../wesl/src/Util.ts
|
|
204
203
|
/** return the last element of an array or undefined */
|
|
205
|
-
function last
|
|
204
|
+
function last(a) {
|
|
206
205
|
return a[a.length - 1];
|
|
207
206
|
}
|
|
208
207
|
/** filter an array, returning the truthy results of the filter function */
|
|
@@ -1053,15 +1052,15 @@ function makeUnaryExpression(operator, expr) {
|
|
|
1053
1052
|
end: expr.end
|
|
1054
1053
|
};
|
|
1055
1054
|
}
|
|
1056
|
-
function makeBinaryExpression(left
|
|
1057
|
-
const { start } = left
|
|
1055
|
+
function makeBinaryExpression(left, operator, right) {
|
|
1056
|
+
const { start } = left;
|
|
1058
1057
|
return {
|
|
1059
1058
|
kind: "binary-expression",
|
|
1060
1059
|
operator,
|
|
1061
|
-
left
|
|
1062
|
-
right
|
|
1060
|
+
left,
|
|
1061
|
+
right,
|
|
1063
1062
|
start,
|
|
1064
|
-
end: right
|
|
1063
|
+
end: right.end
|
|
1065
1064
|
};
|
|
1066
1065
|
}
|
|
1067
1066
|
function makeComponentExpression(base, access, end) {
|
|
@@ -1483,9 +1482,9 @@ function parseUnaryExpression(ctx, conditionRef) {
|
|
|
1483
1482
|
*/
|
|
1484
1483
|
function parseBinaryExpr(ctx, args) {
|
|
1485
1484
|
const { stream: stream$1 } = ctx;
|
|
1486
|
-
const { prec: minPrecedence, left
|
|
1485
|
+
const { prec: minPrecedence, left, group: leftGroup } = args;
|
|
1487
1486
|
const { condRef, inTemplate } = args;
|
|
1488
|
-
let current = left
|
|
1487
|
+
let current = left;
|
|
1489
1488
|
let currentGroup = leftGroup;
|
|
1490
1489
|
while (true) {
|
|
1491
1490
|
const opToken = stream$1.peek();
|
|
@@ -1494,20 +1493,20 @@ function parseBinaryExpr(ctx, args) {
|
|
|
1494
1493
|
if (precedence < minPrecedence) break;
|
|
1495
1494
|
stream$1.nextToken();
|
|
1496
1495
|
currentGroup = checkOpBinding(stream$1, opToken.text, currentGroup);
|
|
1497
|
-
let right
|
|
1498
|
-
if (!right
|
|
1496
|
+
let right = parseUnaryExpression(ctx, condRef);
|
|
1497
|
+
if (!right) throwParseError(stream$1, "Expected expression after binary operator");
|
|
1499
1498
|
const nextToken = stream$1.peek();
|
|
1500
1499
|
if (isBinaryOpInContext(nextToken, inTemplate)) {
|
|
1501
1500
|
const nextPrec = getPrecedence(nextToken);
|
|
1502
|
-
if (nextPrec > precedence) right
|
|
1501
|
+
if (nextPrec > precedence) right = parseBinaryExpr(ctx, {
|
|
1503
1502
|
prec: nextPrec,
|
|
1504
|
-
left: right
|
|
1503
|
+
left: right,
|
|
1505
1504
|
group: "unary",
|
|
1506
1505
|
condRef,
|
|
1507
1506
|
inTemplate
|
|
1508
1507
|
}).expr;
|
|
1509
1508
|
}
|
|
1510
|
-
current = makeBinaryExpression(current, makeBinaryOperator(opToken), right
|
|
1509
|
+
current = makeBinaryExpression(current, makeBinaryOperator(opToken), right);
|
|
1511
1510
|
}
|
|
1512
1511
|
return {
|
|
1513
1512
|
expr: current,
|
|
@@ -3373,6 +3372,7 @@ const wgslStandardAttributes = new Set([
|
|
|
3373
3372
|
function bindIdents(params$1) {
|
|
3374
3373
|
const { rootAst, resolver, virtuals, accumulateUnbound } = params$1;
|
|
3375
3374
|
const { conditions = {}, mangler = minimalMangle } = params$1;
|
|
3375
|
+
const packageName = rootAst.srcModule.modulePath.split("::")[0];
|
|
3376
3376
|
const validRootDecls = findValidRootDecls(rootAst.rootScope, conditions);
|
|
3377
3377
|
const { globalNames, knownDecls } = initRootDecls(validRootDecls);
|
|
3378
3378
|
const bindContext = {
|
|
@@ -3381,6 +3381,7 @@ function bindIdents(params$1) {
|
|
|
3381
3381
|
knownDecls,
|
|
3382
3382
|
virtuals,
|
|
3383
3383
|
mangler,
|
|
3384
|
+
packageName,
|
|
3384
3385
|
foundScopes: /* @__PURE__ */ new Set(),
|
|
3385
3386
|
globalNames,
|
|
3386
3387
|
globalStatements: /* @__PURE__ */ new Map(),
|
|
@@ -3555,25 +3556,25 @@ function matchingImport(identParts, imports) {
|
|
|
3555
3556
|
}
|
|
3556
3557
|
/** @return an exported root declIdent for the provided path. */
|
|
3557
3558
|
function findExport(pathParts, srcModule, ctx) {
|
|
3558
|
-
const { resolver, conditions, virtuals } = ctx;
|
|
3559
3559
|
const modulePath = resolveModulePath(pathParts, srcModule.modulePath.split("::")).slice(0, -1).join("::");
|
|
3560
|
-
const moduleAst = resolver.resolveModule(modulePath) ?? virtualModule(pathParts[0],
|
|
3560
|
+
const moduleAst = ctx.resolver.resolveModule(modulePath) ?? virtualModule(pathParts[0], ctx);
|
|
3561
3561
|
if (!moduleAst) return void 0;
|
|
3562
|
-
const decl = publicDecl(moduleAst.rootScope, last
|
|
3562
|
+
const decl = publicDecl(moduleAst.rootScope, last(pathParts), ctx.conditions);
|
|
3563
3563
|
if (decl) return {
|
|
3564
3564
|
decl,
|
|
3565
3565
|
moduleAst
|
|
3566
3566
|
};
|
|
3567
3567
|
}
|
|
3568
3568
|
/** @return AST for a virtual module. */
|
|
3569
|
-
function virtualModule(moduleName,
|
|
3570
|
-
const found = virtuals?.[moduleName];
|
|
3569
|
+
function virtualModule(moduleName, ctx) {
|
|
3570
|
+
const found = ctx.virtuals?.[moduleName];
|
|
3571
3571
|
if (!found) return void 0;
|
|
3572
3572
|
if (found.ast) return found.ast;
|
|
3573
|
+
const src = found.fn(ctx.conditions);
|
|
3573
3574
|
found.ast = parseSrcModule({
|
|
3574
|
-
modulePath: moduleName,
|
|
3575
|
+
modulePath: ctx.packageName + "::" + moduleName,
|
|
3575
3576
|
debugFilePath: moduleName,
|
|
3576
|
-
src
|
|
3577
|
+
src
|
|
3577
3578
|
});
|
|
3578
3579
|
return found.ast;
|
|
3579
3580
|
}
|
|
@@ -3643,6 +3644,7 @@ function findUnboundRefs(resolver) {
|
|
|
3643
3644
|
globalNames: /* @__PURE__ */ new Set(),
|
|
3644
3645
|
globalStatements: /* @__PURE__ */ new Map(),
|
|
3645
3646
|
mangler: minimalMangle,
|
|
3647
|
+
packageName: "package",
|
|
3646
3648
|
unbound: [],
|
|
3647
3649
|
dontFollowDecls: true
|
|
3648
3650
|
};
|
|
@@ -3936,8 +3938,8 @@ function fileToModulePath(filePath, packageName, treatLibAsRoot) {
|
|
|
3936
3938
|
}
|
|
3937
3939
|
/** Try path variants with/without ./ prefix and extension suffixes. */
|
|
3938
3940
|
function findInVariants(sources, basePath, extensions = ["wesl", "wgsl"]) {
|
|
3939
|
-
for (const prefix
|
|
3940
|
-
const path$3 = prefix
|
|
3941
|
+
for (const prefix of ["", "./"]) {
|
|
3942
|
+
const path$3 = prefix + basePath;
|
|
3941
3943
|
if (sources[path$3] !== void 0) return sources[path$3];
|
|
3942
3944
|
for (const ext$1 of extensions) {
|
|
3943
3945
|
const withExt = `${path$3}.${ext$1}`;
|
|
@@ -4275,189 +4277,6 @@ const textureStorage = matchOneOf(textureStorageTypes);
|
|
|
4275
4277
|
const textureTypes = matchOneOf(sampledTextureTypes);
|
|
4276
4278
|
const multiNames = matchOneOf(multisampledTextureTypes);
|
|
4277
4279
|
|
|
4278
|
-
//#endregion
|
|
4279
|
-
//#region ../../node_modules/.pnpm/berry-pretty@0.0.4/node_modules/berry-pretty/dist/index.js
|
|
4280
|
-
var spaces = memoize((nesting) => {
|
|
4281
|
-
return " ".repeat(nesting);
|
|
4282
|
-
});
|
|
4283
|
-
var defaultCallerSize = 20;
|
|
4284
|
-
var multiLinePad = "\n" + spaces(defaultCallerSize + 3);
|
|
4285
|
-
function memoize(fn) {
|
|
4286
|
-
const cache$1 = /* @__PURE__ */ new Map();
|
|
4287
|
-
return function(...args) {
|
|
4288
|
-
const key = JSON.stringify(args);
|
|
4289
|
-
if (cache$1.has(key)) return cache$1.get(key);
|
|
4290
|
-
else {
|
|
4291
|
-
const value = fn(...args);
|
|
4292
|
-
cache$1.set(key, value);
|
|
4293
|
-
return value;
|
|
4294
|
-
}
|
|
4295
|
-
};
|
|
4296
|
-
}
|
|
4297
|
-
if (typeof DOMRect === "undefined") globalThis.DOMRect = function() {};
|
|
4298
|
-
|
|
4299
|
-
//#endregion
|
|
4300
|
-
//#region ../../node_modules/.pnpm/thimbleberry@0.2.10/node_modules/thimbleberry/dist/thimbleberry.js
|
|
4301
|
-
function memoMemo(fn, options) {
|
|
4302
|
-
const memoizer = options?.memoCache || persistentMemoCache;
|
|
4303
|
-
const keyFn = options?.keyFn || defaultKeyFn;
|
|
4304
|
-
const cache$1 = memoizer();
|
|
4305
|
-
return function(...args) {
|
|
4306
|
-
const key = keyFn(...args);
|
|
4307
|
-
const found = cache$1.get(key);
|
|
4308
|
-
if (found !== void 0) return found;
|
|
4309
|
-
else {
|
|
4310
|
-
const value = fn(...args);
|
|
4311
|
-
cache$1.set(key, value);
|
|
4312
|
-
return value;
|
|
4313
|
-
}
|
|
4314
|
-
};
|
|
4315
|
-
}
|
|
4316
|
-
function persistentMemoCache() {
|
|
4317
|
-
return /* @__PURE__ */ new Map();
|
|
4318
|
-
}
|
|
4319
|
-
function defaultKeyFn(...args) {
|
|
4320
|
-
return JSON.stringify(args[0] ?? "");
|
|
4321
|
-
}
|
|
4322
|
-
function memoizeWithDevice(fn) {
|
|
4323
|
-
const keyFn = cacheKeyWithDevice;
|
|
4324
|
-
let memoFn;
|
|
4325
|
-
return function(paramsObj, memoCache) {
|
|
4326
|
-
if (!memoFn) memoFn = memoMemo(fn, {
|
|
4327
|
-
keyFn,
|
|
4328
|
-
memoCache
|
|
4329
|
-
});
|
|
4330
|
-
return memoFn(paramsObj);
|
|
4331
|
-
};
|
|
4332
|
-
}
|
|
4333
|
-
function cacheKeyWithDevice(paramsObj) {
|
|
4334
|
-
const deviceStr = `device: ${paramsObj.device?.label ?? "."}`;
|
|
4335
|
-
const withoutDevice = { ...paramsObj };
|
|
4336
|
-
delete withoutDevice["device"];
|
|
4337
|
-
return `${JSON.stringify({ ...withoutDevice })}; ${deviceStr}`;
|
|
4338
|
-
}
|
|
4339
|
-
function filledGPUBuffer(device$1, data, usage = GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST | GPUBufferUsage.STORAGE, label, ArrayConstructor = Float32Array) {
|
|
4340
|
-
const buffer = device$1.createBuffer({
|
|
4341
|
-
label,
|
|
4342
|
-
size: data.length * ArrayConstructor.BYTES_PER_ELEMENT,
|
|
4343
|
-
usage,
|
|
4344
|
-
mappedAtCreation: true
|
|
4345
|
-
});
|
|
4346
|
-
new ArrayConstructor(buffer.getMappedRange()).set(data);
|
|
4347
|
-
buffer.unmap();
|
|
4348
|
-
return buffer;
|
|
4349
|
-
}
|
|
4350
|
-
var [top, bottom] = [1, -1];
|
|
4351
|
-
var [left, right] = [-1, 1];
|
|
4352
|
-
var fullFrameTriangleStrip = [
|
|
4353
|
-
[left, bottom],
|
|
4354
|
-
[left, top],
|
|
4355
|
-
[right, top],
|
|
4356
|
-
[right, bottom],
|
|
4357
|
-
[left, bottom]
|
|
4358
|
-
];
|
|
4359
|
-
var resources = /* @__PURE__ */ new WeakMap();
|
|
4360
|
-
var autoContextStack = [];
|
|
4361
|
-
var trackCount = 0;
|
|
4362
|
-
function trackUse(target, context) {
|
|
4363
|
-
const refCount = resources.get(target) || 0;
|
|
4364
|
-
if (refCount === 0) trackCount++;
|
|
4365
|
-
resources.set(target, refCount + 1);
|
|
4366
|
-
last(autoContextStack)?._addRef(target);
|
|
4367
|
-
context?._addRef(target);
|
|
4368
|
-
return target;
|
|
4369
|
-
}
|
|
4370
|
-
function last(a) {
|
|
4371
|
-
return a[a.length - 1];
|
|
4372
|
-
}
|
|
4373
|
-
var fullFrameVertexBuffer = memoizeWithDevice(createFrameVertexBuffer);
|
|
4374
|
-
function createFrameVertexBuffer(params$1) {
|
|
4375
|
-
const { device: device$1 } = params$1;
|
|
4376
|
-
const verts = fullFrameTriangleStrip.flat();
|
|
4377
|
-
const usage = GPUBufferUsage.VERTEX;
|
|
4378
|
-
const buffer = filledGPUBuffer(device$1, verts, usage, "full-screen-verts", Float32Array);
|
|
4379
|
-
trackUse(buffer);
|
|
4380
|
-
return buffer;
|
|
4381
|
-
}
|
|
4382
|
-
async function withBufferCopy(device$1, buffer, fmt, fn) {
|
|
4383
|
-
const size = buffer.size;
|
|
4384
|
-
const copy = device$1.createBuffer({
|
|
4385
|
-
size,
|
|
4386
|
-
usage: GPUBufferUsage.MAP_READ | GPUBufferUsage.COPY_DST
|
|
4387
|
-
});
|
|
4388
|
-
const commands = device$1.createCommandEncoder({});
|
|
4389
|
-
commands.copyBufferToBuffer(buffer, 0, copy, 0, size);
|
|
4390
|
-
const cmdBuffer = commands.finish();
|
|
4391
|
-
device$1.queue.submit([cmdBuffer]);
|
|
4392
|
-
await copy.mapAsync(GPUMapMode.READ);
|
|
4393
|
-
const cpuCopy = arrayForType(fmt, copy.getMappedRange());
|
|
4394
|
-
try {
|
|
4395
|
-
return fn(cpuCopy);
|
|
4396
|
-
} finally {
|
|
4397
|
-
copy.unmap();
|
|
4398
|
-
copy.destroy();
|
|
4399
|
-
}
|
|
4400
|
-
}
|
|
4401
|
-
async function copyBuffer(device$1, buffer, fmt = "u32") {
|
|
4402
|
-
return withBufferCopy(device$1, buffer, fmt, (d) => [...d]);
|
|
4403
|
-
}
|
|
4404
|
-
function arrayForType(type, data) {
|
|
4405
|
-
if (type === "f32" || type.endsWith("f") || type.endsWith("h")) return new Float32Array(data);
|
|
4406
|
-
if (type === "u8") return new Uint8Array(data);
|
|
4407
|
-
if (type === "u32") return new Uint32Array(data);
|
|
4408
|
-
if (type === "i32") return new Int32Array(data);
|
|
4409
|
-
if (type === "i8") return new Int8Array(data);
|
|
4410
|
-
throw new Error(`Unknown type: ${type}`);
|
|
4411
|
-
}
|
|
4412
|
-
function elementStride(fmt) {
|
|
4413
|
-
let numSlots;
|
|
4414
|
-
let elemSize;
|
|
4415
|
-
if (fmt.startsWith("vec")) {
|
|
4416
|
-
elemSize = suffixTypeBytes(fmt.slice(-1));
|
|
4417
|
-
const size = fmt[3];
|
|
4418
|
-
if (size === "2") numSlots = 2;
|
|
4419
|
-
else if (size === "3" || size === "4") numSlots = 4;
|
|
4420
|
-
else throw new Error(`Unknown vector size: ${fmt}`);
|
|
4421
|
-
} else if (fmt.startsWith("mat")) {
|
|
4422
|
-
elemSize = suffixTypeBytes(fmt.slice(-1));
|
|
4423
|
-
const matSize = fmt.slice(3, 6);
|
|
4424
|
-
if (matSize === "2x2") numSlots = 4;
|
|
4425
|
-
else if (matSize === "2x3" || matSize === "3x2" || matSize === "2x4" || matSize === "4x2") numSlots = 8;
|
|
4426
|
-
else if (matSize === "3x3" || matSize === "3x4" || matSize === "4x3") numSlots = 12;
|
|
4427
|
-
else if (matSize === "4x4") numSlots = 16;
|
|
4428
|
-
else throw new Error(`Unknown matrix size: ${fmt}`);
|
|
4429
|
-
} else {
|
|
4430
|
-
numSlots = 1;
|
|
4431
|
-
const found = fmt.match(/\d+/);
|
|
4432
|
-
elemSize = Number.parseInt(found?.[0]) / 8;
|
|
4433
|
-
}
|
|
4434
|
-
return elemSize * numSlots;
|
|
4435
|
-
}
|
|
4436
|
-
function suffixTypeBytes(suffix) {
|
|
4437
|
-
switch (suffix) {
|
|
4438
|
-
case "f":
|
|
4439
|
-
case "u":
|
|
4440
|
-
case "i": return 4;
|
|
4441
|
-
case "h": return 2;
|
|
4442
|
-
default: throw new Error(`Unknown suffix: ${suffix}`);
|
|
4443
|
-
}
|
|
4444
|
-
}
|
|
4445
|
-
var placeholderTexture = memoMemo(makePlaceholderTexture);
|
|
4446
|
-
function makePlaceholderTexture(device$1) {
|
|
4447
|
-
return device$1.createTexture({
|
|
4448
|
-
label: "placeholder texture",
|
|
4449
|
-
size: [50, 50],
|
|
4450
|
-
format: "rgba8unorm",
|
|
4451
|
-
usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_DST | GPUTextureUsage.COPY_SRC
|
|
4452
|
-
});
|
|
4453
|
-
}
|
|
4454
|
-
var prefix = /\s*/.source;
|
|
4455
|
-
var findUnquoted = /(?<findUnquoted>[\w-<>.]+)/.source;
|
|
4456
|
-
var findQuoted = /"(?<findQuoted>[^=]+)"/.source;
|
|
4457
|
-
var replaceKey = /\s*(?<replaceKey>[\w-]+)/.source;
|
|
4458
|
-
var replaceValue = /\s*"(?<replaceValue>[^"]+)"/.source;
|
|
4459
|
-
var parseRule = new RegExp(`${prefix}(${findUnquoted}|${findQuoted})=(${replaceKey}|${replaceValue})`, "g");
|
|
4460
|
-
|
|
4461
4280
|
//#endregion
|
|
4462
4281
|
//#region ../wesl-tooling/src/FileModuleResolver.ts
|
|
4463
4282
|
/**
|
|
@@ -4562,14 +4381,14 @@ const maybeMatch = (reg, str) => {
|
|
|
4562
4381
|
return m ? m[0] : null;
|
|
4563
4382
|
};
|
|
4564
4383
|
const range = (a, b, str) => {
|
|
4565
|
-
let begs, beg, left
|
|
4384
|
+
let begs, beg, left, right = void 0, result;
|
|
4566
4385
|
let ai = str.indexOf(a);
|
|
4567
4386
|
let bi = str.indexOf(b, ai + 1);
|
|
4568
4387
|
let i = ai;
|
|
4569
4388
|
if (ai >= 0 && bi > 0) {
|
|
4570
4389
|
if (a === b) return [ai, bi];
|
|
4571
4390
|
begs = [];
|
|
4572
|
-
left
|
|
4391
|
+
left = str.length;
|
|
4573
4392
|
while (i >= 0 && !result) {
|
|
4574
4393
|
if (i === ai) {
|
|
4575
4394
|
begs.push(i);
|
|
@@ -4579,15 +4398,15 @@ const range = (a, b, str) => {
|
|
|
4579
4398
|
if (r !== void 0) result = [r, bi];
|
|
4580
4399
|
} else {
|
|
4581
4400
|
beg = begs.pop();
|
|
4582
|
-
if (beg !== void 0 && beg < left
|
|
4583
|
-
left
|
|
4584
|
-
right
|
|
4401
|
+
if (beg !== void 0 && beg < left) {
|
|
4402
|
+
left = beg;
|
|
4403
|
+
right = bi;
|
|
4585
4404
|
}
|
|
4586
4405
|
bi = str.indexOf(b, i + 1);
|
|
4587
4406
|
}
|
|
4588
4407
|
i = ai < bi && ai >= 0 ? ai : bi;
|
|
4589
4408
|
}
|
|
4590
|
-
if (begs.length && right
|
|
4409
|
+
if (begs.length && right !== void 0) result = [left, right];
|
|
4591
4410
|
}
|
|
4592
4411
|
return result;
|
|
4593
4412
|
};
|
|
@@ -10492,8 +10311,8 @@ var require_parser = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
10492
10311
|
type: "literal",
|
|
10493
10312
|
value: "E",
|
|
10494
10313
|
description: "\"E\""
|
|
10495
|
-
}, peg$c42 = function(left
|
|
10496
|
-
return node("Float", parseFloat(left
|
|
10314
|
+
}, peg$c42 = function(left, right) {
|
|
10315
|
+
return node("Float", parseFloat(left + "e" + right), line, column);
|
|
10497
10316
|
}, peg$c43 = function(text) {
|
|
10498
10317
|
return node("Float", parseFloat(text), line, column);
|
|
10499
10318
|
}, peg$c44 = "+", peg$c45 = {
|