/** * WebGPU Shader Management * Handles WGSL shader compilation, caching, and compute pipeline creation */ export interface ComputePipelineOptions { label?: string; entryPoint?: string; constants?: Record; } export interface BindGroupEntry { binding: number; resource: GPUBuffer | GPUSampler | GPUTextureView; } /** * Create a shader module from WGSL source */ export declare function createShaderModule(source: string, label?: string): GPUShaderModule; /** * Create a compute pipeline from a shader module */ export declare function createComputePipeline(shaderModule: GPUShaderModule, options?: ComputePipelineOptions): GPUComputePipeline; /** * Create a compute pipeline directly from WGSL source */ export declare function createComputePipelineFromSource(source: string, options?: ComputePipelineOptions): GPUComputePipeline; /** * Create a bind group for a compute pipeline */ export declare function createBindGroup(pipeline: GPUComputePipeline, groupIndex: number, entries: BindGroupEntry[], label?: string): GPUBindGroup; /** * Dispatch a compute shader */ export declare function dispatchCompute(pipeline: GPUComputePipeline, bindGroups: GPUBindGroup[], workgroupCounts: [number, number, number], label?: string): GPUCommandBuffer; /** * Execute a compute shader * By default, submits without waiting (async GPU execution) * Set sync=true only when you need to read results immediately */ export declare function executeCompute(pipeline: GPUComputePipeline, bindGroups: GPUBindGroup[], workgroupCounts: [number, number, number], label?: string, sync?: boolean): Promise; /** * Clear shader and pipeline caches */ export declare function clearShaderCache(): void; /** * Common WGSL utility functions that can be included in shaders */ export declare const WGSL_UTILS = "\n// Activation functions\nfn relu(x: f32) -> f32 {\n return max(x, 0.0);\n}\n\nfn gelu(x: f32) -> f32 {\n // Approximation: 0.5 * x * (1 + tanh(sqrt(2/pi) * (x + 0.044715 * x^3)))\n let c = 0.7978845608; // sqrt(2/pi)\n let inner = c * (x + 0.044715 * x * x * x);\n return 0.5 * x * (1.0 + tanh(inner));\n}\n\nfn silu(x: f32) -> f32 {\n // SiLU (Swish): x * sigmoid(x)\n return x / (1.0 + exp(-x));\n}\n\nfn quick_gelu(x: f32) -> f32 {\n // QuickGELU: x * sigmoid(1.702 * x)\n return x / (1.0 + exp(-1.702 * x));\n}\n\n// Stable softmax helper\nfn safe_exp(x: f32) -> f32 {\n return exp(clamp(x, -88.0, 88.0));\n}\n"; /** * Generate a simple element-wise operation shader */ export declare function generateElementwiseShader(operation: string, workgroupSize?: number): string; /** * Generate a binary operation shader (element-wise on two arrays) */ export declare function generateBinaryShader(operation: string, workgroupSize?: number): string; /** * Calculate workgroup counts for a given size */ export declare function calculateWorkgroups(totalSize: number, workgroupSize: number): number; /** * Calculate 2D workgroup counts */ export declare function calculateWorkgroups2D(width: number, height: number, workgroupSizeX: number, workgroupSizeY: number): [number, number]; /** * Calculate 3D workgroup counts */ export declare function calculateWorkgroups3D(width: number, height: number, depth: number, workgroupSizeX: number, workgroupSizeY: number, workgroupSizeZ: number): [number, number, number]; //# sourceMappingURL=shader.d.ts.map