Creating Mesh from other thread

Piotrek

09-03-2015 14:04:58

Hi,
In my project I am creating Mesh manually, by creating ManualObject and then calling on method ConvertToMesh.
Because I am creating a lot of meshes dynamically, I tried to parallelise that task.
I moved that logic to separate thread and now I have dead lock.
Is there a way to parallelise creation of meshes?

Beauty

13-03-2015 20:30:35

ManualObjects are nice.
As far as I know they can only be created in relation to a SceneManager.
By this I suppose it hast to be created in the same thread.
I'm not shure, but I think so.

I don't know all the internals, but possibly all data are stored in the memory of the graphics card. In this case it could be possible that there would be no performance bost for creating ManualObject in parallel threads. Well, only thoughts. Possibly I'm wrong.

Ogre can be compiled in multi-threading mode. There were a few problems some years ago. Maybe they are solved now.
I think there was a discussion about building Mogre with in multi-threading mode. You can search for it.

Do you create many ManualObjects with less vertices or few ManualObjects with many vertices or both?

Do you create equal ManualObjects?
In this case you need only one mesh and can attach it multiple times to different SceneNodes.

If you need one ManualObject only for one SceneNode, you don't need to call ConvertToMesh().
In this case you can attach the ManualObject directly to the SceneNode.
Posibly you save some CPU without calling ConvertToMesh().

By the way:
If you just need to modificated objects, you don't need to re-create them.
Instead you can modify them. Either by updating single vertices or by delete/create whole sections of a ManualObject.

If the calculations for the vertices are very time consuming, you could calculate the positions in a separate thread. When the calculations are ready, you can create a ManualObject with the pre-calculated positions.

If you don't need to create objects on-the-fly you can create and save them to a mesh file. For later usage you just need to load them.

Oh, I got an idea.
You could create a second SceneManager in a second thread for mesh creation. The created meshes you can save to a RAM disk (or MemoryStream?). After this you can load the mesh from the main thread. This way should be possible for a couple of threads. On the other hand - if they all need access to the GPU memory, this could reduce the performance boost. Maybe do some performance tests to check this case.

Maybe something is useful for you.

Piotrek

22-04-2015 12:32:41

Hi,
thank you very much:)
Especially for the thing that I don't have to ConvertToMesh.

Actually I changed my approach. Currently I am dynamically creating vertex-buffers and index-buffers on other thread and then creating a Mesh object on main thread by filling hardware vertex buffers with data from them.

Do you create many ManualObjects with less vertices or few ManualObjects with many vertices or both?
I am creating many different meshes with a lot of vertices (although I have some memory issues, when I am refilling Mesh buffers with new data - I don't want to recreate whole Meshes to not raise GC to offen - after some time I got out of video memory :/ I will send another post with that).

Once again thanks for helping me :)

Beauty

27-04-2015 21:27:38

Thanks for your reply.
Nice to see that my suggestions were useful.

I suppose you know the sections feature.
It's nice when you want to re-create only a sub-part of a ManualObject.

I'm interested in your announced post about your project. Feel free to attach some screenshoots.