Skip to content

[UNTESTED] Highly experimental H264 support for G45/CTG#11

Draft
irql-notlessorequal wants to merge 8 commits intomasterfrom
experimental-g45-h264
Draft

[UNTESTED] Highly experimental H264 support for G45/CTG#11
irql-notlessorequal wants to merge 8 commits intomasterfrom
experimental-g45-h264

Conversation

@irql-notlessorequal
Copy link
Owner

@irql-notlessorequal irql-notlessorequal commented Mar 17, 2025

I'm leaving this out for several releases since this is a mess.

My gripes with it is that:

  1. This isn't real hardware acceleration, I mean sure, it runs on the GPU alright but this is just doing the number crunching on it, no actual dedicated silicon.
  2. It's very bug prone and likely to just hang your GPU.
  3. GPU configurations vary the maximum resolution, meaning that the luckiest users will be able to handle 1080p30/720p60.
  4. No VPP support, meaning that Chromium WILL NOT work with this generation of hardware.

I'm leaving this PR here for the poor souls that want to test this.

As of writing, this is using the unmodified shaders for CTG, they might work or they might not.

Please leave feedback here, or yell at me to make a dedicated issue tracker for this specific issue.

Compiling this requires setting -Denable_h264_ctg=true in Meson or --enable-h264-ctg in Make.

@irql-notlessorequal irql-notlessorequal self-assigned this Mar 17, 2025
@irql-notlessorequal irql-notlessorequal linked an issue Apr 15, 2025 that may be closed by this pull request
@w8jcik
Copy link

w8jcik commented Apr 17, 2025

Could you suggest which software might make use of this acceleration? Is it VLC, MPlayer, ffmpeg?

I can see pretty clear in the README.md that this solution offers Functioning Chromium support (except for G45 of course). Is Firefox more problematic or less problematic, or simply different? Does it have a chance to work?

@irql-notlessorequal
Copy link
Owner Author

irql-notlessorequal commented Apr 17, 2025

Could you suggest which software might make use of this acceleration? Is it VLC, MPlayer, ffmpeg?

I can see pretty clear in the README.md that this solution offers Functioning Chromium support (except for G45 of course). Is Firefox more problematic or less problematic, or simply different? Does it have a chance to work?

Assuming it works (probably need to rebase the changes and add some missing patches), most software should be able to take advantage of it, Chromium is the odd one out because it is using VPP [1] (post-processing using GPU shaders) to convert the raw NV12 image you get from decoding into BGRA unlike everyone else.

[1] This isn't supported on G45 because the GPU is way more limited in capabilities (to be fair it is a very old integrated graphics solution) and Intel didn't provide any shaders to do conversion with.

This enables the code path for CTG/G45 H.264 support.

Currently does nothing.
@irql-notlessorequal irql-notlessorequal force-pushed the experimental-g45-h264 branch 4 times, most recently from 6c47e93 to 5e27f28 Compare June 18, 2025 11:23
@w8jcik
Copy link

w8jcik commented Jul 5, 2025

I tried this branch

$ git clone --depth 1 --branch experimental-g45-h264 https://github.com/irql-notlessorequal/intel-vaapi-driver.git
$ cd intel-vaapi-driver
$ ./autogen.sh
$ ./configure --enable-h264-ctg LIBVA_DRIVERS_PATH="$(pwd)"
$ make install -j $(nproc)
$ sudo cp i965_drv_video.so /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so
$ sudo vainfo
Trying display: wayland
error: XDG_RUNTIME_DIR is invalid or not set in the environment.
Trying display: x11
libva info: VA-API version 1.22.0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/iHD_drv_video.so
libva info: Found init function __vaDriverInit_1_22
libva error: /usr/lib/x86_64-linux-gnu/dri/iHD_drv_video.so init failed
libva info: va_openDriver() returns 1
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so
libva info: Found init function __vaDriverInit_1_22
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.22 (libva 2.22.0)
vainfo: Driver version: Intel i965 driver for Intel(R) GM45 Express Chipset - 2.4.5.pre1 ()
vainfo: Supported profile and entrypoints
      VAProfileMPEG2Simple            :	VAEntrypointVLD
      VAProfileMPEG2Main              :	VAEntrypointVLD

Support for H264 is not listed. I would expect following lines

      VAProfileH264ConstrainedBaseline:	VAEntrypointVLD
      VAProfileH264Main               :	VAEntrypointVLD
      VAProfileH264High               :	VAEntrypointVLD

My GPU is GMA 4500MHD (CTG) and I saw H264 being listed by vainfo with some other forks of intel-vaapi-driver

$ inxi -G
Graphics:
  Device-1: Intel Mobile 4 Series Integrated Graphics driver: i915 v: kernel
  Display: wayland server: X.Org v: 24.1.2 with: Xwayland v: 24.1.2
    compositor: gnome-shell v: 47.0 driver: X: loaded: modesetting
    unloaded: fbdev,vesa dri: crocus gpu: i915 resolution: 1280x800~60Hz
  API: EGL v: 1.5 drivers: crocus,swrast
    platforms: gbm,wayland,x11,surfaceless,device
  API: OpenGL v: 4.5 compat-v: 2.1 vendor: intel mesa
    v: 24.2.8-1ubuntu1~24.10.1 renderer: Mesa Mobile Intel GM45 Express (CTG)

The switch to enable H264 in CTG seems to be accepted during building

$ cat config.log | grep ENABLE_CTG
#define I965_H264_ENABLE_CTG 1

This modification by Bitbucket user alium makes the H264 entry appear in vainfo output https://github.com/w8jcik/intel-vaapi-driver/pull/1/files. Maybe it can help diagnose the issue.

At the first glance I would expect this declaration to be involved

.has_h264_decoding = 1,

