1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

[ResourceLoader] Do not wait for the main thread during initial reimport.

This commit is contained in:
Pāvels Nadtočajevs
2025-03-12 09:18:39 +02:00
parent 0a30831bed
commit 16865b6917
3 changed files with 16 additions and 3 deletions

View File

@@ -772,6 +772,10 @@ Ref<Resource> ResourceLoader::_load_complete(LoadToken &p_load_token, Error *r_e
return _load_complete_inner(p_load_token, r_error, thread_load_lock); return _load_complete_inner(p_load_token, r_error, thread_load_lock);
} }
void ResourceLoader::set_is_import_thread(bool p_import_thread) {
import_thread = p_import_thread;
}
Ref<Resource> ResourceLoader::_load_complete_inner(LoadToken &p_load_token, Error *r_error, MutexLock<SafeBinaryMutex<BINARY_MUTEX_TAG>> &p_thread_load_lock) { Ref<Resource> ResourceLoader::_load_complete_inner(LoadToken &p_load_token, Error *r_error, MutexLock<SafeBinaryMutex<BINARY_MUTEX_TAG>> &p_thread_load_lock) {
if (r_error) { if (r_error) {
*r_error = OK; *r_error = OK;
@@ -886,9 +890,11 @@ Ref<Resource> ResourceLoader::_load_complete_inner(LoadToken &p_load_token, Erro
MessageQueue::get_main_singleton()->push_callable(callable_mp(rcc.source, &Resource::connect_changed).bind(rcc.callable, rcc.flags)); MessageQueue::get_main_singleton()->push_callable(callable_mp(rcc.source, &Resource::connect_changed).bind(rcc.callable, rcc.flags));
} }
} }
core_bind::Semaphore done; if (!import_thread) { // Main thread is blocked by initial resource reimport, do not wait.
MessageQueue::get_main_singleton()->push_callable(callable_mp(&done, &core_bind::Semaphore::post).bind(1)); core_bind::Semaphore done;
done.wait(); MessageQueue::get_main_singleton()->push_callable(callable_mp(&done, &core_bind::Semaphore::post).bind(1));
done.wait();
}
} }
} }
} }
@@ -1565,6 +1571,7 @@ bool ResourceLoader::create_missing_resources_if_class_unavailable = false;
bool ResourceLoader::abort_on_missing_resource = true; bool ResourceLoader::abort_on_missing_resource = true;
bool ResourceLoader::timestamp_on_load = false; bool ResourceLoader::timestamp_on_load = false;
thread_local bool ResourceLoader::import_thread = false;
thread_local int ResourceLoader::load_nesting = 0; thread_local int ResourceLoader::load_nesting = 0;
thread_local Vector<String> ResourceLoader::load_paths_stack; thread_local Vector<String> ResourceLoader::load_paths_stack;
thread_local HashMap<int, HashMap<String, Ref<Resource>>> ResourceLoader::res_ref_overrides; thread_local HashMap<int, HashMap<String, Ref<Resource>>> ResourceLoader::res_ref_overrides;

View File

@@ -204,6 +204,7 @@ private:
static void _run_load_task(void *p_userdata); static void _run_load_task(void *p_userdata);
static thread_local bool import_thread;
static thread_local int load_nesting; static thread_local int load_nesting;
static thread_local HashMap<int, HashMap<String, Ref<Resource>>> res_ref_overrides; // Outermost key is nesting level. static thread_local HashMap<int, HashMap<String, Ref<Resource>>> res_ref_overrides; // Outermost key is nesting level.
static thread_local Vector<String> load_paths_stack; static thread_local Vector<String> load_paths_stack;
@@ -253,6 +254,8 @@ public:
static bool is_imported(const String &p_path); static bool is_imported(const String &p_path);
static int get_import_order(const String &p_path); static int get_import_order(const String &p_path);
static void set_is_import_thread(bool p_import_thread);
static void set_timestamp_on_load(bool p_timestamp) { timestamp_on_load = p_timestamp; } static void set_timestamp_on_load(bool p_timestamp) { timestamp_on_load = p_timestamp; }
static bool get_timestamp_on_load() { return timestamp_on_load; } static bool get_timestamp_on_load() { return timestamp_on_load; }

View File

@@ -3107,8 +3107,11 @@ void EditorFileSystem::_refresh_filesystem() {
} }
void EditorFileSystem::_reimport_thread(uint32_t p_index, ImportThreadData *p_import_data) { void EditorFileSystem::_reimport_thread(uint32_t p_index, ImportThreadData *p_import_data) {
ResourceLoader::set_is_import_thread(true);
int file_idx = p_import_data->reimport_from + int(p_index); int file_idx = p_import_data->reimport_from + int(p_index);
_reimport_file(p_import_data->reimport_files[file_idx].path); _reimport_file(p_import_data->reimport_files[file_idx].path);
ResourceLoader::set_is_import_thread(false);
p_import_data->imported_sem->post(); p_import_data->imported_sem->post();
} }