blob: be0308321a7d3b55fb27f7459890c558793cddd4 [file] [log] [blame]
Andreas Bollecd5c7c2012-06-12 09:05:03 +02001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2<html lang="en">
3<head>
4 <meta http-equiv="content-type" content="text/html; charset=utf-8">
5 <title>llvmpipe</title>
6 <link rel="stylesheet" type="text/css" href="mesa.css">
7</head>
8<body>
Brian Paul0da2a222011-04-07 13:56:45 -06009
Andreas Bollb5da52a2012-09-18 18:57:02 +020010<div class="header">
11 <h1>The Mesa 3D Graphics Library</h1>
12</div>
13
14<iframe src="contents.html"></iframe>
15<div class="content">
16
Andreas Bollecd5c7c2012-06-12 09:05:03 +020017<h1>Introduction</h1>
Brian Paul0da2a222011-04-07 13:56:45 -060018
19<p>
20The Gallium llvmpipe driver is a software rasterizer that uses LLVM to
21do runtime code generation.
22Shaders, point/line/triangle rasterization and vertex processing are
23implemented with LLVM IR which is translated to x86 or x86-64 machine
24code.
25Also, the driver is multithreaded to take advantage of multiple CPU cores
26(up to 8 at this time).
27It's the fastest software rasterizer for Mesa.
28</p>
José Fonseca9285f152009-08-10 12:35:16 +010029
30
Brian Paul0da2a222011-04-07 13:56:45 -060031<h1>Requirements</h1>
José Fonseca9285f152009-08-10 12:35:16 +010032
José Fonseca65d0c842011-11-05 10:38:16 +000033<ul>
34<li>
Andreas Bollfd64b392012-06-12 09:05:49 +020035 <p>An x86 or amd64 processor; 64-bit mode recommended.</p>
Brian Paul0da2a222011-04-07 13:56:45 -060036 <p>
Matt Turner9f52b872011-11-05 17:11:59 -040037 Support for SSE2 is strongly encouraged. Support for SSSE3 and SSE4.1 will
38 yield the most efficient code. The fewer features the CPU has the more
Andreas Bollfd64b392012-06-12 09:05:49 +020039 likely is that you run into underperforming, buggy, or incomplete code.
Brian Paul0da2a222011-04-07 13:56:45 -060040 </p>
41 <p>
José Fonsecada1c4022009-11-26 11:15:08 +000042 See /proc/cpuinfo to know what your CPU supports.
Brian Paul0da2a222011-04-07 13:56:45 -060043 </p>
José Fonseca65d0c842011-11-05 10:38:16 +000044</li>
45<li>
Andreas Bolldf2be222012-06-12 09:05:22 +020046 <p>LLVM: version 2.9 recommended; 2.6 or later required.</p>
47 <p><b>NOTE</b>: LLVM 2.8 and earlier will not work on systems that support the
Brian Paul06613b72011-04-07 13:43:00 -060048 Intel AVX extensions (e.g. Sandybridge). LLVM's code generator will
49 fail when trying to emit AVX instructions. This was fixed in LLVM 2.9.
Brian Paul0da2a222011-04-07 13:56:45 -060050 </p>
51 <p>
José Fonseca12576552010-01-10 18:37:07 +000052 For Linux, on a recent Debian based distribution do:
Brian Paul0da2a222011-04-07 13:56:45 -060053 </p>
54<pre>
José Fonseca9285f152009-08-10 12:35:16 +010055 aptitude install llvm-dev
Brian Paul0da2a222011-04-07 13:56:45 -060056</pre>
Andreas Bolldf2be222012-06-12 09:05:22 +020057 <p>
Brian Paul0da2a222011-04-07 13:56:45 -060058 For a RPM-based distribution do:
59 </p>
60<pre>
61 yum install llvm-devel
62</pre>
José Fonseca19b31d02009-08-10 15:43:04 +010063
Brian Paul0da2a222011-04-07 13:56:45 -060064 <p>
José Fonseca65d0c842011-11-05 10:38:16 +000065 For Windows you will need to build LLVM from source with MSVC or MINGW
66 (either natively or through cross compilers) and CMake, and set the LLVM
67 environment variable to the directory you installed it to.
José Fonseca19b31d02009-08-10 15:43:04 +010068
José Fonseca65d0c842011-11-05 10:38:16 +000069 LLVM will be statically linked, so when building on MSVC it needs to be
70 built with a matching CRT as Mesa, and you'll need to pass
71 -DLLVM_USE_CRT_RELEASE=MTd for debug and checked builds,
72 -DLLVM_USE_CRT_RELEASE=MTd for profile and release builds.
José Fonsecaf379e7d2010-05-13 16:18:05 +010073
José Fonseca65d0c842011-11-05 10:38:16 +000074 You can build only the x86 target by passing -DLLVM_TARGETS_TO_BUILD=X86
75 to cmake.
Brian Paul0da2a222011-04-07 13:56:45 -060076 </p>
José Fonseca65d0c842011-11-05 10:38:16 +000077</li>
José Fonsecaf379e7d2010-05-13 16:18:05 +010078
José Fonseca65d0c842011-11-05 10:38:16 +000079<li>
80 <p>scons (optional)</p>
81</li>
82</ul>
83
José Fonseca9285f152009-08-10 12:35:16 +010084
Brian Paul0da2a222011-04-07 13:56:45 -060085<h1>Building</h1>
José Fonseca9285f152009-08-10 12:35:16 +010086
José Fonseca12576552010-01-10 18:37:07 +000087To build everything on Linux invoke scons as:
José Fonseca9285f152009-08-10 12:35:16 +010088
Brian Paul0da2a222011-04-07 13:56:45 -060089<pre>
José Fonseca601498a2010-11-01 13:30:22 +000090 scons build=debug libgl-xlib
Brian Paul0da2a222011-04-07 13:56:45 -060091</pre>
José Fonseca9285f152009-08-10 12:35:16 +010092
José Fonseca5811ed82009-08-22 22:26:55 +010093Alternatively, you can build it with GNU make, if you prefer, by invoking it as
94
Brian Paul0da2a222011-04-07 13:56:45 -060095<pre>
José Fonseca5811ed82009-08-22 22:26:55 +010096 make linux-llvm
Brian Paul0da2a222011-04-07 13:56:45 -060097</pre>
José Fonseca5811ed82009-08-22 22:26:55 +010098
José Fonseca1fc41002009-09-11 11:24:00 +010099but the rest of these instructions assume that scons is used.
José Fonseca5811ed82009-08-22 22:26:55 +0100100
José Fonseca65d0c842011-11-05 10:38:16 +0000101For Windows the procedure is similar except the target:
José Fonseca12576552010-01-10 18:37:07 +0000102
Brian Paul0da2a222011-04-07 13:56:45 -0600103<pre>
José Fonseca601498a2010-11-01 13:30:22 +0000104 scons build=debug libgl-gdi
Brian Paul0da2a222011-04-07 13:56:45 -0600105</pre>
José Fonseca9285f152009-08-10 12:35:16 +0100106
Brian Paul0da2a222011-04-07 13:56:45 -0600107
108<h1>Using</h1>
José Fonseca9285f152009-08-10 12:35:16 +0100109
José Fonseca601498a2010-11-01 13:30:22 +0000110On Linux, building will create a drop-in alternative for libGL.so into
José Fonseca9285f152009-08-10 12:35:16 +0100111
Brian Paul0da2a222011-04-07 13:56:45 -0600112<pre>
José Fonseca601498a2010-11-01 13:30:22 +0000113 build/foo/gallium/targets/libgl-xlib/libGL.so
Brian Paul0da2a222011-04-07 13:56:45 -0600114</pre>
115or
116<pre>
117 lib/gallium/libGL.so
118</pre>
José Fonseca9285f152009-08-10 12:35:16 +0100119
José Fonseca601498a2010-11-01 13:30:22 +0000120To use it set the LD_LIBRARY_PATH environment variable accordingly.
José Fonseca5811ed82009-08-22 22:26:55 +0100121
José Fonseca1fc41002009-09-11 11:24:00 +0100122For performance evaluation pass debug=no to scons, and use the corresponding
123lib directory without the "-debug" suffix.
124
José Fonseca12576552010-01-10 18:37:07 +0000125On Windows, building will create a drop-in alternative for opengl32.dll. To use
126it put it in the same directory as the application. It can also be used by
127replacing the native ICD driver, but it's quite an advanced usage, so if you
128need to ask, don't even try it.
129
José Fonseca9285f152009-08-10 12:35:16 +0100130
Brian Paul0da2a222011-04-07 13:56:45 -0600131<h1>Profiling</h1>
José Fonseca388c9412010-09-21 17:50:30 +0100132
133To profile llvmpipe you should pass the options
134
Brian Paul0da2a222011-04-07 13:56:45 -0600135<pre>
Andreas Boll703a6622012-06-12 09:05:15 +0200136 scons build=profile &lt;same-as-before&gt;
Brian Paul0da2a222011-04-07 13:56:45 -0600137</pre>
José Fonseca388c9412010-09-21 17:50:30 +0100138
139This will ensure that frame pointers are used both in C and JIT functions, and
140that no tail call optimizations are done by gcc.
141
José Fonseca388c9412010-09-21 17:50:30 +0100142To better profile JIT code you'll need to build LLVM with oprofile integration.
143
Brian Paul0da2a222011-04-07 13:56:45 -0600144<pre>
José Fonsecae6314db2011-03-13 19:24:26 +0000145 ./configure \
José Fonseca388c9412010-09-21 17:50:30 +0100146 --prefix=$install_dir \
147 --enable-optimized \
148 --disable-profiling \
149 --enable-targets=host-only \
150 --with-oprofile
151
152 make -C "$build_dir"
153 make -C "$build_dir" install
154
155 find "$install_dir/lib" -iname '*.a' -print0 | xargs -0 strip --strip-debug
Brian Paul0da2a222011-04-07 13:56:45 -0600156</pre>
José Fonseca388c9412010-09-21 17:50:30 +0100157
158The you should define
159
Brian Paul0da2a222011-04-07 13:56:45 -0600160<pre>
José Fonseca388c9412010-09-21 17:50:30 +0100161 export LLVM=/path/to/llvm-2.6-profile
Brian Paul0da2a222011-04-07 13:56:45 -0600162</pre>
José Fonseca388c9412010-09-21 17:50:30 +0100163
164and rebuild.
165
166
Brian Paul0da2a222011-04-07 13:56:45 -0600167<h1>Unit testing</h1>
José Fonseca9285f152009-08-10 12:35:16 +0100168
Brian Paul0da2a222011-04-07 13:56:45 -0600169<p>
José Fonseca9285f152009-08-10 12:35:16 +0100170Building will also create several unit tests in
171build/linux-???-debug/gallium/drivers/llvmpipe:
Brian Paul0da2a222011-04-07 13:56:45 -0600172</p>
José Fonseca9285f152009-08-10 12:35:16 +0100173
Andreas Bolldf2be222012-06-12 09:05:22 +0200174<ul>
Brian Paul0da2a222011-04-07 13:56:45 -0600175<li> lp_test_blend: blending
176<li> lp_test_conv: SIMD vector conversion
177<li> lp_test_format: pixel unpacking/packing
178</ul>
José Fonseca9285f152009-08-10 12:35:16 +0100179
Brian Paul0da2a222011-04-07 13:56:45 -0600180<p>
José Fonseca1fc41002009-09-11 11:24:00 +0100181Some of this tests can output results and benchmarks to a tab-separated-file
José Fonseca89146cd2009-08-20 10:21:49 +0100182for posterior analysis, e.g.:
Brian Paul0da2a222011-04-07 13:56:45 -0600183</p>
184<pre>
José Fonseca5811ed82009-08-22 22:26:55 +0100185 build/linux-x86_64-debug/gallium/drivers/llvmpipe/lp_test_blend -o blend.tsv
Brian Paul0da2a222011-04-07 13:56:45 -0600186</pre>
José Fonseca9285f152009-08-10 12:35:16 +0100187
José Fonsecac5531f52009-08-21 10:57:48 +0100188
Brian Paul0da2a222011-04-07 13:56:45 -0600189<h1>Development Notes</h1>
José Fonsecac5531f52009-08-21 10:57:48 +0100190
Brian Paul0da2a222011-04-07 13:56:45 -0600191<ul>
192<li>
193 When looking to this code by the first time start in lp_state_fs.c, and
José Fonseca5811ed82009-08-22 22:26:55 +0100194 then skim through the lp_bld_* functions called in there, and the comments
Andreas Bollfd64b392012-06-12 09:05:49 +0200195 at the top of the lp_bld_*.c functions.
Brian Paul0da2a222011-04-07 13:56:45 -0600196</li>
197<li>
198 The driver-independent parts of the LLVM / Gallium code are found in
Brian Pauld0b35352010-03-15 11:46:41 -0600199 src/gallium/auxiliary/gallivm/. The filenames and function prefixes
200 need to be renamed from "lp_bld_" to something else though.
Brian Paul0da2a222011-04-07 13:56:45 -0600201</li>
202<li>
203 We use LLVM-C bindings for now. They are not documented, but follow the C++
José Fonsecac5531f52009-08-21 10:57:48 +0100204 interfaces very closely, and appear to be complete enough for code
205 generation. See
206 http://npcontemplation.blogspot.com/2008/06/secret-of-llvm-c-bindings.html
José Fonseca601498a2010-11-01 13:30:22 +0000207 for a stand-alone example. See the llvm-c/Core.h file for reference.
Brian Paul0da2a222011-04-07 13:56:45 -0600208</li>
209</ul>
Andreas Bollecd5c7c2012-06-12 09:05:03 +0200210
Andreas Bollb5da52a2012-09-18 18:57:02 +0200211</div>
Andreas Bollecd5c7c2012-06-12 09:05:03 +0200212</body>
213</html>