Cross compiling Mesa for Windows: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
(Add "cleanup" tag)
No edit summary
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Cleanup | reason=Auto-imported from ExpressionEngine.}}
{{LangSwitch}}
 
[[Category:MinGW]]
[[Category:MinGW]]
[[Category:Windows]]
[[Category:Windows]]
[[Category:Qt5]]
[[Category:Qt5]]


= Cross compiling Mesa for Windows =
NB! Current Qt versions ship a build as opengl32sw.dll in the official binary packages. Builds are also available at http://download.qt.io/development_releases/prebuilt/llvmpipe/windows/ For instructions on recreating those builds on Windows with MSVC2015, see [[MesaLlvmpipe]].


QtQuick 2.0 applications require OpenGL 2.1 or higher to run. Windows only provides OpenGL 1.1 by default, which is not sufficient. One workaround is to use ANGLE which implements the OpenGL ES 2 API on top of DirectX 9. The benefit of using ANGLE is that the graphics are hardware-accelerated but ANGLE requires Windows Vista or later. The other option is to use a software renderer such as Mesa which can run on Windows XP or later and may perform better than ANGLE when running inside virtual machines.
QtQuick 2.0 applications require OpenGL 2.1 or higher to run. Windows only provides OpenGL 1.1 by default, which is not sufficient. One workaround is to use ANGLE which implements the OpenGL ES 2 API on top of DirectX 9. The benefit of using ANGLE is that the graphics are hardware-accelerated but ANGLE requires Windows Vista or later. The other option is to use a software renderer such as Mesa which can run on Windows XP or later and may perform better than ANGLE when running inside virtual machines.
Line 14: Line 13:


Prebuilt binaries for Mesa are available from the MSYS2 project:
Prebuilt binaries for Mesa are available from the MSYS2 project:
* "Mesa 10.0.2 for Windows 32-bit binary":http://downloads.sourceforge.net/project/msys2/REPOS/MINGW/i686/mingw-w64-i686-mesa-10.0.2-1-any.pkg.tar.xz
* [http://downloads.sourceforge.net/project/msys2/REPOS/MINGW/i686/mingw-w64-i686-mesa-10.0.2-1-any.pkg.tar.xz Mesa 10.0.2 for Windows 32-bit binary]
* "Mesa 10.0.2 for Windows 64-bit binary":http://downloads.sourceforge.net/project/msys2/REPOS/MINGW/x86_64/mingw-w64-x86_64-mesa-10.0.2-1-any.pkg.tar.xz
* [http://downloads.sourceforge.net/project/msys2/REPOS/MINGW/x86_64/mingw-w64-x86_64-mesa-10.0.2-1-any.pkg.tar.xz Mesa 10.0.2 for Windows 64-bit binary]
 
The library is also shipped with QtCreator in QtCreator\bin\opengl32sw.dll.


== Install required Arch Linux packages ==
== Install required Arch Linux packages ==
Line 37: Line 38:
wget http://llvm.org/releases/3.4/llvm-3.4.src.tar.gz
wget http://llvm.org/releases/3.4/llvm-3.4.src.tar.gz
wget ftp://ftp.freedesktop.org/pub/mesa/10.0.2/MesaLib-10.0.2.tar.bz2
wget ftp://ftp.freedesktop.org/pub/mesa/10.0.2/MesaLib-10.0.2.tar.bz2
</code>
For LLVM build zlib is also needed. (Build steps taken from here: http://stackoverflow.com/a/26021820/754982)
<code>
wget http://zlib.net/zlib-1.2.8.tar.gz
</code>
</code>


Line 44: Line 51:
tar -xvf llvm-3.4.src.tar.gz
tar -xvf llvm-3.4.src.tar.gz
tar -xvf MesaLib-10.0.2.tar.bz2
tar -xvf MesaLib-10.0.2.tar.bz2
tar -xvf zlib-1.2.8.tar.gz
</code>
== Build zlib ==
<code>
cd zlib-1.2.8
#  automatic replacement
sed -e s/"PREFIX ="/"PREFIX = i686-w64-mingw32-"/ -i win32/Makefile.gcc
BINARY_PATH=/usr/i686-w64-mingw32/bin INCLUDE_PATH=/usr/i686-w64-mingw32/include LIBRARY_PATH=/usr/i686-w64-mingw32/lib make -f win32/Makefile.gcc
BINARY_PATH=/usr/i686-w64-mingw32/bin INCLUDE_PATH=/usr/i686-w64-mingw32/include LIBRARY_PATH=/usr/i686-w64-mingw32/lib make -f win32/Makefile.gcc install
</code>
</code>


Line 59: Line 76:
</code>
</code>


Note: Use of the strerror_s function is disabled by writing an entry to config.cache for Windows XP compatibility.
Note: Use of the strerror_s function is disabled by writing an entry to config.cache for Windows XP compatibility. <br />
 
Note2: Make sure that libraries and includes are copied to /usr/i686-w64-mingw32/lib and /usr/i686-w64-mingw32/include directories. If not, copy them manually.
h3. Build Mesa


=== Build Mesa ===
<code>
<code>
cd~/mesa_win32/Mesa-10.0.2
cd~/mesa_win32/Mesa-10.0.2
Line 71: Line 88:
</code>
</code>


=== Complete ===
Note: If you are compiling a newer version of mesa, export CXXFLAGS="-std=c++11" might be needed before running scons.<br />
Note2: If the build fails because the macro M_PI_2 isn't defined in file src/glsl/builtin_functions.cpp you can solve it by copying following lines to the file (after #include <math.h>)


You can now copy opengl32.dll from the ~/mesa_win32/dist folder to the folder containing your application's executable.
<code>
Your Qt must be compiled with Desktop OpenGL to use opengl32.dll. The ANGLE build will not load the mesa library.
#define M_PI_2          1.57079632679489661923
#define M_PI_4          0.78539816339744830962
</code>


h2. Compiling for Windows 64-bit
=== Complete ===


h3. Create a working directory for build
You can now copy opengl32.dll from the ~/mesa_win32/dist folder to the folder containing your application's executable. <br />
Your Qt must be compiled with Desktop OpenGL to use opengl32.dll. The ANGLE build will not load the mesa library. <br />
If you are using QT 5.4 and above then rename the library to opengl32sw.dll. That way it will be used after standard OpenGL and ANGLE fail.


== Compiling for Windows 64-bit ==
=== Create a working directory for build ===
<code>
<code>
mkdir~/mesa_win64
mkdir~/mesa_win64
Line 85: Line 109:
</code>
</code>


h3. Download LLVM and Mesa sources
=== Download LLVM and Mesa sources ===
 
<code>
<code>
wget http://llvm.org/releases/3.4/llvm-3.4.src.tar.gz
wget http://llvm.org/releases/3.4/llvm-3.4.src.tar.gz
Line 92: Line 115:
</code>
</code>


h3. Extract sources
=== Extract sources ===
 
<code>
<code>
tar -xvf llvm-3.4.src.tar.gz
tar -xvf llvm-3.4.src.tar.gz
Line 99: Line 121:
</code>
</code>


h2. Build LLVM
== Build LLVM ==
 
<code>
<code>
cd~/mesa_win64/llvm-3.4
cd~/mesa_win64/llvm-3.4
Line 123: Line 144:
</code>
</code>


h3. Complete
=== Complete ===
 
You can now copy opengl32.dll from the~/mesa_win64/dist folder to the folder containing your application's executable.
You can now copy opengl32.dll from the~/mesa_win64/dist folder to the folder containing your application's executable.

Latest revision as of 11:26, 11 November 2016

En Ar Bg De El Es Fa Fi Fr Hi Hu It Ja Kn Ko Ms Nl Pl Pt Ru Sq Th Tr Uk Zh

NB! Current Qt versions ship a build as opengl32sw.dll in the official binary packages. Builds are also available at http://download.qt.io/development_releases/prebuilt/llvmpipe/windows/ For instructions on recreating those builds on Windows with MSVC2015, see MesaLlvmpipe.

QtQuick 2.0 applications require OpenGL 2.1 or higher to run. Windows only provides OpenGL 1.1 by default, which is not sufficient. One workaround is to use ANGLE which implements the OpenGL ES 2 API on top of DirectX 9. The benefit of using ANGLE is that the graphics are hardware-accelerated but ANGLE requires Windows Vista or later. The other option is to use a software renderer such as Mesa which can run on Windows XP or later and may perform better than ANGLE when running inside virtual machines.

This article describes the process of cross-compiling Mesa for Windows on Arch Linux. The result is an opengl32.dll DLL that you can copy to the folder containing your application's executable to use Mesa LLVMpipe software rendering.

Cross compiling is currently the only method that can compile the latest versions of Mesa for Windows using GCC. Compiling Mesa natively on Windows using GCC with Scons results in "the command line is too long" error during linking. There are known issues when compiling Mesa with optimizations using Visual Studio 2010. Compiling with Visual Studio 2012 is possible but requires Windows 7 and the default platform target does not support Windows XP. It is possible to cross compile using Cygwin or MSYS2 Scons.

Prebuilt binaries for Mesa are available from the MSYS2 project:

The library is also shipped with QtCreator in QtCreator\bin\opengl32sw.dll.

Install required Arch Linux packages

sudo pacman -S base-devel mingw-w64-toolchain libxml2 python2 scons

Compiling for Windows 32-bit

Create a working directory for build

mkdir ~/mesa_win32
cd~/mesa_win32

Download LLVM and Mesa sources

wget http://llvm.org/releases/3.4/llvm-3.4.src.tar.gz
wget ftp://ftp.freedesktop.org/pub/mesa/10.0.2/MesaLib-10.0.2.tar.bz2

For LLVM build zlib is also needed. (Build steps taken from here: http://stackoverflow.com/a/26021820/754982)

wget http://zlib.net/zlib-1.2.8.tar.gz

Extract sources

tar -xvf llvm-3.4.src.tar.gz
tar -xvf MesaLib-10.0.2.tar.bz2
tar -xvf zlib-1.2.8.tar.gz

Build zlib

cd zlib-1.2.8
#  automatic replacement
sed -e s/"PREFIX ="/"PREFIX = i686-w64-mingw32-"/ -i win32/Makefile.gcc
BINARY_PATH=/usr/i686-w64-mingw32/bin INCLUDE_PATH=/usr/i686-w64-mingw32/include LIBRARY_PATH=/usr/i686-w64-mingw32/lib make -f win32/Makefile.gcc
BINARY_PATH=/usr/i686-w64-mingw32/bin INCLUDE_PATH=/usr/i686-w64-mingw32/include LIBRARY_PATH=/usr/i686-w64-mingw32/lib make -f win32/Makefile.gcc install

Build LLVM

cd ~/mesa_win32/llvm-3.4
export PYTHON=/usr/bin/python2
mkdir build
cd build
echo 'ac_cv_have_decl_strerror_s=${ac_cv_have_decl_strerror_s=no}' > config.cache
../configure -C prefix=$HOME/mesa_win32/llvm-3.4.build host=i686-w64-mingw32 enable-optimized disable-assertions disable-pthreads enable-targets=x86 enable-bindings=none disable-libffi with-c-include-dirs=/usr/i686-w64-mingw32 with-gcc-toolchain=/usr/i686-w64-mingw32 with-default-sysroot=/usr/i686-w64-mingw32
make
make install

Note: Use of the strerror_s function is disabled by writing an entry to config.cache for Windows XP compatibility.
Note2: Make sure that libraries and includes are copied to /usr/i686-w64-mingw32/lib and /usr/i686-w64-mingw32/include directories. If not, copy them manually.

Build Mesa

cd~/mesa_win32/Mesa-10.0.2
export LLVM=$HOME/mesa_win32/llvm-3.4.build
LDFLAGS="-static -s" scons build=release platform=windows toolchain=crossmingw machine=x86 libgl-gdi
mkdir ~/mesa_win32/dist
cp -a build/windows-x86/gallium/targets/libgl-gdi/opengl32.dll~/mesa_win32/dist/

Note: If you are compiling a newer version of mesa, export CXXFLAGS="-std=c++11" might be needed before running scons.
Note2: If the build fails because the macro M_PI_2 isn't defined in file src/glsl/builtin_functions.cpp you can solve it by copying following lines to the file (after #include <math.h>)

#define M_PI_2          1.57079632679489661923
#define M_PI_4          0.78539816339744830962

Complete

You can now copy opengl32.dll from the ~/mesa_win32/dist folder to the folder containing your application's executable.
Your Qt must be compiled with Desktop OpenGL to use opengl32.dll. The ANGLE build will not load the mesa library.
If you are using QT 5.4 and above then rename the library to opengl32sw.dll. That way it will be used after standard OpenGL and ANGLE fail.

Compiling for Windows 64-bit

Create a working directory for build

mkdir~/mesa_win64
cd ~/mesa_win64

Download LLVM and Mesa sources

wget http://llvm.org/releases/3.4/llvm-3.4.src.tar.gz
wget ftp://ftp.freedesktop.org/pub/mesa/10.0.2/MesaLib-10.0.2.tar.bz2

Extract sources

tar -xvf llvm-3.4.src.tar.gz
tar -xvf MesaLib-10.0.2.tar.bz2

Build LLVM

cd~/mesa_win64/llvm-3.4
export PYTHON=/usr/bin/python2
mkdir build
cd build
echo 'ac_cv_have_decl_strerror_s=${ac_cv_have_decl_strerror_s=no}' > config.cache
../configure -C prefix=$HOME/mesa_win64/llvm-3.4.build host=x86_64-w64-mingw32 enable-optimized disable-assertions disable-pthreads enable-targets=x86_64 enable-bindings=none disable-libffi with-c-include-dirs=/usr/x86_64-w64-mingw32 with-gcc-toolchain=/usr/x86_64-w64-mingw32 with-default-sysroot=/usr/x86_64-w64-mingw32
make
make install

Note: Use of the strerror_s function is disabled by writing an entry to config.cache for Windows XP x64 compatibility.

Build Mesa

cd ~/mesa_win64/Mesa-10.0.2
LDFLAGS="-static -s" scons build=release platform=windows toolchain=crossmingw machine=x86_64 libgl-gdi
mkdir~/mesa_win64/dist
cp -a build/windows-x86_64/gallium/targets/libgl-gdi/opengl32.dll ~/mesa_win64/dist/

Complete

You can now copy opengl32.dll from the~/mesa_win64/dist folder to the folder containing your application's executable.