Rockchip RK3399 – Mali-T860 GPU驱动

原文链接:https://www.cnblogs.com/zyly/p/17459196.html#_label0_1_0


----------------------------------------------------------------------------------------------------------------------------

开发板 :NanoPC-T4开发板
eMMC16GB
LPDDR34GB
显示屏 :15.6英寸HDMI接口显示屏
u-bootuboot 2023.04
linux6.35.2.8
----------------------------------------------------------------------------------------------------------------------------

需要注意的是:本篇博客是以linux 6.3版本为主体介绍的,但是内容同样适用于linux 5.2.8版本。

一、图像界面卡顿问题

在前面的文章我们已经移植了在NanoPC-T4开发板上移植了uboot 2023.04inux 6.3、以及ubuntu 20.04.4根文件系统。然后在使用ubuntu桌面环境的时候,发现了一个问题,在firefox随便打开一个网页,视频都加载很慢,同时看到CPU的占用率会急剧升高;

1.1 图像卡顿原因

造成这种情况一般由两个原因:

  • 开发板上主控SoC的性能比较弱,没有带3D图形加速(即GPU)功能;
  • 开发板上的SoC带了GPU,但是没有用起来;

第一个原因基本是无解的,如果你选的SoC上面没有带GPU,唯一的办法就是尽量去跑轻量级的图形界面,如果想跑debianubuntu这种发行版上默认搭配的GNOME或者KDE,这种没有GPU支持,所有的图像合成渲染都要通过CPU来运算,是很难跑流畅的。所以如果你对图形显示功能比较看重,在选开发板的时候一定要查阅与之搭配的主控SoC是否带有GPU

也有很多人被卡在了第二个关卡,SoC上搭配了强劲的GPU、比如RK3399S912,他们都搭载了ARM Mali GPU,但是mainline内核(指的是主线linux内核)却缺少相应的驱动支持,GPU驱动一般分为两部分:

  • 一小部分在linux内核中;
  • 另外一大部分在userspace,在userspace的部分向下操作内核中的驱动,向上对应用层提供标准的 OpenGL接口,这样各种图形显示相关的应用才能通过标准的OpenGL API进行图形渲染加速。
1.2 ARM Mail GPU

Mali GPU IP提供商ARM公司只开放了内核部分驱动,而且这部分驱动还没有按照linux kernel的规范以DRM的框架去实现,所以它无法被linux mainline接受,还有一个更重要的部分,Userspace部分ARM没有开源,只是以库的形式提供给购买了Mali GPU授权的SoC厂商,比如RockchipAmlogic。而且这套代码主要是为Android系统设计的,对debianubuntu这种系统的兼容性也不好。

看到这里,也许你就想骂ARM了,其实也不能完全怪他们,因为这并不是ARM独创的玩法,其他的GPU供应商也都这样玩,比如NvidiaVivanteImagination。大神Linus为这事还对Nvidia竖过中指呢,怒吼:“Nvidia,F*K you!”。

面对这种状况,很多人为了能够利用GPU加速,就只能使用SoC原厂提供的内核,和他们定制的系统,这种内核和系统一般都比较老。

如果想跑mainline的内核,基本就没法使用GPU加速了,这也是为什么我们目前看到的大部分开发板如果搭载了mainline内核,基本都不会有GPU加速功能,或者直接就不开图形显示功能。

但是也有一部分黑客们不满于这种封锁,他们勇于探索,积极尝试,逆向了ARM发布的二进制库,然后重写了针对ARM Mali GPU的开源驱动,最终在Linux 5.2发布的时候合并到mainline中:

  • 针对Mali-400/Mali-450的驱动叫做Lima,针对Mali-T6xx / Mali-T7xx / Mali-T8xx GPUGXX系列的叫做Panfrost
  • Usersacpe部分的开源库叫做mesa,对Mali GPU的支持从mesa 19.2开始,这个我们在介绍 OpenGL的实现的时候已经提及到了;

这里我们将学习如何在运行linux kernrl 6.3RK3399开发板上开启GPU加速:RK3399集成了Mali-T860 GPU,所以我们可以利用linux kernelPanfrost驱动 + Userspacemesa来解锁3D图形加速功能。

1.2.1 Panfrost

Panfrost驱动程序栈包括基于MidgardBifrost微架构的ARM Mali GPUOpenGL ES实现,目前支持以下硬件:

Product Architecture OpenGL ES OpenGL
Mali T620 Midgard (v4) 2.0 2.1
Mali T720 Midgard (v4) 2.0 2.1
Mali T760 Midgard (v5) 3.1 3.1
Mali T820 Midgard (v5) 3.1 3.1
Mali T830 Midgard (v5) 3.1 3.1
Mali T860 Midgard (v5) 3.1 3.1
Mali T880 Midgard (v5) 3.1 3.1
Mali G72 Bifrost (v6) 3.1 3.1
Mali G31 Bifrost (v7) 3.1 3.1
Mali G51 Bifrost (v7) 3.1 3.1
Mali G52 Bifrost (v7) 3.1 3.1
Mali G76 Bifrost (v7) 3.1 3.1
Mali G57 Valhall (v9) 3.1 3.1

目前,Panfrost驱动程序还不支持其它基于MidgardBifrost架构的芯片(如T604G71)。

对于基于Utgard架构的旧款Mali芯片(如Mali 400Mali 450),可以在Lima驱动程序中找到支持。Lima驱动程序也可在mesa中使用。

另外,当前版本的Panfrost驱动程序不支持其它图形API(如VulkanOpenCL)。

在支持OpenGL的过程中,Panfrost驱动程序需要实现以下功能:

  • OpenGL指令解析和翻译: Panfrost驱动程序需要解析应用程序发送的OpenGL指令,并将其翻译成适用于 Mali GPU的底层指令,这包括顶点处理、片段处理、纹理映射、着色器处理等;
  • OpenGL状态管理: 驱动程序需要管理OpenGL中的状态机,确保正确地跟踪和应用OpenGL中的状态变化,以便正确地渲染图形;
  • OpenGL内存管理: 驱动程序需要管理GPU内存,确保OpenGL中的图形数据被正确地加载到GPU内存中,并在需要时被释放;
  • OpenGL渲染管线控制: 驱动程序需要控制GPU的渲染管线,确保正确地处理顶点数据、执行着色器程序、进行光栅化等操作;
  • OpenGL版本兼容性: 驱动程序需要确保对OpenGL标准的不同版本提供兼容性支持,以便能够正确地处理来自应用程序的不同版本的OpenGL指令。

注意:以上内容来自https://docs.mesa3d.org/drivers/panfrost.html

1.2.2 mesa

mesa 也称为mesa3Dmesa 3D图形库,是OpenGLVulkan和其他图形API规范的开源实现。 mesa将这些API规范转换为特定于供应商的图形硬件驱动程序。

mesa项目最初是作为OpenGL规范的开源实现而开始。经过多年来发展,具有跨平台支持、高性能、开源和扩展性等特点,并且该项目已经扩展到实现更多的图形API, 包括OpenGL ESOpenCLOpenMAXVDPAUVA-API、VulkanEGL

1.2.3 架构图

总的来说,Panfrost驱动程序通过mesa 3D图形库来实现对OpenGL标准的支持,它需要解析、翻译和执行来自应用程序的OpenGL指令,并管理GPU的状态、内存和渲染管线,以实现对OpenGL的兼容性支持,整体架构图大致如下;

二、图形API

既然上面提到了OpenGL,那么就来简单了解一下计算机图形程序接口,计算机图像程序接口包括OpenGLOpenGLESOpenCLVulkan等。

2.1 OpenGL
2.1.1 OpenGL简介

OpenGL(全写Open Graphics Library)是一套开放的图形编程接口规范。它定义了一系列函数、常量和数据类型,用于渲染2D3D图形,并提供了与图形硬件交互的方法。

OpenGL规范由Khronos Group组织制定和维护,它是跨平台的,可以在不同的操作系统(如windowslinuxmacOS等)和硬件上使用。

通过遵循OpenGL规范,开发人员可以编写跨平台的图形应用程序,而不必关心底层图形硬件的差异。不同的GPU供应商可以实现自己的OpenGL驱动程序来支持该规范,并提供硬件加速的图形渲染功能。开发人员可以使用OpenGL接口调用这些功能,从而实现高性能的图形渲染和可视化效果。

EGL 是一个依赖于平台的API,是OpenGL ES和本地窗口系统之间的一个中间接口层,它主要根据具体系统实现。

2.1.2 OpenGL ES简介

OpenGL ES (OpenGL for Embedded Systems) 是免授权费的,跨平台的,功能完善的2D3D图形应用程序接口API,主要针对多种嵌入式系统专门设计:包括控制台、移动电话、手持设备、家电设备和汽车。它由精心定义的桌面OpenGL子集组成,创造了软件与图形加速间灵活强大的底层交互接

2.1.3 WebGL简介

WebGLWeb Graphics Library)是一种3D绘图协议,这种绘图技术标准允许把JavaScriptOpenGL ES 2.0结合在一起,通过增加OpenGL ES 2.0的一个JavaScript绑定,WebGL可以为HTML5 Canvas提供硬件3D加速渲染,这样Web开发人员就可以借助系统显卡来在浏览器里更流畅地展示3D场景和模型了,还能创建复杂的导航和数据视觉化。显然,WebGL技术标准免去了开发网页专用渲染插件的麻烦,可被用于创建具有复杂3D结构的网站页面,甚至可以用来设计3D网页游戏等等。

WebGL完美地解决了现有的Web交互式三维动画的两个问题:

  • 它通过HTML脚本本身实现Web交互式三维动画的制作,无需任何浏览器插件支持;
  • 它利用底层的图形硬件加速功能进行的图形渲染,是通过统一的、标准的、跨平台的OpenGL接口实现的。

WebGL标准已出现在Mozilla FirefoxApple Safari及开发者预览版Google Chrome等浏览器中,这项技术支持Web开发人员借助系统显示芯片在浏览器中展示各种3D模型和场景,未来有望推出3D网页游戏及复杂3D结构的网站页面。

2.1.4 OpenGL实现

Khronos Group本身并没有实现一套自己的OpenGLKhronos Group是一个由多家硬件和软件公司组成的行业联盟,旨在制定和推动开放的标准和规范。他们负责维护和发展OpenGL规范,但具体的实现是由各个GPU供应商自行开发。

不同的GPU供应商(如NVidiaAMDIntel等)根据OpenGL规范来实现自己的OpenGL驱动程序。这些驱动程序会与具体的硬件架构和操作系统进行交互,以提供对OpenGL功能的支持和硬件加速。因此,每个GPU供应商实现的OpenGL驱动程序可能会有一些差异,但它们都遵循了OpenGL规范,以确保兼容性和可移植性。

以下是一些常见的OpenGL实现:

  • Microsoft Windows上的OpenGL实现:windows操作系统通常使用由各个显卡供应商提供的OpenGL实现。例如,NVIDIA提供了针对其显卡的OpenGL驱动程序,而AMDIntel也提供了相应的驱动程序;
  • macOS上的OpenGL实现:macOS使用苹果自己的OpenGL实现,称为Apple OpenGLmacOS OpenGL。这是基于OpenGL规范的实现,与苹果的硬件和操作系统紧密集成;
  • Linux上的OpenGL实现:Linux上有多个供应商提供的OpenGL实现,包括开源的mesa 3D项目。mesa提供了一个开源的OpenGL实现,可以在许多Linux发行版上使用。此外,显卡供应商如NVIDIAAMDIntel也提供了针对Linux的专有OpenGL驱动程序;
  • 移动平台上的OpenGL ES实现:OpenGL ESOpenGL for Embedded Systems)是针对移动设备和嵌入式系统的精简版OpenGL。针对Android设备,Google提供了OpenGL ES的实现,而对于iOS设备,苹果提供了Metal API,它可以用于绘制2D3D图形。
2.2 OpenCL

OpenCLOpen Computing Language开放计算语言)是一种开放的、免版税的标准,用于超级计算机、云服务器、个人计算机、移动设备和嵌入式平台中各种加速器的跨平台并行编程。

OpenCL是由Khronos Group创建和管理的。OpenCL使应用程序能够使用系统或设备中的并行处理能力,从而使应用程序运行得更快、更流畅。

2.2.1 平台&设备

一个OpenCL平台通常对应一个供应商。它负责为其设备提供OpenCL实现。例如,具有i7-4790 intel cpu的机器将会有一个OpenCL平台,大概命名为intel opencl,该平台将包括两个OpenCL设备:一个是intel cpu本身,另一个是intel hd graphics 4600 GPU。这个intel opencl平台正在为这两个设备提供OpenCL实现,并负责管理它们。

  • OpenCL平台可以有一个或多个设备;
  • 相同的设备可以具有来自不同供应商的一个或多个OpenCL实现。换句话说,OpenCL设备不仅可以属于一个平台。;
  • 该平台的OpenCL版本不一定与设备的OpenCL版本相同;
2.2.2 ICD&ICD Loader

OpenCL Installable Client Driver (ICD),它是针对某个特定设备的专门的OpenCL实现,也就是OpenCL运行时,可以在libIntelOpenCL.solibnvidia-opencl.solibMesaOpenCL.so这样的文件中找到它。

OpenCL 1.2开始,OpenCL提供了一个ICD扩展(cl_khr_icd),它允许不同厂商的多个OpenCL驱动共存于一个主机系统。

OpenCL Installable Client Driver (ICD) Loader是实现OpenCL应用程序与各硬件厂商提供的OpenCL驱动之间隔离的中间库;

  • 它与OpenCL应用程序相关联,并作为ICD的占位符;
  • 应用程序调用ICD加载程序库导出的函数。然而,ICD加载器根据所选的OpenCL平台决定要重定向到哪个ICD
  • ICD加载机制是必需的,因为供应商的OpenCL实现通常只支持该供应商的硬件,但您可能希望在同一个OpenCL应用程序中使用来自不同供应商的多个设备。

OpenCL ICD Loader实现了ICD扩展并提供了所有OpenCL API接口,OpenCL ICD Loader允许应用程序调用clIcdGetPlatformIDsKHR函数已经安装的OpenCL驱动中选择使用一个平台,应用程序的所有OpenCL API请求将被转发到指定的平台。

简单的说,这个Loader Library只是个二传手,它提供了所有OpenCL API的接口,但没有提供实现,所有通过Loader Library调用的OpenCL API请求都会被传递到指定的OpenCL驱动。有了这个中间库,你的项目代码中的OpenCL API请求可以不依赖于任何厂商的OpenCL SDK,可以在没有安装任何OpenCL SDK的环境实现代码编译,你可以以动态库的形式使用它,也可以把这个中间库静态编译到自己的项目代码中,真正的实现OpenCL SDK无关性、设备无关性。

在这里插入图片描述

注意:一台机器可以有几个OpenCL 平台,每个平台都有自己的驱动程序和OpenCL 版本,总是只有一个ICD Loader程序。ICD Loader程充当所有安装的OpenCL平台的主管,并为所有OpenCL调用提供了唯一的入口点。基于平台ID,它将OpenCL主机调用分配到正确的驱动程序。

linux系统,编写OpenCL应用程序需要:

  • OpenCL头文件:CL/cl.h;
  • ICD Loader库文件:libOpenCL.so;
  • ICD定义文件,一般位于/etc/OpenCL/vendors/,在该目录下存放OpenCL实现的厂商特定文件;在这个目录中,通常会有一个或多个.icd文件,用于指定可用的OpenCL平台,这些文件包含OpenCL实现的信息,包括库文件路径;当系统加载OpenCL时,它会检查该目录下的.icd文件,并根据文件中的内容确定可用的OpenCL平台,每个.icd文件通常包含一个供应商库文件的路径;
  • ICD:由设备制造商提供,针对某个特定设备的专门的OpenCL实现;
2.3 VulKan

VulkanKhronos组织制定的下一代开放的图形显示API。是与DirectX12能够匹敌的GPU API标准。Vulkan是基于AMDMantle API演化而来,Vulkan提供了能直接控制和访问底层GPU的显示驱动抽象层。 显示驱动仅仅是对硬件薄薄的封装,这样能够显著提升操作GPU硬件的效率和性能。之前OpenGL的驱动层对开发人员隐藏的非常多细节,如今都暴露出来。Vulkan甚至不包括执行期的错误检查层。驱动层干的事情少了,隐藏的bug也就少了。

Vulkan不再使用OpenGL的状态机设计,内部也不保存全局状态变量。显示资源全然由应用层负责管理。包括内存管理、线程管理、多线程绘制命令产生、渲染队列提交等。应用程序能够充分利用CPU的多核多线程的计算资源,降低CPU等待,降低延迟。 带来的问题是。线程间的同步问题也由应用程序负责,从而对开发人员的要求也更高。

三、配置Panfrost驱动

关于linux 6.3内核的下载和配置、编译参考:Rockchip RK3399 - 移植uboot 2023.04 & linux 6.3

3.1 配置内核
3.1.1 Panfrost GPU驱动

linux内核根目录下执行make menuconfig命令,进入如下配置:

Device Drivers  --->     
    Graphics support  --->  
        <*> Panfrost (DRM support for ARM Mali Midgard/Bifrost GPUs)

默认编译到内核中或者以模块的形式加载都可以。

3.1.2 驱动代码

驱动位于drivers/gpu/drm/panfrost/文件夹下;

root@zhengyang:/work/sambashare/rk3399/linux-6.3# ll drivers/gpu/drm/panfrost/
总用量 1720
drwxrwxr-x  2 root root   4096 Jun  5 20:58 ./
drwxrwxr-x 64 root root  16384 Jun  5 20:22 ../-rw-rw-r--  1 root root    472 Aug  9  2019 Kconfig
-rw-rw-r--  1 root root    225 Aug  9  2019 Makefile-rw-rw-r--  1 root root   5934 Aug  9  2019 panfrost_devfreq.c
-rw-rw-r--  1 root root    441 Aug  9  2019 panfrost_devfreq.h-rw-rw-r--  1 root root   6427 Aug  9  2019 panfrost_device.c
-rw-rw-r--  1 root root   2678 Aug  9  2019 panfrost_device.h-rw-rw-r--  1 root root  11971 Aug  9  2019 panfrost_drv.c-rw-rw-r--  1 root root  11398 Aug  9  2019 panfrost_features.h
-rw-rw-r--  1 root root   2353 Aug  9  2019 panfrost_gem.c
-rw-rw-r--  1 root root    785 Aug  9  2019 panfrost_gem.h-rw-rw-r--  1 root root  10974 Aug  9  2019 panfrost_gpu.c
-rw-rw-r--  1 root root    586 Aug  9  2019 panfrost_gpu.h-rw-rw-r--  1 root root   3944 Aug  9  2019 panfrost_issues.h
-rw-rw-r--  1 root root  13584 Aug  9  2019 panfrost_job.c
-rw-rw-r--  1 root root   1428 Aug  9  2019 panfrost_job.h-rw-rw-r--  1 root root   9752 Aug  9  2019 panfrost_mmu.c
-rw-rw-r--  1 root root    486 Aug  9  2019 panfrost_mmu.h-rw-rw-r--  1 root root  14759 Aug  9  2019 panfrost_regs.h
-rw-rw-r--  1 root root    880 Aug  9  2019 TODO

驱动入口文件在panfrost_drv.c,在该文件我们可以看到支持的GPU型号;

static const struct of_device_id dt_match[] = {
        
        { .compatible = "amlogic,meson-gxm-mali",
          .data = &amlogic_data, },
        { .compatible = "amlogic,meson-g12a-mali",
          .data = &amlogic_data, },
        { .compatible = "arm,mali-t604", .data = &default_data, },
        { .compatible = "arm,mali-t624", .data = &default_data, },
        { .compatible = "arm,mali-t628", .data = &default_data, },
        { .compatible = "arm,mali-t720", .data = &default_data, },
        { .compatible = "arm,mali-t760", .data = &default_data, },
        { .compatible = "arm,mali-t820", .data = &default_data, },
        { .compatible = "arm,mali-t830", .data = &default_data, },
        { .compatible = "arm,mali-t860", .data = &default_data, },
        { .compatible = "arm,mali-t880", .data = &default_data, },
        { .compatible = "arm,mali-bifrost", .data = &default_data, },
        { .compatible = "arm,mali-valhall-jm", .data = &default_data, },
        { .compatible = "mediatek,mt8183-mali", .data = &mediatek_mt8183_data },
        {}
};
MODULE_DEVICE_TABLE(of, dt_match);

static struct platform_driver panfrost_driver = {
        .probe          = panfrost_probe,
        .remove         = panfrost_remove,
        .driver         = {
                .name   = "panfrost",
                .pm     = pm_ptr(&panfrost_pm_ops),
                .of_match_table = dt_match,
        },
};
module_platform_driver(panfrost_driver);

3.2 gpu设备节点

我们可以在arch/arm64/boot/dts/rockchip/rk3399.dtsi文件找到gpu设备节点的定义:

gpu: gpu@ff9a0000 {
        compatible = "rockchip,rk3399-mali", "arm,mali-t860";
        reg = <0x0 0xff9a0000 0x0 0x10000>;
        interrupts = <GIC_SPI 20 IRQ_TYPE_LEVEL_HIGH 0>,
                     <GIC_SPI 21 IRQ_TYPE_LEVEL_HIGH 0>,
                     <GIC_SPI 19 IRQ_TYPE_LEVEL_HIGH 0>;
        interrupt-names = "job", "mmu", "gpu";
        clocks = <&cru ACLK_GPU>;
        #cooling-cells = <2>;
        power-domains = <&power RK3399_PD_GPU>;
        status = "disabled";
};

其中:

  • compatible:说明了设备兼容的驱动名称,即"rockchip,rk3399-mali"和"arm,mali-t860";可以看到arm,mali-t860是和panfrost驱动相匹配的,因此会执行驱动的.probe函数,这里就不深入研究了;
  • reg:指定了寄存器的基地址和大小,即基地址0xff9a0000,大小为0x10000
  • interruptsinterrupt-names:分别指定了该设备所使用的中断号和中断的名称;
  • clocks:指定了使用哪个时钟控制器(CRU)提供GPU时钟;
  • power-domains:用于指定设备所属的电源域,即RK3399_PD_GPU
  • status:设置为"disabled"表示GPU设备当前处于禁用状态,无法使用;
3.2.1 设备节点gpu新增属性

我们需要在arch/arm64/boot/dts/rockchip/rk3399-evb.dts文件中为gpu设备节点新增以下属性;

&gpu {
        mali-supply = <&vdd_gpu>;
        status = "okay";
};

其中:

  • mali-supply:指定了GPU设备使用的电源管脚;

  • status:指定GPU设备的状态(“okay” 表示设备正常工作);

3.2.2 GPU电源接线原理图

我们看一下GPU电源的接线图;

从图中可以看到VDD_GPU是由SYR838PKC输出的,SYR837/SYR838是一款高效率的同步降压DC/DC变换器芯片,内部应该就是通过BUCK降压电路实现的。其主要特点包括:

  • 最大输出电流可达6A
  • 宽输入电压范围:2.6V5.5V
  • 集成主开关和同步开关,具有非常低的导通损耗(即R DS(ON)值很低);
  • 输出电压可以通过I2C接口编程,范围从0.7125V1.5V

SYR837/SYR838具有I2C接口,允许主处理器通过控制输出电压来实现电压缩放(DVS)功能。I2C接口支持最高达3.4MHz的时钟速度,并使用标准的I2C命令。SYR837/SYR838始终作为从设备运行,并通过一个由7位从地址和一个第8位读写标志组成的地址被寻址。SYR837I2C地址在出厂时设置为0x40HSYR838的地址设置为0x41H

通过I2C接口,主处理器可以向SYR837/SYR838发送命令,以控制输出电压大小,实现电压缩放功能,从而适应不同的工作负载和功耗需求。此外,I2C接口还可以实现对芯片的配置、监测和故障诊断等功能,提高了系统的可靠性和灵活性。

I2C接线如下:

SYR838PKC RK3399 描述
SCL I2C_SCL_PMIC(GPIO1_C0/SPI3_TXD/I2C0_SCL) I2C串行时钟线
SDA I2C_SDA_PMIC(GPIO1_B7/SPI3_RXD/I2C0_SDA) I2C串行数据线
VSEL GPU_SLEEP(GPIO1_B6/PWM3B_IR) 电压选择引脚;
低电平时,该芯片将根据VSEL0寄存器的值来设置输出电压VOUT;
高电平时,该芯片将根据VSEL1寄存器的值来设置输出电压VOUT。
VIN VCC3V3_SYS 输入电压
VOUT VDDGPU(GPU_VDD1~20) 输出电压

需要注意的是:以上内容来自SYR838PKC datasheet,更多细节请自己查看手册。

3.2.3 设备节点vdd_gpu

vdd_gpu设备节点描述GPU所需的电源配置信息。具体来说,它描述了一个名为vdd_gpu的稳压管(也就是SYR828PKC芯片),用于为GPU提供电源。

vdd_gpu设备节点节点是i2c0设备节点的子节点,配置如下

vdd_gpu: regulator@41 {
        compatible = "silergy,syr828";
        reg = <0x41>;
        fcs,suspend-voltage-selector = <1>;
        pinctrl-names = "default";
        pinctrl-0 = <&gpu_sleep>;
        regulator-always-on;
        regulator-boot-on;
        regulator-min-microvolt = <712500>;
        regulator-max-microvolt = <1500000>;
        regulator-name = "vdd_gpu";
        regulator-ramp-delay = <1000>;
        vin-supply = <&vcc3v3_sys>;

        regulator-state-mem {
                regulator-off-in-suspend;
        };
};

这个稳压管的配置信息包括:

  • compatible:指定了稳压管使用的驱动程序类型和版本信息;
  • reg:指定了I2C设备的地址;
  • fcs,suspend-voltage-selector :指定了稳压管在睡眠模式下的工作电压;
  • pinctrl-names:设置了引脚的默认状态,引脚配置设置为gpu_sleep
  • pinctrl-0:指定了default状态的对应的引脚配置,即gpu_sleep
  • regulator-always-on:表示稳压管始终处于开启状态;
  • regulator-boot-on:表示稳压管在启动时自动开启;
  • regulator-min-microvolt:指定了稳压管的最小输出电压;
  • regulator-max-microvolt:指定了稳压管的最大输出电压;
  • regulator-name:指定了稳压管在的名称。
  • regulator-ramp-delay:指定了稳压管从关闭到开启时的延迟时间;
  • vin-supply :指定了稳压管的输入电源,VCC3V3_SYS是由电源输入的12V电源经过稳压管NB680GD输出得到的;

既然我们已经看到这里了,不妨继续看一下引脚配置节点gpu_sleep,其定义在pinctrl设备节点下:

