Jump to content

Creating entity on other thread


L B
 Share

Recommended Posts

I have managed to enable simple multi-threading by using a lock, or mutual-exclusion (mutex) system. Basically, I lock around all Leadwerks commands, so that none of them can be called at the same time, and forcing them to execute sequentially.

 

This works really well for all commands. Except for the ones which create an entity, be it a body, model, mesh, light, etc.I'm wondering why that occurs, but most importantly, how can I truly create an entity on another thread.

 

I know I could invoke the entity to be created on the main thread (using a delegate that gets executed at the next loop), and this is the approach I've used so far. However, for many reasons, I would like to create entities on other threads.

 

How can I *truly* create entities on other threads without Leadwerks crashing?

Link to comment
Share on other sites

Strange, your approach with locking should work just fine... You could also use a concurrent_queue and load everything from your main thread. Just push_back everywhere you need it, and try_pop on the main thread.

You're suggesting C/++ methods to the wrong guy. :)

 

Besides, I did have a queue on the main thread to work so far, but that turned out limiting after a while. So I really need to actually load the models on another thread. No fake, no almost.

Link to comment
Share on other sites

Mm. Josh never said anything about it though. His answer seems to be that we always have to call Leadwerks methods on the main thread - which is false, with proper synchronization, only LoadModel seems to be failing right now.

 

Maybe Mika could help us figure a workaround with the source?

Link to comment
Share on other sites

The main problem seems to be that the other threads don't have an active OpenGL canvas or driver, so for example LoadTexture fails because the maximum texture size is 0 (instead of 8192 like on the main thread).

 

However, when I preload and free the models in the main thread first, then it works also on the other threads:

FreeEntity(LoadMesh("oildrum.gmf"));
FreeEntity(LoadMesh("mushroom.gmf"));

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

The main problem seems to be that the other threads don't have an active OpenGL canvas or driver, so for example LoadTexture fails because the maximum texture size is 0 (instead of 8192 like on the main thread).

 

However, when I preload and free the models in the main thread first, then it works also on the other threads:

FreeEntity(LoadMesh("oildrum.gmf"));
FreeEntity(LoadMesh("mushroom.gmf"));

How did changing the memory structure as we discussed the other day work out?

Link to comment
Share on other sites

It had nothing to do with memory structure. It's just that OpenGL doesn't return anything useful on other threads if it's not done first on thread which creates the graphics window. Even when I hardcoded the maximum texture size to 8192, it still failed on the OpenGL compileshader command. Klepto2 said it has something to do with FBOs.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

It's amusing that both you and Metatron are attempting this simultaneously.

 

He's shown proof of concept, which means that it's possible for other languages (C#) to do it!

The modification(s) to be done is(/are) in the engine DLL, hence why Metatron has to do it. And then, from that point, any language could use it.

Link to comment
Share on other sites

It's amusing that both you and Metatron are attempting this simultaneously.

I tried multithreading earlier without mutex locking, but then it crashed on every LE2 command, so I didn't investigate further.

 

Now Lazlo showed that actually all commands work with mutex locking, except the one's which are using buffers/FBO's.

 

And those remaining commands work also when they are first used from the same thread which created the Graphics window,

so even in this state it's already useful, but the ultimate goal would be of course to have FBO's working on all threads without preloading.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

I tried multithreading earlier without mutex locking, but then it crashed on every LE2 command, so I didn't investigate further.

 

Now Lazlo showed that actually all commands work with mutex locking, except the one's which are using buffers/FBO's.

 

And those remaining commands work also when they are first used from the same thread which created the Graphics window,

so even in this state it's already useful, but the ultimate goal would be of course to have FBO's working on all threads without preloading.

Any update on this? I personnally humbly admit I cannot help at all.

Link to comment
Share on other sites

Nope, I think this is as good as it gets with LE2.

But it's quite nice, as now I can make an animated loader screen while the scene is loading, and I'll add that to my Guess A Number game too.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...