Search Unity

  1. How has 2019.2 and the beta been for you so far? Give us feedback in this thread.
    Dismiss Notice
  2. We would like to hear your feedback about Unity and our products. Click here for more information.
    Dismiss Notice

Job System + WebGL

Discussion in '2018.1 Beta' started by RSpicer, Mar 27, 2018.

  1. RSpicer

    RSpicer

    Joined:
    Feb 27, 2014
    Posts:
    9
    What's the current status of the Job System in WebGL builds (asm.js or WebAssembly)? What I've observed, in 2018.1b11:

    * IJobParallelFor works as expected in standalone builds and the editor, as long as I call job.Schedule().
    * Switch build type to WebGL, and jobs don't execute. They seem to silently fail -- even though I call jobHandle.Complete() in LateUpdate, the contents of the NativeArray the job modifies remain unmodified.
    * Add an explicit JobHandle.ScheduleBatchedJobs() and everything works, but it seems to run computation on the main JS thread.

    Is this intended? I don't mind wrapping a JobHandle.ScheduleBatchedJobs in a conditional for WebGL, but hopefully sooner or later the jobs can be offloaded to WebWorkers..
     
  2. Schubkraft

    Schubkraft

    Unity Technologies

    Joined:
    Dec 3, 2012
    Posts:
    882
    Afaik the job system is not supported for WebGL atm due to being single threaded.

    But just silently failing is not nice behaviour. Can you please submit a bug report for this with a repro project and ping the case number here? Thanks!
     
  3. superpig

    superpig

    Quis aedificabit ipsos aedificatores? Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,156
    So firstly I believe you should be calling JobHandle.ScheduleBatchedJobs on all platforms, not just WebGL. But yeah, as @Schubkraft says, silent failure is almost certainly not the behaviour we expect.

    Secondly, what you're describing sounds like expected behaviour to me - AFAIK we do not currently support WebWorkers, and all jobs run on the main thread (including engine jobs, not just C# jobs). If the WebGL team add WebWorkers later then I imagine that your jobs will Just Work, though looking at the WebWorkers documentation it looks like using them efficiently for the jobsystem will be a pretty difficult task, what with all the isolated context stuff.
     
  4. RSpicer

    RSpicer

    Joined:
    Feb 27, 2014
    Posts:
    9
    Thank you for the reply! Sounds like the error case may be "in the Editor and Windows Standalone, jobs run when scheduled with jobInstance.Schedule(), without calling JobHandle.ScheduleBatchedJobs()," then. I'll submit a minimal repro case to the bug tracker tomorrow.
     
  5. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    1,443
    Did you submit that report yet? It would be much appreciated! Please reply with the case # if you do.