-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Removed ResourceInteractiveLoader, add built-in threaded loading. #36640
Conversation
What if I want to load as fast as possible without affecting the game performance? |
Will that allow for something like 'level-streaming' in background functionality? |
There's a tradeoff here 🙂 When you load resources in the background, start as early as possible so you never have to stall the main thread to wait for a resource to finish loading. Other than that, I don't think much can be done about it.
This is what |
What about multi-threaded resource loading in editor? |
@KoBeWi The problem is that there is no real metric for this. You can control how much it may affect game performance by the number of threads used, but this is entirely different on each hardware, so in the end the only "safe" value is to just use threads or don't use them. |
@qarmin could eventually happen i suppose. Once this is well tested, it can be enabled. |
2a98426
to
475e4ea
Compare
Forget it, just realised my error. This obviously makes no sense when you have a game that is CPU capped without introducing weird stuff like fps caps. |
@jejay I really prefer to not have to play with thread priorities nowadays. It just opens a different can of worms. Generally the high amount of cores and schedulers make sure everything more or less works ok,and in most operating systems the main UI or rendering thread already is given more priority so for now I would prefer to not get into that stuff. On iOS as an example, you can start having problems using spinlocks if you have threads of too high or low priority. |
Thanks! |
I didn't see that any documentation was added with the addition of these 3 methods. Any plans on making that happen? @reduz |
Really great improvement, but
Makes me a bit suspicious. Is it a real deadlock? It is very bad and A runtime error, or at least warning would be way better - if not better get rid of that behavior. |
@reduz, with your proposed implementation, the user would have to continuously poll the progress of the loading process before they're safely able to get the resource (without blocking their main process). |
@aspenforest A signal may be a bit complex, but with the new callable API, maybe you can just specify a function to get called when it's done. The only downside to this is that it will be called on the main thread. May be enough, though. |
load_threaded_request |
This is a Godot 4.0 feature. |
How does this work with OpenGL contexts that may only be active in a single thread at a time? As far as I can tell, calls like glTexImage will fail in a separate thread without additional preparation. And the ideal solution would be to fully load resources in a separate thread, i.e. GPU stuff should be available for use on the GPU. This would require special synchronization calls both in OpenGL and Vulkan and I don't see such things here, so I wonder how this works. From what I see these calls are not even directly available in GLES2, but Android and iOS provide their own ways to resolve this (Android via EGL, Apple via extensions that mimic GLES3). All in all, it seems there still a lot of work to do before actual multithreaded resource loading is there. At the sime time, the "interactive loader" was already removed, and it was the main means of loading a scene in chunks, providing more granular feedback of the loading progress to the user. |
This is cool. But the API is very weird. Why not use an |
@PranavSK Please open a proposal on the Godot proposals repository to request improvements. |
Any chance of this making it over to 3.x? :D I keep running into bizarre issues using multithreading with loading in gdscript. Now I'm having to do scary things like add a 1 second delay to avoid errors and crashes, but I don't feel good about it. |
This relies on core refactoring (and breaks compatibility with existing projects), so it can't be backported to |
ResourceInteractiveLoader was an old vestige of the past, when Godot was aimed mainly at devices that only had one processor, like mobile, low end desktops and some consoles.
Godot has supported loading of resources on threads since a long time, so this old method of loading was obsolete.
In exchange, a new set of functions were added:
First, a thread loading process is requested. It can be a single thread or multiple threads. If you want to focus on loadig times (load as fast as possible), then multiple threads can be specified. If you wan to focus on not affecting the game performance (just background load), then single threaded mode can be specified.
Status can be requested at any time by calling:
Optionally, progress can be retrieved from the status, too:
Finally, when status is complete (ResourceLoader.THREAD_LOAD_LOADED), the resource can be obtained:
Calling the above function before thread is done loading will just result in blocking the current thread until the resource has finished loading.
This is a very useful feature because it allows the common pattern of start loading something (like, the first level while on the intro and title screen), and the block until completion, severely reducing load times in games.
It is important to not block the main game thread during this process, else the engine will deadlock. If you want your loading to happen entirely on the main thread, use the old
ResourceLoader.load()
funciton, don't use these.Using threaded loading in my tests resulted in an improvement of 4x to 6x times faster loading.