/** * WebGPU Context Management * * Handles WebGPU device initialization, feature detection, and fallback strategies. * * @module gpu/WebGPUContext */ export interface WebGPUCapabilities { supported: boolean; adapter: GPUAdapter | null; device: GPUDevice | null; limits: GPUSupportedLimits | null; features: Set; } export interface WebGPUContextOptions { powerPreference?: 'low-power' | 'high-performance'; requiredFeatures?: GPUFeatureName[]; requiredLimits?: Record; fallbackToCPU?: boolean; } export interface WebGPUAdapterIdentity { readonly vendor?: string; readonly architecture?: string; readonly device?: string; readonly description?: string; } /** * WebGPU Context Manager * * Provides centralized WebGPU device initialization with feature detection * and graceful fallback to CPU when WebGPU is unavailable. * * @example * ```typescript * const context = new WebGPUContext({ * powerPreference: 'high-performance', * fallbackToCPU: true, * }); * * await context.initialize(); * * if (context.isSupported()) { * // Use GPU acceleration * const device = context.getDevice(); * // ... create compute pipelines * } else { * // Fallback to CPU physics * console.warn('WebGPU not available, using CPU fallback'); * } * ``` */ export declare class WebGPUContext { private adapter; private device; private limits; private features; private options; private initialized; constructor(options?: WebGPUContextOptions); /** * Initialize WebGPU context * * @returns Promise that resolves when initialization is complete * @throws Error if WebGPU is not supported and fallbackToCPU is false */ initialize(): Promise; /** * Check if WebGPU is supported and initialized */ isSupported(): boolean; /** * Get WebGPU device * @throws Error if device is not initialized */ getDevice(): GPUDevice; /** * Get WebGPU adapter * @throws Error if adapter is not available */ getAdapter(): GPUAdapter; /** Serializable identity from the exact adapter backing this context. */ getAdapterIdentity(): WebGPUAdapterIdentity | null; /** * Get device limits */ getLimits(): GPUSupportedLimits; /** * Get supported features */ getFeatures(): Set; /** * Check if a specific feature is supported */ hasFeature(feature: string): boolean; /** * Get capabilities object */ getCapabilities(): WebGPUCapabilities; /** * Get optimal workgroup size for compute shaders * * Returns a workgroup size that maximizes occupancy based on device limits. * Common values: 64, 128, 256 (must be power of 2) */ getOptimalWorkgroupSize(): number; /** * Cleanup resources */ destroy(): void; /** * Handle unsupported browser/device */ private handleUnsupported; /** * Handle device lost event */ private handleDeviceLost; /** * Detect and log GPU information (for debugging) */ logGPUInfo(): Promise; } /** * Get or create global WebGPU context */ export declare function getGlobalWebGPUContext(options?: WebGPUContextOptions): WebGPUContext; /** * Helper: Create a WebGPU-enabled or CPU fallback simulation * * @example * ```typescript * const physics = await createPhysicsSimulation({ * particleCount: 100000, * preferGPU: true, * }); * * if (physics.usingGPU) { * console.log('Using GPU acceleration! 🚀'); * } else { * console.log('Using CPU simulation'); * } * ``` */ export declare function createPhysicsSimulation(options: { particleCount: number; preferGPU?: boolean; }): Promise<{ usingGPU: boolean; context?: WebGPUContext; }>; //# sourceMappingURL=WebGPUContext.d.ts.map