DmitriySalnikov / godot_debug_draw_3d

Draw 3D debug graphics and 2D overlays with this add-on.
https://dd3d.dmitriysalnikov.ru/
Other
451 stars 23 forks source link

[Bug]: weird constant high gpu usage anywhere in the editor #28

Closed morganholly closed 10 months ago

morganholly commented 10 months ago

Godot version

4.1.1 no c#

DebugDraw3D version

1.2.0

On which operating systems the error occurs

macOS

Using which renderers the error occurs

Vulkan

Issue description

so i've had a weird issue where in the editor (not an issue at all in game), there's very high gpu usage everywhere in the editor, on the previous project file i had it happen in empty 2d scenes, this time i noticed it in the script editor. but not in the game itself, the game taking focus away from the editor would reduce the gpu usage, at least when in the menu.

to test, i installed another plugin, tho it's gdscript not gdextension so maybe it's gdextension specific, but i saw no or nearly no change in gpu usage. i previously thought it was yet another plugin, which did have a bug that caused high gpu usage, and i created a fresh project to redo stuff after testing an empty project with that other plugin and not seeing the same issue, and after copying some files from before i remember it starting to a new project file, including with debug draw, and having the same issue.

i opened a nearly empty project file to test, and after installing, without even leaving the addons page, i was able to see the increase in gpu usage, and after deleting it with the integrated file browser, it went back down to baseline.

Steps to reproduce

install addon look at gpu usage

Minimal reproduction project

N/A

DmitriySalnikov commented 10 months ago

Confirmed. As far as I understand, the problem at the moment is that my code updates 3d objects constantly.

Without DD3D:

https://github.com/DmitriySalnikov/godot_debug_draw_3d/assets/7782218/f8ee3c52-56ef-4115-86a8-a45f6bd61f44

With DD3D:

https://github.com/DmitriySalnikov/godot_debug_draw_3d/assets/7782218/b7da8e0e-ab59-4af1-885e-d3899b522cdb

You can confirm this by simply turning on the spinner in the editor settings: image

I also have an increased load on the GPU up to 30-40% in an almost empty viewport. But this percentage directly depends on the GPU frequency and VRAM frequency, which are at low values. Therefore, with such a "load", the fans of the video card do not even turn on and I did not notice that the editor window is constantly updated 😅.

I will try to remove the load on the GPU in empty scenes, but in scenes where @tool and draw_* will be used, updates will still be every frame.

morganholly commented 10 months ago

i'm just confused why it would happen in a project with no 3d scenes, in the assetlib tab, immediately after downloading

DmitriySalnikov commented 10 months ago

immediately after downloading

Actually DD3D really connects immediately after loading, but GDScript cannot correctly update the list of singletons, which is why it is impossible to use DD3D in the usual way without restarting.

In the editor, you can create such a script and check whether there is an addon sington or not (Ctrl + Shift + X, or File - Run):

@tool
extends EditorScript

func _run():
    print(Engine.has_singleton(&"DebugDraw3D"))
    Engine.get_singleton(&"DebugDraw3D").draw_aabb(AABB(Vector3.ZERO, Vector3.ONE), Color(0,0,0,0), 10)

After installing the addon and executing this script, a cube will appear in the 3D editor.

in a project with no 3d scenes

3D editor is also a 3D scene and a 3D world in which my addon exists and is updated every frame. And this 3D world always exists in the editor.

morganholly commented 10 months ago

is there a way to turn it off in the editor? i don't have any tool scripts

DmitriySalnikov commented 10 months ago

is there a way to turn it off in the editor?

Not yet. But I will add a property for the default debug state to the project settings.

As a workaround, you can use this script: disable_dd3d.gd

@tool
extends Node

func _ready():
    if Engine.is_editor_hint():
        DebugDrawManager.debug_enabled = false

Then add it to Project Settings - Autoload.

DmitriySalnikov commented 10 months ago

Can you test the fix using binaries from here?

It also contains a new setting debug_draw_3d/settings/initial_debug_state

morganholly commented 10 months ago

i will try it out now

morganholly commented 10 months ago

yea seems to have fixed it. i don't see it in the plugins list but it works when the game is launched and there's no constant gpu load in the editor