avfoundation - 如何在 macOS 上使用 MTLTexture 和 MTLStorageModeShared 在 kCVPixelFormatType_422YpCbCr8 中渲染 CVPixelBuffer
问题描述
我不知道如何使用 MTLStorageModeShared 加速 CIImage 渲染到 drawable.texture:
目前的程序是(大约):
- 我的 cvBuffer 在 kCVPixelFormatType_422YpCbCr8 pixelFormat 中(非平面)
- 我创建 ciimage = [CIImage imageWithCVImageBuffer: cvBuffer]
- 我向 CAMetalLayer 询问 nextDrawable
- 我创建 CIRenderDestination
- 我渲染 ciimage:
[ciContext startTaskToRender: ciImage toDestination: renderDestination error: &error];
这是代码中最慢的部分(大约每秒需要“更多”时间来渲染)。在带有集成 GPU 的 Mac 上运行时,它会在关键时间间隔下呈现。我猜这是因为在集成显卡上使用了共享内存 GPU 和 CPU。我的想法是使用 MTLStorageModeShared 创建 MTLTexture,然后将 kCVPixelFormatType_422YpCbCr8 pixelFormat 中的 cvBuffer 复制到纹理,使用着色器将 kCVPixelFormatType_422YpCbCr8 转换为 MTLPixelFormatRG8Unorm 纹理并blit 到目标纹理。
我的问题:
- MTLTexture 不接受 YUV 像素格式。将 kCVPixelFormatType_422YpCbCr8 转换为 kCVPixelFormatType_32BGRA 的最快方法是什么(然后我可以将它与 MTLTexture 一起使用)?
- 如果没有这样的快速函数,要转换这样的 cvBuffer,MTLCompute……是正确的方向吗?
- 这个想法(将 MTLTexture 与 MTLStorageModeShared 一起使用)对吗?我会得到更好的表现吗?
- 是否有任何其他技术可以避免在具有离散 GPU 的 macOS 上进行 CPU-> GPU 内存传输?
谢谢你。
解决方案
推荐阅读
- python - Python socket 同时接收多条消息
- django - 如何将不同模型的查询集与外键关系合并?
- python-3.x - python3日期时间问题
- node.js - Braintree.Transaction.Status 在braintree-node 中不存在
- python - 每次我运行我的程序时,都会出现意外的冻结 matplotlib 图形窗口
- python - 道路设计特征的对象识别
- android - StartLockTask 因硬件按钮而失败
- php - 如何一次编写多个foreach语句
- c++ - 如何将向量中的每个元素增加指定值?
- node.js - 使用 HTTP 代理时通过 Chrome 与 Node.js 的 HTTP 请求的差异