/// import { HasReactive } from "@reactively/decorate"; import { Cache, ComposableShader, ValueOrFn, Vec2 } from "thimbleberry"; import { BinOpModule } from "../util/BinOpModules.js"; import { ComponentName, LoadComponent } from "../util/GenerateLoadTexel.js"; export interface ReduceTextureParams { device: GPUDevice; /** * Source data to be reduced. * * A function returning the source buffer will be executed lazily, * and reexecuted if the function's `@reactively` source values change. */ source: ValueOrFn; /** {@inheritDoc ReduceTexture#blockSize} */ blockSize?: Vec2; /** {@inheritDoc ReduceTexture#bufferBlockLength} */ bufferBlockLength?: number; /** {@inheritDoc ReduceTexture#forceWorkgroupSize} */ forceWorkgroupSize?: Vec2; /** {@inheritDoc ReduceTexture#binOps} */ binOps: BinOpModule; /** {@inheritDoc ReduceTexture#sourceComponent} */ sourceComponent?: ComponentName | LoadComponent; /** cache for GPUComputePipeline */ pipelineCache?: () => Cache; /** {@inheritDoc ReduceTexture#label} */ label?: string; } /** * A sequence of shader dispatches that reduces a source texture to a single value * according to a specified binary operation (e.g. min, max, or sum). * * Two underlying shaders are used: * . one to reduce the source texture to a small buffer * . one to reduce a small buffer to smaller buffer * * When executed, FrameReduceSequence will dispatch a sufficient number of times * to end with a single value. The final result is stored in a single element * `reducedResult` buffer. */ export declare class ReduceTexture extends HasReactive implements ComposableShader { source: GPUTexture; /** length of block to read when reducing from texture to buffer */ blockSize: Vec2; /** length of block to read when reducing from buffer to buffer */ bufferBlockLength: number | undefined; /** number and arrangement of threads in each dispatched workgroup */ forceWorkgroupSize: Vec2 | undefined; /** wgsl macros for a binary operation to reduce two elements to one */ binOps: BinOpModule; /** select or synthesize a component from the source texture */ sourceComponent: ComponentName | LoadComponent; /** Debug label attached to gpu objects for error reporting */ label?: string; device: GPUDevice; private usageContext; private pipelineCache?; constructor(params: ReduceTextureParams); commands(commandEncoder: GPUCommandEncoder): void; destroy(): void; /** Execute the reduce immediately and copy the results back to the CPU. * (results are copied from the {@link ReduceTexture.result} GPUBuffer) * @returns a single reduced result value in an array */ reduce(): Promise; /** result of the final reduction pass, one element in size */ get result(): GPUBuffer; /** all shaders needed to reduce the texture to a single reduced value */ private get shaders(); /** shader to reduce the texture to a buffer */ private get reduceTexture(); /** created only if necessary, a shader to reduce the buffer to a single element */ private get reduceBuffer(); private get reduceBufferNeeded(); /** template or generator for loading src data from the texture */ private get loadComponent(); }