DarkBASIC Professional Help File

DX11 SET COMPUTE SHADER APPEND CONSUME BUFFER

Sets a read/write append/consume buffer that can be accessed by the specified compute shader.
Append/consume buffers are inherently read/write buffers since both the Append and Consume functions serve to change the resource.
Take note that append/consume buffers can only be either appended (stack-like push operation) to or consumed (stack-like pop operation) from in the same shader stage.
They can however be swapped around between shaders so that one consumes the data in such a buffer while another shader appends new data to it.
You can bind up to 8 different buffer and image resources for read/write access by a compute shader on DX11 hardware. These will use registers u0 through u7.
Only a single read/write resource can be bound at any one time on DX10 hardware (to register u0).
Take note that buffers and textures (as well as render targets, but those aren't applicable to the compute shader; if you use read/write resources in a pixel shader they share slots with render targets
as well however) share the same register slots, thus setting a buffer to slot 1 followed by setting a texture to the same slot will overwrite the previously set buffer.
You can unbind buffers by specifying nullptr as the buffer argument; this is neccessary if the same buffer is bound as a read-only buffer by the same shader since a resource cannot simultaneously
be bound for read-only and read/write access (you can read from the read/write resource as the name suggests though).
Append/consume buffers are declared like so in HLSL:

- AppendStructuredBuffer BufferName : register(t?) where ? ranges between 0 and 7 (only slot 0 is available on DX10 hardware) for append/consume buffers that will be appended by the shader
- ConsumeStructuredBuffer BufferName : register(t?) where ? ranges between 0 and 7 (only slot 0 is available on DX10 hardware) for append/consume buffers that will be consumed by the shader

As can be seen above the append/consume buffers are really just a different way of looking at a structured buffer.
Because of this they are accessed like normal structured buffers by shaders when bound as a read-only buffer.
If you use DX11 SET COMPUTE SHADER RWBUFFER to set an append/consume buffer it will also be made accessible as a normal RWStructuredBuffer by your shaders.
This different way of looking at the same resource can have its uses.

Syntax

    DX11 SET COMPUTE SHADER APPEND CONSUME BUFFER shader, slot, buffer

Parameters

    shader

> Dword
> The compute shader to set the (writable) append/consume buffer resource for.

    slot

> Dword
> The shader register slot to bind the append/consume buffer to. The valid range is 0 through 7 on DX11 hardware, or just slot 0 on DX10 hardware. Take note that read/write texture resources as well as other RWBuffers use the same register slots.

    buffer

> Dword
> The append/consume buffer to bind to the specified slot of the given compute shader. An error will be raised if you provide any other type of buffer; those should be set using DX11 SET COMPUTE SHADER RWBUFFER instead. Set to nullptr to remove a previously bound buffer / texture from the given slot.

Returns

This function does not return a value.

See also

DIRECTCOMPUTE Functions Menu
DX11 Function Categories