OGRE-Next  4.0.0unstable
Object-Oriented Graphics Rendering Engine
Ogre::MetalVaoManager Class Referencefinal

#include <OgreMetalVaoManager.h>

+ Inheritance diagram for Ogre::MetalVaoManager:

Classes

struct  Block
 
struct  StrideChanger
 

Public Types

typedef vector< Block >::type BlockVec
 
typedef vector< StrideChanger >::type StrideChangerVec
 
- Public Types inherited from Ogre::VaoManager
typedef vector< MemoryStatsEntry >::type MemoryStatsEntryVec
 

Public Member Functions

 MetalVaoManager (MetalDevice *device, const NameValuePairList *params)
 
 ~MetalVaoManager () override
 
void _notifyDeviceStalled ()
 
void _notifyNewCommandBuffer ()
 
void _update () override
 
void _waitUntilCommitedCommandBufferCompleted () override
 Waits for the last committed command buffer completion instead of the last frame completion with command buffer switching, so we can continue to work with current command buffer. More...
 
void bindDrawId ()
 Binds the Draw ID to the current RenderEncoder. (Assumed to be active!) More...
 
void cleanupEmptyPools () override
 Frees GPU memory if there are empty, unused pools. More...
 
AsyncTicketPtr createAsyncTicket (BufferPacked *creator, StagingBuffer *stagingBuffer, size_t elementStart, size_t elementCount) override
 
StagingBuffercreateStagingBuffer (size_t sizeBytes, bool forUpload) override
 Creates a new staging buffer and adds it to the pool. More...
 
MetalDevicegetDevice ()
 
void getMemoryStats (MemoryStatsEntryVec &outStats, size_t &outCapacityBytes, size_t &outFreeBytes, Log *log, bool &outIncludesTextures) const override
 Retrieves memory stats about our GPU pools being managed. More...
 
bool isFrameFinished (uint32 frameCount) override
 See VaoManager::isFrameFinished. More...
 
void unalignedCopy (id< MTLBuffer > dstBuffer, size_t dstOffsetBytes, id< MTLBuffer > srcBuffer, size_t srcOffsetBytes, size_t sizeBytes)
 In macOS before Catalina (i.e. More...
 
void waitForSpecificFrameToFinish (uint32 frameCount) override
 See VaoManager::waitForSpecificFrameToFinish. More...
 
uint8 waitForTailFrameToFinish () override
 
- Public Member Functions inherited from Ogre::VaoManager
 VaoManager (const NameValuePairList *params)
 
virtual ~VaoManager ()
 
virtual void _beginFrame ()
 
uint8 _getDynamicBufferCurrentFrameNoWait () const
 
void _notifyStagingBufferEnteredZeroRef (StagingBuffer *stagingBuffer)
 
void _notifyStagingBufferLeftZeroRef (StagingBuffer *stagingBuffer)
 
ConstBufferPackedcreateConstBuffer (size_t sizeBytes, BufferType bufferType, void *initialData, bool keepAsShadow)
 Creates an constant buffer based on the given parameters. More...
 
IndexBufferPackedcreateIndexBuffer (IndexBufferPacked::IndexType indexType, size_t numIndices, BufferType bufferType, void *initialData, bool keepAsShadow)
 Creates an index buffer based on the given parameters. More...
 
IndirectBufferPackedcreateIndirectBuffer (size_t sizeBytes, BufferType bufferType, void *initialData, bool keepAsShadow)
 Creates an indirect buffer. More...
 
ReadOnlyBufferPackedcreateReadOnlyBuffer (PixelFormatGpu pixelFormat, size_t sizeBytes, BufferType bufferType, void *initialData, bool keepAsShadow)
 Creates a read-only buffer based on the given parameters. More...
 
TexBufferPackedcreateTexBuffer (PixelFormatGpu pixelFormat, size_t sizeBytes, BufferType bufferType, void *initialData, bool keepAsShadow)
 Creates an constant buffer based on the given parameters. More...
 
UavBufferPackedcreateUavBuffer (size_t numElements, uint32 bytesPerElement, uint32 bindFlags, void *initialData, bool keepAsShadow)
 Creates an UAV buffer based on the given parameters. More...
 
VertexArrayObjectcreateVertexArrayObject (const VertexBufferPackedVec &vertexBuffers, IndexBufferPacked *indexBuffer, OperationType opType)
 Creates a VertexArrayObject that binds all the vertex buffers with their respective declarations, and the index buffers. More...
 
VertexBufferPackedcreateVertexBuffer (const VertexElement2Vec &vertexElements, size_t numVertices, BufferType bufferType, void *initialData, bool keepAsShadow)
 Creates a vertex buffer based on the given parameters. More...
 
void deleteStagingBuffers ()
 
void destroyConstBuffer (ConstBufferPacked *constBuffer)
 Destroys the given constant buffer created with createConstBuffer. More...
 
void destroyIndexBuffer (IndexBufferPacked *indexBuffer)
 Destroys the given index buffer created with createIndexBuffer. More...
 
void destroyIndirectBuffer (IndirectBufferPacked *indirectBuffer)
 Destroys the given indirect buffer created with createIndirectBuffer. More...
 
void destroyReadOnlyBuffer (ReadOnlyBufferPacked *readOnlyBuffer)
 Destroys the given texture buffer created with createReadOnlyBuffer. More...
 
void destroyTexBuffer (TexBufferPacked *texBuffer)
 Destroys the given texture buffer created with createTexBuffer. More...
 
void destroyUavBuffer (UavBufferPacked *uavBuffer)
 Destroys the given UAV buffer created with createUavBuffer. More...
 
void destroyVertexArrayObject (VertexArrayObject *vao)
 Destroys the input pointer. More...
 
void destroyVertexBuffer (VertexBufferPacked *vertexBuffer)
 Destroys the given vertex buffer created with createVertexBuffer. More...
 
uint32 getConstBufferAlignment () const
 
size_t getConstBufferMaxSize () const
 
uint32 getDefaultStagingBufferLifetime () const
 
uint32 getDefaultStagingBufferUnfencedTime () const
 
uint8 getDynamicBufferMultiplier () const
 
uint32 getFrameCount ()
 
size_t getReadOnlyBufferMaxSize () const
 
StagingBuffergetStagingBuffer (size_t minSizeBytes, bool forUpload)
 Retrieves a staging buffer for use. More...
 
uint32 getTexBufferAlignment () const
 
size_t getTexBufferMaxSize () const
 
TimergetTimer ()
 
uint32 getUavBufferAlignment () const
 
size_t getUavBufferMaxSize () const
 
bool readOnlyIsTexBuffer () const
 When true, ReadOnlyBufferPacked behaves like TexBufferPacked, i.e. More...
 
void setDefaultStagingBufferlifetime (uint32 lifetime, uint32 unfencedTime)
 Sets the default time for staging buffers. More...
 
bool supportsBaseInstance () const
 
bool supportsIndirectBuffers () const
 When false, IndirectBufferPacked will emulate the mapping behavior, and we need to use the emulated calls in RenderSystem. More...
 
bool supportsPersistentMapping () const
 

Static Public Member Functions

static uint32 getAttributeIndexFor (VertexElementSemantic semantic)
 
static void mergeContiguousBlocks (BlockVec::iterator blockToMerge, BlockVec &blocks)
 
static dispatch_semaphore_t waitFor (dispatch_semaphore_t fenceName, MetalDevice *device)
 Will stall undefinitely until GPU finishes (signals the sync object). More...
 
- Static Public Member Functions inherited from Ogre::VaoManager
static uint32 calculateVertexSize (const VertexElement2Vec &vertexElements)
 Returns the size of a single vertex buffer source with the given declaration, in bytes. More...
 

Member Typedef Documentation

◆ BlockVec

typedef vector<Block>::type Ogre::MetalVaoManager::BlockVec

◆ StrideChangerVec

Constructor & Destructor Documentation

◆ MetalVaoManager()

Ogre::MetalVaoManager::MetalVaoManager ( MetalDevice device,
const NameValuePairList params 
)

◆ ~MetalVaoManager()

Ogre::MetalVaoManager::~MetalVaoManager ( )
override

Member Function Documentation

◆ _notifyDeviceStalled()

void Ogre::MetalVaoManager::_notifyDeviceStalled ( )

◆ _notifyNewCommandBuffer()

void Ogre::MetalVaoManager::_notifyNewCommandBuffer ( )

◆ _update()

void Ogre::MetalVaoManager::_update ( )
overridevirtual

Reimplemented from Ogre::VaoManager.

◆ _waitUntilCommitedCommandBufferCompleted()

void Ogre::MetalVaoManager::_waitUntilCommitedCommandBufferCompleted ( )
overridevirtual

Waits for the last committed command buffer completion instead of the last frame completion with command buffer switching, so we can continue to work with current command buffer.

It's required for BT_DEFAULT_SHARED buffers upload

Remarks
BT_DEFAULT_SHARED were designed for rare uploads. Nevertheless if we need to upload new data we have to be sure that last committed command buffer's completed to avoid artefacts due to data changing on the go. Indeed on some heavy scenes gpu may still execute last committed command buffer that uses BT_DEFAULT_SHARED vertex/index buffers when we come to upload some new data. Of cause we can wait for previous frame completion using waitForSpecificFrameToFinish(), but waitForSpecificFrameToFinish(vaoManager->getFrameCount()) leads to stall() call which is more slow: switches current command buffer and notify everyone with _notifyDeviceStalled() call. So _waitUntilCommitedCommandBufferCompleted() is more lightweight aspecially for Metal render system

Reimplemented from Ogre::VaoManager.

◆ bindDrawId()

void Ogre::MetalVaoManager::bindDrawId ( )

Binds the Draw ID to the current RenderEncoder. (Assumed to be active!)

◆ cleanupEmptyPools()

void Ogre::MetalVaoManager::cleanupEmptyPools ( )
overridevirtual

Frees GPU memory if there are empty, unused pools.

Implements Ogre::VaoManager.

◆ createAsyncTicket()

AsyncTicketPtr Ogre::MetalVaoManager::createAsyncTicket ( BufferPacked creator,
StagingBuffer stagingBuffer,
size_t  elementStart,
size_t  elementCount 
)
overridevirtual

Implements Ogre::VaoManager.

◆ createStagingBuffer()

StagingBuffer* Ogre::MetalVaoManager::createStagingBuffer ( size_t  sizeBytes,
bool  forUpload 
)
overridevirtual

Creates a new staging buffer and adds it to the pool.

See also
getStagingBuffer.
Remarks
The returned buffer starts with a reference count of 1. You should decrease it when you're done using it.

Implements Ogre::VaoManager.

◆ getAttributeIndexFor()

static uint32 Ogre::MetalVaoManager::getAttributeIndexFor ( VertexElementSemantic  semantic)
static

◆ getDevice()

MetalDevice* Ogre::MetalVaoManager::getDevice ( )
inline

◆ getMemoryStats()

void Ogre::MetalVaoManager::getMemoryStats ( MemoryStatsEntryVec outStats,
size_t &  outCapacityBytes,
size_t &  outFreeBytes,
Log log,
bool &  outIncludesTextures 
) const
overridevirtual

Retrieves memory stats about our GPU pools being managed.

The output in the Log will be csv data that resembles the following: Pool Type Offset Bytes Pool Capacity CPU_INACCESSIBLE 0 148128 67108864 CPU_INACCESSIBLE 200000 1024 67108864 CPU_ACCESSIBLE_PERSISTENT 0 1152 16777216

These are the chunks of memory currently in use. If there are multiple entries belonging to the same pool, that means the memory has been fragmented.

The actual output may vary depending on the RenderSystem.

Remarks
Worst case scenario this function has O(N^2) complexity where N is the number of free blocks.
Parameters
outStatsDetailed information about each entry.
outCapacityBytesTotal capacity i.e. total used VRAM in GPU.
outFreeBytesTotal free memory available for consumption.
logOptional to dump all information to a CSV file. Nullptr to avoid dumping.
outIncludesTextures[out] When true, memory reports in outCapacityBytes & outFreeBytes include textures. See Tutorial_Memory on how to deal with this output.

Note outIncludesTextures may be false but some entries in outStats[n].bPoolHasTextures may be true. If this happens, then outCapacityBytes & outFreeBytes don't include texture consumption; but the pools with bPoolHasTextures in MemoryStatsEntryVec may.

Implements Ogre::VaoManager.

◆ isFrameFinished()

bool Ogre::MetalVaoManager::isFrameFinished ( uint32  frameCount)
overridevirtual

◆ mergeContiguousBlocks()

static void Ogre::MetalVaoManager::mergeContiguousBlocks ( BlockVec::iterator  blockToMerge,
BlockVec blocks 
)
static
See also
StagingBuffer::mergeContiguousBlocks

◆ unalignedCopy()

void Ogre::MetalVaoManager::unalignedCopy ( id< MTLBuffer >  dstBuffer,
size_t  dstOffsetBytes,
id< MTLBuffer >  srcBuffer,
size_t  srcOffsetBytes,
size_t  sizeBytes 
)

In macOS before Catalina (i.e.

<= Mojave), MTLBlitCommandEncoder copyFromBuffer must be aligned to 4 bytes. When that's not possible, we have to workaround this limitation with a compute shader

◆ waitFor()

static dispatch_semaphore_t Ogre::MetalVaoManager::waitFor ( dispatch_semaphore_t  fenceName,
MetalDevice device 
)
static

Will stall undefinitely until GPU finishes (signals the sync object).

Parameters
fenceNameSync object to wait for. Will be deleted on success. On failure, throws an exception and fenceName will not be deleted.
deviceDevice this fence is linked to.
Returns
Null ptr on success. Should throw on failure, but if this function for some strange reason doesn't throw, it is programmed to return 'fenceName'

◆ waitForSpecificFrameToFinish()

void Ogre::MetalVaoManager::waitForSpecificFrameToFinish ( uint32  frameCount)
overridevirtual

◆ waitForTailFrameToFinish()

uint8 Ogre::MetalVaoManager::waitForTailFrameToFinish ( )
overridevirtual

The documentation for this class was generated from the following file: