ShaderStorageBuffer QML Type

Declares a GPU buffer resource that shaders can read or write. More...

Import Statement: import QtQuick3D
Since: Qt 6.13
Inherits:

Object3D

Properties

Detailed Description

A ShaderStorageBuffer is a GPU-side shader storage buffer, with content that is either uploaded from the CPU (via bufferData) or produced entirely on the GPU (by a ComputePass, a CustomMaterial, or an Effect writing to it). It is meant to be read from and/or written to directly in shader code, rather than used as a regular uniform buffer.

A ShaderStorageBuffer is exposed to a shader by using it as a property in the ComputePass, RenderPass, Effect, or CustomMaterial:

 ShaderStorageBuffer {
     id: myBuffer
     size: 1024
 }

 ComputePass {
     computeShader: "generate.comp"
     property ShaderStorageBuffer targetBuffer: myBuffer
 }

In the shader, the property is declared with the STORAGE_BUFFER macro, using the same name as the QML property (targetBuffer in the example above):

 STORAGE_BUFFER(targetBuffer, "writeonly") {
     vec4 values[];
 }

 void main() {
     values[gl_GlobalInvocationID.x] = vec4(1.0);
 }

The last argument to STORAGE_BUFFER is a memory qualifier string made up of any combination of readonly, writeonly, coherent, volatile, and restrict, matching the GLSL memory qualifiers of the same names; an empty string means implicit read-write access. Any other word is rejected with a warning, and the shader cannot be used.

Note: The declaration is recognized by scanning the shader source before any preprocessing takes place. The memory qualifiers must therefore be written as a literal string, and the name as a plain identifier; #define'd values are not recognized. Each name can be declared only once in a shader, even in different preprocessor branches, while declarations inside comments are ignored. Like other GLSL interface blocks, the block can end with a semicolon. A declaration that does not follow this form is left in the shader source unprocessed, which typically shows up as a shader compilation error.

See also ShaderStorageBufferData, ComputePass, and ShaderImage.

Property Documentation

bufferData : ShaderStorageBufferData

This property holds the ShaderStorageBufferData providing this buffer's content from the CPU. Assigning it uploads the data returned by bufferData() to the GPU and updates size to match; setting it to null resets size to 0.

bufferProvider : RenderExtension

This property holds a RenderExtension that is responsible for providing this buffer's backing GPU resource, for advanced use cases where the buffer needs to be created and managed by custom C++ rendering code rather than by the engine.

Note: When bufferProvider is set, the size is not automatically updated to match the size provided, but setting size manually is still ignored.

size : int

This property holds the size of the buffer, in bytes.

Setting bufferData automatically updates this property to match the size of the assigned data; setting size directly is meant for buffers whose content is produced entirely on the GPU, without a bufferData. Setting size is ignored if bufferData or bufferProvider is also set.