Search Unity

Burst 1.1.1 new release

Discussion in 'Burst' started by xoofx, Jul 12, 2019.

  1. xoofx

    xoofx

    Unity Technologies

    Joined:
    Nov 5, 2016
    Posts:
    417
    Hi all,

    We are pleased to release a new version of Burst 1.1.1 with the following fixes, new features and improvements:
    • Many bug fixes, please upgrade from 1.0.x which is no longer updated/supported
    • Improve performance when detecting if a method needs to be recompiled at JIT time
    • Add support for SharedStatic<T> to allow sharing mutable static data between C# and HPC# (not yet activated in this version, will be available in 1.1.2)
    • Add support for FunctionPointer<T> usable from Burst Jobs. Compile your function in C# via BurstCompiler.CompileFunctionPointer<T> and use it from an HPC# Job
    • Add support for structs with explicit layout (see known issues)
    • Add support for BurstCompiler.Options to allow controlling/enabling/disabling Burst jobs (compilation/run) at runtime
    • Add support for BurstRuntime.GetHashCode32<T> and GetHashCode64<T> to allow generation of a hash code for a specified type from a HPC# job
    • Add support for reporting a compilation error when writing to a [ReadOnly] container/variable (preview)
    • Add support for new math.bitmask(bool4)

    This new version of Burst relies on a new version of Unity.Mathematics 1.1.0.

    Our documentation is still not entirely up-to date with these latest features but we are going to update it in the coming weeks.

    With this version, Burst also becomes a verified package for the upcoming Unity 2019.3! A verified package implies that the Unity's Quality Assurance team has officially verified that this package works with a specific version of the Editor.

    For this version, we have known issues that you should be aware of:
    • Burst is compatible with Unity versions 2018.4 and up. However, see note immediately below (also see the documentation for additional notes for specific platforms)
    • For the new 2019.3 version of the editor our support starts from 2019.3.0a8 (already available); using this version of Burst with prior alpha versions will give an error
    • When upgrading to a new version of Burst via the package manager (or even when changing your manifest.json), Burst can’t be unloaded, so the upgrade will fail. You need to close and re-open the editor, and in some cases remove the old Burst package from the Package Cache before opening the editor again
    • While upgrading from a previous 1.0.x version, you might encounter an error saying that the assembly Unity.Burst cannot be found and the GUID for the assembly doesn’t match. We actually unintentionally broke this GUID while moving from 1.0.x to 1.1.x, our apologies for this breaking change. In order to fix this, you need to manually edit your asmdef in case it is using the GUID. The most common case is while you reference Unity.Burst, you need to use GUID 2665a8d13d1b3f18800f46e256720795
    We have also updated the known issues in the package documentation.

    Let us know what you think about this new release!

    The Burst Team
     
    5argon, nxrighthere, Grizmu and 17 others like this.
  2. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    So do the explicit layout fixes mean it now plays nice with BlobAssetReference? So we can burstify Unity.Physics collider creation?
     
  3. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,759
    This version will just not work for me. None of my jobs will burst compile in editor.

    going to try a full re-import.

    -edit-

    yep even after clearing cache and re-importing none of my jobs (or any jobs form unity packages) will burst compile. 2019.3a8

    -edit2-

    turning on synchronous compilation causes jobs to burst again.
    turning it off causes jobs not to burst compile.
    So yeah issue is something to do with the async burst compiler i guess.

    Side note, shows how important burst is
    No burst
    upload_2019-7-15_9-27-21.png
    Burst
    upload_2019-7-15_9-29-10.png
    Just a casual, 18-39x faster.

    -edit3-

    downgraded project to 2019.2b9, issue still exists.

    TLDR: if anyone else has issues, turn on Synchronous Compilation.
     
    Last edited: Jul 15, 2019
    Opeth001 likes this.
  4. Singtaa

    Singtaa

    Joined:
    Dec 14, 2010
    Posts:
    492
    Hmm works fine for me even without turning on Synchronous Compilation (Burst 1.1.1 and Unity 2019.3a8).

    I double-checked the profiler and the Burst inspector, all the jobs are indeed burst-compiled.

    Only thing I noticed was that upon first upgrading to Burst 1.1.1 (from 1.1.0p4), there was some error about not being able to load file or assembly Smash. It fixed itself after I exited+reopened the project.
     
  5. Adam-Mechtley

    Adam-Mechtley

    Administrator

    Joined:
    Feb 5, 2007
    Posts:
    290
    Hi! BlobAssetReferenceData is now Burst compatible with this fix. However note that some of the collider factory methods in Unity Physics still take e.g., managed arrays. Those ones still need to be ironed out in the physics package, but we expect everything else should be fine now. Let us know if you see something different.
     
  6. fabrizio_unity

    fabrizio_unity

    Unity Technologies

    Joined:
    May 3, 2018
    Posts:
    47
    Hello!
    @tertle we are trying to reproduce the issue with some test projects we have without success unfortunately.
    Could you please provide some details about the jobs you are trying to burst?

    Thanks
     
  7. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    982
    Just want to clarify. Will this work even with a not up to date Unity.Entities? Still stuck with preview.30.
     
  8. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,759
    OK I kind of got to the bottom of it after toggling this a bunch of times and doing some testing, I noticed after one attempt when I resumed playing after taking a sample all the jobs are finally burst compiled.

    After testing I realized it's taking much longer for burst jobs to asynchronously compile than I expected, over 20 seconds after playing.

    I downgraded to 1.0.4 with same code base to compare, and it did take nearly as long (was around 15 seconds but this wasn't exactly a scientific test so could be the same) so there is probably no regression here and it appears to be working fine.

    So I apologize if I wasted anyone's time. It looks like it simply takes much longer than I remember since I last checked and after I upgraded and went through did some tests to make sure new version was working and jumped the gun.
     
    Last edited: Jul 15, 2019
  9. fabrizio_unity

    fabrizio_unity

    Unity Technologies

    Joined:
    May 3, 2018
    Posts:
    47
    Hi!
    @tertle thank you very much for checking. Compiling asynchronously means that you are at the mercy of whatever workload is going on at the time (burst may not get time, if heavy cpu usage for instance, it's a thread and will time slice) so, the time fluctuations you are experiencing are very likely due to this.

    @davenirline we just checked whether there are compatibility issues between the new burst package and entities package preview.30 version and there are no apparent incompatibilities on our side.
     
    davenirline likes this.
  10. shaunnortonAU

    shaunnortonAU

    Joined:
    Jan 19, 2018
    Posts:
    9
  11. RBogdy

    RBogdy

    Joined:
    Mar 6, 2019
    Posts:
    65
    Projects with Unity Physics and Burst are still not working on Android devices...
     
  12. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
    FYI the Android issue is not about Burst. The was an alignment issue on the jacobians that crashed on Android. We have a fix that will be in the next release.
    If you want to fix this locally then

    - in com.unity.physics/Unity.Physics/Dynamics/Jacobians/Jacobian.cs
    and the
    ReadJacobianHeader
    functions, change all references of
    short

    to
    int
    .

    - in com.unity.physics/Unity.Physics/Dynamics/Solver/Solver.cs and the
    InitModifierData 
    function change
    short jacobianSize = (short)JacobianHeader.CalculateSize 

    to
    int jacobianSize = JacobianHeader.Calculatesize
     
    Kichang-Kim and RBogdy like this.
  13. sebas77

    sebas77

    Joined:
    Nov 4, 2011
    Posts:
    1,642
    hey @xoofx once you told me:

    "We have known issues with function pointers that will require more work on our side to make it possible for a public release (e.g exceptions in a burst compiled function are not handled at all as they are handled in the burst job system)"

    is the reason of calling the CompileFunctionPointer inside jobs that there is not handling of exception otherwise, which would result in a hard crash, or is there something else? I would like to see an example too, not sure about its reason to exist
     
    Last edited: Jul 21, 2019
  14. nxrighthere

    nxrighthere

    Joined:
    Mar 2, 2014
    Posts:
    567
    @xoofx Can you make FunctionPointer._ptr accessible via a property, please?
    Code (csharp):
    1. public IntPtr Ptr {
    2.    get { return _ptr; }
    3. }
    This would be enough.
     
    elcionap and tarahugger like this.
  15. jacksondunstan

    jacksondunstan

    Joined:
    Feb 28, 2014
    Posts:
    2
    I'm having trouble getting
    BurstCompiler.CompileFunctionPointer
    to work. Here's a simple test case:

    Code (CSharp):
    1. using UnityEngine;
    2. using Unity.Burst;
    3.  
    4. delegate void D();
    5.  
    6. public static class C
    7. {
    8.     public static void F()
    9.     {
    10.     }
    11. }
    12.  
    13. class TestScript : MonoBehaviour
    14. {
    15.     void Start()
    16.     {
    17.         BurstCompiler.CompileFunctionPointer<D>(C.F);
    18.     }
    19. }
    When I run this with Unity 2019.1.10f1 and Burst 1.1.1, I get the following error:

    InvalidOperationException: Burst failed to compile the given delegate: Void F()

    Unity.Burst.BurstCompiler.Compile[T] (T delegateObj) (at Library/PackageCache/com.unity.burst@1.1.1/Runtime/BurstCompiler.cs:120)
    Unity.Burst.BurstCompiler.CompileFunctionPointer[T] (T delegateMethod) (at Library/PackageCache/com.unity.burst@1.1.1/Runtime/BurstCompiler.cs:78)
    TestScript.Start () (at Assets/TestScript.cs:17)
    Does anyone know how to get this to work?
     
  16. Abbrew

    Abbrew

    Joined:
    Jan 1, 2018
    Posts:
    417
    Any progress on getting EntityCommandBuffer to work with Burst?
     
  17. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,759
    Abbrew likes this.
  18. nxrighthere

    nxrighthere

    Joined:
    Mar 2, 2014
    Posts:
    567
    @jacksondunstan To compile functions with Burst, they should be marked with the appropriate attribute, so put [BurstCompile] to your F() and it will work. Also, instead of declaring delegates, you can use Action and Func<TResult> as generics to reduce the amount of code.
    Code (csharp):
    1. using System;
    2. using UnityEngine;
    3. using Unity.Burst;
    4.  
    5. public static class C {
    6.    [BurstCompile]
    7.    public static void F() { }
    8. }
    9.  
    10. class TestScript : MonoBehaviour {
    11.    void Start() {
    12.        var functionPointer = BurstCompiler.CompileFunctionPointer<Action>(C.F);
    13.    }
    14. }
     
    Last edited: Jul 22, 2019
    e199 likes this.
  19. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    982
    Cool! How is the function pointer used after that?
     
  20. nxrighthere

    nxrighthere

    Joined:
    Mar 2, 2014
    Posts:
    567
    You can pass it to a job with the same generic FunctionPointer<Action> as any other structure an then call Invoke().
     
  21. Deleted User

    Deleted User

    Guest

    Good afternoon Alexandre,

    Do you have a moment? I would like to ask a question regarding BurstRuntime.GetHashCode32<T>. Is it deterministic across all the platforms? For instance, difference in Endianness on Mac. Assuming that some of the CPU works only with Big Endian hence the byte order of the Type.AssemblyQualifiedName might be different.
    Also, would you be able to add the 16 bit support for the hashcode?

    I am gladly appreciate your work.
    Thank you.
     
  22. elcionap

    elcionap

    Joined:
    Jan 11, 2016
    Posts:
    138
    This doesn't answer your question but i think it adds relevant information:
    https://forum.unity.com/threads/reading-data-with-pointer-operation.584584/#post-3908620

    []'s
     
    Deleted User likes this.
  23. xoofx

    xoofx

    Unity Technologies

    Joined:
    Nov 5, 2016
    Posts:
    417
    It is following the same rule as GetHashCode, so it is a stable runtime hash, but we provide no guarantee across platforms.

    Just truncate the 32 version to 16.
     
    Deleted User likes this.
  24. jacksondunstan

    jacksondunstan

    Joined:
    Feb 28, 2014
    Posts:
    2
    Thanks for pointing out that I needed to add the [BurstCompile] attribute. It now works in the editor, but errors in a standalone build. Here's the error I get when using your above source code with Unity 2019.2.0f1 and Burst 1.1.2 on macOS 10.14.6:

    InvalidOperationException: Burst failed to compile the given delegate: Void F()
    attribute: Unity.Burst.BurstCompileAttribute

    at Unity.Burst.BurstCompiler.Compile[T] (T delegateObj) [0x00000] in <00000000000000000000000000000000>:0
    (Filename: currently not available on il2cpp Line: -1)​

    Is there something else I need to do to make this feature work?
     
    dyox likes this.
  25. nxrighthere

    nxrighthere

    Joined:
    Mar 2, 2014
    Posts:
    567
    Looks like an issue with the Burst itself since it works fine in the editor.
     
    dyox likes this.
  26. dyox

    dyox

    Joined:
    Aug 19, 2011
    Posts:
    619
    Yes i have same problem and i was not able to fix it.
    I've tested many approach but FunctionPointer fail all time on Build.

    "InvalidOperationException: Burst failed to compile the given delegate"
     
    nxrighthere likes this.
  27. Deleted User

    Deleted User

    Guest

    Thank you. I have faced an issue on the current version of Burst 1.1.2 with generic calls of a job. A generic job compiles and runs fine in Editor mode but not in the build mode. Is there a possible fix for it?

    https://forum.unity.com/threads/burst-job-inside-of-generic-class.614737/
     
  28. xoofx

    xoofx

    Unity Technologies

    Joined:
    Nov 5, 2016
    Posts:
    417
    We discovered that the ability to compile delegates for burst was actually not activated for Unity 2018.4 to 2019.2, so we had to backport this fix and it should be available in the next releases of Unity. We will double check what is the status of these releases.
     
    pal_trefall likes this.
  29. korzen303

    korzen303

    Joined:
    Oct 2, 2012
    Posts:
    223
    Hey guys, following the conversation with Joachim here Scheduling jobs from NOT a MainThread I would like to ask for help with compiling and launching this job outside the JobSystem using CompileFunctionPointer<T>:

    Code (CSharp):
    1. [BurstCompile]
    2. struct OceanJob2 : IJob
    3. {
    4.     public NativeArray<Vector3> vertices;
    5.  
    6.     public float time, rippleStrength, scale;
    7.  
    8.     public void Execute()
    9.     {
    10.         for (int i = 0; i < vertices.Length; i++)
    11.         {
    12.             float3 vertex = vertices[i];
    13.             float2 offset = new float2(vertex.x, vertex.z);
    14.             float ripple = math.sin(time + math.length(offset));
    15.             vertex.y = ripple * rippleStrength;
    16.             vertices[i] = vertex;
    17.         }
    18.     }
    19. }
    Thanks!