From 613e33ee8ffc1f2b9c5db1e1b5bb5253a159ed6d Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 4 Nov 2013 15:07:14 +0100 Subject: Bug 888 - Validate CPU Runtime Performance: X11GLXGraphicsConfiguration.GLXFBConfig2GLCapabilities(..) X11GLXGraphicsConfiguration.GLXFBConfig2GLCapabilities(..) ran over all FB configs and for each it grabbed native config values separately. Fetching them in bulk mode saves around 7% of this function's cost. Also reuse XRenderPictFormat instance for 'XRenderDirectFormat XRenderFindVisualFormat(..)' call, saving a few NIO creation cycles w/ StructAccessor. Biggest savior is X11GLXGraphicsConfigurationFactory.chooseGraphicsConfigurationFBConfig()'s fast path w/o chooser and usable 1st FBConfig. Here we only issue 'GLXFBConfig2GLCapabilities(..)' on the first valid entry. Test w/ 50 X11GLXGraphicsConfigurationFactory.chooseGraphicsConfigurationFBConfig() invocations: - pre change: 1.708 ms - post change: 650 ms Time is no spent almost solely on native glXChooseFBConfig (546ms). --- make/config/jogl/glx-CustomCCode.c | 25 ++++++++++++++++++++++++ make/config/jogl/glx-CustomJavaCode.java | 22 +++++++++++++++++++++ make/config/nativewindow/x11-CustomJavaCode.java | 15 ++++++++++++++ 3 files changed, 62 insertions(+) (limited to 'make') diff --git a/make/config/jogl/glx-CustomCCode.c b/make/config/jogl/glx-CustomCCode.c index 71dc68b08..5c73dfea6 100644 --- a/make/config/jogl/glx-CustomCCode.c +++ b/make/config/jogl/glx-CustomCCode.c @@ -59,6 +59,31 @@ static void _initClazzAccess(JNIEnv *env) { } } +/* Java->C glue code: + * Java package: jogamp.opengl.x11.glx.GLX + * Java method: int glXGetFBConfigAttributes(long dpy, long config, IntBuffer attributes, IntBuffer values) + */ +JNIEXPORT jint JNICALL +Java_jogamp_opengl_x11_glx_GLX_dispatch_1glXGetFBConfigAttributes(JNIEnv *env, jclass _unused, jlong dpy, jlong config, jint attributeCount, jobject attributes, jint attributes_byte_offset, jobject values, jint values_byte_offset, jlong procAddress) { + typedef int (APIENTRY*_local_PFNGLXGETFBCONFIGATTRIBPROC)(Display * dpy, GLXFBConfig config, int attribute, int * value); + _local_PFNGLXGETFBCONFIGATTRIBPROC ptr_glXGetFBConfigAttrib = (_local_PFNGLXGETFBCONFIGATTRIBPROC) (intptr_t) procAddress; + assert(ptr_glXGetFBConfigAttrib != NULL); + + int err = 0; + if ( attributeCount > 0 && NULL != attributes ) { + int i; + int * attributes_ptr = (int *) (((char*) (*env)->GetDirectBufferAddress(env, attributes)) + attributes_byte_offset); + int * values_ptr = (int *) (((char*) (*env)->GetDirectBufferAddress(env, values)) + values_byte_offset); + for(i=0; 0 == err && iC glue code: * Java package: jogamp.opengl.x11.glx.GLX * Java method: XVisualInfo glXGetVisualFromFBConfig(long dpy, long config) diff --git a/make/config/jogl/glx-CustomJavaCode.java b/make/config/jogl/glx-CustomJavaCode.java index f3e743930..4cce05dda 100644 --- a/make/config/jogl/glx-CustomJavaCode.java +++ b/make/config/jogl/glx-CustomJavaCode.java @@ -1,4 +1,26 @@ + /** + * Returns the GLX error value, i.e. 0 for no error. In case of an error values.get(values.getPosition()) contains the attributes index causing the error. + *

+ * Entry point to C language function: int glXGetFBConfigAttrib(Display * dpy, GLXFBConfig config, int attribute, int * value);
Part of GLX_VERSION_1_3 + *

+ */ + public static int glXGetFBConfigAttributes(long dpy, long config, IntBuffer attributes, IntBuffer values) { + if( attributes == null || values == null ) { + throw new RuntimeException("arrays buffers are null"); + } + if( !Buffers.isDirect(attributes) || !Buffers.isDirect(values) ) { + throw new RuntimeException("arrays buffers are not direct"); + } + if( attributes.remaining() > values.remaining() ) { + throw new RuntimeException("not enough values "+values+" for attributes "+attributes); + } + final long __addr = glxProcAddressTable._addressof_glXGetFBConfigAttrib; + return dispatch_glXGetFBConfigAttributes(dpy, config, attributes.remaining(), attributes, Buffers.getDirectBufferByteOffset(attributes), + values, Buffers.getDirectBufferByteOffset(values), __addr); + } + private static native int dispatch_glXGetFBConfigAttributes(long dpy, long config, int attributeCount, Object attributes, int attributes_byte_offset, Object values, int valuesOffset, long procAddr); + /** Interface to C language function:
- Alias for:
XVisualInfo * glXGetVisualFromFBConfigSGIX, glXGetVisualFromFBConfig(Display * dpy, GLXFBConfig config); */ public static XVisualInfo glXGetVisualFromFBConfig(long dpy, long config) { diff --git a/make/config/nativewindow/x11-CustomJavaCode.java b/make/config/nativewindow/x11-CustomJavaCode.java index 4240c5e2f..d1e011184 100644 --- a/make/config/nativewindow/x11-CustomJavaCode.java +++ b/make/config/nativewindow/x11-CustomJavaCode.java @@ -1,4 +1,19 @@ + /** Interface to C language function:
XRenderPictFormat * XRenderFindVisualFormat(Display * dpy, const Visual * visual); */ + public static boolean XRenderFindVisualFormat(long dpy, long visual, XRenderPictFormat dest) { + if( dest == null ) { + throw new RuntimeException("dest is null"); + } + final ByteBuffer destBuffer = dest.getBuffer(); + if( !Buffers.isDirect(destBuffer) ) { + throw new RuntimeException("dest buffer is not direct"); + } + return XRenderFindVisualFormat1(dpy, visual, destBuffer); + } + /** Entry point to C language function: XVisualInfo * XGetVisualInfo(Display * , long, XVisualInfo * , int * ); */ + private static native boolean XRenderFindVisualFormat1(long dpy, long visual, ByteBuffer xRenderPictFormat); + + /** Interface to C language function:
XVisualInfo * XGetVisualInfo(Display * , long, XVisualInfo * , int * ); */ public static XVisualInfo[] XGetVisualInfo(long arg0, long arg1, XVisualInfo arg2, int[] arg3, int arg3_offset) { -- cgit v1.2.3