博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Metal Tips and Techniques
阅读量:3612 次
发布时间:2019-05-21

本文共 3172 字,大约阅读时间需要 10 分钟。

Metal Tips and Techniques

This chapter discusses tips and techniques that can improve app performance or developer productivity.

Creating Libraries During the App Build Process

Compiling shader language source files and building a library (.metallib file) during the app build process achieves better app performance than compiling shader source code at runtime. You can build a library within Xcode or by using command line utilities.

Using Xcode to Build a Library

Any shader source files that are in your project are automatically used to generate the default library, which you can access from Metal framework code with the  method of .

Using Command Line Utilities to Build a Library

 shows the command line utilities that form the compiler toolchain for Metal shader source code. When you include .metal files in your project, Xcode invokes these tools to build a library file that you can access in your app at run time.

To compile shader source into a library without using Xcode:

  1. Use metal to compile each .metal file into a single .air file, which stores an intermediate representation of shader language code.

  2. Use metal-ar to archive several .air files together into a single .metalar file. metal-ar is similar to the Unix utility ar.

  3. Use metallib to build a Metal .metallib library file from the archive .metalar file.

Figure 8-1  Building a Library File with Command Line Utilities

To access the resulting library in framework code, call the  method of .

Xcode Scheme Settings and Performance

When a Metal app is running from Xcode, the default scheme settings reduce performance. Xcode detects whether the Metal API is used in the source code and automatically enables the GPU Frame Capture and Metal API Validation settings, as seen in Figure 8-2. When GPU Frame Capture is enabled, the debug layer is activated. When Metal API Validation is enabled, each call is validated, which affects performance further. For both settings, CPU performance is more affected than GPU performance. Unless you disable these settings, app performance may noticeably improve when the app is run outside of Xcode.

Figure 8-2  Xcode Scheme Editor Settings for a Metal App

Debugging

Use the tips in the following sections to gain more useful diagnostic information when debugging and profiling your Metal app.

File Extension for Metal Shading Language Source Files

For Metal shading language source code file names, you must use the .metal file name extension to ensure that the development tools (Xcode and the GPU frame debugger) recognize the source files when debugging or profiling.

Performing Frame Capture with Xcode

To perform frame capture in Xcode, enable debug and call the  method of  to inform Xcode. The  and  methods of  similarly inform Xcode about frame capture, so call  only if those methods are not present.

The Label Property

Many Metal framework objects—such as command buffers, pipeline states, and resources—support a  property. You can use this property to assign a name for each object that is meaningful in the context of your application’s design. These labels appear in the Xcode Frame Capture debugging interface, allowing you to more easily identify objects.


转载地址:http://azzkn.baihongyu.com/

你可能感兴趣的文章
公司架构师常常提起的DNS负载均衡是个什么鬼?
查看>>
Kafka如何做到1秒处理1500万条消息?
查看>>
儒猿云平台:解决技术学习的“最后一公里”
查看>>
图解 | 你管这破玩意叫线程池?
查看>>
图解 | 你管这破玩意儿叫TCP?
查看>>
ConcurrentHashMap中有十个提升性能的细节,你都知道吗?
查看>>
你管这破玩意叫 class?
查看>>
搞懂高可用:异地多活,看这篇文章就够了!
查看>>
从面试角度一文学完 Kafka
查看>>
图解 | 你管这破玩意叫文件系统?
查看>>
Java 8 ConcurrentHashMap源码中竟然隐藏着两个BUG
查看>>
工作四年,分享50个让你代码更好的小建议
查看>>
聊聊二维码扫码登录的原理
查看>>
大厂为什么都很重视 API 网关?聊聊 API 网关的作用
查看>>
如何设计一个亿级消息量的 IM 系统
查看>>
高并发系列:存储优化之也许可能是史上最详尽的分库分表文章之一
查看>>
为什么 Java 线程没有 Running 状态?一下被问懵!
查看>>
Java 线程的状态及转换
查看>>
细数ThreadLocal三大坑,内存泄露仅是小儿科
查看>>
主流微服务全链路监控系统实战
查看>>