vulkan/image: use the full video info for returning vulkan formats
authorMatthew Waters <matthew@centricular.com>
Tue, 29 Oct 2019 13:57:55 +0000 (00:57 +1100)
committerGStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Thu, 7 Nov 2019 20:01:57 +0000 (20:01 +0000)
We may need some colorspace information for returning sRGB vs no sRGB.

ext/vulkan/vkcolorconvert.c
ext/vulkan/vkimageidentity.c
ext/vulkan/vkupload.c
ext/vulkan/vkviewconvert.c
gst-libs/gst/vulkan/gstvkimagebufferpool.c
gst-libs/gst/vulkan/gstvkimagememory.c
gst-libs/gst/vulkan/gstvkimagememory.h
gst-libs/gst/vulkan/gstvkswapper.c

index 32b4f00a2e14d80e5f11aa798990b032772ffe9b..82efb69ba22ed168366041206dea41403a301f14 100644 (file)
@@ -1333,7 +1333,7 @@ static VkAttachmentDescription
   for (i = 0; i < *n_descriptions; i++) {
     /* *INDENT-OFF* */
     color_attachments[i] = (VkAttachmentDescription) {
-        .format = gst_vulkan_format_from_video_format (GST_VIDEO_INFO_FORMAT (&render->out_info), i),
+        .format = gst_vulkan_format_from_video_info (&render->out_info, i),
         .samples = VK_SAMPLE_COUNT_1_BIT,
         .loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR,
         .storeOp = VK_ATTACHMENT_STORE_OP_STORE,
@@ -1764,12 +1764,11 @@ gst_vulkan_color_convert_transform (GstBaseTransform * bt, GstBuffer * inbuf,
       /* we need a scratch buffer because framebuffers can only output to
        * attachments of at least the same size which means no sub-sampled
        * rendering */
-      GstVideoFormat v_format = GST_VIDEO_INFO_FORMAT (&render->out_info);
       VkImageTiling tiling = VK_IMAGE_TILING_OPTIMAL;
       VkFormat vk_format;
       GstMemory *mem;
 
-      vk_format = gst_vulkan_format_from_video_format (v_format, i);
+      vk_format = gst_vulkan_format_from_video_info (&render->out_info, i);
 
       mem = gst_vulkan_image_memory_alloc (render->device,
           vk_format, GST_VIDEO_INFO_WIDTH (&render->out_info),
index 828b474fa0298805f0ba3d662ea844d2487e74bf..b896e867f5e4dde0ed0e5ec107cebcbacae8cea9 100644 (file)
@@ -261,7 +261,7 @@ static VkAttachmentDescription
   color_attachments = g_new0 (VkAttachmentDescription, *n_descriptions);
   /* *INDENT-OFF* */
   color_attachments[0] = (VkAttachmentDescription) {
-      .format = gst_vulkan_format_from_video_format (GST_VIDEO_INFO_FORMAT (&render->in_info), 0),
+      .format = gst_vulkan_format_from_video_info (&render->in_info, 0),
       .samples = VK_SAMPLE_COUNT_1_BIT,
       .loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR,
       .storeOp = VK_ATTACHMENT_STORE_OP_STORE,
index c0f220f30d6628e837429590b235d322d0caa8cb..ba4bdc5237c32e6c9c2bc3080d83c8bba8592421 100644 (file)
@@ -239,11 +239,10 @@ _raw_to_buffer_set_caps (gpointer impl, GstCaps * in_caps, GstCaps * out_caps)
   out_height = GST_VIDEO_INFO_HEIGHT (&raw->out_info);
 
   for (i = 0; i < GST_VIDEO_INFO_N_PLANES (&raw->out_info); i++) {
-    GstVideoFormat v_format = GST_VIDEO_INFO_FORMAT (&raw->out_info);
     GstVulkanImageMemory *img_mem;
     VkFormat vk_format;
 
-    vk_format = gst_vulkan_format_from_video_format (v_format, i);
+    vk_format = gst_vulkan_format_from_video_info (&raw->out_info, i);
 
     img_mem = (GstVulkanImageMemory *)
         gst_vulkan_image_memory_alloc (raw->upload->device, vk_format,
index 2e60285f6d9a102abd5b7fb454734d46b80351d9..8ab2d44f0f3e6a4de9b2dc514da97190c179576a 100644 (file)
@@ -1944,7 +1944,7 @@ static VkAttachmentDescription
   for (i = 0; i < *n_descriptions; i++) {
     /* *INDENT-OFF* */
     color_attachments[i] = (VkAttachmentDescription) {
-        .format = gst_vulkan_format_from_video_format (GST_VIDEO_INFO_FORMAT (&render->out_info), i),
+        .format = gst_vulkan_format_from_video_info (&render->out_info, i),
         .samples = VK_SAMPLE_COUNT_1_BIT,
         .loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR,
         .storeOp = VK_ATTACHMENT_STORE_OP_STORE,
index 2d6c3eda51121a236f625cafd609e6ff855c26a9..5c859a5a68baf2c9b2fd5b78ddc3e4cf3509d74b 100644 (file)
@@ -103,13 +103,12 @@ gst_vulkan_image_buffer_pool_set_config (GstBufferPool * pool,
   /* get the size of the buffer to allocate */
   priv->v_info.size = 0;
   for (i = 0; i < GST_VIDEO_INFO_N_PLANES (&priv->v_info); i++) {
-    GstVideoFormat v_format = GST_VIDEO_INFO_FORMAT (&priv->v_info);
     GstVulkanImageMemory *img_mem;
     VkImageTiling tiling = VK_IMAGE_TILING_OPTIMAL;
     guint width, height;
     VkFormat vk_format;
 
-    vk_format = gst_vulkan_format_from_video_format (v_format, i);
+    vk_format = gst_vulkan_format_from_video_info (&priv->v_info, i);
     width = GST_VIDEO_INFO_COMP_WIDTH (&priv->v_info, i);
     height = GST_VIDEO_INFO_COMP_HEIGHT (&priv->v_info, i);
     if (priv->raw_caps)
@@ -171,12 +170,11 @@ gst_vulkan_image_buffer_pool_alloc (GstBufferPool * pool, GstBuffer ** buffer,
   }
 
   for (i = 0; i < GST_VIDEO_INFO_N_PLANES (&priv->v_info); i++) {
-    GstVideoFormat v_format = GST_VIDEO_INFO_FORMAT (&priv->v_info);
     VkImageTiling tiling = VK_IMAGE_TILING_OPTIMAL;
     VkFormat vk_format;
     GstMemory *mem;
 
-    vk_format = gst_vulkan_format_from_video_format (v_format, i);
+    vk_format = gst_vulkan_format_from_video_info (&priv->v_info, i);
     if (priv->raw_caps)
       tiling = VK_IMAGE_TILING_LINEAR;
 
index f691773cfc77b89baf2a95bb16f2761c0b88d565..490e68606ba84f91fb234ae318c83e995a107b28 100644 (file)
@@ -40,8 +40,8 @@ GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFUALT);
 static GstAllocator *_vulkan_image_memory_allocator;
 
 /**
- * gst_vulkan_format_from_video_format: (skip)
- * @v_format: the #GstVideoFormat
+ * gst_vulkan_format_from_video_info: (skip)
+ * @v_info: the #GstVideoInfo
  * @plane: the plane
  *
  * Returns: the VkFormat to use for @v_format and @plane
@@ -49,21 +49,34 @@ static GstAllocator *_vulkan_image_memory_allocator;
  * Since: 1.18
  */
 VkFormat
-gst_vulkan_format_from_video_format (GstVideoFormat v_format, guint plane)
+gst_vulkan_format_from_video_info (GstVideoInfo * v_info, guint plane)
 {
   guint n_plane_components;
 
-  switch (v_format) {
+  switch (GST_VIDEO_INFO_FORMAT (v_info)) {
     case GST_VIDEO_FORMAT_RGBx:
     case GST_VIDEO_FORMAT_RGBA:
-      return VK_FORMAT_R8G8B8A8_UNORM;
+      if (GST_VIDEO_INFO_COLORIMETRY (v_info).transfer ==
+          GST_VIDEO_TRANSFER_SRGB)
+        return VK_FORMAT_R8G8B8A8_UNORM;
+      else
+        return VK_FORMAT_R8G8B8A8_SRGB;
     case GST_VIDEO_FORMAT_BGRx:
     case GST_VIDEO_FORMAT_BGRA:
-      return VK_FORMAT_B8G8R8A8_UNORM;
+      if (GST_VIDEO_INFO_COLORIMETRY (v_info).transfer ==
+          GST_VIDEO_TRANSFER_SRGB)
+        return VK_FORMAT_B8G8R8A8_UNORM;
+      else
+        return VK_FORMAT_B8G8R8A8_SRGB;
     case GST_VIDEO_FORMAT_xRGB:
     case GST_VIDEO_FORMAT_ARGB:
     case GST_VIDEO_FORMAT_xBGR:
     case GST_VIDEO_FORMAT_ABGR:
+      if (GST_VIDEO_INFO_COLORIMETRY (v_info).transfer ==
+          GST_VIDEO_TRANSFER_SRGB)
+        n_plane_components = 4;
+      else
+        return VK_FORMAT_UNDEFINED;
     case GST_VIDEO_FORMAT_AYUV:
       n_plane_components = 4;
       break;
index e0cd975ceb176838a884a34109cda5ea7a6b9b7f..26461f3e65c0f4b9846e41b745e8da2952adfde9 100644 (file)
@@ -142,7 +142,7 @@ void            gst_vulkan_image_memory_add_view        (GstVulkanImageMemory *
                                                          GstVulkanImageView * view);
 
 GST_VULKAN_API
-VkFormat gst_vulkan_format_from_video_format (GstVideoFormat v_format,
+VkFormat gst_vulkan_format_from_video_info   (GstVideoInfo * v_info,
                                               guint plane);
 
 G_END_DECLS
index d7fd00be698b6aaebe65cc49480c182129f579bc..93199864bd219c4461fa7aaf02209a7e8de8efaa 100644 (file)
@@ -158,55 +158,18 @@ _vk_format_to_video_format (VkFormat format)
   switch (format) {
       /* double check endianness */
     case VK_FORMAT_R8G8B8A8_UNORM:
-    case VK_FORMAT_R8G8B8A8_SRGB:
       return GST_VIDEO_FORMAT_RGBA;
     case VK_FORMAT_R8G8B8_UNORM:
-    case VK_FORMAT_R8G8B8_SRGB:
       return GST_VIDEO_FORMAT_RGB;
     case VK_FORMAT_B8G8R8A8_UNORM:
-    case VK_FORMAT_B8G8R8A8_SRGB:
       return GST_VIDEO_FORMAT_BGRA;
     case VK_FORMAT_B8G8R8_UNORM:
-    case VK_FORMAT_B8G8R8_SRGB:
       return GST_VIDEO_FORMAT_BGR;
     default:
       return GST_VIDEO_FORMAT_UNKNOWN;
   }
 }
 
-static VkFormat
-_vk_format_from_video_info (GstVideoInfo * v_info)
-{
-  switch (GST_VIDEO_INFO_FORMAT (v_info)) {
-    case GST_VIDEO_FORMAT_RGBA:
-      if (GST_VIDEO_INFO_COLORIMETRY (v_info).transfer ==
-          GST_VIDEO_TRANSFER_SRGB)
-        return VK_FORMAT_R8G8B8A8_SRGB;
-      else
-        return VK_FORMAT_R8G8B8A8_UNORM;
-    case GST_VIDEO_FORMAT_RGB:
-      if (GST_VIDEO_INFO_COLORIMETRY (v_info).transfer ==
-          GST_VIDEO_TRANSFER_SRGB)
-        return VK_FORMAT_R8G8B8_SRGB;
-      else
-        return VK_FORMAT_R8G8B8_UNORM;
-    case GST_VIDEO_FORMAT_BGRA:
-      if (GST_VIDEO_INFO_COLORIMETRY (v_info).transfer ==
-          GST_VIDEO_TRANSFER_SRGB)
-        return VK_FORMAT_B8G8R8A8_SRGB;
-      else
-        return VK_FORMAT_B8G8R8A8_UNORM;
-    case GST_VIDEO_FORMAT_BGR:
-      if (GST_VIDEO_INFO_COLORIMETRY (v_info).transfer ==
-          GST_VIDEO_TRANSFER_SRGB)
-        return VK_FORMAT_B8G8R8_SRGB;
-      else
-        return VK_FORMAT_B8G8R8_UNORM;
-    default:
-      return VK_FORMAT_UNDEFINED;
-  }
-}
-
 static VkColorSpaceKHR
 _vk_color_space_from_video_info (GstVideoInfo * v_info)
 {
@@ -742,7 +705,7 @@ _allocate_swapchain (GstVulkanSwapper * swapper, GstCaps * caps,
     preTransform = swapper->priv->surf_props.currentTransform;
   }
 
-  format = _vk_format_from_video_info (&swapper->priv->v_info);
+  format = gst_vulkan_format_from_video_info (&swapper->priv->v_info, 0);
   color_space = _vk_color_space_from_video_info (&swapper->priv->v_info);
 
   if ((swapper->priv->surf_props.supportedCompositeAlpha &