summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephane Marchesin <stephane.marchesin@gmail.com>2011-01-07 20:37:47 -0800
committerStephane Marchesin <stephane.marchesin@gmail.com>2011-01-07 20:37:47 -0800
commitbe6fd3e5caffe765589dacfb55c966886c54d26f (patch)
tree90cc36ba5950be82d6b4a1c410e1c732bb449ef6
parent351262962f17a662bd41f3a873028f72ded85a31 (diff)
Fix array support.
-rw-r--r--epilogue.c148
-rw-r--r--gen.c14
-rw-r--r--prologue.c2
3 files changed, 144 insertions, 20 deletions
diff --git a/epilogue.c b/epilogue.c
index 6b144c4..3f195ee 100644
--- a/epilogue.c
+++ b/epilogue.c
@@ -9,47 +9,122 @@ __GLXextFuncPtr glXGetProcAddress(const GLubyte *name)
return glXGetProcAddressARB(name);
}
-typedef struct
+typedef struct vertex_array_format
{
struct
{
GLenum type;
- GLint num_components;
+ GLint size;
GLint enabled;
}
attrib[16];
+ uint64_t uses;
+ uint64_t total_time;
+ struct vertex_array_format* next;
}
vertex_array_format;
-static void vertex_array_get_format(vertex_array_format* f)
+static vertex_array_format* format_list = NULL;
+
+static vertex_array_format* vertex_array_get_format()
{
- int a;
+ int a, num_enabled = 0;
+ vertex_array_format* f = (vertex_array_format*) malloc(sizeof(*f));
for(a = 0 ; a < 16 ; a++)
{
glGetVertexAttribiv(a, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &f->attrib[a].enabled);
if (f->attrib[a].enabled)
{
- glGetVertexAttribiv(a, GL_VERTEX_ATTRIB_ARRAY_SIZE, &f->attrib[a].num_components);
+ glGetVertexAttribiv(a, GL_VERTEX_ATTRIB_ARRAY_SIZE, &f->attrib[a].size);
glGetVertexAttribiv(a, GL_VERTEX_ATTRIB_ARRAY_TYPE, &f->attrib[a].type);
- printf("attrib %d %d %x\n",a,f->attrib[a].num_components,f->attrib[a].type);
+ num_enabled++;
}
else
{
- f->attrib[a].num_components = 0;
+ f->attrib[a].size = 0;
f->attrib[a].type = 0;
}
}
+ if (num_enabled == 0)
+ {
+ GLint save_active_texture;
+ glGetIntegerv(GL_CLIENT_ACTIVE_TEXTURE, &save_active_texture);
+ for(a = 0 ; a < 16 ; a++)
+ {
+ GLenum get_enabled, get_size, get_type;
+ GLint enabled = -1, size = -1, type = -1;
+
+ switch(a)
+ {
+ case 0: get_enabled = GL_VERTEX_ARRAY; get_size = GL_VERTEX_ARRAY_SIZE; get_type = GL_VERTEX_ARRAY_TYPE; break;
+ case 1: get_enabled = GL_NORMAL_ARRAY; size = 3; get_type = GL_NORMAL_ARRAY_TYPE; break;
+ case 2: get_enabled = GL_COLOR_ARRAY; get_size = GL_COLOR_ARRAY_SIZE; get_type = GL_COLOR_ARRAY_TYPE; break;
+ case 3: get_enabled = GL_INDEX_ARRAY; size = 1; get_type = GL_INDEX_ARRAY_TYPE; break;
+ case 4: get_enabled = GL_EDGE_FLAG_ARRAY; size = 1; type = GL_UNSIGNED_BYTE; break;
+ case 5: get_enabled = GL_FOG_COORD_ARRAY; size = 1; get_type = GL_FOG_COORD_ARRAY_TYPE; break;
+ case 6: get_enabled = GL_SECONDARY_COLOR_ARRAY; size = 1; get_type = GL_FOG_COORD_ARRAY_TYPE; break;
+ case 7: enabled = 0; size = 0; type = 0; break;
+ case 8: get_enabled = GL_TEXTURE_COORD_ARRAY; get_size = GL_TEXTURE_COORD_ARRAY_SIZE; type = GL_TEXTURE_COORD_ARRAY_TYPE; break;
+ case 9: get_enabled = GL_TEXTURE_COORD_ARRAY; get_size = GL_TEXTURE_COORD_ARRAY_SIZE; type = GL_TEXTURE_COORD_ARRAY_TYPE; break;
+ case 10: get_enabled = GL_TEXTURE_COORD_ARRAY; get_size = GL_TEXTURE_COORD_ARRAY_SIZE; type = GL_TEXTURE_COORD_ARRAY_TYPE; break;
+ case 11: get_enabled = GL_TEXTURE_COORD_ARRAY; get_size = GL_TEXTURE_COORD_ARRAY_SIZE; type = GL_TEXTURE_COORD_ARRAY_TYPE; break;
+ case 12: get_enabled = GL_TEXTURE_COORD_ARRAY; get_size = GL_TEXTURE_COORD_ARRAY_SIZE; type = GL_TEXTURE_COORD_ARRAY_TYPE; break;
+ case 13: get_enabled = GL_TEXTURE_COORD_ARRAY; get_size = GL_TEXTURE_COORD_ARRAY_SIZE; type = GL_TEXTURE_COORD_ARRAY_TYPE; break;
+ case 14: get_enabled = GL_TEXTURE_COORD_ARRAY; get_size = GL_TEXTURE_COORD_ARRAY_SIZE; type = GL_TEXTURE_COORD_ARRAY_TYPE; break;
+ case 15: get_enabled = GL_TEXTURE_COORD_ARRAY; get_size = GL_TEXTURE_COORD_ARRAY_SIZE; type = GL_TEXTURE_COORD_ARRAY_TYPE; break;
+ }
+
+ if (a>=8)
+ {
+ glClientActiveTexture(GL_TEXTURE0+a-8);
+ }
+ if (enabled == -1)
+ enabled = glIsEnabled(get_enabled);
+ if (size == -1)
+ glGetIntegerv(get_size, &size);
+ if (type == -1)
+ glGetIntegerv(get_type, &type);
+
+ f->attrib[a].enabled = enabled;
+ f->attrib[a].size = size;
+ f->attrib[a].type = type;
+ }
+ glClientActiveTexture(save_active_texture);
+ }
+
+ f->uses = 0;
+ f->total_time = 0;
+ f->next = NULL;
+ return f;
}
-static void vertex_array_add(vertex_array_format* f, int num)
+static vertex_array_format* vertex_array_find_format(vertex_array_format* to_find)
{
+ vertex_array_format* f = format_list;
+ while(f)
+ {
+ if(! memcmp(&f->attrib, &to_find->attrib, sizeof(f->attrib) ) )
+ {
+ free(to_find);
+ return f;
+ }
+
+ f = f->next;
+ }
+
+ // not found allocate new
+ to_find->next = format_list;
+ format_list = to_find;
+ return to_find;
}
-static void add_array(int num_elements)
+static void vertex_array_add(int num_elements, uint64_t time)
{
- vertex_array_format f;
- vertex_array_get_format(&f);
- vertex_array_add(&f, num_elements);
+ vertex_array_format *f, *g;
+ f = vertex_array_get_format();
+ g = vertex_array_find_format(f);
+ g->uses += num_elements;
+ g->total_time += time;
}
@@ -63,6 +138,21 @@ static int compare(const void* a, const void* b)
return total_time[v1]<total_time[v2]?1:-1;
}
+static void gl_type(GLenum type, char* s)
+{
+ switch(type)
+ {
+ case GL_BYTE: sprintf(s, "B "); break;
+ case GL_UNSIGNED_BYTE: sprintf(s, "UB"); break;
+ case GL_SHORT: sprintf(s, "S "); break;
+ case GL_UNSIGNED_SHORT: sprintf(s, "US"); break;
+ case GL_INT: sprintf(s, "I "); break;
+ case GL_UNSIGNED_INT: sprintf(s, "UI"); break;
+ case GL_FLOAT: sprintf(s, "F "); break;
+ case GL_DOUBLE: sprintf(s, "D"); break;
+ }
+}
+
static void exit_func()
{
rtld_fini_func();
@@ -80,6 +170,7 @@ static void exit_func()
qsort(findex, num_funcs, sizeof(int), compare);
+ printf("=============================================================\n");
printf("Function Name \t\t\ttotal(us) \ttotal(%%) \t #calls\t avg us\n");
for(i = 0 ; i < num_funcs ; i++)
{
@@ -94,6 +185,39 @@ static void exit_func()
}
}
free(findex);
+ printf("=============================================================\n");
+ printf("Array format \t\tusage \t total\n");
+ printf("V N C I EF FG C2 ? T0 T1 T2 T3 T4 T5 T6 T7 \t\tpercent\t #vertex\n");
+
+ uint64_t total_uses = 0;
+ vertex_array_format* f = format_list;
+
+ while(f)
+ {
+ total_uses += f->uses;
+
+ f = f->next;
+ }
+
+ f = format_list;
+ while(f)
+ {
+ int a;
+ for(a = 0 ; a < 16 ; a++)
+ {
+ if (f->attrib[a].enabled)
+ {
+ char type_name[4];
+ gl_type(f->attrib[a].type, type_name);
+ printf("%d%s ",f->attrib[a].size,type_name);
+ }
+ else
+ printf(" ");
+ }
+ printf("\t\t%7.3f\t %d\n",f->uses*100.0/total_uses,f->uses);
+
+ f = f->next;
+ }
}
}
diff --git a/gen.c b/gen.c
index 0d1a5b1..fe840d6 100644
--- a/gen.c
+++ b/gen.c
@@ -424,13 +424,6 @@ int main()
// generate the function body
- if (!strcmp(func_name,"DrawArrays"))
- fprintf(file_wrapped,"\tadd_array(count);\n");
- if (!strcmp(func_name,"DrawElements"))
- fprintf(file_wrapped,"\tadd_array(count);\n");
- if (!strcmp(func_name,"ArrayElement"))
- fprintf(file_wrapped,"\tadd_array(1);\n");
-
fprintf(file_wrapped,"\tuint64_t before, after;\n");
fprintf(file_wrapped,"\tif (trace_perfunc) {\n");
fprintf(file_wrapped,"\t\tprintf(\"gl%s\\n\");\n",func_name);
@@ -483,6 +476,13 @@ int main()
fprintf(file_wrapped,"\t\ttotal_calls[%d] ++;\n", fnum);
fprintf(file_wrapped, "\t}\n");
+ if (!strcmp(func_name,"DrawArrays"))
+ fprintf(file_wrapped,"\tvertex_array_add(count, after - before);\n");
+ if (!strcmp(func_name,"DrawElements"))
+ fprintf(file_wrapped,"\tvertex_array_add(count, after - before);\n");
+ if (!strcmp(func_name,"ArrayElement"))
+ fprintf(file_wrapped,"\tvertex_array_add(1, after - before);\n");
+
if (type_match(return_type) != 0)
fprintf(file_wrapped,"\treturn ret;\n");
diff --git a/prologue.c b/prologue.c
index 8863af0..4ce20fc 100644
--- a/prologue.c
+++ b/prologue.c
@@ -32,6 +32,6 @@ static uint64_t gettime64()
return ((uint64_t)tv.tv_sec * 1000000ULL + (uint64_t)tv.tv_usec);
}
-static void add_array(int num_elements);
+static void vertex_array_add(int num_elements, uint64_t time);