Results 1 to 7 of 7

Thread: multi-thread question(about load res)

  1. #1

    Default multi-thread question(about load res)

    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

  2. #2
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    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.

  3. #3

    Default

    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.
    or
    Load resource in main thread, show progress bar in other?
    Last edited by kyelin; 07-10-2014 at 02:14 PM.

  4. #4
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    Always draw from the main thread

  5. #5

    Default

    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.
    can you give me some advice ?

  6. #6
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    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/libr...(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.

  7. #7

    Default

    Okey, i see.
    thank you very very very much for your help, ;
    Last edited by kyelin; 07-17-2014 at 11:07 AM.

Similar Threads

  1. Replies: 2
    Last Post: 12-23-2011, 07:50 AM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •