0
$\begingroup$

I have written a relatively simple interactive C program using OpenGL 4.4 with a vertex shader and a fragment shader, running in the CodeBlocks IDE on Windows. I included an FPS counter basically as in Anton Gerdelan's tutorial here:

Gerdelan

However, instead of GLFW I just use the Windows API myself. When the graphics window is in focus, the reported fps stays around 60. I noticed recently when the program was still running, but was not the active window, that the fan started running very loudly and the laptop became very warm. Using ALT-TAB a preview of the various windows I had open appeared above the taskbar (I think), as is normal in that version of windows. In the little scaled-down preview of the graphics window, visible before choosing that as the active window, I could see that the fps was reported as 8000 fps or something like that. As soon as I selected that as the active window, the fps dropped down to 60 and the fan began to calm down.

Now I am worried - by tabbing away, have I accidentally defeated the mechanism that allows the operating system to tell my C program to wait until it is ready to swap the buffers, and if so, do I thereby risk allowing my program to run the GPU so hot that I will damage it ?

Do laptop GPUs these days have built-in throttling that will slow them down when they get hot enough to risk damage ? If so, then by programming in C using OpenGL, have I accidentally defeated this mechanism ?

Ought I to add a Sleep command to my animation loop, to avoid this ? Would that work ?

$\endgroup$
2
  • $\begingroup$ The swapBuffers call is likely unsynchronized (not waiting the the DWM's refresh to composite) when the window is occluded, and therefore you start consuming 100% CPU in a tight loop, rendering and swapping with no graphical result, but your framerate will climb into the thousands - taxing the CPU's render loop. (Why render at all in this case?) $\endgroup$
    – Wyck
    Dec 20, 2022 at 16:47
  • $\begingroup$ Thank you Wyck ! Do you know how I could synchronise the swapBuffers call and thereby avoid this ? $\endgroup$
    – Simon
    Dec 22, 2022 at 14:33

1 Answer 1

3
$\begingroup$

Do laptop GPUs these days have built-in throttling that will slow them down when they get hot enough to risk damage ?

Yes. Every portable computing device these days has “thermal throttling” — reducing the clock rate in order to keep temperature within safe limits. If one runaway program could destroy the hardware, that would be noticed — many games are not programmed especially carefully.

These mechanisms are not perfect — there have been incidents where a very particular workload produced localized heat that was not detected adequately and damaged the hardware. But those are rare exceptions.

If so, then by programming in C using OpenGL, have I accidentally defeated this mechanism ?

No, not at all. The mechanism is usually built into the hardware and firmware — because it's important that it keep operating regardless of what the parts of the system that run user-supplied code are doing. You're far above the layer of the system that would need to be disturbed to stop that.

The fact that your laptop is warm on the outside and running fans vigorously may be unpleasant to your hands and ears, but does not mean it is damaging itself. If the fans are running then that's a sign that the thermal protection is working.

Ought I to add a Sleep command to my animation loop, to avoid this ?

No, you should notice when the window system tells you your window is minimized or otherwise fully obscured (I don't know how this works on Microsoft Windows but this is a feature offered by most platforms), and stop rendering entirely. Or maybe only render every second or so, for the sake of an updated preview image.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.