【问题标题】:Cast MTLTexture from depth32Float to bgra8UNorm将 MTLTexture 从 depth32Float 转换为 bgra8UNorm
【发布时间】:2019-07-09 11:14:48
【问题描述】:

我想使用 Metal Performance Shaders 处理来自深度缓冲区的信息,例如使用高斯或索贝尔着色器。

在使用MTLTexturedepth32Float 像素格式时遇到问题。 MPSImageGaussianBlur 或任何其他性能着色器不接受它作为源纹理。

我尝试使用:depthBufferTexture.makeTextureView(pixelFormat: .bgra8Unorm) 进行转换,但出现错误提示:

validateArgumentsForTextureViewOnDevice:1406:断言失败source texture pixelFormat (MTLPixelFormatDepth32Float) not castable.

有什么方法可以将depth32Float 转换为bgra8UNorm 或任何其他像素格式?

【问题讨论】:

    标签: metalkit metal-performance-shaders


    【解决方案1】:

    在我看来,从depth32Float 转换为bgra8UNorm 没有多大意义,它们具有不同的维度和通道数。在您的情况下,最好的解决方案是使用MTLPixelFormatR32Float。 要将depth32Float 转换为MTLPixelFormatR32Float,请使用MTLComputeCommandEncoder

    【讨论】:

    • 感谢您的提示!它对我有用。实际上这是我的第一个想法,但我担心性能问题。再次感谢
    • 很高兴能帮上忙。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-09
    • 1970-01-01
    • 2018-06-09
    • 2017-12-04
    • 1970-01-01
    • 2021-04-23
    • 1970-01-01
    相关资源
    最近更新 更多