본문 바로가기
안드로이드

Termux debian proot-distro 에서 mesa 빌드하기 (kgsl / dri3 enable)

by ㅋㅋ잠자 2024. 6. 26.
반응형

안녕하세요. 일단 GPU 가속 부분을 적용하기 위해 mesa 를 빌드해보겠습니다.

아래 내용은 퀄컴 제품에만 해당될 수 있으며, 테스트는 갤럭시S23 울트라에서 진행하였습니다.

 

1. deb-src repo 주소 추가

root@localhost:~# cat /etc/apt/sources.list
deb [signed-by="/usr/share/keyrings/debian-archive-keyring.gpg"] http://deb.debian.org/debian bookworm main contrib non-free
deb [signed-by="/usr/share/keyrings/debian-archive-keyring.gpg"] http://deb.debian.org/debian bookworm-updates main contrib non-free
deb [signed-by="/usr/share/keyrings/debian-archive-keyring.gpg"] http://security.debian.org/debian-security bookworm-security main contrib non-free
deb [signed-by="/usr/share/keyrings/debian-archive-keyring.gpg"] http://deb.debian.org/debian bookworm-backports main contrib non-free
deb-src [signed-by="/usr/share/keyrings/debian-archive-keyring.gpg"] http://deb.debian.org/debian bookworm main contrib non-free
deb-src [signed-by="/usr/share/keyrings/debian-archive-keyring.gpg"] http://deb.debian.org/debian bookworm-updates main contrib non-free
deb-src [signed-by="/usr/share/keyrings/debian-archive-keyring.gpg"] http://security.debian.org/debian-security bookworm-security main contrib non-free
deb-src [signed-by="/usr/share/keyrings/debian-archive-keyring.gpg"] http://deb.debian.org/debian bookworm-backports main contrib non-free

 

2. 빌드 의존 패키지 설치하기

root@localhost:~# apt build-dep mesa 

 

3. mesa 소스 클론 및 빌드

root@localhost:~# git clone https://gitlab.freedesktop.org/mesa/mesa --depth 1
Cloning into 'mesa'...
warning: redirecting to https://gitlab.freedesktop.org/mesa/mesa.git/
remote: Enumerating objects: 10688, done.
remote: Counting objects: 100% (10688/10688), done.
remote: Compressing objects: 100% (9590/9590), done.
Receiving objects:  19% (2088/10688), 7.88 MiB | 442.00 KiB/s 

root@localhost:~# cd mesa/

아래 명령으로 컴파일을 진행합니다.

root@localhost:~/mesa# meson build -Dgbm=enabled -Dopengl=true -Degl=enabled -Degl-native-platform=x11 -Dgles1=disabled -Dgles2=enabled -Ddri3=enabled -Dglx=dri -Dllvm=enabled -Dshared-llvm=disabled -Dplatforms=x11,wayland -Dgallium-drivers=swrast,virgl,zink -Dosmesa=true -Dglvnd=true -Dxmlconfig=disabled --reconfigure --prefix=/usr/local --libdir=/usr/local/lib/aarch64-linux-gnu
The Meson build system
Version: 1.0.1
Source dir: /root/mesa
Build dir: /root/mesa/build
Build type: native build

meson.build:21:0: ERROR: Meson version is 1.0.1 but project requires >= 1.1.0

일단 에러를 해결해보겠습니다.

python3-pip 를 설치합니다. meson 툴의 경우 python 툴이기 때문에 pip3 를 통해 업데이트합니다.

root@localhost:~/mesa# apt install python3-pip
root@localhost:~/mesa# pip3 install -U meson --break-system-packages

버전을 확인합니다.

root@localhost:~/mesa# meson --version
1.4.1

다시 시도해봅니다.

root@localhost:~/mesa# meson build -Dgbm=enabled -Dopengl=true -Degl=enabled -Degl-native-platform=x11 -Dgles1=disabled -Dgles2=enabled -Ddri3=enabled -Dglx=dri -Dllvm=enabled -Dshared-llvm=disabled -Dplatforms=x11,wayland -Dgallium-drivers=swrast,virgl,zink -Dosmesa=true -Dglvnd=true -Dxmlconfig=disabled --reconfigure --prefix=/usr/local --libdir=/usr/local/lib/aarch64-linux-gnu

