diff options
author | Jose Fonseca <jfonseca@vmware.com> | 2016-05-08 22:33:44 +0100 |
---|---|---|
committer | Jose Fonseca <jfonseca@vmware.com> | 2016-05-10 03:25:25 -0700 |
commit | dddc5b8534d68b5315d9b9aaafd45d8a79e36198 (patch) | |
tree | e5de0832ad6cb320cb5f1c5c7ef8139ce76ea35a /wrappers | |
parent | f2f96569a38a8fada61096ea725f24715669978e (diff) |
gltrace: Pass draw parameters as struct.
Diffstat (limited to 'wrappers')
-rw-r--r-- | wrappers/gltrace.py | 27 | ||||
-rw-r--r-- | wrappers/gltrace_arrays.cpp | 83 | ||||
-rw-r--r-- | wrappers/gltrace_arrays.hpp | 100 |
3 files changed, 123 insertions, 87 deletions
diff --git a/wrappers/gltrace.py b/wrappers/gltrace.py index 700a9db3..065f7608 100644 --- a/wrappers/gltrace.py +++ b/wrappers/gltrace.py @@ -366,7 +366,7 @@ class GlTracer(Tracer): )) # XXX: We currently ignore the gl*Draw*ElementArray* functions - draw_function_regex = re.compile(r'^gl([A-Z][a-z]+)*Draw(Range)?(Arrays|Elements)([A-Z][a-zA-Z]*)?$' ) + draw_function_regex = re.compile(r'^(?P<radical>gl([A-Z][a-z]+)*Draw(Range)?(Arrays|Elements))(?P<suffix>[A-Z][a-zA-Z]*)?$' ) interleaved_formats = [ 'GL_V2F', @@ -465,14 +465,33 @@ class GlTracer(Tracer): print ' }' # ... to the draw calls - if self.draw_function_regex.match(function.name): + mo = self.draw_function_regex.match(function.name) + if mo: + functionRadical = mo.group('radical') print ' gltrace::Context *_ctx = gltrace::getContext();' print ' if (_need_user_arrays(_ctx)) {' if 'Indirect' in function.name: print r' os::log("apitrace: warning: %s: indirect user arrays not supported\n");' % (function.name,) else: - arg_names = ', '.join([arg.name for arg in function.args[1:]]) - print ' GLuint _count = _%s_count(%s);' % (function.name, arg_names) + # Pick the corresponding *Params + if 'Arrays' in functionRadical: + paramsType = 'DrawArraysParams' + elif 'Elements' in functionRadical: + paramsType = 'DrawElementsParams' + else: + assert 0 + if 'Multi' in functionRadical: + assert 'drawcount' in function.argNames() + paramsType = 'Multi' + paramsType + print r' %s _params;' % paramsType + + for arg in function.args: + paramsMember = arg.name.lower() + if paramsMember in ('mode', 'modestride'): + continue + print r' _params.%s = %s;' % (paramsMember, arg.name) + + print ' GLuint _count = _glDraw_count(_params);' # Some apps, in particular Quake3, can tell the driver to lock more # vertices than those actually required for the draw call. print ' if (_checkLockArraysEXT) {' diff --git a/wrappers/gltrace_arrays.cpp b/wrappers/gltrace_arrays.cpp index b2b1eb38..8986131d 100644 --- a/wrappers/gltrace_arrays.cpp +++ b/wrappers/gltrace_arrays.cpp @@ -27,19 +27,35 @@ #include "gltrace_arrays.hpp" +/* FIXME take in consideration instancing */ + + GLuint -_glDrawArrays_count(GLint first, GLsizei count) +_glDraw_count(const DrawArraysParams ¶ms) { - if (!count) { + if (!params.count) { return 0; } - return first + count; + return params.first + params.count; } GLuint -_glDrawElementsBaseVertex_count(GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex) +_glDraw_count(const DrawElementsParams ¶ms) { + if (params.end < params.start || + params.count <= 0) { + return 0; + } + + if (params.end != ~0U) { + return params.end + params.basevertex + 1; + } + + GLuint count = params.count; + GLenum type = params.type; + const void *indices = params.indices; + GLvoid *temp = 0; if (!count) { @@ -117,30 +133,27 @@ _glDrawElementsBaseVertex_count(GLsizei count, GLenum type, const GLvoid *indice free(temp); } - maxindex += basevertex; + maxindex += params.basevertex; return maxindex + 1; } GLuint -_glDrawRangeElementsBaseVertex_count(GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices, GLint basevertex) -{ - if (end < start || - count < 0) { - return 0; - } - - return end + basevertex + 1; -} - - -GLuint -_glMultiDrawArrays_count(const GLint *first, const GLsizei *count, GLsizei drawcount) +_glDraw_count(const MultiDrawArraysParams ¶ms) { GLuint _count = 0; - for (GLsizei draw = 0; draw < drawcount; ++draw) { - GLuint _count_draw = _glDrawArrays_count(first[draw], count[draw]); + for (GLsizei draw = 0; draw < params.drawcount; ++draw) { + DrawArraysParams params_draw; + if (params.first) { + params_draw.first = params.first[draw]; + } + if (params.count) { + params_draw.count = params.count[draw]; + } + params_draw.instancecount = params.instancecount; + params_draw.baseinstance = params.baseinstance; + GLuint _count_draw = _glDraw_count(params_draw); _count = std::max(_count, _count_draw); } return _count; @@ -148,24 +161,26 @@ _glMultiDrawArrays_count(const GLint *first, const GLsizei *count, GLsizei drawc GLuint -_glMultiDrawElements_count(const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei drawcount) +_glDraw_count(const MultiDrawElementsParams ¶ms) { GLuint _count = 0; - for (GLsizei draw = 0; draw < drawcount; ++draw) { - GLuint _count_draw = _glDrawElements_count(count[draw], type, indices[draw]); + for (GLsizei draw = 0; draw < params.drawcount; ++draw) { + DrawElementsParams params_draw; + if (params.count) { + params_draw.count = params.count[draw]; + } + params_draw.type = params.type; + if (params.indices) { + params_draw.indices = params.indices[draw]; + } + if (params.basevertex) { + params_draw.basevertex = params.basevertex[draw]; + } + params_draw.instancecount = params.instancecount; + params_draw.baseinstance = params.baseinstance; + GLuint _count_draw = _glDraw_count(params_draw); _count = std::max(_count, _count_draw); } return _count; } - -GLuint -_glMultiDrawElementsBaseVertex_count(const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei drawcount, const GLint * basevertex) -{ - GLuint _count = 0; - for (GLsizei draw = 0; draw < drawcount; ++draw) { - GLuint _count_draw = _glDrawElementsBaseVertex_count(count[draw], type, indices[draw], basevertex[draw]); - _count = std::max(_count, _count_draw); - } - return _count; -} diff --git a/wrappers/gltrace_arrays.hpp b/wrappers/gltrace_arrays.hpp index d3b2662a..2ecf893c 100644 --- a/wrappers/gltrace_arrays.hpp +++ b/wrappers/gltrace_arrays.hpp @@ -30,61 +30,63 @@ #include "glsize.hpp" -GLuint -_glDrawArrays_count(GLint first, GLsizei count); - -#define _glDrawArraysEXT_count _glDrawArrays_count +/* + * TODO: Unify all draw params structure into a single structure. + */ + + +struct DrawArraysParams +{ + GLuint first = 0; + GLuint count = 0; + GLsizei instancecount = 1; + GLuint baseinstance = 0; +}; + + +struct DrawElementsParams +{ + GLuint start = 0; + GLuint end = ~0U; + GLuint count = 0; + GLenum type = GL_NONE; + const void *indices = nullptr; + GLint basevertex = 0; + GLsizei instancecount = 1; + GLuint baseinstance = 0; +}; + + +struct MultiDrawArraysParams +{ + const GLint *first = nullptr; + const GLsizei *count = nullptr; + GLsizei drawcount = 0; + GLsizei instancecount = 1; + GLuint baseinstance = 0; +}; + + +struct MultiDrawElementsParams +{ + const GLsizei *count = nullptr; + GLenum type = GL_NONE; + const void * const *indices = nullptr; + const GLint *basevertex = nullptr; + GLsizei drawcount = 0; + GLsizei instancecount = 1; + GLuint baseinstance = 0; +}; -GLuint -_glDrawElementsBaseVertex_count(GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex); GLuint -_glDrawRangeElementsBaseVertex_count(GLuint start, GLuint end, GLsizei count, GLenum type, const void *indices, GLint basevertex); - - -#define _glDrawElements_count(count, type, indices) _glDrawElementsBaseVertex_count(count, type, indices, 0) -#define _glDrawRangeElements_count(start, end, count, type, indices) _glDrawRangeElementsBaseVertex_count(start, end, count, type, indices, 0) -#define _glDrawRangeElementsEXT_count _glDrawRangeElements_count - -/* FIXME take in consideration instancing */ -#define _glDrawArraysInstanced_count(first, count, primcount) _glDrawArrays_count(first, count) -#define _glDrawElementsInstanced_count(count, type, indices, primcount) _glDrawElements_count(count, type, indices) -#define _glDrawElementsInstancedBaseVertex_count(count, type, indices, primcount, basevertex) _glDrawElementsBaseVertex_count(count, type, indices, basevertex) -#define _glDrawRangeElementsInstanced_count(start, end, count, type, indices, primcount) _glDrawRangeElements_count(start, end, count, type, indices) -#define _glDrawRangeElementsInstancedBaseVertex_count(start, end, count, type, indices, primcount, basevertex) _glDrawRangeElementsBaseVertex_count(start, end, count, type, indices, basevertex) - -#define _glDrawArraysInstancedBaseInstance_count(first, count, primcount, baseinstance) _glDrawArrays_count(first, count) -#define _glDrawElementsInstancedBaseInstance_count(count, type, indices, primcount, baseinstance) _glDrawElements_count(count, type, indices) -#define _glDrawElementsInstancedBaseVertexBaseInstance_count(count, type, indices, primcount, basevertex, baseinstance) _glDrawElementsBaseVertex_count(count, type, indices, basevertex) - -#define _glDrawArraysInstancedARB_count _glDrawArraysInstanced_count -#define _glDrawArraysInstancedEXT_count _glDrawArraysInstanced_count -#define _glDrawArraysInstancedANGLE_count _glDrawArraysInstanced_count -#define _glDrawArraysInstancedBaseInstanceEXT_count _glDrawArraysInstancedBaseInstance_count -#define _glDrawElementsBaseVertexEXT_count _glDrawElementsBaseVertex_count -#define _glDrawElementsInstancedARB_count _glDrawElementsInstanced_count -#define _glDrawElementsInstancedEXT_count _glDrawElementsInstanced_count -#define _glDrawElementsInstancedANGLE_count _glDrawElementsInstanced_count -#define _glDrawElementsInstancedBaseInstanceEXT_count _glDrawElementsInstancedBaseInstance_count -#define _glDrawElementsInstancedBaseVertexEXT_count _glDrawElementsInstancedBaseVertex_count -#define _glDrawElementsInstancedBaseVertexBaseInstanceEXT_count _glDrawElementsInstancedBaseVertexBaseInstance_count -#define _glDrawRangeElementsBaseVertexEXT_count _glDrawRangeElementsBaseVertex_count - +_glDraw_count(const DrawArraysParams ¶ms); GLuint -_glMultiDrawArrays_count(const GLint *first, const GLsizei *count, GLsizei drawcount); +_glDraw_count(const DrawElementsParams ¶ms); GLuint -_glMultiDrawElements_count(const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei drawcount); +_glDraw_count(const MultiDrawArraysParams ¶ms); GLuint -_glMultiDrawElementsBaseVertex_count(const GLsizei *count, GLenum type, const GLvoid* const *indices, GLsizei drawcount, const GLint * basevertex); - -#define _glMultiDrawArraysEXT_count _glMultiDrawArrays_count -#define _glMultiDrawElementsEXT_count _glMultiDrawElements_count -#define _glMultiDrawElementsBaseVertexEXT_count _glMultiDrawElementsBaseVertex_count - -#define _glMultiModeDrawArraysIBM_count(first, count, drawcount, modestride) _glMultiDrawArrays_count(first, count, drawcount) -#define _glMultiModeDrawElementsIBM_count(count, type, indices, drawcount, modestride) _glMultiDrawElements_count(count, type, (const GLvoid **)indices, drawcount) - - +_glDraw_count(const MultiDrawElementsParams ¶ms); |