Search Unity

Can [BurstCompile] use on normal static class/method?

Discussion in 'Burst' started by inspoy, Jun 15, 2019.

  1. inspoy

    inspoy

    Joined:
    Sep 27, 2013
    Posts:
    3
    Hi

    I already know that [BurstCompile] attribute on IJob can bring us much benefit.

    So when put it on normal static utility class will also compiled to optimized code?

    The static method will be called from "ComponentSystem.OnUpdate()" rather than "Jobs".

    Code (CSharp):
    1. [BurstCompile]
    2. public static class MyUtils
    3. {
    4.     public static int Add(int a, int b)
    5.     {
    6.         return a+b;
    7.     }
    8. }
     
  2. 8bitgoose

    8bitgoose

    Joined:
    Dec 28, 2014
    Posts:
    448
    I am pretty sure putting that attribute on the static class doesn't do anything.

    However, if you have a static method that is accessed from a burst job, the static method will be compiled using burst. You don't have to do anything else, just make sure the job is labeled for [BurstCompile]
     
    inspoy and JesOb like this.
  3. JesOb

    JesOb

    Joined:
    Sep 3, 2012
    Posts:
    1,109
    Is there support for Static Method compilation using burst or plan to support?
     
  4. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    Burst support methods (if you look at source code) but not fully and not oficially (yet), you can enable it by declaring specific define in project settings. But I'll not recommend you doing that now.
     
    JesOb likes this.
  5. 8bitgoose

    8bitgoose

    Joined:
    Dec 28, 2014
    Posts:
    448
    @eizenhorn Am I right about burst compile for statics accessed through burstable jobs?
     
  6. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    Static methods outside of job can be used, without problem if they compatible with burst - not using managed data, fields only const/readonly etc.
     
    JesOb likes this.