configure 결과가 아래와 같이 출력됩니다.

mesa 24.2.0-devel

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

  Common C and C++ arguments
    c_cpp_args                   :

  OpenGL
    OpenGL                       : YES
    ES1                          : NO
    ES2                          : YES
    Shared glapi                 : YES
    GLVND                        : YES

  DRI
    Platform                     : drm
    Driver dir                   : /usr/local/lib/aarch64-linux-gnu/dri

  GLX
    Enabled                      : YES
    Provider                     : dri

  EGL
    Enabled                      : YES
    Drivers                      : builtin:egl_dri2 builtin:egl_dri3
    Platforms                    : x11 wayland surfaceless drm xcb

  GBM
    Enabled                      : YES
    Backends path                : /usr/local/lib/aarch64-linux-gnu/gbm

  Vulkan
    Drivers                      : swrast
    Platforms                    : x11 wayland surfaceless drm xcb
    ICD dir                      : share/vulkan/icd.d
    Intel Ray tracing            : NO

  Video
    Codecs                       : av1dec av1enc vp9dec
    APIs                         : vdpau va vulkan

  LLVM
    Enabled                      : YES
    Version                      : 15.0.6

  Gallium
    Enabled                      : YES
    Drivers                      : swrast virgl zink
    Platforms                    : x11 wayland surfaceless drm xcb
    Frontends                    : mesa vdpau va
    Off-screen rendering (OSMesa): libOSMesa
    HUD lm-sensors               : YES

  Perfetto
    Enabled                      : NO

  Teflon (TensorFlow Lite delegate)
    Enabled                      : NO

  User defined options
    libdir                       : /usr/local/lib/aarch64-linux-gnu
    prefix                       : /usr/local
    dri3                         : enabled
    egl                          : enabled
    egl-native-platform          : x11
    gallium-drivers              : swrast,virgl,zink
    gbm                          : enabled
    gles1                        : disabled
    gles2                        : enabled
    glvnd                        : true
    glx                          : dri
    llvm                         : enabled
    opengl                       : true
    osmesa                       : true
    platforms                    : x11,wayland
    shared-llvm                  : disabled
    vulkan-drivers               : swrast
    xmlconfig                    : disabled

아래 명령으로 컴파일 합니다.

root@localhost:~/mesa# ninja -C build 
ninja: Entering directory `build'
[177/1735] Linking target subprojects/wayland...pedantic-staging_xdg_dialog_xdg_dialog_v1_xml

Found ninja-1.11.1 at /usr/bin/ninja
WARNING: Running the setup command as `meson [options]` instead of `meson setup [options]` is ambiguous and deprecated.
root@localhost:~/mesa# ninja -C build 
ninja: Entering directory `build'
[1735/1735] Linking target src/gallium/targets/lavapipe/libvulkan_lvp.so

컴파일이 완료되었습니다.

아래 명령으로 설치합니다.

