Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The function call ShowDemoWindow of ImGui make FPS low #171

Open
onon1101 opened this issue Apr 8, 2024 · 7 comments
Open

The function call ShowDemoWindow of ImGui make FPS low #171

onon1101 opened this issue Apr 8, 2024 · 7 comments
Labels
bug Something isn't working

Comments

@onon1101
Copy link
Collaborator

onon1101 commented Apr 8, 2024

Problem

As you can see, the FPS low when open the demo-window of ImGui

2024-04-08.224030.mp4

Ps: the Problem occur commit between 823926c and 22ef5ca

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 823926c

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
@onon1101 onon1101 added the bug Something isn't working label Apr 8, 2024
@github-project-automation github-project-automation bot moved this to 🆕 Backlog in New Game Framework Apr 8, 2024
@onon1101 onon1101 changed the title The function call ShowDemoWindow of ImGui have been break the FPS The function call ShowDemoWindow of ImGui make FPS low Apr 8, 2024
@onon1101
Copy link
Collaborator Author

onon1101 commented Apr 8, 2024

and comment out this code can also make fps normal,

glDebugMessageCallback(Core::OpenGLDebugMessageCallback, nullptr);

@HeavenManySugar
Copy link
Contributor

HeavenManySugar commented Apr 8, 2024

This is because PR #162 would result in a large amount of OpenGL Severity NOTIFICATION. Besides commenting out, you can also try this method.
image

The reason why commenting out this code can solve the problem can be referred to in this.

glDebugMessageCallback(Core::OpenGLDebugMessageCallback, nullptr);

@HeavenManySugar
Copy link
Contributor

HeavenManySugar commented Apr 8, 2024

It work but not elegant
NTUT-FUCK-PTSD@c463129

Original code
SDL_Delay(static_cast<Uint32>(frameTime - Util::Time::GetDeltaTime())); is incorrect , milliseconds-seconds

@onon1101
Copy link
Collaborator Author

onon1101 commented Apr 9, 2024

This problem seems not to occurs in macOS.

result.mov

@Dragonfly911117
Copy link
Contributor

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.

@Dragonfly911117
Copy link
Contributor

Dragonfly911117 commented Apr 9, 2024

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.

Shoot, thought this was #167.

@HeavenManySugar
Copy link
Contributor

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.

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());

image
可以看到他的DeltaTime一上一下,這是因為GetDeltaTime()他並不會記錄上次Delay了多久,因此他會將那部分再下次也計算進入上次的Delay時間,這導致了GetDeltaTime()的值上下波動,顯然這樣的幀生成時間是不正確的

而我的那份commit其實他大致上的行為和目前差不多,唯一的區別就是他會將Delay的時間排除掉,我修改過後的
image

但這一切都成立於我沒有理解錯誤當前PTSD的程式碼,如果理解錯誤那可能是我造了一台鴿子直升機
1280

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: 🆕 Backlog
Development

No branches or pull requests

3 participants