OGRE-Next
2.3
Object-Oriented Graphics Rendering Engine
|
#include <OgreMetalVaoManager.h>
Classes | |
struct | Block |
struct | StrideChanger |
Public Types | |
typedef vector< Block >::type | BlockVec |
typedef vector< MemoryStatsEntry >::type | MemoryStatsEntryVec |
typedef vector< StrideChanger >::type | StrideChangerVec |
Public Member Functions | |
MetalVaoManager (MetalDevice *device, const NameValuePairList *params) | |
~MetalVaoManager () override | |
virtual void | _beginFrame () |
uint8 | _getDynamicBufferCurrentFrameNoWait () const |
void | _notifyDeviceStalled () |
void | _notifyNewCommandBuffer () |
void | _notifyStagingBufferEnteredZeroRef (StagingBuffer *stagingBuffer) |
void | _notifyStagingBufferLeftZeroRef (StagingBuffer *stagingBuffer) |
void | _update () override |
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 |
ConstBufferPacked * | createConstBuffer (size_t sizeBytes, BufferType bufferType, void *initialData, bool keepAsShadow) |
Creates an constant buffer based on the given parameters. More... | |
IndexBufferPacked * | createIndexBuffer (IndexBufferPacked::IndexType indexType, size_t numIndices, BufferType bufferType, void *initialData, bool keepAsShadow) |
Creates an index buffer based on the given parameters. More... | |
IndirectBufferPacked * | createIndirectBuffer (size_t sizeBytes, BufferType bufferType, void *initialData, bool keepAsShadow) |
Creates an indirect buffer. More... | |
ReadOnlyBufferPacked * | createReadOnlyBuffer (PixelFormatGpu pixelFormat, size_t sizeBytes, BufferType bufferType, void *initialData, bool keepAsShadow) |
Creates a read-only buffer based on the given parameters. More... | |
StagingBuffer * | createStagingBuffer (size_t sizeBytes, bool forUpload) override |
Creates a new staging buffer and adds it to the pool. More... | |
TexBufferPacked * | createTexBuffer (PixelFormatGpu pixelFormat, size_t sizeBytes, BufferType bufferType, void *initialData, bool keepAsShadow) |
Creates an constant buffer based on the given parameters. More... | |
UavBufferPacked * | createUavBuffer (size_t numElements, uint32 bytesPerElement, uint32 bindFlags, void *initialData, bool keepAsShadow) |
Creates an UAV buffer based on the given parameters. More... | |
VertexArrayObject * | createVertexArrayObject (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... | |
VertexBufferPacked * | createVertexBuffer (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 |
MetalDevice * | getDevice () |
uint8 | getDynamicBufferMultiplier () const |
uint32 | getFrameCount () |
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... | |
size_t | getReadOnlyBufferMaxSize () const |
StagingBuffer * | getStagingBuffer (size_t minSizeBytes, bool forUpload) |
Retrieves a staging buffer for use. More... | |
uint32 | getTexBufferAlignment () const |
size_t | getTexBufferMaxSize () const |
Timer * | getTimer () |
uint32 | getUavBufferAlignment () const |
size_t | getUavBufferMaxSize () const |
bool | isFrameFinished (uint32 frameCount) override |
See VaoManager::isFrameFinished. More... | |
void | operator delete (void *ptr) |
void | operator delete (void *ptr, const char *, int, const char *) |
void | operator delete (void *ptr, void *) |
void | operator delete[] (void *ptr) |
void | operator delete[] (void *ptr, const char *, int, const char *) |
void * | operator new (size_t sz) |
void * | operator new (size_t sz, const char *file, int line, const char *func) |
operator new, with debug line info More... | |
void * | operator new (size_t sz, void *ptr) |
placement operator new More... | |
void * | operator new[] (size_t sz) |
void * | operator new[] (size_t sz, const char *file, int line, const char *func) |
array operator new, with debug line info More... | |
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 |
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 |
Static Public Member Functions | |
static uint32 | calculateVertexSize (const VertexElement2Vec &vertexElements) |
Returns the size of a single vertex buffer source with the given declaration, in bytes. More... | |
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... | |
typedef vector<Block>::type Ogre::MetalVaoManager::BlockVec |
|
inherited |
typedef vector<StrideChanger>::type Ogre::MetalVaoManager::StrideChangerVec |
Ogre::MetalVaoManager::MetalVaoManager | ( | MetalDevice * | device, |
const NameValuePairList * | params | ||
) |
|
override |
|
inlinevirtualinherited |
Reimplemented in Ogre::D3D11VaoManager.
|
inlineinherited |
void Ogre::MetalVaoManager::_notifyDeviceStalled | ( | ) |
void Ogre::MetalVaoManager::_notifyNewCommandBuffer | ( | ) |
|
inherited |
|
inherited |
|
overridevirtual |
Reimplemented from Ogre::VaoManager.
void Ogre::MetalVaoManager::bindDrawId | ( | ) |
Binds the Draw ID to the current RenderEncoder. (Assumed to be active!)
|
staticinherited |
Returns the size of a single vertex buffer source with the given declaration, in bytes.
|
overridevirtual |
Frees GPU memory if there are empty, unused pools.
Implements Ogre::VaoManager.
|
overridevirtual |
Implements Ogre::VaoManager.
|
inherited |
Creates an constant buffer based on the given parameters.
Behind the scenes, the buffer is actually part of much larger buffer, in order to reduce bindings at runtime. (depends on the RenderSystem, on D3D11 we're forced to give its own buffer)
sizeBytes | The size in bytes of the given constant buffer. API restrictions may apply. To stay safe keep it multiple of 16, don't request more than 64kb per buffer. |
|
inherited |
Creates an index buffer based on the given parameters.
Behind the scenes, the buffer is actually part of much larger buffer, in order to reduce bindings at runtime.
indexType | Whether this Index Buffer should be 16-bit (recommended) or 32-bit |
numIndices | The number of indices |
|
inherited |
Creates an indirect buffer.
|
inherited |
Creates a read-only buffer based on the given parameters.
Behind the scenes, the buffer is actually part of much larger buffer, in order to reduce bindings at runtime. (depends on the RenderSystem, on D3D11 we're forced to give its own buffer)
pixelFormat | The pixel format for the texture buffer. |
sizeBytes | The size in bytes of the given constant buffer. API restrictions may apply. |
|
overridevirtual |
Creates a new staging buffer and adds it to the pool.
Implements Ogre::VaoManager.
|
inherited |
Creates an constant buffer based on the given parameters.
Behind the scenes, the buffer is actually part of much larger buffer, in order to reduce bindings at runtime. (depends on the RenderSystem, on D3D11 we're forced to give its own buffer)
pixelFormat | The pixel format for the texture buffer. |
sizeBytes | The size in bytes of the given constant buffer. API restrictions may apply. |
|
inherited |
Creates an UAV buffer based on the given parameters.
Behind the scenes, the buffer is actually part of much larger buffer, in order to reduce bindings at runtime. (depends on the RenderSystem, on D3D11 we're forced to give its own buffer)
sizeBytes | The size in bytes of the given constant buffer. API restrictions may apply. |
bindFlags | A combination of BufferBindFlags. BB_FLAG_UAV is implicit. |
|
inherited |
Creates a VertexArrayObject that binds all the vertex buffers with their respective declarations, and the index buffers.
The returned value is immutable and thus cannot be modified.
vertexBuffers | An array of vertex buffers to be bound to the vertex array object. |
indexBuffer | The index buffer to be bound. |
opType | Type of operation. Cannot be changed later. |
|
inherited |
Creates a vertex buffer based on the given parameters.
Behind the scenes, the vertex buffer is part of much larger vertex buffer, in order to reduce bindings at runtime.
vertexElements | A list of element bindings for this vertex buffer. Once created, changing VertexElements is not possible, you'll have to create another Vertex Buffer. |
numVertices | The number of vertices for this vertex |
bufferType | The type of buffer for this vertex buffer. @See BufferType::BT_DYNAMIC special case. |
initialData | Initial data the buffer will hold upon creation. Can be null (i.e. you plan to upload later). Cannot be null when bufferType is BT_IMMUTABLE. Must have enough room to prevent an overflow. |
keepAsShadow | Whether to keep the pointer "initialData" as a shadow copy of the contents. @See BufferPacked::BufferPacked regarding on who is responsible for freeing this pointer and what happens if an exception was raised. |
|
inherited |
|
inherited |
Destroys the given constant buffer created with createConstBuffer.
constBuffer | Constant Buffer created with createConstBuffer |
|
inherited |
Destroys the given index buffer created with createIndexBuffer.
indexBuffer | Index Buffer created with createIndexBuffer |
|
inherited |
Destroys the given indirect buffer created with createIndirectBuffer.
indirectBuffer | Indirect Buffer created with createIndirectBuffer |
|
inherited |
Destroys the given texture buffer created with createReadOnlyBuffer.
readOnlyBuffer | ReadOnlyBufferPacked created with createReadOnlyBuffer |
|
inherited |
Destroys the given texture buffer created with createTexBuffer.
constBuffer | Texture Buffer created with createTexBuffer |
|
inherited |
Destroys the given UAV buffer created with createUavBuffer.
constBuffer | Uav Buffer created with createUavBuffer |
|
inherited |
Destroys the input pointer.
After this call, it's no longer valid
|
inherited |
Destroys the given vertex buffer created with createVertexBuffer.
NOTE: Vertex Buffers created by a MultiSourceVertexBufferPool must be freed by the pool that created it, don't use this function for those.
|
static |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inline |
|
inlineinherited |
|
inlineinherited |
|
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.
outStats | Detailed information about each entry. |
outCapacityBytes | Total capacity i.e. total used VRAM in GPU. |
outFreeBytes | Total free memory available for consumption. |
log | Optional 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.
|
inlineinherited |
|
inherited |
Retrieves a staging buffer for use.
We'll search for existing ones that can hold minSizeBytes. We first prioritize those that won't cause a stall at all. Then those that will cause a partial stall, and otherwise return one that will cause full stall. If we can't find any existing buffer that can hold the requested number bytes, we'll create a new one.
sizeBytes | Minimum size, in bytes, of the staging buffer. The returned buffer may be bigger. |
forUpload | True if it should be used to upload data to GPU, false to download. |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
overridevirtual |
See VaoManager::isFrameFinished.
Implements Ogre::VaoManager.
|
static |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
|
inlineinherited |
operator new, with debug line info
|
inlineinherited |
placement operator new
|
inlineinherited |
|
inlineinherited |
array operator new, with debug line info
|
inlineinherited |
When true, ReadOnlyBufferPacked behaves like TexBufferPacked, i.e.
assigned to texture buffer slots.
When false, ReadOnlyBufferPacked behaves like UavBufferPacked i.e. assigned to UAV buffer slots. Except D3D11, which still uses texture buffer slots when false but chooses StructuredBuffer over Buffer
|
inherited |
Sets the default time for staging buffers.
Staging buffers are recycled/reused. When their reference count reaches 0, this VaoManager will begin to track how long since the last time they've reached ref count 0. When the time threshold is met, the staging buffer gets removed.
StagingBuffers may produce "pops" when created (due to API/driver stalls) so we reuse them. We keep track of how long StagingBuffers have been remained unused, and delete old ones. The intention is to be able to recycle old buffers, while getting rid of the excess if a sudden spike happened. That's what the lifetime threshold controls.
We also have the "unfenced threshold". This controls something very different. StagingBuffers usages need fences to check whether we're done using the buffer. But we don't issue a fence every time you do something with them, because that could result in a lot of fences (i.e. imagine you do a 1000 uploads of 16 bytes each, in succession, we shouldn't do 1000 fences); so we fence when certain upload/download thresholds are met (i.e. you've uploaded 1MB of data). So if you've uploaded 750kb so far, no fence will be issued. But if you upload 300kb more, we will fence. But what happens if you've only uploaded 750kb and then nothing more for the last 10 minutes? Since we haven't fenced, and now you need to upload a lot more, we don't know if those 750kb are done uploading because we never fenced it. It probably ended 10 minutes ago, but we won't know. We would have to fence now and perform a full stall waiting for that fence. To solve this edge case, we fence whenever X time has elapsed without fencing (and only if there's data that remains unfenced of course). That's what the unfenced threshold is for.
lifetime | Time in milliseconds. The default is 5 minutes. A staging buffer that remained at zero ref. count for lifetime milliseconds will be destroyed. |
unfencedTime | For efficiency reasons (API overhead), some staging buffers implementations will not track all hazards on fences. A staging buffer that remained at zero ref. count for unfencedTime milliseconds will be told to clean their hazards, creating the missing appropiate fences. unfencedTime can't be higher than lifetime. unfencedTime should not be too far away from lifetime, and not too soon either, to maximize the chances of no stalls when we finally destroy it and avoid excessive API overhead in keeping fences alive. The default is 4 minutes 59 seconds. |
|
inlineinherited |
|
inlineinherited |
When false, IndirectBufferPacked will emulate the mapping behavior, and we need to use the emulated calls in RenderSystem.
|
inlineinherited |
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
|
static |
Will stall undefinitely until GPU finishes (signals the sync object).
fenceName | Sync object to wait for. Will be deleted on success. On failure, throws an exception and fenceName will not be deleted. |
device | Device this fence is linked to. |
|
overridevirtual |
See VaoManager::waitForSpecificFrameToFinish.
Implements Ogre::VaoManager.
|
overridevirtual |
Implements Ogre::VaoManager.