DarkBASIC Professional Help File

DX11 CREATE BYTE ADDRESS BUFFER

Creates a byte address buffer.
Byte address buffers are used to store a raw data block. Unlike the other buffer types there are no pre-defined elements in a byte address buffer which means you can store anything
in them. This affords the possibility to build your own data structures such as linked lists with variable-size elements.
Byte address buffers must have a size that is a multiple of four and their contents is read in 4-byte increments by your shaders (their Load() function requires an offset that is divisible by four as well).
Other data than the raw uints (dwords) you can extract from the buffer on the GPU in this fashion can be obtained by bitshifting and using the asfloat HLSL function. Similarly you have to pack your data
back into 32-bit values when writing to a byte address buffer; the asint HLSL function comes in handy for storing a float value's bit pattern as an integer.
Byte address buffers are available in both DX10- and DX11 mode.
A byte address buffer is declared like so in HLSL:
`
ByteAddressBuffer MyBuffer : register(t16); // This defines a read-only byte address buffer that is bound to register t16 and is accessible to all shader stages.
RWByteAddressBuffer MyWritableBuffer : register(u1); // This defines a Read/Write byte address buffer that is bound to register u1 and is only accessible to pixel and compute shaders.
`
Buffers can be used to share data between the CPU and GPU and can be bound to the shader pipeline using functions such as DX11 SET OBJECT BUFFER, DX11 SET SPRITE BUFFER, and so forth.
Buffers can be bound to everything that can also have textures bound. When accessed from your shader programs read-only buffers will be bound to registers t16 through t23 (registers t0 through t15 are
reserved for texture resources). Buffers can also be written to by pixel and compute shaders (the other shader stages can not have output resources). The nice thing about this is that you can
write anything to a buffer, at any position, which is different from for example writing to a render target where you will only be able to write to a single pre-defined position. You can also read from
any position within a writable buffer from your shader.
There are however some limitations; a buffer cannot be bound as a read-only resource at the same time as it is bound as a read-only resource. This means that if your pixel shader writes to a certain buffer
that buffer can not be accessed by any other shader stages within the same shader technique. Compute shaders are run in isolation so this limitation does not apply for them.
When using an output buffer with a pixel shader it should also be noted that it shares registers with render targets. In order to find out what register your writable resource will be bound to, all render
targets will be bound first, starting at register u0. After that any writable texture resources are set. Buffers will be bound to the slots after that.
There is also a hardware limitation on how many output resources that can be bound simultaneously; for DX11 this number is 8, meaning that your combined number of render targets, RWTextures and RWBuffers
must not exceed 8. On DX10 hardware you can only have a single output resource however. Since there is always a render target associated with a camera, this means that you cannot use output resources
with your pixel shaders in DX10 compatibility mode. You can still use them in compute shaders however.

Syntax

    Return Dword = DX11 CREATE BYTE ADDRESS BUFFER(byteSize, accessMode)

Parameters

    byteSize

> Dword
> The size in bytes of the entire buffer; this value will be rounded up to the nearest even multiple of 4.

    accessMode

> Dword
> Corresponds to the ACCESSMODE_XXX constants. You must set this to ACCESSMODE_GPU_WRITABLE to create a buffer that can be written to by the GPU.

Returns

The created byte address buffer.

See also

DIRECTCOMPUTE Functions Menu
DX11 Function Categories