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