Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Drawing image via OpenGL textures: no speedup?



Two things come to mind. The call stack is obviously somewhat bogus, OpenGL does a lot of runtime code gen which confuses samples so once you get past 0x1e821c8 things are really up in the air. Run the OpenGL Profiler on your app (which gives the right calls stats) and look at the call stats to determine were time in GL is being spent. Second, turn off execution of all OpenGL entry points and see what the change in frame rate is (i.e., how much affect does GL have on the app's speed).

One thing to think about is that if you are updating the texture every frame you are more like a movie app then an image app. So keep this in mind (you are using shared memory which would be the right thing). If you are modifying your texture in place you will also need to correctly fence that modification.

We should have more examples out next week showing some of these techniques.


Hi folks,

I've been trying to speed up Squeak's display performance by using OpenGL to do the image (texture) drawing, and using the various "extreme" optimization techniques. The OpenGL drawing code was mostly copied from the OpenGLView sample code, the main difference is that I have only 1 texture and reload it every time. Anyway, drawing isn't getting any faster, despite the fact that drawing has been switched to OpenGL (I disabled the "normal" drawing code just to be sure). It seems like something is making a copy of the image/texture in main memory, despite the fact that I've turned on all the relevant OpenGL extensions.

Throughput is thus limited to about 80 MB/s, with the overall speed being around 20% slower than staight CoreGraphics calls.


Here is the call graph showing the memmove():

Call graph:
5000 Thread_0d03
5000 start
5000 _start
...
4891 -[SqView drawRect:]
3770 -[SqView defineQuad:]
3770 0x1e821c8
3770 gldUpdateDispatch
3762 gldDestroyPipelineProgram
3761 gldFlush
3761 gldFlush
3387 gldFlush
3386 memmove
3386 memmove [STACK TOP]

As you can see, most of the time is spent moving memory. The "defineQuad" method (which is "my" method in the call-stack) looks like this:

-(void)defineQuad:(NSRect)r
{
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex2f(-1.0f, 1.0f);

glTexCoord2f(0.0f, r.size.height);
glVertex2f(-1.0f, -1.0f);

glTexCoord2f(r.size.width, r.size.height);
glVertex2f(1.0f, -1.0f);

glTexCoord2f(r.size.width, 0.0f);
glVertex2f(1.0f, 1.0f);

glEnd();
}

So, it seems like just defininig/drawing the rectangle is the culprit.

The drawRect routine looks like this (ugly, yes, cleanup later):

-(void)drawRect:(NSRect)rect
{
static int inited=NO;
static int first=YES;
NSRect r=[self frame];
[[self openGLContext] makeCurrentContext];
if (!inited) {
[self setupOpenGL];
inited=YES;
}
[self loadTextures:first];
first=NO;
[self defineQuad:r];
glFinish();
}

This is the texture setup (almost straight copy-paste from the example code, that's why it has the unecessary for-loop, and forced-true if-test):

- (void)loadTextures: (GLboolean)first
{
GLint i;
NSRect r=[self frame];
[[self openGLContext] makeCurrentContext];
[[self openGLContext] update];
if(YES)
{
for(i = 0; i < 1; i++)
{
if(!first)
{
GLint dt = i+1;
glDeleteTextures(1, &dt);
}

glDisable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_RECTANGLE_EXT);
glEnable(GL_UNPACK_CLIENT_STORAGE_APPLE);
glEnable(GL_APPLE_texture_range);
glBindTexture(GL_TEXTURE_RECTANGLE_EXT, i+1);
glTexParameterf(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_PRIORITY, 1.0);
glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);
glTexParameteri(GL_APPLE_texture_range, GL_TEXTURE_STORAGE_HINT_APPLE, GL_STORAGE_SHARED_APPLE);
glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_RECTANGLE_EXT, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);

glTexImage2D(GL_TEXTURE_RECTANGLE_EXT, 0, GL_RGBA, (int)r.size.width,(int)r.size.height,
0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, (void*)lastBitsIndex);
}
}

}

I added the code that sets up the GL_APPLE_texture_range extension, behavior was the same with or without. The bitmap has 32 bits per pixel, the width is 1284. I've also checked/forced the alignment of the pointer, it makes no difference. So, what am I doing wrong?

Thanks for any pointers,

Marcel

--
Marcel Weiher Metaobject Software Technologies
email@hidden www.metaobject.com
Metaprogramming for the Graphic Arts. HOM, IDEAs, MetaAd etc.
_______________________________________________
mac-opengl mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/mac-opengl
Do not post admin requests to the list. They will be ignored.


--
Geoff Stahl
OpenGL Engineer
Apple
_______________________________________________
mac-opengl mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/mac-opengl
Do not post admin requests to the list. They will be ignored.

References: 
 >Drawing image via OpenGL textures: no speedup? (From: Marcel Weiher <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.