VSync causes 33% FPS drop on Direct3D

Place for things which are bugs but we have no idea how to solve them. Things related to hardware, libraries, strange setups, etc.
Tekky
Smart Inserter
Smart Inserter
Posts: 1040
Joined: Sun Jul 31, 2016 10:53 am
Contact:

VSync causes 33% FPS drop on Direct3D

Post by Tekky »

I currently have two computers on which I play Factorio. One is about 4 years old and one is 8 years old. The graphics card on my older computer has been upgraded afterwards, though, so that it is only about 4 years old.

On both computers, with VSync disabled, I reliably get an FPS/UPS of 60/60 (an ideal value). Both computers can handle larger factories without problems, without suffering any drops in FPS or UPS.

However, when I enable VSync, my older computer drops to an FPS of about 40. UPS is unaffected and remains at 60. My newer computer does not suffer from this drop in FPS.

In Factorio Friday Facts #70, Kovarex wrote that a FPS/UPS of 40/60 is the result of rendered frames not being prepared in time for the vertical synchronization point. He states that this happens when many things are on the screen that need to be rendered and that this could occur especially on far zoom levels.

However, on my older computer with VSync enabled, I always have an FPS/UPS of 40/60, even at the very start of the game where there is very little to render and even if I zoom in fully and set the graphics to minimum ("sprite resolution" to "extra low"). Therefore, I do not believe that my older computer is unable to deliver 60 FPS, but rather suspect that there is something wrong with the game loop. The fact that my older computer is able to reliably deliver 60 FPS with VSync disabled seems to corroborate this.

I am using the latest Nvidia graphics card drivers on Windows 7. I have been experiencing the issue at least since version 0.13 and the issue still persists in version 0.15. I am not using any mods. This issue is also not related to a specific savegame. Even if I start a new game, I have the same issue right from the start.

Strangely, this issue disappears completely when I start the game with the launch option "--force-opengl". In that case, I always get a FPS/UPS of 60/60, even with VSync active.

What is also strange is that when I set the the launch option "--force-opengl", the Factorio setting "Wait for VSync" seems to have no effect. I notice no visible tearing either way. Therefore, I assume VSync must always be active when using OpenGL, even if I disable VSync in Factorio. My Nvidia Control Panel is using default settings, i.e. it is not overriding VSync.

I have attached 4 log files, the first are with VSync enabled and disabled in Direct3D, the next two log are the ones in OpenGL.
Log file with Direct3D and VSync enabled
Log file with Direct3D and VSync disabled
Log file with OpenGL and VSync enabled
Log file with OpenGL and VSync disabled
Last edited by Tekky on Sat May 06, 2017 1:09 pm, edited 2 times in total.
BenSeidel
Filter Inserter
Filter Inserter
Posts: 590
Joined: Tue Jun 28, 2016 1:44 am
Contact:

Re: VSync causes 33% FPS drop on Direct3D

Post by BenSeidel »

Are you able to check what the FPS goes to when you run

Code: Select all

/c game.speed = 2
It should jump to 120/120 if your computer can handle it. If it instead goes to 60/120, then it's probably a rounding error.
Tekky
Smart Inserter
Smart Inserter
Posts: 1040
Joined: Sun Jul 31, 2016 10:53 am
Contact:

Re: VSync causes 33% FPS drop on Direct3D

Post by Tekky »

BenSeidel wrote:Are you able to check what the FPS goes to when you run

Code: Select all

/c game.speed = 2
It should jump to 120/120 if your computer can handle it. If it instead goes to 60/120, then it's probably a rounding error.
Good idea. The results were very interesting:

When I do that with VSync enabled in Direct3D, I get an FPS/UPS of about 40/120 (the 40 fluctuates a bit between 35 and 45, as it also does without this command)

When I do that with VSync disabled in Direct3D, I get an FPS/UPS of 120/120. Only when I zoom out heavily, the FPS drops to maybe 100 FPS.

