# VMware guest GL driver

This page describes how to build, install and use the VMware guest GL driver (aka the SVGA or SVGA3D driver) for Linux using the latest source code. This driver gives a Linux virtual machine access to the host's GPU for hardware-accelerated 3D. VMware Workstation running on Linux or Windows and VMware Fusion running on MacOS are all supported.

End users shouldn't have to go through all these steps once the driver is included in newer Linux distributions.

For more information about the X components see these wiki pages at x.org:

- Driver Overview
- xf86-video-vmware Details

## Components

The components involved in this include:

- Linux kernel module: vmwgfx
- X server 2D driver: xf86-video-vmware
- User-space libdrm library
- Mesa/gallium OpenGL driver: "svga"

## Prerequisites

- Kernel version at least 2.6.25
- Xserver version at least 1.7
- Ubuntu: For ubuntu you need to install a number of build dependencies.

        sudo apt-get install git-core
        sudo apt-get install automake libtool libpthread-stubs0-dev
        sudo apt-get install xserver-xorg-dev x11proto-xinerama-dev
        sudo apt-get build-dep libgl1-mesa-dri libxcb-glx0-dev

- Fedora: For Fedora you also need to install a number of build dependencies.

        sudo yum install mesa-libGL-devel xorg-x11-server-devel xorg-x11-util-macros
        sudo yum install automake gcc libtool expat-devel kernel-devel git-core

Depending on your Linux distro, other packages may be needed. The configure scripts should tell you what's missing.

## Getting the Latest Source Code

Begin by saving your current directory location:

      export TOP=$PWD

- Mesa/Gallium master branch. This code is used to build libGL, and the direct rendering svga driver for libGL, vmwgfx_dri.so, and the X acceleration library libxatracker.so.x.x.x.

        git clone git://anongit.freedesktop.org/git/mesa/mesa

- VMware Linux guest kernel module. Note that this repo contains the complete DRM and TTM code. The vmware-specific driver is really only the files prefixed with vmwgfx.

        git clone git://anongit.freedesktop.org/git/mesa/vmwgfx

- libdrm, A user-space library that interfaces with drm. Most distros ship with this driver. Safest bet is really to replace the system one. Optionally you can point LIBDRM_CFLAGS and LIBDRM_LIBS to the libdrm-2.4.22 package in toolchain. But here, we replace:

        git clone git://anongit.freedesktop.org/git/mesa/drm

- xf86-video-vmware. The chainloading driver, vmware_drv.so, the legacy driver vmwlegacy_drv.so, and the vmwgfx driver vmwgfx_drv.so.

        git clone git://anongit.freedesktop.org/git/xorg/driver/xf86-video-vmware

## Building the Code

- Build libdrm: If you're on a 32-bit system, you should skip the --libdir configure option. Note also the comment about toolchain libdrm above.

        cd $TOP/drm
        ./autogen.sh --prefix=/usr --enable-vmwgfx-experimental-api --libdir=/usr/lib64
        make
        sudo make install

- Build Mesa and the vmwgfx_dri.so driver, the vmwgfx_drv.so xorg driver, the X acceleration library libxatracker. The vmwgfx_dri.so is used by the OpenGL libraries during direct rendering, and by the Xorg server during accelerated indirect GL rendering. The libxatracker library is used exclusively by the X server to do render, copy and video acceleration:
  The following configure options doesn't build the EGL system.
  As before, if you're on a 32-bit system, you should skip the --libdir configure option.

        cd $TOP/mesa
        ./autogen.sh --prefix=/usr --libdir=/usr/lib64 --with-gallium-drivers=svga --with-dri-drivers= --enable-xa
        make
        sudo make install

  Note that you may have to install other packages that Mesa depends upon if they're not installed in your system. You should be told what's missing.
- xf86-video-vmware: Now, once libxatracker is installed, we proceed with building and replacing the current Xorg driver. First check if your system is 32- or 64-bit. If you're building for a 32-bit system, you will not be needing the --libdir=/usr/lib64 option to autogen.

        cd $TOP/xf86-video-vmware
        ./autogen.sh --prefix=/usr --libdir=/usr/lib64
        make
        sudo make install

- vmwgfx kernel module. First make sure that any old version of this kernel module is removed from the system by issuing

        sudo rm /lib/modules/`uname -r`/kernel/drivers/gpu/drm/vmwgfx.ko*

  Then

        cd $TOP/vmwgfx
        make
        sudo make install
        sudo cp 00-vmwgfx.rules /etc/udev/rules.d
        sudo depmod -ae

Now try to load the kernel module by issuing

      sudo modprobe vmwgfx

Then type

      dmesg

to watch the debug output. It should contain a number of lines prefixed with "[vmwgfx]".

Then restart the Xserver (or reboot). The lines starting with "vmwlegacy" or "VMWARE" in the file /var/log/Xorg.0.log should now have been replaced with lines starting with "vmwgfx", indicating that the new Xorg driver is in use.

## Running OpenGL Programs

In a shell, run 'glxinfo' and look for the following to verify that the driver is working:

    OpenGL vendor string: VMware, Inc.
    OpenGL renderer string: Gallium 0.4 on SVGA3D; build: RELEASE;
    OpenGL version string: 2.1 Mesa 8.0

If you don't see this, try setting this environment variable:

      export LIBGL_DEBUG=verbose

then rerun glxinfo and examine the output for error messages.