Author Topic: JPCT-AE MultiThreading  (Read 5290 times)

Offline karoshi

  • byte
  • *
  • Posts: 6
    • View Profile
JPCT-AE MultiThreading
« on: March 19, 2014, 07:31:41 am »
Dear,
I 've used an other thread to load model 3d into JPCT-AE world. However, Rendering is still blocked at render time 1st(we can see 1st frame) until finishing loading.
The way I do:
1. Start loading data thread at onSurfaceCreate
//Create world
new Thread(new Runable(){
//Load 3ds model which has not been used at starting time yet.
}).start();
2. DrawFrame: Normal update world(example move Camera). It should be not blocked by data loading, it means other data should be updated normally.

I don't understand why, please help

Thank you.
 


Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: JPCT-AE MultiThreading
« Reply #1 on: March 19, 2014, 10:52:29 am »
Can you give more details on where exactly the render thread blocks? It might happen because the actual loading code in Loader is synchronized and it is used to load the shader files, so doing this in parallel to the file loading might block the thread.

Offline karoshi

  • byte
  • *
  • Posts: 6
    • View Profile
Re: JPCT-AE MultiThreading
« Reply #2 on: March 26, 2014, 09:59:01 am »
I got 1st frame rendered, then no update until loading finished.
What do you mean "shader files"?
I saw only  connection between 2 thread(loading and render) is world:
 + In Loading Thread: Add new object to world if any ready loaded
+ In Render Thread: Render world

Do you think world is blocked during Loading thread running?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: JPCT-AE MultiThreading
« Reply #3 on: March 26, 2014, 10:50:13 pm »
The shader files are loaded using the same loader that loads the objects and it might block, because the loader internally only processes one request at a time because of shared resources. However, i don't see how this should apply here. Can you provide me with a test case?

Offline rainfalls

  • byte
  • *
  • Posts: 27
    • View Profile
Re: JPCT-AE MultiThreading
« Reply #4 on: April 02, 2014, 08:12:47 pm »
I got 1st frame rendered, then no update until loading finished.

In my experience, this "no update" problem has nothing to do with multi-threading.

When some new models are *dynamically* added into a world, there are always a lot of compiling(?) work happens on the first render of this model, which can "freeze" the current frame for some time, depending on how complex the model(s) are.

I doubt your situation might be the same to mine.

I don't know if this can be avoided. Maybe Egon has some better understanding/solution on this?

