Difference between revisions of "Atomic Variable Operations"

From OpenGL.org
Jump to: navigation, search
(Page for atomic operations on shader variables. Used for transclusions.)
 
(formatting.)
Line 1: Line 1:
 
All of the atomic functions return the '''''original''''' value. The term "''n''int" can be {{code|int}} or {{code|uint}}.
 
All of the atomic functions return the '''''original''''' value. The term "''n''int" can be {{code|int}} or {{code|uint}}.
  
''n''int atomicAdd(inout ''n''int {{param|mem}}, ''n''int {{param|data}})
+
{{funcdef|''n''int atomicAdd(inout ''n''int {{param|mem}}, ''n''int {{param|data}})}}
  
 
Adds {{param|data}} to {{param|mem}}.
 
Adds {{param|data}} to {{param|mem}}.
  
''n''int atomicMin(inout ''n''int {{param|mem}}, ''n''int {{param|data}})
+
{{funcdef|''n''int atomicMin(inout ''n''int {{param|mem}}, ''n''int {{param|data}})}}
  
 
The {{param|mem}}'s value is no lower than {{param|data}}.
 
The {{param|mem}}'s value is no lower than {{param|data}}.
  
''n''int atomicMax(inout ''n''int {{param|mem}}, ''n''int {{param|data}})
+
{{funcdef|''n''int atomicMax(inout ''n''int {{param|mem}}, ''n''int {{param|data}})}}
  
 
The {{param|mem}}'s value is no greater than {{param|data}}.
 
The {{param|mem}}'s value is no greater than {{param|data}}.
  
''n''int atomicAnd (inout ''n''int {{param|mem}}, ''n''int {{param|data}})
+
{{funcdef|''n''int atomicAnd (inout ''n''int {{param|mem}}, ''n''int {{param|data}})}}
  
 
{{param|mem}} becomes the bitwise-and between {{param|mem}} and {{param|data}}.
 
{{param|mem}} becomes the bitwise-and between {{param|mem}} and {{param|data}}.
  
''n''int atomicOr(inout ''n''int {{param|mem}}, ''n''int {{param|data}})
+
{{funcdef|''n''int atomicOr(inout ''n''int {{param|mem}}, ''n''int {{param|data}})}}
  
 
{{param|mem}} becomes the bitwise-or between {{param|mem}} and {{param|data}}.
 
{{param|mem}} becomes the bitwise-or between {{param|mem}} and {{param|data}}.
  
''n''int atomicXor(inout ''n''int {{param|mem}}, ''n''int {{param|data}})
+
{{funcdef|''n''int atomicXor(inout ''n''int {{param|mem}}, ''n''int {{param|data}})}}
  
 
{{param|mem}} becomes the bitwise-xor between {{param|mem}} and {{param|data}}.
 
{{param|mem}} becomes the bitwise-xor between {{param|mem}} and {{param|data}}.
  
''n''int atomicExchange(inout ''n''int {{param|mem}}, ''n''int {{param|data}})
+
{{funcdef|''n''int atomicExchange(inout ''n''int {{param|mem}}, ''n''int {{param|data}})}}
  
 
Sets {{param|mem}}'s value to {{param|data}}.
 
Sets {{param|mem}}'s value to {{param|data}}.
  
''n''int atomicCompSwap(inout ''n''int {{param|mem}}, ''n''int {{param|compare}}, ''n''int {{param|data}})
+
{{funcdef|''n''int atomicCompSwap(inout ''n''int {{param|mem}}, ''n''int {{param|compare}}, ''n''int {{param|data}})}}
  
 
If the current value of {{param|mem}} is equal to {{param|compare}}, then {{param|mem}} is set to {{param|data}}.
 
If the current value of {{param|mem}} is equal to {{param|compare}}, then {{param|mem}} is set to {{param|data}}.

Revision as of 19:09, 5 January 2013

All of the atomic functions return the original value. The term "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 bitwise-and between mem​ and data​.

nint atomicOr(inout nint mem​, nint data​)

mem​ becomes the bitwise-or between mem​ and data​.

nint atomicXor(inout nint mem​, nint data​)

mem​ becomes the bitwise-xor 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​.