-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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
SubViewPort.get_texture.get_image makes Godot stutter/jitter #75877
Comments
I'm not super familiar with 4.x or this bit of code, but reading back from GPU to CPU often causes a pipeline stall. The GPU is working on a queue, in a different place, sometimes different frame to the CPU. As soon as you ask to read something back "immediately", the GPU has to finish everything in the queue before the state is correct to read back. This can even mean rendering one or multiple frames. Even requesting a single pixel can cause this. |
That flat line is oddly bumpy. I think the stutter isn't fully resolved here. 😶 This isn't something that can be fully resolved without implementing hardware readbacks, which have 2-3 frames of latency. We should probably implement a way to perform those from a script, but it's not trivial. |
Thanks for the info. My context is the following:
These 2 tutorials cover stealth mechanics; detecting if the player is hidden in shadows/darkness. Both tutorials repeatedly call For the above use-cases the timing is not super important, as detection may happen every 200ms or so. It would perhaps be nice if we could get the image but it doesn't have to be "right now" in favor of not stuttering Godot. I am also wondering if I can solve this by staying within the GPU and measuring pixels via a compute shader. |
If it is still the same as with Godot 3 then Viewport.get_texture().get_image() also does a full image copy so the frame stutter gets more intense the higher the rendertarget resolution. In Godot 3 it was basically impossible to have acceptable frame rate while requiring texture reads on rendertargets for e.g. deformable terrain or other effects that require textures at higher resolution to be detailed enough. Last time I tested in Godot 4 beta it still had all the same issues. |
There's a lot of possible ways of detecting shadows in stealth games, I've done it before but am no expert. I suspect many use smoke and mirrors (e.g. artist placed areas / scripting, because gameplay scripting can be critical), and not what you think. I haven't watched these videos, but reading back from GPU is not a good way of doing this imo. I had a few people ask this for my lightmap module (i.e. just reading the lightmap), but just because your feet are in shadow doesn't mean the rest of your body is. Some options off the top of my head (whether level is static or dynamic will affect choices):
|
Yeppers, I saw those pixel-based tutorials but in the end I went with just raycasting and some trigonometry. Works like a charm <3 |
Perhaps this micro-stuttering only occurs on my Ubuntu machine (nvidia driver issue?) I tried another OS, same hardware:
And got a pretty stable frametime (with the project included in OP): I also tried on my laptop (Ubuntu 21, thinkpad X1 Gen9 - random intel GPU) and it felt pretty smooth. Maybe someone with Linux + official Nvidia drivers + |
I gave this a stab in my project where I'm having this issue and unfortunately the stutter seems to remain. |
just stumbled upon this, in fact simply adding a subviewport to a scene causes it to stutter dramatically. |
Can you upload a minimal reproduction project for that? If the SubViewport is redrawing continuously, it's possible that your CPU or GPU can't keep up with the increased demands of rendering two viewports at once instead of just one. |
Godot version
4.0.2-stable
System information
Ubuntu 22.04, RTX 3080, Vulkan API 1.3.224 - Forward+, OpenGL API 3.3.0 NVIDIA 525.60.13, X11, AMD 5900x
Issue description
Each of these spikes is exactly 0.2sec apart and caused by the
get_image()
call in the following line:This micro-stutter is noticeable especially when walking around, moving with the mouse (FPS character, etc)
Some things I have noticed:
DEBUG_DRAW_UNSHADED
would still stuttergodot/drivers/vulkan/rendering_device_vulkan.cpp
Line 2844 in 278fc75
I patched it with:
and set my subviewport size width to
127
so it doesn't_flush()
for my specific case and the micro-stutter is gone. A flat line:p.s: that FPS counter is mangohud, e.g:
mangohud ./bin/godot.linuxbsd.editor.x86_64
Steps to reproduce
SubViewport
with a camera inside itget_texture()
get_image()
on that textureOr download my minimal reproduction project
Minimal reproduction project
stutter_image_data.zip
The text was updated successfully, but these errors were encountered: