From 0b657e84188652ea4e400861f778bdebcd35d6b3 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 21 Aug 2008 17:40:54 +0000 Subject: ES2 performance test: 1st draft git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/../svn-server-sync/jogl-demos/branches/JOGL_2_SANDBOX@277 3298f667-5e0e-4b4a-8ed4-a3559d26a5f4 --- make/build.xml | 2 +- src/demos/es1/cube/Cube.java | 36 ++-- src/demos/es1/cube/CubeImmModeSink.java | 7 +- src/demos/es1/cubefbo/Main.java | 2 +- src/demos/es2/RedSquare.java | 11 +- src/demos/es2/perftst/PerfModule.java | 94 ++++++++++ src/demos/es2/perftst/PerfUniLoad.java | 180 +++++++++++++++++++ src/demos/es2/perftst/PerfVBOLoad.java | 190 +++++++++++++++++++++ src/demos/es2/perftst/Perftst.java | 171 +++++++++++++++++++ src/demos/es2/perftst/shader/bin/nvidia/fcolor.bfp | Bin 0 -> 524 bytes .../es2/perftst/shader/bin/nvidia/uni-vert-col.bvp | Bin 0 -> 8148 bytes .../es2/perftst/shader/bin/nvidia/vbo-vert-col.bvp | Bin 0 -> 864 bytes src/demos/es2/perftst/shader/fcolor.fp | 16 ++ .../perftst/shader/scripts/nvidia-apx/glslc-ff.bat | 9 + src/demos/es2/perftst/shader/uni-vert-col.vp | 57 +++++++ src/demos/es2/perftst/shader/vbo-vert-col.vp | 19 +++ wince/perftst-uni-args.txt | 2 + wince/perftst-uni.lnk | 1 + wince/perftst-vbo-args.txt | 2 + wince/perftst-vbo.lnk | 1 + wince/redsquare-es2-args.txt | 2 +- 21 files changed, 777 insertions(+), 25 deletions(-) create mode 100644 src/demos/es2/perftst/PerfModule.java create mode 100755 src/demos/es2/perftst/PerfUniLoad.java create mode 100755 src/demos/es2/perftst/PerfVBOLoad.java create mode 100755 src/demos/es2/perftst/Perftst.java create mode 100755 src/demos/es2/perftst/shader/bin/nvidia/fcolor.bfp create mode 100755 src/demos/es2/perftst/shader/bin/nvidia/uni-vert-col.bvp create mode 100755 src/demos/es2/perftst/shader/bin/nvidia/vbo-vert-col.bvp create mode 100644 src/demos/es2/perftst/shader/fcolor.fp create mode 100755 src/demos/es2/perftst/shader/scripts/nvidia-apx/glslc-ff.bat create mode 100644 src/demos/es2/perftst/shader/uni-vert-col.vp create mode 100644 src/demos/es2/perftst/shader/vbo-vert-col.vp create mode 100755 wince/perftst-uni-args.txt create mode 100755 wince/perftst-uni.lnk create mode 100755 wince/perftst-vbo-args.txt create mode 100755 wince/perftst-vbo.lnk diff --git a/make/build.xml b/make/build.xml index 588cd46..06ff814 100644 --- a/make/build.xml +++ b/make/build.xml @@ -211,7 +211,7 @@ + includes="demos/es2/shader/**, demos/es2/perftst/shader/**" /> diff --git a/src/demos/es1/cube/Cube.java b/src/demos/es1/cube/Cube.java index d46e87d..48e1b6b 100644 --- a/src/demos/es1/cube/Cube.java +++ b/src/demos/es1/cube/Cube.java @@ -77,6 +77,9 @@ public class Cube implements GLEventListener { gl.getGLES2().enableFixedFunctionEmulationMode(GLES2.FIXED_EMULATION_VERTEXCOLORTEXTURE); System.err.println("Cubes Fixed emu: FIXED_EMULATION_VERTEXCOLORTEXTURE"); } + + gl.glGenBuffers(4, vboNames, 0); + if(!innerCube) { System.err.println("Entering initialization"); System.err.println("GL Profile: "+GLProfile.getProfile()); @@ -133,13 +136,32 @@ public class Cube implements GLEventListener { } gl.glEnableClientState(gl.GL_VERTEX_ARRAY); + gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vboNames[0]); + gl.glBufferData(GL.GL_ARRAY_BUFFER, cubeVertices.limit() * BufferUtil.SIZEOF_SHORT, cubeVertices, GL.GL_STATIC_DRAW); + gl.glVertexPointer(3, gl.GL_SHORT, 0, 0); + gl.glEnableClientState(gl.GL_NORMAL_ARRAY); + gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vboNames[1]); + gl.glBufferData(GL.GL_ARRAY_BUFFER, cubeNormals.limit() * BufferUtil.SIZEOF_BYTE, cubeNormals, GL.GL_STATIC_DRAW); + gl.glNormalPointer(gl.GL_BYTE, 0, 0); + gl.glEnableClientState(gl.GL_COLOR_ARRAY); + gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vboNames[2]); + gl.glBufferData(GL.GL_ARRAY_BUFFER, cubeColors.limit() * BufferUtil.SIZEOF_FLOAT, cubeColors, GL.GL_STATIC_DRAW); + gl.glColorPointer(4, gl.GL_FLOAT, 0, 0); + if (cubeTexCoords != null) { gl.glEnableClientState(gl.GL_TEXTURE_COORD_ARRAY); + gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vboNames[3]); + gl.glBufferData(GL.GL_ARRAY_BUFFER, cubeTexCoords.limit() * BufferUtil.SIZEOF_SHORT, cubeTexCoords, GL.GL_STATIC_DRAW); + gl.glTexCoordPointer(2, gl.GL_SHORT, 0, 0); + if(null!=glF) { + glF.glTexEnvi(glF.GL_TEXTURE_ENV, glF.GL_TEXTURE_ENV_MODE, glF.GL_INCR); + } } else { gl.glDisableClientState(gl.GL_TEXTURE_COORD_ARRAY); } + gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); if(null!=glF) { glF.glHint(glF.GL_PERSPECTIVE_CORRECTION_HINT, glF.GL_FASTEST); @@ -172,17 +194,6 @@ public class Cube implements GLEventListener { gl.glRotatef((float)(time * 29.77f), 1.0f, 2.0f, 0.0f); gl.glRotatef((float)(time * 22.311f), -0.1f, 0.0f, -5.0f); - gl.glVertexPointer(3, gl.GL_SHORT, 0, cubeVertices); - gl.glColorPointer(4, gl.GL_FLOAT, 0, cubeColors); - gl.glNormalPointer(gl.GL_BYTE, 0, cubeNormals); - if (cubeTexCoords != null) { - gl.glTexCoordPointer(2, gl.GL_SHORT, 0, cubeTexCoords); - if(null!=glF) { - glF.glTexEnvi(glF.GL_TEXTURE_ENV, glF.GL_TEXTURE_ENV_MODE, glF.GL_INCR); - } - } - - gl.glDrawElements(gl.GL_TRIANGLES, 6 * 6, gl.GL_UNSIGNED_BYTE, cubeIndices); // gl.glFinish(); // System.err.println(gl); @@ -199,6 +210,7 @@ public class Cube implements GLEventListener { static final float[] material_spec = { 1.0f, 1.0f, 1.0f, 0.f }; static final float[] zero_vec4 = { 0.0f, 0.0f, 0.0f, 0.f }; + int[] vboNames = new int[4]; boolean innerCube; boolean initialized = false; float time = 0.0f; @@ -311,7 +323,7 @@ public class Cube implements GLEventListener { window.setFullscreen(true); window.setVisible(true); - while (window.getDuration() < 20000) { + while (window.getDuration() < 31000) { window.display(); } diff --git a/src/demos/es1/cube/CubeImmModeSink.java b/src/demos/es1/cube/CubeImmModeSink.java index 219e5fd..c0ad4aa 100644 --- a/src/demos/es1/cube/CubeImmModeSink.java +++ b/src/demos/es1/cube/CubeImmModeSink.java @@ -43,6 +43,7 @@ public class CubeImmModeSink implements GLEventListener { this(false, false); } + private static boolean VBO_CACHE = true; ByteBuffer cubeIndices=null; ImmModeSink vboCubeF = null; @@ -78,7 +79,6 @@ public class CubeImmModeSink implements GLEventListener { if(null!=vboCubeF) { vboCubeF.draw(gl, cubeIndices, true); } - System.err.println("VBO Cube fin"); } private GLUquadric sphere=null; @@ -86,6 +86,7 @@ public class CubeImmModeSink implements GLEventListener { public void drawSphere(GL gl, float radius, int slices, int stacks) { if(sphere==null) { sphere = glu.gluNewQuadric(); + sphere.enableImmModeSink(true); sphere.setImmMode((VBO_CACHE)?false:true); } ImmModeSink vbo = vboSphere; @@ -105,12 +106,12 @@ public class CubeImmModeSink implements GLEventListener { } - private static boolean VBO_CACHE = true; private GLUquadric cylinder=null; private ImmModeSink vboCylinder=null; public void drawCylinder(GL gl, float radius, float halfHeight, int upAxis) { if(cylinder==null) { cylinder = glu.gluNewQuadric(); + cylinder.enableImmModeSink(true); cylinder.setImmMode((VBO_CACHE)?false:true); } @@ -409,7 +410,7 @@ public class CubeImmModeSink implements GLEventListener { long curTime; long startTime = System.currentTimeMillis(); - while (((curTime = System.currentTimeMillis()) - startTime) < 20000) { + while (((curTime = System.currentTimeMillis()) - startTime) < 31000) { window.display(); } diff --git a/src/demos/es1/cubefbo/Main.java b/src/demos/es1/cubefbo/Main.java index b23b221..cc43ebf 100755 --- a/src/demos/es1/cubefbo/Main.java +++ b/src/demos/es1/cubefbo/Main.java @@ -67,7 +67,7 @@ public class Main implements MouseListener { FBCubes cubes = new FBCubes(); window.addGLEventListener(cubes); - while ( !quit && window.getDuration() < 215000) { + while ( !quit && window.getDuration() < 31000) { window.display(); } diff --git a/src/demos/es2/RedSquare.java b/src/demos/es2/RedSquare.java index 089ebfe..ce1d0c2 100755 --- a/src/demos/es2/RedSquare.java +++ b/src/demos/es2/RedSquare.java @@ -138,7 +138,7 @@ public class RedSquare implements MouseListener, GLEventListener { throw new GLException("Error setting PMVMatrix in shader: "+st); } // Allocate vertex arrays - GLArrayDataClient vertices = GLArrayDataClient.createGLSL(-1, "mgl_Vertex", 3, gl.GL_FLOAT, false, 4); + GLArrayDataClient vertices = GLArrayDataClient.createGLSL("mgl_Vertex", 3, gl.GL_FLOAT, false, 4); { // Fill them up FloatBuffer verticeb = (FloatBuffer)vertices.getBuffer(); @@ -146,10 +146,10 @@ public class RedSquare implements MouseListener, GLEventListener { verticeb.put( 2); verticeb.put( 2); verticeb.put( 0); verticeb.put(-2); verticeb.put( -2); verticeb.put( 0); verticeb.put( 2); verticeb.put( -2); verticeb.put( 0); - verticeb.flip(); } + vertices.seal(gl, true); - GLArrayDataClient colors = GLArrayDataClient.createGLSL(-1, "mgl_Color", 4, gl.GL_FLOAT, false, 4); + GLArrayDataClient colors = GLArrayDataClient.createGLSL("mgl_Color", 4, gl.GL_FLOAT, false, 4); { // Fill them up FloatBuffer colorb = (FloatBuffer)colors.getBuffer(); @@ -157,12 +157,9 @@ public class RedSquare implements MouseListener, GLEventListener { colorb.put( 0); colorb.put( 0); colorb.put( 1); colorb.put( 1); colorb.put( 1); colorb.put( 0); colorb.put( 0); colorb.put( 1); colorb.put( 1); colorb.put( 0); colorb.put( 0); colorb.put( 1); - colorb.flip(); } + colors.seal(gl, true); - st.glVertexAttribPointer(gl, vertices); - st.glVertexAttribPointer(gl, colors); - // OpenGL Render Settings gl.glClearColor(0, 0, 0, 1); gl.glEnable(GL2ES2.GL_DEPTH_TEST); diff --git a/src/demos/es2/perftst/PerfModule.java b/src/demos/es2/perftst/PerfModule.java new file mode 100644 index 0000000..aaac612 --- /dev/null +++ b/src/demos/es2/perftst/PerfModule.java @@ -0,0 +1,94 @@ +package demos.es2.perftst; + +import java.nio.*; +import javax.media.opengl.*; +import javax.media.opengl.util.*; +import javax.media.opengl.glsl.*; + +public abstract class PerfModule { + + public abstract void initShaderState(GL2ES2 gl); + + public abstract void run(GLAutoDrawable drawable, int loops); + + ShaderState st = null; + + public void initShaderState(GL2ES2 gl, String vShaderName, String fShaderName) { + if(st!=null) return; + + long t0, t1; + + st = new ShaderState(); + + // Create & Compile the shader objects + ShaderCode vp = ShaderCode.create(gl, gl.GL_VERTEX_SHADER, 1, Perftst.class, + "shader", "shader/bin", vShaderName); + ShaderCode fp = ShaderCode.create(gl, gl.GL_FRAGMENT_SHADER, 1, Perftst.class, + "shader", "shader/bin", fShaderName); + + // Create & Link the shader program + ShaderProgram sp = new ShaderProgram(); + sp.add(vp); + sp.add(fp); + + t0 = System.currentTimeMillis(); + + if(!sp.link(gl, System.err)) { + throw new GLException("Couldn't link program: "+sp); + } + + t1 = System.currentTimeMillis(); + + long dt = t1-t0; + + System.out.println("shader creation: "+dt+" ms"); + + // Let's manage all our states using ShaderState. + st.attachShaderProgram(gl, sp); + + st.glUseProgram(gl, true); + } + + public static final void put(Buffer buffer, int type, float v) { + switch (type) { + case GL.GL_UNSIGNED_BYTE: + ((ByteBuffer)buffer).put((byte)(v*(float)0xFF)); + break; + case GL.GL_BYTE: + ((ByteBuffer)buffer).put((byte)(v*(float)0x7F)); + break; + case GL.GL_UNSIGNED_SHORT: + ((ShortBuffer)buffer).put((short)(v*(float)0xFFFF)); + break; + case GL.GL_SHORT: + ((ShortBuffer)buffer).put((short)(v*(float)0x7FFF)); + break; + case GL.GL_FLOAT: + ((FloatBuffer)buffer).put(v); + break; + case GL.GL_FIXED: + ((IntBuffer)buffer).put(FixedPoint.toFixed(v)); + break; + } + } + + public static final String getTypeName(int type) { + switch (type) { + case GL.GL_UNSIGNED_BYTE: + return "GL_UNSIGNED_BYTE"; + case GL.GL_BYTE: + return "GL_BYTE"; + case GL.GL_UNSIGNED_SHORT: + return "GL_UNSIGNED_SHORT"; + case GL.GL_SHORT: + return "GL_SHORT"; + case GL.GL_FLOAT: + return "GL_FLOAT"; + case GL.GL_FIXED: + return "GL_FIXED"; + } + return null; + } + +} + diff --git a/src/demos/es2/perftst/PerfUniLoad.java b/src/demos/es2/perftst/PerfUniLoad.java new file mode 100755 index 0000000..a85de7f --- /dev/null +++ b/src/demos/es2/perftst/PerfUniLoad.java @@ -0,0 +1,180 @@ +package demos.es2.perftst; + +import java.nio.*; +import javax.media.opengl.*; +import javax.media.opengl.util.*; +import javax.media.opengl.glsl.*; + +import com.sun.javafx.newt.*; + +public class PerfUniLoad extends PerfModule { + + GLUniformData[] dummyA, dummyB, dummyC; + final int dataType=GL.GL_FLOAT; + + public PerfUniLoad() { + } + + public void initShaderState(GL2ES2 gl) { + initShaderState(gl, "uni-vert-col", "fcolor"); + } + + protected void runOneSet(GLAutoDrawable drawable, int numObjs, int numArrayElem, int loops) { + GL2ES2 gl = drawable.getGL().getGL2ES2(); + + // + // Vertices Data setup + // + + if(numObjs>16) { + throw new GLException("numObjs must be within 0..16"); + } + + if(numArrayElem>16) { + throw new GLException("numArrayElem must be within 0..16"); + } + + st.glUseProgram(gl, true); + + GLArrayDataServer vertices = GLArrayDataServer.createGLSL("mgl_Vertex", 3, GL.GL_FLOAT, true, 4, GL.GL_STATIC_DRAW); + { + FloatBuffer vb = (FloatBuffer)vertices.getBuffer(); + vb.put(0f); vb.put(0f); vb.put(0f); + vb.put(1f); vb.put(0f); vb.put(0f); + vb.put(0f); vb.put(1f); vb.put(0f); + vb.put(1f); vb.put(1f); vb.put(0f); + } + vertices.seal(gl, true); + + GLArrayDataServer colors = GLArrayDataServer.createGLSL("mgl_Color", 4, GL.GL_FLOAT, true, 4, GL.GL_STATIC_DRAW); + { + FloatBuffer cb = (FloatBuffer)colors.getBuffer(); + cb.put(0f); cb.put(0f); cb.put(0f); cb.put(1f); + cb.put(1f); cb.put(0f); cb.put(0f); cb.put(1f); + cb.put(0f); cb.put(1f); cb.put(0f); cb.put(1f); + cb.put(0f); cb.put(0f); cb.put(1f); cb.put(1f); + } + colors.seal(gl, true); + + // + // Uniform Data setup + // + + GLUniformData[] dummyUni = new GLUniformData[numObjs]; + + float x=0f, y=0f, z=0f, w=0f; + + for(int i=0; i1f) { x=0f; y=0f; z+=0.01f; } + } + fb.flip(); + } + + // + // run loops + // + + long dtC, dt, dt2, dt3, dtF, dtS, dtT; + long tStart; + long[] tC = new long[loops]; + long[] t0 = new long[loops]; + long[][] t1 = new long[loops][numObjs]; + long[][] t2 = new long[loops][numObjs]; + long[] tF = new long[loops]; + long[] tS = new long[loops]; + + tStart = System.currentTimeMillis(); + + for(int i=0; i1f) { x=0f; y=0f; z+=0.01f; } + } + } + colors[i] = GLArrayDataServer.createGLSL("mgl_Color", 4, dataType, true, numVertices, GL.GL_STATIC_DRAW); + { + // Fill them up + Buffer colorb = colors[i].getBuffer(); + for(int j =0; j=0; i--) { + if(args[i].equals("-awt")) { + type |= USE_AWT; + } + if(args[i].equals("-test") && i+1