ios - Metal 最佳实践 - 在渲染期间更改渲染管道描述符

标签 ios swift ios9 metal

在我的渲染管道中,我想使用一些着色器,并且在某些情况下修改 MTLRenderPipelineDescriptor 对象上的参数(例如,更改混合函数)。

在我看来,我有 2 个选择:

  1. 为每个参数组合(顶点着色器、片段着色器、混合等)创建并预编译一个 MTLRenderPipelineState。我可以有很多这样的状态对象,因为可能有很多组合。

  2. 在渲染过程中创建并编译新的 MTLRenderPipelineState 对象。

哪个选项更好?我还缺少其他选项吗?

最佳答案

对于最佳实践(和最佳性能),您应该遵循选项 1

Transient and Non-transient Objects in Metal Metal 编程指南 部分非常清楚哪些对象应被视为 transient 或非 transient ,以及应缓存和重用非 transient 对象。

特别是对于 MTLRenderPipelineState 对象,这是指南在 Creating a Render Pipeline State 中必须说的内容部分:

A render pipeline state object is a long-lived persistent object that can be created outside of a render command encoder, cached in advance, and reused across several render command encoders. When describing the same set of graphics state, reusing a previously created render pipeline state object may avoid expensive operations that re-evaluate and translate the specified state to GPU commands.

关于ios - Metal 最佳实践 - 在渲染期间更改渲染管道描述符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36033890/

相关文章:

ios - 自定义 UIActionSheet

ios - 单击 tableView 中的文本字段时,ScrollView 没有向上移动

xcode - localizable.string 不适用于 iOS 8 中的模拟器

swift - 如何缩放/定位节点 Swift SpriteKit?自定义 View ?

swift - 水平 ScrollView 中的自定义 View 。是否可以?

ios - 使用UIActivityViewController对话框通过Twitter的iOS 8&9 iPad共享在60秒内关闭了viewServiceDidTerminateWithError

iphone - 如何构建通用ios静态库

ios - 单击按钮删除 View Controller

html - 从 HTML 源 Swift 中提取链接

ios9 - Xcode7:此应用程序正在从后台线程修改自动布局引擎,这可能导致引擎损坏和奇怪的崩溃