Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
831 views
in Technique[技术] by (71.8m points)

performance - OpenGL core profile incredible slowdown on OS X

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.

I collected some traces with Instruments and the GL profiler:

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

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

  • use glDrawElements instead (no effect)
  • flip culling (no effect on speed)
  • disable some GL_DYNAMIC_DRAW buffers (no effect)
  • bind index buffer after VAO when drawing (no effect)
  • converted indices to 4 byte (no effect)
  • use GL_BGRA textures (no effect)

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];

Tried on the following specs:

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

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

UPDATE: reported to Apple.

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 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.

Test program:

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

How to repro:

  • open with XCode
  • open common/glext.h (don't be disturbed by the name)
  • modify the GLDECLUSAGE_POSITION constant from 0 to 1
  • compile and run => slow
  • changing back to zero => good

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...