ios metal_Metal,iOS 8的新图形API

ios metal

metal-logo

Exciting times for graphics on iOS 8!

iOS 8上图形的激动人心的时刻!

At its recent World Wide Developers Conference, Apple introduced Metal, a new graphics API that’s low-overhead, high efficient, and designed specifically for the A7 chip. It provides a way for game makers to take full advantage of iOS hardware and achieve far greater realism, detail, and interactivity in their games than ever before.

苹果公司在最近举行的全球开发者大会上推出了Metal,这是一种新的图形API,具有低开销,高效,专为A7芯片设计的功能。 它为游戏制造商提供了一种充分利用iOS硬件并在游戏中实现比以往更大的真实感,细节和交互性的方法。

We’ll be adding support for Metal soon, but in advance, wanted to take you through the new technology and explain why it is such a big deal.

我们将很快增加对Metal的支持,但是在此之前,我们想带您了解新技术并解释为什么如此重要。

金属一目了然 (Metal at a glance)

Metal has several key ideas in it that enable lower overhead, more predictable performance and better programmability:

Metal具有以下几个关键思想,它们可以降低开销,提高可预测的性能和更好的可编程性:

  • All iOS devices have shared memory for CPU & GPU. There’s no need to pretend that data from the CPU has to be “copied” into some video memory anymore. When you create a buffer, you just get a pointer to it, and that’s the same memory that the GPU sees.

    所有iOS设备均具有用于CPU和GPU的共享内存。 无需假装必须将来自CPU的数据“复制”到某些视频存储器中。 创建缓冲区时,您仅获得指向它的指针,这与GPU看到的内存相同

  • All the points above translate to much lower CPU overhead and much more predictable performance.

    上面的所有要点转化为更低的CPU开销和更可预测的性能。

Now let’s go into even more details!

现在,让我们进入更多细节!

开奖电话问题 (The Draw Call Problem)

If you’re making games, particularly mobile games, you’re probably aware of The Draw Call Problem. Each and every object that is rendered in the game has some CPU cost, and realistically on mobile right now you cannot afford more than a few hundred objects being rendered. In a real game, you also very much want to use CPU for other things – gameplay logic, physics, AI, animations and so on. Unity has some measures to minimize the number of draw calls being made – static & dynamic batching, occlusion culling, LOD and distance-based layer culling; you can also merge close objects together, put textures into atlases to reduce number of materials.

如果您要制作游戏,尤其是手机游戏,那么您可能已经意识到“抽奖电话问题”。 游戏中渲染的每个对象都有一定的CPU成本,而实际上在移动设备上,现在您承担不起的渲染对象不能超过数百个。 在真实游戏中,您也非常想将CPU用于其他方面–游戏逻辑,物理,人工智能,动画等。 Unity采取了一些措施来最大程度地减少绘制调用的次数–静态和动态批处理,遮挡剔除,LOD和基于距离的图层剔除; 您还可以将关闭的对象合并在一起,将纹理放入地图集中以减少材料数量。

A good question is – why there has to be a CPU cost to render something? After all, it’s the GPU that is doing the actual work.

一个很好的问题是– 为什么渲染某些东西需要一定的CPU成本? 毕竟,是GPU在做实际的工作。

Some of the overhead is on “the engine” side – CPU has to iterate over visible objects, figure out which shader passes need to be rendered, which lights affect which objects, which material parameters to apply and so on. Some of that is cached; some of that is multi-threaded; and generally this is platform-independent code. In each Unity release, we try to optimize this part, and Metal generally does not affect this.

一些开销在“引擎”端– CPU必须遍历可见的对象,找出需要渲染的着色器通道,哪些灯光影响哪些对象,应用哪些材质参数,等等。 其中一些已缓存; 其中一些是多线程的; 通常这是与平台无关的代码。 在每个Unity版本中,我们都会尝试优化这一部分,而Metal通常不会对此产生影响。

However, other part of the CPU overhead is in the “graphics API & driver” part. Depending on the game, this part can be significant. Metal is an attempt to make this part virtually go away, by being a much better match for modern hardware, somewhat lower level and doing massively less guesswork than OpenGL ES used to do. Up-front rendering state creation & validation; explicit actions related to render target loads & stores; no synchronization dances done on the API side — all these things contribute to much lower CPU overhead.

但是,CPU开销的其他部分在“图形API和驱动程序”部分中。 根据游戏的不同,这部分可能很重要。 通过与现代硬件更好地匹配,更低的级别并比过去的OpenGL ES做更少的猜测,Metal试图使这部分几乎消失。 前期渲染状态创建和验证; 与渲染目标加载和存储相关的显式操作; 没有在API端进行任何同步操作-所有这些都有助于降低CPU开销。

