José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 1 | ########################################################################## |
| 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é Fonseca | c5bf77a | 2014-08-14 16:10:02 +0100 | [diff] [blame] | 30 | import re |
| 31 | import sys |
| 32 | |
José Fonseca | 452d325 | 2012-04-14 15:55:40 +0100 | [diff] [blame] | 33 | from trace import Tracer |
José Fonseca | 1b6c875 | 2012-04-15 14:33:00 +0100 | [diff] [blame] | 34 | from dispatch import function_pointer_type, function_pointer_value |
José Fonseca | bd86a22 | 2011-09-27 09:21:38 +0100 | [diff] [blame] | 35 | import specs.stdapi as stdapi |
| 36 | import specs.glapi as glapi |
| 37 | import specs.glparams as glparams |
| 38 | from specs.glxapi import glxapi |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 39 | |
| 40 | |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 41 | class TypeGetter(stdapi.Visitor): |
| 42 | '''Determine which glGet*v function that matches the specified type.''' |
| 43 | |
José Fonseca | c493e3e | 2011-06-29 12:57:06 +0100 | [diff] [blame] | 44 | def __init__(self, prefix = 'glGet', long_suffix = True, ext_suffix = ''): |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 45 | self.prefix = prefix |
| 46 | self.long_suffix = long_suffix |
José Fonseca | c493e3e | 2011-06-29 12:57:06 +0100 | [diff] [blame] | 47 | self.ext_suffix = ext_suffix |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 48 | |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 49 | def visitConst(self, const): |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 50 | return self.visit(const.type) |
| 51 | |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 52 | def visitAlias(self, alias): |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 53 | if alias.expr == 'GLboolean': |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 54 | if self.long_suffix: |
José Fonseca | c493e3e | 2011-06-29 12:57:06 +0100 | [diff] [blame] | 55 | suffix = 'Booleanv' |
| 56 | arg_type = alias.expr |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 57 | else: |
José Fonseca | c493e3e | 2011-06-29 12:57:06 +0100 | [diff] [blame] | 58 | suffix = 'iv' |
| 59 | arg_type = 'GLint' |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 60 | elif alias.expr == 'GLdouble': |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 61 | if self.long_suffix: |
José Fonseca | c493e3e | 2011-06-29 12:57:06 +0100 | [diff] [blame] | 62 | suffix = 'Doublev' |
| 63 | arg_type = alias.expr |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 64 | else: |
José Fonseca | c493e3e | 2011-06-29 12:57:06 +0100 | [diff] [blame] | 65 | suffix = 'dv' |
| 66 | arg_type = alias.expr |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 67 | elif alias.expr == 'GLfloat': |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 68 | if self.long_suffix: |
José Fonseca | c493e3e | 2011-06-29 12:57:06 +0100 | [diff] [blame] | 69 | suffix = 'Floatv' |
| 70 | arg_type = alias.expr |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 71 | else: |
José Fonseca | c493e3e | 2011-06-29 12:57:06 +0100 | [diff] [blame] | 72 | suffix = 'fv' |
| 73 | arg_type = alias.expr |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 74 | elif alias.expr in ('GLint', 'GLuint', 'GLsizei'): |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 75 | if self.long_suffix: |
José Fonseca | c493e3e | 2011-06-29 12:57:06 +0100 | [diff] [blame] | 76 | suffix = 'Integerv' |
| 77 | arg_type = 'GLint' |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 78 | else: |
José Fonseca | c493e3e | 2011-06-29 12:57:06 +0100 | [diff] [blame] | 79 | suffix = 'iv' |
| 80 | arg_type = 'GLint' |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 81 | else: |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 82 | print(alias.expr) |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 83 | assert False |
José Fonseca | c493e3e | 2011-06-29 12:57:06 +0100 | [diff] [blame] | 84 | function_name = self.prefix + suffix + self.ext_suffix |
| 85 | return function_name, arg_type |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 86 | |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 87 | def visitEnum(self, enum): |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 88 | return self.visit(glapi.GLint) |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 89 | |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 90 | def visitBitmask(self, bitmask): |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 91 | return self.visit(glapi.GLint) |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 92 | |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 93 | def visitOpaque(self, pointer): |
José Fonseca | c493e3e | 2011-06-29 12:57:06 +0100 | [diff] [blame] | 94 | return self.prefix + 'Pointerv' + self.ext_suffix, 'GLvoid *' |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 95 | |
| 96 | |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 97 | class GlTracer(Tracer): |
| 98 | |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 99 | 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é Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 108 | ] |
José Fonseca | c9f1223 | 2011-03-25 20:07:42 +0000 | [diff] [blame] | 109 | arrays.reverse() |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 110 | |
José Fonseca | b0c5972 | 2015-01-05 20:45:41 +0000 | [diff] [blame] | 111 | # arrays available in ES1 |
Chia-I Wu | b3d218d | 2011-11-03 01:37:36 +0800 | [diff] [blame] | 112 | arrays_es1 = ("Vertex", "Normal", "Color", "TexCoord") |
| 113 | |
José Fonseca | 4c938c2 | 2011-04-30 22:44:38 +0100 | [diff] [blame] | 114 | def header(self, api): |
| 115 | Tracer.header(self, api) |
| 116 | |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 117 | print('#include <algorithm>') |
| 118 | print() |
| 119 | print('#include "gltrace.hpp"') |
| 120 | print('#include "gltrace_arrays.hpp"') |
| 121 | print() |
José Fonseca | 5a568a9 | 2011-06-29 16:43:36 +0100 | [diff] [blame] | 122 | |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 123 | # Whether we need user arrays |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 124 | print('static inline bool _need_user_arrays(gltrace::Context *_ctx)') |
| 125 | print('{') |
| 126 | print(' if (!_ctx->user_arrays) {') |
| 127 | print(' return false;') |
| 128 | print(' }') |
| 129 | print() |
| 130 | print(' glfeatures::Profile profile = _ctx->profile;') |
| 131 | print(' bool es1 = profile.es() && profile.major == 1;') |
| 132 | print() |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 133 | |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 134 | for camelcase_name, uppercase_name in self.arrays: |
Chia-I Wu | b3d218d | 2011-11-03 01:37:36 +0800 | [diff] [blame] | 135 | # in which profile is the array available? |
José Fonseca | 34ea616 | 2015-01-08 23:45:43 +0000 | [diff] [blame] | 136 | profile_check = 'profile.desktop()' |
Chia-I Wu | b3d218d | 2011-11-03 01:37:36 +0800 | [diff] [blame] | 137 | if camelcase_name in self.arrays_es1: |
José Fonseca | b0c5972 | 2015-01-05 20:45:41 +0000 | [diff] [blame] | 138 | profile_check = '(' + profile_check + ' || es1)'; |
Chia-I Wu | b3d218d | 2011-11-03 01:37:36 +0800 | [diff] [blame] | 139 | |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 140 | function_name = 'gl%sPointer' % camelcase_name |
| 141 | enable_name = 'GL_%s_ARRAY' % uppercase_name |
| 142 | binding_name = 'GL_%s_ARRAY_BUFFER_BINDING' % uppercase_name |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 143 | print(' // %s' % function_name) |
| 144 | print(' if (%s) {' % profile_check) |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 145 | self.array_prolog(api, uppercase_name) |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 146 | print(' if (_glIsEnabled(%s) &&' % enable_name) |
| 147 | print(' _glGetInteger(%s) == 0) {' % binding_name) |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 148 | self.array_cleanup(api, uppercase_name) |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 149 | print(' return true;') |
| 150 | print(' }') |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 151 | self.array_epilog(api, uppercase_name) |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 152 | print(' }') |
| 153 | print() |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 154 | |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 155 | print(' // ES1 does not support generic vertex attributes') |
| 156 | print(' if (es1)') |
| 157 | print(' return false;') |
| 158 | print() |
| 159 | print(' // glVertexAttribPointer') |
| 160 | print(' GLint _max_vertex_attribs = _glGetInteger(GL_MAX_VERTEX_ATTRIBS);') |
| 161 | print(' for (GLint index = 0; index < _max_vertex_attribs; ++index) {') |
| 162 | print(' if (_glGetVertexAttribi(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED) &&') |
| 163 | print(' _glGetVertexAttribi(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING) == 0) {') |
| 164 | print(' return true;') |
| 165 | print(' }') |
| 166 | print(' }') |
| 167 | print() |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 168 | |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 169 | print(' return false;') |
| 170 | print('}') |
| 171 | print() |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 172 | |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 173 | print(r'static void _trace_user_arrays(gltrace::Context *_ctx, GLuint count);') |
| 174 | print() |
Jose Fonseca | 6ef9b3c | 2016-01-27 23:18:52 +0000 | [diff] [blame] | 175 | |
Jose Fonseca | 27b8d81 | 2016-05-13 07:09:09 -0700 | [diff] [blame] | 176 | # Declare helper functions to emit fake function calls into the trace |
| 177 | for function in api.getAllFunctions(): |
| 178 | if function.name in self.fake_function_names: |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 179 | print(function.prototype('_fake_' + function.name) + ';') |
| 180 | print() |
| 181 | print(r'static inline void') |
| 182 | print(r'_fakeStringMarker(const std::string &s) {') |
| 183 | print(r' _fake_glStringMarkerGREMEDY(s.length(), s.data());') |
| 184 | print(r'}') |
| 185 | print() |
José Fonseca | 867b1b7 | 2011-04-24 11:58:04 +0100 | [diff] [blame] | 186 | |
José Fonseca | 9c536b0 | 2012-02-29 20:54:13 +0000 | [diff] [blame] | 187 | # Buffer mappings |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 188 | print('// whether glMapBufferRange(GL_MAP_WRITE_BIT) has ever been called') |
| 189 | print('static bool _checkBufferMapRange = false;') |
| 190 | print() |
| 191 | print('// whether glBufferParameteriAPPLE(GL_BUFFER_FLUSHING_UNMAP_APPLE, GL_FALSE) has ever been called') |
| 192 | print('static bool _checkBufferFlushingUnmapAPPLE = false;') |
| 193 | print() |
José Fonseca | 867b1b7 | 2011-04-24 11:58:04 +0100 | [diff] [blame] | 194 | |
José Fonseca | a3f89ae | 2011-04-26 08:50:32 +0100 | [diff] [blame] | 195 | # Generate a helper function to determine whether a parameter name |
| 196 | # refers to a symbolic value or not |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 197 | print('static bool') |
| 198 | print('is_symbolic_pname(GLenum pname) {') |
| 199 | print(' switch (pname) {') |
José Fonseca | 5ea9187 | 2011-05-04 09:41:55 +0100 | [diff] [blame] | 200 | for function, type, count, name in glparams.parameters: |
José Fonseca | a3f89ae | 2011-04-26 08:50:32 +0100 | [diff] [blame] | 201 | if type is glapi.GLenum: |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 202 | print(' case %s:' % name) |
| 203 | print(' return true;') |
| 204 | print(' default:') |
| 205 | print(' return false;') |
| 206 | print(' }') |
| 207 | print('}') |
| 208 | print() |
José Fonseca | a3f89ae | 2011-04-26 08:50:32 +0100 | [diff] [blame] | 209 | |
| 210 | # Generate a helper function to determine whether a parameter value is |
| 211 | # potentially symbolic or not; i.e., if the value can be represented in |
| 212 | # an enum or not |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 213 | print('template<class T>') |
| 214 | print('static inline bool') |
| 215 | print('is_symbolic_param(T param) {') |
| 216 | print(' return static_cast<T>(static_cast<GLenum>(param)) == param;') |
| 217 | print('}') |
| 218 | print() |
José Fonseca | 4c938c2 | 2011-04-30 22:44:38 +0100 | [diff] [blame] | 219 | |
| 220 | # Generate a helper function to know how many elements a parameter has |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 221 | print('static size_t') |
| 222 | print('_gl_param_size(GLenum pname) {') |
| 223 | print(' switch (pname) {') |
José Fonseca | 5ea9187 | 2011-05-04 09:41:55 +0100 | [diff] [blame] | 224 | for function, type, count, name in glparams.parameters: |
Jose Fonseca | 11b6bfa | 2015-07-21 13:32:51 +0100 | [diff] [blame] | 225 | if name == 'GL_PROGRAM_BINARY_FORMATS': |
| 226 | count = 0 |
José Fonseca | 4c938c2 | 2011-04-30 22:44:38 +0100 | [diff] [blame] | 227 | if type is not None: |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 228 | print(' case %s: return %s;' % (name, count)) |
| 229 | print(' default:') |
| 230 | print(r' os::log("apitrace: warning: %s: unknown GLenum 0x%04X\n", __FUNCTION__, pname);') |
| 231 | print(' return 1;') |
| 232 | print(' }') |
| 233 | print('}') |
| 234 | print() |
José Fonseca | 4c938c2 | 2011-04-30 22:44:38 +0100 | [diff] [blame] | 235 | |
Chia-I Wu | 335efb4 | 2011-11-03 01:59:22 +0800 | [diff] [blame] | 236 | # states such as GL_UNPACK_ROW_LENGTH are not available in GLES |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 237 | print('static inline bool') |
| 238 | print('can_unpack_subimage(void) {') |
| 239 | print(' gltrace::Context *_ctx = gltrace::getContext();') |
Jose Fonseca | 487e9c5 | 2019-06-17 10:36:16 +0100 | [diff] [blame^] | 240 | print(' return _ctx->features.unpack_subimage;') |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 241 | print('}') |
| 242 | print() |
Chia-I Wu | 335efb4 | 2011-11-03 01:59:22 +0800 | [diff] [blame] | 243 | |
José Fonseca | 631dbd1 | 2014-12-15 16:34:45 +0000 | [diff] [blame] | 244 | # VMWX_map_buffer_debug |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 245 | print(r'extern "C" PUBLIC') |
| 246 | print(r'void APIENTRY') |
| 247 | print(r'glNotifyMappedBufferRangeVMWX(const void * start, GLsizeiptr length) {') |
José Fonseca | 631dbd1 | 2014-12-15 16:34:45 +0000 | [diff] [blame] | 248 | self.emit_memcpy('start', 'length') |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 249 | print(r'}') |
| 250 | print() |
José Fonseca | 631dbd1 | 2014-12-15 16:34:45 +0000 | [diff] [blame] | 251 | |
José Fonseca | 1b6c875 | 2012-04-15 14:33:00 +0100 | [diff] [blame] | 252 | getProcAddressFunctionNames = [] |
| 253 | |
| 254 | def traceApi(self, api): |
| 255 | if self.getProcAddressFunctionNames: |
| 256 | # Generate a function to wrap proc addresses |
| 257 | getProcAddressFunction = api.getFunctionByName(self.getProcAddressFunctionNames[0]) |
| 258 | argType = getProcAddressFunction.args[0].type |
| 259 | retType = getProcAddressFunction.type |
| 260 | |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 261 | print('static %s _wrapProcAddress(%s procName, %s procPtr);' % (retType, argType, retType)) |
| 262 | print() |
José Fonseca | 1b6c875 | 2012-04-15 14:33:00 +0100 | [diff] [blame] | 263 | |
| 264 | Tracer.traceApi(self, api) |
| 265 | |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 266 | print('static %s _wrapProcAddress(%s procName, %s procPtr) {' % (retType, argType, retType)) |
Peter Lohrmann | 0b5b75e | 2013-06-03 14:58:41 -0700 | [diff] [blame] | 267 | |
| 268 | # Provide fallback functions to missing debug functions |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 269 | print(' if (!procPtr) {') |
Peter Lohrmann | 0b5b75e | 2013-06-03 14:58:41 -0700 | [diff] [blame] | 270 | else_ = '' |
| 271 | for function_name in self.debug_functions: |
| 272 | if self.api.getFunctionByName(function_name): |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 273 | print(' %sif (strcmp("%s", (const char *)procName) == 0) {' % (else_, function_name)) |
| 274 | print(' return (%s)&%s;' % (retType, function_name)) |
| 275 | print(' }') |
Peter Lohrmann | 0b5b75e | 2013-06-03 14:58:41 -0700 | [diff] [blame] | 276 | else_ = 'else ' |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 277 | print(' %s{' % else_) |
| 278 | print(' return NULL;') |
| 279 | print(' }') |
| 280 | print(' }') |
Peter Lohrmann | 0b5b75e | 2013-06-03 14:58:41 -0700 | [diff] [blame] | 281 | |
José Fonseca | 8130193 | 2012-11-11 00:10:20 +0000 | [diff] [blame] | 282 | for function in api.getAllFunctions(): |
José Fonseca | 1b6c875 | 2012-04-15 14:33:00 +0100 | [diff] [blame] | 283 | ptype = function_pointer_type(function) |
| 284 | pvalue = function_pointer_value(function) |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 285 | print(' if (strcmp("%s", (const char *)procName) == 0) {' % function.name) |
| 286 | print(' assert(procPtr != (%s)&%s);' % (retType, function.name)) |
| 287 | print(' %s = (%s)procPtr;' % (pvalue, ptype)) |
| 288 | print(' return (%s)&%s;' % (retType, function.name,)) |
| 289 | print(' }') |
| 290 | print(' os::log("apitrace: warning: unknown function \\"%s\\"\\n", (const char *)procName);') |
| 291 | print(' return procPtr;') |
| 292 | print('}') |
| 293 | print() |
José Fonseca | 1b6c875 | 2012-04-15 14:33:00 +0100 | [diff] [blame] | 294 | else: |
| 295 | Tracer.traceApi(self, api) |
| 296 | |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 297 | array_pointer_function_names = set(( |
| 298 | "glVertexPointer", |
| 299 | "glNormalPointer", |
| 300 | "glColorPointer", |
| 301 | "glIndexPointer", |
| 302 | "glTexCoordPointer", |
| 303 | "glEdgeFlagPointer", |
| 304 | "glFogCoordPointer", |
| 305 | "glSecondaryColorPointer", |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 306 | |
José Fonseca | ac5285b | 2011-05-04 11:09:08 +0100 | [diff] [blame] | 307 | "glInterleavedArrays", |
| 308 | |
José Fonseca | 7e0bfd9 | 2011-04-30 23:09:03 +0100 | [diff] [blame] | 309 | "glVertexPointerEXT", |
| 310 | "glNormalPointerEXT", |
| 311 | "glColorPointerEXT", |
| 312 | "glIndexPointerEXT", |
| 313 | "glTexCoordPointerEXT", |
| 314 | "glEdgeFlagPointerEXT", |
| 315 | "glFogCoordPointerEXT", |
| 316 | "glSecondaryColorPointerEXT", |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 317 | |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 318 | "glVertexAttribPointer", |
| 319 | "glVertexAttribPointerARB", |
| 320 | "glVertexAttribPointerNV", |
José Fonseca | ac5285b | 2011-05-04 11:09:08 +0100 | [diff] [blame] | 321 | "glVertexAttribIPointer", |
| 322 | "glVertexAttribIPointerEXT", |
José Fonseca | 7f5163e | 2011-03-31 23:37:26 +0100 | [diff] [blame] | 323 | "glVertexAttribLPointer", |
| 324 | "glVertexAttribLPointerEXT", |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 325 | |
| 326 | #"glMatrixIndexPointerARB", |
| 327 | )) |
| 328 | |
José Fonseca | c5bf77a | 2014-08-14 16:10:02 +0100 | [diff] [blame] | 329 | # XXX: We currently ignore the gl*Draw*ElementArray* functions |
Jose Fonseca | dddc5b8 | 2016-05-08 22:33:44 +0100 | [diff] [blame] | 330 | draw_function_regex = re.compile(r'^(?P<radical>gl([A-Z][a-z]+)*Draw(Range)?(Arrays|Elements))(?P<suffix>[A-Z][a-zA-Z]*)?$' ) |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 331 | |
José Fonseca | c9f1223 | 2011-03-25 20:07:42 +0000 | [diff] [blame] | 332 | interleaved_formats = [ |
| 333 | 'GL_V2F', |
| 334 | 'GL_V3F', |
| 335 | 'GL_C4UB_V2F', |
| 336 | 'GL_C4UB_V3F', |
| 337 | 'GL_C3F_V3F', |
| 338 | 'GL_N3F_V3F', |
| 339 | 'GL_C4F_N3F_V3F', |
| 340 | 'GL_T2F_V3F', |
| 341 | 'GL_T4F_V4F', |
| 342 | 'GL_T2F_C4UB_V3F', |
| 343 | 'GL_T2F_C3F_V3F', |
| 344 | 'GL_T2F_N3F_V3F', |
| 345 | 'GL_T2F_C4F_N3F_V3F', |
| 346 | 'GL_T4F_C4F_N3F_V4F', |
| 347 | ] |
| 348 | |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 349 | def traceFunctionImplBody(self, function): |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 350 | # Defer tracing of user array pointers... |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 351 | if function.name in self.array_pointer_function_names: |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 352 | print(' GLint _array_buffer = _glGetInteger(GL_ARRAY_BUFFER_BINDING);') |
| 353 | print(' if (!_array_buffer) {') |
| 354 | print(' static bool warned = false;') |
| 355 | print(' if (!warned) {') |
| 356 | print(' warned = true;') |
| 357 | 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__);') |
| 358 | print(' }') |
| 359 | print(' gltrace::Context *_ctx = gltrace::getContext();') |
| 360 | print(' _ctx->user_arrays = true;') |
José Fonseca | 5a568a9 | 2011-06-29 16:43:36 +0100 | [diff] [blame] | 361 | if function.name == "glVertexAttribPointerNV": |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 362 | print(r' os::log("apitrace: warning: %s: user memory arrays with NV_vertex_program longer supported\n", __FUNCTION__);') |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 363 | self.invokeFunction(function) |
José Fonseca | ac5285b | 2011-05-04 11:09:08 +0100 | [diff] [blame] | 364 | |
| 365 | # And also break down glInterleavedArrays into the individual calls |
| 366 | if function.name == 'glInterleavedArrays': |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 367 | print() |
José Fonseca | ac5285b | 2011-05-04 11:09:08 +0100 | [diff] [blame] | 368 | |
| 369 | # Initialize the enable flags |
| 370 | for camelcase_name, uppercase_name in self.arrays: |
José Fonseca | 632a78d | 2012-04-19 07:18:59 +0100 | [diff] [blame] | 371 | flag_name = '_' + uppercase_name.lower() |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 372 | print(' GLboolean %s = GL_FALSE;' % flag_name) |
| 373 | print() |
José Fonseca | ac5285b | 2011-05-04 11:09:08 +0100 | [diff] [blame] | 374 | |
| 375 | # Switch for the interleaved formats |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 376 | print(' switch (format) {') |
José Fonseca | ac5285b | 2011-05-04 11:09:08 +0100 | [diff] [blame] | 377 | for format in self.interleaved_formats: |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 378 | print(' case %s:' % format) |
José Fonseca | ac5285b | 2011-05-04 11:09:08 +0100 | [diff] [blame] | 379 | for camelcase_name, uppercase_name in self.arrays: |
José Fonseca | 632a78d | 2012-04-19 07:18:59 +0100 | [diff] [blame] | 380 | flag_name = '_' + uppercase_name.lower() |
José Fonseca | ac5285b | 2011-05-04 11:09:08 +0100 | [diff] [blame] | 381 | if format.find('_' + uppercase_name[0]) >= 0: |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 382 | print(' %s = GL_TRUE;' % flag_name) |
| 383 | print(' break;') |
| 384 | print(' default:') |
| 385 | print(' return;') |
| 386 | print(' }') |
| 387 | print() |
José Fonseca | ac5285b | 2011-05-04 11:09:08 +0100 | [diff] [blame] | 388 | |
| 389 | # Emit fake glEnableClientState/glDisableClientState flags |
| 390 | for camelcase_name, uppercase_name in self.arrays: |
José Fonseca | 632a78d | 2012-04-19 07:18:59 +0100 | [diff] [blame] | 391 | flag_name = '_' + uppercase_name.lower() |
José Fonseca | ac5285b | 2011-05-04 11:09:08 +0100 | [diff] [blame] | 392 | enable_name = 'GL_%s_ARRAY' % uppercase_name |
| 393 | |
| 394 | # Emit a fake function |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 395 | print(' if (%s) {' % flag_name) |
| 396 | print(' _fake_glEnableClientState(%s);' % enable_name) |
| 397 | print(' } else {') |
| 398 | print(' _fake_glDisableClientState(%s);' % enable_name) |
| 399 | print(' }') |
José Fonseca | ac5285b | 2011-05-04 11:09:08 +0100 | [diff] [blame] | 400 | |
José Fonseca | c629a8c | 2014-06-01 21:12:27 +0100 | [diff] [blame] | 401 | # Warn about buggy glGet(GL_*ARRAY_SIZE) not returning GL_BGRA |
| 402 | buggyFunctions = { |
| 403 | 'glColorPointer': ('glGetIntegerv', '', 'GL_COLOR_ARRAY_SIZE'), |
| 404 | 'glSecondaryColorPointer': ('glGetIntegerv', '', 'GL_SECONDARY_COLOR_ARRAY_SIZE'), |
| 405 | 'glVertexAttribPointer': ('glGetVertexAttribiv', 'index, ', 'GL_VERTEX_ATTRIB_ARRAY_SIZE'), |
| 406 | 'glVertexAttribPointerARB': ('glGetVertexAttribivARB', 'index, ', 'GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB'), |
| 407 | } |
| 408 | if function.name in buggyFunctions: |
| 409 | getter, extraArg, pname = buggyFunctions[function.name] |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 410 | print(r' static bool _checked = false;') |
| 411 | print(r' if (!_checked && size == GL_BGRA) {') |
| 412 | print(r' GLint _size = 0;') |
| 413 | print(r' _%s(%s%s, &_size);' % (getter, extraArg, pname)) |
| 414 | print(r' if (_size != GL_BGRA) {') |
| 415 | 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)) |
| 416 | print(r' }') |
| 417 | print(r' _checked = true;') |
| 418 | print(r' }') |
José Fonseca | c629a8c | 2014-06-01 21:12:27 +0100 | [diff] [blame] | 419 | |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 420 | print(' return;') |
| 421 | print(' }') |
José Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 422 | |
José Fonseca | 8a6c6cb | 2011-03-23 16:44:30 +0000 | [diff] [blame] | 423 | # ... to the draw calls |
Jose Fonseca | dddc5b8 | 2016-05-08 22:33:44 +0100 | [diff] [blame] | 424 | mo = self.draw_function_regex.match(function.name) |
| 425 | if mo: |
| 426 | functionRadical = mo.group('radical') |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 427 | print(' gltrace::Context *_ctx = gltrace::getContext();') |
| 428 | print(' if (_need_user_arrays(_ctx)) {') |
José Fonseca | 246508e | 2014-08-14 16:07:46 +0100 | [diff] [blame] | 429 | if 'Indirect' in function.name: |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 430 | print(r' os::log("apitrace: warning: %s: indirect user arrays not supported\n");' % (function.name,)) |
José Fonseca | 246508e | 2014-08-14 16:07:46 +0100 | [diff] [blame] | 431 | else: |
Jose Fonseca | dddc5b8 | 2016-05-08 22:33:44 +0100 | [diff] [blame] | 432 | # Pick the corresponding *Params |
| 433 | if 'Arrays' in functionRadical: |
| 434 | paramsType = 'DrawArraysParams' |
| 435 | elif 'Elements' in functionRadical: |
| 436 | paramsType = 'DrawElementsParams' |
| 437 | else: |
| 438 | assert 0 |
| 439 | if 'Multi' in functionRadical: |
| 440 | assert 'drawcount' in function.argNames() |
| 441 | paramsType = 'Multi' + paramsType |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 442 | print(r' %s _params;' % paramsType) |
Jose Fonseca | dddc5b8 | 2016-05-08 22:33:44 +0100 | [diff] [blame] | 443 | |
| 444 | for arg in function.args: |
| 445 | paramsMember = arg.name.lower() |
| 446 | if paramsMember in ('mode', 'modestride'): |
| 447 | continue |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 448 | print(r' _params.%s = %s;' % (paramsMember, arg.name)) |
Jose Fonseca | dddc5b8 | 2016-05-08 22:33:44 +0100 | [diff] [blame] | 449 | |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 450 | print(' GLuint _count = _glDraw_count(_ctx, _params);') |
| 451 | print(' _trace_user_arrays(_ctx, _count);') |
| 452 | print(' }') |
José Fonseca | 707630d | 2014-03-07 14:20:35 +0000 | [diff] [blame] | 453 | if function.name == 'glLockArraysEXT': |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 454 | print(' gltrace::Context *_ctx = gltrace::getContext();') |
| 455 | print(' if (_ctx) {') |
| 456 | print(' _ctx->lockedArrayCount = first + count;') |
| 457 | print(' }') |
José Fonseca | 4a7d860 | 2014-06-18 16:03:44 +0100 | [diff] [blame] | 458 | |
| 459 | # Warn if user arrays are used with glBegin/glArrayElement/glEnd. |
| 460 | if function.name == 'glBegin': |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 461 | print(r' gltrace::Context *_ctx = gltrace::getContext();') |
| 462 | print(r' _ctx->userArraysOnBegin = _need_user_arrays(_ctx);') |
José Fonseca | 7c39d01 | 2014-11-07 19:46:53 +0000 | [diff] [blame] | 463 | if function.name.startswith('glArrayElement'): |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 464 | print(r' gltrace::Context *_ctx = gltrace::getContext();') |
| 465 | print(r' if (_ctx->userArraysOnBegin) {') |
| 466 | print(r' os::log("apitrace: warning: user arrays with glArrayElement not supported (https://github.com/apitrace/apitrace/issues/276)\n");') |
| 467 | print(r' _ctx->userArraysOnBegin = false;') |
| 468 | print(r' }') |
José Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 469 | |
José Fonseca | 7337360 | 2011-05-20 17:45:26 +0100 | [diff] [blame] | 470 | # Emit a fake memcpy on buffer uploads |
José Fonseca | 9c536b0 | 2012-02-29 20:54:13 +0000 | [diff] [blame] | 471 | if function.name == 'glBufferParameteriAPPLE': |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 472 | print(' if (pname == GL_BUFFER_FLUSHING_UNMAP_APPLE && param == GL_FALSE) {') |
| 473 | print(' _checkBufferFlushingUnmapAPPLE = true;') |
| 474 | print(' }') |
José Fonseca | cdc322c | 2012-02-29 19:29:51 +0000 | [diff] [blame] | 475 | if function.name in ('glUnmapBuffer', 'glUnmapBufferARB'): |
José Fonseca | 9c536b0 | 2012-02-29 20:54:13 +0000 | [diff] [blame] | 476 | if function.name.endswith('ARB'): |
| 477 | suffix = 'ARB' |
| 478 | else: |
| 479 | suffix = '' |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 480 | print(' GLint access_flags = 0;') |
| 481 | print(' GLint access = 0;') |
| 482 | print(' bool flush;') |
| 483 | print(' // GLES3 does not have GL_BUFFER_ACCESS;') |
| 484 | print(' if (_checkBufferMapRange) {') |
| 485 | print(' _glGetBufferParameteriv%s(target, GL_BUFFER_ACCESS_FLAGS, &access_flags);' % suffix) |
| 486 | print(' flush = (access_flags & GL_MAP_WRITE_BIT) && !(access_flags & (GL_MAP_FLUSH_EXPLICIT_BIT | GL_MAP_PERSISTENT_BIT));') |
| 487 | print(' } else {') |
| 488 | print(' _glGetBufferParameteriv%s(target, GL_BUFFER_ACCESS, &access);' % suffix) |
| 489 | print(' flush = access != GL_READ_ONLY;') |
| 490 | print(' }') |
| 491 | print(' if (flush) {') |
| 492 | print(' GLvoid *map = NULL;') |
| 493 | print(' _glGetBufferPointerv%s(target, GL_BUFFER_MAP_POINTER, &map);' % suffix) |
| 494 | print(' if (map) {') |
| 495 | print(' GLint length = -1;') |
| 496 | print(' if (_checkBufferMapRange) {') |
| 497 | print(' _glGetBufferParameteriv%s(target, GL_BUFFER_MAP_LENGTH, &length);' % suffix) |
| 498 | print(' if (length == -1) {') |
| 499 | print(' // Mesa drivers refuse GL_BUFFER_MAP_LENGTH without GL 3.0 up-to') |
| 500 | print(' // http://cgit.freedesktop.org/mesa/mesa/commit/?id=ffee498fb848b253a7833373fe5430f8c7ca0c5f') |
| 501 | print(' static bool warned = false;') |
| 502 | print(' if (!warned) {') |
| 503 | print(' os::log("apitrace: warning: glGetBufferParameteriv%s(GL_BUFFER_MAP_LENGTH) failed\\n");' % suffix) |
| 504 | print(' warned = true;') |
| 505 | print(' }') |
| 506 | print(' }') |
| 507 | print(' } else {') |
| 508 | print(' length = 0;') |
| 509 | print(' _glGetBufferParameteriv%s(target, GL_BUFFER_SIZE, &length);' % suffix) |
| 510 | print(' }') |
| 511 | print(' if (_checkBufferFlushingUnmapAPPLE) {') |
| 512 | print(' GLint flushing_unmap = GL_TRUE;') |
| 513 | print(' _glGetBufferParameteriv%s(target, GL_BUFFER_FLUSHING_UNMAP_APPLE, &flushing_unmap);' % suffix) |
| 514 | print(' flush = flush && flushing_unmap;') |
| 515 | print(' }') |
| 516 | print(' if (flush && length > 0) {') |
José Fonseca | 6f0e303 | 2014-06-25 01:00:35 +0100 | [diff] [blame] | 517 | self.emit_memcpy('map', 'length') |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 518 | print(' }') |
| 519 | print(' }') |
| 520 | print(' }') |
José Fonseca | cdc322c | 2012-02-29 19:29:51 +0000 | [diff] [blame] | 521 | if function.name == 'glUnmapBufferOES': |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 522 | print(' GLint access_flags = 0;') |
| 523 | print(' GLint access = 0;') |
| 524 | print(' bool flush;') |
| 525 | print(' // GLES3 does not have GL_BUFFER_ACCESS;') |
| 526 | print(' if (_checkBufferMapRange) {') |
| 527 | print(' _glGetBufferParameteriv(target, GL_BUFFER_ACCESS_FLAGS, &access_flags);') |
| 528 | print(' flush = (access_flags & GL_MAP_WRITE_BIT) && !(access_flags & (GL_MAP_FLUSH_EXPLICIT_BIT | GL_MAP_PERSISTENT_BIT));') |
| 529 | print(' } else {') |
| 530 | print(' _glGetBufferParameteriv(target, GL_BUFFER_ACCESS, &access);') |
| 531 | print(' flush = access != GL_READ_ONLY;') |
| 532 | print(' }') |
| 533 | print(' if (flush) {') |
| 534 | print(' GLvoid *map = NULL;') |
| 535 | print(' _glGetBufferPointervOES(target, GL_BUFFER_MAP_POINTER, &map);') |
| 536 | print(' if (map) {') |
| 537 | print(' GLint length = 0;') |
| 538 | print(' GLint offset = 0;') |
| 539 | print(' if (_checkBufferMapRange) {') |
| 540 | print(' _glGetBufferParameteriv(target, GL_BUFFER_MAP_LENGTH, &length);') |
| 541 | print(' _glGetBufferParameteriv(target, GL_BUFFER_MAP_OFFSET, &offset);') |
| 542 | print(' } else {') |
| 543 | print(' _glGetBufferParameteriv(target, GL_BUFFER_SIZE, &length);') |
| 544 | print(' }') |
| 545 | print(' if (flush && length > 0) {') |
Jose Fonseca | d2fb340 | 2015-01-24 13:42:52 +0000 | [diff] [blame] | 546 | self.emit_memcpy('map', 'length') |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 547 | print(' }') |
| 548 | print(' }') |
| 549 | print(' }') |
José Fonseca | 4920c30 | 2014-08-13 18:35:57 +0100 | [diff] [blame] | 550 | if function.name == 'glUnmapNamedBuffer': |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 551 | print(' GLint access_flags = 0;') |
| 552 | print(' _glGetNamedBufferParameteriv(buffer, GL_BUFFER_ACCESS_FLAGS, &access_flags);') |
| 553 | print(' if ((access_flags & GL_MAP_WRITE_BIT) &&') |
| 554 | print(' !(access_flags & (GL_MAP_FLUSH_EXPLICIT_BIT | GL_MAP_PERSISTENT_BIT))) {') |
| 555 | print(' GLvoid *map = NULL;') |
| 556 | print(' _glGetNamedBufferPointerv(buffer, GL_BUFFER_MAP_POINTER, &map);') |
| 557 | print(' GLint length = 0;') |
| 558 | print(' _glGetNamedBufferParameteriv(buffer, GL_BUFFER_MAP_LENGTH, &length);') |
| 559 | print(' if (map && length > 0) {') |
José Fonseca | 4920c30 | 2014-08-13 18:35:57 +0100 | [diff] [blame] | 560 | self.emit_memcpy('map', 'length') |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 561 | print(' }') |
| 562 | print(' }') |
José Fonseca | fb3bd60 | 2012-01-15 13:56:28 +0000 | [diff] [blame] | 563 | if function.name == 'glUnmapNamedBufferEXT': |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 564 | print(' GLint access_flags = 0;') |
| 565 | print(' _glGetNamedBufferParameterivEXT(buffer, GL_BUFFER_ACCESS_FLAGS, &access_flags);') |
| 566 | print(' if ((access_flags & GL_MAP_WRITE_BIT) &&') |
| 567 | print(' !(access_flags & (GL_MAP_FLUSH_EXPLICIT_BIT | GL_MAP_PERSISTENT_BIT))) {') |
| 568 | print(' GLvoid *map = NULL;') |
| 569 | print(' _glGetNamedBufferPointervEXT(buffer, GL_BUFFER_MAP_POINTER, &map);') |
| 570 | print(' GLint length = 0;') |
| 571 | print(' _glGetNamedBufferParameterivEXT(buffer, GL_BUFFER_MAP_LENGTH, &length);') |
| 572 | print(' if (map && length > 0) {') |
José Fonseca | 6f0e303 | 2014-06-25 01:00:35 +0100 | [diff] [blame] | 573 | self.emit_memcpy('map', 'length') |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 574 | print(' }') |
| 575 | print(' }') |
José Fonseca | 77ef0ce | 2012-02-29 18:08:48 +0000 | [diff] [blame] | 576 | if function.name == 'glFlushMappedBufferRange': |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 577 | print(' GLvoid *map = NULL;') |
| 578 | print(' _glGetBufferPointerv(target, GL_BUFFER_MAP_POINTER, &map);') |
| 579 | print(' if (map && length > 0) {') |
José Fonseca | 6f0e303 | 2014-06-25 01:00:35 +0100 | [diff] [blame] | 580 | self.emit_memcpy('(const char *)map + offset', 'length') |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 581 | print(' }') |
Jose Fonseca | d2fb340 | 2015-01-24 13:42:52 +0000 | [diff] [blame] | 582 | if function.name == 'glFlushMappedBufferRangeEXT': |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 583 | print(' GLvoid *map = NULL;') |
| 584 | print(' _glGetBufferPointervOES(target, GL_BUFFER_MAP_POINTER_OES, &map);') |
| 585 | print(' if (map && length > 0) {') |
Jose Fonseca | d2fb340 | 2015-01-24 13:42:52 +0000 | [diff] [blame] | 586 | self.emit_memcpy('(const char *)map + offset', 'length') |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 587 | print(' }') |
José Fonseca | 77ef0ce | 2012-02-29 18:08:48 +0000 | [diff] [blame] | 588 | if function.name == 'glFlushMappedBufferRangeAPPLE': |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 589 | print(' GLvoid *map = NULL;') |
| 590 | print(' _glGetBufferPointerv(target, GL_BUFFER_MAP_POINTER, &map);') |
| 591 | print(' if (map && size > 0) {') |
José Fonseca | 6f0e303 | 2014-06-25 01:00:35 +0100 | [diff] [blame] | 592 | self.emit_memcpy('(const char *)map + offset', 'size') |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 593 | print(' }') |
José Fonseca | 4920c30 | 2014-08-13 18:35:57 +0100 | [diff] [blame] | 594 | if function.name == 'glFlushMappedNamedBufferRange': |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 595 | print(' GLvoid *map = NULL;') |
| 596 | print(' _glGetNamedBufferPointerv(buffer, GL_BUFFER_MAP_POINTER, &map);') |
| 597 | print(' if (map && length > 0) {') |
José Fonseca | 4920c30 | 2014-08-13 18:35:57 +0100 | [diff] [blame] | 598 | self.emit_memcpy('(const char *)map + offset', 'length') |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 599 | print(' }') |
José Fonseca | fb3bd60 | 2012-01-15 13:56:28 +0000 | [diff] [blame] | 600 | if function.name == 'glFlushMappedNamedBufferRangeEXT': |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 601 | print(' GLvoid *map = NULL;') |
| 602 | print(' _glGetNamedBufferPointervEXT(buffer, GL_BUFFER_MAP_POINTER, &map);') |
| 603 | print(' if (map && length > 0) {') |
José Fonseca | 6f0e303 | 2014-06-25 01:00:35 +0100 | [diff] [blame] | 604 | self.emit_memcpy('(const char *)map + offset', 'length') |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 605 | print(' }') |
José Fonseca | 867b1b7 | 2011-04-24 11:58:04 +0100 | [diff] [blame] | 606 | |
José Fonseca | 3522cbd | 2014-02-28 14:45:32 +0000 | [diff] [blame] | 607 | # FIXME: We don't support coherent/pinned memory mappings |
José Fonseca | 631dbd1 | 2014-12-15 16:34:45 +0000 | [diff] [blame] | 608 | if function.name in ('glBufferStorage', 'glNamedBufferStorage', 'glNamedBufferStorageEXT'): |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 609 | print(r' if (flags & GL_MAP_NOTIFY_EXPLICIT_BIT_VMWX) {') |
| 610 | print(r' if (!(flags & GL_MAP_PERSISTENT_BIT)) {') |
| 611 | print(r' os::log("apitrace: warning: %s: MAP_NOTIFY_EXPLICIT_BIT_VMWX set w/o MAP_PERSISTENT_BIT\n", __FUNCTION__);') |
| 612 | print(r' }') |
| 613 | print(r' if (!(flags & GL_MAP_WRITE_BIT)) {') |
| 614 | print(r' os::log("apitrace: warning: %s: MAP_NOTIFY_EXPLICIT_BIT_VMWX set w/o MAP_WRITE_BIT\n", __FUNCTION__);') |
| 615 | print(r' }') |
| 616 | print(r' flags &= ~GL_MAP_NOTIFY_EXPLICIT_BIT_VMWX;') |
| 617 | print(r' }') |
Jose Fonseca | d2fb340 | 2015-01-24 13:42:52 +0000 | [diff] [blame] | 618 | if function.name in ('glMapBufferRange', 'glMapBufferRangeEXT', 'glMapNamedBufferRange', 'glMapNamedBufferRangeEXT'): |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 619 | print(r' if (access & GL_MAP_NOTIFY_EXPLICIT_BIT_VMWX) {') |
| 620 | print(r' if (!(access & GL_MAP_PERSISTENT_BIT)) {') |
| 621 | print(r' os::log("apitrace: warning: %s: MAP_NOTIFY_EXPLICIT_BIT_VMWX set w/o MAP_PERSISTENT_BIT\n", __FUNCTION__);') |
| 622 | print(r' }') |
| 623 | print(r' if (!(access & GL_MAP_WRITE_BIT)) {') |
| 624 | print(r' os::log("apitrace: warning: %s: MAP_NOTIFY_EXPLICIT_BIT_VMWX set w/o MAP_WRITE_BIT\n", __FUNCTION__);') |
| 625 | print(r' }') |
| 626 | print(r' if (access & GL_MAP_FLUSH_EXPLICIT_BIT) {') |
| 627 | print(r' os::log("apitrace: warning: %s: MAP_NOTIFY_EXPLICIT_BIT_VMWX set w/ MAP_FLUSH_EXPLICIT_BIT\n", __FUNCTION__);') |
| 628 | print(r' }') |
| 629 | print(r' access &= ~GL_MAP_NOTIFY_EXPLICIT_BIT_VMWX;') |
| 630 | print(r' } else if (access & GL_MAP_WRITE_BIT) {') |
| 631 | print(r' if (access & GL_MAP_COHERENT_BIT) {') |
| 632 | print(r' os::log("apitrace: warning: %s: MAP_COHERENT_BIT|MAP_WRITE_BIT unsupported <https://git.io/vV9kM>\n", __FUNCTION__);') |
| 633 | print(r' } else if ((access & GL_MAP_PERSISTENT_BIT) &&') |
| 634 | print(r' !(access & GL_MAP_FLUSH_EXPLICIT_BIT)) {') |
| 635 | print(r' os::log("apitrace: warning: %s: MAP_PERSISTENT_BIT|MAP_WRITE_BIT w/o MAP_FLUSH_EXPLICIT_BIT unsupported <https://git.io/vV9kM>\n", __FUNCTION__);') |
| 636 | print(r' }') |
| 637 | print(r' }') |
José Fonseca | 3522cbd | 2014-02-28 14:45:32 +0000 | [diff] [blame] | 638 | if function.name in ('glBufferData', 'glBufferDataARB'): |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 639 | print(r' if (target == GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD) {') |
| 640 | print(r' os::log("apitrace: warning: GL_AMD_pinned_memory not fully supported\n");') |
| 641 | print(r' }') |
José Fonseca | 3522cbd | 2014-02-28 14:45:32 +0000 | [diff] [blame] | 642 | |
José Fonseca | d0f1e29 | 2014-11-13 13:21:51 +0000 | [diff] [blame] | 643 | # TODO: We don't track GL_INTEL_map_texture mappings |
| 644 | if function.name == 'glMapTexture2DINTEL': |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 645 | print(r' if (access & GL_MAP_WRITE_BIT) {') |
| 646 | print(r' os::log("apitrace: warning: GL_INTEL_map_texture not fully supported\n");') |
| 647 | print(r' }') |
José Fonseca | d0f1e29 | 2014-11-13 13:21:51 +0000 | [diff] [blame] | 648 | |
José Fonseca | 91492d2 | 2011-05-23 21:20:31 +0100 | [diff] [blame] | 649 | # Don't leave vertex attrib locations to chance. Instead emit fake |
| 650 | # glBindAttribLocation calls to ensure that the same locations will be |
| 651 | # used when retracing. Trying to remap locations after the fact would |
| 652 | # be an herculian task given that vertex attrib locations appear in |
| 653 | # many entry-points, including non-shader related ones. |
| 654 | if function.name == 'glLinkProgram': |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 655 | Tracer.invokeFunction(self, function) |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 656 | print(' GLint active_attributes = 0;') |
| 657 | print(' _glGetProgramiv(program, GL_ACTIVE_ATTRIBUTES, &active_attributes);') |
| 658 | print(' for (GLint attrib = 0; attrib < active_attributes; ++attrib) {') |
| 659 | print(' GLint size = 0;') |
| 660 | print(' GLenum type = 0;') |
| 661 | print(' GLchar name[256];') |
José Fonseca | 91492d2 | 2011-05-23 21:20:31 +0100 | [diff] [blame] | 662 | # TODO: Use ACTIVE_ATTRIBUTE_MAX_LENGTH instead of 256 |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 663 | print(' _glGetActiveAttrib(program, attrib, sizeof name, NULL, &size, &type, name);') |
| 664 | print(" if (name[0] != 'g' || name[1] != 'l' || name[2] != '_') {") |
| 665 | print(' GLint location = _glGetAttribLocation(program, name);') |
| 666 | print(' if (location >= 0) {') |
| 667 | print(' _fake_glBindAttribLocation(program, location, name);') |
| 668 | print(' }') |
| 669 | print(' }') |
| 670 | print(' }') |
José Fonseca | 91492d2 | 2011-05-23 21:20:31 +0100 | [diff] [blame] | 671 | if function.name == 'glLinkProgramARB': |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 672 | Tracer.invokeFunction(self, function) |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 673 | print(' GLint active_attributes = 0;') |
| 674 | print(' _glGetObjectParameterivARB(programObj, GL_OBJECT_ACTIVE_ATTRIBUTES_ARB, &active_attributes);') |
| 675 | print(' for (GLint attrib = 0; attrib < active_attributes; ++attrib) {') |
| 676 | print(' GLint size = 0;') |
| 677 | print(' GLenum type = 0;') |
| 678 | print(' GLcharARB name[256];') |
José Fonseca | 91492d2 | 2011-05-23 21:20:31 +0100 | [diff] [blame] | 679 | # TODO: Use ACTIVE_ATTRIBUTE_MAX_LENGTH instead of 256 |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 680 | print(' _glGetActiveAttribARB(programObj, attrib, sizeof name, NULL, &size, &type, name);') |
| 681 | print(" if (name[0] != 'g' || name[1] != 'l' || name[2] != '_') {") |
| 682 | print(' GLint location = _glGetAttribLocationARB(programObj, name);') |
| 683 | print(' if (location >= 0) {') |
| 684 | print(' _fake_glBindAttribLocationARB(programObj, location, name);') |
| 685 | print(' }') |
| 686 | print(' }') |
| 687 | print(' }') |
José Fonseca | 91492d2 | 2011-05-23 21:20:31 +0100 | [diff] [blame] | 688 | |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 689 | Tracer.traceFunctionImplBody(self, function) |
José Fonseca | 7337360 | 2011-05-20 17:45:26 +0100 | [diff] [blame] | 690 | |
Peter Lohrmann | 0b5b75e | 2013-06-03 14:58:41 -0700 | [diff] [blame] | 691 | # These entrypoints are only expected to be implemented by tools; |
| 692 | # drivers will probably not implement them. |
José Fonseca | f028a8f | 2012-02-15 23:33:35 +0000 | [diff] [blame] | 693 | marker_functions = [ |
| 694 | # GL_GREMEDY_string_marker |
José Fonseca | 8f34d34 | 2011-07-15 20:16:40 +0100 | [diff] [blame] | 695 | 'glStringMarkerGREMEDY', |
José Fonseca | f028a8f | 2012-02-15 23:33:35 +0000 | [diff] [blame] | 696 | # GL_GREMEDY_frame_terminator |
José Fonseca | 8f34d34 | 2011-07-15 20:16:40 +0100 | [diff] [blame] | 697 | 'glFrameTerminatorGREMEDY', |
| 698 | ] |
| 699 | |
Peter Lohrmann | 0b5b75e | 2013-06-03 14:58:41 -0700 | [diff] [blame] | 700 | # These entrypoints may be implemented by drivers, but are also very useful |
| 701 | # for debugging / analysis tools. |
| 702 | debug_functions = [ |
| 703 | # GL_KHR_debug |
| 704 | 'glDebugMessageControl', |
| 705 | 'glDebugMessageInsert', |
| 706 | 'glDebugMessageCallback', |
| 707 | 'glGetDebugMessageLog', |
| 708 | 'glPushDebugGroup', |
| 709 | 'glPopDebugGroup', |
| 710 | 'glObjectLabel', |
| 711 | 'glGetObjectLabel', |
| 712 | 'glObjectPtrLabel', |
| 713 | 'glGetObjectPtrLabel', |
Jose Fonseca | e01aa3b | 2015-06-27 11:07:05 +0100 | [diff] [blame] | 714 | # GL_KHR_debug (for OpenGL ES) |
| 715 | 'glDebugMessageControlKHR', |
| 716 | 'glDebugMessageInsertKHR', |
| 717 | 'glDebugMessageCallbackKHR', |
| 718 | 'glGetDebugMessageLogKHR', |
| 719 | 'glPushDebugGroupKHR', |
| 720 | 'glPopDebugGroupKHR', |
| 721 | 'glObjectLabelKHR', |
| 722 | 'glGetObjectLabelKHR', |
| 723 | 'glObjectPtrLabelKHR', |
| 724 | 'glGetObjectPtrLabelKHR', |
Peter Lohrmann | 0b5b75e | 2013-06-03 14:58:41 -0700 | [diff] [blame] | 725 | # GL_ARB_debug_output |
| 726 | 'glDebugMessageControlARB', |
| 727 | 'glDebugMessageInsertARB', |
| 728 | 'glDebugMessageCallbackARB', |
| 729 | 'glGetDebugMessageLogARB', |
| 730 | # GL_AMD_debug_output |
| 731 | 'glDebugMessageEnableAMD', |
| 732 | 'glDebugMessageInsertAMD', |
| 733 | 'glDebugMessageCallbackAMD', |
| 734 | 'glGetDebugMessageLogAMD', |
José Fonseca | 71f5a35 | 2014-07-28 12:19:50 +0100 | [diff] [blame] | 735 | # GL_EXT_debug_label |
| 736 | 'glLabelObjectEXT', |
| 737 | 'glGetObjectLabelEXT', |
| 738 | # GL_EXT_debug_marker |
| 739 | 'glInsertEventMarkerEXT', |
| 740 | 'glPushGroupMarkerEXT', |
| 741 | 'glPopGroupMarkerEXT', |
Peter Lohrmann | 0b5b75e | 2013-06-03 14:58:41 -0700 | [diff] [blame] | 742 | ] |
| 743 | |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 744 | def invokeFunction(self, function): |
José Fonseca | 91492d2 | 2011-05-23 21:20:31 +0100 | [diff] [blame] | 745 | if function.name in ('glLinkProgram', 'glLinkProgramARB'): |
| 746 | # These functions have been dispatched already |
| 747 | return |
| 748 | |
José Fonseca | e0c55fd | 2015-01-26 22:46:13 +0000 | [diff] [blame] | 749 | # Force glProgramBinary to fail. Per ARB_get_program_binary this |
| 750 | # should signal the app that it needs to recompile. |
| 751 | if function.name in ('glProgramBinary', 'glProgramBinaryOES'): |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 752 | print(r' binaryFormat = 0xDEADDEAD;') |
| 753 | print(r' binary = &binaryFormat;') |
| 754 | print(r' length = sizeof binaryFormat;') |
José Fonseca | e0c55fd | 2015-01-26 22:46:13 +0000 | [diff] [blame] | 755 | |
José Fonseca | 2cfa02c | 2013-06-10 08:05:29 +0100 | [diff] [blame] | 756 | Tracer.invokeFunction(self, function) |
| 757 | |
| 758 | def doInvokeFunction(self, function): |
| 759 | # Same as invokeFunction() but called both when trace is enabled or disabled. |
| 760 | # |
| 761 | # Used to modify the behavior of GL entry-points. |
| 762 | |
| 763 | # Override GL extensions |
| 764 | if function.name in ('glGetString', 'glGetIntegerv', 'glGetStringi'): |
| 765 | Tracer.doInvokeFunction(self, function, prefix = 'gltrace::_', suffix = '_override') |
| 766 | return |
| 767 | |
José Fonseca | 71f5a35 | 2014-07-28 12:19:50 +0100 | [diff] [blame] | 768 | # We implement GL_GREMEDY_*, etc., and not the driver |
José Fonseca | f028a8f | 2012-02-15 23:33:35 +0000 | [diff] [blame] | 769 | if function.name in self.marker_functions: |
José Fonseca | 8f34d34 | 2011-07-15 20:16:40 +0100 | [diff] [blame] | 770 | return |
| 771 | |
Peter Lohrmann | 9d9eb81 | 2013-07-12 16:15:25 -0400 | [diff] [blame] | 772 | # We may be faking KHR_debug, so ensure the pointer queries result is |
| 773 | # always zeroed to prevent dereference of unitialized pointers |
| 774 | if function.name == 'glGetPointerv': |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 775 | print(' if (params &&') |
| 776 | print(' (pname == GL_DEBUG_CALLBACK_FUNCTION ||') |
| 777 | print(' pname == GL_DEBUG_CALLBACK_USER_PARAM)) {') |
| 778 | print(' *params = NULL;') |
| 779 | print(' }') |
Peter Lohrmann | 9d9eb81 | 2013-07-12 16:15:25 -0400 | [diff] [blame] | 780 | |
José Fonseca | 2cfa02c | 2013-06-10 08:05:29 +0100 | [diff] [blame] | 781 | if function.name in self.getProcAddressFunctionNames: |
José Fonseca | 631dbd1 | 2014-12-15 16:34:45 +0000 | [diff] [blame] | 782 | nameArg = function.args[0].name |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 783 | print(' if (strcmp("glNotifyMappedBufferRangeVMWX", (const char *)%s) == 0) {' % (nameArg,)) |
| 784 | print(' _result = (%s)&glNotifyMappedBufferRangeVMWX;' % (function.type,)) |
José Fonseca | f028a8f | 2012-02-15 23:33:35 +0000 | [diff] [blame] | 785 | for marker_function in self.marker_functions: |
José Fonseca | 1b6c875 | 2012-04-15 14:33:00 +0100 | [diff] [blame] | 786 | if self.api.getFunctionByName(marker_function): |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 787 | print(' } else if (strcmp("%s", (const char *)%s) == 0) {' % (marker_function, nameArg)) |
| 788 | print(' _result = (%s)&%s;' % (function.type, marker_function)) |
| 789 | print(' } else {') |
José Fonseca | 2cfa02c | 2013-06-10 08:05:29 +0100 | [diff] [blame] | 790 | Tracer.doInvokeFunction(self, function) |
| 791 | |
| 792 | # Replace function addresses with ours |
| 793 | # XXX: Doing this here instead of wrapRet means that the trace will |
| 794 | # contain the addresses of the wrapper functions, and not the real |
| 795 | # functions, but in practice this should make no difference. |
| 796 | if function.name in self.getProcAddressFunctionNames: |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 797 | print(' _result = _wrapProcAddress(%s, _result);' % (nameArg,)) |
José Fonseca | 2cfa02c | 2013-06-10 08:05:29 +0100 | [diff] [blame] | 798 | |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 799 | print(' }') |
José Fonseca | 1b3d375 | 2011-07-15 10:15:19 +0100 | [diff] [blame] | 800 | return |
| 801 | |
José Fonseca | e0c55fd | 2015-01-26 22:46:13 +0000 | [diff] [blame] | 802 | if function.name in ('glGetProgramBinary', 'glGetProgramBinaryOES'): |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 803 | print(r' bufSize = 0;') |
José Fonseca | e0c55fd | 2015-01-26 22:46:13 +0000 | [diff] [blame] | 804 | |
José Fonseca | 2cfa02c | 2013-06-10 08:05:29 +0100 | [diff] [blame] | 805 | Tracer.doInvokeFunction(self, function) |
José Fonseca | 91492d2 | 2011-05-23 21:20:31 +0100 | [diff] [blame] | 806 | |
José Fonseca | e0c55fd | 2015-01-26 22:46:13 +0000 | [diff] [blame] | 807 | if function.name == 'glGetProgramiv': |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 808 | print(r' if (params && pname == GL_PROGRAM_BINARY_LENGTH) {') |
| 809 | print(r' *params = 0;') |
| 810 | print(r' }') |
José Fonseca | e0c55fd | 2015-01-26 22:46:13 +0000 | [diff] [blame] | 811 | if function.name in ('glGetProgramBinary', 'glGetProgramBinaryOES'): |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 812 | print(r' if (length) {') |
| 813 | print(r' *length = 0;') |
| 814 | print(r' }') |
José Fonseca | e0c55fd | 2015-01-26 22:46:13 +0000 | [diff] [blame] | 815 | |
José Fonseca | 867b1b7 | 2011-04-24 11:58:04 +0100 | [diff] [blame] | 816 | buffer_targets = [ |
| 817 | 'ARRAY_BUFFER', |
| 818 | 'ELEMENT_ARRAY_BUFFER', |
| 819 | 'PIXEL_PACK_BUFFER', |
| 820 | 'PIXEL_UNPACK_BUFFER', |
José Fonseca | 7b20d67 | 2012-01-10 19:13:58 +0000 | [diff] [blame] | 821 | 'UNIFORM_BUFFER', |
| 822 | 'TEXTURE_BUFFER', |
| 823 | 'TRANSFORM_FEEDBACK_BUFFER', |
| 824 | 'COPY_READ_BUFFER', |
| 825 | 'COPY_WRITE_BUFFER', |
| 826 | 'DRAW_INDIRECT_BUFFER', |
| 827 | 'ATOMIC_COUNTER_BUFFER', |
José Fonseca | 867b1b7 | 2011-04-24 11:58:04 +0100 | [diff] [blame] | 828 | ] |
| 829 | |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 830 | def wrapRet(self, function, instance): |
| 831 | Tracer.wrapRet(self, function, instance) |
José Fonseca | 1b3d375 | 2011-07-15 10:15:19 +0100 | [diff] [blame] | 832 | |
José Fonseca | cdc322c | 2012-02-29 19:29:51 +0000 | [diff] [blame] | 833 | # Keep track of buffer mappings |
Jose Fonseca | d2fb340 | 2015-01-24 13:42:52 +0000 | [diff] [blame] | 834 | if function.name in ('glMapBufferRange', 'glMapBufferRangeEXT'): |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 835 | print(' if (access & GL_MAP_WRITE_BIT) {') |
| 836 | print(' _checkBufferMapRange = true;') |
| 837 | print(' }') |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 838 | |
José Fonseca | c9f1223 | 2011-03-25 20:07:42 +0000 | [diff] [blame] | 839 | boolean_names = [ |
| 840 | 'GL_FALSE', |
| 841 | 'GL_TRUE', |
| 842 | ] |
| 843 | |
| 844 | def gl_boolean(self, value): |
| 845 | return self.boolean_names[int(bool(value))] |
| 846 | |
José Fonseca | a442a46 | 2014-11-12 21:16:22 +0000 | [diff] [blame] | 847 | # Regular expression for the names of the functions that unpack from a |
| 848 | # pixel buffer object. See the ARB_pixel_buffer_object specification. |
| 849 | unpack_function_regex = re.compile(r'^gl(' + r'|'.join([ |
| 850 | r'Bitmap', |
| 851 | r'PolygonStipple', |
| 852 | r'PixelMap[a-z]+v', |
| 853 | r'DrawPixels', |
| 854 | r'Color(Sub)?Table', |
| 855 | r'(Convolution|Separable)Filter[12]D', |
| 856 | r'(Compressed)?(Multi)?Tex(ture)?(Sub)?Image[1-4]D', |
| 857 | ]) + r')[0-9A-Z]*$') |
José Fonseca | e97bab9 | 2011-06-02 23:15:11 +0100 | [diff] [blame] | 858 | |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 859 | def serializeArgValue(self, function, arg): |
José Fonseca | e97bab9 | 2011-06-02 23:15:11 +0100 | [diff] [blame] | 860 | # Recognize offsets instead of blobs when a PBO is bound |
José Fonseca | a442a46 | 2014-11-12 21:16:22 +0000 | [diff] [blame] | 861 | if self.unpack_function_regex.match(function.name) \ |
José Fonseca | e97bab9 | 2011-06-02 23:15:11 +0100 | [diff] [blame] | 862 | and (isinstance(arg.type, stdapi.Blob) \ |
| 863 | or (isinstance(arg.type, stdapi.Const) \ |
| 864 | and isinstance(arg.type.type, stdapi.Blob))): |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 865 | print(' {') |
| 866 | print(' gltrace::Context *_ctx = gltrace::getContext();') |
| 867 | print(' GLint _unpack_buffer = 0;') |
| 868 | print(' if (_ctx->features.pixel_buffer_object)') |
| 869 | print(' _glGetIntegerv(GL_PIXEL_UNPACK_BUFFER_BINDING, &_unpack_buffer);') |
| 870 | print(' if (_unpack_buffer) {') |
| 871 | print(' trace::localWriter.writePointer((uintptr_t)%s);' % arg.name) |
| 872 | print(' } else {') |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 873 | Tracer.serializeArgValue(self, function, arg) |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 874 | print(' }') |
| 875 | print(' }') |
José Fonseca | e97bab9 | 2011-06-02 23:15:11 +0100 | [diff] [blame] | 876 | return |
| 877 | |
Jose Fonseca | 0a676c5 | 2016-04-04 23:24:32 +0100 | [diff] [blame] | 878 | # Recognize offsets instead of pointers when query buffer is bound |
| 879 | if function.name.startswith('glGetQueryObject') and arg.output: |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 880 | print(r' gltrace::Context *_ctx = gltrace::getContext();') |
| 881 | print(r' GLint _query_buffer = 0;') |
| 882 | print(r' if (_ctx->features.query_buffer_object) {') |
| 883 | print(r' _query_buffer = _glGetInteger(GL_QUERY_BUFFER_BINDING);') |
| 884 | print(r' }') |
| 885 | print(r' if (_query_buffer) {') |
| 886 | print(r' trace::localWriter.writePointer((uintptr_t)%s);' % arg.name) |
| 887 | print(r' } else {') |
Jose Fonseca | 0a676c5 | 2016-04-04 23:24:32 +0100 | [diff] [blame] | 888 | Tracer.serializeArgValue(self, function, arg) |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 889 | print(r' }') |
Jose Fonseca | 0a676c5 | 2016-04-04 23:24:32 +0100 | [diff] [blame] | 890 | return |
| 891 | |
José Fonseca | a3f89ae | 2011-04-26 08:50:32 +0100 | [diff] [blame] | 892 | # Several GL state functions take GLenum symbolic names as |
| 893 | # integer/floats; so dump the symbolic name whenever possible |
José Fonseca | 3bcb33c | 2011-05-27 20:14:31 +0100 | [diff] [blame] | 894 | if function.name.startswith('gl') \ |
José Fonseca | e357109 | 2011-10-13 08:26:27 +0100 | [diff] [blame] | 895 | and arg.type in (glapi.GLint, glapi.GLfloat, glapi.GLdouble) \ |
José Fonseca | 3bcb33c | 2011-05-27 20:14:31 +0100 | [diff] [blame] | 896 | and arg.name == 'param': |
José Fonseca | a3f89ae | 2011-04-26 08:50:32 +0100 | [diff] [blame] | 897 | assert arg.index > 0 |
| 898 | assert function.args[arg.index - 1].name == 'pname' |
| 899 | assert function.args[arg.index - 1].type == glapi.GLenum |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 900 | print(' if (is_symbolic_pname(pname) && is_symbolic_param(%s)) {' % arg.name) |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 901 | self.serializeValue(glapi.GLenum, arg.name) |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 902 | print(' } else {') |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 903 | Tracer.serializeArgValue(self, function, arg) |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 904 | print(' }') |
José Fonseca | a3f89ae | 2011-04-26 08:50:32 +0100 | [diff] [blame] | 905 | return |
| 906 | |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 907 | Tracer.serializeArgValue(self, function, arg) |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 908 | |
Jose Fonseca | 27b8d81 | 2016-05-13 07:09:09 -0700 | [diff] [blame] | 909 | fake_function_names = [ |
| 910 | 'glBindAttribLocation', |
| 911 | 'glBindAttribLocationARB', |
| 912 | 'glBindBuffer', |
| 913 | 'glBitmap', |
| 914 | 'glClientActiveTexture', |
| 915 | 'glDisableClientState', |
| 916 | 'glEnableClientState', |
| 917 | 'glEndList', |
| 918 | 'glNewList', |
| 919 | 'glScissor', |
| 920 | 'glStringMarkerGREMEDY', |
| 921 | 'glTexImage2D', |
| 922 | 'glViewport', |
| 923 | ] |
| 924 | |
José Fonseca | 4c938c2 | 2011-04-30 22:44:38 +0100 | [diff] [blame] | 925 | def footer(self, api): |
| 926 | Tracer.footer(self, api) |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 927 | |
Jose Fonseca | 27b8d81 | 2016-05-13 07:09:09 -0700 | [diff] [blame] | 928 | # Generate helper functions to emit fake function calls into the trace |
| 929 | for function in api.getAllFunctions(): |
| 930 | if function.name in self.fake_function_names: |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 931 | print(function.prototype('_fake_' + function.name)) |
| 932 | print(r'{') |
Jose Fonseca | 27b8d81 | 2016-05-13 07:09:09 -0700 | [diff] [blame] | 933 | self.fake_call(function, function.argNames()) |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 934 | print(r'}') |
| 935 | print() |
Jose Fonseca | 27b8d81 | 2016-05-13 07:09:09 -0700 | [diff] [blame] | 936 | |
José Fonseca | 4c938c2 | 2011-04-30 22:44:38 +0100 | [diff] [blame] | 937 | # A simple state tracker to track the pointer values |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 938 | # update the state |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 939 | print('static void _trace_user_arrays(gltrace::Context *_ctx, GLuint count)') |
| 940 | print('{') |
| 941 | print(' glfeatures::Profile profile = _ctx->profile;') |
| 942 | print(' bool es1 = profile.es() && profile.major == 1;') |
| 943 | print() |
José Fonseca | 8d1408b | 2014-02-03 19:57:18 +0000 | [diff] [blame] | 944 | |
Jose Fonseca | 97d22a7 | 2016-05-10 04:47:08 -0700 | [diff] [blame] | 945 | # Some apps, in particular Quake3, can tell the driver to lock more |
| 946 | # vertices than those actually required for the draw call. |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 947 | print(' count = std::max(count, _ctx->lockedArrayCount);') |
| 948 | print() |
Jose Fonseca | 97d22a7 | 2016-05-10 04:47:08 -0700 | [diff] [blame] | 949 | |
José Fonseca | 8d1408b | 2014-02-03 19:57:18 +0000 | [diff] [blame] | 950 | # Temporarily unbind the array buffer |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 951 | print(' GLint _array_buffer = _glGetInteger(GL_ARRAY_BUFFER_BINDING);') |
| 952 | print(' if (_array_buffer) {') |
| 953 | print(' _fake_glBindBuffer(GL_ARRAY_BUFFER, 0);') |
| 954 | print(' }') |
| 955 | print() |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 956 | |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 957 | for camelcase_name, uppercase_name in self.arrays: |
Chia-I Wu | b3d218d | 2011-11-03 01:37:36 +0800 | [diff] [blame] | 958 | # in which profile is the array available? |
José Fonseca | 34ea616 | 2015-01-08 23:45:43 +0000 | [diff] [blame] | 959 | profile_check = 'profile.desktop()' |
Chia-I Wu | b3d218d | 2011-11-03 01:37:36 +0800 | [diff] [blame] | 960 | if camelcase_name in self.arrays_es1: |
José Fonseca | b0c5972 | 2015-01-05 20:45:41 +0000 | [diff] [blame] | 961 | profile_check = '(' + profile_check + ' || es1)'; |
Chia-I Wu | b3d218d | 2011-11-03 01:37:36 +0800 | [diff] [blame] | 962 | |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 963 | function_name = 'gl%sPointer' % camelcase_name |
| 964 | enable_name = 'GL_%s_ARRAY' % uppercase_name |
| 965 | binding_name = 'GL_%s_ARRAY_BUFFER_BINDING' % uppercase_name |
José Fonseca | 1b6c875 | 2012-04-15 14:33:00 +0100 | [diff] [blame] | 966 | function = api.getFunctionByName(function_name) |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 967 | |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 968 | print(' // %s' % function.prototype()) |
| 969 | print(' if (%s) {' % profile_check) |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 970 | self.array_trace_prolog(api, uppercase_name) |
| 971 | self.array_prolog(api, uppercase_name) |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 972 | print(' if (_glIsEnabled(%s)) {' % enable_name) |
| 973 | print(' GLint _binding = _glGetInteger(%s);' % binding_name) |
| 974 | print(' if (!_binding) {') |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 975 | |
| 976 | # Get the arguments via glGet* |
| 977 | for arg in function.args: |
| 978 | arg_get_enum = 'GL_%s_ARRAY_%s' % (uppercase_name, arg.name.upper()) |
| 979 | arg_get_function, arg_type = TypeGetter().visit(arg.type) |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 980 | print(' %s %s = 0;' % (arg_type, arg.name)) |
| 981 | print(' _%s(%s, &%s);' % (arg_get_function, arg_get_enum, arg.name)) |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 982 | |
| 983 | arg_names = ', '.join([arg.name for arg in function.args[:-1]]) |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 984 | print(' size_t _size = _%s_size(%s, count);' % (function.name, arg_names)) |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 985 | |
| 986 | # Emit a fake function |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 987 | self.array_trace_intermezzo(api, uppercase_name) |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 988 | print(' unsigned _call = trace::localWriter.beginEnter(&_%s_sig, true);' % (function.name,)) |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 989 | for arg in function.args: |
| 990 | assert not arg.output |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 991 | print(' trace::localWriter.beginArg(%u);' % (arg.index,)) |
José Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 992 | if arg.name != 'pointer': |
José Fonseca | 54f304a | 2012-01-14 19:33:08 +0000 | [diff] [blame] | 993 | self.serializeValue(arg.type, arg.name) |
José Fonseca | 14c21bc | 2011-02-20 23:32:22 +0000 | [diff] [blame] | 994 | else: |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 995 | print(' trace::localWriter.writeBlob((const void *)%s, _size);' % (arg.name)) |
| 996 | print(' trace::localWriter.endArg();') |
José Fonseca | 9922183 | 2011-03-22 22:15:46 +0000 | [diff] [blame] | 997 | |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 998 | print(' trace::localWriter.endEnter();') |
| 999 | print(' trace::localWriter.beginLeave(_call);') |
| 1000 | print(' trace::localWriter.endLeave();') |
| 1001 | print(' }') |
| 1002 | print(' }') |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 1003 | self.array_epilog(api, uppercase_name) |
| 1004 | self.array_trace_epilog(api, uppercase_name) |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 1005 | print(' }') |
| 1006 | print() |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 1007 | |
José Fonseca | 1601c41 | 2011-05-10 10:38:19 +0100 | [diff] [blame] | 1008 | # Samething, but for glVertexAttribPointer* |
| 1009 | # |
| 1010 | # Some variants of glVertexAttribPointer alias conventional and generic attributes: |
| 1011 | # - glVertexAttribPointer: no |
| 1012 | # - glVertexAttribPointerARB: implementation dependent |
| 1013 | # - glVertexAttribPointerNV: yes |
| 1014 | # |
| 1015 | # This means that the implementations of these functions do not always |
| 1016 | # alias, and they need to be considered independently. |
| 1017 | # |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 1018 | print(' // ES1 does not support generic vertex attributes') |
| 1019 | print(' if (es1)') |
| 1020 | print(' return;') |
| 1021 | print() |
Jose Fonseca | ef45b1f | 2016-05-08 23:31:24 +0100 | [diff] [blame] | 1022 | |
| 1023 | function_name = 'glVertexAttribPointer' |
| 1024 | function = api.getFunctionByName(function_name) |
| 1025 | |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 1026 | print(' // %s' % function.prototype()) |
| 1027 | print(' GLint _max_vertex_attribs = _glGetInteger(GL_MAX_VERTEX_ATTRIBS);') |
| 1028 | print(' for (GLint index = 0; index < _max_vertex_attribs; ++index) {') |
| 1029 | print(' GLint _enabled = 0;') |
| 1030 | print(' _glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &_enabled);') |
| 1031 | print(' if (_enabled) {') |
| 1032 | print(' GLint _binding = 0;') |
| 1033 | print(' _glGetVertexAttribiv(index, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, &_binding);') |
| 1034 | print(' if (!_binding) {') |
Jose Fonseca | ef45b1f | 2016-05-08 23:31:24 +0100 | [diff] [blame] | 1035 | |
| 1036 | # Get the arguments via glGet* |
| 1037 | for arg in function.args[1:]: |
| 1038 | arg_get_enum = 'GL_VERTEX_ATTRIB_ARRAY_%s' % (arg.name.upper()) |
| 1039 | arg_get_function, arg_type = TypeGetter('glGetVertexAttrib', False).visit(arg.type) |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 1040 | print(' %s %s = 0;' % (arg_type, arg.name)) |
| 1041 | print(' _%s(index, %s, &%s);' % (arg_get_function, arg_get_enum, arg.name)) |
Jose Fonseca | ef45b1f | 2016-05-08 23:31:24 +0100 | [diff] [blame] | 1042 | |
| 1043 | arg_names = ', '.join([arg.name for arg in function.args[1:-1]]) |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 1044 | print(' size_t _size = _%s_size(%s, count);' % (function.name, arg_names)) |
Jose Fonseca | ef45b1f | 2016-05-08 23:31:24 +0100 | [diff] [blame] | 1045 | |
| 1046 | # Emit a fake function |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 1047 | print(' unsigned _call = trace::localWriter.beginEnter(&_%s_sig, true);' % (function.name,)) |
Jose Fonseca | ef45b1f | 2016-05-08 23:31:24 +0100 | [diff] [blame] | 1048 | for arg in function.args: |
| 1049 | assert not arg.output |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 1050 | print(' trace::localWriter.beginArg(%u);' % (arg.index,)) |
Jose Fonseca | ef45b1f | 2016-05-08 23:31:24 +0100 | [diff] [blame] | 1051 | if arg.name != 'pointer': |
| 1052 | self.serializeValue(arg.type, arg.name) |
| 1053 | else: |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 1054 | print(' trace::localWriter.writeBlob((const void *)%s, _size);' % (arg.name)) |
| 1055 | print(' trace::localWriter.endArg();') |
Jose Fonseca | ef45b1f | 2016-05-08 23:31:24 +0100 | [diff] [blame] | 1056 | |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 1057 | print(' trace::localWriter.endEnter();') |
| 1058 | print(' trace::localWriter.beginLeave(_call);') |
| 1059 | print(' trace::localWriter.endLeave();') |
| 1060 | print(' }') |
| 1061 | print(' }') |
| 1062 | print(' }') |
| 1063 | print() |
José Fonseca | 1a2fdd2 | 2011-04-01 00:55:09 +0100 | [diff] [blame] | 1064 | |
José Fonseca | 8d1408b | 2014-02-03 19:57:18 +0000 | [diff] [blame] | 1065 | # Restore the original array_buffer |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 1066 | print(' if (_array_buffer) {') |
| 1067 | print(' _fake_glBindBuffer(GL_ARRAY_BUFFER, _array_buffer);') |
| 1068 | print(' }') |
| 1069 | print() |
José Fonseca | 8d1408b | 2014-02-03 19:57:18 +0000 | [diff] [blame] | 1070 | |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 1071 | print('}') |
| 1072 | print() |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 1073 | |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 1074 | # |
| 1075 | # Hooks for glTexCoordPointer, which is identical to the other array |
| 1076 | # pointers except the fact that it is indexed by glClientActiveTexture. |
| 1077 | # |
| 1078 | |
| 1079 | def array_prolog(self, api, uppercase_name): |
| 1080 | if uppercase_name == 'TEXTURE_COORD': |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 1081 | print(' GLint max_units = 0;') |
| 1082 | print(' if (_ctx->profile.desktop())') |
| 1083 | print(' _glGetIntegerv(GL_MAX_TEXTURE_COORDS, &max_units);') |
| 1084 | print(' else') |
| 1085 | print(' _glGetIntegerv(GL_MAX_TEXTURE_UNITS, &max_units);') |
| 1086 | print(' GLint client_active_texture = GL_TEXTURE0;') |
| 1087 | print(' if (max_units > 0) {') |
| 1088 | print(' _glGetIntegerv(GL_CLIENT_ACTIVE_TEXTURE, &client_active_texture);') |
| 1089 | print(' }') |
| 1090 | print(' GLint unit = 0;') |
| 1091 | print(' do {') |
| 1092 | print(' GLint texture = GL_TEXTURE0 + unit;') |
| 1093 | print(' if (max_units > 0) {') |
| 1094 | print(' _glClientActiveTexture(texture);') |
| 1095 | print(' }') |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 1096 | |
| 1097 | def array_trace_prolog(self, api, uppercase_name): |
| 1098 | if uppercase_name == 'TEXTURE_COORD': |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 1099 | print(' bool client_active_texture_dirty = false;') |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 1100 | |
| 1101 | def array_epilog(self, api, uppercase_name): |
| 1102 | if uppercase_name == 'TEXTURE_COORD': |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 1103 | print(' } while (++unit < max_units);') |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 1104 | self.array_cleanup(api, uppercase_name) |
| 1105 | |
| 1106 | def array_cleanup(self, api, uppercase_name): |
| 1107 | if uppercase_name == 'TEXTURE_COORD': |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 1108 | print(' if (max_units > 0) {') |
| 1109 | print(' _glClientActiveTexture(client_active_texture);') |
| 1110 | print(' }') |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 1111 | |
| 1112 | def array_trace_intermezzo(self, api, uppercase_name): |
| 1113 | if uppercase_name == 'TEXTURE_COORD': |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 1114 | print(' if (texture != client_active_texture || client_active_texture_dirty) {') |
| 1115 | print(' client_active_texture_dirty = true;') |
| 1116 | print(' _fake_glClientActiveTexture(texture);') |
| 1117 | print(' }') |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 1118 | |
| 1119 | def array_trace_epilog(self, api, uppercase_name): |
| 1120 | if uppercase_name == 'TEXTURE_COORD': |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 1121 | print(' if (client_active_texture_dirty) {') |
| 1122 | print(' _fake_glClientActiveTexture(client_active_texture);') |
| 1123 | print(' }') |
José Fonseca | fb6744f | 2011-04-15 11:18:37 +0100 | [diff] [blame] | 1124 | |
José Fonseca | 151c370 | 2013-05-10 08:28:15 +0100 | [diff] [blame] | 1125 | def emitFakeTexture2D(self): |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 1126 | print(r' _fake_glTexImage2D(target, level, internalformat, width, height, border, format, type, pixels);') |
José Fonseca | 669b122 | 2011-02-20 09:05:10 +0000 | [diff] [blame] | 1127 | |