pmic {
        cpu_b_sleep: cpu-b-sleep {
                rockchip,pins = <1 RK_PC1 RK_FUNC_GPIO &pcfg_pull_down>;
        };

        gpu_sleep: gpu-sleep {
                rockchip,pins = <1 RK_PB6 RK_FUNC_GPIO &pcfg_pull_down>;
        };

        pmic_int_l: pmic-int-l {
                rockchip,pins = <1 RK_PC5 RK_FUNC_GPIO &pcfg_pull_up>;
        };
};

可以看到这里配置GPIO1_B6引脚功能为GPIO,电气特性为pcfg_pull_down,表示下拉。GPIO1_B6连接的就是SYR838PKCVSEL引脚。

至于设备vcc3v3_sys设备节点,实际上就比较简单了,其它描述了一个名为vcc3v3_sys的稳压管(也就是NB680GD芯片,其输出电压是固定的就是3.3V,因此也没啥好说的);

vcc3v3_sys: vcc3v3-sys {
        compatible = "regulator-fixed";
        regulator-always-on;
        regulator-boot-on;
        regulator-min-microvolt = <3300000>;
        regulator-max-microvolt = <3300000>;
        regulator-name = "vcc3v3_sys";
};

3.3 保存配置

配置完内核之后记得保存配置:

存档:

root@zhengyang:/work/sambashare/rk3399/linux-6.3# mv rk3399_defconfig ./arch/arm64/configs/

重新配置内核:

root@zhengyang:/work/sambashare/rk3399/linux-6.3# make rk3399_defconfig

3.4 编译并烧录
3.4.1 编译内核

linux内核根目录下执行如下命令进行编译内核:

root@zhengyang:/work/sambashare/rk3399/linux-6.3# make -j8

u-boot-2023.04路径下的mkimage工具拷贝过来,然后在命令行使用mkimage工具编译即可:

root@zhengyang:/work/sambashare/rk3399/linux-6.3# cp ../u-boot-2023.04/tools/mkimage ./
root@zhengyang:/work/sambashare/rk3399/linux-6.3# ./mkimage -f kernel.its kernel.itb

需要注意的是这里一定不能指定-E参数,不然uboot在进行kernel镜像hash校验的时候就会失败。

3.4.2 通过tftp烧录内核

给开发板上电,同时连接上网线,进入uboot命令行。我们将内核拷贝到tftp文件目录:

root@zhengyang:/work/sambashare/rk3399/linux-6.3# cp kernel.itb /work/tftpboot/

接着通过uboot命令行将kernel.itb下到内存地址0x10000000处:

=> tftp 0x10000000 kernel.itb

通过mmc write命令将内核镜像烧录到eMMC0x8000个扇区处:

=> mmc erase 0x8000 0xA000
=> mmc write 0x10000000 0x8000 0xA000

3.4.3 启动内核

我们重新启动开发板,如果Panfrost GPU驱动正常加载,我们会看到类似下面的日志:

[    1.605438] panfrost ff9a0000.gpu: clock rate = 500000000
[    1.611515] panfrost ff9a0000.gpu: failed to get regulator: -517
[    1.618246] panfrost ff9a0000.gpu: regulator init failed -517
......
[    4.576304] panfrost ff9a0000.gpu: clock rate = 500000000
[    4.583134] panfrost ff9a0000.gpu: mali-t860 id 0x860 major 0x2 minor 0x0 status 0x0
[    4.591970] panfrost ff9a0000.gpu: features: 00000000,100e77bf, issues: 00000000,24040400
[    4.601269] panfrost ff9a0000.gpu: Features: L2:0x07120206 Shader:0x00000000 Tiler:0x00000809 Mem:0x1 MMU:0x00002830 AS:0xff JS:0x7
[    4.614692] panfrost ff9a0000.gpu: shader_present=0xf l2_present=0x1
[    4.623663] [drm] Initialized panfrost 1.0.0 20180908 for ff9a0000.gpu on minor 1

我们通过cat /proc/interrupts查看的中断资源申请信息:

root@rk3399:~# cat /proc/interrupts
           CPU0       CPU1       CPU2       CPU3       CPU4       CPU5
 18:          0          0          0          0          0          0     GICv3  25 Level     vgic
 20:          0          0          0          0          0          0     GICv3  27 Level     kvm guest vtimer
 23:       7017       6076       5976       5599      11979      19022     GICv3  30 Level     arch_timer
 25:       1788       1798       1450       1230        929        773     GICv3 113 Level     rk_timer
 31:          0          0          0          0          0          0  GICv3-23   0 Level     arm-pmu
 32:          0          0          0          0          0          0  GICv3-23   1 Level     arm-pmu
 33:          1          0          0          0          0          0     GICv3  59 Level     rockchip_usb2phy
 34:          1          0          0          0          0          0     GICv3  63 Level     rockchip_usb2phy
 35:          0          0          0          0          0          0     GICv3  37 Level     ff6d0000.dma-controller
 36:          0          0          0          0          0          0     GICv3  38 Level     ff6d0000.dma-controller
 37:          0          0          0          0          0          0     GICv3  39 Level     ff6e0000.dma-controller
 38:          0          0          0          0          0          0     GICv3  40 Level     ff6e0000.dma-controller
 39:        354          0          0          0          0          0     GICv3 132 Level     ttyS2
 40:          0          0          0          0          0          0     GICv3 147 Level     ff650800.iommu
 41:          0          0          0          0          0          0     GICv3 149 Level     ff660480.iommu
 42:       2452          0          0          0          0          0     GICv3 151 Level     ff8f3f00.iommu, ff8f0000.vop
 43:          0          0          0          0          0          0     GICv3 150 Level     ff903f00.iommu, ff900000.vop
 44:          0          0          0          0          0          0     GICv3  75 Level     ff914000.iommu
 45:          0          0          0          0          0          0     GICv3  76 Level     ff924000.iommu
 46:         43          0          0          0          0          0     GICv3  44 Level     eth0
 47:          2          0          0          0          0          0     GICv3  58 Level     ehci_hcd:usb2
 48:          2          0          0          0          0          0     GICv3  62 Level     ehci_hcd:usb1
 49:         47          0          0          0          0          0     GICv3  64 Level     ohci_hcd:usb4
 50:         33          0          0          0          0          0     GICv3  60 Level     ohci_hcd:usb3
 51:        111          0          0          0          0          0     GICv3  68 Level     ff160000.i2c
 52:        222          0          0          0          0          0     GICv3  89 Level     ff3c0000.i2c
 53:          0          0          0          0          0          0  rockchip_gpio_irq  21 Level     rk808
 63:          0          0          0          0          0          0     GICv3 152 Edge      ff848000.watchdog
 64:       8295          0          0          0          0          0     GICv3  96 Level     dw-mci
 65:      10042          0          0          0          0          0     GICv3  43 Level     mmc0
 66:          1          0          0          0          0          0  rockchip_gpio_irq   4 Edge
 67:          1          0          0          0          0          0     GICv3  55 Level     ff940000.hdmi
 68:         86          0          0          0          0          0     GICv3  51 Level     panfrost-gpu
 69:          0          0          0          0          0          0     GICv3  53 Level     panfrost-mmu
 70:       2106          0          0          0          0          0     GICv3  52 Level     panfrost-job
IPI0:       588        537        590        570        334        427       Rescheduling interrupts
IPI1:      9858      10924      13311      12477      13037      12794       Function call interrupts
IPI2:         0          0          0          0          0          0       CPU stop interrupts
IPI3:         0          0          0          0          0          0       CPU stop (for crash dump) interrupts
IPI4:       737       1128       1132       1122        851        779       Timer broadcast interrupts
IPI5:         2          0          0          0          0          0       IRQ work interrupts
IPI6:         0          0          0          0          0          0       CPU wake-up interrupts

gpujobmmu都是Panfrost GPU驱动注册的中断,都是电平触发类型的中断,高电平触发。左边的数字1032168是当前产生的中断的数量。

四、安装mesa

ARM Mali GPU驱动Usersacpe部分的开源库叫做mesa,安装mesa有两种方式,一种是直接通过apt install安装,还有一种是通过编译源码安装。后者比较繁琐,我们单独一节来介绍。本节我们先介绍apt install安装方式。

4.1 安装依赖

我们首先安装一些常见的工具包:

root@rk3399:~$ sudo apt install cmake git build-essential meson python3-pip

其中:

  • cmake: 用于构建C++项目的跨平台构建工具;
  • git: 版本控制系统,用于管理代码库;
  • meson: 构建系统,用于自动化项目的构建过程;
  • python3-pip: Python包管理器,用于安装和管理Python包。

对于一个包是否已经安装,我们可以通过如下命令来判定,执行类似如下命令从本地仓库中查找指定的包名,支持通配符;

root@rk3399:/# apt list weston
Listing... Done
weston/focal 8.0.0-1 arm64

可以看到本地仓库中有weston,但是并没有安装,如果包名后面带有”[installed]"表示该软件已经安装。

root@rk3399:/# apt list weston
Listing... Done
weston/focal,now 8.0.0-1 arm64 [installed]

4.1.1 安装mesa-utils

首先我们需要先安装mesa-utilsmesa-utils是一个Linux上的实用工具包,用于与mesa图形库(用于支持OpenGL)进行交互和诊断,用于查看图形驱动的信息、测试OpenGL的功能和性能以及检查3D加速是否正常工作;

roott@rk3399:/test# apt install mesa-utils 

以下是mesa-utils的一些常见用途:

  • glxinfo:该工具提供了有关系统上安装的OpenGL实现的详细信息。您可以使用glxinfo命令查看OpenGL 版本、支持的扩展、渲染器信息等。例如,运行 glxinfo | grep "OpenGL version" 可以查看系统上安装的OpenGL版本;
  • glxgears: 这是一个简单的测试工具,用于检测系统对OpenGL的支持情况。它会显示一个旋转的齿轮动画,并报告每秒渲染的帧数;
  • glxheads: 这个工具可以列出当前系统中可用的X11窗口和OpenGL上下文,并提供有关它们的详细信息;

注意:mesa-utils并不是开发mesa应用程序所必需的,而是一个用于调试和测试的辅助工具集。

4.1.2 安装mesa

如果需要开发OpenGL应用程序,需要安装:

root@rk3399:~$ apt install libgl1-mesa-dev libgles2-mesa-dev libegl1-mesa-dev

其中:

  • libgl1-mesa-dev: 用于编译和链接OpenGL应用程序;OpenGL是一套用于渲染2D3D图形的API,它支持广泛的硬件和操作系统平台,是mesa图形库的核心部分;libgl1-mesa-dev 包含了 OpenGL的开发头文件和库,可以在开发环境中使用OpenGL来编写和运行应用程序;
  • libgles2-mesa-dev: 用于编译和链接OpenGL ES 2.0应用程序;penGL ES是面向嵌入式系统和移动设备的精简版OpenGL,它提供了一套用于渲染2D3D图形的APIlibgles2-mesa-dev包含了 GLES2的开发头文件和库,可以在开发环境中使用GLES2来编写和运行应用程序。
  • libegl1-mesa-dev: 用于编译和链接EGL应用程序;EGL是一个用于管理原生窗口系统和图形渲染上下文的接口,它与底层图形系统进行交互,实现了跨平台和设备的图形渲染;libegl1-mesa-dev包含了EGL的开发头文件和库,可以在开发环境中使用EGL来创建和管理窗口系统的集成。
4.1.3 安装opencl

ocl-icd-libopencl1ocl-icd-opencl-devOpenCL ICD Loader的包,用于在Linux系统中加载OpenCL平台。安装命令如下:

root@rk3399:~$ apt install opencl-headers ocl-icd-libopencl1 ocl-icd-opencl-dev

安装mesa clover OpenCL ICD驱动程序(OpenCL开源实现):

root@rk3399:~$ apt install mesa-opencl-icd

我们可以查看/etc/OpenCL/vendors/目录获取当前系统中可用的OpenCL平台;

root@rk3399:~$ ls -l /etc/OpenCL/vendors/
-rw-r--r-- 1 root root 19 Jan 20 19:50 mesa.icd
root@rk3399:~$ cat /etc/OpenCL/vendors/mesa.icd
libMesaOpenCL.so.1

4.1.4 查看头文件和库文件

安装完mesa图像库之后,我们可以在系统找到安装的开发库和头文件:

root@rk3399:/opt# find /usr | grep lib.*GL.*.so  # OpenGL等库
/usr/lib/libreoffice/program/libOGLTranslo.so
/usr/lib/aarch64-linux-gnu/libOpenGL.so.0
/usr/lib/aarch64-linux-gnu/libGLU.so.1.3.1
/usr/lib/aarch64-linux-gnu/libEGL.so
/usr/lib/aarch64-linux-gnu/libEGL.so.1
/usr/lib/aarch64-linux-gnu/libOpenGL.so.0.0.0
/usr/lib/aarch64-linux-gnu/libGLX_mesa.so.0.0.0
/usr/lib/aarch64-linux-gnu/libGL.so
/usr/lib/aarch64-linux-gnu/libGLdispatch.so.0
/usr/lib/aarch64-linux-gnu/libGL.so.1.7.0
/usr/lib/aarch64-linux-gnu/libGLU.so.1
/usr/lib/aarch64-linux-gnu/libGLESv1_CM.so.1
/usr/lib/aarch64-linux-gnu/libGLESv1_CM.so
/usr/lib/aarch64-linux-gnu/libEGL.so.1.1.0
/usr/lib/aarch64-linux-gnu/libGLdispatch.so
/usr/lib/aarch64-linux-gnu/libGLESv2.so.2.1.0
/usr/lib/aarch64-linux-gnu/libGLESv2.so
/usr/lib/aarch64-linux-gnu/libGL.so.1
/usr/lib/aarch64-linux-gnu/libEGL_mesa.so.0.0.0
/usr/lib/aarch64-linux-gnu/libGLX.so
/usr/lib/aarch64-linux-gnu/libOpenGL.so
/usr/lib/aarch64-linux-gnu/libGLX.so.0.0.0
/usr/lib/aarch64-linux-gnu/libGLX_indirect.so.0
/usr/lib/aarch64-linux-gnu/libEGL_mesa.so.0
/usr/lib/aarch64-linux-gnu/libGLdispatch.so.0.0.0
/usr/lib/aarch64-linux-gnu/libGLESv2.so.2
/usr/lib/aarch64-linux-gnu/libGLX.so.0
/usr/lib/aarch64-linux-gnu/libGLX_mesa.so.0
/usr/lib/aarch64-linux-gnu/libGLESv1_CM.so.1.2.0

root@rk3399:/opt# ls -l /usr/lib/aarch64-linux-gnu/dri/  # dri库
-rw-r--r-- 38 root root 23619952 Mar  9  2022 armada-drm_dri.so
-rw-r--r-- 38 root root 23619952 Mar  9  2022 d3d12_dri.so
-rw-r--r-- 38 root root 23619952 Mar  9  2022 etnaviv_dri.so
-rw-r--r-- 38 root root 23619952 Mar  9  2022 exynos_dri.so
-rw-r--r-- 38 root root 23619952 Mar  9  2022 hx8357d_dri.so
-rw-r--r-- 38 root root 23619952 Mar  9  2022 ili9225_dri.so
-rw-r--r-- 38 root root 23619952 Mar  9  2022 ili9341_dri.so
-rw-r--r-- 38 root root 23619952 Mar  9  2022 imx-dcss_dri.so
-rw-r--r-- 38 root root 23619952 Mar  9  2022 imx-drm_dri.so
-rw-r--r-- 38 root root 23619952 Mar  9  2022 ingenic-drm_dri.so
-rw-r--r-- 38 root root 23619952 Mar  9  2022 kgsl_dri.so
-rw-r--r-- 38 root root 23619952 Mar  9  2022 kms_swrast_dri.so
-rw-r--r-- 38 root root 23619952 Mar  9  2022 lima_dri.so
-rw-r--r-- 38 root root 23619952 Mar  9  2022 mali-dp_dri.so
-rw-r--r-- 38 root root 23619952 Mar  9  2022 mcde_dri.so
-rw-r--r-- 38 root root 23619952 Mar  9  2022 mediatek_dri.so
-rw-r--r-- 38 root root 23619952 Mar  9  2022 meson_dri.so
-rw-r--r-- 38 root root 23619952 Mar  9  2022 mi0283qt_dri.so
-rw-r--r-- 38 root root 23619952 Mar  9  2022 msm_dri.so
-rw-r--r-- 38 root root 23619952 Mar  9  2022 mxsfb-drm_dri.so
-rw-r--r-- 38 root root 23619952 Mar  9  2022 nouveau_dri.so
-rw-r--r--  3 root root  5796048 Mar  9  2022 nouveau_vieux_dri.so
-rw-r--r-- 38 root root 23619952 Mar  9  2022 panfrost_dri.so
-rw-r--r-- 38 root root 23619952 Mar  9  2022 pl111_dri.so
-rw-r--r--  3 root root  5796048 Mar  9  2022 r200_dri.so
-rw-r--r-- 38 root root 23619952 Mar  9  2022 r300_dri.so
-rw-r--r-- 38 root root 23619952 Mar  9  2022 r600_dri.so
-rw-r--r--  3 root root  5796048 Mar  9  2022 radeon_dri.so
-rw-r--r-- 38 root root 23619952 Mar  9  2022 radeonsi_dri.so
-rw-r--r-- 38 root root 23619952 Mar  9  2022 repaper_dri.so
-rw-r--r-- 38 root root 23619952 Mar  9  2022 rockchip_dri.so
-rw-r--r-- 38 root root 23619952 Mar  9  2022 st7586_dri.so
-rw-r--r-- 38 root root 23619952 Mar  9  2022 st7735r_dri.so
-rw-r--r-- 38 root root 23619952 Mar  9  2022 stm_dri.so
-rw-r--r-- 38 root root 23619952 Mar  9  2022 sun4i-drm_dri.so
-rw-r--r-- 38 root root 23619952 Mar  9  2022 swrast_dri.so
-rw-r--r-- 38 root root 23619952 Mar  9  2022 tegra_dri.so
-rw-r--r-- 38 root root 23619952 Mar  9  2022 v3d_dri.so
-rw-r--r-- 38 root root 23619952 Mar  9  2022 vc4_dri.so
-rw-r--r-- 38 root root 23619952 Mar  9  2022 virtio_gpu_dri.so
-rw-r--r-- 38 root root 23619952 Mar  9  2022 zink_dri.so

root@rk3399:/opt/mesa-22.0.0# ls -l /usr/lib/aarch64-linux-gnu/*OpenCL* # OpenCL库
#ocl-icd-opencl-dev包安装
lrwxrwxrwx 1 root root      18 Apr  5  2017 /usr/lib/aarch64-linux-gnu/libOpenCL.so -> libOpenCL.so.1.0.0
#ocl-icd-libopencl1包安装
lrwxrwxrwx 1 root root      18 Apr  5  2017 /usr/lib/aarch64-linux-gnu/libOpenCL.so.1 -> libOpenCL.so.1.0.0
-rw-r--r-- 1 root root   34808 Apr  5  2017 /usr/lib/aarch64-linux-gnu/libOpenCL.so.1.0.0
#mesa-opencl-icd包安装
lrwxrwxrwx 1 root root      18 Mar  9  2022 /usr/lib/aarch64-linux-gnu/libMesaOpenCL.so -> libMesaOpenCL.so.1
lrwxrwxrwx 1 root root      22 Mar  9  2022 /usr/lib/aarch64-linux-gnu/libMesaOpenCL.so.1 -> libMesaOpenCL.so.1.0.0
-rw-r--r-- 1 root root 1372512 Mar  9  2022 /usr/lib/aarch64-linux-gnu/libMesaOpenCL.so.1.0.0

root@rk3399:/opt# ls  /usr/include | grep GL
EGL GL GLES GLES2 GLES3

root@rk3399:/opt# ls -l /usr/include/EGL/
-rw-r--r-- 1 root root 20345 Jun 26  2020 egl.h
-rw-r--r-- 1 root root 68048 Jun 26  2020 eglext.h
-rw-r--r-- 1 root root  3192 Nov 25  2021 eglextchromium.h
-rw-r--r-- 1 root root  2129 Nov 25  2021 eglmesaext.h
-rw-r--r-- 1 root root  6049 Jun 26  2020 eglplatform.h

root@rk3399:/opt# ls -l /usr/include/GL
-rw-r--r-- 1 root root  80393 Jun 26  2020 gl.h
-rw-r--r-- 1 root root 421339 Jun 26  2020 glcorearb.h
-rw-r--r-- 1 root root 848032 Jun 26  2020 glext.h
-rw-r--r-- 1 root root  16906 Jun 26  2020 glx.h
-rw-r--r-- 1 root root  48370 Jun 26  2020 glxext.h
-rw-r--r-- 1 root root   4695 Mar  9  2020 glxint.h
-rw-r--r-- 1 root root   2085 Mar  9  2020 glxmd.h
-rw-r--r-- 1 root root  78531 Mar  9  2020 glxproto.h
-rw-r--r-- 1 root root  11429 Mar  9  2020 glxtokens.h
drwxr-xr-x 2 root root   4096 Nov 13 13:22 

root@rk3399:/opt# ls -l /usr/include/GLES
-rw-r--r-- 1 root root   922 Jun 26  2020 egl.h
-rw-r--r-- 1 root root 31669 Jun 26  2020 gl.h
-rw-r--r-- 1 root root 53780 Jun 26  2020 glext.h
-rw-r--r-- 1 root root  1152 Jun 26  2020 glplatform.h

root@rk3399:/opt# ls -l /usr/include/GLES2
-rw-r--r-- 1 root root  43996 Jun 26  2020 gl2.h
-rw-r--r-- 1 root root 231362 Jun 26  2020 gl2ext.h
-rw-r--r-- 1 root root   1160 Jun 26  2020 gl2platform.h

root@rk3399:/opt# ls -l /usr/include/GLES3
-rw-r--r-- 1 root root  82674 Jun 26  2020 gl3.h
-rw-r--r-- 1 root root 107463 Jun 26  2020 gl31.h
-rw-r--r-- 1 root root 128343 Jun 26  2020 gl32.h
-rw-r--r-- 1 root root    166 Jun 26  2020 gl3ext.h
-rw-r--r-- 1 root root   1160 Jun 26  2020 gl3platform.h

4.2 测试GPU
4.2.1 glxinfo

进入桌面后,打开一个终端,使用glxinfo -B命令查看GPU驱动,可以看到驱动为Mali T860 (Panfrost)OpenGL version string: 3.1 mesa 21.2.6

roott@rk3399:/test#  export DISPLAY=:0.0; glxinfo -B
name of display: :0.0
display: :0  screen: 0
direct rendering: Yes
Extended renderer info (GLX_MESA_query_renderer):
    Vendor: Panfrost (0xffffffff)
    Device: Mali T860 (Panfrost) (0xffffffff)
    Version: 21.2.6
    Accelerated: yes
    Video memory: 3874MB
    Unified memory: yes
    Preferred profile: core (0x1)
    Max core profile version: 3.1
    Max compat profile version: 3.1
    Max GLES1 profile version: 1.1
    Max GLES[23] profile version: 3.1
OpenGL vendor string: Panfrost
OpenGL renderer string: Mali T860 (Panfrost)
OpenGL core profile version string: 3.1 mesa 21.2.6
OpenGL core profile shading language version string: 1.40
OpenGL core profile context flags: (none)

OpenGL version string: 3.1 mesa 21.2.6
OpenGL shading language version string: 1.40
OpenGL context flags: (none)

OpenGL ES profile version string: OpenGL ES 3.1 mesa 21.2.6
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.10

前面有讲到,GPU驱动分两部分,一部分在内核中,我们已经启动了,另外还有一个重要的部分在userspace中,对于Panfrost GPU驱动来说,它叫做mesa

mesa中实现了Panfrost GPU驱动的userspace部分,它向下操作内核中的GPU驱动,相上提供标准的OpenGL接口供各种绘图应用使用。

我们在输出的信息中可以看到如下信息,这说明mesa也已经安装了,版本号也是大于19.2的。

OpenGL version string: 3.1 mesa 21.2.6

4.2.2 screenfetch

使用screenfetch命令也可以看到GPU驱动使用的是Mali T860 (Panfrost)

root@rk3399:/test# sudo apt install screenfetch
root@rk3399:/test# screenfetch
Failed to init libxfconf: The connection is closed.
Failed to init libxfconf: The connection is closed.
                          ./+o+-       zhengyang@rk3399
                  yyyyy- -yyyyyy+      OS: Ubuntu 20.04 focal
               ://+//-yyyyyyo      Kernel: aarch64 Linux 5.2.8
           .++ .:/++++++/-.+sss/`      Uptime: 18m
         .:++o:  /++++++++/:--:/-      Packages: 1815
        o:+o+:++.`..```.-/oo+++++/     Shell: bash 5.0.17
       .:+o:+o/.          `+sssoo+/    Resolution: 1920x1080
  .++/+:+oo+o:`             /sssooo.   DE: Xfce
 /+++//+:`oo+o               /::--:.   WM: Xfwm4
 +/+o+++`o++o               ++.   WM Theme:
  .++.o+++oo+:`             /dddhhh.   Font: Not Identified
       .+.o+oo:.          `oddhhhh+    Disk: 6.6G / 17G (42%)
        +.++o+o``-````.:ohdhhhhh+     CPU: 6x Unknown
         `:o+++ `ohhhhhhhhyo++os:      GPU: Mali T860 (Panfrost)
           .o:`.syhhhhhhh/.oo++o`      RAM: 971MiB / 3874MiB
               /osyyyyyyo++ooo+++/
                   `````+oo+++o:
                          `oo++.

4.2.3 GPU工作情况

其实到这里,因为GPU就已经真正的使用起来,通过以下方法可以快速判断GPU有没有在工作:

  • cat /proc/interrupts查看jpujob产生的中断数量,如果GPU在工作,会频繁产生中断;
  • 运行top命令,观察cpu利用率,如果GPU没工作,所有的图像渲染靠CPUCPU占用率会高;

再次在firefox浏览器打开视频测试,测试发现虽然GPU已经工作,频繁产生中断但是CPU的利用率还是很高。

后来查阅资料判定可能是以下原因:firefox浏览器并没有开启GPU加速。

4.2.4 glmark2测试

Glmark2是一款比较出名的GPU benchmark测试程序,支持OpenGL 2.0OpenGL ES 2.0。在ubuntu系统上可以直接通过apt install命令安装,在debian系统上需要通过源码编译:

root@rk3399:~# sudo apt-get install glmark2

在桌面环境终端运行glmark2命令即可进行测试;

root@rk3399:/test# glmark2
=======================================================
    glmark2 2021.02
=======================================================
    OpenGL Information
    GL_VENDOR:     Panfrost
    GL_RENDERER:   Mali T860 (Panfrost)
    GL_VERSION:    3.1 mesa 21.2.6
=======================================================
[build] use-vbo=false: FPS: 557 FrameTime: 1.795 ms
[build] use-vbo=true: FPS: 612 FrameTime: 1.634 ms
[texture] texture-filter=nearest: FPS: 674 FrameTime: 1.484 ms
[texture] texture-filter=linear: FPS: 677 FrameTime: 1.477 ms
[texture] texture-filter=mipmap: FPS: 672 FrameTime: 1.488 ms
[shading] shading=gouraud: FPS: 518 FrameTime: 1.931 ms
[shading] shading=blinn-phong-inf: FPS: 511 FrameTime: 1.957 ms
[shading] shading=phong: FPS: 457 FrameTime: 2.188 ms
[shading] shading=cel: FPS: 457 FrameTime: 2.188 ms
[bump] bump-render=high-poly: FPS: 283 FrameTime: 3.534 ms
[bump] bump-render=normals: FPS: 652 FrameTime: 1.534 ms
[bump] bump-render=height: FPS: 634 FrameTime: 1.577 ms
[effect2d] kernel=0,1,0;1,-4,1;0,1,0;: FPS: 419 FrameTime: 2.387 ms
[effect2d] kernel=1,1,1,1,1;1,1,1,1,1;1,1,1,1,1;: FPS: 196 FrameTime: 5.102 ms
[pulsar] light=false:quads=5:texture=false: FPS: 677 FrameTime: 1.477 ms
[desktop] blur-radius=5:effect=blur:passes=1:separable=true:windows=4: FPS: 146 FrameTime: 6.849 ms
[desktop] effect=shadow:windows=4: FPS: 556 FrameTime: 1.799 ms
[buffer] columns=200:interleave=false:update-dispersion=0.9:update-fraction=0.5:update-method=map: FPS: 122 FrameTime: 8.197 ms
[buffer] columns=200:interleave=false:update-dispersion=0.9:update-fraction=0.5:update-method=subdata: FPS: 23 FrameTime: 43.478 ms
[buffer] columns=200:interleave=true:update-dispersion=0.9:update-fraction=0.5:update-method=map: FPS: 159 FrameTime: 6.289 ms
[ideas] speed=duration: FPS: 356 FrameTime: 2.809 ms
[jellyfish] <default>: FPS: 307 FrameTime: 3.257 ms
[terrain] <default>: FPS: 19 FrameTime: 52.632 ms
[shadow] <default>: FPS: 298 FrameTime: 3.356 ms
[refract] <default>: FPS: 62 FrameTime: 16.129 ms
[conditionals] fragment-steps=0:vertex-steps=0: FPS: 591 FrameTime: 1.692 ms
[conditionals] fragment-steps=5:vertex-steps=0: FPS: 419 FrameTime: 2.387 ms
[conditionals] fragment-steps=0:vertex-steps=5: FPS: 611 FrameTime: 1.637 ms
[function] fragment-complexity=low:fragment-steps=5: FPS: 492 FrameTime: 2.033 ms
[function] fragment-complexity=medium:fragment-steps=5: FPS: 368 FrameTime: 2.717 ms
[loop] fragment-loop=false:fragment-steps=5:vertex-steps=5: FPS: 490 FrameTime: 2.041 ms
[loop] fragment-steps=5:fragment-uniform=false:vertex-steps=5: FPS: 491 FrameTime: 2.037 ms
[loop] fragment-steps=5:fragment-uniform=true:vertex-steps=5: FPS: 399 FrameTime: 2.506 ms
=======================================================
                                  glmark2 Score: 421
=======================================================

glmark2的测试并不依赖于第三节安装的那些包,即便不安装也可以正常测试。

4.2.5 clinfo

clinfo是一个用于显示OpenCL平台和设备信息的实用程序。

通过clinfo命令可以查看安装的mesa clover OpenCL驱动程序的版本信息;

root@rk3399:/opt# apt install clinfo
root@rk3399:/opt/mesa-22.0.0# clinfo
Number of platforms                               1
  Platform Name                                   Clover
  Platform Vendor                                 Mesa
  Platform Version                                OpenCL 1.1 Mesa 21.2.6
  Platform Profile                                FULL_PROFILE
  Platform Extensions                             cl_khr_icd
  Platform Extensions function suffix             MESA

  Platform Name                                   Clover
Number of devices                                 0

NULL platform behavior
  clGetPlatformInfo(NULL, CL_PLATFORM_NAME, ...)  Clover
  clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, ...)
  clCreateContext(NULL, ...) [default]            No devices found in platform
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_DEFAULT)  No devices found in platform
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_CPU)  No devices found in platform
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_GPU)  No devices found in platform
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_ACCELERATOR)  No devices found in platform
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_CUSTOM)  No devices found in platform
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_ALL)  No devices found in platform

ICD loader properties
  ICD loader Name                                 OpenCL ICD Loader
  ICD loader Vendor                               OCL Icd free software
  ICD loader Version                              2.2.11
  ICD loader Profile                              OpenCL 2.1                          0

可以看出系统中安装了mesa clover OpenCL ICD驱动程序,但没有找到任何可用的设备,估计是mesa clover平台并不支持ARM Mali T860 GPU设备。

4.3 Chromium开启GPU
4.3.1 安装Chromium

运行以下命令以安装Chromium浏览器:

root@rk3399:/opt# sudo apt-get install dialog
root@rk3399:/opt# sudo apt install chromium-browser

这样,您就成功在ubuntu 20.04上安装了Chromium浏览器。可以在应用程序菜单中搜索并启动Chromium浏览器,或者在终端中运行chromium-browser命令来启动它。

root@rk3399:/opt# export DISPLAY=:0.0; chromium-browser --no-sandbox --user-data-dir

4.3.2 GPU支持情况

安装的Chromium浏览器默认启用硬件加速,支持WebGL,可以通过 输入网址chrome://gpu了解硬件加速情况,如下图所示:

硬件加速:

  • WebGL:Hardware accelerated
  • WebGL2:Hardware accelerated
4.3.3 查看CPU利用率

Chromium浏览器打开视频,再次查看CPU利用率;

可以看到CPU利用率已经从之前的70%+降低到40%+

五、编译安装mesa

接下来我们介绍一下mesa的编译安装流程,如果不感兴趣忽略即可。

如果想在开发板上进行编译安装,必须首先安装linux-headers,具体参考:《Rockchip RK3399 - 移植uboot 2017.09 & linux 4.19(友善之家脚本方式)》。

编译内核头文件章节:

root@zhengyang:/work/sambashare/rk3399/linux-6.3# make -j8 bindeb-pkgmkae bindeb-pkg

make bindeb-pkg是一个用于构建debian包的命令,它通常用于编译linux内核并生成对应的debian软件包。

当执行make bindeb-pkg 命令时,它会读取当前目录下的linux内核源代码,并根据配置文件进行内核编译。

编译过程将包括编译内核、生成模块、创建initramfs等步骤。最后,它将生成一组二进制文件和相关的debian控制文件,用于创建 debian包。

linux 6.3执行完成会在内核源码debian目录生成以下文件;

root@zhengyang:/work/sambashare/rk3399/linux-6.3# ll debian/
-rw-r--r--  1 root root    6 Sep 23 20:58 arch
-rw-r--r--  1 root root  136 Sep 23 20:58 changelog
-rw-r--r--  1 root root 1239 Sep 23 20:58 control
-rw-r--r--  1 root root  691 Sep 23 20:58 copyright
-rw-r--r--  1 root root  264 Sep 23 21:05 files
drwxr-xr-x  5 root root 4096 Sep 23 21:05 linux-headers/
drwxr-xr-x  7 root root 4096 Sep 23 21:04 linux-image/
drwxr-xr-x  4 root root 4096 Sep 23 21:05 linux-image-dbg/
drwxr-xr-x  4 root root 4096 Sep 23 21:05 linux-libc-dev/
-rwxr-xr-x  1 root root  486 Sep 23 20:58 rules*

同时会在内核上一级目录下生成如下deb包:

  • linux-image-<version>.deb:内核镜像文件,用于安装和引导新的内核;
  • linux-headers-<version>.deb:内核头文件,用于开发其他软件或编译内核模块;
  • linux-libc-dev_<version>.deb:用于构建用户空间软件的头文件和静态库;

这些生成的debian包可以在 debian或基于debian的系统上安装和使用。

将我们编译的头文件拷贝到开发板/opt目录下;

root@rk3399:~# cd /opt
root@rk3399:/opt# scp [email protected]:/work/sambashare/rk3399/linux-headers-6.3.0.deb /opt/
root@rk3399:/opt# sudo dpkg -i /opt/linux-headers-*.deb

安装完成后,我们可以看一下/usr/src目录下是否创建了linux-headers-$(uname-r)文件;

root@rk3399:/opt$ ll /usr/src/
drwxr-xr-x 5 root root 4096 Nov 13 00:35 linux-headers-6.3.0
root@rk3399:/opt# ll /usr/src/linux-headers-6.3.0/
total 1400
drwxr-xr-x  5 root root    4096 Nov 13 00:35 ./
drwxr-xr-x  3 root root    4096 Nov 13 00:35 ../
-rw-r--r--  1 root root  264166 Sep 23 20:58 .config
-rw-r--r--  1 root root   71751 Jun 12  2023 Makefile
-rw-r--r--  1 root root 1064676 Sep 23 20:58 Module.symvers
drwxr-xr-x  3 root root    4096 Nov 13 00:35 arch/
drwxr-xr-x 33 root root    4096 Nov 13 00:35 include/
drwxr-xr-x 17 root root   12288 Nov 13 00:35 scripts/

5.2 下载mesa
root@rk3399:/opt# wget https://archive.mesa3d.org/mesa-22.0.0.tar.xz
root@rk3399:/opt# tar -xvf mesa-22.0.0.tar.xz
root@rk3399:/opt# cd mesa-22.0.0

5.2.1 升级meson
root@rk3399:/opt# sudo apt install python3-pip
root@rk3399:/opt# pip3 install meson==0.63
root@rk3399:/opt/mesa-22.0.0# cp /usr/local/bin/meson /usr/bin/

备注:ubuntu 20.04上 使用apt默认安装的版本可能是0.53.2,而meson编译,需要更高的 meson 版本, 大于0.60

5.2.2 升级cmake
root@rk3399:/opt# sudo apt remove cmake   # 移除低版本cmake 3.16.3
root@rk3399:/opt# wget https://521github.com/extdomains/github.com/Kitware/CMake/releases/download/v3.28.0/cmake-3.28.0-linux-aarch64.tar.gz
root@rk3399:/opt# tar -xzvf cmake-3.28.0-linux-aarch64.tar.gz
root@rk3399:/opt# mv cmake-3.28.0-linux-aarch64 cmake-3.28.0
root@rk3399:/opt# ln -sf /opt/cmake-3.28.0/bin/* /usr/bin/
root@rk3399:/opt# cmake --version
cmake version 3.28.0

CMake suite maintained and supported by Kitware (kitware.com/cmake).
root@rk3399:/opt# vim /etc/profile
export  PATH=$PATH:/opt/cmake-3.28.0/bin
root@rk3399:/opt# source /etc/profile

5.3 安装依赖
5.3.1 安装glslang

安装glslang

root@rk3399:/opt# wget https://521github.com/extdomains/github.com/KhronosGroup/glslang/archive/refs/tags/14.0.0.tar.gz
root@rk3399:/opt# tar -xvf 14.0.0.tar.gz
root@rk3399:/opt# cd glslang-14.0.0

root@rk3399:/opt/glslang-14.0.0# ./update_glslang_sources.py  # 如果下载慢,github修改镜像
root@rk3399:/opt/glslang-14.0.0# cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$(pwd)/install" .
root@rk3399:/opt/glslang-14.0.0# make -j4 install

root@rk3399:/opt/glslang-14.0.0# mv install/bin/* /usr/local/bin/
root@rk3399:/opt/glslang-14.0.0# mv install/lib/* /usr/local/lib/
root@rk3399:/opt/glslang-14.0.0# mv install/include/* /usr/local/include/
root@rk3399:/opt/glslang-14.0.0# cd ..
root@rk3399:/opt# rm -rf glslang-14.0.0*

5.3.2 安装libdrm

下载源码:

root@rk3399:/opt# get https://dri.freedesktop.org/libdrm/libdrm-2.4.118.tar.xz
root@rk3399:/opt# tar -xvf libdrm-2.4.118.tar.xz
root@rk3399:/opt# mv libdrm-2.4.118 drm

在编译和安装libdrm之前,你需要先安装一些依赖项:

root@rk3399:/opt# apt install autoconf libtool pkg-config libpciaccess-dev

编译和安装:

root@rk3399:/opt# cd drm
root@rk3399:/opt/drm# meson build
root@rk3399:/opt/drm# ninja -C build
root@rk3399:/opt/drm# ninja -C build install
ninja: Entering directory `build'
[0/1] Installing files.
Installing libdrm.so.2.4.0 to /usr/local/lib/aarch64-linux-gnu
Installing nouveau/libdrm_nouveau.so.2.0.0 to /usr/local/lib/aarch64-linux-gnu
Installing radeon/libdrm_radeon.so.1.0.1 to /usr/local/lib/aarch64-linux-gnu
Installing amdgpu/libdrm_amdgpu.so.1.0.0 to /usr/local/lib/aarch64-linux-gnu
Installing freedreno/libdrm_freedreno.so.1.0.0 to /usr/local/lib/aarch64-linux-gnu
Installing etnaviv/libdrm_etnaviv.so.1.0.0 to /usr/local/lib/aarch64-linux-gnu
Installing /opt/drm/libsync.h to /usr/local/include
Installing /opt/drm/xf86drm.h to /usr/local/include
Installing /opt/drm/xf86drmMode.h to /usr/local/include
Installing /opt/drm/include/drm/drm.h to /usr/local/include/libdrm
Installing /opt/drm/include/drm/drm_fourcc.h to /usr/local/include/libdrm
Installing /opt/drm/include/drm/drm_mode.h to /usr/local/include/libdrm
Installing /opt/drm/include/drm/drm_sarea.h to /usr/local/include/libdrm
Installing /opt/drm/include/drm/i915_drm.h to /usr/local/include/libdrm
Installing /opt/drm/include/drm/mach64_drm.h to /usr/local/include/libdrm
Installing /opt/drm/include/drm/mga_drm.h to /usr/local/include/libdrm
Installing /opt/drm/include/drm/msm_drm.h to /usr/local/include/libdrm
Installing /opt/drm/include/drm/nouveau_drm.h to /usr/local/include/libdrm
Installing /opt/drm/include/drm/qxl_drm.h to /usr/local/include/libdrm
Installing /opt/drm/include/drm/r128_drm.h to /usr/local/include/libdrm
......
root@rk3399:/opt/drm# cd ..
root@rk3399:/opt# rm -rf libdrm-2.4.118.tar.xz
root@rk3399:/opt# rm -rf drm

