Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (603)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  RGB vs RGBA texture upload  (Read 2664 times)
0 Members and 1 Guest are viewing this topic.
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 846
Projects: 4
Exp: 16 years


Hand over your head.


« Posted 2005-05-13 07:45:24 »

I recently benchmarked texture uploading-speed of OpenGL.

Ofcourse I didn't mipmap, as that's done on the cpu.

For a 1024x1024 texture:
as LUMI: 3.4ms
as RGB: 220.8ms Shocked
as RGBA: 12.2ms
as DXT3: 5.6ms
as DXT5: 6.3ms
Uploading as: GL_UNSIGNED_BYTE

I can understand that uploading RGB could be somewhat slower, because the gpu might have to do some conversions, but ~20x slower... doesn't seem to make much sense.

Update:
Benchmark is just sending an 'empty' direct ByteBuffer of the appropriate length to the gpu.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
Offline cfmdobbie

Senior Devvie


Medals: 1


Who, me?


« Reply #1 - Posted 2005-05-13 10:58:06 »

Over how many runs are these results averaged?  Was there much variance in the runs, or were all results for a particular test pretty much the same?

Hellomynameis Charlie Dobbie.
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 846
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #2 - Posted 2005-05-16 09:23:51 »

16 runs, same performance per run

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline cfmdobbie

Senior Devvie


Medals: 1


Who, me?


« Reply #3 - Posted 2005-05-16 11:06:21 »

How interesting!  Could you post your benchmark code so we can try it on a variety of hardware, please?

Hellomynameis Charlie Dobbie.
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 846
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #4 - Posted 2005-05-16 16:24:54 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
import java.nio.IntBuffer;
import java.nio.ByteBuffer;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.PixelFormat;

public class TextureUploadBenchmark
{
   public static void main(String[] args) throws Exception
   {
      Display.setTitle("Texture Upload Benchmark");
      Display.setFullscreen(false);

      Display.create();

      GL11.glClearColor(0, 0, 1, 1);
      GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);

      Display.update();

      GL11.glEnable(GL11.GL_TEXTURE_2D);

      int dim = 1024;
      int count = 16;

      System.out.println("Texture-Upload Benchmark");
      System.out.println();
      System.out.println("   Texture dimension: " + dim);
      System.out.println("   Number of textures per run: " + count);
      System.out.println();
      System.out.println("   Results:");
      System.out.println("    - LUMI: " + benchmarkUpload(dim, GL11.GL_LUMINANCE, count) + "ms / texture");
      System.out.println("    - RGB:  " + benchmarkUpload(dim, GL11.GL_RGB, count) + "ms / texture");
      System.out.println("    - RGBA: " + benchmarkUpload(dim, GL11.GL_RGBA, count) + "ms / texture");
      System.out.println();
      System.out.println("Done.");

      Display.destroy();
   }



   private static final float benchmarkUpload(int dim, int format, int count)
   {
      int bytesPerPixel = -1;

      switch (format)
      {
         case GL11.GL_LUMINANCE:
            bytesPerPixel = 1;
            break;
         case GL11.GL_RGB:
            bytesPerPixel = 3;
            break;
         case GL11.GL_RGBA:
            bytesPerPixel = 4;
            break;
      }

      ByteBuffer buf = BufferUtils.createByteBuffer(dim * dim * bytesPerPixel);
      IntBuffer idBuf = BufferUtils.createIntBuffer(count);
      GL11.glGenTextures(idBuf);

      long t0 = System.currentTimeMillis();
      for (int i = 0; i < count; i++)
      {
         GL11.glBindTexture(GL11.GL_TEXTURE_2D, idBuf.get(i));

         GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, format, dim, dim, 0, format, GL11.GL_UNSIGNED_BYTE, buf);
         GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
         GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
         GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
         GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
      }
      long t1 = System.currentTimeMillis();

      GL11.glDeleteTextures(idBuf);

      float took = (t1 - t0) / (float) count;

      // format to 1 decimal
      return ((int) (took * 10)) / 10.0F;
   }
}


Output for:
ATi Radeon 9700 PRO

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
Texture-Upload Benchmark

   Texture dimension: 1024
   Number of textures per run: 16

   Results:
    - LUMI: 3.8ms / texture
    - RGB:  229.5ms / texture
    - RGBA: 15.6ms / texture

Done.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
Offline Matzon

JGO Knight


Medals: 19
Projects: 1


I'm gonna wring your pants!


« Reply #5 - Posted 2005-05-16 16:35:55 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
   Texture dimension: 1024
   Number of textures per run: 16

   Results:
    - LUMI: 4.8ms / texture
    - RGB:  17.5ms / texture
    - RGBA: 17.5ms / texture

Done.
GeForce 6600GT

Offline Spasi
« Reply #6 - Posted 2005-05-16 17:27:15 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
   Texture dimension: 1024
   Number of textures per run: 16

   Results:
    - LUMI: 4.9ms / texture
    - RGB:  15.6ms / texture
    - RGBA: 17.5ms / texture

Done.

-----------------------

   Texture dimension: 2048
   Number of textures per run: 16

   Results:
    - LUMI: 17.5ms / texture
    - RGB:  46.8ms / texture
    - RGBA: 77.1ms / texture

Done.


GeFX 5900, Forceware 76.91
Offline Riven
« League of Dukes »

« JGO Overlord »


Medals: 846
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #7 - Posted 2005-05-16 18:02:51 »

Thanks.

Anyone with ATi card please?

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social
8: Undefined index: online
File: /home/jgo/public_html/Themes/default/Display.template.php (main sub template - eval?)
Line: 161