When I do that with VSync enabled in OpenGL, I get an FPS/UPS of 60/120.

When I do that with VSync disabled in OpenGL, I also get an FPS/UPS of 60/120. This confirms my suspicion that the VSync setting is ignored when using OpenGL, i.e. VSync seems to be always active.

These results prove that my older computer is able to reliably deliver 120 FPS (100 FPS when fully zoomed out). Therefore, the fact that the FPS drops to around 40 when I activate VSync in Direct3D is, in my opinion, a sign that something may be wrong with Factorio's game loop. It is probably something that only happens with older computers. But I don't want to speculate too much, because the Factorio devs can certainly judge that better.
Twinsen
Factorio Staff
Factorio Staff
Posts: 1351
Joined: Tue Sep 23, 2014 7:10 am
Contact:

Re: VSync causes 33% FPS drop on Direct3D

Post by Twinsen »

For more detailed info open debug info(F4) and select show-time-usage. I suspect too much time will be spent inside flip. If it is so, it's something to do with the way our graphics library handles vsync.
It's a known issue that we were unable to solve and has been driving me crazy for some time now.
Tekky
Smart Inserter
Smart Inserter
Posts: 1040
Joined: Sun Jul 31, 2016 10:53 am
Contact:

Re: VSync causes 33% FPS drop on Direct3D

Post by Tekky »

Twinsen wrote:For more detailed info open debug info(F4) and select show-time-usage. I suspect too much time will be spent inside flip.
When I do that with VSync active, the field "Flip" displays the following values:

In Direct3D: 21.617/14.342/30.293
In OpenGL: 10.261/2.159/10.530

In case you need information on the values of the other fields, I have attached screenshots below:
screenshot in Direct3D
screenshot in OpenGL
Twinsen wrote:If it is so, it's something to do with the way our graphics library handles vsync.
Are you referring to Allegro or to your own in-house graphics library?

Twinsen wrote:It's a known issue that we were unable to solve and has been driving me crazy for some time now.
Hehe, yes, Posila has already made a post about your frustration with VSync issues. :-)
Twinsen
Factorio Staff
Factorio Staff
Posts: 1351
Joined: Tue Sep 23, 2014 7:10 am
Contact:

Re: VSync causes 33% FPS drop on Direct3D

Post by Twinsen »

Tekky wrote:In Direct3D: 21.617/14.342/30.293
In OpenGL: 10.261/2.159/10.530
Yes, flip should not go over 16ms(one frame), unless the video card is doing more work than it can handle(which is not happening since the scene is mostly empty and your video card is more than capable).
The waiting is inside the driver so it's not Factorio code or Allegro, thus not easy to debug. But Allegro is probably telling the driver to do something stupid.
It's the known issue we have no solution for yet. So I will unfortunately move this to 0/1 magic. We have some plans that might solve it in the future.

Tekky wrote:
Twinsen wrote:If it is so, it's something to do with the way our graphics library handles vsync.
Are you referring to Allegro or to your own in-house graphics library?
Allegro.


