wgsl-test 0.2.1 → 0.2.3

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/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { DeviceCache, RenderUniforms, RenderUniforms as RenderUniforms$1, SamplerOptions, checkerboardTexture, colorBarsTexture, createSampler, createUniformsVirtualLib, edgePatternTexture, fullscreenTriangleVertex, gradientTexture, noiseTexture, radialGradientTexture, renderUniformBuffer, simpleRender, solidTexture, updateRenderUniforms, withErrorScopes } from "wesl-gpu";
1
+ import { DeviceCache, FragmentRenderParams, RenderUniforms, SamplerOptions, WeslOptions, checkerboardTexture, colorBarsTexture, createSampler, createUniformsVirtualLib, edgePatternTexture, fullscreenTriangleVertex, gradientTexture, noiseTexture, radialGradientTexture, renderUniformBuffer, simpleRender, solidTexture, updateRenderUniforms, withErrorScopes } from "wesl-gpu";
2
2
  import { LinkParams, ModuleResolver, WeslBundle } from "wesl";
3
3
  import { WgslElementType, WgslElementType as WgslElementType$1 } from "thimbleberry";
4
4
  import { ImageData, ImageData as ImageData$1, MatchImageOptions } from "vitest-image-snapshot";
@@ -140,7 +140,7 @@ declare function testCompute(params: ComputeTestParams): Promise<number[]>;
140
140
  declare function runCompute(device: GPUDevice, module: GPUShaderModule, resultFormat?: WgslElementType$1, size?: number, dispatchWorkgroups?: number | [number, number, number]): Promise<number[]>;
141
141
  //#endregion
142
142
  //#region src/TestFragmentShader.d.ts
143
- interface FragmentTestParams {
143
+ interface FragmentTestParams extends WeslOptions, FragmentRenderParams {
144
144
  /** WESL/WGSL source code for the fragment shader to test.
145
145
  * Either src or moduleName must be provided, but not both. */
146
146
  src?: string;
@@ -153,31 +153,6 @@ interface FragmentTestParams {
153
153
  * Optional: defaults to searching upward from cwd for package.json or wesl.toml.
154
154
  * Typically use `import.meta.url`. */
155
155
  projectDir?: string;
156
- /** GPU device for running the tests.
157
- * Typically use `getGPUDevice()` from wgsl-test. */
158
- device: GPUDevice;
159
- /** Texture format for the output texture. Default: "rgba32float" */
160
- textureFormat?: GPUTextureFormat;
161
- /** Size of the output texture. Default: [1, 1] for simple color tests.
162
- * Use [2, 2] for derivative tests (forms a complete 2x2 quad for dpdx/dpdy). */
163
- size?: [width: number, height: number];
164
- /** Flags for conditional compilation to test shader specialization.
165
- * Useful for testing `@if` statements in the shader. */
166
- conditions?: LinkParams["conditions"];
167
- /** Constants for shader compilation.
168
- * Injects host-provided values via the `constants::` namespace. */
169
- constants?: LinkParams["constants"];
170
- /** Uniform values for the shader (time, mouse).
171
- * Resolution is auto-populated from the size parameter.
172
- * Creates test::Uniforms struct available in the shader. */
173
- uniforms?: RenderUniforms$1;
174
- /** Input textures for the shader.
175
- * Bindings: textures at [1..n], samplers at [n+1..n+m].
176
- * Binding 0 is reserved for uniforms. */
177
- textures?: GPUTexture[];
178
- /** Samplers for the input textures.
179
- * Must be length 1 (reused for all textures) or match textures.length exactly. */
180
- samplers?: GPUSampler[];
181
156
  /** Use source shaders from current package instead of built bundles.
182
157
  * Default: true for faster iteration during development. */
183
158
  useSourceShaders?: boolean;
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
- import { DeviceCache, DeviceCache as DeviceCache$1, checkerboardTexture, colorBarsTexture, createSampler, createUniformsVirtualLib, edgePatternTexture, fullscreenTriangleVertex, gradientTexture, linkFragmentShader, noiseTexture, radialGradientTexture, renderUniformBuffer, renderUniformBuffer as renderUniformBuffer$1, simpleRender, simpleRender as simpleRender$1, solidTexture, updateRenderUniforms, withErrorScopes, withErrorScopes as withErrorScopes$1 } from "wesl-gpu";
1
+ import { DeviceCache, DeviceCache as DeviceCache$1, checkerboardTexture, colorBarsTexture, createSampler, createUniformsVirtualLib, edgePatternTexture, fullscreenTriangleVertex, gradientTexture, noiseTexture, radialGradientTexture, renderUniformBuffer, runFragment, simpleRender, solidTexture, updateRenderUniforms, withErrorScopes, withErrorScopes as withErrorScopes$1 } from "wesl-gpu";
2
2
  import * as path$1 from "node:path";
3
3
  import path, { posix, win32 } from "node:path";
4
4
  import { URL as URL$1, fileURLToPath, pathToFileURL } from "node:url";
5
- import { CompositeResolver, RecordResolver, WeslParseError, filterMap, findUnboundIdents, link, normalizeModuleName, npmNameVariations, parseSrcModule } from "wesl";
5
+ import { CompositeResolver, RecordResolver, WeslParseError, filterMap, findUnboundIdents, link, moduleToRelativePath, normalizeDebugRoot, normalizeModuleName, npmNameVariations, parseSrcModule } from "wesl";
6
6
  import * as fs$3 from "node:fs";
7
7
  import fs, { realpathSync, statSync } from "node:fs";
8
8
  import * as fs$2 from "node:fs/promises";
@@ -125,23 +125,16 @@ var FileModuleResolver = class {
125
125
  }
126
126
  /** Convert module path (package::foo::bar) to filesystem path (baseDir/foo/bar) */
127
127
  moduleToFilePath(modulePath) {
128
- const parts = modulePath.split("::");
129
- if (!(parts[0] === "package" || parts[0] === this.packageName)) return void 0;
130
- const relativePath = parts.slice(1).join("/");
128
+ const relativePath = moduleToRelativePath(modulePath, this.packageName);
129
+ if (!relativePath) return void 0;
131
130
  return `${this.baseDir}/${relativePath}`;
132
131
  }
133
132
  /** Convert module path to debug path for error messages */
134
133
  modulePathToDebugPath(modulePath) {
135
- const relativePath = modulePath.split("::").slice(1).join("/");
136
- return normalizeDebugRoot(this.debugWeslRoot) + relativePath + ".wesl";
134
+ const relative = moduleToRelativePath(modulePath, this.packageName) ?? "";
135
+ return normalizeDebugRoot(this.debugWeslRoot) + relative + ".wesl";
137
136
  }
138
137
  };
139
- /** Normalize debugWeslRoot to ensure it ends with / or is empty */
140
- function normalizeDebugRoot(debugWeslRoot) {
141
- if (debugWeslRoot === void 0) return "./";
142
- if (debugWeslRoot === "") return "";
143
- return debugWeslRoot.endsWith("/") ? debugWeslRoot : debugWeslRoot + "/";
144
- }
145
138
 
146
139
  //#endregion
147
140
  //#region ../../node_modules/.pnpm/@isaacs+balanced-match@4.0.1/node_modules/@isaacs/balanced-match/dist/esm/index.js
@@ -11454,7 +11447,7 @@ async function expectFragmentImage(device, moduleName, opts = {}) {
11454
11447
  */
11455
11448
  async function testFragment(params) {
11456
11449
  const { textureFormat = "rgba32float" } = params;
11457
- const data = await runFragment(params);
11450
+ const data = await runFragment$1(params);
11458
11451
  const count = numComponents(textureFormat);
11459
11452
  return data.slice(0, count);
11460
11453
  }
@@ -11468,7 +11461,7 @@ async function testFragment(params) {
11468
11461
  */
11469
11462
  async function testFragmentImage(params) {
11470
11463
  const { textureFormat = "rgba32float", size = [1, 1] } = params;
11471
- const data = imageToUint8(await runFragment(params), textureFormat, size[0], size[1]);
11464
+ const data = imageToUint8(await runFragment$1(params), textureFormat, size[0], size[1]);
11472
11465
  return {
11473
11466
  data: new Uint8ClampedArray(data),
11474
11467
  width: size[0],
@@ -11476,33 +11469,20 @@ async function testFragmentImage(params) {
11476
11469
  colorSpace: "srgb"
11477
11470
  };
11478
11471
  }
11479
- async function runFragment(params) {
11480
- const { projectDir, device, src, moduleName, useSourceShaders } = params;
11481
- const { conditions = {}, constants } = params;
11482
- const { textureFormat = "rgba32float", size = [1, 1] } = params;
11483
- const { textures, samplers, uniforms = {} } = params;
11472
+ async function runFragment$1(params) {
11473
+ const { projectDir, src, moduleName, useSourceShaders } = params;
11484
11474
  const fragmentSrc = await resolveShaderSource(src, moduleName, projectDir);
11485
11475
  const ctx = await resolveShaderContext({
11486
11476
  src: fragmentSrc,
11487
11477
  projectDir,
11488
11478
  useSourceShaders
11489
11479
  });
11490
- return await simpleRender$1({
11491
- device,
11492
- module: await linkFragmentShader({
11493
- device,
11494
- fragmentSource: fragmentSrc,
11495
- bundles: ctx.libs,
11496
- resolver: ctx.resolver,
11497
- packageName: ctx.packageName,
11498
- conditions,
11499
- constants
11500
- }),
11501
- outputFormat: textureFormat,
11502
- size,
11503
- textures,
11504
- samplers,
11505
- uniformBuffer: renderUniformBuffer$1(device, size, uniforms)
11480
+ return runFragment({
11481
+ ...params,
11482
+ src: fragmentSrc,
11483
+ libs: params.libs ?? ctx.libs,
11484
+ resolver: params.resolver ?? ctx.resolver,
11485
+ packageName: params.packageName ?? ctx.packageName
11506
11486
  });
11507
11487
  }
11508
11488
  /** Convert texture data to RGBA Uint8ClampedArray for image comparison. */