godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
86.42k stars 19.25k forks source link

Heavy stuttering issue in simple 2D game [Windows 10, Nvidia] #19783

Closed crystalnoir closed 4 years ago

crystalnoir commented 6 years ago

Godot version: Godot 3.1-dev / Godot 2.X

OS/device including version: PC - Windows 10, GeForce GTX 1060 6 GB, 16 GB RAM.

Issue description: Stuttering / jitters when moving a 2D Sprite. Reproduced on 2 computers (with nvidia graphic cards, the one above and a laptop), a friend of mine reproduce this issue too.

Steps to reproduce: I just download the "First project" that we can make in the documentation. I have tested to reproduce the first part of this tutorial to only have the player and nothing else. If I run it without change anything. I have some stuttering at the same as the game run with 60 FPS. The motion is not smooth. I collaborate with a dev to try to reproduce this problem and try to understand the issue. I have made a lot of test (Run from editor, run after compilation without debug mode etc...But when I deleted the animation, all run smoothly.

PS : it seems that physic behaviour make sprite stuttering too (try with kinematic and Area2D node with collision). If I desactivate collision and replace Area2D with a simple node2D there is no stuttering (if I don't play any animation on the player).

Minimal reproduction project: Here's a minimalist project (that comes from the first game project of the documentation). If I run it, I have some stuttering. If I delete the player animation I have no more stuttering. FirstGame.zip

crystalnoir commented 6 years ago

Hi, I have updated my report because I tested it on my other computer (home) and the issue is here at the same as I change the animation. So, this is not the animation that causes the issue. I think I believed it because when I saw that it was on my laptop, it has a small screen. Here's a video of the issue (the video is at 60 FPS) : GodotStutter.zip

akien-mga commented 6 years ago

If the video is an accurate representation of what's on screen in real time, then it's a hell lot more stutter than I've ever seen mentioned in any stutter-related issue here. There must seriously be something wrong with this Windows 10 / GTX 1060 setup (I see quite a few articles on the Internet detailing performance issue on Windows 10 / Nvidia after major Windows updates, but can't tell if it's related).

akien-mga commented 6 years ago

Here's a video of the test project on my system, Mageia 6 x86_64 (Linux), Nvidia GTX 670MX with recent proprietary drivers (390.59). No stutter at all (on Openbox - on KWin the compositor messes things up and there's a very light stutter every 10 s or so). StutterTest_LinuxNvidia_OK.zip

BTW here's a fixed version of the demo project firstGame_fixed.zip, the original one had files split over three different folders somehow ("firstgame", "firstGame" and "FirstGame").

Zylann commented 6 years ago

The game gives me the same amount of stuttering as in the video. However, turning vsync off gets rid of the stuttering completely (but the game runs at 4000 fps). Windows 10 64 bits nVidia GTX 1060 too here.

RaXaR commented 6 years ago

I also tested as @Zylann suggested here and got the same results. I too have Win10 x64 and nVidia GTX 1060.

Edit: I use these drivers from nVidia: 398.11-desktop-win10-64bit-international-whql

Ranoller commented 6 years ago

Win 7 64 bit GLES2 and GLES3 tested, GeForce GTX 660/PCIe/SSE2... no stutters. Turning on Aero, with the 2d editor of godot behind the game results in some little stutter (Godot editor render interfere with the rendering of the game).

However, Godot stuttering is the giant invisible enemy, we all know it is there but we do not want to look very closely because we know that the solution is not simple.

Your issue seems like different physics fixed fps with monitor refresh rate, i see this kind of stutter in monitors that have not same hz that editor configured physics fps, but can be other thing.

Zylann commented 6 years ago

Your issue seems like different physics fixed fps with monitor refresh rate

The demo doesn't uses physics, only a simple _process.

Ranoller commented 6 years ago

True... i say that i only see that heavy stutter in this case, but it´s true that there is no physics process involved. I test changing hz of one of the monitors and no differences, 0 stutter in my gear.

Edit: I got win 7, win 8.1 and win 10 in this computer and take the time to test all. No stutters in win 8.1. I´m testing in win 10 now and is very smooth... no windows problem. Godot is angry with your 1060?

crystalnoir commented 6 years ago

Here's the same test with my laptop. As you can see the problem is here too. But it seems that's less visible but it's here.

Laptop Specs : Windows 10 - Geforce 940M

Here's the Laptop video (it's a 60 FPS video) : GodotStutterLap.zip

