How to get accelerated H.264 video decoding on Radeon GPUs?

Hi,

first of all, I have been working with Linux servers for 15 years as a system administrator so I'm not new to the world of UNIX-based OSes, but absolutely new to BSDs of any kind. After having used Linux for such a long time, I wanted to try something else and also, get a bit more familiar with BSD so a few days ago I decided to reinstall my home PC with FreeBSD, replacing my good old CentOS 7 system I have used (and kind-of liked) for many years. No regrets, so far! :)

I'm currently running FreeBSD 12.0-CURRENT with all the updates installed, my graphics card is a Radeon HD 7750:

Code:
root@nb:~ # uname -a
FreeBSD nb 12.0-CURRENT FreeBSD 12.0-CURRENT #0 r331740: Thu Mar 29 21:24:24 UTC 2018     root@releng3.nyi.freebsd.org:/usr/obj/usr/src/amd64.amd64/sys/GENERIC  amd64

Code:
root@nb:~ # pciconf -lv | grep -A 4 'vgapci0@pci0:1:0:0'
vgapci0@pci0:1:0:0:    class=0x030000 card=0xe213174b chip=0x683f1002 rev=0x00 hdr=0x00
    vendor     = 'Advanced Micro Devices, Inc. [AMD/ATI]'
    device     = 'Cape Verde PRO [Radeon HD 7750/8740 / R7 250E]'
    class      = display
    subclass   = VGA

I have built and installed the new DRM modules from drm-next-kmod using the Ports system and also rebuilt mesa-dri to have VAAPI and VDPAU support enabled. That's basically everything I have done so far, except for installing some packages I need using the pkg install command.

Some relevant packages and their versions:

Code:
[nb@nb /usr/home/nb]$ for pkg in mesa-dri xf86-video-amdgpu drm-next-kmod; do pkg info $pkg | head -n1; done
mesa-dri-17.3.1_1
xf86-video-amdgpu-1.3.0_1
drm-next-kmod-4.11.g20180224

The amdgpu KMS module is loaded at boot-time through the setting kld_list="amdgpu" in /etc/rc.conf. The module loads and cooperates absolutely fine with the amdgpu video driver as all the usual desktop effects work correctly within GNOME and no errors are logged to /var/log/Xorg.0.log.

After successfully rebuilding mesa-dri with VDPAU and VAAPI support enabled, I can see VDPAU is present but only with limited codec support:

Code:
[nb@nb /usr/home/nb]$ vdpauinfo
display: :0   screen: 0
API version: 1
Information string: G3DVL VDPAU Driver Shared Library version 1.0

Video surface:

name   width height types
-------------------------------------------
420    16384 16384  NV12 YV12 
422    16384 16384  UYVY YUYV 
444    16384 16384  Y8U8V8A8 V8U8Y8A8 

Decoder capabilities:

name                        level macbs width height
----------------------------------------------------
MPEG1                           0 1048576 16384 16384
MPEG2_SIMPLE                    3 1048576 16384 16384
MPEG2_MAIN                      3 1048576 16384 16384
H264_BASELINE                  --- not supported ---
H264_MAIN                      --- not supported ---
H264_HIGH                      --- not supported ---
VC1_SIMPLE                     --- not supported ---
VC1_MAIN                       --- not supported ---
VC1_ADVANCED                   --- not supported ---
MPEG4_PART2_SP                 --- not supported ---
MPEG4_PART2_ASP                --- not supported ---
DIVX4_QMOBILE                  --- not supported ---
DIVX4_MOBILE                   --- not supported ---
DIVX4_HOME_THEATER             --- not supported ---
DIVX4_HD_1080P                 --- not supported ---
DIVX5_QMOBILE                  --- not supported ---
DIVX5_MOBILE                   --- not supported ---
DIVX5_HOME_THEATER             --- not supported ---
DIVX5_HD_1080P                 --- not supported ---
H264_CONSTRAINED_BASELINE      --- not supported ---
H264_EXTENDED                  --- not supported ---
H264_PROGRESSIVE_HIGH          --- not supported ---
H264_CONSTRAINED_HIGH          --- not supported ---
H264_HIGH_444_PREDICTIVE       --- not supported ---
HEVC_MAIN                      --- not supported ---
HEVC_MAIN_10                   --- not supported ---
HEVC_MAIN_STILL                --- not supported ---
HEVC_MAIN_12                   --- not supported ---
HEVC_MAIN_444                  --- not supported ---

Output surface:

name              width height nat types
----------------------------------------------------
B8G8R8A8         16384 16384    y  NV12 YV12 UYVY YUYV Y8U8V8A8 V8U8Y8A8 A8I8 I8A8 
R8G8B8A8         16384 16384    y  NV12 YV12 UYVY YUYV Y8U8V8A8 V8U8Y8A8 A8I8 I8A8 
R10G10B10A2      16384 16384    y  NV12 YV12 UYVY YUYV Y8U8V8A8 V8U8Y8A8 A8I8 I8A8 
B10G10R10A2      16384 16384    y  NV12 YV12 UYVY YUYV Y8U8V8A8 V8U8Y8A8 A8I8 I8A8 

