Daemon icon indicating copy to clipboard operation
Daemon copied to clipboard

Excessive CPU usage with vsync + NVidia

Open slipher opened this issue 1 year ago • 3 comments

On my Windows 10 machine with an Nvidia card, setting r_swapInterval caps the FPS as expected, for values -4 to -1 or 1 to 4. But despite the lower FPS, it increases the CPU usage. I did some tests with the 0.54.1 release with all default cvars except resolution and full screen, looking at the plat23 alien base. At 125 FPS without vsync, the CPU usage is 5%. With any value of vsync enabled (which gives possible FPSes of 60, 30, 20, or 15), the CPU usage is 8%. This means roughly all of 1 core, as the denominator here is 12 cores.

The problem does not occur with Intel graphics.

The problem does not occur in the main menu. So it can't be explained by something as simple as always busy-looping until the monitor is ready...

slipher avatar May 30 '24 08:05 slipher

The problem does not occur in the main menu.

The main menu is doing a lot of IPC while reading cvar values of (not-displayed but active) preferences options windows, maybe this inserts dozens and dozens of sleep calls in an existing busy loop?

illwieckz avatar May 30 '24 11:05 illwieckz

The problem does not occur in the main menu.

The main menu is doing a lot of IPC while reading cvar values of (not-displayed but active) preferences options windows, maybe this inserts dozens and dozens of sleep calls in an existing busy loop?

I don't follow this theory. If there were a busy wait, it would be once per frame, at the point when we request the completed frame to be rendered. I don't see how the graphics driver would observe how many cvar syscalls we used. The engine is by default single-threaded after all.

slipher avatar May 31 '24 12:05 slipher

Ah yes with vsync the busy loop would be in the graphics driver, not in the engine…

illwieckz avatar May 31 '24 12:05 illwieckz