burst.网络_使用Burst Compiler 1.3优化项目

burst.网络_使用Burst Compiler 1.3优化项目

burst.网络

Since the first stable release of Burst Compiler a year ago, we have been working to improve the quality, experience, and robustness of the compiler. As we’ve released a major new version, Burst 1.3, we would like to take this opportunity to give you more insights about why we are excited about it and what’s coming next.

自一年前Burst Compiler的第一个稳定版本以来,我们一直在努力提高编译器的质量,体验和健壮性。 当我们发布了一个主要的新版本Burst 1.3时,我们想借此机会为您提供更多有关我们为何对此感到兴奋以及接下来会发生什么的见解。

We’re trying to constantly listen to our users and Unity partners. Also, internal teams at Unity are using Burst more and more. Based on this feedback, we have been prioritizing our work for the past quarter to ensure that we’re always thoroughly balancing the following 4 areas of improvements:

我们正在努力不断听取用户和Unity合作伙伴的意见。 而且,Unity的内部团队越来越使用Burst。 根据这些反馈,我们一直在优先考虑上季度的工作,以确保我们始终在以下4个方面进行全面平衡:

  • Scalability

    可扩展性

  • Performance

    性能

  • Quality

    质量

  • Usability and Debuggability

    可用性和可调试性

As Burst is a core part of DOTS (Data-Oriented Technology Stack), the new 1.3 release of the Burst Compiler is trying to improve each of these areas to improve user experience.

由于Burst是 DOTS (面向数据的技术堆栈) 的核心部分 ,因此1.3版的Burst Compiler的新版本正试图改善这些方面,以改善用户体验。

桌面交叉编译 (Cross compilation for Desktop)

Many of you have requested an option to compile a desktop player for a platform different from where the editor is running. One typical scenario is when you use Unity Build Cloud Services and the build machines are running on macOS while you’re trying to generate players for Windows. This new version of Burst enables the compilation of a Mono-based player across different desktop platforms.

你们中的许多人都要求为与运行编辑器的平台不同的平台编译桌面播放器的选项。 一种典型的情况是,当您尝试为Windows生成播放器时,当您使用Unity Build Cloud Services且构建机器在macOS上运行时。 这个新版本的Burst可以在不同的桌面平台上编译基于Mono的播放器。

Note that this new feature applies only for desktop build players. Console and mobile platforms usually have restrictions about which platform they can be compiled from as their SDK is often compatible with only one host platform.

请注意,此新功能仅适用于桌面构建播放器。 控制台和移动平台通常会限制从哪个平台进行编译,因为它们的SDK通常仅与一个主机平台兼容。

本机调试 (Native Debugging)

Debugging code compiled with Burst is another much-awaited usability feature. Until recently, the only way to debug Burst code was to actually disable Burst and rely on existing .NET managed debugging facilities. 

使用Burst编译的调试代码是另一个备受期待的可用性功能。 直到最近,调试Burst代码的唯一方法是实际上禁用Burst并依赖现有的.NET管理的调试工具。

With Burst 1.3, you can now use any integrated IDE native debugger found in Visual Studio, XCode or VSCode and debug Burst code with it:

借助Burst 1.3,您现在可以使用在Visual Studio,XCode或VSCode中找到的任何集成的IDE本机调试器,并使用它调试Burst代码:

In order to enable this feature, you need to select Enable Native Debugging in the Unity Editor Burst menu. The debugging experience allows you to:

为了启用此功能,您需要 在Unity Editor Burst 菜单中 选择 Enable Native Debugging 。 调试经验使您能够:

  • Hit breakpoints, including conditional breakpoints (data breakpoints should work too)

    命中断点,包括条件断点(数据 断点也应起作用)

  • Inspect frame callstack

    检查框架调用堆栈

  • Inspect local variables

    检查局部变量

  • Inspect structures and data, follow pointers

    检查结构和数据,遵循指针

  • Use debugger watches

    使用调试器手表

You need a separate native debugger launched from your regular .NET IDE in order to use this feature. You can then attach this native debugger to your game or even the Unity Editor. You can watch the following video tutorial for more details.

