/** * WGSL Compiler -- `BoundaryDef` to struct definitions + `@group`/`@binding` declarations. * * Generates WebGPU Shading Language code from boundary definitions, * mapping JS scalar/vector values to WGSL types and producing struct layouts * suitable for uniform buffer bindings. * * @module */ import type { Boundary, StateUnion } from '@czap/core'; /** WGSL scalar, vector, or matrix primitive type. */ export type WGSLType = 'f32' | 'i32' | 'u32' | 'bool' | 'vec2f' | 'vec3f' | 'vec4f' | 'vec2i' | 'vec3i' | 'vec4i' | 'mat2x2f' | 'mat3x3f' | 'mat4x4f'; /** A binding's type is either a WGSL primitive type or a user-declared struct name. */ export type WGSLBindingType = WGSLType | string; /** JSON-safe authored WGSL vector value. */ export type WGSLUniformVector = readonly [number, number] | readonly [number, number, number] | readonly [number, number, number, number]; /** JSON-safe authored WGSL uniform value. */ export type WGSLUniformValue = number | WGSLUniformVector; /** A single `@group(G) @binding(B) var …` declaration. */ export interface WGSLBinding { /** Bind group index. */ readonly group: number; /** Binding index within the group. */ readonly binding: number; /** Binding variable name. */ readonly name: string; /** Resolved primitive or struct type. */ readonly type: WGSLBindingType; } /** A WGSL `struct { … }` definition produced by {@link WGSLCompiler.compile}. */ export interface WGSLStruct { /** Struct identifier (PascalCase, suffixed `State`). */ readonly name: string; /** Ordered fields; the first is always `state_index: u32`. */ readonly fields: readonly { readonly name: string; readonly type: WGSLType; }[]; } /** * Output of {@link WGSLCompiler.compile}. * * `declarations` is the ready-to-prepend WGSL preamble containing state * constants, the uniform struct, and its binding declaration. */ export interface WGSLCompileResult { /** Declared struct types (currently one: the boundary's state struct). */ readonly structs: readonly WGSLStruct[]; /** Uniform buffer bindings. */ readonly bindings: readonly WGSLBinding[]; /** Default field values keyed by WGSL field name. */ readonly bindingValues: Record; /** * Per-state binding values keyed by state name then snake_case field name — * the WGSL analog of `GLSLCompileResult.stateUniforms`. Built alongside the * merged `bindingValues` so the live runtime can resolve * `stateBindings[currentState]` and update struct fields on each crossing. */ readonly stateBindings: Record>; /** Pre-serialized WGSL preamble string. */ readonly declarations: string; } /** * Compile a boundary definition and per-state scalar/vector value maps into * WGSL struct definitions, `@group/@binding` declarations, and state constants. * * @example * ```ts * import { Boundary } from '@czap/core'; * import { WGSLCompiler } from '@czap/compiler'; * * const boundary = Boundary.make({ * input: 'viewport', * at: [[0, 'mobile'], [768, 'desktop']], * }); * const result = WGSLCompiler.compile(boundary, { * mobile: { blur_radius: 2.0, scale: 0.5 }, * desktop: { blur_radius: 0.0, scale: 1.0 }, * }); * console.log(result.declarations); * // struct ViewportState { state_index: u32, blur_radius: f32, scale: f32 } * // @group(0) @binding(0) var boundary_state: ViewportState; * ``` * * @param boundary - The boundary definition with states * @param states - Per-state scalar/vector value maps * @returns A {@link WGSLCompileResult} with structs, bindings, and declarations */ declare function compile(boundary: B, states: { [S in StateUnion & string]: Record; }): WGSLCompileResult; /** * Serialize a {@link WGSLCompileResult} into a WGSL declaration string. * * @example * ```ts * import { WGSLCompiler } from '@czap/compiler'; * * const result = WGSLCompiler.compile(boundary, states); * const wgsl = WGSLCompiler.serialize(result); * // Prepend to your compute/render shader * ``` * * @param result - The compile result to serialize * @returns A WGSL declaration string */ declare function serialize(result: WGSLCompileResult): string; /** * WGSL compiler namespace. * * Compiles boundary definitions into WebGPU Shading Language code: struct * layouts for uniform buffers, `@group/@binding` declarations, and `const` * state index values. * * @example * ```ts * import { Boundary } from '@czap/core'; * import { WGSLCompiler } from '@czap/compiler'; * * const boundary = Boundary.make({ * input: 'viewport', * at: [[0, 'sm'], [768, 'lg']], * }); * const result = WGSLCompiler.compile(boundary, { * sm: { radius: 4 }, lg: { radius: 12 }, * }); * const wgsl = WGSLCompiler.serialize(result); * ``` */ export declare const WGSLCompiler: { readonly compile: typeof compile; readonly serialize: typeof serialize; }; export {}; //# sourceMappingURL=wgsl.d.ts.map