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