Ranoller commented 6 years ago

Can anyone with the stutter problem try to execute the demo changing in Player.gd _process with _physics_process?

crystalnoir commented 6 years ago

I will test this evening on my home PC this is where I have the problem all the time. But I have a weird thing : This morning, I gave you a video with the project on my laptop and as you can see you have the same kind of stuttering. The problem is that now, if I run it again I don't have this stuttering again, like it's random. And I didn't change anything on my laptop, I worked on it all the morning on a TSE session.

Warning : I talk only for my laptop. On my home PC with GTX 1060 the problem is always here. But on my laptop the problem seems to occur randomly. That's why I think that for now, I will let my laptop on the side for testing purpose and I will test only on my home PC that have the problem all the time, to be able to isolate the "bug".

RaXaR commented 6 years ago

@Ranoller I tested it and got the same result. The stutter is still there and it pretty much looks the same.

crystalnoir commented 6 years ago

@Ranoller Made the test and the same à @RaXaR that doesn't change anything. Got the same problem.

Ranoller commented 6 years ago

This not look well....

To exactly specify the bug I would do this tests:

1) Full screen on - off 2) If more than 1 monitor: Disable- Enable shared desktop 3) Aero on-off

Your cards run well other games? ...

Reading the first post about the animation -> stutter / no animation -> no stutter i read the code and i see some stuff that i don´t think it´s correct... exactly: changing animation every frame. I think that code should check current animation. Probably it didn´t change nothing, but if someone want test to change Player.gd in this way:

extends Area2D

# class member variables go here, for example:
# var a = 2
# var b = "textvar"
export (int) var SPEED #How fast the player will move (pixel/sec)
var screenSize #size of the game window
onready var AnimSprite = $AnimatedSprite

func _ready():
    # Called when the node is added to the scene for the first time.
    # Initialization here
    screenSize = get_viewport_rect().size
    #Engine.target_fps = 60
    pass

func _process(delta):
#   # Called every frame. Delta is time since last frame.
#   # Update game logic here.
    var velocity = Vector2() #Player movement vector
    if Input.is_action_pressed("ui_right") :
        velocity.x += 1
    if Input.is_action_pressed("ui_left") :
        velocity.x -= 1
    if Input.is_action_pressed("ui_down") :
        velocity.y += 1
    if Input.is_action_pressed("ui_up") :
        velocity.y -= 1
    if velocity.length() > 0 :
        velocity = velocity.normalized() * SPEED
        if !AnimSprite.is_playing():
            AnimSprite.play()
    else :
        if AnimSprite.is_playing():
            AnimSprite.stop()

    if velocity.x != 0 :
        if AnimSprite.animation != "right":
            AnimSprite.animation = "right"
        AnimSprite.flip_v = false
        AnimSprite.flip_h = velocity.x < 0
    elif velocity.y != 0 :
        if AnimSprite.animation != "up":
            AnimSprite.animation = "up"
        AnimSprite.flip_v = velocity.y > 0

    position += velocity * delta
    position.x = clamp(position.x, 0, screenSize.x)
    position.y = clamp(position.y, 0, screenSize.y)

This is the last idea... probably nosense for the problem, but... your graphic card is very common in players, so godot should execute well in it.

crystalnoir commented 6 years ago

@Ranoller

For :

crystalnoir commented 6 years ago

Just tested your code and it doesn't change anything :(

Ranoller commented 6 years ago

Although this problem may not be directly related to godot, godot must revise well stuttering issues... it´s not true that all games stutters as it was said in another thread. Today i was playing n++, full screen, windowed, trying to see any stutter and no.... no stutters at all. Same with Ori and the blind forest, to many bad things have to do to have any stutter in this game (windowed with other programs in background, etc.... and only 2 o 3 frame skips in a hour...). Godot, on starting execution, always stutter x number of seconds, later it stabilizes, but every X seconds you are going to have frame skips (if you don´t have the problem of the gtx1060 of course). We shouldn´t treat this issue as a minor problem.

crystalnoir commented 6 years ago

