Buffers

In Shadeup buffers are used to store data on the GPU. The data exists on both the CPU and GPU, but the CPU data is typically used to upload and download data to and from the GPU.

Creating a buffer

Uploading data to a buffer

Use buffer.upload() to send the data currently on the CPU to the GPU. Data is also automatically uploaded when the buffer is used in a shader just before dispatch.

Downloading data from a buffer

Use buffer.download() to download the data currently on the GPU to the CPU. This is a blocking operation and needs to wait for the GPU to finish before it can return. The example below uses a compute shader to fill the data, a later section will explain compute shaders.

Downloading data from a buffer asynchronously

You can call buffer.download() in an async { ... } block to download the data asynchronously. This will not block the CPU “thread” (we’re still operating in the world of Javascript here)

Buffers in shaders

Buffers can be used in shaders by indexing them with an integer.

Structured buffers

Buffers can also be used to store structs.

Note that any structs used in buffers are serialized and will not contain pointers, references, or non-GPU types (string, dynamicly sized arrays, maps, etc).