General

Reply

Making Graphics framework thread safe

Hey

 

Im trying to load assets in the background via a separate thread but the graphics framework isn't thread safe and crashes when i try to load a texture or using anything in the graphics framework. How do i go about making this so?

Please use plain text.

Level 6

Level 6
AlexMcDev
Posts: 1,221
Registered: ‎19-04-2012
Message 2 of 18 (395 Views)

Re: Making Graphics framework thread safe

Hi:

 

Did you try using mutex( c# lock(<variable name>) ) between the graphics calls? I know this could be slow but could work, and of course doing only when all other subsystem are running not when rendering.

 

Cheers,

Please use plain text.

Re: Making Graphics framework thread safe

Hi Infinite_Daremo,

 

Multi-threading on the graphics framework is currently not supported. For this reason, all your graphics calls have to be on the same thread.

 

 


PlayStation®Mobile Dev Team
I am like you, I have no name.
Please use plain text.

Level 6

Level 6
AlexMcDev
Posts: 1,221
Registered: ‎19-04-2012
Message 4 of 18 (364 Views)

Re: Making Graphics framework thread safe

Hi:

 

Correct me if I'm wrong, but if he use locking and make a call from other thread and that thread use exclusive calls(mutex lock-unlock) on texture creation that will work. Is not at the same time but is loading data when doing other stuff like game update (physics/game logics/ etc etc). Ex:

 

Thread1 : running game logic update(nothing related with graphics);

Thread2: calling texture creation(only on this thread);

 

of course is possible that this hung too but...I need to review this again....

 

Cheers

Please use plain text.

Re: Making Graphics framework thread safe

Is there an alternative for background loading?

 

All my assets load in around 2 seconds anyways but there are other games im due to port which utilize background loading heavily.

Please use plain text.

Level 6

Level 6
AlexMcDev
Posts: 1,221
Registered: ‎19-04-2012
Message 6 of 18 (354 Views)

Re: Making Graphics framework thread safe

Hi:

 

Since you can create textures using byte arrays, load them as streams(not png) and then in the main thread create the textures, but I'm sure that the other idea could work. Did you try it?

 

Cheers,

Please use plain text.

Re: Making Graphics framework thread safe

I tried it in a basic project and it still crashed. Its the Texture2D constructor where it crashes which doesnt need the context. I tried updating in a separate thread and leaving rendering on the main thread but its still the same issue with loading being on a separate thread.

Please use plain text.

Level 6

Level 6
AlexMcDev
Posts: 1,221
Registered: ‎19-04-2012
Message 8 of 18 (340 Views)

Re: Making Graphics framework thread safe

Hi:

 

Strange because I made a quick test today and works. I still sugest you to use a mutex on both resource manager and rendering,, did you us a kind of threadpool manager?

 

Cheers,

Alex

 

 

Please use plain text.

Re: Making Graphics framework thread safe

Ill give it another go. Haven't had much chance to play with it as the porting of the game is the higher priority as opposed to a 2 second load hang on the splash screen.

Please use plain text.

Re: Making Graphics framework thread safe

Please let us know the outcome of your test . In theory, you should be able to load all your Texture2D images on a seperate thread and pass them to your main thread when you need it.

 

If you still have the same problem, please feel free to post or pm me some code and we can investigate it further.

 

 

PlayStation®Mobile Dev Team
I am like you, I have no name.
Please use plain text.
Announcements

Welcome to the PlayStation Mobile Developer Forums


This is a community for the discussion of technical topics with other developers and SCE engineers. Posting ideas/requests are also appreciated. Join the discussion!

PlayStation®Mobile開発者フォーラムでは世界中の開発者の皆様と一緒に、議論や情報交換が可能です。SCEも議論に参加し、皆様の開発をサポートします。アイデアやリクエストも大歓迎です。ぜひご参加ください。

PSM Developer Registration (for free) on PSM DevPortal is required to post on the forum.
Please sign out then sign in again to the forum and PSM DevPortal after you have completed the registration.

フォーラムへ投稿をするにはPSM DevPortalへの登録(無料)が必要です。
登録後はフォーラムと PSM DevPortalを一度ログアウトし、再度ログインしてください。