Commit Graph

214 Commits

Author SHA1 Message Date
5c970db2e4 ResourceLoader: Optimize remap check by deferring until a non-mutex zone 2024-08-21 12:19:43 +02:00
28619e26cf ResourceLoader: Enhance deadlock prevention
Benefits:
- Simpler code. The main load function is renamed so it's apparent that it's not just a thread entry point anymore.
- Cache and thread modes of the original task are honored. A beautiful consequence of this is that, unlike formerly, re-issued loads can use the resource cache, which makes this mechanism much more performant.
- The newly added getter for caller task id in WorkerThreadPool allows to remove the custom tracking of that in ResourceLoader.
- The check to replace a cached resource and the replacement itself happen atomically. That fixes deadlock prevention leading to multiple resource instances of the same one on disk. As a side effect, it also makes the regular check for replace load mode more robust.
2024-08-21 12:19:43 +02:00
bd0959ebdd ResourceLoader: Properly push & pop TLS state on recursive load tasks 2024-08-21 12:19:43 +02:00
5ca419e32c Merge pull request #94801 from gamelessone/fix-cond-var
Fix use-after-free of `ConditionVariable` in `ResourceLoader`
2024-08-21 11:14:22 +02:00
6a829d5a86 Merge pull request #95508 from Summersay415/loaded-when-not
Return error when no ResourceFormatLoader found
2024-08-19 14:34:17 +02:00
e9407d4877 ResourceLoader: Revert workaround resource loading crashes due to buggy TLS
This reverts commit 41c0785636.
2024-08-19 12:22:31 +02:00
f01e052162 Merge pull request #95549 from timothyqiu/split-translation-server
Split `TranslationServer` into its own file
2024-08-16 14:36:16 +02:00
ae2044dccb Merge pull request #95477 from RandomShaper/res_load_dev_bugs
ResourceLoader: Use better error handling for possible engine bugs
2024-08-16 10:36:33 +02:00
7343dc3a5d Split TranslationServer into its own file 2024-08-15 15:00:47 +08:00
6df3621b47 Return error when no ResourceFormatLoader found. 2024-08-14 11:45:23 +07:00
31a9e10ddb ResourceLoader: Use better error handling for possible engine bugs 2024-08-13 12:52:08 +02:00
17ea4b405a ResourceLoader: Fix error on querying progress for uncached loads 2024-08-13 12:41:11 +02:00
f5bb14dceb [ResourceLoader] Add check to prevent double free crashes. 2024-08-06 08:31:03 +03:00
2ff6594928 Fix use condition_variable after free 2024-07-30 13:59:20 +03:00
5640e8adc9 ResourceLoader: Let resource setup late steps invoke loading in turn 2024-07-29 18:13:37 +02:00
28a7a95531 ResourceLoader: Fix sync issues with error reporting
This is about not letting the resource format loader set the error code directly on the task anymore. Instead, it's stored locally and assigned only when it is right to do so.

Otherwise, other tasks may see an error code in the current one before it's state having transitioned to errored. While this, besides the technically true data race, may not be a problem in practice, it causes surprising situations during debugging as it breaks assumptions.
2024-07-19 10:00:41 +02:00
5b5cdf2414 Fixup recent changes to threading concerns
ResourceLoader:
- Fix invalid tokens being returned.
- Remove no longer written `ThreadLoadTask::dependent_path` and the code reading from it.
- Clear deadlock hazard by keeping the mutex unlocked during userland polling.

WorkerThreadPool:
- Include thread call queue override in the thread state reset set, which allows to simplify the code that handled that (imperfectly) in the ResourceLoader.
- Handle the mutex type correctly on entering an allowance zone.

CommandQueueMT:
- Handle the additional possibility of command buffer reallocation that mutex unlock allowance introduces.
2024-07-16 11:03:02 +02:00
a426479b3f ResourceLoader: Fix error message due to already-awaited tasks being re-awaited 2024-07-08 12:19:44 +02:00
f952d3956c ResourceLoader: Fixup management of thread-specific status
- Allows the message queue override to flush after loading each resource, which was the original intent.
- Removes a redundant call to mark the thread as safe-for-nodes.
2024-07-08 10:30:25 +02:00
ec61c5064c ResourceLoader: Support polling and get-before-complete on the main thread 2024-06-28 11:25:10 +02:00
c1391489e3 GDScript: Enhance handling of cyclic dependencies 2024-06-26 17:44:32 +02:00
884d1da938 ResourceLoader: Fix handling of uncached loads
- `CACHE_MODE_IGNORE_DEEP` is checked in addition to `CACHE_MODE_IGNORE` to determine if a load is uncached. This avoids crashes in uncached loads due to prematurely freed load tasks.
- Cached load tasks are isolated (not registered in the task map ever). This avoids regular loads from reusing in-flight cached loads, which is not correct.
2024-06-24 11:25:57 +02:00
087ef4b942 Merge pull request #93124 from RandomShaper/skull_trio
`ResourceLoader`: Let the caller thread use its own message queue override
2024-06-14 17:13:38 +02:00
cc6f5d1a7a ResourceLoader: Let the caller thread use its own message queue override 2024-06-13 10:31:11 +02:00
21c03d1956 WorkerThreadPool: Fix thread message queue not restored after overridden in a task
Also, simplifies the thread override teardown in MessageQueue.
2024-06-13 10:31:08 +02:00
bdcceef0e2 ResourceLoader: Avoid deadlock when awaiting a loader thread that failed early 2024-06-12 13:49:37 +02:00
e4fa8543ea Revert "Fix FileSystem dock won't show any file folders"
This reverts commit 72856d633a.

