Search Unity

Showcase Support for Generic Burst Jobs

Discussion in 'Burst' started by TriceHelix, Jun 8, 2023.

  1. TriceHelix

    TriceHelix

    Joined:
    Mar 6, 2019
    Posts:
    34
    GenericBurstJobs is an easy to use tool which automatically registers your generic job types using Unity's
    RegisterGenericJobType
    attribute (documented here). Instead of having to manually add this attribute yourself every time you use a different variation of a generic job struct, you can safely rely on the tool to do it for you.

    By analyzing your compiled scripts, it detects every unique generic instance of your job structs and registers them with Burst the same way you would. The source generator runs just before you build the Player application and optionally after every script recompilation, saving you a lot of time - especially on large projects. Code analysis is precise and reliable even when generic arguments are passed through multiple layers of classes and methods, enabling you to focus on the re-usability of your code instead of copy-pasting the same logic with slight variations just so that Burst can compile them all.

    The best part is that it works out of the box, requiring zero effort after installation unless your project is split into multiple assemblies. In that case you will only need to add a single line of code to each of those assemblies, which is described here.

    To install the tool in your project, simply open the Package Manager and add
    https://github.com/TriceHelix/GenericBurstJobs.git#upm
    as a git package.
    If you encounter any bugs, feel free to open up an issue on GitHub and I will look into it. Alternatively, you can voice your feedback below.

    Happy coding!
     
    Last edited: Sep 2, 2023
    mm_hohu, VirtusH and Deleted User like this.
  2. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    4,264
  3. TriceHelix

    TriceHelix

    Joined:
    Mar 6, 2019
    Posts:
    34
    Just from briefly looking at your 5 different methods, I believe my solution could ensure all of them are burst compiled at runtime (Editor and Build). From my knowledge, the only way to force Burst to compile a job with concrete generic arguments (when it cannot figure out that info itself like in case 1 & 2) is to use this attribute.

    What the tool does is deeply analyze the compiled IL from your scripts and gather every possible generic argument a given generic job could have. Regardless whether the generic parameters are those of a wrapper class or need to be inferred through multiple layers of generic types/methods - it will find all generic arguments required. The resulting job struct variants will be registered using the aforementioned attribute via source generation. That way you can spend more time designing your actual jobs and classes efficiently, and less time testing if the job is actually burst compiled.

    The only catch is that your job structs needs to be public (including types in which it is nested), because otherwise it cannot be referenced from the generated code.
     
    Last edited: Sep 2, 2023
    Kobix likes this.
  4. TriceHelix

    TriceHelix

    Joined:
    Mar 6, 2019
    Posts:
    34
    Full Release 1.0.0 is now out!
    Major issues and bugs have been fixed, and the tool has been thoroughly tested.
    For anyone who is still using the preview version, please update as soon as possible.

    Cheers!
     
  5. TriceHelix

    TriceHelix

    Joined:
    Mar 6, 2019
    Posts:
    34
    Version 2.0.0 has been released!
    To update, simply press the
    Update
    button in the package manager.
    Installation instructions can be found here.


    New Features
    • Custom tab in Project Settings for easy configuration
    • Automatic code generation when Player application is built, optionally after every script recompile
    • GenericBurstJobsConfig
      and
      CodeGen
      API for configuring and activating the generator via script
    Improvements
    • Overhaul of code analysis yielding better results than ever (constructors, virtual methods, deeply propagated generic arguments, etc.)
    • Clarified some parts of the documentation
    • Super simple installation after removal of 3rd party dependency
    • Performance improved significantly by minimizing use of recursive functions and LINQ queries
    • Many major and minor bug fixes

    This update made the tool easier to use than ever and quite a lot more powerful in terms of analysis. Pretty much every major issue of v1.0.0 has been fixed now. This will be the last major version for now as the project is considered feature complete. However, bug fixes and QOL improvements will still be addressed in future patches.

    Cheers!
     
    Kobix, mm_hohu and brunocoimbra like this.