blob: 1fbb1e3ba7887ffaa3616daa61320a707575e104 [file] [log] [blame]
José Fonseca669b1222011-02-20 09:05:10 +00001##########################################################################
2#
3# Copyright 2008-2010 VMware, Inc.
4# All Rights Reserved.
5#
6# Permission is hereby granted, free of charge, to any person obtaining a copy
7# of this software and associated documentation files (the "Software"), to deal
8# in the Software without restriction, including without limitation the rights
9# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10# copies of the Software, and to permit persons to whom the Software is
11# furnished to do so, subject to the following conditions:
12#
13# The above copyright notice and this permission notice shall be included in
14# all copies or substantial portions of the 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 NONINFRINGEMENT. IN NO EVENT SHALL THE
19# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22# THE SOFTWARE.
23#
24##########################################################################/
25
26
27"""GL tracing generator."""
28
29
José Fonsecac5bf77a2014-08-14 16:10:02 +010030import re
31import sys
32
José Fonseca452d3252012-04-14 15:55:40 +010033from trace import Tracer
José Fonseca1b6c8752012-04-15 14:33:00 +010034from dispatch import function_pointer_type, function_pointer_value
José Fonsecabd86a222011-09-27 09:21:38 +010035import specs.stdapi as stdapi
36import specs.glapi as glapi
37import specs.glparams as glparams
38from specs.glxapi import glxapi
José Fonseca669b1222011-02-20 09:05:10 +000039
40
José Fonseca99221832011-03-22 22:15:46 +000041class TypeGetter(stdapi.Visitor):
42 '''Determine which glGet*v function that matches the specified type.'''
43
José Fonsecac493e3e2011-06-29 12:57:06 +010044 def __init__(self, prefix = 'glGet', long_suffix = True, ext_suffix = ''):
José Fonseca1a2fdd22011-04-01 00:55:09 +010045 self.prefix = prefix
46 self.long_suffix = long_suffix
José Fonsecac493e3e2011-06-29 12:57:06 +010047 self.ext_suffix = ext_suffix
José Fonseca1a2fdd22011-04-01 00:55:09 +010048
José Fonseca54f304a2012-01-14 19:33:08 +000049 def visitConst(self, const):
José Fonseca99221832011-03-22 22:15:46 +000050 return self.visit(const.type)
51
José Fonseca54f304a2012-01-14 19:33:08 +000052 def visitAlias(self, alias):
José Fonseca99221832011-03-22 22:15:46 +000053 if alias.expr == 'GLboolean':
José Fonseca1a2fdd22011-04-01 00:55:09 +010054 if self.long_suffix:
José Fonsecac493e3e2011-06-29 12:57:06 +010055 suffix = 'Booleanv'
56 arg_type = alias.expr
José Fonseca1a2fdd22011-04-01 00:55:09 +010057 else:
José Fonsecac493e3e2011-06-29 12:57:06 +010058 suffix = 'iv'
59 arg_type = 'GLint'
José Fonseca99221832011-03-22 22:15:46 +000060 elif alias.expr == 'GLdouble':
José Fonseca1a2fdd22011-04-01 00:55:09 +010061 if self.long_suffix:
José Fonsecac493e3e2011-06-29 12:57:06 +010062 suffix = 'Doublev'
63 arg_type = alias.expr
José Fonseca1a2fdd22011-04-01 00:55:09 +010064 else:
José Fonsecac493e3e2011-06-29 12:57:06 +010065 suffix = 'dv'
66 arg_type = alias.expr
José Fonseca99221832011-03-22 22:15:46 +000067 elif alias.expr == 'GLfloat':
José Fonseca1a2fdd22011-04-01 00:55:09 +010068 if self.long_suffix:
José Fonsecac493e3e2011-06-29 12:57:06 +010069 suffix = 'Floatv'
70 arg_type = alias.expr
José Fonseca1a2fdd22011-04-01 00:55:09 +010071 else:
José Fonsecac493e3e2011-06-29 12:57:06 +010072 suffix = 'fv'
73 arg_type = alias.expr
José Fonseca7f5163e2011-03-31 23:37:26 +010074 elif alias.expr in ('GLint', 'GLuint', 'GLsizei'):
José Fonseca1a2fdd22011-04-01 00:55:09 +010075 if self.long_suffix:
José Fonsecac493e3e2011-06-29 12:57:06 +010076 suffix = 'Integerv'
77 arg_type = 'GLint'
José Fonseca1a2fdd22011-04-01 00:55:09 +010078 else:
José Fonsecac493e3e2011-06-29 12:57:06 +010079 suffix = 'iv'
80 arg_type = 'GLint'
José Fonseca99221832011-03-22 22:15:46 +000081 else:
82 print alias.expr
83 assert False
José Fonsecac493e3e2011-06-29 12:57:06 +010084 function_name = self.prefix + suffix + self.ext_suffix
85 return function_name, arg_type
José Fonseca99221832011-03-22 22:15:46 +000086
José Fonseca54f304a2012-01-14 19:33:08 +000087 def visitEnum(self, enum):
José Fonseca1a2fdd22011-04-01 00:55:09 +010088 return self.visit(glapi.GLint)
José Fonseca99221832011-03-22 22:15:46 +000089
José Fonseca54f304a2012-01-14 19:33:08 +000090 def visitBitmask(self, bitmask):
José Fonseca1a2fdd22011-04-01 00:55:09 +010091 return self.visit(glapi.GLint)
José Fonseca99221832011-03-22 22:15:46 +000092
José Fonseca54f304a2012-01-14 19:33:08 +000093 def visitOpaque(self, pointer):
José Fonsecac493e3e2011-06-29 12:57:06 +010094 return self.prefix + 'Pointerv' + self.ext_suffix, 'GLvoid *'
José Fonseca99221832011-03-22 22:15:46 +000095
96
José Fonseca669b1222011-02-20 09:05:10 +000097class GlTracer(Tracer):
98
José Fonseca99221832011-03-22 22:15:46 +000099 arrays = [
100 ("Vertex", "VERTEX"),
101 ("Normal", "NORMAL"),
102 ("Color", "COLOR"),
103 ("Index", "INDEX"),
104 ("TexCoord", "TEXTURE_COORD"),
105 ("EdgeFlag", "EDGE_FLAG"),
106 ("FogCoord", "FOG_COORD"),
107 ("SecondaryColor", "SECONDARY_COLOR"),
José Fonseca14c21bc2011-02-20 23:32:22 +0000108 ]
José Fonsecac9f12232011-03-25 20:07:42 +0000109 arrays.reverse()
José Fonseca669b1222011-02-20 09:05:10 +0000110
José Fonsecab0c59722015-01-05 20:45:41 +0000111 # arrays available in ES1
Chia-I Wub3d218d2011-11-03 01:37:36 +0800112 arrays_es1 = ("Vertex", "Normal", "Color", "TexCoord")
113
José Fonseca4c938c22011-04-30 22:44:38 +0100114 def header(self, api):
115 Tracer.header(self, api)
116
José Fonseca707630d2014-03-07 14:20:35 +0000117 print '#include <algorithm>'
118 print
José Fonseca1b3d3752011-07-15 10:15:19 +0100119 print '#include "gltrace.hpp"'
120 print
José Fonseca5a568a92011-06-29 16:43:36 +0100121
122 # Which glVertexAttrib* variant to use
123 print 'enum vertex_attrib {'
124 print ' VERTEX_ATTRIB,'
José Fonseca5a568a92011-06-29 16:43:36 +0100125 print ' VERTEX_ATTRIB_NV,'
126 print '};'
127 print
José Fonseca632a78d2012-04-19 07:18:59 +0100128 print 'static vertex_attrib _get_vertex_attrib(void) {'
José Fonsecaf028a8f2012-02-15 23:33:35 +0000129 print ' gltrace::Context *ctx = gltrace::getContext();'
José Fonseca74b661a2014-07-17 19:10:24 +0100130 print ' if (ctx->user_arrays_nv) {'
José Fonseca632a78d2012-04-19 07:18:59 +0100131 print ' GLboolean _vertex_program = GL_FALSE;'
132 print ' _glGetBooleanv(GL_VERTEX_PROGRAM_ARB, &_vertex_program);'
133 print ' if (_vertex_program) {'
Chia-I Wu8ef66972011-11-03 01:19:46 +0800134 print ' if (ctx->user_arrays_nv) {'
José Fonseca26be8f92014-03-07 14:08:50 +0000135 print ' GLint _vertex_program_binding_nv = _glGetInteger(GL_VERTEX_PROGRAM_BINDING_NV);'
José Fonseca632a78d2012-04-19 07:18:59 +0100136 print ' if (_vertex_program_binding_nv) {'
José Fonseca5a568a92011-06-29 16:43:36 +0100137 print ' return VERTEX_ATTRIB_NV;'
138 print ' }'
139 print ' }'
José Fonseca5a568a92011-06-29 16:43:36 +0100140 print ' }'
141 print ' }'
142 print ' return VERTEX_ATTRIB;'
143 print '}'
144 print
145
Imre Deakd4937372012-04-24 14:06:48 +0300146 self.defineShadowBufferHelper()
147
José Fonseca8a6c6cb2011-03-23 16:44:30 +0000148 # Whether we need user arrays
José Fonseca632a78d2012-04-19 07:18:59 +0100149 print 'static inline bool _need_user_arrays(void)'
José Fonseca8a6c6cb2011-03-23 16:44:30 +0000150 print '{'
José Fonsecaf028a8f2012-02-15 23:33:35 +0000151 print ' gltrace::Context *ctx = gltrace::getContext();'
Chia-I Wu8ef66972011-11-03 01:19:46 +0800152 print ' if (!ctx->user_arrays) {'
José Fonseca25ebe542011-04-24 10:08:22 +0100153 print ' return false;'
154 print ' }'
155 print
José Fonsecab0c59722015-01-05 20:45:41 +0000156 print ' glprofile::Profile profile = ctx->profile;'
157 print ' bool es1 = profile.es() && profile.major == 1;'
José Fonseca8b04b5a2014-07-17 19:25:21 +0100158 print
José Fonseca1a2fdd22011-04-01 00:55:09 +0100159
José Fonseca8a6c6cb2011-03-23 16:44:30 +0000160 for camelcase_name, uppercase_name in self.arrays:
Chia-I Wub3d218d2011-11-03 01:37:36 +0800161 # in which profile is the array available?
José Fonseca34ea6162015-01-08 23:45:43 +0000162 profile_check = 'profile.desktop()'
Chia-I Wub3d218d2011-11-03 01:37:36 +0800163 if camelcase_name in self.arrays_es1:
José Fonsecab0c59722015-01-05 20:45:41 +0000164 profile_check = '(' + profile_check + ' || es1)';
Chia-I Wub3d218d2011-11-03 01:37:36 +0800165
José Fonseca8a6c6cb2011-03-23 16:44:30 +0000166 function_name = 'gl%sPointer' % camelcase_name
167 enable_name = 'GL_%s_ARRAY' % uppercase_name
168 binding_name = 'GL_%s_ARRAY_BUFFER_BINDING' % uppercase_name
169 print ' // %s' % function_name
Chia-I Wub3d218d2011-11-03 01:37:36 +0800170 print ' if (%s) {' % profile_check
José Fonsecafb6744f2011-04-15 11:18:37 +0100171 self.array_prolog(api, uppercase_name)
José Fonseca8b04b5a2014-07-17 19:25:21 +0100172 print ' if (_glIsEnabled(%s) &&' % enable_name
173 print ' _glGetInteger(%s) == 0) {' % binding_name
José Fonsecafb6744f2011-04-15 11:18:37 +0100174 self.array_cleanup(api, uppercase_name)
José Fonseca8b04b5a2014-07-17 19:25:21 +0100175 print ' return true;'
José Fonseca8a6c6cb2011-03-23 16:44:30 +0000176 print ' }'
José Fonsecafb6744f2011-04-15 11:18:37 +0100177 self.array_epilog(api, uppercase_name)
Chia-I Wub3d218d2011-11-03 01:37:36 +0800178 print ' }'
José Fonseca8a6c6cb2011-03-23 16:44:30 +0000179 print
José Fonseca7f5163e2011-03-31 23:37:26 +0100180
Chia-I Wub3d218d2011-11-03 01:37:36 +0800181 print ' // ES1 does not support generic vertex attributes'
José Fonsecab0c59722015-01-05 20:45:41 +0000182 print ' if (es1)'
Chia-I Wub3d218d2011-11-03 01:37:36 +0800183 print ' return false;'
184 print
José Fonseca632a78d2012-04-19 07:18:59 +0100185 print ' vertex_attrib _vertex_attrib = _get_vertex_attrib();'
José Fonseca5a568a92011-06-29 16:43:36 +0100186 print
187 print ' // glVertexAttribPointer'
José Fonseca632a78d2012-04-19 07:18:59 +0100188 print ' if (_vertex_attrib == VERTEX_ATTRIB) {'
José Fonseca26be8f92014-03-07 14:08:50 +0000189 print ' GLint _max_vertex_attribs = _glGetInteger(GL_MAX_VERTEX_ATTRIBS);'
José Fonseca632a78d2012-04-19 07:18:59 +0100190 print ' for (GLint index = 0; index < _max_vertex_attribs; ++index) {'
José Fonseca8b04b5a2014-07-17 19:25:21 +0100191 print ' if (_glGetVertexAttribi(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED) &&'
192 print ' _glGetVertexAttribi(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING) == 0) {'
193 print ' return true;'
José Fonseca5a568a92011-06-29 16:43:36 +0100194 print ' }'
195 print ' }'
196 print ' }'
197 print
José Fonseca5a568a92011-06-29 16:43:36 +0100198 print ' // glVertexAttribPointerNV'
José Fonseca632a78d2012-04-19 07:18:59 +0100199 print ' if (_vertex_attrib == VERTEX_ATTRIB_NV) {'
José Fonseca5a568a92011-06-29 16:43:36 +0100200 print ' for (GLint index = 0; index < 16; ++index) {'
José Fonseca8b04b5a2014-07-17 19:25:21 +0100201 print ' if (_glIsEnabled(GL_VERTEX_ATTRIB_ARRAY0_NV + index)) {'
José Fonseca5a568a92011-06-29 16:43:36 +0100202 print ' return true;'
José Fonseca1a2fdd22011-04-01 00:55:09 +0100203 print ' }'
204 print ' }'
205 print ' }'
206 print
207
José Fonseca8a6c6cb2011-03-23 16:44:30 +0000208 print ' return false;'
209 print '}'
210 print
José Fonseca669b1222011-02-20 09:05:10 +0000211
José Fonseca14cb9ef2012-05-17 21:33:14 +0100212 print 'static void _trace_user_arrays(GLuint count);'
José Fonseca14c21bc2011-02-20 23:32:22 +0000213 print
José Fonseca867b1b72011-04-24 11:58:04 +0100214
José Fonseca707630d2014-03-07 14:20:35 +0000215 print '// whether glLockArraysEXT() has ever been called'
216 print 'static bool _checkLockArraysEXT = false;'
217 print
218
José Fonseca9c536b02012-02-29 20:54:13 +0000219 # Buffer mappings
220 print '// whether glMapBufferRange(GL_MAP_WRITE_BIT) has ever been called'
José Fonseca632a78d2012-04-19 07:18:59 +0100221 print 'static bool _checkBufferMapRange = false;'
José Fonseca9c536b02012-02-29 20:54:13 +0000222 print
223 print '// whether glBufferParameteriAPPLE(GL_BUFFER_FLUSHING_UNMAP_APPLE, GL_FALSE) has ever been called'
José Fonseca632a78d2012-04-19 07:18:59 +0100224 print 'static bool _checkBufferFlushingUnmapAPPLE = false;'
José Fonseca9c536b02012-02-29 20:54:13 +0000225 print
José Fonseca867b1b72011-04-24 11:58:04 +0100226
José Fonsecaa3f89ae2011-04-26 08:50:32 +0100227 # Generate a helper function to determine whether a parameter name
228 # refers to a symbolic value or not
229 print 'static bool'
230 print 'is_symbolic_pname(GLenum pname) {'
José Fonseca06e85192011-10-16 14:15:36 +0100231 print ' switch (pname) {'
José Fonseca5ea91872011-05-04 09:41:55 +0100232 for function, type, count, name in glparams.parameters:
José Fonsecaa3f89ae2011-04-26 08:50:32 +0100233 if type is glapi.GLenum:
José Fonseca4c938c22011-04-30 22:44:38 +0100234 print ' case %s:' % name
235 print ' return true;'
236 print ' default:'
237 print ' return false;'
José Fonsecaa3f89ae2011-04-26 08:50:32 +0100238 print ' }'
239 print '}'
240 print
241
242 # Generate a helper function to determine whether a parameter value is
243 # potentially symbolic or not; i.e., if the value can be represented in
244 # an enum or not
245 print 'template<class T>'
246 print 'static inline bool'
247 print 'is_symbolic_param(T param) {'
248 print ' return static_cast<T>(static_cast<GLenum>(param)) == param;'
249 print '}'
250 print
José Fonseca4c938c22011-04-30 22:44:38 +0100251
252 # Generate a helper function to know how many elements a parameter has
253 print 'static size_t'
José Fonseca632a78d2012-04-19 07:18:59 +0100254 print '_gl_param_size(GLenum pname) {'
José Fonseca06e85192011-10-16 14:15:36 +0100255 print ' switch (pname) {'
José Fonseca5ea91872011-05-04 09:41:55 +0100256 for function, type, count, name in glparams.parameters:
José Fonseca4c938c22011-04-30 22:44:38 +0100257 if type is not None:
José Fonsecaddf6d2c2012-12-20 15:34:50 +0000258 print ' case %s: return %s;' % (name, count)
José Fonseca4c938c22011-04-30 22:44:38 +0100259 print ' default:'
José Fonseca559d5342011-10-27 08:10:56 +0100260 print r' os::log("apitrace: warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);'
José Fonseca4c938c22011-04-30 22:44:38 +0100261 print ' return 1;'
262 print ' }'
263 print '}'
264 print
265
Chia-I Wu335efb42011-11-03 01:59:22 +0800266 # states such as GL_UNPACK_ROW_LENGTH are not available in GLES
267 print 'static inline bool'
268 print 'can_unpack_subimage(void) {'
José Fonsecaf028a8f2012-02-15 23:33:35 +0000269 print ' gltrace::Context *ctx = gltrace::getContext();'
José Fonseca34ea6162015-01-08 23:45:43 +0000270 print ' return ctx->profile.desktop();'
Chia-I Wu335efb42011-11-03 01:59:22 +0800271 print '}'
272 print
273
José Fonseca631dbd12014-12-15 16:34:45 +0000274 # VMWX_map_buffer_debug
275 print r'extern "C" PUBLIC'
276 print r'void APIENTRY'
277 print r'glNotifyMappedBufferRangeVMWX(const void * start, GLsizeiptr length) {'
278 self.emit_memcpy('start', 'length')
279 print r'}'
280 print
281
José Fonseca1b6c8752012-04-15 14:33:00 +0100282 getProcAddressFunctionNames = []
283
284 def traceApi(self, api):
285 if self.getProcAddressFunctionNames:
286 # Generate a function to wrap proc addresses
287 getProcAddressFunction = api.getFunctionByName(self.getProcAddressFunctionNames[0])
288 argType = getProcAddressFunction.args[0].type
289 retType = getProcAddressFunction.type
290
291 print 'static %s _wrapProcAddress(%s procName, %s procPtr);' % (retType, argType, retType)
292 print
293
294 Tracer.traceApi(self, api)
295
296 print 'static %s _wrapProcAddress(%s procName, %s procPtr) {' % (retType, argType, retType)
Peter Lohrmann0b5b75e2013-06-03 14:58:41 -0700297
298 # Provide fallback functions to missing debug functions
José Fonseca1b6c8752012-04-15 14:33:00 +0100299 print ' if (!procPtr) {'
Peter Lohrmann0b5b75e2013-06-03 14:58:41 -0700300 else_ = ''
301 for function_name in self.debug_functions:
302 if self.api.getFunctionByName(function_name):
303 print ' %sif (strcmp("%s", (const char *)procName) == 0) {' % (else_, function_name)
304 print ' return (%s)&%s;' % (retType, function_name)
305 print ' }'
306 else_ = 'else '
307 print ' %s{' % else_
308 print ' return NULL;'
309 print ' }'
José Fonseca1b6c8752012-04-15 14:33:00 +0100310 print ' }'
Peter Lohrmann0b5b75e2013-06-03 14:58:41 -0700311
José Fonseca81301932012-11-11 00:10:20 +0000312 for function in api.getAllFunctions():
José Fonseca1b6c8752012-04-15 14:33:00 +0100313 ptype = function_pointer_type(function)
314 pvalue = function_pointer_value(function)
315 print ' if (strcmp("%s", (const char *)procName) == 0) {' % function.name
316 print ' %s = (%s)procPtr;' % (pvalue, ptype)
317 print ' return (%s)&%s;' % (retType, function.name,)
318 print ' }'
319 print ' os::log("apitrace: warning: unknown function \\"%s\\"\\n", (const char *)procName);'
320 print ' return procPtr;'
321 print '}'
322 print
323 else:
324 Tracer.traceApi(self, api)
325
Imre Deakd4937372012-04-24 14:06:48 +0300326 def defineShadowBufferHelper(self):
327 print 'void _shadow_glGetBufferSubData(GLenum target, GLintptr offset,'
328 print ' GLsizeiptr size, GLvoid *data)'
329 print '{'
José Fonsecaa33d0bb2012-11-10 09:11:42 +0000330 print ' gltrace::Context *ctx = gltrace::getContext();'
Imre Deakd4937372012-04-24 14:06:48 +0300331 print ' if (!ctx->needsShadowBuffers() || target != GL_ELEMENT_ARRAY_BUFFER) {'
José Fonseca219c9f22012-11-03 10:13:17 +0000332 print ' _glGetBufferSubData(target, offset, size, data);'
Imre Deakd4937372012-04-24 14:06:48 +0300333 print ' return;'
334 print ' }'
335 print
José Fonseca26be8f92014-03-07 14:08:50 +0000336 print ' GLint buffer_binding = _glGetInteger(GL_ELEMENT_ARRAY_BUFFER_BINDING);'
José Fonseca219c9f22012-11-03 10:13:17 +0000337 print ' if (buffer_binding > 0) {'
338 print ' gltrace::Buffer & buf = ctx->buffers[buffer_binding];'
339 print ' buf.getSubData(offset, size, data);'
340 print ' }'
Imre Deakd4937372012-04-24 14:06:48 +0300341 print '}'
342
José Fonseca219c9f22012-11-03 10:13:17 +0000343 def shadowBufferMethod(self, method):
344 # Emit code to fetch the shadow buffer, and invoke a method
345 print ' gltrace::Context *ctx = gltrace::getContext();'
346 print ' if (ctx->needsShadowBuffers() && target == GL_ELEMENT_ARRAY_BUFFER) {'
José Fonseca26be8f92014-03-07 14:08:50 +0000347 print ' GLint buffer_binding = _glGetInteger(GL_ELEMENT_ARRAY_BUFFER_BINDING);'
José Fonseca219c9f22012-11-03 10:13:17 +0000348 print ' if (buffer_binding > 0) {'
349 print ' gltrace::Buffer & buf = ctx->buffers[buffer_binding];'
350 print ' buf.' + method + ';'
351 print ' }'
352 print ' }'
353 print
354
Imre Deakd4937372012-04-24 14:06:48 +0300355 def shadowBufferProlog(self, function):
356 if function.name == 'glBufferData':
José Fonseca219c9f22012-11-03 10:13:17 +0000357 self.shadowBufferMethod('bufferData(size, data)')
Imre Deakd4937372012-04-24 14:06:48 +0300358
359 if function.name == 'glBufferSubData':
José Fonseca219c9f22012-11-03 10:13:17 +0000360 self.shadowBufferMethod('bufferSubData(offset, size, data)')
Imre Deakd4937372012-04-24 14:06:48 +0300361
362 if function.name == 'glDeleteBuffers':
363 print ' gltrace::Context *ctx = gltrace::getContext();'
364 print ' if (ctx->needsShadowBuffers()) {'
José Fonseca219c9f22012-11-03 10:13:17 +0000365 print ' for (GLsizei i = 0; i < n; i++) {'
366 print ' ctx->buffers.erase(buffer[i]);'
Imre Deakd4937372012-04-24 14:06:48 +0300367 print ' }'
368 print ' }'
369
José Fonseca99221832011-03-22 22:15:46 +0000370 array_pointer_function_names = set((
371 "glVertexPointer",
372 "glNormalPointer",
373 "glColorPointer",
374 "glIndexPointer",
375 "glTexCoordPointer",
376 "glEdgeFlagPointer",
377 "glFogCoordPointer",
378 "glSecondaryColorPointer",
José Fonseca7f5163e2011-03-31 23:37:26 +0100379
José Fonsecaac5285b2011-05-04 11:09:08 +0100380 "glInterleavedArrays",
381
José Fonseca7e0bfd92011-04-30 23:09:03 +0100382 "glVertexPointerEXT",
383 "glNormalPointerEXT",
384 "glColorPointerEXT",
385 "glIndexPointerEXT",
386 "glTexCoordPointerEXT",
387 "glEdgeFlagPointerEXT",
388 "glFogCoordPointerEXT",
389 "glSecondaryColorPointerEXT",
José Fonseca99221832011-03-22 22:15:46 +0000390
José Fonseca7f5163e2011-03-31 23:37:26 +0100391 "glVertexAttribPointer",
392 "glVertexAttribPointerARB",
393 "glVertexAttribPointerNV",
José Fonsecaac5285b2011-05-04 11:09:08 +0100394 "glVertexAttribIPointer",
395 "glVertexAttribIPointerEXT",
José Fonseca7f5163e2011-03-31 23:37:26 +0100396 "glVertexAttribLPointer",
397 "glVertexAttribLPointerEXT",
José Fonseca99221832011-03-22 22:15:46 +0000398
399 #"glMatrixIndexPointerARB",
400 ))
401
José Fonsecac5bf77a2014-08-14 16:10:02 +0100402 # XXX: We currently ignore the gl*Draw*ElementArray* functions
403 draw_function_regex = re.compile(r'^gl([A-Z][a-z]+)*Draw(Range)?(Arrays|Elements)([A-Z][a-zA-Z]*)?$' )
José Fonseca99221832011-03-22 22:15:46 +0000404
José Fonsecac9f12232011-03-25 20:07:42 +0000405 interleaved_formats = [
406 'GL_V2F',
407 'GL_V3F',
408 'GL_C4UB_V2F',
409 'GL_C4UB_V3F',
410 'GL_C3F_V3F',
411 'GL_N3F_V3F',
412 'GL_C4F_N3F_V3F',
413 'GL_T2F_V3F',
414 'GL_T4F_V4F',
415 'GL_T2F_C4UB_V3F',
416 'GL_T2F_C3F_V3F',
417 'GL_T2F_N3F_V3F',
418 'GL_T2F_C4F_N3F_V3F',
419 'GL_T4F_C4F_N3F_V4F',
420 ]
421
José Fonseca54f304a2012-01-14 19:33:08 +0000422 def traceFunctionImplBody(self, function):
José Fonseca8a6c6cb2011-03-23 16:44:30 +0000423 # Defer tracing of user array pointers...
José Fonseca99221832011-03-22 22:15:46 +0000424 if function.name in self.array_pointer_function_names:
José Fonseca26be8f92014-03-07 14:08:50 +0000425 print ' GLint _array_buffer = _glGetInteger(GL_ARRAY_BUFFER_BINDING);'
José Fonseca632a78d2012-04-19 07:18:59 +0100426 print ' if (!_array_buffer) {'
José Fonsecaf15546b2015-01-20 13:37:45 +0000427 print ' static bool warned = false;'
428 print ' if (!warned) {'
429 print ' warned = true;'
José Fonsecafe91ec32015-01-20 18:17:34 +0000430 print ' os::log("apitrace: warning: %s: call will be faked due to pointer to user memory (https://github.com/apitrace/apitrace/blob/master/docs/BUGS.markdown#tracing)\\n", __FUNCTION__);'
José Fonsecaf15546b2015-01-20 13:37:45 +0000431 print ' }'
José Fonsecaf028a8f2012-02-15 23:33:35 +0000432 print ' gltrace::Context *ctx = gltrace::getContext();'
Chia-I Wu8ef66972011-11-03 01:19:46 +0800433 print ' ctx->user_arrays = true;'
José Fonseca5a568a92011-06-29 16:43:36 +0100434 if function.name == "glVertexAttribPointerNV":
Chia-I Wu8ef66972011-11-03 01:19:46 +0800435 print ' ctx->user_arrays_nv = true;'
José Fonseca54f304a2012-01-14 19:33:08 +0000436 self.invokeFunction(function)
José Fonsecaac5285b2011-05-04 11:09:08 +0100437
438 # And also break down glInterleavedArrays into the individual calls
439 if function.name == 'glInterleavedArrays':
440 print
441
442 # Initialize the enable flags
443 for camelcase_name, uppercase_name in self.arrays:
José Fonseca632a78d2012-04-19 07:18:59 +0100444 flag_name = '_' + uppercase_name.lower()
José Fonsecaac5285b2011-05-04 11:09:08 +0100445 print ' GLboolean %s = GL_FALSE;' % flag_name
446 print
447
448 # Switch for the interleaved formats
449 print ' switch (format) {'
450 for format in self.interleaved_formats:
451 print ' case %s:' % format
452 for camelcase_name, uppercase_name in self.arrays:
José Fonseca632a78d2012-04-19 07:18:59 +0100453 flag_name = '_' + uppercase_name.lower()
José Fonsecaac5285b2011-05-04 11:09:08 +0100454 if format.find('_' + uppercase_name[0]) >= 0:
455 print ' %s = GL_TRUE;' % flag_name
456 print ' break;'
457 print ' default:'
458 print ' return;'
459 print ' }'
460 print
461
462 # Emit fake glEnableClientState/glDisableClientState flags
463 for camelcase_name, uppercase_name in self.arrays:
José Fonseca632a78d2012-04-19 07:18:59 +0100464 flag_name = '_' + uppercase_name.lower()
José Fonsecaac5285b2011-05-04 11:09:08 +0100465 enable_name = 'GL_%s_ARRAY' % uppercase_name
466
467 # Emit a fake function
468 print ' {'
José Fonseca632a78d2012-04-19 07:18:59 +0100469 print ' static const trace::FunctionSig &_sig = %s ? _glEnableClientState_sig : _glDisableClientState_sig;' % flag_name
José Fonseca7a5f23a2014-06-24 19:20:36 +0100470 print ' unsigned _call = trace::localWriter.beginEnter(&_sig, true);'
José Fonsecab4a3d142011-10-27 07:43:19 +0100471 print ' trace::localWriter.beginArg(0);'
José Fonseca54f304a2012-01-14 19:33:08 +0000472 self.serializeValue(glapi.GLenum, enable_name)
José Fonsecab4a3d142011-10-27 07:43:19 +0100473 print ' trace::localWriter.endArg();'
474 print ' trace::localWriter.endEnter();'
José Fonseca632a78d2012-04-19 07:18:59 +0100475 print ' trace::localWriter.beginLeave(_call);'
José Fonsecab4a3d142011-10-27 07:43:19 +0100476 print ' trace::localWriter.endLeave();'
José Fonsecaac5285b2011-05-04 11:09:08 +0100477 print ' }'
478
José Fonsecac629a8c2014-06-01 21:12:27 +0100479 # Warn about buggy glGet(GL_*ARRAY_SIZE) not returning GL_BGRA
480 buggyFunctions = {
481 'glColorPointer': ('glGetIntegerv', '', 'GL_COLOR_ARRAY_SIZE'),
482 'glSecondaryColorPointer': ('glGetIntegerv', '', 'GL_SECONDARY_COLOR_ARRAY_SIZE'),
483 'glVertexAttribPointer': ('glGetVertexAttribiv', 'index, ', 'GL_VERTEX_ATTRIB_ARRAY_SIZE'),
484 'glVertexAttribPointerARB': ('glGetVertexAttribivARB', 'index, ', 'GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB'),
485 }
486 if function.name in buggyFunctions:
487 getter, extraArg, pname = buggyFunctions[function.name]
488 print r' static bool _checked = false;'
489 print r' if (!_checked && size == GL_BGRA) {'
490 print r' GLint _size = 0;'
491 print r' _%s(%s%s, &_size);' % (getter, extraArg, pname)
492 print r' if (_size != GL_BGRA) {'
493 print r' os::log("apitrace: warning: %s(%s) does not return GL_BGRA; trace will be incorrect (https://github.com/apitrace/apitrace/issues/261)\n");' % (getter, pname)
494 print r' }'
495 print r' _checked = true;'
496 print r' }'
497
José Fonseca99221832011-03-22 22:15:46 +0000498 print ' return;'
499 print ' }'
José Fonseca14c21bc2011-02-20 23:32:22 +0000500
José Fonseca8a6c6cb2011-03-23 16:44:30 +0000501 # ... to the draw calls
José Fonsecac5bf77a2014-08-14 16:10:02 +0100502 if self.draw_function_regex.match(function.name):
José Fonseca632a78d2012-04-19 07:18:59 +0100503 print ' if (_need_user_arrays()) {'
José Fonseca246508e2014-08-14 16:07:46 +0100504 if 'Indirect' in function.name:
505 print r' os::log("apitrace: warning: %s: indirect user arrays not supported\n");' % (function.name,)
506 else:
507 arg_names = ', '.join([arg.name for arg in function.args[1:]])
508 print ' GLuint _count = _%s_count(%s);' % (function.name, arg_names)
509 # Some apps, in particular Quake3, can tell the driver to lock more
510 # vertices than those actually required for the draw call.
511 print ' if (_checkLockArraysEXT) {'
512 print ' GLuint _locked_count = _glGetInteger(GL_ARRAY_ELEMENT_LOCK_FIRST_EXT)'
513 print ' + _glGetInteger(GL_ARRAY_ELEMENT_LOCK_COUNT_EXT);'
514 print ' _count = std::max(_count, _locked_count);'
515 print ' }'
516 print ' _trace_user_arrays(_count);'
José Fonseca8a6c6cb2011-03-23 16:44:30 +0000517 print ' }'
José Fonseca707630d2014-03-07 14:20:35 +0000518 if function.name == 'glLockArraysEXT':
519 print ' _checkLockArraysEXT = true;'
José Fonseca4a7d8602014-06-18 16:03:44 +0100520
521 # Warn if user arrays are used with glBegin/glArrayElement/glEnd.
522 if function.name == 'glBegin':
José Fonseca7c39d012014-11-07 19:46:53 +0000523 print r' gltrace::Context *ctx = gltrace::getContext();'
524 print r' ctx->userArraysOnBegin = _need_user_arrays();'
525 if function.name.startswith('glArrayElement'):
526 print r' gltrace::Context *ctx = gltrace::getContext();'
527 print r' if (ctx->userArraysOnBegin) {'
José Fonseca4a7d8602014-06-18 16:03:44 +0100528 print r' os::log("apitrace: warning: user arrays with glArrayElement not supported (https://github.com/apitrace/apitrace/issues/276)\n");'
José Fonseca7c39d012014-11-07 19:46:53 +0000529 print r' ctx->userArraysOnBegin = false;'
José Fonseca4a7d8602014-06-18 16:03:44 +0100530 print r' }'
José Fonseca14c21bc2011-02-20 23:32:22 +0000531
José Fonseca73373602011-05-20 17:45:26 +0100532 # Emit a fake memcpy on buffer uploads
José Fonseca9c536b02012-02-29 20:54:13 +0000533 if function.name == 'glBufferParameteriAPPLE':
534 print ' if (pname == GL_BUFFER_FLUSHING_UNMAP_APPLE && param == GL_FALSE) {'
José Fonseca632a78d2012-04-19 07:18:59 +0100535 print ' _checkBufferFlushingUnmapAPPLE = true;'
José Fonseca9c536b02012-02-29 20:54:13 +0000536 print ' }'
José Fonsecacdc322c2012-02-29 19:29:51 +0000537 if function.name in ('glUnmapBuffer', 'glUnmapBufferARB'):
José Fonseca9c536b02012-02-29 20:54:13 +0000538 if function.name.endswith('ARB'):
539 suffix = 'ARB'
540 else:
541 suffix = ''
Jose Fonsecad2fb3402015-01-24 13:42:52 +0000542 print ' GLint access_flags = 0;'
José Fonseca9c536b02012-02-29 20:54:13 +0000543 print ' GLint access = 0;'
Jose Fonsecad2fb3402015-01-24 13:42:52 +0000544 print ' bool flush;'
545 print ' // GLES3 does not have GL_BUFFER_ACCESS;'
546 print ' if (_checkBufferMapRange) {'
547 print ' _glGetBufferParameteriv%s(target, GL_BUFFER_ACCESS_FLAGS, &access_flags);' % suffix
548 print ' flush = (access_flags & GL_MAP_WRITE_BIT) && !(access_flags & (GL_MAP_FLUSH_EXPLICIT_BIT | GL_MAP_PERSISTENT_BIT));'
549 print ' } else {'
550 print ' _glGetBufferParameteriv%s(target, GL_BUFFER_ACCESS, &access);' % suffix
551 print ' flush = access != GL_READ_ONLY;'
552 print ' }'
553 print ' if (flush) {'
José Fonseca9c536b02012-02-29 20:54:13 +0000554 print ' GLvoid *map = NULL;'
José Fonseca632a78d2012-04-19 07:18:59 +0100555 print ' _glGetBufferPointerv%s(target, GL_BUFFER_MAP_POINTER, &map);' % suffix
José Fonseca9c536b02012-02-29 20:54:13 +0000556 print ' if (map) {'
557 print ' GLint length = -1;'
José Fonseca632a78d2012-04-19 07:18:59 +0100558 print ' if (_checkBufferMapRange) {'
559 print ' _glGetBufferParameteriv%s(target, GL_BUFFER_MAP_LENGTH, &length);' % suffix
José Fonseca9c536b02012-02-29 20:54:13 +0000560 print ' if (length == -1) {'
José Fonsecacb07e2d2014-02-04 15:14:09 +0000561 print ' // Mesa drivers refuse GL_BUFFER_MAP_LENGTH without GL 3.0 up-to'
562 print ' // http://cgit.freedesktop.org/mesa/mesa/commit/?id=ffee498fb848b253a7833373fe5430f8c7ca0c5f'
José Fonsecadb1ccce2012-02-29 21:09:24 +0000563 print ' static bool warned = false;'
564 print ' if (!warned) {'
565 print ' os::log("apitrace: warning: glGetBufferParameteriv%s(GL_BUFFER_MAP_LENGTH) failed\\n");' % suffix
566 print ' warned = true;'
567 print ' }'
José Fonseca9c536b02012-02-29 20:54:13 +0000568 print ' }'
569 print ' } else {'
570 print ' length = 0;'
José Fonseca632a78d2012-04-19 07:18:59 +0100571 print ' _glGetBufferParameteriv%s(target, GL_BUFFER_SIZE, &length);' % suffix
José Fonseca9c536b02012-02-29 20:54:13 +0000572 print ' }'
José Fonseca632a78d2012-04-19 07:18:59 +0100573 print ' if (_checkBufferFlushingUnmapAPPLE) {'
José Fonseca9c536b02012-02-29 20:54:13 +0000574 print ' GLint flushing_unmap = GL_TRUE;'
José Fonseca632a78d2012-04-19 07:18:59 +0100575 print ' _glGetBufferParameteriv%s(target, GL_BUFFER_FLUSHING_UNMAP_APPLE, &flushing_unmap);' % suffix
José Fonseca9c536b02012-02-29 20:54:13 +0000576 print ' flush = flush && flushing_unmap;'
577 print ' }'
578 print ' if (flush && length > 0) {'
José Fonseca6f0e3032014-06-25 01:00:35 +0100579 self.emit_memcpy('map', 'length')
José Fonseca9c536b02012-02-29 20:54:13 +0000580 print ' }'
581 print ' }'
582 print ' }'
José Fonsecacdc322c2012-02-29 19:29:51 +0000583 if function.name == 'glUnmapBufferOES':
Jose Fonsecad2fb3402015-01-24 13:42:52 +0000584 print ' GLint access_flags = 0;'
José Fonsecacdc322c2012-02-29 19:29:51 +0000585 print ' GLint access = 0;'
Jose Fonsecad2fb3402015-01-24 13:42:52 +0000586 print ' bool flush;'
587 print ' // GLES3 does not have GL_BUFFER_ACCESS;'
588 print ' if (_checkBufferMapRange) {'
589 print ' _glGetBufferParameteriv(target, GL_BUFFER_ACCESS_FLAGS, &access_flags);'
590 print ' flush = (access_flags & GL_MAP_WRITE_BIT) && !(access_flags & (GL_MAP_FLUSH_EXPLICIT_BIT | GL_MAP_PERSISTENT_BIT));'
591 print ' } else {'
592 print ' _glGetBufferParameteriv(target, GL_BUFFER_ACCESS, &access);'
593 print ' flush = access != GL_READ_ONLY;'
594 print ' }'
595 print ' if (flush) {'
José Fonsecacdc322c2012-02-29 19:29:51 +0000596 print ' GLvoid *map = NULL;'
Jose Fonsecad2fb3402015-01-24 13:42:52 +0000597 print ' _glGetBufferPointervOES(target, GL_BUFFER_MAP_POINTER, &map);'
598 print ' if (map) {'
599 print ' GLint length = 0;'
600 print ' GLint offset = 0;'
601 print ' if (_checkBufferMapRange) {'
602 print ' _glGetBufferParameteriv(target, GL_BUFFER_MAP_LENGTH, &length);'
603 print ' _glGetBufferParameteriv(target, GL_BUFFER_MAP_OFFSET, &offset);'
604 print ' } else {'
605 print ' _glGetBufferParameteriv(target, GL_BUFFER_SIZE, &length);'
606 print ' }'
607 print ' if (flush && length > 0) {'
608 self.emit_memcpy('map', 'length')
609 self.shadowBufferMethod('bufferSubData(offset, length, map)')
610 print ' }'
José Fonsecacdc322c2012-02-29 19:29:51 +0000611 print ' }'
José Fonseca867b1b72011-04-24 11:58:04 +0100612 print ' }'
José Fonseca4920c302014-08-13 18:35:57 +0100613 if function.name == 'glUnmapNamedBuffer':
614 print ' GLint access_flags = 0;'
615 print ' _glGetNamedBufferParameteriv(buffer, GL_BUFFER_ACCESS_FLAGS, &access_flags);'
José Fonsecaa4210e22014-12-13 15:49:37 +0000616 print ' if ((access_flags & GL_MAP_WRITE_BIT) &&'
617 print ' !(access_flags & (GL_MAP_FLUSH_EXPLICIT_BIT | GL_MAP_PERSISTENT_BIT))) {'
José Fonseca4920c302014-08-13 18:35:57 +0100618 print ' GLvoid *map = NULL;'
619 print ' _glGetNamedBufferPointerv(buffer, GL_BUFFER_MAP_POINTER, &map);'
620 print ' GLint length = 0;'
621 print ' _glGetNamedBufferParameteriv(buffer, GL_BUFFER_MAP_LENGTH, &length);'
622 print ' if (map && length > 0) {'
623 self.emit_memcpy('map', 'length')
624 print ' }'
625 print ' }'
José Fonsecafb3bd602012-01-15 13:56:28 +0000626 if function.name == 'glUnmapNamedBufferEXT':
José Fonseca024aff42012-02-29 18:00:06 +0000627 print ' GLint access_flags = 0;'
José Fonseca632a78d2012-04-19 07:18:59 +0100628 print ' _glGetNamedBufferParameterivEXT(buffer, GL_BUFFER_ACCESS_FLAGS, &access_flags);'
José Fonsecaa4210e22014-12-13 15:49:37 +0000629 print ' if ((access_flags & GL_MAP_WRITE_BIT) &&'
630 print ' !(access_flags & (GL_MAP_FLUSH_EXPLICIT_BIT | GL_MAP_PERSISTENT_BIT))) {'
José Fonsecafb3bd602012-01-15 13:56:28 +0000631 print ' GLvoid *map = NULL;'
José Fonseca632a78d2012-04-19 07:18:59 +0100632 print ' _glGetNamedBufferPointervEXT(buffer, GL_BUFFER_MAP_POINTER, &map);'
José Fonsecafb3bd602012-01-15 13:56:28 +0000633 print ' GLint length = 0;'
José Fonseca632a78d2012-04-19 07:18:59 +0100634 print ' _glGetNamedBufferParameterivEXT(buffer, GL_BUFFER_MAP_LENGTH, &length);'
José Fonseca024aff42012-02-29 18:00:06 +0000635 print ' if (map && length > 0) {'
José Fonseca6f0e3032014-06-25 01:00:35 +0100636 self.emit_memcpy('map', 'length')
José Fonseca024aff42012-02-29 18:00:06 +0000637 print ' }'
José Fonsecafb3bd602012-01-15 13:56:28 +0000638 print ' }'
José Fonseca77ef0ce2012-02-29 18:08:48 +0000639 if function.name == 'glFlushMappedBufferRange':
640 print ' GLvoid *map = NULL;'
José Fonseca632a78d2012-04-19 07:18:59 +0100641 print ' _glGetBufferPointerv(target, GL_BUFFER_MAP_POINTER, &map);'
José Fonseca77ef0ce2012-02-29 18:08:48 +0000642 print ' if (map && length > 0) {'
José Fonseca6f0e3032014-06-25 01:00:35 +0100643 self.emit_memcpy('(const char *)map + offset', 'length')
José Fonseca77ef0ce2012-02-29 18:08:48 +0000644 print ' }'
Jose Fonsecad2fb3402015-01-24 13:42:52 +0000645 if function.name == 'glFlushMappedBufferRangeEXT':
646 print ' GLvoid *map = NULL;'
647 print ' _glGetBufferPointervOES(target, GL_BUFFER_MAP_POINTER_OES, &map);'
648 print ' if (map && length > 0) {'
649 self.emit_memcpy('(const char *)map + offset', 'length')
650 print ' }'
José Fonseca77ef0ce2012-02-29 18:08:48 +0000651 if function.name == 'glFlushMappedBufferRangeAPPLE':
652 print ' GLvoid *map = NULL;'
José Fonseca632a78d2012-04-19 07:18:59 +0100653 print ' _glGetBufferPointerv(target, GL_BUFFER_MAP_POINTER, &map);'
José Fonseca77ef0ce2012-02-29 18:08:48 +0000654 print ' if (map && size > 0) {'
José Fonseca6f0e3032014-06-25 01:00:35 +0100655 self.emit_memcpy('(const char *)map + offset', 'size')
José Fonseca73373602011-05-20 17:45:26 +0100656 print ' }'
José Fonseca4920c302014-08-13 18:35:57 +0100657 if function.name == 'glFlushMappedNamedBufferRange':
658 print ' GLvoid *map = NULL;'
659 print ' _glGetNamedBufferPointerv(buffer, GL_BUFFER_MAP_POINTER, &map);'
660 print ' if (map && length > 0) {'
661 self.emit_memcpy('(const char *)map + offset', 'length')
662 print ' }'
José Fonsecafb3bd602012-01-15 13:56:28 +0000663 if function.name == 'glFlushMappedNamedBufferRangeEXT':
664 print ' GLvoid *map = NULL;'
José Fonseca632a78d2012-04-19 07:18:59 +0100665 print ' _glGetNamedBufferPointervEXT(buffer, GL_BUFFER_MAP_POINTER, &map);'
José Fonseca024aff42012-02-29 18:00:06 +0000666 print ' if (map && length > 0) {'
José Fonseca6f0e3032014-06-25 01:00:35 +0100667 self.emit_memcpy('(const char *)map + offset', 'length')
José Fonsecafb3bd602012-01-15 13:56:28 +0000668 print ' }'
José Fonseca867b1b72011-04-24 11:58:04 +0100669
José Fonseca3522cbd2014-02-28 14:45:32 +0000670 # FIXME: We don't support coherent/pinned memory mappings
José Fonseca631dbd12014-12-15 16:34:45 +0000671 if function.name in ('glBufferStorage', 'glNamedBufferStorage', 'glNamedBufferStorageEXT'):
672 print r' if (!(flags & GL_MAP_PERSISTENT_BIT)) {'
673 print r' os::log("apitrace: warning: %s: MAP_NOTIFY_EXPLICIT_BIT_VMWX set w/o MAP_PERSISTENT_BIT\n", __FUNCTION__);'
674 print r' }'
675 print r' flags &= ~GL_MAP_NOTIFY_EXPLICIT_BIT_VMWX;'
Jose Fonsecad2fb3402015-01-24 13:42:52 +0000676 if function.name in ('glMapBufferRange', 'glMapBufferRangeEXT', 'glMapNamedBufferRange', 'glMapNamedBufferRangeEXT'):
José Fonseca631dbd12014-12-15 16:34:45 +0000677 print r' if (access & GL_MAP_NOTIFY_EXPLICIT_BIT_VMWX) {'
678 print r' if (!(access & GL_MAP_PERSISTENT_BIT)) {'
679 print r' os::log("apitrace: warning: %s: MAP_NOTIFY_EXPLICIT_BIT_VMWX set w/o MAP_PERSISTENT_BIT\n", __FUNCTION__);'
680 print r' }'
681 print r' if (access & GL_MAP_FLUSH_EXPLICIT_BIT) {'
682 print r' os::log("apitrace: warning: %s: MAP_NOTIFY_EXPLICIT_BIT_VMWX set w/ MAP_FLUSH_EXPLICIT_BIT\n", __FUNCTION__);'
683 print r' }'
684 print r' access &= ~GL_MAP_NOTIFY_EXPLICIT_BIT_VMWX;'
685 print r' } else if (access & GL_MAP_COHERENT_BIT) {'
José Fonsecaa4210e22014-12-13 15:49:37 +0000686 print r' os::log("apitrace: warning: %s: MAP_COHERENT_BIT unsupported (https://github.com/apitrace/apitrace/issues/232)\n", __FUNCTION__);'
687 print r' } else if ((access & GL_MAP_PERSISTENT_BIT) &&'
688 print r' !(access & GL_MAP_FLUSH_EXPLICIT_BIT)) {'
689 print r' os::log("apitrace: warning: %s: MAP_PERSISTENT_BIT w/o FLUSH_EXPLICIT_BIT unsupported (https://github.com/apitrace/apitrace/issues/232)\n", __FUNCTION__);'
José Fonseca3522cbd2014-02-28 14:45:32 +0000690 print r' }'
691 if function.name in ('glBufferData', 'glBufferDataARB'):
692 print r' if (target == GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD) {'
693 print r' os::log("apitrace: warning: GL_AMD_pinned_memory not fully supported\n");'
694 print r' }'
695
José Fonsecad0f1e292014-11-13 13:21:51 +0000696 # TODO: We don't track GL_INTEL_map_texture mappings
697 if function.name == 'glMapTexture2DINTEL':
698 print r' if (access & GL_MAP_WRITE_BIT) {'
699 print r' os::log("apitrace: warning: GL_INTEL_map_texture not fully supported\n");'
700 print r' }'
701
José Fonseca91492d22011-05-23 21:20:31 +0100702 # Don't leave vertex attrib locations to chance. Instead emit fake
703 # glBindAttribLocation calls to ensure that the same locations will be
704 # used when retracing. Trying to remap locations after the fact would
705 # be an herculian task given that vertex attrib locations appear in
706 # many entry-points, including non-shader related ones.
707 if function.name == 'glLinkProgram':
José Fonseca54f304a2012-01-14 19:33:08 +0000708 Tracer.invokeFunction(self, function)
José Fonseca91492d22011-05-23 21:20:31 +0100709 print ' GLint active_attributes = 0;'
José Fonseca632a78d2012-04-19 07:18:59 +0100710 print ' _glGetProgramiv(program, GL_ACTIVE_ATTRIBUTES, &active_attributes);'
José Fonseca7525e6f2011-09-28 09:04:56 +0100711 print ' for (GLint attrib = 0; attrib < active_attributes; ++attrib) {'
José Fonseca91492d22011-05-23 21:20:31 +0100712 print ' GLint size = 0;'
713 print ' GLenum type = 0;'
714 print ' GLchar name[256];'
715 # TODO: Use ACTIVE_ATTRIBUTE_MAX_LENGTH instead of 256
José Fonseca632a78d2012-04-19 07:18:59 +0100716 print ' _glGetActiveAttrib(program, attrib, sizeof name, NULL, &size, &type, name);'
José Fonseca2a794f52011-05-26 20:54:29 +0100717 print " if (name[0] != 'g' || name[1] != 'l' || name[2] != '_') {"
José Fonseca632a78d2012-04-19 07:18:59 +0100718 print ' GLint location = _glGetAttribLocation(program, name);'
José Fonseca2a794f52011-05-26 20:54:29 +0100719 print ' if (location >= 0) {'
José Fonseca1b6c8752012-04-15 14:33:00 +0100720 bind_function = glapi.glapi.getFunctionByName('glBindAttribLocation')
José Fonseca91492d22011-05-23 21:20:31 +0100721 self.fake_call(bind_function, ['program', 'location', 'name'])
José Fonseca2a794f52011-05-26 20:54:29 +0100722 print ' }'
José Fonseca91492d22011-05-23 21:20:31 +0100723 print ' }'
724 print ' }'
725 if function.name == 'glLinkProgramARB':
José Fonseca54f304a2012-01-14 19:33:08 +0000726 Tracer.invokeFunction(self, function)
José Fonseca91492d22011-05-23 21:20:31 +0100727 print ' GLint active_attributes = 0;'
José Fonseca632a78d2012-04-19 07:18:59 +0100728 print ' _glGetObjectParameterivARB(programObj, GL_OBJECT_ACTIVE_ATTRIBUTES_ARB, &active_attributes);'
José Fonseca7525e6f2011-09-28 09:04:56 +0100729 print ' for (GLint attrib = 0; attrib < active_attributes; ++attrib) {'
José Fonseca91492d22011-05-23 21:20:31 +0100730 print ' GLint size = 0;'
731 print ' GLenum type = 0;'
732 print ' GLcharARB name[256];'
733 # TODO: Use ACTIVE_ATTRIBUTE_MAX_LENGTH instead of 256
José Fonseca632a78d2012-04-19 07:18:59 +0100734 print ' _glGetActiveAttribARB(programObj, attrib, sizeof name, NULL, &size, &type, name);'
José Fonseca2a794f52011-05-26 20:54:29 +0100735 print " if (name[0] != 'g' || name[1] != 'l' || name[2] != '_') {"
José Fonseca632a78d2012-04-19 07:18:59 +0100736 print ' GLint location = _glGetAttribLocationARB(programObj, name);'
José Fonseca2a794f52011-05-26 20:54:29 +0100737 print ' if (location >= 0) {'
José Fonseca1b6c8752012-04-15 14:33:00 +0100738 bind_function = glapi.glapi.getFunctionByName('glBindAttribLocationARB')
José Fonseca91492d22011-05-23 21:20:31 +0100739 self.fake_call(bind_function, ['programObj', 'location', 'name'])
José Fonseca2a794f52011-05-26 20:54:29 +0100740 print ' }'
José Fonseca91492d22011-05-23 21:20:31 +0100741 print ' }'
742 print ' }'
743
Imre Deakd4937372012-04-24 14:06:48 +0300744 self.shadowBufferProlog(function)
745
José Fonseca54f304a2012-01-14 19:33:08 +0000746 Tracer.traceFunctionImplBody(self, function)
José Fonseca73373602011-05-20 17:45:26 +0100747
Peter Lohrmann0b5b75e2013-06-03 14:58:41 -0700748 # These entrypoints are only expected to be implemented by tools;
749 # drivers will probably not implement them.
José Fonsecaf028a8f2012-02-15 23:33:35 +0000750 marker_functions = [
751 # GL_GREMEDY_string_marker
José Fonseca8f34d342011-07-15 20:16:40 +0100752 'glStringMarkerGREMEDY',
José Fonsecaf028a8f2012-02-15 23:33:35 +0000753 # GL_GREMEDY_frame_terminator
José Fonseca8f34d342011-07-15 20:16:40 +0100754 'glFrameTerminatorGREMEDY',
755 ]
756
Peter Lohrmann0b5b75e2013-06-03 14:58:41 -0700757 # These entrypoints may be implemented by drivers, but are also very useful
758 # for debugging / analysis tools.
759 debug_functions = [
760 # GL_KHR_debug
761 'glDebugMessageControl',
762 'glDebugMessageInsert',
763 'glDebugMessageCallback',
764 'glGetDebugMessageLog',
765 'glPushDebugGroup',
766 'glPopDebugGroup',
767 'glObjectLabel',
768 'glGetObjectLabel',
769 'glObjectPtrLabel',
770 'glGetObjectPtrLabel',
Jose Fonsecae01aa3b2015-06-27 11:07:05 +0100771 # GL_KHR_debug (for OpenGL ES)
772 'glDebugMessageControlKHR',
773 'glDebugMessageInsertKHR',
774 'glDebugMessageCallbackKHR',
775 'glGetDebugMessageLogKHR',
776 'glPushDebugGroupKHR',
777 'glPopDebugGroupKHR',
778 'glObjectLabelKHR',
779 'glGetObjectLabelKHR',
780 'glObjectPtrLabelKHR',
781 'glGetObjectPtrLabelKHR',
Peter Lohrmann0b5b75e2013-06-03 14:58:41 -0700782 # GL_ARB_debug_output
783 'glDebugMessageControlARB',
784 'glDebugMessageInsertARB',
785 'glDebugMessageCallbackARB',
786 'glGetDebugMessageLogARB',
787 # GL_AMD_debug_output
788 'glDebugMessageEnableAMD',
789 'glDebugMessageInsertAMD',
790 'glDebugMessageCallbackAMD',
791 'glGetDebugMessageLogAMD',
José Fonseca71f5a352014-07-28 12:19:50 +0100792 # GL_EXT_debug_label
793 'glLabelObjectEXT',
794 'glGetObjectLabelEXT',
795 # GL_EXT_debug_marker
796 'glInsertEventMarkerEXT',
797 'glPushGroupMarkerEXT',
798 'glPopGroupMarkerEXT',
Peter Lohrmann0b5b75e2013-06-03 14:58:41 -0700799 ]
800
José Fonseca54f304a2012-01-14 19:33:08 +0000801 def invokeFunction(self, function):
José Fonseca91492d22011-05-23 21:20:31 +0100802 if function.name in ('glLinkProgram', 'glLinkProgramARB'):
803 # These functions have been dispatched already
804 return
805
José Fonsecae0c55fd2015-01-26 22:46:13 +0000806 # Force glProgramBinary to fail. Per ARB_get_program_binary this
807 # should signal the app that it needs to recompile.
808 if function.name in ('glProgramBinary', 'glProgramBinaryOES'):
809 print r' binaryFormat = 0xDEADDEAD;'
810 print r' binary = &binaryFormat;'
811 print r' length = sizeof binaryFormat;'
812
José Fonseca2cfa02c2013-06-10 08:05:29 +0100813 Tracer.invokeFunction(self, function)
814
815 def doInvokeFunction(self, function):
816 # Same as invokeFunction() but called both when trace is enabled or disabled.
817 #
818 # Used to modify the behavior of GL entry-points.
819
820 # Override GL extensions
821 if function.name in ('glGetString', 'glGetIntegerv', 'glGetStringi'):
822 Tracer.doInvokeFunction(self, function, prefix = 'gltrace::_', suffix = '_override')
823 return
824
José Fonseca71f5a352014-07-28 12:19:50 +0100825 # We implement GL_GREMEDY_*, etc., and not the driver
José Fonsecaf028a8f2012-02-15 23:33:35 +0000826 if function.name in self.marker_functions:
José Fonseca8f34d342011-07-15 20:16:40 +0100827 return
828
Peter Lohrmann9d9eb812013-07-12 16:15:25 -0400829 # We may be faking KHR_debug, so ensure the pointer queries result is
830 # always zeroed to prevent dereference of unitialized pointers
831 if function.name == 'glGetPointerv':
832 print ' if (params &&'
833 print ' (pname == GL_DEBUG_CALLBACK_FUNCTION ||'
834 print ' pname == GL_DEBUG_CALLBACK_USER_PARAM)) {'
835 print ' *params = NULL;'
836 print ' }'
837
José Fonseca2cfa02c2013-06-10 08:05:29 +0100838 if function.name in self.getProcAddressFunctionNames:
José Fonseca631dbd12014-12-15 16:34:45 +0000839 nameArg = function.args[0].name
840 print ' if (strcmp("glNotifyMappedBufferRangeVMWX", (const char *)%s) == 0) {' % (nameArg,)
841 print ' _result = (%s)&glNotifyMappedBufferRangeVMWX;' % (function.type,)
José Fonsecaf028a8f2012-02-15 23:33:35 +0000842 for marker_function in self.marker_functions:
José Fonseca1b6c8752012-04-15 14:33:00 +0100843 if self.api.getFunctionByName(marker_function):
José Fonseca631dbd12014-12-15 16:34:45 +0000844 print ' } else if (strcmp("%s", (const char *)%s) == 0) {' % (marker_function, nameArg)
José Fonseca632a78d2012-04-19 07:18:59 +0100845 print ' _result = (%s)&%s;' % (function.type, marker_function)
José Fonseca631dbd12014-12-15 16:34:45 +0000846 print ' } else {'
José Fonseca2cfa02c2013-06-10 08:05:29 +0100847 Tracer.doInvokeFunction(self, function)
848
849 # Replace function addresses with ours
850 # XXX: Doing this here instead of wrapRet means that the trace will
851 # contain the addresses of the wrapper functions, and not the real
852 # functions, but in practice this should make no difference.
853 if function.name in self.getProcAddressFunctionNames:
José Fonseca631dbd12014-12-15 16:34:45 +0000854 print ' _result = _wrapProcAddress(%s, _result);' % (nameArg,)
José Fonseca2cfa02c2013-06-10 08:05:29 +0100855
José Fonseca8f34d342011-07-15 20:16:40 +0100856 print ' }'
José Fonseca1b3d3752011-07-15 10:15:19 +0100857 return
858
José Fonsecae0c55fd2015-01-26 22:46:13 +0000859 if function.name in ('glGetProgramBinary', 'glGetProgramBinaryOES'):
860 print r' bufSize = 0;'
861
José Fonseca2cfa02c2013-06-10 08:05:29 +0100862 Tracer.doInvokeFunction(self, function)
José Fonseca91492d22011-05-23 21:20:31 +0100863
José Fonsecae0c55fd2015-01-26 22:46:13 +0000864 if function.name == 'glGetProgramiv':
865 print r' if (params && pname == GL_PROGRAM_BINARY_LENGTH) {'
866 print r' *params = 0;'
867 print r' }'
868 if function.name in ('glGetProgramBinary', 'glGetProgramBinaryOES'):
869 print r' if (length) {'
870 print r' *length = 0;'
871 print r' }'
872
José Fonseca867b1b72011-04-24 11:58:04 +0100873 buffer_targets = [
874 'ARRAY_BUFFER',
875 'ELEMENT_ARRAY_BUFFER',
876 'PIXEL_PACK_BUFFER',
877 'PIXEL_UNPACK_BUFFER',
José Fonseca7b20d672012-01-10 19:13:58 +0000878 'UNIFORM_BUFFER',
879 'TEXTURE_BUFFER',
880 'TRANSFORM_FEEDBACK_BUFFER',
881 'COPY_READ_BUFFER',
882 'COPY_WRITE_BUFFER',
883 'DRAW_INDIRECT_BUFFER',
884 'ATOMIC_COUNTER_BUFFER',
José Fonseca867b1b72011-04-24 11:58:04 +0100885 ]
886
José Fonseca54f304a2012-01-14 19:33:08 +0000887 def wrapRet(self, function, instance):
888 Tracer.wrapRet(self, function, instance)
José Fonseca1b3d3752011-07-15 10:15:19 +0100889
José Fonsecacdc322c2012-02-29 19:29:51 +0000890 # Keep track of buffer mappings
Jose Fonsecad2fb3402015-01-24 13:42:52 +0000891 if function.name in ('glMapBufferRange', 'glMapBufferRangeEXT'):
José Fonseca9c536b02012-02-29 20:54:13 +0000892 print ' if (access & GL_MAP_WRITE_BIT) {'
José Fonseca632a78d2012-04-19 07:18:59 +0100893 print ' _checkBufferMapRange = true;'
José Fonseca9c536b02012-02-29 20:54:13 +0000894 print ' }'
José Fonseca669b1222011-02-20 09:05:10 +0000895
José Fonsecac9f12232011-03-25 20:07:42 +0000896 boolean_names = [
897 'GL_FALSE',
898 'GL_TRUE',
899 ]
900
901 def gl_boolean(self, value):
902 return self.boolean_names[int(bool(value))]
903
José Fonsecaa442a462014-11-12 21:16:22 +0000904 # Regular expression for the names of the functions that unpack from a
905 # pixel buffer object. See the ARB_pixel_buffer_object specification.
906 unpack_function_regex = re.compile(r'^gl(' + r'|'.join([
907 r'Bitmap',
908 r'PolygonStipple',
909 r'PixelMap[a-z]+v',
910 r'DrawPixels',
911 r'Color(Sub)?Table',
912 r'(Convolution|Separable)Filter[12]D',
913 r'(Compressed)?(Multi)?Tex(ture)?(Sub)?Image[1-4]D',
914 ]) + r')[0-9A-Z]*$')
José Fonsecae97bab92011-06-02 23:15:11 +0100915
José Fonseca54f304a2012-01-14 19:33:08 +0000916 def serializeArgValue(self, function, arg):
José Fonsecae97bab92011-06-02 23:15:11 +0100917 # Recognize offsets instead of blobs when a PBO is bound
José Fonsecaa442a462014-11-12 21:16:22 +0000918 if self.unpack_function_regex.match(function.name) \
José Fonsecae97bab92011-06-02 23:15:11 +0100919 and (isinstance(arg.type, stdapi.Blob) \
920 or (isinstance(arg.type, stdapi.Const) \
921 and isinstance(arg.type.type, stdapi.Blob))):
José Fonsecac29f4f12011-06-11 12:19:05 +0100922 print ' {'
José Fonsecaf028a8f2012-02-15 23:33:35 +0000923 print ' gltrace::Context *ctx = gltrace::getContext();'
José Fonseca632a78d2012-04-19 07:18:59 +0100924 print ' GLint _unpack_buffer = 0;'
José Fonseca34ea6162015-01-08 23:45:43 +0000925 print ' if (ctx->profile.desktop())'
José Fonseca632a78d2012-04-19 07:18:59 +0100926 print ' _glGetIntegerv(GL_PIXEL_UNPACK_BUFFER_BINDING, &_unpack_buffer);'
927 print ' if (_unpack_buffer) {'
José Fonsecad559f022012-04-15 16:13:51 +0100928 print ' trace::localWriter.writePointer((uintptr_t)%s);' % arg.name
José Fonsecac29f4f12011-06-11 12:19:05 +0100929 print ' } else {'
José Fonseca54f304a2012-01-14 19:33:08 +0000930 Tracer.serializeArgValue(self, function, arg)
José Fonsecac29f4f12011-06-11 12:19:05 +0100931 print ' }'
José Fonsecae97bab92011-06-02 23:15:11 +0100932 print ' }'
933 return
934
José Fonsecaa3f89ae2011-04-26 08:50:32 +0100935 # Several GL state functions take GLenum symbolic names as
936 # integer/floats; so dump the symbolic name whenever possible
José Fonseca3bcb33c2011-05-27 20:14:31 +0100937 if function.name.startswith('gl') \
José Fonsecae3571092011-10-13 08:26:27 +0100938 and arg.type in (glapi.GLint, glapi.GLfloat, glapi.GLdouble) \
José Fonseca3bcb33c2011-05-27 20:14:31 +0100939 and arg.name == 'param':
José Fonsecaa3f89ae2011-04-26 08:50:32 +0100940 assert arg.index > 0
941 assert function.args[arg.index - 1].name == 'pname'
942 assert function.args[arg.index - 1].type == glapi.GLenum
943 print ' if (is_symbolic_pname(pname) && is_symbolic_param(%s)) {' % arg.name
José Fonseca54f304a2012-01-14 19:33:08 +0000944 self.serializeValue(glapi.GLenum, arg.name)
José Fonsecaa3f89ae2011-04-26 08:50:32 +0100945 print ' } else {'
José Fonseca54f304a2012-01-14 19:33:08 +0000946 Tracer.serializeArgValue(self, function, arg)
José Fonsecaa3f89ae2011-04-26 08:50:32 +0100947 print ' }'
948 return
949
José Fonseca54f304a2012-01-14 19:33:08 +0000950 Tracer.serializeArgValue(self, function, arg)
José Fonseca99221832011-03-22 22:15:46 +0000951
José Fonseca4c938c22011-04-30 22:44:38 +0100952 def footer(self, api):
953 Tracer.footer(self, api)
José Fonseca669b1222011-02-20 09:05:10 +0000954
José Fonseca4c938c22011-04-30 22:44:38 +0100955 # A simple state tracker to track the pointer values
José Fonseca669b1222011-02-20 09:05:10 +0000956 # update the state
José Fonseca14cb9ef2012-05-17 21:33:14 +0100957 print 'static void _trace_user_arrays(GLuint count)'
José Fonseca669b1222011-02-20 09:05:10 +0000958 print '{'
José Fonsecaf028a8f2012-02-15 23:33:35 +0000959 print ' gltrace::Context *ctx = gltrace::getContext();'
José Fonseca8d1408b2014-02-03 19:57:18 +0000960 print
José Fonsecab0c59722015-01-05 20:45:41 +0000961 print ' glprofile::Profile profile = ctx->profile;'
962 print ' bool es1 = profile.es() && profile.major == 1;'
963 print
José Fonseca8d1408b2014-02-03 19:57:18 +0000964
965 # Temporarily unbind the array buffer
José Fonseca26be8f92014-03-07 14:08:50 +0000966 print ' GLint _array_buffer = _glGetInteger(GL_ARRAY_BUFFER_BINDING);'
José Fonseca8d1408b2014-02-03 19:57:18 +0000967 print ' if (_array_buffer) {'
968 self.fake_glBindBuffer(api, 'GL_ARRAY_BUFFER', '0')
969 print ' }'
970 print
José Fonseca1a2fdd22011-04-01 00:55:09 +0100971
José Fonseca99221832011-03-22 22:15:46 +0000972 for camelcase_name, uppercase_name in self.arrays:
Chia-I Wub3d218d2011-11-03 01:37:36 +0800973 # in which profile is the array available?
José Fonseca34ea6162015-01-08 23:45:43 +0000974 profile_check = 'profile.desktop()'
Chia-I Wub3d218d2011-11-03 01:37:36 +0800975 if camelcase_name in self.arrays_es1:
José Fonsecab0c59722015-01-05 20:45:41 +0000976 profile_check = '(' + profile_check + ' || es1)';
Chia-I Wub3d218d2011-11-03 01:37:36 +0800977
José Fonseca99221832011-03-22 22:15:46 +0000978 function_name = 'gl%sPointer' % camelcase_name
979 enable_name = 'GL_%s_ARRAY' % uppercase_name
980 binding_name = 'GL_%s_ARRAY_BUFFER_BINDING' % uppercase_name
José Fonseca1b6c8752012-04-15 14:33:00 +0100981 function = api.getFunctionByName(function_name)
José Fonseca99221832011-03-22 22:15:46 +0000982
José Fonseca06e85192011-10-16 14:15:36 +0100983 print ' // %s' % function.prototype()
Chia-I Wub3d218d2011-11-03 01:37:36 +0800984 print ' if (%s) {' % profile_check
José Fonsecafb6744f2011-04-15 11:18:37 +0100985 self.array_trace_prolog(api, uppercase_name)
986 self.array_prolog(api, uppercase_name)
José Fonseca632a78d2012-04-19 07:18:59 +0100987 print ' if (_glIsEnabled(%s)) {' % enable_name
José Fonseca26be8f92014-03-07 14:08:50 +0000988 print ' GLint _binding = _glGetInteger(%s);' % binding_name
José Fonseca632a78d2012-04-19 07:18:59 +0100989 print ' if (!_binding) {'
José Fonseca99221832011-03-22 22:15:46 +0000990
991 # Get the arguments via glGet*
992 for arg in function.args:
993 arg_get_enum = 'GL_%s_ARRAY_%s' % (uppercase_name, arg.name.upper())
994 arg_get_function, arg_type = TypeGetter().visit(arg.type)
José Fonseca7f5163e2011-03-31 23:37:26 +0100995 print ' %s %s = 0;' % (arg_type, arg.name)
José Fonseca632a78d2012-04-19 07:18:59 +0100996 print ' _%s(%s, &%s);' % (arg_get_function, arg_get_enum, arg.name)
José Fonseca99221832011-03-22 22:15:46 +0000997
998 arg_names = ', '.join([arg.name for arg in function.args[:-1]])
José Fonseca14cb9ef2012-05-17 21:33:14 +0100999 print ' size_t _size = _%s_size(%s, count);' % (function.name, arg_names)
José Fonseca99221832011-03-22 22:15:46 +00001000
1001 # Emit a fake function
José Fonsecafb6744f2011-04-15 11:18:37 +01001002 self.array_trace_intermezzo(api, uppercase_name)
José Fonseca7a5f23a2014-06-24 19:20:36 +01001003 print ' unsigned _call = trace::localWriter.beginEnter(&_%s_sig, true);' % (function.name,)
José Fonseca669b1222011-02-20 09:05:10 +00001004 for arg in function.args:
1005 assert not arg.output
José Fonsecab4a3d142011-10-27 07:43:19 +01001006 print ' trace::localWriter.beginArg(%u);' % (arg.index,)
José Fonseca14c21bc2011-02-20 23:32:22 +00001007 if arg.name != 'pointer':
José Fonseca54f304a2012-01-14 19:33:08 +00001008 self.serializeValue(arg.type, arg.name)
José Fonseca14c21bc2011-02-20 23:32:22 +00001009 else:
José Fonseca632a78d2012-04-19 07:18:59 +01001010 print ' trace::localWriter.writeBlob((const void *)%s, _size);' % (arg.name)
José Fonsecab4a3d142011-10-27 07:43:19 +01001011 print ' trace::localWriter.endArg();'
José Fonseca99221832011-03-22 22:15:46 +00001012
José Fonsecab4a3d142011-10-27 07:43:19 +01001013 print ' trace::localWriter.endEnter();'
José Fonseca632a78d2012-04-19 07:18:59 +01001014 print ' trace::localWriter.beginLeave(_call);'
José Fonsecab4a3d142011-10-27 07:43:19 +01001015 print ' trace::localWriter.endLeave();'
José Fonseca99221832011-03-22 22:15:46 +00001016 print ' }'
José Fonseca669b1222011-02-20 09:05:10 +00001017 print ' }'
José Fonsecafb6744f2011-04-15 11:18:37 +01001018 self.array_epilog(api, uppercase_name)
1019 self.array_trace_epilog(api, uppercase_name)
Chia-I Wub3d218d2011-11-03 01:37:36 +08001020 print ' }'
José Fonseca99221832011-03-22 22:15:46 +00001021 print
José Fonseca1a2fdd22011-04-01 00:55:09 +01001022
José Fonseca1601c412011-05-10 10:38:19 +01001023 # Samething, but for glVertexAttribPointer*
1024 #
1025 # Some variants of glVertexAttribPointer alias conventional and generic attributes:
1026 # - glVertexAttribPointer: no
1027 # - glVertexAttribPointerARB: implementation dependent
1028 # - glVertexAttribPointerNV: yes
1029 #
1030 # This means that the implementations of these functions do not always
1031 # alias, and they need to be considered independently.
1032 #
Chia-I Wub3d218d2011-11-03 01:37:36 +08001033 print ' // ES1 does not support generic vertex attributes'
José Fonsecab0c59722015-01-05 20:45:41 +00001034 print ' if (es1)'
Chia-I Wub3d218d2011-11-03 01:37:36 +08001035 print ' return;'
1036 print
José Fonseca632a78d2012-04-19 07:18:59 +01001037 print ' vertex_attrib _vertex_attrib = _get_vertex_attrib();'
José Fonseca5a568a92011-06-29 16:43:36 +01001038 print
José Fonseca74b661a2014-07-17 19:10:24 +01001039 for suffix in ['', 'NV']:
José Fonseca5a568a92011-06-29 16:43:36 +01001040 if suffix:
José Fonsecad94aaac2011-06-28 20:50:49 +01001041 SUFFIX = '_' + suffix
José Fonsecad94aaac2011-06-28 20:50:49 +01001042 else:
José Fonseca5a568a92011-06-29 16:43:36 +01001043 SUFFIX = suffix
José Fonseca1601c412011-05-10 10:38:19 +01001044 function_name = 'glVertexAttribPointer' + suffix
José Fonseca1b6c8752012-04-15 14:33:00 +01001045 function = api.getFunctionByName(function_name)
José Fonseca06e85192011-10-16 14:15:36 +01001046
1047 print ' // %s' % function.prototype()
José Fonseca632a78d2012-04-19 07:18:59 +01001048 print ' if (_vertex_attrib == VERTEX_ATTRIB%s) {' % SUFFIX
José Fonseca5a568a92011-06-29 16:43:36 +01001049 if suffix == 'NV':
José Fonseca632a78d2012-04-19 07:18:59 +01001050 print ' GLint _max_vertex_attribs = 16;'
José Fonseca5a568a92011-06-29 16:43:36 +01001051 else:
José Fonseca26be8f92014-03-07 14:08:50 +00001052 print ' GLint _max_vertex_attribs = _glGetInteger(GL_MAX_VERTEX_ATTRIBS);'
José Fonseca632a78d2012-04-19 07:18:59 +01001053 print ' for (GLint index = 0; index < _max_vertex_attribs; ++index) {'
1054 print ' GLint _enabled = 0;'
José Fonseca5a568a92011-06-29 16:43:36 +01001055 if suffix == 'NV':
José Fonseca632a78d2012-04-19 07:18:59 +01001056 print ' _glGetIntegerv(GL_VERTEX_ATTRIB_ARRAY0_NV + index, &_enabled);'
José Fonseca5a568a92011-06-29 16:43:36 +01001057 else:
José Fonseca632a78d2012-04-19 07:18:59 +01001058 print ' _glGetVertexAttribiv%s(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED%s, &_enabled);' % (suffix, SUFFIX)
1059 print ' if (_enabled) {'
1060 print ' GLint _binding = 0;'
José Fonseca5a568a92011-06-29 16:43:36 +01001061 if suffix != 'NV':
1062 # It doesn't seem possible to use VBOs with NV_vertex_program.
José Fonseca632a78d2012-04-19 07:18:59 +01001063 print ' _glGetVertexAttribiv%s(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING%s, &_binding);' % (suffix, SUFFIX)
1064 print ' if (!_binding) {'
José Fonseca1a2fdd22011-04-01 00:55:09 +01001065
José Fonseca1601c412011-05-10 10:38:19 +01001066 # Get the arguments via glGet*
1067 for arg in function.args[1:]:
José Fonseca5a568a92011-06-29 16:43:36 +01001068 if suffix == 'NV':
1069 arg_get_enum = 'GL_ATTRIB_ARRAY_%s%s' % (arg.name.upper(), SUFFIX)
1070 else:
1071 arg_get_enum = 'GL_VERTEX_ATTRIB_ARRAY_%s%s' % (arg.name.upper(), SUFFIX)
José Fonsecac493e3e2011-06-29 12:57:06 +01001072 arg_get_function, arg_type = TypeGetter('glGetVertexAttrib', False, suffix).visit(arg.type)
José Fonseca5a568a92011-06-29 16:43:36 +01001073 print ' %s %s = 0;' % (arg_type, arg.name)
José Fonseca632a78d2012-04-19 07:18:59 +01001074 print ' _%s(index, %s, &%s);' % (arg_get_function, arg_get_enum, arg.name)
José Fonseca1601c412011-05-10 10:38:19 +01001075
1076 arg_names = ', '.join([arg.name for arg in function.args[1:-1]])
José Fonseca14cb9ef2012-05-17 21:33:14 +01001077 print ' size_t _size = _%s_size(%s, count);' % (function.name, arg_names)
José Fonseca1a2fdd22011-04-01 00:55:09 +01001078
José Fonseca1601c412011-05-10 10:38:19 +01001079 # Emit a fake function
José Fonseca7a5f23a2014-06-24 19:20:36 +01001080 print ' unsigned _call = trace::localWriter.beginEnter(&_%s_sig, true);' % (function.name,)
José Fonseca1601c412011-05-10 10:38:19 +01001081 for arg in function.args:
1082 assert not arg.output
José Fonsecab4a3d142011-10-27 07:43:19 +01001083 print ' trace::localWriter.beginArg(%u);' % (arg.index,)
José Fonseca1601c412011-05-10 10:38:19 +01001084 if arg.name != 'pointer':
José Fonseca54f304a2012-01-14 19:33:08 +00001085 self.serializeValue(arg.type, arg.name)
José Fonseca1601c412011-05-10 10:38:19 +01001086 else:
José Fonseca632a78d2012-04-19 07:18:59 +01001087 print ' trace::localWriter.writeBlob((const void *)%s, _size);' % (arg.name)
José Fonsecab4a3d142011-10-27 07:43:19 +01001088 print ' trace::localWriter.endArg();'
José Fonseca1601c412011-05-10 10:38:19 +01001089
José Fonsecab4a3d142011-10-27 07:43:19 +01001090 print ' trace::localWriter.endEnter();'
José Fonseca632a78d2012-04-19 07:18:59 +01001091 print ' trace::localWriter.beginLeave(_call);'
José Fonsecab4a3d142011-10-27 07:43:19 +01001092 print ' trace::localWriter.endLeave();'
José Fonseca1601c412011-05-10 10:38:19 +01001093 print ' }'
1094 print ' }'
1095 print ' }'
1096 print ' }'
1097 print
José Fonseca1a2fdd22011-04-01 00:55:09 +01001098
José Fonseca8d1408b2014-02-03 19:57:18 +00001099 # Restore the original array_buffer
1100 print ' if (_array_buffer) {'
1101 self.fake_glBindBuffer(api, 'GL_ARRAY_BUFFER', '_array_buffer')
1102 print ' }'
1103 print
1104
José Fonseca669b1222011-02-20 09:05:10 +00001105 print '}'
1106 print
1107
José Fonsecafb6744f2011-04-15 11:18:37 +01001108 #
1109 # Hooks for glTexCoordPointer, which is identical to the other array
1110 # pointers except the fact that it is indexed by glClientActiveTexture.
1111 #
1112
1113 def array_prolog(self, api, uppercase_name):
1114 if uppercase_name == 'TEXTURE_COORD':
Jose Fonseca6ac76c12015-06-26 10:27:30 +01001115 print ' GLint max_units = 0;'
José Fonseca34ea6162015-01-08 23:45:43 +00001116 print ' if (ctx->profile.desktop())'
Jose Fonseca6ac76c12015-06-26 10:27:30 +01001117 print ' _glGetIntegerv(GL_MAX_TEXTURE_COORDS, &max_units);'
Chia-I Wub3d218d2011-11-03 01:37:36 +08001118 print ' else'
Jose Fonseca6ac76c12015-06-26 10:27:30 +01001119 print ' _glGetIntegerv(GL_MAX_TEXTURE_UNITS, &max_units);'
1120 print ' GLint client_active_texture = GL_TEXTURE0;'
1121 print ' if (max_units > 0) {'
1122 print ' _glGetIntegerv(GL_CLIENT_ACTIVE_TEXTURE, &client_active_texture);'
1123 print ' }'
1124 print ' GLint unit = 0;'
1125 print ' do {'
José Fonseca7525e6f2011-09-28 09:04:56 +01001126 print ' GLint texture = GL_TEXTURE0 + unit;'
Jose Fonseca6ac76c12015-06-26 10:27:30 +01001127 print ' if (max_units > 0) {'
1128 print ' _glClientActiveTexture(texture);'
1129 print ' }'
José Fonsecafb6744f2011-04-15 11:18:37 +01001130
1131 def array_trace_prolog(self, api, uppercase_name):
1132 if uppercase_name == 'TEXTURE_COORD':
1133 print ' bool client_active_texture_dirty = false;'
1134
1135 def array_epilog(self, api, uppercase_name):
1136 if uppercase_name == 'TEXTURE_COORD':
Jose Fonseca6ac76c12015-06-26 10:27:30 +01001137 print ' } while (++unit < max_units);'
José Fonsecafb6744f2011-04-15 11:18:37 +01001138 self.array_cleanup(api, uppercase_name)
1139
1140 def array_cleanup(self, api, uppercase_name):
1141 if uppercase_name == 'TEXTURE_COORD':
Jose Fonseca6ac76c12015-06-26 10:27:30 +01001142 print ' if (max_units > 0) {'
1143 print ' _glClientActiveTexture(client_active_texture);'
1144 print ' }'
José Fonsecafb6744f2011-04-15 11:18:37 +01001145
1146 def array_trace_intermezzo(self, api, uppercase_name):
1147 if uppercase_name == 'TEXTURE_COORD':
1148 print ' if (texture != client_active_texture || client_active_texture_dirty) {'
1149 print ' client_active_texture_dirty = true;'
1150 self.fake_glClientActiveTexture_call(api, "texture");
1151 print ' }'
1152
1153 def array_trace_epilog(self, api, uppercase_name):
1154 if uppercase_name == 'TEXTURE_COORD':
1155 print ' if (client_active_texture_dirty) {'
1156 self.fake_glClientActiveTexture_call(api, "client_active_texture");
1157 print ' }'
1158
José Fonseca8d1408b2014-02-03 19:57:18 +00001159 def fake_glBindBuffer(self, api, target, buffer):
1160 function = api.getFunctionByName('glBindBuffer')
1161 self.fake_call(function, [target, buffer])
1162
José Fonsecafb6744f2011-04-15 11:18:37 +01001163 def fake_glClientActiveTexture_call(self, api, texture):
José Fonseca1b6c8752012-04-15 14:33:00 +01001164 function = api.getFunctionByName('glClientActiveTexture')
José Fonsecafb6744f2011-04-15 11:18:37 +01001165 self.fake_call(function, [texture])
1166
José Fonseca151c3702013-05-10 08:28:15 +01001167 def emitFakeTexture2D(self):
1168 function = glapi.glapi.getFunctionByName('glTexImage2D')
1169 instances = function.argNames()
José Fonseca7a5f23a2014-06-24 19:20:36 +01001170 print ' unsigned _fake_call = trace::localWriter.beginEnter(&_%s_sig, true);' % (function.name,)
José Fonseca151c3702013-05-10 08:28:15 +01001171 for arg in function.args:
1172 assert not arg.output
1173 self.serializeArg(function, arg)
1174 print ' trace::localWriter.endEnter();'
1175 print ' trace::localWriter.beginLeave(_fake_call);'
1176 print ' trace::localWriter.endLeave();'
José Fonsecafb6744f2011-04-15 11:18:37 +01001177
1178
1179
1180
1181
José Fonseca669b1222011-02-20 09:05:10 +00001182
1183
1184
1185
1186
1187