wgsl-test 0.2.23 → 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.
@@ -1,6 +1,5 @@
1
1
  #!/usr/bin/env node --experimental-strip-types
2
- import "@reactively/core";
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$1(a) {
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$1, operator, right$1) {
1057
- const { start } = left$1;
1055
+ function makeBinaryExpression(left, operator, right) {
1056
+ const { start } = left;
1058
1057
  return {
1059
1058
  kind: "binary-expression",
1060
1059
  operator,
1061
- left: left$1,
1062
- right: right$1,
1060
+ left,
1061
+ right,
1063
1062
  start,
1064
- end: right$1.end
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: left$1, group: leftGroup } = args;
1485
+ const { prec: minPrecedence, left, group: leftGroup } = args;
1487
1486
  const { condRef, inTemplate } = args;
1488
- let current = left$1;
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$1 = parseUnaryExpression(ctx, condRef);
1498
- if (!right$1) throwParseError(stream$1, "Expected expression after binary operator");
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$1 = parseBinaryExpr(ctx, {
1501
+ if (nextPrec > precedence) right = parseBinaryExpr(ctx, {
1503
1502
  prec: nextPrec,
1504
- left: right$1,
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$1);
1509
+ current = makeBinaryExpression(current, makeBinaryOperator(opToken), right);
1511
1510
  }
1512
1511
  return {
1513
1512
  expr: current,
@@ -3560,7 +3559,7 @@ function findExport(pathParts, srcModule, ctx) {
3560
3559
  const modulePath = resolveModulePath(pathParts, srcModule.modulePath.split("::")).slice(0, -1).join("::");
3561
3560
  const moduleAst = ctx.resolver.resolveModule(modulePath) ?? virtualModule(pathParts[0], ctx);
3562
3561
  if (!moduleAst) return void 0;
3563
- const decl = publicDecl(moduleAst.rootScope, last$1(pathParts), ctx.conditions);
3562
+ const decl = publicDecl(moduleAst.rootScope, last(pathParts), ctx.conditions);
3564
3563
  if (decl) return {
3565
3564
  decl,
3566
3565
  moduleAst
@@ -3939,8 +3938,8 @@ function fileToModulePath(filePath, packageName, treatLibAsRoot) {
3939
3938
  }
3940
3939
  /** Try path variants with/without ./ prefix and extension suffixes. */
3941
3940
  function findInVariants(sources, basePath, extensions = ["wesl", "wgsl"]) {
3942
- for (const prefix$1 of ["", "./"]) {
3943
- const path$3 = prefix$1 + basePath;
3941
+ for (const prefix of ["", "./"]) {
3942
+ const path$3 = prefix + basePath;
3944
3943
  if (sources[path$3] !== void 0) return sources[path$3];
3945
3944
  for (const ext$1 of extensions) {
3946
3945
  const withExt = `${path$3}.${ext$1}`;
@@ -4278,189 +4277,6 @@ const textureStorage = matchOneOf(textureStorageTypes);
4278
4277
  const textureTypes = matchOneOf(sampledTextureTypes);
4279
4278
  const multiNames = matchOneOf(multisampledTextureTypes);
4280
4279
 
4281
- //#endregion
4282
- //#region ../../node_modules/.pnpm/berry-pretty@0.0.4/node_modules/berry-pretty/dist/index.js
4283
- var spaces = memoize((nesting) => {
4284
- return " ".repeat(nesting);
4285
- });
4286
- var defaultCallerSize = 20;
4287
- var multiLinePad = "\n" + spaces(defaultCallerSize + 3);
4288
- function memoize(fn) {
4289
- const cache$1 = /* @__PURE__ */ new Map();
4290
- return function(...args) {
4291
- const key = JSON.stringify(args);
4292
- if (cache$1.has(key)) return cache$1.get(key);
4293
- else {
4294
- const value = fn(...args);
4295
- cache$1.set(key, value);
4296
- return value;
4297
- }
4298
- };
4299
- }
4300
- if (typeof DOMRect === "undefined") globalThis.DOMRect = function() {};
4301
-
4302
- //#endregion
4303
- //#region ../../node_modules/.pnpm/thimbleberry@0.2.10/node_modules/thimbleberry/dist/thimbleberry.js
4304
- function memoMemo(fn, options) {
4305
- const memoizer = options?.memoCache || persistentMemoCache;
4306
- const keyFn = options?.keyFn || defaultKeyFn;
4307
- const cache$1 = memoizer();
4308
- return function(...args) {
4309
- const key = keyFn(...args);
4310
- const found = cache$1.get(key);
4311
- if (found !== void 0) return found;
4312
- else {
4313
- const value = fn(...args);
4314
- cache$1.set(key, value);
4315
- return value;
4316
- }
4317
- };
4318
- }
4319
- function persistentMemoCache() {
4320
- return /* @__PURE__ */ new Map();
4321
- }
4322
- function defaultKeyFn(...args) {
4323
- return JSON.stringify(args[0] ?? "");
4324
- }
4325
- function memoizeWithDevice(fn) {
4326
- const keyFn = cacheKeyWithDevice;
4327
- let memoFn;
4328
- return function(paramsObj, memoCache) {
4329
- if (!memoFn) memoFn = memoMemo(fn, {
4330
- keyFn,
4331
- memoCache
4332
- });
4333
- return memoFn(paramsObj);
4334
- };
4335
- }
4336
- function cacheKeyWithDevice(paramsObj) {
4337
- const deviceStr = `device: ${paramsObj.device?.label ?? "."}`;
4338
- const withoutDevice = { ...paramsObj };
4339
- delete withoutDevice["device"];
4340
- return `${JSON.stringify({ ...withoutDevice })}; ${deviceStr}`;
4341
- }
4342
- function filledGPUBuffer(device$1, data, usage = GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST | GPUBufferUsage.STORAGE, label, ArrayConstructor = Float32Array) {
4343
- const buffer = device$1.createBuffer({
4344
- label,
4345
- size: data.length * ArrayConstructor.BYTES_PER_ELEMENT,
4346
- usage,
4347
- mappedAtCreation: true
4348
- });
4349
- new ArrayConstructor(buffer.getMappedRange()).set(data);
4350
- buffer.unmap();
4351
- return buffer;
4352
- }
4353
- var [top, bottom] = [1, -1];
4354
- var [left, right] = [-1, 1];
4355
- var fullFrameTriangleStrip = [
4356
- [left, bottom],
4357
- [left, top],
4358
- [right, top],
4359
- [right, bottom],
4360
- [left, bottom]
4361
- ];
4362
- var resources = /* @__PURE__ */ new WeakMap();
4363
- var autoContextStack = [];
4364
- var trackCount = 0;
4365
- function trackUse(target, context) {
4366
- const refCount = resources.get(target) || 0;
4367
- if (refCount === 0) trackCount++;
4368
- resources.set(target, refCount + 1);
4369
- last(autoContextStack)?._addRef(target);
4370
- context?._addRef(target);
4371
- return target;
4372
- }
4373
- function last(a) {
4374
- return a[a.length - 1];
4375
- }
4376
- var fullFrameVertexBuffer = memoizeWithDevice(createFrameVertexBuffer);
4377
- function createFrameVertexBuffer(params$1) {
4378
- const { device: device$1 } = params$1;
4379
- const verts = fullFrameTriangleStrip.flat();
4380
- const usage = GPUBufferUsage.VERTEX;
4381
- const buffer = filledGPUBuffer(device$1, verts, usage, "full-screen-verts", Float32Array);
4382
- trackUse(buffer);
4383
- return buffer;
4384
- }
4385
- async function withBufferCopy(device$1, buffer, fmt, fn) {
4386
- const size = buffer.size;
4387
- const copy = device$1.createBuffer({
4388
- size,
4389
- usage: GPUBufferUsage.MAP_READ | GPUBufferUsage.COPY_DST
4390
- });
4391
- const commands = device$1.createCommandEncoder({});
4392
- commands.copyBufferToBuffer(buffer, 0, copy, 0, size);
4393
- const cmdBuffer = commands.finish();
4394
- device$1.queue.submit([cmdBuffer]);
4395
- await copy.mapAsync(GPUMapMode.READ);
4396
- const cpuCopy = arrayForType(fmt, copy.getMappedRange());
4397
- try {
4398
- return fn(cpuCopy);
4399
- } finally {
4400
- copy.unmap();
4401
- copy.destroy();
4402
- }
4403
- }
4404
- async function copyBuffer(device$1, buffer, fmt = "u32") {
4405
- return withBufferCopy(device$1, buffer, fmt, (d) => [...d]);
4406
- }
4407
- function arrayForType(type, data) {
4408
- if (type === "f32" || type.endsWith("f") || type.endsWith("h")) return new Float32Array(data);
4409
- if (type === "u8") return new Uint8Array(data);
4410
- if (type === "u32") return new Uint32Array(data);
4411
- if (type === "i32") return new Int32Array(data);
4412
- if (type === "i8") return new Int8Array(data);
4413
- throw new Error(`Unknown type: ${type}`);
4414
- }
4415
- function elementStride(fmt) {
4416
- let numSlots;
4417
- let elemSize;
4418
- if (fmt.startsWith("vec")) {
4419
- elemSize = suffixTypeBytes(fmt.slice(-1));
4420
- const size = fmt[3];
4421
- if (size === "2") numSlots = 2;
4422
- else if (size === "3" || size === "4") numSlots = 4;
4423
- else throw new Error(`Unknown vector size: ${fmt}`);
4424
- } else if (fmt.startsWith("mat")) {
4425
- elemSize = suffixTypeBytes(fmt.slice(-1));
4426
- const matSize = fmt.slice(3, 6);
4427
- if (matSize === "2x2") numSlots = 4;
4428
- else if (matSize === "2x3" || matSize === "3x2" || matSize === "2x4" || matSize === "4x2") numSlots = 8;
4429
- else if (matSize === "3x3" || matSize === "3x4" || matSize === "4x3") numSlots = 12;
4430
- else if (matSize === "4x4") numSlots = 16;
4431
- else throw new Error(`Unknown matrix size: ${fmt}`);
4432
- } else {
4433
- numSlots = 1;
4434
- const found = fmt.match(/\d+/);
4435
- elemSize = Number.parseInt(found?.[0]) / 8;
4436
- }
4437
- return elemSize * numSlots;
4438
- }
4439
- function suffixTypeBytes(suffix) {
4440
- switch (suffix) {
4441
- case "f":
4442
- case "u":
4443
- case "i": return 4;
4444
- case "h": return 2;
4445
- default: throw new Error(`Unknown suffix: ${suffix}`);
4446
- }
4447
- }
4448
- var placeholderTexture = memoMemo(makePlaceholderTexture);
4449
- function makePlaceholderTexture(device$1) {
4450
- return device$1.createTexture({
4451
- label: "placeholder texture",
4452
- size: [50, 50],
4453
- format: "rgba8unorm",
4454
- usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.RENDER_ATTACHMENT | GPUTextureUsage.COPY_DST | GPUTextureUsage.COPY_SRC
4455
- });
4456
- }
4457
- var prefix = /\s*/.source;
4458
- var findUnquoted = /(?<findUnquoted>[\w-<>.]+)/.source;
4459
- var findQuoted = /"(?<findQuoted>[^=]+)"/.source;
4460
- var replaceKey = /\s*(?<replaceKey>[\w-]+)/.source;
4461
- var replaceValue = /\s*"(?<replaceValue>[^"]+)"/.source;
4462
- var parseRule = new RegExp(`${prefix}(${findUnquoted}|${findQuoted})=(${replaceKey}|${replaceValue})`, "g");
4463
-
4464
4280
  //#endregion
4465
4281
  //#region ../wesl-tooling/src/FileModuleResolver.ts
4466
4282
  /**
@@ -4565,14 +4381,14 @@ const maybeMatch = (reg, str) => {
4565
4381
  return m ? m[0] : null;
4566
4382
  };
4567
4383
  const range = (a, b, str) => {
4568
- let begs, beg, left$1, right$1 = void 0, result;
4384
+ let begs, beg, left, right = void 0, result;
4569
4385
  let ai = str.indexOf(a);
4570
4386
  let bi = str.indexOf(b, ai + 1);
4571
4387
  let i = ai;
4572
4388
  if (ai >= 0 && bi > 0) {
4573
4389
  if (a === b) return [ai, bi];
4574
4390
  begs = [];
4575
- left$1 = str.length;
4391
+ left = str.length;
4576
4392
  while (i >= 0 && !result) {
4577
4393
  if (i === ai) {
4578
4394
  begs.push(i);
@@ -4582,15 +4398,15 @@ const range = (a, b, str) => {
4582
4398
  if (r !== void 0) result = [r, bi];
4583
4399
  } else {
4584
4400
  beg = begs.pop();
4585
- if (beg !== void 0 && beg < left$1) {
4586
- left$1 = beg;
4587
- right$1 = bi;
4401
+ if (beg !== void 0 && beg < left) {
4402
+ left = beg;
4403
+ right = bi;
4588
4404
  }
4589
4405
  bi = str.indexOf(b, i + 1);
4590
4406
  }
4591
4407
  i = ai < bi && ai >= 0 ? ai : bi;
4592
4408
  }
4593
- if (begs.length && right$1 !== void 0) result = [left$1, right$1];
4409
+ if (begs.length && right !== void 0) result = [left, right];
4594
4410
  }
4595
4411
  return result;
4596
4412
  };
@@ -10495,8 +10311,8 @@ var require_parser = /* @__PURE__ */ __commonJSMin(((exports, module) => {
10495
10311
  type: "literal",
10496
10312
  value: "E",
10497
10313
  description: "\"E\""
10498
- }, peg$c42 = function(left$1, right$1) {
10499
- return node("Float", parseFloat(left$1 + "e" + right$1), line, column);
10314
+ }, peg$c42 = function(left, right) {
10315
+ return node("Float", parseFloat(left + "e" + right), line, column);
10500
10316
  }, peg$c43 = function(text) {
10501
10317
  return node("Float", parseFloat(text), line, column);
10502
10318
  }, peg$c44 = "+", peg$c45 = {