Commit Graph

271 Commits (cb1569345a6f17da08241e645ab03cb2e1b78d2f)

Author SHA1 Message Date
Kongfa Waroros bfb5570c03 Fix ResourceLoader is not verbosely printing a resource path on loading 2024-08-28 03:37:51 +07:00
Rémi Verschelde ce44c91223
Merge pull request #93739 from AThousandShips/lock_unlock
[Core] Allow locking/unlocking of `MutexLock`
2024-08-26 22:45:13 +07:00
Rémi Verschelde b78da13e2a
Merge pull request #93064 from Hilderin/fix-fileSystem-dock-wont-show-any-file-folders
Fix FileSystem dock won't show any file folders (v2)
2024-08-26 22:45:04 +07:00
A Thousand Ships 723f5500f4
[Core] Allow locking/unlocking of `MutexLock` 2024-08-26 12:38:03 +07:00
Pedro J. Estébanez f4d76853b9 WorkerThreadPool (plus friends): Overhaul unlock allowance zones
This fixes a rare but possible deadlock, maybe due to undefined behavior. The new implementation is safer, at the cost of some added boilerplate.
2024-08-21 12:22:52 +07:00
Pedro J. Estébanez df23858488 ResourceLoader: Fix edge cases in the management of user tokens
1. Make handling of user tokens atomic:
   Loads started with the external-facing API used to perform a two-step setup of the user token. Between both, the mutex was unlocked without its reference count having been increased. A non-user-initiated load could therefore destroy the load task when it unreferenced the token.
   Those stages now happen atomically so in the one hand, the described race condition can't happen so the load task life insurance doesn't have a gap anymore and, on the other hand, the ugliness that the call to load could return `ERR_BUSY` if happening while other thread was between both steps is gone.
   The code has been refactored so the user token concerns are still outside the inner load start function, which is agnostic to that for a cleaner implementation.
2. Clear ambiguity between load operations running on `WorkerThreadPool`:
   The two cases are: single-loaded thread directly started by a user pool task and a load started by the system as part of a multi-threaded load.
   Since ensuring all the code dealing with this distinction would make it very complex, and error-prone, a different measure is applied instead: just take one of the cases out of the dicotomy. We now ensure every load happening on a pool thread has been initiated by the system.
   The way of achieving that is that a single-threaded user-started load initiated from a pool thread, is run as another task.
2024-08-21 12:22:52 +07:00
Pedro J. Estébanez 5c970db2e4 ResourceLoader: Optimize remap check by deferring until a non-mutex zone 2024-08-21 12:19:43 +07:00
Pedro J. Estébanez 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 +07:00
Pedro J. Estébanez bd0959ebdd ResourceLoader: Properly push & pop TLS state on recursive load tasks 2024-08-21 12:19:43 +07:00
Rémi Verschelde 5ca419e32c
Merge pull request #94801 from gamelessone/fix-cond-var
Fix use-after-free of `ConditionVariable` in `ResourceLoader`
2024-08-21 11:14:22 +07:00
Hilderin 1b0c5cbc01 Fix FileSystem dock won't show any file folders (v2) 2024-08-20 21:23:13 +07:00
Rémi Verschelde 6a829d5a86
Merge pull request #95508 from Summersay415/loaded-when-not
Return error when no ResourceFormatLoader found
2024-08-19 14:34:17 +07:00
Pedro J. Estébanez e9407d4877 ResourceLoader: Revert workaround resource loading crashes due to buggy TLS
This reverts commit 41c0785636.
2024-08-19 12:22:31 +07:00
Rémi Verschelde f01e052162
Merge pull request #95549 from timothyqiu/split-translation-server
Split `TranslationServer` into its own file
2024-08-16 14:36:16 +07:00
Rémi Verschelde 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 +07:00
Haoyu Qiu 7343dc3a5d Split TranslationServer into its own file 2024-08-15 15:00:47 +07:00
Summersay415 6df3621b47 Return error when no ResourceFormatLoader found. 2024-08-14 11:45:23 +07:00
Pedro J. Estébanez 31a9e10ddb ResourceLoader: Use better error handling for possible engine bugs 2024-08-13 12:52:08 +07:00
Pedro J. Estébanez 17ea4b405a ResourceLoader: Fix error on querying progress for uncached loads 2024-08-13 12:41:11 +07:00
bruvzg f5bb14dceb
[ResourceLoader] Add check to prevent double free crashes. 2024-08-06 08:31:03 +07:00
Aleksey Vasenev 2ff6594928 Fix use condition_variable after free 2024-07-30 13:59:20 +07:00
Pedro J. Estébanez 5640e8adc9 ResourceLoader: Let resource setup late steps invoke loading in turn 2024-07-29 18:13:37 +07:00
Pedro J. Estébanez 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 +07:00
Pedro J. Estébanez 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 +07:00
Pedro J. Estébanez a426479b3f ResourceLoader: Fix error message due to already-awaited tasks being re-awaited 2024-07-08 12:19:44 +07:00
Pedro J. Estébanez 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 +07:00
Pedro J. Estébanez ec61c5064c ResourceLoader: Support polling and get-before-complete on the main thread 2024-06-28 11:25:10 +07:00
Pedro J. Estébanez c1391489e3 GDScript: Enhance handling of cyclic dependencies 2024-06-26 17:44:32 +07:00
Pedro J. Estébanez 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 +07:00
Rémi Verschelde 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 +07:00
Pedro J. Estébanez cc6f5d1a7a ResourceLoader: Let the caller thread use its own message queue override 2024-06-13 10:31:11 +07:00
Pedro J. Estébanez 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 +07:00
Pedro J. Estébanez bdcceef0e2 ResourceLoader: Avoid deadlock when awaiting a loader thread that failed early 2024-06-12 13:49:37 +07:00
Rémi Verschelde e4fa8543ea
Revert "Fix FileSystem dock won't show any file folders"
This reverts commit 72856d633a.

