simvx.graphics.renderer.gpu_batch

GPU-driven batch rendering with multi-draw indirect (MDI) and fallback.

Module Contents

Classes

GPUBatch

Manages batched draw commands.

Data

API

simvx.graphics.renderer.gpu_batch.log[source]

‘getLogger(…)’

simvx.graphics.renderer.gpu_batch.__all__

[‘GPUBatch’]

class simvx.graphics.renderer.gpu_batch.GPUBatch(device: Any, physical_device: Any, max_draws: int = 1000, *, use_mdi: bool = True)[source]

Manages batched draw commands.

When use_mdi=True (default), uses vkCmdDrawIndexedIndirect to issue all draw commands in a single GPU call. When use_mdi=False, falls back to a loop of vkCmdDrawIndexed calls — functionally identical but slower on GPUs that support MDI.

Usage::

batch = GPUBatch(device, physical_device, max_draws=100)
batch.add_draw(index_count=36, first_instance=0)
batch.upload()
batch.draw(cmd)

Initialization

add_draw(index_count: int, instance_count: int = 1, first_index: int = 0, vertex_offset: int = 0, first_instance: int = 0) int[source]

Add a draw command. Returns the draw index.

add_draws(index_count: int, first_instances: numpy.ndarray | list[int]) int[source]

Bulk-add draw commands sharing the same mesh — avoids per-instance Python loop.

Args: index_count: Index count for the mesh (same for all draws). first_instances: (N,) array of SSBO instance indices.

Returns: Batch offset of the first added draw command.

upload() None[source]

Upload draw commands to GPU indirect buffer.

draw(cmd: Any) None[source]

Record draw commands for the entire batch.

draw_range(cmd: Any, offset: int, count: int) None[source]

Draw a sub-range of commands.

Args: cmd: Vulkan command buffer offset: First draw command index (not byte offset) count: Number of draw commands to execute

reset() None[source]

Clear batch for next frame.

destroy() None[source]

Free GPU resources.