A demo showing an example of graphics benchmark using GDScript.
The objective is to set the user's graphic settings automatically, using the most compatible graphic settings the user can render at the threshold FPS.
The project flow goes as follows:
- The game starts.
- A "Benchmark" scene is instanced.
- The
benchmark()
function is called. Thebenchmark()
first disables the main viewport (to avoid noise in the render timestamp of the benchmark), and test eachGraphicSettings
resource set at the "Benchmark" scene sequentially (those are theGraphicSettings
it may return). For eachGraphicSettings
to test:- The
GraphicSettings
is applied to the benchmark viewport. - A timestamp is created with
capture_timestamp("timestamp")
RenderingServer.force_draw()
is called.- On the next frame, the timestamp difference is captured with
rendering_device.get_captured_timestamp_gpu_time(0)
. - If the render duration is bigger than a threshold, skips the rest of the test (user hardware is too slow for the Graphic settings, so there is no need to test further). Else, store the duration and test X more times, storing the average render frame time.
- The
benchmark()
stores the benchmark results for the different settings inbenchmark_results
.- The optimal
GraphicSettings
is applied to the root viewport.