X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=docs%2Fdispatch.html;h=c96ec2de302b522776473c42d10364aee2b8abf1;hb=66ebdfbd44cb62c58a7711fb72566f07d801809a;hp=bcab74c707096fc21dbe4b0fedf4d6ae42cae01e;hpb=82c2f7756af19f0a19aeda7ea1f627262e4561c0;p=mesa.git diff --git a/docs/dispatch.html b/docs/dispatch.html index bcab74c7070..c96ec2de302 100644 --- a/docs/dispatch.html +++ b/docs/dispatch.html @@ -1,22 +1,31 @@ - - -GL Dispatch in Mesa - - + + + + + GL Dispatch in Mesa + + + - -

GL Dispatch in Mesa

+
+

The Mesa 3D Graphics Library

+
+ + +
+ +

GL Dispatch in Mesa

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 overview of Mesa's implementation.

+with the issues around GL dispatch can safely skip ahead to the overview of Mesa's implementation.

-

1. Complexity of GL Dispatch

+

1. Complexity of GL Dispatch

Every GL application has at least one object called a GL context. -This object, which is an implicit parameter to ever GL function, stores all +This object, which is an implicit parameter to every GL function, stores all of the GL related state for the application. Every texture, every buffer object, every enable, and much, much more is stored in the context. Since an application can have more than one context, the context to be used is @@ -42,12 +51,11 @@ example, glFogCoordf may operate differently depending on whether or not fog is enabled.

In multi-threaded environments, it is possible for each thread to have a -differnt GL context current. This means that poor old glVertex3fv +different GL context current. This means that poor old glVertex3fv has to know which GL context is current in the thread where it is being called.

- -

2. Overview of Mesa's Implementation

+

2. Overview of Mesa's Implementation

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 @@ -75,7 +83,7 @@ table. void glVertex3f(GLfloat x, GLfloat y, GLfloat z) { const struct _glapi_table * const dispatch = GET_DISPATCH(); - + (*dispatch->Vertex3f)(x, y, z); } Sample dispatch function @@ -84,19 +92,19 @@ void glVertex3f(GLfloat x, GLfloat y, GLfloat z)

The problem with this simple implementation is the large amount of overhead that it adds to every GL function call.

-

In a multithreaded environment, a niave implementation of +

In a multithreaded environment, a naive implementation of GET_DISPATCH involves a call to pthread_getspecific or a similar function. Mesa provides a wrapper function called _glapi_get_dispatch that is used by default.

-

3. Optimizations

+

3. Optimizations

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.

-

3.1. Dual dispatch table pointers

+

3.1. Dual dispatch table pointers

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 @@ -131,7 +139,7 @@ the common case.

Improved GET_DISPATCH Implementation -

3.2. ELF TLS

+

3.2. ELF TLS

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 @@ -161,7 +169,7 @@ extern __thread struct _glapi_table *_glapi_tls_Dispatch GLX_USE_TLS. Any platform capable of using TLS should use this as the default dispatch method.

-

3.3. Assembly Language Dispatch Stubs

+

3.3. Assembly Language Dispatch Stubs

Many platforms has difficulty properly optimizing the tail-call in the dispatch stubs. Platforms like x86 that pass parameters on the stack seem @@ -170,7 +178,7 @@ routines are very short, and it is trivial to create optimal assembly 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 below).

+space optimization (see below).

The biggest hurdle to creating assembly stubs is handling the various ways that the dispatch table pointer can be accessed. There are four @@ -196,18 +204,15 @@ terribly relevant.

few preprocessor defines.

Two different techniques are used to handle the various different cases. On x86 and SPARC, a macro called GL_STUB is used. In the preamble of the assembly source file different implementations of the macro are -selected based on the defined preprocessor variables. The assmebly code +selected based on the defined preprocessor variables. The assembly code then consists of a series of invocations of the macros such as:

@@ -236,19 +241,18 @@ first technique, is to insert #ifdef within the assembly implementation of each function. This makes the assembly file considerably larger (e.g., 29,332 lines for glapi_x86-64.S versus 1,155 lines for glapi_x86.S) and causes simple changes to the function -implementation to generate many lines of diffs. Since the assmebly files -are typically generated by scripts (see below), this +implementation to generate many lines of diffs. Since the assembly files +are typically generated by scripts (see below), this isn't a significant problem.

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 src/mesa/sources. That gets the file built and linked. The second step is to add the correct #ifdef magic to -src/mesa/main/dispatch.c to prevent the C version of the dispatch -functions from being built.

+src/mesa/glapi/glapi_dispatch.c to prevent the C version of the +dispatch functions from being built.

- -

3.4. Fixed-Length Dispatch Stubs

+

3.4. Fixed-Length Dispatch Stubs

To implement glXGetProcAddress, Mesa stores a table that associates function names with pointers to those functions. This table is @@ -267,8 +271,8 @@ dispatch stub.

src/mesa/glapi/glapi.c just before glprocs.h is included.

-
-

4. Automatic Generation of Dispatch Stubs

+

4. Automatic Generation of Dispatch Stubs

- - +
+ +