Multidraw Context
Defines
-
USE_STAGING_MULTIDRAW_BUF
-
CONSTEXPR_EXT_MULTIDRAW
Checks if extended draw call arguments structure is used.
-
template<typename PerDrawDataT, uint32_t DrawIdBits = 20>
class MultidrawContext - #include <dag_multidrawContext.h>
Multidraw Context
This class incapsulates logic of filling multidraw buffers. It implements draw call id/per draw parameters passing for different platforms and manages buffers required for it.
- Template Parameters:
PerDrawDataT – Type of per draw parameters structure. If only draw call id is required, use uint32_t. When dword is enough there won’t be any indirection for per draw parameter reading in the shader.
DrawIdBits – Number of bits used for draw call id storage inside draw arguments structure. Default is 20 bits. Other bits could be used by user for per draw data, so this data could be read without indirections.
Public Functions
-
inline MultidrawContext(const char *name)
Default constructor.
- Parameters:
name – must be unique for each context.
-
MultidrawContext(MultidrawContext&&) = default
Default move constructor.
-
MultidrawContext &operator=(MultidrawContext&&) = default
Default move assignment operator.
-
MultidrawContext(MultidrawContext&) = delete
Removed copy constructor since we use unique buffer holders.
-
MultidrawContext &operator=(MultidrawContext&) = delete
Removed copy assignment operator since we use unique buffer holders.
-
template<typename T>
inline MultidrawRenderExecutor fillBuffers(uint32_t drawcalls_count, const T &set_cb) Fills multidraw buffers.
This method iterates over locked buffers content and calls params_setter for each draw call to fill only allowed parameters of drawcall. If the buffers are too small, it recreates them.
- Parameters:
drawcalls_count – number of draw calls.
set_cb – function that sets draw call parameters.
- Returns:
executor that could be used to render draw calls.
-
inline void close()
Closes buffers.
Public Members
-
const uint32_t DRAW_DWORD_FREE_BITS = 32 - DrawIdBits
Number of free bits in draw call arguments structure for user data.
Private Functions
Private Members
-
eastl::string name
Name for context that is used as a buffer name and as a prefix for helper buffers.
-
RingDynamicSB multidrawArguments
Buffer for draw calls arguments.
-
UniqueBufHolder perDrawArgsBuffer
Buffer for per draw parameters.
-
uint32_t allocatedDrawcallsInBuffer = 0
Number of draw calls that can be stored in buffer.
-
uint32_t actualStart = 0
Offset in buffer for next draw call.
Private Static Functions
-
static inline constexpr bool usesExtendedMultiDrawStruct()
-
static inline constexpr bool needPerDrawParamsBuffer()
Checks if per draw parameter could be stored instead of draw id. In this case we don’t need per draw parameters buffer.
Private Static Attributes
-
static constexpr uint8_t bytesCountPerDrawcall = sizeof(DrawIndexedIndirectArgs)
-
class MultidrawRenderExecutor
- #include <dag_multidrawContext.h>
Executor for multidraw calls.
This class is used to pass multidraw buffers to a draw call. It could be constructed only by MultidrawContext. It is used to hide multidraw buffers from a user.
Public Functions
-
inline MultidrawRenderExecutor(const MultidrawContext *context)
Constructor.
- Parameters:
context – reference to a context that is used for rendering. If context is a nullptr, render method does nothing.
-
inline void render(uint32_t primitive_type, uint32_t first_drawcall, uint32_t drawcalls_count) const
Renders draw calls.
This method renders draw calls using multidraw indirect buffers.
- Parameters:
primitive_type – type of primitive.
first_drawcall – index of first draw call in the buffer.
drawcalls_count – number of draw calls to execute.
Private Functions
-
MultidrawRenderExecutor() = delete
Default constructors and operator= are deleted.
-
MultidrawRenderExecutor(MultidrawRenderExecutor&&) = delete
-
MultidrawRenderExecutor &operator=(MultidrawRenderExecutor&&) = delete
-
MultidrawRenderExecutor(MultidrawRenderExecutor&) = delete
-
MultidrawRenderExecutor &operator=(MultidrawRenderExecutor&) = delete
Private Members
-
const MultidrawContext *context
Pointer to a context that is used for rendering.
Friends
- friend class MultidrawContext
-
inline MultidrawRenderExecutor(const MultidrawContext *context)