栅格系统的工作原理是什么_什么是工作系统?

栅格系统的工作原理是什么

Looking for a way to get started writing safe multithreaded code? Learn the principles behind our Job System and how it works together with the Entity Component System (ECS) and the Burst compiler from this brief intro!

寻找开始编写安全的多线程代码的方法吗? 从这个简短的介绍中了解我们的作业系统背后的原理,以及它如何与实体组件系统(ECS)和Burst编译器一起工作!

In Unity 2017.3 we exposed our Job System to C# code. Together with our new Burst compiler and Entity Component System (ECS), the job system makes up a high-performance multithreaded system, that will make it possible for games to fully utilize the multicore processors available today.

在Unity 2017.3中,我们将Job System暴露于C#代码。 作业系统与我们新的Burst编译器和实体组件系统(ECS)一起构成了高性能的多线程系统,这将使游戏能够充分利用当今可用的多核处理器。

The purpose of the Job System is to allow the game simulation to use all the available CPU cores. Almost all modern CPUs have multiple cores and the trend is increasing. Yet many games and applications rely on using just a single core. When you split your processing into multiple smaller chunks and run them across multiple cores, you are able to process simultaneously in parallel, instead of one after another. This uses the capacity of the cores more efficiently and therefore brings massive performance improvements. Or to be more specific, using all available cores makes the simulation use less wall-time (time on the clock from starting the simulation until completing it), without optimizing the thread-time (the number of CPU instructions spent computing the result).

Job System的目的是允许游戏模拟使用所有可用的CPU内核。 几乎所有现代CPU都具有多个内核,并且这种趋势正在增加。 然而,许多游戏和应用程序仅依赖使用一个内核。 将处理分成多个较小的块并在多个内核中运行时,您可以并行并行处理,而不必一个接一个地处理。 这样可以更有效地利用内核的容量,因此可以带来巨大的性能提升。 更具体地说,使用所有可用的内核可以使仿真使用更少的挂墙时间(从启动仿真到完成仿真的时间),而无需优化线程时间(计算结果所花费的CPU指令数量)。

减少挂墙时间 (Reducing wall-time)

The easiest way to get started reducing wall-time with the Job System is to use ParallelFor jobs. A ParallelFor job is used when processing a large set of values in the same way. Essentially, the job system processes each item in the array individually using a job – which means all the items can be processed in parallel to each other utilizing multiple CPU cores, if available. In practice, the number of jobs is actually much lower than one per item in the array, there is one job per CPU core and they each get an even amount of items to process. Since some workers finish their work faster than others, we use something called work-stealing to even out the time spent on each core. When a worker has finished all its work, it looks at the other workers’ queues and tries to process some of the items assigned to another worker.

开始使用Job System减少工作时间的最简单方法是使用ParallelFor jobs 。 以相同方式处理大量值时,将使用ParallelFor作业。 本质上,作业系统使用作业单独处理阵列中的每个项目,这意味着可以使用多个CPU内核(如果可用)彼此并行处理所有项目。 实际上,作业的数量实际上比阵列中每个项目要少得多,每个CPU内核只有一个作业,并且每个作业要处理的项目数量都是偶数。 由于有些工人比其他工人更快地完成工作,因此我们使用一种称为“偷工”的方法来平均花费在每个核心上的时间。 当一个工人完成所有工作后,它将查看其他工人的队列,并尝试处理分配给另一个工人的某些物料。

超越ParallelFor (Going beyond ParallelFor)

If you have some very heavy systems containing many similar items, ParallelFor works great. But even if you only have a few things of each type, you can take advantage of the Job System. On a high level, the design of a Job System is to split the entire application into small self-contained units of work called jobs. Each CPU core has its own thread executing these jobs, which makes all jobs run in parallel to each other. So as long as the different items don’t depend on each other, all you have to do is schedule jobs for them without waiting for any other jobs, and they will run in parallel to other things.

如果您有一些包含许多类似项目的非常重的系统,那么ParallelFor的效果很好。 但是,即使每种类型只有几件东西,您也可以利用作业系统。 在较高的层次上,作业系统的设计是将整个应用程序拆分为称为作业的小型独立工作单元。 每个CPU内核都有自己的线程来执行这些作业,这使所有作业彼此并行运行。 因此,只要不同的项目彼此不依赖,您要做的就是为它们安排作业,而无需等待任何其他作业,并且它们将与其他事物并行运行。

提早安排,迟到 (Schedule early, complete late)

Something we often suggest when talking about the Job System is the concept of scheduling early and waiting late. The purpose of this pattern is to make sure the main thread doesn’t have to wait for the job to complete. By the time the main thread needs the results of a job, it should ideally already have finished executing. A very common question which does not have a simple answer is: Which update pass is “early” and “late”? What we mean when we say schedule early and wait late is that you should give the job as much time as possible to run. It doesn’t matter much in which part of the frame you schedule and wait, as long as they’re as far apart as possible. If one frame latency is acceptable, you can even wait for the job in the next frame. Any time you see a “wait” on the main thread in the profiler, you should investigate what it’s waiting for and, if you can, schedule that job earlier or complete it later to get rid of the wait.