I try to do my best to isolate the problem but at my level it's a bit difficult. I tried testing different setups but without result. I also tested to but a background image instead of use a color with clearscreen. I've already seen (don't remembre witch) an engine with this problem because of rendering a 2D sprite on a "void screen" causes this problem, but it seems that's not the case here. So I don't have any idea for now.

Zylann commented 6 years ago

Out of curiosity, try to profile how long SwapBuffers takes in context_gl_win.cpp around line 68. If it takes longer than 16ms, then you are likely dropping a frame here.

crystalnoir commented 6 years ago

If someone that knows the sources of Godot could test that I'm interesting in the result (sorry for my english...)

RaXaR commented 6 years ago

I was playing with this issue yesterday and I it magically resolved itself after the game windows was running for about 60 seconds. Then it was smooth, this tells me that it could be a caching thing?

Ranoller commented 6 years ago

Out of curiosity, try to profile how long SwapBuffers takes in context_gl_win.cpp around line 68. If it takes longer than 16ms, then you are likely dropping a frame here.

Maybe could be helpful to know if the problem happends in GLES2, we don´t test that

crystalnoir commented 6 years ago

I tried to play with options in Godot about it, but it doesn't change anything for me, may be I don't know exactly what to change ?

Tried to let the game for more than 2 minutes but the problem is always here not solved for me after 60 s.

meld-cp commented 6 years ago

I had a similar issue with 3.0.3. (Win10 64 bit, Nvidia 660) I didn't notice it with 3.0.2.

I think it has something to do with the AnimatedSprite Node because I see the performance issues with levels which have this node. I get the shuttering when running from the IDE or if I export to Win 32bit, but If I export to Win 64bit everything runs as it should, no stuttering.

meld-cp commented 6 years ago

.. interestingly, I don't have the issue with the example project 'FirstGame.zip'... but still do with my game, FPS drops to 5 when run from the IDE and 32bit version, GPU sits about 2%... but, with the 64bit export GPU is at 30% and everything is fine.

crystalnoir commented 5 years ago

Hi there, is any news about this problem ? I've just tested with the pong demo (I didn't do that before, just with the tutorial game) and it seems the problem is here with this sample project too. I use the last version of Godot on Steam to test it.

Updating Nvidia drivers didn't change anything, so I come to take some news about this issue. I didn't find how to get ride of it yet.

Ranoller commented 5 years ago

I have now a computer with a geforce gtx 1060 (3gb- cheap) and don´t have the issue in windows 10 home. It can be some background app? Some hardware especific configuration AMD-Nvidia Intel-Nvidia....? I don´t have any game aplication in this computer (is in my music recording-studio) but godot runs smothly even with 3 screens connected to the computer. Anybody with the problem can check if have any game-monitoring software running in background, or steam, or something like this...? And if got it try to dissable?

crystalnoir commented 5 years ago

Difficult to turn off Steam when you use it to launch Godot...Godot runs great the problem is the game you make with. I already tried to disable all what I can disable, that changes nothing. I made a lot of tests without success. I also tried to reset the nvidia drivers for example, update them etc... but it changes nothing.

On the other side, I have a bunch of engines that run smoothly so why not Godot ? That's the thing I tried to find. But for now I don't find something. There is something somewhere but what and where, that is the question :-)

Ranoller commented 5 years ago

This issue is too "engine-dev-specific" to find a acceptable solution by own search. i can look for hours to the godot code and i know that never will have any possibility to find something related to this... i know that engine devs like more code new functionality and "bug-fix" is considerated more "junior-work" or something like this. But with this kind of issue is not the case. We need some engine dev to auto-assign this issue and other "complicated-ghost-low level-hard to afford" bug fixes...

crystalnoir commented 5 years ago

I mention that I already tried the dev version (without Steam) and the problem is the same.

Qws commented 5 years ago

Hi I had exact same stutter problem (using Godot 3.1 from Git source), any movement lagged for me, exactly like in your video, be it move_and_slide or just animation-player movement. but turning V-Sync on in project setting completely solved stutter problem in 2D game.

I'm kinda confused because @Zylann said turning V-Sync off removed the stuttering, but for me it's the opposite.

Zylann commented 5 years ago

@Qws turning it off AND making the game run at more than 60fps (which it did at the time) made the stutter go away for me but it brings other issues (using all power available and making fail everything that did not use a proper delta time). If you have stutter with V-sync off then it's either due to improper delta time or a situation where the game has to wait/process longer than a frame to update the screen.

Ranoller commented 5 years ago

First test that i did with new gtx 1060 give no problem... but later i experience that stutter. Only thing that i changed is the dvi to hdmi conexion (and some programs instaled)... this its a bit weird. Only thing that i convinced is that the problem is not in the windows 10 side.

emo10001 commented 5 years ago

