Skip to content
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

RenderingServer.viewport_get_measured_render_time_gpu always return 0 #75346

Open
lemtea8 opened this issue Mar 26, 2023 · 2 comments · May be fixed by #75394
Open

RenderingServer.viewport_get_measured_render_time_gpu always return 0 #75346

lemtea8 opened this issue Mar 26, 2023 · 2 comments · May be fixed by #75394

Comments

@lemtea8
Copy link

lemtea8 commented Mar 26, 2023

Godot version

4.0.1-stable

System information

Kubuntu, Forward+/Mobile, GTX 1050

Issue description

I tried to use the code to measure cpu/gpu time, but these method always return 0.

var viewport_rid = get_tree().root.get_viewport_rid()
var duration = RenderingServer.viewport_get_measured_render_time_gpu(viewport_rid)
print(duration)

Steps to reproduce

Download the MRP and run.

Minimal reproduction project

tmp.zip

@Calinou
Copy link
Member

Calinou commented Mar 26, 2023

You need to enable time measurements first by calling RenderingServer.viewport_set_measure_render_time(get_tree().root.get_viewport_rid(), true) in _ready(). See https://github.com/godotengine/godot-benchmarks for a working example.

We should probably add a project setting to do this this automatically when you need to use time measurements.

You can then get CPU time spent on rendering the last frame using RenderingServer.viewport_get_measured_render_time_cpu(get_tree().root.get_viewport_rid()) + RenderingServer.get_frame_setup_time_cpu(), and GPU time using RenderingServer.viewport_get_measured_render_time_gpu(get_tree().root.get_viewport_rid()). Both of these calls should be performed in _process() to reflect the last frame's rendering as closely as possible.

Testing project: test_measure_render_time.zip

@lemtea8
Copy link
Author

lemtea8 commented Mar 27, 2023

Thanks! Adding this option to project settings would be wonderful.

Also I think this is worth documenting, as https://docs.godotengine.org/en/stable/classes/class_renderingserver.html#class-renderingserver-method-viewport-get-measured-render-time-cpu didn't have a description yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants