Clone of mesa.
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included
  12. * in all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  15. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * VMWARE BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  18. * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  19. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. */
  21. /**
  22. * Measure glReadPixels speed.
  23. * XXX also read into a PBO?
  24. * XXX also read from FBOs?
  25. *
  26. * Brian Paul
  27. * 23 Sep 2009
  28. */
  29. #include <string.h>
  30. #include <assert.h>
  31. #include "glmain.h"
  32. #include "common.h"
  33. int WinWidth = 1000, WinHeight = 1000;
  34. static GLuint VBO;
  35. static const GLboolean DrawPoint = GL_TRUE;
  36. static const GLboolean BufferSubDataInHalves = GL_TRUE;
  37. static const GLfloat Vertex0[2] = { 0.0, 0.0 };
  38. static GLenum HaveDepthStencil;
  39. static GLenum ReadFormat, ReadType;
  40. static GLint ReadWidth, ReadHeight;
  41. static GLvoid *ReadBuffer;
  42. /** Called from test harness/main */
  43. void
  44. PerfInit(void)
  45. {
  46. /* setup VBO */
  47. glGenBuffersARB(1, &VBO);
  48. glBindBufferARB(GL_ARRAY_BUFFER_ARB, VBO);
  49. glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(Vertex0), Vertex0, GL_STATIC_DRAW_ARB);
  50. glVertexPointer(2, GL_FLOAT, sizeof(Vertex0), (void *) 0);
  51. glEnableClientState(GL_VERTEX_ARRAY);
  52. glPixelStorei(GL_PACK_ALIGNMENT, 1);
  53. HaveDepthStencil = PerfExtensionSupported("GL_EXT_packed_depth_stencil");
  54. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
  55. glEnable(GL_DEPTH_TEST);
  56. glEnable(GL_STENCIL_TEST);
  57. }
  58. static void
  59. ReadPixels(unsigned count)
  60. {
  61. unsigned i;
  62. for (i = 0; i < count; i++) {
  63. /* read from random pos */
  64. GLint x, y;
  65. x = WinWidth - ReadWidth;
  66. y = WinHeight - ReadHeight;
  67. if (x > 0)
  68. x = rand() % x;
  69. if (y > 0)
  70. y = rand() % y;
  71. if (DrawPoint)
  72. glDrawArrays(GL_POINTS, 0, 1);
  73. glReadPixels(x, y, ReadWidth, ReadHeight,
  74. ReadFormat, ReadType, ReadBuffer);
  75. }
  76. glFinish();
  77. }
  78. static const GLsizei Sizes[] = {
  79. 10,
  80. 100,
  81. 500,
  82. 1000,
  83. 0
  84. };
  85. static const struct {
  86. GLenum format;
  87. GLenum type;
  88. const char *name;
  89. GLuint pixel_size;
  90. } DstFormats[] = {
  91. { GL_RGBA, GL_UNSIGNED_BYTE, "RGBA/ubyte", 4 },
  92. { GL_BGRA, GL_UNSIGNED_BYTE, "BGRA/ubyte", 4 },
  93. { GL_RGB, GL_UNSIGNED_SHORT_5_6_5, "RGB/565", 2 },
  94. { GL_LUMINANCE, GL_UNSIGNED_BYTE, "L/ubyte", 1 },
  95. { GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, "Z/uint", 4 },
  96. { GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT, "Z+S/uint", 4 },
  97. { 0, 0, NULL, 0 }
  98. };
  99. /** Called from test harness/main */
  100. void
  101. PerfNextRound(void)
  102. {
  103. }
  104. /** Called from test harness/main */
  105. void
  106. PerfDraw(void)
  107. {
  108. double rate, mbPerSec;
  109. int fmt, sz;
  110. /* loop over formats */
  111. for (fmt = 0; DstFormats[fmt].format; fmt++) {
  112. ReadFormat = DstFormats[fmt].format;
  113. ReadType = DstFormats[fmt].type;
  114. /* loop over sizes */
  115. for (sz = 0; Sizes[sz]; sz++) {
  116. int imgSize;
  117. ReadWidth = ReadHeight = Sizes[sz];
  118. imgSize = ReadWidth * ReadHeight * DstFormats[fmt].pixel_size;
  119. ReadBuffer = malloc(imgSize);
  120. if (ReadFormat == GL_DEPTH_STENCIL_EXT && !HaveDepthStencil) {
  121. rate = 0.0;
  122. mbPerSec = 0.0;
  123. }
  124. else {
  125. rate = PerfMeasureRate(ReadPixels);
  126. mbPerSec = rate * imgSize / (1024.0 * 1024.0);
  127. }
  128. perf_printf("glReadPixels(%d x %d, %s): %.1f images/sec, %.1f Mpixels/sec\n",
  129. ReadWidth, ReadHeight,
  130. DstFormats[fmt].name, rate, mbPerSec);
  131. free(ReadBuffer);
  132. }
  133. }
  134. exit(0);
  135. }