From 91137f5929dad7655f3bb4e9a6122e0519cd091d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= <sandro.jaeckel@gmail.com>
Date: Mon, 21 Nov 2022 01:29:32 +0100
Subject: [PATCH 1/2] intel-media-driver: 22.5.3.1 -> 22.6.3

---
 .../libraries/intel-media-driver/32bit.patch  | 22 +++++++++++++++++++
 .../libraries/intel-media-driver/default.nix  | 14 +++++-------
 2 files changed, 28 insertions(+), 8 deletions(-)
 create mode 100644 pkgs/development/libraries/intel-media-driver/32bit.patch

diff --git a/pkgs/development/libraries/intel-media-driver/32bit.patch b/pkgs/development/libraries/intel-media-driver/32bit.patch
new file mode 100644
index 000000000000..ddeeea66e3b8
--- /dev/null
+++ b/pkgs/development/libraries/intel-media-driver/32bit.patch
@@ -0,0 +1,22 @@
+diff --git a/media_softlet/linux/common/ddi/media_libva_util_next.cpp b/media_softlet/linux/common/ddi/media_libva_util_next.cpp
+index 66fab63de..a2cdf79d7 100644
+--- a/media_softlet/linux/common/ddi/media_libva_util_next.cpp
++++ b/media_softlet/linux/common/ddi/media_libva_util_next.cpp
+@@ -2195,8 +2195,8 @@ void MediaLibvaUtilNext::MediaPrintFps()
+ 
+         int64_t diff  = (tv2.tv_sec - m_tv1.tv_sec)*1000000 + tv2.tv_usec - m_tv1.tv_usec;
+         float fps     = m_frameCountFps / (diff / 1000000.0);
+-        DDI_NORMALMESSAGE("FPS:%6.4f, Interval:%11lu.", fps,((uint64_t)tv2.tv_sec)*1000 + (tv2.tv_usec/1000));
+-        sprintf(temp,"FPS:%6.4f, Interval:%11lu\n", fps,((uint64_t)tv2.tv_sec)*1000 + (tv2.tv_usec/1000));
++        DDI_NORMALMESSAGE("FPS:%6.4f, Interval:%11llu.", fps,((uint64_t)tv2.tv_sec)*1000 + (tv2.tv_usec/1000));
++        sprintf(temp,"FPS:%6.4f, Interval:%11llu\n", fps,((uint64_t)tv2.tv_sec)*1000 + (tv2.tv_usec/1000));
+ 
+         MOS_ZeroMemory(fpsFileName,LENGTH_OF_FPS_FILE_NAME);
+         sprintf(fpsFileName, FPS_FILE_NAME);
+@@ -2213,4 +2213,4 @@ void MediaLibvaUtilNext::MediaPrintFps()
+     pthread_mutex_unlock(&m_fpsMutex);
+     return;
+ }
+-#endif
+\ No newline at end of file
++#endif
diff --git a/pkgs/development/libraries/intel-media-driver/default.nix b/pkgs/development/libraries/intel-media-driver/default.nix
index 925cd2eeb8f8..4f5f8fc28613 100644
--- a/pkgs/development/libraries/intel-media-driver/default.nix
+++ b/pkgs/development/libraries/intel-media-driver/default.nix
@@ -16,7 +16,7 @@
 
 stdenv.mkDerivation rec {
   pname = "intel-media-driver";
-  version = "22.5.3.1";
+  version = "22.6.3";
 
   outputs = [ "out" "dev" ];
 
@@ -24,7 +24,7 @@ stdenv.mkDerivation rec {
     owner = "intel";
     repo = "media-driver";
     rev = "intel-media-${version}";
-    sha256 = "sha256-3l8mfw1h1se0+w4VtfMr0xuPW8G3JA6hbvkyCaEGTek=";
+    sha256 = "sha256-lQg+L64DW2ZIBeJRimNkba7EL+SM4jSnX9PWIx4j2AY=";
   };
 
   patches = [
@@ -33,12 +33,10 @@ stdenv.mkDerivation rec {
       url = "https://salsa.debian.org/multimedia-team/intel-media-driver-non-free/-/raw/master/debian/patches/0002-Remove-settings-based-on-ARCH.patch";
       sha256 = "sha256-f4M0CPtAVf5l2ZwfgTaoPw7sPuAP/Uxhm5JSHEGhKT0=";
     })
-    # fix compilation on i686-linux
-    (fetchpatch {
-      url = "https://github.com/intel/media-driver/commit/5ee502b84eb70f0d677a3b49d624c356b3f0c2b1.patch";
-      revert = true;
-      sha256 = "sha256-yRS10BKD5IkW8U0PxmyB7ryQiLwrqeetm0NivnoM224=";
-    })
+  ] ++ lib.optional stdenv.is32bit [
+    # fix compilation on i686-linux but also breaks x86_64
+    # a similar issue got fixed in https://github.com/intel/media-driver/pull/1493 but thats to much C magic for me
+    ./32bit.patch
   ];
 
   cmakeFlags = [

From 8cdb30946686bf45cba20f28ca5ef57060c9ebc6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= <sandro.jaeckel@gmail.com>
Date: Mon, 21 Nov 2022 01:30:39 +0100
Subject: [PATCH 2/2] libva: add intel-media-driver to passthru.tests

---
 pkgs/development/libraries/libva/default.nix | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/pkgs/development/libraries/libva/default.nix b/pkgs/development/libraries/libva/default.nix
index 045b060a04fb..0ded7e20088e 100644
--- a/pkgs/development/libraries/libva/default.nix
+++ b/pkgs/development/libraries/libva/default.nix
@@ -3,6 +3,7 @@
 , minimal ? false, libva-minimal
 , libX11, libXext, libXfixes, wayland, libffi, libGL
 , mesa
+, intel-media-driver
 }:
 
 stdenv.mkDerivation rec {
@@ -29,6 +30,10 @@ stdenv.mkDerivation rec {
     "-Ddriverdir=${mesa.drivers.driverLink}/lib/dri:/usr/lib/dri:/usr/lib32/dri:/usr/lib/x86_64-linux-gnu/dri:/usr/lib/i386-linux-gnu/dri"
   ];
 
+  passthru.tests = {
+    inherit intel-media-driver;
+  };
+
   meta = with lib; {
     description = "An implementation for VA-API (Video Acceleration API)";
     longDescription = ''