support gl contexts with multithread?

96 views
Skip to first unread message

jinkun xv

unread,
Sep 12, 2023, 1:27:55 AM9/12/23
to angleproject
Hello!
  now I have this requirement: I want to create 2 thread that each one has a EGLContext and  each EGLContext is shared with others(from same display),an this 2 thread:
   thread 1: use gl opers to generate a texture ant push to thread 2
   thread 2: recv texture frome thread 1 and use gl opers draw a new texture

however I failed!
I use DirectX11 backend !
I look into the angle code and find that 
   DisplayD3D:

        ->Render11

            ->StateManager11

               ->VertextDataManager

                ->IndexDataManager

                ->InputLayoutCache


Context11

    ref Render11

like this,DisplayD3D object has a Render11 and Render11 own a StateManager which hold the draw states.and Context!! just has a ref of Render11 from display ,so even thought I create a EGLContext for each thread,but render just use one stateManger and multi thread render become invalid!


now I'm not sure that can angle satify my requirement or I have wrong usage on angle?

Anyone knows?


jinkun xv

unread,
Sep 12, 2023, 1:54:07 AM9/12/23
to angleproject
both thread 1 and thread 2 use shader and gl draw call to generate/update texture data

Shahbaz Youssefi

unread,
Sep 12, 2023, 5:56:41 AM9/12/23
to angleproject
Hi,

Currently, only the Vulkan backend of ANGLE is thread safe. With the other backends, please use only a single thread.

Sorry for the inconvenience.

P.S. When using multiple threads like in the scenario above, don't forget that you need a fence to synchronize texture uploads with their use. That is, glFenceSync() after the texture uploads and glWaitSync() (+ rebind the textures) on the other thread before they are used. Otherwise that's invalid GL and rendering would be racy.

jinkun xv

unread,
Sep 12, 2023, 6:37:16 PM9/12/23
to angleproject
Maybe I didn't describe it clearly, I just want to share textures in 2 threads,one product texture(use shader),one use this texture to draw.but it seems impossible because it always crash, I'm not sure whether my illegal usage or angle not support this on directX backend.

here is my backtrace below.
I have use fence already,the backtrace below show it's crashing seem not related to the texture fence,mExecutableD3D is nullptr in my bt,this value set to nullptr on onMakeCurrent() , this function call on context switch, it seems that contextes switch on multithread cause this crash.

Please help me.
Thank you!

bt.png

Shahbaz Youssefi

unread,
Sep 12, 2023, 7:16:06 PM9/12/23
to angleproject
Right, as I mentioned, the d3d backend does not support multiple threads, so anything could happen.

Regarding the exact crash, if you 2 contexts on 2 threads, you shouldn't need to eglMakeCurrent() all the time; just once at the beginning of each thread. If the executable is nullptr, it's a case where there is no (successfully-linked) program bound to the context.

Reply all
Reply to author
Forward
0 new messages