~ubuntu-branches/ubuntu/quantal/mesa/quantal

« back to all changes in this revision

Viewing changes to docs/drivers.html

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-02-21 12:44:07 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20070221124407-rgcacs32mycrtadl
ImportĀ upstreamĀ versionĀ 6.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<HTML>
 
2
 
 
3
<TITLE>Writing Mesa Device Drivers</TITLE>
 
4
 
 
5
<BODY text="#000000" bgcolor="#55bbff" link="#111188">
 
6
 
 
7
<center><h1>Writing Mesa Device Drivers</h1></center>
 
8
 
 
9
<h2>Introduction</h2>
 
10
 
 
11
<p>
 
12
Several different classes of drivers can be identified:
 
13
</p>
 
14
<ul>
 
15
<li><b>100% Software Driver</b> -
 
16
    a software driver that does not utilize accelerated graphics hardware.
 
17
    Such a driver will basically just write (and read) pixel values to the
 
18
    computer's frame buffer or a malloc'd color buffer.
 
19
    Examples include the X11/XMesa driver, the Windows driver and OSMesa.
 
20
</li>
 
21
<br>
 
22
<li><b>Hardware Rasterization Driver</b> -
 
23
    for graphics hardware that implements accelerated point/line/triangle
 
24
    rasterization, but relies on core Mesa for vertex transformation.
 
25
    Examples include the DRI 3Dfx, Matrox, and Rage 128 drivers.
 
26
</li>
 
27
<br>
 
28
<li><b>Hardware Transformation and Rasterization Driver</b> -
 
29
    for graphics hardware that implements accelerated rasterization and vertex
 
30
    transformation.
 
31
    Examples include the DRI Radeon and R200 drivers.
 
32
</li>
 
33
</ul>
 
34
 
 
35
<p>
 
36
Each class of driver builds on the functionality of the preceeding one.
 
37
For example, a hardware rasterization driver may need to fall back to
 
38
software rasterization when a particular OpenGL state combination is set
 
39
but not supported by the hardware (perhaps smooth, stippled, textured
 
40
triangles).
 
41
</p>
 
42
 
 
43
<p>
 
44
Likewise, a hardware transformation driver might need to fall back to
 
45
software-based transformation when a particular, seldom-used lighting
 
46
mode is enabled.
 
47
</p>
 
48
 
 
49
 
 
50
<h2>Getting Started</h2>
 
51
 
 
52
<p>
 
53
The best way to get started writing a new driver is to find an existing
 
54
driver similar to what you plan to implement, and then study it.
 
55
</p>
 
56
<p>
 
57
It's not feasible for this document to explain every detail of writing
 
58
a driver.
 
59
The minute details can be gleaned by looking at existing drivers.
 
60
This document focuses on the high-level concepts and will perhaps expand
 
61
on the details in the future.
 
62
</p>
 
63
<p>
 
64
For examples of 100% software drivers, the OSMesa and XMesa (fake/stand-alone
 
65
GLX) drivers are the best examples.
 
66
</p>
 
67
<p>
 
68
For examples of hardware drivers, the DRI Radeon and R200 drivers are good
 
69
examples.
 
70
</p>
 
71
 
 
72
 
 
73
 
 
74
<h2>Programming API vs. Drivers</h2>
 
75
 
 
76
<p>
 
77
There are two aspects to a Mesa device driver:
 
78
</p>
 
79
 
 
80
<ul>
 
81
<li><b>Public programming API</b> -
 
82
    this is the interface which application programmers use.
 
83
    Examples are the GLX, WGL and OSMesa interfaces.
 
84
    If you're developing a device driver for a new operating system or
 
85
    window system you'll have to design and implement an <em>OpenGL glue</em>
 
86
    interface similar to these.
 
87
    This interface will, in turn, communicate with the internal driver code.
 
88
</li>
 
89
<br>
 
90
<li><b>Private/internal driver code</b> -
 
91
    this is the code which (effectively) translates OpenGL API calls into
 
92
    rendering operations.
 
93
    The device driver must manage hardware resources, track OpenGL state
 
94
    and implement or dispatch the fundamental rendering operations such as
 
95
    point, line, triangle and image rendering.
 
96
</li>
 
97
</ul>
 
98
 
 
99
<p>
 
100
The remainder of this document will focus on the later part.
 
101
Furthermore, we'll use the GLX interface for examples.
 
102
</p>
 
103
 
 
104
<p>
 
105
In the case of the DRI drivers, the public GLX interface is contained in
 
106
the <b>libGL.so</b> library.
 
107
libGL.so, in turn, dynamically loads one of the DRI drivers (such as
 
108
radeon_dri.so).
 
109
Both libGL.so and the driver modules talk to the X window system via the
 
110
DRI extension.
 
111
Furthermore, the driver modules interface to the graphics hardware with
 
112
the help of a kernel module and the conventional 2D X server driver.
 
113
</p>
 
114
 
 
115
 
 
116
 
 
117
 
 
118
<h2>Software Driver Overview</h2>
 
119
 
 
120
<p>
 
121
A software driver is primarily concerned with writing pixel values to the
 
122
system's color buffer (and reading them back).
 
123
The color buffers might be window canvases (typically the front
 
124
color buffer) and/or off-screen image buffers (typically the back color
 
125
buffer).
 
126
The depth, stencil and accumulation buffers will be implemented within
 
127
core Mesa.
 
128
</p>
 
129
<p>
 
130
The software driver must also be concerned with allocation and deallocation
 
131
of rendering contexts, frame buffers and pixel formats (visuals).
 
132
</p>
 
133
 
 
134
 
 
135
<h3>Rendering Contexts</h3>
 
136
 
 
137
<p>
 
138
The glue interface will always have a function for creating new rendering
 
139
contexts (such as glXCreateContext).
 
140
The device driver must have a function which allocates and initializes
 
141
a device-specific rendering context.
 
142
</p>
 
143
 
 
144
 
 
145
<h3>Frame Buffers</h3>
 
146
 
 
147
<p>
 
148
The <em>frame buffer</em> can either be a screen region defined by a window
 
149
or the entire screen.
 
150
</p>
 
151
<p>
 
152
In either case, the device driver must implement functions for allocating,
 
153
initializing and managing frame buffers.
 
154
<p>
 
155
 
 
156
 
 
157
<h3>Spans</h3>
 
158
 
 
159
<p>
 
160
The fundamental rendering operation is to write (and read)
 
161
<em>spans</em> of pixels to the front / back color buffers.
 
162
A span is a horizontal array of pixel colors with an array of mask
 
163
flags.  The span begins at a particular (x,y) screen coordinate,
 
164
extends for N pixels, describes N RGBA colors (or color indexes) and
 
165
has an array of N boolean flags indicating which pixels to write and skip.
 
166
<p>
 
167
 
 
168
<h3>Miscellaneous functions</h3>
 
169
 
 
170
<p>
 
171
Additionally, a software driver will typically have functions for
 
172
binding rendering contexts to frame buffers (via glXMakeCurrent),
 
173
swapping color buffers (via glXSwapBuffers), synchronization
 
174
(via glFlush/glFinish) and queries (via glGetString).
 
175
</p>
 
176
 
 
177
<h3>Optimizations</h3>
 
178
 
 
179
<p>
 
180
A software driver might implement optimized routines for drawing lines
 
181
and triangles for common cases (such as smooth shading with depth-testing).
 
182
Then, the span functions can be bypassed for a little extra speed.
 
183
The OSMesa and XMesa drivers have examples of this.
 
184
</p>
 
185
 
 
186
 
 
187
 
 
188
 
 
189
 
 
190
 
 
191
 
 
192
<h2>Hardware Driver Overview</h2>
 
193
 
 
194
<p>
 
195
To do...
 
196
</p>
 
197
 
 
198
 
 
199
 
 
200
<h2>OOP-Style Inheritance and Specialization</h2>
 
201
 
 
202
<p>
 
203
Even though Mesa and most device drivers are written in C, object oriented
 
204
programming principles are used in several places.
 
205
</p>
 
206
 
 
207
<h3>Rendering Contexts</h3>
 
208
 
 
209
<p>
 
210
Every Mesa device driver will need to define a device-specific rendering
 
211
context structure.
 
212
</p>
 
213
 
 
214
 
 
215
<h2>State Tracking</h2>
 
216
 
 
217
 
 
218
 
 
219
 
 
220
</BODY>
 
221
</HTML>