Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question "Multithreaded Rendering" vs "Graphics Jobs"

Discussion in 'General Graphics' started by Peter77, Apr 18, 2021.

  1. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,589
    Unity built-in (legacy) renderer:
    In the Player Settings you find the "Multithreaded Rendering" and "Graphics Jobs" options. The following text is copied from the documentation, but it sounds very similar to me:
    https://docs.unity3d.com/Manual/class-PlayerSettingsAndroid.html

    It seems the difference is that Multithreaded Rendering runs on exactly one worker thread, where Graphics Jobs might run on multiple worker threads.
    1. What are the pros and cons of each method? They must have different pros and cons, otherwise more than one option wouldn't exist.
    2. When would I use MTR over GJ for example?
    3. The MTR and GJ options don't seem to be exclusive, I can enable just one or both. Which option dominates when I enable both?
     
    xucian and PutridEx like this.
  2. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,983
    Hi!
    The options are not mutually exclusive, you can enable both.

    Multithreaded rendering: graphics API calls are moved from the main thread to a separate render thread.
    Graphics jobs: multiple threads prepare commands for the thread that submits graphics API calls.

    If you have both enabled, main thread schedules some work for worker threads, which prepare commands for the render thread, which in turn submits graphics API calls.
     
    konsnos, roointan and SugoiDev like this.
  3. leozzyzheng2

    leozzyzheng2

    Joined:
    Jul 2, 2021
    Posts:
    60
    If I disable Multithreaded rendering and only enable Graphics jobs, will main thread offload all its works including something like Batch.DrawInstanced to Render Thread?
     
    Last edited: Aug 26, 2022
  4. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,983
    There will be no dedicated render thread in this setup.
     
  5. leozzyzheng2

    leozzyzheng2

    Joined:
    Jul 2, 2021
    Posts:
    60
    Sounds like it won't benefit to performance?
     
  6. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,983
    It depends on what your performance bottleneck is and on the target hardware. If any of those options would've been a clear performance benefit in all possible scenarios, there wouldn't have been an checkbox :)
     
  7. leozzyzheng2

    leozzyzheng2

    Joined:
    Jul 2, 2021
    Posts:
    60
    Thanks for reply.

    My scenario is I found Batch.DrawInstanced run on Main Thread will dispatch Batch.FillInstanceProperties to job worker threads but it will wait for it to finish the job. So the Batch.DrawInstanced will cost much on Main Thread.
    I found enable Graphics jobs will dispatch some calls of Batch.DrawInstanced to Render Thread on Editor, but it has no effect on Android with OpenGLES 3.2, so I'm wondering if there is any way to make Render Thread or job worker thread also run some Batch.DrawInstanced to reduce the workload on Main Thread on Android with OpenGLES?
     
  8. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,983
    If you want to reduce the load on the main thread, you need to enable multithreaded rendering.
     
  9. leozzyzheng2

    leozzyzheng2

    Joined:
    Jul 2, 2021
    Posts:
    60
    Yes, I always enable multithreaded rendering, but I found the Batch.DrawInstanced on MainThread will wait Batch.FillInstanceProperties which takes a lot of time on MainThread. I found Graphics jobs could move some works to Render Thread but it donesn't take effect on Android with OpenGLES, so I want to know will Graphics jobs have effect on Android with OpenGLES?
     
  10. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,983
    Ah! Now I get your question :)
    No, OpenGL ES doesn't support graphics jobs.
    You can try enabling Vulkan.
     
    DevDunk likes this.
  11. dnach

    dnach

    Unity Technologies

    Joined:
    Mar 9, 2022
    Posts:
    89
    As @aleksandrk mentioned above, on Android you can target Vulkan in order to enable Native Graphics Jobs which aim to better utilize the CPU during rendering setup. You can read a bit more on the different 'Rendering Thread Modes' in the API docs: https://docs.unity3d.com/ScriptReference/Rendering.RenderingThreadingMode.html

    Worth noting, we are now working on a new graphics jobs threading mode which aims to remove unnecessary synchronization between the main thread and graphics jobs threads at the beginning/end of frames. In addition, we are also working to provide official Graphics Jobs support in Editor. We are first targeting DX12, but support for other compatible graphics backends will follow shortly.
     
    Mikedegianthobbit, Kreshi and DevDunk like this.
  12. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,969
    Good to know that it's being worked on. Vulkan support would also be great since it's cross platform by design (and has issues in 2021 on quest 2 which then could be included)
     
    Mikedegianthobbit likes this.
  13. leozzyzheng2

    leozzyzheng2

    Joined:
    Jul 2, 2021
    Posts:
    60
    Thanks! I'm already trying the vulkan!
     
  14. leozzyzheng2

    leozzyzheng2

    Joined:
    Jul 2, 2021
    Posts:
    60
    Thanks for the explaination, seems there are some compatibale problem on my android device for Vulkan, I will digging more about it.
     
    tmonestudio likes this.