/* ======================== PC_EndFrame ======================== */ void PC_EndFrame() { #if 0 if ( !r_pix.GetBool() ) { return; } int64 totalGPU = 0; int64 totalCPU = 0; idLib::Printf( "----- GPU Events -----\n" ); for ( int i = 0 ; i < numPixEvents ; i++ ) { pixEvent_t *ev = &pixEvents[i]; int64 gpuTime = 0; glGetQueryObjectui64vEXT( timeQueryIds[i], GL_QUERY_RESULT, (GLuint64EXT *)&gpuTime ); ev->gpuTime = gpuTime; idLib::Printf( "%2d: %1.2f (GPU) %1.3f (CPU) = %s\n", i, ev->gpuTime / 1000000.0f, ev->cpuTime / 1000.0f, ev->name ); totalGPU += ev->gpuTime; totalCPU += ev->cpuTime; } idLib::Printf( "%2d: %1.2f (GPU) %1.3f (CPU) = total\n", numPixEvents, totalGPU / 1000000.0f, totalCPU / 1000.0f ); memset( pixEvents, 0, numPixLevels * sizeof( pixEvents[0] ) ); numPixEvents = 0; numPixLevels = 0; #endif }
/** * @brief glEndTimeQuery * @param ret * @return */ inline GLuint64EXT glEndTimeQuery(GLuint ret) { GLuint64 timeVal = 0; //Timing #ifndef PIC_DISABLE_OPENGL_NON_CORE glEndQuery(GL_TIME_ELAPSED_EXT); glGetQueryObjectui64vEXT(ret, GL_QUERY_RESULT, &timeVal); #endif return timeVal; }
template<> UnsignedLong AbstractQuery::result<UnsignedLong>() { UnsignedLong result; #ifndef MAGNUM_TARGET_GLES glGetQueryObjectui64v(_id, GL_QUERY_RESULT, &result); #elif !defined(CORRADE_TARGET_NACL) glGetQueryObjectui64vEXT(_id, GL_QUERY_RESULT_EXT, &result); #else CORRADE_ASSERT_UNREACHABLE(); #endif return result; }
void Profile::begin() { assert(!CHECKERROR); if (ready) { ready = false; } if (queries.size()) { //if the last query is done, they are all done GLint available; glGetQueryObjectiv(queryObjs[current-1], GL_QUERY_RESULT_AVAILABLE, &available); if (available) { //get the results timeStamps.resize(queryObjs.size()); for (int i = 0; i < (int)queryObjs.size(); ++i) { CHECKERROR; GLuint64 result; glGetQueryObjectui64vEXT(queryObjs[i], GL_QUERY_RESULT, &result); timeStamps[i] = result; CHECKERROR; } //append the differences to the samples list for (QueryMap::iterator it = queries.begin(); it != queries.end(); ++it) { if (it->second.timeDiff < 1) continue; GLuint64 timediff = timeStamps[it->second.timeDiff] - timeStamps[it->second.timeDiff-1]; it->second.times.push_back(timediff); if (it->second.times.size() > PROFILE_SAMPLES) it->second.times.pop_front(); it->second.timeDiff = -1; } //start the next set of samples ready = true; restartQueries(); } } else ready = true; if (ready) { glQueryCounter(getNextQuery(), GL_TIMESTAMP); } }
void Profiler::nextFrame() { // Wait for all queries to complete if (m_supportsQuery && m_enabled) { static const RealTime TIMEOUT = 2; RealTime startQuery = System::time(); for (int i = 0; i < m_pendingQueries.size(); ++i) { // Block until available GLint available = 0; const GLint id = m_pendingQueries[i].query; const std::string& name = m_pendingQueries[i].name; do { glGetQueryObjectiv(id, GL_QUERY_RESULT_AVAILABLE, &available); } while ((available == 0) && (System::time() - startQuery < TIMEOUT)); // Get the time, in nanoseconds GLuint64EXT nsElapsed = 0; glGetQueryObjectui64vEXT(id, GL_QUERY_RESULT, &nsElapsed); Task& t = m_gfxTask[name]; t.m_time = nsElapsed * 1e-9; t.m_frameNum = m_frameNum; // Put the query object back on the GPU freelist m_queryFreelist.append(id); } if (System::time() - startQuery >= TIMEOUT) { logPrintf("\nWARNING: G3D::Profiler::nextFrame() aborted profiling because glGetQueryObjectiv took more than %f seconds to return.", TIMEOUT); m_enabled = false; } } m_oldCPUTask = m_cpuTask.m_data; m_oldGFXTask = m_gfxTask.m_data; m_pendingQueries.fastClear(); // Advance the frame counter ++m_frameNum; }
int dxt_encoder_compress_texture(struct dxt_encoder* encoder, int texture, unsigned char* image_compressed) { #ifdef USE_PBO_DXT_ENCODER GLubyte *ptr; #endif glBindTexture(GL_TEXTURE_2D, texture); glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT); assert(GL_FRAMEBUFFER_COMPLETE == glCheckFramebufferStatus(GL_FRAMEBUFFER)); glClearColor(1,0,0,1); glClear(GL_COLOR_BUFFER_BIT); if(encoder->legacy) { glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex2f(-1.0, -1.0); glTexCoord2f(1.0, 0.0); glVertex2f(1.0, -1.0); glTexCoord2f(1.0, 1.0); glVertex2f(1.0, 1.0); glTexCoord2f(0.0, 1.0); glVertex2f(-1.0, 1.0); glEnd(); } else { #if ! defined HAVE_MACOSX || OS_VERSION_MAJOR >= 11 // Compress glBindVertexArray(encoder->g_vao); //glDrawElements(GL_TRIANGLE_STRIP, sizeof(m_quad.indices) / sizeof(m_quad.indices[0]), GL_UNSIGNED_SHORT, BUFFER_OFFSET(0)); glDrawArrays(GL_TRIANGLES, 0, 6); glBindVertexArray(0); #endif } #ifdef HAVE_GPUPERFAPI GPA_EndSample(); GPA_BeginSample(3); #endif #ifdef RTDXT_DEBUG glEndQuery(GL_TIME_ELAPSED_EXT); glBeginQuery(GL_TIME_ELAPSED_EXT, encoder->queries[3]); #endif #ifdef RTDXT_DEBUG_HOST glFinish(); TIMER_STOP_PRINT("Texture Compress: "); TIMER_START(); #endif glReadBuffer(GL_COLOR_ATTACHMENT0_EXT); #ifdef USE_PBO_DXT_ENCODER // Read back // read pixels from framebuffer to PBO // glReadPixels() should return immediately. glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, encoder->pbo_out); if ( encoder->type == DXT_TYPE_DXT5_YCOCG ) glReadPixels(0, 0, (encoder->width + 3) / 4, (encoder->height + 3) / 4, GL_RGBA_INTEGER_EXT, GL_UNSIGNED_INT, 0); else glReadPixels(0, 0, (encoder->width + 3) / 4, (encoder->height + 3) / 4 , GL_RGBA_INTEGER_EXT, GL_UNSIGNED_SHORT, 0); // map the PBO to process its data by CPU glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, encoder->pbo_out); ptr = (GLubyte*)glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY_ARB); if(ptr) { memcpy(image_compressed, ptr, ((encoder->width + 3) / 4 * 4) * ((encoder->height + 3) / 4 * 4) / (encoder->type == DXT_TYPE_DXT5_YCOCG ? 1 : 2)); glUnmapBufferARB(GL_PIXEL_PACK_BUFFER_ARB); } // back to conventional pixel operation glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0); #else glReadPixels(0, 0, (encoder->width + 3) / 4, (encoder->height + 3) / 4, GL_RGBA_INTEGER_EXT, encoder->type == DXT_TYPE_DXT5_YCOCG ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, image_compressed); #endif #ifdef RTDXT_DEBUG_HOST glFinish(); TIMER_STOP_PRINT("Texture Save: "); #endif #ifdef RTDXT_DEBUG glEndQuery(GL_TIME_ELAPSED_EXT); { GLint available = 0; GLuint64 load = 0, convert = 0, compress = 0, store = 0; while (!available) { glGetQueryObjectiv(encoder->queries[3], GL_QUERY_RESULT_AVAILABLE, &available); } glGetQueryObjectui64vEXT(encoder->queries[0], GL_QUERY_RESULT, &load); glGetQueryObjectui64vEXT(encoder->queries[1], GL_QUERY_RESULT, &convert); glGetQueryObjectui64vEXT(encoder->queries[2], GL_QUERY_RESULT, &compress); glGetQueryObjectui64vEXT(encoder->queries[3], GL_QUERY_RESULT, &store); printf("Load: %8lu; YUV444->YUV422: %8lu; compress: %8lu; store: %8lu\n", load, convert, compress, store); } #endif #ifdef HAVE_GPUPERFAPI GPA_EndSample(); GPA_EndPass(); #endif return 0; }
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_EXTTimerQuery_nglGetQueryObjectui64vEXT__IIJ(JNIEnv *__env, jclass clazz, jint id, jint pname, jlong paramsAddress) { glGetQueryObjectui64vEXTPROC glGetQueryObjectui64vEXT = (glGetQueryObjectui64vEXTPROC)tlsGetFunction(1822); intptr_t params = (intptr_t)paramsAddress; UNUSED_PARAM(clazz) glGetQueryObjectui64vEXT(id, pname, params); }