I will say this much. I am working on a 2D game tutorial "Hoppy Days" from the Gamedev.tv tutorials. I WAS using 3.0.2 to develop it, and it was working just fine. I noticed that the tutorial was using 3.0.4, so literally TODAY I decided to upgrade to 3.0.6. There is now a noticeable lag in the game. The lag was not there at all in 3.0.2. It is there now. All other settings are the same.

My Laptop is a fairly new (purchased March of 2017) Dell Inspiron 7000 series gaming laptop. Processor is 7th Generation Intel Core i7-7700HQ Quad Core (6MB Cache, up to 3.8 GHz). Video card is NVIDIA GeForce GTX 1050Ti with 4GB GDDR5. RAM is 16GB, 2400MHz, DDR4. Hard drive is a Samsung SSD. Windows 10.

To me, it very much seems like something changed either in 3.0.4 or 3.0.6.....Nothing else has changed at all. Not even the game (as in...I haven't changed/edited/updated the level at all).

akien-mga commented 5 years ago

@emo10001 Could you test 3.0.3? That's when we changed the buildsystem used to make 3.0.x binaries (3.0 up to 3.0.2 were built on AppVeyor CI with MSVC 2015, 3.0.3 up to 3.0.6 have been built with GCC 8 via MinGW).

If your laptop has Optimus/switchable graphics, it could be that your system whitelisted the 3.0.2 binary to be used with the Nvidia GPU, while 3.0.3+ would default to an IGP. Or it could be that 3.0.2 was whitelisted by your antivirus while 3.0.3+ are seen as coming from a different source (which is true) and not yet deemed as safe, so the antivirus would run its full checks and impact performance. Those are only guesses, but otherwise I'm not sure what actual Godot change would impact performance like that, so I can only think of buildsystem changes.

CC @hpvb

alanenggb commented 5 years ago

I'm having the same problem! My project stutters for 20 to 30 seconds, then runs smoothly afterwards. I downloaded the project in OP post and it is the exact same thing. Turning V-Sync off removes the problem, and it runs at 4000+ fps.

I'm running version 3.0.6 on Linux Mint 19 (so I guess that windows tag is innacurate, eh?) and GTX 760 with latest proprietary drivers.

akien-mga commented 5 years ago

I'm running version 3.0.6 on Linux Mint 19 (so I guess that windows tag is innacurate, eh?) and GTX 760 with latest proprietary drivers.

No, but this is likely a different issue. Stuttering on Linux often happens due to window manager's compositing (for example I have some with KWin, none with Openbox).

Ranoller commented 5 years ago

My project stutters for 20 to 30 seconds, then runs smoothly afterwards

I notice this a lot, if i execute scene that i´m editing, there is stutter and some tearing (with vsync on) about 15-30 secs, but if i start project from main menu and open the scene with the scenes-selector... well, there is no stutter in the same scene (there is eventually, but not ever). There is some explanation about this event? Godot? Windows? How many frames are necessary to stabilize reproduction?... it will be great to know that things because there are necessary to the game-design.

alanenggb commented 5 years ago

No, but this is likely a different issue.

Hmm, I see. What I meant is, this specific issue is probably multi-platform as many people are experiencing the same problems.

jaredtjenkins commented 5 years ago

I've been messing around and noticed that two kinematic bodies stutter exactly at the same time, for both move_and_slide() and move_and_collide().

Hooking a camera up to one as they both oscillate, everything in the scene stutters except for the two kinematic nodes. A static camera shows only the two kinematic nodes stutter.

It doesn't seem to matter what graphic settings I change, nor _process or _physics_process. nor does using a different delta variable.

Ranoller commented 5 years ago

I think that this project is not representative of real use... more complicated projects runs a bit smooth. I think that windows don't handle well an excesive large godot idle time... I found another related issue, not only for godot but it suffers a lot with that: in multimonitor with extended desktop game is more smooth in monitor 1 if this is taged like "primary monitor". If primary monitor is other that 1 there is stutter in secondary monitor ( youtube suffer from that to, but not unity commercial games like ori). With full screen in secondary monitor, aero in win 7, and monitors swapped (ej: monitor 2 like primary) the scenary is the worst and there is a big stutter (not only godot, but nor game maker or unity games).... i know that multimonitor with extended desktop in 2 1080p screens is hard for cheap GPUs but other games are smoother ( godot don't lose fps, only stutter). If this test will continue we should make a more complex example.

alanenggb commented 5 years ago

@Ranoller my setup is a dual monitor in a gtx 760, second monitor tagged as 'primary', linux mint 19 with cinnamon. I was try to understand the specific condition the project stutters, but couldn't figure out. These small projects sometimes stutter, sometimes don't (only stuttering, no fps loss). Also, when it stutters (running in windowed, godot testing configs), I usually have one or more chrome windows in the second monitor (not the primary), and when I minimize them, the stutter is gone... after some minimizing/restoring on the chrome windows, the stuttering is totally gone.

Ranoller commented 5 years ago

I´ve got 2 computers -> one with i5 gtx660 2 screens 1080p and other with i7 gtx 1060 3 screens (2 1080p and other hdready)... well, i have this stutter problem related with secondary monitors in gtx660, i think that is related exclusivelly with rendering, godot and chrome stutters, game maker and unity don´t (commercial games, exactly HiperLightDrifter and Ori, i didn´t test demos or templates). Windows aero stutters more in full screen (i think is not really full screen) but have very much fps, without aero in win 7 i´ve got in my project 130-140 fps without vsync, with aero i pass 400 fps, but... stutters (a lot) in certains conditions (with and without vsync). I can´t barelly make godot stutter in the i7 gtx 1060 (with real project, the demo in this thread stutters and i explain jet my opinion about). I think is a optimization /OpenGL problem, ej: Light2D is barelly unusable, any mix mode other than "mix" can stutter if the system is not too powerful, but godot should handle permormance in same level that game maker or unity does. Probably once 3.1 was launched, work for optimization could beggin (if problem is fixable and it isn´t a Direct3D / OpenGL - Windows problem of course... i don´t know how to find GLES2/3 games in windows to test and disccard a direct OpenGL - Aero/Win7-8-10 problem)... I understand that permormance of godot never will be the same of propietary -> one game based engines (Ej: Rayman origins runs smooth in an old laptop i´ve got, godot 2 don´t), but it should render at least at the same stable level that game maker (Unity probably will be better optimized that godot for a long time, you know, the money...). For now i feel that godot performs well only in high end hardware or in low resolution screens (I test in an i5 win7 32bit 15" intel hd graphics computer and performs good, but i don´t think that with an hd screen this computer will run´s godot smoothly)...

Of course all of that are my opinions/experiencies, i can be wrong (and i hope to be.. if this would be a simple one-line fix this could be great!!!)

Ranoller commented 5 years ago

On other hand i remember to read reduz writing something related to the "process priority" of the godot executable, but in windows there is not difference if you manually change the priority of godot in execution, godot don´t underperformant (whou, I have invented a word?), execution of the program doesn´t have spikes, it´s the rendering, something related with nvidia/godot and the computer desktop (i n windows, i don´t try in linux)

crystalnoir commented 5 years ago

Hi there, so, are there any news about this problem ? ^^ I will test again with the newest version but it seems that the problem still there.

zhagsenkk commented 5 years ago

does this exit in android or ios platform now?there are some games in google store made by early godot that also have shutter problem.like: https://play.google.com/store/apps/details?id=com.MoTaiGikStudio.DunkUp

Ranoller commented 5 years ago

This exist in all tested platforms in certains circunstances, with diverse GPU´s and diverse operating systems... is not documented in consoles.

MightyPrinny commented 5 years ago

I tested it on both linux and windows and it ran smoothly with the ocasional small stuttering, I have a low end integrated intel hd graphics baytrail graphics card

meld-cp commented 5 years ago

After many hours of trying to figure out the cause of the stutter, in my case at least, I by chance tracked the consistent 1s stutter down to having the 'Auto Switch To Remote Scene Tree' enabled in 'Editor Settings'. Unticking this resolves the stutter and performance issues for me. (there is possibly a very slight stutter still, but it's barely noticeable.)

godot windows tools 64_2018-11-14_01-19-20

Godot build 8849d3b47de8ab936549f0b9262c1193164feee5 Win10 64bit, NVIDIA GeForce GTX 660, driver v416.81

behelit2 commented 5 years ago

I also have the stuttering issue with my game. The only thing that seems to make it better is switching full screen off and on while the game is running... And even then there is a slight stutter that creeps up afterwards. Seems to happen completely at random. Sometimes the game will run near perfect, other times the stuttering occurs.

2D project with kinematic characters. Intel i5-2550K CPU 16gb ram Geforce GTX 970 Win10 64bit Godot 3.0,6