Unity DOTS

Glossary

诞生原因

使用

导入 HybridRenderer

ECS

组合模式

Entity

  1. Constitute - a key - bind lots of component - 相同组件排列在连续内存,增大Cache命中 - 轻量级
  2. entity->prefab
     EntityManager.CreateEntity()
    
  3. prefab->entity
    • proxy
    • noproxy
    • component
      • GenerateAuthoringComponent
    • System
    • Other
      • :IDeclareReferencedPrefabs,IConvertGameObjectToEntity

        Component

        • component
    • :ICompionentData
      • 实质:struct数据存储
        • component≠monobeihavior
        • 无GC
        • Fuction无作用
    • ISharedCompnentData
      • 比较
        • IEquatable
      • 结构体内容完全相同
      • e.g.
        • SharedMesh

          System


job system

  1. 优势
    • 高效运行多线程代码
    • before JobSystem
      • unity内部多线程,对外主线程
      • C#多线程只支持处理数据
    • 利用多核
  2. 接口
    1. IJob
     struct Job:IJob{
     };
     var job=new Job()
     JobHandle handle=job.Schedule();
     handle.Complete();
    
    1. IJobParallelFor
     struct Job:IJobParallelFor{
     };
     //等待job完成
     handle.Complete()
    
    • 优点
      • 完全并行
      • 数据加锁 ReadOnly
      • 多线程数据存储

burst

  1. 优点:
    • 生成高度优化的本地代码
    • 编译器
    • 基础
      • LLVM
        • IR抽象语言
        • 支持多语言
        • 开源
      • 后端编译
    • 原理
      • 源代码->全段->优化器->后端->机器码
  2. 缺点:
    • 只支持值类型
    • LLVM对C# GC支持极差
  3. e.g.
     [BurstCompile]
     struct job{
     };
    

mathematics库

原理:直接映射到硬件SIMD寄存器


HPC#,Hyper C#

GC

ArcheType


World

  1. 组成
    • EntityManager
    • ComponentSystem
      • 主线程
      • JobComponentSystem
        • 同步点
          • 实体创建\销毁\组件添加删除
          • 主线程卡顿
      • IJobForEach<T1,T2>
    • Archtype
  2. create
    • default
    • new world()
  3. 多world间并行不互通
  4. export scene to ecs
    • Hybrid
    • scene批量转换ECS工具
    • 默认不支持Lightmap,需要自定义实现
    • SubScene
      • World.GetOrCreateSystem()
      • 流式加载
        • LoadSceneAsync()
        • UnLoadScene()
        • GameObjectConversionUtilityConvertGameObjectHierachy()
    • GO->ECS
    • 只支持部分

Debug

Entity Debugger

其他

  1. 渲染
    • theory
    • Job准备数据 - 方法
    • GPU Instancing
    • CommandBuffer
    • BatchRendererGroup
      • 强制镜头裁剪Job
      • 需要提供每个渲染物体的包围盒区域
        • 镜头裁剪相关
      • 没有1023数量限制
        • 内部调用自动Graphics.DrawMeshInstanced (前提:开启GPU In试探此难关)