OpenGL
摘自 Wikipedia:OpenGL:
- OpenGL (Open Graphics Library) 是一個跨語言、跨平台的應用程式編程接口(API),用於渲染 2D 和 3D 矢量圖形。
可在Khronos上了解更多信息。
OpenGL 的開發已於 2017 年停止,取而代之的是 Vulkan,這是「下一代」API,可在較新的硬體上提供更高的性能。
安裝
要運行使用 OpenGL 的應用程式,您需要為您的硬體(GPU 或 CPU)安裝正確的驅動程序。
- 英特爾的GenN硬體不是指CPU的一代,而是指GPU的一代,這與CPU的一代不同。
- 要查找 AMD(和 ATI)GPU 系列,請查閱Wikipedia:List of AMD graphics processing units#Features overview。
- 要查找 NVIDIA GPU 的代號,請查看 Nouveau 項目中的代碼列表。
- 與 Fedora Linux 的社區軟體倉庫不同,Arch Linux 不會為受專利保護的視頻和音頻編解碼器提供「freeworld」軟體包變體;標準 Mesa 軟體包在編譯時已啟用所有相關編解碼器,與 Fedora 的「freeworld」軟體包相同。
Mesa 是一個開源的 OpenGL 實現,它不斷更新以支持最新的 OpenGL 規範。它有一系列用於 Intel 圖形處理器、AMDGPU(以前稱為 ATI)和 NVIDIA GPU 的開源驅動程序。Mesa 還提供軟體光柵器,例如 llvmpipe。
有兩個 Mesa 軟體包可選,每個軟體包都有一組不同的驅動程序:
-
mesa包 mesa 是最新的 Mesa 軟體包,其中包括用於較新硬體的大多數現代驅動程序:
-
r300: 適用於AMD的Radeon R300, R400, 和 R500 GPU。 -
r600: 適用於 AMD 的 Radeon R600 GPU,最高支持Northern Islands架構。由 AMD 官方支持。 -
radeonsi: 適用於 AMD 的 Southern Island GPU 及更高版本。由 AMD 官方支持。 -
nouveau: Nouveau是用於 NVIDIA GPU 的開源驅動程序。 -
virtio_gpu: 一個適用於 virtio 的虛擬 GPU 驅動程序,可與基於 QEMU 的 VMM(如 KVM 或 Xen)一起使用。 -
vmwgfx: 適用於 VMware 虛擬 GPU。 -
i915: 適用於英特爾的第 3 代硬體。 -
crocus: 適用於英特爾的第 4 代至第 7 代硬體。 -
iris: 適用於英特爾的第 8 代硬體及更高版本。由英特爾正式支持。 -
zink: 用於在 Vulkan 上運行 OpenGL 的 Gallium 驅動程序。 -
d3d12: 用於僅支持 D3D12(即 WSL)的設備上的 OpenGL 3.3 支持。 -
softpipe: 軟體光柵器和參考 Gallium 驅動程序。 -
llvmpipe: 軟體光柵化器,它使用 LLVM 生成 x86 JIT 代碼,並且是多線程的。
-
-
mesa-amber包 是傳統的 Mesa 軟體包,其中包括用於舊硬體的經典(非 Gallium3D)驅動程序:
-
i830: 適用於英特爾的第 2 代硬體。與i965相同的二進制文件。 -
i915: 適用於英特爾的第 3 代硬體。與i965. 相同的二進制文件。 -
i965: 適用於英特爾的第 4 代至第 11 代硬體。由英特爾正式支持。 -
radeon: 適用於 AMD 的 Radeon R100 GPU。與r200相同的二進制文件。 -
r200: 適用於 AMD 的 Radeon R200 GPU。 -
nouveau_vieux: 適用於 NVIDIA NV04(Fahrenheit) 至 NV20(Kelvin) GPU。 -
swrast: 舊版軟體光柵器
-
- 注意:使用 Mesa 時,系統會自動選擇正確的驅動程序,因此安裝軟體包後無需配置。
- nvidia-utils包 是用於NVIDIA GPU 的專有驅動程序,其中包括關於 OpenGL 的實現。
驗證安裝
要驗證您的 OpenGL 安裝,您可以使用 mesa-utils包 eglinfo ,它應該顯示如下輸出(當然,根據您的設置,其值不同):
$ eglinfo -B
Wayland platform: EGL API version: 1.5 EGL vendor string: Mesa Project EGL version string: 1.5 EGL client APIs: OpenGL OpenGL_ES OpenGL core profile vendor: Intel OpenGL core profile renderer: Mesa Intel(R) UHD Graphics (CML GT2) OpenGL core profile version: 4.6 (Core Profile) Mesa 25.1.3-arch1.3 OpenGL core profile shading language version: 4.60 OpenGL compatibility profile vendor: Intel OpenGL compatibility profile renderer: Mesa Intel(R) UHD Graphics (CML GT2) OpenGL compatibility profile version: 4.6 (Compatibility Profile) Mesa 25.1.3-arch1.3 OpenGL compatibility profile shading language version: 4.60 OpenGL ES profile vendor: Intel OpenGL ES profile renderer: Mesa Intel(R) UHD Graphics (CML GT2) OpenGL ES profile version: OpenGL ES 3.2 Mesa 25.1.3-arch1.3 OpenGL ES profile shading language version: OpenGL ES GLSL ES 3.20 X11 platform: EGL API version: 1.5 EGL vendor string: Mesa Project EGL version string: 1.5 EGL client APIs: OpenGL OpenGL_ES OpenGL core profile vendor: Intel OpenGL core profile renderer: Mesa Intel(R) UHD Graphics (CML GT2) OpenGL core profile version: 4.6 (Core Profile) Mesa 25.1.3-arch1.3 OpenGL core profile shading language version: 4.60 OpenGL compatibility profile vendor: Intel OpenGL compatibility profile renderer: Mesa Intel(R) UHD Graphics (CML GT2) OpenGL compatibility profile version: 4.6 (Compatibility Profile) Mesa 25.1.3-arch1.3 OpenGL compatibility profile shading language version: 4.60 OpenGL ES profile vendor: Intel OpenGL ES profile renderer: Mesa Intel(R) UHD Graphics (CML GT2) OpenGL ES profile version: OpenGL ES 3.2 Mesa 25.1.3-arch1.3 OpenGL ES profile shading language version: OpenGL ES GLSL ES 3.20
在 X11 平台上,也可以使用glxinfo。
在同一個軟體包中,您還可以使用 eglgears 或 glxgears_x11 (在 X11 上)或 eglgears_wayland (在 Wayland 上)作為基本 OpenGL 測試。運行程序時,您應該會看到 3 個旋轉齒輪。
在驅動程序之間切換
Mesa
您可以使用以下環境變量覆蓋用於應用程式的驅動程序:
MESA_LOADER_DRIVER_OVERRIDE=driver
默認情況下,Mesa 在 /lib/dri/ 中搜索驅動程序。您可以使用以下命令查看已安裝的驅動程序列表。
$ ls /lib/dri/
driver_dri.so 中的 driver 是驅動程序的實際名稱。如果 Mesa 無法找到指定的驅動程序,就會退回到 llvmpipe。
您還可以通過設置以下環境變量來使用 OpenGL 軟體光柵器:
LIBGL_ALWAYS_SOFTWARE=true GALLIUM_DRIVER=driver
driver 可以是 softpipe, llvmpipe 或 swr。
llvmpipe 與 swr 比 softpipe 更快。Vulkan 上的 OpenGL (Zink)
來自 Mesa 文檔:
- Zink 驅動程序是一個 Gallium 驅動程序,它能發出 Vulkan API 調用,而不是針對特定的 GPU 架構。它可用於在僅支持 Vulkan 的設備上獲得完整的桌面 OpenGL 支持。
如果您在默認 OpenGL 驅動程序中遇到問題(RadeonSI、Iris 等中的錯誤),您可以嘗試使用 Zink 驅動程序。
根據此 Phoronix 基準測試, 與 RadeonSI 相比,某些應用程式的平均 FPS 可能更低。
請注意,在使用 AMD 或 Intel DDX 驅動程序(分別為 xf86-video-amdgpu包 和 xf86-video-intel包)的 X 系統上,Zink 已無法開箱即用。上游開發者建議使用通用的 modesetting(4) DDX 驅動程序。[1] 或者,也可以通過設置以下環境變量來繞過此問題:
$ LIBGL_KOPPER_DRI2=1 MESA_LOADER_DRIVER_OVERRIDE=zink
要在 NVIDIA 驅動程序上使用 Zink,請使用以下命令或類似命令:
$ env __GLX_VENDOR_LIBRARY_NAME=mesa __EGL_VENDOR_LIBRARY_FILENAMES=/usr/share/glvnd/egl_vendor.d/50_mesa.json MESA_LOADER_DRIVER_OVERRIDE=zink GALLIUM_DRIVER=zink LIBGL_KOPPER_DRI2=1 application
故障排除
聯想設備的 Mesa GPU 圖形錯誤
Mesa 使用 CPU(llvmpipe)進行軟體渲染,導致部分圖形界面軟體崩潰。可以通過進入 BIOS 設置,將顯卡模式從獨立顯卡模式(Discrete Graphics)切換為動態顯卡模式(Dynamic Graphics)來解決此問題(如果使用其他品牌的計算機,應選擇允許在不同 GPU 之間切換的選項,而不是禁用集成顯卡)。如果未安裝主 GPU 的驅動程序,卻期望集成顯卡正常工作,則可能出現此問題。[2]