///
import { HasReactive } from "@reactively/decorate";
import { Cache, ComposableShader, ValueOrFn } from "thimbleberry";
import { BinOpModule } from "../util/BinOpModules.js";
export interface BufferReduceParams {
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 ReduceBuffer#sourceOffset} */
sourceOffset?: number;
/** {@inheritDoc ReduceBuffer#resultOffset} */
resultOffset?: number;
/** {@inheritDoc ReduceBuffer#blockLength} */
blockLength?: number;
/** {@inheritDoc ReduceBuffer#forceWorkgroupLength} */
forceWorkgroupLength?: number;
/** {@inheritDoc ReduceBuffer#forceMaxWorkgroups} */
forceMaxWorkgroups?: number | undefined;
/** {@inheritDoc ReduceBuffer#binOps} */
binOps: BinOpModule;
/** cache for GPUComputePipeline */
pipelineCache?: () => Cache;
/** {@inheritDoc ReduceBuffer#label} */
label?: string;
}
/**
* Reduce a buffer of data to a single value by running an associative
* binary operation over every element.
*
* The binary operation is specified by a BinOpModule. Possible binary
* operations include sum, min, and max.
*/
export declare class ReduceBuffer extends HasReactive implements ComposableShader {
/** Source data to be reduced */
source: GPUBuffer;
/** macros to customize wgsl shader for size of data and type of reduce*/
binOps: BinOpModule;
/** Debug label attached to gpu objects for error reporting */
label?: string;
/** start scan at this element offset in the source. (0) */
sourceOffset: number;
/** start emitting results at this element offset in the results. (0) */
resultOffset: number;
/** number of elements to reduce in each invocation (4) */
blockLength: number;
/** Override to set compute workgroup size e.g. for testing.
@defaultValue maxComputeInvocationsPerWorkgroup of the `GPUDevice` (256)
*/
forceWorkgroupLength?: number;
/** Override to set max number of workgroups for dispatch e.g. for testing.
@defaultValue maxComputeWorkgroupsPerDimension from the `GPUDevice` (65535)
*/
forceMaxWorkgroups?: number;
device: GPUDevice;
private pipelineCache?;
private usageContext;
constructor(params: BufferReduceParams);
commands(commandEncoder: GPUCommandEncoder): void;
private encodePass;
/** Release the result buffer and intermediate buffers for destruction. */
destroy(): void;
/** Execute the reduce immediately and copy the results back to the CPU.
* (results are copied from the {@link ReduceBuffer.result} GPUBuffer)
* @returns a single reduced result value in an array
*/
reduce(): Promise;
/** Buffer containing results of the reduce after the shader has run. */
get result(): GPUBuffer;
get workgroupWGSL(): string;
/** @internal */
get debugBuffer(): GPUBuffer;
/** Strategy for partitioning large sources into multiple dispatches
* and a partitioned uniform buffer */
private get inputSlicing();
/** one or more dispatches to cover the source */
private get sourceReductions();
/** dispatches to cover the internal layers after the source layer is reduced */
private get layerReductions();
/** buffers for both source and layer reductions */
private get resultBuffers();
private get sourceReductionBuffer();
private get layerReductionBuffers();
private createBuffer;
private get registry();
/** all dispatches use the same pipeline */
private get pipeline();
private get wgslParams();
/** * One bind group for all source reductions,
* (but we'll dispatch with dynamic offsets to point at
* different parts of the uniform buffer) */
private get sourceBindGroup();
private get layerBindGroups();
private createBindGroup;
private get uniforms();
private writeUniforms;
/** offsets into the result buffer for a sliced first layer multi-dispatch */
private get resultOffsets();
private get workgroupLength();
private get sourceElems();
private get maxWorkgroups();
}