Buffers
_ua_ -> allows UAV access (default is formatted/sampled view)
_sr_ -> allows SRV access (default is formatted/sampled view)
_cb -> allows const buffer access
_one_frame_ -> for cb to indicate this buffer contents is only valid this frame after a discard write
_persistent_ -> for cb counter part to _one_frame_, buffer holds its contents until changed
_byte_address -> for ua and sr to indicate byte address view
_structured -> for ua and sr to indicate structured view
_readback -> buffer is used for read back
_indirect -> buffer can be an indirect argument
_staging -> staging buffer
-
namespace d3d
opaque class that holds data for resource/texture update
-
namespace buffers
Enums
Functions
-
template<typename T>
inline uint32_t cb_array_reg_count(uint32_t array_size) Calculate the number of register (in const buffer term) count for a given array size of type T. Structure must be aligned as float4 to not have problems with alignment in cbuffer.
- Template Parameters
T – The type of the array elements.
- Parameters
array_size – The size of the array.
- Returns
The registers count.
-
template<typename T>
inline uint32_t cb_struct_reg_count() Calculate the number of register (in const buffer term) count for a single instance of a type T. Structure must be aligned as float4 to not have problems with alignment in cbuffer.
- Template Parameters
T – The type of the structure.
- Returns
The registers count.
-
inline Sbuffer *create_persistent_cb(uint32_t registers_count, const char *name)
Create a persistent constant buffer.
Such buffers could be updated from time to time. It is recommended to use cb_array_reg_count and cb_struct_reg_count methods to calculate registers_count.
Warning
This buffer will not be restored after device reset!
- Parameters
registers_count – The number of registers in the buffer. Must be not bigger than 4096.
name – The name of the buffer, used for debugging purposes, like showing in in statistcs, and frame debuggers like PIX.
- Returns
Created persistent constant buffer.
-
inline Sbuffer *create_one_frame_cb(uint32_t registers_count, const char *name)
Create an one frame constant buffer.
Such buffers must be updated every frame (you can skip update if the buffer is not used this frame). Because of that we don’t care about its content on device reset. It is recommended to use cb_array_reg_count and cb_struct_reg_count methods to calculate registers_count.
- Parameters
registers_count – The number of registers. Must be not bigger than 4096.
name – The name of the buffer, used for debugging purposes, like showing in in statistcs, and frame debuggers like PIX.
buffer_init – The initialization option for the buffer.
- Returns
A pointer to the created buffer.
-
inline Sbuffer *create_ua_sr_byte_address(uint32_t size_in_dwords, const char *name, Init buffer_init = Init::No)
Create a byte address buffer, which can be used thorugh an unordered access view or through a shader resource view in shaders. In a shader you can declare the buffer using (RW)ByteAddressBuffer. Such a buffer is always 16-byte aligned.
- Todo:
Use registers instead of dwords for size because of alignment.
- Parameters
size_in_dwords – The size of the buffer in dwords.
name – The name of the buffer, used for debugging purposes, like showing in in statistcs, and frame debuggers like PIX.
buffer_init – The initialization option for the buffer.
- Returns
A pointer to the created buffer.
-
inline Sbuffer *create_ua_sr_structured(uint32_t structure_size, uint32_t elements_count, const char *name, Init buffer_init = Init::No)
Create a structured buffer, which can be used thorugh an unordered access view or through a shader resource view in shaders. In a shader you can declare the buffer using (RW)StructuredBuffer<StructureType>. StructureType is a kind of template parameter here.
- Parameters
structure_size – The size of the structure of the buffer elements. Usually it is a sizeof(StructureType).
elements_count – The number of elements in the buffer.
name – The name of the buffer, used for debugging purposes, like showing in in statistcs, and frame debuggers like PIX.
buffer_init – The initialization option for the buffer.
- Returns
A pointer to the created buffer.
-
inline Sbuffer *create_ua_byte_address(uint32_t size_in_dwords, const char *name)
Create a byte address buffer, which can be used thorugh an unordered access view in shaders. In a shader you can declare the buffer using RWByteAddressBuffer. Such a buffer is always 16-byte aligned.
- Todo:
Use registers instead of dwords for size because of alignment.
- Parameters
size_in_dwords – The size of the buffer in dwords.
name – The name of the buffer, used for debugging purposes, like showing in in statistcs, and frame debuggers like PIX.
- Returns
A pointer to the created buffer.
-
inline Sbuffer *create_ua_structured(uint32_t structure_size, uint32_t elements_count, const char *name)
Create a structured buffer, which can be used thorugh an unordered access view in shaders. In a shader you can declare the buffer using RWStructuredBuffer<StructureType>. StructureType is a kind of template parameter here.
- Parameters
structure_size – The size of the structure of the buffer elements. Usually it is a sizeof(StructureType).
elements_count – The number of elements in the buffer.
name – The name of the buffer, used for debugging purposes, like showing in in statistcs, and frame debuggers like PIX.
- Returns
A pointer to the created buffer.
-
inline Sbuffer *create_ua_byte_address_readback(uint32_t size_in_dwords, const char *name, Init buffer_init = Init::No)
The same as create_ua_byte_address but its content can be read on CPU. Such a buffer is always 16-byte aligned.
- Todo:
Use registers instead of dwords for size because of alignment.
- Parameters
size_in_dwords – The size of the buffer in dwords.
name – The name of the buffer, used for debugging purposes, like showing in in statistcs, and frame debuggers like PIX.
buffer_init – The initialization option for the buffer.
- Returns
A pointer to the created buffer.
-
inline Sbuffer *create_ua_structured_readback(uint32_t structure_size, uint32_t elements_count, const char *name, Init buffer_init = Init::No)
The same as create_ua_structured but its content can be read on CPU.
- Parameters
structure_size – The size of the structure of the buffer elements. Usually it is a sizeof(StructureType).
elements_count – The number of elements in the buffer.
name – The name of the buffer, used for debugging purposes, like showing in in statistcs, and frame debuggers like PIX.
buffer_init – The initialization option for the buffer.
- Returns
A pointer to the created buffer.
-
inline uint32_t dword_count_per_call(Indirect indirect_type)
Returns the amount of dwords per indirect command parameters based on the given indirect buffer type.
- Parameters
indirect_type – The type of indirect operation (Dispatch, Draw, or DrawIndexed).
- Returns
The amount of dwords per indirect command parameters.
-
inline Sbuffer *create_ua_indirect(Indirect indirect_type, uint32_t records_count, const char *name)
Creates an indirect buffer filled by the GPU.
- Parameters
indirect_type – The type of the indirect commands stored in the buffer.
records_count – The number of indirect records in the buffer.
name – The name of the buffer, used for debugging purposes, like showing in in statistcs, and frame debuggers like PIX.
- Returns
A pointer to the created buffer.
-
inline Sbuffer *create_indirect(Indirect indirect_type, uint32_t records_count, const char *name)
Creates an indirect buffer filled by the CPU.
- Parameters
indirect_type – The type of the indirect commands stored in the buffer.
records_count – The number of indirect records in the buffer.
name – The name of the buffer, used for debugging purposes, like showing in in statistcs, and frame debuggers like PIX.
- Returns
A pointer to the created buffer.
-
inline Sbuffer *create_staging(uint32_t size_in_bytes, const char *name)
Creates a buffer for data transfer from CPU to GPU.
- Parameters
size_in_bytes – The size of the buffer in bytes.
name – The name of the buffer, used for debugging purposes, like showing in in statistcs, and frame debuggers like PIX.
- Returns
A pointer to the created buffer.
-
inline Sbuffer *create_persistent_sr_tbuf(uint32_t elements_count, uint32_t format, const char *name, Init buffer_init = Init::No)
Create a t-buffer, which can be used through a shader resource view in shaders. In a shader you can declare the buffer using Buffer<BufferFormat>. BufferFormat is a kind of template parameter here.
The total size of the buffer is sizeof(format) * elements_count.
It is a persistent buffer, so you can update it with VBLOCK_WRITEONLY flag. Locked part of the buffer content will be overwritten.
Warning
The buffer type can be used only for the code which will be used for DX10 compatible hardware.
- Parameters
elements_count – The number of elements in the buffer.
format – The format of each element in the buffer. It must be a valid texture format. Not all texture formats are allowed.
name – The name of the buffer, used for debugging purposes, like showing in in statistcs, and frame debuggers like PIX.
buffer_init – The initialization option for the buffer.
- Returns
A pointer to the created buffer.
-
inline Sbuffer *create_persistent_sr_byte_address(uint32_t size_in_dwords, const char *name, Init buffer_init = Init::No)
Create a byte address buffer, which can be used through a shader resource view in shaders. In a shader you can declare the buffer using ByteAddressBuffer.
It is a persistent buffer, so you can update it with VBLOCK_WRITEONLY flag. Locked part of the buffer content will be overwritten.
- Parameters
size_in_dwords – The size of the buffer in dwords.
name – The name of the buffer, used for debugging purposes, like showing in in statistcs, and frame debuggers like PIX.
buffer_init – The initialization option for the buffer.
- Returns
A pointer to the created buffer.
-
inline Sbuffer *create_persistent_sr_structured(uint32_t structure_size, uint32_t elements_count, const char *name, Init buffer_init = Init::No)
Create a structured buffer, which can be used through a shader resource view in shaders. In a shader you can declare the buffer using StructuredBuffer<StructureType>. StructureType is a kind of template parameter here.
It is a persistent buffer, so you can update it with VBLOCK_WRITEONLY flag. Locked part of the buffer content will be overwritten.
Declare StructureType in *.hlsli file and include it both in C++ and shader code.
- Parameters
structure_size – The size of the structure of the buffer elements. Usually it is a sizeof(StructureType).
elements_count – The number of elements in the buffer.
name – The name of the buffer, used for debugging purposes, like showing in in statistcs, and frame debuggers like PIX.
buffer_init – The initialization option for the buffer.
- Returns
A pointer to the created buffer.
-
inline Sbuffer *create_one_frame_sr_tbuf(uint32_t elements_count, uint32_t format, const char *name)
Create a t-buffer, which can be used through a shader resource view in shaders. In a shader you can declare the buffer using Buffer<BufferFormat>. BufferFormat is a kind of template parameter here.
The total size of the buffer is sizeof(format) * elements_count. To use the buffer, lock it with VBLOCK_DISCARD flag (and with VBLOCK_NOOVERWRITE during the frame) and fill it on CPU. On the next frame data in the buffer could be invalid, so don’t read from it until you fill it with lock again.
Warning
The buffer type can be used only for the code which will be used for DX10 compatible hardware.
- Parameters
elements_count – The number of elements in the buffer.
format – The format of each element in the buffer. It must be a valid texture format. Not all texture formats are allowed.
name – The name of the buffer, used for debugging purposes, like showing in in statistcs, and frame debuggers like PIX.
- Returns
A pointer to the created buffer.
-
inline Sbuffer *create_one_frame_sr_byte_address(uint32_t size_in_dwords, const char *name)
Create a byte address buffer, which can be used through a shader resource view in shaders. In a shader you can declare the buffer using ByteAddressBuffer.
To use the buffer, lock it with VBLOCK_DISCARD flag (and with VBLOCK_NOOVERWRITE during the frame) and fill it on CPU. On the next frame data in the buffer could be invalid, so don’t read from it until you fill it with lock again.
- Parameters
size_in_dwords – The size of the buffer in dwords.
name – The name of the buffer, used for debugging purposes, like showing in in statistcs, and frame debuggers like PIX.
- Returns
A pointer to the created buffer.
-
inline Sbuffer *create_one_frame_sr_structured(uint32_t structure_size, uint32_t elements_count, const char *name)
Create a structured buffer, which can be used through a shader resource view in shaders. In a shader you can declare the buffer using StructuredBuffer<StructureType>. StructureType is a kind of template parameter here.
To use the buffer, lock it with VBLOCK_DISCARD flag (and with VBLOCK_NOOVERWRITE during the frame) and fill it on CPU. On the next frame data in the buffer could be invalid, so don’t read from it until you fill it with lock again.
Declare StructureType in *.hlsli file and include it both in C++ and shader code.
- Parameters
structure_size – The size of the structure of the buffer elements. Usually it is a sizeof(StructureType).
elements_count – The number of elements in the buffer.
name – The name of the buffer, used for debugging purposes, like showing in in statistcs, and frame debuggers like PIX.
- Returns
A pointer to the created buffer.
Variables
-
constexpr uint32_t CBUFFER_REGISTER_SIZE = 16
The size of the cbuffer register. It should have a size divisible by sizeof(float4), because the cbuffer is a set of float4 registers.
-
constexpr uint32_t BYTE_ADDRESS_ELEMENT_SIZE = sizeof(uint32_t)
The size of an element of a byte address buffer.
-
template<typename T>
-
namespace buffers