practical-tools-for-simple-design
practical-tools-for-simple-design copied to clipboard
The function call ShowDemoWindow of ImGui make FPS low
Problem
As you can see, the FPS low when open the demo-window of ImGui
https://github.com/ntut-open-source-club/practical-tools-for-simple-design/assets/98307453/f34650e0-6b79-4a66-b538-70c7396a2b31
Ps: the Problem occur commit between 823926c952ddbd068dc74909bf0663a00573d248 and 22ef5cac61e231c3f1da68f7d2bbb70bfbeacc99
Steps to reproduce
git clone https://github.com/ntut-open-source-club/practical-tools-for-simple-design
cd practical-tools-for-simple-design
git checkout 823926c
cmake -Bbuild -G "Ninja" -DCMAKE_BUILD_TYPE=Debug
cmake --build build -j 32
./build/Sample
Expected behavior
It will keep 60fps in window.
PTSD version
commit 823926c952ddbd068dc74909bf0663a00573d248
Operating system/version
~~Unix~~ Window 11 24H2
CMake version
3.27.6
CMakeCache.txt
OpenGL Info
[info] OpenGL Info
[info] Vendor: NVIDIA Corporation
[info] Renderer: NVIDIA GeForce RTX 3060/PCIe/SSE2
[info] Version: 4.1.0 NVIDIA 537.13
[info] GLSL Version: 4.10 NVIDIA via Cg compiler
and comment out this code can also make fps normal,
glDebugMessageCallback(Core::OpenGLDebugMessageCallback, nullptr);
This is because PR #162 would result in a large amount of OpenGL Severity NOTIFICATION. Besides commenting out, you can also try this method.
The reason why commenting out this code can solve the problem can be referred to in this.
glDebugMessageCallback(Core::OpenGLDebugMessageCallback, nullptr);
It work but not elegant https://github.com/NTUT-FUCK-PTSD/practical-tools-for-simple-design/commit/c4631295eacd13b3e0e9ebe45cf841f4f80874af
Original code
SDL_Delay(static_cast<Uint32>(frameTime - Util::Time::GetDeltaTime()));
is incorrect , milliseconds-seconds
This problem seems not to occurs in macOS.
https://github.com/ntut-open-source-club/practical-tools-for-simple-design/assets/98307453/bb4a3bee-0847-479a-9b18-562d832b28ed
It work but not elegant NTUT-FUCK-PTSD@c463129
Original code
SDL_Delay(static_cast<Uint32>(frameTime - Util::Time::GetDeltaTime()));
is incorrect , milliseconds-seconds
We are working on that. Should have the PR open this week.
It work but not elegant NTUT-FUCK-PTSD@c463129 Original code
SDL_Delay(static_cast<Uint32>(frameTime - Util::Time::GetDeltaTime()));
is incorrect , milliseconds-secondsWe are working on that. Should have the PR open this week.
Shoot, thought this was #167.
It work but not elegant NTUT-FUCK-PTSD@c463129 Original code
SDL_Delay(static_cast<Uint32>(frameTime - Util::Time::GetDeltaTime()));
is incorrect , milliseconds-secondsWe are working on that. Should have the PR open this week.
Shoot, thought this was #167.
其實不僅僅是相減會有問題而已,他們兩個數字的單位就不同了,frameTime(單位:毫秒)而Util::Time::GetDeltaTime(單位:秒),兩個不同單位的值做相減,我想結果應該不會是正確的結果,但儘管我把他更改為正確單位,他仍然有錯誤,會發生下面這件事情 測試程式碼:
constexpr double frameTime =
FPS_CAP != 0 ? 1000 / static_cast<double>(FPS_CAP) : 0;
m_FPS_DeltaTime = Util::Time::GetDeltaTime()*1000;
if (m_FPS_DeltaTime < frameTime) {
SDL_Delay(static_cast<Uint32>(frameTime - m_FPS_DeltaTime));
}
m_FPS_Timer = Util::Time::GetElapsedTimeMs();
LOG_INFO("GetDeltaTime: {}", Util::Time::GetDeltaTime());
可以看到他的DeltaTime一上一下,這是因為GetDeltaTime()他並不會記錄上次Delay了多久,因此他會將那部分再下次也計算進入上次的Delay時間,這導致了GetDeltaTime()的值上下波動,顯然這樣的幀生成時間是不正確的
而我的那份commit其實他大致上的行為和目前差不多,唯一的區別就是他會將Delay的時間排除掉,我修改過後的
但這一切都成立於我沒有理解錯誤當前PTSD的程式碼,如果理解錯誤那可能是我造了一台鴿子直升機