OpenGL核心配置文件在OS X上令人难以置信的速度下降 [英] OpenGL core profile incredible slowdown on OS X

查看:52
本文介绍了OpenGL核心配置文件在OS X上令人难以置信的速度下降的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我向引擎添加了一个新的GL渲染器,该渲染器使用了核心配置文件.虽然它可以在Windows 和/或nvidia卡上正常运行,但在OS X上却要慢10倍(3 fps而不是30 fps).奇怪的是,我的兼容性配置文件渲染器运行正常.

I added a new GL renderer to my engine, which uses the core profile. While it runs fine on Windows and/or nvidia cards, it is like 10 times slower on OS X (3 fps instead of 30). The weird thing is, that my compatibility profile renderer runs fine.

我使用Instruments和GL profiler收集了一些跟踪记录:

I collected some traces with Instruments and the GL profiler:

https://www.dropbox.com/sh/311fg9wu0zrarzm/31CGvUcf2q

它表明应用程序将时间花在glDrawRangeElements上. 我尝试了以下操作:

It shows that the application spends its time in glDrawRangeElements. I tried the following things:

  • 改为使用glDrawElements(无效)
  • 翻转剔除(不影响速度)
  • 禁用某些GL_DYNAMIC_DRAW缓冲区(无效)
  • 绘制时在VAO之后绑定索引缓冲区(无效)
  • 将索引转换为4个字节(无效)
  • 使用GL_BGRA纹理(无效果)

我没有尝试过将顶点对齐到16字节边界和/或将索引转换为4字节,但是很严重的是,如果那是个问题,那为什么为什么要使用标准允许吗?

What I didn't try is to align my vertices to 16 byte boundary and/or convert indices to 4 byte, but seriously, if that would be the issue then why the hell does the standard allow it?

我正在创建这样的上下文:

I'm creating the context like this:

NSOpenGLPixelFormatAttribute attributes[] =
{
    NSOpenGLPFAColorSize, 24,
    NSOpenGLPFAAlphaSize, 8,
    NSOpenGLPFADepthSize, 24,
    NSOpenGLPFAStencilSize, 8,
    NSOpenGLPFADoubleBuffer,
    NSOpenGLPFAAccelerated,
    NSOpenGLPFANoRecovery,
    NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core,
    0
};

NSOpenGLPixelFormat* format = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes];
NSOpenGLContext* context = [[NSOpenGLContext alloc] initWithFormat:format shareContext:nil];

[self.view setOpenGLContext:context];
[context makeCurrentContext];

尝试以下规格:

  • radeon 6630M,OS X 10.7.5
  • radeon 6750M,OS X 10.7.5
  • geforce GT 330M,OS X 10.8.3

您有什么想法我可能做错了吗?再次,它与兼容性配置文件一起正常工作(虽然不使用VAO).

Do you have any ideas what I might do wrong? Again, it works fine with the compatibility profile (not using VAOs though).

更新:已向Apple报告.

UPDATE: reported to Apple.

更新:Apple并没有对此问题表示怀疑……无论如何,我创建了一个很小的测试程序,它实际上是很好的.现在,我将调用堆栈与Instruments进行了比较,发现使用引擎时, glDrawRangeElements 会执行两个调用:

UPDATE: Apple doesn't give a damn to the problem...anyway I created a small test program which is actually good. Now I compared the call stack with Instruments, and found out that when using the engine, glDrawRangeElements does two calls:

  • gleDrawArraysOrElements_ExecCore
  • gleDrawArraysOrElements_Entries_Body

在测试程序中,它仅调用第二个.现在,第一个调用的功能类似于即时模式渲染(gleFlushPrimitivesTCLFunc,gleRunVertexSubmitterImmediate),因此显然会导致速度下降.

while in the test program it calls only the second. Now the first call does something like an immediate mode render (gleFlushPrimitivesTCLFunc, gleRunVertexSubmitterImmediate), so obviously casues the slowdown.

推荐答案

最后,我能够重现减速情况.这简直太疯狂了……这显然是由于在"my_Position"属性上调用 glBindAttribLocation 引起的.现在,我做了一些测试:

Finally, I was able to reproduce the slowdown. This is just crazy... It is clearly caused by glBindAttribLocation being called on the "my_Position" attribute. Now I did some testing:

  • 默认为1(由 glGetAttribLocation 返回)
  • 如果我将其设置为零,就没有问题
  • 如果将其设置为1,渲染会变慢
  • 如果我将其设置为更大的数字,它将再次变慢
  • 1 is default (as returned by glGetAttribLocation)
  • if I set it to zero, theres no problem
  • if I set it to 1, the rendering becomes slow
  • if I set it to any larger number, it is slow again

很明显,我重新链接了程序(检查代码).在实现中这不是问题,我也使用正常"值对其进行了测试.

Obviously I relink the program (check code). It is not a problem in the implementation, I tested it with "normal" values too.

测试程序:

https://www.dropbox.com/s/dgg48g1fwgyc5h0/SLOWDOWN_REPRO.zip

如何复制:

  • 使用XCode打开
  • 打开common/glext.h(请勿打扰该名称)
  • 将GLDECLUSAGE_POSITION常量从0修改为1
  • 编译并运行=>慢
  • 变回零=>好

这篇关于OpenGL核心配置文件在OS X上令人难以置信的速度下降的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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