Repository navigation
Description
While PoB has focus, OnFrame runs every vsync even when nothing changes. The main loop only waits when minimized (
PathOfBuilding-SimpleGraphic/engine/system/win/sys_main.cpp
Lines 697 to 704 in 421d188
| while (exitFlag == false) { | |
| if (minimized) { | |
| glfwWaitEventsTimeout(0.1); | |
| } | |
| else { | |
| glfwPollEvents(); | |
| } | |
| auto wnd = (GLFWwindow*)video->GetWindowHandle(); |
ui_main_c::Frame only sleeps when the window is unfocused (PathOfBuilding-SimpleGraphic/ui_main.cpp
Lines 389 to 391 in 421d188
| else if (!sys->video->IsActive() && !sys->video->IsCursorOverWindow() && !hasActiveCoroutine && !hasSubscript) { | |
| sys->Sleep(100); | |
| return; |
PathOfBuilding-SimpleGraphic/ui_main.cpp
Lines 435 to 437 in 421d188
| if ( !sys->video->IsActive() && !hasActiveCoroutine && !hasSubscript ) { | |
| sys->Sleep(100); | |
| } |
PathOfBuilding-SimpleGraphic/engine/render/r_main.cpp
Lines 1209 to 1240 in 421d188
| uint64_t commandDigest = 0; | |
| if (elideFrames) { | |
| auto* frameHasher = frameHashState.get(); | |
| XXH3_64bits_reset(frameHasher); | |
| for (auto lIdx = 0; lIdx < numLayer; ++lIdx) { | |
| auto layer = layerSort[lIdx]; | |
| uint64_t subHash = XXH3_64bits(layer->cmdStorage.data(), (int)layer->cmdCursor); | |
| XXH3_64bits_update(frameHasher, &subHash, sizeof(subHash)); | |
| } | |
| commandDigest = XXH3_64bits_digest(frameHasher); | |
| } | |
| ++totalFrames; | |
| const bool elideDraw = lastFrameHash != 0 && lastFrameHash == commandDigest; | |
| if (!elideDraw) | |
| { | |
| glBindFramebuffer(GL_FRAMEBUFFER, GetDrawRenderTarget().framebuffer); | |
| glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); | |
| for (int l = 0; l < numLayer; l++) { | |
| auto& layer = layerSort[l]; | |
| if (layerBreak && layerBreak->first == layer->layer && layerBreak->second == layer->subLayer) { | |
| #ifdef _WIN32 | |
| DebugBreak(); | |
| #endif | |
| } | |
| inhibitElision = layer->Render() || inhibitElision; | |
| } | |
| presentRtt = 1 - presentRtt; | |
| ++drawnFrames; | |
| } |
I know running Lua only when something happens is on your list. These are the places I think it would touch:
- The elision hash could double as an idle detector. After a few identical frames with no input, no subscript, no running coroutine and no pending texture, the loop could switch from
glfwPollEventstoglfwWaitEventsTimeout. - The GLFW callbacks would set a dirty flag. The cursor callback already stores the position ().
PathOfBuilding-SimpleGraphic/engine/system/win/sys_video.cpp
Lines 487 to 494 in 421d188
glfwSetCursorPosCallback(wnd, [](GLFWwindow* wnd, double x, double y) { auto sys = (sys_main_c*)glfwGetWindowUserPointer(wnd); if (ImGui::GetIO().WantCaptureMouse) { return; } auto video = (sys_video_c*)sys->video; video->lastCursorPos = CursorPos{ (int)x, (int)y }; }); - Workers would call
glfwPostEmptyEvent()when they hand something to the main thread: subscript messages, and texture uploads ().PathOfBuilding-SimpleGraphic/engine/render/r_texture.cpp
Lines 184 to 188 in 421d188
void t_manager_c::EnqueueTextureUpload(r_tex_c* tex) { std::scoped_lock lk(uploadMutex); uploadQueue.push_back(tex); } - The texture workers spin on
Sleep(1)while idle (). The condvar change from fix: accurate frame elision and draw performance #110 (6a74097) already fixes that.renderer->sys->Sleep(1);
On the PoB side the caret blink, toasts and the rotating jewel rings need regular frames, so a timeout of a few hundred ms, or a way for Lua to ask for the next frame, would keep those working.
Activity