Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Mesa 3-D graphics library |
Brian Paul | 514a15c | 2006-03-15 20:56:22 +0000 | [diff] [blame] | 3 | * Version: 6.5 |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 4 | * |
Brian Paul | 514a15c | 2006-03-15 20:56:22 +0000 | [diff] [blame] | 5 | * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 6 | * |
| 7 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 8 | * copy of this software and associated documentation files (the "Software"), |
| 9 | * to deal in the Software without restriction, including without limitation |
| 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 11 | * and/or sell copies of the Software, and to permit persons to whom the |
| 12 | * Software is furnished to do so, subject to the following conditions: |
| 13 | * |
| 14 | * The above copyright notice and this permission notice shall be included |
| 15 | * in all copies or substantial portions of the Software. |
| 16 | * |
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 20 | * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 21 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 23 | */ |
| 24 | |
| 25 | |
Brian Paul | 7e1161b | 1999-11-25 18:17:04 +0000 | [diff] [blame] | 26 | /* |
| 27 | * This file manages the OpenGL API dispatch layer. |
| 28 | * The dispatch table (struct _glapi_table) is basically just a list |
| 29 | * of function pointers. |
| 30 | * There are functions to set/get the current dispatch table for the |
| 31 | * current thread and to manage registration/dispatch of dynamically |
| 32 | * added extension functions. |
Brian Paul | 9f94399 | 2000-01-28 19:03:33 +0000 | [diff] [blame] | 33 | * |
| 34 | * It's intended that this file and the other glapi*.[ch] files are |
| 35 | * flexible enough to be reused in several places: XFree86, DRI- |
| 36 | * based libGL.so, and perhaps the SGI SI. |
| 37 | * |
Brian Paul | 4e9676f | 2002-06-29 19:48:15 +0000 | [diff] [blame] | 38 | * NOTE: There are no dependencies on Mesa in this code. |
Brian Paul | ab0c886 | 2001-01-23 23:35:47 +0000 | [diff] [blame] | 39 | * |
| 40 | * Versions (API changes): |
| 41 | * 2000/02/23 - original version for Mesa 3.3 and XFree86 4.0 |
| 42 | * 2001/01/16 - added dispatch override feature for Mesa 3.5 |
Brian Paul | 4e9676f | 2002-06-29 19:48:15 +0000 | [diff] [blame] | 43 | * 2002/06/28 - added _glapi_set_warning_func(), Mesa 4.1. |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 44 | * 2002/10/01 - _glapi_get_proc_address() will now generate new entrypoints |
| 45 | * itself (using offset ~0). _glapi_add_entrypoint() can be |
| 46 | * called afterward and it'll fill in the correct dispatch |
| 47 | * offset. This allows DRI libGL to avoid probing for DRI |
| 48 | * drivers! No changes to the public glapi interface. |
Brian Paul | 7e1161b | 1999-11-25 18:17:04 +0000 | [diff] [blame] | 49 | */ |
| 50 | |
| 51 | |
| 52 | |
Brian Paul | 3c27be3 | 2000-02-10 21:27:48 +0000 | [diff] [blame] | 53 | #include "glheader.h" |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 54 | #include "glapi.h" |
Brian Paul | 0c239fc | 1999-12-16 12:38:11 +0000 | [diff] [blame] | 55 | #include "glapioffsets.h" |
| 56 | #include "glapitable.h" |
Brian Paul | bb72d32 | 1999-12-16 17:31:59 +0000 | [diff] [blame] | 57 | |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 58 | /***** BEGIN NO-OP DISPATCH *****/ |
| 59 | |
| 60 | static GLboolean WarnFlag = GL_FALSE; |
Brian Paul | 4e9676f | 2002-06-29 19:48:15 +0000 | [diff] [blame] | 61 | static _glapi_warning_func warning_func; |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 62 | |
Kristian Høgsberg | 3a6d968 | 2006-03-29 22:32:38 +0000 | [diff] [blame] | 63 | #if defined(PTHREADS) || defined(GLX_USE_TLS) |
Ian Romanick | 25fe93f | 2005-04-13 20:59:15 +0000 | [diff] [blame] | 64 | static void init_glapi_relocs(void); |
Kristian Høgsberg | 3a6d968 | 2006-03-29 22:32:38 +0000 | [diff] [blame] | 65 | #endif |
Ian Romanick | 25fe93f | 2005-04-13 20:59:15 +0000 | [diff] [blame] | 66 | |
| 67 | static _glapi_proc generate_entrypoint(GLuint functionOffset); |
| 68 | static void fill_in_entrypoint_offset(_glapi_proc entrypoint, GLuint offset); |
Brian Paul | 4e9676f | 2002-06-29 19:48:15 +0000 | [diff] [blame] | 69 | |
| 70 | /* |
| 71 | * Enable/disable printing of warning messages. |
| 72 | */ |
Adam Jackson | 791ce02 | 2004-12-15 23:14:29 +0000 | [diff] [blame] | 73 | PUBLIC void |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 74 | _glapi_noop_enable_warnings(GLboolean enable) |
| 75 | { |
| 76 | WarnFlag = enable; |
| 77 | } |
| 78 | |
Brian Paul | 4e9676f | 2002-06-29 19:48:15 +0000 | [diff] [blame] | 79 | /* |
| 80 | * Register a callback function for reporting errors. |
| 81 | */ |
Adam Jackson | 791ce02 | 2004-12-15 23:14:29 +0000 | [diff] [blame] | 82 | PUBLIC void |
Brian Paul | 4e9676f | 2002-06-29 19:48:15 +0000 | [diff] [blame] | 83 | _glapi_set_warning_func( _glapi_warning_func func ) |
| 84 | { |
| 85 | warning_func = func; |
| 86 | } |
| 87 | |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 88 | static GLboolean |
| 89 | warn(void) |
| 90 | { |
Ben Crossman | d8aa5ff | 2005-04-15 09:13:21 +0000 | [diff] [blame] | 91 | if ((WarnFlag || getenv("MESA_DEBUG") || getenv("LIBGL_DEBUG")) |
Brian Paul | 4e9676f | 2002-06-29 19:48:15 +0000 | [diff] [blame] | 92 | && warning_func) { |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 93 | return GL_TRUE; |
Brian Paul | 4e9676f | 2002-06-29 19:48:15 +0000 | [diff] [blame] | 94 | } |
| 95 | else { |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 96 | return GL_FALSE; |
Brian Paul | 4e9676f | 2002-06-29 19:48:15 +0000 | [diff] [blame] | 97 | } |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | |
| 101 | #define KEYWORD1 static |
Ian Romanick | 4e4b5f4 | 2006-08-22 16:34:38 +0000 | [diff] [blame] | 102 | #define KEYWORD1_ALT static |
Daniel Borca | 722cb89 | 2004-01-07 12:37:09 +0000 | [diff] [blame] | 103 | #define KEYWORD2 GLAPIENTRY |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 104 | #define NAME(func) NoOp##func |
| 105 | |
Brian Paul | 4e9676f | 2002-06-29 19:48:15 +0000 | [diff] [blame] | 106 | #define F NULL |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 107 | |
Brian Paul | 5849e3d | 2004-11-05 18:32:02 +0000 | [diff] [blame] | 108 | #define DISPATCH(func, args, msg) \ |
| 109 | if (warn()) { \ |
| 110 | warning_func(NULL, "GL User Error: called without context: %s", #func); \ |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 111 | } |
| 112 | |
Brian Paul | 5849e3d | 2004-11-05 18:32:02 +0000 | [diff] [blame] | 113 | #define RETURN_DISPATCH(func, args, msg) \ |
| 114 | if (warn()) { \ |
| 115 | warning_func(NULL, "GL User Error: called without context: %s", #func); \ |
| 116 | } \ |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 117 | return 0 |
| 118 | |
| 119 | #define DISPATCH_TABLE_NAME __glapi_noop_table |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 120 | #define UNUSED_TABLE_NAME __unused_noop_functions |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 121 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 122 | #define TABLE_ENTRY(name) (_glapi_proc) NoOp##name |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 123 | |
Brian Paul | a760ccf | 2004-12-03 15:24:34 +0000 | [diff] [blame] | 124 | static GLint NoOpUnused(void) |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 125 | { |
| 126 | if (warn()) { |
Brian Paul | 4e9676f | 2002-06-29 19:48:15 +0000 | [diff] [blame] | 127 | warning_func(NULL, "GL User Error: calling extension function without a current context\n"); |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 128 | } |
| 129 | return 0; |
| 130 | } |
| 131 | |
| 132 | #include "glapitemp.h" |
| 133 | |
| 134 | /***** END NO-OP DISPATCH *****/ |
| 135 | |
| 136 | |
| 137 | |
Ian Romanick | 967b006 | 2005-08-10 23:54:15 +0000 | [diff] [blame] | 138 | /** |
| 139 | * \name Current dispatch and current context control variables |
| 140 | * |
| 141 | * Depending on whether or not multithreading is support, and the type of |
| 142 | * support available, several variables are used to store the current context |
| 143 | * pointer and the current dispatch table pointer. In the non-threaded case, |
| 144 | * the variables \c _glapi_Dispatch and \c _glapi_Context are used for this |
| 145 | * purpose. |
| 146 | * |
| 147 | * In the "normal" threaded case, the variables \c _glapi_Dispatch and |
| 148 | * \c _glapi_Context will be \c NULL if an application is detected as being |
| 149 | * multithreaded. Single-threaded applications will use \c _glapi_Dispatch |
| 150 | * and \c _glapi_Context just like the case without any threading support. |
| 151 | * When \c _glapi_Dispatch and \c _glapi_Context are \c NULL, the thread state |
| 152 | * data \c _gl_DispatchTSD and \c ContextTSD are used. Drivers and the |
| 153 | * static dispatch functions access these variables via \c _glapi_get_dispatch |
| 154 | * and \c _glapi_get_context. |
| 155 | * |
| 156 | * There is a race condition in setting \c _glapi_Dispatch to \c NULL. It is |
| 157 | * possible for the original thread to be setting it at the same instant a new |
| 158 | * thread, perhaps running on a different processor, is clearing it. Because |
| 159 | * of that, \c ThreadSafe, which can only ever be changed to \c GL_TRUE, is |
| 160 | * used to determine whether or not the application is multithreaded. |
| 161 | * |
| 162 | * In the TLS case, the variables \c _glapi_Dispatch and \c _glapi_Context are |
| 163 | * hardcoded to \c NULL. Instead the TLS variables \c _glapi_tls_Dispatch and |
| 164 | * \c _glapi_tls_Context are used. Having \c _glapi_Dispatch and |
| 165 | * \c _glapi_Context be hardcoded to \c NULL maintains binary compatability |
| 166 | * between TLS enabled loaders and non-TLS DRI drivers. |
| 167 | */ |
| 168 | /*@{*/ |
| 169 | #if defined(GLX_USE_TLS) |
| 170 | |
| 171 | PUBLIC __thread struct _glapi_table * _glapi_tls_Dispatch |
| 172 | __attribute__((tls_model("initial-exec"))) |
| 173 | = (struct _glapi_table *) __glapi_noop_table; |
| 174 | |
| 175 | PUBLIC __thread void * _glapi_tls_Context |
| 176 | __attribute__((tls_model("initial-exec"))); |
| 177 | |
| 178 | PUBLIC const struct _glapi_table *_glapi_Dispatch = NULL; |
| 179 | PUBLIC const void *_glapi_Context = NULL; |
| 180 | |
| 181 | #else |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 182 | |
| 183 | #if defined(THREADS) |
| 184 | |
Ian Romanick | d14d103 | 2004-07-02 00:01:09 +0000 | [diff] [blame] | 185 | static GLboolean ThreadSafe = GL_FALSE; /**< In thread-safe mode? */ |
Ian Romanick | 8e77da1 | 2004-06-29 19:08:20 +0000 | [diff] [blame] | 186 | _glthread_TSD _gl_DispatchTSD; /**< Per-thread dispatch pointer */ |
Ian Romanick | 8e77da1 | 2004-06-29 19:08:20 +0000 | [diff] [blame] | 187 | static _glthread_TSD ContextTSD; /**< Per-thread context pointer */ |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 188 | |
Brian Paul | 385f23e | 2006-06-16 14:50:05 +0000 | [diff] [blame] | 189 | #if defined(WIN32_THREADS) |
| 190 | void FreeTSD(_glthread_TSD *p); |
| 191 | void FreeAllTSD(void) |
| 192 | { |
| 193 | FreeTSD(&_gl_DispatchTSD); |
| 194 | FreeTSD(&ContextTSD); |
| 195 | } |
| 196 | #endif /* defined(WIN32_THREADS) */ |
| 197 | |
Ian Romanick | 967b006 | 2005-08-10 23:54:15 +0000 | [diff] [blame] | 198 | #endif /* defined(THREADS) */ |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 199 | |
Ian Romanick | 967b006 | 2005-08-10 23:54:15 +0000 | [diff] [blame] | 200 | PUBLIC struct _glapi_table *_glapi_Dispatch = |
| 201 | (struct _glapi_table *) __glapi_noop_table; |
Adam Jackson | 791ce02 | 2004-12-15 23:14:29 +0000 | [diff] [blame] | 202 | PUBLIC void *_glapi_Context = NULL; |
Brian Paul | 8f91fb6 | 1999-12-17 14:51:28 +0000 | [diff] [blame] | 203 | |
Ian Romanick | 25fe93f | 2005-04-13 20:59:15 +0000 | [diff] [blame] | 204 | #endif /* defined(GLX_USE_TLS) */ |
Ian Romanick | 967b006 | 2005-08-10 23:54:15 +0000 | [diff] [blame] | 205 | /*@}*/ |
Brian Paul | ab0c886 | 2001-01-23 23:35:47 +0000 | [diff] [blame] | 206 | |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 207 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 208 | /** |
| 209 | * strdup() is actually not a standard ANSI C or POSIX routine. |
Brian Paul | 3c257e1 | 2001-03-28 17:19:58 +0000 | [diff] [blame] | 210 | * Irix will not define it if ANSI mode is in effect. |
| 211 | */ |
| 212 | static char * |
| 213 | str_dup(const char *str) |
Randy Frank | d7361e1 | 2000-03-27 21:13:58 +0000 | [diff] [blame] | 214 | { |
Brian Paul | fffb809 | 2000-03-29 18:46:11 +0000 | [diff] [blame] | 215 | char *copy; |
| 216 | copy = (char*) malloc(strlen(str) + 1); |
| 217 | if (!copy) |
| 218 | return NULL; |
| 219 | strcpy(copy, str); |
| 220 | return copy; |
Randy Frank | d7361e1 | 2000-03-27 21:13:58 +0000 | [diff] [blame] | 221 | } |
| 222 | |
Brian Paul | 7fb54ae | 1999-11-19 22:33:50 +0000 | [diff] [blame] | 223 | |
Brian Paul | bb72d32 | 1999-12-16 17:31:59 +0000 | [diff] [blame] | 224 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 225 | /** |
Brian Paul | bb72d32 | 1999-12-16 17:31:59 +0000 | [diff] [blame] | 226 | * We should call this periodically from a function such as glXMakeCurrent |
Brian Paul | 5104b4d | 2002-03-07 21:50:41 +0000 | [diff] [blame] | 227 | * in order to test if multiple threads are being used. |
Brian Paul | bb72d32 | 1999-12-16 17:31:59 +0000 | [diff] [blame] | 228 | */ |
Ian Romanick | 967b006 | 2005-08-10 23:54:15 +0000 | [diff] [blame] | 229 | void |
Brian Paul | bb72d32 | 1999-12-16 17:31:59 +0000 | [diff] [blame] | 230 | _glapi_check_multithread(void) |
| 231 | { |
Ian Romanick | 25fe93f | 2005-04-13 20:59:15 +0000 | [diff] [blame] | 232 | #if defined(THREADS) && !defined(GLX_USE_TLS) |
Ian Romanick | d14d103 | 2004-07-02 00:01:09 +0000 | [diff] [blame] | 233 | if (!ThreadSafe) { |
Brian Paul | bb72d32 | 1999-12-16 17:31:59 +0000 | [diff] [blame] | 234 | static unsigned long knownID; |
| 235 | static GLboolean firstCall = GL_TRUE; |
| 236 | if (firstCall) { |
| 237 | knownID = _glthread_GetID(); |
| 238 | firstCall = GL_FALSE; |
| 239 | } |
| 240 | else if (knownID != _glthread_GetID()) { |
Ian Romanick | d14d103 | 2004-07-02 00:01:09 +0000 | [diff] [blame] | 241 | ThreadSafe = GL_TRUE; |
Brian Paul | bb72d32 | 1999-12-16 17:31:59 +0000 | [diff] [blame] | 242 | _glapi_set_dispatch(NULL); |
Brian | 66d3368 | 2007-04-02 10:03:34 -0600 | [diff] [blame] | 243 | _glapi_set_context(NULL); |
Brian Paul | bb72d32 | 1999-12-16 17:31:59 +0000 | [diff] [blame] | 244 | } |
| 245 | } |
Ian Romanick | 8e77da1 | 2004-06-29 19:08:20 +0000 | [diff] [blame] | 246 | else if (!_glapi_get_dispatch()) { |
| 247 | /* make sure that this thread's dispatch pointer isn't null */ |
| 248 | _glapi_set_dispatch(NULL); |
| 249 | } |
Brian Paul | bb72d32 | 1999-12-16 17:31:59 +0000 | [diff] [blame] | 250 | #endif |
| 251 | } |
| 252 | |
| 253 | |
| 254 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 255 | /** |
Brian Paul | 8f91fb6 | 1999-12-17 14:51:28 +0000 | [diff] [blame] | 256 | * Set the current context pointer for this thread. |
| 257 | * The context pointer is an opaque type which should be cast to |
| 258 | * void from the real context pointer type. |
| 259 | */ |
Adam Jackson | 791ce02 | 2004-12-15 23:14:29 +0000 | [diff] [blame] | 260 | PUBLIC void |
Brian Paul | f9b97d9 | 2000-01-28 20:17:42 +0000 | [diff] [blame] | 261 | _glapi_set_context(void *context) |
Brian Paul | 8f91fb6 | 1999-12-17 14:51:28 +0000 | [diff] [blame] | 262 | { |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 263 | (void) __unused_noop_functions; /* silence a warning */ |
Ian Romanick | 25fe93f | 2005-04-13 20:59:15 +0000 | [diff] [blame] | 264 | #if defined(GLX_USE_TLS) |
| 265 | _glapi_tls_Context = context; |
| 266 | #elif defined(THREADS) |
Brian Paul | 3c27be3 | 2000-02-10 21:27:48 +0000 | [diff] [blame] | 267 | _glthread_SetTSD(&ContextTSD, context); |
Ian Romanick | d14d103 | 2004-07-02 00:01:09 +0000 | [diff] [blame] | 268 | _glapi_Context = (ThreadSafe) ? NULL : context; |
Brian Paul | 8f91fb6 | 1999-12-17 14:51:28 +0000 | [diff] [blame] | 269 | #else |
Brian Paul | f9b97d9 | 2000-01-28 20:17:42 +0000 | [diff] [blame] | 270 | _glapi_Context = context; |
Brian Paul | 8f91fb6 | 1999-12-17 14:51:28 +0000 | [diff] [blame] | 271 | #endif |
| 272 | } |
| 273 | |
| 274 | |
| 275 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 276 | /** |
Brian Paul | 8f91fb6 | 1999-12-17 14:51:28 +0000 | [diff] [blame] | 277 | * Get the current context pointer for this thread. |
| 278 | * The context pointer is an opaque type which should be cast from |
| 279 | * void to the real context pointer type. |
| 280 | */ |
Adam Jackson | 791ce02 | 2004-12-15 23:14:29 +0000 | [diff] [blame] | 281 | PUBLIC void * |
Brian Paul | f9b97d9 | 2000-01-28 20:17:42 +0000 | [diff] [blame] | 282 | _glapi_get_context(void) |
Brian Paul | 8f91fb6 | 1999-12-17 14:51:28 +0000 | [diff] [blame] | 283 | { |
Ian Romanick | 25fe93f | 2005-04-13 20:59:15 +0000 | [diff] [blame] | 284 | #if defined(GLX_USE_TLS) |
| 285 | return _glapi_tls_Context; |
| 286 | #elif defined(THREADS) |
Ian Romanick | d14d103 | 2004-07-02 00:01:09 +0000 | [diff] [blame] | 287 | if (ThreadSafe) { |
Brian Paul | 8f91fb6 | 1999-12-17 14:51:28 +0000 | [diff] [blame] | 288 | return _glthread_GetTSD(&ContextTSD); |
| 289 | } |
| 290 | else { |
Brian Paul | f9b97d9 | 2000-01-28 20:17:42 +0000 | [diff] [blame] | 291 | return _glapi_Context; |
Brian Paul | 8f91fb6 | 1999-12-17 14:51:28 +0000 | [diff] [blame] | 292 | } |
| 293 | #else |
Brian Paul | f9b97d9 | 2000-01-28 20:17:42 +0000 | [diff] [blame] | 294 | return _glapi_Context; |
Brian Paul | 8f91fb6 | 1999-12-17 14:51:28 +0000 | [diff] [blame] | 295 | #endif |
| 296 | } |
| 297 | |
| 298 | |
| 299 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 300 | /** |
Brian Paul | 7fb54ae | 1999-11-19 22:33:50 +0000 | [diff] [blame] | 301 | * Set the global or per-thread dispatch table pointer. |
Brian Paul | 514a15c | 2006-03-15 20:56:22 +0000 | [diff] [blame] | 302 | * If the dispatch parameter is NULL we'll plug in the no-op dispatch |
| 303 | * table (__glapi_noop_table). |
Brian Paul | 7fb54ae | 1999-11-19 22:33:50 +0000 | [diff] [blame] | 304 | */ |
Adam Jackson | 791ce02 | 2004-12-15 23:14:29 +0000 | [diff] [blame] | 305 | PUBLIC void |
Brian Paul | 7fb54ae | 1999-11-19 22:33:50 +0000 | [diff] [blame] | 306 | _glapi_set_dispatch(struct _glapi_table *dispatch) |
| 307 | { |
Ian Romanick | 25fe93f | 2005-04-13 20:59:15 +0000 | [diff] [blame] | 308 | #if defined(PTHREADS) || defined(GLX_USE_TLS) |
| 309 | static pthread_once_t once_control = PTHREAD_ONCE_INIT; |
Ian Romanick | 25fe93f | 2005-04-13 20:59:15 +0000 | [diff] [blame] | 310 | pthread_once( & once_control, init_glapi_relocs ); |
| 311 | #endif |
| 312 | |
Ian Romanick | 6c5402b | 2004-07-05 22:40:54 +0000 | [diff] [blame] | 313 | if (!dispatch) { |
| 314 | /* use the no-op functions */ |
| 315 | dispatch = (struct _glapi_table *) __glapi_noop_table; |
| 316 | } |
Brian Paul | 7fb54ae | 1999-11-19 22:33:50 +0000 | [diff] [blame] | 317 | #ifdef DEBUG |
Ian Romanick | 6c5402b | 2004-07-05 22:40:54 +0000 | [diff] [blame] | 318 | else { |
Brian Paul | 7fb54ae | 1999-11-19 22:33:50 +0000 | [diff] [blame] | 319 | _glapi_check_table(dispatch); |
| 320 | } |
| 321 | #endif |
| 322 | |
Ian Romanick | 25fe93f | 2005-04-13 20:59:15 +0000 | [diff] [blame] | 323 | #if defined(GLX_USE_TLS) |
Ian Romanick | 967b006 | 2005-08-10 23:54:15 +0000 | [diff] [blame] | 324 | _glapi_tls_Dispatch = dispatch; |
Ian Romanick | 25fe93f | 2005-04-13 20:59:15 +0000 | [diff] [blame] | 325 | #elif defined(THREADS) |
Ian Romanick | 967b006 | 2005-08-10 23:54:15 +0000 | [diff] [blame] | 326 | _glthread_SetTSD(&_gl_DispatchTSD, (void *) dispatch); |
| 327 | _glapi_Dispatch = (ThreadSafe) ? NULL : dispatch; |
Brian Paul | 3a71d05 | 2000-09-05 20:17:37 +0000 | [diff] [blame] | 328 | #else /*THREADS*/ |
Ian Romanick | 967b006 | 2005-08-10 23:54:15 +0000 | [diff] [blame] | 329 | _glapi_Dispatch = dispatch; |
Brian Paul | 3a71d05 | 2000-09-05 20:17:37 +0000 | [diff] [blame] | 330 | #endif /*THREADS*/ |
Brian Paul | 7fb54ae | 1999-11-19 22:33:50 +0000 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | |
Brian Paul | bb72d32 | 1999-12-16 17:31:59 +0000 | [diff] [blame] | 334 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 335 | /** |
Brian Paul | bb72d32 | 1999-12-16 17:31:59 +0000 | [diff] [blame] | 336 | * Return pointer to current dispatch table for calling thread. |
Brian Paul | 7fb54ae | 1999-11-19 22:33:50 +0000 | [diff] [blame] | 337 | */ |
Adam Jackson | 791ce02 | 2004-12-15 23:14:29 +0000 | [diff] [blame] | 338 | PUBLIC struct _glapi_table * |
Brian Paul | 7fb54ae | 1999-11-19 22:33:50 +0000 | [diff] [blame] | 339 | _glapi_get_dispatch(void) |
| 340 | { |
Ian Romanick | 967b006 | 2005-08-10 23:54:15 +0000 | [diff] [blame] | 341 | struct _glapi_table * api; |
Ian Romanick | 25fe93f | 2005-04-13 20:59:15 +0000 | [diff] [blame] | 342 | #if defined(GLX_USE_TLS) |
Ian Romanick | 967b006 | 2005-08-10 23:54:15 +0000 | [diff] [blame] | 343 | api = _glapi_tls_Dispatch; |
| 344 | #elif defined(THREADS) |
| 345 | api = (ThreadSafe) |
| 346 | ? (struct _glapi_table *) _glthread_GetTSD(&_gl_DispatchTSD) |
| 347 | : _glapi_Dispatch; |
| 348 | #else |
| 349 | api = _glapi_Dispatch; |
| 350 | #endif |
Ian Romanick | 25fe93f | 2005-04-13 20:59:15 +0000 | [diff] [blame] | 351 | return api; |
Brian Paul | 3a71d05 | 2000-09-05 20:17:37 +0000 | [diff] [blame] | 352 | } |
Brian Paul | ab0c886 | 2001-01-23 23:35:47 +0000 | [diff] [blame] | 353 | |
Brian Paul | 3a71d05 | 2000-09-05 20:17:37 +0000 | [diff] [blame] | 354 | |
Brian Paul | 514a15c | 2006-03-15 20:56:22 +0000 | [diff] [blame] | 355 | |
| 356 | /*** |
| 357 | *** The rest of this file is pretty much concerned with GetProcAddress |
| 358 | *** functionality. |
| 359 | ***/ |
| 360 | |
Ian Romanick | d319edf | 2006-08-22 18:22:20 +0000 | [diff] [blame] | 361 | #if defined(USE_X64_64_ASM) && defined(GLX_USE_TLS) |
| 362 | # define DISPATCH_FUNCTION_SIZE 16 |
| 363 | #elif defined(USE_X86_ASM) |
| 364 | # if defined(THREADS) && !defined(GLX_USE_TLS) |
| 365 | # define DISPATCH_FUNCTION_SIZE 32 |
| 366 | # else |
| 367 | # define DISPATCH_FUNCTION_SIZE 16 |
| 368 | # endif |
| 369 | #endif |
| 370 | |
| 371 | #if !defined(DISPATCH_FUNCTION_SIZE) && !defined(XFree86Server) && !defined(XGLServer) |
| 372 | # define NEED_FUNCTION_POINTER |
Ian Romanick | 8e77da1 | 2004-06-29 19:08:20 +0000 | [diff] [blame] | 373 | #endif |
Ian Romanick | 7867799 | 2004-05-27 00:05:13 +0000 | [diff] [blame] | 374 | |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 375 | /* The code in this file is auto-generated with Python */ |
Brian Paul | b5fd886 | 2001-11-18 22:48:11 +0000 | [diff] [blame] | 376 | #include "glprocs.h" |
Brian Paul | 7fb54ae | 1999-11-19 22:33:50 +0000 | [diff] [blame] | 377 | |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 378 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 379 | /** |
| 380 | * Search the table of static entrypoint functions for the named function |
| 381 | * and return the corresponding glprocs_table_t entry. |
| 382 | */ |
Ian Romanick | 7867799 | 2004-05-27 00:05:13 +0000 | [diff] [blame] | 383 | static const glprocs_table_t * |
| 384 | find_entry( const char * n ) |
| 385 | { |
Brian Paul | a760ccf | 2004-12-03 15:24:34 +0000 | [diff] [blame] | 386 | GLuint i; |
Brian Paul | a760ccf | 2004-12-03 15:24:34 +0000 | [diff] [blame] | 387 | for (i = 0; static_functions[i].Name_offset >= 0; i++) { |
Brian Paul | 514a15c | 2006-03-15 20:56:22 +0000 | [diff] [blame] | 388 | const char *testName = gl_string_table + static_functions[i].Name_offset; |
| 389 | if (strcmp(testName, n) == 0) { |
| 390 | return &static_functions[i]; |
Ian Romanick | 7867799 | 2004-05-27 00:05:13 +0000 | [diff] [blame] | 391 | } |
| 392 | } |
| 393 | return NULL; |
| 394 | } |
| 395 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 396 | |
| 397 | /** |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 398 | * Return dispatch table offset of the named static (built-in) function. |
| 399 | * Return -1 if function not found. |
| 400 | */ |
| 401 | static GLint |
| 402 | get_static_proc_offset(const char *funcName) |
| 403 | { |
Ian Romanick | 7867799 | 2004-05-27 00:05:13 +0000 | [diff] [blame] | 404 | const glprocs_table_t * const f = find_entry( funcName ); |
Brian Paul | 514a15c | 2006-03-15 20:56:22 +0000 | [diff] [blame] | 405 | if (f) { |
Ian Romanick | 7867799 | 2004-05-27 00:05:13 +0000 | [diff] [blame] | 406 | return f->Offset; |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 407 | } |
| 408 | return -1; |
| 409 | } |
| 410 | |
| 411 | |
Brian Paul | 514a15c | 2006-03-15 20:56:22 +0000 | [diff] [blame] | 412 | #if !defined(XFree86Server) && !defined(XGLServer) |
Ian Romanick | 8e77da1 | 2004-06-29 19:08:20 +0000 | [diff] [blame] | 413 | #ifdef USE_X86_ASM |
Ian Romanick | 8e77da1 | 2004-06-29 19:08:20 +0000 | [diff] [blame] | 414 | |
Ian Romanick | 25fe93f | 2005-04-13 20:59:15 +0000 | [diff] [blame] | 415 | #if defined( GLX_USE_TLS ) |
| 416 | extern GLubyte gl_dispatch_functions_start[]; |
| 417 | extern GLubyte gl_dispatch_functions_end[]; |
| 418 | #else |
| 419 | extern const GLubyte gl_dispatch_functions_start[]; |
| 420 | #endif |
| 421 | |
Brian Paul | 514a15c | 2006-03-15 20:56:22 +0000 | [diff] [blame] | 422 | #endif /* USE_X86_ASM */ |
| 423 | |
Ian Romanick | 8e77da1 | 2004-06-29 19:08:20 +0000 | [diff] [blame] | 424 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 425 | /** |
Brian Paul | 514a15c | 2006-03-15 20:56:22 +0000 | [diff] [blame] | 426 | * Return dispatch function address for the named static (built-in) function. |
Ian Romanick | 8e77da1 | 2004-06-29 19:08:20 +0000 | [diff] [blame] | 427 | * Return NULL if function not found. |
| 428 | */ |
Brian Paul | 09c8e41 | 2006-04-13 01:51:25 +0000 | [diff] [blame] | 429 | static _glapi_proc |
Ian Romanick | 8e77da1 | 2004-06-29 19:08:20 +0000 | [diff] [blame] | 430 | get_static_proc_address(const char *funcName) |
| 431 | { |
| 432 | const glprocs_table_t * const f = find_entry( funcName ); |
Brian Paul | 514a15c | 2006-03-15 20:56:22 +0000 | [diff] [blame] | 433 | if (f) { |
Ian Romanick | f3f51bc | 2006-10-11 22:37:14 +0000 | [diff] [blame] | 434 | #if defined(DISPATCH_FUNCTION_SIZE) && defined(GLX_INDIRECT_RENDERING) |
| 435 | return (f->Address == NULL) |
| 436 | ? (_glapi_proc) (gl_dispatch_functions_start |
Ian Romanick | 4616513 | 2006-10-13 17:34:01 +0000 | [diff] [blame] | 437 | + (DISPATCH_FUNCTION_SIZE * f->Offset)) |
Ian Romanick | f3f51bc | 2006-10-11 22:37:14 +0000 | [diff] [blame] | 438 | : f->Address; |
| 439 | #elif defined(DISPATCH_FUNCTION_SIZE) |
Brian Paul | 209bd3a | 2004-11-27 04:02:32 +0000 | [diff] [blame] | 440 | return (_glapi_proc) (gl_dispatch_functions_start |
Ian Romanick | d319edf | 2006-08-22 18:22:20 +0000 | [diff] [blame] | 441 | + (DISPATCH_FUNCTION_SIZE * f->Offset)); |
Brian Paul | 514a15c | 2006-03-15 20:56:22 +0000 | [diff] [blame] | 442 | #else |
| 443 | return f->Address; |
| 444 | #endif |
Ian Romanick | 8e77da1 | 2004-06-29 19:08:20 +0000 | [diff] [blame] | 445 | } |
| 446 | else { |
| 447 | return NULL; |
| 448 | } |
| 449 | } |
| 450 | |
Brian Paul | 514a15c | 2006-03-15 20:56:22 +0000 | [diff] [blame] | 451 | #endif /* !defined(XFree86Server) && !defined(XGLServer) */ |
Ian Romanick | 8e77da1 | 2004-06-29 19:08:20 +0000 | [diff] [blame] | 452 | |
| 453 | |
Ian Romanick | 7867799 | 2004-05-27 00:05:13 +0000 | [diff] [blame] | 454 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 455 | /** |
| 456 | * Return the name of the function at the given offset in the dispatch |
| 457 | * table. For debugging only. |
| 458 | */ |
Ian Romanick | 7867799 | 2004-05-27 00:05:13 +0000 | [diff] [blame] | 459 | static const char * |
| 460 | get_static_proc_name( GLuint offset ) |
| 461 | { |
Brian Paul | a760ccf | 2004-12-03 15:24:34 +0000 | [diff] [blame] | 462 | GLuint i; |
Brian Paul | a760ccf | 2004-12-03 15:24:34 +0000 | [diff] [blame] | 463 | for (i = 0; static_functions[i].Name_offset >= 0; i++) { |
Ian Romanick | 7867799 | 2004-05-27 00:05:13 +0000 | [diff] [blame] | 464 | if (static_functions[i].Offset == offset) { |
| 465 | return gl_string_table + static_functions[i].Name_offset; |
Brian Paul | 9c7ca85 | 2000-10-19 20:13:12 +0000 | [diff] [blame] | 466 | } |
| 467 | } |
| 468 | return NULL; |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | |
| 472 | |
| 473 | /********************************************************************** |
| 474 | * Extension function management. |
| 475 | */ |
| 476 | |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 477 | /* |
| 478 | * Number of extension functions which we can dynamically add at runtime. |
| 479 | */ |
| 480 | #define MAX_EXTENSION_FUNCS 300 |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 481 | |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 482 | |
| 483 | /* |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 484 | * The dispatch table size (number of entries) is the size of the |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 485 | * _glapi_table struct plus the number of dynamic entries we can add. |
| 486 | * The extra slots can be filled in by DRI drivers that register new extension |
| 487 | * functions. |
| 488 | */ |
| 489 | #define DISPATCH_TABLE_SIZE (sizeof(struct _glapi_table) / sizeof(void *) + MAX_EXTENSION_FUNCS) |
| 490 | |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 491 | |
Ian Romanick | 1585c23 | 2005-07-28 00:29:51 +0000 | [diff] [blame] | 492 | /** |
| 493 | * Track information about a function added to the GL API. |
| 494 | */ |
| 495 | struct _glapi_function { |
| 496 | /** |
| 497 | * Name of the function. |
| 498 | */ |
| 499 | const char * name; |
| 500 | |
| 501 | |
| 502 | /** |
| 503 | * Text string that describes the types of the parameters passed to the |
| 504 | * named function. Parameter types are converted to characters using the |
| 505 | * following rules: |
| 506 | * - 'i' for \c GLint, \c GLuint, and \c GLenum |
| 507 | * - 'p' for any pointer type |
| 508 | * - 'f' for \c GLfloat and \c GLclampf |
| 509 | * - 'd' for \c GLdouble and \c GLclampd |
| 510 | */ |
| 511 | const char * parameter_signature; |
| 512 | |
| 513 | |
| 514 | /** |
| 515 | * Offset in the dispatch table where the pointer to the real function is |
| 516 | * located. If the driver has not requested that the named function be |
| 517 | * added to the dispatch table, this will have the value ~0. |
| 518 | */ |
| 519 | unsigned dispatch_offset; |
| 520 | |
| 521 | |
| 522 | /** |
| 523 | * Pointer to the dispatch stub for the named function. |
| 524 | * |
| 525 | * \todo |
| 526 | * The semantic of this field should be changed slightly. Currently, it |
| 527 | * is always expected to be non-\c NULL. However, it would be better to |
| 528 | * only allocate the entry-point stub when the application requests the |
| 529 | * function via \c glXGetProcAddress. This would save memory for all the |
| 530 | * functions that the driver exports but that the application never wants |
| 531 | * to call. |
| 532 | */ |
| 533 | _glapi_proc dispatch_stub; |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 534 | }; |
| 535 | |
| 536 | |
Ian Romanick | 1585c23 | 2005-07-28 00:29:51 +0000 | [diff] [blame] | 537 | static struct _glapi_function ExtEntryTable[MAX_EXTENSION_FUNCS]; |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 538 | static GLuint NumExtEntryPoints = 0; |
| 539 | |
davem69 | 4a497e6 | 2001-06-06 22:55:28 +0000 | [diff] [blame] | 540 | #ifdef USE_SPARC_ASM |
| 541 | extern void __glapi_sparc_icache_flush(unsigned int *); |
| 542 | #endif |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 543 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 544 | /** |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 545 | * Generate a dispatch function (entrypoint) which jumps through |
| 546 | * the given slot number (offset) in the current dispatch table. |
| 547 | * We need assembly language in order to accomplish this. |
| 548 | */ |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 549 | static _glapi_proc |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 550 | generate_entrypoint(GLuint functionOffset) |
| 551 | { |
| 552 | #if defined(USE_X86_ASM) |
Ian Romanick | 25fe93f | 2005-04-13 20:59:15 +0000 | [diff] [blame] | 553 | /* 32 is chosen as something of a magic offset. For x86, the dispatch |
| 554 | * at offset 32 is the first one where the offset in the |
| 555 | * "jmp OFFSET*4(%eax)" can't be encoded in a single byte. |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 556 | */ |
Ian Romanick | 25fe93f | 2005-04-13 20:59:15 +0000 | [diff] [blame] | 557 | const GLubyte * const template_func = gl_dispatch_functions_start |
Ian Romanick | d319edf | 2006-08-22 18:22:20 +0000 | [diff] [blame] | 558 | + (DISPATCH_FUNCTION_SIZE * 32); |
| 559 | GLubyte * const code = (GLubyte *) malloc(DISPATCH_FUNCTION_SIZE); |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 560 | |
Ian Romanick | 25fe93f | 2005-04-13 20:59:15 +0000 | [diff] [blame] | 561 | |
| 562 | if ( code != NULL ) { |
Ian Romanick | d319edf | 2006-08-22 18:22:20 +0000 | [diff] [blame] | 563 | (void) memcpy(code, template_func, DISPATCH_FUNCTION_SIZE); |
Ian Romanick | 25fe93f | 2005-04-13 20:59:15 +0000 | [diff] [blame] | 564 | fill_in_entrypoint_offset( (_glapi_proc) code, functionOffset ); |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 565 | } |
Ian Romanick | 25fe93f | 2005-04-13 20:59:15 +0000 | [diff] [blame] | 566 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 567 | return (_glapi_proc) code; |
davem69 | 775355a | 2001-06-05 23:54:00 +0000 | [diff] [blame] | 568 | #elif defined(USE_SPARC_ASM) |
| 569 | |
Ian Romanick | 9f23a3a | 2005-07-28 00:11:10 +0000 | [diff] [blame] | 570 | #ifdef __arch64__ |
davem69 | 775355a | 2001-06-05 23:54:00 +0000 | [diff] [blame] | 571 | static const unsigned int insn_template[] = { |
| 572 | 0x05000000, /* sethi %uhi(_glapi_Dispatch), %g2 */ |
| 573 | 0x03000000, /* sethi %hi(_glapi_Dispatch), %g1 */ |
| 574 | 0x8410a000, /* or %g2, %ulo(_glapi_Dispatch), %g2 */ |
| 575 | 0x82106000, /* or %g1, %lo(_glapi_Dispatch), %g1 */ |
| 576 | 0x8528b020, /* sllx %g2, 32, %g2 */ |
| 577 | 0xc2584002, /* ldx [%g1 + %g2], %g1 */ |
| 578 | 0x05000000, /* sethi %hi(8 * glapioffset), %g2 */ |
| 579 | 0x8410a000, /* or %g2, %lo(8 * glapioffset), %g2 */ |
| 580 | 0xc6584002, /* ldx [%g1 + %g2], %g3 */ |
| 581 | 0x81c0c000, /* jmpl %g3, %g0 */ |
| 582 | 0x01000000 /* nop */ |
| 583 | }; |
| 584 | #else |
| 585 | static const unsigned int insn_template[] = { |
| 586 | 0x03000000, /* sethi %hi(_glapi_Dispatch), %g1 */ |
| 587 | 0xc2006000, /* ld [%g1 + %lo(_glapi_Dispatch)], %g1 */ |
| 588 | 0xc6006000, /* ld [%g1 + %lo(4*glapioffset)], %g3 */ |
| 589 | 0x81c0c000, /* jmpl %g3, %g0 */ |
| 590 | 0x01000000 /* nop */ |
| 591 | }; |
Brian Paul | 514a15c | 2006-03-15 20:56:22 +0000 | [diff] [blame] | 592 | #endif /* __arch64__ */ |
Brian Paul | dec2a4d | 2002-10-29 15:03:14 +0000 | [diff] [blame] | 593 | unsigned int *code = (unsigned int *) malloc(sizeof(insn_template)); |
davem69 | 775355a | 2001-06-05 23:54:00 +0000 | [diff] [blame] | 594 | unsigned long glapi_addr = (unsigned long) &_glapi_Dispatch; |
| 595 | if (code) { |
| 596 | memcpy(code, insn_template, sizeof(insn_template)); |
| 597 | |
Ian Romanick | 9f23a3a | 2005-07-28 00:11:10 +0000 | [diff] [blame] | 598 | #ifdef __arch64__ |
davem69 | 775355a | 2001-06-05 23:54:00 +0000 | [diff] [blame] | 599 | code[0] |= (glapi_addr >> (32 + 10)); |
| 600 | code[1] |= ((glapi_addr & 0xffffffff) >> 10); |
davem69 | 4a497e6 | 2001-06-06 22:55:28 +0000 | [diff] [blame] | 601 | __glapi_sparc_icache_flush(&code[0]); |
davem69 | 775355a | 2001-06-05 23:54:00 +0000 | [diff] [blame] | 602 | code[2] |= ((glapi_addr >> 32) & ((1 << 10) - 1)); |
| 603 | code[3] |= (glapi_addr & ((1 << 10) - 1)); |
davem69 | 4a497e6 | 2001-06-06 22:55:28 +0000 | [diff] [blame] | 604 | __glapi_sparc_icache_flush(&code[2]); |
davem69 | 775355a | 2001-06-05 23:54:00 +0000 | [diff] [blame] | 605 | code[6] |= ((functionOffset * 8) >> 10); |
| 606 | code[7] |= ((functionOffset * 8) & ((1 << 10) - 1)); |
davem69 | 4a497e6 | 2001-06-06 22:55:28 +0000 | [diff] [blame] | 607 | __glapi_sparc_icache_flush(&code[6]); |
davem69 | 775355a | 2001-06-05 23:54:00 +0000 | [diff] [blame] | 608 | #else |
| 609 | code[0] |= (glapi_addr >> 10); |
| 610 | code[1] |= (glapi_addr & ((1 << 10) - 1)); |
davem69 | 4a497e6 | 2001-06-06 22:55:28 +0000 | [diff] [blame] | 611 | __glapi_sparc_icache_flush(&code[0]); |
davem69 | 775355a | 2001-06-05 23:54:00 +0000 | [diff] [blame] | 612 | code[2] |= (functionOffset * 4); |
davem69 | 4a497e6 | 2001-06-06 22:55:28 +0000 | [diff] [blame] | 613 | __glapi_sparc_icache_flush(&code[2]); |
Brian Paul | 514a15c | 2006-03-15 20:56:22 +0000 | [diff] [blame] | 614 | #endif /* __arch64__ */ |
davem69 | 775355a | 2001-06-05 23:54:00 +0000 | [diff] [blame] | 615 | } |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 616 | return (_glapi_proc) code; |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 617 | #else |
Brian Paul | a6c423d | 2004-08-25 15:59:48 +0000 | [diff] [blame] | 618 | (void) functionOffset; |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 619 | return NULL; |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 620 | #endif /* USE_*_ASM */ |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 624 | /** |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 625 | * This function inserts a new dispatch offset into the assembly language |
| 626 | * stub that was generated with the preceeding function. |
| 627 | */ |
| 628 | static void |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 629 | fill_in_entrypoint_offset(_glapi_proc entrypoint, GLuint offset) |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 630 | { |
| 631 | #if defined(USE_X86_ASM) |
Ian Romanick | 25fe93f | 2005-04-13 20:59:15 +0000 | [diff] [blame] | 632 | GLubyte * const code = (GLubyte *) entrypoint; |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 633 | |
Ian Romanick | d319edf | 2006-08-22 18:22:20 +0000 | [diff] [blame] | 634 | #if DISPATCH_FUNCTION_SIZE == 32 |
Ian Romanick | 25fe93f | 2005-04-13 20:59:15 +0000 | [diff] [blame] | 635 | *((unsigned int *)(code + 11)) = 4 * offset; |
| 636 | *((unsigned int *)(code + 22)) = 4 * offset; |
Ian Romanick | d319edf | 2006-08-22 18:22:20 +0000 | [diff] [blame] | 637 | #elif DISPATCH_FUNCTION_SIZE == 16 && defined( GLX_USE_TLS ) |
Ian Romanick | 25fe93f | 2005-04-13 20:59:15 +0000 | [diff] [blame] | 638 | *((unsigned int *)(code + 8)) = 4 * offset; |
Ian Romanick | d319edf | 2006-08-22 18:22:20 +0000 | [diff] [blame] | 639 | #elif DISPATCH_FUNCTION_SIZE == 16 |
Ian Romanick | 25fe93f | 2005-04-13 20:59:15 +0000 | [diff] [blame] | 640 | *((unsigned int *)(code + 7)) = 4 * offset; |
| 641 | #else |
Ian Romanick | d319edf | 2006-08-22 18:22:20 +0000 | [diff] [blame] | 642 | # error Invalid DISPATCH_FUNCTION_SIZE! |
Ian Romanick | 25fe93f | 2005-04-13 20:59:15 +0000 | [diff] [blame] | 643 | #endif |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 644 | |
| 645 | #elif defined(USE_SPARC_ASM) |
| 646 | |
| 647 | /* XXX this hasn't been tested! */ |
| 648 | unsigned int *code = (unsigned int *) entrypoint; |
Ian Romanick | 9f23a3a | 2005-07-28 00:11:10 +0000 | [diff] [blame] | 649 | #ifdef __arch64__ |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 650 | code[6] = 0x05000000; /* sethi %hi(8 * glapioffset), %g2 */ |
| 651 | code[7] = 0x8410a000; /* or %g2, %lo(8 * glapioffset), %g2 */ |
| 652 | code[6] |= ((offset * 8) >> 10); |
| 653 | code[7] |= ((offset * 8) & ((1 << 10) - 1)); |
| 654 | __glapi_sparc_icache_flush(&code[6]); |
Ian Romanick | 9f23a3a | 2005-07-28 00:11:10 +0000 | [diff] [blame] | 655 | #else /* __arch64__ */ |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 656 | code[2] = 0xc6006000; /* ld [%g1 + %lo(4*glapioffset)], %g3 */ |
Brian Paul | 944ea20 | 2002-10-17 16:29:17 +0000 | [diff] [blame] | 657 | code[2] |= (offset * 4); |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 658 | __glapi_sparc_icache_flush(&code[2]); |
Ian Romanick | 9f23a3a | 2005-07-28 00:11:10 +0000 | [diff] [blame] | 659 | #endif /* __arch64__ */ |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 660 | |
Brian Paul | a6c423d | 2004-08-25 15:59:48 +0000 | [diff] [blame] | 661 | #else |
| 662 | |
| 663 | /* an unimplemented architecture */ |
| 664 | (void) entrypoint; |
| 665 | (void) offset; |
| 666 | |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 667 | #endif /* USE_*_ASM */ |
| 668 | } |
| 669 | |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 670 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 671 | /** |
Ian Romanick | 1585c23 | 2005-07-28 00:29:51 +0000 | [diff] [blame] | 672 | * Generate new entrypoint |
| 673 | * |
| 674 | * Use a temporary dispatch offset of ~0 (i.e. -1). Later, when the driver |
| 675 | * calls \c _glapi_add_dispatch we'll put in the proper offset. If that |
| 676 | * never happens, and the user calls this function, he'll segfault. That's |
| 677 | * what you get when you try calling a GL function that doesn't really exist. |
| 678 | * |
| 679 | * \param funcName Name of the function to create an entry-point for. |
| 680 | * |
| 681 | * \sa _glapi_add_entrypoint |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 682 | */ |
Ian Romanick | 1585c23 | 2005-07-28 00:29:51 +0000 | [diff] [blame] | 683 | |
| 684 | static struct _glapi_function * |
| 685 | add_function_name( const char * funcName ) |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 686 | { |
Ian Romanick | 1585c23 | 2005-07-28 00:29:51 +0000 | [diff] [blame] | 687 | struct _glapi_function * entry = NULL; |
| 688 | |
| 689 | if (NumExtEntryPoints < MAX_EXTENSION_FUNCS) { |
| 690 | _glapi_proc entrypoint = generate_entrypoint(~0); |
| 691 | if (entrypoint != NULL) { |
| 692 | entry = & ExtEntryTable[NumExtEntryPoints]; |
| 693 | |
| 694 | ExtEntryTable[NumExtEntryPoints].name = str_dup(funcName); |
| 695 | ExtEntryTable[NumExtEntryPoints].parameter_signature = NULL; |
| 696 | ExtEntryTable[NumExtEntryPoints].dispatch_offset = ~0; |
| 697 | ExtEntryTable[NumExtEntryPoints].dispatch_stub = entrypoint; |
| 698 | NumExtEntryPoints++; |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | return entry; |
| 703 | } |
| 704 | |
| 705 | |
| 706 | /** |
| 707 | * Fill-in the dispatch stub for the named function. |
| 708 | * |
| 709 | * This function is intended to be called by a hardware driver. When called, |
| 710 | * a dispatch stub may be created created for the function. A pointer to this |
| 711 | * dispatch function will be returned by glXGetProcAddress. |
| 712 | * |
| 713 | * \param function_names Array of pointers to function names that should |
| 714 | * share a common dispatch offset. |
| 715 | * \param parameter_signature String representing the types of the parameters |
| 716 | * passed to the named function. Parameter types |
| 717 | * are converted to characters using the following |
| 718 | * rules: |
| 719 | * - 'i' for \c GLint, \c GLuint, and \c GLenum |
| 720 | * - 'p' for any pointer type |
| 721 | * - 'f' for \c GLfloat and \c GLclampf |
| 722 | * - 'd' for \c GLdouble and \c GLclampd |
| 723 | * |
| 724 | * \returns |
| 725 | * The offset in the dispatch table of the named function. A pointer to the |
| 726 | * driver's implementation of the named function should be stored at |
| 727 | * \c dispatch_table[\c offset]. |
| 728 | * |
| 729 | * \sa glXGetProcAddress |
| 730 | * |
| 731 | * \warning |
| 732 | * This function can only handle up to 8 names at a time. As far as I know, |
| 733 | * the maximum number of names ever associated with an existing GL function is |
| 734 | * 4 (\c glPointParameterfSGIS, \c glPointParameterfEXT, |
| 735 | * \c glPointParameterfARB, and \c glPointParameterf), so this should not be |
| 736 | * too painful of a limitation. |
| 737 | * |
| 738 | * \todo |
| 739 | * Determine whether or not \c parameter_signature should be allowed to be |
| 740 | * \c NULL. It doesn't seem like much of a hardship for drivers to have to |
| 741 | * pass in an empty string. |
| 742 | * |
| 743 | * \todo |
| 744 | * Determine if code should be added to reject function names that start with |
| 745 | * 'glX'. |
| 746 | * |
| 747 | * \bug |
| 748 | * Add code to compare \c parameter_signature with the parameter signature of |
| 749 | * a static function. In order to do that, we need to find a way to \b get |
| 750 | * the parameter signature of a static function. |
| 751 | */ |
| 752 | |
| 753 | PUBLIC int |
| 754 | _glapi_add_dispatch( const char * const * function_names, |
| 755 | const char * parameter_signature ) |
| 756 | { |
| 757 | static int next_dynamic_offset = _gloffset_FIRST_DYNAMIC; |
| 758 | const char * const real_sig = (parameter_signature != NULL) |
| 759 | ? parameter_signature : ""; |
| 760 | struct _glapi_function * entry[8]; |
| 761 | GLboolean is_static[8]; |
| 762 | unsigned i; |
| 763 | unsigned j; |
| 764 | int offset = ~0; |
| 765 | int new_offset; |
| 766 | |
| 767 | |
| 768 | (void) memset( is_static, 0, sizeof( is_static ) ); |
| 769 | (void) memset( entry, 0, sizeof( entry ) ); |
| 770 | |
| 771 | for ( i = 0 ; function_names[i] != NULL ; i++ ) { |
| 772 | /* Do some trivial validation on the name of the function. |
| 773 | */ |
| 774 | |
Ian Romanick | 1585c23 | 2005-07-28 00:29:51 +0000 | [diff] [blame] | 775 | if (!function_names[i] || function_names[i][0] != 'g' || function_names[i][1] != 'l') |
| 776 | return GL_FALSE; |
Ian Romanick | 1585c23 | 2005-07-28 00:29:51 +0000 | [diff] [blame] | 777 | |
| 778 | /* Determine if the named function already exists. If the function does |
| 779 | * exist, it must have the same parameter signature as the function |
| 780 | * being added. |
| 781 | */ |
Brian Paul | 8ad1076 | 2002-10-11 17:41:03 +0000 | [diff] [blame] | 782 | |
Ian Romanick | 1585c23 | 2005-07-28 00:29:51 +0000 | [diff] [blame] | 783 | new_offset = get_static_proc_offset(function_names[i]); |
| 784 | if (new_offset >= 0) { |
| 785 | /* FIXME: Make sure the parameter signatures match! How do we get |
| 786 | * FIXME: the parameter signature for static functions? |
| 787 | */ |
| 788 | |
| 789 | if ( (offset != ~0) && (new_offset != offset) ) { |
| 790 | return -1; |
| 791 | } |
| 792 | |
| 793 | is_static[i] = GL_TRUE; |
| 794 | offset = new_offset; |
| 795 | } |
| 796 | |
| 797 | |
| 798 | for ( j = 0 ; j < NumExtEntryPoints ; j++ ) { |
| 799 | if (strcmp(ExtEntryTable[j].name, function_names[i]) == 0) { |
| 800 | /* The offset may be ~0 if the function name was added by |
| 801 | * glXGetProcAddress but never filled in by the driver. |
| 802 | */ |
| 803 | |
| 804 | if (ExtEntryTable[j].dispatch_offset != ~0) { |
| 805 | if (strcmp(real_sig, ExtEntryTable[j].parameter_signature) |
| 806 | != 0) { |
| 807 | return -1; |
| 808 | } |
| 809 | |
| 810 | if ( (offset != ~0) && (ExtEntryTable[j].dispatch_offset != offset) ) { |
| 811 | return -1; |
| 812 | } |
| 813 | |
| 814 | offset = ExtEntryTable[j].dispatch_offset; |
| 815 | } |
| 816 | |
| 817 | entry[i] = & ExtEntryTable[j]; |
| 818 | break; |
| 819 | } |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 820 | } |
| 821 | } |
| 822 | |
Ian Romanick | 1585c23 | 2005-07-28 00:29:51 +0000 | [diff] [blame] | 823 | if (offset == ~0) { |
| 824 | offset = next_dynamic_offset; |
| 825 | next_dynamic_offset++; |
| 826 | } |
| 827 | |
Ian Romanick | 1585c23 | 2005-07-28 00:29:51 +0000 | [diff] [blame] | 828 | for ( i = 0 ; function_names[i] != NULL ; i++ ) { |
| 829 | if (! is_static[i] ) { |
| 830 | if (entry[i] == NULL) { |
| 831 | entry[i] = add_function_name( function_names[i] ); |
| 832 | if (entry[i] == NULL) { |
| 833 | /* FIXME: Possible memory leak here. |
| 834 | */ |
| 835 | return -1; |
| 836 | } |
| 837 | } |
| 838 | |
Ian Romanick | 1585c23 | 2005-07-28 00:29:51 +0000 | [diff] [blame] | 839 | entry[i]->parameter_signature = str_dup(real_sig); |
| 840 | fill_in_entrypoint_offset(entry[i]->dispatch_stub, offset); |
| 841 | entry[i]->dispatch_offset = offset; |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 842 | } |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 843 | } |
Ian Romanick | 1585c23 | 2005-07-28 00:29:51 +0000 | [diff] [blame] | 844 | |
| 845 | return offset; |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 849 | /** |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 850 | * Return offset of entrypoint for named function within dispatch table. |
| 851 | */ |
Adam Jackson | 791ce02 | 2004-12-15 23:14:29 +0000 | [diff] [blame] | 852 | PUBLIC GLint |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 853 | _glapi_get_proc_offset(const char *funcName) |
| 854 | { |
| 855 | /* search extension functions first */ |
Brian Paul | b51b0a8 | 2001-03-07 05:06:11 +0000 | [diff] [blame] | 856 | GLuint i; |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 857 | for (i = 0; i < NumExtEntryPoints; i++) { |
Ian Romanick | 1585c23 | 2005-07-28 00:29:51 +0000 | [diff] [blame] | 858 | if (strcmp(ExtEntryTable[i].name, funcName) == 0) { |
| 859 | return ExtEntryTable[i].dispatch_offset; |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 860 | } |
| 861 | } |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 862 | /* search static functions */ |
| 863 | return get_static_proc_offset(funcName); |
| 864 | } |
| 865 | |
| 866 | |
| 867 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 868 | /** |
| 869 | * Return pointer to the named function. If the function name isn't found |
| 870 | * in the name of static functions, try generating a new API entrypoint on |
| 871 | * the fly with assembly language. |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 872 | */ |
Ian Romanick | 967b006 | 2005-08-10 23:54:15 +0000 | [diff] [blame] | 873 | _glapi_proc |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 874 | _glapi_get_proc_address(const char *funcName) |
| 875 | { |
Ian Romanick | 1585c23 | 2005-07-28 00:29:51 +0000 | [diff] [blame] | 876 | struct _glapi_function * entry; |
Brian Paul | b51b0a8 | 2001-03-07 05:06:11 +0000 | [diff] [blame] | 877 | GLuint i; |
Brian Paul | a6ed6f4 | 2003-08-27 14:48:16 +0000 | [diff] [blame] | 878 | |
Brian Paul | f7b4e0d | 2004-04-23 20:33:07 +0000 | [diff] [blame] | 879 | #ifdef MANGLE |
| 880 | if (funcName[0] != 'm' || funcName[1] != 'g' || funcName[2] != 'l') |
| 881 | return NULL; |
| 882 | #else |
Brian Paul | a6ed6f4 | 2003-08-27 14:48:16 +0000 | [diff] [blame] | 883 | if (funcName[0] != 'g' || funcName[1] != 'l') |
| 884 | return NULL; |
Brian Paul | f7b4e0d | 2004-04-23 20:33:07 +0000 | [diff] [blame] | 885 | #endif |
Brian Paul | a6ed6f4 | 2003-08-27 14:48:16 +0000 | [diff] [blame] | 886 | |
| 887 | /* search extension functions first */ |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 888 | for (i = 0; i < NumExtEntryPoints; i++) { |
Ian Romanick | 1585c23 | 2005-07-28 00:29:51 +0000 | [diff] [blame] | 889 | if (strcmp(ExtEntryTable[i].name, funcName) == 0) { |
| 890 | return ExtEntryTable[i].dispatch_stub; |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 891 | } |
| 892 | } |
| 893 | |
Dave Airlie | f236300 | 2006-02-10 21:46:17 +0000 | [diff] [blame] | 894 | #if !defined( XFree86Server ) && !defined( XGLServer ) |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 895 | /* search static functions */ |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 896 | { |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 897 | const _glapi_proc func = get_static_proc_address(funcName); |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 898 | if (func) |
| 899 | return func; |
| 900 | } |
Ian Romanick | 44b1bd7 | 2005-10-11 16:56:39 +0000 | [diff] [blame] | 901 | #endif /* !defined( XFree86Server ) */ |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 902 | |
Ian Romanick | 1585c23 | 2005-07-28 00:29:51 +0000 | [diff] [blame] | 903 | entry = add_function_name(funcName); |
| 904 | return (entry == NULL) ? NULL : entry->dispatch_stub; |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 905 | } |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 906 | |
| 907 | |
| 908 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 909 | /** |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 910 | * Return the name of the function at the given dispatch offset. |
| 911 | * This is only intended for debugging. |
| 912 | */ |
Ian Romanick | 967b006 | 2005-08-10 23:54:15 +0000 | [diff] [blame] | 913 | const char * |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 914 | _glapi_get_proc_name(GLuint offset) |
| 915 | { |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 916 | GLuint i; |
Ian Romanick | 7867799 | 2004-05-27 00:05:13 +0000 | [diff] [blame] | 917 | const char * n; |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 918 | |
| 919 | /* search built-in functions */ |
Ian Romanick | 7867799 | 2004-05-27 00:05:13 +0000 | [diff] [blame] | 920 | n = get_static_proc_name(offset); |
| 921 | if ( n != NULL ) { |
| 922 | return n; |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | /* search added extension functions */ |
| 926 | for (i = 0; i < NumExtEntryPoints; i++) { |
Ian Romanick | 1585c23 | 2005-07-28 00:29:51 +0000 | [diff] [blame] | 927 | if (ExtEntryTable[i].dispatch_offset == offset) { |
| 928 | return ExtEntryTable[i].name; |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 929 | } |
| 930 | } |
| 931 | return NULL; |
| 932 | } |
| 933 | |
| 934 | |
| 935 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 936 | /** |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 937 | * Return size of dispatch table struct as number of functions (or |
| 938 | * slots). |
| 939 | */ |
Adam Jackson | 791ce02 | 2004-12-15 23:14:29 +0000 | [diff] [blame] | 940 | PUBLIC GLuint |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 941 | _glapi_get_dispatch_table_size(void) |
| 942 | { |
| 943 | return DISPATCH_TABLE_SIZE; |
| 944 | } |
| 945 | |
| 946 | |
| 947 | |
Brian Paul | 767e15a | 2004-11-27 03:51:11 +0000 | [diff] [blame] | 948 | /** |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 949 | * Make sure there are no NULL pointers in the given dispatch table. |
Brian Paul | 5104b4d | 2002-03-07 21:50:41 +0000 | [diff] [blame] | 950 | * Intended for debugging purposes. |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 951 | */ |
Ian Romanick | 967b006 | 2005-08-10 23:54:15 +0000 | [diff] [blame] | 952 | void |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 953 | _glapi_check_table(const struct _glapi_table *table) |
| 954 | { |
Brian Paul | 5104b4d | 2002-03-07 21:50:41 +0000 | [diff] [blame] | 955 | #ifdef DEBUG |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 956 | const GLuint entries = _glapi_get_dispatch_table_size(); |
| 957 | const void **tab = (const void **) table; |
| 958 | GLuint i; |
| 959 | for (i = 1; i < entries; i++) { |
| 960 | assert(tab[i]); |
| 961 | } |
| 962 | |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 963 | /* Do some spot checks to be sure that the dispatch table |
| 964 | * slots are assigned correctly. |
| 965 | */ |
| 966 | { |
| 967 | GLuint BeginOffset = _glapi_get_proc_offset("glBegin"); |
| 968 | char *BeginFunc = (char*) &table->Begin; |
| 969 | GLuint offset = (BeginFunc - (char *) table) / sizeof(void *); |
| 970 | assert(BeginOffset == _gloffset_Begin); |
| 971 | assert(BeginOffset == offset); |
| 972 | } |
| 973 | { |
| 974 | GLuint viewportOffset = _glapi_get_proc_offset("glViewport"); |
| 975 | char *viewportFunc = (char*) &table->Viewport; |
| 976 | GLuint offset = (viewportFunc - (char *) table) / sizeof(void *); |
| 977 | assert(viewportOffset == _gloffset_Viewport); |
| 978 | assert(viewportOffset == offset); |
| 979 | } |
| 980 | { |
| 981 | GLuint VertexPointerOffset = _glapi_get_proc_offset("glVertexPointer"); |
| 982 | char *VertexPointerFunc = (char*) &table->VertexPointer; |
| 983 | GLuint offset = (VertexPointerFunc - (char *) table) / sizeof(void *); |
| 984 | assert(VertexPointerOffset == _gloffset_VertexPointer); |
| 985 | assert(VertexPointerOffset == offset); |
| 986 | } |
| 987 | { |
| 988 | GLuint ResetMinMaxOffset = _glapi_get_proc_offset("glResetMinmax"); |
| 989 | char *ResetMinMaxFunc = (char*) &table->ResetMinmax; |
| 990 | GLuint offset = (ResetMinMaxFunc - (char *) table) / sizeof(void *); |
| 991 | assert(ResetMinMaxOffset == _gloffset_ResetMinmax); |
| 992 | assert(ResetMinMaxOffset == offset); |
| 993 | } |
| 994 | { |
| 995 | GLuint blendColorOffset = _glapi_get_proc_offset("glBlendColor"); |
| 996 | char *blendColorFunc = (char*) &table->BlendColor; |
| 997 | GLuint offset = (blendColorFunc - (char *) table) / sizeof(void *); |
| 998 | assert(blendColorOffset == _gloffset_BlendColor); |
| 999 | assert(blendColorOffset == offset); |
| 1000 | } |
| 1001 | { |
Brian Paul | a14cbff | 2000-10-27 18:31:21 +0000 | [diff] [blame] | 1002 | GLuint secondaryColor3fOffset = _glapi_get_proc_offset("glSecondaryColor3fEXT"); |
| 1003 | char *secondaryColor3fFunc = (char*) &table->SecondaryColor3fEXT; |
| 1004 | GLuint offset = (secondaryColor3fFunc - (char *) table) / sizeof(void *); |
| 1005 | assert(secondaryColor3fOffset == _gloffset_SecondaryColor3fEXT); |
| 1006 | assert(secondaryColor3fOffset == offset); |
Brian Paul | a14cbff | 2000-10-27 18:31:21 +0000 | [diff] [blame] | 1007 | } |
Brian Paul | 91d6f12 | 2002-05-29 15:23:16 +0000 | [diff] [blame] | 1008 | { |
| 1009 | GLuint pointParameterivOffset = _glapi_get_proc_offset("glPointParameterivNV"); |
| 1010 | char *pointParameterivFunc = (char*) &table->PointParameterivNV; |
| 1011 | GLuint offset = (pointParameterivFunc - (char *) table) / sizeof(void *); |
| 1012 | assert(pointParameterivOffset == _gloffset_PointParameterivNV); |
| 1013 | assert(pointParameterivOffset == offset); |
Brian Paul | 91d6f12 | 2002-05-29 15:23:16 +0000 | [diff] [blame] | 1014 | } |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 1015 | { |
| 1016 | GLuint setFenceOffset = _glapi_get_proc_offset("glSetFenceNV"); |
| 1017 | char *setFenceFunc = (char*) &table->SetFenceNV; |
| 1018 | GLuint offset = (setFenceFunc - (char *) table) / sizeof(void *); |
| 1019 | assert(setFenceOffset == _gloffset_SetFenceNV); |
| 1020 | assert(setFenceOffset == offset); |
Brian Paul | 54f3aab | 2002-10-02 01:51:44 +0000 | [diff] [blame] | 1021 | } |
Brian Paul | a6c423d | 2004-08-25 15:59:48 +0000 | [diff] [blame] | 1022 | #else |
| 1023 | (void) table; |
Brian Paul | 959f802 | 2000-03-19 01:10:11 +0000 | [diff] [blame] | 1024 | #endif |
| 1025 | } |
Ian Romanick | 25fe93f | 2005-04-13 20:59:15 +0000 | [diff] [blame] | 1026 | |
| 1027 | |
Kristian Høgsberg | 3a6d968 | 2006-03-29 22:32:38 +0000 | [diff] [blame] | 1028 | #if defined(PTHREADS) || defined(GLX_USE_TLS) |
Ian Romanick | 25fe93f | 2005-04-13 20:59:15 +0000 | [diff] [blame] | 1029 | /** |
| 1030 | * Perform platform-specific GL API entry-point fixups. |
Ian Romanick | 25fe93f | 2005-04-13 20:59:15 +0000 | [diff] [blame] | 1031 | */ |
| 1032 | static void |
| 1033 | init_glapi_relocs( void ) |
| 1034 | { |
Brian | edf0741 | 2007-06-12 09:47:03 -0600 | [diff] [blame^] | 1035 | #if defined(USE_X86_ASM) && defined(GLX_USE_TLS) && !defined(GLX_X86_READONLY_TEXT) |
| 1036 | extern unsigned long _x86_get_dispatch(void); |
| 1037 | char run_time_patch[] = { |
| 1038 | 0x65, 0xa1, 0, 0, 0, 0 /* movl %gs:0,%eax */ |
| 1039 | }; |
| 1040 | GLuint *offset = (GLuint *) &run_time_patch[2]; /* 32-bits for x86/32 */ |
| 1041 | const GLubyte * const get_disp = (const GLubyte *) run_time_patch; |
Ian Romanick | 25fe93f | 2005-04-13 20:59:15 +0000 | [diff] [blame] | 1042 | GLubyte * curr_func = (GLubyte *) gl_dispatch_functions_start; |
| 1043 | |
Brian | edf0741 | 2007-06-12 09:47:03 -0600 | [diff] [blame^] | 1044 | *offset = _x86_get_dispatch(); |
Ian Romanick | 25fe93f | 2005-04-13 20:59:15 +0000 | [diff] [blame] | 1045 | while ( curr_func != (GLubyte *) gl_dispatch_functions_end ) { |
Brian | edf0741 | 2007-06-12 09:47:03 -0600 | [diff] [blame^] | 1046 | (void) memcpy( curr_func, get_disp, sizeof(run_time_patch)); |
Ian Romanick | d319edf | 2006-08-22 18:22:20 +0000 | [diff] [blame] | 1047 | curr_func += DISPATCH_FUNCTION_SIZE; |
Ian Romanick | 25fe93f | 2005-04-13 20:59:15 +0000 | [diff] [blame] | 1048 | } |
Kristian Høgsberg | 3a6d968 | 2006-03-29 22:32:38 +0000 | [diff] [blame] | 1049 | #endif |
Brian | edf0741 | 2007-06-12 09:47:03 -0600 | [diff] [blame^] | 1050 | } |
| 1051 | #endif /* defined(PTHREADS) || defined(GLX_USE_TLS) */ |