summaryrefslogtreecommitdiff
path: root/progs/perf/drawoverhead.c
blob: c1e166e7462f3e3b9b810027da36c7ce20cc7bcc (plain)
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
 * Copyright (C) 2009  VMware, Inc.  All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * VMWARE BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

/**
 * Measure drawing overhead
 *
 * This is the first in a series of simple performance benchmarks.
 * The code in this file should be as simple as possible to make it
 * easily portable to other APIs.
 *
 * All the window-system stuff should be contained in glmain.c (or TBDmain.c).
 * All the re-usable, generic code should be in common.c (XXX not done yet).
 *
 * Brian Paul
 * 15 Sep 2009
 */

#include "glmain.h"
#include "common.h"


int WinWidth = 100, WinHeight = 100;

static GLuint VBO;

struct vertex
{
   GLfloat x, y;
};

static const struct vertex vertices[4] = {
   { -1.0, -1.0 },
   {  1.0, -1.0 },
   {  1.0,  1.0 },
   { -1.0,  1.0 }
};


/** Called from test harness/main */
void
PerfInit(void)
{
   /* setup VBO w/ vertex data */
   glGenBuffersARB(1, &VBO);
   glBindBufferARB(GL_ARRAY_BUFFER_ARB, VBO);
   glBufferDataARB(GL_ARRAY_BUFFER_ARB,
                   sizeof(vertices), vertices, GL_STATIC_DRAW_ARB);
   glVertexPointer(2, GL_FLOAT, sizeof(struct vertex), (void *) 0);
   glEnableClientState(GL_VERTEX_ARRAY);

   /* misc GL state */
   glAlphaFunc(GL_ALWAYS, 0.0);
}


static void
DrawNoStateChange(unsigned count)
{
   unsigned i;
   for (i = 0; i < count; i++) {
      glDrawArrays(GL_POINTS, 0, 4);
   }
   glFinish();
}


static void
DrawNopStateChange(unsigned count)
{
   unsigned i;
   for (i = 0; i < count; i++) {
      glDisable(GL_ALPHA_TEST);
      glDrawArrays(GL_POINTS, 0, 4);
   }
   glFinish();
}


static void
DrawStateChange(unsigned count)
{
   unsigned i;
   for (i = 0; i < count; i++) {
      if (i & 1)
         glEnable(GL_TEXTURE_GEN_S);
      else
         glDisable(GL_TEXTURE_GEN_S);
      glDrawArrays(GL_POINTS, 0, 4);
   }
   glFinish();
}


/** Called from test harness/main */
void
PerfDraw(void)
{
   double rate0, rate1, rate2, overhead;

   rate0 = PerfMeasureRate(DrawNoStateChange);
   perf_printf("   Draw only: %.1f draws/second\n", rate0);
   

   rate1 = PerfMeasureRate(DrawNopStateChange);
   overhead = 1000.0 * (1.0 / rate1 - 1.0 / rate0);
   perf_printf("   Draw w/ nop state change: %.1f draws/sec (overhead: %f ms/draw)\n",
               rate1, overhead);

   rate2 = PerfMeasureRate(DrawStateChange);
   overhead = 1000.0 * (1.0 / rate2 - 1.0 / rate0);
   perf_printf("   Draw w/ state change: %.1f draws/sec (overhead: %f ms/draw)\n",
               rate2, overhead);

   exit(0);
}