]> granicus.if.org Git - handbrake/commitdiff
QSV: Adding D11 support for encode
authormaxd <maxim.d33@gmail.com>
Wed, 13 Sep 2017 19:24:49 +0000 (21:24 +0200)
committerScott <628593+sr55@users.noreply.github.com>
Sun, 17 Sep 2017 20:40:30 +0000 (21:40 +0100)
libhb/enc_qsv.c
libhb/qsv_common.c
libhb/qsv_common.h

index 11a3dace97a35603beb9a4f666d2420dd52df340..6e44bf740e1b2c07539df1b97245531d66738999 100644 (file)
@@ -668,8 +668,8 @@ int qsv_enc_init(hb_work_private_t *pv)
     if ((MFXQueryIMPL   (qsv->mfx_session, &impl)    == MFX_ERR_NONE) &&
         (MFXQueryVersion(qsv->mfx_session, &version) == MFX_ERR_NONE))
     {
-        hb_log("qsv_enc_init: using '%s' implementation, API: %"PRIu16".%"PRIu16"",
-               hb_qsv_impl_get_name(impl), version.Major, version.Minor);
+        hb_log("qsv_enc_init: using '%s %s' implementation, API: %"PRIu16".%"PRIu16"",
+               hb_qsv_impl_get_name(impl), hb_qsv_impl_get_via_name(impl), version.Major, version.Minor);
     }
     else
     {
index 9cd54fb0beb620ef342237ad7b9ba9e40518bdbd..cc95e6a2d4fb7115021abfb41c89f9c98543acee 100644 (file)
@@ -644,6 +644,11 @@ int hb_qsv_info_init()
      */
     mfxSession session;
     mfxVersion version = { .Major = 1, .Minor = 0, };
+#ifdef SYS_LINUX
+    mfxIMPL hw_preference = MFX_IMPL_VIA_ANY;
+#else
+    mfxIMPL hw_preference = MFX_IMPL_VIA_D3D11;
+#endif
 
     // check for software fallback
     if (MFXInit(MFX_IMPL_SOFTWARE, &version, &session) == MFX_ERR_NONE)
@@ -664,25 +669,41 @@ int hb_qsv_info_init()
     }
 
     // check for actual hardware support
