Metal 是 Apple 设备的标准图形 API。Unity 支持 iOS、tvOS 和 macOS 上的 Metal(Standalone 和 Editor)。
Metal 在 Apple 平台上具有比 OpenGL ES 更丰富的功能集。请参阅下面关于使用 Metal 的优缺点。
使用 Metal 的优点
使用 Metal 的缺点
iOS 和 tvOS 为 Apple A7 或更新的 SoC 提供 Metal 支持。
macOS 为 HD 4000 系列或更高的 Intel HD 和 Iris Graphics、AMD GCN 架构 GPU 以及 Nvidia Kepler 架构 GPU 或更新版本提供 Metal 支持。
最低着色器编译目标为 3.5。
Metal 不支持几何着色器。
要使 Unity Editor 和独立平台播放器将 Metal 用作默认图形 API,请执行以下操作之一:
在 Editor 中,选择菜单:__Edit__ > Project Settings__,然后选择 Player__ 类别,并启用 Metal Editor Support。
如果使用 MacOS,打开 Terminal 并使用 -force-metal
命令行参数。
默认情况下,iOS、tvOS 和 macOS 独立平台播放器上均启用 Metal。
Xcode 提供 Metal API 验证功能,可用于跟踪隐蔽的问题。要在 Xcode 中启用 Metal API 验证,请执行以下操作:
在 Unity 中,针对 iOS 构建项目。结果将生成 Xcode 项目。
在 Xcode 中打开生成的 Xcode 项目,然后选择 Edit Scheme。
验证错误会中断 XCode 编辑器中的代码执行,并显示在设备日志中。
__注意__:启用验证会增加 CPU 使用率,因此仅在进行调试时启用。
Metal 允许您在运行应用程序时选择 GPU 设备。因此,可使用不同的 GPU 设置来测试项目,或使用低功耗 GPU 省电。
要更改 Unity Editor 目标 GPU 设备,请选择菜单:__Unity__ > Preferences… > General 并设置 __Device To Use__:
要更改独立平台播放器目标 GPU 设备,请启动应用程序(或选择菜单:__File__ > Build and run__)并将 Graphics device to use__ 设置为随后显示的对话框中的相关 GPU:
Metal 允许您使用 iOS 和 tvOS 10.0 中引入的无内存渲染目标来优化移动设备上的内存。借助此功能,您在渲染场景到渲染纹理 (RenderTexture)时,无需将其备份到系统内存,内容仅在渲染期间临时存储在 on-tile 内存中。
有关更多信息,请参阅RenderTexture.memorylessMode。
2018–05–22 页面已发布
在 2017.4 版中添加了关于使用 Metal 的建议
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.