Bitmap surface:

name              width height
------------------------------
B8G8R8A8         16384 16384
R8G8B8A8         16384 16384
R10G10B10A2      16384 16384
B10G10R10A2      16384 16384
A8               16384 16384

Video mixer:

feature name                    sup
------------------------------------
DEINTERLACE_TEMPORAL             y
DEINTERLACE_TEMPORAL_SPATIAL     -
INVERSE_TELECINE                 -
NOISE_REDUCTION                  y
SHARPNESS                        y
LUMA_KEY                         y
HIGH QUALITY SCALING - L1        y
HIGH QUALITY SCALING - L2        -
HIGH QUALITY SCALING - L3        -
HIGH QUALITY SCALING - L4        -
HIGH QUALITY SCALING - L5        -
HIGH QUALITY SCALING - L6        -
HIGH QUALITY SCALING - L7        -
HIGH QUALITY SCALING - L8        -
HIGH QUALITY SCALING - L9        -

parameter name                  sup      min      max
-----------------------------------------------------
VIDEO_SURFACE_WIDTH              y        48    16384
VIDEO_SURFACE_HEIGHT             y        48    16384
CHROMA_TYPE                      y  
LAYERS                           y         0        4

attribute name                  sup      min      max
-----------------------------------------------------
BACKGROUND_COLOR                 y  
CSC_MATRIX                       y  
NOISE_REDUCTION_LEVEL            y      0.00     1.00
SHARPNESS_LEVEL                  y     -1.00     1.00
LUMA_KEY_MIN_LUMA                y  
LUMA_KEY_MAX_LUMA                y

Note that the GPU is UVD4.0 compliant and therefore it should support quite a few codecs, including H.264.

Could someone please assist how do I get hardware accelerated support for H.264 playback? Is this because H.264 decoding is not implemented (yet) in the amdgpu driver or it's just not enabled by default and I have to rebuild some of the relevant packages with custom options?

If this won't work with the amdgpu driver then I'd be very grateful to get some help to make DRI work with the "classic" open-source radeon driver, if possible. I have read that the lack of KMS support in the FreeBSD kernel caused quite some delay to implement multimedia features that are present in Linux for many years but maybe there's still hope to make this work somehow.

This is a little bit off-topic but my first impression is that FreeBSD rocks, it's amazing to see how well-maintained, logical and professional the codebase and the development process is, not to mention the detailed, understandable (for IT professionals, at least) and regulalry updated docs and the good & helpful community that has evolved around the project. It was a really refreshing first impression after confusingly watching what's happening to Linux-based OSes during the last few years. Besides a few minor bugs I have seen so far, FreeBSD definitely looks to be a very good choice for UNIX-oriented IT professionals - even as a desktop, as it seems! Only if I could get HW accelerated decoding for H.264.... ;)

Your help is much appreciated!

Thanks,
Gergely
 
Check the notes on wiki , hardware-assisted video decoding is not yet working/implemented on Radeon video cards. btw, check this topic too about what versions of fBSD are supported on this forum.
 
The unfortunate truth is that full GPU support is pretty much limited to Nvidia, using the proprietary FreeBSD driver from NVidia. drm-stable-kmod and drm-next-kmod from ports enable some functionality for AMD and Intel GPUs. By the way, this would also be the case for 11.1 and 11-STABLE.

Current may not be your best option, as kernel DRM support and compatibility with the kmod port can be all over the place, sometimes it works, sometimes it doesn't.

I have h.264 working on an old Celeron in an Intel NUC (FreeBSD 12-CURRENT with drm-stable-kmod). That being said, that HTPC box will be replaced and the new box will have a NVidia card, even though I do not like NVidia very much and would have prefered to buy an AMD APU.
 
Thanks for the replies, so far!

xchris I have already checked the wiki page you mentioned but I thought that just goes to the current STABLE and RELEASE versions, that's why I replaced the RELEASE version I installed at first with CURRENT. Regarding your note about supported FreeBSD versions, I haven't read that topic until now, so please bear with me. I understand that development version cannot be supported due to many reasons. In case HW acceleration would not work even with the CURRENT release then I think I'll just return to RELEASE for now. I can live without HW acceleration as my PC has a pretty fast CPU which can easily decode even 4K videos without any issues.

recluce I have a feeling FreeBSD is more rigorous about "supported features" compared to any flavour of Linux out there. If the dev team supports a feature then it just works (with some minor bugs, if any :)) but if not, then users are pretty much out of luck. This, of course, has its pros but it definitely looks like a major difference compared to Linux-based distributions where users try to workaround issues and find alternative solutions. As I wrote above, I think I'll switch back to RELEASE for now and maybe get an NVIDIA card if I have a chance.
 
In the meantime I managed to replace my Radeon card with an NVIDIA GTS 450. It has quite similar capabilities and performance as the Radeon card but seems to be much better supported on FreeBSD. After going back to 11.1-RELEASE and installing the proprietary NVIDIA driver, now I have 3D acceleration and full VDPAU support, including HW-assisted H.264 decoding.
 
Back
Top