1*61046927SAndroid Build Coastguard WorkerLLVMpipe 2*61046927SAndroid Build Coastguard Worker======== 3*61046927SAndroid Build Coastguard Worker 4*61046927SAndroid Build Coastguard WorkerIntroduction 5*61046927SAndroid Build Coastguard Worker------------ 6*61046927SAndroid Build Coastguard Worker 7*61046927SAndroid Build Coastguard WorkerThe Gallium LLVMpipe driver is a software rasterizer that uses LLVM to 8*61046927SAndroid Build Coastguard Workerdo runtime code generation. Shaders, point/line/triangle rasterization 9*61046927SAndroid Build Coastguard Workerand vertex processing are implemented with LLVM IR which is translated 10*61046927SAndroid Build Coastguard Workerto x86, x86-64, or ppc64le machine code. Also, the driver is 11*61046927SAndroid Build Coastguard Workermultithreaded to take advantage of multiple CPU cores (up to 32 at this 12*61046927SAndroid Build Coastguard Workertime). It's the fastest software rasterizer for Mesa. 13*61046927SAndroid Build Coastguard Worker 14*61046927SAndroid Build Coastguard WorkerRequirements 15*61046927SAndroid Build Coastguard Worker------------ 16*61046927SAndroid Build Coastguard Worker 17*61046927SAndroid Build Coastguard Worker- For x86 or amd64 processors, 64-bit mode is recommended. Support for 18*61046927SAndroid Build Coastguard Worker SSE2 is strongly encouraged. Support for SSE3 and SSE4.1 will yield 19*61046927SAndroid Build Coastguard Worker the most efficient code. The fewer features the CPU has the more 20*61046927SAndroid Build Coastguard Worker likely it is that you will run into underperforming, buggy, or 21*61046927SAndroid Build Coastguard Worker incomplete code. 22*61046927SAndroid Build Coastguard Worker 23*61046927SAndroid Build Coastguard Worker For ppc64le processors, use of the Altivec feature (the Vector 24*61046927SAndroid Build Coastguard Worker Facility) is recommended if supported; use of the VSX feature (the 25*61046927SAndroid Build Coastguard Worker Vector-Scalar Facility) is recommended if supported AND Mesa is built 26*61046927SAndroid Build Coastguard Worker with LLVM version 4.0 or later. 27*61046927SAndroid Build Coastguard Worker 28*61046927SAndroid Build Coastguard Worker See ``/proc/cpuinfo`` to know what your CPU supports. 29*61046927SAndroid Build Coastguard Worker 30*61046927SAndroid Build Coastguard Worker- Unless otherwise stated, LLVM version 3.9 or later is required. 31*61046927SAndroid Build Coastguard Worker 32*61046927SAndroid Build Coastguard Worker For Linux, on a recent Debian based distribution do: 33*61046927SAndroid Build Coastguard Worker 34*61046927SAndroid Build Coastguard Worker .. code-block:: sh 35*61046927SAndroid Build Coastguard Worker 36*61046927SAndroid Build Coastguard Worker aptitude install llvm-dev 37*61046927SAndroid Build Coastguard Worker 38*61046927SAndroid Build Coastguard Worker If you want development snapshot builds of LLVM for Debian and 39*61046927SAndroid Build Coastguard Worker derived distributions like Ubuntu, you can use the APT repository at 40*61046927SAndroid Build Coastguard Worker `apt.llvm.org <https://apt.llvm.org/>`__, which are maintained by 41*61046927SAndroid Build Coastguard Worker Debian's LLVM maintainer. 42*61046927SAndroid Build Coastguard Worker 43*61046927SAndroid Build Coastguard Worker For a RPM-based distribution do: 44*61046927SAndroid Build Coastguard Worker 45*61046927SAndroid Build Coastguard Worker .. code-block:: sh 46*61046927SAndroid Build Coastguard Worker 47*61046927SAndroid Build Coastguard Worker yum install llvm-devel 48*61046927SAndroid Build Coastguard Worker 49*61046927SAndroid Build Coastguard Worker If you want development snapshot builds of LLVM for Fedora, you can 50*61046927SAndroid Build Coastguard Worker use the Copr repository at `fedora-llvm-team/llvm-snapshots <https://copr.fedorainfracloud.org/coprs/g/fedora-llvm-team/llvm-snapshots/>`__, 51*61046927SAndroid Build Coastguard Worker which is maintained by Red Hat's LLVM team. 52*61046927SAndroid Build Coastguard Worker 53*61046927SAndroid Build Coastguard Worker For Windows you will need to build LLVM from source with MSVC or 54*61046927SAndroid Build Coastguard Worker MINGW (either natively or through cross compilers) and CMake, and set 55*61046927SAndroid Build Coastguard Worker the ``LLVM`` environment variable to the directory you installed it 56*61046927SAndroid Build Coastguard Worker to. LLVM will be statically linked, so when building on MSVC it needs 57*61046927SAndroid Build Coastguard Worker to be built with a matching CRT as Mesa, and you'll need to pass 58*61046927SAndroid Build Coastguard Worker ``-DLLVM_USE_CRT_xxx=yyy`` as described below. 59*61046927SAndroid Build Coastguard Worker 60*61046927SAndroid Build Coastguard Worker 61*61046927SAndroid Build Coastguard Worker +-----------------+----------------------------------------------------------------+ 62*61046927SAndroid Build Coastguard Worker | LLVM build-type | Mesa build-type | 63*61046927SAndroid Build Coastguard Worker | +--------------------------------+-------------------------------+ 64*61046927SAndroid Build Coastguard Worker | | debug,checked | release,profile | 65*61046927SAndroid Build Coastguard Worker +=================+================================+===============================+ 66*61046927SAndroid Build Coastguard Worker | Debug | ``-DLLVM_USE_CRT_DEBUG=MTd`` | ``-DLLVM_USE_CRT_DEBUG=MT`` | 67*61046927SAndroid Build Coastguard Worker +-----------------+--------------------------------+-------------------------------+ 68*61046927SAndroid Build Coastguard Worker | Release | ``-DLLVM_USE_CRT_RELEASE=MTd`` | ``-DLLVM_USE_CRT_RELEASE=MT`` | 69*61046927SAndroid Build Coastguard Worker +-----------------+--------------------------------+-------------------------------+ 70*61046927SAndroid Build Coastguard Worker 71*61046927SAndroid Build Coastguard Worker You can build only the x86 target by passing 72*61046927SAndroid Build Coastguard Worker ``-DLLVM_TARGETS_TO_BUILD=X86`` to CMake. 73*61046927SAndroid Build Coastguard Worker 74*61046927SAndroid Build Coastguard WorkerBuilding 75*61046927SAndroid Build Coastguard Worker-------- 76*61046927SAndroid Build Coastguard Worker 77*61046927SAndroid Build Coastguard WorkerTo build everything on Linux invoke meson as: 78*61046927SAndroid Build Coastguard Worker 79*61046927SAndroid Build Coastguard Worker.. code-block:: sh 80*61046927SAndroid Build Coastguard Worker 81*61046927SAndroid Build Coastguard Worker mkdir build 82*61046927SAndroid Build Coastguard Worker cd build 83*61046927SAndroid Build Coastguard Worker meson -D glx=xlib -D gallium-drivers=swrast 84*61046927SAndroid Build Coastguard Worker ninja 85*61046927SAndroid Build Coastguard Worker 86*61046927SAndroid Build Coastguard WorkerTo build on Android requires the additional step of building LLVM 87*61046927SAndroid Build Coastguard Workerfor Android using the NDK. Before following the steps in 88*61046927SAndroid Build Coastguard Worker:doc:`Android's documentation <../android>` you must build a version 89*61046927SAndroid Build Coastguard Workerof LLVM that targets the NDK with all the required libraries for 90*61046927SAndroid Build Coastguard Workerllvmpipe, and then create a wrap file so the meson knows where to 91*61046927SAndroid Build Coastguard Workerfind the LLVM libraries. It can be a bit tricky to get LLVM to build 92*61046927SAndroid Build Coastguard Workerproperly using the Android NDK, so the below cmake command can be 93*61046927SAndroid Build Coastguard Workerused as a reference to configure LLVM to build with the NDK for x86. 94*61046927SAndroid Build Coastguard WorkerYou need to set the ``ANDROID_NDK_ROOT`` and ``INSTALL_PREFIX`` 95*61046927SAndroid Build Coastguard Workerenvironment variable appropriately. 96*61046927SAndroid Build Coastguard Worker 97*61046927SAndroid Build Coastguard Worker.. code-block:: sh 98*61046927SAndroid Build Coastguard Worker 99*61046927SAndroid Build Coastguard Worker cmake ../llvm-project-18.1.1.src/llvm \ 100*61046927SAndroid Build Coastguard Worker -DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_ROOT}/build/cmake/android.toolchain.cmake \ 101*61046927SAndroid Build Coastguard Worker -DANDROID_ABI=x86_64 \ 102*61046927SAndroid Build Coastguard Worker -DANDROID_PLATFORM=android-23 \ 103*61046927SAndroid Build Coastguard Worker -DANDROID_NDK=${ANDROID_NDK_ROOT} \ 104*61046927SAndroid Build Coastguard Worker -DCMAKE_ANDROID_ARCH_ABI=x86_64 \ 105*61046927SAndroid Build Coastguard Worker -DCMAKE_ANDROID_NDK=${ANDROID_NDK_ROOT} \ 106*61046927SAndroid Build Coastguard Worker -DCMAKE_BUILD_TYPE=MinSizeRel \ 107*61046927SAndroid Build Coastguard Worker -DCMAKE_SYSTEM_NAME=Android \ 108*61046927SAndroid Build Coastguard Worker -DCMAKE_SYSTEM_VERSION=23 \ 109*61046927SAndroid Build Coastguard Worker -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} \ 110*61046927SAndroid Build Coastguard Worker -DCMAKE_CXX_FLAGS='-march=x86-64 --target=x86_64-linux-android23 -fno-rtti' \ 111*61046927SAndroid Build Coastguard Worker -DLLVM_HOST_TRIPLE=x86_64-linux-android23 \ 112*61046927SAndroid Build Coastguard Worker -DLLVM_TARGETS_TO_BUILD=X86 \ 113*61046927SAndroid Build Coastguard Worker -DLLVM_BUILD_LLVM_DYLIB=OFF \ 114*61046927SAndroid Build Coastguard Worker -DLLVM_BUILD_TESTS=OFF \ 115*61046927SAndroid Build Coastguard Worker -DLLVM_BUILD_EXAMPLES=OFF \ 116*61046927SAndroid Build Coastguard Worker -DLLVM_BUILD_DOCS=OFF \ 117*61046927SAndroid Build Coastguard Worker -DLLVM_BUILD_TOOLS=OFF \ 118*61046927SAndroid Build Coastguard Worker -DLLVM_ENABLE_RTTI=OFF \ 119*61046927SAndroid Build Coastguard Worker -DLLVM_BUILD_INSTRUMENTED_COVERAGE=OFF \ 120*61046927SAndroid Build Coastguard Worker -DLLVM_NATIVE_TOOL_DIR=${ANDROID_NDK_ROOT}toolchains/llvm/prebuilt/linux-x86_64/bin \ 121*61046927SAndroid Build Coastguard Worker -DLLVM_ENABLE_PIC=False 122*61046927SAndroid Build Coastguard Worker 123*61046927SAndroid Build Coastguard Worker make -j$(nproc) install 124*61046927SAndroid Build Coastguard Worker 125*61046927SAndroid Build Coastguard Worker 126*61046927SAndroid Build Coastguard WorkerYou will also need to create a wrap file, so that meson is able 127*61046927SAndroid Build Coastguard Workerto find the LLVM libraries built with the NDK. The process for this 128*61046927SAndroid Build Coastguard Workeris described in :doc:`meson documentation <../meson>`. For example a 129*61046927SAndroid Build Coastguard Workerfile like this would work ``subprojects/llvm/meson.build`` where 130*61046927SAndroid Build Coastguard Worker``INSTALL_PREFIX`` is replaced with the path LLVM was installed to. 131*61046927SAndroid Build Coastguard Worker 132*61046927SAndroid Build Coastguard Worker.. code-block:: 133*61046927SAndroid Build Coastguard Worker 134*61046927SAndroid Build Coastguard Worker project('llvm', ['cpp']) 135*61046927SAndroid Build Coastguard Worker 136*61046927SAndroid Build Coastguard Worker cpp = meson.get_compiler('cpp') 137*61046927SAndroid Build Coastguard Worker 138*61046927SAndroid Build Coastguard Worker _deps = [] 139*61046927SAndroid Build Coastguard Worker _search = join_paths('$INSTALL_PREFIX', 'lib') 140*61046927SAndroid Build Coastguard Worker 141*61046927SAndroid Build Coastguard Worker foreach d: ['libLLVMAggressiveInstCombine', 'libLLVMAnalysis', 'libLLVMAsmParser', 'libLLVMAsmPrinter', 'libLLVMBinaryFormat', 'libLLVMBitReader', 'libLLVMBitstreamReader', 'libLLVMBitWriter', 'libLLVMCFGuard', 'libLLVMCFIVerify', 'libLLVMCodeGen', 'libLLVMCodeGenTypes', 'libLLVMCore', 'libLLVMCoroutines', 'libLLVMCoverage', 'libLLVMDebugInfoBTF', 'libLLVMDebugInfoCodeView', 'libLLVMDebuginfod', 'libLLVMDebugInfoDWARF', 'libLLVMDebugInfoGSYM', 'libLLVMDebugInfoLogicalView', 'libLLVMDebugInfoMSF', 'libLLVMDebugInfoPDB', 'libLLVMDemangle', 'libLLVMDiff', 'libLLVMDlltoolDriver', 'libLLVMDWARFLinker', 'libLLVMDWARFLinkerClassic', 'libLLVMDWARFLinkerParallel', 'libLLVMDWP', 'libLLVMExecutionEngine', 'libLLVMExegesis', 'libLLVMExegesisX86', 'libLLVMExtensions', 'libLLVMFileCheck', 'libLLVMFrontendDriver', 'libLLVMFrontendHLSL', 'libLLVMFrontendOffloading', 'libLLVMFrontendOpenACC', 'libLLVMFrontendOpenMP', 'libLLVMFuzzerCLI', 'libLLVMFuzzMutate', 'libLLVMGlobalISel', 'libLLVMHipStdPar', 'libLLVMInstCombine', 'libLLVMInstrumentation', 'libLLVMInterfaceStub', 'libLLVMInterpreter', 'libLLVMipo', 'libLLVMIRPrinter', 'libLLVMIRReader', 'libLLVMJITLink', 'libLLVMLibDriver', 'libLLVMLineEditor', 'libLLVMLinker', 'libLLVMLTO', 'libLLVMMC', 'libLLVMMCA', 'libLLVMMCDisassembler', 'libLLVMMCJIT', 'libLLVMMCParser', 'libLLVMMIRParser', 'libLLVMObjCARCOpts', 'libLLVMObjCopy', 'libLLVMObject', 'libLLVMObjectYAML', 'libLLVMOption', 'libLLVMOrcDebugging', 'libLLVMOrcJIT', 'libLLVMOrcShared', 'libLLVMOrcTargetProcess', 'libLLVMPasses', 'libLLVMProfileData', 'libLLVMRemarks', 'libLLVMRuntimeDyld', 'libLLVMScalarOpts', 'libLLVMSelectionDAG', 'libLLVMSupport', 'libLLVMSymbolize', 'libLLVMTableGen', 'libLLVMTableGenCommon', 'libLLVMTableGenGlobalISel', 'libLLVMTarget', 'libLLVMTargetParser', 'libLLVMTextAPI', 'libLLVMTextAPIBinaryReader', 'libLLVMTransformUtils', 'libLLVMVectorize', 'libLLVMWindowsDriver', 'libLLVMWindowsManifest', 'libLLVMX86AsmParser', 'libLLVMX86CodeGen', 'libLLVMX86Desc', 'libLLVMX86Disassembler', 'libLLVMX86Info', 'libLLVMX86TargetMCA', 'libLLVMXRay'] 142*61046927SAndroid Build Coastguard Worker _deps += cpp.find_library(d, dirs : _search) 143*61046927SAndroid Build Coastguard Worker endforeach 144*61046927SAndroid Build Coastguard Worker 145*61046927SAndroid Build Coastguard Worker dep_llvm = declare_dependency( 146*61046927SAndroid Build Coastguard Worker include_directories : include_directories('$INSTALL_PREFIX/include'), 147*61046927SAndroid Build Coastguard Worker dependencies : _deps, 148*61046927SAndroid Build Coastguard Worker version : '6.0.0', 149*61046927SAndroid Build Coastguard Worker ) 150*61046927SAndroid Build Coastguard Worker 151*61046927SAndroid Build Coastguard Worker has_rtti = false 152*61046927SAndroid Build Coastguard Worker irbuilder_h = files('$INSTALL_PREFIX/include/llvm/IR/IRBuilder.h') 153*61046927SAndroid Build Coastguard Worker 154*61046927SAndroid Build Coastguard WorkerAfterwards you can continue following the instructors to build mesa 155*61046927SAndroid Build Coastguard Workeron :doc:`Android <../android>` and follow the steps to add the driver 156*61046927SAndroid Build Coastguard Workerdirectly to an Android OS image. Please note that you'll need to set 157*61046927SAndroid Build Coastguard Worker``-Ddri-search-path`` when building the driver, so that the loader 158*61046927SAndroid Build Coastguard Workerwill be able to find the driver libraries in the vendor partition 159*61046927SAndroid Build Coastguard Worker``/vendor/lib(64)/egl``. 160*61046927SAndroid Build Coastguard Worker 161*61046927SAndroid Build Coastguard WorkerUsing 162*61046927SAndroid Build Coastguard Worker----- 163*61046927SAndroid Build Coastguard Worker 164*61046927SAndroid Build Coastguard WorkerEnvironment variables 165*61046927SAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~~ 166*61046927SAndroid Build Coastguard Worker 167*61046927SAndroid Build Coastguard Worker.. envvar:: LP_NATIVE_VECTOR_WIDTH 168*61046927SAndroid Build Coastguard Worker 169*61046927SAndroid Build Coastguard Worker We can use it to override vector bits. Because sometimes it turns 170*61046927SAndroid Build Coastguard Worker out LLVMpipe can be fastest by using 128 bit vectors, 171*61046927SAndroid Build Coastguard Worker yet use AVX instructions. 172*61046927SAndroid Build Coastguard Worker 173*61046927SAndroid Build Coastguard Worker.. envvar:: GALLIUM_NOSSE 174*61046927SAndroid Build Coastguard Worker 175*61046927SAndroid Build Coastguard Worker Deprecated in favor of ``GALLIUM_OVERRIDE_CPU_CAPS``, 176*61046927SAndroid Build Coastguard Worker use ``GALLIUM_OVERRIDE_CPU_CAPS=nosse`` instead. 177*61046927SAndroid Build Coastguard Worker 178*61046927SAndroid Build Coastguard Worker.. envvar:: LP_FORCE_SSE2 179*61046927SAndroid Build Coastguard Worker 180*61046927SAndroid Build Coastguard Worker Deprecated in favor of ``GALLIUM_OVERRIDE_CPU_CAPS`` 181*61046927SAndroid Build Coastguard Worker use ``GALLIUM_OVERRIDE_CPU_CAPS=sse2`` instead. 182*61046927SAndroid Build Coastguard Worker 183*61046927SAndroid Build Coastguard WorkerLinux 184*61046927SAndroid Build Coastguard Worker~~~~~ 185*61046927SAndroid Build Coastguard Worker 186*61046927SAndroid Build Coastguard WorkerOn Linux, building will create a drop-in alternative for ``libGL.so`` 187*61046927SAndroid Build Coastguard Workerinto 188*61046927SAndroid Build Coastguard Worker 189*61046927SAndroid Build Coastguard Worker:: 190*61046927SAndroid Build Coastguard Worker 191*61046927SAndroid Build Coastguard Worker build/foo/gallium/targets/libgl-xlib/libGL.so 192*61046927SAndroid Build Coastguard Worker 193*61046927SAndroid Build Coastguard Workeror 194*61046927SAndroid Build Coastguard Worker 195*61046927SAndroid Build Coastguard Worker:: 196*61046927SAndroid Build Coastguard Worker 197*61046927SAndroid Build Coastguard Worker lib/gallium/libGL.so 198*61046927SAndroid Build Coastguard Worker 199*61046927SAndroid Build Coastguard WorkerTo use it set the ``LD_LIBRARY_PATH`` environment variable accordingly. 200*61046927SAndroid Build Coastguard Worker 201*61046927SAndroid Build Coastguard WorkerWindows 202*61046927SAndroid Build Coastguard Worker~~~~~~~ 203*61046927SAndroid Build Coastguard Worker 204*61046927SAndroid Build Coastguard WorkerOn Windows, building will create 205*61046927SAndroid Build Coastguard Worker``build/windows-x86-debug/gallium/targets/libgl-gdi/opengl32.dll`` which 206*61046927SAndroid Build Coastguard Workeris a drop-in alternative for system's ``opengl32.dll``, which will use 207*61046927SAndroid Build Coastguard Workerthe Mesa ICD, ``build/windows-x86-debug/gallium/targets/wgl/libgallium_wgl.dll``. 208*61046927SAndroid Build Coastguard WorkerTo use it put both DLLs in the same directory as your application. It can also 209*61046927SAndroid Build Coastguard Workerbe used by replacing the native ICD driver, but it's quite an advanced usage, so if 210*61046927SAndroid Build Coastguard Workeryou need to ask, don't even try it. 211*61046927SAndroid Build Coastguard Worker 212*61046927SAndroid Build Coastguard WorkerThere is however an easy way to replace the OpenGL software renderer 213*61046927SAndroid Build Coastguard Workerthat comes with Microsoft Windows 7 (or later) with LLVMpipe (that is, 214*61046927SAndroid Build Coastguard Workeron systems without any OpenGL drivers): 215*61046927SAndroid Build Coastguard Worker 216*61046927SAndroid Build Coastguard Worker- copy 217*61046927SAndroid Build Coastguard Worker ``build/windows-x86-debug/gallium/targets/wgl/libgallium_wgl.dll`` to 218*61046927SAndroid Build Coastguard Worker ``C:\Windows\SysWOW64\mesadrv.dll`` 219*61046927SAndroid Build Coastguard Worker 220*61046927SAndroid Build Coastguard Worker- load this registry settings: 221*61046927SAndroid Build Coastguard Worker 222*61046927SAndroid Build Coastguard Worker :: 223*61046927SAndroid Build Coastguard Worker 224*61046927SAndroid Build Coastguard Worker REGEDIT4 225*61046927SAndroid Build Coastguard Worker 226*61046927SAndroid Build Coastguard Worker ; https://technet.microsoft.com/en-us/library/cc749368.aspx 227*61046927SAndroid Build Coastguard Worker ; https://www.msfn.org/board/topic/143241-portable-windows-7-build-from-winpe-30/page-5#entry942596 228*61046927SAndroid Build Coastguard Worker [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\OpenGLDrivers\MSOGL] 229*61046927SAndroid Build Coastguard Worker "DLL"="mesadrv.dll" 230*61046927SAndroid Build Coastguard Worker "DriverVersion"=dword:00000001 231*61046927SAndroid Build Coastguard Worker "Flags"=dword:00000001 232*61046927SAndroid Build Coastguard Worker "Version"=dword:00000002 233*61046927SAndroid Build Coastguard Worker 234*61046927SAndroid Build Coastguard Worker- Ditto for 64 bits drivers if you need them. 235*61046927SAndroid Build Coastguard Worker 236*61046927SAndroid Build Coastguard WorkerProfiling 237*61046927SAndroid Build Coastguard Worker--------- 238*61046927SAndroid Build Coastguard Worker 239*61046927SAndroid Build Coastguard WorkerLinux perf integration 240*61046927SAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~~~ 241*61046927SAndroid Build Coastguard Worker 242*61046927SAndroid Build Coastguard WorkerOn Linux, it is possible to have symbol resolution of JIT code with 243*61046927SAndroid Build Coastguard Worker`Linux perf <https://perf.wiki.kernel.org/>`__: 244*61046927SAndroid Build Coastguard Worker 245*61046927SAndroid Build Coastguard Worker:: 246*61046927SAndroid Build Coastguard Worker 247*61046927SAndroid Build Coastguard Worker perf record -g /my/application 248*61046927SAndroid Build Coastguard Worker perf report 249*61046927SAndroid Build Coastguard Worker 250*61046927SAndroid Build Coastguard WorkerWhen run inside Linux perf, LLVMpipe will create a 251*61046927SAndroid Build Coastguard Worker``/tmp/perf-XXXXX.map`` file with symbol address table. It also dumps 252*61046927SAndroid Build Coastguard Workerassembly code to ``/tmp/perf-XXXXX.map.asm``, which can be used by the 253*61046927SAndroid Build Coastguard Worker``bin/perf-annotate-jit.py`` script to produce disassembly of the 254*61046927SAndroid Build Coastguard Workergenerated code annotated with the samples. 255*61046927SAndroid Build Coastguard Worker 256*61046927SAndroid Build Coastguard WorkerYou can obtain a call graph via 257*61046927SAndroid Build Coastguard Worker`Gprof2Dot <https://github.com/jrfonseca/gprof2dot#linux-perf>`__. 258*61046927SAndroid Build Coastguard Worker 259*61046927SAndroid Build Coastguard WorkerFlameGraph support 260*61046927SAndroid Build Coastguard Worker~~~~~~~~~~~~~~~~~~~~~~ 261*61046927SAndroid Build Coastguard Worker 262*61046927SAndroid Build Coastguard WorkerOutside Linux, it is possible to generate a 263*61046927SAndroid Build Coastguard Worker`FlameGraph <https://github.com/brendangregg/FlameGraph>`__ 264*61046927SAndroid Build Coastguard Workerwith resolved JIT symbols. 265*61046927SAndroid Build Coastguard Worker 266*61046927SAndroid Build Coastguard WorkerSet the environment variable ``JIT_SYMBOL_MAP_DIR`` to a directory path, 267*61046927SAndroid Build Coastguard Workerand run your LLVMpipe program. Follow the FlameGraph instructions: 268*61046927SAndroid Build Coastguard Workercapture traces using a supported tool (for example DTrace), 269*61046927SAndroid Build Coastguard Workerand fold the stacks using the associated script 270*61046927SAndroid Build Coastguard Worker(``stackcollapse.pl`` for DTrace stacks). 271*61046927SAndroid Build Coastguard Worker 272*61046927SAndroid Build Coastguard WorkerLLVMpipe will create a ``jit-symbols-XXXXX.map`` file containing the symbol 273*61046927SAndroid Build Coastguard Workeraddress table inside the chosen directory. It will also dump the JIT 274*61046927SAndroid Build Coastguard Workerdisassemblies to ``jit-symbols-XXXXX.map.asm``. Run your folded traces and 275*61046927SAndroid Build Coastguard Workerboth output files through the ``bin/flamegraph_map_lp_jit.py`` script to map 276*61046927SAndroid Build Coastguard Workeraddresses to JIT symbols, and annotate the disassembly with the sample counts. 277*61046927SAndroid Build Coastguard Worker 278*61046927SAndroid Build Coastguard WorkerUnit testing 279*61046927SAndroid Build Coastguard Worker------------ 280*61046927SAndroid Build Coastguard Worker 281*61046927SAndroid Build Coastguard WorkerBuilding will also create several unit tests in 282*61046927SAndroid Build Coastguard Worker``build/linux-???-debug/gallium/drivers/llvmpipe``: 283*61046927SAndroid Build Coastguard Worker 284*61046927SAndroid Build Coastguard Worker- ``lp_test_blend``: blending 285*61046927SAndroid Build Coastguard Worker- ``lp_test_conv``: SIMD vector conversion 286*61046927SAndroid Build Coastguard Worker- ``lp_test_format``: pixel unpacking/packing 287*61046927SAndroid Build Coastguard Worker 288*61046927SAndroid Build Coastguard WorkerSome of these tests can output results and benchmarks to a tab-separated 289*61046927SAndroid Build Coastguard Workerfile for later analysis, e.g.: 290*61046927SAndroid Build Coastguard Worker 291*61046927SAndroid Build Coastguard Worker:: 292*61046927SAndroid Build Coastguard Worker 293*61046927SAndroid Build Coastguard Worker build/linux-x86_64-debug/gallium/drivers/llvmpipe/lp_test_blend -o blend.tsv 294*61046927SAndroid Build Coastguard Worker 295*61046927SAndroid Build Coastguard WorkerDevelopment Notes 296*61046927SAndroid Build Coastguard Worker----------------- 297*61046927SAndroid Build Coastguard Worker 298*61046927SAndroid Build Coastguard Worker- When looking at this code for the first time, start in lp_state_fs.c, 299*61046927SAndroid Build Coastguard Worker and then skim through the ``lp_bld_*`` functions called there, and 300*61046927SAndroid Build Coastguard Worker the comments at the top of the ``lp_bld_*.c`` functions. 301*61046927SAndroid Build Coastguard Worker- The driver-independent parts of the LLVM / Gallium code are found in 302*61046927SAndroid Build Coastguard Worker ``src/gallium/auxiliary/gallivm/``. The filenames and function 303*61046927SAndroid Build Coastguard Worker prefixes need to be renamed from ``lp_bld_`` to something else 304*61046927SAndroid Build Coastguard Worker though. 305*61046927SAndroid Build Coastguard Worker- We use LLVM-C bindings for now. They are not documented, but follow 306*61046927SAndroid Build Coastguard Worker the C++ interfaces very closely, and appear to be complete enough for 307*61046927SAndroid Build Coastguard Worker code generation. See `this stand-alone 308*61046927SAndroid Build Coastguard Worker example <https://npcontemplation.blogspot.com/2008/06/secret-of-llvm-c-bindings.html>`__. 309*61046927SAndroid Build Coastguard Worker See the ``llvm-c/Core.h`` file for reference. 310*61046927SAndroid Build Coastguard Worker 311*61046927SAndroid Build Coastguard Worker.. _recommended_reading: 312*61046927SAndroid Build Coastguard Worker 313*61046927SAndroid Build Coastguard WorkerRecommended Reading 314*61046927SAndroid Build Coastguard Worker------------------- 315*61046927SAndroid Build Coastguard Worker 316*61046927SAndroid Build Coastguard Worker- Rasterization 317*61046927SAndroid Build Coastguard Worker 318*61046927SAndroid Build Coastguard Worker - `Triangle Scan Conversion using 2D Homogeneous 319*61046927SAndroid Build Coastguard Worker Coordinates <https://userpages.cs.umbc.edu/olano/papers/2dh-tri/>`__ 320*61046927SAndroid Build Coastguard Worker - `Rasterization on 321*61046927SAndroid Build Coastguard Worker Larrabee <https://www.drdobbs.com/parallel/rasterization-on-larrabee/217200602>`__ 322*61046927SAndroid Build Coastguard Worker - `Rasterization using half-space 323*61046927SAndroid Build Coastguard Worker functions <http://web.archive.org/web/20110820052005/http://www.devmaster.net/codespotlight/show.php?id=17>`__ 324*61046927SAndroid Build Coastguard Worker - `Advanced 325*61046927SAndroid Build Coastguard Worker Rasterization <http://web.archive.org/web/20140514220546/http://devmaster.net/posts/6145/advanced-rasterization>`__ 326*61046927SAndroid Build Coastguard Worker - `Optimizing Software Occlusion 327*61046927SAndroid Build Coastguard Worker Culling <https://fgiesen.wordpress.com/2013/02/17/optimizing-sw-occlusion-culling-index/>`__ 328*61046927SAndroid Build Coastguard Worker 329*61046927SAndroid Build Coastguard Worker- Texture sampling 330*61046927SAndroid Build Coastguard Worker 331*61046927SAndroid Build Coastguard Worker - `Perspective Texture 332*61046927SAndroid Build Coastguard Worker Mapping <https://chrishecker.com/Miscellaneous_Technical_Articles#Perspective_Texture_Mapping>`__ 333*61046927SAndroid Build Coastguard Worker - `Texturing As In 334*61046927SAndroid Build Coastguard Worker Unreal <https://www.flipcode.com/archives/Texturing_As_In_Unreal.shtml>`__ 335*61046927SAndroid Build Coastguard Worker - `Run-Time MIP-Map 336*61046927SAndroid Build Coastguard Worker Filtering <http://web.archive.org/web/20220709145555/http://www.gamasutra.com/view/feature/3301/runtime_mipmap_filtering.php>`__ 337*61046927SAndroid Build Coastguard Worker - `Will "brilinear" filtering 338*61046927SAndroid Build Coastguard Worker persist? <https://alt.3dcenter.org/artikel/2003/10-26_a_english.php>`__ 339*61046927SAndroid Build Coastguard Worker - `Trilinear 340*61046927SAndroid Build Coastguard Worker filtering <http://ixbtlabs.com/articles2/gffx/nv40-rx800-3.html>`__ 341*61046927SAndroid Build Coastguard Worker - `Texture tiling and 342*61046927SAndroid Build Coastguard Worker swizzling <https://fgiesen.wordpress.com/2011/01/17/texture-tiling-and-swizzling/>`__ 343*61046927SAndroid Build Coastguard Worker 344*61046927SAndroid Build Coastguard Worker- SIMD 345*61046927SAndroid Build Coastguard Worker 346*61046927SAndroid Build Coastguard Worker - `Whole-Function 347*61046927SAndroid Build Coastguard Worker Vectorization <https://compilers.cs.uni-saarland.de/projects/wfv/#pubs>`__ 348*61046927SAndroid Build Coastguard Worker 349*61046927SAndroid Build Coastguard Worker- Optimization 350*61046927SAndroid Build Coastguard Worker 351*61046927SAndroid Build Coastguard Worker - `Optimizing Pixomatic For Modern x86 352*61046927SAndroid Build Coastguard Worker Processors <https://www.drdobbs.com/optimizing-pixomatic-for-modern-x86-proc/184405807>`__ 353*61046927SAndroid Build Coastguard Worker - `Intel 64 and IA-32 Architectures Optimization Reference 354*61046927SAndroid Build Coastguard Worker Manual <https://www.intel.com/content/www/us/en/content-details/779559/intel-64-and-ia-32-architectures-optimization-reference-manual.html>`__ 355*61046927SAndroid Build Coastguard Worker - `Software optimization 356*61046927SAndroid Build Coastguard Worker resources <https://www.agner.org/optimize/>`__ 357*61046927SAndroid Build Coastguard Worker - `Intel Intrinsics 358*61046927SAndroid Build Coastguard Worker Guide <https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html>`__ 359*61046927SAndroid Build Coastguard Worker 360*61046927SAndroid Build Coastguard Worker- LLVM 361*61046927SAndroid Build Coastguard Worker 362*61046927SAndroid Build Coastguard Worker - `LLVM Language Reference 363*61046927SAndroid Build Coastguard Worker Manual <https://llvm.org/docs/LangRef.html>`__ 364*61046927SAndroid Build Coastguard Worker - `The secret of LLVM C 365*61046927SAndroid Build Coastguard Worker bindings <https://npcontemplation.blogspot.com/2008/06/secret-of-llvm-c-bindings.html>`__ 366*61046927SAndroid Build Coastguard Worker 367*61046927SAndroid Build Coastguard Worker- General 368*61046927SAndroid Build Coastguard Worker 369*61046927SAndroid Build Coastguard Worker - `A trip through the Graphics 370*61046927SAndroid Build Coastguard Worker Pipeline <https://fgiesen.wordpress.com/2011/07/09/a-trip-through-the-graphics-pipeline-2011-index/>`__ 371*61046927SAndroid Build Coastguard Worker - `WARP Architecture and 372*61046927SAndroid Build Coastguard Worker Performance <https://learn.microsoft.com/en-us/windows/win32/direct3darticles/directx-warp#warp-architecture-and-performance>`__ 373