Merge pull request #85885 from YuriSizov/bench-pressing

Improve engine startup/shutdown benchmarks
This commit is contained in:
Yuri Sizov 2023-12-08 17:12:26 +01:00
commit 07677f0f51
19 changed files with 466 additions and 291 deletions

View File

@ -626,17 +626,22 @@ String OS::get_benchmark_file() {
return benchmark_file; return benchmark_file;
} }
void OS::benchmark_begin_measure(const String &p_what) { void OS::benchmark_begin_measure(const String &p_context, const String &p_what) {
#ifdef TOOLS_ENABLED #ifdef TOOLS_ENABLED
start_benchmark_from[p_what] = OS::get_singleton()->get_ticks_usec(); Pair<String, String> mark_key(p_context, p_what);
ERR_FAIL_COND_MSG(benchmark_marks_from.has(mark_key), vformat("Benchmark key '%s:%s' already exists.", p_context, p_what));
benchmark_marks_from[mark_key] = OS::get_singleton()->get_ticks_usec();
#endif #endif
} }
void OS::benchmark_end_measure(const String &p_what) { void OS::benchmark_end_measure(const String &p_context, const String &p_what) {
#ifdef TOOLS_ENABLED #ifdef TOOLS_ENABLED
uint64_t total = OS::get_singleton()->get_ticks_usec() - start_benchmark_from[p_what]; Pair<String, String> mark_key(p_context, p_what);
double total_f = double(total) / double(1000000); ERR_FAIL_COND_MSG(!benchmark_marks_from.has(mark_key), vformat("Benchmark key '%s:%s' doesn't exist.", p_context, p_what));
startup_benchmark_json[p_what] = total_f; uint64_t total = OS::get_singleton()->get_ticks_usec() - benchmark_marks_from[mark_key];
double total_f = double(total) / double(1000000);
benchmark_marks_final[mark_key] = total_f;
#endif #endif
} }
@ -645,19 +650,33 @@ void OS::benchmark_dump() {
if (!use_benchmark) { if (!use_benchmark) {
return; return;
} }
if (!benchmark_file.is_empty()) { if (!benchmark_file.is_empty()) {
Ref<FileAccess> f = FileAccess::open(benchmark_file, FileAccess::WRITE); Ref<FileAccess> f = FileAccess::open(benchmark_file, FileAccess::WRITE);
if (f.is_valid()) { if (f.is_valid()) {
Dictionary benchmark_marks;
for (const KeyValue<Pair<String, String>, double> &E : benchmark_marks_final) {
const String mark_key = vformat("[%s] %s", E.key.first, E.key.second);
benchmark_marks[mark_key] = E.value;
}
Ref<JSON> json; Ref<JSON> json;
json.instantiate(); json.instantiate();
f->store_string(json->stringify(startup_benchmark_json, "\t", false, true)); f->store_string(json->stringify(benchmark_marks, "\t", false, true));
} }
} else { } else {
List<Variant> keys; HashMap<String, String> results;
startup_benchmark_json.get_key_list(&keys); for (const KeyValue<Pair<String, String>, double> &E : benchmark_marks_final) {
if (E.key.first == "Startup" && !results.has(E.key.first)) {
results.insert(E.key.first, "", true); // Hack to make sure "Startup" always comes first.
}
results[E.key.first] += vformat("\t\t- %s: %.3f msec.\n", E.key.second, (E.value * 1000));
}
print_line("BENCHMARK:"); print_line("BENCHMARK:");
for (const Variant &K : keys) { for (const KeyValue<String, String> &E : results) {
print_line("\t-", K, ": ", startup_benchmark_json[K], +" sec."); print_line(vformat("\t[%s]\n%s", E.key, E.value));
} }
} }
#endif #endif

View File

@ -79,8 +79,8 @@ class OS {
// For tracking benchmark data // For tracking benchmark data
bool use_benchmark = false; bool use_benchmark = false;
String benchmark_file; String benchmark_file;
HashMap<String, uint64_t> start_benchmark_from; HashMap<Pair<String, String>, uint64_t, PairHash<String, String>> benchmark_marks_from;
Dictionary startup_benchmark_json; HashMap<Pair<String, String>, double, PairHash<String, String>> benchmark_marks_final;
protected: protected:
void _set_logger(CompositeLogger *p_logger); void _set_logger(CompositeLogger *p_logger);
@ -313,8 +313,8 @@ public:
bool is_use_benchmark_set(); bool is_use_benchmark_set();
void set_benchmark_file(const String &p_benchmark_file); void set_benchmark_file(const String &p_benchmark_file);
String get_benchmark_file(); String get_benchmark_file();
virtual void benchmark_begin_measure(const String &p_what); virtual void benchmark_begin_measure(const String &p_context, const String &p_what);
virtual void benchmark_end_measure(const String &p_what); virtual void benchmark_end_measure(const String &p_context, const String &p_what);
virtual void benchmark_dump(); virtual void benchmark_dump();
virtual void process_and_drop_events() {} virtual void process_and_drop_events() {}

View File

@ -120,7 +120,8 @@ static ResourceUID *resource_uid = nullptr;
static bool _is_core_extensions_registered = false; static bool _is_core_extensions_registered = false;
void register_core_types() { void register_core_types() {
OS::get_singleton()->benchmark_begin_measure("register_core_types"); OS::get_singleton()->benchmark_begin_measure("Core", "Register Types");
//consistency check //consistency check
static_assert(sizeof(Callable) <= 16); static_assert(sizeof(Callable) <= 16);
@ -296,7 +297,7 @@ void register_core_types() {
worker_thread_pool = memnew(WorkerThreadPool); worker_thread_pool = memnew(WorkerThreadPool);
OS::get_singleton()->benchmark_end_measure("register_core_types"); OS::get_singleton()->benchmark_end_measure("Core", "Register Types");
} }
void register_core_settings() { void register_core_settings() {
@ -311,6 +312,8 @@ void register_core_settings() {
} }
void register_core_singletons() { void register_core_singletons() {
OS::get_singleton()->benchmark_begin_measure("Core", "Register Singletons");
GDREGISTER_CLASS(ProjectSettings); GDREGISTER_CLASS(ProjectSettings);
GDREGISTER_ABSTRACT_CLASS(IP); GDREGISTER_ABSTRACT_CLASS(IP);
GDREGISTER_CLASS(core_bind::Geometry2D); GDREGISTER_CLASS(core_bind::Geometry2D);
@ -346,25 +349,35 @@ void register_core_singletons() {
Engine::get_singleton()->add_singleton(Engine::Singleton("GDExtensionManager", GDExtensionManager::get_singleton())); Engine::get_singleton()->add_singleton(Engine::Singleton("GDExtensionManager", GDExtensionManager::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("ResourceUID", ResourceUID::get_singleton())); Engine::get_singleton()->add_singleton(Engine::Singleton("ResourceUID", ResourceUID::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("WorkerThreadPool", worker_thread_pool)); Engine::get_singleton()->add_singleton(Engine::Singleton("WorkerThreadPool", worker_thread_pool));
OS::get_singleton()->benchmark_end_measure("Core", "Register Singletons");
} }
void register_core_extensions() { void register_core_extensions() {
OS::get_singleton()->benchmark_begin_measure("Core", "Register Extensions");
// Hardcoded for now. // Hardcoded for now.
GDExtension::initialize_gdextensions(); GDExtension::initialize_gdextensions();
gdextension_manager->load_extensions(); gdextension_manager->load_extensions();
gdextension_manager->initialize_extensions(GDExtension::INITIALIZATION_LEVEL_CORE); gdextension_manager->initialize_extensions(GDExtension::INITIALIZATION_LEVEL_CORE);
_is_core_extensions_registered = true; _is_core_extensions_registered = true;
OS::get_singleton()->benchmark_end_measure("Core", "Register Extensions");
} }
void unregister_core_extensions() { void unregister_core_extensions() {
OS::get_singleton()->benchmark_begin_measure("Core", "Unregister Extensions");
if (_is_core_extensions_registered) { if (_is_core_extensions_registered) {
gdextension_manager->deinitialize_extensions(GDExtension::INITIALIZATION_LEVEL_CORE); gdextension_manager->deinitialize_extensions(GDExtension::INITIALIZATION_LEVEL_CORE);
} }
GDExtension::finalize_gdextensions(); GDExtension::finalize_gdextensions();
OS::get_singleton()->benchmark_end_measure("Core", "Unregister Extensions");
} }
void unregister_core_types() { void unregister_core_types() {
OS::get_singleton()->benchmark_begin_measure("unregister_core_types"); OS::get_singleton()->benchmark_begin_measure("Core", "Unregister Types");
// Destroy singletons in reverse order to ensure dependencies are not broken. // Destroy singletons in reverse order to ensure dependencies are not broken.
@ -435,5 +448,5 @@ void unregister_core_types() {
CoreStringNames::free(); CoreStringNames::free();
StringName::cleanup(); StringName::cleanup();
OS::get_singleton()->benchmark_end_measure("unregister_core_types"); OS::get_singleton()->benchmark_end_measure("Core", "Unregister Types");
} }

View File

@ -107,7 +107,7 @@ Ref<FontVariation> make_bold_font(const Ref<Font> &p_font, double p_embolden, Ty
} }
void editor_register_fonts(Ref<Theme> p_theme) { void editor_register_fonts(Ref<Theme> p_theme) {
OS::get_singleton()->benchmark_begin_measure("editor_register_fonts"); OS::get_singleton()->benchmark_begin_measure("EditorTheme", "Register Fonts");
Ref<DirAccess> dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); Ref<DirAccess> dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
TextServer::FontAntialiasing font_antialiasing = (TextServer::FontAntialiasing)(int)EDITOR_GET("interface/editor/font_antialiasing"); TextServer::FontAntialiasing font_antialiasing = (TextServer::FontAntialiasing)(int)EDITOR_GET("interface/editor/font_antialiasing");
@ -445,5 +445,5 @@ void editor_register_fonts(Ref<Theme> p_theme) {
p_theme->set_font_size("status_source_size", EditorStringName(EditorFonts), default_font_size); p_theme->set_font_size("status_source_size", EditorStringName(EditorFonts), default_font_size);
p_theme->set_font("status_source", EditorStringName(EditorFonts), mono_other_fc); p_theme->set_font("status_source", EditorStringName(EditorFonts), mono_other_fc);
OS::get_singleton()->benchmark_end_measure("editor_register_fonts"); OS::get_singleton()->benchmark_end_measure("EditorTheme", "Register Fonts");
} }

View File

@ -2360,6 +2360,7 @@ void EditorHelp::_add_text(const String &p_bbcode) {
_add_text_to_rt(p_bbcode, class_desc, this, edited_class); _add_text_to_rt(p_bbcode, class_desc, this, edited_class);
} }
int EditorHelp::doc_generation_count = 0;
String EditorHelp::doc_version_hash; String EditorHelp::doc_version_hash;
Thread EditorHelp::worker_thread; Thread EditorHelp::worker_thread;
@ -2392,6 +2393,8 @@ void EditorHelp::_load_doc_thread(void *p_udata) {
// We have to go back to the main thread to start from scratch, bypassing any possibly existing cache. // We have to go back to the main thread to start from scratch, bypassing any possibly existing cache.
callable_mp_static(&EditorHelp::generate_doc).bind(false).call_deferred(); callable_mp_static(&EditorHelp::generate_doc).bind(false).call_deferred();
} }
OS::get_singleton()->benchmark_end_measure("EditorHelp", vformat("Generate Documentation (Run %d)", doc_generation_count));
} }
void EditorHelp::_gen_doc_thread(void *p_udata) { void EditorHelp::_gen_doc_thread(void *p_udata) {
@ -2417,6 +2420,8 @@ void EditorHelp::_gen_doc_thread(void *p_udata) {
if (err) { if (err) {
ERR_PRINT("Cannot save editor help cache (" + get_cache_full_path() + ")."); ERR_PRINT("Cannot save editor help cache (" + get_cache_full_path() + ").");
} }
OS::get_singleton()->benchmark_end_measure("EditorHelp", vformat("Generate Documentation (Run %d)", doc_generation_count));
} }
void EditorHelp::_gen_extensions_docs() { void EditorHelp::_gen_extensions_docs() {
@ -2424,7 +2429,8 @@ void EditorHelp::_gen_extensions_docs() {
} }
void EditorHelp::generate_doc(bool p_use_cache) { void EditorHelp::generate_doc(bool p_use_cache) {
OS::get_singleton()->benchmark_begin_measure("EditorHelp::generate_doc"); doc_generation_count++;
OS::get_singleton()->benchmark_begin_measure("EditorHelp", vformat("Generate Documentation (Run %d)", doc_generation_count));
// In case not the first attempt. // In case not the first attempt.
_wait_for_thread(); _wait_for_thread();
@ -2444,8 +2450,6 @@ void EditorHelp::generate_doc(bool p_use_cache) {
doc->generate(); doc->generate();
worker_thread.start(_gen_doc_thread, nullptr); worker_thread.start(_gen_doc_thread, nullptr);
} }
OS::get_singleton()->benchmark_end_measure("EditorHelp::generate_doc");
} }
void EditorHelp::_toggle_scripts_pressed() { void EditorHelp::_toggle_scripts_pressed() {

View File

@ -187,6 +187,7 @@ class EditorHelp : public VBoxContainer {
String _fix_constant(const String &p_constant) const; String _fix_constant(const String &p_constant) const;
void _toggle_scripts_pressed(); void _toggle_scripts_pressed();
static int doc_generation_count;
static String doc_version_hash; static String doc_version_hash;
static Thread worker_thread; static Thread worker_thread;

View File

@ -627,7 +627,7 @@ void EditorNode::_notification(int p_what) {
if (requested_first_scan) { if (requested_first_scan) {
requested_first_scan = false; requested_first_scan = false;
OS::get_singleton()->benchmark_begin_measure("editor_scan_and_import"); OS::get_singleton()->benchmark_begin_measure("Editor", "First Scan");
if (run_surface_upgrade_tool) { if (run_surface_upgrade_tool) {
run_surface_upgrade_tool = false; run_surface_upgrade_tool = false;
@ -1044,7 +1044,7 @@ void EditorNode::_sources_changed(bool p_exist) {
if (waiting_for_first_scan) { if (waiting_for_first_scan) {
waiting_for_first_scan = false; waiting_for_first_scan = false;
OS::get_singleton()->benchmark_end_measure("editor_scan_and_import"); OS::get_singleton()->benchmark_end_measure("Editor", "First Scan");
// Reload the global shader variables, but this time // Reload the global shader variables, but this time
// loading textures, as they are now properly imported. // loading textures, as they are now properly imported.
@ -1053,11 +1053,12 @@ void EditorNode::_sources_changed(bool p_exist) {
_load_editor_layout(); _load_editor_layout();
if (!defer_load_scene.is_empty()) { if (!defer_load_scene.is_empty()) {
OS::get_singleton()->benchmark_begin_measure("editor_load_scene"); OS::get_singleton()->benchmark_begin_measure("Editor", "Load Scene");
load_scene(defer_load_scene); load_scene(defer_load_scene);
defer_load_scene = ""; defer_load_scene = "";
OS::get_singleton()->benchmark_end_measure("editor_load_scene");
OS::get_singleton()->benchmark_end_measure("Editor", "Load Scene");
OS::get_singleton()->benchmark_dump(); OS::get_singleton()->benchmark_dump();
} }
@ -4668,7 +4669,7 @@ void EditorNode::_begin_first_scan() {
// In headless mode, scan right away. // In headless mode, scan right away.
// This allows users to continue using `godot --headless --editor --quit` to prepare a project. // This allows users to continue using `godot --headless --editor --quit` to prepare a project.
if (!DisplayServer::get_singleton()->window_can_draw()) { if (!DisplayServer::get_singleton()->window_can_draw()) {
OS::get_singleton()->benchmark_begin_measure("editor_scan_and_import"); OS::get_singleton()->benchmark_begin_measure("Editor", "First Scan");
EditorFileSystem::get_singleton()->scan(); EditorFileSystem::get_singleton()->scan();
return; return;
} }

View File

@ -403,7 +403,9 @@ float get_gizmo_handle_scale(const String &gizmo_handle_name = "") {
} }
void editor_register_and_generate_icons(Ref<Theme> p_theme, bool p_dark_theme, float p_icon_saturation, int p_thumb_size, bool p_only_thumbs = false) { void editor_register_and_generate_icons(Ref<Theme> p_theme, bool p_dark_theme, float p_icon_saturation, int p_thumb_size, bool p_only_thumbs = false) {
OS::get_singleton()->benchmark_begin_measure("editor_register_and_generate_icons_" + String((p_only_thumbs ? "with_only_thumbs" : "all"))); const String benchmark_key = vformat("Generate Icons (%s)", (p_only_thumbs ? "Only Thumbs" : "All"));
OS::get_singleton()->benchmark_begin_measure("EditorTheme", benchmark_key);
// Before we register the icons, we adjust their colors and saturation. // Before we register the icons, we adjust their colors and saturation.
// Most icons follow the standard rules for color conversion to follow the editor // Most icons follow the standard rules for color conversion to follow the editor
// theme's polarity (dark/light). We also adjust the saturation for most icons, // theme's polarity (dark/light). We also adjust the saturation for most icons,
@ -531,11 +533,11 @@ void editor_register_and_generate_icons(Ref<Theme> p_theme, bool p_dark_theme, f
p_theme->set_icon(editor_icons_names[index], EditorStringName(EditorIcons), icon); p_theme->set_icon(editor_icons_names[index], EditorStringName(EditorIcons), icon);
} }
} }
OS::get_singleton()->benchmark_end_measure("editor_register_and_generate_icons_" + String((p_only_thumbs ? "with_only_thumbs" : "all"))); OS::get_singleton()->benchmark_end_measure("EditorTheme", benchmark_key);
} }
Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
OS::get_singleton()->benchmark_begin_measure("create_editor_theme"); OS::get_singleton()->benchmark_begin_measure("EditorTheme", "Create Editor Theme");
Ref<EditorTheme> theme = memnew(EditorTheme); Ref<EditorTheme> theme = memnew(EditorTheme);
// Controls may rely on the scale for their internal drawing logic. // Controls may rely on the scale for their internal drawing logic.
@ -2360,15 +2362,16 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {
theme->set_color("search_result_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/search_result_color")); theme->set_color("search_result_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/search_result_color"));
theme->set_color("search_result_border_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/search_result_border_color")); theme->set_color("search_result_border_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/search_result_border_color"));
OS::get_singleton()->benchmark_end_measure("create_editor_theme"); OS::get_singleton()->benchmark_end_measure("EditorTheme", "Create Editor Theme");
return theme; return theme;
} }
Ref<Theme> create_custom_theme(const Ref<Theme> p_theme) { Ref<Theme> create_custom_theme(const Ref<Theme> p_theme) {
OS::get_singleton()->benchmark_begin_measure("create_custom_theme");
Ref<Theme> theme = create_editor_theme(p_theme); Ref<Theme> theme = create_editor_theme(p_theme);
OS::get_singleton()->benchmark_begin_measure("EditorTheme", "Create Custom Theme");
const String custom_theme_path = EDITOR_GET("interface/theme/custom_theme"); const String custom_theme_path = EDITOR_GET("interface/theme/custom_theme");
if (!custom_theme_path.is_empty()) { if (!custom_theme_path.is_empty()) {
Ref<Theme> custom_theme = ResourceLoader::load(custom_theme_path); Ref<Theme> custom_theme = ResourceLoader::load(custom_theme_path);
@ -2377,7 +2380,7 @@ Ref<Theme> create_custom_theme(const Ref<Theme> p_theme) {
} }
} }
OS::get_singleton()->benchmark_end_measure("create_custom_theme"); OS::get_singleton()->benchmark_end_measure("EditorTheme", "Create Custom Theme");
return theme; return theme;
} }

View File

@ -129,7 +129,7 @@
#include "editor/register_exporters.h" #include "editor/register_exporters.h"
void register_editor_types() { void register_editor_types() {
OS::get_singleton()->benchmark_begin_measure("register_editor_types"); OS::get_singleton()->benchmark_begin_measure("Editor", "Register Types");
ResourceLoader::set_timestamp_on_load(true); ResourceLoader::set_timestamp_on_load(true);
ResourceSaver::set_timestamp_on_save(true); ResourceSaver::set_timestamp_on_save(true);
@ -282,11 +282,11 @@ void register_editor_types() {
ei_singleton.editor_only = true; ei_singleton.editor_only = true;
Engine::get_singleton()->add_singleton(ei_singleton); Engine::get_singleton()->add_singleton(ei_singleton);
OS::get_singleton()->benchmark_end_measure("register_editor_types"); OS::get_singleton()->benchmark_end_measure("Editor", "Register Types");
} }
void unregister_editor_types() { void unregister_editor_types() {
OS::get_singleton()->benchmark_begin_measure("unregister_editor_types"); OS::get_singleton()->benchmark_begin_measure("Editor", "Unregister Types");
EditorNode::cleanup(); EditorNode::cleanup();
EditorInterface::free(); EditorInterface::free();
@ -296,5 +296,5 @@ void unregister_editor_types() {
} }
EditorStringNames::free(); EditorStringNames::free();
OS::get_singleton()->benchmark_end_measure("unregister_editor_types"); OS::get_singleton()->benchmark_end_measure("Editor", "Unregister Types");
} }

View File

@ -766,12 +766,13 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
// Benchmark tracking must be done after `OS::get_singleton()->initialize()` as on some // Benchmark tracking must be done after `OS::get_singleton()->initialize()` as on some
// platforms, it's used to set up the time utilities. // platforms, it's used to set up the time utilities.
OS::get_singleton()->benchmark_begin_measure("startup_begin"); OS::get_singleton()->benchmark_begin_measure("Startup", "Total");
OS::get_singleton()->benchmark_begin_measure("Startup", "Setup");
engine = memnew(Engine); engine = memnew(Engine);
MAIN_PRINT("Main: Initialize CORE"); MAIN_PRINT("Main: Initialize CORE");
OS::get_singleton()->benchmark_begin_measure("core"); OS::get_singleton()->benchmark_begin_measure("Startup", "Core");
register_core_types(); register_core_types();
register_core_driver_types(); register_core_driver_types();
@ -2180,11 +2181,13 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
Thread::release_main_thread(); // If setup2() is called from another thread, that one will become main thread, so preventively release this one. Thread::release_main_thread(); // If setup2() is called from another thread, that one will become main thread, so preventively release this one.
set_current_thread_safe_for_nodes(false); set_current_thread_safe_for_nodes(false);
OS::get_singleton()->benchmark_end_measure("Startup", "Core");
if (p_second_phase) { if (p_second_phase) {
return setup2(); return setup2();
} }
OS::get_singleton()->benchmark_end_measure("core"); OS::get_singleton()->benchmark_end_measure("Startup", "Setup");
return OK; return OK;
error: error:
@ -2238,7 +2241,8 @@ error:
memdelete(message_queue); memdelete(message_queue);
} }
OS::get_singleton()->benchmark_end_measure("core"); OS::get_singleton()->benchmark_end_measure("Startup", "Core");
OS::get_singleton()->benchmark_end_measure("Startup", "Setup");
OS::get_singleton()->finalize_core(); OS::get_singleton()->finalize_core();
locale = String(); locale = String();
@ -2272,25 +2276,10 @@ Error Main::setup2() {
// Print engine name and version // Print engine name and version
print_line(String(VERSION_NAME) + " v" + get_full_version_string() + " - " + String(VERSION_WEBSITE)); print_line(String(VERSION_NAME) + " v" + get_full_version_string() + " - " + String(VERSION_WEBSITE));
OS::get_singleton()->benchmark_begin_measure("servers");
tsman = memnew(TextServerManager);
if (tsman) {
Ref<TextServerDummy> ts;
ts.instantiate();
tsman->add_interface(ts);
}
physics_server_3d_manager = memnew(PhysicsServer3DManager);
physics_server_2d_manager = memnew(PhysicsServer2DManager);
register_server_types();
initialize_modules(MODULE_INITIALIZATION_LEVEL_SERVERS);
GDExtensionManager::get_singleton()->initialize_extensions(GDExtension::INITIALIZATION_LEVEL_SERVERS);
#ifdef TOOLS_ENABLED #ifdef TOOLS_ENABLED
if (editor || project_manager || cmdline_tool) { if (editor || project_manager || cmdline_tool) {
OS::get_singleton()->benchmark_begin_measure("Startup", "Initialize Early Settings");
EditorPaths::create(); EditorPaths::create();
// Editor setting class is not available, load config directly. // Editor setting class is not available, load config directly.
@ -2352,16 +2341,49 @@ Error Main::setup2() {
return FAILED; return FAILED;
} }
} }
OS::get_singleton()->benchmark_end_measure("Startup", "Initialize Early Settings");
} }
#endif #endif
OS::get_singleton()->benchmark_begin_measure("Startup", "Servers");
tsman = memnew(TextServerManager);
if (tsman) {
Ref<TextServerDummy> ts;
ts.instantiate();
tsman->add_interface(ts);
}
physics_server_3d_manager = memnew(PhysicsServer3DManager);
physics_server_2d_manager = memnew(PhysicsServer2DManager);
register_server_types();
{
OS::get_singleton()->benchmark_begin_measure("Servers", "Modules and Extensions");
initialize_modules(MODULE_INITIALIZATION_LEVEL_SERVERS);
GDExtensionManager::get_singleton()->initialize_extensions(GDExtension::INITIALIZATION_LEVEL_SERVERS);
OS::get_singleton()->benchmark_end_measure("Servers", "Modules and Extensions");
}
/* Initialize Input */ /* Initialize Input */
input = memnew(Input); {
OS::get_singleton()->benchmark_begin_measure("Servers", "Input");
input = memnew(Input);
OS::get_singleton()->initialize_joypads();
OS::get_singleton()->benchmark_end_measure("Servers", "Input");
}
/* Initialize Display Server */ /* Initialize Display Server */
{ {
OS::get_singleton()->benchmark_begin_measure("Servers", "Display");
String display_driver = DisplayServer::get_create_function_name(display_driver_idx); String display_driver = DisplayServer::get_create_function_name(display_driver_idx);
Vector2i *window_position = nullptr; Vector2i *window_position = nullptr;
@ -2395,10 +2417,12 @@ Error Main::setup2() {
ERR_PRINT("Unable to create DisplayServer, all display drivers failed."); ERR_PRINT("Unable to create DisplayServer, all display drivers failed.");
return err; return err;
} }
}
if (display_server->has_feature(DisplayServer::FEATURE_ORIENTATION)) { if (display_server->has_feature(DisplayServer::FEATURE_ORIENTATION)) {
display_server->screen_set_orientation(window_orientation); display_server->screen_set_orientation(window_orientation);
}
OS::get_singleton()->benchmark_end_measure("Servers", "Display");
} }
if (GLOBAL_GET("debug/settings/stdout/print_fps") || print_fps) { if (GLOBAL_GET("debug/settings/stdout/print_fps") || print_fps) {
@ -2426,48 +2450,58 @@ Error Main::setup2() {
/* Initialize Pen Tablet Driver */ /* Initialize Pen Tablet Driver */
{ {
OS::get_singleton()->benchmark_begin_measure("Servers", "Tablet Driver");
GLOBAL_DEF_RST_NOVAL("input_devices/pen_tablet/driver", ""); GLOBAL_DEF_RST_NOVAL("input_devices/pen_tablet/driver", "");
GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "input_devices/pen_tablet/driver.windows", PROPERTY_HINT_ENUM, "wintab,winink"), ""); GLOBAL_DEF_RST_NOVAL(PropertyInfo(Variant::STRING, "input_devices/pen_tablet/driver.windows", PROPERTY_HINT_ENUM, "wintab,winink"), "");
}
if (tablet_driver.is_empty()) { // specified in project.godot if (tablet_driver.is_empty()) { // specified in project.godot
tablet_driver = GLOBAL_GET("input_devices/pen_tablet/driver"); tablet_driver = GLOBAL_GET("input_devices/pen_tablet/driver");
if (tablet_driver.is_empty()) { if (tablet_driver.is_empty()) {
tablet_driver = DisplayServer::get_singleton()->tablet_get_driver_name(0); tablet_driver = DisplayServer::get_singleton()->tablet_get_driver_name(0);
}
} }
}
for (int i = 0; i < DisplayServer::get_singleton()->tablet_get_driver_count(); i++) { for (int i = 0; i < DisplayServer::get_singleton()->tablet_get_driver_count(); i++) {
if (tablet_driver == DisplayServer::get_singleton()->tablet_get_driver_name(i)) { if (tablet_driver == DisplayServer::get_singleton()->tablet_get_driver_name(i)) {
DisplayServer::get_singleton()->tablet_set_current_driver(DisplayServer::get_singleton()->tablet_get_driver_name(i)); DisplayServer::get_singleton()->tablet_set_current_driver(DisplayServer::get_singleton()->tablet_get_driver_name(i));
break; break;
}
} }
}
if (DisplayServer::get_singleton()->tablet_get_current_driver().is_empty()) { if (DisplayServer::get_singleton()->tablet_get_current_driver().is_empty()) {
DisplayServer::get_singleton()->tablet_set_current_driver(DisplayServer::get_singleton()->tablet_get_driver_name(0)); DisplayServer::get_singleton()->tablet_set_current_driver(DisplayServer::get_singleton()->tablet_get_driver_name(0));
} }
print_verbose("Using \"" + tablet_driver + "\" pen tablet driver..."); print_verbose("Using \"" + tablet_driver + "\" pen tablet driver...");
OS::get_singleton()->benchmark_end_measure("Servers", "Tablet Driver");
}
/* Initialize Rendering Server */ /* Initialize Rendering Server */
rendering_server = memnew(RenderingServerDefault(OS::get_singleton()->get_render_thread_mode() == OS::RENDER_SEPARATE_THREAD)); {
OS::get_singleton()->benchmark_begin_measure("Servers", "Rendering");
rendering_server->init(); rendering_server = memnew(RenderingServerDefault(OS::get_singleton()->get_render_thread_mode() == OS::RENDER_SEPARATE_THREAD));
//rendering_server->call_set_use_vsync(OS::get_singleton()->_use_vsync);
rendering_server->set_render_loop_enabled(!disable_render_loop);
if (profile_gpu || (!editor && bool(GLOBAL_GET("debug/settings/stdout/print_gpu_profile")))) { rendering_server->init();
rendering_server->set_print_gpu_profile(true); //rendering_server->call_set_use_vsync(OS::get_singleton()->_use_vsync);
} rendering_server->set_render_loop_enabled(!disable_render_loop);
if (Engine::get_singleton()->get_write_movie_path() != String()) { if (profile_gpu || (!editor && bool(GLOBAL_GET("debug/settings/stdout/print_gpu_profile")))) {
movie_writer = MovieWriter::find_writer_for_file(Engine::get_singleton()->get_write_movie_path()); rendering_server->set_print_gpu_profile(true);
if (movie_writer == nullptr) {
ERR_PRINT("Can't find movie writer for file type, aborting: " + Engine::get_singleton()->get_write_movie_path());
Engine::get_singleton()->set_write_movie_path(String());
} }
if (Engine::get_singleton()->get_write_movie_path() != String()) {
movie_writer = MovieWriter::find_writer_for_file(Engine::get_singleton()->get_write_movie_path());
if (movie_writer == nullptr) {
ERR_PRINT("Can't find movie writer for file type, aborting: " + Engine::get_singleton()->get_write_movie_path());
Engine::get_singleton()->set_write_movie_path(String());
}
}
OS::get_singleton()->benchmark_end_measure("Servers", "Rendering");
} }
#ifdef UNIX_ENABLED #ifdef UNIX_ENABLED
@ -2477,210 +2511,246 @@ Error Main::setup2() {
} }
#endif #endif
OS::get_singleton()->initialize_joypads();
/* Initialize Audio Driver */ /* Initialize Audio Driver */
AudioDriverManager::initialize(audio_driver_idx); {
OS::get_singleton()->benchmark_begin_measure("Servers", "Audio");
print_line(" "); //add a blank line for readability AudioDriverManager::initialize(audio_driver_idx);
// right moment to create and initialize the audio server print_line(" "); // Add a blank line for readability.
audio_server = memnew(AudioServer); // Right moment to create and initialize the audio server.
audio_server->init(); audio_server = memnew(AudioServer);
audio_server->init();
// also init our xr_server from here OS::get_singleton()->benchmark_end_measure("Servers", "Audio");
xr_server = memnew(XRServer); }
/* Initialize XR Server */
{
OS::get_singleton()->benchmark_begin_measure("Servers", "XR");
xr_server = memnew(XRServer);
OS::get_singleton()->benchmark_end_measure("Servers", "XR");
}
OS::get_singleton()->benchmark_end_measure("Startup", "Servers");
register_core_singletons(); register_core_singletons();
MAIN_PRINT("Main: Setup Logo"); /* Initialize the main window and boot screen */
{
OS::get_singleton()->benchmark_begin_measure("Startup", "Setup Window and Boot");
MAIN_PRINT("Main: Setup Logo");
#if !defined(TOOLS_ENABLED) && (defined(WEB_ENABLED) || defined(ANDROID_ENABLED)) #if !defined(TOOLS_ENABLED) && (defined(WEB_ENABLED) || defined(ANDROID_ENABLED))
bool show_logo = false; bool show_logo = false;
#else #else
bool show_logo = true; bool show_logo = true;
#endif #endif
if (init_windowed) { if (init_windowed) {
//do none.. //do none..
} else if (init_maximized) { } else if (init_maximized) {
DisplayServer::get_singleton()->window_set_mode(DisplayServer::WINDOW_MODE_MAXIMIZED); DisplayServer::get_singleton()->window_set_mode(DisplayServer::WINDOW_MODE_MAXIMIZED);
} else if (init_fullscreen) { } else if (init_fullscreen) {
DisplayServer::get_singleton()->window_set_mode(DisplayServer::WINDOW_MODE_FULLSCREEN); DisplayServer::get_singleton()->window_set_mode(DisplayServer::WINDOW_MODE_FULLSCREEN);
} }
if (init_always_on_top) { if (init_always_on_top) {
DisplayServer::get_singleton()->window_set_flag(DisplayServer::WINDOW_FLAG_ALWAYS_ON_TOP, true); DisplayServer::get_singleton()->window_set_flag(DisplayServer::WINDOW_FLAG_ALWAYS_ON_TOP, true);
} }
MAIN_PRINT("Main: Load Boot Image"); MAIN_PRINT("Main: Load Boot Image");
Color clear = GLOBAL_DEF_BASIC("rendering/environment/defaults/default_clear_color", Color(0.3, 0.3, 0.3)); Color clear = GLOBAL_DEF_BASIC("rendering/environment/defaults/default_clear_color", Color(0.3, 0.3, 0.3));
RenderingServer::get_singleton()->set_default_clear_color(clear); RenderingServer::get_singleton()->set_default_clear_color(clear);
if (show_logo) { //boot logo! if (show_logo) { //boot logo!
const bool boot_logo_image = GLOBAL_DEF_BASIC("application/boot_splash/show_image", true); const bool boot_logo_image = GLOBAL_DEF_BASIC("application/boot_splash/show_image", true);
const String boot_logo_path = String(GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "application/boot_splash/image", PROPERTY_HINT_FILE, "*.png"), String())).strip_edges(); const String boot_logo_path = String(GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "application/boot_splash/image", PROPERTY_HINT_FILE, "*.png"), String())).strip_edges();
const bool boot_logo_scale = GLOBAL_DEF_BASIC("application/boot_splash/fullsize", true); const bool boot_logo_scale = GLOBAL_DEF_BASIC("application/boot_splash/fullsize", true);
const bool boot_logo_filter = GLOBAL_DEF_BASIC("application/boot_splash/use_filter", true); const bool boot_logo_filter = GLOBAL_DEF_BASIC("application/boot_splash/use_filter", true);
Ref<Image> boot_logo; Ref<Image> boot_logo;
if (boot_logo_image) { if (boot_logo_image) {
if (!boot_logo_path.is_empty()) { if (!boot_logo_path.is_empty()) {
boot_logo.instantiate(); boot_logo.instantiate();
Error load_err = ImageLoader::load_image(boot_logo_path, boot_logo); Error load_err = ImageLoader::load_image(boot_logo_path, boot_logo);
if (load_err) { if (load_err) {
ERR_PRINT("Non-existing or invalid boot splash at '" + boot_logo_path + "'. Loading default splash."); ERR_PRINT("Non-existing or invalid boot splash at '" + boot_logo_path + "'. Loading default splash.");
}
} }
} else {
// Create a 1×1 transparent image. This will effectively hide the splash image.
boot_logo.instantiate();
boot_logo->initialize_data(1, 1, false, Image::FORMAT_RGBA8);
boot_logo->set_pixel(0, 0, Color(0, 0, 0, 0));
} }
} else {
// Create a 1×1 transparent image. This will effectively hide the splash image.
boot_logo.instantiate();
boot_logo->initialize_data(1, 1, false, Image::FORMAT_RGBA8);
boot_logo->set_pixel(0, 0, Color(0, 0, 0, 0));
}
Color boot_bg_color = GLOBAL_GET("application/boot_splash/bg_color"); Color boot_bg_color = GLOBAL_GET("application/boot_splash/bg_color");
#if defined(TOOLS_ENABLED) && !defined(NO_EDITOR_SPLASH) #if defined(TOOLS_ENABLED) && !defined(NO_EDITOR_SPLASH)
boot_bg_color = boot_bg_color =
GLOBAL_DEF_BASIC("application/boot_splash/bg_color", GLOBAL_DEF_BASIC("application/boot_splash/bg_color",
(editor || project_manager) ? boot_splash_editor_bg_color : boot_splash_bg_color); (editor || project_manager) ? boot_splash_editor_bg_color : boot_splash_bg_color);
#endif #endif
if (boot_logo.is_valid()) { if (boot_logo.is_valid()) {
RenderingServer::get_singleton()->set_boot_image(boot_logo, boot_bg_color, boot_logo_scale, RenderingServer::get_singleton()->set_boot_image(boot_logo, boot_bg_color, boot_logo_scale,
boot_logo_filter); boot_logo_filter);
} else { } else {
#ifndef NO_DEFAULT_BOOT_LOGO #ifndef NO_DEFAULT_BOOT_LOGO
MAIN_PRINT("Main: Create bootsplash"); MAIN_PRINT("Main: Create bootsplash");
#if defined(TOOLS_ENABLED) && !defined(NO_EDITOR_SPLASH) #if defined(TOOLS_ENABLED) && !defined(NO_EDITOR_SPLASH)
Ref<Image> splash = (editor || project_manager) ? memnew(Image(boot_splash_editor_png)) : memnew(Image(boot_splash_png)); Ref<Image> splash = (editor || project_manager) ? memnew(Image(boot_splash_editor_png)) : memnew(Image(boot_splash_png));
#else #else
Ref<Image> splash = memnew(Image(boot_splash_png)); Ref<Image> splash = memnew(Image(boot_splash_png));
#endif #endif
MAIN_PRINT("Main: ClearColor"); MAIN_PRINT("Main: ClearColor");
RenderingServer::get_singleton()->set_default_clear_color(boot_bg_color); RenderingServer::get_singleton()->set_default_clear_color(boot_bg_color);
MAIN_PRINT("Main: Image"); MAIN_PRINT("Main: Image");
RenderingServer::get_singleton()->set_boot_image(splash, boot_bg_color, false); RenderingServer::get_singleton()->set_boot_image(splash, boot_bg_color, false);
#endif #endif
} }
#if defined(TOOLS_ENABLED) && defined(MACOS_ENABLED) #if defined(TOOLS_ENABLED) && defined(MACOS_ENABLED)
if (OS::get_singleton()->get_bundle_icon_path().is_empty()) { if (OS::get_singleton()->get_bundle_icon_path().is_empty()) {
Ref<Image> icon = memnew(Image(app_icon_png)); Ref<Image> icon = memnew(Image(app_icon_png));
DisplayServer::get_singleton()->set_icon(icon); DisplayServer::get_singleton()->set_icon(icon);
}
#endif
}
DisplayServer::set_early_window_clear_color_override(false);
MAIN_PRINT("Main: DCC");
RenderingServer::get_singleton()->set_default_clear_color(
GLOBAL_GET("rendering/environment/defaults/default_clear_color"));
GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "application/config/icon", PROPERTY_HINT_FILE, "*.png,*.webp,*.svg"), String());
GLOBAL_DEF(PropertyInfo(Variant::STRING, "application/config/macos_native_icon", PROPERTY_HINT_FILE, "*.icns"), String());
GLOBAL_DEF(PropertyInfo(Variant::STRING, "application/config/windows_native_icon", PROPERTY_HINT_FILE, "*.ico"), String());
Input *id = Input::get_singleton();
if (id) {
agile_input_event_flushing = GLOBAL_DEF("input_devices/buffering/agile_event_flushing", false);
if (bool(GLOBAL_DEF_BASIC("input_devices/pointing/emulate_touch_from_mouse", false)) &&
!(editor || project_manager)) {
if (!DisplayServer::get_singleton()->is_touchscreen_available()) {
//only if no touchscreen ui hint, set emulation
id->set_emulate_touch_from_mouse(true);
} }
#endif
} }
id->set_emulate_mouse_from_touch(bool(GLOBAL_DEF_BASIC("input_devices/pointing/emulate_mouse_from_touch", true))); MAIN_PRINT("Main: Clear Color");
}
GLOBAL_DEF_BASIC("input_devices/pointing/android/enable_long_press_as_right_click", false); DisplayServer::set_early_window_clear_color_override(false);
GLOBAL_DEF_BASIC("input_devices/pointing/android/enable_pan_and_scale_gestures", false); RenderingServer::get_singleton()->set_default_clear_color(
GLOBAL_GET("rendering/environment/defaults/default_clear_color"));
GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "application/config/icon", PROPERTY_HINT_FILE, "*.png,*.webp,*.svg"), String());
GLOBAL_DEF(PropertyInfo(Variant::STRING, "application/config/macos_native_icon", PROPERTY_HINT_FILE, "*.icns"), String());
GLOBAL_DEF(PropertyInfo(Variant::STRING, "application/config/windows_native_icon", PROPERTY_HINT_FILE, "*.ico"), String());
MAIN_PRINT("Main: Touch Input");
Input *id = Input::get_singleton();
if (id) {
agile_input_event_flushing = GLOBAL_DEF("input_devices/buffering/agile_event_flushing", false);
if (bool(GLOBAL_DEF_BASIC("input_devices/pointing/emulate_touch_from_mouse", false)) &&
!(editor || project_manager)) {
if (!DisplayServer::get_singleton()->is_touchscreen_available()) {
//only if no touchscreen ui hint, set emulation
id->set_emulate_touch_from_mouse(true);
}
}
id->set_emulate_mouse_from_touch(bool(GLOBAL_DEF_BASIC("input_devices/pointing/emulate_mouse_from_touch", true)));
}
GLOBAL_DEF_BASIC("input_devices/pointing/android/enable_long_press_as_right_click", false);
GLOBAL_DEF_BASIC("input_devices/pointing/android/enable_pan_and_scale_gestures", false);
OS::get_singleton()->benchmark_end_measure("Startup", "Setup Window and Boot");
}
MAIN_PRINT("Main: Load Translations and Remaps"); MAIN_PRINT("Main: Load Translations and Remaps");
translation_server->setup(); //register translations, load them, etc. /* Setup translations and remaps */
if (!locale.is_empty()) {
translation_server->set_locale(locale);
}
translation_server->load_translations();
ResourceLoader::load_translation_remaps(); //load remaps for resources
ResourceLoader::load_path_remaps(); {
OS::get_singleton()->benchmark_begin_measure("Startup", "Translations and Remaps");
translation_server->setup(); //register translations, load them, etc.
if (!locale.is_empty()) {
translation_server->set_locale(locale);
}
translation_server->load_translations();
ResourceLoader::load_translation_remaps(); //load remaps for resources
ResourceLoader::load_path_remaps();
OS::get_singleton()->benchmark_end_measure("Startup", "Translations and Remaps");
}
MAIN_PRINT("Main: Load TextServer"); MAIN_PRINT("Main: Load TextServer");
/* Enum text drivers */ /* Setup Text Server */
GLOBAL_DEF_RST("internationalization/rendering/text_driver", "");
String text_driver_options;
for (int i = 0; i < TextServerManager::get_singleton()->get_interface_count(); i++) {
const String driver_name = TextServerManager::get_singleton()->get_interface(i)->get_name();
if (driver_name == "Dummy") {
// Dummy text driver cannot draw any text, making the editor unusable if selected.
continue;
}
if (!text_driver_options.is_empty() && text_driver_options.find(",") == -1) {
// Not the first option; add a comma before it as a separator for the property hint.
text_driver_options += ",";
}
text_driver_options += driver_name;
}
ProjectSettings::get_singleton()->set_custom_property_info(PropertyInfo(Variant::STRING, "internationalization/rendering/text_driver", PROPERTY_HINT_ENUM, text_driver_options));
/* Determine text driver */ {
if (text_driver.is_empty()) { OS::get_singleton()->benchmark_begin_measure("Startup", "Text Server");
text_driver = GLOBAL_GET("internationalization/rendering/text_driver");
}
if (!text_driver.is_empty()) { /* Enum text drivers */
/* Load user selected text server. */ GLOBAL_DEF_RST("internationalization/rendering/text_driver", "");
String text_driver_options;
for (int i = 0; i < TextServerManager::get_singleton()->get_interface_count(); i++) { for (int i = 0; i < TextServerManager::get_singleton()->get_interface_count(); i++) {
if (TextServerManager::get_singleton()->get_interface(i)->get_name() == text_driver) { const String driver_name = TextServerManager::get_singleton()->get_interface(i)->get_name();
text_driver_idx = i; if (driver_name == "Dummy") {
break; // Dummy text driver cannot draw any text, making the editor unusable if selected.
continue;
} }
if (!text_driver_options.is_empty() && text_driver_options.find(",") == -1) {
// Not the first option; add a comma before it as a separator for the property hint.
text_driver_options += ",";
}
text_driver_options += driver_name;
} }
} ProjectSettings::get_singleton()->set_custom_property_info(PropertyInfo(Variant::STRING, "internationalization/rendering/text_driver", PROPERTY_HINT_ENUM, text_driver_options));
if (text_driver_idx < 0) { /* Determine text driver */
/* If not selected, use one with the most features available. */ if (text_driver.is_empty()) {
int max_features = 0; text_driver = GLOBAL_GET("internationalization/rendering/text_driver");
for (int i = 0; i < TextServerManager::get_singleton()->get_interface_count(); i++) {
uint32_t features = TextServerManager::get_singleton()->get_interface(i)->get_features();
int feature_number = 0;
while (features) {
feature_number += features & 1;
features >>= 1;
}
if (feature_number >= max_features) {
max_features = feature_number;
text_driver_idx = i;
}
} }
}
if (text_driver_idx >= 0) {
Ref<TextServer> ts = TextServerManager::get_singleton()->get_interface(text_driver_idx);
TextServerManager::get_singleton()->set_primary_interface(ts);
if (ts->has_feature(TextServer::FEATURE_USE_SUPPORT_DATA)) {
ts->load_support_data("res://" + ts->get_support_data_filename());
}
} else {
ERR_FAIL_V_MSG(ERR_CANT_CREATE, "TextServer: Unable to create TextServer interface.");
}
OS::get_singleton()->benchmark_end_measure("servers"); if (!text_driver.is_empty()) {
/* Load user selected text server. */
for (int i = 0; i < TextServerManager::get_singleton()->get_interface_count(); i++) {
if (TextServerManager::get_singleton()->get_interface(i)->get_name() == text_driver) {
text_driver_idx = i;
break;
}
}
}
if (text_driver_idx < 0) {
/* If not selected, use one with the most features available. */
int max_features = 0;
for (int i = 0; i < TextServerManager::get_singleton()->get_interface_count(); i++) {
uint32_t features = TextServerManager::get_singleton()->get_interface(i)->get_features();
int feature_number = 0;
while (features) {
feature_number += features & 1;
features >>= 1;
}
if (feature_number >= max_features) {
max_features = feature_number;
text_driver_idx = i;
}
}
}
if (text_driver_idx >= 0) {
Ref<TextServer> ts = TextServerManager::get_singleton()->get_interface(text_driver_idx);
TextServerManager::get_singleton()->set_primary_interface(ts);
if (ts->has_feature(TextServer::FEATURE_USE_SUPPORT_DATA)) {
ts->load_support_data("res://" + ts->get_support_data_filename());
}
} else {
ERR_FAIL_V_MSG(ERR_CANT_CREATE, "TextServer: Unable to create TextServer interface.");
}
OS::get_singleton()->benchmark_end_measure("Startup", "Text Server");
}
MAIN_PRINT("Main: Load Scene Types"); MAIN_PRINT("Main: Load Scene Types");
OS::get_singleton()->benchmark_begin_measure("scene"); OS::get_singleton()->benchmark_begin_measure("Startup", "Scene");
// Initialize ThemeDB early so that scene types can register their theme items. // Initialize ThemeDB early so that scene types can register their theme items.
// Default theme will be initialized later, after modules and ScriptServer are ready. // Default theme will be initialized later, after modules and ScriptServer are ready.
@ -2691,23 +2761,42 @@ Error Main::setup2() {
register_scene_singletons(); register_scene_singletons();
initialize_modules(MODULE_INITIALIZATION_LEVEL_SCENE); {
GDExtensionManager::get_singleton()->initialize_extensions(GDExtension::INITIALIZATION_LEVEL_SCENE); OS::get_singleton()->benchmark_begin_measure("Scene", "Modules and Extensions");
initialize_modules(MODULE_INITIALIZATION_LEVEL_SCENE);
GDExtensionManager::get_singleton()->initialize_extensions(GDExtension::INITIALIZATION_LEVEL_SCENE);
OS::get_singleton()->benchmark_end_measure("Scene", "Modules and Extensions");
}
OS::get_singleton()->benchmark_end_measure("Startup", "Scene");
#ifdef TOOLS_ENABLED #ifdef TOOLS_ENABLED
ClassDB::set_current_api(ClassDB::API_EDITOR); ClassDB::set_current_api(ClassDB::API_EDITOR);
register_editor_types(); register_editor_types();
initialize_modules(MODULE_INITIALIZATION_LEVEL_EDITOR);
GDExtensionManager::get_singleton()->initialize_extensions(GDExtension::INITIALIZATION_LEVEL_EDITOR); {
OS::get_singleton()->benchmark_begin_measure("Editor", "Modules and Extensions");
initialize_modules(MODULE_INITIALIZATION_LEVEL_EDITOR);
GDExtensionManager::get_singleton()->initialize_extensions(GDExtension::INITIALIZATION_LEVEL_EDITOR);
OS::get_singleton()->benchmark_end_measure("Editor", "Modules and Extensions");
}
ClassDB::set_current_api(ClassDB::API_CORE); ClassDB::set_current_api(ClassDB::API_CORE);
#endif #endif
MAIN_PRINT("Main: Load Modules"); MAIN_PRINT("Main: Load Platforms");
OS::get_singleton()->benchmark_begin_measure("Startup", "Platforms");
register_platform_apis(); register_platform_apis();
OS::get_singleton()->benchmark_end_measure("Startup", "Platforms");
GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "display/mouse_cursor/custom_image", PROPERTY_HINT_FILE, "*.png,*.webp"), String()); GLOBAL_DEF_BASIC(PropertyInfo(Variant::STRING, "display/mouse_cursor/custom_image", PROPERTY_HINT_FILE, "*.png,*.webp"), String());
GLOBAL_DEF_BASIC("display/mouse_cursor/custom_image_hotspot", Vector2()); GLOBAL_DEF_BASIC("display/mouse_cursor/custom_image_hotspot", Vector2());
GLOBAL_DEF_BASIC("display/mouse_cursor/tooltip_position_offset", Point2(10, 10)); GLOBAL_DEF_BASIC("display/mouse_cursor/tooltip_position_offset", Point2(10, 10));
@ -2721,12 +2810,18 @@ Error Main::setup2() {
} }
} }
OS::get_singleton()->benchmark_begin_measure("Startup", "Finalize Setup");
camera_server = CameraServer::create(); camera_server = CameraServer::create();
MAIN_PRINT("Main: Load Physics"); MAIN_PRINT("Main: Load Physics");
initialize_physics(); initialize_physics();
MAIN_PRINT("Main: Load Navigation");
initialize_navigation_server(); initialize_navigation_server();
register_server_singletons(); register_server_singletons();
// This loads global classes, so it must happen before custom loaders and savers are registered // This loads global classes, so it must happen before custom loaders and savers are registered
@ -2758,6 +2853,8 @@ Error Main::setup2() {
rendering_server->global_shader_parameters_load_settings(!editor); rendering_server->global_shader_parameters_load_settings(!editor);
} }
OS::get_singleton()->benchmark_end_measure("Startup", "Finalize Setup");
_start_success = true; _start_success = true;
ClassDB::set_current_api(ClassDB::API_NONE); //no more APIs are registered at this point ClassDB::set_current_api(ClassDB::API_NONE); //no more APIs are registered at this point
@ -2766,7 +2863,7 @@ Error Main::setup2() {
print_verbose("EDITOR API HASH: " + uitos(ClassDB::get_api_hash(ClassDB::API_EDITOR))); print_verbose("EDITOR API HASH: " + uitos(ClassDB::get_api_hash(ClassDB::API_EDITOR)));
MAIN_PRINT("Main: Done"); MAIN_PRINT("Main: Done");
OS::get_singleton()->benchmark_end_measure("scene"); OS::get_singleton()->benchmark_end_measure("Startup", "Setup");
return OK; return OK;
} }
@ -3173,7 +3270,7 @@ bool Main::start() {
if (!project_manager && !editor) { // game if (!project_manager && !editor) { // game
if (!game_path.is_empty() || !script.is_empty()) { if (!game_path.is_empty() || !script.is_empty()) {
//autoload //autoload
OS::get_singleton()->benchmark_begin_measure("load_autoloads"); OS::get_singleton()->benchmark_begin_measure("Startup", "Load Autoloads");
HashMap<StringName, ProjectSettings::AutoloadInfo> autoloads = ProjectSettings::get_singleton()->get_autoload_list(); HashMap<StringName, ProjectSettings::AutoloadInfo> autoloads = ProjectSettings::get_singleton()->get_autoload_list();
//first pass, add the constants so they exist before any script is loaded //first pass, add the constants so they exist before any script is loaded
@ -3238,7 +3335,7 @@ bool Main::start() {
for (Node *E : to_add) { for (Node *E : to_add) {
sml->get_root()->add_child(E); sml->get_root()->add_child(E);
} }
OS::get_singleton()->benchmark_end_measure("load_autoloads"); OS::get_singleton()->benchmark_end_measure("Startup", "Load Autoloads");
} }
} }
@ -3277,7 +3374,7 @@ bool Main::start() {
EditorNode *editor_node = nullptr; EditorNode *editor_node = nullptr;
if (editor) { if (editor) {
OS::get_singleton()->benchmark_begin_measure("editor"); OS::get_singleton()->benchmark_begin_measure("Startup", "Editor");
editor_node = memnew(EditorNode); editor_node = memnew(EditorNode);
sml->get_root()->add_child(editor_node); sml->get_root()->add_child(editor_node);
@ -3286,7 +3383,7 @@ bool Main::start() {
game_path = ""; // Do not load anything. game_path = ""; // Do not load anything.
} }
OS::get_singleton()->benchmark_end_measure("editor"); OS::get_singleton()->benchmark_end_measure("Startup", "Editor");
} }
#endif #endif
sml->set_auto_accept_quit(GLOBAL_GET("application/config/auto_accept_quit")); sml->set_auto_accept_quit(GLOBAL_GET("application/config/auto_accept_quit"));
@ -3424,7 +3521,7 @@ bool Main::start() {
if (!project_manager && !editor) { // game if (!project_manager && !editor) { // game
OS::get_singleton()->benchmark_begin_measure("game_load"); OS::get_singleton()->benchmark_begin_measure("Startup", "Load Game");
// Load SSL Certificates from Project Settings (or builtin). // Load SSL Certificates from Project Settings (or builtin).
Crypto::load_default_certificates(GLOBAL_GET("network/tls/certificate_bundle_override")); Crypto::load_default_certificates(GLOBAL_GET("network/tls/certificate_bundle_override"));
@ -3466,19 +3563,19 @@ bool Main::start() {
} }
} }
OS::get_singleton()->benchmark_end_measure("game_load"); OS::get_singleton()->benchmark_end_measure("Startup", "Load Game");
} }
#ifdef TOOLS_ENABLED #ifdef TOOLS_ENABLED
if (project_manager) { if (project_manager) {
OS::get_singleton()->benchmark_begin_measure("project_manager"); OS::get_singleton()->benchmark_begin_measure("Startup", "Project Manager");
Engine::get_singleton()->set_editor_hint(true); Engine::get_singleton()->set_editor_hint(true);
ProjectManager *pmanager = memnew(ProjectManager); ProjectManager *pmanager = memnew(ProjectManager);
ProgressDialog *progress_dialog = memnew(ProgressDialog); ProgressDialog *progress_dialog = memnew(ProgressDialog);
pmanager->add_child(progress_dialog); pmanager->add_child(progress_dialog);
sml->get_root()->add_child(pmanager); sml->get_root()->add_child(pmanager);
DisplayServer::get_singleton()->set_context(DisplayServer::CONTEXT_PROJECTMAN); DisplayServer::get_singleton()->set_context(DisplayServer::CONTEXT_PROJECTMAN);
OS::get_singleton()->benchmark_end_measure("project_manager"); OS::get_singleton()->benchmark_end_measure("Startup", "Project Manager");
} }
if (project_manager || editor) { if (project_manager || editor) {
@ -3506,7 +3603,7 @@ bool Main::start() {
} }
} }
OS::get_singleton()->benchmark_end_measure("startup_begin"); OS::get_singleton()->benchmark_end_measure("Startup", "Total");
OS::get_singleton()->benchmark_dump(); OS::get_singleton()->benchmark_dump();
return true; return true;
@ -3755,7 +3852,7 @@ void Main::force_redraw() {
* The order matters as some of those steps are linked with each other. * The order matters as some of those steps are linked with each other.
*/ */
void Main::cleanup(bool p_force) { void Main::cleanup(bool p_force) {
OS::get_singleton()->benchmark_begin_measure("Main::cleanup"); OS::get_singleton()->benchmark_begin_measure("Shutdown", "Total");
if (!p_force) { if (!p_force) {
ERR_FAIL_COND(!_start_success); ERR_FAIL_COND(!_start_success);
} }
@ -3896,7 +3993,7 @@ void Main::cleanup(bool p_force) {
uninitialize_modules(MODULE_INITIALIZATION_LEVEL_CORE); uninitialize_modules(MODULE_INITIALIZATION_LEVEL_CORE);
unregister_core_types(); unregister_core_types();
OS::get_singleton()->benchmark_end_measure("Main::cleanup"); OS::get_singleton()->benchmark_end_measure("Shutdown", "Total");
OS::get_singleton()->benchmark_dump(); OS::get_singleton()->benchmark_dump();
OS::get_singleton()->finalize_core(); OS::get_singleton()->finalize_core();

View File

@ -184,7 +184,7 @@ class Godot(private val context: Context) : SensorEventListener {
return return
} }
beginBenchmarkMeasure("Godot::onCreate") beginBenchmarkMeasure("Startup", "Godot::onCreate")
try { try {
this.primaryHost = primaryHost this.primaryHost = primaryHost
val activity = requireActivity() val activity = requireActivity()
@ -286,7 +286,7 @@ class Godot(private val context: Context) : SensorEventListener {
initializationStarted = false initializationStarted = false
throw e throw e
} finally { } finally {
endBenchmarkMeasure("Godot::onCreate"); endBenchmarkMeasure("Startup", "Godot::onCreate");
} }
} }
@ -1016,13 +1016,13 @@ class Godot(private val context: Context) : SensorEventListener {
} }
@Keep @Keep
private fun nativeBeginBenchmarkMeasure(label: String) { private fun nativeBeginBenchmarkMeasure(scope: String, label: String) {
beginBenchmarkMeasure(label) beginBenchmarkMeasure(scope, label)
} }
@Keep @Keep
private fun nativeEndBenchmarkMeasure(label: String) { private fun nativeEndBenchmarkMeasure(scope: String, label: String) {
endBenchmarkMeasure(label) endBenchmarkMeasure(scope, label)
} }
@Keep @Keep

View File

@ -172,7 +172,7 @@ public class GodotFragment extends Fragment implements IDownloaderClient, GodotH
@Override @Override
public void onCreate(Bundle icicle) { public void onCreate(Bundle icicle) {
BenchmarkUtils.beginBenchmarkMeasure("GodotFragment::onCreate"); BenchmarkUtils.beginBenchmarkMeasure("Startup", "GodotFragment::onCreate");
super.onCreate(icicle); super.onCreate(icicle);
final Activity activity = getActivity(); final Activity activity = getActivity();
@ -180,7 +180,7 @@ public class GodotFragment extends Fragment implements IDownloaderClient, GodotH
godot = new Godot(requireContext()); godot = new Godot(requireContext());
performEngineInitialization(); performEngineInitialization();
BenchmarkUtils.endBenchmarkMeasure("GodotFragment::onCreate"); BenchmarkUtils.endBenchmarkMeasure("Startup", "GodotFragment::onCreate");
} }
private void performEngineInitialization() { private void performEngineInitialization() {

View File

@ -41,7 +41,7 @@ import org.godotengine.godot.io.file.FileAccessFlags
import org.godotengine.godot.io.file.FileAccessHandler import org.godotengine.godot.io.file.FileAccessHandler
import org.json.JSONObject import org.json.JSONObject
import java.nio.ByteBuffer import java.nio.ByteBuffer
import java.util.concurrent.ConcurrentSkipListMap import java.util.Collections
/** /**
* Contains benchmark related utilities methods * Contains benchmark related utilities methods
@ -51,44 +51,47 @@ private const val TAG = "GodotBenchmark"
var useBenchmark = false var useBenchmark = false
var benchmarkFile = "" var benchmarkFile = ""
private val startBenchmarkFrom = ConcurrentSkipListMap<String, Long>() private val startBenchmarkFrom = Collections.synchronizedMap(LinkedHashMap<Pair<String, String>, Long>())
private val benchmarkTracker = ConcurrentSkipListMap<String, Double>() private val benchmarkTracker = Collections.synchronizedMap(LinkedHashMap<Pair<String, String>, Double>())
/** /**
* Start measuring and tracing the execution of a given section of code using the given label. * Start measuring and tracing the execution of a given section of code using the given label
* within the given scope.
* *
* Must be followed by a call to [endBenchmarkMeasure]. * Must be followed by a call to [endBenchmarkMeasure].
* *
* Note: Only enabled on 'editorDev' build variant. * Note: Only enabled on 'editorDev' build variant.
*/ */
fun beginBenchmarkMeasure(label: String) { fun beginBenchmarkMeasure(scope: String, label: String) {
if (BuildConfig.FLAVOR != "editor" || BuildConfig.BUILD_TYPE != "dev") { if (BuildConfig.FLAVOR != "editor" || BuildConfig.BUILD_TYPE != "dev") {
return return
} }
startBenchmarkFrom[label] = SystemClock.elapsedRealtime() val key = Pair(scope, label)
startBenchmarkFrom[key] = SystemClock.elapsedRealtime()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
Trace.beginAsyncSection(label, 0) Trace.beginAsyncSection("[$scope] $label", 0)
} }
} }
/** /**
* End measuring and tracing of the section of code with the given label. * End measuring and tracing of the section of code with the given label within the given scope.
* *
* Must be preceded by a call [beginBenchmarkMeasure] * Must be preceded by a call [beginBenchmarkMeasure]
* *
* * Note: Only enabled on 'editorDev' build variant. * * Note: Only enabled on 'editorDev' build variant.
*/ */
fun endBenchmarkMeasure(label: String) { fun endBenchmarkMeasure(scope: String, label: String) {
if (BuildConfig.FLAVOR != "editor" || BuildConfig.BUILD_TYPE != "dev") { if (BuildConfig.FLAVOR != "editor" || BuildConfig.BUILD_TYPE != "dev") {
return return
} }
val startTime = startBenchmarkFrom[label] ?: return val key = Pair(scope, label)
val startTime = startBenchmarkFrom[key] ?: return
val total = SystemClock.elapsedRealtime() - startTime val total = SystemClock.elapsedRealtime() - startTime
benchmarkTracker[label] = total / 1000.0 benchmarkTracker[key] = total / 1_000.0
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
Trace.endAsyncSection(label, 0) Trace.endAsyncSection("[$scope] $label", 0)
} }
} }
@ -107,8 +110,16 @@ fun dumpBenchmark(fileAccessHandler: FileAccessHandler?, filepath: String? = ben
return return
} }
val results = LinkedHashMap<String, String>()
for (entry in benchmarkTracker) {
if (!results.containsKey(entry.key.first)) {
results[entry.key.first] = ""
}
results[entry.key.first] += "\t\t- ${entry.key.second}: ${entry.value * 1_000.0} msec.\n"
}
val printOut = val printOut =
benchmarkTracker.map { "\t- ${it.key} : ${it.value} sec." }.joinToString("\n") results.map { "\t- [${it.key}]\n ${it.value}" }.joinToString("\n")
Log.i(TAG, "BENCHMARK:\n$printOut") Log.i(TAG, "BENCHMARK:\n$printOut")
if (fileAccessHandler != null && !filepath.isNullOrBlank()) { if (fileAccessHandler != null && !filepath.isNullOrBlank()) {

View File

@ -78,8 +78,8 @@ GodotJavaWrapper::GodotJavaWrapper(JNIEnv *p_env, jobject p_activity, jobject p_
_on_godot_main_loop_started = p_env->GetMethodID(godot_class, "onGodotMainLoopStarted", "()V"); _on_godot_main_loop_started = p_env->GetMethodID(godot_class, "onGodotMainLoopStarted", "()V");
_create_new_godot_instance = p_env->GetMethodID(godot_class, "createNewGodotInstance", "([Ljava/lang/String;)I"); _create_new_godot_instance = p_env->GetMethodID(godot_class, "createNewGodotInstance", "([Ljava/lang/String;)I");
_get_render_view = p_env->GetMethodID(godot_class, "getRenderView", "()Lorg/godotengine/godot/GodotRenderView;"); _get_render_view = p_env->GetMethodID(godot_class, "getRenderView", "()Lorg/godotengine/godot/GodotRenderView;");
_begin_benchmark_measure = p_env->GetMethodID(godot_class, "nativeBeginBenchmarkMeasure", "(Ljava/lang/String;)V"); _begin_benchmark_measure = p_env->GetMethodID(godot_class, "nativeBeginBenchmarkMeasure", "(Ljava/lang/String;Ljava/lang/String;)V");
_end_benchmark_measure = p_env->GetMethodID(godot_class, "nativeEndBenchmarkMeasure", "(Ljava/lang/String;)V"); _end_benchmark_measure = p_env->GetMethodID(godot_class, "nativeEndBenchmarkMeasure", "(Ljava/lang/String;Ljava/lang/String;)V");
_dump_benchmark = p_env->GetMethodID(godot_class, "nativeDumpBenchmark", "(Ljava/lang/String;)V"); _dump_benchmark = p_env->GetMethodID(godot_class, "nativeDumpBenchmark", "(Ljava/lang/String;)V");
_get_gdextension_list_config_file = p_env->GetMethodID(godot_class, "getGDExtensionConfigFiles", "()[Ljava/lang/String;"); _get_gdextension_list_config_file = p_env->GetMethodID(godot_class, "getGDExtensionConfigFiles", "()[Ljava/lang/String;");
_has_feature = p_env->GetMethodID(godot_class, "hasFeature", "(Ljava/lang/String;)Z"); _has_feature = p_env->GetMethodID(godot_class, "hasFeature", "(Ljava/lang/String;)Z");
@ -348,21 +348,23 @@ int GodotJavaWrapper::create_new_godot_instance(List<String> args) {
} }
} }
void GodotJavaWrapper::begin_benchmark_measure(const String &p_label) { void GodotJavaWrapper::begin_benchmark_measure(const String &p_context, const String &p_label) {
if (_begin_benchmark_measure) { if (_begin_benchmark_measure) {
JNIEnv *env = get_jni_env(); JNIEnv *env = get_jni_env();
ERR_FAIL_NULL(env); ERR_FAIL_NULL(env);
jstring j_context = env->NewStringUTF(p_context.utf8().get_data());
jstring j_label = env->NewStringUTF(p_label.utf8().get_data()); jstring j_label = env->NewStringUTF(p_label.utf8().get_data());
env->CallVoidMethod(godot_instance, _begin_benchmark_measure, j_label); env->CallVoidMethod(godot_instance, _begin_benchmark_measure, j_context, j_label);
} }
} }
void GodotJavaWrapper::end_benchmark_measure(const String &p_label) { void GodotJavaWrapper::end_benchmark_measure(const String &p_context, const String &p_label) {
if (_end_benchmark_measure) { if (_end_benchmark_measure) {
JNIEnv *env = get_jni_env(); JNIEnv *env = get_jni_env();
ERR_FAIL_NULL(env); ERR_FAIL_NULL(env);
jstring j_context = env->NewStringUTF(p_context.utf8().get_data());
jstring j_label = env->NewStringUTF(p_label.utf8().get_data()); jstring j_label = env->NewStringUTF(p_label.utf8().get_data());
env->CallVoidMethod(godot_instance, _end_benchmark_measure, j_label); env->CallVoidMethod(godot_instance, _end_benchmark_measure, j_context, j_label);
} }
} }

