Unity prepares a new compiler in C # called Burst

unity-logo

Unity is an extremely popular game engineespecially for its comprehensive and easy-to-use editing tools.

However, the engine must follow the evolution of the machines: for ten years, processors do not increase in frequency, but in number of cores. In other words, To exploit the new available performance, games must run their code on different cores, through different threads.

However, from the moment the technology is available, few games are really successful. In fact, the problems in writing such code are numerous.

To avoid these disadvantages, it is possible to follow some sets of rules. This is one of the reasons Unity is working on a new compiler in C #, called Burst with which, if these rules are not followed, a compilation error will occur.

To achieve this, the code should be written as a collection of tasks to be performed. Each of these tasks performs some transformations on the data.

The programmer must specify the memory areas that he can access read-only and those in which he wants to read and write data- The compiler will make sure you don't use anything outside of these declarations.

A scheduler then determines the best way to accomplish these tasks, in real time, with this additional information: you can ensure that no task will write data where someone else is trying to read or write, for example.

Burst is not only intended to facilitate parallel programming: it is also used in the most critical parts (from a performance point of view) of the Unity code.

Until now these were written in C ++, but current compilers are not entirely satisfactory.

In fact, if a developer wants a loop to be vectorized, they have no guarantee that the compiler will, due to an addition between two vectors, for example, the compiler must formally prove that, in all possible and imaginable cases, the two vectors do not correspond to the same addresses in memory).

burst-inspector

Why Burst and not an existing compiler?

Performance is a critical point if a loop is not vectorized it is a real problem that needs to be fixed quickly.

In addition, generated binary should be safe given buffer overflow errors and dangerous references should be discovered as soon as possible, with actual error messages rather than undefined behaviors (which cause many security problems).

Faced with these raised needs, you still need to choose the input language of this compiler- A variant or a subset of C, C ++, C # or a new language?

A new language is not a good option since in the beginning you avoid having to train people with this new tool.

C # has the preference from the users point of view, Since it is already used by the game engine, it will be encoded in the same language as the games.

In addition, C # already has a very large ecosystem, on the contrary, C ++ still suffers from its heritage from C, with not always obvious inclusions to be determined and huge compile times, flaws that C ++ 20 partially fixes, despite its obsession with performance.

The decision was made to continue with C #, but by removing a number of performance-hampering items, such as the standard library, mostly garbage collection, and permissions.

Burst doesn't really work as a full compiler since it doesn't take a large amount of code as input, but only the entry point to a crucial loop.

It just compiles it as a function, as well as everything it calls. The level of optimization is extremely high: since Burst focuses on certain parts of the code, it can take time.

The first iteration of Burst, with HPC # and the task system came with Unity 2018.1.

The generated code is sometimes faster than the previous version in C ++, sometimes slower, but developers trust that they will always achieve at least the same level of performance as C ++.

Source:  blogs.unity3d.com


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: AB Internet Networks 2008 SL
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.