blob: 87d1fd44d35d43a038a1f91e85bad8e292732dc7 [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 Bollecd5c7c2012-06-12 09:05:03 +020010<h1>Introduction</h1>
Brian Paul0da2a222011-04-07 13:56:45 -060011
12<p>
13The Gallium llvmpipe driver is a software rasterizer that uses LLVM to
14do runtime code generation.
15Shaders, point/line/triangle rasterization and vertex processing are
16implemented with LLVM IR which is translated to x86 or x86-64 machine
17code.
18Also, the driver is multithreaded to take advantage of multiple CPU cores
19(up to 8 at this time).
20It's the fastest software rasterizer for Mesa.
21</p>
José Fonseca9285f152009-08-10 12:35:16 +010022
23
Brian Paul0da2a222011-04-07 13:56:45 -060024<h1>Requirements</h1>
José Fonseca9285f152009-08-10 12:35:16 +010025
José Fonseca65d0c842011-11-05 10:38:16 +000026<ul>
27<li>
28 <p>An x86 or amd64 processor; 64-bit mode recommended.</p
Brian Paul0da2a222011-04-07 13:56:45 -060029 <p>
Matt Turner9f52b872011-11-05 17:11:59 -040030 Support for SSE2 is strongly encouraged. Support for SSSE3 and SSE4.1 will
31 yield the most efficient code. The fewer features the CPU has the more
32 likely is that you run into underperforming, buggy, or incomplete code.
Brian Paul0da2a222011-04-07 13:56:45 -060033 </p>
34 <p>
José Fonsecada1c4022009-11-26 11:15:08 +000035 See /proc/cpuinfo to know what your CPU supports.
Brian Paul0da2a222011-04-07 13:56:45 -060036 </p>
José Fonseca65d0c842011-11-05 10:38:16 +000037</li>
38<li>
39 <p>LLVM: version 2.9 recommended; 2.6 or later required.</p>
Brian Paul0da2a222011-04-07 13:56:45 -060040 <b>NOTE</b>: LLVM 2.8 and earlier will not work on systems that support the
Brian Paul06613b72011-04-07 13:43:00 -060041 Intel AVX extensions (e.g. Sandybridge). LLVM's code generator will
42 fail when trying to emit AVX instructions. This was fixed in LLVM 2.9.
Brian Paul0da2a222011-04-07 13:56:45 -060043 </p>
44 <p>
José Fonseca12576552010-01-10 18:37:07 +000045 For Linux, on a recent Debian based distribution do:
Brian Paul0da2a222011-04-07 13:56:45 -060046 </p>
47<pre>
José Fonseca9285f152009-08-10 12:35:16 +010048 aptitude install llvm-dev
Brian Paul0da2a222011-04-07 13:56:45 -060049</pre>
50 For a RPM-based distribution do:
51 </p>
52<pre>
53 yum install llvm-devel
54</pre>
José Fonseca19b31d02009-08-10 15:43:04 +010055
Brian Paul0da2a222011-04-07 13:56:45 -060056 <p>
José Fonseca65d0c842011-11-05 10:38:16 +000057 For Windows you will need to build LLVM from source with MSVC or MINGW
58 (either natively or through cross compilers) and CMake, and set the LLVM
59 environment variable to the directory you installed it to.
José Fonseca19b31d02009-08-10 15:43:04 +010060
José Fonseca65d0c842011-11-05 10:38:16 +000061 LLVM will be statically linked, so when building on MSVC it needs to be
62 built with a matching CRT as Mesa, and you'll need to pass
63 -DLLVM_USE_CRT_RELEASE=MTd for debug and checked builds,
64 -DLLVM_USE_CRT_RELEASE=MTd for profile and release builds.
José Fonsecaf379e7d2010-05-13 16:18:05 +010065
José Fonseca65d0c842011-11-05 10:38:16 +000066 You can build only the x86 target by passing -DLLVM_TARGETS_TO_BUILD=X86
67 to cmake.
Brian Paul0da2a222011-04-07 13:56:45 -060068 </p>
José Fonseca65d0c842011-11-05 10:38:16 +000069</li>
José Fonsecaf379e7d2010-05-13 16:18:05 +010070
José Fonseca65d0c842011-11-05 10:38:16 +000071<li>
72 <p>scons (optional)</p>
73</li>
74</ul>
75
José Fonseca9285f152009-08-10 12:35:16 +010076
77
Brian Paul0da2a222011-04-07 13:56:45 -060078
79<h1>Building</h1>
José Fonseca9285f152009-08-10 12:35:16 +010080
José Fonseca12576552010-01-10 18:37:07 +000081To build everything on Linux invoke scons as:
José Fonseca9285f152009-08-10 12:35:16 +010082
Brian Paul0da2a222011-04-07 13:56:45 -060083<pre>
José Fonseca601498a2010-11-01 13:30:22 +000084 scons build=debug libgl-xlib
Brian Paul0da2a222011-04-07 13:56:45 -060085</pre>
José Fonseca9285f152009-08-10 12:35:16 +010086
José Fonseca5811ed82009-08-22 22:26:55 +010087Alternatively, you can build it with GNU make, if you prefer, by invoking it as
88
Brian Paul0da2a222011-04-07 13:56:45 -060089<pre>
José Fonseca5811ed82009-08-22 22:26:55 +010090 make linux-llvm
Brian Paul0da2a222011-04-07 13:56:45 -060091</pre>
José Fonseca5811ed82009-08-22 22:26:55 +010092
José Fonseca1fc41002009-09-11 11:24:00 +010093but the rest of these instructions assume that scons is used.
José Fonseca5811ed82009-08-22 22:26:55 +010094
José Fonseca65d0c842011-11-05 10:38:16 +000095For Windows the procedure is similar except the target:
José Fonseca12576552010-01-10 18:37:07 +000096
Brian Paul0da2a222011-04-07 13:56:45 -060097<pre>
José Fonseca601498a2010-11-01 13:30:22 +000098 scons build=debug libgl-gdi
Brian Paul0da2a222011-04-07 13:56:45 -060099</pre>
José Fonseca9285f152009-08-10 12:35:16 +0100100
Brian Paul0da2a222011-04-07 13:56:45 -0600101
102<h1>Using</h1>
José Fonseca9285f152009-08-10 12:35:16 +0100103
José Fonseca601498a2010-11-01 13:30:22 +0000104On Linux, building will create a drop-in alternative for libGL.so into
José Fonseca9285f152009-08-10 12:35:16 +0100105
Brian Paul0da2a222011-04-07 13:56:45 -0600106<pre>
José Fonseca601498a2010-11-01 13:30:22 +0000107 build/foo/gallium/targets/libgl-xlib/libGL.so
Brian Paul0da2a222011-04-07 13:56:45 -0600108</pre>
109or
110<pre>
111 lib/gallium/libGL.so
112</pre>
José Fonseca9285f152009-08-10 12:35:16 +0100113
José Fonseca601498a2010-11-01 13:30:22 +0000114To use it set the LD_LIBRARY_PATH environment variable accordingly.
José Fonseca5811ed82009-08-22 22:26:55 +0100115
José Fonseca1fc41002009-09-11 11:24:00 +0100116For performance evaluation pass debug=no to scons, and use the corresponding
117lib directory without the "-debug" suffix.
118
José Fonseca12576552010-01-10 18:37:07 +0000119On Windows, building will create a drop-in alternative for opengl32.dll. To use
120it put it in the same directory as the application. It can also be used by
121replacing the native ICD driver, but it's quite an advanced usage, so if you
122need to ask, don't even try it.
123
José Fonseca9285f152009-08-10 12:35:16 +0100124
Brian Paul0da2a222011-04-07 13:56:45 -0600125<h1>Profiling</h1>
José Fonseca388c9412010-09-21 17:50:30 +0100126
127To profile llvmpipe you should pass the options
128
Brian Paul0da2a222011-04-07 13:56:45 -0600129<pre>
Andreas Boll703a6622012-06-12 09:05:15 +0200130 scons build=profile &lt;same-as-before&gt;
Brian Paul0da2a222011-04-07 13:56:45 -0600131</pre>
José Fonseca388c9412010-09-21 17:50:30 +0100132
133This will ensure that frame pointers are used both in C and JIT functions, and
134that no tail call optimizations are done by gcc.
135
José Fonseca388c9412010-09-21 17:50:30 +0100136To better profile JIT code you'll need to build LLVM with oprofile integration.
137
Brian Paul0da2a222011-04-07 13:56:45 -0600138<pre>
José Fonsecae6314db2011-03-13 19:24:26 +0000139 ./configure \
José Fonseca388c9412010-09-21 17:50:30 +0100140 --prefix=$install_dir \
141 --enable-optimized \
142 --disable-profiling \
143 --enable-targets=host-only \
144 --with-oprofile
145
146 make -C "$build_dir"
147 make -C "$build_dir" install
148
149 find "$install_dir/lib" -iname '*.a' -print0 | xargs -0 strip --strip-debug
Brian Paul0da2a222011-04-07 13:56:45 -0600150</pre>
José Fonseca388c9412010-09-21 17:50:30 +0100151
152The you should define
153
Brian Paul0da2a222011-04-07 13:56:45 -0600154<pre>
José Fonseca388c9412010-09-21 17:50:30 +0100155 export LLVM=/path/to/llvm-2.6-profile
Brian Paul0da2a222011-04-07 13:56:45 -0600156</pre>
José Fonseca388c9412010-09-21 17:50:30 +0100157
158and rebuild.
159
160
Brian Paul0da2a222011-04-07 13:56:45 -0600161<h1>Unit testing</h1>
José Fonseca9285f152009-08-10 12:35:16 +0100162
Brian Paul0da2a222011-04-07 13:56:45 -0600163<p>
José Fonseca9285f152009-08-10 12:35:16 +0100164Building will also create several unit tests in
165build/linux-???-debug/gallium/drivers/llvmpipe:
Brian Paul0da2a222011-04-07 13:56:45 -0600166</p>
José Fonseca9285f152009-08-10 12:35:16 +0100167
Brian Paul0da2a222011-04-07 13:56:45 -0600168</ul>
169<li> lp_test_blend: blending
170<li> lp_test_conv: SIMD vector conversion
171<li> lp_test_format: pixel unpacking/packing
172</ul>
José Fonseca9285f152009-08-10 12:35:16 +0100173
Brian Paul0da2a222011-04-07 13:56:45 -0600174<p>
José Fonseca1fc41002009-09-11 11:24:00 +0100175Some of this tests can output results and benchmarks to a tab-separated-file
José Fonseca89146cd2009-08-20 10:21:49 +0100176for posterior analysis, e.g.:
Brian Paul0da2a222011-04-07 13:56:45 -0600177</p>
178<pre>
José Fonseca5811ed82009-08-22 22:26:55 +0100179 build/linux-x86_64-debug/gallium/drivers/llvmpipe/lp_test_blend -o blend.tsv
Brian Paul0da2a222011-04-07 13:56:45 -0600180</pre>
José Fonseca9285f152009-08-10 12:35:16 +0100181
José Fonsecac5531f52009-08-21 10:57:48 +0100182
Brian Paul0da2a222011-04-07 13:56:45 -0600183<h1>Development Notes</h1>
José Fonsecac5531f52009-08-21 10:57:48 +0100184
Brian Paul0da2a222011-04-07 13:56:45 -0600185<ul>
186<li>
187 When looking to this code by the first time start in lp_state_fs.c, and
José Fonseca5811ed82009-08-22 22:26:55 +0100188 then skim through the lp_bld_* functions called in there, and the comments
189 at the top of the lp_bld_*.c functions.
Brian Paul0da2a222011-04-07 13:56:45 -0600190</li>
191<li>
192 The driver-independent parts of the LLVM / Gallium code are found in
Brian Pauld0b35352010-03-15 11:46:41 -0600193 src/gallium/auxiliary/gallivm/. The filenames and function prefixes
194 need to be renamed from "lp_bld_" to something else though.
Brian Paul0da2a222011-04-07 13:56:45 -0600195</li>
196<li>
197 We use LLVM-C bindings for now. They are not documented, but follow the C++
José Fonsecac5531f52009-08-21 10:57:48 +0100198 interfaces very closely, and appear to be complete enough for code
199 generation. See
200 http://npcontemplation.blogspot.com/2008/06/secret-of-llvm-c-bindings.html
José Fonseca601498a2010-11-01 13:30:22 +0000201 for a stand-alone example. See the llvm-c/Core.h file for reference.
Brian Paul0da2a222011-04-07 13:56:45 -0600202</li>
203</ul>
Andreas Bollecd5c7c2012-06-12 09:05:03 +0200204
205</body>
206</html>