mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-04 23:46:43 +00:00
vulkan: add gst_vulkan_video_image_create_view()
This function is moved from gstvkdecoder-private so it could be used by gstvkencoder-private too, removing there what it should be duplicated code. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/7984>
This commit is contained in:
parent
3389347467
commit
603e7c3e5f
4 changed files with 82 additions and 94 deletions
|
@ -1088,61 +1088,14 @@ gst_vulkan_decoder_picture_create_view (GstVulkanDecoder * self,
|
|||
GstBuffer * buf, gboolean is_out)
|
||||
{
|
||||
GstVulkanDecoderPrivate *priv;
|
||||
VkSamplerYcbcrConversionInfo yuv_sampler_info;
|
||||
VkImageViewCreateInfo view_create_info;
|
||||
GstVulkanImageMemory *vkmem;
|
||||
GstMemory *mem;
|
||||
gpointer pnext;
|
||||
guint n_mems;
|
||||
|
||||
g_return_val_if_fail (GST_IS_VULKAN_DECODER (self) && GST_IS_BUFFER (buf),
|
||||
NULL);
|
||||
|
||||
n_mems = gst_buffer_n_memory (buf);
|
||||
if (n_mems != 1)
|
||||
return NULL;
|
||||
|
||||
mem = gst_buffer_peek_memory (buf, 0);
|
||||
if (!gst_is_vulkan_image_memory (mem))
|
||||
return NULL;
|
||||
|
||||
priv = gst_vulkan_decoder_get_instance_private (self);
|
||||
|
||||
pnext = NULL;
|
||||
if (priv->sampler) {
|
||||
/* *INDENT-OFF* */
|
||||
yuv_sampler_info = (VkSamplerYcbcrConversionInfo) {
|
||||
.sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO,
|
||||
.conversion = priv->sampler->handle,
|
||||
};
|
||||
/* *INDENT-ON* */
|
||||
|
||||
pnext = &yuv_sampler_info;
|
||||
}
|
||||
|
||||
vkmem = (GstVulkanImageMemory *) mem;
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
view_create_info = (VkImageViewCreateInfo) {
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
|
||||
.pNext = pnext,
|
||||
.viewType = self->layered_dpb && !is_out ?
|
||||
VK_IMAGE_VIEW_TYPE_2D_ARRAY: VK_IMAGE_VIEW_TYPE_2D,
|
||||
.format = vkmem->create_info.format,
|
||||
.image = vkmem->image,
|
||||
.components = _vk_identity_component_map,
|
||||
.subresourceRange = (VkImageSubresourceRange) {
|
||||
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
|
||||
.baseArrayLayer = 0,
|
||||
.layerCount = self->layered_dpb && !is_out ?
|
||||
VK_REMAINING_ARRAY_LAYERS : 1,
|
||||
.levelCount = 1,
|
||||
},
|
||||
};
|
||||
/* *INDENT-ON* */
|
||||
|
||||
return gst_vulkan_get_or_create_image_view_with_info (vkmem,
|
||||
&view_create_info);
|
||||
return gst_vulkan_video_image_create_view (buf, self->layered_dpb, is_out,
|
||||
priv->sampler);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -372,45 +372,6 @@ gst_vulkan_encoder_new_video_session_parameters (GstVulkanEncoder * self,
|
|||
priv->vk.DestroyVideoSessionParameters);
|
||||
}
|
||||
|
||||
static GstVulkanImageView *
|
||||
gst_vulkan_encoder_get_image_view_from_buffer (GstVulkanEncoder * self,
|
||||
GstBuffer * buf, gboolean dpb)
|
||||
{
|
||||
GstVulkanEncoderPrivate *priv =
|
||||
gst_vulkan_encoder_get_instance_private (self);
|
||||
VkImageViewCreateInfo view_create_info;
|
||||
GstVulkanImageMemory *vkmem;
|
||||
GstMemory *mem;
|
||||
guint n_mems;
|
||||
|
||||
n_mems = gst_buffer_n_memory (buf);
|
||||
g_assert (n_mems == 1);
|
||||
|
||||
mem = gst_buffer_peek_memory (buf, 0);
|
||||
g_assert (gst_is_vulkan_image_memory (mem));
|
||||
|
||||
vkmem = (GstVulkanImageMemory *) mem;
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
view_create_info = (VkImageViewCreateInfo) {
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
|
||||
.viewType = (dpb && priv->layered_dpb) ? VK_IMAGE_VIEW_TYPE_2D_ARRAY : VK_IMAGE_VIEW_TYPE_2D,
|
||||
.format = vkmem->create_info.format,
|
||||
.image = vkmem->image,
|
||||
.components = _vk_identity_component_map,
|
||||
.subresourceRange = (VkImageSubresourceRange) {
|
||||
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
|
||||
.baseArrayLayer = (dpb && priv->layered_dpb) ? priv->current_slot_index : 0,
|
||||
.layerCount = 1,
|
||||
.levelCount = 1,
|
||||
},
|
||||
};
|
||||
/* *INDENT-ON* */
|
||||
|
||||
return gst_vulkan_get_or_create_image_view_with_info (vkmem,
|
||||
&view_create_info);
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_vulkan_encode_picture_new:
|
||||
* @self: the #GstVulkanEncoder with the pool's configuration.
|
||||
|
@ -1141,9 +1102,8 @@ gst_vulkan_encoder_encode (GstVulkanEncoder * self,
|
|||
/* Set the ref slots according to the pic refs to bound the video
|
||||
session encoding. It should contain all the references + 1 to book
|
||||
a new slotIndex (-1) for the current picture. */
|
||||
pic->dpb_view =
|
||||
gst_vulkan_encoder_get_image_view_from_buffer (self, pic->dpb_buffer,
|
||||
TRUE);
|
||||
pic->dpb_view = gst_vulkan_video_image_create_view (pic->dpb_buffer,
|
||||
priv->layered_dpb, FALSE, NULL);
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
pic->dpb = (VkVideoPictureResourceInfoKHR) {
|
||||
|
@ -1248,9 +1208,8 @@ gst_vulkan_encoder_encode (GstVulkanEncoder * self,
|
|||
/* Peek the output memory to be used by VkVideoEncodeInfoKHR.dstBuffer */
|
||||
mem = gst_buffer_peek_memory (pic->out_buffer, n_mems);
|
||||
/* Peek the image view to be encoded */
|
||||
pic->img_view =
|
||||
gst_vulkan_encoder_get_image_view_from_buffer (self, pic->in_buffer,
|
||||
FALSE);
|
||||
pic->img_view = gst_vulkan_video_image_create_view (pic->in_buffer,
|
||||
priv->layered_dpb, TRUE, NULL);
|
||||
|
||||
/* Attribute a free slot index to the picture to be used later as a reference.
|
||||
* The picture is kept until it remains useful to the encoding process.*/
|
||||
|
|
|
@ -241,3 +241,74 @@ gst_vulkan_video_codec_buffer_new (GstVulkanDevice * device,
|
|||
gst_buffer_append_memory (buf, mem);
|
||||
return buf;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_vulkan_video_image_create_view:
|
||||
* @buf: a #GstBuffer
|
||||
* @layered_dpb: if DPB is layered
|
||||
* @is_out: if @buf is for output or for DPB
|
||||
* @sampler: (optional): sampler #GstVulkanHandle
|
||||
*
|
||||
* Creates a #GstVulkanImageView for @buf for decoding, with the internal Ycbcr
|
||||
* sampler, if available.
|
||||
*
|
||||
* Returns: (transfer full) (nullable): the #GstVulkanImageView.
|
||||
*/
|
||||
GstVulkanImageView *
|
||||
gst_vulkan_video_image_create_view (GstBuffer * buf, gboolean layered_dpb,
|
||||
gboolean is_out, GstVulkanHandle * sampler)
|
||||
{
|
||||
VkSamplerYcbcrConversionInfo yuv_sampler_info;
|
||||
VkImageViewCreateInfo view_create_info;
|
||||
GstVulkanImageMemory *vkmem;
|
||||
GstMemory *mem;
|
||||
gpointer pnext;
|
||||
guint n_mems;
|
||||
|
||||
g_return_val_if_fail (GST_IS_BUFFER (buf), NULL);
|
||||
|
||||
n_mems = gst_buffer_n_memory (buf);
|
||||
if (n_mems != 1)
|
||||
return NULL;
|
||||
|
||||
mem = gst_buffer_peek_memory (buf, 0);
|
||||
if (!gst_is_vulkan_image_memory (mem))
|
||||
return NULL;
|
||||
|
||||
pnext = NULL;
|
||||
if (sampler
|
||||
&& sampler->type == GST_VULKAN_HANDLE_TYPE_SAMPLER_YCBCR_CONVERSION) {
|
||||
yuv_sampler_info = (VkSamplerYcbcrConversionInfo) {
|
||||
/* *INDENT-OFF* */
|
||||
.sType = VK_STRUCTURE_TYPE_SAMPLER_YCBCR_CONVERSION_INFO,
|
||||
.conversion = sampler->handle,
|
||||
/* *INDENT-ON* */
|
||||
};
|
||||
|
||||
pnext = &yuv_sampler_info;
|
||||
}
|
||||
|
||||
vkmem = (GstVulkanImageMemory *) mem;
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
view_create_info = (VkImageViewCreateInfo) {
|
||||
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
|
||||
.pNext = pnext,
|
||||
.viewType = layered_dpb && !is_out ?
|
||||
VK_IMAGE_VIEW_TYPE_2D_ARRAY: VK_IMAGE_VIEW_TYPE_2D,
|
||||
.format = vkmem->create_info.format,
|
||||
.image = vkmem->image,
|
||||
.components = _vk_identity_component_map,
|
||||
.subresourceRange = (VkImageSubresourceRange) {
|
||||
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
|
||||
.baseArrayLayer = 0,
|
||||
.layerCount = layered_dpb && !is_out ?
|
||||
VK_REMAINING_ARRAY_LAYERS : 1,
|
||||
.levelCount = 1,
|
||||
},
|
||||
};
|
||||
/* *INDENT-ON* */
|
||||
|
||||
return gst_vulkan_get_or_create_image_view_with_info (vkmem,
|
||||
&view_create_info);
|
||||
}
|
||||
|
|
|
@ -91,4 +91,9 @@ GstBuffer * gst_vulkan_video_codec_buffer_new (GstVulkanDevice
|
|||
VkBufferUsageFlags usage,
|
||||
gsize size);
|
||||
|
||||
GstVulkanImageView * gst_vulkan_video_image_create_view (GstBuffer * buf,
|
||||
gboolean layered_dpb,
|
||||
gboolean is_out,
|
||||
GstVulkanHandle * sampler);
|
||||
|
||||
G_END_DECLS
|
||||
|
|
Loading…
Reference in a new issue