View File

@ -105,8 +105,8 @@ public:
void vibrate(int p_duration_ms); void vibrate(int p_duration_ms);
String get_input_fallback_mapping(); String get_input_fallback_mapping();
int create_new_godot_instance(List<String> args); int create_new_godot_instance(List<String> args);
void begin_benchmark_measure(const String &p_label); void begin_benchmark_measure(const String &p_context, const String &p_label);
void end_benchmark_measure(const String &p_label); void end_benchmark_measure(const String &p_context, const String &p_label);
void dump_benchmark(const String &benchmark_file); void dump_benchmark(const String &benchmark_file);
// Return the list of gdextensions config file. // Return the list of gdextensions config file.

View File

@ -708,15 +708,15 @@ String OS_Android::get_config_path() const {
return get_user_data_dir().path_join("config"); return get_user_data_dir().path_join("config");
} }
void OS_Android::benchmark_begin_measure(const String &p_what) { void OS_Android::benchmark_begin_measure(const String &p_context, const String &p_what) {
#ifdef TOOLS_ENABLED #ifdef TOOLS_ENABLED
godot_java->begin_benchmark_measure(p_what); godot_java->begin_benchmark_measure(p_context, p_what);
#endif #endif
} }
void OS_Android::benchmark_end_measure(const String &p_what) { void OS_Android::benchmark_end_measure(const String &p_context, const String &p_what) {
#ifdef TOOLS_ENABLED #ifdef TOOLS_ENABLED
godot_java->end_benchmark_measure(p_what); godot_java->end_benchmark_measure(p_context, p_what);
#endif #endif
} }

