Skip to main content

GPUDataView

From: v10Status: Work-In-Progress

GPUDataView describes borrowed fixed-width values over a GPU buffer-like resource. A view has one physical format, value count, byte offset, and byte stride. It does not own its buffer or carry logical list topology, validity, or adapter metadata.

GPUData.getChild() returns a GPUDataView for one named field in an interleaved struct. Views can also be constructed directly or derived from an explicit BufferLayout attribute.

Usage

import {GPUDataView, makeGPUDataViewFromAttribute} from '@luma.gl/tables';

const positions = new GPUDataView({
buffer,
format: 'float32x3',
length: vertexCount,
byteOffset: 4,
byteStride: 16
});

const colors = makeGPUDataViewFromAttribute({
buffer,
bufferLayout,
attributeName: 'colors',
length: vertexCount
});

Constructor

new GPUDataView(props)

PropTypeDefaultMeaning
bufferBuffer | DynamicBuffer | GPUDataViewBufferRequiredBuffer-like resource containing the values.
formatVertexFormatRequiredFixed-width physical format for one value.
lengthnumberRequiredNumber of values in the view.
byteOffsetnumber0Byte offset of the first value.
byteStridenumberFormat byte lengthByte distance between consecutive values.

Construction rejects negative or unsafe integer values, strides smaller than the physical format, and ranges that exceed the backing buffer.

Properties

PropertyTypeMeaning
bufferGPUDataViewBufferBorrowed backing resource.
formatVertexFormatFixed-width physical value format.
lengthnumberNumber of values in the view.
byteOffsetnumberByte offset of the first value.
byteStridenumberByte distance between consecutive values.
elementByteLengthnumberByte length of one physical value.
byteLengthnumberByte range from the first value through the final value payload.

Attribute Views

makeGPUDataViewFromAttribute(props): GPUDataView

PropTypeDefaultMeaning
bufferBuffer | DynamicBuffer | GPUDataViewBufferRequiredBuffer-like resource described by bufferLayout.
bufferLayoutBufferLayoutRequiredInterleaved layout containing the requested attribute.
attributeNamestringRequiredAttribute to expose as a view.
lengthnumberRequiredNumber of attribute values.
byteOffsetnumber0Base byte offset added before the attribute offset.

The helper combines the base and attribute offsets and uses the layout's shared byteStride. It throws when the attribute, its format, or the layout stride is missing.

Ownership

A GPUDataView never destroys its buffer. The object that owns the backing GPUData, Buffer, or DynamicBuffer remains responsible for its lifetime.