|
VisuTwin Canvas
C++ 3D Engine — Metal Backend
|
#include <platform/graphics/metal/metalUniformRingBuffer.h>
Public Member Functions | |
| size_t | alignedSlotSize () const |
| size_t | allocate (const void *data, size_t dataSize) |
| void | beginFrame () |
| MTL::Buffer * | buffer () const |
| size_t | currentDrawCount () const |
| void | endFrame (MTL::CommandBuffer *commandBuffer) |
| size_t | maxDrawsPerFrame () const |
| MetalUniformRingBuffer (const MetalUniformRingBuffer &)=delete | |
| MetalUniformRingBuffer (MetalUniformRingBuffer &&)=delete | |
| MetalUniformRingBuffer (MTL::Device *device, size_t maxDrawsPerFrame, size_t uniformStructSize, const char *label="UniformRing") | |
| MetalUniformRingBuffer & | operator= (const MetalUniformRingBuffer &)=delete |
| MetalUniformRingBuffer & | operator= (MetalUniformRingBuffer &&)=delete |
| size_t | totalSize () const |
| ~MetalUniformRingBuffer () | |
Static Public Attributes | |
| static constexpr size_t | kAlignment = 256 |
| static constexpr int | kMaxInflightFrames = 3 |
Triple-buffered ring buffer for per-draw uniform data.
Replaces setVertexBytes()/setFragmentBytes() with a pre-allocated MTLBuffer where each draw call's uniforms are sub-allocated from a linearly-advancing write cursor. Three frame regions prevent CPU/GPU contention without explicit fencing per draw.
Apple Metal Best Practices Guide recommends:
Usage:
Definition at line 35 of file metalUniformRingBuffer.h.
|
inline |
| device | Metal device for buffer allocation |
| maxDrawsPerFrame | Maximum draw calls expected per frame (grows if exceeded) |
| uniformStructSize | Size of the largest uniform struct this ring will hold |
| label | Debug label for Metal GPU capture |
Definition at line 47 of file metalUniformRingBuffer.h.
References kAlignment, kMaxInflightFrames, and maxDrawsPerFrame().
Referenced by MetalUniformRingBuffer(), MetalUniformRingBuffer(), operator=(), and operator=().
|
inline |
Definition at line 64 of file metalUniformRingBuffer.h.
|
delete |
References MetalUniformRingBuffer().
|
delete |
References MetalUniformRingBuffer().
|
inlinenodiscard |
Definition at line 123 of file metalUniformRingBuffer.h.
|
inlinenodiscard |
Write uniform data for one draw call into the ring buffer.
| data | Pointer to uniform struct data |
| dataSize | Size in bytes of the data to copy (must be <= alignedSlotSize) |
Definition at line 96 of file metalUniformRingBuffer.h.
Referenced by visutwin::canvas::MetalUniformBinder::setTransformUniforms(), and visutwin::canvas::MetalUniformBinder::submitPerDrawUniforms().
|
inline |
Call at frame start. Blocks if GPU hasn't finished with this region. Must be called before any allocate() calls for the new frame.
Definition at line 82 of file metalUniformRingBuffer.h.
References kMaxInflightFrames.
|
inlinenodiscard |
Definition at line 122 of file metalUniformRingBuffer.h.
|
inlinenodiscard |
Definition at line 124 of file metalUniformRingBuffer.h.
|
inline |
Register GPU completion signal on the frame's command buffer. Must be called on the LAST command buffer committed per frame (typically the present buffer in onFrameEnd).
Definition at line 113 of file metalUniformRingBuffer.h.
|
inlinenodiscard |
Definition at line 125 of file metalUniformRingBuffer.h.
Referenced by MetalUniformRingBuffer().
|
delete |
References MetalUniformRingBuffer().
|
delete |
References MetalUniformRingBuffer().
|
inlinenodiscard |
Definition at line 126 of file metalUniformRingBuffer.h.
|
staticconstexpr |
Definition at line 39 of file metalUniformRingBuffer.h.
Referenced by MetalUniformRingBuffer().
|
staticconstexpr |
Definition at line 38 of file metalUniformRingBuffer.h.
Referenced by beginFrame(), and MetalUniformRingBuffer().