View File

@ -165,8 +165,8 @@ public:
virtual Error setup_remote_filesystem(const String &p_server_host, int p_port, const String &p_password, String &r_project_path) override; virtual Error setup_remote_filesystem(const String &p_server_host, int p_port, const String &p_password, String &r_project_path) override;
virtual void benchmark_begin_measure(const String &p_what) override; virtual void benchmark_begin_measure(const String &p_context, const String &p_what) override;
virtual void benchmark_end_measure(const String &p_what) override; virtual void benchmark_end_measure(const String &p_context, const String &p_what) override;
virtual void benchmark_dump() override; virtual void benchmark_dump() override;
virtual void load_platform_gdextensions() const override; virtual void load_platform_gdextensions() const override;

View File

@ -293,6 +293,8 @@ static Ref<ResourceFormatSaverShaderInclude> resource_saver_shader_include;
static Ref<ResourceFormatLoaderShaderInclude> resource_loader_shader_include; static Ref<ResourceFormatLoaderShaderInclude> resource_loader_shader_include;
void register_scene_types() { void register_scene_types() {
OS::get_singleton()->benchmark_begin_measure("Scene", "Register Types");
SceneStringNames::create(); SceneStringNames::create();
OS::get_singleton()->yield(); // may take time to init OS::get_singleton()->yield(); // may take time to init
@ -1182,9 +1184,13 @@ void register_scene_types() {
} }
SceneDebugger::initialize(); SceneDebugger::initialize();
OS::get_singleton()->benchmark_end_measure("Scene", "Register Types");
} }
void unregister_scene_types() { void unregister_scene_types() {
OS::get_singleton()->benchmark_begin_measure("Scene", "Unregister Types");
SceneDebugger::deinitialize(); SceneDebugger::deinitialize();
ResourceLoader::remove_resource_format_loader(resource_loader_texture_layered); ResourceLoader::remove_resource_format_loader(resource_loader_texture_layered);
@ -1227,10 +1233,16 @@ void unregister_scene_types() {
CanvasItemMaterial::finish_shaders(); CanvasItemMaterial::finish_shaders();
ColorPicker::finish_shaders(); ColorPicker::finish_shaders();
SceneStringNames::free(); SceneStringNames::free();
OS::get_singleton()->benchmark_end_measure("Scene", "Unregister Types");
} }
void register_scene_singletons() { void register_scene_singletons() {
OS::get_singleton()->benchmark_begin_measure("Scene", "Register Singletons");
GDREGISTER_CLASS(ThemeDB); GDREGISTER_CLASS(ThemeDB);
Engine::get_singleton()->add_singleton(Engine::Singleton("ThemeDB", ThemeDB::get_singleton())); Engine::get_singleton()->add_singleton(Engine::Singleton("ThemeDB", ThemeDB::get_singleton()));
OS::get_singleton()->benchmark_end_measure("Scene", "Register Singletons");
} }

View File

@ -117,6 +117,8 @@ static MovieWriterMJPEG *writer_mjpeg = nullptr;
static MovieWriterPNGWAV *writer_pngwav = nullptr; static MovieWriterPNGWAV *writer_pngwav = nullptr;
void register_server_types() { void register_server_types() {
OS::get_singleton()->benchmark_begin_measure("Servers", "Register Extensions");
shader_types = memnew(ShaderTypes); shader_types = memnew(ShaderTypes);
GDREGISTER_CLASS(TextServerManager); GDREGISTER_CLASS(TextServerManager);
@ -293,16 +295,24 @@ void register_server_types() {
writer_pngwav = memnew(MovieWriterPNGWAV); writer_pngwav = memnew(MovieWriterPNGWAV);
MovieWriter::add_writer(writer_pngwav); MovieWriter::add_writer(writer_pngwav);
OS::get_singleton()->benchmark_end_measure("Servers", "Register Extensions");
} }
void unregister_server_types() { void unregister_server_types() {
OS::get_singleton()->benchmark_begin_measure("Servers", "Unregister Extensions");
ServersDebugger::deinitialize(); ServersDebugger::deinitialize();
memdelete(shader_types); memdelete(shader_types);
memdelete(writer_mjpeg); memdelete(writer_mjpeg);
memdelete(writer_pngwav); memdelete(writer_pngwav);
OS::get_singleton()->benchmark_end_measure("Servers", "Unregister Extensions");
} }
void register_server_singletons() { void register_server_singletons() {
OS::get_singleton()->benchmark_begin_measure("Servers", "Register Singletons");
Engine::get_singleton()->add_singleton(Engine::Singleton("DisplayServer", DisplayServer::get_singleton(), "DisplayServer")); Engine::get_singleton()->add_singleton(Engine::Singleton("DisplayServer", DisplayServer::get_singleton(), "DisplayServer"));
Engine::get_singleton()->add_singleton(Engine::Singleton("RenderingServer", RenderingServer::get_singleton(), "RenderingServer")); Engine::get_singleton()->add_singleton(Engine::Singleton("RenderingServer", RenderingServer::get_singleton(), "RenderingServer"));
Engine::get_singleton()->add_singleton(Engine::Singleton("AudioServer", AudioServer::get_singleton(), "AudioServer")); Engine::get_singleton()->add_singleton(Engine::Singleton("AudioServer", AudioServer::get_singleton(), "AudioServer"));
@ -312,4 +322,6 @@ void register_server_singletons() {
Engine::get_singleton()->add_singleton(Engine::Singleton("NavigationServer3D", NavigationServer3D::get_singleton(), "NavigationServer3D")); Engine::get_singleton()->add_singleton(Engine::Singleton("NavigationServer3D", NavigationServer3D::get_singleton(), "NavigationServer3D"));
Engine::get_singleton()->add_singleton(Engine::Singleton("XRServer", XRServer::get_singleton(), "XRServer")); Engine::get_singleton()->add_singleton(Engine::Singleton("XRServer", XRServer::get_singleton(), "XRServer"));
Engine::get_singleton()->add_singleton(Engine::Singleton("CameraServer", CameraServer::get_singleton(), "CameraServer")); Engine::get_singleton()->add_singleton(Engine::Singleton("CameraServer", CameraServer::get_singleton(), "CameraServer"));
OS::get_singleton()->benchmark_end_measure("Servers", "Register Singletons");
} }