OGRE Using the new threading scheme

来源:互联网 发布:java小技术分享 编辑:程序博客网 时间:2024/06/05 10:34
by JeDi » Wed Nov 19, 2008 4:56 pm
Hi,

I upgraded to Ogre 1.6, and want to make use of the new threading scheme (OGRE_THREAD_SUPPORT = 2). We have a fairly complex resource system on top of Ogre (because we use our "engine" on a lot of systems, some not using Ogre, some not even graphical), so we have our own background thread doing paging and resource loading.

I just used to call SceneManager::createEntity in our background thread, because I had full threading enabled in our previous version. But I want to do it properly now. The resources are downloaded from a server on the fly. I want to process the meshes, materials and textures in the background thread. What would be the proper way to do this?

I can't find a lot of information/documentation about this subject, but my idea for now is to create the resources in our background thread, and also call Resource::prepare there. Then queue the entity with a mutex around the queue, and process it in a frame listener (so in the main thread). Does this sound OK, or am I thinking in a very wrong direction?

Any help appreciated.

Greetz,
JeDi
JeDi
Gnome
 
Posts: 351
Kudos: 3
Joined: 21 Oct 2004
Location: Diepenbeek, Belgium
  • Website
Top

Postbysinbad » Wed Nov 19, 2008 7:51 pm

In OGRE_THREAD_SUPPORT = 2 mode, only the 'preparation' of resource data should be in a thread other than the graphics thread. That means cacheing data from the filesystem or from some other slow medium, or calculating the data if it's procedural. It's important that nothing in that separate thread can create any GPU resources - that is the essence of OGRE_THREAD_SUPPORT = 2, in that the graphics API (D3D, GL) can continue to run in single-threaded mode with no locks, which is considerably faster than the situation with OGRE_THREAD_SUPPORT = 1, which let you create GPU structures if you wanted but therefore required the graphics API to be fully threadsafe, which has an overhead.

The original discussion about this is here: http://www.ogre3d.org/phpBB2/viewtopic. ... ght=thread

Blog | Twitter

sinbad
OGRE Founder (Retired)
 
 
Posts: 25862
Kudos: 61
Joined: 06 Oct 2002
Location: Guernsey, Channel Islands
  • Website
Top

PostbyJeDi » Wed Nov 19, 2008 9:19 pm

Thanks, that confirms that my thoughts were on the right track.

I'm still getting used to this. I parse the material and prepare the mesh in the background thread and then queue the entity so that it is created in the graphics thread. Will it work that way? Or do I have to explicitly load the mesh first? I guess I have to queue destroying the entities (when they're paged out) too?

Edit I implemented it this way, and it works perfectly. A lot smoother than with full threading! Thanks a lot for these improvements!
 
http://www.ogre3d.org/forums/viewtopic.php?f=5&t=45943
原创粉丝点击