Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Will Unity 5 be multi-core?

Discussion in 'General Discussion' started by Arowx, May 23, 2014.

  1. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
    It tends to range from 50 ms to 110 ms with a chunk view range of 2 only, which is not good because you feel choppiness from that. And this is entirely from the 'baking of collision data' when the colliders are created. It performs well after that's done with, until more need to be made.

    Well, the idea is to not draw the faces that are not visible to the player. So there tends to be only one or two faces being rendered and able to be collided with at any given time. Of course my mesh is calculated to make this happen, and I just use that same mesh for the collider. Have to be very mindful of performance.

    I suppose you mean that it might not be the case that there are available threads to run it in parallel. Currently I only use two separate threads - one is for mesh creation (and I'd like to use it for collider creation as well if possible), and one is for the LibNoise terrain data creation.

    But I suppose Unity is using a bunch of threads as well. Basically what I need is [some way] for it to be happening in parallel and not affecting the player.

    http://forum.unity3d.com/threads/247866-Need-Help-Improving-Performance-of-Mesh-Collider-Creation

    (Apparently I had it in the wrong section, whoops).
     
  2. npsf3000

    npsf3000

    Joined:
    Sep 19, 2010
    Posts:
    3,830
    Continued in your thread.
     
  3. jonas-echterhoff

    jonas-echterhoff

    Unity Technologies

    Joined:
    Aug 18, 2005
    Posts:
    1,666
    I can comment on the "new multithreaded job scheduler" feature in Unity 5.0. We rewrote the multi-threading system used by the engine to be much smarter in how it manages tasks and dependencies between them.

    Basically, in Unity 4.x, multi-threaded tasks in Unity (such as Skinning, Animation, Particles, Culling, etc) are implemented by having respective sections of the main loop when all the engine does at that point is calculating animation results, or skinning meshes, etc. It would then split those tasks into jobs which are are distributed among all CPU cores. This means that while the engine is handling tasks which are not multi-threaded (such as Physics in 4.x, game scripts, issuing render commands for a camera), all the other CPU cores are unused. So this means that essentially, Unity is only making use of all cores half of the time.

    In Unity 5.x we introduced a new job scheduling system where jobs can be queued up and don't need to be finished before anything else actually needs the results. That means that for instance, we can queue a whole bunch of animation jobs, and then go straight to running game scripts - while the animation jobs are running on the other cores. Only when a script will actually access data which requires animation results (like access a transform component which is being used by the animation system), then it will block script execution until that task is finished. We can chain these dependencies so that for a skinned character for instance, several subsystems would queue dependent jobs, so that the rendering thread will wait for the skinning to be done, which will wait for the culling to be done, which will wait for the animation to be done, so that all these jobs would only have to be run when results are needed by something else. Overall, this allows much better utilization of CPU cores. In some examples we benchmarked, we were able to get frame durations down by 40% on a four core machine. These are constructed benchmark samples, real world performance gains will be lower - but I expect all content to be faster. Having multi-threaded physics in PhysX 3 will also add to that. On top of this, we will have a new timeline profiler, which allows you to inspect exactly what any CPU core is doing at any given point in time.

    What this will not be is a new way to multi-thread user code. But, it *will* make sure that Unity will schedule other required tasks to run on other cores while your user scripts are running, so those cores are not idling like now.

    This tech is pretty cool, I think we should write a blog post on it, showing some results (I'll check if someone wants to do it or if I'll find time to do it myself next week).
     
  4. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,613
    Work-stealing task scheduler? I have a dim recollection of an Xfest some years ago where the guys from Xbox ATG said it was the provably optimal approach.
     
  5. npsf3000

    npsf3000

    Joined:
    Sep 19, 2010
    Posts:
    3,830
    I'd be interested in reading more about this.
     
  6. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    Sounds great, looking forward to the blog post.

    Will it be possible to utilise this job scheduling system from our scripts via the UnityEngine API?
     
  7. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    That's kind of orthogonal to what Jonas described (you can build up a job scheduler with fine grained dependencies without work-stealing). But yes, our implementation is work-stealing as well.