But as far as I can tell, it is set to 1 on both branches. So maybe H264 entry appears only after successful initialization and initialization is failing at some point.

@irql-notlessorequal
Copy link
Owner Author

I reached the same result while I was updating the branch and pulling in additional changes on the G45 test machine that I have, when I get a moment to set it up again I'll go figure out why it isn't exposing H264 support.

@jonathan-teh
Copy link

This is missing some includes:

--- a/src/i965_device_info.c
+++ b/src/i965_device_info.c
@@ -23,6 +23,7 @@
  *
  */
 
+#include "sysdeps.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include "i965_drv_video.h"
--- a/src/i965_media.h
+++ b/src/i965_media.h
@@ -30,6 +30,8 @@
 #ifndef _I965_MEDIA_H_
 #define _I965_MEDIA_H_
 
+#include "sysdeps.h"
+
 #include <xf86drm.h>
 #include <drm.h>
 #include <i915_drm.h>

so that the code paths relying on I965_H264_ENABLE_CTG being defined are actually built.

With that, the expected H.264 profiles are returned:

$ vainfo
Trying display: wayland
libva info: VA-API version 1.22.0
libva info: Trying to open /usr/lib64/dri-nonfree/iHD_drv_video.so
libva info: Trying to open /usr/lib64/dri-freeworld/iHD_drv_video.so
libva info: Trying to open /usr/lib64/dri/iHD_drv_video.so
libva info: va_openDriver() returns -1
libva info: Trying to open /usr/lib64/dri-nonfree/i965_drv_video.so
libva info: Trying to open /usr/lib64/dri-freeworld/i965_drv_video.so
libva info: Trying to open /usr/lib64/dri/i965_drv_video.so
libva info: Found init function __vaDriverInit_1_22
error: failed to resolve wl_drm_interface(): /lib64/libEGL_mesa.so.0: undefined symbol: wl_drm_interface
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.22 (libva 2.22.0)
vainfo: Driver version: Intel i965 driver for Intel(R) GM45 Express Chipset - 2.4.5.pre1 (2.4.4-14-g5c668ce0)
vainfo: Supported profile and entrypoints
      VAProfileMPEG2Simple            : VAEntrypointVLD
      VAProfileMPEG2Main              : VAEntrypointVLD
      VAProfileH264ConstrainedBaseline: VAEntrypointVLD
      VAProfileH264Main               : VAEntrypointVLD
      VAProfileH264High               : VAEntrypointVLD

Playing a video with mpv 0.40 in Fedora 43 LXQt (miriway as the Wayland compositor):

$ mpv --fs --hwdec=auto-safe --profile=fast big_buck_bunny_720p_h264.mov
[lavf] Failed to convert channel layout 6 channels (FC+FL+FR+SL+SR+LFE) to mpv one!                                                                             
● Video  --vid=1  --vlang=eng  (h264 1280x720 24 fps) [default]                 
● Audio  --aid=1  --alang=eng  (aac 48000 Hz 438 kbps) [default]
[vo/gpu/libplacebo] Found no suitable device, giving up.
[vo/gpu/libplacebo] Failed initializing vulkan device                           
[vo/gpu/libplacebo] Found no suitable device, giving up.                        
[vo/gpu/libplacebo] Failed initializing vulkan device                           
Cannot load libcuda.so.1                                                        
error: failed to resolve wl_drm_interface(): /lib64/libEGL_mesa.so.0: undefined symbol: wl_drm_interface
[ffmpeg] AVHWFramesContext: Failed to create surface: 14 (the requested RT Format is not supported).                                                            
[ffmpeg] AVHWFramesContext: Unable to allocate a surface from internal buffer pool.                                                                             
[ffmpeg] AVHWFramesContext: Failed to create surface: 14 (the requested RT Format is not supported).                                                            
[ffmpeg] AVHWFramesContext: Unable to allocate a surface from internal buffer pool.                                                                             
Using hardware decoding (vaapi).                                                
AO: [pipewire] 48000Hz 5.1 6ch floatp
VO: [gpu] 1280x720 vaapi[nv12]
AV: 00:00:01 / 00:09:56 (0%) A-V: -0.000 Cache: 240s/150MB 
Exiting... (Quit)

pauses for a few seconds and then the screen comes up a solid green with the audio playing.

dmesg shows:

[ 4235.747467] i915 0000:00:02.0: [drm] GPU HANG: ecode 4:1:8eeefed5, in vo [5561]
[ 4235.747647] i915 0000:00:02.0: [drm] GT0: Resetting chip for stopped heartbeat on rcs0
[ 4235.850213] i915 0000:00:02.0: [drm] vo[5561] context reset due to GPU hang

Same result with a 480p24 H.264 video. My understanding is this needs a much larger allocation of video memory than the 32MiB provided by the BIOS but this Lenovo T400 does not have an option to change it.

@SiliconExarch
Copy link

I've tried this with the above includes patch on my HP Touchsmart tm2 with the most favourable video memory allocation (64MB pre-allocated + 224MB DVMT) however the outcome is the same - a GPU hang followed by a green screen in mpv, no matter whether the video is 480i, 720p or 1080p

Presumably this must have worked at some point, however I'm not super invested so I'll probably just stick to using the dedicated ATI HD4550 to decode video and put up with the reduced battery life that entails.

@averagenokiauser
Copy link

I tried this with the patch above on ThinkPad T500 with QX9300 and Libreboot and i am having the same issue. I just get a green screen.

@jonathan-teh
Copy link

There were some details in the section removed from the Arch Linux wiki on Intel graphics, in particular this November 2019 post on the guix-patches mailing list that says a 256MB video RAM allocation on a Librebooted ThinkPad T400 worked with the previous version of this patch, at least with the software stack at the time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

h264 support for G45

5 participants