在我的渲染管道中,我想使用一些着色器,并且在某些情况下修改 MTLRenderPipelineDescriptor 对象上的参数(例如,更改混合函数)。
在我看来,我有 2 个选择:
为每个参数组合(顶点着色器、片段着色器、混合等)创建并预编译一个 MTLRenderPipelineState。我可以有很多这样的状态对象,因为可能有很多组合。
在渲染过程中创建并编译新的 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/