Code: [Select]
04-02 19:03:14.461: I/jPCT-AE(30592): Subobject of object 3/object5 compiled to indexed fixed point data using 6/4 vertices in 1ms!
04-02 19:03:14.461: I/jPCT-AE(30592): Object 3/object5 compiled to 1 subobjects in 1ms!
04-02 19:03:14.481: I/jPCT-AE(30592): Subobject of object 4/object6 compiled to indexed fixed point data using 1182/226 vertices in 18ms!
04-02 19:03:14.481: I/jPCT-AE(30592): Object 4/object6 compiled to 1 subobjects in 24ms!
04-02 19:03:14.481: I/jPCT-AE(30592): Subobject of object 5/object7 compiled to indexed fixed point data using 6/4 vertices in 1ms!
04-02 19:03:14.481: I/jPCT-AE(30592): Object 5/object7 compiled to 1 subobjects in 1ms!
04-02 19:03:14.481: I/jPCT-AE(30592): Subobject of object 6/object8 compiled to indexed fixed point data using 387/130 vertices in 2ms!
04-02 19:03:14.481: I/jPCT-AE(30592): Object 6/object8 compiled to 1 subobjects in 2ms!
04-02 19:03:14.491: I/jPCT-AE(30592): Subobject of object 7/object9 compiled to indexed fixed point data using 192/94 vertices in 6ms!
04-02 19:03:14.491: I/jPCT-AE(30592): Object 7/object9 compiled to 1 subobjects in 8ms!
04-02 19:03:14.501: I/jPCT-AE(30592): Subobject of object 8/object10 compiled to indexed fixed point data using 1548/313 vertices in 7ms!
04-02 19:03:14.501: I/jPCT-AE(30592): Object 8/object10 compiled to 1 subobjects in 10ms!
04-02 19:03:14.501: I/jPCT-AE(30592): Subobject of object 9/object11 compiled to indexed fixed point data using 192/66 vertices in 2ms!
04-02 19:03:14.501: I/jPCT-AE(30592): Object 9/object11 compiled to 1 subobjects in 2ms!
04-02 19:03:14.511: I/jPCT-AE(30592): Subobject of object 10/object12 compiled to indexed fixed point data using 192/66 vertices in 1ms!
04-02 19:03:14.511: I/jPCT-AE(30592): Object 10/object12 compiled to 1 subobjects in 1ms!
04-02 19:03:14.511: I/jPCT-AE(30592): Subobject of object 11/object13 compiled to indexed fixed point data using 18/12 vertices in 0ms!
04-02 19:03:14.511: I/jPCT-AE(30592): Object 11/object13 compiled to 1 subobjects in 0ms!
04-02 19:03:14.511: I/jPCT-AE(30592): Subobject of object 16/object18 compiled to indexed fixed point data using 168/112 vertices in 1ms!
04-02 19:03:14.511: I/jPCT-AE(30592): Object 16/object18 compiled to 1 subobjects in 1ms!
04-02 19:03:14.511: I/jPCT-AE(30592): Subobject of object 18/object20 compiled to indexed fixed point data using 168/112 vertices in 1ms!
04-02 19:03:14.511: I/jPCT-AE(30592): Object 18/object20 compiled to 1 subobjects in 1ms!
04-02 19:03:14.511: I/jPCT-AE(30592): Subobject of object 21/object23 compiled to indexed fixed point data using 360/78 vertices in 1ms!
04-02 19:03:14.511: I/jPCT-AE(30592): Object 21/object23 compiled to 1 subobjects in 2ms!
04-02 19:03:14.511: I/jPCT-AE(30592): Object 'object23' uses one texture set!
04-02 19:03:14.511: I/jPCT-AE(30592): Subobject of object 22/object24 compiled to indexed fixed point data using 360/78 vertices in 1ms!
04-02 19:03:14.511: I/jPCT-AE(30592): Object 22/object24 compiled to 1 subobjects in 2ms!
04-02 19:03:14.511: I/jPCT-AE(30592): Object 'object24' uses one texture set!
04-02 19:03:14.521: I/jPCT-AE(30592): Subobject of object 23/object25 compiled to indexed fixed point data using 360/78 vertices in 2ms!
04-02 19:03:14.521: I/jPCT-AE(30592): Object 23/object25 compiled to 1 subobjects in 3ms!
04-02 19:03:14.521: I/jPCT-AE(30592): Object 'object25' uses one texture set!
04-02 19:03:14.521: I/jPCT-AE(30592): Subobject of object 24/object26 compiled to indexed fixed point data using 360/78 vertices in 1ms!
04-02 19:03:14.521: I/jPCT-AE(30592): Object 24/object26 compiled to 1 subobjects in 2ms!
04-02 19:03:14.521: I/jPCT-AE(30592): Object 'object26' uses one texture set!
04-02 19:03:14.521: I/jPCT-AE(30592): Subobject of object 25/object27 compiled to indexed fixed point data using 360/78 vertices in 2ms!
04-02 19:03:14.521: I/jPCT-AE(30592): Object 25/object27 compiled to 1 subobjects in 3ms!
04-02 19:03:14.521: I/jPCT-AE(30592): Object 'object27' uses one texture set!
04-02 19:03:14.521: I/jPCT-AE(30592): Subobject of object 26/object28 compiled to indexed fixed point data using 360/78 vertices in 2ms!
04-02 19:03:14.521: I/jPCT-AE(30592): Object 26/object28 compiled to 1 subobjects in 2ms!
04-02 19:03:14.521: I/jPCT-AE(30592): Object 'object28' uses one texture set!
04-02 19:03:14.531: I/jPCT-AE(30592): Subobject of object 27/object29 compiled to indexed fixed point data using 360/78 vertices in 2ms!
04-02 19:03:14.531: I/jPCT-AE(30592): Object 27/object29 compiled to 1 subobjects in 2ms!
04-02 19:03:14.531: I/jPCT-AE(30592): Object 'object29' uses one texture set!
04-02 19:03:14.531: I/jPCT-AE(30592): Subobject of object 28/object30 compiled to indexed fixed point data using 360/78 vertices in 2ms!
04-02 19:03:14.531: I/jPCT-AE(30592): Object 28/object30 compiled to 1 subobjects in 3ms!
04-02 19:03:14.531: I/jPCT-AE(30592): Object 'object30' uses one texture set!
04-02 19:03:14.531: I/jPCT-AE(30592): Subobject of object 29/object31 compiled to indexed fixed point data using 360/78 vertices in 2ms!
04-02 19:03:14.531: I/jPCT-AE(30592): Object 29/object31 compiled to 1 subobjects in 2ms!
04-02 19:03:14.531: I/jPCT-AE(30592): Object 'object31' uses one texture set!
04-02 19:03:14.531: I/jPCT-AE(30592): Subobject of object 30/object32 compiled to indexed fixed point data using 360/78 vertices in 1ms!
04-02 19:03:14.531: I/jPCT-AE(30592): Object 30/object32 compiled to 1 subobjects in 2ms!
04-02 19:03:14.531: I/jPCT-AE(30592): Object 'object32' uses one texture set!
04-02 19:03:14.541: I/jPCT-AE(30592): Subobject of object 14/object16 compiled to indexed fixed point data using 1500/371 vertices in 7ms!
04-02 19:03:14.541: I/jPCT-AE(30592): Object 14/object16 compiled to 1 subobjects in 10ms!
04-02 19:03:14.541: I/jPCT-AE(30592): Object 'object16' uses one texture set!
04-02 19:03:14.551: I/jPCT-AE(30592): Subobject of object 33/object35 compiled to indexed fixed point data using 168/112 vertices in 1ms!
04-02 19:03:14.551: I/jPCT-AE(30592): Object 33/object35 compiled to 1 subobjects in 1ms!
04-02 19:03:14.551: I/jPCT-AE(30592): Subobject of object 35/object37 compiled to indexed fixed point data using 360/78 vertices in 2ms!
04-02 19:03:14.551: I/jPCT-AE(30592): Object 35/object37 compiled to 1 subobjects in 3ms!
04-02 19:03:14.551: I/jPCT-AE(30592): Object 'object37' uses one texture set!
04-02 19:03:14.551: I/jPCT-AE(30592): Subobject of object 36/object38 compiled to indexed fixed point data using 360/78 vertices in 2ms!
04-02 19:03:14.551: I/jPCT-AE(30592): Object 36/object38 compiled to 1 subobjects in 2ms!
04-02 19:03:14.551: I/jPCT-AE(30592): Object 'object38' uses one texture set!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: JPCT-AE MultiThreading
« Reply #5 on: April 02, 2014, 09:01:01 pm »
I don't know if this can be avoided. Maybe Egon has some better understanding/solution on this?
You can't fully avoid it, because a new model has to be uploaded to the gpu. You can prepone the actual compilation process by adding them before they are being used and then using World.compileAllObjects().

Offline rainfalls

  • byte
  • *
  • Posts: 27
    • View Profile
Re: JPCT-AE MultiThreading
« Reply #6 on: April 02, 2014, 09:55:05 pm »
You can't fully avoid it, because a new model has to be uploaded to the gpu. You can prepone the actual compilation process by adding them before they are being used and then using World.compileAllObjects().

Thanks Egon, you are very right. I wasn't aware that World.compileAllObjects() can be repeatedly used each time after the world is dynamically changed. I just made some quick tests and it worked well.

Offline karoshi

  • byte
  • *
  • Posts: 6
    • View Profile
Re: JPCT-AE MultiThreading
« Reply #7 on: April 08, 2014, 07:50:58 am »
Maybe, rainfalls said right, although I use other thread to add new object to World, World is still blocked during compiling time -> multithread not effective.
Thank you all.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: JPCT-AE MultiThreading
« Reply #8 on: April 08, 2014, 10:43:15 am »
I could try to handle this case somehow, but i need some test case that shows the problem...