Ejemplo n.º 1
0
static pm4::Buffer *
allocateCommandBuffer()
{
   if (gx2::internal::getMainCoreId() != coreinit::OSGetCoreId()) {
      // Only the main core can have command buffers
      gLog->warn("Tried to allocate command buffer on non-main graphics core");
      return nullptr;
   }

   auto retiredTimestamp = GX2GetRetiredTimeStamp();
   auto buffer = &gCommandBufferPool.items[gCommandBufferPool.itemsHead];

   if (buffer->submitTime > retiredTimestamp) {
      GX2WaitTimeStamp(buffer->submitTime);
   }

   buffer->userBuffer = false;
   buffer->submitTime = 0;
   buffer->curSize = 0;
   buffer->maxSize = gCommandBufferPool.itemSize / 4;
   buffer->buffer = gCommandBufferPool.base + buffer->maxSize * gCommandBufferPool.itemsHead;
   gCommandBufferPool.itemsHead++;

   if (gCommandBufferPool.itemsHead >= gCommandBufferPool.items.size()) {
      gCommandBufferPool.itemsHead = 0;
   }

   return buffer;
}
Ejemplo n.º 2
0
static pm4::Buffer *
allocateCommandBuffer(uint32_t size)
{
   // This is to ensure that only one command buffer is lease from our
   //  pool at any particular time.
   decaf_check(!sBufferPoolLeased);

   // Only the main core can have command buffers
   if (gx2::internal::getMainCoreId() != coreinit::OSGetCoreId()) {
      gLog->warn("Tried to allocate command buffer on non-main graphics core");
      return nullptr;
   }

   // Lets try to get ourselves a buffer from the pool
   uint32_t *allocatedBuffer = nullptr;
   uint32_t allocatedSize = 0;

   while (!allocatedBuffer) {
      allocatedBuffer = allocateFromPool(size, allocatedSize);

      if (!allocatedBuffer) {
         // If we failed to allocate from the pool, lets wait till
         //  a buffer has been freed, and then try again
         GX2WaitTimeStamp(GX2GetRetiredTimeStamp() + 1);
      }
   }

   // We need to grab a buffer object to hold the info
   auto cb = allocateBufferObj();
   cb->displayList = false;
   cb->submitTime = 0;
   cb->curSize = 0;
   cb->maxSize = allocatedSize;
   cb->buffer = allocatedBuffer;

   sBufferPoolLeased = true;
   return cb;
}