godot icon indicating copy to clipboard operation
godot copied to clipboard

SubViewPort.get_texture.get_image makes Godot stutter/jitter

Open sanderfoobar opened this issue 1 year ago • 10 comments

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

https://i.imgur.com/qgSqlT1.png

Each of these spikes is exactly 0.2sec apart and caused by the get_image() call in the following line:

# runs every 0.2sec
get_node("%subviewport").get_texture().get_image()

This micro-stutter is noticeable especially when walking around, moving with the mouse (FPS character, etc)

Some things I have noticed:

  1. The size of the subviewport seems of no influence
  2. The draw mode of the subviewport seems of no influence, for example DEBUG_DRAW_UNSHADED would still stutter
  3. I tracked it down to the following call:

https://github.com/godotengine/godot/blob/278fc7538dbd98ff0e06410d69adca49b5326b21/drivers/vulkan/rendering_device_vulkan.cpp#L2844 I patched it with:

if(tex->width != 127)
    _flush(true);

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:

https://i.imgur.com/kPVWr1P.png

p.s: that FPS counter is mangohud, e.g: mangohud ./bin/godot.linuxbsd.editor.x86_64

Steps to reproduce

  1. Create a 3D scene
  2. Create a SubViewport with a camera inside it
  3. Get the texture of the subviewport via get_texture()
  4. Call get_image() on that texture
  5. Observe a stutter

Or download my minimal reproduction project

Minimal reproduction project

stutter_image_data.zip

sanderfoobar avatar Apr 10 '23 03:04 sanderfoobar