OpenGLES将代码混合到金属翻译 [英] OpenGLES blending code to Metal translation

查看:103
本文介绍了OpenGLES将代码混合到金属翻译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Metal拥有以下简单的OpenGLES混合代码:

 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

解决方案

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

当然,还有其他一些因素可能会影响性能,例如着色器功能的细节.

您如何衡量效果?

金属应用程序可以比OpenGL应用程序具有更高的性能,但这不是因为任何给定的单个渲染操作都更快. GPU硬件的性能将成为限制因素. Metal可以消除OpenGL的开销,为应用程序提供对资源管理的更多控制权等,从而获得更高的性能.在不代表真实应用程序的非常简单的测试用例中,这些因素可能不会出现.

I have this simple OpenGLES blending code to Metal:

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

I wrote code in Metal but am confused if it is exactly does the same job. Specifically, do I need to mention alpha blending factors or no. Because I see performance of this code in Metal worse than OpenGLES which is weird. Please let me know if there is anything missing in this code.

   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

解决方案

The blending configuration seems correct relative to the OpenGL code. The pipeline descriptor has default values for alpha blending that are probably fine. alphaBlendOperation defaults to .add, sourceAlphaBlendFactor defaults to .one, and destinationAlphaBlendFactor defaults to .zero.

Of course, there's other stuff that may play a factor in performance, like the specifics of your shader functions.

How are you measuring the performance?

Metal apps can have higher performance than OpenGL apps, but that's not because any given single render operation is faster. The GPU hardware's performance will be the limiting factor there. Metal can achieve higher performance by eliminating overhead that OpenGL has, by giving the app more control over resource management, etc. In very simple test cases that aren't representative of real apps, these factors may not show up.

这篇关于OpenGLES将代码混合到金属翻译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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