# Metal（API）

Metal 是 Apple 为其自有 GPU 开发的一套低开销图形与计算应用编程接口（API），配套一门着色语言以及一整套性能分析与调试工具，覆盖 iPhone、iPad、Mac、Apple TV 和 [Apple Vision Pro](https://www.edgepedia.org/zh/apple-vision-pro)。<sup>[1](https://developer.apple.com/metal/)</sup> Apple 将其描述为一套现代、高度集成的图形与计算 API，旨在让开发者充分利用 Apple 芯片，其低开销模型让开发者可以直接控制 GPU 执行的每一项任务。<sup>[1](https://developer.apple.com/metal/)</sup>

| 关键事实 | 详情 |
|---|---|
| 首次发布 | 2014 年 WWDC，由 Apple 软件工程副总裁克雷格·费德里吉（Craig Federighi）发布，作为 iOS 上 OpenGL 的替代方案，面向 A7 系统级芯片<sup>[2](https://time.com/2814252/apples-metal-ios/)</sup> |
| 发布时宣称的提升 | 绘制调用速率最高可达 OpenGL 的 10 倍；支持预编译着色器和高效多线程<sup>[2](https://time.com/2814252/apples-metal-ios/)</sup> |
| 扩展到 Mac | 2015 年 WWDC 宣布支持 OS X<sup>[3](https://time.com/3912982/apple-metal/)</sup> |
| 图形与计算 | 缓冲区、纹理、命令队列等同一套数据结构同时服务于图形与计算操作<sup>[4](https://developer-rno.apple.com/library/archive/documentation/Miscellaneous/Conceptual/MetalProgrammingGuide/Device/Device.html)</sup> |
| 当前主版本 | Metal 4，于 2025 年 WWDC 推出，带来新的命令队列协议、统一编码器、驻留集和机器学习集成<sup>[5](https://msc-kobol-public-prod.apple.com/documentation/Metal/understanding-the-metal-4-core-api)</sup><sup> • </sup><sup>[6](https://developer.apple.com/videos/play/wwdc2025/254/)</sup> |
| Metal 上的 Vulkan | 不存在原生 Vulkan 驱动，因为 Apple 不支持替代性的底层图形驱动；Khronos 的 MoltenVK 项目在 Metal 之上对 Vulkan 做分层实现<sup>[7](https://www.lunarg.com/wp-content/uploads/2024/01/The-State-of-Vulkan-on-Apple-January-2024.pdf)</sup> |

## 设计与编程模型

Metal 通过一小组核心对象来暴露 GPU。应用通过设备对象找到 GPU——这是用于绘制图形和并行运行计算的主要 Metal 接口——并创建命令队列，为 GPU 调度渲染与计算工作。<sup>[8](https://ma-kobol-public-prod.apple.com/documentation/metal/mtldevice)</sup> 命令被放入命令缓冲区，缓冲区入队和提交的顺序会影响 Metal 执行工作的顺序；渲染命令编码器和计算命令编码器负责发出各条具体命令。<sup>[9](https://apple-docs.everest.mt/docs/metal/setting-up-a-command-structure)</sup>

**图形与计算共用一套模型。** 无论是图形还是计算工作，Metal 都依赖一套通用的数据结构和资源——包括缓冲区、纹理和命令队列——其着色语言同时处理图形与计算函数。资源可以在运行时接口、图形着色器和计算函数之间共享。<sup>[4](https://developer-rno.apple.com/library/archive/documentation/Miscellaneous/Conceptual/MetalProgrammingGuide/Device/Device.html)</sup> 着色器可以在构建时随应用一同编译，并在运行时加载，Apple 的文档称这种工作流能带来更好的代码生成和更便捷的调试；同时也支持运行时编译。<sup>[4](https://developer-rno.apple.com/library/archive/documentation/Miscellaneous/Conceptual/MetalProgrammingGuide/Device/Device.html)</sup>

着色语言在 Apple 的《Metal 着色语言规范》中另行规定。<sup>[10](https://developer.apple.com/metal/resources/)</sup> 在核心 API 之上，Metal Performance Shaders 框架提供了一套优化的计算与渲染着色器库，可充分利用每款 GPU 的硬件特性。<sup>[11](https://developer.apple.com/documentation/Metal?language=objc)</sup>

## 历史

**2014 年：iOS 首秀。** Apple 软件工程副总裁[克雷格·费德里吉](https://www.edgepedia.org/zh/craig-federighi)在 2014 年 WWDC 上发布 Metal，作为 OpenGL 的替代方案，成为 iOS 开发者触及 A7 芯片硬件的途径。他称 OpenGL“日益成为……游戏与硬件之间厚厚的一层开销”，并承诺以 Metal 实现“近乎直接访问底层硬件”。<sup>[2](https://time.com/2814252/apples-metal-ios/)</sup> 他宣称绘制调用速率最高可提升 10 倍，并表示 Metal 支持可缩短加载时间的预编译着色器以及高效多线程。<sup>[2](https://time.com/2814252/apples-metal-ios/)</sup> Apple 曾与 Crytek、Epic、EA 和 [Unity](https://www.edgepedia.org/zh/unity-game-engine) 合作制作 Metal 演示；费德里吉提到 Crytek 的一个演示达到每帧最高 4,000 次绘制调用，Epic 创始人蒂姆·斯威尼（Tim Sweeney）则展示了虚幻引擎 4 的“禅意花园”技术演示。<sup>[2](https://time.com/2814252/apples-metal-ios/)</sup> 当时有评论将 Metal 的角色类比为 Windows 上的 DirectX。<sup>[12](https://time.com/2821769/directx-apple-metal-opengl/)</sup>

**2015 年：OS X。** 在 2015 年 WWDC 上，费德里吉宣布 Metal 登陆 OS X，Epic 再次登台在 Mac 上做了演示。<sup>[3](https://time.com/3912982/apple-metal/)</sup>

**Metal 3，2022 年。** Metal 3 新增了快速资源加载，利用 Apple 芯片的统一内存架构和高速 SSD 存储，以低延迟、高吞吐量加载资源；离线着色器编译，缩短加载时间；MetalFX 超分，以较低分辨率渲染再放大到最终分辨率；[网格着色器](https://www.edgepedia.org/zh/mesh-shader)，以灵活的两阶段对象与网格模型取代传统顶点阶段来处理几何；以及更快的加速结构构建和求交，用于光线追踪。<sup>[13](https://developer.apple.com/videos/play/wwdc2022/10066/)</sup><sup> • </sup><sup>[14](https://developer.apple.com/videos/play/wwdc2022/10104/)</sup> Metal 3 还增强了无绑定渲染，让着色器可以通过无界数组访问资源。<sup>[15](https://developer.apple.com/videos/play/wwdc2022/10101/)</sup>

## Metal 4

Metal 4 于 2025 年 WWDC 推出，面向流式加载数 GB 几何与纹理数据、并以数千个着色器进行渲染的现代游戏引擎。<sup>[6](https://developer.apple.com/videos/play/wwdc2025/254/)</sup> Metal 新增 `MTL4CommandQueue` 协议，这是一种全新的命令队列设计，在命令缓冲区提交的那一刻就把工作分派给 GPU，从而减少 CPU 运行时间和内存开销。<sup>[5](https://msc-kobol-public-prod.apple.com/documentation/Metal/understanding-the-metal-4-core-api)</sup>

**编码与资源。** Metal 4 将最常见的操作统一为两个编码器类：渲染和计算；所有计算操作、内核调度、位块传输和加速结构构建都可以编码进单个计算编码器，除非用通道屏障表达数据依赖，否则它们会并发执行。<sup>[6](https://developer.apple.com/videos/play/wwdc2025/254/)</sup> 命令分配器让开发者可以显式管理编码期间分配的内存，命令缓冲区可以跨多线程编码工作。<sup>[6](https://developer.apple.com/videos/play/wwdc2025/254/)</sup> 面向大规模资源管理，参数表和驻留集允许绑定数千个资源；驻留集将管线、缓冲区、纹理和可绘制对象分组，一次性使其对 GPU 可见，可挂接到命令队列或正在提交的命令缓冲区上。<sup>[6](https://developer.apple.com/videos/play/wwdc2025/254/)</sup> 队列屏障表达同一队列上不同编码器之间的数据依赖，Metal 4 让开发者负责同步资源，以减少跟踪开销。<sup>[6](https://developer.apple.com/videos/play/wwdc2025/254/)</sup>

**机器学习集成。** Metal 4 新增机器学习命令编码器和张量资源，让应用可以将模型运行与渲染、计算工作一同安排在 GPU 时间线上；还提供着色器机器学习，将神经网络直接嵌入着色器以获得效果与性能提升。<sup>[16](https://www.youtube.com/watch?v=ev2xZYzupD0)</sup> Apple 指出，机器学习命令编码器并不局限于整帧游戏处理，可以服务于任何符合实时预算的网络。<sup>[17](https://developer-mdn.apple.com/videos/play/wwdc2025/262/)</sup>

**MetalFX。** 根据 Apple 的功能集表格，MetalFX 系列涵盖空间超分（Metal 3，Apple GPU 家族 3）、时域超分（Apple 家族 7）、帧插值（Apple 家族 5）和降噪超分（Apple 家族 9）。<sup>[18](https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf)</sup>

## 机器学习与计算性能

Metal 不仅面向图形，也面向机器学习等要求严苛的计算工作负载。<sup>[1](https://developer.apple.com/metal/)</sup> 针对 Apple 芯片的独立基准测试展示了这套 API 所能达到的水平：用 Metal 着色语言编写基准的研究人员测得 M4 GPU 的 FP32 峰值性能为 2.9 TFLOPS，而其 CPU 为 1.5 FP32 TFLOPS，从 M2 起 GPU 性能便超过 CPU；M 系列 GPU 不支持原生 FP64，但可以模拟，并且针对 FP32 和 FP16/INT8 混合精度计算做了优化。<sup>[19](https://arxiv.org/abs/2502.05317)</sup>

## Vulkan、移植与更广泛的生态

Apple 不支持替代性底层图形驱动的机制，因此面向 Apple 平台的原生 Vulkan 驱动不可能存在；Khronos 的 Vulkan 可移植性倡议转而标准化了分层在其他底层 API 之上的 Vulkan 实现，MoltenVK 就是在 Metal 之上实现 Vulkan。<sup>[7](https://www.lunarg.com/wp-content/uploads/2024/01/The-State-of-Vulkan-on-Apple-January-2024.pdf)</sup> MoltenVK 支持 `VK_KHR_portability_subset` 扩展；在 macOS 上，只有在创建实例时设置了 `VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR` 标志，Vulkan 加载器才会枚举 MoltenVK 设备。<sup>[20](https://github.com/KhronosGroup/MoltenVK/blob/main/Docs/MoltenVK_Runtime_UserGuide.md)</sup>

**移植工具。** Apple 的游戏移植工具包汇集了在 Mac 上评估 Windows 游戏、转换着色器与资源以及构建原生游戏的工具。<sup>[1](https://developer.apple.com/metal/)</sup> Metal 着色器转换器可将现有的 HLSL 着色器编译为 Metal，Metal C++ 接口（metal-cpp）则允许用 C++ 编写 Metal 程序。<sup>[21](https://developer-rno.apple.com/videos/play/wwdc2023/10125/)</sup> 一个具体的大规模移植案例是 Mac 版《赛博朋克 2077》：CD Projekt Red 添加了对 Metal 的支持，使用 Metal C++ 接口和着色器转换器针对 Apple 芯片 GPU 进行优化，并采用了 Apple 的分块渲染——将渲染拆分为更小的块并分配给 GPU 核心；MetalFX 帧插值和 MetalFX 降噪计划在 Metal 4 发布时集成。<sup>[22](https://www.tomshardware.com/software/macos/cyberpunk-2077-comes-to-the-mac-july-17-patient-apple-gamers-get-support-for-every-apple-silicon-chip-new-metal-features-and-spatial-audio)</sup>

**功能集与硬件家族。** Metal 的能力通过功能集表格描述，表格将每项功能映射到最低 Metal 版本和 Apple GPU 家族；例如，网格着色需要 Apple 家族 7 上的 Metal 3，64 位原子操作需要 Apple 家族 9，而参数表、命令分配器和命令屏障等 Metal 4 功能需要 Apple 家族 7。<sup>[18](https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf)</sup> 应用在运行时通过 `MTLFeatureSet.iOS_GPUFamily4_v1` 之类的枚举查询设备支持的功能集。<sup>[23](https://developer.apple.com/documentation/metal/detecting-gpu-features-and-metal-software-versions?language=objc%2Cobjc)</sup> 在诊断方面，Metal HUD 是一种平视显示工具，最初为开发者在 macOS 上测试游戏和应用而构建，可从终端启用。<sup>[24](https://www.techradar.com/computing/mac-os/benchmarking-macs-3dmark-and-other-testing-tools-that-make-it-easy-to-test-your-apple-macs-performance)</sup>

## References

1. [Metal Overview, Apple Developer](https://developer.apple.com/metal/)
2. [Apple's 'Metal' Could Transform iOS Gaming If It Works as Promised, Time (June 2014)](https://time.com/2814252/apples-metal-ios/)
3. [Apple Just Gave Gamers a Huge Reason to Hope, Time (June 2015)](https://time.com/3912982/apple-metal/)
4. [Fundamental Metal Concepts, Metal Programming Guide (archive), Apple Developer](https://developer-rno.apple.com/library/archive/documentation/Miscellaneous/Conceptual/MetalProgrammingGuide/Device/Device.html)
5. [Understanding the Metal 4 core API, Apple Developer Documentation](https://msc-kobol-public-prod.apple.com/documentation/Metal/understanding-the-metal-4-core-api)
6. [Explore Metal 4 games, WWDC25, Apple Developer](https://developer.apple.com/videos/play/wwdc2025/254/)
7. [The State of Vulkan on Apple, January 2024, LunarG](https://www.lunarg.com/wp-content/uploads/2024/01/The-State-of-Vulkan-on-Apple-January-2024.pdf)
8. [MTLDevice, Apple Developer Documentation](https://ma-kobol-public-prod.apple.com/documentation/metal/mtldevice)
9. [Setting up a command structure, Apple Developer Docs](https://apple-docs.everest.mt/docs/metal/setting-up-a-command-structure)
10. [Resources, Metal, Apple Developer](https://developer.apple.com/metal/resources/)
11. [Metal, Apple Developer Documentation](https://developer.apple.com/documentation/Metal?language=objc)
12. [DirectX Creator Says Apple's Metal Heralds the End of OpenGL, Time (June 2014)](https://time.com/2821769/directx-apple-metal-opengl/)
13. [Discover Metal 3, WWDC22, Apple Developer](https://developer.apple.com/videos/play/wwdc2022/10066/)
14. [Load resources faster with Metal 3, WWDC22, Apple Developer](https://developer.apple.com/videos/play/wwdc2022/10104/)
15. [Go bindless with Metal 3, WWDC22, Apple Developer](https://developer.apple.com/videos/play/wwdc2022/10101/)
16. [WWDC25: Combine Metal 4 machine learning and graphics, Apple Developer (YouTube)](https://www.youtube.com/watch?v=ev2xZYzupD0)
17. [Combine Metal 4 machine learning and graphics, WWDC25, Apple Developer](https://developer-mdn.apple.com/videos/play/wwdc2025/262/)
18. [Metal Feature Set Tables, Apple Developer](https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf)
19. [Apple vs. Oranges: Evaluating the Apple Silicon M-Series SoCs for HPC Performance and Efficiency, arXiv:2502.05317](https://arxiv.org/abs/2502.05317)
20. [MoltenVK Runtime User Guide, KhronosGroup/MoltenVK, GitHub](https://github.com/KhronosGroup/MoltenVK/blob/main/Docs/MoltenVK_Runtime_UserGuide.md)
21. [Bring your game to Mac, Part 3: Render with Metal, WWDC23, Apple Developer](https://developer-rno.apple.com/videos/play/wwdc2023/10125/)
22. [Cyberpunk 2077 comes to the Mac July 17, Tom's Hardware](https://www.tomshardware.com/software/macos/cyberpunk-2077-comes-to-the-mac-july-17-patient-apple-gamers-get-support-for-every-apple-silicon-chip-new-metal-features-and-spatial-audio)
23. [Detecting GPU features and Metal software versions, Apple Developer Documentation](https://developer.apple.com/documentation/metal/detecting-gpu-features-and-metal-software-versions?language=objc%2Cobjc)
24. [Benchmarking Macs: 3DMark and other testing tools, TechRadar](https://www.techradar.com/computing/mac-os/benchmarking-macs-3dmark-and-other-testing-tools-that-make-it-easy-to-test-your-apple-macs-performance)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 30, 2026; Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Development tools and collaboration infrastructure › Frameworks, libraries, and APIs › Graphics and multimedia APIs

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/metal-api

English original: https://www.edgepedia.org/metal-api
