DarkBASIC Professional Help File

DX11 CREATE ARRAY BUFFER

Creates an array buffer.
Array buffers represents an array-like structure where each element corresponds to a primitive datatype whose memory layout matches a certain DXGI_FORMAT value.
Take note that you cannot use any datatype whose size exceeds 32-bits with an array buffer, such as the HLSL float3 and similar types. If you need such data you should use a structured buffer instead.
Array buffers are DX11-exclusive resources!
An array buffer is declared like so in HLSL:
`
Buffer MyArrayBuffer : register(t16); // This defines a read-only array buffer containing float elements that is bound to register t16 and is accessible to all shader stages.
RWBuffer MyWritableBuffer : register(u1); // This defines a Read/Write array buffer containing uint (dword) elements 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 ARRAY BUFFER(elementCount, format, accessMode)

Parameters

    elementCount

> Dword
> The number of elements in the created array buffer.

    format

> Dword
> Corresponds to the DXGI_FORMAT constants. The format determines the size and memory layout of each element in the array buffer. Note that only primitive datatypes can be used!

    accessMode

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

Returns

The created array buffer.

See also

DIRECTCOMPUTE Functions Menu
DX11 Function Categories