root@localhost:~/mesa# ninja -C build install
ninja: Entering directory `build'
[1/2] Installing files.

 

4. llvmpipe 에서 벤치마크

아래 패키지를 설치합니다.

root@localhost:~# apt install mesa-utils
root@localhost:~# glxinfo -B
name of display: :0.0
display: :0  screen: 0
direct rendering: Yes
Extended renderer info (GLX_MESA_query_renderer):
    Vendor: Mesa/X.org (0xffffffff)
    Device: llvmpipe (LLVM 15.0.6, 128 bits) (0xffffffff)
    Version: 22.3.6
    Accelerated: no
    Video memory: 11029MB
    Unified memory: yes
    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 15.0.6, 128 bits)
OpenGL core profile version string: 4.5 (Core Profile) Mesa 22.3.6
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.3.6
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.3.6
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20
root@localhost:~# glxgears
1186 frames in 5.0 seconds = 237.109 FPS

 

5. termux 환경에서 turnip 드라이버 활성화

termux 시작 스크립트를 조금 수정합니다.

#!/bin/sh

# cleanup process
pkill -9 -ef "http://m.termux.x11.Loader"
pkill -9 -ef "pulseaudio"
rm -rf ${TMPDIR}/*

# termux app start
am start --user 0 -n com.termux.x11/com.termux.x11.MainActivity

# termux-x11 start
XDG_RUNTIME_DIR=${TMPDIR} termux-x11 :0 -ac -extension MIT-SHM &
sleep 1

# pulseaudio server start
pulseaudio --start --load="module-native-protocol-tcp auth-ip-acl=127.0.0.1 auth-anonymous=1" --exit-idle-time=-1 > /dev/null 2>&1 &
sleep 1

# dummy /proc/bus/pci/devices path binding
touch ~/bind

# remove cache for clean-up xfce4 dirty session
proot-distro login debian --shared-tmp --no-sysvipc -- bash -c "rm -rf /root/.cache"

# start xfce4-session
proot-distro login debian --bind ~/bind:/proc/bus/pci/devices --shared-tmp --no-sysvipc -- bash -c "export DISPLAY=:0 PULSE_SERVER=tcp:127.0.0.1:4713; MESA_NO_ERROR=1 MESA_LOADER_DRIVER_OVERRIDE=zink TU_DEBUG=noconform MESA_GL_VERSION_OVERRIDE=4.6COMPAT MESA_GLES_VERSION_OVERRIDE=3.2 dbus-launch --exit-with-session xfce4-session"

위 dummy binding은 chrome 브라우저를 시작할 때 /proc/bus/pci/devices 경로를 체그합니다. 이때 proot 환경에서는 해당 path가 존재할 수 없기 때문에 시작할 때 더미로 생성하여 넘기는 것입니다.

 

시작하면 xfce4 정보에 아래와 같이 표시됩니다.

glxinfo 는 아래와 같이 표시됩니다.

root@localhost:~# glxinfo -B
name of display: :0.0
display: :0  screen: 0
direct rendering: Yes
Extended renderer info (GLX_MESA_query_renderer):
    Vendor: Mesa (0x5143)
    Device: zink Vulkan 1.3(Turnip Adreno (TM) 740 (MESA_TURNIP)) (0x43050a01)
    Version: 24.2.0
    Accelerated: yes
    Video memory: 8271MB
    Unified memory: yes
    Preferred profile: core (0x1)
    Max core profile version: 4.6
    Max compat profile version: 4.6
    Max GLES1 profile version: 1.1
    Max GLES[23] profile version: 3.2
Memory info (GL_ATI_meminfo):
    VBO free memory - total: 8269 MB, largest block: 8269 MB
    VBO free aux. memory - total: 0 MB, largest block: 0 MB
    Texture free memory - total: 8269 MB, largest block: 8269 MB
    Texture free aux. memory - total: 0 MB, largest block: 0 MB
    Renderbuffer free memory - total: 8269 MB, largest block: 8269 MB
    Renderbuffer free aux. memory - total: 0 MB, largest block: 0 MB
Memory info (GL_NVX_gpu_memory_info):
    Dedicated video memory: 8271 MB
    Total available memory: 8271 MB
    Currently available dedicated video memory: 8269 MB
OpenGL vendor string: Mesa
OpenGL renderer string: zink Vulkan 1.3(Turnip Adreno (TM) 740 (MESA_TURNIP))
OpenGL core profile version string: 4.6 (Compatibility Profile) Mesa 24.2.0-devel (git-93f790b04a)
OpenGL core profile shading language version string: 4.60
OpenGL core profile context flags: no-error
OpenGL core profile profile mask: compatibility profile

OpenGL version string: 4.6 (Compatibility Profile) Mesa 24.2.0-devel (git-93f790b04a)
OpenGL shading language version string: 4.60
OpenGL context flags: no-error
OpenGL profile mask: compatibility profile

OpenGL ES profile version string: OpenGL ES 3.2 Mesa 24.2.0-devel (git-93f790b04a)
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.20

glxgear 를 구동해보면

500프레임 이상으로 측정됩니다.

 

6. thorium-browser 에서 Web Aquarium

1000마리 기준으로 측정하였습니다.

https://webglsamples.org/aquarium/aquarium.html

아래는 zink 를 enable 한 상태의 스크린샷입니다.

llvmpipe 때 1000마리 7프레임 8프레임 나오던걸 생각하면 크게 성능이 향상되었습니다.

 

7. 기타

root@localhost:~# apt install vulkan-tools

root@localhost:~# apt install glmark2
root@localhost:~# glmark2
=======================================================
    glmark2 2023.01
=======================================================
    OpenGL Information
    GL_VENDOR:      Mesa
    GL_RENDERER:    zink Vulkan 1.3(Turnip Adreno (TM) 740 (MESA_TURNIP))
    GL_VERSION:     4.6 (Compatibility Profile) Mesa 24.2.0-devel (git-93f790b04a)
    Surface Config: buf=32 r=8 g=8 b=8 a=8 depth=24 stencil=0 samples=0
    Surface Size:   800x600 windowed
=======================================================
[build] use-vbo=false: FPS: 416 FrameTime: 2.406 ms
[build] use-vbo=true: FPS: 512 FrameTime: 1.956 ms
[texture] texture-filter=nearest: FPS: 516 FrameTime: 1.940 ms
[texture] texture-filter=linear: FPS: 496 FrameTime: 2.020 ms
[texture] texture-filter=mipmap: FPS: 501 FrameTime: 1.998 ms
[shading] shading=gouraud: FPS: 496 FrameTime: 2.019 ms
[shading] shading=blinn-phong-inf: FPS: 492 FrameTime: 2.034 ms
[shading] shading=phong: FPS: 463 FrameTime: 2.162 ms
[shading] shading=cel: FPS: 487 FrameTime: 2.054 ms
[bump] bump-render=high-poly: FPS: 419 FrameTime: 2.389 ms
[bump] bump-render=normals: FPS: 496 FrameTime: 2.017 ms
[bump] bump-render=height: FPS: 489 FrameTime: 2.048 ms
[effect2d] kernel=0,1,0;1,-4,1;0,1,0;: FPS: 425 FrameTime: 2.354 ms
[effect2d] kernel=1,1,1,1,1;1,1,1,1,1;1,1,1,1,1;: FPS: 346 FrameTime: 2.897 ms
[pulsar] light=false:quads=5:texture=false: FPS: 270 FrameTime: 3.710 ms
[desktop] blur-radius=5:effect=blur:passes=1:separable=true:windows=4: FPS: 282 FrameTime: 3.550 ms
[desktop] effect=shadow:windows=4: FPS: 356 FrameTime: 2.809 ms
[buffer] columns=200:interleave=false:update-dispersion=0.9:update-fraction=0.5:update-method=map: FPS: 247 FrameTime: 4.054 ms
[buffer] columns=200:interleave=false:update-dispersion=0.9:update-fraction=0.5:update-method=subdata: FPS: 227 FrameTime: 4.407 ms
[buffer] columns=200:interleave=true:update-dispersion=0.9:update-fraction=0.5:update-method=map: FPS: 267 FrameTime: 3.758 ms
[ideas] speed=duration: FPS: 253 FrameTime: 3.963 ms
[jellyfish] <default>: FPS: 358 FrameTime: 2.797 ms
[terrain] <default>: FPS: 141 FrameTime: 7.129 ms
[shadow] <default>: FPS: 358 FrameTime: 2.801 ms
[refract] <default>: FPS: 184 FrameTime: 5.460 ms
[conditionals] fragment-steps=0:vertex-steps=0: FPS: 434 FrameTime: 2.308 ms
[conditionals] fragment-steps=5:vertex-steps=0: FPS: 445 FrameTime: 2.251 ms
[conditionals] fragment-steps=0:vertex-steps=5: FPS: 458 FrameTime: 2.186 ms
[function] fragment-complexity=low:fragment-steps=5: FPS: 463 FrameTime: 2.161 ms
[function] fragment-complexity=medium:fragment-steps=5: FPS: 448 FrameTime: 2.232 ms
[loop] fragment-loop=false:fragment-steps=5:vertex-steps=5: FPS: 452 FrameTime: 2.215 ms
[loop] fragment-steps=5:fragment-uniform=false:vertex-steps=5: FPS: 446 FrameTime: 2.246 ms
[loop] fragment-steps=5:fragment-uniform=true:vertex-steps=5: FPS: 446 FrameTime: 2.244 ms
=======================================================
                                  glmark2 Score: 395 
=======================================================
root@localhost:~# 

반응형

댓글