您需要一个从常规.NET IDE启动的单独的本机调试器,才能使用此功能。 然后,您可以将此本地调试器附加到您的游戏甚至Unity Editor。 您可以观看以下 **** 以了解更多详细信息。

演示地址

We understand that a more integrated debugging experience alongside regular .NET managed code is something that our users are looking forward to. This is something that we want to pursue as well, even though it’s difficult to bring about without penalizing the debugging experience. But we will try to improve this situation in the future. 

我们了解,用户希望拥有与常规.NET托管代码一起更集成的调试体验。 即使不牺牲调试经验也很难实现这一点,我们也想追求这一点。 但是我们将来会努力改善这种情况。

Debug.Log和字符串支持 (Debug.Log and strings support)

Another usability feature is the support for Debug.Log and partial string support available for Unity 2019.3 and above.

另一个可用性功能是对Debug.Log的支持以及对Unity 2019.3及更高版本的部分字符串支持。

1
2
3
int value = 256;
Debug.Log($"This is an integer value {value} logged with Burst.");
1
2
3
int value = 256 ;
Debug . Log ( $ "This is an integer value {value} logged with Burst." ) ;

You can learn more about this feature from this documentation.

您可以从本 文档中 了解有关此功能的更多信息 。

新的Intel CPU内部API (New Intel CPU Intrinsics API)

Burst has been optimized to leverage the power of SIMD. The Unity Mathematics package supported by Burst provides an API to manipulate standard vector types (e.g float3, float4) and to perform various calculations encountered by 2D and 3D workloads more efficiently. 

突发已进行优化,以利用SIMD的功能。 Burst支持 的 Unity Mathematics 软件包提供了一个API,用于处理标准向量类型(例如float3,float4),并更有效地执行2D和3D工作负载遇到的各种计算。

We also understand that in order to fully take advantage of existing hardware and to empower our users, we need not only to provide this abstract math API, but also to unlock more advanced optimization scenarios. With this new release, we’re introducing a new Intel CPU Intrinsics API to cover that performance aspect.

我们还了解到,为了充分利用现有硬件并增强我们的用户的能力,我们不仅需要提供此抽象数学API,而且还需要解锁更高级的优化方案。 在此新版本中,我们将引入一个 新的Intel CPU Intrinsics API 来涵盖该性能方面。

1
2
3
4
5
6
7
8
9
10
11
v128 a = Input.ReinterpretLoad<v128>(i);
v128 mask = cmplt_ps(a, Limit);
int m = movemask_ps(a);
v128 packed = shuffle_epi8(a, Lut[m]);
Output.ReinterpretStore(outputIndex, packed);
outputIndex += popcnt_u32((uint)m);
1
2
3
4
5
6
7
8
9
10
11
v128 a = Input . ReinterpretLoad < v128 > ( i ) ;
v128 mask = cmplt_ps ( a , Limit ) ;
int m = movemask_ps ( a ) ;
v128 packed = shuffle_epi8 ( a , Lut [ m ] ) ;
Output . ReinterpretStore ( outputIndex , packed ) ;
outputIndex += popcnt_u32 ( ( uint ) m ) ;

编译时间 (Compilation Time)

As more and more studios and teams are using it to optimize their games, Burst has to compile and optimize an increasing amount of user code. In the previous version, we introduced multithreaded compilation for both in-Editor experience and when building a standalone player, but the compiler still had to recompile your entire project whenever you restarted the editor.

随着越来越多的工作室和团队使用它来优化他们的游戏,Burst必须编译和优化越来越多的用户代码。 在以前的 版本中,我们引入了多线程编译,以提供编辑器中的体验以及构建独立播放器时的性能,但是无论何时重新启动编辑器,编译器仍必须重新编译整个项目。

We’re working on improving this scalability problem by first introducing in Burst 1.3 the caching of compilation results to disk, so that whenever you restart the editor, Burst should no longer try to recompile code that was previously compiled.

我们正在通过首先在Burst 1.3中引入将编译结果缓存到磁盘的方式来改善可伸缩性问题,以便每当您重新启动编辑器时,Burst都不再试图重新编译以前编译的代码。

But we’re not where we want to be with compilation times just yet. In the next quarter, we’re actively working to improve further and help larger projects iterate faster with Burst.

但是到目前为止,我们还不希望出现编译时间。 在下一季度,我们将积极努力进一步改进并帮助大型项目使用Burst更快地进行迭代。

更好的代码生成 (Better codegen)

Thanks to the C# Job System which ensures that concurrent write accesses are impossible, the Burst Compiler is in a unique position to better optimize your code than a regular C++ compiler. One of the critical optimizations that Burst allows is auto-vectorization, which can bring a 3x to 4x performance boost over regular scalar code. When you couple this with a carefully crafted layout of your game data, you can get improve the efficiency of your code by another order of magnitude, compared to non-data-oriented game code.

由于 C#作业系统 确保了不可能进行并行写访问,因此Burst编译器处于独特的位置,与常规的C ++编译器相比,可以更好地优化代码。 自动向量化是Burst允许的关键优化之一,与常规的标量代码相比,自动向量化可以将性能提高3到4倍。 当您将其与精心设计的游戏数据布局结合使用时,与非面向数据的游戏代码相比,可以将代码的效率提高另一个数量级。

In this new version of Burst, we have rewritten the memory aliasing analysis which is the entry point to actually auto-vectorize your code. We’re also introducing new intrinsics,  providing asserts to your code that can verify that two memory references aren’t aliasing or that a loop should vectorize (this one is still experimental).

在此新版本的Burst中,我们重写了内存别名分析,这是实际自动向量化代码的切入点。 我们还将引入新的内在函数,为您的代码提供断言,以验证两个内存引用没有混叠或一个循环应该向量化(此仍在实验中)。

You can learn more about this unique feature from this Memory Aliasing and noalias documentation.

您可以从此 内存别名和noalias 文档中 了解有关此独特功能的更多信息 。

更多错误修复 (More bug fixes)

The Burst Compiler should generate code that you can safely rely on, but as with any other compiler, it can have bugs. Since the 1.2 release, we have fixed many issues and invalid codegen cases. But we’re also trying to make sure that the quality of the compiler is rock solid by adding more and more unit tests and integration tests with larger projects for every new release.

Burst编译器应生成可以安全依赖的代码,但与其他任何编译器一样,它也可能存在错误。 自1.2版本以来,我们已修复了许多问题和无效的代码生成案例。 但是,我们还试图通过为每个新版本添加越来越多的单元测试和与大型项目的集成测试来确保编译器的质量牢不可破。

While it improves codegen performance, this new release should also be safer to use in your projects.

尽管它提高了代码生成性能,但该新版本还应更安全地用于您的项目中。

下一步是什么? (What’s next?)

We’re constantly adapting our priorities based on your feedback. In the coming months, we’ll be working on:

我们会根据您的反馈不断调整优先级。 在接下来的几个月中,我们将致力于:

  • Improving compilation time for both editor experience and player builds.

    缩短编辑经验和播放器构建的编译时间。

  • Improving codegen.

    改进代码生成。

  • Bringing a new intrinsics API for Arm CPUs.

    为Arm CPU带来新的内在API。

  • Various improvements in C# support (foreach, IDisposable…)

    C#支持的各种改进(foreach,IDisposable…)

开始使用连拍 (Start using Burst)

Burst is part of DOTS and you can already use it now! It’s stable and we’re actively working on improving it.

爆裂是DOTS的一部分,您现在可以使用它了! 它很稳定,我们正在积极进行改进。

It supports major desktop, console, and mobile platforms. It’s verified for Unity 2018.4 and newer, including the latest Unity 2020.2 alpha.

它支持主要的台式机,控制台和移动平台。 已针对Unity 2018.4及更高版本进行了验证,包括最新的Unity 2020.2 alpha。

We will come back in an upcoming series of blog posts to provide better guidance on using Burst as well as insights about what’s coming next.

我们将在即将到来的一系列博客文章中回来,以提供有关使用Burst的更好指导以及对下一步的了解。

In the meantime, let us know what you are doing with it and if you have any questions or issues, please feel free to leave a message on the DOTS forum!

同时,让我们知道您在做什么,如果您有任何疑问或问题,请随时在 DOTS论坛留言

翻译自: https://blogs.unity3d.com/2020/05/27/optimize-your-projects-with-burst-compiler-1-3/

burst.网络