Intel N100のQSVをUbuntu22.04で使う

話題のIntel N100(Alder Lake-N)な格安小型PCを買いました。
Amazonで大体2.2万円くらいでした。

QSVを目的に買ったのですが、Ubuntu 22.04でそのままでは動かなかったため、動くようにするメモです。

## 結論を先に
とりあえず、結論はIntel N100が新しすぎることでした。
色々調べた結果として、カーネル？が対応していないことが原因のようだったので、以下を実行したら使えるようになりました。

```sh
sudo apt install linux-generic-hwe-22.04
sudo reboot
```

## やったこと
QSVをさくっと動かしたかったので、QSVEncCを入れてみました

https://github.com/rigaya/QSVEnc/blob/master/Install.ja.md#linux-ubuntu-2204

```sh
$ sudo apt-get install -y gpg-agent wget
$ wget -qO - https://repositories.intel.com/graphics/intel-graphics.key | \
  sudo gpg --dearmor --output /usr/share/keyrings/intel-graphics.gpg
$ echo 'deb [arch=amd64,i386 signed-by=/usr/share/keyrings/intel-graphics.gpg] https://repositories.intel.com/graphics/ubuntu jammy arc' | \
  sudo tee  /etc/apt/sources.list.d/intel.gpu.jammy.list
$ sudo apt-get update
$ sudo apt install intel-media-va-driver-non-free intel-opencl-icd
$ sudo gpasswd -a ${USER} video
$ sudo gpasswd -a ${USER} render
$ wget https://github.com/rigaya/QSVEnc/releases/download/7.57/qsvencc_7.57_Ubuntu22.04_amd64.deb
$ sudo apt install ./qsvencc_7.57_Ubuntu22.04_amd64.deb
```

しかし、動かない
```sh
$ qsvencc --check-hw
DRMLibVA::DRMLibVA: Intel GPU was not found
Failed to initialize HW Device.: lose the HW acceleration device..
DRMLibVA::DRMLibVA: Intel GPU was not found
DRMLibVA::DRMLibVA: Intel GPU was not found
Failed to initialize HW Device.: lose the HW acceleration device..
DRMLibVA::DRMLibVA: Intel GPU was not found
Error: QuickSyncVideo (hw encoding) unavailable
QSVEncC.exe finished with error!
```

vainfoで見てみる
```sh
$ sudo apt install vainfo
$ sudo vainfo
Trying display: wayland
error: XDG_RUNTIME_DIR not set in the environment.
Trying display: x11
error: can't connect to X server!
Trying display: drm
error: failed to initialize display
```

intel-gpu-toolsもみてみる
```sh
$ sudo apt install intel-gpu-tools
$ sudo intel_gpu_top
No device filter specified and no discrete/integrated i915 devices found
```

全然ダメそう

色々調べてたら、以下の記事にたどり着きました

https://askubuntu.com/questions/1475673/is-it-normal-that-my-intel-n100-server-has-no-gpu-drivers-loaded-on-22-04-can-i

> The latest linux-image-generic-hwe-22.04 is 6.2.0.26.26~22.04.7 (i.e. Linux Kernel 6.2), and now it supports Intel N100's UHD Graphics:

最新のhwe(よくわからない)とやらを入れたら動くっぽいようなので実行
```sh
$ sudo apt install linux-generic-hwe-22.04
$ sudo reboot
```

そしたら、動きそうな感じになりました

```
$ qsvencc --check-hw
libva info: VA-API version 1.18.0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/iHD_drv_video.so
libva info: Found init function __vaDriverInit_1_18
libva info: va_openDriver() returns 0
libva info: VA-API version 1.18.0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/iHD_drv_video.so
libva info: Found init function __vaDriverInit_1_18
libva info: va_openDriver() returns 0
libva info: VA-API version 1.18.0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/iHD_drv_video.so
libva info: Found init function __vaDriverInit_1_18
libva info: va_openDriver() returns 0
Success: QuickSyncVideo (hw encoding) available
Supported Encode Codecs for device auto:
libva info: VA-API version 1.18.0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/iHD_drv_video.so
libva info: Found init function __vaDriverInit_1_18
libva info: VA-API version 1.18.0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/iHD_drv_video.so
libva info: Found init function __vaDriverInit_1_18
libva info: VA-API version 1.18.0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/iHD_drv_video.so
libva info: VA-API version 1.18.0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/iHD_drv_video.so
libva info: VA-API version 1.18.0
libva info: Found init function __vaDriverInit_1_18
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/iHD_drv_video.so
libva info: VA-API version 1.18.0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/iHD_drv_video.so
libva info: Found init function __vaDriverInit_1_18
libva info: Found init function __vaDriverInit_1_18
libva info: Found init function __vaDriverInit_1_18
libva info: VA-API version 1.18.0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/iHD_drv_video.so
libva info: VA-API version 1.18.0
libva info: Found init function __vaDriverInit_1_18
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/iHD_drv_video.so
libva info: Found init function __vaDriverInit_1_18
libva info: VA-API version 1.18.0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/iHD_drv_video.so
libva info: VA-API version 1.18.0
libva info: Found init function __vaDriverInit_1_18
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/iHD_drv_video.so
libva info: Found init function __vaDriverInit_1_18
libva info: va_openDriver() returns 0
libva info: va_openDriver() returns 0
libva info: va_openDriver() returns 0
libva info: va_openDriver() returns 0
libva info: va_openDriver() returns 0
libva info: va_openDriver() returns 0
libva info: va_openDriver() returns 0
libva info: va_openDriver() returns 0
libva info: va_openDriver() returns 0
libva info: va_openDriver() returns 0
H.264/AVC PG
H.264/AVC FF
H.265/HEVC PG
H.265/HEVC FF
VP9 FF
```


