d3d11device: Add fallback for device creation
authorSeungha Yang <seungha@centricular.com>
Sun, 26 Apr 2020 13:37:12 +0000 (22:37 +0900)
committerGStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Tue, 28 Apr 2020 17:33:56 +0000 (17:33 +0000)
D3D11_CREATE_DEVICE_DEBUG flag will be used while creating d3d11 device
to activate debug layer. However, if system doesn't support the
debug layer for some reason, we should try to create d3d11 device
without the flag. Debug layer should be optional for device creation.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1217>

sys/d3d11/gstd3d11device.c

index 4265e63512b0d8c81d665cbfd4b07d6d17bae4dc..c8df4a8aa1cbad8e3a7e53d440a227ba035e6839 100644 (file)
@@ -602,6 +602,30 @@ gst_d3d11_device_constructed (GObject * object)
     priv->feature_level = selected_level;
   }
 
+  /* if D3D11_CREATE_DEVICE_DEBUG was enabled but couldn't create device,
+   * try it without the flag again */
+  if (FAILED (hr) && (d3d11_flags & D3D11_CREATE_DEVICE_DEBUG) ==
+      D3D11_CREATE_DEVICE_DEBUG) {
+    GST_WARNING_OBJECT (self, "Couldn't create d3d11 device with debug flag");
+
+    d3d11_flags &= ~D3D11_CREATE_DEVICE_DEBUG;
+
+    hr = D3D11CreateDevice ((IDXGIAdapter *) adapter, D3D_DRIVER_TYPE_UNKNOWN,
+        NULL, d3d11_flags, feature_levels, G_N_ELEMENTS (feature_levels),
+        D3D11_SDK_VERSION, &priv->device, &selected_level,
+        &priv->device_context);
+    priv->feature_level = selected_level;
+
+    if (!gst_d3d11_result (hr, NULL)) {
+      /* Retry if the system could not recognize D3D_FEATURE_LEVEL_11_1 */
+      hr = D3D11CreateDevice ((IDXGIAdapter *) adapter, D3D_DRIVER_TYPE_UNKNOWN,
+          NULL, d3d11_flags, &feature_levels[1],
+          G_N_ELEMENTS (feature_levels) - 1, D3D11_SDK_VERSION, &priv->device,
+          &selected_level, &priv->device_context);
+      priv->feature_level = selected_level;
+    }
+  }
+
   if (gst_d3d11_result (hr, NULL)) {
     GST_DEBUG_OBJECT (self, "Selected feature level 0x%x", selected_level);
   } else {