Multi threaded Loading

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Valmond
Posts: 308
Joined: Thu Apr 12, 2007 3:26 pm

Multi threaded Loading

Post by Valmond »

Hi everyone!

In my game I load things dynamically (Static meshes, skinmeshes, terrains, images etc.)
and of course the game freezez up when the loading occurs
so I'm looking into ways to remove those freezes using a loading-thread.


I've done some searches and if I understood correctly:
You can't mess with the scenegraph in another thread.
You can't load up textures or meshes to another scenemanager in another thread as different scenemanagers share caches.


So the question is, can you load up things in memory and let main thread add it to the scenegraph when it is done?

or can you have an invisible node (so that the draw calls won't be affected by it or by its childs) and load up things to it
(say a mesh+texture) in the loading-thread and when it is done, main thread can move the newly loaded data to the correct place?


Or maybe there is another way to do it?


Thanks!
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

There are two critical things in this process. One is the handling of the scene graph. You don't need two scene managers, because loading just the mesh (without adding a scene node) does not touch the scene graph. And AFAIK, the mesh cache is not that fragile.
Loading textures (which also happens in the mesh loading phase) does not work from different threads, though. Simply because the texture creation involves the GPU/hw driver as well. And there's no easy way around.
Valmond
Posts: 308
Joined: Thu Apr 12, 2007 3:26 pm

Post by Valmond »

Thanks for the answer hybrid!

I guess the most of the 'freeze' time concerning texture creation (but I can be wrong for sure)
goes to disk access and much less to the AGP/PCI-Express bus data transfer and other driver related things.
If that's so, is there a way to preload the texture into memory and then in
the main thread create the new texture from memory instead of from disk?
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

Yes, load an IImage instead of a texture. This will take them from disk but not put them into graphics memory, you can create the textures manually in the graphics thread.

Models (VBOs) are added and removed into GPU memory on the fly, so no need to worry about them. You may need to hack the mesh loaders to make sure they don't create textures though.
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
Valmond
Posts: 308
Joined: Thu Apr 12, 2007 3:26 pm

Post by Valmond »

Thanks bitplane !

So you can load meshes in the other thread without any problem except texture creation ?

I'll try out with models exported without textures (just UV) and see how it works out.
d3jake
Posts: 198
Joined: Sat Mar 22, 2008 7:49 pm
Location: United States of America

Post by d3jake »

It will be interesting to see if we could, at the end of this, add in a loader that will allow things to be rendered while a mesh is being loaded, removing the usual stall related to loading a mesh.
The Open Descent Foundation is always looking for programmers! http://www.odf-online.org
"I'll find out if what I deleted was vital here shortly..." -d3jake
drr00t
Posts: 14
Joined: Wed Aug 05, 2009 2:11 pm
Location: Brasilia/DF - Brasil

Post by drr00t »

Hi,

I very interest in this topic too, if we could implement this feature in irrlicht core as generic task based system multicore hardware could be detected and equivalent thread number created, it could be used in Filesystem, Scene paging, loading mesh, etc...

We could talk in Open development thread and design something.

What you think?
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

Sounds good, please start the thread with your ideas. I have some ideas but I'm not sure how to convert them into a design. I'm sure Hybrid will have some input too.
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
Valmond
Posts: 308
Joined: Thu Apr 12, 2007 3:26 pm

Post by Valmond »

First fast-try, very conclusive.

It might be the fact that I also added a 'max-time' (or bail-out-time if you want) to spend each frame in the create-mesh function though...
Post Reply