Volumes Of Fun
http://www.volumesoffun.com/phpBB3/

Threads and LargeVolume Paging
http://www.volumesoffun.com/phpBB3/viewtopic.php?f=14&t=279
Page 2 of 2

Author:  David Williams [ Fri Oct 21, 2011 9:34 pm ]
Post subject:  Re: Threads and LargeVolume Paging

@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.

Author:  DefiniteIntegral [ Sat Oct 22, 2011 3:16 am ]
Post subject:  Re: Threads and LargeVolume Paging

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.

Author:  GM_Riscvul [ Sat Oct 22, 2011 11:01 pm ]
Post subject:  Re: Threads and LargeVolume Paging

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.

Page 2 of 2 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/