Search Unity

  1. Unity 2020.2 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Is there any trick to enable or disable multithread-rendering at runtime?

Discussion in 'General Graphics' started by pippocao, Jan 15, 2016.

  1. pippocao

    pippocao

    Joined:
    Apr 10, 2014
    Posts:
    16
    Multithread-rendering brings a big performance advantage to our Android game. but we found it would crashes occasionally on some devices. So we want to disable it on some devices, but as we know, multitread-rendering is a option of building phase, and there is no API to enable or disable it at runtime.
    I was once to think that we can modify the "assets/bin/mainData" file to enable or disable it before the UnityPlayer Activity start. But sadly I found files under "assets" folder is read only, can not be modified.
    So, is there another method or trick to toggle multithread-rendering at runtime?
     
  2. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,118
    I know that its not the preferred way of doing it: You can upload a second apk for specific devices for the Google play store if that what you are targeting. Then you can only list devices that have problems with the multithreading and ship to those devices the single thread version.
     
  3. pippocao

    pippocao

    Joined:
    Apr 10, 2014
    Posts:
    16
    Thx your reply, maybe it's a good solution. But we have hundreds download channels in Chinese android market which many of these can not specify devices, and very few people use Google Play in China.
     
  4. johnpine

    johnpine

    Joined:
    Sep 19, 2015
    Posts:
    26
    yes would be definitely a good option to switch this runtime. but i guess thats not gonna happen.
    multithreaded rendering is also causing other problems still ( unity version 5.3.5f1 ).
    like with vsync on gui sometimes flickers on android with multithreaded rendering.
    so basically this cant be enabled anyways. better to leave it off.
    it is impossible to test on all android devices if it works but if you get huge performance benefits then maybe
    you can trade it for the occasional flickering.
     
  5. Packedbox

    Packedbox

    Joined:
    Jun 20, 2013
    Posts:
    17
    Old thread still not possible in Unity 2019 to disable MTRendering for certain device, CPU Type, OS...
    But you can use this trick on IOS :

    Code (CSharp):
    1. In DeviceSettings.mm
    2.  
    3. bool reportFakeCPUcount = 0;
    4.  
    5. extern "C" int UnityDeviceCPUCount()
    6. {
    7.  
    8.     if (_DeviceCPUCount <= 0)
    9.     {
    10.         // maybe would be better to use HW_AVAILCPU
    11.         int     ctlName[]   = {CTL_HW, HW_NCPU};
    12.         size_t  dataLen     = sizeof(_DeviceCPUCount);
    13.  
    14.         ::sysctl(ctlName, 2, &_DeviceCPUCount, &dataLen, NULL, 0);
    15.     }
    16.     if(reportFakeCPUcount){
    17.         reportFakeCPUcount = 0;
    18.         return 1;
    19.     }
    20.     return _DeviceCPUCount;
    21. }
    Code (CSharp):
    1. In UnityAppController.mm
    2.  
    3. extern bool reportFakeCPUcount;
    4.  
    5.  
    6. - (void)startUnity:(UIApplication*)application
    7. {
    8.     NSAssert(_unityAppReady == NO, @"[UnityAppController startUnity:] called after Unity has been initialized");
    9.  
    10.    
    11.  
    12.  
    13.  
    14.     if(!UnityiOS110orNewer()){
    15.         NSLog(@"iOS is less than 11, disabling multithread rendering");
    16.         reportFakeCPUcount = 1;
    17.     }
    18.    
    19.    
    20.     UnityInitApplicationGraphics();
    21. ...
     
  6. Alejandro-Martinez-Chacin

    Alejandro-Martinez-Chacin

    Joined:
    Oct 15, 2013
    Posts:
    74
    Woah, could something similar be done on android?
     
  7. tms_dev

    tms_dev

    Joined:
    Nov 26, 2018
    Posts:
    42
  8. CChong_at_Infinity

    CChong_at_Infinity

    Joined:
    Apr 7, 2020
    Posts:
    5
  9. tms_dev

    tms_dev

    Joined:
    Nov 26, 2018
    Posts:
    42
    It's in PlayerSettings, so it should work on runtime as far as I know. It says "Enable or disable multithreaded rendering option for mobile platform."
     
unityunity