From: José Maldonado Subject: Re: Enable VA-API in graphics/ffmpeg To: Landry Breuil Cc: ports@openbsd.org Date: Sun, 28 Jul 2024 15:24:40 -0400 El dom, 28 jul 2024 a la(s) 4:59 a.m., Landry Breuil (landry@openbsd.org) escribió: > > Le Sun, Jul 28, 2024 at 09:43:55AM +0200, Landry Breuil a écrit : > > with the latest version of the patchset, i have something that doesnt > crash, but fails to properly initialize vaapi: > > [(null) 51070: Main Thread]: D/Dmabuf DMABufDevice::Configure() > [(null) 51070: Main Thread]: D/Dmabuf Loading DMABuf system library libgbm.so ... > [(null) 51070: Main Thread]: D/Dmabuf Using DRM device /dev/dri/renderD128 > [(null) 51070: Main Thread]: D/Dmabuf DMABuf is enabled > drmfd preopened, fd=12 > [(null) 51070: Main Thread]: D/OpenBSDSandbox /tmp: unveil(/tmp, rwc) > [(null) 51070: Main Thread]: D/OpenBSDSandbox /etc/firefox/pledge.rdd: pledge(stdio rpath tmppath recvfd sendfd unix) > [RDD 51070: MediaSupervisor #1]: D/FFmpegVideo FFMPEG: FFmpegVideoDecoder::FFmpegVideoDecoder MIME video/avc Codec ID 27 > [RDD 51070: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: Initialising VA-API FFmpeg decoder > [RDD 51070: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: codec h264 : H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 > [RDD 51070: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: Can't get DRM VA-API display. > [RDD 51070: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: Failed to create VA-API device context > > the gfxvars object isnt initialized yet, so it requires > MOZ_DRM_DEVICE=/dev/dri/renderD128 in the env to find the right device. > > Landry In my case, when I create the symlinks (for libgbm and libdrm), I can obtain VAAPI support (and DMAbuf work fine), short log (using Firefox 128.0.2): MOZ_LOG="FFmpegVideo:5,Dmabuf:5,OpenBSDSandbox:5" MOZ_GFX_DEBUG=1 firefox GLX_TEST: childgltest start GLX_TEST: get_pci_status start GLX_TEST: get_pci_status finished GLX_TEST: x11_egltest start GLX_TEST: get_egl_status start GLX_TEST: get_egl_gl_status start GLX_TEST: get_egl_gl_status finished GLX_TEST: get_egl_status finished with return: 1 GLX_TEST: get_xrandr_info start GLX_TEST: get_xrandr_info finished GLX_TEST: x11_egltest finished DRI_DRIVER radeonsi VENDOR AMD RENDERER AMD Radeon RX 580 Series (radeonsi, polaris10, LLVM 16.0.6, DRM 3.54, 7.5) VERSION 4.6 (Compatibility Profile) Mesa 23.3.6 TFP TRUE DRM_RENDERDEVICE /dev/dri/renderD128 MESA_VENDOR_ID 0x1002 MESA_DEVICE_ID 0x67df DDX_DRIVER AMD Radeon RX 580 Series @ pci:0000:2b:00.0; TEST_TYPE EGL GLX_TEST: childgltest finished [Parent 32023: Main Thread]: D/Dmabuf DMABufDevice::Configure() [Parent 32023: Main Thread]: D/Dmabuf Loading DMABuf system library libgbm.so.1 ... [Parent 32023: Main Thread]: D/Dmabuf Using DRM device /dev/dri/renderD128 [Parent 32023: Main Thread]: D/Dmabuf DMABuf is enabled vaapitest start, device /dev/dri/renderD128 libva info: VA-API version 1.22.0 libva info: Trying to open /usr/X11R6/lib/modules/dri/radeonsi_drv_video.so libva info: Found init function __vaDriverInit_1_22 libva info: va_openDriver() returns 0 vaInitialize finished Profile: H264ConstrainedBaseline Profile: H264Main Profile: H264High vaapitest finished VAAPI_SUPPORTED TRUE VAAPI_HWCODECS 16 ... [RDD 9892: MediaSupervisor #1]: D/FFmpegVideo FFMPEG: FFmpegVideoDecoder::FFmpegVideoDecoder MIME video/avc Codec ID 27 [RDD 9892: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: Initialising VA-API FFmpeg decoder [RDD 9892: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: codec h264 : H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 [RDD 9892: MediaPDecoder #1]: D/Dmabuf DMABufDevice::Configure() [RDD 9892: MediaPDecoder #1]: D/Dmabuf Loading DMABuf system library libgbm.so.1 ... [RDD 9892: MediaPDecoder #1]: D/Dmabuf Using DRM device /dev/dri/renderD128 [RDD 9892: MediaPDecoder #1]: D/Dmabuf DMABuf is enabled libva info: VA-API version 1.22.0 libva info: Trying to open /usr/X11R6/lib/modules/dri/radeonsi_drv_video.so libva info: Found init function __vaDriverInit_1_22 /usr/X11R6/share/libdrm/amdgpu.ids: No such file or directory libva info: va_openDriver() returns 0 [RDD 9892: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: FFmpegVideoDecoder::GetAcceleratedFormats() [RDD 9892: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: Profile H264ConstrainedBaseline: [RDD 9892: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: codec h264 format nv12 3 12 [RDD 9892: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: codec h264 format nv12 3 12 [RDD 9892: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: codec h264 format p010le 3 15 [RDD 9892: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: Profile H264Main: [RDD 9892: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: codec h264 format nv12 3 12 [RDD 9892: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: codec h264 format nv12 3 12 [RDD 9892: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: codec h264 format p010le 3 15 [RDD 9892: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: Profile H264High: [RDD 9892: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: codec h264 format nv12 3 12 [RDD 9892: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: codec h264 format nv12 3 12 [RDD 9892: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: codec h264 format p010le 3 15 [RDD 9892: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: Supported accelerated formats: [RDD 9892: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: h264 [RDD 9892: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: VA-API FFmpeg init successful [RDD 9892: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: FFmpegDataDecoder: shutdown [RDD 9892: MediaSupervisor #1]: D/FFmpegVideo FFMPEG: FFmpegVideoDecoder::FFmpegVideoDecoder MIME video/avc Codec ID 27 [RDD 9892: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: Initialising VA-API FFmpeg decoder [RDD 9892: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: Format h264 is accelerated [RDD 9892: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: codec h264 : H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 /usr/X11R6/share/libdrm/amdgpu.ids: No such file or directory [AVHWDeviceContext @ 0x3862695bb80] Format 0x3231564e -> nv12. [AVHWDeviceContext @ 0x3862695bb80] Format 0x30313050 -> p010le. [AVHWDeviceContext @ 0x3862695bb80] Format 0x36313050 -> unknown. [AVHWDeviceContext @ 0x3862695bb80] Format 0x30323449 -> yuv420p. [AVHWDeviceContext @ 0x3862695bb80] Format 0x32315659 -> yuv420p. [AVHWDeviceContext @ 0x3862695bb80] Format 0x56595559 -> unknown. [AVHWDeviceContext @ 0x3862695bb80] Format 0x32595559 -> yuyv422. [AVHWDeviceContext @ 0x3862695bb80] Format 0x59565955 -> uyvy422. [AVHWDeviceContext @ 0x3862695bb80] Format 0x30303859 -> gray. [AVHWDeviceContext @ 0x3862695bb80] Format 0x50343434 -> yuv444p. [AVHWDeviceContext @ 0x3862695bb80] Format 0x50424752 -> unknown. [AVHWDeviceContext @ 0x3862695bb80] Format 0x41524742 -> bgra. [AVHWDeviceContext @ 0x3862695bb80] Format 0x41424752 -> rgba. [AVHWDeviceContext @ 0x3862695bb80] Format 0x42475241 -> argb. [AVHWDeviceContext @ 0x3862695bb80] Format 0x58524742 -> bgr0. [AVHWDeviceContext @ 0x3862695bb80] Format 0x58424752 -> rgb0. [AVHWDeviceContext @ 0x3862695bb80] VAAPI driver: Mesa Gallium driver 23.3.6 for AMD Radeon Graphics (radeonsi, polaris10, LLVM 16.0.6, DRM 3.54, 7.5). [AVHWDeviceContext @ 0x3862695bb80] Driver not found in known nonstandard list, using standard behaviour. [h264 @ 0x385b7535800] nal_unit_type: 7(SPS), nal_ref_idc: 3 [h264 @ 0x385b7535800] nal_unit_type: 8(PPS), nal_ref_idc: 3 [RDD 9892: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: VA-API FFmpeg init successful [RDD 9892: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: FFmpegDataDecoder: shutdown [RDD 9892: MediaSupervisor #1]: D/FFmpegVideo FFMPEG: FFmpegVideoDecoder::FFmpegVideoDecoder MIME video/avc Codec ID 27 [RDD 9892: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: Initialising VA-API FFmpeg decoder [RDD 9892: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: Format h264 is accelerated [RDD 9892: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: codec h264 : H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 ... [RDD 9892: MediaPDecoder #3]: D/Dmabuf DMABUFSurfaceImage::DMABUFSurfaceImage (385db4610f0) aSurface 38628adb000 UID 2 [RDD 9892: MediaPDecoder #3]: D/Dmabuf VideoFrameSurface: VAAPI releasing dmabuf surface UID 2 FFMPEG ID 0x15 aForFrameRecycle 1 mLib 38650b65840 mAVHWFrameContext 38620f9be40 mHWAVBuffer 385db47e640 [RDD 9892: MediaPDecoder #3]: D/Dmabuf DMABufSurfaceYUV::ReleaseSurface() UID 2 [RDD 9892: MediaPDecoder #3]: D/Dmabuf DMABufSurfaceYUV::ReleaseTextures() UID 2 [RDD 9892: MediaPDecoder #3]: D/Dmabuf DMABufSurface::ReleaseDMABuf() UID 2 [RDD 9892: MediaSupervisor #3]: D/Dmabuf DMABufSurfaceYUV::Serialize() UID 2 [RDD 9892: MediaSupervisor #3]: D/Dmabuf DMABufSurfaceYUV::Serialize() UID 2 [Parent 32023: Compositor]: D/Dmabuf DMABufSurfaceYUV::ImportSurfaceDescriptor() UID 2 [h264 @ 0x38558ea3000] nal_unit_type: 1(Coded slice of a non-IDR picture), nal_ref_idc: 2 [h264 @ 0x38558ea3000] Param buffer (type 0, 672 bytes) is 0x1b. [h264 @ 0x38558ea3000] Param buffer (type 1, 240 bytes) is 0x1c. [h264 @ 0x38558ea3000] Slice 0 param buffer (3128 bytes) is 0x1d. [h264 @ 0x38558ea3000] Slice 0 data buffer (20300 bytes) is 0x1e. [h264 @ 0x38558ea3000] Decode to surface 0x14. [RDD 9892: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: Frame decode takes 0.16 ms average decode time 0.21 ms frame duration 16.68 average frame duration 16.68 decoded 317 frames [RDD 9892: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: VA-API Got one frame output with pts=5271933 dts=5271933 duration=16683 [RDD 9892: MediaPDecoder #1]: D/Dmabuf Using VA-API DMABufSurface UID 2 FFMPEG ID 0x17 [RDD 9892: MediaPDecoder #1]: D/Dmabuf Surface pool size 1 used copied 0 used ffmpeg 0 (max 17) free ratio 1.000000 [RDD 9892: MediaPDecoder #1]: D/Dmabuf DMABufSurfaceYUV::UpdateYUVData() UID 2 copy 0 [RDD 9892: MediaPDecoder #1]: D/Dmabuf DMABufSurfaceYUV::ImportPRIMESurfaceDescriptor() UID 2 [RDD 9892: MediaPDecoder #1]: D/Dmabuf plane 0 size 1920 x 1080 format 20203852 [RDD 9892: MediaPDecoder #1]: D/Dmabuf plane 1 size 960 x 540 format 38385247 [RDD 9892: MediaPDecoder #1]: D/Dmabuf VideoFrameSurface: VAAPI locking dmabuf surface UID 2 FFMPEG ID 0x17 mAVHWFrameContext 385f4ce5000 mHWAVBuffer 385a383a280 [RDD 9892: MediaPDecoder #1]: D/Dmabuf DMABUFSurfaceImage::DMABUFSurfaceImage (385f4cd3410) aSurface 38628adb000 UID 2 [RDD 9892: MediaPDecoder #1]: D/Dmabuf VideoFrameSurface: VAAPI releasing dmabuf surface UID 2 FFMPEG ID 0x17 aForFrameRecycle 1 mLib 38650b65840 mAVHWFrameContext 385f4ce5000 mHWAVBuffer 385a383a280 [RDD 9892: MediaPDecoder #1]: D/Dmabuf DMABufSurfaceYUV::ReleaseSurface() UID 2 [RDD 9892: MediaPDecoder #1]: D/Dmabuf DMABufSurfaceYUV::ReleaseTextures() UID 2 [RDD 9892: MediaPDecoder #1]: D/Dmabuf DMABufSurface::ReleaseDMABuf() UID 2 [RDD 9892: MediaSupervisor #3]: D/Dmabuf DMABufSurfaceYUV::Serialize() UID 2 [RDD 9892: MediaSupervisor #3]: D/Dmabuf DMABufSurfaceYUV::Serialize() UID 2 [Parent 32023: Compositor]: D/Dmabuf DMABufSurfaceYUV::ImportSurfaceDescriptor() UID 2 [RDD 9892: MediaSupervisor #3]: D/Dmabuf DMABUFSurfaceImage::~DMABUFSurfaceImage (385db461780) mSurface 38628adb000 UID 2 [Parent 32023: Compositor]: D/Dmabuf DMABufSurfaceYUV::ReleaseSurface() UID 2 [Parent 32023: Compositor]: D/Dmabuf DMABufSurfaceYUV::ReleaseTextures() UID 2 [Parent 32023: Compositor]: D/Dmabuf DMABufSurface::ReleaseDMABuf() UID 2 [RDD 9892: MediaSupervisor #3]: D/Dmabuf DMABUFSurfaceImage::~DMABUFSurfaceImage (385db4610f0) mSurface 38628adb000 UID 2 [RDD 9892: MediaSupervisor #3]: D/Dmabuf DMABUFSurfaceImage::~DMABUFSurfaceImage (385f4cd3410) mSurface 38628adb000 UID 2 [Parent 32023: Compositor]: D/Dmabuf DMABufSurfaceYUV::ReleaseSurface() UID 2 [Parent 32023: Compositor]: D/Dmabuf DMABufSurfaceYUV::ReleaseTextures() UID 2 [Parent 32023: Compositor]: D/Dmabuf DMABufSurface::ReleaseDMABuf() UID 2 [RDD 9892: MediaPDecoder #3]: D/FFmpegVideo FFMPEG: ProcessFlush() [Parent 32023: Compositor]: D/Dmabuf DMABufSurfaceYUV::ReleaseSurface() UID 2 [RDD 9892: MediaPDecoder #3]: D/FFmpegVideo FFMPEG: FFmpegDataDecoder: flushing buffers [Parent 32023: Compositor]: D/Dmabuf DMABufSurfaceYUV::ReleaseTextures() UID 2 [Parent 32023: Compositor]: D/Dmabuf DMABufSurface::ReleaseDMABuf() UID 2 [RDD 9892: MediaPDecoder #1]: D/Dmabuf ~VideoFrameSurface: deleting dmabuf surface UID 2 [RDD 9892: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: FFmpegDataDecoder: shutdown When I delete the symlinks, I obtain this (fail VAAPI init and not DMAbuf) GLX_TEST: childgltest start GLX_TEST: get_pci_status start GLX_TEST: get_pci_status finished GLX_TEST: x11_egltest start GLX_TEST: get_egl_status start GLX_TEST: get_egl_gl_status start GLX_TEST: get_egl_gl_status finished GLX_TEST: get_egl_status finished with return: 1 GLX_TEST: get_xrandr_info start GLX_TEST: get_xrandr_info finished GLX_TEST: x11_egltest finished DRI_DRIVER radeonsi VENDOR AMD RENDERER AMD Radeon RX 580 Series (radeonsi, polaris10, LLVM 16.0.6, DRM 3.54, 7.5) VERSION 4.6 (Compatibility Profile) Mesa 23.3.6 TFP TRUE DRM_RENDERDEVICE /dev/dri/renderD128 MESA_VENDOR_ID 0x1002 MESA_DEVICE_ID 0x67df DDX_DRIVER AMD Radeon RX 580 Series @ pci:0000:2b:00.0; TEST_TYPE EGL GLX_TEST: childgltest finished [Parent 62454: Main Thread]: D/Dmabuf DMABufDevice::Configure() [Parent 62454: Main Thread]: D/Dmabuf Loading DMABuf system library libgbm.so.1 ... [Parent 62454: Main Thread]: D/Dmabuf Failed to load libgbm.so.1, dmabuf isn't available. [Parent 62454: Main Thread]: D/Dmabuf GbmLib is not available! vaapitest start, device /dev/dri/renderD128 libva info: VA-API version 1.22.0 libva info: Trying to open /usr/X11R6/lib/modules/dri/radeonsi_drv_video.so libva info: Found init function __vaDriverInit_1_22 libva info: va_openDriver() returns 0 vaInitialize finished Profile: H264ConstrainedBaseline Profile: H264Main Profile: H264High vaapitest finished VAAPI_SUPPORTED TRUE VAAPI_HWCODECS 16 ... [RDD 77513: MediaSupervisor #1]: D/FFmpegVideo FFMPEG: FFmpegVideoDecoder::FFmpegVideoDecoder MIME video/avc Codec ID 27 [RDD 77513: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: Initialising VA-API FFmpeg decoder [RDD 77513: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: codec h264 : H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 [RDD 77513: MediaPDecoder #1]: D/Dmabuf DMABufDevice::Configure() [RDD 77513: MediaPDecoder #1]: D/Dmabuf Loading DMABuf system library libgbm.so.1 ... [RDD 77513: MediaPDecoder #1]: D/Dmabuf Failed to load libgbm.so.1, dmabuf isn't available. [RDD 77513: MediaPDecoder #1]: D/Dmabuf GbmLib is not available! [RDD 77513: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: Can't get DRM VA-API display. [RDD 77513: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: Failed to create VA-API device context [RDD 77513: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: Initialising FFmpeg decoder [RDD 77513: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: codec h264 : H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 [RDD 77513: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: Set get_buffer2 for customized buffer allocation [h264 @ 0x34c86bff800] Requested frame threading with a custom get_buffer2() implementation which is not marked as thread safe. This is not supported anymore, make your callback thread-safe. [RDD 77513: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: FFmpeg decoder init successful. [RDD 77513: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: FFmpegDataDecoder: shutdown [RDD 77513: MediaSupervisor #1]: D/FFmpegVideo FFMPEG: FFmpegVideoDecoder::FFmpegVideoDecoder MIME video/avc Codec ID 27 [RDD 77513: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: Initialising VA-API FFmpeg decoder [RDD 77513: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: codec h264 : H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 [RDD 77513: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: Can't get DRM VA-API display. [RDD 77513: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: Failed to create VA-API device context [RDD 77513: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: Initialising FFmpeg decoder [RDD 77513: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: codec h264 : H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 [RDD 77513: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: Set get_buffer2 for customized buffer allocation [h264 @ 0x34c210c3800] Requested frame threading with a custom get_buffer2() implementation which is not marked as thread safe. This is not supported anymore, make your callback thread-safe. [RDD 77513: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: FFmpeg decoder init successful. [RDD 77513: MediaPDecoder #1]: D/FFmpegVideo FFMPEG: FFmpegDataDecoder: shutdown Now, about what you say about the solution with symbolic links, the truth is that THIS is not a solution, it is horrible. The correct solution is to patch upstream or directly make a patch for OpenBSD and apply it in the compilation to correct the hardcode of the Firefox libraries and to look for the correct names/versions in OpenBSD. As for preloading the libraries to keep access to a minimum and keep the sandbox safe, it is fine, it is the way to go, especially with the experiences you have had before. I am just saying that everything seems to indicate that both libgbm and libdrm must be there for VAAPI to work correctly. And if it is possible to do it globally, so that it is not only RDD that has that access, it could be beneficial when using DMabuf in loads such as WebGL where it is also used a lot. Also as you mention here (https://bugzilla.mozilla.org/show_bug.cgi?id=1840272) it paves the way for us to test on Wayland, where many things are directly related to DMAbuf (https://bugzilla.mozilla.org/show_bug.cgi?id=1586696 - https://bugzilla.mozilla.org/show_bug.cgi?id=1619523) Regarding the scope of DMAbuf in OpenBSD DRM, this could be answered by @jsg, I think he is the one who has more knowledge about DRM and its capabilities in OpenBSD. -- "Dios en su Cielo, todo bien en la Tierra" ***********************************************