从CVImageBuffer保持MTLTexture会导致口吃 [英] Holding onto a MTLTexture from a CVImageBuffer causes stuttering

查看:356
本文介绍了从CVImageBuffer保持MTLTexture会导致口吃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 CVImageBuffer (来自相机和玩家)创建 MTLTexture > CVMetalTextureCacheCreateTextureFromImage 获取 CVMetalTexture 然后 CVMetalTextureGetTexture 获取 MTLTexture

I'm creating a MTLTexture from CVImageBuffers (from camera and players) using CVMetalTextureCacheCreateTextureFromImage to get a CVMetalTexture and then CVMetalTextureGetTexture to get the MTLTexture.

我看到的问题是,当我稍后使用Metal渲染纹理时,我偶尔会看到渲染出的视频帧可能因为CoreVideo正在修改底层的 CVImageBuffer 存储和 MTLTexture ,因此顺序(在视觉上它会在时间上前后断断续续)只是指向那里。

The problem I'm seeing is that when I later render the texture using Metal, I occasionally see video frames rendered out of order (visually it stutters back and forth in time), presumably because CoreVideo is modifying the underlying CVImageBuffer storage and the MTLTexture is just pointing there.

有没有办法让CoreVideo不接触那个缓冲区并使用其池中的另一个缓冲区直到我发布 MTLTexture object?

Is there any way to make CoreVideo not touch that buffer and use another one from its pool until I release the MTLTexture object?

我当前的解决方法是使用 MTLBlitCommandEncoder 对纹理进行blitting,但是因为我只是需要保持纹理约30毫秒,这似乎是不必要的。

My current workaround is blitting the texture using a MTLBlitCommandEncoder but since I just need to hold on to the texture for ~30 milliseconds that seems unnecessary.

推荐答案

我最近碰到了同样的问题。问题是MTLTexture无效,除非它拥有CVMetalTextureRef仍然存在。您必须在使用MTLTexture的整个过程中保持对CVMetalTextureRef的引用(一直到当前渲染周期结束)。

I recently ran into this exact same issue. The problem is that the MTLTexture is not valid unless it's owning CVMetalTextureRef is still alive. You must keep a reference to the CVMetalTextureRef the entire time you're using the MTLTexture (all the way until the end of the current rendering cycle).

这篇关于从CVImageBuffer保持MTLTexture会导致口吃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