Based on our testing so far, we have seen API+driver overhead vanish to just a few percent of CPU time. That is a tremendous improvement comparing to 15-40% of CPU time that it used to be before! That means majority of the remaining CPU overhead is in our own code now. I guess we’ll have to continue optimizing that :)

根据到目前为止的测试,我们已经看到API +驱动程序开销仅占CPU时间的百分之几。 与以前的15-40%的CPU时间相比,这是一个巨大的进步! 这意味着剩余的大部分CPU开销现在都在我们自己的代码中。 我猜我们将不得不继续优化它:)

We’re also looking forward to using Metal ability to do rendering submissions from multiple threads; this opens up very interesting optimization opportunities as well.

我们也期待使用Metal功能从多个线程进行渲染提交。 这也带来了非常有趣的优化机会。

计算机会 (The Compute Opportunity)

With Metal, the GPU can be used for doing computation outside of typical vertex+fragment shaders area — known as “compute shaders”. Basically, this is an ability to run any kind of “parallel computation” on the many little processors inside a GPU. Compute shaders also have a concept of “local storage” – very fast piece of dedicated on-GPU memory that can be used to share data between these parallel work items. This particular piece of memory enables using GPU for things that aren’t easily expressible in ye olde vertex and fragment shaders.

借助Metal,GPU可用于在典型的“顶点+片段”着色器区域(称为“计算着色器”)之外进行计算。 基本上,这是一种在GPU内的许多小处理器上运行任何类型的“并行计算”的能力。 计算着色器还具有“本地存储”的概念-非常快速的一块专用GPU内存,可用于在这些并行工作项之间共享数据。 通过使用这种特殊的内存,可以将GPU用于在旧的顶点和片段着色器中难以表达的事物。

There are tons of interesting areas to use compute shaders for — optimized post-processing effects, particle systems, shadow and light culling and so on.

有大量有趣的区域可使用计算着色器进行优化的后处理效果,粒子系统,阴影和光剔除等。

While we aren’t using compute shaders much in Unity just yet, we’re looking forward to using them for more and more stuff. Exciting times ahead!

尽管我们还没有在Unity中使用很多计算着色器, 但是我们希望将它们用于更多的东西。 激动人心的时刻!

常问问题 (FAQ)

When can I get this? We can’t wait to ship this, but would like to avoid promising any actual dates. We have done a lot already, but still some things remain in order to be “shippable”. Our current plan is to first integrate all of the bits of Metal that provide the huge boosts to CPU side performance. Hopefully in Unity 5.0. Later on, we’ll add compute shader support (compute shader support is somewhat more involved on our side).

我什么时候可以得到这个? 我们迫不及待想发货,但希望避免承诺任何实际日期。 我们已经做了很多工作,但是仍然有些事情要做才能“可运输”。 我们当前的计划是首先集成所有Metal元素,这些元素将极大提高CPU端的性能。 希望在Unity 5.0中。 稍后,我们将添加对计算着色器的支持(对计算着色器的支持更多地涉及了我们)。

What would be the platform requirements? Metal requires iOS 8 and an A7-based device (iPhone 5S, iPad Air, Retina iPad Mini).

平台要求是什么? Metal需要iOS 8和基于A7的设备(iPhone 5S,iPad Air,Retina iPad Mini)。

What would I have to do to take advantage Metal’s lower CPU overhead? Generally, nothing. Once we add support for Metal in Unity, using it should be very transparent. All your existing projects, all your shaders and graphics effects should just work. Just enjoy your lower CPU usage!

我要怎么做才能利用Metal较低的CPU开销? 一般来说,什么都没有。 一旦我们在Unity中添加了对Metal的支持,使用它应该非常透明。 您所有现有的项目,所有着色器和图形效果均应正常工作。 只需享受较低的CPU使用率即可!

But what about shaders, since Metal has a different shading language? We’ll take care of that. Right now you generally write shaders in Cg/HLSL, which we convert into GLSL for OpenGL ES behind the scenes. For Metal, we’ll convert them in a very similar way.

但是着色器又如何呢,因为Metal具有不同的着色语言? 我们会照顾的。 现在,您通常使用Cg / HLSL编写着色器,我们将在幕后将其转换为OpenGL ES的GLSL。 对于Metal,我们将以非常相似的方式进行转换。

What can I do with lower CPU overhead, again? Have better physics, AI or more complex gameplay logic. Put more objects on the screen. Or just enjoy lower battery usage. It’s all up to you!

再次,如何用较低的CPU开销做什么? 具有更好的物理,人工智能或更复杂的游戏逻辑。 在屏幕上放置更多对象。 或者只是享受较低的电池使用量。 这一切都取决于你!

翻译自: https://blogs.unity3d.com/2014/07/03/metal-a-new-graphics-api-for-ios-8/

ios metal

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值