Search Unity

Multithread rendering with OpenGL Linux

Discussion in 'Linux' started by jsantander2, Mar 20, 2019.

  1. jsantander2

    jsantander2

    Joined:
    Mar 20, 2019
    Posts:
    4
    I hope you can clarify something for me. Is multithread rendering supported with OpenGL Linux?
    I'm not sure I reach any conclusions from https://unity3d.com/es/learn/tutorials/topics/best-practices/multithreaded-rendering-graphics-jobs

    The thing is that I have a piece of native code which is called from GL.IssuePluginEvent (and in turn this is called from a coroutine that waits for end-of-frame) and in an OpenGL linux player (built on linux), the profiler shows that code as running after the LateUpdate events and as part of the main thread... which I believe indicates that it's using singlethreaded rendering
    Alternatively, a similar setup for a Direct3D windows player (built on windows), shows the native code as being run in the Render thread (which seems to point to single client, single worker thread type of configuration), and outside of the player loop.

    Any advice is welcomed. This player is intended to run headless from a server, with the view of the world being served as a video stream. However, so far, the FPS I can get from opengl linux players (~ 20 fps) is way below what I can get from the direct3d windows player (~60 fps) on the same hardware (nvidia GTX 1060).

    This is Unity 2018.3.8f1 and the latest nvidia drivers (418.43)

    I can consider moving to Vulkan, but I'm not sure if that would bring me other problems with the headless set-up (so far I'm using something like what it is described in https://towardsdatascience.com/how-to-run-unity-on-amazon-cloud-or-without-monitor-3c10ce022639, after no success with the server build flag).

    Thanks very much in advance and best regards.

    Julian
     
  2. Tak

    Tak

    Joined:
    Mar 8, 2010
    Posts:
    1,001
    Yes, both the client/worker model and graphics jobs are supported in the Linux player, with client/worker being the default.
    (Please note that the editor, when on OpenGL, still uses single-threaded rendering on Linux for now.)

    If you believe that the wrong model is being chosen by the player, please file a bug report with steps to reproduce.

    You can try forcing the threading model for the renderer using the following command line arguments to the player:
    -force-gfx-direct: Single threaded
    -force-gfx-mt: Client/worker multithreaded
    -force-gfx-jobs: Graphics jobs
     
  3. jsantander2

    jsantander2

    Joined:
    Mar 20, 2019
    Posts:
    4
    Thanks, got it working using the command line flags. In my experience, the default seemed to be the graphics jobs (but this still executes device GL.IssuePluginEvent in the main thread)
     
  4. pancymon

    pancymon

    Joined:
    Jul 9, 2017
    Posts:
    2
    Hi @Tak , I'm making an application with Unity 2018.3.6f1 on ubuntu 16.04 and opengl 4.5

    I used to have one camera in my scene, and the built player takes about 50% of cpu, as shown in top, which is fine. Then one day, I added six more cameras to my scene for the purpose of a new feature. The problem is that, with these cameras added, the cpu usage is over 300% now.

    I tried running the built player with -force-gfx-direct, it would reduce the cpu usage from 300% to 200%. I still wanted that 50% cpu usage though.

    I've done some experiments and it looks like the cpu usage increases with every extra camera. I would expect -force-gfx-direct to force the player to be strictly single threaded, so that cpu usage goes below 100%.

    Could you please explain to me, why the cpu usage increases with each extra camera?
    And why with -force-gfx-direct, it's still multithreaded, like 200% cpu usage?
    With my curent settings of six cameras, is it possible to force the player to run in one thread, i.e. below 100% cpu usage, or I have to figure out a way to work with only one camera?

    Your help would be appreciated. Thanks in advance!
     
    Last edited: May 16, 2019