Overview
The @luma.gl/gpgpu module performs GPU-based data transformation.
API Reference
Installing
npm install @luma.gl/gpgpu
Usage
Interleaving two buffers together
import {luma} from '@luma.gl/core';
import {webglAdapter} from '@luma.gl/webgl';
import {GPUTableEvaluator, backendRegistry, webglBackend, add, interleave} from '@luma.gl/gpgpu';
const inputA = GPUTableEvaluator.fromArray(new Float32Array([0, 0, 0, 1, 0, 0]), {size: 3});
const inputB = GPUTableEvaluator.fromArray(new Float32Array([10, 20]), {size: 1});
const output = interleave(inputA, inputB);
// Operations can be chained
const outputAlt = interleave(inputA, add(inputB, GPUTableEvaluator.fromConstant(1)));
// No computation is performed until the output is evaluated
backendRegistry.add('webgl', webglBackend);
const device = await luma.createDevice({
type: 'webgl',
adapters: [webglAdapter]
});
const outputVector = await output.evaluate(device);
BackendRegistry
The backendRegistry allows apps to include only the implementations for the device types that they wish to support. The CPU backend is registered by default. Register webglBackend or webgpuBackend before evaluating operation-backed tables on those device types.
import {backendRegistry, webglBackend, webgpuBackend} from '@luma.gl/gpgpu';
backendRegistry.add('webgl', webglBackend);
backendRegistry.add('webgpu', webgpuBackend);
Concepts
Operationsdocuments the supported lazy compute operations such asadd(),interleave(), andfround().GPUTableEvaluatorrepresents structured input and output data for lazy GPGPU operations. It can borrow packed single-chunkGPUVectorinputs from@luma.gl/tables.cleanEvaluateevaluates final result tables and cleans up intermediate dependencies in one step.
Related Engine APIs
@luma.gl/gpgpu uses engine compute helpers internally, but it does not re-export them. Import BufferTransform, TextureTransform, and Computation from @luma.gl/engine when you need direct access to those lower-level classes.