Try   HackMD

Unity JobSystem

JobSystem 詳細介紹

  • IJobParallelFor
    • batch
    • 分配流程
  • Safety System
  • Native Container
  • Job Dependencies
  • BurstCompile

可以講的

  • job 的組成有 blittable typesNativeContainer
  • Safety System
  • custom native container
  • job 的使用上 schedulerrunJob Dependencies
  • IJobParallelFor 的 batch分配流程Work stealing
  • BurstCompile

標題

  • Job 內只能用 blittable types 和 NativeContainer

    • 在C#中有一些类型在托管与非托管代码之间可以直接使用,不需要进行任何转换,这些类型就称之为 blittable types
    • NativeContainer 只能用實質型別
  • NativeContainer分配器(Allocator)

    • Allocator.Temp: 不能把 Temp 的 Container 丟給 job 使用
    • Allocator.TempJob: 沒有主動釋放會跳警告
      • Internal: JobTempAlloc has allocations that are more than the maximum lifespan of 4 frames old - this is not allowed and likely a leak
    • Allocator.Persistent
  • NativeContainers don’t implement ref return

    • 不能用 nativeArray[0]++
      • 實測數值正確,但文件說不行???
  • Safty Check 只有在 Editor 有效

    • 包在 ENABLE_UNITY_COLLECTIONS_CHECKS define symbol 裡面
  • Safty Check 的開銷問題

    • 直觀的檢查機制消耗很大
    • 有了 schedule 後能建立 directed acyclic job graph,降低檢查的開銷
  • job scheduler 盡可能創建 worker threads

    • JobsUtility.JobWorkerCount 可以限制數量避免壟斷CPU資源
  • job.run() 直接在主執行緒上執行

  • Burst Compiler 基本介紹

    • Burst is a compiler that you can use with Unity's job system to create code that enhances and improves your application's performance. It translates your code from IL/.NET bytecode to optimized native CPU code that uses the LLVM compiler.
    • Burst Inspector
    • 不能用託管對象與引用類型
  • ECS?