MultidrawContext

template<typename PerDrawDataT>
class MultidrawContext

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.

Public Types

using MultidrawParametersSetter = eastl::fixed_function<sizeof(void*), void(uint32_t draw_index, uint32_t &index_count_per_instance, uint32_t &instance_count, uint32_t &start_index_location, int32_t &base_vertex_location, PerDrawDataT &per_draw_data)>

Type for a callback that is called for each draw call to fill draw call parameters. We don’t allow to fill startInstanceLocation because it is used for draw call id on some platforms.

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.

inline MultidrawRenderExecutor fillBuffers(uint32_t drawcalls_count, const MultidrawParametersSetter &params_setter)

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.

  • params_setter – function that sets draw call parameters.

Returns

executor that could be used to render draw calls.

inline void close()

Closes buffers.

Private Functions

inline eastl::string getPerDrawArgsBufferName() const

Returns name for per draw parameters buffer.

Private Members

eastl::string name

Name for context that is used as a buffer name and as a prefix for helper buffers.

UniqueBuf 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.

uint32_t lastOffset = 0

Offset in buffer for next unused draw call.

Private Static Functions

static inline bool usesExtendedMultiDrawStruct()

Checks if extended draw call arguments structure is used.

static inline uint32_t bytesCountPerDrawcall()

Returns size of draw call arguments structure for a current driver.

static inline uint32_t dwordsCountPerDrawcall()

Returns size of draw call arguments structure in dwords for a current driver.

static inline 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.

struct ExtendedDrawIndexedIndirectArgs

Extended draw call arguments structure.

This structure is used for platforms that pass draw call id/per draw parameters using per draw root constants. Currently it is used only for DX12.

Public Members

uint32_t drawcallId
DrawIndexedIndirectArgs args
class MultidrawRenderExecutor

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