WSL2 GUI レンダリング問題発生
WSL2では、WSLgの機能によりGUIアプリが動作するようになりました。
そこで、google-chromeをインストールするとレンダリング問題が発生しました。
発生したPCは、HP Spectre x360 16-aaでGPUにNVIDIA GeForce RTX 4050グラフィックスを搭載しています。
GUIアプリを表示させた場合にレンダリング異常なのかchromeの枠だけ表示して内側は透明になりWindowsの壁紙が透ける現象が発生しました。
$ google-chrome
いろいろ調べて、このレンダリング問題が解決したのでその際の対応方法を記載します。
GPUの確認
最初にGPUを確認します。
glxinfoツールは、LinuxでOpenGLの実装情報を表示するためのコマンドラインツールです。
OpenGLのバージョン、レンダラー、ベンダー、対応している拡張機能などの詳細を確認できます。
次のように、glxinfoを以下ストールします。
$ sudo apt install mesa-utils
glxinfo -Bコマンドで確認します。
$ glxinfo -B
name of display: :0
display: :0 screen: 0
direct rendering: Yes
Extended renderer info (GLX_MESA_query_renderer):
Vendor: Microsoft Corporation (0xffffffff)
Device: D3D12 (Intel(R) Arc(TM) Graphics) (0xffffffff)
Version: 24.2.8
Accelerated: yes
Video memory: 18437MB
Unified memory: yes
Preferred profile: core (0x1)
Max core profile version: 4.6
Max compat profile version: 4.6
Max GLES1 profile version: 1.1
Max GLES[23] profile version: 3.1
OpenGL vendor string: Microsoft Corporation
OpenGL renderer string: D3D12 (Intel(R) Arc(TM) Graphics)
OpenGL core profile version string: 4.6 (Core Profile) Mesa 24.2.8-1ubuntu1~24.04.1
OpenGL core profile shading language version string: 4.60
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL version string: 4.6 (Compatibility Profile) Mesa 24.2.8-1ubuntu1~24.04.1
OpenGL shading language version string: 4.60
OpenGL context flags: (none)
OpenGL profile mask: compatibility profile
OpenGL ES profile version string: OpenGL ES 3.1 Mesa 24.2.8-1ubuntu1~24.04.1
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.10
GPUは、Intel Arc Graphicsを使用するようになっているのが問題のようです。
ChromeでGPU無効
Chromeを起動するとき、「–disable-gpu」オプションを付けてGPUを無効にするとchromeブラウザを表示しました。
$ google-chrome --disable-gpu
WSL2でGPUを無効に
WSL2で動作させるGUIアプリは、Chromeだけではありません。
他のGUIアプリでも同じようなレンダリング問題が発生してしまいます。
そこで、WSL2でGPUを無効にできないか調べました。
環境変数LIBGL_ALWAYS_SOFTWARE=1とすることで、GPUを無効にしてソフトウェアでレンダリングできるようです。
$ export LIBGL_ALWAYS_SOFTWARE=1
glxinfo -Bコマンドで確認します。
$ glxinfo -B
name of display: :0
display: :0 screen: 0
direct rendering: Yes
Extended renderer info (GLX_MESA_query_renderer):
Vendor: Mesa (0xffffffff)
Device: llvmpipe (LLVM 19.1.1, 256 bits) (0xffffffff)
Version: 24.2.8
Accelerated: no
Video memory: 15670MB
Unified memory: yes
Preferred profile: core (0x1)
Max core profile version: 4.5
Max compat profile version: 4.5
Max GLES1 profile version: 1.1
Max GLES[23] profile version: 3.2
Memory info (GL_ATI_meminfo):
VBO free memory - total: 31 MB, largest block: 31 MB
VBO free aux. memory - total: 14942 MB, largest block: 14942 MB
Texture free memory - total: 31 MB, largest block: 31 MB
Texture free aux. memory - total: 14942 MB, largest block: 14942 MB
Renderbuffer free memory - total: 31 MB, largest block: 31 MB
Renderbuffer free aux. memory - total: 14942 MB, largest block: 14942 MB
Memory info (GL_NVX_gpu_memory_info):
Dedicated video memory: 4293464819 MB
Total available memory: 4293480490 MB
Currently available dedicated video memory: 31 MB
OpenGL vendor string: Mesa
OpenGL renderer string: llvmpipe (LLVM 19.1.1, 256 bits)
OpenGL core profile version string: 4.5 (Core Profile) Mesa 24.2.8-1ubuntu1~24.04.1
OpenGL core profile shading language version string: 4.50
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL version string: 4.5 (Compatibility Profile) Mesa 24.2.8-1ubuntu1~24.04.1
OpenGL shading language version string: 4.50
OpenGL context flags: (none)
OpenGL profile mask: compatibility profile
OpenGL ES profile version string: OpenGL ES 3.2 Mesa 24.2.8-1ubuntu1~24.04.1
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20
Accelerated: noとなりました。
$ google-chrome
Chromeブラウザを表示できました。
WSLgでのGPU選択
これで根本的に解決できた訳ではありません。せっかくNVIDIA GeForce RTX 4050グラフィックスを搭載しているのに、GPUを活用できていないのですから。
このサイト( WSLgでのGPU選択 )に役に立つ情報が書かれていました。
環境変数MESA_D3D12_DEFAULT_ADAPTER_NAMEにGPUを指定することにより、NVIDIA GPUを使用することができます。
$ export MESA_D3D12_DEFAULT_ADAPTER_NAME=NVIDIA
glxinfo -Bコマンドで確認します。
$ glxinfo -B
name of display: :0
display: :0 screen: 0
direct rendering: Yes
Extended renderer info (GLX_MESA_query_renderer):
Vendor: Microsoft Corporation (0xffffffff)
Device: D3D12 (NVIDIA GeForce RTX 4050 Laptop GPU) (0xffffffff)
Version: 24.2.8
Accelerated: yes
Video memory: 24230MB
Unified memory: no
Preferred profile: core (0x1)
Max core profile version: 4.6
Max compat profile version: 4.6
Max GLES1 profile version: 1.1
Max GLES[23] profile version: 3.1
OpenGL vendor string: Microsoft Corporation
OpenGL renderer string: D3D12 (NVIDIA GeForce RTX 4050 Laptop GPU)
OpenGL core profile version string: 4.6 (Core Profile) Mesa 24.2.8-1ubuntu1~24.04.1
OpenGL core profile shading language version string: 4.60
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL version string: 4.6 (Compatibility Profile) Mesa 24.2.8-1ubuntu1~24.04.1
OpenGL shading language version string: 4.60
OpenGL context flags: (none)
OpenGL profile mask: compatibility profile
OpenGL ES profile version string: OpenGL ES 3.1 Mesa 24.2.8-1ubuntu1~24.04.1
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.10
Device: D3D12にNVIDIA GeForce RTX 4050 Laptop GPUを使用するようになりました。
$ google-chrome
Chromeブラウザを表示できました。
WSL2に登録
WSL2を起動するごとに環境変数を設定するのは面倒です。
そこで、bashシェルの起動時に読み込む設定ファイル.bashrcの最後に、「export MESA_D3D12_DEFAULT_ADAPTER_NAME=NVIDIA」を指定します。