It is currently Sat Aug 22, 2020 3:36 pm


All times are UTC




Post new topic Reply to topic  [ 13 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: Threads and LargeVolume Paging
PostPosted: Fri Oct 21, 2011 9:34 pm 
Developer
User avatar

Joined: Sun May 04, 2008 6:35 pm
Posts: 1827
@ker - Thanks for sorting that out... it's good to know it's not an issue with PolyVox.

@GM_Riscvul - It sounds like you are trying to create your manual object from your extraction thread rather than your main thread. You probably can't do that as Direct3D9/OpenGL2 hardware (and hence Ogre) requires that all GPU operations be performed from the main thread. I suspect your manual objects need to be built on the same thread that created the Ogre::Root object, though maybe you can consult the Ogre documentation for the exact rules.

You probably need to pass your extracted meshes back to the main thread for this purpose. Also have a look at section 3.4.3 of my book chapter.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Threads and LargeVolume Paging
PostPosted: Sat Oct 22, 2011 3:16 am 

Joined: Sun Jan 23, 2011 6:06 am
Posts: 92
If you are using Ogre, your implementation for creating ManualObject's will need to vary depending on whether you plan to use OpenGL.

For OpenGL, the vertex buffers need to be created / destroyed in the main thread. If you are only using DirectX9 and not OpenGL, you can create/destroy the vertex buffers in a separate thread.

However, Ogre isn't very thread safe. I have found I need to wrap Ogre in a mutex and lock it anytime I access Ogre at all. So I lock it for accessing the scene graph, as well as creating and destroying objects, or altering the viewport, etc etc.

If you are creating a new ManualObject for each mesh, you can do this:

-lock ogre mutex
-create manual object
-set manual object dynamic FALSE
-unlock ogre mutex
-begin
-specify number of vertices
-specify number of indices
-add vertices
-add indices
-lock ogre mutex
-end
-unlock ogre mutex

The first lock/unlock is required because it allocates memory in the ogre scene manager and can create an access violation. The second is required because it allocates vertex buffers in video memory and an access violation will hang the rendering context and ogre will crash.

If you set manualobject's dynamic flag to TRUE though, you would need to lock the entire begin/end sequence since calling position() can make changes to vertex buffer as well.


Top
Offline Profile  
Reply with quote  
 Post subject: Re: Threads and LargeVolume Paging
PostPosted: Sat Oct 22, 2011 11:01 pm 
User avatar

Joined: Tue Feb 22, 2011 8:04 am
Posts: 101
Thank you for the replies. This isn't even an ogre forum and everyone has provided more information than the ogre forum has in over a week. I still haven't had a reply there yet.

I did some testing and it is exactly as everyone has stated. OpenGL due to its state machine architecture is incredibly bad with threading. I altered my MeshManager class to create but not end the manual objects, and left that task to the main thread. This has solved most of my threading problems.

I store the un-ended manual objects in a queue and had the MeshManager class inherit from Ogre's FrameListener Class. If the queue's size is greater than zero the main ogre thread pulls out a manual object during a frameRenderingQueued event, ends it, and attaches it to the scene.

This appears to work, and makes sense in my mind, but I still have a few errors left. Some areas never show up although the FPS monitor makes it clear meshes are being added and decimated as I see FPS drops followed by a speedup over time. I suppose such drops could be caused by other problems, but they are consistent with what I have experienced in the past.

Hopefully They will be ironed out soon. Thanks again for the help, and if you see in errors in my algorithm above, feel free to point them out.

_________________
--Real Programmers use a magnetized needle and a steady hand.
--xkcd--


Top
Offline Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ]  Go to page Previous  1, 2

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme created StylerBB.net