gceSTATUS gcoQUEUE_Destroy( IN gcoQUEUE Queue ) { gceSTATUS status; gcmHEADER_ARG("Queue=0x%x", Queue); /* Verify the arguments. */ gcmVERIFY_OBJECT(Queue, gcvOBJ_QUEUE); #ifndef __QNXNTO__ /* Free any records in the queue. */ while (Queue->head != gcvNULL) { gcsQUEUE_PTR record; /* Unlink the first record from the queue. */ record = Queue->head; Queue->head = record->next; gcmONERROR(gcmOS_SAFE_FREE(gcvNULL, record)); } /* Free any records in the free list. */ while (Queue->freeList != gcvNULL) { gcsQUEUE_PTR record; /* Unlink the first record from the queue. */ record = Queue->freeList; Queue->freeList = record->next; gcmONERROR(gcmOS_SAFE_FREE(gcvNULL, record)); } #else /* Free any records in the queue. */ if ( Queue->records ) { gcmVERIFY_OK(gcoOS_FreeNonPagedMemory(gcvNULL, BUFFER_SIZE, gcvNULL, Queue->records)); } #endif /* Free the queue. */ gcmONERROR(gcmOS_SAFE_FREE(gcvNULL, Queue)); /* Success. */ gcmFOOTER_NO(); return gcvSTATUS_OK; OnError: /* Return the status. */ gcmFOOTER(); return status; }
/******************************************************************************* ** ** gcoDUMP_Destroy ** ** Destroy a gcoDUMP object created by gcDUMP_COnstruct. ** ** INPUT: ** ** gcoDUMP Dump ** Pointer to a gcoDUMP object. ** ** OUTPUT: ** ** Nothing. */ gceSTATUS gcoDUMP_Destroy( IN gcoDUMP Dump ) { gcmHEADER_ARG("Dump=0x%x", Dump); /* Verify the arguments. */ gcmVERIFY_OBJECT(Dump, gcvOBJ_DUMP); if (Dump->file != gcvNULL) { if (Dump->frameStart != 0) { gcoDUMP_FrameEnd(Dump); } /* Close any open file. */ gcmVERIFY_OK(gcoDUMP_Control(Dump, gcvNULL)); } if (gcPLS.hal->dump == Dump) { /* Remove current gcoDUMP object. */ gcPLS.hal->dump = gcvNULL; } /* Free the gcoDUMP structure. */ gcmVERIFY_OK(gcmOS_SAFE_FREE(gcvNULL, Dump)); /* Success. */ gcmFOOTER_NO(); return gcvSTATUS_OK; }
gceSTATUS glfCompactNamedObjectList( IN glsCONTEXT_PTR Context, IN glsNAMEDOBJECTLIST_PTR List ) { gceSTATUS status = gcvSTATUS_OK; gcmHEADER_ARG("Context=0x%x List=0x%x", Context, List); do { gceSTATUS last; glsNAMEDOBJECT_PTR wrapper = List->freeList; while (wrapper) { glsNAMEDOBJECT_PTR temp = wrapper; wrapper = wrapper->next; gcmCHECK_STATUS(gcmOS_SAFE_FREE(gcvNULL, temp)); } List->freeList = gcvNULL; } while (gcvFALSE); gcmFOOTER(); return status; }
void _glshDereferenceRenderbuffer( GLContext Context, GLRenderbuffer Renderbuffer ) { gcmASSERT((Renderbuffer->object.reference - 1) >= 0); if (--Renderbuffer->object.reference == 0) { if (Renderbuffer->surface != gcvNULL) { if (Renderbuffer->combined == gcvNULL) { gcmVERIFY_OK(gcoSURF_Destroy(Renderbuffer->surface)); } else { Renderbuffer->combined->combined = gcvNULL; } } gcmVERIFY_OK(gcmOS_SAFE_FREE(gcvNULL, Renderbuffer)); } }
static GLRenderbuffer _NewRenderbuffer( GLContext Context, GLuint Name ) { GLRenderbuffer renderbuffer; gctPOINTER pointer = gcvNULL; /* Allocate memory for the renderbuffer object. */ if (gcmIS_ERROR(gcoOS_Allocate(gcvNULL, gcmSIZEOF(struct _GLRenderbuffer), &pointer))) { /* Out of memory error. */ gcmFATAL("%s(%d): Out of memory", __FUNCTION__, __LINE__); gl2mERROR(GL_OUT_OF_MEMORY); return gcvNULL; } renderbuffer = pointer; /* Create a new object. */ if (!_glshInsertObject(&Context->renderbufferObjects, &renderbuffer->object, GLObject_Renderbuffer, Name)) { /* Roll back. */ gcmVERIFY_OK(gcmOS_SAFE_FREE(gcvNULL, renderbuffer)); /* Out of memory error. */ gcmFATAL("%s(%d): Out of memory", __FUNCTION__, __LINE__); gl2mERROR(GL_OUT_OF_MEMORY); return gcvNULL; } /* The renderbuffer object is not yet bound. */ renderbuffer->width = 0; renderbuffer->height = 0; renderbuffer->format = GL_NONE; renderbuffer->surface = gcvNULL; renderbuffer->combined = gcvNULL; renderbuffer->eglUsed = GL_FALSE; renderbuffer->object.reference = 1; /* Return the renderbuffer. */ return renderbuffer; }
static gceSTATUS gcoBUFFER_FreeObjects( IN gcoBUFFER Buffer ) { gceSTATUS status; gctUINT i; gcmHEADER_ARG("Buffer=0x%x", Buffer); /* Roll back all command buffers. */ for (i = 0; i < gcmCOUNTOF(Buffer->commandBuffers); i += 1) { if (Buffer->commandBuffers[i] != gcvNULL) { /* Destroy command buffer. */ gcmONERROR(gcoCMDBUF_Destroy(Buffer->commandBuffers[i])); Buffer->commandBuffers[i] = gcvNULL; } if (Buffer->signal[i] != gcvNULL) { /* Destroy signal. */ gcmONERROR(gcoOS_DestroySignal(gcvNULL, Buffer->signal[i])); Buffer->signal[i] = gcvNULL; } } /* Free the object memory. */ gcmONERROR(gcmOS_SAFE_FREE(gcvNULL, Buffer)); /* Success. */ gcmFOOTER(); return gcvSTATUS_OK; OnError: /* Return the status. */ gcmFOOTER(); return status; }
static void _DestroyThreadData( gcsTLS_PTR TLS ) { gcmHEADER_ARG("TLS=0x%x", TLS); if (TLS->context != gcvNULL) { /*VEGLThreadData thread;*/ VEGLDisplay head; /*thread = (VEGLThreadData) TLS->context;*/ head = (VEGLDisplay) gcoOS_GetPLSValue(gcePLS_VALUE_EGL_DISPLAY_INFO); while (head != EGL_NO_DISPLAY) { VEGLDisplay display = head; if (display->ownerThread == gcoOS_GetCurrentThreadID()) { /* This thread has not eglTerminated the display.*/ eglTerminate(display); } head = display->next; if (TLS->ProcessExiting) { gcmVERIFY_OK(gcmOS_SAFE_FREE(gcvNULL, display)); gcoOS_SetPLSValue(gcePLS_VALUE_EGL_DISPLAY_INFO, (gctPOINTER) head); } } TLS->context = gcvNULL; } gcmFOOTER_NO(); }
gceSTATUS glfDestroyNamedObjectList( IN glsCONTEXT_PTR Context, IN glsNAMEDOBJECTLIST_PTR List ) { gceSTATUS status = gcvSTATUS_OK; gcmHEADER_ARG("Context=0x%x List=0x%x", Context, List); do { gceSTATUS last; gctINT i; /* Free all objects in the free list. */ gcmCHECK_STATUS(glfCompactNamedObjectList(Context, List)); /* Free all existing objects. */ for (i = 0; i < glvNAMEDOBJECT_HASHTABLE_SIZE; i++) { glsNAMEDOBJECT_PTR wrapper = List->hashTable[i]; while (wrapper) { glsNAMEDOBJECT_PTR temp = wrapper; wrapper = wrapper->next; gcmCHECK_STATUS((*temp->deleteObject)(Context, temp->object)); gcmCHECK_STATUS(gcmOS_SAFE_FREE(gcvNULL, temp)); } } } while (gcvFALSE); gcmFOOTER(); return status; }
/******************************************************************************* ** ** gcoCMDBUF_Destroy ** ** Destroy a gcoCMDBUF object. ** ** INPUT: ** ** gcoCMDBUF CommandBuffer ** Pointer to an gcoCMDBUF object. ** ** OUTPUT: ** ** None. */ gceSTATUS gcoCMDBUF_Destroy( IN gcoCMDBUF CommandBuffer ) { gceSTATUS status; gcsHAL_INTERFACE iface; gcmHEADER_ARG("CommandBuffer=0x%x", CommandBuffer); /* Verify the object. */ gcmVERIFY_OBJECT(CommandBuffer, gcvOBJ_COMMANDBUFFER); if (CommandBuffer->logical != gcvNULL) { /* Use events to free the buffer. */ iface.command = gcvHAL_FREE_CONTIGUOUS_MEMORY; iface.u.FreeContiguousMemory.bytes = CommandBuffer->bytes; iface.u.FreeContiguousMemory.physical = CommandBuffer->physical; iface.u.FreeContiguousMemory.logical = CommandBuffer->logical; /* Send event. */ gcmONERROR(gcoHARDWARE_CallEvent(&iface)); /* Reset the buffer pointer. */ CommandBuffer->logical = gcvNULL; } #if gcdSECURE_USER if (CommandBuffer->hintArray != gcvNULL) { #ifdef __QNXNTO__ gcmONERROR(gcoOS_FreeNonPagedMemory( gcvNULL, CommandBuffer->hintArraySize, gcvNULL, CommandBuffer->hintArray )); #else gcmONERROR(gcmOS_SAFE_FREE(gcvNULL, CommandBuffer->hintArray)); #endif CommandBuffer->hintArray = CommandBuffer->hintArrayTail = gcvNULL; } #endif /* Free the gcoCMDBUF object. */ #ifdef __QNXNTO__ gcmONERROR(gcoOS_FreeNonPagedMemory( gcvNULL, gcmSIZEOF(struct _gcoCMDBUF), gcvNULL, CommandBuffer )); #else gcmONERROR(gcmOS_SAFE_FREE(gcvNULL, CommandBuffer)); #endif /* Success. */ gcmFOOTER_NO(); return gcvSTATUS_OK; OnError: /* Return the status. */ gcmFOOTER(); return status; }
/******************************************************************************* ** ** gcoCMDBUF_Construct ** ** Construct a new gcoCMDBUF object. ** ** INPUT: ** ** gcoOS Os ** Pointer to a gcoOS object. ** ** gcoHARDWARE Hardware ** Pointer to a gcoHARDWARE object. ** ** gctSIZE_T Bytes ** Number of bytes for the buffer. ** ** gcsCOMMAND_BUFFER_PTR Info ** Alignment and head/tail information. ** ** OUTPUT: ** ** gcoCMDBUF * CommandBuffer ** Pointer to a variable that will hold the the gcoCMDBUF object ** pointer. */ gceSTATUS gcoCMDBUF_Construct( IN gcoOS Os, IN gcoHARDWARE Hardware, IN gctSIZE_T Bytes, IN gcsCOMMAND_INFO_PTR Info, OUT gcoCMDBUF * CommandBuffer ) { gceSTATUS status; gcoCMDBUF commandBuffer = gcvNULL; gctSIZE_T objectSize; #ifdef __QNXNTO__ gctPHYS_ADDR physical; #else gctPOINTER pointer = gcvNULL; #endif gcmHEADER_ARG("Bytes=%lu Info=0x%x", Bytes, Info); /* Verify the arguments. */ gcmDEBUG_VERIFY_ARGUMENT(Bytes > 0); gcmDEBUG_VERIFY_ARGUMENT(CommandBuffer != gcvNULL); /* Set the size of the object. */ objectSize = gcmSIZEOF(struct _gcoCMDBUF); /* Allocate the gcoCMDBUF object. */ #ifdef __QNXNTO__ /* gcoCMDBUF object needs to be accessible from the kernel; to avoid copying of the data for each access, allocate the object from the kernel non-paged memory. */ gcmONERROR(gcoOS_AllocateNonPagedMemory( gcvNULL, gcvTRUE, &objectSize, &physical, (gctPOINTER *) &commandBuffer )); #else /* Currently in most OS we are able to access the user-side data from the kernel by simple memory mapping, therefore here we allocate the object from the cached user memory. */ gcmONERROR(gcoOS_Allocate(gcvNULL, objectSize, &pointer)); commandBuffer = pointer; #endif /* Reset the command buffer object. */ gcmONERROR(gcoOS_ZeroMemory(commandBuffer, objectSize)); /* Initialize the gcoCMDBUF object. */ commandBuffer->object.type = gcvOBJ_COMMANDBUFFER; commandBuffer->bytes = Bytes; /* Allocate the physical buffer for the command. */ gcmONERROR(gcoOS_AllocateContiguous( gcvNULL, gcvTRUE, &commandBuffer->bytes, &commandBuffer->physical, &commandBuffer->logical )); /* Initialize command buffer. */ commandBuffer->free = commandBuffer->bytes; #if gcdSECURE_USER /* Determine the size of the state array. */ commandBuffer->hintArraySize = Bytes; /* Allocate the state array. */ #ifdef __QNXNTO__ gcmONERROR(gcoOS_AllocateNonPagedMemory( gcvNULL, gcvTRUE, &commandBuffer->hintArraySize, &physical, (gctPOINTER *) &commandBuffer->hintArray )); #else gcmONERROR(gcoOS_Allocate( gcvNULL, commandBuffer->hintArraySize, &pointer )); commandBuffer->hintArray = pointer; #endif /* Initialize the state array tail pointer. */ commandBuffer->hintArrayTail = commandBuffer->hintArray; #endif /* Return pointer to the gcoCMDBUF object. */ *CommandBuffer = commandBuffer; /* Success. */ gcmFOOTER_ARG("*CommandBuffer=0x%x", *CommandBuffer); return gcvSTATUS_OK; OnError: /* Roll back. */ if (commandBuffer != gcvNULL) { if (commandBuffer->logical != gcvNULL) { gcmVERIFY_OK(gcoOS_FreeContiguous( gcvNULL, commandBuffer->physical, commandBuffer->logical, commandBuffer->bytes )); } #if gcdSECURE_USER if (commandBuffer->hintArray != gcvNULL) { #ifdef __QNXNTO__ gcmVERIFY_OK(gcoOS_FreeNonPagedMemory( gcvNULL, commandBuffer->hintArraySize, gcvNULL, commandBuffer->hintArray )); #else gcmVERIFY_OK(gcmOS_SAFE_FREE(gcvNULL, commandBuffer->hintArray)); #endif } #endif #ifdef __QNXNTO__ gcmVERIFY_OK(gcoOS_FreeNonPagedMemory( gcvNULL, objectSize, gcvNULL, commandBuffer )); #else gcmVERIFY_OK(gcmOS_SAFE_FREE(gcvNULL, commandBuffer)); #endif } /* Return the status. */ gcmFOOTER(); return status; }
gceSTATUS gcoQUEUE_Construct( IN gcoOS Os, OUT gcoQUEUE * Queue ) { gcoQUEUE queue = gcvNULL; gceSTATUS status; #ifdef __QNXNTO__ gctSIZE_T allocationSize; gctPHYS_ADDR physAddr; #endif gctPOINTER pointer = gcvNULL; gcmHEADER(); /* Verify the arguments. */ gcmVERIFY_ARGUMENT(Queue != gcvNULL); /* Create the queue. */ gcmONERROR( gcoOS_Allocate(gcvNULL, gcmSIZEOF(struct _gcoQUEUE), &pointer)); queue = pointer; /* Initialize the object. */ queue->object.type = gcvOBJ_QUEUE; /* Nothing in the queue yet. */ queue->head = queue->tail = gcvNULL; queue->recordCount = 0; #ifdef __QNXNTO__ /* Allocate buffer of records. */ allocationSize = BUFFER_SIZE; physAddr = 0; gcmONERROR( gcoOS_AllocateNonPagedMemory(gcvNULL, gcvTRUE, &allocationSize, &physAddr, (gctPOINTER *) &queue->records)); queue->freeBytes = allocationSize; queue->offset = 0; #else queue->freeList = gcvNULL; #endif /* Return gcoQUEUE pointer. */ *Queue = queue; /* Success. */ gcmFOOTER_ARG("*Queue=0x%x", *Queue); return gcvSTATUS_OK; OnError: if (queue != gcvNULL) { /* Roll back. */ gcmVERIFY_OK(gcmOS_SAFE_FREE(gcvNULL, queue)); } /* Return the status. */ gcmFOOTER(); return status; }
gceSTATUS gcoPROFILER_Initialize( IN gcoHAL Hal ) { gceSTATUS status = gcvSTATUS_OK; char* fileName = gcvNULL; char* filter = gcvNULL; char* env = gcvNULL; gctSTRING portName; gctINT port; gcsHAL_INTERFACE iface; gcmHEADER(); /* Check if already initialized. */ if (gcPLS.hal->profiler.enable) { gcPLS.hal->profiler.enable++; gcmFOOTER(); return gcvSTATUS_LOCKED; } /* Get profile setting. */ iface.command = gcvHAL_GET_PROFILE_SETTING; /* Call the kernel. */ status = gcoOS_DeviceControl(gcvNULL, IOCTL_GCHAL_INTERFACE, &iface, gcmSIZEOF(iface), &iface, gcmSIZEOF(iface)); if (gcmIS_ERROR(status) || !iface.u.GetProfileSetting.enable) { gcPLS.hal->profiler.enable = 0; status = gcvSTATUS_GENERIC_IO; gcmFOOTER(); return status; } gcoOS_ZeroMemory(&gcPLS.hal->profiler, gcmSIZEOF(gcPLS.hal->profiler)); gcoOS_GetEnv(gcvNULL, "VP_COUNTER_FILTER", &filter); /* Enable/Disable specific counters. */ if ((filter != gcvNULL)) { gctSIZE_T bitsLen; gcoOS_StrLen(filter, &bitsLen); if (bitsLen > 2) { gcPLS.hal->profiler.enableHal = (filter[2] == '1'); } else { gcPLS.hal->profiler.enableHal = gcvTRUE; } if (bitsLen > 3) { gcPLS.hal->profiler.enableHW = (filter[3] == '1'); } else { gcPLS.hal->profiler.enableHW = gcvTRUE; } if (bitsLen > 8) { gcPLS.hal->profiler.enableSH = (filter[8] == '1'); } else { gcPLS.hal->profiler.enableSH = gcvTRUE; } } else { gcPLS.hal->profiler.enableHal = gcvTRUE; gcPLS.hal->profiler.enableHW = gcvTRUE; gcPLS.hal->profiler.enableSH = gcvTRUE; } gcoOS_GetEnv(gcvNULL, "VPROFILER_OUTPUT", &fileName); gcPLS.hal->profiler.useSocket = gcvFALSE; if (fileName && *fileName != '\0' && *fileName != ' ') { /* Extract port info. */ gcoOS_StrFindReverse(fileName, ':', &portName); if (portName) { gcoOS_StrToInt(portName + 1, &port); if (port > 0) { /*status = gcoOS_Socket(gcvNULL, AF_INET, SOCK_STREAM, 0, &gcPLS.hal->profiler.sockFd);*/ status = gcoOS_Socket(gcvNULL, 2, 1, 0, &gcPLS.hal->profiler.sockFd); if (gcmIS_SUCCESS(status)) { *portName = '\0'; status = gcoOS_Connect(gcvNULL, gcPLS.hal->profiler.sockFd, fileName, port); *portName = ':'; if (gcmIS_SUCCESS(status)) { gcPLS.hal->profiler.useSocket = gcvTRUE; } } } } } else { fileName = iface.u.GetProfileSetting.fileName; } if (! gcPLS.hal->profiler.useSocket) { status = gcoOS_Open(gcvNULL, fileName, #if gcdNEW_PROFILER_FILE gcvFILE_CREATE, #else gcvFILE_CREATETEXT, #endif &gcPLS.hal->profiler.file); } if (gcmIS_ERROR(status)) { gcPLS.hal->profiler.enable = 0; status = gcvSTATUS_GENERIC_IO; gcmFOOTER(); return status; } gcPLS.hal->profiler.isSyncMode = gcvFALSE; gcoOS_GetEnv(gcvNULL, "VPROFILER_SYNC_MODE", &env); if ((env != gcvNULL) && gcmIS_SUCCESS(gcoOS_StrCmp(env, "1"))) { gcPLS.hal->profiler.isSyncMode = gcvTRUE; } if (env) { gcmOS_SAFE_FREE(gcvNULL, env); } gcPLS.hal->profiler.enable = 1; gcoOS_GetTime(&gcPLS.hal->profiler.frameStart); gcPLS.hal->profiler.frameStartTimeusec = gcPLS.hal->profiler.frameStart; gcPLS.hal->profiler.prevVSInstCount = 0; gcPLS.hal->profiler.prevVSBranchInstCount = 0; gcPLS.hal->profiler.prevVSTexInstCount = 0; gcPLS.hal->profiler.prevVSVertexCount = 0; gcPLS.hal->profiler.prevPSInstCount = 0; gcPLS.hal->profiler.prevPSBranchInstCount = 0; gcPLS.hal->profiler.prevPSTexInstCount = 0; gcPLS.hal->profiler.prevPSPixelCount = 0; #if gcdNEW_PROFILER_FILE gcmWRITE_CONST(VPHEADER); gcmWRITE_BUFFER(4, "VP12"); #else gcmWRITE_STRING("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<VProfile>\n"); #endif /* Success. */ gcmFOOTER(); return status; }