Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5564 serge 1
2
3
4
  
5
  llvmpipe
6
  
7
8
9
 
10
11
  

The Mesa 3D Graphics Library

12
13
 
14
15
16
 
17

Introduction

18
 
19

20
The Gallium llvmpipe driver is a software rasterizer that uses LLVM to
21
do runtime code generation.
22
Shaders, point/line/triangle rasterization and vertex processing are
23
implemented with LLVM IR which is translated to x86 or x86-64 machine
24
code.
25
Also, the driver is multithreaded to take advantage of multiple CPU cores
26
(up to 8 at this time).
27
It's the fastest software rasterizer for Mesa.
28

29
 
30
 
31

Requirements

32
 
33
    34
  • 35
       

    An x86 or amd64 processor; 64-bit mode recommended.

    36
       

    37
       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
    39
       likely is that you run into underperforming, buggy, or incomplete code.
    40
       

    41
       

    42
       See /proc/cpuinfo to know what your CPU supports.
    43
       

    44
    45
  • 46
       

    LLVM: version 3.4 recommended; 3.3 or later required.

    47
       

    48
       For Linux, on a recent Debian based distribution do:
    49
       

    50
    51
         aptitude install llvm-dev
    52
    53
       

    54
       For a RPM-based distribution do:
    55
       

    56
    57
         yum install llvm-devel
    58
    59
     
    60
       

    61
       For Windows you will need to build LLVM from source with MSVC or MINGW
    62
       (either natively or through cross compilers) and CMake, and set the LLVM
    63
       environment variable to the directory you installed it to.
    64
     
    65
       LLVM will be statically linked, so when building on MSVC it needs to be
    66
       built with a matching CRT as Mesa, and you'll need to pass
    67
       -DLLVM_USE_CRT_xxx=yyy as described below.
    68
       

    69
     
    70
       
    71
         
    72
           
    LLVM build-type
    73
           
    Mesa build-type
    74
         
    75
         
    76
           
    debug,checked
    77
           
    release,profile
    78
         
    79
         
    80
           
    Debug
    81
           
    -DLLVM_USE_CRT_DEBUG=MTd
    82
           
    -DLLVM_USE_CRT_DEBUG=MT
    83
         
    84
         
    85
           
    Release
    86
           
    -DLLVM_USE_CRT_RELEASE=MTd
    87
           
    -DLLVM_USE_CRT_RELEASE=MT
    88
         
    89
       
    90
     
    91
       

    92
       You can build only the x86 target by passing -DLLVM_TARGETS_TO_BUILD=X86
    93
       to cmake.
    94
       

    95
    96
     
    97
  • 98
       

    scons (optional)

    99
    100
    101
     
    102
     
    103

    Building

    104
     
    105
    To build everything on Linux invoke scons as:
    106
     
    107
    108
      scons build=debug libgl-xlib
    109
    110
     
    111
    Alternatively, you can build it with GNU make, if you prefer, by invoking it as
    112
     
    113
    114
      make linux-llvm
    115
    116
     
    117
    but the rest of these instructions assume that scons is used.
    118
     
    119
    For Windows the procedure is similar except the target:
    120
     
    121
    122
      scons platform=windows build=debug libgl-gdi
    123
    124
     
    125
     
    126

    Using

    127
     
    128

    Linux

    129
     
    130

    On Linux, building will create a drop-in alternative for libGL.so into

    131
     
    132
    133
      build/foo/gallium/targets/libgl-xlib/libGL.so
    134
    135
    or
    136
    137
      lib/gallium/libGL.so
    138
    139
     
    140

    To use it set the LD_LIBRARY_PATH environment variable accordingly.

    141
     
    142

    For performance evaluation pass build=release to scons, and use the corresponding

    143
    lib directory without the "-debug" suffix.

    144
     
    145
     
    146

    Windows

    147
     
    148

    149
    On Windows, building will create
    150
    build/windows-x86-debug/gallium/targets/libgl-gdi/opengl32.dll
    151
    which is a drop-in alternative for system's opengl32.dll.  To use
    152
    it put it in the same directory as your application.  It can also be used by
    153
    replacing the native ICD driver, but it's quite an advanced usage, so if you
    154
    need to ask, don't even try it.
    155

    156
     
    157

    158
    There is however an easy way to replace the OpenGL software renderer that comes
    159
    with Microsoft Windows 7 (or later) with llvmpipe (that is, on systems without
    160
    any OpenGL drivers):
    161

    162
     
    163
      164
        
    • copy build/windows-x86-debug/gallium/targets/libgl-gdi/opengl32.dll to C:\Windows\SysWOW64\mesadrv.dll

    • 165
        
    • load this registry settings:

    • 166
        
      REGEDIT4
      167
       
      168
      ; http://technet.microsoft.com/en-us/library/cc749368.aspx
      169
      ; http://www.msfn.org/board/topic/143241-portable-windows-7-build-from-winpe-30/page-5#entry942596
      170
      [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\OpenGLDrivers\MSOGL]
      171
      "DLL"="mesadrv.dll"
      172
      "DriverVersion"=dword:00000001
      173
      "Flags"=dword:00000001
      174
      "Version"=dword:00000002
      175
      176
        
      177
        
    • Ditto for 64 bits drivers if you need them.
    • 178
      179
       
      180
       
      181

      Profiling

      182
       
      183

      184
      To profile llvmpipe you should build as
      185

      186
      187
        scons build=profile <same-as-before>
      188
      189
       
      190

      191
      This will ensure that frame pointers are used both in C and JIT functions, and
      192
      that no tail call optimizations are done by gcc.
      193

      194
       
      195

      Linux perf integration

      196
       
      197

      198
      On Linux, it is possible to have symbol resolution of JIT code with Linux perf:
      199

      200
       
      201
      202
      	perf record -g /my/application
      203
      	perf report
      204
      205
       
      206

      207
      When run inside Linux perf, llvmpipe will create a /tmp/perf-XXXXX.map file with
      208
      symbol address table.  It also dumps assembly code to /tmp/perf-XXXXX.map.asm,
      209
      which can be used by the bin/perf-annotate-jit script to produce disassembly of
      210
      the generated code annotated with the samples.
      211

      212
       
      213

      You can obtain a call graph via

      214
      Gprof2Dot.

      215
       
      216
       
      217

      Unit testing

      218
       
      219

      220
      Building will also create several unit tests in
      221
      build/linux-???-debug/gallium/drivers/llvmpipe:
      222

      223
       
      224
        225
      • lp_test_blend: blending
      • 226
      • lp_test_conv: SIMD vector conversion
      • 227
      • lp_test_format: pixel unpacking/packing
      • 228
        229
         
        230

        231
        Some of this tests can output results and benchmarks to a tab-separated-file
        232
        for posterior analysis, e.g.:
        233

        234
        235
          build/linux-x86_64-debug/gallium/drivers/llvmpipe/lp_test_blend -o blend.tsv
        236
        237
         
        238
         
        239

        Development Notes

        240
         
        241
          242
        • 243
            When looking to this code by the first time start in lp_state_fs.c, and
          244
            then skim through the lp_bld_* functions called in there, and the comments
          245
            at the top of the lp_bld_*.c functions.
          246
          247
        • 248
            The driver-independent parts of the LLVM / Gallium code are found in
          249
            src/gallium/auxiliary/gallivm/.  The filenames and function prefixes
          250
            need to be renamed from "lp_bld_" to something else though.
          251
          252
        • 253
            We use LLVM-C bindings for now. They are not documented, but follow the C++
          254
            interfaces very closely, and appear to be complete enough for code
          255
            generation. See
          256
            
          257
            this stand-alone example.  See the llvm-c/Core.h file for reference.
          258
          259
          260
           
          261

          Recommended Reading

          262
           
          263
            264
              
          • 265
                

            Rasterization

            266
                
              267
                    
            • Triangle Scan Conversion using 2D Homogeneous Coordinates
            • 268
                    
            • Rasterization on Larrabee (DevMaster copy)
            • 269
                    
            • Rasterization using half-space functions
            • 270
                    
            • Advanced Rasterization
            • 271
                    
            • Optimizing Software Occlusion Culling
            • 272
                  
              273
                
              274
                
            • 275
                  

              Texture sampling

              276
                  
                277
                      
              • Perspective Texture Mapping
              • 278
                      
              • Texturing As In Unreal
              • 279
                      
              • Run-Time MIP-Map Filtering
              • 280
                      
              • Will "brilinear" filtering persist?
              • 281
                      
              • Trilinear filtering
              • 282
                      
              • Texture Swizzling
              • 283
                    
                284
                  
                285
                  
              • 286
                    

                SIMD

                287
                    
                  288
                        
                • Whole-Function Vectorization
                • 289
                      
                  290
                    
                  291
                    
                • 292
                      

                  Optimization

                  293
                      
                    294
                          
                  • Optimizing Pixomatic For Modern x86 Processors
                  • 295
                          
                  • Intel 64 and IA-32 Architectures Optimization Reference Manual
                  • 296
                          
                  • Software optimization resources
                  • 297
                          
                  • Intel Intrinsics Guide
                  • 298
                        
                    299
                      
                    300
                      
                  • 301
                        

                    LLVM

                    302
                        
                      303
                            
                    • LLVM Language Reference Manual
                    • 304
                            
                    • The secret of LLVM C bindings
                    • 305
                          
                      306
                        
                      307
                        
                    • 308
                          

                      General

                      309
                          
                        310
                              
                      • A trip through the Graphics Pipeline
                      • 311
                              
                      • WARP Architecture and Performance
                      • 312
                            
                        313
                          
                        314
                        315
                         
                        316
                        317
                        318