thimbleberry
Version:
WebGPU utilities
46 lines (45 loc) • 1.7 kB
TypeScript
import { HasReactive } from "@reactively/decorate";
import { BinOpTemplate } from "../shader-util/BinOpTemplate";
import { Cache } from "../shader-util/MemoMemo";
import { ValueOrFn } from "../shader-util/ReactiveUtil";
import { ComposableShader } from "../shader-util/ComposableShader";
export interface BufferReduceParams {
device: GPUDevice;
source: ValueOrFn<GPUBuffer>;
reducedResult: ValueOrFn<GPUBuffer>;
dispatchLength: ValueOrFn<number>;
sourceStart?: ValueOrFn<number>;
sourceEnd?: ValueOrFn<number>;
blockLength?: ValueOrFn<number>;
workgroupLength?: ValueOrFn<number>;
reduceTemplate?: ValueOrFn<BinOpTemplate>;
pipelineCache?: <T extends object>() => Cache<T>;
}
/**
* Reduce workgroup sized blocks of data to single elements.
*
* A full reduction requires running this shader repeatedly, each time
* reducing the previously reduced buffer until only a single workgroup
* sized block remains. Then the final reduction will reduce one block to
* a buffer containing only a single element.
*
* The reduce operation is controlled by template: could be sum,min,max, etc.
*/
export declare class BufferReduceShader extends HasReactive implements ComposableShader {
source: GPUBuffer;
reducedResult: GPUBuffer;
dispatchLength: number;
blockLength: number;
workgroupLength?: number;
reduceTemplate: BinOpTemplate;
private device;
private usageContext;
private pipelineCache?;
constructor(params: BufferReduceParams);
commands(commandEncoder: GPUCommandEncoder): void;
destroy(): void;
get debugBuffer(): GPUBuffer;
private pipeline;
private bindGroup;
private actualWorkgroupLength;
}