摘自 Wikipedia:OpenGL:
- OpenGL (Open Graphics Library) 是一個跨語言、跨平台的應用程式編程接口(API),用於渲染 2D 和 3D 矢量圖形。
可在Khronos上了解更多信息。
OpenGL 的開發已於 2017 年停止,取而代之的是 Vulkan,這是「下一代」API,可在較新的硬體上提供更高的性能。
安裝
要運行使用 OpenGL 的應用程式,您需要為您的硬體(GPU 或 CPU)安裝正確的驅動程序。
- 對於 AMD(和 ATI),建議使用開源驅動程序,除非您有充分的理由使用專有驅動程序。
- 對於 NVIDIA,建議將專有驅動程序用在比 Kepler (NVE0/GKXXX) 系列更新的顯卡上,並且總體上性能更好。
- 英特爾的GenN硬體不是指CPU的一代,而是指GPU的一代,這與CPU的一代不同。
- 要查找 AMD(和 ATI)GPU 系列,請查閱Wikipedia:List of AMD graphics processing units#Features overview
- 要查找 NVIDIA GPU 的代號,請查看 Nouveau 項目中的代碼列表
Mesa 是一個開源的 OpenGL 實現,它不斷更新以支持最新的 OpenGL 規範。它有一系列用於 Intel 顯卡、AMD(以前稱為 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 支持。 -
swrast
:舊的軟體光柵化器。從 Mesa 22.0.0[1]起,該驅動程序已停用,但原始碼中仍有該驅動程序(ArchLinux 截止到 24.1.1[2] 仍包含該驅動程序)。
-
-
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 的實現。
- amdgpu-pro-oglpAUR 是用於 AMD GPU 的專有驅動程序。
驗證安裝
要驗證您的 OpenGL 安裝,您可以使用 mesa-utils包 eglinfo
,它應該顯示如下輸出(當然,根據您的設置,其值不同):
$ eglinfo -B
Wayland platform: EGL API version: 1.4 EGL vendor string: Mesa Project EGL version string: 1.4 EGL client APIs: OpenGL OpenGL_ES OpenGL compatibility profile vendor: Mesa Project OpenGL compatibility profile renderer: i915 (chipset: Pineview M) OpenGL compatibility profile version: 2.1 Mesa 23.1.5 OpenGL compatibility profile shading language version: 1.20 OpenGL ES profile vendor: Mesa Project OpenGL ES profile renderer: i915 (chipset: Pineview M) OpenGL ES profile version: OpenGL ES 2.0 Mesa 23.1.5 OpenGL ES profile shading language version: OpenGL ES GLSL ES 1.0.16 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: Mesa OpenGL core profile renderer: llvmpipe (LLVM 15.0.7, 128 bits) OpenGL core profile version: 4.5 (Core Profile) Mesa 23.1.5 OpenGL core profile shading language version: 4.50 OpenGL compatibility profile vendor: Mesa OpenGL compatibility profile renderer: llvmpipe (LLVM 15.0.7, 128 bits) OpenGL compatibility profile version: 4.5 (Compatibility Profile) Mesa 23.1.5 OpenGL compatibility profile shading language version: 4.50 OpenGL ES profile vendor: Mesa OpenGL ES profile renderer: llvmpipe (LLVM 15.0.7, 128 bits) OpenGL ES profile version: OpenGL ES 3.2 Mesa 23.1.5 OpenGL ES profile shading language version: OpenGL ES GLSL ES 3.20
在 X11 平台上,也可以使用glxinfo
。
在同一個軟體包中,您還可以使用 eglgears_x11
或 glxgears
(在 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 可能更低。
要在 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 application
開發
在代碼中使用 OpenGL 需要函數加載器,在 Khronos 上閱讀更多內容。
OpenGL 硬體資料庫
GPUInfo 提供了用戶報告的 GPU/驅動程序組合、支持的擴展、功能等。此信息可用於驗證 OpenGL 和 Vulkan 下特定硬體的兼容性/合規性。