头文件安装到/usr/local/include/libdrm,库文件安装到/usr/local/lib/aarch64-linux-gnu,这里不要去改动默认路径;可以使用ldconfig -p | grep libdrm命令来查看系统中是否存在正确的libdrm库;

root@rk3399:/opt/mesa-22.0.0
        libdrm_tegra.so.0 (libc6,AArch64) => /lib/aarch64-linux-gnu/libdrm_tegra.so.0
        libdrm_tegra.so (libc6,AArch64) => /lib/aarch64-linux-gnu/libdrm_tegra.so
        libdrm_radeon.so.1 (libc6,AArch64) => /usr/local/lib/aarch64-linux-gnu/libdrm_radeon.so.1
        libdrm_radeon.so.1 (libc6,AArch64) => /lib/aarch64-linux-gnu/libdrm_radeon.so.1
        libdrm_radeon.so (libc6,AArch64) => /usr/local/lib/aarch64-linux-gnu/libdrm_radeon.so
        libdrm_radeon.so (libc6,AArch64) => /lib/aarch64-linux-gnu/libdrm_radeon.so
        libdrm_nouveau.so.2 (libc6,AArch64) => /usr/local/lib/aarch64-linux-gnu/libdrm_nouveau.so.2
        libdrm_nouveau.so.2 (libc6,AArch64) => /lib/aarch64-linux-gnu/libdrm_nouveau.so.2
        libdrm_nouveau.so (libc6,AArch64) => /usr/local/lib/aarch64-linux-gnu/libdrm_nouveau.so
        libdrm_nouveau.so (libc6,AArch64) => /lib/aarch64-linux-gnu/libdrm_nouveau.so
        libdrm_freedreno.so.1 (libc6,AArch64) => /usr/local/lib/aarch64-linux-gnu/libdrm_freedreno.so.1
        libdrm_freedreno.so.1 (libc6,AArch64) => /lib/aarch64-linux-gnu/libdrm_freedreno.so.1
        libdrm_freedreno.so (libc6,AArch64) => /usr/local/lib/aarch64-linux-gnu/libdrm_freedreno.so
        libdrm_freedreno.so (libc6,AArch64) => /lib/aarch64-linux-gnu/libdrm_freedreno.so
        libdrm_etnaviv.so.1 (libc6,AArch64) => /lib/aarch64-linux-gnu/libdrm_etnaviv.so.1
        libdrm_etnaviv.so (libc6,AArch64) => /lib/aarch64-linux-gnu/libdrm_etnaviv.so
        libdrm_amdgpu.so.1 (libc6,AArch64) => /usr/local/lib/aarch64-linux-gnu/libdrm_amdgpu.so.1
        libdrm_amdgpu.so.1 (libc6,AArch64) => /lib/aarch64-linux-gnu/libdrm_amdgpu.so.1
        libdrm_amdgpu.so (libc6,AArch64) => /usr/local/lib/aarch64-linux-gnu/libdrm_amdgpu.so
        libdrm_amdgpu.so (libc6,AArch64) => /lib/aarch64-linux-gnu/libdrm_amdgpu.so
        libdrm.so.2 (libc6,AArch64) => /usr/local/lib/aarch64-linux-gnu/libdrm.so.2
        libdrm.so.2 (libc6,AArch64) => /lib/aarch64-linux-gnu/libdrm.so.2
        libdrm.so (libc6,AArch64) => /usr/local/lib/aarch64-linux-gnu/libdrm.so
        libdrm.so (libc6,AArch64) => /lib/aarch64-linux-gnu/libdrm.so

5.3.3 安装llvm
root@rk3399:/opt# apt install llvm-11 clang-11
root@rk3399:/opt# cd /usr/bin
root@rk3399:/usr/bin# rm -rf /usr/bin/llvm-config
root@rk3399:/usr/bin# ln -s ../lib/llvm-11/bin/llvm-config /usr/bin/llvm-config
root@rk3399:/usr/bin# ls -l /usr/bin/llvm-config*
lrwxrwxrwx 1 root root 30 Jan 20 17:24 /usr/bin/llvm-config -> ../lib/llvm-11/bin/llvm-config
lrwxrwxrwx 1 root root 30 Apr 20  2020 /usr/bin/llvm-config-10 -> ../lib/llvm-10/bin/llvm-config
lrwxrwxrwx 1 root root 30 Oct 30  2020 /usr/bin/llvm-config-11 -> ../lib/llvm-11/bin/llvm-config
lrwxrwxrwx 1 root root 29 Mar 19  2020 /usr/bin/llvm-config-8 -> ../lib/llvm-8/bin/llvm-config
root@rk3399:/usr/bin# llvm-config --version
11.0.0
root@rk3399:/usr/bin# llvm-config --libdir
/usr/lib/llvm-11/lib

5.3.4 安装其它依赖
root@rk3399:/opt# apt install flex bison python3-mako libwayland-egl-backend-dev libxcb-dri3-dev libxcb-dri2-0-dev libxcb-glx0-dev ibxcb-shm0-dev libx11-xcb-dev libxcb-present-dev libxcb-sync-dev libxxf86vm-dev libxshmfence-dev libxrandr-dev libwayland-dev libxdamage-dev libxext-dev libxfixes-dev x11proto-dri2-dev x11proto-dri3-dev x11proto-present-dev x11proto-gl-dev x11proto-xf86vidmode-dev libexpat1-dev libudev-dev gettext xutils-dev libpthread-stubs0-dev bc valgrind llvm llvm-8-dev  zlib1g-dev wayland-protocols libelf-dev

5.4 编译mesa

编译mesa流程来自官网:Compilation and Installation Using Meson

5.4.1 配置

执行如下命令在builddir目录中进行meson初始化和配置。它将读取项目源代码,并生成构建文件;

root@rk3399:/opt/mesa-22.0.0# meson -Dplatforms=x11 -Dvulkan-drivers=panfrost -Dgallium-drivers=panfrost -Dgallium-opencl=icd -Dlibunwind=disabled -Dprefix=/opt/mesa builddir/
The Meson build system
Version: 0.63.0
Source dir: /opt/mesa-22.0.0
Build dir: /opt/mesa-22.0.0/builddir
Build type: native build
Program python3 found: YES (/usr/bin/python3)
Project name: mesa
Project version: 22.0.0
......
Message: Configuration summary:

        prefix:          /opt/mesa
        libdir:          lib/aarch64-linux-gnu
        includedir:      include

        OpenGL:          yes (ES1: yes ES2: yes)
        OSMesa:          no

        DRI platform:    drm
        DRI drivers:     no
        DRI driver dir:  /opt/mesa/lib/aarch64-linux-gnu/dri

        GLX:             DRI-based

        EGL:             yes
        EGL drivers:     builtin:egl_dri2 builtin:egl_dri3
        EGL/Vulkan/VL platforms:   x11 surfaceless drm xcb
        GBM:             yes
        GBM backends path: /opt/mesa/lib/aarch64-linux-gnu/gbm

        Vulkan drivers:  panfrost
        Vulkan ICD dir:  share/vulkan/icd.d

        llvm:            yes
        llvm-version:    11.0.0

        Gallium drivers: panfrost
        Gallium st:      mesa clover
        HUD lmsensors:   no

        Shared-glapi:    yes

        Perfetto:        no
        Perfetto ds:     auto

Build targets in project: 178
NOTICE: Future-deprecated features used:
 * 0.55.0: {'ExternalProgram.path'}
 * 0.56.0: {'meson.source_root'}

mesa 22.0.0

  User defined options
    prefix         : /opt/mesa
    gallium-drivers: panfrost
    gallium-opencl : icd
    libunwind      : disabled
    platforms      : x11
    vulkan-drivers : panfrost

其中:

  • -Dplatforms=x11:设置要支持的窗口系统为x11
  • -Dvulkan-drivers=panfrost 指定要构建的Vulkan驱动程序列表;
  • -Dgallium-drivers=panfrost:指定要构建的gallium驱动程序列表;
  • -Dgallium-opencl=icdbuild gallium "clover" OpenCL frontend
  • -Dlibunwind=false:禁用libunwind来获取堆栈跟踪信息;
  • -Dprefix=/opt/mesa:指定安装目录;如果不指定,默认安装到/usr

更多配置选项可以参考当前目录下meson_options.txt文件,或者通过meson configure builddir/查看选项配置值;

5.4.2 编译

编译项目:

root@rk3399:/opt/mesa-22.0.0# ninja -C builddir/ -j6

5.4.3 安装到/opt/mesa

最后一步进行安装:

root@rk3399:/opt/mesa-22.0.0# ninja -C builddir/ install
ninja: Entering directory `builddir/'
[1/2] Installing files.
Installing src/mapi/shared-glapi/libglapi.so.0.0.0 to /opt/mesa/lib/aarch64-linux-gnu
Installing src/mapi/es1api/libGLESv1_CM.so.1.1.0 to /opt/mesa/lib/aarch64-linux-gnu
Installing src/mapi/es2api/libGLESv2.so.2.0.0 to /opt/mesa/lib/aarch64-linux-gnu
Installing src/panfrost/vulkan/libvulkan_panfrost.so to /opt/mesa/lib/aarch64-linux-gnu
Installing src/panfrost/vulkan/panfrost_icd.aarch64.json to /opt/mesa/share/vulkan/icd.d
Installing src/gbm/libgbm.so.1.0.0 to /opt/mesa/lib/aarch64-linux-gnu
Installing src/gallium/targets/pipe-loader/pipe_kmsro.so to /opt/mesa/lib/aarch64-linux-gnu/gallium-pipe
Installing src/gallium/targets/opencl/libMesaOpenCL.so.1.0.0 to /opt/mesa/lib/aarch64-linux-gnu
Installing src/gallium/targets/dri/libgallium_dri.so to /opt/mesa/lib/aarch64-linux-gnu/dri
Installing src/glx/libGL.so.1.2.0 to /opt/mesa/lib/aarch64-linux-gnu
Installing src/egl/libEGL.so.1.0.0 to /opt/mesa/lib/aarch64-linux-gnu
Installing /opt/mesa-22.0.0/include/KHR/khrplatform.h to /opt/mesa/include/KHR/
Installing /opt/mesa-22.0.0/include/GLES/egl.h to /opt/mesa/include/GLES/
Installing /opt/mesa-22.0.0/include/GLES/gl.h to /opt/mesa/include/GLES/
Installing /opt/mesa-22.0.0/include/GLES/glext.h to /opt/mesa/include/GLES/
Installing /opt/mesa-22.0.0/include/GLES/glplatform.h to /opt/mesa/include/GLES/
Installing /opt/mesa-22.0.0/include/GLES2/gl2.h to /opt/mesa/include/GLES2/
Installing /opt/mesa-22.0.0/include/GLES2/gl2ext.h to /opt/mesa/include/GLES2/
Installing /opt/mesa-22.0.0/include/GLES2/gl2platform.h to /opt/mesa/include/GLES2/
Installing /opt/mesa-22.0.0/include/GLES3/gl3.h to /opt/mesa/include/GLES3/
Installing /opt/mesa-22.0.0/include/GLES3/gl31.h to /opt/mesa/include/GLES3/
Installing /opt/mesa-22.0.0/include/GLES3/gl32.h to /opt/mesa/include/GLES3/
Installing /opt/mesa-22.0.0/include/GLES3/gl3ext.h to /opt/mesa/include/GLES3/
Installing /opt/mesa-22.0.0/include/GLES3/gl3platform.h to /opt/mesa/include/GLES3/
Installing /opt/mesa-22.0.0/include/GL/gl.h to /opt/mesa/include/GL/
Installing /opt/mesa-22.0.0/include/GL/glcorearb.h to /opt/mesa/include/GL/
Installing /opt/mesa-22.0.0/include/GL/glext.h to /opt/mesa/include/GL/
Installing /opt/mesa-22.0.0/include/GL/glx.h to /opt/mesa/include/GL/
Installing /opt/mesa-22.0.0/include/GL/glxext.h to /opt/mesa/include/GL/
Installing /opt/mesa-22.0.0/include/EGL/egl.h to /opt/mesa/include/EGL/
Installing /opt/mesa-22.0.0/include/EGL/eglext.h to /opt/mesa/include/EGL/
Installing /opt/mesa-22.0.0/include/EGL/eglplatform.h to /opt/mesa/include/EGL/
Installing /opt/mesa-22.0.0/include/EGL/eglmesaext.h to /opt/mesa/include/EGL/
Installing /opt/mesa-22.0.0/include/EGL/eglextchromium.h to /opt/mesa/include/EGL/
Installing /opt/mesa-22.0.0/include/GL/internal/dri_interface.h to /opt/mesa/include/GL/internal/
Installing /opt/mesa-22.0.0/src/gbm/main/gbm.h to /opt/mesa/include/
Installing /opt/mesa-22.0.0/src/util/00-mesa-defaults.conf to /opt/mesa/share/drirc.d
Installing /opt/mesa-22.0.0/builddir/meson-private/glesv1_cm.pc to /opt/mesa/lib/aarch64-linux-gnu/pkgconfig
Installing /opt/mesa-22.0.0/builddir/meson-private/glesv2.pc to /opt/mesa/lib/aarch64-linux-gnu/pkgconfig
Installing /opt/mesa-22.0.0/builddir/meson-private/gbm.pc to /opt/mesa/lib/aarch64-linux-gnu/pkgconfig
Installing /opt/mesa-22.0.0/builddir/src/gallium/targets/opencl/mesa.icd to /opt/mesa/etc/OpenCL/vendors
Installing /opt/mesa-22.0.0/builddir/meson-private/dri.pc to /opt/mesa/lib/aarch64-linux-gnu/pkgconfig
Installing /opt/mesa-22.0.0/builddir/meson-private/egl.pc to /opt/mesa/lib/aarch64-linux-gnu/pkgconfig
Installing /opt/mesa-22.0.0/builddir/meson-private/gl.pc to /opt/mesa/lib/aarch64-linux-gnu/pkgconfig
Installing symlink pointing to libglapi.so.0.0.0 to /opt/mesa/lib/aarch64-linux-gnu/libglapi.so.0
Installing symlink pointing to libglapi.so.0 to /opt/mesa/lib/aarch64-linux-gnu/libglapi.so
Installing symlink pointing to libGLESv1_CM.so.1.1.0 to /opt/mesa/lib/aarch64-linux-gnu/libGLESv1_CM.so.1
Installing symlink pointing to libGLESv1_CM.so.1 to /opt/mesa/lib/aarch64-linux-gnu/libGLESv1_CM.so
Installing symlink pointing to libGLESv2.so.2.0.0 to /opt/mesa/lib/aarch64-linux-gnu/libGLESv2.so.2
Installing symlink pointing to libGLESv2.so.2 to /opt/mesa/lib/aarch64-linux-gnu/libGLESv2.so
Installing symlink pointing to libgbm.so.1.0.0 to /opt/mesa/lib/aarch64-linux-gnu/libgbm.so.1
Installing symlink pointing to libgbm.so.1 to /opt/mesa/lib/aarch64-linux-gnu/libgbm.so
Installing symlink pointing to libMesaOpenCL.so.1.0.0 to /opt/mesa/lib/aarch64-linux-gnu/libMesaOpenCL.so.1
Installing symlink pointing to libMesaOpenCL.so.1 to /opt/mesa/lib/aarch64-linux-gnu/libMesaOpenCL.so
Installing symlink pointing to libGL.so.1.2.0 to /opt/mesa/lib/aarch64-linux-gnu/libGL.so.1
Installing symlink pointing to libGL.so.1 to /opt/mesa/lib/aarch64-linux-gnu/libGL.so
Installing symlink pointing to libEGL.so.1.0.0 to /opt/mesa/lib/aarch64-linux-gnu/libEGL.so.1
Installing symlink pointing to libEGL.so.1 to /opt/mesa/lib/aarch64-linux-gnu/libEGL.so
Running custom install script '/usr/bin/python3 /opt/mesa-22.0.0/bin/install_megadrivers.py /opt/mesa-22.0.0/builddir/src/gallium/targets/dri/libgallium_dri.so /opt/mesa/lib/aarch64-linux-gnu/dri armada-drm_dri.so exynos_dri.so hx8357d_dri.so ili9225_dri.so ili9341_dri.so imx-drm_dri.so imx-dcss_dri.so ingenic-drm_dri.so kirin_dri.so komeda_dri.so mali-dp_dri.so mcde_dri.so mediatek_dri.so meson_dri.so mi0283qt_dri.so mxsfb-drm_dri.so pl111_dri.so rcar-du_dri.so repaper_dri.so rockchip_dri.so st7586_dri.so st7735r_dri.so stm_dri.so sun4i-drm_dri.so panfrost_dri.so'

mesa编译后生成的是就是我们常见的OpenGLOpenCL的那种库,如下所示:

root@rk3399:/opt/mesa-22.0.0#  ll /opt/mesa
drwxr-xr-x  3 root root 4096 Jan 20 20:29 etc/
drwxr-xr-x  8 root root 4096 Jan 20 20:29 include/
drwxr-xr-x  3 root root 4096 Jan 20 20:29 lib/
drwxr-xr-x  4 root root 4096 Jan 20 20:29 share/

root@rk3399:/opt/mesa-22.0.0# ll /opt/mesa/include  # 头文件
├── EGL
│   ├── egl.h
│   ├── eglext.h
│   ├── eglextchromium.h
│   ├── eglmesaext.h
│   ├── eglplatform.h
├── GL
│   ├── gl.h
│   ├── glcorearb.h
│   ├── glext.h
│   ├── glx.h
│   ├── glxext.h
│   ├── internal
│       ├── dri_interface.h
├── GLES
│   ├── egl.h
│   ├── gl.h
│   ├── glext.h
│   ├── glplatform.h
├── GLES2
│   ├── gl2.h
│   ├── gl2ext.h
│   ├── gl2platform.h
├── GLES3
│   ├── gl3.h
│   ├── gl31.h
│   ├── gl32.h
│   ├── gl3ext.h
│   ├── gl3platform.h
├── KHR
│   ├── khrplatform.h
gbm.h

root@rk3399:/opt/mesa-22.0.0# ll /opt/mesa/lib  # 库文件
drwxr-xr-x 5 root root 4096 Jan 20 20:29 aarch64-linux-gnu/
root@rk3399:/opt/mesa-22.0.0# ll /opt/mesa/lib/aarch64-linux-gnu
├── dri
│   ├── armada-drm_dri.so
│   ├── exynos_dri.so
│   ├── hx8357d_dri.so
│   ├── ili9225_dri.so
│   ├── ili9341_dri.so
│   ├── imx-dcss_dri.so
│   ├── imx-drm_dri.so
│   ├── ingenic-drm_dri.so
│   ├── kirin_dri.so
│   ├── komeda_dri.so
│   ├── mali-dp_dri.so
│   ├── mcde_dri.so
│   ├── mediatek_dri.so
│   ├── meson_dri.so
│   ├── mi0283qt_dri.so
│   ├── mxsfb-drm_dri.so
│   ├── panfrost_dri.so
│   ├── pl111_dri.so
│   ├── rcar-du_dri.so
│   ├── repaper_dri.so
│   ├── rockchip_dri.so
│   ├── st7586_dri.so
│   ├── st7735r_dri.so
│   ├── stm_dri.so
│   ├── sun4i-drm_dri.so
├── libEGL.so -> libEGL.so.1
├── libEGL.so.1 -> libEGL.so.1.0.0
├── libEGL.so.1.0.0
├── libGL.so -> libGL.so.1
├── libGL.so.1 -> libGL.so.1.2.0
├── libGL.so.1.2.0
├── libGLESv1_CM.so -> libGLESv1_CM.so.1
├── libGLESv1_CM.so.1 -> libGLESv1_CM.so.1.1.0
├── libGLESv1_CM.so.1.1.0
├── libGLESv2.so -> libGLESv2.so.2
├── libGLESv2.so.2 -> libGLESv2.so.2.0.0
├── libGLESv2.so.2.0.0
├── libMesaOpenCL.so -> libMesaOpenCL.so.1
├── libMesaOpenCL.so.1 -> libMesaOpenCL.so.1.0.0
├── libMesaOpenCL.so.1.0.0
├── libgbm.so -> libgbm.so.1
├── libgbm.so.1 -> libgbm.so.1.0.0
├── libgbm.so.1.0.0
├── libglapi.so -> libglapi.so.0
├── libglapi.so.0 -> libglapi.so.0.0.0
├── libglapi.so.0.0.0
├── libvulkan_panfrost.so
└── pkgconfig

这里dri目录下的内容是和平台相关的,比如:

  • ili9225intel的;
  • panfrostmali的;

之后将编译出来的库文件放到开发板对应位置就可以使用了。当然这里dri的库需要根据开发板实际情况调整,比如RK3399的板子,GPUT860,拷贝panfrost_dri.so即可。

4.4.4 安装到默认路径

我们卸载之前通过apt install安装的meta包:

root@rk3399:/opt/mesa-22.0.0# apt remove libgl1-mesa-dev libgles2-mesa-dev libegl1-mesa-dev  mesa-opencl-icd
root@rk3399:/opt/mesa-22.0.0#  rm -rf /usr/lib/aarch64-linux-gnu/dri /usr/include/EGL /usr/include/GLES /usr/include/GLES2 /usr/include/GLE3

修改mesa配置的默认安装路径:

root@rk3399:/opt/mesa-22.0.0

重新安装:

root@rk3399:/opt/mesa-22.0.0# ninja -C builddir/ install
ninja: Entering directory `builddir/'
[0/1] Regenerating build files.
The Meson build system
Version: 0.63.0
Source dir: /opt/mesa-22.0.0
Build dir: /opt/mesa-22.0.0/builddir
Build type: native build
Program python3 found: YES (/usr/bin/python3)
Project name: mesa
Project version: 22.0.0
C compiler for the host machine: cc (gcc 9.4.0 "cc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0")
C linker for the host machine: cc ld.bfd 2.34
C++ compiler for the host machine: c++ (gcc 9.4.0 "c++ (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0")
C++ linker for the host machine: c++ ld.bfd 2.34
Host machine cpu family: aarch64
Host machine cpu: aarch64
Checking if "-mtls-dialect=gnu2" runs: DID NOT COMPILE
Dependency libclc found: YES 0.2.0 (cached)
Program python3 found: YES (/usr/bin/python3)
Fetching value of define "ETIME" : 62 (cached)
Checking for function "bswap32" : YES (cached)
Checking for function "bswap64" : YES (cached)
Checking for function "clz" : YES (cached)
.....
Checking for function "dlopen" : NO (cached)
Library dl found: YES
Checking for function "dladdr" with dependency -ldl: YES (cached)
Checking for function "dl_iterate_phdr" : YES (cached)
Checking for function "clock_gettime" : YES (cached)
Dependency zlib found: YES 1.2.11 (cached)
Found pkg-config: /usr/bin/pkg-config (0.29.1)
Found CMake: /usr/bin/cmake (3.28.0)
Run-time dependency libzstd found: NO (tried pkgconfig and cmake)
Dependency threads found: YES unknown (cached)
Checking for function "pthread_setaffinity_np" with dependency threads: YES (cached)
Dependency expat found: YES 2.2.9 (cached)
Library m found: YES
Dependency libdrm found: YES 2.4.118 (cached)
Dependency libudev found: YES 245 (cached)
WARNING: Optional LLVM module all-targets was not found
WARNING: CMake: Dependency z for LLVM was not found
WARNING: CMake: Dependency rt for LLVM was not found
......
WARNING: Ignoring LLVM CMake dependency because dynamic was requested
llvm-config found: YES (/usr/bin/llvm-config) 11.0.0
Run-time dependency LLVM (modules: bitwriter, core, coverage, engine, executionengine, instcombine, instrumentation, ipo, irreader, linker, lto, mcdisassembler, mcjit, objc                                                                                                                 arcopts, option, profiledata, scalaropts, transformutils, all-targets, coroutines, frontendopenmp) found: YES 11.0.0
Dependency libelf found: YES 0.176 (cached)
Dependency valgrind found: YES 3.15.0 (cached)
Program bison found: YES (/usr/bin/bison)
Program bison found: YES 3.5.1 (/usr/bin/bison)
Program flex found: YES (/usr/bin/flex)
Dependency x11 found: YES 1.6.9 (cached)
Dependency xext found: YES 1.3.4 (cached)
Dependency xfixes found: YES 5.0.3 (cached)
Dependency xcb-glx found: YES 1.14 (cached)
Dependency xcb-shm found: YES 1.14 (cached)
Dependency xcb found: YES 1.14 (cached)
Dependency x11-xcb found: YES 1.6.9 (cached)
Dependency xcb-dri2 found: YES 1.14 (cached)
Dependency xcb-dri3 found: YES 1.14 (cached)
Dependency xcb-present found: YES 1.14 (cached)
Dependency xcb-shm found: YES 1.14 (cached)
Dependency xcb-sync found: YES 1.14 (cached)
Dependency xshmfence found: YES 1.3 (cached)
Dependency glproto found: YES 1.4.17 (cached)
Dependency dri2proto found: YES 2.8 (cached)
Dependency xxf86vm found: YES 1.1.4 (cached)
Dependency xcb-xfixes found: YES 1.14 (cached)
Dependency xcb-randr found: YES 1.14 (cached)
Dependency xrandr found: YES 1.5.2 (cached)
Library sensors found: NO
Program nm found: YES (/usr/bin/nm)
Program symbols-check.py found: YES (/usr/bin/python3 /opt/mesa-22.0.0/bin/symbols-check.py)
Program install_megadrivers.py found: YES (/usr/bin/python3 /opt/mesa-22.0.0/bin/install_megadrivers.py)
WARNING: Library target 'GLESv1_CM' has 'name_prefix' set. Compilers may not find it from its '-lGLESv1_CM' linker flag in the 'glesv1_cm.pc' pkg-config file.
WARNING: Library target 'GLESv1_CM' has 'name_prefix' set. Compilers may not find it from its '-lGLESv1_CM' linker flag in the 'glesv1_cm-uninstalled.pc' pkg-config file.
WARNING: Library target 'GLESv2' has 'name_prefix' set. Compilers may not find it from its '-lGLESv2' linker flag in the 'glesv2.pc' pkg-config file.
WARNING: Library target 'GLESv2' has 'name_prefix' set. Compilers may not find it from its '-lGLESv2' linker flag in the 'glesv2-uninstalled.pc' pkg-config file.
Checking for function "mmap" : YES (cached)
Program decode.py found: YES (/opt/mesa-22.0.0/src/compiler/isaspec/decode.py)
Program encode.py found: YES (/opt/mesa-22.0.0/src/compiler/isaspec/encode.py)
Compiler for C++ supports arguments -Wno-ignored-attributes: YES (cached)
Library Polly found: YES
Library PollyISL found: YES
Library clang-cpp found: YES
Compiler for C++ supports link arguments -Wl,--rpath=/usr/lib/llvm-11/lib: YES (cached)
Checking if "dep-clang-usable" with dependencies LLVM, -lclang-cpp, threads runs: YES
Configuring mesa.icd using configuration
Checking for function "mincore" : YES (cached)
WARNING: Library target 'EGL' has 'name_prefix' set. Compilers may not find it from its '-lEGL' linker flag in the 'egl.pc' pkg-config file.
WARNING: Library target 'EGL' has 'name_prefix' set. Compilers may not find it from its '-lEGL' linker flag in the 'egl-uninstalled.pc' pkg-config file.
Message: Configuration summary:

        prefix:          /usr
        libdir:          lib/aarch64-linux-gnu
        includedir:      include

        OpenGL:          yes (ES1: yes ES2: yes)
        OSMesa:          no

        DRI platform:    drm
        DRI drivers:     no
        DRI driver dir:  /usr/lib/aarch64-linux-gnu/dri

        GLX:             DRI-based

        EGL:             yes
        EGL drivers:     builtin:egl_dri2 builtin:egl_dri3
        EGL/Vulkan/VL platforms:   x11 surfaceless drm xcb
        GBM:             yes
        GBM backends path: /usr/lib/aarch64-linux-gnu/gbm

        Vulkan drivers:  panfrost
        Vulkan ICD dir:  share/vulkan/icd.d

        llvm:            yes
        llvm-version:    11.0.0

        Gallium drivers: panfrost
        Gallium st:      mesa clover
        HUD lmsensors:   no

        Shared-glapi:    yes

        Perfetto:        no
        Perfetto ds:     auto

