Raspberry Pi 3のGPUが64bit linux（aarch64）でも使えるようになってた

この記事は、株式会社ACCESS Advent Calendar 2017の11日目の記事です。
（元々投稿しようと考えてた内容がまだうまくまとまってないので、別ネタです）

Raspberry Pi 3のSoCにはVideoCore IVというGPUが載っています。
32bit linux（armv7l）でなら2016年には
http://mickey-happygolucky.hatenablog.com/entry/2016/11/03/001257
にもあるようにRaspberry Pi 3上でOpenGLESでGPU Accelerationを効かせれれたのですが、
https://github.com/raspberrypi/userland/issues/314
などを見て、64bit linux（aarch64）ではまだGPUを使えない（OpenGLESの処理をCPUで行う）と思ってました。

ところが今年の秋の
https://git.yoctoproject.org/cgit/cgit.cgi/meta-raspberrypi/commit/?h=rocko&id=bb51049ebe761ac2806fa0fa492c586976632011
により、yocto 2.4 (rocko)でaarch64ビルドしたlinuxでGPU Accelerationが効くようになった模様。
カーネルモジュールとMesa（OpenGLライブラリ）の対応が進んでうまく協働するようになったということでしょうか。

ビルドして起動してみました。
（事情により、pokyとOEは 2.3 (pyro)、meta-raspberrypiは 2.4 (rocko)という組み合わせですが。。。）
aarch64ビルドするためlocal.confに `MACHINE = "raspberrypi3-64"` を記載し、 `bitbake core-image-sato` しました。

dmesgの抜粋：

```
[    0.000000] Linux version 4.9.50 (oe-user@oe-host) (gcc version 5.4.0 (GCC) ) #1 SMP PREEMPT Tue Dec 5 14:36:16 UTC 2017
[    0.000000] Boot CPU: AArch64 Processor [410fd034]

[    0.211370] raspberrypi-firmware soc:firmware: Attached to firmware from 2017-08-08 12:01
[    0.447095] [drm] Initialized

[    2.544958] vc4-drm soc:gpu: bound 3f600000.firmwarekms (ops vc4_fkms_ops [vc4])
[    2.575580] vc4-drm soc:gpu: bound 3fc00000.v3d (ops vc4_v3d_ops [vc4])
[    2.577951] [drm] Supports vblank timestamp caching Rev 2 (21.10.2013).
[    2.577982] [drm] Driver supports precise vblank timestamp query.
[    2.834165] vc4-drm soc:gpu: fb0:  frame buffer device
```

X.orgの起動ログ（Xorg.0.log）の抜粋：

```
[     4.778] (II) LoadModule: "modesetting"
[     4.779] (II) Loading /usr/lib/xorg/modules/drivers/modesetting_drv.so
[     4.785] (II) Module modesetting: vendor="X.Org Foundation"
[     4.785] 	compiled for 1.19.1, module version = 1.19.1
[     4.786] 	Module class: X.Org Video Driver
[     4.786] 	ABI class: X.Org Video Driver, version 23.0
[     4.787] (II) modesetting: Driver for Modesetting Kernel Drivers: kms
[     4.787] (--) using VT number 2

[     4.849] (II) modeset(0): using drv /dev/dri/card0
[     4.849] (WW) VGA arbiter: cannot open kernel arbiter, no multi-card support
[     4.851] (II) modeset(0): Creating default Display subsection in Screen section
	"Default Screen Section" for depth/fbbpp 24/32
[     4.851] (==) modeset(0): Depth 24, (==) framebuffer bpp 32
[     4.851] (==) modeset(0): RGB weight 888
[     4.851] (==) modeset(0): Default visual is TrueColor
[     4.851] (II) Loading sub module "glamoregl"
[     4.851] (II) LoadModule: "glamoregl"
[     4.851] (II) Loading /usr/lib/xorg/modules/libglamoregl.so
[     4.953] (II) Module glamoregl: vendor="X.Org Foundation"
[     4.954] 	compiled for 1.19.1, module version = 1.0.0
[     4.954] 	ABI class: X.Org ANSI C Emulation, version 0.4
[     4.954] (II) glamor: OpenGL accelerated X.org driver based.
[     5.258] (II) glamor: EGL version 1.4 (DRI2):
[     5.307] (II) modeset(0): glamor initialized
[     5.308] (II) modeset(0): Output HDMI-1 has no monitor section
[     5.309] (II) modeset(0): EDID for output HDMI-1
[     5.309] (II) modeset(0): Printing probed modes for output HDMI-1
[     5.309] (II) modeset(0): Modeline "1920x1080"x60.0  173.00  1920 2048 2248 2576  1080 1083 1088 1120 -hsync +vsync (67.2 kHz)
[     5.309] (II) modeset(0): Output HDMI-1 connected
[     5.309] (II) modeset(0): Using sloppy heuristic for initial modes
[     5.309] (II) modeset(0): Output HDMI-1 using initial mode 1920x1080 +0+0
[     5.309] (==) modeset(0): Using gamma correction (1.0, 1.0, 1.0)
[     5.309] (==) modeset(0): DPI set to (96, 96)
[     5.309] (II) Loading sub module "fb"
[     5.309] (II) LoadModule: "fb"
[     5.309] (II) Loading /usr/lib/xorg/modules/libfb.so
[     5.322] (II) Module fb: vendor="X.Org Foundation"
[     5.322] 	compiled for 1.19.1, module version = 1.0.0
[     5.322] 	ABI class: X.Org ANSI C Emulation, version 0.4
[     5.322] (==) Depth 24 pixmap format is 32 bpp
[     5.810] (==) modeset(0): Backing store enabled
[     5.811] (==) modeset(0): Silken mouse enabled
[     5.811] (II) modeset(0): RandR 1.2 enabled, ignore the following RandR disabled message.
[     5.812] (==) modeset(0): DPMS enabled
[     5.812] (II) modeset(0): [DRI2] Setup complete
[     5.812] (II) modeset(0): [DRI2]   DRI driver: vc4
[     5.812] (II) modeset(0): [DRI2]   VDPAU driver: vc4
[     5.812] (--) RandR disabled
[     5.828] (II) AIGLX: enabled GLX_MESA_copy_sub_buffer
[     5.828] (II) AIGLX: enabled GLX_ARB_create_context
[     5.828] (II) AIGLX: enabled GLX_ARB_create_context_profile
[     5.828] (II) AIGLX: enabled GLX_EXT_create_context_es{,2}_profile
[     5.828] (II) AIGLX: enabled GLX_INTEL_swap_event
[     5.828] (II) AIGLX: enabled GLX_SGI_swap_control
[     5.828] (II) AIGLX: enabled GLX_EXT_framebuffer_sRGB
[     5.828] (II) AIGLX: enabled GLX_ARB_fbconfig_float
[     5.828] (II) AIGLX: enabled GLX_EXT_fbconfig_packed_float
[     5.828] (II) AIGLX: GLX_EXT_texture_from_pixmap backed by buffer objects
[     5.832] (II) AIGLX: Loaded and initialized vc4
[     5.832] (II) GLX: Initialized DRI2 GL provider for screen 0
```

