Unity2013.1.19_DOTS_Burst compiler

Unity2013.1.19_DOTS_Burst compiler

DOTS是一种新产品,现在尚在起步阶段。由于它处于持续发展中,随着我们努力使其达到最佳状态,您将看到API会不断演变和日趋成熟。

DOTS包含以下元素:

  1. 实体组件系统(ECS) - 提供使用面向数据的方法进行编码的框架。它通过Entities软件包进行分发,您可以通过Package Manager来添加编辑器。

  2. C#作业系统 - 提供一种生成多线程代码的简单方法。它通过Jobs软件包进行分发。

  3. Burst编译器 - 可生成快速、优化的本机代码。它通过Burst软件包进行分发,可通过Package Manager在编辑器中使用。

  4. 本机容器 - 属于ECS数据结构,可提供对内存的控制。

继续跟进DOTS的第三个部分Burst compiler。官方是正道。

Unity - Manual: Burst (unity3d.com)

Burst compiler简介

Burst设计Burst compiler是和JobSystem一起工作的。

在你的代码中使用Burst compiler,先用  [BurstCompile]属性封装一个 Job struct 。

再添加[BurstCompile] 到你想要Burst编译的类型和静态方法中。

Burst compiles your code just-in-time (JIT) while in Play mode in the Editor, and ahead-of-time (AOT) when your application runs in a Player. For more information on compilation, see Burst compilation

using Unity.Burst;
using Unity.Collections;
using Unity.Jobs;
using UnityEngine;

public class MyBurst2Behavior : MonoBehaviour
{
    void Start()
    {
        var input = new NativeArray<float>(10, Allocator.Persistent);
        var output = new NativeArray<float>(1, Allocator.Persistent);
        for (int i = 0; i < input.Length; i++)
            input[i] = 1.0f * i;

        var job = new MyJob
        {
            Input = input,
            Output = output
        };
        job.Schedule().Complete();

        Debug.Log("The result of the sum is: " + output[0]);
        input.Dispose();
        output.Dispose();
    }

    // Using BurstCompile to compile a Job with Burst

    [BurstCompile]
    private struct MyJob : IJob
    {
        [ReadOnly]
        public NativeArray<float> Input;

        [WriteOnly]
        public NativeArray<float> Output;

        public void Execute()
        {
            float result = 0.0f;
            for (int i = 0; i < Input.Length; i++)
            {
                result += Input[i];
            }
            Output[0] = result;
        }
    }
}

参考文档:

官方:

About Burst | Burst | 1.8.12 (unity3d.com)

Unity 之Burst Compile底层原理 - 知乎 (zhihu.com)

Unity Live Help

什么是DOTS?为什么说DOTS非常重要? - Unity Learn

Unity-Technologies/ECS-Network-Racing-Sample: ECS multiplayer racing sample to showcase using Unity Entities and netcode with best practices (github.com)

ECS系列教程:

UnityECS_嵩小帽子啊的博客-CSDN博客[Unity ECS入门]8.System执行顺序-ECS入门-笨木头与游戏开发 (benmutou.com)

相关推荐

  1. Unity-时间

    2024-03-10 00:38:08       61 阅读
  2. Unity-GUID

    2024-03-10 00:38:08       55 阅读
  3. Unity-脚本

    2024-03-10 00:38:08       59 阅读
  4. Unity GC

    2024-03-10 00:38:08       49 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-10 00:38:08       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-10 00:38:08       100 阅读
  3. 在Django里面运行非项目文件

    2024-03-10 00:38:08       82 阅读
  4. Python语言-面向对象

    2024-03-10 00:38:08       91 阅读

热门阅读

  1. QT使用官方VLC以及Ffmpeg库的方法

    2024-03-10 00:38:08       38 阅读
  2. UE4游戏传奇4的SDK的部分数据之-移动状态

    2024-03-10 00:38:08       53 阅读
  3. iperf流量分析

    2024-03-10 00:38:08       52 阅读
  4. Oracle统计信息收集维护

    2024-03-10 00:38:08       49 阅读
  5. C语言深入学习 --- 5.动态内存管理

    2024-03-10 00:38:08       38 阅读
  6. Rust基础教程

    2024-03-10 00:38:08       35 阅读
  7. test02

    2024-03-10 00:38:08       45 阅读
  8. c 不同类型指针的转换

    2024-03-10 00:38:08       46 阅读