-    if (MFXInit(MFX_IMPL_HARDWARE_ANY, &version, &session) == MFX_ERR_NONE)
-    {
-        // Media SDK hardware found, but check that our minimum is supported
-        //
-        // Note: this-party hardware (QSV_G0) is unsupported for the time being
-        MFXQueryVersion(session, &qsv_hardware_version);
-        if (qsv_hardware_generation(hb_get_cpu_platform()) >= QSV_G1 &&
-            HB_CHECK_MFX_VERSION(qsv_hardware_version,
-                                 HB_QSV_MINVERSION_MAJOR,
-                                 HB_QSV_MINVERSION_MINOR))
+    do{
+        if (MFXInit(MFX_IMPL_HARDWARE_ANY | hw_preference, &version, &session) == MFX_ERR_NONE)
+        {
+            // Media SDK hardware found, but check that our minimum is supported
+            //
+            // Note: this-party hardware (QSV_G0) is unsupported for the time being
+            MFXQueryVersion(session, &qsv_hardware_version);
+            if (qsv_hardware_generation(hb_get_cpu_platform()) >= QSV_G1 &&
+                HB_CHECK_MFX_VERSION(qsv_hardware_version,
+                                     HB_QSV_MINVERSION_MAJOR,
+                                     HB_QSV_MINVERSION_MINOR))
+            {
+                query_capabilities(session, qsv_hardware_version, &qsv_hardware_info_avc);
+                qsv_hardware_info_avc.implementation = MFX_IMPL_HARDWARE_ANY | hw_preference;
+                query_capabilities(session, qsv_hardware_version, &qsv_hardware_info_hevc);
+                qsv_hardware_info_hevc.implementation = MFX_IMPL_HARDWARE_ANY | hw_preference;
+                // now that we know which hardware encoders are
+                // available, we can set the preferred implementation
+                hb_qsv_impl_set_preferred("hardware");
+            }
+            MFXClose(session);
+            hw_preference = 0;
+        }
+        else
         {
-            query_capabilities(session, qsv_hardware_version, &qsv_hardware_info_avc);
-            query_capabilities(session, qsv_hardware_version, &qsv_hardware_info_hevc);
-            // now that we know which hardware encoders are
-            // available, we can set the preferred implementation
-            hb_qsv_impl_set_preferred("hardware");
+#ifndef SYS_LINUX
+            // Windows only: After D3D11 we will try D3D9
+            if (hw_preference == MFX_IMPL_VIA_D3D11)
+                hw_preference = MFX_IMPL_VIA_D3D9;
+            else
+#endif
+                hw_preference = 0;
         }
-        MFXClose(session);
     }
+    while(hw_preference != 0);
 
     // success
     return 0;
@@ -796,8 +817,9 @@ void hb_qsv_info_print()
         if (hb_qsv_info_avc != NULL && hb_qsv_info_avc->available)
         {
             hb_log(" - H.264 encoder: yes");
-            hb_log("    - preferred implementation: %s",
-                   hb_qsv_impl_get_name(hb_qsv_info_avc->implementation));
+            hb_log("    - preferred implementation: %s %s",
+                   hb_qsv_impl_get_name(hb_qsv_info_avc->implementation),
+                   hb_qsv_impl_get_via_name(hb_qsv_info_avc->implementation));
             if (qsv_hardware_info_avc.available)
             {
                 log_capabilities(1, qsv_hardware_info_avc.capabilities,
@@ -816,8 +838,9 @@ void hb_qsv_info_print()
         if (hb_qsv_info_hevc != NULL && hb_qsv_info_hevc->available)
         {
             hb_log(" - H.265 encoder: yes (8bit: yes, 10bit: %s)", (qsv_hardware_generation(hb_get_cpu_platform()) < QSV_G6) ? "no" : "yes" );
-            hb_log("    - preferred implementation: %s",
-                   hb_qsv_impl_get_name(hb_qsv_info_hevc->implementation));
+            hb_log("    - preferred implementation: %s %s",
+                   hb_qsv_impl_get_name(hb_qsv_info_hevc->implementation),
+                   hb_qsv_impl_get_via_name(hb_qsv_info_hevc->implementation));
             if (qsv_hardware_info_hevc.available)
             {
                 log_capabilities(1, qsv_hardware_info_hevc.capabilities,
@@ -2159,6 +2182,19 @@ const char* hb_qsv_impl_get_name(int impl)
     }
 }
 
+const char* hb_qsv_impl_get_via_name(int impl)
+{
+    if (impl & MFX_IMPL_VIA_VAAPI)
+        return "via VAAPI";
+    else if (impl & MFX_IMPL_VIA_D3D11)
+        return "via D3D11";
+    else if (impl & MFX_IMPL_VIA_D3D9)
+        return "via D3D9";
+    else if (impl & MFX_IMPL_VIA_ANY)
+        return "via ANY";
+    else return NULL;
+}
+
 void hb_qsv_force_workarounds()
 {
 #define FORCE_WORKAROUNDS ~(HB_QSV_CAP_OPTION2_BREFTYPE)
index d59cdfd3c7b0aa0289fdf020dbb44ca6dd7fc6bf..e5964ca9d5ccf4b81a40d684278d58839123c3a9 100644 (file)
@@ -35,7 +35,7 @@ typedef struct hb_qsv_info_s
 {
     // each info struct only corresponds to one CodecId and implementation combo
     const mfxU32  codec_id;
-    const mfxIMPL implementation;
+    mfxIMPL implementation;
 
     // whether the encoder is available for this implementation
     int available;
@@ -188,6 +188,7 @@ uint8_t     hb_qsv_frametype_xlat(uint16_t qsv_frametype, uint16_t *out_flags);
 
 int         hb_qsv_impl_set_preferred(const char *name);
 const char* hb_qsv_impl_get_name(int impl);
+const char* hb_qsv_impl_get_via_name(int impl);
 
 void hb_qsv_force_workarounds(); // for developers only