Fixes #93022.
2024-06-11 11:46:35 +02:00
72856d633a Fix FileSystem dock won't show any file folders 2024-06-10 19:54:37 -04:00
00cc0a3e8f Merge pull request #90091 from ajreckof/Fix-load-subtask-not-being-registered-leading-to-false-progress-values-
Fix load subtask not being registered leading to false progress values.
2024-04-24 18:55:04 +02:00
ca020ad8cd Fix load subtask not being registered leading to false progress values. 2024-04-13 01:42:29 +02:00
64146cb7f3 [Core] Add iteration support to Array 2024-04-10 14:49:34 +02:00
0274877def [Core] Fix ResourceLoader.load cache with relative paths
Paths were not simplified meaning that `res://foo.bar` was treated
differently from `./foo.bar` and similar
2024-03-30 12:50:08 +01:00
5e144022e7 Enhance cache modes in resource loading
- Unify documentation, hoping to clear misconcepctions about about propagation of the cache mode across dependant loads.
- Clarify in docs that `CACHE_MODE_REPLACE` now also works on the main resource (from #87008).
- Add two recursive modes, counterparts of `CACHE_MODE_REPLACE` and `CACHE_MODE_IGNORE`, since it seems some need them (see #59669, #82830).
- Let resources, even loaded with one of the ignore-cache modes, get a path, which is useful for tools.
2024-02-26 14:59:04 +01:00
851f1d49d7 Remove spammy dev-mode message about load deadlock prevention 2024-02-23 14:54:03 +01:00
a8bc9f3e78 Add const lvalue ref to core/* container parameters 2024-02-14 11:20:36 -03:00
dc99c8d4a4 Merge pull request #87008 from KoBeWi/cache_mode_replace_fixes²
Fix² behavior of ResourceFormatLoader `CACHE_MODE_REPLACE`
2024-02-13 23:43:18 +01:00
71e0082ab0 Extract 'SafeBinaryMutex' to separate header
This change simply extracts 'SafeBinaryMutex' from 'mutex.h' to
    'safe_binary_mutex.h', in an effort to reduce the compilation
    speed impact of including `mutex.h`.
2024-02-04 16:59:54 +01:00
3dfedd69ea Merge pull request #87711 from matthew1006/threaded-loading-progress-fix
Fix `ResourceLoader.load_threaded_get_status` returning `[0]` constantly in exported projects.
2024-01-30 17:48:11 +01:00
b65c495d6e Merge pull request #86845 from RandomShaper/no_load_regress
Avoid regressing in progress reporting in resource load
2024-01-29 21:33:00 +01:00
7565d1f3ab Push p_original_path into load_paths_stack and sub_tasks instead of p_path. 2024-01-29 17:27:57 +00:00
dc79e956b6 Merge pull request #86587 from RandomShaper/wtp_enhance
Enhance & fix `WorkerThreadPool`
2024-01-11 17:38:09 +01:00
2e09985c0d Fix² behavior of ResourceFormatLoader CACHE_MODE_REPLACE 2024-01-09 16:01:37 +01:00
9ca3d3ec83 Revert "Fix behavior of ResourceFormatLoader CACHE_MODE_REPLACE" 2024-01-09 10:49:14 +01:00
9444d297ed WorkerThreadPool: Overhaul scheduling and synchronization
This commits rewrites the sync logic in a way that the
`use_system_threads_for_low_priority_tasks` setting, which was added due to
the lack of a cross-platform wait-for-multiple-objects functionality, can be
removed (it's as if it was effectively hardcoded to `false`).

With the new implementation, we have the best of both worlds: threads don't
have to poll, plus no bespoke threads are used.

In addition, regarding deadlock prevention, since not every possible case of
wait-deadlock could be avoided, this commits removes the current best-effort
avoidance mechanisms and keeps only a simple, pessimistic way of detection.

It turns out that the only current user of deadlock prevention, ResourceLoader,
works fine with it and so every possible situation in resource loading is now
properly handled, with no possibilities of deadlocking. There's a comment in
the code with further details.

Lastly, a potential for load tasks never being awaited/disposed is cleared.
2024-01-08 12:45:42 +01:00
f5ca58d32f Avoid regressing in progress reporting in resource load 2024-01-05 19:33:58 +01:00
2e94be2ea4 Merge pull request #84167 from SaracenOne/cache_mode_replace_fixes
Fix behavior of ResourceFormatLoader `CACHE_MODE_REPLACE`
2023-12-08 15:23:13 +01:00
bc1949d797 Correctly check scripts that must inherit EditorPlugin
Also updates some error messages related to this kind of check
across the codebase.
2023-11-23 16:24:43 +01:00
f392a9c4f8 Fix CACHE_MODE_REPLACE 2023-11-15 18:55:20 +00:00
2bcc2a3cd0 Merge pull request #84791 from akien-mga/fix-translation-remapping-check
Fix translation remapping check for imported resources
2023-11-12 23:00:08 +01:00
2729a78fd7 Fix translation remapping check for imported resources
Fixes #81660.
2023-11-12 13:17:12 +01:00