Fixes #93022.
2024-06-11 11:46:35 +07:00
Hilderin 72856d633a Fix FileSystem dock won't show any file folders 2024-06-10 19:54:37 +07:00
Rémi Verschelde 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 +07:00
ajreckof ca020ad8cd Fix load subtask not being registered leading to false progress values. 2024-04-13 01:42:29 +07:00
A Thousand Ships 64146cb7f3
[Core] Add iteration support to `Array` 2024-04-10 14:49:34 +07:00
A Thousand Ships 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 +07:00
Pedro J. Estébanez 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 +07:00
Pedro J. Estébanez 851f1d49d7 Remove spammy dev-mode message about load deadlock prevention 2024-02-23 14:54:03 +07:00
Muller-Castro a8bc9f3e78 Add const lvalue ref to core/* container parameters 2024-02-14 11:20:36 +07:00
Rémi Verschelde dc99c8d4a4
Merge pull request #87008 from KoBeWi/cache_mode_replace_fixes²
Fix² behavior of ResourceFormatLoader `CACHE_MODE_REPLACE`
2024-02-13 23:43:18 +07:00
vittorioromeo 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 +07:00
Rémi Verschelde 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 +07:00
Rémi Verschelde b65c495d6e
Merge pull request #86845 from RandomShaper/no_load_regress
Avoid regressing in progress reporting in resource load
2024-01-29 21:33:00 +07:00
Matthew Edwards 7565d1f3ab Push p_original_path into load_paths_stack and sub_tasks instead of p_path. 2024-01-29 17:27:57 +07:00
Rémi Verschelde dc79e956b6
Merge pull request #86587 from RandomShaper/wtp_enhance
Enhance & fix `WorkerThreadPool`
2024-01-11 17:38:09 +07:00
kobewi 2e09985c0d Fix² behavior of ResourceFormatLoader CACHE_MODE_REPLACE 2024-01-09 16:01:37 +07:00
Rémi Verschelde 9ca3d3ec83
Revert "Fix behavior of ResourceFormatLoader `CACHE_MODE_REPLACE`" 2024-01-09 10:49:14 +07:00
Pedro J. Estébanez 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 +07:00
Pedro J. Estébanez f5ca58d32f Avoid regressing in progress reporting in resource load 2024-01-05 19:33:58 +07:00
Yuri Sizov 2e94be2ea4 Merge pull request #84167 from SaracenOne/cache_mode_replace_fixes
Fix behavior of ResourceFormatLoader `CACHE_MODE_REPLACE`
2023-12-08 15:23:13 +07:00
Yuri Sizov 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 +07:00
Saracen f392a9c4f8 Fix CACHE_MODE_REPLACE 2023-11-15 18:55:20 +07:00
Rémi Verschelde 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 +07:00
Rémi Verschelde 2729a78fd7
Fix translation remapping check for imported resources
Fixes #81660.
2023-11-12 13:17:12 +07:00
kobewi a3627b6e37 Assign temporary path to preloaded resources 2023-11-10 00:43:30 +07:00
Haoyu Qiu dc7e309f48 Fix heap-use-after-free when resource loaded with load_threaded_request is never fetched
Co-authored-by: Pedro J. Estébanez <pedrojrulez@gmail.com>
2023-10-23 16:21:17 +07:00
A Thousand Ships 893f889d74 [Core] Replace `ERR_FAIL_COND` with `ERR_FAIL_NULL` where applicable 2023-09-11 19:45:49 +07:00
Yuri Sizov d8ff69d53c Extract ScriptInstance to simplify includes
This allows to include script_instance.h directly in the
generated gdvirtual.gen.inc, and remove excessive includes
from the codebase.

This should also allow Resource to use GDVIRTUAL macros,
which wasn't possible previously due to a circular dependency.
2023-09-06 22:54:38 +07:00
Hugo Locurcio 5bf64255b0
Mention expected resource type in ResourceLoader load error
This helps troubleshoot issues due to incorrect import types.
2023-07-21 04:45:34 +07:00
Rémi Verschelde cdd2313ba2
Merge pull request #78977 from RandomShaper/workaround_tls_shutdown
Workaround resource loading crashes due to buggy TLS
2023-07-03 19:43:07 +07:00
Pedro J. Estébanez 41c0785636 Workaround resource loading crashes due to buggy TLS 2023-07-03 13:54:55 +07:00
Pedro J. Estébanez 30925fcfb0 Fix management of safe-for-nodes flag in ResourceLoader and WorkerThreadPool 2023-07-03 12:27:57 +07:00
Pedro J. Estébanez 2b001db76e Let user scripts disable thread safety checks 2023-06-09 18:24:01 +07:00
Pedro J. Estébanez e725b4b02b Allow threads to mark themselves as safe for nodes 2023-05-24 00:22:58 +07:00
Pedro J. Estébanez c450260e3e Fix message queue issues
- Missing flush in resource loading.
- Wrong checks about message queue instance.
2023-05-19 13:11:34 +07:00
Pedro J. Estébanez a6e43f71b6 Avoid multiple possibilites of deadlock in resource loading 2023-05-17 01:52:39 +07:00
Pedro J. Estébanez 7537a0521f Simplify ResourceLoader error callbacks 2023-05-12 17:44:48 +07:00
Pedro J. Estébanez 045401c64e Use WorkerThreadPool for threaded resource loading 2023-05-10 18:53:41 +07:00
Pedro J. Estébanez 5a4613f551 Avoid sync issues in resources with deferred updates 2023-05-10 18:53:41 +07:00
Pedro J. Estébanez 8983b20ccd Avoid interaction issues between resource loading threads 2023-05-10 18:53:41 +07:00
Rémi Verschelde cef3587427
Merge pull request #74120 from RandomShaper/res_loader_teardown
Clear resource load tasks at exit
2023-04-03 15:59:51 +07:00
Rémi Verschelde bdb3738023
Merge pull request #74166 from RandomShaper/fix_res_loader_read_freed
Fix crash in resource load
2023-03-03 11:06:15 +07:00
Rémi Verschelde 4fceabc30c
Merge pull request #73862 from RandomShaper/fix_subthreaded_res_load
Lift restriction that resource load thread requester has to be the initiator
2023-03-02 11:26:54 +07:00
Pedro J. Estébanez 047671df0f Fix crash in resource load 2023-03-01 18:30:16 +07:00
Pedro J. Estébanez b8b6a05c17 Clear resource load tasks at exit 2023-02-28 18:56:21 +07:00
Pedro J. Estébanez b60197d1c6 Fix deadlock in cyclic resource load 2023-02-26 17:19:48 +07:00
Pedro J. Estébanez c51229491d Lift restriction that resource load thread requester has to be the initiator 2023-02-24 13:19:31 +07:00
Pedro J. Estébanez b862fc8c9b Fix cases of resource load tasks not being awaitable 2023-02-20 21:20:05 +07:00
Pedro J. Estébanez 618bb173ba Fix race condition in resource loader when a load task is reused 2023-02-20 21:20:05 +07:00
Raul Santos 9e9eac4676
Use enum instead of int in virtual methods return type 2023-01-31 19:06:49 +07:00
Rémi Verschelde ebd0b40f6e
Merge pull request #71687 from reduz/support-script-class-name-in-efs
Support script global resource name in EditorFileSystem
2023-01-21 16:54:23 +07:00
Juan Linietsky dddd8d43f6 Support script global resource name in EditorFileSystem
* Works for binary and text files.
* Makes EditorQuickOpen work with custom resources again.
* Information is cached and easily accessible.

Properly fixes #66179. Supersedes #66215 and supersedes #62417

**WARNING**: This required breaking backwards binary compatibility (.res and .scn files). Files saved after this PR is merged will no longer open in any earlier versions of Godot.
2023-01-21 14:19:27 +07:00
kobewi c0083e431b Cleanup unused engine code v2 2023-01-19 13:02:18 +07:00
Rémi Verschelde d95794ec8a
One Copyright Update to rule them all
As many open source projects have started doing it, we're removing the
current year from the copyright notice, so that we don't need to bump
it every year.

It seems like only the first year of publication is technically
relevant for copyright notices, and even that seems to be something
that many companies stopped listing altogether (in a version controlled
codebase, the commits are a much better source of date of publication
than a hardcoded copyright statement).

We also now list Godot Engine contributors first as we're collectively
the current maintainers of the project, and we clarify that the
"exclusive" copyright of the co-founders covers the timespan before
opensourcing (their further contributions are included as part of Godot
Engine contributors).

Also fixed "cf." Frenchism - it's meant as "refer to / see".
2023-01-05 13:25:55 +07:00
Adam Scott 4a16b8630e Fix `ResourceLoader::thread_load_tasks` crash 2022-12-07 16:59:10 +07:00
Rémi Verschelde 5947f22be9
Merge pull request #67578 from KoBeWi/GEDITOR
Unify usage of GLOBAL/EDITOR_GET
2022-10-31 13:15:58 +07:00
kobewi d06a8320e5 Simplify GDVIRTUAL_CALL calls 2022-10-19 00:05:48 +07:00
kobewi e48c5daddf Unify usage of GLOBAL/EDITOR_GET 2022-10-18 19:01:48 +07:00
Gilles Roudière 8aa904f56c Exposes ResourceFormatLoader.recognize_path to scripting 2022-10-11 12:35:27 +07:00
bruvzg 0103af1ddd
Fix MSVC warnings, rename shadowed variables, fix uninitialized values, change warnings=all to use /W4. 2022-10-07 11:32:33 +07:00
Rémi Verschelde 9b19a02f31
Merge pull request #63632 from dsnopek/fix-locale-remap-with-binary-resources-4.x
[4.x] Fix locale resource remapping with binary conversion on export
2022-08-08 20:03:23 +07:00
David Snopek 6bbc126c34 Fix locale resource remapping with binary conversion on export 2022-08-08 09:31:35 +07:00
PucklaMotzer09 b32b570d7a Show dependency warning when removing remaps and fallback if translation
remap does not exist
2022-08-03 12:31:29 +07:00
reduz 6236a688b7 Implement Feature Build Profiles
This PR is a continuation of #50381 (which was implemented exactly a year ago!)

* Add a visual interface to select which classes should not be built into Godot (well, they are built if something else uses them, but if not used the optimizer will remove them out).
* Add a detection system to scan the project and figure out the actual classes used.
* Added the ability for SCons to load build profiles.

Obligatory Screen:

A simple test with a couple of nodes in the scene resulted in a 25% reduction for the final binary size

TODO:

* Script languages need to implement used class detection (left for another PR).
* Options to disable servers or server functionalities (like 2D or 3D physics, navigation, etc). Are missing, that should also greatly aid in reducing binary size.
* Options to disable some modules would be desired.
* More options to disable drivers (OpenGL, Vulkan, etc) would be desired.

In general this PR is a starting point for more contributors to improve and enhance this functionality.
2022-07-22 10:53:23 +07:00
reduz e772b65d92 Remake resource thread safety and API
* Ensures thread safety when resources are destroyed.
* Simplified API by always forcing `ResourceCache::get_ref`, which needs less hacks and is fully thread safe.
* Removed RWLock for resources because its not possible to use for the new logic. Should not be a problem.

Supersedes #57533
2022-06-22 13:46:46 +07:00
Aaron Record 900c676b02 Use range iterators for RBSet in most cases 2022-05-19 12:09:16 +07:00
reduz 746dddc067 Replace most uses of Map by HashMap
* Map is unnecessary and inefficient in almost every case.
* Replaced by the new HashMap.
* Renamed Map to RBMap and Set to RBSet for cases that still make sense
  (order matters) but use is discouraged.

There were very few cases where replacing by HashMap was undesired because
keeping the key order was intended.
I tried to keep those (as RBMap) as much as possible, but might have missed
some. Review appreciated!
2022-05-16 10:37:48 +07:00