Enabling Graphics Acceleration on WSL2

By default, running any GUI (Graphical User Interface) Linux applications on WSL will use your CPU as the renderer. This isn't optimal for Gazebo, since we'll be running simulations.
This guide will show you how to force WSL to use your dedicated graphics card (if you have it on your laptop) for Gazebo and any other GUI applications.

Prereqs

  1. WSL2 installed
  2. Dedicated graphics card on your laptop. See below on how to check if you have one.
    • To check, open Task Manager>Performance>GPU.
    • If you see something like NVIDIA like below, you have dedicated GPU ✅. Continue with this guide
      • If you only see 1 GPU, you don't have a dedicated GPU ❌.
        Don't continue with this guide, as WSL is already using your integrated graphics.
      • Pasted image 20250911175347.png
  3. ROS2 + Gazebo installed → see 9/8 guide

Setup on WSL side

If you installed WSL2 and Ubuntu-24.04 during the 9/8 meeting, then you don't have to do this step. Move on to Ubuntu Setup.

If you have an existing WSL installation, you need to check if you have WSL1 or WSL2 installed. It's very likely you have WSL2 installed, unless you installed WSL >3 years ago.
To check just in case, follow the below steps.

  1. Open an elevated command prompt
    Pasted image 20250911180153.png
  2. Run wsl --list -v.
    Pasted image 20250911180353.png

Ubuntu Setup

We'll need to add some lines to our ~/.bashrc to force any GUI applications to use your dedicated GPU.

For context, the ~/.bashrc file is a shell script that the Bash shell (your Ubuntu shell) runs whenever your Linux terminal starts.

To edit the ~/.bashrc file, we'll use nano, a lightweight text editor built-in to Ubuntu. You can also use vi or vim if you're familiar with that.

  1. Open your ~/.bashrc file with nano using nano ~/.bashrc.
  2. There'll be a lot of preloaded text. Scroll to the bottom and paste the following lines. Change NVIDIA to AMD if you have an AMD GPU. You may need to use CTRL+SHIFT+V or right click to paste on Ubuntu, if CTRL+V doesn't work.
export MESA_D3D12_DEFAULT_ADAPTER_NAME=NVIDIA
export GALLIUM_DRIVER=d3d12

Pasted image 20250915011545.png
3. After pasting those lines, we need to save our changes. To save changes in nano, press CTRL+X, then press Y, and Enter.
4. After saving, you'll need to "source" your ~/.bashrc file. This "reloads" your terminal by re-executing the commands/scripts inside ~/.bashrc. Since we added new lines to it, we need to source it

source ~/.bashrc
  1. Now, let's check which GPU is being used now.
glxinfo | grep "OpenGL renderer"
  1. If successful, you should see your dedicated GPU being used, as below:
    Pasted image 20250911190222.png