imm_atomic_alloc (sm5 - asm)

Atomically increment the hidden 32-bit counter stored with a Count or Append unordered access view (UAV), returning the original value.

imm_atomic_alloc dest[.single_component_mask], dstUAV
Item Description
dest
[in] Contains the returned counter value.
dstUAV
[in] A Structured Buffer UAV with the Count or Append flag.

Remarks

There is a hidden unsigned 32-bit integer counter value associated with each Count or Append Buffer view which is initialized when the view is bound to the pipeline, including the option to keep the previous value.

This instruction does an atomic increment of the counter value, returning the original to dest.

For an Append UAV, the returned value is only valid for the duration of the shader invocation. after that the implementation may rearrange the memory layout. Any memory addressing based on the returned value must be limited to the shader invocation.

For an Append UAV, within the shader invocation the HLSL compiler can use the returned value as the struct index to use for accessing the structured buffer. Accessing any struct index other than those locations returned by call(s) to imm_atomic_alloc or _consume produce undefined results in that exactly which memory location within the UAV is being accessed is random and only fixed for the lifetime of the shader invocation.

For a Count UAV, the returned value can be saved by the application as a reference to a fixed location within the UAV that is meaningful after the shader invocation is over. Any location in a Count UAV may always be accessed independent of what the count value is.

There is no clamping of the count, so it wraps on overflow.

The same shader cannot attempt both imm_atomic_alloc and imm_atomic_consume on the same UAV. Further, the GPU cannot allow multiple shader invocations to mix imm_atomic_alloc and imm_atomic_consume on the same UAV.

This instruction applies to the following shader stages:

Vertex Hull Domain Geometry Pixel Compute
X X

Because UAVs are available at all shader stages for Direct3D 11.1, this instruction applies to all shader stages for the Direct3D 11.1 runtime, which is available starting with Windows 8.

Vertex Hull Domain Geometry Pixel Compute
X X X X X X

Minimum Shader Model

This instruction is supported in the following shader models:

Shader Model Supported
Shader Model 5 yes
Shader Model 4.1 no
Shader Model 4 no
Shader Model 3 (DirectX HLSL) no
Shader Model 2 (DirectX HLSL) no
Shader Model 1 (DirectX HLSL) no

Shader Model 5 Assembly (DirectX HLSL)