Skip to main content

Upload and copy operations

gpuUpload and gpuCopy use the same descriptions in GPUGraph and reusable GPUSimpleGraph. They compose with expressions in program order and define their own results. Import them from @luma.gl/graph.

import {GPUGraph, gpuUpload, gpuCopy, gpuExpression} from '@luma.gl/graph/gpu-graph';

const graph = new GPUGraph(); // Or new GPUSimpleGraph() for WebGL/WebGPU.
graph
.add(gpuUpload, {
output: 'positions',
format: 'float32x2',
data: new Float32Array([1, 2, 3, 4])
})
.add(gpuExpression, {output: 'scaled', expression: 'positions * 2'})
.add(gpuCopy, {input: 'scaled', output: 'result'});
const compiledGraph = graph.compile(device);
const {result} = await compiledGraph.run({});
// Use result, then release it. Each run produces independent storage.
result.destroy();
compiledGraph.destroy();

Upload​

PropertyMeaning
outputName of the produced vector.
formatfloat32, sint32, or uint32, optionally with x2, x3, or x4.
dataMatching Float32Array, Int32Array, or Uint32Array, or an array of those chunks.
idOptional diagnostic identifier.

Data must contain complete packed rows. Construction snapshots the supplied arrays, including subarray offsets: later CPU mutations do not change the operation. An array of typed arrays preserves every chunk, including empty chunks. No implicit concatenation or type conversion occurs. Use expressions for numeric conversions.

This is an immutable upload recipe. For data that changes between executions, declare an input with addInput() and supply a GPUVector at execution; the upload operation does not introduce a second host-input binding API.

Copy​

PropertyMeaning
inputName of an existing vector.
outputName of a new produced vector; mutually exclusive with target.
targetName of an existing mutable vector, such as declared GPUGraph state; mutually exclusive with output.
idOptional diagnostic identifier.

Copy preserves the format, row count, and chunk partition. It copies row bytes into independent storage without readback when using output. With target, it writes the existing vector, which must match the source format and chunk lengths. Graph inputs are read-only and cannot be targets. Use this form to commit expression results to mutable state. It does not cast, gather, compact, or repartition rows. To copy a subrange, bind a vector whose chunks describe that range, using GPUData.byteOffset and length. Reusable graph bindings currently require packed 32-bit rows.

For capacity/count results, copying the vector copies its entire capacity. The associated count remains a separate graph value; select it explicitly if the caller needs it.

Texture copies​

On WebGPU, the same graph.add(gpuCopy, {input, output}) also copies named texture values in GPUGraph and reusable SimpleGraph. It preserves format, extent, and selected mip/layer ranges, without sampling or conversion. See texture bindings for declarations, caller-owned encoding, and output ownership. Vector copy behavior is unchanged.

Execution and ownership​

Produced results of both operations support the normal outputTargets bindings. Copying to target uses that existing value's binding instead. Supplied targets remain borrowed; automatically allocated selected results belong to the caller. Targets must match format and chunk lengths and must not alias inputs or other results. Unselected results are graph scratch.

GPUGraph.prepare() allocates staging resources without submitting work. Uploads and copies are encoded in order on the caller's encoder. Keep the prepared execution alive through submission, then destroy it to release staging and scratch. run() handles that lifecycle.

Reusable SimpleGraph executes the same descriptions on WebGL or WebGPU. Its existing GPUSimpleGraphUploadOperation, GPUSimpleGraphCopyOperation, and evaluator recipe APIs retain their existing lazy evaluation, caching, and ownership behavior. These new shared operations belong to the reusable compile(device) interface.

Copying concrete row views​

When composing a GPUCommandGraph, supply the source and destination GPUGraphDataView for a single chunk. The graph derives the copy accesses and workload from the views.

commandGraph.add({
command: 'copyRows',
id: 'copy-selected-rows',
source, destination
});

Both views must have the same format, row width, and row count. Nonempty copies require distinct buffers with copy-source and copy-destination usage. Each encoded byte offset and copy size must be a multiple of four. Packed views use one copy. Strided views copy each row and preserve destination padding. An empty view encodes zero copies. The semantic gpuCopy operation uses this command for each nonempty vector chunk.