0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

MacOSのUTM仮想環境上でOpenGLプログラムを動かす時のエラー回避方法

Posted at

概要

学校の授業で配布されたOpenGLのサンプルコードをM1 Mac上のUTMで立てたUbuntu環境で実行した際にVertexShader compile error: 0:4(10): error: GLSL 1.30 is not supported. Supported versions are: 1.10, 1.20, 1.00 ES, and 3.00 ESというエラーが発生し、描画されませんでした。その際に取った解決方法を簡単にまとめておきます。

環境

MacOS: Ventura v13.1
チップ: M1
仮想マシーン:UTM v3.1.5
ゲストOS:Ubuntu server 22.04.1 LTS
OpneGLバージョン

% glxinfo -B
name of display: :0
display: :0  screen: 0
direct rendering: Yes
Extended renderer info (GLX_MESA_query_renderer):
    Vendor: Mesa/X.org (0x1af4)
    Device: virgl (ANGLE (Apple, Apple M1, OpenGL 4.1 Metal - 83)) (0x1010)
    Version: 22.0.5
    Accelerated: yes
    Video memory: 0MB
    Unified memory: no
    Preferred profile: compat (0x2)
    Max core profile version: 0.0
    Max compat profile version: 2.1
    Max GLES1 profile version: 1.1
    Max GLES[23] profile version: 3.0
OpenGL vendor string: Mesa/X.org
OpenGL renderer string: virgl (ANGLE (Apple, Apple M1, OpenGL 4.1 Metal - 83))
OpenGL version string: 2.1 Mesa 22.0.5
OpenGL shading language version string: 1.20

OpenGL ES profile version string: OpenGL ES 3.0 Mesa 22.0.5
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.00

プログラム

C言語
ライブラリ:GL/glut.h

エラー

GL_VERSION : 2.1 Mesa 22.0.5
VertexShader compile error: 0:4(10): error: GLSL 1.30 is not supported. Supported versions are: 1.10, 1.20, 1.00 ES, and 3.00 ES

これを見る限りバージョンが合って無さそう。。。

以下の表はGLSLとOpenGLのバージョン対応表です。

#version GLSL OpenGL
無指定 1.0 OpenGL 1.5
#version 110 1.10 2.0
#version 120 1.20 2.1 ESSL 1.00 相当
#version 130 1.30 3.0
#version 140 1.40 3.1
#version 150 1.50 3.2
#version 330 3.30 3.3 ESSL 3.00 相当
#version 400 4.00 4.0
#version 410 4.10 4.1
#version 420 4.20 4.2
#version 430 4.30 4.3
#version 440 4.40 4.4
#version 450 4.50 4.5
#version 460 4.60 4.6

詳しくないので分かりませんがホストOS側のOpenGLとゲストOS側のOpenGLの環境がうまく対応できていない感じがします。

解決

ということで、UTMのDisplay設定を見てみます。
image.png

Emulated Display Cardがvirtio-ramfb-gl(GPU Supported)となっています。

とても怪しいですね。
試しに別のに変えてみます。

image.png

GPUサポートのないvirtio-ramfb-glがあるので、これを選択してみます。

プログラムを実行すると、ちゃんと起動し、描画できました。

image.png

バージョン情報を見てみます。すると、バージョンがさっきと変わっています。
デバイスがM1 Macのものから別のものに変わっています。つまり、仮想環境でGPUサポートを行うとホストOS側のデバイスが使用されるため、仮想環境側のOpenGLの環境をホストOS側に合わせる必要があるということが分かります。ただ、対応の仕方がよく分からないのと、GPUサポートの必要性がないので、一旦サポートなしで使っていこうと思います。

glxinfo -B
name of display: :0
display: :0  screen: 0
direct rendering: Yes
Extended renderer info (GLX_MESA_query_renderer):
    Vendor: Mesa/X.org (0xffffffff)
    Device: llvmpipe (LLVM 13.0.1, 128 bits) (0xffffffff)
    Version: 22.0.5
    Accelerated: no
    Video memory: 3908MB
    Unified memory: no
    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
OpenGL vendor string: Mesa/X.org
OpenGL renderer string: llvmpipe (LLVM 13.0.1, 128 bits)
OpenGL core profile version string: 4.5 (Core Profile) Mesa 22.0.5
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 22.0.5
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 22.0.5
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20

もし、GPUサポートが必要であれば、ホストOS側とゲストOS側のバージョンの対応関係を正しく取ってあげる必要があります。

これに関する知見がある方でもっと良い解決を知っている人がいれば、ぜひ教えて下さい。お願いします🙇

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?