import { type Nullable } from "@onerjs/core/types.js"; import { type ConnectionPoint } from "../connection/connectionPoint.js"; import { SmartFilter } from "../smartFilter.js"; /** * @internal */ export type StackItem = { /** * The connection points to which to connect the output of the optimized block, once the optimized block has been created. */ inputsToConnectTo: ConnectionPoint[]; /** * The connection point to process. */ outputConnectionPoint: ConnectionPoint; }; export declare enum OptimizerDebugMode { /** * Clamps the values returned by fragment shaders to the 0-1 range. * Fragment shader output is often clamped by the target texture, but in an optimized Smart Filter, multiple * fragment shaders can get combined into one, and the output of one simply returned to the next as-is. In this case, * the clamping would not happen, and so you could get different results when the optimizer is enabled if your blocks * can return values outside of the 0-1 range. * If you see different results when using this debug mode, you may need to clamp the output of one of your blocks * to prevent the results from changing when the block is used in an optimized Smart Filter. */ ClampReturnValues = 1 } /** * Options for the smart filter optimizer. */ export interface ISmartFilterOptimizerOptions { /** * The maximum number of samplers allowed in the fragment shader. Default: 8 */ maxSamplersInFragmentShader?: number; /** * If true, the optimizer will remove the disabled blocks from the optimized smart filter. Default: false * It allows more aggressive optimizations, but removed blocks will no longer be available in the optimized smart filter. */ removeDisabledBlocks?: boolean; /** * The optional debug mode to use. */ debugMode?: OptimizerDebugMode; } /** * Optimizes a smart filter by aggregating blocks whenever possible, to reduce the number of draw calls. */ export declare class SmartFilterOptimizer { private _sourceSmartFilter; private _options; private _blockStack; private _blockToStackItem; private _savedBlockStack; private _savedBlockToStackItem; private _symbolOccurrences; private _remappedSymbols; private _blockToMainFunctionName; private _mainFunctionNameToCode; private _dependencyGraph; private _vertexShaderCode; private _currentOutputTextureOptions; private _forceUnoptimized; /** * Creates a new smart filter optimizer * @param smartFilter - The smart filter to optimize * @param options - Options for the optimizer */ constructor(smartFilter: SmartFilter, options?: ISmartFilterOptimizerOptions); /** * Optimizes the smart filter by aggregating blocks whenever possible, to lower the number of rendering passes * @returns The optimized smart filter, or null if the optimization failed */ optimize(): Nullable; private _disconnectDisabledBlocks; private _initialize; private _makeSymbolUnique; private _processDefines; /** * Processes each helper function (any function that's not the main function), adding those to emit in the final * block to _remappedSymbols and noting any necessary renames in renameWork. If a helper does not access any * uniforms, it only needs to be emitted once regardless of how many instances of the block that define it are * folded into the final optimized block. * NOTE: so this function can know about the uniforms to test for them, it must be called after _processVariables. * @param block - The block we are processing * @param shaderProgram - The shader program associated with the block * @param renameWork - The list of rename work to add to as needed * @param samplerList - The list of sampler names */ private _processHelperFunctions; /** * Processes either consts or uniforms. Handles capturing the rename work needed, updating the sampler list, and * accounting for single instance situations (where a const or uniform is shared across all instances of this block). * @param block - The block to work on * @param renameWork - The RenameWork list to update * @param varDecl - Which type of variable we're working with * @param declarations - The declarations of those variables from the shader * @param sharedByAllInstances - If this should be treated as a shared value across all instances of this shader block * @returns The list of samplers */ private _processVariables; private _processSampleTexture; private _canBeOptimized; private _optimizeBlock; /** * Replaces calls to __sampleTexture(foo, uv); with calls to a function bar(uv); for chaining optimized blocks together * @param code - The code to process * @param samplerName - The old name of the sampler * @param functionName - The name of the function to call instead * @returns The updated code */ private _replaceSampleTextureWithFunctionCall; private _replaceSampleTextureWithTexture2DCall; /** * Processes all the functions, both main and helper functions, applying the renames and changes which have been collected * @param block - The original block we are optimizing * @param shaderProgram - The shader of the block we are optimizing * @param renameWork - The rename work to apply * @param newMainFunctionName - The new name for the main function */ private _processAllFunctions; /** * Applies all required changes specific to just the main function * @param code - The code of the main function * @param shaderProgram - The shader program containing the main function * @param newMainFunctionName - The new name for the main function * @returns The updated main function code */ private _processMainFunction; /** * Applies all required changes to a function (main or helper) * @param block - The original block we are optimizing * @param code - The code of the function * @param renameWork - The rename work to apply * @returns The updated function code */ private _processFunction; private _saveBlockStackState; private _restoreBlockStackState; private _processBlock; /** * If this block used DisableStrategy.AutoSample, find all the __sampleTexture calls which just pass the vUV, * skip the first one, and for all others replace with the local variable created by the DisableStrategy.AutoSample * * @param code - The shader code to process * @param sampler - The name of the sampler * * @returns The processed code */ private _applyAutoSampleStrategy; } //# sourceMappingURL=smartFilterOptimizer.d.ts.map