void CompositorBase::SubmitFovLayer(ovrRecti viewport[ovrEye_Count], ovrFovPort fov[ovrEye_Count], ovrTextureSwapChain swapChain[ovrEye_Count], unsigned int flags) { MICROPROFILE_SCOPE(SubmitFovLayer); // If the right eye isn't set used the left eye for both if (!swapChain[ovrEye_Right]) swapChain[ovrEye_Right] = swapChain[ovrEye_Left]; MICROPROFILE_META_CPU("SwapChain Right", swapChain[ovrEye_Right]->Identifier); MICROPROFILE_META_CPU("SwapChain Left", swapChain[ovrEye_Left]->Identifier); // Render the scene layer for (int i = 0; i < ovrEye_Count; i++) { // Get the scene fov ovrFovPort sceneFov; if (m_SceneLayer->Type == ovrLayerType_EyeFov) sceneFov = ((ovrLayerEyeFov*)m_SceneLayer)->Fov[i]; else if (m_SceneLayer->Type == ovrLayerType_EyeMatrix) sceneFov = MatrixToFovPort(((ovrLayerEyeMatrix*)m_SceneLayer)->Matrix[i]); // Calculate the fov quad vr::HmdVector4_t quad; quad.v[0] = fov[i].LeftTan / -sceneFov.LeftTan; quad.v[1] = fov[i].RightTan / sceneFov.RightTan; quad.v[2] = fov[i].UpTan / sceneFov.UpTan; quad.v[3] = fov[i].DownTan / -sceneFov.DownTan; // Calculate the texture bounds vr::VRTextureBounds_t bounds = ViewportToTextureBounds(viewport[i], swapChain[i], flags); // Composit the layer if (m_SceneLayer->Type == ovrLayerType_EyeFov) { ovrLayerEyeFov* layer = (ovrLayerEyeFov*)m_SceneLayer; RenderTextureSwapChain((vr::EVREye)i, swapChain[i], layer->ColorTexture[i], layer->Viewport[i], bounds, quad); } else if (m_SceneLayer->Type == ovrLayerType_EyeMatrix) { ovrLayerEyeMatrix* layer = (ovrLayerEyeMatrix*)m_SceneLayer; RenderTextureSwapChain((vr::EVREye)i, swapChain[i], layer->ColorTexture[i], layer->Viewport[i], bounds, quad); } } swapChain[ovrEye_Left]->Submit(); if (swapChain[ovrEye_Left] != swapChain[ovrEye_Right]) swapChain[ovrEye_Right]->Submit(); }
void WorkerThreadLong(int threadId) { uint32_t c0 = 0xff3399ff; uint32_t c1 = 0xffff99ff; char name[100]; snprintf(name, 99, "Worker_long%d", threadId); MicroProfileOnThreadCreate(&name[0]); while(!g_nQuit) { MICROPROFILE_SCOPEI("long", "outer 150ms", c0); MICROPROFILE_META_CPU("Sleep",100); usleep(100*1000); for(int i = 0; i < 10; ++i) { MICROPROFILE_SCOPEI("long", "inner 5ms", c1); MICROPROFILE_META_CPU("Sleep",5); usleep(5000); } } }
vr::VRCompositorError CompositorBase::SubmitSceneLayer(ovrRecti viewport[ovrEye_Count], ovrFovPort fov[ovrEye_Count], ovrTextureSwapChain swapChain[ovrEye_Count], unsigned int flags) { MICROPROFILE_SCOPE(SubmitSceneLayer); // If the right eye isn't set used the left eye for both if (!swapChain[ovrEye_Right]) swapChain[ovrEye_Right] = swapChain[ovrEye_Left]; MICROPROFILE_META_CPU("SwapChain Right", swapChain[ovrEye_Right]->Identifier); MICROPROFILE_META_CPU("SwapChain Left", swapChain[ovrEye_Left]->Identifier); // Submit the scene layer. vr::VRCompositorError err; for (int i = 0; i < ovrEye_Count; i++) { ovrTextureSwapChain chain = swapChain[i]; vr::VRTextureBounds_t bounds = ViewportToTextureBounds(viewport[i], swapChain[i], flags); // Shrink the bounds to account for the overlapping fov vr::VRTextureBounds_t fovBounds = FovPortToTextureBounds((ovrEyeType)i, fov[i]); // Combine the fov bounds with the viewport bounds bounds.uMin += fovBounds.uMin * bounds.uMax; bounds.uMax *= fovBounds.uMax; bounds.vMin += fovBounds.vMin * bounds.vMax; bounds.vMax *= fovBounds.vMax; vr::Texture_t texture = chain->Textures[chain->SubmitIndex]->ToVRTexture(); err = vr::VRCompositor()->Submit((vr::EVREye)i, &texture, &bounds); if (err != vr::VRCompositorError_None) break; } swapChain[ovrEye_Left]->Submit(); if (swapChain[ovrEye_Left] != swapChain[ovrEye_Right]) swapChain[ovrEye_Right]->Submit(); return err; }
void WorkerThread(int threadId) { char name[100]; snprintf(name, 99, "Worker%d", threadId); MicroProfileOnThreadCreate(&name[0]); uint32_t c0 = 0xff3399ff; uint32_t c1 = 0xffff99ff; uint32_t c2 = 0xff33ff00; uint32_t c3 = 0xff3399ff; uint32_t c4 = 0xff33ff33; while(!g_nQuit) { switch(threadId) { case 0: { usleep(100); { MICROPROFILE_SCOPEI("Thread0", "Work Thread0", c4); MICROPROFILE_META_CPU("Sleep",10); usleep(200); { MICROPROFILE_SCOPEI("Thread0", "Work Thread1", c3); MICROPROFILE_META_CPU("DrawCalls", 1); MICROPROFILE_META_CPU("DrawCalls", 1); MICROPROFILE_META_CPU("DrawCalls", 1); usleep(200); { MICROPROFILE_SCOPEI("Thread0", "Work Thread2", c2); MICROPROFILE_META_CPU("DrawCalls", 1); usleep(200); { MICROPROFILE_SCOPEI("Thread0", "Work Thread3", c1); MICROPROFILE_META_CPU("DrawCalls", 4); MICROPROFILE_META_CPU("Triangles",1000); usleep(200); } } } } } break; case 1: { usleep(100); MICROPROFILE_SCOPEI("Thread1", "Work Thread 1", c1); usleep(2000); } break; case 2: { usleep(1000); { MICROPROFILE_SCOPEI("Thread2", "Worker2", c0); spinsleep(100000); { MICROPROFILE_SCOPEI("Thread2", "InnerWork0", c1); spinsleep(100); { MICROPROFILE_SCOPEI("Thread2", "InnerWork1", c2); usleep(100); { MICROPROFILE_SCOPEI("Thread2", "InnerWork2", c3); usleep(100); { // for(uint32_t i = 0; i < 1000; ++i) // { // MICROPROFILE_SCOPEI("Thread2", "InnerWork3", c4); // spinsleep(10); // } } } } } } } break; case 3: { MICROPROFILE_SCOPEI("ThreadWork", "MAIN", c0); usleep(1000);; for(uint32_t i = 0; i < 10; ++i) { MICROPROFILE_SCOPEI("ThreadWork", "Inner0", c1); usleep(100); for(uint32_t j = 0; j < 4; ++j) { MICROPROFILE_SCOPEI("ThreadWork", "Inner1", c4); usleep(50); MICROPROFILE_SCOPEI("ThreadWork", "Inner1", c4); usleep(50); MICROPROFILE_SCOPEI("ThreadWork", "Inner2", c2); usleep(50); MICROPROFILE_SCOPEI("ThreadWork", "Inner3", c3); usleep(50); MICROPROFILE_SCOPEI("ThreadWork", "Inner4", c3); usleep(50); } } } break; default: MICROPROFILE_SCOPE(ThreadSafeMain); usleep(1000);; for(uint32_t i = 0; i < 5; ++i) { MICROPROFILE_SCOPE(ThreadSafeInner0); usleep(1000); for(uint32_t j = 0; j < 4; ++j) { MICROPROFILE_META_CPU("custom_very_long_meta", 1); MICROPROFILE_SCOPE(ThreadSafeInner1); usleep(500); MICROPROFILE_SCOPE(ThreadSafeInner2); usleep(150); MICROPROFILE_SCOPE(ThreadSafeInner3); usleep(150); MICROPROFILE_SCOPE(ThreadSafeInner4); usleep(150); } } break; } } }
int main(int argc, char* argv[]) { MICROPROFILE_REGISTER_GROUP("Thread0", "Threads", 0x88008800); MICROPROFILE_REGISTER_GROUP("Thread1", "Threads", 0x88008800); MICROPROFILE_REGISTER_GROUP("Thread2", "Threads", 0x88008800); MICROPROFILE_REGISTER_GROUP("Thread2xx", "Threads", 0x88008800); MICROPROFILE_REGISTER_GROUP("MAIN", "main", 0x88fff00f); g_QueueGraphics = MICROPROFILE_GPU_INIT_QUEUE("GPU-Graphics-Queue"); printf("press 'z' to toggle microprofile drawing\n"); printf("press 'right shift' to pause microprofile update\n"); printf("press 'x' to toggle profiling\n"); printf("press 'c' to toggle enable of all profiler groups\n"); MicroProfileOnThreadCreate("AA_Main"); if(SDL_Init(SDL_INIT_VIDEO) < 0) { return 1; } SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); SDL_GL_SetSwapInterval(1); SDL_Window * pWindow = SDL_CreateWindow("microprofiledemo", 10, 10, WIDTH, HEIGHT, SDL_WINDOW_OPENGL); if(!pWindow) return 1; SDL_GLContext glcontext = SDL_GL_CreateContext(pWindow); glewExperimental=1; GLenum err=glewInit(); if(err!=GLEW_OK) { __BREAK(); } glGetError(); //glew generates an error #if MICROPROFILE_ENABLED MicroProfileGpuInitGL(); MicroProfileDrawInit(); MP_ASSERT(glGetError() == 0); MicroProfileToggleDisplayMode(); MicroProfileInitUI(); MicroProfileCustomGroup("Custom1", 2, 47, 2.f, MICROPROFILE_CUSTOM_BARS); MicroProfileCustomGroupAddTimer("Custom1", "MicroProfile", "Draw"); MicroProfileCustomGroupAddTimer("Custom1", "MicroProfile", "Detailed View"); MicroProfileCustomGroup("Custom2", 2, 100, 20.f, MICROPROFILE_CUSTOM_BARS|MICROPROFILE_CUSTOM_BAR_SOURCE_MAX); MicroProfileCustomGroupAddTimer("Custom2", "MicroProfile", "Draw"); MicroProfileCustomGroupAddTimer("Custom2", "MicroProfile", "Detailed View"); MicroProfileCustomGroup("Custom3", 2, 0, 5.f, MICROPROFILE_CUSTOM_STACK|MICROPROFILE_CUSTOM_STACK_SOURCE_MAX); MicroProfileCustomGroupAddTimer("Custom3", "MicroProfile", "Draw"); MicroProfileCustomGroupAddTimer("Custom3", "MicroProfile", "Detailed View"); MicroProfileCustomGroup("ThreadSafe", 6, 10, 600.f, MICROPROFILE_CUSTOM_BARS | MICROPROFILE_CUSTOM_STACK); MicroProfileCustomGroupAddTimer("ThreadSafe", "ThreadSafe", "main"); MicroProfileCustomGroupAddTimer("ThreadSafe", "ThreadSafe", "inner0"); MicroProfileCustomGroupAddTimer("ThreadSafe", "ThreadSafe", "inner1"); MicroProfileCustomGroupAddTimer("ThreadSafe", "ThreadSafe", "inner2"); MicroProfileCustomGroupAddTimer("ThreadSafe", "ThreadSafe", "inner3"); MicroProfileCustomGroupAddTimer("ThreadSafe", "ThreadSafe", "inner4"); #endif MICROPROFILE_COUNTER_CONFIG("memory/main", MICROPROFILE_COUNTER_FORMAT_BYTES, 10ll<<30ll, 0); MICROPROFILE_COUNTER_CONFIG("memory/gpu/indexbuffers", MICROPROFILE_COUNTER_FORMAT_BYTES, 0, 0); MICROPROFILE_COUNTER_CONFIG("memory/gpu/vertexbuffers", MICROPROFILE_COUNTER_FORMAT_BYTES, 0, 0); MICROPROFILE_COUNTER_CONFIG("memory/mainx", MICROPROFILE_COUNTER_FORMAT_BYTES, 10000, 0); MICROPROFILE_COUNTER_ADD("memory/main", 1000); MICROPROFILE_COUNTER_ADD("memory/gpu/vertexbuffers", 1000); MICROPROFILE_COUNTER_ADD("memory/gpu/indexbuffers", 200); MICROPROFILE_COUNTER_ADD("memory//", 10<<10); MICROPROFILE_COUNTER_ADD("memory//main", (32ll<<30ll) + (1ll <<29ll)); MICROPROFILE_COUNTER_ADD("//memory//mainx/\\//", 1000); MICROPROFILE_COUNTER_ADD("//memoryx//mainx/", 1000); MICROPROFILE_COUNTER_ADD("//memoryy//main/", -1000000); MICROPROFILE_COUNTER_ADD("//\\\\///lala////lelel", 1000); MICROPROFILE_COUNTER_CONFIG("engine/frames", MICROPROFILE_COUNTER_FORMAT_DEFAULT, 1000, 0); MICROPROFILE_COUNTER_SET("fisk/geder/", 42); MICROPROFILE_COUNTER_SET("fisk/aborre/", -2002); MICROPROFILE_COUNTER_SET_LIMIT("fisk/aborre/", 120); static int Frames = 0; static uint64_t FramesX = 0; MICROPROFILE_COUNTER_SET_INT64_PTR("frames/int64", &FramesX); MICROPROFILE_COUNTER_SET_INT32_PTR("frames/int32", &Frames); MICROPROFILE_COUNTER_CONFIG("/test/sinus", MICROPROFILE_COUNTER_FORMAT_BYTES, 0, MICROPROFILE_COUNTER_FLAG_DETAILED); MICROPROFILE_COUNTER_CONFIG("/test/cosinus", MICROPROFILE_COUNTER_FORMAT_DEFAULT, 0, MICROPROFILE_COUNTER_FLAG_DETAILED); MICROPROFILE_COUNTER_CONFIG("/runtime/sdl_frame_events", MICROPROFILE_COUNTER_FORMAT_DEFAULT, 0, MICROPROFILE_COUNTER_FLAG_DETAILED); StartFakeWork(); while(!g_nQuit) { Frames++; FramesX += 1024*1024; MICROPROFILE_SCOPE(MAIN); MICROPROFILE_COUNTER_ADD("engine/frames", 1); SDL_Event Evt; while(SDL_PollEvent(&Evt)) { MICROPROFILE_COUNTER_LOCAL_ADD(SDLFrameEvents, 1); HandleEvent(&Evt); } MICROPROFILE_COUNTER_LOCAL_UPDATE_SET(SDLFrameEvents); glClearColor(0.3f,0.4f,0.6f,0.f); glViewport(0, 0, WIDTH, HEIGHT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); #if 1||FAKE_WORK { MICROPROFILE_SCOPEI("BMain", "Dummy", 0xff3399ff); for(uint32_t i = 0; i < 14; ++i) { MICROPROFILE_SCOPEI("BMain", "1ms", 0xff3399ff); MICROPROFILE_META_CPU("Sleep",1); usleep(1000); } } #endif MicroProfileMouseButton(g_MouseDown0, g_MouseDown1); MicroProfileMousePosition(g_MouseX, g_MouseY, g_MouseDelta); g_MouseDelta = 0; MicroProfileFlip(0); static float f = 0; f += 0.1f; int sinus = (int)(10000000 * (sinf(f))); int cosinus = int(cosf(f*1.3f) * 100000 + 50000); MICROPROFILE_COUNTER_SET("/test/sinus", sinus); MICROPROFILE_COUNTER_SET("/test/cosinus", cosinus); { MICROPROFILE_SCOPEGPUI("MicroProfileDraw", 0x88dd44); float projection[16]; float left = 0.f; float right = WIDTH; float bottom = HEIGHT; float top = 0.f; float near = -1.f; float far = 1.f; memset(&projection[0], 0, sizeof(projection)); projection[0] = 2.0f / (right - left); projection[5] = 2.0f / (top - bottom); projection[10] = -2.0f / (far - near); projection[12] = - (right + left) / (right - left); projection[13] = - (top + bottom) / (top - bottom); projection[14] = - (far + near) / (far - near); projection[15] = 1.f; glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_DEPTH_TEST); #if MICROPROFILE_ENABLED MicroProfileBeginDraw(WIDTH, HEIGHT, &projection[0]); MicroProfileDraw(WIDTH, HEIGHT); MicroProfileEndDraw(); #endif glDisable(GL_BLEND); } MICROPROFILE_SCOPEI("MAIN", "Flip", 0xffee00); SDL_GL_SwapWindow(pWindow); } StopFakeWork(); MicroProfileShutdown(); SDL_GL_DeleteContext(glcontext); SDL_DestroyWindow(pWindow); SDL_Quit(); return 0; }
int main(int argc, char* argv[]) { MICROPROFILE_REGISTER_GROUP("Thread0", "Threads", 0x88008800); MICROPROFILE_REGISTER_GROUP("Thread1", "Threads", 0x88008800); MICROPROFILE_REGISTER_GROUP("Thread2", "Threads", 0x88008800); MICROPROFILE_REGISTER_GROUP("Thread2xx", "Threads", 0x88008800); MICROPROFILE_REGISTER_GROUP("GPU", "main", 0x88fff00f); MICROPROFILE_REGISTER_GROUP("MAIN", "main", 0x88fff00f); printf("press 'z' to toggle microprofile drawing\n"); printf("press 'right shift' to pause microprofile update\n"); printf("press 'x' to toggle profiling\n"); printf("press 'c' to toggle enable of all profiler groups\n"); MicroProfileOnThreadCreate("AA_Main"); if(SDL_Init(SDL_INIT_VIDEO) < 0) { return 1; } SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); SDL_GL_SetSwapInterval(1); SDL_Window * pWindow = SDL_CreateWindow("microprofiledemo", 10, 10, WIDTH, HEIGHT, SDL_WINDOW_OPENGL); if(!pWindow) return 1; SDL_GLContext glcontext = SDL_GL_CreateContext(pWindow); glewExperimental=1; GLenum err=glewInit(); if(err!=GLEW_OK) { __BREAK(); } glGetError(); //glew generates an error #if MICROPROFILE_ENABLED MicroProfileGpuInitGL(); MicroProfileDrawInit(); MP_ASSERT(glGetError() == 0); MicroProfileToggleDisplayMode(); #endif StartFakeWork(); while(!g_nQuit) { MICROPROFILE_SCOPE(MAIN); SDL_Event Evt; while(SDL_PollEvent(&Evt)) { HandleEvent(&Evt); } glClearColor(0.3f,0.4f,0.6f,0.f); glViewport(0, 0, WIDTH, HEIGHT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); #if 1||FAKE_WORK { MICROPROFILE_SCOPEI("BMain", "Dummy", 0xff3399ff); for(uint32_t i = 0; i < 14; ++i) { MICROPROFILE_SCOPEI("BMain", "1ms", 0xff3399ff); MICROPROFILE_META_CPU("Sleep",1); usleep(1000); } } #endif MicroProfileMouseButton(g_MouseDown0, g_MouseDown1); MicroProfileMousePosition(g_MouseX, g_MouseY, g_MouseDelta); g_MouseDelta = 0; MicroProfileFlip(); { MICROPROFILE_SCOPEGPUI("MicroProfileDraw", 0x88dd44); float projection[16]; float left = 0.f; float right = WIDTH; float bottom = HEIGHT; float top = 0.f; float near = -1.f; float far = 1.f; memset(&projection[0], 0, sizeof(projection)); projection[0] = 2.0f / (right - left); projection[5] = 2.0f / (top - bottom); projection[10] = -2.0f / (far - near); projection[12] = - (right + left) / (right - left); projection[13] = - (top + bottom) / (top - bottom); projection[14] = - (far + near) / (far - near); projection[15] = 1.f; glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_DEPTH_TEST); #if MICROPROFILE_ENABLED MicroProfileBeginDraw(WIDTH, HEIGHT, &projection[0]); MicroProfileDraw(WIDTH, HEIGHT); MicroProfileEndDraw(); #endif glDisable(GL_BLEND); } MICROPROFILE_SCOPEI("MAIN", "Flip", 0xffee00); SDL_GL_SwapWindow(pWindow); } StopFakeWork(); MicroProfileShutdown(); SDL_GL_DeleteContext(glcontext); SDL_DestroyWindow(pWindow); SDL_Quit(); return 0; }