在谈论作业系统时,我们经常建议的是提早调度和延迟等待的概念。 该模式的目的是确保主线程不必等待作业完成。 当主线程需要作业结果时,理想情况下它应该已经完成​​执行。 一个没有简单答案的非常常见的问题是:哪个更新阶段是“早期”和“后期”? 我们提早安排时间并迟到的意思是,您应该给工作尽可能多的时间来运行。 安排和等待帧的哪一部分都没有关系,只要它们尽可能地间隔开即可。 如果可接受一帧延迟,那么您甚至可以等待下一帧的作业。 每当您在探查器的主线程上看到“等待”时,就应该调查它正在等待什么,并且,如果可以的话,可以提前安排该作业或稍后完成它以摆脱等待。

它不能解决什么问题? (What problem does it not solve?)

A Job System is not designed to be a solution for long running low priority tasks, and it is not designed for operations waiting instead of using CPU resources, like IO. It’s still possible to do these things, but it’s not the primary purpose of the Job System, which means they come with some limitations you need to be aware of.

作业系统并非旨在解决长期运行的低优先级任务, 也不是为了等待操作而不是使用CPU资源(例如IO)而设计的。 仍然可以做这些事情,但这不是工作系统的主要目的,这意味着它们有一些您需要注意的限制。

合作多任务 (Cooperative multi-tasking)

Each worker thread in the JobSystem is tied to a physical or a virtual CPU core. Once one of these threads start executing a job, the job will run to completion without any interruptions. If you want to share a CPU core with something else, you need to manually yield, and the only way to do that is to split your job into two jobs with dependencies between them. Since the system is never doing any context switching for you, a running job will occupy one full core of the CPU, even if you aren’t actually doing anything important.

JobSystem中的每个工作线程都绑定到物理或虚拟CPU内核。 这些线程之一开始执行作业后,该作业将运行完成而不会出现任何中断。 如果您想与其他人共享一个CPU内核,则需要手动屈服,而唯一的方法就是将您的工作分成两个相互依赖的工作。 由于系统永远不会为您执行任何上下文切换,因此即使您实际上没有做任何重要的事情,一项正在运行的作业也会占用CPU的一个完整内核。

它如何与ECS和Burst一起工作 (How it works together with ECS and Burst)

There are many implications for using the C# Job System, and generally speaking, this approach should lead to better performance across the board. This is particularly true as new Unity features like the Entity Component System and the Burst compiler technology come into play. The Entity Component System focuses on reducing the thread-time required to compute a result by organizing your data in a very cache-friendly way. Burst focuses on reducing the thread-time by optimizing your code better when it’s running within the job system. The goal of all these systems is to increase what is fundamentally possible in Unity in terms of performance, while still supporting existing workflows and making the transition easier.

使用C#作业系统有很多含义,通常来说,这种方法应该可以带来更好的整体性能。 当诸如实体组件系统和Burst编译器技术之类的Unity新功能开始发挥作用时,尤其如此。 实体组件系统的重点是通过以非常易于缓存的方式组织数据来减少计算结果所需的线程时间。 Burst致力于通过在作业系统中运行代码时更好地优化代码来减少线程时间。 所有这些系统的目标是在性能方面增加Unity上从根本上可能实现的功能,同时仍支持现有工作流程并简化过渡。

结论 (Conclusion)

Modern hardware architecture is equipped with and trending towards having multiple cores. Yet many processes rely on using just a single core. By running multiple processes across multiple cores, you’re able to run it simultaneously in parallel, instead of one after another, thus utilizing the capacity of the cores more efficiently and gaining massive performance improvements.

现代硬件体系结构配备了并且趋向于具有多个内核。 然而,许多进程仅依赖使用单个内核。 通过跨多个核心运行多个进程,您可以并行而不是一个接一个地并行运行它,从而更有效地利用核心的容量并获得巨大的性能提升。

The new C# Job System takes advantage of multiple cores in a safe and easy way. Easy, as it’s designed to open this approach up to your scripts and allow you to write fast jobified code, and safe because it provides protection from some of the pitfalls of multi-threading, such as race conditions.

新的C#作业系统以安全,简便的方式利用了多个内核。 这很容易,因为它旨在将这种方法开放给您的脚本,并允许您编写快速的作业代码,并且安全,因为它提供了针对多线程某些陷阱的保护,例如竞争条件。

You can use the new multithreaded systems to create games that run on a variety of hardware. You can also take full advantage of the performance gains to create richer game worlds with more units and more complex simulations.

您可以使用新的多线程系统来创建可以在各种硬件上运行的游戏。 您还可以充分利用性能提升来利用更多的单位和更复杂的模拟来创建更丰富的游戏世界。

To learn more and grab resources to get started please visit https://unity3d.com/unity/features/job-system-ECS.

要了解更多信息并获取入门资源,请访问https://unity3d.com/unity/features/job-system-ECS。

Got questions? Talk to us on the ECS and C# Job System forum.

有问题吗? 在ECS和C#作业系统论坛上与我们联系。

翻译自: https://blogs.unity3d.com/2018/10/22/what-is-a-job-system/

栅格系统的工作原理是什么

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值