mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-03 14:08:56 +00:00
vkformat: move gst_vulkan_format_from_video_info()
Moved gst_vulkan_format_from_video_info() from gstvkimagememory to gstvkformat in order to centralize the video format operations in a single source file. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4351>
This commit is contained in:
parent
b1c166b53c
commit
14dd6aac16
4 changed files with 75 additions and 73 deletions
|
@ -436,3 +436,73 @@ gst_vulkan_format_get_info (VkFormat format)
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* *INDENT-OFF* */
|
||||||
|
const static struct {
|
||||||
|
GstVideoFormat format;
|
||||||
|
VkFormat vkfrmt;
|
||||||
|
VkFormat vkfrmts[GST_VIDEO_MAX_PLANES];
|
||||||
|
} vk_formats_map[] = {
|
||||||
|
/* RGB transfer sRGB */
|
||||||
|
{ GST_VIDEO_FORMAT_RGBx, VK_FORMAT_R8G8B8A8_SRGB, { VK_FORMAT_R8G8B8A8_UNORM, } },
|
||||||
|
{ GST_VIDEO_FORMAT_RGBA, VK_FORMAT_R8G8B8A8_SRGB, { VK_FORMAT_R8G8B8A8_UNORM, } },
|
||||||
|
{ GST_VIDEO_FORMAT_BGRx, VK_FORMAT_B8G8R8A8_SRGB, { VK_FORMAT_B8G8R8A8_UNORM, } },
|
||||||
|
{ GST_VIDEO_FORMAT_BGRA, VK_FORMAT_B8G8R8A8_SRGB, { VK_FORMAT_B8G8R8A8_UNORM, } },
|
||||||
|
{ GST_VIDEO_FORMAT_xRGB, VK_FORMAT_UNDEFINED, { VK_FORMAT_R8G8B8A8_UNORM, } },
|
||||||
|
{ GST_VIDEO_FORMAT_ARGB, VK_FORMAT_UNDEFINED, { VK_FORMAT_R8G8B8A8_UNORM, } },
|
||||||
|
{ GST_VIDEO_FORMAT_xBGR, VK_FORMAT_UNDEFINED, { VK_FORMAT_R8G8B8A8_UNORM, } },
|
||||||
|
{ GST_VIDEO_FORMAT_ABGR, VK_FORMAT_UNDEFINED, { VK_FORMAT_R8G8B8A8_UNORM, } },
|
||||||
|
{ GST_VIDEO_FORMAT_RGB, VK_FORMAT_R8G8B8_UNORM, { VK_FORMAT_UNDEFINED, } },
|
||||||
|
{ GST_VIDEO_FORMAT_BGR, VK_FORMAT_B8G8R8_UNORM, { VK_FORMAT_UNDEFINED, } },
|
||||||
|
{ GST_VIDEO_FORMAT_RGB16, VK_FORMAT_R5G6B5_UNORM_PACK16, { VK_FORMAT_UNDEFINED, } },
|
||||||
|
{ GST_VIDEO_FORMAT_BGR16, VK_FORMAT_B5G6R5_UNORM_PACK16, { VK_FORMAT_UNDEFINED, } },
|
||||||
|
/* Gray */
|
||||||
|
{ GST_VIDEO_FORMAT_GRAY16_BE, VK_FORMAT_R8G8_UNORM, { VK_FORMAT_UNDEFINED, } },
|
||||||
|
{ GST_VIDEO_FORMAT_GRAY16_LE, VK_FORMAT_R8G8_UNORM, { VK_FORMAT_UNDEFINED, } },
|
||||||
|
{ GST_VIDEO_FORMAT_GRAY8, VK_FORMAT_R8_UNORM, { VK_FORMAT_UNDEFINED, } },
|
||||||
|
/* YUV planes */
|
||||||
|
{ GST_VIDEO_FORMAT_AYUV, VK_FORMAT_UNDEFINED, { VK_FORMAT_R8G8B8A8_UNORM, } },
|
||||||
|
{ GST_VIDEO_FORMAT_YUY2, VK_FORMAT_UNDEFINED, { VK_FORMAT_R8G8_UNORM, } },
|
||||||
|
{ GST_VIDEO_FORMAT_UYVY, VK_FORMAT_UNDEFINED, { VK_FORMAT_R8G8_UNORM, } },
|
||||||
|
{ GST_VIDEO_FORMAT_NV12, VK_FORMAT_UNDEFINED, { VK_FORMAT_R8_UNORM, VK_FORMAT_R8G8_UNORM } },
|
||||||
|
{ GST_VIDEO_FORMAT_NV21, VK_FORMAT_UNDEFINED, { VK_FORMAT_R8_UNORM, VK_FORMAT_R8G8_UNORM } },
|
||||||
|
{ GST_VIDEO_FORMAT_Y444, VK_FORMAT_UNDEFINED, { VK_FORMAT_R8_UNORM, } },
|
||||||
|
{ GST_VIDEO_FORMAT_Y42B, VK_FORMAT_UNDEFINED, { VK_FORMAT_R8_UNORM, } },
|
||||||
|
{ GST_VIDEO_FORMAT_Y41B, VK_FORMAT_UNDEFINED, { VK_FORMAT_R8_UNORM, } },
|
||||||
|
{ GST_VIDEO_FORMAT_I420, VK_FORMAT_UNDEFINED, { VK_FORMAT_R8_UNORM, } },
|
||||||
|
{ GST_VIDEO_FORMAT_YV12, VK_FORMAT_UNDEFINED, { VK_FORMAT_R8_UNORM, } },
|
||||||
|
};
|
||||||
|
/* *INDENT-ON* */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_vulkan_format_from_video_info: (skip)
|
||||||
|
* @v_info: the #GstVideoInfo
|
||||||
|
* @plane: the plane
|
||||||
|
*
|
||||||
|
* Returns: the VkFormat to use for @v_format and @plane
|
||||||
|
*
|
||||||
|
* Since: 1.18
|
||||||
|
*/
|
||||||
|
VkFormat
|
||||||
|
gst_vulkan_format_from_video_info (GstVideoInfo * v_info, guint plane)
|
||||||
|
{
|
||||||
|
guint i;
|
||||||
|
|
||||||
|
for (i = 0; i < G_N_ELEMENTS (vk_formats_map); i++) {
|
||||||
|
if (vk_formats_map[i].format != GST_VIDEO_INFO_FORMAT (v_info))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (GST_VIDEO_INFO_IS_RGB (v_info) &&
|
||||||
|
(GST_VIDEO_INFO_COLORIMETRY (v_info).transfer ==
|
||||||
|
GST_VIDEO_TRANSFER_SRGB)) {
|
||||||
|
return vk_formats_map[i].vkfrmts[0];
|
||||||
|
} else if (GST_VIDEO_INFO_IS_YUV (v_info) &&
|
||||||
|
GST_VIDEO_INFO_N_PLANES (v_info) > plane) {
|
||||||
|
return vk_formats_map[i].vkfrmts[plane];
|
||||||
|
}
|
||||||
|
|
||||||
|
return vk_formats_map[i].vkfrmt;
|
||||||
|
}
|
||||||
|
|
||||||
|
return VK_FORMAT_UNDEFINED;
|
||||||
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#define __GST_VULKAN_FORMAT_H__
|
#define __GST_VULKAN_FORMAT_H__
|
||||||
|
|
||||||
#include <gst/vulkan/vulkan.h>
|
#include <gst/vulkan/vulkan.h>
|
||||||
|
#include <gst/video/video.h>
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
@ -123,6 +124,10 @@ struct _GstVulkanFormatInfo
|
||||||
GST_VULKAN_API
|
GST_VULKAN_API
|
||||||
const GstVulkanFormatInfo * gst_vulkan_format_get_info (VkFormat format);
|
const GstVulkanFormatInfo * gst_vulkan_format_get_info (VkFormat format);
|
||||||
|
|
||||||
|
GST_VULKAN_API
|
||||||
|
VkFormat gst_vulkan_format_from_video_info (GstVideoInfo * v_info,
|
||||||
|
guint plane);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __GST_VULKAN_FORMAT_H__ */
|
#endif /* __GST_VULKAN_FORMAT_H__ */
|
||||||
|
|
|
@ -39,76 +39,6 @@ GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFUALT);
|
||||||
|
|
||||||
static GstAllocator *_vulkan_image_memory_allocator;
|
static GstAllocator *_vulkan_image_memory_allocator;
|
||||||
|
|
||||||
/* *INDENT-OFF* */
|
|
||||||
const static struct {
|
|
||||||
GstVideoFormat format;
|
|
||||||
VkFormat vkfrmt;
|
|
||||||
VkFormat vkfrmts[GST_VIDEO_MAX_PLANES];
|
|
||||||
} vk_formats_map[] = {
|
|
||||||
/* RGB transfer sRGB */
|
|
||||||
{ GST_VIDEO_FORMAT_RGBx, VK_FORMAT_R8G8B8A8_SRGB, { VK_FORMAT_R8G8B8A8_UNORM, } },
|
|
||||||
{ GST_VIDEO_FORMAT_RGBA, VK_FORMAT_R8G8B8A8_SRGB, { VK_FORMAT_R8G8B8A8_UNORM, } },
|
|
||||||
{ GST_VIDEO_FORMAT_BGRx, VK_FORMAT_B8G8R8A8_SRGB, { VK_FORMAT_B8G8R8A8_UNORM, } },
|
|
||||||
{ GST_VIDEO_FORMAT_BGRA, VK_FORMAT_B8G8R8A8_SRGB, { VK_FORMAT_B8G8R8A8_UNORM, } },
|
|
||||||
{ GST_VIDEO_FORMAT_xRGB, VK_FORMAT_UNDEFINED, { VK_FORMAT_R8G8B8A8_UNORM, } },
|
|
||||||
{ GST_VIDEO_FORMAT_ARGB, VK_FORMAT_UNDEFINED, { VK_FORMAT_R8G8B8A8_UNORM, } },
|
|
||||||
{ GST_VIDEO_FORMAT_xBGR, VK_FORMAT_UNDEFINED, { VK_FORMAT_R8G8B8A8_UNORM, } },
|
|
||||||
{ GST_VIDEO_FORMAT_ABGR, VK_FORMAT_UNDEFINED, { VK_FORMAT_R8G8B8A8_UNORM, } },
|
|
||||||
{ GST_VIDEO_FORMAT_RGB, VK_FORMAT_R8G8B8_UNORM, { VK_FORMAT_UNDEFINED, } },
|
|
||||||
{ GST_VIDEO_FORMAT_BGR, VK_FORMAT_B8G8R8_UNORM, { VK_FORMAT_UNDEFINED, } },
|
|
||||||
{ GST_VIDEO_FORMAT_RGB16, VK_FORMAT_R5G6B5_UNORM_PACK16, { VK_FORMAT_UNDEFINED, } },
|
|
||||||
{ GST_VIDEO_FORMAT_BGR16, VK_FORMAT_B5G6R5_UNORM_PACK16, { VK_FORMAT_UNDEFINED, } },
|
|
||||||
/* Gray */
|
|
||||||
{ GST_VIDEO_FORMAT_GRAY16_BE, VK_FORMAT_R8G8_UNORM, { VK_FORMAT_UNDEFINED, } },
|
|
||||||
{ GST_VIDEO_FORMAT_GRAY16_LE, VK_FORMAT_R8G8_UNORM, { VK_FORMAT_UNDEFINED, } },
|
|
||||||
{ GST_VIDEO_FORMAT_GRAY8, VK_FORMAT_R8_UNORM, { VK_FORMAT_UNDEFINED, } },
|
|
||||||
/* YUV planes */
|
|
||||||
{ GST_VIDEO_FORMAT_AYUV, VK_FORMAT_UNDEFINED, { VK_FORMAT_R8G8B8A8_UNORM, } },
|
|
||||||
{ GST_VIDEO_FORMAT_YUY2, VK_FORMAT_UNDEFINED, { VK_FORMAT_R8G8_UNORM, } },
|
|
||||||
{ GST_VIDEO_FORMAT_UYVY, VK_FORMAT_UNDEFINED, { VK_FORMAT_R8G8_UNORM, } },
|
|
||||||
{ GST_VIDEO_FORMAT_NV12, VK_FORMAT_UNDEFINED, { VK_FORMAT_R8_UNORM, VK_FORMAT_R8G8_UNORM } },
|
|
||||||
{ GST_VIDEO_FORMAT_NV21, VK_FORMAT_UNDEFINED, { VK_FORMAT_R8_UNORM, VK_FORMAT_R8G8_UNORM } },
|
|
||||||
{ GST_VIDEO_FORMAT_Y444, VK_FORMAT_UNDEFINED, { VK_FORMAT_R8_UNORM, } },
|
|
||||||
{ GST_VIDEO_FORMAT_Y42B, VK_FORMAT_UNDEFINED, { VK_FORMAT_R8_UNORM, } },
|
|
||||||
{ GST_VIDEO_FORMAT_Y41B, VK_FORMAT_UNDEFINED, { VK_FORMAT_R8_UNORM, } },
|
|
||||||
{ GST_VIDEO_FORMAT_I420, VK_FORMAT_UNDEFINED, { VK_FORMAT_R8_UNORM, } },
|
|
||||||
{ GST_VIDEO_FORMAT_YV12, VK_FORMAT_UNDEFINED, { VK_FORMAT_R8_UNORM, } },
|
|
||||||
};
|
|
||||||
/* *INDENT-ON* */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* gst_vulkan_format_from_video_info: (skip)
|
|
||||||
* @v_info: the #GstVideoInfo
|
|
||||||
* @plane: the plane
|
|
||||||
*
|
|
||||||
* Returns: the VkFormat to use for @v_format and @plane
|
|
||||||
*
|
|
||||||
* Since: 1.18
|
|
||||||
*/
|
|
||||||
VkFormat
|
|
||||||
gst_vulkan_format_from_video_info (GstVideoInfo * v_info, guint plane)
|
|
||||||
{
|
|
||||||
guint i;
|
|
||||||
|
|
||||||
for (i = 0; i < G_N_ELEMENTS (vk_formats_map); i++) {
|
|
||||||
if (vk_formats_map[i].format != GST_VIDEO_INFO_FORMAT (v_info))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (GST_VIDEO_INFO_IS_RGB (v_info) &&
|
|
||||||
(GST_VIDEO_INFO_COLORIMETRY (v_info).transfer ==
|
|
||||||
GST_VIDEO_TRANSFER_SRGB)) {
|
|
||||||
return vk_formats_map[i].vkfrmts[0];
|
|
||||||
} else if (GST_VIDEO_INFO_IS_YUV (v_info) &&
|
|
||||||
GST_VIDEO_INFO_N_PLANES (v_info) > plane) {
|
|
||||||
return vk_formats_map[i].vkfrmts[plane];
|
|
||||||
}
|
|
||||||
|
|
||||||
return vk_formats_map[i].vkfrmt;
|
|
||||||
}
|
|
||||||
|
|
||||||
return VK_FORMAT_UNDEFINED;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
_create_info_from_args (VkImageCreateInfo * info, VkFormat format, gsize width,
|
_create_info_from_args (VkImageCreateInfo * info, VkFormat format, gsize width,
|
||||||
gsize height, VkImageTiling tiling, VkImageUsageFlags usage)
|
gsize height, VkImageTiling tiling, VkImageUsageFlags usage)
|
||||||
|
|
|
@ -215,9 +215,6 @@ GST_VULKAN_API
|
||||||
void gst_vulkan_image_memory_add_view (GstVulkanImageMemory * image,
|
void gst_vulkan_image_memory_add_view (GstVulkanImageMemory * image,
|
||||||
GstVulkanImageView * view);
|
GstVulkanImageView * view);
|
||||||
|
|
||||||
GST_VULKAN_API
|
|
||||||
VkFormat gst_vulkan_format_from_video_info (GstVideoInfo * v_info,
|
|
||||||
guint plane);
|
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue