Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

api_speed.c 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * (C) Copyright IBM Corporation 2002
  3. * All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * on the rights to use, copy, modify, merge, publish, distribute, sub
  9. * license, and/or sell copies of the Software, and to permit persons to whom
  10. * the Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice (including the next
  13. * paragraph) shall be included in all copies or substantial portions of the
  14. * Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  19. * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
  20. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  21. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  22. * USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. */
  24. /**
  25. * \file api_speed.c
  26. * Simple test to measure the overhead of making GL calls.
  27. *
  28. * The main purpose of this test is to measure the difference in calling
  29. * overhead of different dispatch methods. Since it uses asm/timex.h to
  30. * access the Pentium's cycle counters, it will probably only compile on
  31. * Linux (though most architectures have a get_cycles function in timex.h).
  32. * That is why it isn't in the default Makefile.
  33. *
  34. * \author Ian Romanick <idr@us.ibm.com>
  35. */
  36. #include <stdio.h>
  37. #include <stdlib.h>
  38. #define GL_GLEXT_PROTOTYPES
  39. #include <GL/gl.h>
  40. #include <GL/glext.h>
  41. #include <GL/glut.h>
  42. #define inline __inline__
  43. #include <asm/timex.h>
  44. static float Width = 400;
  45. static float Height = 400;
  46. static unsigned count = 1000000;
  47. static void Idle( void )
  48. {
  49. glutPostRedisplay();
  50. }
  51. #define DO_FUNC(f,p) \
  52. do { \
  53. t0 = get_cycles(); \
  54. for ( i = 0 ; i < count ; i++ ) { \
  55. f p ; \
  56. } \
  57. t1 = get_cycles(); \
  58. printf("%u calls to % 20s required %llu cycles.\n", count, # f, t1 - t0); \
  59. } while( 0 )
  60. /**
  61. * Main display function. This is the place to add more API calls.
  62. */
  63. static void Display( void )
  64. {
  65. int i;
  66. const float v[3] = { 1.0, 0.0, 0.0 };
  67. cycles_t t0;
  68. cycles_t t1;
  69. glBegin(GL_TRIANGLE_STRIP);
  70. DO_FUNC( glColor3fv, (v) );
  71. DO_FUNC( glNormal3fv, (v) );
  72. DO_FUNC( glTexCoord2fv, (v) );
  73. DO_FUNC( glTexCoord3fv, (v) );
  74. DO_FUNC( glMultiTexCoord2fv, (GL_TEXTURE0, v) );
  75. DO_FUNC( glMultiTexCoord2f, (GL_TEXTURE0, 0.0, 0.0) );
  76. DO_FUNC( glFogCoordfvEXT, (v) );
  77. DO_FUNC( glFogCoordfEXT, (0.5) );
  78. glEnd();
  79. exit(0);
  80. }
  81. static void Reshape( int width, int height )
  82. {
  83. Width = width;
  84. Height = height;
  85. glViewport( 0, 0, width, height );
  86. glMatrixMode( GL_PROJECTION );
  87. glLoadIdentity();
  88. glOrtho(0.0, width, 0.0, height, -1.0, 1.0);
  89. glMatrixMode( GL_MODELVIEW );
  90. glLoadIdentity();
  91. }
  92. static void Key( unsigned char key, int x, int y )
  93. {
  94. (void) x;
  95. (void) y;
  96. switch (key) {
  97. case 27:
  98. exit(0);
  99. break;
  100. }
  101. glutPostRedisplay();
  102. }
  103. int main( int argc, char *argv[] )
  104. {
  105. glutInit( &argc, argv );
  106. glutInitWindowSize( (int) Width, (int) Height );
  107. glutInitWindowPosition( 0, 0 );
  108. glutInitDisplayMode( GLUT_RGB );
  109. glutCreateWindow( argv[0] );
  110. if ( argc > 1 ) {
  111. count = strtoul( argv[1], NULL, 0 );
  112. if ( count == 0 ) {
  113. fprintf( stderr, "Usage: %s [iterations]\n", argv[0] );
  114. exit(1);
  115. }
  116. }
  117. glutReshapeFunc( Reshape );
  118. glutKeyboardFunc( Key );
  119. glutDisplayFunc( Display );
  120. glutIdleFunc( Idle );
  121. glutMainLoop();
  122. return 0;
  123. }