View Full Version : multi-thread question(about load res)

07-09-2014, 11:45 AM
When i load image or texture resource in one thread then use them in another thread, bug it can't work ,just draw same black rect.
How to solve?

Thanks for your time

07-10-2014, 11:15 AM
You cannot reliably upload to a GPU using different threads. It might work on some drivers, but not others.

Also there is no benefit in doing so. The CPU threads are separate to GPU cores. The driver does all the hard work, in choosing when and where to dispatch the upload.

Instead, you can load the image in a different thread, and have the main thread upload the image once loaded.

See Examples/Display/Thread for an example of how this is done.

07-10-2014, 12:12 PM
Thanks for your help.
I have to load lots of images and texture when start app,
So want to load them in another thread, and show progress bar in the main thread.
Load resource in main thread, show progress bar in other?

07-10-2014, 03:10 PM
Always draw from the main thread

07-14-2014, 03:06 AM
That's it, i have try create a displaywindow (for show progress bar) and draw in another thread when main thread loading res, it crashed.

but now i load res will cause gui stuck, about 10s:cry:.
can you give me some advice :)?

07-14-2014, 05:57 AM
My last comment said "Always draw from the main thread" :)

1) Create display window in main thread
2) Load the resource data (eg graphics) in the worker thread. BUT do not upload to the GPU in the worker thread. E.g. Only load the png as a pixelbuffer
3) Upload graphics in the main thread
4) Draw in the main thread.

The problem with uploading in the worker thread is as follows:
1) You need a different device context for the worker thread. Some OpenGL drivers do not support this, and crash (They allow sharing data with "worker display windows" and the "main window" but only when they use the same thread)
2) Or you need mutex locks around each group of gpu calls (this negates the usefulness of multithreading)

See http://msdn.microsoft.com/en-gb/library/windows/desktop/ff476891(v=vs.85).aspx for Direct3D

i.e. It's not worth the effort. IMHO, only use the GPU in the main thread. Only the CPU in worker threads.

07-14-2014, 06:58 AM
Okey, i see.
thank you very very very much for your help, :hat::hug:;