Tekky wrote:
Twinsen wrote:It's a known issue that we were unable to solve and has been driving me crazy for some time now.
Hehe, yes, Posila has already made a post about your frustration with VSync issues. :-)
HAHAHA... :oops: :cry: :( :evil:
xeln4g4
Long Handed Inserter
Long Handed Inserter
Posts: 53
Joined: Fri Oct 28, 2016 2:42 pm
Contact:

Re: VSync causes 33% FPS drop on Direct3D

Post by xeln4g4 »

Was this problem solved? Anyone??? I either turn on vsync ON and play without stuttering but with FPS/UPS 45/60 or turn Vsync OFF and play 60/60 but with a lot of stuttering due to vertical sync.
Hardware not a problem and not a huge factorio base (it's the same when starging a new game from scratch).
Jap2.0
Smart Inserter
Smart Inserter
Posts: 2379
Joined: Tue Jun 20, 2017 12:02 am
Contact:

Re: VSync causes 33% FPS drop on Direct3D

Post by Jap2.0 »

xeln4g4 wrote:Was this problem solved? Anyone??? I either turn on vsync ON and play without stuttering but with FPS/UPS 45/60 or turn Vsync OFF and play 60/60 but with a lot of stuttering due to vertical sync.
Hardware not a problem and not a huge factorio base (it's the same when starging a new game from scratch).
It doesn't appear to have been, but the entirety of the graphics engine is being rewritten for 0.17, so that might help.
There are 10 types of people: those who get this joke and those who don't.
Tekky
Smart Inserter
Smart Inserter
Posts: 1040
Joined: Sun Jul 31, 2016 10:53 am
Contact:

Re: VSync causes 33% FPS drop on Direct3D

Post by Tekky »

xeln4g4 wrote:Was this problem solved? Anyone??? I either turn on vsync ON and play without stuttering but with FPS/UPS 45/60 or turn Vsync OFF and play 60/60 but with a lot of stuttering due to vertical sync.
Hardware not a problem and not a huge factorio base (it's the same when starging a new game from scratch).
As I stated above, I was able to work around the problem by using OpenGL instead of Direct3D. In order to do so, all you have to do is start the game with the following command line option:

Code: Select all

--force-opengl
In Steam, you must do the following to change the command line options:

Right click on Factorio in the games library -> Properies -> General -> Set Launch Options -> "--force-opengl" (without the quotes)
Jap2.0 wrote:
xeln4g4 wrote:Was this problem solved? Anyone??? I either turn on vsync ON and play without stuttering but with FPS/UPS 45/60 or turn Vsync OFF and play 60/60 but with a lot of stuttering due to vertical sync.
Hardware not a problem and not a huge factorio base (it's the same when starging a new game from scratch).
It doesn't appear to have been, but the entirety of the graphics engine is being rewritten for 0.17, so that might help.
That is correct. In his post above, Factorio developer Twinsen stated that it is likely that the problem is caused by the graphics engine Allegro. Since this is being replaced by their own graphics engine in 0.17, it is likely that this will solve the problem.

See Factorio Friday Facts #230 for more information on the new graphics engine and why it is being replaced.
xeln4g4
Long Handed Inserter
Long Handed Inserter
Posts: 53
Joined: Fri Oct 28, 2016 2:42 pm
Contact:

Re: VSync causes 33% FPS drop on Direct3D

Post by xeln4g4 »

Tekky wrote:
xeln4g4 wrote:Was this problem solved? Anyone??? I either turn on vsync ON and play without stuttering but with FPS/UPS 45/60 or turn Vsync OFF and play 60/60 but with a lot of stuttering due to vertical sync.
Hardware not a problem and not a huge factorio base (it's the same when starging a new game from scratch).
As I stated above, I was able to work around the problem by using OpenGL instead of Direct3D. In order to do so, all you have to do is start the game with the following command line option:

Code: Select all

--force-opengl
In Steam, you must do the following to change the command line options:

Right click on Factorio in the games library -> Properies -> General -> Set Launch Options -> "--force-opengl" (without the quotes)
Jap2.0 wrote:
xeln4g4 wrote:Was this problem solved? Anyone??? I either turn on vsync ON and play without stuttering but with FPS/UPS 45/60 or turn Vsync OFF and play 60/60 but with a lot of stuttering due to vertical sync.
Hardware not a problem and not a huge factorio base (it's the same when starging a new game from scratch).
It doesn't appear to have been, but the entirety of the graphics engine is being rewritten for 0.17, so that might help.
That is correct. In his post above, Factorio developer Twinsen stated that it is likely that the problem is caused by the graphics engine Allegro. Since this is being replaced by their own graphics engine in 0.17, it is likely that this will solve the problem.

See Factorio Friday Facts #230 for more information on the new graphics engine and why it is being replaced.
Thank you soooo much 10/10, this solution ("--force-opengl") solved the problem!!!!
Tekky
Smart Inserter
Smart Inserter
Posts: 1040
Joined: Sun Jul 31, 2016 10:53 am
Contact:

Re: VSync causes 33% FPS drop on Direct3D

Post by Tekky »

xeln4g4 wrote:Thank you soooo much 10/10, this solution ("--force-opengl") solved the problem!!!!
I'm pleased I was able to help.

However, I suggest that you deactivate that command-line option again after 0.17 is released, otherwise it may cause you trouble. You should no longer need that workaround with the new graphics engine.
xeln4g4
Long Handed Inserter
Long Handed Inserter
Posts: 53
Joined: Fri Oct 28, 2016 2:42 pm
Contact:

Re: VSync causes 33% FPS drop on Direct3D

Post by xeln4g4 »

Ok, hope i'll remember, i found out about 0.17 likely to solve the problem, but right now, i couldnt find any solution after few days searching, you were the only one able to help!!!
boksiora
Fast Inserter
Fast Inserter
Posts: 109
Joined: Thu Mar 10, 2016 7:45 pm
Contact:

Re: VSync causes 33% FPS drop on Direct3D

Post by boksiora »

Hi @Twinsen

yes FLIP is the problem i send few PMs to kovarex on Fri Oct 06, 2017 noticing the issue with FLIP issue on my laptop and he suggested to file bug report, but i was too lazy to do it

Hi

I tested few previous versions

Its ok on 0.15.34 where FLIP is taking lower amount of time

http://prntscr.com/gu4xqv

bug is appearing after 0.15.34 where flip takes 2.5

pls fix it as newest version is unplayable now on my PC :)

i have good PC with 16GB ram and i7

i will stick to older version for now
There is something called FLIP that is causing super big lagging in the newest version

On empty map when i move on every few frames the game is freezing for little

http://prntscr.com/gu4m8x

This FLIP thing goes to 2.5 in usage on every few frames
i changed few settings and now flip is 14 but does not cause lag

http://prntscr.com/gu5hf2


i put


force-opengl=true
cache-sprite-atlas=true
tree-sprite-mipmaps=false
atlas-specialization=true
skip-vram-detection=true
video-memory-usage=high
do im pretty sure FLIP is the cause of this
Rseding91
Factorio Staff
Factorio Staff
Posts: 14338
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: VSync causes 33% FPS drop on Direct3D

Post by Rseding91 »

boksiora wrote: Mon Sep 17, 2018 8:50 pm do im pretty sure FLIP is the cause of this
Saying "FLIP" is the cause of the slowdown is like saying "Rendering" is the cause of low FPS :)
If you want to get ahold of me I'm almost always on Discord.
boksiora
Fast Inserter
Fast Inserter
Posts: 109
Joined: Thu Mar 10, 2016 7:45 pm
Contact:

Re: VSync causes 33% FPS drop on Direct3D

Post by boksiora »

Rseding91 wrote: Mon Sep 17, 2018 9:11 pm Saying "FLIP" is the cause of the slowdown is like saying "Rendering" is the cause of low FPS :)
i don't know what im talking about, but FLIP is the cause of the issue :) :lol: :lol:
Jap2.0
Smart Inserter
Smart Inserter
Posts: 2379
Joined: Tue Jun 20, 2017 12:02 am
Contact:

Re: VSync causes 33% FPS drop on Direct3D

Post by Jap2.0 »

Rseding91 wrote: Mon Sep 17, 2018 9:11 pm
boksiora wrote: Mon Sep 17, 2018 8:50 pm do im pretty sure FLIP is the cause of this
Saying "FLIP" is the cause of the slowdown is like saying "Rendering" is the cause of low FPS :)
I mean, it's not wrong... :P

boksiora wrote: Mon Sep 17, 2018 9:14 pm i don't know what im talking about
And there's our problem
There are 10 types of people: those who get this joke and those who don't.
Post Reply

Return to “1 / 0 magic”