maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   Xlib+OpenGLES performace (https://talk.maemo.org/showthread.php?t=37356)

exoticorn 2009-12-15 22:21

Xlib+OpenGLES performace
 
Hi.

I have played around with getting a simple GLES app running on my N900 last weekend through the combination of Xlib and EGL, and I got it running ok, although only using an ugly hack.

The thing is, if I simply render as fast as I can, I am rendering about 30 frames per second, of which only 10 or so actually end up being displayed. My assumption is that the window manager simply doesn't get enough time on the GPU to display all my rendered frames.
I was able to improve this situation by putting a usleep() into my mainloop, but that is hardly a satisfying solution.

Does anyone have any pointers on how to wait for the window manager to catch up more cleanly? (I had some hope for eglWaitNative(), but it didn't seem to help when I tried it.)

(For those interested, the source can be found at http://exoticorn.de/simplegl.tgz)

Another question comes up when comparing the output of 'top' when running my test app to the output when running bounce: While my app is running, I get about 10% CPU usage from Xorg and 4% from hildon-desktop (even in fullscreen mode), while bounce is running, I only see about 4% Xorg and no hildon-desktop at all.
Could this mean that bounce is somehow bypassing the window manager (at least in fullscreen mode) and rendering to the screen directly? Any chance of getting some information on how to do this myself?

As soon as I can get the basics figured out, I would like to port my game 'spidr' (http://pouet.net/prod.php?which=53019) to the N900.

Cheers,
Dennis

hhedberg 2009-12-16 10:46

Re: Xlib+OpenGLES performace
 
Quote:

Originally Posted by exoticorn (Post 429657)

Another question comes up when comparing the output of 'top' when running my test app to the output when running bounce: While my app is running, I get about 10% CPU usage from Xorg and 4% from hildon-desktop (even in fullscreen mode), while bounce is running, I only see about 4% Xorg and no hildon-desktop at all.
Could this mean that bounce is somehow bypassing the window manager (at least in fullscreen mode) and rendering to the screen directly? Any chance of getting some information on how to do this myself?

Most probably. See this post in Maemo Developers mailing list:

http://lists.maemo.org/pipermail/mae...ch/018645.html

Unfortunately I have not seen any public information about the issue, but I would look at the XAtoms of the Bounce's game window.

kwotski 2009-12-16 11:07

Re: Xlib+OpenGLES performace
 
Hi, I don't know too much about this! :D But after a quick look at the code, just wondering why you're calling XGetWindowAttributes() inside your render function? I'd have assumed it's better to do this in setup or when you get some notification event? (Asking as much for my benefit as for yours ;) )

exoticorn 2009-12-16 11:32

Re: Xlib+OpenGLES performace
 
@hhedberg:

Thanks, I will look into that as soon as I get a chance. If I find something that works along those lines, it might make the first question obsolete, although I'd still like to find an answer for that for when I'm not running fullscreen.

@kwotski:

You are right, in a real application you would probably just read out the window size when you get a resize event, but I consider this test app as just a hacky playground to learn about Xlib and EGL, both of which I haven't used before.

kwotski 2009-12-16 11:53

Re: Xlib+OpenGLES performace
 
exoticorn: Right, but have you tried doing this once in main() instead, and the glViewport(), etc., to see if this is the source of your performance hit?

(or if you want to stay hacky ;) just leave them where they are, but put them in something like: )
Code:

static int donesetup=0;

if(!donesetup) {

        XGetWindowAttributes(dpy, win, &gwa);
        glViewport(0, 0, gwa.width, gwa.height);
        glClearColor(0, 1, 0, 1);
        glClear(GL_COLOR_BUFFER_BIT);
        donesetup = 1;
}


exoticorn 2009-12-16 12:21

Re: Xlib+OpenGLES performace
 
@kwotski:

No, I haven't tried it, but will do that at the next opportunity. I doubt that this is the cause of the problem, though, as my problem is not CPU related (my app uses about 1.5% CPU time) and in fact the problem is that I am rendering too fast and not too slowly.

Btw: While mose GL tutorials tell you to call glViewport in the resize event handler, you can be pretty sure (as long as the GL(ES) implementation isn't completely broken) that a glViewport call per frame isn't the cause for any performance issues. In fact, there are very valid reasons to call glViewport multiple times per frame - think of split screen games or rendering to textures.

kwotski 2009-12-16 12:33

Re: Xlib+OpenGLES performace
 
See, I learned something ;)

javispedro 2009-12-16 12:51

Re: Xlib+OpenGLES performace
 
Quote:

Originally Posted by exoticorn (Post 429657)
Could this mean that bounce is somehow bypassing the window manager (at least in fullscreen mode) and rendering to the screen directly? Any chance of getting some information on how to do this myself?

Either wait for next firmware release or see this post.

javispedro 2009-12-16 13:08

Re: Xlib+OpenGLES performace
 
Quote:

Originally Posted by exoticorn (Post 430317)
Btw: While mose GL tutorials tell you to call glViewport in the resize event handler, you can be pretty sure (as long as the GL(ES) implementation isn't completely broken) that a glViewport call per frame isn't the cause for any performance issues. In fact, there are very valid reasons to call glViewport multiple times per frame - think of split screen games or rendering to textures.

The Xlib call, on the other side, is a roundtrip to the X server. Removing it (along with all the another unneeded "finish" calls) wins a few fps.

With that and the above I get around 43fps.

exoticorn 2009-12-16 13:45

Re: Xlib+OpenGLES performace
 
@javispedro: Aha! That looks just like what I was hoping for, thanks!

And you are right about the roundtrip time, of course - I didn't give much thought to that as I felt I had some bigger problem to solve first.

Miika 2009-12-16 17:13

Re: Xlib+OpenGLES performace
 
Yes, in Bounce we use _HILDON_NON_COMPOSITED_WINDOW. This should bring clear&swap performance up to at least 80 fps.

There is no need to resort to any trickery like sleeping or flushing to gain performance, they will only make things slower. The fewer you bother EGL/GLES the better.

Notice also that the rendering is asynchronous if you don't do anything that forces synchronization. This means that the application doesn't have to wait rendering to complete before starting the next one which allows CPU and GPU to work concurrently.

exoticorn 2009-12-16 22:52

Re: Xlib+OpenGLES performace
 
Thanks, Miika, it's good to hear that _HILDON_NON_COMPOSITED_WINDOW is all you need and that no further black magic is required.

I have now tried it and I'm very happy with the results, so all is now set for some game programming over the Xmas holiday.

Mr_Smiley 2009-12-20 02:33

Re: Xlib+OpenGLES performace
 
Hello,

Would you be able to post the new source code for your simple example? I've tried modifying your simplegl code with _HILDON_NON_COMPOSITED_WINDOW and I'm getting about 30 FPS. Shouldn't it be faster?

Thanks!

Mara 2009-12-20 02:57

Re: Xlib+OpenGLES performace
 
So my first on hand experience and gut feeling was correct whats' going on....

http://talk.maemo.org/showpost.php?p...&postcount=412

:D

Master of Gizmo 2009-12-20 16:00

Re: Xlib+OpenGLES performace
 
Quote:

Originally Posted by Mr_Smiley (Post 434995)
Hello,

Would you be able to post the new source code for your simple example? I've tried modifying your simplegl code with _HILDON_NON_COMPOSITED_WINDOW and I'm getting about 30 FPS. Shouldn't it be faster?

Thanks!

Agreed! We really should create a simple gles demo that's a) as fast as possible and b) as simple as possible. This might then become the starting point for real apps.

And please put this into extras-devel so people easily find it, can easily test it and most important are only one tiny "apt-get source" step away from the complete source code and all dependencies they need to compile it themselves.

exoticorn 2009-12-21 15:28

Re: Xlib+OpenGLES performace
 
Quote:

Originally Posted by Mr_Smiley (Post 434995)
Hello,

Would you be able to post the new source code for your simple example? I've tried modifying your simplegl code with _HILDON_NON_COMPOSITED_WINDOW and I'm getting about 30 FPS. Shouldn't it be faster?

Thanks!

You can find the updated code at http://exoticorn.de/simpleglv2.tgz. With this, I get about 42fps. (The framerate is very dependent on the size of the triangle on the screen, as the pixel shader with its sinus is killing the fillrate.)
Looking at the version of my code you posted at http://wiki.maemo.org/SimpleGL_Example, I see that you still have the 'usleep(1000*30)' in there, which I guess is the cause for your 30 fps. You also set _NET_WM_STATE_FULLSCREEN twice.

Good luck with your game.

Mr_Smiley 2009-12-21 23:44

Re: Xlib+OpenGLES performace
 
Quote:

Originally Posted by exoticorn (Post 436473)
I see that you still have the 'usleep(1000*30)' in there, which I guess is the cause for your 30 fps. You also set _NET_WM_STATE_FULLSCREEN twice.

Good luck with your game.

I totally missed that, thanks! I have added a link to the code on the wiki page (http://wiki.maemo.org/OpenGL_ES_Libraries). Hope this is OK.

Cheers.

endboss 2010-02-16 15:53

Re: Xlib+OpenGLES performace
 
Hi,

I'm currently learning openGL ES 2.0. I was studying that nice example. Thnks for that.

I was reorganizing and commenting it a bit in order to be more understandable. I would like to replace the wiki-example with my version, which you can find here:
http://www.agnld.uni-potsdam.de/~ber...gl-example.cpp

Is that ok?

Mr_Smiley 2010-02-17 05:24

Re: Xlib+OpenGLES performace
 
Quote:

Originally Posted by endboss (Post 529794)
Hi,

I'm currently learning openGL ES 2.0. I was studying that nice example. Thnks for that.

I was reorganizing and commenting it a bit in order to be more understandable. I would like to replace the wiki-example with my version, which you can find here:
http://www.agnld.uni-potsdam.de/~ber...gl-example.cpp

Is that ok?

That's fine with me. Good work commenting it :)

endboss 2010-02-17 12:08

Re: Xlib+OpenGLES performace
 
Ok, I updated the example program and added a screen shot.
I commented the code, cleaned it up (removing useless includes...) and corrected some small mistakes. I also changed a bit what it's doing, to be a little bit more attractive (watch the screen shot).

javispedro 2010-02-17 17:40

Re: Xlib+OpenGLES performace
 
BTW, you no longer need the HILDON_NON_COMPOSITED stuff.

misiak 2010-02-19 02:18

Re: Xlib+OpenGLES performace
 
I managed to get keyboard working in your example :)

you need to change:

Code:

\\swa.event_mask  =  ExposureMask | PointerMotionMask;
swa.event_mask  =  ExposureMask | PointerMotionMask | KeyPressMask | ButtonPressMask | ButtonReleaseMask;

and

Code:

while (!quit) {
XSetInputFocus( x_display, root, RevertToParent, CurrentTime);
XSetInputFocus( x_display, win, RevertToParent, CurrentTime);
XFlush( x_display );
while(XPending( x_display )) { ...

And then the main loop with xev.type will be able to handle: MotionNotify, ButtonPress, ButtonRelease and KeyPress events :)

note: you may need to add
Code:

#include <X11/Xutil.h>
after line with X11/Xlib.h , but I'm not sure, my code is a little bit longer at the moment... Can I change this in your code at wiki? do you agree? : ) I've spent 3 days on this silly little problem, but finally solved it, with help of this page (and other pages it links to, and so on) : http://talk.maemo.org/showthread.php?t=36952

It seems you need to setup this ButtonPressMask and manualy call XSetInputFocus to get keyboard running in X app... I will post in near future very simple code with implemented handling of keyboard, mouse (touchscreen), accelerometer and opengles 2.0, as I'm still working on it :) it's also very modular, splitted into files like "accelerometer.h", "glinit.h", "glrender.h", etc. ; ) Hope this helps many developers to start developing :D ( because this whole setup is the hardest part I think... )

endboss 2010-02-19 10:55

Re: Xlib+OpenGLES performace
 
Quote:

Originally Posted by misiak (Post 535779)
I managed to get keyboard working in your example :)

you need to change:

Code:

\\swa.event_mask  =  ExposureMask | PointerMotionMask;
swa.event_mask  =  ExposureMask | PointerMotionMask | KeyPressMask | ButtonPressMask | ButtonReleaseMask;

and

Code:

while (!quit) {
XSetInputFocus( x_display, root, RevertToParent, CurrentTime);
XSetInputFocus( x_display, win, RevertToParent, CurrentTime);
XFlush( x_display );
while(XPending( x_display )) { ...

And then the main loop with xev.type will be able to handle: MotionNotify, ButtonPress, ButtonRelease and KeyPress events :)

note: you may need to add
Code:

#include <X11/Xutil.h>
after line with X11/Xlib.h , but I'm not sure, my code is a little bit longer at the moment... Can I change this in your code at wiki? do you agree? : ) I've spent 3 days on this silly little problem, but finally solved it, with help of this page (and other pages it links to, and so on) : http://talk.maemo.org/showthread.php?t=36952

It seems you need to setup this ButtonPressMask and manualy call XSetInputFocus to get keyboard running in X app... I will post in near future very simple code with implemented handling of keyboard, mouse (touchscreen), accelerometer and opengles 2.0, as I'm still working on it :) it's also very modular, splitted into files like "accelerometer.h", "glinit.h", "glrender.h", etc. ; ) Hope this helps many developers to start developing :D ( because this whole setup is the hardest part I think... )

Thank you for your work. Of course one needs to activate the KeyPressEvent to get key presses delivered.
I edited the example already. I tested this on my phone and it works as desired.

javispedro 2010-02-19 14:49

Re: Xlib+OpenGLES performace
 
Quote:

Originally Posted by misiak (Post 535779)
Code:

while (!quit) {
XSetInputFocus( x_display, root, RevertToParent, CurrentTime);
XSetInputFocus( x_display, win, RevertToParent, CurrentTime);
XFlush( x_display );
while(XPending( x_display )) { ...



Argh, you don't need the above. Please set the proper WM_HINTS (the input hint at least), read http://tronche.com/gui/x/xlib/ICC/cl.../wm-hints.html

javispedro 2010-03-05 01:30

Re: Xlib+OpenGLES performace
 
I've rewritten Exoticorn's sample to make it use my "new" library (which I call SDL_gles) that allows you to easily use OpenGL|ES (either 1.1 or 2.0) within your SDL applications.

Check it out here: http://git.maemo.org/git/sdlhildon/?...egl.cc;hb=HEAD .

The entire initialization code gets reduced to
Code:

SDL_Init(SDL_INIT_VIDEO);
SDL_GLES_Init(SDL_GLES_VERSION_2_0);
screen = SDL_SetVideoMode(0, 0, 16, SDL_SWSURFACE | SDL_FULLSCREEN);
SDL_WM_SetCaption("SimpleGL", "SimpleGL");
SDL_ShowCursor(SDL_DISABLE);
context = SDL_GLES_CreateContext();
SDL_GLES_MakeCurrent(context);

(start of OpenGL|ES code)
glClearColor(0.08, 0.06, 0.07, 1.0);        // background color

GLuint vertexShader = load_shader(vertex_src, GL_VERTEX_SHADER);        // load vertex shader
...

and that is already doing more stuff than the previous Xlib "example", since it's hiding the mouse pointer, calculating the screen size (screen->w, screen->h), setting all the appropriate atoms and WmHints, etc. And you don't have to write a single Xlib call (not even a single EGL call if the application is simple enough).

As you can guess, the event handling code is also very much simplified (getting keyboard input, mouse events, is as easy as with any SDL app).

The library is already available on extras-devel (package name is "libsdl-gles1.2-dev", garage project is "sdlhildon"). For now, best documentation is the header itself on SDL_gles.h, but I plan to put some simpler examples later (or see the tests directory in git)

Master of Gizmo 2010-03-15 10:38

Re: Xlib+OpenGLES performace
 
Quote:

Originally Posted by javispedro (Post 556269)
The library is already available on extras-devel (package name is "libsdl-gles1.2-dev", garage project is "sdlhildon"). For now, best documentation is

Hmm, seems to want to be allowed to exclusively create /opt. Unfortunately espeak does the same:

Code:

Unpacking libsdl-gles1.2-1 (from .../libsdl-gles1.2-1_1.0.0_armel.deb) ...
dpkg: error processing /var/cache/apt/archives/libsdl-gles1.2-1_1.0.0_armel.deb (--unpack):
 trying to overwrite `/opt', which is also in package espeak-data
Selecting previously deselected package libsdl-gles1.2-dev.


javispedro 2010-03-20 00:19

Re: Xlib+OpenGLES performace
 
Quote:

Originally Posted by Master of Gizmo (Post 567583)
Hmm, seems to want to be allowed to exclusively create /opt. Unfortunately espeak does the same:

I am sorry, but I've not managed to reproduce this even though I've tried quite a few times...

Code:

Nokia-N900-02-8:~# dpkg -l espeak-data libsdl-gles1.2-1
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Cfg-files/Unpacked/Failed-cfg/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad)
||/ Name          Version        Description
+++-==============-==============-============================================
ii  espeak-data    1.43.03        eSpeak speech data files
ii  libsdl-gles1.2 1.0.0          OpenGL|ES library for Simple DirectMedia Lay

Can you give me a hint over how to reproduce it? As of now, I don't even know what could cause that, since I'm using the autobuilder optifier.

If this is scratchbox you're talking about, I think there was a FAQ item about something like that but iirc was fixed in recent PR1.1 onwards rootstraps.

JanJordan 2010-04-22 11:56

Re: Xlib+OpenGLES performace
 
small remark regarding that example as shown on http://wiki.maemo.org/SimpleGL_example:

It uses GL_TRIANGLE_STRIP to draw a quad, but since 5 vertices are given, it actually draws 3 triangles. For triangle srtip, only 4 are needed, but you need to reorder the vertices. Or you just remove the last vertices and draw a GL_TRIANGLE_FAN

Stumbled across this while porting the example to Python using ctypes,
http://orgetik.de/wp/wordpress/?p=131
if anyone is interested.


All times are GMT. The time now is 21:35.

vBulletin® Version 3.8.8