Difference between revisions of "Shader Storage Buffer Object"
(→Atomic operations: Better descriptions.) 

Line 32:  Line 32:  
{{clear float}}  {{clear float}}  
''n''int atomicAdd(inout ''n''int {{parammem}}, ''n''int {{paramdata}})  ''n''int atomicAdd(inout ''n''int {{parammem}}, ''n''int {{paramdata}})  
+  
+  Adds {{paramdata}} to {{parammem}}.  
+  
''n''int atomicMin(inout ''n''int {{parammem}}, ''n''int {{paramdata}})  ''n''int atomicMin(inout ''n''int {{parammem}}, ''n''int {{paramdata}})  
+  
+  The {{parammem}}'s value is no lower than {{paramdata}}.  
+  
''n''int atomicMax(inout ''n''int {{parammem}}, ''n''int {{paramdata}})  ''n''int atomicMax(inout ''n''int {{parammem}}, ''n''int {{paramdata}})  
+  
+  The {{parammem}}'s value is no greater than {{paramdata}}.  
+  
''n''int atomicAnd (inout ''n''int {{parammem}}, ''n''int {{paramdata}})  ''n''int atomicAnd (inout ''n''int {{parammem}}, ''n''int {{paramdata}})  
+  
+  {{parammem}} becomes the bitwiseand between {{parammem}} and {{paramdata}}.  
+  
''n''int atomicOr(inout ''n''int {{parammem}}, ''n''int {{paramdata}})  ''n''int atomicOr(inout ''n''int {{parammem}}, ''n''int {{paramdata}})  
+  
+  {{parammem}} becomes the bitwiseor between {{parammem}} and {{paramdata}}.  
+  
''n''int atomicXor(inout ''n''int {{parammem}}, ''n''int {{paramdata}})  ''n''int atomicXor(inout ''n''int {{parammem}}, ''n''int {{paramdata}})  
+  
+  {{parammem}} becomes the bitwisexor between {{parammem}} and {{paramdata}}.  
+  
''n''int atomicExchange(inout ''n''int {{parammem}}, ''n''int {{paramdata}})  ''n''int atomicExchange(inout ''n''int {{parammem}}, ''n''int {{paramdata}})  
+  
+  Sets {{parammem}}'s value to {{paramdata}}.  
+  
''n''int atomicCompSwap(inout ''n''int {{parammem}}, ''n''int {{paramcompare}}, ''n''int {{paramdata}})  ''n''int atomicCompSwap(inout ''n''int {{parammem}}, ''n''int {{paramcompare}}, ''n''int {{paramdata}})  
−  +  If the current value of {{parammem}} is equal to {{paramcompare}}, then {{parammem}} is set to {{paramdata}}.  
Revision as of 22:58, 3 January 2013


OpenGL Objects

A Shader Storage Buffer Object is a Buffer Object that is used to store and retrieve data from GLSL.
This article is a stub. You can help the OpenGL Wiki by expanding it. 
Overview
SSBOs are a lot like Uniform Buffer Objects. Shader storage blocks are defined almost identically to uniform blocks. SSBOs are bound to SSBO binding points, just as UBOs are bound to UBO binding points. And so forth.
The major differences between them are:
 SSBOs are typically much larger. The smallest required UBO size is 16KB; the smallest required SSBO size is 16MB, and typical sizes will be on the order of the size of GPU memory.
 SSBOs are writable, even atomically; UBOs are uniforms. SSBOs have the same memory characteristics as Image Load Store operations, so they need appropriate memory barriers.
 SSBOs can have unbounded storage, up to the buffer range bound; UBOs must have a specific, fixed storage size. This means that you can have an array of arbitrary length in an SSBO. The actual size of the array, based on the range of the buffer bound, can be queried at runtime in the shader using the length function on the unbounded array variable.
Functionally speaking, SSBOs can be thought of as a much nicer interface to Buffer Textures when accessed via Image Load Store.
Atomic operations
There are special atomic functions that can be applied to buffer variables (and to compute shader shared variables). They only take uint or int types, but these can be members of aggregates (structs/arrays) or vector elements (ie: you can atomically access uvec3.x).
All of the atomic functions return the original value.
The atomic operations are (where "nint" can be int or uint):
nint atomicAdd(inout nint mem, nint data)
Adds data to mem.
nint atomicMin(inout nint mem, nint data)
The mem's value is no lower than data.
nint atomicMax(inout nint mem, nint data)
The mem's value is no greater than data.
nint atomicAnd (inout nint mem, nint data)
mem becomes the bitwiseand between mem and data.
nint atomicOr(inout nint mem, nint data)
mem becomes the bitwiseor between mem and data.
nint atomicXor(inout nint mem, nint data)
mem becomes the bitwisexor between mem and data.
nint atomicExchange(inout nint mem, nint data)
Sets mem's value to data.
nint atomicCompSwap(inout nint mem, nint compare, nint data)
If the current value of mem is equal to compare, then mem is set to data.