Build targets in project: 178
NOTICE: Future-deprecated features used:
 * 0.55.0: {'ExternalProgram.path'}
 * 0.56.0: {'meson.source_root'}

mesa 22.0.0

  User defined options
    backend        : ninja
    prefix         : /usr
    gallium-drivers: panfrost
    gallium-opencl : icd
    libunwind      : disabled
    platforms      : x11
    vulkan-drivers : panfrost

Found ninja-1.10.0 at /usr/bin/ninja
Cleaning... 0 files.
[21/22] Installing files.
Installing src/mapi/shared-glapi/libglapi.so.0.0.0 to /usr/lib/aarch64-linux-gnu
Installing src/mapi/es1api/libGLESv1_CM.so.1.1.0 to /usr/lib/aarch64-linux-gnu
Installing src/mapi/es2api/libGLESv2.so.2.0.0 to /usr/lib/aarch64-linux-gnu
Installing src/panfrost/vulkan/libvulkan_panfrost.so to /usr/lib/aarch64-linux-gnu
Installing src/panfrost/vulkan/panfrost_icd.aarch64.json to /usr/share/vulkan/icd.d
Installing src/gbm/libgbm.so.1.0.0 to /usr/lib/aarch64-linux-gnu
Installing src/gallium/targets/pipe-loader/pipe_kmsro.so to /usr/lib/aarch64-linux-gnu/gallium-pipe
Installing src/gallium/targets/opencl/libMesaOpenCL.so.1.0.0 to /usr/lib/aarch64-linux-gnu
Installing src/gallium/targets/dri/libgallium_dri.so to /usr/lib/aarch64-linux-gnu/dri
Installing src/glx/libGL.so.1.2.0 to /usr/lib/aarch64-linux-gnu
Installing src/egl/libEGL.so.1.0.0 to /usr/lib/aarch64-linux-gnu
Installing /opt/mesa-22.0.0/include/KHR/khrplatform.h to /usr/include/KHR
Installing /opt/mesa-22.0.0/include/GLES/egl.h to /usr/include/GLES
Installing /opt/mesa-22.0.0/include/GLES/gl.h to /usr/include/GLES
Installing /opt/mesa-22.0.0/include/GLES/glext.h to /usr/include/GLES
Installing /opt/mesa-22.0.0/include/GLES/glplatform.h to /usr/include/GLES
Installing /opt/mesa-22.0.0/include/GLES2/gl2.h to /usr/include/GLES2
Installing /opt/mesa-22.0.0/include/GLES2/gl2ext.h to /usr/include/GLES2
Installing /opt/mesa-22.0.0/include/GLES2/gl2platform.h to /usr/include/GLES2
Installing /opt/mesa-22.0.0/include/GLES3/gl3.h to /usr/include/GLES3
Installing /opt/mesa-22.0.0/include/GLES3/gl31.h to /usr/include/GLES3
Installing /opt/mesa-22.0.0/include/GLES3/gl32.h to /usr/include/GLES3
Installing /opt/mesa-22.0.0/include/GLES3/gl3ext.h to /usr/include/GLES3
Installing /opt/mesa-22.0.0/include/GLES3/gl3platform.h to /usr/include/GLES3
Installing /opt/mesa-22.0.0/include/GL/gl.h to /usr/include/GL
Installing /opt/mesa-22.0.0/include/GL/glcorearb.h to /usr/include/GL
Installing /opt/mesa-22.0.0/include/GL/glext.h to /usr/include/GL
Installing /opt/mesa-22.0.0/include/GL/glx.h to /usr/include/GL
Installing /opt/mesa-22.0.0/include/GL/glxext.h to /usr/include/GL
Installing /opt/mesa-22.0.0/include/EGL/egl.h to /usr/include/EGL
Installing /opt/mesa-22.0.0/include/EGL/eglext.h to /usr/include/EGL
Installing /opt/mesa-22.0.0/include/EGL/eglplatform.h to /usr/include/EGL
Installing /opt/mesa-22.0.0/include/EGL/eglmesaext.h to /usr/include/EGL/
Installing /opt/mesa-22.0.0/include/EGL/eglextchromium.h to /usr/include/EGL/
Installing /opt/mesa-22.0.0/include/GL/internal/dri_interface.h to /usr/include/GL/internal
Installing /opt/mesa-22.0.0/src/gbm/main/gbm.h to /usr/include/
Installing /opt/mesa-22.0.0/src/util/00-mesa-defaults.conf to /usr/share/drirc.d
Installing /opt/mesa-22.0.0/builddir/meson-private/glesv1_cm.pc to /usr/lib/aarch64-linux-gnu/pkgconfig
Installing /opt/mesa-22.0.0/builddir/meson-private/glesv2.pc to /usr/lib/aarch64-linux-gnu/pkgconfig
Installing /opt/mesa-22.0.0/builddir/meson-private/gbm.pc to /usr/lib/aarch64-linux-gnu/pkgconfig
Installing /opt/mesa-22.0.0/builddir/src/gallium/targets/opencl/mesa.icd to /etc/OpenCL/vendors
Installing /opt/mesa-22.0.0/builddir/meson-private/dri.pc to /usr/lib/aarch64-linux-gnu/pkgconfig
Installing /opt/mesa-22.0.0/builddir/meson-private/egl.pc to /usr/lib/aarch64-linux-gnu/pkgconfig
Installing /opt/mesa-22.0.0/builddir/meson-private/gl.pc to /usr/lib/aarch64-linux-gnu/pkgconfig
Installing symlink pointing to libglapi.so.0.0.0 to /usr/lib/aarch64-linux-gnu/libglapi.so.0
Installing symlink pointing to libglapi.so.0 to /usr/lib/aarch64-linux-gnu/libglapi.so
Installing symlink pointing to libGLESv1_CM.so.1.1.0 to /usr/lib/aarch64-linux-gnu/libGLESv1_CM.so.1
Installing symlink pointing to libGLESv1_CM.so.1 to /usr/lib/aarch64-linux-gnu/libGLESv1_CM.so
Installing symlink pointing to libGLESv2.so.2.0.0 to /usr/lib/aarch64-linux-gnu/libGLESv2.so.2
Installing symlink pointing to libGLESv2.so.2 to /usr/lib/aarch64-linux-gnu/libGLESv2.so
Installing symlink pointing to libgbm.so.1.0.0 to /usr/lib/aarch64-linux-gnu/libgbm.so.1
Installing symlink pointing to libgbm.so.1 to /usr/lib/aarch64-linux-gnu/libgbm.so
Installing symlink pointing to libMesaOpenCL.so.1.0.0 to /usr/lib/aarch64-linux-gnu/libMesaOpenCL.so.1
Installing symlink pointing to libMesaOpenCL.so.1 to /usr/lib/aarch64-linux-gnu/libMesaOpenCL.so
Installing symlink pointing to libGL.so.1.2.0 to /usr/lib/aarch64-linux-gnu/libGL.so.1
Installing symlink pointing to libGL.so.1 to /usr/lib/aarch64-linux-gnu/libGL.so
Installing symlink pointing to libEGL.so.1.0.0 to /usr/lib/aarch64-linux-gnu/libEGL.so.1
Installing symlink pointing to libEGL.so.1 to /usr/lib/aarch64-linux-gnu/libEGL.so
Running custom install script '/usr/bin/python3 /opt/mesa-22.0.0/bin/install_megadrivers.py /opt/mesa-22.0.0/builddir/src/gallium/targets/dri/libgallium_dri.so /usr/lib/aar                                                                                                                 ch64-linux-gnu/dri armada-drm_dri.so exynos_dri.so hx8357d_dri.so ili9225_dri.so ili9341_dri.so imx-drm_dri.so imx-dcss_dri.so ingenic-drm_dri.so kirin_dri.so komeda_dri.so                                                                                                                  mali-dp_dri.so mcde_dri.so mediatek_dri.so meson_dri.so mi0283qt_dri.so mxsfb-drm_dri.so pl111_dri.so rcar-du_dri.so repaper_dri.so rockchip_dri.so st7586_dri.so st7735r_d                                                                                                                 ri.so stm_dri.so sun4i-drm_dri.so panfrost_dri.so'

5.4.5 glxinfo

使用glxinfo测试:

root@rk3399:/opt# export DISPLAY=:0.0; glxinfo -B
name of display: :0.0
display: :0  screen: 0
direct rendering: Yes
Extended renderer info (GLX_MESA_query_renderer):
    Vendor: Panfrost (0xffffffff)
    Device: Mali-T860 (Panfrost) (0xffffffff)
    Version: 22.0.0
    Accelerated: yes
    Video memory: 3851MB
    Unified memory: yes
    Preferred profile: core (0x1)
    Max core profile version: 3.1
    Max compat profile version: 3.1
    Max GLES1 profile version: 1.1
    Max GLES[23] profile version: 3.1
OpenGL vendor string: Panfrost
OpenGL renderer string: Mali-T860 (Panfrost)
OpenGL core profile version string: 3.1 Mesa 22.0.0
OpenGL core profile shading language version string: 1.40
OpenGL core profile context flags: (none)

OpenGL version string: 3.1 Mesa 22.0.0
OpenGL shading language version string: 1.40
OpenGL context flags: (none)

OpenGL ES profile version string: OpenGL ES 3.1 Mesa 22.0.0
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.10

以看到驱动为Mali T860 (Panfrost)OpenGL version string: 3.1 Mesa 22.0.0

5.4.6 clinfo
root@rk3399:/opt# clinfo
Number of platforms                               1
  Platform Name                                   Clover
  Platform Vendor                                 Mesa
  Platform Version                                OpenCL 1.1 Mesa 22.0.0
  Platform Profile                                FULL_PROFILE
  Platform Extensions                             cl_khr_icd
  Platform Extensions function suffix             MESA

  Platform Name                                   Clover
Number of devices                                 0

NULL platform behavior
  clGetPlatformInfo(NULL, CL_PLATFORM_NAME, ...)  Clover
  clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, ...) 
  clCreateContext(NULL, ...) [default]            No devices found in platform
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_DEFAULT)  No devices found in platform
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_CPU)  No devices found in platform
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_GPU)  No devices found in platform
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_ACCELERATOR)  No devices found in platform
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_CUSTOM)  No devices found in platform
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_ALL)  No devices found in platform

ICD loader properties
  ICD loader Name                                 OpenCL ICD Loader
  ICD loader Vendor                               OCL Icd free software
  ICD loader Version                              2.2.11
  ICD loader Profile                              OpenCL 2.1

5.5 源码目录结构

参考文章

[1] 在 RK3399 上运行开源的 Mali GPU 驱动

[2] mainlineu-bootlinux kernel

[3] MaliGraphics

[4] ARM Mali GPU

[5] 播放 4K 视频吃 CPU 还是 GPU

[6] [Linux RK Debian 10] chrome浏览器开启GPU硬件加速

[7] Ubuntu22.04平台安装mesa

[8] how to install Drivers to make OpenGL Programs

[9] Compiliing and Installiing mesa

[10] The mesa 3D Graphics Library

[11] mesa gitlab源码

[12] Enable OpenCL support on Debian/hikey960