Ooops
October 24, 2021, 21:59:46

Author Topic: Threaded Loader Test NG with animated Shaders  (Read 1141 times)

Offline AntonM

  • Jr. Member
  • **
  • Posts: 2
Re: Threaded Loader Test NG with animated Shaders
« Reply #15 on: April 20, 2021, 14:07:30 »
For BlitzMax it is very important to know, that you CAN NOT load TImages (LoadImage()) in threads ... and if it works somehow -  avoid it!. So all the images I load are actually loaded as TPixmap (so just into RAM, not to the GPU/VRAM). Then they are marked for further "processing" and then the main thread has to load them into TImage if required. The slow part of "LoadImage()" is decoding the image file into a pixmap, not loading it into an image.
Why you can not load images in threads? LoadImage just loads the pixmap, and texture in video memory is created on the first render.
« Last Edit: April 20, 2021, 14:33:10 by AntonM »

Offline Derron

  • Hero Member
  • *****
  • Posts: 3674
Re: Threaded Loader Test NG with animated Shaders
« Reply #16 on: April 20, 2021, 17:22:09 »
Threads OTHER than the main thread cannot safely access the GPU (graphics context or whatever).

Maybe @Col can chime in here - having more knowledge on the innerts of max2d and the backend drivers.


bye
Ron

Offline col

  • Hero Member
  • *****
  • Posts: 601
Re: Threaded Loader Test NG with animated Shaders
« Reply #17 on: April 20, 2021, 17:43:20 »
AntonM is correct in that the texture isn't created until the first Draw* call is used. For the older APIs (BMax in general) all drawing must be done on the same thread that created the device/context via the Graphics command... For 99.99% of BMax users that would be the main thread.

Offline Krischan

  • Full Member
  • ***
  • Posts: 244
    • Krischan's Homepage
Re: Threaded Loader Test NG with animated Shaders
« Reply #18 on: April 20, 2021, 17:50:36 »
In other words: I have to live with the microstutters?
Kind regards
Krischan

Windows 10 Pro | i7 9700K@ 3.6GHz | RTX 2080 8GB]
My Blitzbasic Archive | Extrasolar Project | My Github projects

Offline Derron

  • Hero Member
  • *****
  • Posts: 3674
Re: Threaded Loader Test NG with animated Shaders
« Reply #19 on: April 20, 2021, 19:01:12 »
AntonM is correct in that the texture isn't created until the first Draw* call is used. For the older APIs (BMax in general) all drawing must be done on the same thread that created the device/context via the Graphics command... For 99.99% of BMax users that would be the main thread.

I am not sure why - but LoadImage in threads did not work for me that time (I would elsewise not have come up with the TPixmap usage "out of the blue").
so can you imagine another issue one could encounter there? So maybe situations in which the child-thread-created TImages would make trouble / are auto-uploaded to the GPU there.


@Krischan
Just find out what causes the micro stuttering ... eg by not loading the image but reusing the reference of an already loaded one ..


bye
Ron

Offline col

  • Hero Member
  • *****
  • Posts: 601
Re: Threaded Loader Test NG with animated Shaders
« Reply #20 on: April 21, 2021, 07:47:13 »
Not sure why that would happen. Does the NG SDL backend do anything different?

Offline Derron

  • Hero Member
  • *****
  • Posts: 3674
Re: Threaded Loader Test NG with animated Shaders
« Reply #21 on: April 21, 2021, 09:20:22 »
The time I wrote the threaded loader ... I was not using SDL then. Even was using vanilla for most stuff.

I do not know why - but there must be a reason to have used TPixmap, not TImage (as this would be another little shape-off performance-wise).


Edit: I found some mojolabs posts using tpixmap loading too - and replies stating that you could do LoadImage() in threads too. But I have one potential (albeit not overly often used :D) situation in which it would not work: If you load your assets _before_ the graphics context (eg. by calling "graphics 800,600") is created, TImage stuff cannot be loaded properly (it creates different context-specific objects - for GL and DirectX, SDL-GL, SDL-DX ,...)

Edit2: Col meanwhile had a look into the code and it seems no context is needed during "loading". So ... might be safe to do so.


bye
Ron
« Last Edit: April 21, 2021, 09:53:37 by Derron »

Offline Derron

  • Hero Member
  • *****
  • Posts: 3674
Re: Threaded Loader Test NG with animated Shaders
« Reply #22 on: April 21, 2021, 10:20:36 »
I stand corrected: my registry-image loader (run in threads) does LoadImage() too. I am not sure why my brain mixed that up with something - maybe it was not working properly in the past, or with some older NG version.
So excuse the false information.

Yet please be aware of not "drawing" from within threads - but this is something you might already have known before.


bye
Ron

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal