import { DeviceCache, FragmentRenderParams, SamplerOptions, WeslOptions, checkerboardTexture, colorBarsTexture, createSampler, edgePatternTexture, fullscreenTriangleVertex, gradientTexture, noiseTexture, radialGradientTexture, simpleRender, solidTexture, withErrorScopes } from "wesl-gpu"; import { FnElem, LinkParams, ModuleResolver, WeslAST, WeslBundle, WeslJsPlugin } from "wesl"; import { DiscoveredResource } from "wesl-reflect"; import { WgslElementType } from "thimbleberry"; import { ImageData, ImageData as ImageData$1, MatchImageOptions } from "vitest-image-snapshot"; import { ImageData as ImageData$2 } from "vitest-image-snapshot/core"; //#region src/CompileShader.d.ts interface ShaderContext { /** Dependency bundles for the shader. */ libs: WeslBundle[]; /** Package name for module resolution. */ packageName?: string; /** File resolver for lazy loading (when useSourceShaders is true). * Shared across compileShader calls; wrapped with freshResolver per call. */ fileResolver?: ModuleResolver; } interface ResolveContextParams { /** WESL/WGSL shader source code. */ src: string; /** Project directory for resolving dependencies. */ projectDir?: string; /** Use source shaders instead of built bundles. Default: true. */ useSourceShaders?: boolean; /** Virtual lib names to exclude from dependency resolution. */ virtualLibNames?: string[]; } interface CompileShaderParams { /** Project directory for resolving shader dependencies. * Used to locate installed npm shader libraries. * Optional: defaults to searching upward from cwd for package.json or wesl.toml. */ projectDir?: string; /** GPU device to use for shader compilation. */ device: GPUDevice; /** WESL/WGSL shader source code to compile. */ src: string; /** Conditions for conditional compilation. * Used to control `@if` directives in the shader. */ conditions?: LinkParams["conditions"]; /** Constants for shader compilation. * Injects host-provided values via the `constants::` namespace. */ constants?: LinkParams["constants"]; /** Virtual libraries to include in the shader. * Allows dynamic generation of shader code at runtime. */ virtualLibs?: LinkParams["virtualLibs"]; /** Additional WESL bundles to include. * These are merged with auto-discovered dependencies. */ libs?: WeslBundle[]; /** Override the package name for module resolution. * Used to ensure package:: references resolve correctly. */ packageName?: string; /** Use source shaders from current package instead of built bundles. * Default: true for faster iteration during development. * Set to false or use TEST_BUNDLES=true environment variable to test built bundles. * * Precedence: explicit parameter > TEST_BUNDLES env var > default (true) */ useSourceShaders?: boolean; /** Pre-resolved shader context. Skips dependency resolution if provided. */ shaderContext?: ShaderContext; /** WESL linker plugins (e.g. annotatedResourcesPlugin). */ plugins?: WeslJsPlugin[]; } /** * Compiles a WESL shader source string into a GPUShaderModule with automatic dependency resolution. * * Parses the shader source to detect references to shader packages, then automatically * includes the required npm package bundles. By default, loads source shaders from the * current package for fast iteration without requiring rebuilds. * * @returns Compiled GPUShaderModule ready for use in render or compute pipelines * @throws Error if shader compilation fails with compilation error details */ declare function compileShader(params: CompileShaderParams): Promise; /** Resolve project context for shader compilation: bundles, resolver, and package name. */ declare function resolveShaderContext(params: ResolveContextParams): Promise; /** Create a project resolver for loading modules from the filesystem. * Handles wesl.toml configuration and creates FileModuleResolver with correct baseDir. * * @param projectDir Project directory (defaults to cwd) * @param packageName Package name for module resolution (optional) * @returns FileModuleResolver configured for the project */ declare function createProjectResolver(projectDir?: string, packageName?: string): Promise; /** Build a fresh resolver from a ShaderContext and main source. * Returns undefined if context has no fileResolver (bundle-only mode). */ declare function buildResolver(ctx: ShaderContext, src: string): ModuleResolver | undefined; //#endregion //#region src/ExampleImages.d.ts /** return a texture to the bundled lemur test image. */ declare function lemurTexture(device: GPUDevice, size?: 256 | 512): Promise; /** Get the path to the bundled lemur test image. */ declare function lemurImagePath(size?: 256 | 512): string; //#endregion //#region src/ImageHelpers.d.ts /** Load PNG file and create GPU texture. */ declare function pngToTexture(device: GPUDevice, imagePath: string): Promise; //#endregion //#region src/TestComputeShader.d.ts interface ComputeTestParams { /** WESL/WGSL source code for the compute shader to test. * Either src or moduleName must be provided, but not both. */ src?: string; /** Name of shader module to load from filesystem. * Supports: bare name (sum.wgsl), path (algorithms/sum.wgsl), or module path (package::algorithms::sum). * Either src or moduleName must be provided, but not both. */ moduleName?: string; /** Project directory for resolving shader dependencies. * Allows the shader to import from npm shader libraries. * Optional: defaults to searching upward from cwd for package.json or wesl.toml. * Typically use `import.meta.url`. */ projectDir?: string; /** GPU device for running the tests. */ device: GPUDevice; /** Flags for conditional compilation to test shader specialization. */ conditions?: LinkParams["conditions"]; /** Constants for shader compilation, injected via the `constants::` namespace. */ constants?: LinkParams["constants"]; /** Use source shaders from current package instead of built bundles. * Default: true for faster iteration during development. */ useSourceShaders?: boolean; /** Number of workgroups to dispatch. Default: 1 * Can be a single number or [x, y, z] for multi-dimensional dispatch. */ dispatchWorkgroups?: number | [number, number, number]; } /** * Compile and run a compute shader on the GPU for testing. * * Each `@buffer` declared in the shader becomes a bound storage buffer; values * written to read_write buffers are returned in the result, keyed by var name. * Unwritten slots show as -999 (f32 sentinel pre-fill). * * Shader libraries mentioned in the source are auto-resolved from node_modules. * * Example: * ```ts * const { results } = await testCompute({ device, src: ` * @buffer var results: array; * @compute @workgroup_size(1) fn main() { results[0] = 42u; results[1] = 7u; } * `}); * ``` * * @returns Record keyed by `@buffer` var name; values are decoded as the * buffer's leaf scalar type (f32/i32/u32). */ declare function testCompute(params: ComputeTestParams): Promise>; //#endregion //#region src/TestDiscovery.d.ts interface TestFunctionInfo { name: string; description?: string; fn: FnElem; } interface SnapshotFunctionInfo { name: string; snapshotName: string; extent: [number, number]; fn: FnElem; } /** Format test name for display: "fnName" or "fnName - description" */ declare function testDisplayName(name: string, description?: string): string; /** Find all functions marked with @test attribute (excluding @snapshot fns). */ declare function findTestFunctions(ast: WeslAST): TestFunctionInfo[]; /** Find all @fragment @snapshot functions in a parsed WESL module. */ declare function findSnapshotFunctions(ast: WeslAST): SnapshotFunctionInfo[]; //#endregion //#region src/TestFragmentShader.d.ts interface FragmentTestParams extends WeslOptions, FragmentRenderParams { /** WESL/WGSL source code for the fragment shader to test. * Either src or moduleName must be provided, but not both. */ src?: string; /** Name of shader module to load from filesystem. * Supports: bare name (blur.wgsl), path (effects/blur.wgsl), or module path (package::effects::blur). * Either src or moduleName must be provided, but not both. */ moduleName?: string; /** Project directory for resolving shader dependencies. * Allows the shader to import from npm shader libraries. * Optional: defaults to searching upward from cwd for package.json or wesl.toml. * Typically use `import.meta.url`. */ projectDir?: string; /** Use source shaders from current package instead of built bundles. * Default: true for faster iteration during development. */ useSourceShaders?: boolean; } interface FragmentImageTestParams extends Omit { /** Optional snapshot name override. If not provided, derived from shader name. */ snapshotName?: string; } /** Run a fragment shader test and validate image snapshot. * @param device GPU device for rendering * @param moduleName Shader name to load - supports: * - Bare name: "blur.wgsl" → resolves to shaders/blur.wgsl * - Relative path: "effects/blur.wgsl" → resolves to shaders/effects/blur.wgsl * - Module path: "package::effects::blur" → same resolution * @param opts Test parameters (size defaults to 256×256 for snapshots) */ declare function expectFragmentImage(device: GPUDevice, moduleName: string, opts?: FragmentImageTestParams): Promise; /** * Renders a fragment shader and returns pixel (0,0) color values for validation. * * Useful for simple color tests where you only need to check a single pixel result. * * @returns Array of color component values from pixel (0,0) */ declare function testFragment(params: FragmentTestParams): Promise; /** * Renders a fragment shader and returns the complete rendered image. * * Useful for image snapshot testing or when you need to validate the entire output. * For snapshot testing shader files, consider using `expectFragmentImage` instead. * * @returns ImageData containing the full rendered output */ declare function testFragmentImage(params: FragmentTestParams): Promise; //#endregion //#region src/TestResourceSetup.d.ts /** GPU resources created for annotated test vars. */ interface TestResources { /** Bind group entries for annotated resources (binding 1, 2, ...). */ entries: GPUBindGroupEntry[]; /** Layout entries for annotated resources. */ layoutEntries: GPUBindGroupLayoutEntry[]; /** Read-write storage buffers to re-zero between tests. */ buffers: GPUBuffer[]; } interface CreateTestResourcesOptions { /** f32 sentinel to pre-fill storage buffers, so unwritten slots are visible in failing tests. */ prefill?: number; } /** Create GPU resources from discovered annotated vars for testing. */ declare function createTestResources(device: GPUDevice, resources: DiscoveredResource[], startBinding?: number, opts?: CreateTestResourcesOptions): Promise; //#endregion //#region src/TestSnapshotShader.d.ts interface SnapshotResult { passed: boolean; isNew: boolean; diffPixels?: number; diffPath?: string; message?: string; } interface SnapshotTestParams { device: GPUDevice; shaderSrc: string; shaderContext: ShaderContext; resources: DiscoveredResource[]; fragmentResources?: TestResources; allSnapshotFns: SnapshotFunctionInfo[]; testFns: TestFunctionInfo[]; conditions?: LinkParams["conditions"]; constants?: LinkParams["constants"]; } /** Render a @fragment @snapshot test and return ImageData. */ declare function renderSnapshotImage(snap: SnapshotFunctionInfo, params: SnapshotTestParams): Promise; /** Render a snapshot test and compare against the saved reference image. */ declare function runSnapshotTest(snap: SnapshotFunctionInfo, params: SnapshotTestParams, testFilePath: string, updateSnapshot?: string): Promise; //#endregion //#region src/TestWesl.d.ts /** Parameters for running @test functions in a WESL module. */ type RunWeslParams = Omit & { /** Run only the @test function with this name */testName?: string; /** Path to test file (for snapshot directory resolution) */ testFilePath?: string; /** Snapshot update mode: "all", "new", or "none" */ updateSnapshot?: string; }; /** Result from running a single @test function on the GPU. */ interface TestResult { name: string; passed: boolean; actual: number[]; expected: number[]; snapshot?: SnapshotResult; } /** Parameters for testWesl() which registers all @test functions with vitest. */ type TestWeslParams = Omit; /** * Discovers @test and @snapshot functions in a WESL module and registers each * as a vitest test. Use top-level await in your test file to call this function. */ declare function testWesl(params: TestWeslParams): Promise; /** * Runs all @test functions and asserts they pass. * Throws descriptive error on failure showing test name and actual/expected values. */ declare function expectWesl(params: RunWeslParams): Promise; /** * Runs all @test and @snapshot functions in a WESL module. * Compute tests are wrapped and dispatched. Fragment tests are rendered and compared. * Returns unified results for all tests. */ declare function runWesl(runParams: RunWeslParams): Promise; //#endregion //#region src/WebGPUTestSetup.d.ts declare const isDeno: boolean; /** get or create shared GPU device for testing */ declare function getGPUDevice(): Promise; /** get or create shared GPU object for testing */ declare function getGPU(): Promise; /** get or create shared GPU adapter for testing */ declare function getGPUAdapter(): Promise; /** destroy globally shared GPU test device */ declare function destroySharedDevice(): void; //#endregion //#region src/index.d.ts declare module "vitest" { interface Matchers { toMatchImage(nameOrOptions?: string | MatchImageOptions): Promise; } } //#endregion export { CompileShaderParams, ComputeTestParams, CreateTestResourcesOptions, DeviceCache, FragmentImageTestParams, FragmentTestParams, type ImageData, ResolveContextParams, RunWeslParams, type SamplerOptions, ShaderContext, SnapshotFunctionInfo, SnapshotResult, SnapshotTestParams, TestFunctionInfo, TestResources, TestResult, TestWeslParams, type WgslElementType, buildResolver, checkerboardTexture, colorBarsTexture, compileShader, createProjectResolver, createSampler, createTestResources, destroySharedDevice, edgePatternTexture, expectFragmentImage, expectWesl, findSnapshotFunctions, findTestFunctions, fullscreenTriangleVertex, getGPU, getGPUAdapter, getGPUDevice, gradientTexture, isDeno, lemurImagePath, lemurTexture, noiseTexture, pngToTexture, radialGradientTexture, renderSnapshotImage, resolveShaderContext, runSnapshotTest, runWesl, simpleRender, solidTexture, testCompute, testDisplayName, testFragment, testFragmentImage, testWesl, withErrorScopes }; //# sourceMappingURL=index.d.ts.map