es2_infoの出力：

```
EGL_VERSION: 1.4 (DRI2)
EGL_VENDOR: Mesa Project
EGL_EXTENSIONS:
    EGL_CHROMIUM_sync_control, EGL_EXT_image_dma_buf_import, 
    EGL_KHR_cl_event2, EGL_KHR_config_attribs, EGL_KHR_create_context, 
    EGL_KHR_fence_sync, EGL_KHR_get_all_proc_addresses, EGL_KHR_gl_colorspace, 
    EGL_KHR_gl_renderbuffer_image, EGL_KHR_gl_texture_2D_image, 
    EGL_KHR_gl_texture_3D_image, EGL_KHR_gl_texture_cubemap_image, 
    EGL_KHR_image, EGL_KHR_image_base, EGL_KHR_image_pixmap, 
    EGL_KHR_no_config_context, EGL_KHR_reusable_sync, 
    EGL_KHR_surfaceless_context, EGL_KHR_wait_sync, 
    EGL_MESA_configless_context, EGL_MESA_drm_image, 
    EGL_MESA_image_dma_buf_export, EGL_NOK_swap_region, 
    EGL_NOK_texture_from_pixmap, EGL_NV_post_sub_buffer, 
    EGL_WL_bind_wayland_display
EGL_CLIENT_APIS: OpenGL OpenGL_ES 
GL_VERSION: OpenGL ES 2.0 Mesa 17.0.2
GL_RENDERER: Gallium 0.4 on VC4 V3D 2.1
GL_EXTENSIONS:
    GL_EXT_blend_minmax, GL_EXT_multi_draw_arrays, 
    GL_EXT_texture_format_BGRA8888, GL_OES_compressed_ETC1_RGB8_texture, 
    GL_OES_depth24, GL_OES_element_index_uint, GL_OES_fbo_render_mipmap, 
    GL_OES_mapbuffer, GL_OES_rgb8_rgba8, GL_OES_stencil8, GL_OES_texture_3D, 
    GL_OES_texture_npot, GL_OES_vertex_half_float, GL_OES_EGL_image, 
    GL_OES_depth_texture, GL_OES_packed_depth_stencil, 
    GL_EXT_texture_type_2_10_10_10_REV, GL_OES_get_program_binary, 
    GL_APPLE_texture_max_level, GL_EXT_discard_framebuffer, 
    GL_EXT_read_format_bgra, GL_NV_fbo_color_attachments, 
    GL_OES_EGL_image_external, GL_OES_EGL_sync, GL_OES_vertex_array_object, 
    GL_EXT_unpack_subimage, GL_NV_draw_buffers, GL_NV_read_buffer, 
    GL_NV_read_depth, GL_NV_read_depth_stencil, GL_NV_read_stencil, 
    GL_EXT_draw_buffers, GL_EXT_map_buffer_range, GL_KHR_debug, 
    GL_OES_surfaceless_context, GL_EXT_separate_shader_objects, 
    GL_EXT_draw_elements_base_vertex, GL_EXT_texture_border_clamp, 
    GL_KHR_context_flush_control, GL_OES_draw_elements_base_vertex, 
    GL_OES_texture_border_clamp
```

`GL_RENDERER: Gallium 0.4 on VC4 V3D 2.1` とあるので、ちゃんとGPU Accelerationするようです。

mesa-demosパッケージを入れてes2gears_x11を表示したところ：
![es2gears_x11.png](https://qiita-image-store.s3.amazonaws.com/0/41296/01bb4209-3705-59be-e3f5-c329336db6e0.png)
Full HDのスクリーンに対して46FPS出てました。