Jogl Gears - slow performance

I accidently stumpled upon the gears demo in jogl, and wondered why we hadn’t done one for LWJGL. Though very simple it is used as some sort of simple benchmark.

I added some FPS output to the original jogl gears demo.
I then took that code and changed the initialization to fit with LWJGL’s Display, did a search/replace for gl. to GL11. and changed some code to use FloatBuffers (we don’t support arrays).
Lastly I took the original gears and compiled with Visual Studio 2005.
This is the result:

[quote]native = ~4200 fps = 100%
lwjgl = ~3200 fps = 76%
jogl = ~ 900 fps = 21%
[/quote]
I was a bit surprised about the jogl performance (or lack thereof). I used the latest (1.1b05 - August 4) build.
I am running Windows XP SP2, Ati Radeon 9700.

I was expecting to find that the order of performance would be like above, but I was a bit shocked to find jogl that far behind - and I can only attribute it to somekind of bug in the jogl implementation I got…

Seems to be spending a lot of time making the context current - even though I am only using 1 thread??

[quote] Stub + native Method
51.8% 0 + 823 net.java.games.jogl.impl.windows.WGL.wglMakeCurrent
22.2% 0 + 353 net.java.games.jogl.impl.windows.WGL.SwapBuffers
4.8% 0 + 77 net.java.games.jogl.impl.windows.WindowsGLImpl.glCallList
3.1% 0 + 50 net.java.games.jogl.impl.JAWT_DrawingSurface.Lock0
1.8% 15 + 14 net.java.games.jogl.impl.JAWT.GetDrawingSurface0
1.1% 0 + 17 net.java.games.jogl.impl.JAWT_DrawingSurface.FreeDrawingSurfaceInfo0
[/quote]

-DATI_WORKAROUND=false

See if that gives the fps a boost. If not can you post your code so I can look at it.

it did boost it - by some 1-200 fps.

The code is exactly like in the jogl-demos distribtution. I only added the FPS code:
private long startTime = System.currentTimeMillis() + 5000;

if (startTime > System.currentTimeMillis()) {
fps++;
} else {
long timeUsed = 5000 + (startTime - System.currentTimeMillis());
startTime = System.currentTimeMillis() + 5000;
System.out.println(fps + " frames in " + (float) (timeUsed / 1000f) + " seconds = " + (fps / (timeUsed / 1000f)));
fps = 0;
}

Was the profile the same with -DATI_WORKAROUND=false? On my machine SwapBuffers is the highest and wglMakeCurrent is one of the lowest. wglMakeCurrent really should only be called a few times. I will try on my ATI powered laptop tonight.

the profile was with the -DATI_WORKAROUND=false - also, I am starting the whole thing from command line using java -cp -DATI_WORKAROUND=false demos.gears.Gears

One of the issues we have with the JOGL implementation is in the swapbuffers area. it seems that every frame it’s creating instances of FloatBuffer somewhere. I don’t know if it’s doing this to duplicate() the buffer so it can do it’s own things with them, or if something else is happening involving data copies. We haven’t looked into this other than what our profilers are telling us at a higher level. It’s not majorly important right now as we’re typlical transform or app limited in our code, so those sorts of inefficienices are not showing up as costing frame rates in real world applications.

Tha call to wglMakeCurrent on most Win32 drivers is very slow (mainly because the drivers are optimised for games that have but one context). It should rarely be called. Seeing as the context is hidden in JOGL/AWT it would be entirely reasonable to keep track of it internally and only call it as necessary? (eg. when rendering to more than one window)

Cas :slight_smile:

[quote]Tha call to wglMakeCurrent on most Win32 drivers is very slow (mainly because the drivers are optimised for games that have but one context).
[/quote]
You’re absolutely right - I’ve observed this odd behaviour in my tests too (using an ATI card).

OT: Btw, I’m about to award you with an extra nick name - “The Popup Miracle” - you can append it to your sig if you will :wink: … “Whenever there is discussion about the performance differences of LWJGL and JOGL, there is the Popup Miracle too…”

Matzon: That is odd. The profile is totally different on my ATI laptop than on my nvidia pc. I will run it through the debugger and see what the deal is. I assume it has to do with ATI_WORKAROUND.

Mithrandir: I don’t see anywhere in the loop where we are creating any FloatBuffer’s. It also doesn’t appear in any profiling I did last night. If you can find where it is coming from let me know.

I think I found the problem. I will send the fix off to Ken to see what he thinks. I went from 200fps to 1200fps.

Wanna hear funny thing?
Take one laptop with Radeon128 and 600Mhz Pentium Processor 256MbRam. Try Jogl with ATI and with GDI support.Guess what is going faster?:slight_smile:

Yes youre right! Jogl is truly decelerator of graphics under non Nvidia cards hahaha… how to solve this @#$@#$???

[quote]The Popup Miracle
[/quote]
It’s a conspiracy. Ask Matzon 8)

Cas :slight_smile:

This might be a little more complex than I initially thought. Fix will take a little more thought.

Where possible, JOGL does keep track of what context is current on a given thread and avoids makeCurrent/free calls. However, on ATI cards, the current driver bug workarounds in the JOGL source base cause the context to be made current only on the AWT thread, not the user’s animation thread. Because of this multiplexing on the AWT thread, the context handling optimizations don’t apply.

A few of us (myself and GKW, and separately some people inside Sun) are discussing the context handling, comparing it to Java3D’s context handling, and seeing how it might be restructured. There is a possibility that we may be able to enable the context handling optimizations on ATI cards. This would be even more likely if ATI’s drivers became more stable in multithreaded situations. It’s possible that their latest drivers are better in this area but I haven’t had time to test them.

ATI drivers stable!??! pffffft ;D

Na. Their OGL drivers are still horrible. Catalyst 4.8 broke fog again, after they fixed it in 4.7 grrrrr…

[quote]native = ~4200 fps = 100%
lwjgl = ~3200 fps = 76%
jogl = ~ 900 fps = 21%
[/quote]
When I run Jogl Gears.java on my older Nvidia card:

GL_VENDOR: NVIDIA Corporation
GL_RENDERER: GeForce2 GTS/AGP/SSE2
GL_VERSION: 1.5.1

I get jogl = 75 fps.

Slow is relative. :slight_smile:

Have you disabled vsync in your drivers settings? If not, it looks like you have a screen refresh rate of 75 Hz :slight_smile:

[quote]Have you disabled vsync in your drivers settings? If not, it looks like you have a screen refresh rate of 75 Hz :slight_smile:
[/quote]
Doh! It’s ~1480 fps with vsync disabled. Thanks!