```sh
$ sudo vainfo
Trying display: wayland
error: XDG_RUNTIME_DIR not set in the environment.
Trying display: x11
error: can't connect to X server!
Trying display: drm
libva info: VA-API version 1.18.0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/iHD_drv_video.so
libva info: Found init function __vaDriverInit_1_18
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.18 (libva 2.18.0)
vainfo: Driver version: Intel iHD driver for Intel(R) Gen Graphics - 23.2.1 ()
vainfo: Supported profile and entrypoints
      VAProfileNone                   :	VAEntrypointVideoProc
      VAProfileNone                   :	VAEntrypointStats
      VAProfileMPEG2Simple            :	VAEntrypointVLD
      VAProfileMPEG2Simple            :	VAEntrypointEncSlice
      VAProfileMPEG2Main              :	VAEntrypointVLD
      VAProfileMPEG2Main              :	VAEntrypointEncSlice
      VAProfileH264Main               :	VAEntrypointVLD
      VAProfileH264Main               :	VAEntrypointEncSlice
      VAProfileH264Main               :	VAEntrypointFEI
      VAProfileH264Main               :	VAEntrypointEncSliceLP
      VAProfileH264High               :	VAEntrypointVLD
      VAProfileH264High               :	VAEntrypointEncSlice
      VAProfileH264High               :	VAEntrypointFEI
      VAProfileH264High               :	VAEntrypointEncSliceLP
      VAProfileVC1Simple              :	VAEntrypointVLD
      VAProfileVC1Main                :	VAEntrypointVLD
      VAProfileVC1Advanced            :	VAEntrypointVLD
      VAProfileJPEGBaseline           :	VAEntrypointVLD
      VAProfileJPEGBaseline           :	VAEntrypointEncPicture
      VAProfileH264ConstrainedBaseline:	VAEntrypointVLD
      VAProfileH264ConstrainedBaseline:	VAEntrypointEncSlice
      VAProfileH264ConstrainedBaseline:	VAEntrypointFEI
      VAProfileH264ConstrainedBaseline:	VAEntrypointEncSliceLP
      VAProfileVP8Version0_3          :	VAEntrypointVLD
      VAProfileHEVCMain               :	VAEntrypointVLD
      VAProfileHEVCMain               :	VAEntrypointEncSlice
      VAProfileHEVCMain               :	VAEntrypointFEI
      VAProfileHEVCMain               :	VAEntrypointEncSliceLP
      VAProfileHEVCMain10             :	VAEntrypointVLD
      VAProfileHEVCMain10             :	VAEntrypointEncSlice
      VAProfileHEVCMain10             :	VAEntrypointEncSliceLP
      VAProfileVP9Profile0            :	VAEntrypointVLD
      VAProfileVP9Profile0            :	VAEntrypointEncSliceLP
      VAProfileVP9Profile1            :	VAEntrypointVLD
      VAProfileVP9Profile1            :	VAEntrypointEncSliceLP
      VAProfileVP9Profile2            :	VAEntrypointVLD
      VAProfileVP9Profile2            :	VAEntrypointEncSliceLP
      VAProfileVP9Profile3            :	VAEntrypointVLD
      VAProfileVP9Profile3            :	VAEntrypointEncSliceLP
      VAProfileHEVCMain12             :	VAEntrypointVLD
      VAProfileHEVCMain12             :	VAEntrypointEncSlice
      VAProfileHEVCMain422_10         :	VAEntrypointVLD
      VAProfileHEVCMain422_10         :	VAEntrypointEncSlice
      VAProfileHEVCMain422_12         :	VAEntrypointVLD
      VAProfileHEVCMain422_12         :	VAEntrypointEncSlice
      VAProfileHEVCMain444            :	VAEntrypointVLD
      VAProfileHEVCMain444            :	VAEntrypointEncSliceLP
      VAProfileHEVCMain444_10         :	VAEntrypointVLD
      VAProfileHEVCMain444_10         :	VAEntrypointEncSliceLP
      VAProfileHEVCMain444_12         :	VAEntrypointVLD
      VAProfileHEVCSccMain            :	VAEntrypointVLD
      VAProfileHEVCSccMain            :	VAEntrypointEncSliceLP
      VAProfileHEVCSccMain10          :	VAEntrypointVLD
      VAProfileHEVCSccMain10          :	VAEntrypointEncSliceLP
      VAProfileHEVCSccMain444         :	VAEntrypointVLD
      VAProfileHEVCSccMain444         :	VAEntrypointEncSliceLP
      VAProfileAV1Profile0            :	VAEntrypointVLD
      VAProfileHEVCSccMain444_10      :	VAEntrypointVLD
      VAProfileHEVCSccMain444_10      :	VAEntrypointEncSliceLP
```