【问题标题】:OpenGLES blending code to Metal translationOpenGLES 混合代码到金属翻译
【发布时间】:2018-05-28 07:49:08
【问题描述】:

我有这个简单的 OpenGLES 混合代码到 Metal:

 glBlendEquation(GL_FUNC_ADD);
 glBlendFunc(GL_ONE, GL_ONE);
 glEnable(GL_BLEND);

我在 Metal 中编写了代码,但我很困惑它是否完全相同。具体来说,我是否需要提及 alpha 混合因子。因为我看到此代码在 Metal 中的性能比 OpenGLES 差,这很奇怪。如果此代码中缺少任何内容,请告诉我。

   let renderPipelineDescriptorGreen = MTLRenderPipelineDescriptor()
    renderPipelineDescriptorGreen.vertexFunction = vertexFunctionGreen
    renderPipelineDescriptorGreen.fragmentFunction = fragmentFunctionAccumulator
    renderPipelineDescriptorGreen.colorAttachments[0].pixelFormat = .bgra8Unorm
    renderPipelineDescriptorGreen.colorAttachments[0].isBlendingEnabled = true
    renderPipelineDescriptorGreen.colorAttachments[0].rgbBlendOperation = .add
    renderPipelineDescriptorGreen.colorAttachments[0].sourceRGBBlendFactor = .one
    renderPipelineDescriptorGreen.colorAttachments[0].destinationRGBBlendFactor = .one

【问题讨论】:

    标签: ios opengl-es metal


    【解决方案1】:

    相对于 OpenGL 代码,混合配置似乎是正确的。管道描述符具有可能很好的 alpha 混合默认值。 alphaBlendOperation 默认为.addsourceAlphaBlendFactor 默认为.onedestinationAlphaBlendFactor 默认为.zero

    当然,还有其他因素可能会影响性能,例如着色器函数的细节。

    您如何衡量绩效?

    Metal 应用可以比 OpenGL 应用具有更高的性能,但这并不是因为任何给定的单一渲染操作都更快。 GPU 硬件的性能将是那里的限制因素。 Metal 可以通过消除 OpenGL 的开销、让应用对资源管理进行更多控制等来实现更高的性能。在不代表真实应用的非常简单的测试用例中,这些因素可能不会出现。

    【讨论】:

    • 与 OpenGLES 中的类似代码(GPUImage 框架的 HistogramFilter)相比,我纯粹以 FPS 术语衡量性能。 OpenGLES 代码的唯一区别是 GPUImage 将像素值作为顶点传递给顶点着色器(这意味着它读取 CPU 中纹理的像素值),而我在 GPU 的顶点着色器中读取像素值,就像我在这里所做的那样:-stackoverflow.com/questions/50504961/…
    • 好的,我想我错过了在 GPUImage 代码中设置等效参数以进行比较。 Metal 代码比 OpenGLES 2.0 快 2 倍。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-21
    • 1970-01-01
    • 1970-01-01
    • 2018-12-26
    • 1970-01-01
    相关资源
    最近更新 更多