-<HTML>
-<HEAD>
-<TITLE>GL Dispatch in Mesa</TITLE>
-<LINK REL="stylesheet" TYPE="text/css" HREF="mesa.css">
-</HEAD>
-
-<BODY>
-<H1>GL Dispatch in Mesa</H1>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html lang="en">
+<head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+ <title>GL Dispatch in Mesa</title>
+ <link rel="stylesheet" type="text/css" href="mesa.css">
+</head>
+<body>
+<h1>GL Dispatch in Mesa</h1>
<p>Several factors combine to make efficient dispatch of OpenGL functions
fairly complicated. This document attempts to explain some of the issues
and introduce the reader to Mesa's implementation. Readers already familiar
-with the issues around GL dispatch can safely skip ahead to the <A
-HREF="#overview">overview of Mesa's implementation</A>.</p>
+with the issues around GL dispatch can safely skip ahead to the <a
+href="#overview">overview of Mesa's implementation</a>.</p>
-<H2>1. Complexity of GL Dispatch</H2>
+<h2>1. Complexity of GL Dispatch</h2>
<p>Every GL application has at least one object called a GL <em>context</em>.
This object, which is an implicit parameter to ever GL function, stores all
has to know which GL context is current in the thread where it is being
called.</p>
-<A NAME="overview"/>
-<H2>2. Overview of Mesa's Implementation</H2>
+<h2 id="overview">2. Overview of Mesa's Implementation</h2>
<p>Mesa uses two per-thread pointers. The first pointer stores the address
of the context current in the thread, and the second pointer stores the
void glVertex3f(GLfloat x, GLfloat y, GLfloat z)
{
const struct _glapi_table * const dispatch = GET_DISPATCH();
-
+
(*dispatch->Vertex3f)(x, y, z);
}</pre></td></tr>
<tr><td>Sample dispatch function</td></tr></table>
<p>The problem with this simple implementation is the large amount of
overhead that it adds to every GL function call.</p>
-<p>In a multithreaded environment, a niave implementation of
+<p>In a multithreaded environment, a naive implementation of
<tt>GET_DISPATCH</tt> involves a call to <tt>pthread_getspecific</tt> or a
similar function. Mesa provides a wrapper function called
<tt>_glapi_get_dispatch</tt> that is used by default.</p>
-<H2>3. Optimizations</H2>
+<h2>3. Optimizations</h2>
<p>A number of optimizations have been made over the years to diminish the
performance hit imposed by GL dispatch. This section describes these
optimizations. The benefits of each optimization and the situations where
each can or cannot be used are listed.</p>
-<H3>3.1. Dual dispatch table pointers</H3>
+<h3>3.1. Dual dispatch table pointers</h3>
<p>The vast majority of OpenGL applications use the API in a single threaded
manner. That is, the application has only one thread that makes calls into
<tr><td>Improved <tt>GET_DISPATCH</tt> Implementation</td></tr></table>
</blockquote>
-<H3>3.2. ELF TLS</H3>
+<h3>3.2. ELF TLS</h3>
<p>Starting with the 2.4.20 Linux kernel, each thread is allocated an area
of per-thread, global storage. Variables can be put in this area using some
<tt>GLX_USE_TLS</tt>. Any platform capable of using TLS should use this as
the default dispatch method.</p>
-<H3>3.3. Assembly Language Dispatch Stubs</H3>
+<h3>3.3. Assembly Language Dispatch Stubs</h3>
<p>Many platforms has difficulty properly optimizing the tail-call in the
dispatch stubs. Platforms like x86 that pass parameters on the stack seem
language versions. The amount of optimization provided by using assembly
stubs varies from platform to platform and application to application.
However, by using the assembly stubs, many platforms can use an additional
-space optimization (see <A HREF="#fixedsize">below</A>).</p>
+space optimization (see <a href="#fixedsize">below</a>).</p>
<p>The biggest hurdle to creating assembly stubs is handling the various
ways that the dispatch table pointer can be accessed. There are four
<ul>
<li>If <tt>GLX_USE_TLS</tt> is defined, method #4 is used.</li>
<li>If <tt>PTHREADS</tt> is defined, method #3 is used.</li>
-<li>If any of <tt>PTHREADS</tt>,
-<tt>SOLARIS_THREADS</tt>, <tt>WIN32_THREADS</tt>, or <tt>BEOS_THREADS</tt>
-is defined, method #2 is used.</li>
+<li>If <tt>WIN32_THREADS</tt> is defined, method #2 is used.</li>
<li>If none of the preceeding are defined, method #1 is used.</li>
</ul>
larger (e.g., 29,332 lines for <tt>glapi_x86-64.S</tt> versus 1,155 lines for
<tt>glapi_x86.S</tt>) and causes simple changes to the function
implementation to generate many lines of diffs. Since the assmebly files
-are typically generated by scripts (see <A HREF="#autogen">below</A>), this
+are typically generated by scripts (see <a href="#autogen">below</a>), this
isn't a significant problem.</p>
<p>Once a new assembly file is created, it must be inserted in the build
system. There are two steps to this. The file must first be added to
<tt>src/mesa/sources</tt>. That gets the file built and linked. The second
step is to add the correct <tt>#ifdef</tt> magic to
-<tt>src/mesa/main/dispatch.c</tt> to prevent the C version of the dispatch
-functions from being built.</p>
+<tt>src/mesa/glapi/glapi_dispatch.c</tt> to prevent the C version of the
+dispatch functions from being built.</p>
-<A NAME="fixedsize"/>
-<H3>3.4. Fixed-Length Dispatch Stubs</H3>
+<h3 id="fixedsize">3.4. Fixed-Length Dispatch Stubs</h3>
<p>To implement <tt>glXGetProcAddress</tt>, Mesa stores a table that
associates function names with pointers to those functions. This table is
<tt>src/mesa/glapi/glapi.c</tt> just before <tt>glprocs.h</tt> is
included.</p>
-<A NAME="autogen"/>
-<H2>4. Automatic Generation of Dispatch Stubs</H2>
+<h2 id="autogen">4. Automatic Generation of Dispatch Stubs</h2>
-</BODY>
-</HTML>
+</body>
+</html>