kinetic-slider
Version:
A WebGL-powered kinetic slider component using PIXI.js
117 lines (116 loc) • 3.85 kB
TypeScript
/**
* @file ShaderResourceManager.ts
* @description Manages shader resources with pooling, caching, and performance monitoring.
* Optimizes GPU resource usage by sharing shader programs across filters.
*/
import { GlProgram, Filter } from 'pixi.js';
/**
* Configuration options for the ShaderResourceManager
*/
interface ShaderManagerOptions {
/** Enable performance tracking */
enableMetrics?: boolean;
/** Enable debug logging */
debug?: boolean;
/** Maximum number of shaders to keep in the pool */
maxPoolSize?: number;
}
/**
* Manager for shader program resources with pooling and performance metrics
*
* Provides:
* - Shader program pooling to share across filter instances
* - Performance metrics tracking for shader compilation and usage
* - Automatic cleanup of unused shaders
*/
export declare class ShaderResourceManager {
/** Singleton instance of the shader manager */
private static instance;
/** Pool of shader programs indexed by hash */
private shaderPool;
/** Map of filters to their associated shader hashes */
private filterShaderMap;
/** Manager configuration */
private options;
/** Is debug logging enabled */
private debug;
/**
* Creates a new ShaderResourceManager instance
*
* @param options - Configuration options
*/
private constructor();
/**
* Get the singleton instance of the ShaderResourceManager
*
* @param options - Optional configuration options
* @returns The singleton instance
*/
static getInstance(options?: ShaderManagerOptions): ShaderResourceManager;
/**
* Log a message if debug is enabled
*
* @param message - Message to log
*/
private log;
/**
* Generate a hash for a shader program based on its source code
*
* @param vertexSrc - Vertex shader source code
* @param fragmentSrc - Fragment shader source code
* @returns A hash string uniquely identifying the shader program
*/
private generateShaderHash;
/**
* Simplified method to get or create a shader program from a filter
* This method extracts the shader source from the filter if available
*
* @param key - Unique identifier for the shader configuration
* @param filter - The filter instance to extract shader from
* @returns The shader program or undefined if extraction failed
*/
getShaderProgram(key: string, filter: Filter): GlProgram | undefined;
/**
* Internal implementation of getShaderProgram with all parameters
*/
private getShaderProgramInternal;
/**
* Release a shader program by key
*
* @param key - The key used when getting the shader
*/
releaseShader(key: string): void;
/**
* Release a shader program associated with a filter
*
* @param filter - The filter instance
*/
private releaseShaderByFilter;
/**
* Prune the shader pool by removing the least recently used shaders
* when the pool exceeds the maximum size
*/
pruneShaderPool(): void;
/**
* Get statistics about shader usage and the shader pool
*
* @returns Statistics object
*/
getStats(): Record<string, any>;
/**
* Registers a filter with the shader manager for tracking and optimization
*
* @param filter - The filter to register
* @param key - Optional unique key to identify this filter's shader
* @returns True if registration was successful
*/
registerFilter(filter: Filter, key?: string): boolean;
/**
* Releases a filter from the shader manager
*
* @param filter - The filter to release
* @param key - Optional key that was used to register the filter
*/
releaseFilter(filter: Filter, key?: string): void;
}
export {};