X Window Systemã使ã£ã¦ãªã¢ã¼ããµã¼ãã§OpenGLãªããã°ã©ã ãèµ°ãããæ¹æ³
åæ©
SSHã§ãã°ã¤ã³ãããªã¢ã¼ããµã¼ãï¼SSHãµã¼ãï¼ä¸ã§OpenGLã«ããGUIã¢ããªã±ã¼ã·ã§ã³ãåããããã¼ã«ã«ã³ã³ãã¥ã¼ã¿ï¼SSHã¯ã©ã¤ã¢ã³ãï¼ã®ç»é¢ã«è¡¨ç¤ºããããã¨ãã®ã¡ã¢æ¸ãã
TL; DR
- SSHã¯ã©ã¤ã¢ã³ãï¼Xãµã¼ãï¼å´ã§ãXèµ·åæã«
+iglx
ãªãã·ã§ã³ã ssh -XY
ã§ãã°ã¤ã³ããã- ãã¼ã«ã«ã¨ãªã¢ã¼ãã§
libGL.so
ã®ç³»åãæããå¿ è¦ãããããã¼ã«ã«ãmesaãªããªã¢ã¼ããmesaã«åããããLD_PRELOAD
ç°å¢å¤æ°ã使ãã
åè
- OpenGL hardware acceleration through remote X11 SSH connection « Evgeny Pokhilko's Weblog
- Using the GUI on a remote machine — Installation 2017 documentation
åºæ¬äºé
X Window System
ããããããããã£ã¹ãã¬ã¤ä¸ã§ã¦ã£ã³ãã¦ã·ã¹ãã ãæä¾ãã表示ãããã³ã«ãï¼wikipediaããå¼ç¨ï¼ãGUIãæ§ç¯ããããã®åºæ¬çãªãã¼ã«ããããæä¾ãããå®éã«çµµã表示ãããç»é¢ã管çãããXãµã¼ããããã¼ã¢ã³ã¨ãã¦å®è¡ããåGUIããã°ã©ã ï¼GnomeãAwesomeWMã®ãããªã¦ã£ã³ãã¦ããã¼ã¸ã£ããã®ä»ã®GUIã¢ããªã±ã¼ã·ã§ã³ãªã©ï¼ã¯ãXã¯ã©ã¤ã¢ã³ããã¨ãªã£ã¦Xãµã¼ãã«æç»å½ä»¤ãéä¿¡ãããXãµã¼ãã»Xã¯ã©ã¤ã¢ã³ãéã®éä¿¡ãããã³ã«ãX Window Systemã®ä¸é¨ã¨ãã¦è¦å®ããã¦ããã
LinuxãGUIãã·ã³ã¨ãã¦ç¨ããå ´åãæ®éã¯X Window Systemã®ãªãã¡ã¬ã³ã¹å®è£ ã§ããXorgã使ã£ã¦ããã¨æã£ã¦å·®ãæ¯ããªãï¼2018/01ç¾å¨ãä»å¾Waylandã¨ãæ°ããã®ã主æµã«ãªããããããªããããã§ã¯å²æï¼ã
ãªããXãµã¼ãã¨Xã¯ã©ã¤ã¢ã³ãã¯å¥ã®ãã·ã³ã§åãã¦ãã¦ãè¯ãããã ãããã¼ã«ã«ã³ã³ãã¥ã¼ã¿ï¼SSHã¯ã©ã¤ã¢ã³ãï¼ãããªã¢ã¼ããµã¼ãï¼SSHãµã¼ãï¼ã«ã¢ã¯ã»ã¹ãããªã¢ã¼ããµã¼ãä¸ã§å®è¡ããGUIã¢ããªã±ã¼ã·ã§ã³ã®ç»é¢ããã¼ã«ã«ã³ã³ãã¥ã¼ã¿ã«è¡¨ç¤ºããå ´åãX Window Systemã®è¦³ç¹ããè¦ãã¨ãã¼ã«ã«ã³ã³ãã¥ã¼ã¿ã§ãXãµã¼ãããã¼ã¢ã³ãå®è¡ããã¦ããããªã¢ã¼ããµã¼ãä¸ã§åããGUIã¢ããªã±ã¼ã·ã§ã³ããXã¯ã©ã¤ã¢ã³ããã¨ãªã£ã¦ãã®Xãµã¼ãã«æ¥ç¶ãããã¨ã«ãªããSSHãµã¼ãã¨SSHã¯ã©ã¤ã¢ã³ãã®é¢ä¿ã¨ã¯éåããªã®ã§æ··ä¹±ããªããã注æã
OpenGL
2D/3Dã®ã³ã³ãã¥ã¼ã¿ã°ã©ãã£ãã¯ã¹APIãæç»ã®ã³ã¢æ©è½ã¯ã½ããã¦ã§ã¢ã©ã¤ãã©ãªã§ã¯ãªã対å¿ããGPUä¸ã«ãã¼ãã¦ã§ã¢å®è£ ãããããä¸è¬ã«ãOpenGLãã¨å¼ã¶ã¨ãã¯ãã®ãã¼ãã¦ã§ã¢å®è£ ãã½ããã¦ã§ã¢ããå©ç¨ããããã®API群ãæãã
GLX
Xãµã¼ããåãã¦ãããã®ã¨åããã·ã³ã§OpenGLã¢ããªã±ã¼ã·ã§ã³ãå®è¡ããã¨ãããã®ã¢ããªã±ã¼ã·ã§ã³ã¯Xã¯ã©ã¤ã¢ã³ãã¨ãã¦ã¦ã£ã³ãã¦ã®ãæ ã ããã¯Xãµã¼ãã«ç®¡çãã¦ãããã¤ã¤*1ããã®ãæ ãã®ä¸ã«è¡¨ç¤ºããçµµï¼ã¤ã¾ã3D CGï¼ã¯GPUã«ç´æ¥ï¼X Window Systemãä»ããï¼æç»å½ä»¤ãéã£ã¦ã¬ã³ããªã³ã°ããããããdirect renderingã¨å¼ã¶ã
ããã§ãXãµã¼ãã¨OpenGLã¢ããªã±ã¼ã·ã§ã³ï¼Xã¯ã©ã¤ã¢ã³ãï¼ãç°ãªãã³ã³ãã¥ã¼ã¿ã§åãã¦ããå ´åãå½ç¶OpenGLã¢ããªã±ã¼ã·ã§ã³ã¯Xãµã¼ããåãã¦ãããã·ã³ã®GPUã«ç´æ¥ã¢ã¯ã»ã¹ãããã¨ã¯ã§ãããXã®éä¿¡ãããã³ã«ã®æ çµã¿ã®ä¸ã§GPUã«æç»å½ä»¤ãéãå¿ è¦ãããããã®ããã«Xãä»ãã¦OpenGLã®æç»å½ä»¤ãéããã¨ãindirect renderingã¨å¼ã³ããã®indirect renderingãå®ç¾ããããã«Xã®éä¿¡ãããã³ã«ãæ¡å¼µããAPIå®ç¾©ãGLXã§ããã
Xãµã¼ãï¼ãã¼ã«ã«ã³ã³ãã¥ã¼ã¿ï¼ã®è¨å®
è¨äºå·çæç¹ã§ææ°ã®Xorgã¯1.19ç³»åã ããXorg1.17以éãXãµã¼ãã¨å¥ã®ãã·ã³ã§åãXã¯ã©ã¤ã¢ã³ãããã®GLXã¢ã¯ã»ã¹ã¯ããã©ã«ãã§æå¦ããããã«ãªã£ã¦ããã®ã§ãããã許å¯ãããããã¯ãXãµã¼ããåãã¦ãããã¼ã«ã«ã³ã³ãã¥ã¼ã¿ï¼ã¤ã¾ãSSHã¯ã©ã¤ã¢ã³ãï¼ã§ãXï¼/usr/bin/Xorg
ï¼ãèµ·åããéã«+iglx
ãªãã·ã§ã³ãã¤ãããã¨ã§å®ç¾ã§ããã
ãã¼ã«ã«ã³ã³ãã¥ã¼ã¿ãèµ·åããéã«ã©ãã§Xãèµ·åããã¦ãããã¯åãã·ã³ã®è¨å®ã«ä¾ãã®ã§çµ±ä¸çãªãã¨ã¯è¨ããªãããå¤ãã®ç°å¢ã§ã¯lightdmãgdmã®ãããªdisplay managerãXãèµ·åãã責任ãæã¤ãçè ã¯ubuntuã¨archlinuxãå©ç¨ãã¦ããããããã®ç°å¢ã§ãlightdmãdisplay managerã¨ãã¦ç¨ãã¦ããï¼ubuntuã§ã¯lightdmãããã©ã«ãï¼ãããä¾ã¨ãã¦lightdmã®è¨å®ã示ãã
Ubuntuã®å ´åã/etc/lightdm/lightdm.conf.d/
以ä¸ã«50-xserver-command.conf
ãã¡ã¤ã«ãä½ãã以ä¸ã®2è¡ãæå®ããã
[SeatDefaults] xserver-command=X -core +iglx
Archlinuxã§pacmançµç±ã§lightdmãã¤ã³ã¹ãã¼ã«ããå ´åã/etc/lightdm/lightdm.conf
ã«ãã§ã«xserver-command
ã®ãã¬ã¼ã¹ãã«ããç¨æããã¦ããããããããç·¨éããã°è¯ãã
ãªã¢ã¼ããµã¼ãã«æ¥ç¶
SSHã®ã³ãã¯ã·ã§ã³ã®ä¸ã§Xã®éä¿¡ãããã³ã«ãæ±ããããã«ããX11 Forwardingãç¨ãã¦ãªã¢ã¼ããµã¼ãã«æ¥ç¶ãããssh -XY
ã³ãã³ããªãã·ã§ã³ã使ããã$HOME/.ssh/config
ã§ForwadX11 yes
ããã³ForwardX11Trusted yes
ãæå®ããã
ãªããä¸è¬ã«SSHãµã¼ãä¸ã§GUIã¢ããªã±ã¼ã·ã§ã³ãåããããã«ã¯ForwardX11 yes
ã¤ã¾ãssh -X
ã ãã§ååã§ããããForwardX11ã¯Xã®éä¿¡ãããã³ã«ã®ä¸é¨ãç¡å¹åãããããã¯Xããã¼å
¥åãªã©ã®æ
å ±ãæ±ã£ã¦ãããããXã¯ã©ã¤ã¢ã³ãã«æªæãããå ´åã¯Xãµã¼ããåãã¦ãããã·ã³ã®æ©å¯æ
å ±ãçã¾ãã¦ãã¾ãå±éºãããããã ãããã®ã¨ãç¡å¹åããããã®ã®ä¸ã«GLXãå«ã¾ããã
ãããã£ã¦GLXã使ããããã«ããããã«ã¯ãSSHãµã¼ãä¸ã§åãXã¯ã©ã¤ã¢ã³ãããä¿¡é ¼ãããå¿
è¦ãããããã®ããã®ãªãã·ã§ã³ãForwardX11Trusted yes
ã¤ã¾ãssh -Y
ã³ãã³ããªãã·ã§ã³ã§ãã*2ã
å¥è§£ï¼éæ¨å¥¨ï¼
/usr/bin/Xorg
ãèµ·åããéã-listen tcp
ãªãã·ã§ã³ãã¤ãããã¨ã§SSHã¨ã¯å¥ã«Xå°ç¨ã®TCPã³ãã¯ã·ã§ã³ãå¼µããã¨ãã§ããããããããã®ããã«ã¯Xãµã¼ãã®è©²å½ãã¼ãã¯ãã¡ã¤ã¤ã¦ã©ã¼ã«ã«ç©´ãéããå¿
è¦ããããXãµã¼ãã¨Xã¯ã©ã¤ã¢ã³ãã®èªè¨¼ãxauth
ã使ã£ã¦ç¬èªã«ç®¡çããå¿
è¦ããããªã©ãæéã¨ã»ãã¥ãªãã£ãªã¹ã¯ã大ãããããæ¬ç¨¿ã§ã¯æ¨å¥¨ããªãããã ããSSHã®æå·åããã»ã¹ãªã©ããã¹ã¦ã¹ããããããã¨ã«ããããã©ã¼ãã³ã¹ã¯æ大åãããããããã»ã©æ§è½è¦æ±ãå³ããå ´åã«ã¯æ¤è¨ãã¦ãè¯ããããããªãããå¾ãããæ§è½åä¸ã¯ããã¾ã§å¤§ãããªãã
OpenGLã¢ããªã±ã¼ã·ã§ã³ã®å®è¡
以ä¸ã®æé ãè¸ãã§ãªã¢ã¼ããµã¼ãã§OpenGLã¢ããªã±ã¼ã·ã§ã³ãå®è¡ããã°ããã¼ã«ã«ã³ã³ãã¥ã¼ã¿ã®ç»é¢ã«ãã®çµæã表示ãããã¨ãã§ããã¯ãã§ããã
ããããå ´åã«ãã£ã¦ã¯ä»¥ä¸ã®ãããªã¨ã©ã¼ã«ããã¢ããªã±ã¼ã·ã§ã³ããã¾ãèµ·åããªããã¨ãããï¼glxgears
ã¯æ¯è»ãå転ããã¢ãã¡ã¼ã·ã§ã³ã®OpenGLã®ãã¢ããã°ã©ã ï¼ã
$ glxgears X Error of failed request: 255 Major opcode of failed request: 155 (GLX) Minor opcode of failed request: 1 (X_GLXRender) Serial number of failed request: 898 Current serial number in output stream: 1064
ããã¯æ§ã
ãªçç±ã«ãã£ã¦èµ·ããããä¸æ¦ã«åå ã示ããã¨ãã§ããªãããããããåå ã¨ãã¦ããã¼ã«ã«ã¨ãªã¢ã¼ãã§libGL.so
ã®ä¸èº«ãéããã¨ãããã®ããããlibGL.so
ã¯ä¸è¬ã«GPUãã©ã¤ãã®ä¸é¨ã¨ãã¦ããã±ã¼ã¸ããã¦ãããAPIã¯OpenGLã®è¦æ ¼ã«å¾ã£ã¦æ´åããã¦ããããå
é¨ã®å®è£
ã¯GPUãã³ãã¾ãã¯ãã©ã¤ãã®é
å¸å
ã«ãã£ã¦ãã©ãã©ã§ããã
ä¸ä¾ã¨ãã¦ãnVidiaã®GeForceãç©ãã ãªã¢ã¼ããµã¼ãï¼nVidiaã®ãããã©ã¤ã¨ã¿ãªãªãã©ã¤ããå
¥ã£ã¦ããï¼ã«ãintelã®CPUçµ±åã°ã©ãã£ãã¯ã¹ãããªããã¼ã«ã«ãã·ã³ï¼mesaã®ãªã¼ãã³ã½ã¼ã¹ãã©ã¤ãã§åãã¦ããï¼ã§æ¥ç¶ããã¨ãããããã®ã¨ãããªã¢ã¼ããµã¼ãã§åããOpenGLã¢ããªã±ã¼ã·ã§ã³ã¯nVidiaã®ãã©ã¤ãã«å«ã¾ããlibGL.so
ããªã³ã¯ãã¦ä½¿ç¨ããããnVidiaã®libGL.so
ã«ãã£ã¦çæãããGLXã®ã³ãã³ãããã¼ã«ã«ã®Xãµã¼ãã«éã£ã¦ãããã¼ã«ã«ã®Xãµã¼ããGPUãé§åããããã«å©ç¨ãã¦ããmesaã®libGL.so
ã¯ãã®GLXã³ãã³ãã解éã§ãããä¸è¨ã®ãããªã¨ã©ã¼ã¨ãªãã
ããã解決ããããã«ã¯ããªã¢ã¼ãã§åããOpenGLã¢ããªã±ã¼ã·ã§ã³ããmesaã®ãlibGL.so
ãå©ç¨ããããã«å¼·å¶ãã¦ããã°è¯ããããã«ã¯LD_PRELOAD
ç°å¢å¤æ°ã使ããã¤ã¾ã
export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0 glxgears
ã®ããã«ãããã¨ã§æ£å¸¸ã«èµ·åããããã«ãªãã¨æãï¼LD_PRELOAD
ã®å¤ã¯åèªã®ãã¼ã«ã«ã§åãã¦ããGPUããµã¼ãã§åãã¦ããOSã®ç¨®é¡ã«ããç°ãªãï¼ããã ããæç»æ§è½ã¯å£æ»
çã§ããå ´åãå¤ããç¾ä»£çãªGPUãç©ãã ãã·ã³ã§glxgears
ãå®è¡ããã¨æ°ä¸FPSã«éãããã¨ãããããã ãããã®æ¹æ³ã§ã§ã¯ãããã5FPSç¨åº¦ã«ãªããããã¯ã©ããããããªãã®ã§ã解決ããããã°ãµã¼ãã«ç©ãã§ãããã®ã¨åããã³ãã®GPUãè²·ããããªãã
*1:OpenGLã¢ããªã±ã¼ã·ã§ã³ããã«ã¹ã¯ãªã¼ã³ã§å®è¡ããå ´åã¯ã¦ã£ã³ãã¦æ ã®ç®¡çãä¸è¦ã«ãªãã®ã§ä¸æ¦Xãç¡å¹åãã¦GPUã®ã¬ã³ããªã³ã°çµæã ããç´æ¥ç»é¢ã«éãã®ãï¼ãã®è¾ºã¯åå¼·ä¸è¶³ã§ããããã£ã¦ããªã
*2:ãã®ã¨ãssh -Yã¯ãXã¯ã©ã¤ã¢ã³ããä¿¡é ¼ãããã ãã§ãããå®éã«ãXãããã³ã«ãforwardãããã¨ããæå³ã¯å«ã¾ãªãããããã£ã¦-Xãªãã§-Yã ãæå®ãã¦ãGUIã¢ããªã±ã¼ã·ã§ã³ãåãããªããã¨ã«æ³¨æ