qsvencoder: Bind internal texture to render target
authorSeungha Yang <seungha@centricular.com>
Thu, 26 May 2022 14:50:08 +0000 (23:50 +0900)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Fri, 27 May 2022 14:03:49 +0000 (14:03 +0000)
... so that memory allocator can initialize texture with black color

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2502>

subprojects/gst-plugins-bad/sys/qsv/gstqsvencoder.cpp

index dbb82be..88bbf89 100644 (file)
@@ -898,11 +898,24 @@ gst_qsv_encoder_prepare_d3d11_pool (GstQsvEncoder * self,
   GstStructure *config;
   GstD3D11AllocationParams *params;
   GstD3D11Device *device = GST_D3D11_DEVICE_CAST (priv->device);
+  guint bind_flags = 0;
+  GstD3D11Format device_format;
+
+  gst_d3d11_device_get_format (device, GST_VIDEO_INFO_FORMAT (aligned_info),
+      &device_format);
+  if ((device_format.format_support[0] & D3D11_FORMAT_SUPPORT_RENDER_TARGET) ==
+      D3D11_FORMAT_SUPPORT_RENDER_TARGET) {
+    /* XXX: workaround for greenish artifacts
+     * https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/1238
+     * bind to render target so that d3d11 memory allocator can clear texture
+     * with black color */
+    bind_flags = D3D11_BIND_RENDER_TARGET;
+  }
 
   priv->internal_pool = gst_d3d11_buffer_pool_new (device);
   config = gst_buffer_pool_get_config (priv->internal_pool);
   params = gst_d3d11_allocation_params_new (device, aligned_info,
-      (GstD3D11AllocationFlags) 0, 0);
+      (GstD3D11AllocationFlags) 0, bind_flags);
 
   gst_buffer_pool_config_set_d3d11_allocation_params (config, params);
   gst_d3d11_allocation_params_free (params);