2019-05-16 09:48:24 +00:00
|
|
|
/*
|
|
|
|
* GStreamer
|
|
|
|
* Copyright (C) 2019 Matthew Waters <matthew@centricular.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:element-vulkanimageidentity
|
|
|
|
* @title: vulkanimgeidentity
|
|
|
|
*
|
|
|
|
* vulkanimageidentity produces a vulkan image that is a copy of the input image.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "vkimageidentity.h"
|
|
|
|
#include "vkshader.h"
|
2019-09-24 07:24:38 +00:00
|
|
|
#include "vkelementutils.h"
|
|
|
|
|
2019-05-16 09:48:24 +00:00
|
|
|
#include "shaders/identity.vert.h"
|
|
|
|
#include "shaders/identity.frag.h"
|
|
|
|
|
|
|
|
GST_DEBUG_CATEGORY (gst_debug_vulkan_image_identity);
|
|
|
|
#define GST_CAT_DEFAULT gst_debug_vulkan_image_identity
|
|
|
|
|
|
|
|
static gboolean gst_vulkan_image_identity_start (GstBaseTransform * bt);
|
|
|
|
static gboolean gst_vulkan_image_identity_stop (GstBaseTransform * bt);
|
|
|
|
|
|
|
|
static GstCaps *gst_vulkan_image_identity_transform_caps (GstBaseTransform * bt,
|
|
|
|
GstPadDirection direction, GstCaps * caps, GstCaps * filter);
|
|
|
|
static GstFlowReturn gst_vulkan_image_identity_transform (GstBaseTransform * bt,
|
|
|
|
GstBuffer * inbuf, GstBuffer * outbuf);
|
2019-06-19 05:27:11 +00:00
|
|
|
static gboolean gst_vulkan_image_identity_set_caps (GstBaseTransform * bt,
|
|
|
|
GstCaps * in_caps, GstCaps * out_caps);
|
2019-05-16 09:48:24 +00:00
|
|
|
|
2019-06-10 16:05:32 +00:00
|
|
|
static VkAttachmentReference
|
|
|
|
* gst_vulkan_image_identity_render_pass_attachment_references
|
|
|
|
(GstVulkanFullScreenRender * render, guint * n_attachments);
|
|
|
|
static VkAttachmentDescription
|
|
|
|
* gst_vulkan_image_identity_render_pass_attachment_descriptions
|
|
|
|
(GstVulkanFullScreenRender * render, guint * n_descriptions);
|
|
|
|
static VkDescriptorSetLayoutBinding
|
|
|
|
* gst_vulkan_image_identity_descriptor_set_layout_bindings
|
|
|
|
(GstVulkanFullScreenRender * render, guint * n_bindings);
|
|
|
|
static void
|
|
|
|
gst_vulkan_image_identity_shader_create_info (GstVulkanFullScreenRender *
|
|
|
|
render);
|
|
|
|
|
2019-05-16 09:48:24 +00:00
|
|
|
#define IMAGE_FORMATS " { BGRA }"
|
|
|
|
|
|
|
|
static GstStaticPadTemplate gst_vulkan_sink_template =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE_WITH_FEATURES
|
|
|
|
(GST_CAPS_FEATURE_MEMORY_VULKAN_IMAGE,
|
|
|
|
IMAGE_FORMATS)));
|
|
|
|
|
|
|
|
static GstStaticPadTemplate gst_vulkan_src_template =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE_WITH_FEATURES
|
|
|
|
(GST_CAPS_FEATURE_MEMORY_VULKAN_IMAGE,
|
|
|
|
IMAGE_FORMATS)));
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
SIGNAL_0,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
/* static guint gst_vulkan_image_identity_signals[LAST_SIGNAL] = { 0 }; */
|
|
|
|
|
|
|
|
#define gst_vulkan_image_identity_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstVulkanImageIdentity, gst_vulkan_image_identity,
|
2019-06-10 16:05:32 +00:00
|
|
|
GST_TYPE_VULKAN_FULL_SCREEN_RENDER,
|
2019-05-16 09:48:24 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_debug_vulkan_image_identity,
|
|
|
|
"vulkanimageidentity", 0, "Vulkan Image identity"));
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vulkan_image_identity_class_init (GstVulkanImageIdentityClass * klass)
|
|
|
|
{
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
GstBaseTransformClass *gstbasetransform_class;
|
2019-06-10 16:05:32 +00:00
|
|
|
GstVulkanFullScreenRenderClass *fullscreenrender_class;
|
2019-05-16 09:48:24 +00:00
|
|
|
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
|
|
|
gstbasetransform_class = (GstBaseTransformClass *) klass;
|
2019-06-10 16:05:32 +00:00
|
|
|
fullscreenrender_class = (GstVulkanFullScreenRenderClass *) klass;
|
2019-05-16 09:48:24 +00:00
|
|
|
|
|
|
|
gst_element_class_set_metadata (gstelement_class, "Vulkan Uploader",
|
|
|
|
"Filter/Video", "A Vulkan image copier",
|
|
|
|
"Matthew Waters <matthew@centricular.com>");
|
|
|
|
|
|
|
|
gst_element_class_add_static_pad_template (gstelement_class,
|
|
|
|
&gst_vulkan_sink_template);
|
|
|
|
gst_element_class_add_static_pad_template (gstelement_class,
|
|
|
|
&gst_vulkan_src_template);
|
|
|
|
|
|
|
|
gstbasetransform_class->start =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_vulkan_image_identity_start);
|
|
|
|
gstbasetransform_class->stop =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_vulkan_image_identity_stop);
|
|
|
|
gstbasetransform_class->transform_caps =
|
|
|
|
gst_vulkan_image_identity_transform_caps;
|
2019-06-19 05:27:11 +00:00
|
|
|
gstbasetransform_class->set_caps = gst_vulkan_image_identity_set_caps;
|
2019-05-16 09:48:24 +00:00
|
|
|
gstbasetransform_class->transform = gst_vulkan_image_identity_transform;
|
|
|
|
|
2019-06-10 16:05:32 +00:00
|
|
|
fullscreenrender_class->render_pass_attachment_references =
|
|
|
|
gst_vulkan_image_identity_render_pass_attachment_references;
|
|
|
|
fullscreenrender_class->render_pass_attachment_descriptions =
|
|
|
|
gst_vulkan_image_identity_render_pass_attachment_descriptions;
|
|
|
|
fullscreenrender_class->descriptor_set_layout_bindings =
|
|
|
|
gst_vulkan_image_identity_descriptor_set_layout_bindings;
|
|
|
|
fullscreenrender_class->shader_create_info =
|
|
|
|
gst_vulkan_image_identity_shader_create_info;
|
2019-05-16 09:48:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-06-10 16:05:32 +00:00
|
|
|
gst_vulkan_image_identity_init (GstVulkanImageIdentity * vk_identity)
|
2019-05-16 09:48:24 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstCaps *
|
|
|
|
gst_vulkan_image_identity_transform_caps (GstBaseTransform * bt,
|
|
|
|
GstPadDirection direction, GstCaps * caps, GstCaps * filter)
|
|
|
|
{
|
|
|
|
GstCaps *result, *tmp;
|
|
|
|
|
|
|
|
tmp = gst_caps_copy (caps);
|
|
|
|
|
|
|
|
if (filter) {
|
|
|
|
result = gst_caps_intersect_full (filter, tmp, GST_CAPS_INTERSECT_FIRST);
|
|
|
|
gst_caps_unref (tmp);
|
|
|
|
} else {
|
|
|
|
result = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-06-10 16:05:32 +00:00
|
|
|
static void
|
|
|
|
destroy_shader_create_info (GstVulkanFullScreenRender * render, gpointer data)
|
2019-05-16 09:48:24 +00:00
|
|
|
{
|
2019-06-10 16:05:32 +00:00
|
|
|
VkPipelineShaderStageCreateInfo *info = data;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < render->n_shader_stages; i++) {
|
|
|
|
vkDestroyShaderModule (render->device->device, info[i].module, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (info);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vulkan_image_identity_shader_create_info (GstVulkanFullScreenRender *
|
|
|
|
render)
|
|
|
|
{
|
|
|
|
VkShaderModule vert_module, frag_module;
|
|
|
|
|
|
|
|
vert_module =
|
|
|
|
_vk_create_shader (render->device, identity_vert, identity_vert_size,
|
2019-05-16 09:48:24 +00:00
|
|
|
NULL);
|
2019-06-10 16:05:32 +00:00
|
|
|
frag_module =
|
|
|
|
_vk_create_shader (render->device, identity_frag, identity_frag_size,
|
2019-05-16 09:48:24 +00:00
|
|
|
NULL);
|
|
|
|
|
2019-06-10 16:05:32 +00:00
|
|
|
render->n_shader_stages = 2;
|
|
|
|
render->shader_create_info =
|
|
|
|
g_new0 (VkPipelineShaderStageCreateInfo, render->n_shader_stages);
|
|
|
|
render->destroy_shader_create_info = destroy_shader_create_info;
|
|
|
|
|
2019-05-16 09:48:24 +00:00
|
|
|
/* *INDENT-OFF* */
|
2019-06-10 16:05:32 +00:00
|
|
|
render->shader_create_info[0] = (VkPipelineShaderStageCreateInfo) {
|
2019-05-16 09:48:24 +00:00
|
|
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
|
|
|
|
.pNext = NULL,
|
|
|
|
.stage = VK_SHADER_STAGE_VERTEX_BIT,
|
|
|
|
.module = vert_module,
|
|
|
|
.pName = "main"
|
|
|
|
};
|
|
|
|
|
2019-06-10 16:05:32 +00:00
|
|
|
render->shader_create_info[1] = (VkPipelineShaderStageCreateInfo) {
|
2019-05-16 09:48:24 +00:00
|
|
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
|
|
|
|
.pNext = NULL,
|
|
|
|
.stage = VK_SHADER_STAGE_FRAGMENT_BIT,
|
|
|
|
.module = frag_module,
|
|
|
|
.pName = "main"
|
|
|
|
};
|
2019-06-10 16:05:32 +00:00
|
|
|
}
|
2019-05-16 09:48:24 +00:00
|
|
|
|
2019-06-10 16:05:32 +00:00
|
|
|
static VkDescriptorSetLayoutBinding *
|
|
|
|
gst_vulkan_image_identity_descriptor_set_layout_bindings (GstVulkanFullScreenRender * render, guint * n_bindings)
|
|
|
|
{
|
|
|
|
VkDescriptorSetLayoutBinding *bindings;
|
2019-05-16 09:48:24 +00:00
|
|
|
|
2019-06-10 16:05:32 +00:00
|
|
|
*n_bindings = 1;
|
|
|
|
bindings = g_new0 (VkDescriptorSetLayoutBinding, *n_bindings);
|
2019-05-16 09:48:24 +00:00
|
|
|
|
2019-06-10 16:05:32 +00:00
|
|
|
/* *INDENT-OFF* */
|
|
|
|
bindings[0] = (VkDescriptorSetLayoutBinding) {
|
|
|
|
.binding = 0,
|
|
|
|
.descriptorCount = 1,
|
|
|
|
.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
|
|
|
.pImmutableSamplers = NULL,
|
|
|
|
.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT
|
2019-05-16 09:48:24 +00:00
|
|
|
};
|
|
|
|
/* *INDENT-ON* */
|
|
|
|
|
2019-06-10 16:05:32 +00:00
|
|
|
return bindings;
|
2019-05-16 09:48:24 +00:00
|
|
|
}
|
|
|
|
|
2019-06-10 16:05:32 +00:00
|
|
|
static VkAttachmentReference
|
|
|
|
* gst_vulkan_image_identity_render_pass_attachment_references
|
|
|
|
(GstVulkanFullScreenRender * render, guint * n_attachments)
|
2019-05-16 09:48:24 +00:00
|
|
|
{
|
2019-06-10 16:05:32 +00:00
|
|
|
VkAttachmentReference *attachments;
|
|
|
|
|
|
|
|
*n_attachments = 1;
|
|
|
|
attachments = g_new0 (VkAttachmentReference, *n_attachments);
|
2019-05-16 09:48:24 +00:00
|
|
|
/* *INDENT-OFF* */
|
2019-06-10 16:05:32 +00:00
|
|
|
attachments[0] = (VkAttachmentReference) {
|
|
|
|
.attachment = 0,
|
|
|
|
.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
|
2019-05-16 09:48:24 +00:00
|
|
|
};
|
|
|
|
/* *INDENT-ON* */
|
|
|
|
|
2019-06-10 16:05:32 +00:00
|
|
|
return attachments;
|
2019-05-16 09:48:24 +00:00
|
|
|
}
|
|
|
|
|
2019-06-10 16:05:32 +00:00
|
|
|
static VkAttachmentDescription
|
|
|
|
* gst_vulkan_image_identity_render_pass_attachment_descriptions
|
|
|
|
(GstVulkanFullScreenRender * render, guint * n_descriptions)
|
2019-05-16 09:48:24 +00:00
|
|
|
{
|
2019-06-10 16:05:32 +00:00
|
|
|
VkAttachmentDescription *color_attachments;
|
2019-05-16 09:48:24 +00:00
|
|
|
|
2019-06-10 16:05:32 +00:00
|
|
|
*n_descriptions = 1;
|
|
|
|
color_attachments = g_new0 (VkAttachmentDescription, *n_descriptions);
|
2019-05-16 09:48:24 +00:00
|
|
|
/* *INDENT-OFF* */
|
2019-06-10 16:05:32 +00:00
|
|
|
color_attachments[0] = (VkAttachmentDescription) {
|
2019-10-29 13:57:55 +00:00
|
|
|
.format = gst_vulkan_format_from_video_info (&render->in_info, 0),
|
2019-05-16 09:48:24 +00:00
|
|
|
.samples = VK_SAMPLE_COUNT_1_BIT,
|
|
|
|
.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR,
|
|
|
|
.storeOp = VK_ATTACHMENT_STORE_OP_STORE,
|
|
|
|
.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE,
|
|
|
|
.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE,
|
|
|
|
/* FIXME: share this between elements to avoid pipeline barriers */
|
|
|
|
.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
|
|
|
|
.finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
|
|
|
|
};
|
2019-06-10 16:05:32 +00:00
|
|
|
/* *INDENT-ON* */
|
2019-05-16 09:48:24 +00:00
|
|
|
|
2019-06-10 16:05:32 +00:00
|
|
|
return color_attachments;
|
|
|
|
}
|
2019-05-16 09:48:24 +00:00
|
|
|
|
2019-11-06 11:19:42 +00:00
|
|
|
static GstVulkanDescriptorCache *
|
2019-06-10 16:05:32 +00:00
|
|
|
_create_descriptor_pool (GstVulkanImageIdentity * vk_identity)
|
|
|
|
{
|
|
|
|
GstVulkanFullScreenRender *render =
|
|
|
|
GST_VULKAN_FULL_SCREEN_RENDER (vk_identity);
|
2019-11-06 11:19:42 +00:00
|
|
|
guint max_sets = 32; /* FIXME: Don't hardcode this! */
|
2019-06-10 16:05:32 +00:00
|
|
|
|
|
|
|
/* *INDENT-OFF* */
|
|
|
|
VkDescriptorPoolSize pool_sizes = {
|
|
|
|
.type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
2019-11-06 11:19:42 +00:00
|
|
|
.descriptorCount = max_sets
|
2019-05-16 09:48:24 +00:00
|
|
|
};
|
|
|
|
|
2019-06-10 16:05:32 +00:00
|
|
|
VkDescriptorPoolCreateInfo pool_info = {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
|
2019-05-16 09:48:24 +00:00
|
|
|
.pNext = NULL,
|
2019-06-10 16:05:32 +00:00
|
|
|
.poolSizeCount = 1,
|
|
|
|
.pPoolSizes = &pool_sizes,
|
2019-11-06 11:19:42 +00:00
|
|
|
.maxSets = max_sets
|
2019-05-16 09:48:24 +00:00
|
|
|
};
|
|
|
|
/* *INDENT-ON* */
|
2019-06-10 16:05:32 +00:00
|
|
|
VkDescriptorPool pool;
|
2019-11-06 11:19:42 +00:00
|
|
|
GstVulkanDescriptorPool *ret;
|
|
|
|
GstVulkanDescriptorCache *cache;
|
2019-05-16 09:48:24 +00:00
|
|
|
GError *error = NULL;
|
2019-06-10 16:05:32 +00:00
|
|
|
VkResult err;
|
2019-05-16 09:48:24 +00:00
|
|
|
|
|
|
|
err =
|
2019-06-10 16:05:32 +00:00
|
|
|
vkCreateDescriptorPool (render->device->device, &pool_info, NULL, &pool);
|
|
|
|
if (gst_vulkan_error_to_g_error (err, &error, "vkCreateDescriptorPool") < 0) {
|
|
|
|
GST_ERROR_OBJECT (render, "Failed to create descriptor pool: %s",
|
2019-05-16 09:48:24 +00:00
|
|
|
error->message);
|
2019-06-10 16:05:32 +00:00
|
|
|
g_clear_error (&error);
|
2019-11-06 11:19:42 +00:00
|
|
|
return NULL;
|
2019-05-16 09:48:24 +00:00
|
|
|
}
|
|
|
|
|
2019-11-06 11:19:42 +00:00
|
|
|
ret = gst_vulkan_descriptor_pool_new_wrapped (render->device, pool, max_sets);
|
|
|
|
cache =
|
|
|
|
gst_vulkan_descriptor_cache_new (ret, 1, &render->descriptor_set_layout);
|
|
|
|
gst_object_unref (ret);
|
2019-05-16 09:48:24 +00:00
|
|
|
|
2019-11-06 11:19:42 +00:00
|
|
|
return cache;
|
2019-05-16 09:48:24 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 05:27:11 +00:00
|
|
|
static gboolean
|
|
|
|
gst_vulkan_image_identity_set_caps (GstBaseTransform * bt, GstCaps * in_caps,
|
|
|
|
GstCaps * out_caps)
|
|
|
|
{
|
|
|
|
GstVulkanImageIdentity *vk_identity = GST_VULKAN_IMAGE_IDENTITY (bt);
|
|
|
|
GstVulkanFullScreenRender *render = GST_VULKAN_FULL_SCREEN_RENDER (bt);
|
2019-11-05 22:34:36 +00:00
|
|
|
GstVulkanFence *last_fence;
|
2019-06-19 05:27:11 +00:00
|
|
|
|
|
|
|
if (!GST_BASE_TRANSFORM_CLASS (parent_class)->set_caps (bt, in_caps,
|
|
|
|
out_caps))
|
|
|
|
return FALSE;
|
|
|
|
|
2019-11-05 22:34:36 +00:00
|
|
|
if (render->last_fence)
|
|
|
|
last_fence = gst_vulkan_fence_ref (render->last_fence);
|
|
|
|
else
|
|
|
|
last_fence = gst_vulkan_fence_new_always_signalled (render->device);
|
|
|
|
|
2019-11-06 11:19:42 +00:00
|
|
|
if (vk_identity->descriptor_pool)
|
|
|
|
gst_vulkan_trash_list_add (render->trash_list,
|
|
|
|
gst_vulkan_trash_new_object_unref (gst_vulkan_fence_ref
|
|
|
|
(last_fence), (GstObject *) vk_identity->descriptor_pool));
|
|
|
|
vk_identity->descriptor_pool = NULL;
|
2019-11-05 22:34:36 +00:00
|
|
|
|
|
|
|
gst_vulkan_fence_unref (last_fence);
|
2019-06-19 05:27:11 +00:00
|
|
|
|
|
|
|
if (!(vk_identity->descriptor_pool = _create_descriptor_pool (vk_identity)))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-05-16 09:48:24 +00:00
|
|
|
static VkSampler
|
|
|
|
_create_sampler (GstVulkanImageIdentity * vk_identity)
|
|
|
|
{
|
2019-06-10 16:05:32 +00:00
|
|
|
GstVulkanFullScreenRender *render =
|
|
|
|
GST_VULKAN_FULL_SCREEN_RENDER (vk_identity);
|
|
|
|
|
2019-05-16 09:48:24 +00:00
|
|
|
/* *INDENT-OFF* */
|
|
|
|
VkSamplerCreateInfo samplerInfo = {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
|
|
|
|
.magFilter = VK_FILTER_LINEAR,
|
|
|
|
.minFilter = VK_FILTER_LINEAR,
|
2019-10-27 15:18:18 +00:00
|
|
|
.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
|
|
|
|
.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
|
|
|
|
.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
|
2019-05-16 09:48:24 +00:00
|
|
|
.anisotropyEnable = VK_FALSE,
|
|
|
|
.maxAnisotropy = 1,
|
|
|
|
.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK,
|
|
|
|
.unnormalizedCoordinates = VK_FALSE,
|
|
|
|
.compareEnable = VK_FALSE,
|
|
|
|
.compareOp = VK_COMPARE_OP_ALWAYS,
|
|
|
|
.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR,
|
|
|
|
.mipLodBias = 0.0f,
|
|
|
|
.minLod = 0.0f,
|
|
|
|
.maxLod = 0.0f
|
|
|
|
};
|
|
|
|
/* *INDENT-ON* */
|
|
|
|
GError *error = NULL;
|
|
|
|
VkSampler sampler;
|
|
|
|
VkResult err;
|
|
|
|
|
2019-06-10 16:05:32 +00:00
|
|
|
err = vkCreateSampler (render->device->device, &samplerInfo, NULL, &sampler);
|
2019-05-16 09:48:24 +00:00
|
|
|
if (gst_vulkan_error_to_g_error (err, &error, "vkCreateSampler") < 0) {
|
|
|
|
GST_ERROR_OBJECT (vk_identity, "Failed to create sampler: %s",
|
|
|
|
error->message);
|
|
|
|
g_clear_error (&error);
|
2019-10-16 06:42:33 +00:00
|
|
|
return VK_NULL_HANDLE;
|
2019-05-16 09:48:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return sampler;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_vulkan_image_identity_start (GstBaseTransform * bt)
|
|
|
|
{
|
|
|
|
GstVulkanImageIdentity *vk_identity = GST_VULKAN_IMAGE_IDENTITY (bt);
|
|
|
|
|
2019-06-10 16:05:32 +00:00
|
|
|
if (!GST_BASE_TRANSFORM_CLASS (parent_class)->start (bt))
|
2019-05-16 09:48:24 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!(vk_identity->sampler = _create_sampler (vk_identity)))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_vulkan_image_identity_stop (GstBaseTransform * bt)
|
|
|
|
{
|
|
|
|
GstVulkanImageIdentity *vk_identity = GST_VULKAN_IMAGE_IDENTITY (bt);
|
2019-06-10 16:05:32 +00:00
|
|
|
GstVulkanFullScreenRender *render = GST_VULKAN_FULL_SCREEN_RENDER (bt);
|
2019-05-16 09:48:24 +00:00
|
|
|
|
2019-06-10 16:05:32 +00:00
|
|
|
if (render->device) {
|
2019-11-05 22:34:36 +00:00
|
|
|
GstVulkanFence *last_fence;
|
|
|
|
|
|
|
|
if (render->last_fence)
|
|
|
|
last_fence = gst_vulkan_fence_ref (render->last_fence);
|
|
|
|
else
|
|
|
|
last_fence = gst_vulkan_fence_new_always_signalled (render->device);
|
|
|
|
|
2019-11-06 11:19:42 +00:00
|
|
|
gst_vulkan_trash_list_add (render->trash_list,
|
|
|
|
gst_vulkan_trash_new_object_unref (gst_vulkan_fence_ref
|
|
|
|
(last_fence), (GstObject *) vk_identity->descriptor_pool));
|
|
|
|
vk_identity->descriptor_pool = NULL;
|
|
|
|
gst_vulkan_trash_list_add (render->trash_list,
|
|
|
|
gst_vulkan_trash_new_free_sampler (gst_vulkan_fence_ref
|
|
|
|
(last_fence), vk_identity->sampler));
|
2019-11-05 22:34:36 +00:00
|
|
|
vk_identity->sampler = VK_NULL_HANDLE;
|
|
|
|
|
|
|
|
gst_vulkan_fence_unref (last_fence);
|
2019-05-16 09:48:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (vk_identity->cmd_pool)
|
|
|
|
gst_object_unref (vk_identity->cmd_pool);
|
2019-10-16 06:42:33 +00:00
|
|
|
vk_identity->cmd_pool = VK_NULL_HANDLE;
|
2019-05-16 09:48:24 +00:00
|
|
|
|
2019-06-10 16:05:32 +00:00
|
|
|
return GST_BASE_TRANSFORM_CLASS (parent_class)->stop (bt);
|
2019-05-16 09:48:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-11-06 11:19:42 +00:00
|
|
|
update_descriptor_set (GstVulkanImageIdentity * vk_identity,
|
|
|
|
VkDescriptorSet set, VkImageView view)
|
2019-05-16 09:48:24 +00:00
|
|
|
{
|
2019-06-10 16:05:32 +00:00
|
|
|
GstVulkanFullScreenRender *render =
|
|
|
|
GST_VULKAN_FULL_SCREEN_RENDER (vk_identity);
|
|
|
|
|
2019-05-16 09:48:24 +00:00
|
|
|
/* *INDENT-OFF* */
|
|
|
|
VkDescriptorImageInfo image_info = {
|
|
|
|
.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
|
|
|
.imageView = view,
|
|
|
|
.sampler = vk_identity->sampler
|
|
|
|
};
|
|
|
|
|
|
|
|
VkWriteDescriptorSet writes = {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
|
|
|
|
.pNext = NULL,
|
2019-11-06 11:19:42 +00:00
|
|
|
.dstSet = set,
|
2019-05-16 09:48:24 +00:00
|
|
|
.dstBinding = 0,
|
|
|
|
.dstArrayElement = 0,
|
|
|
|
.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
|
|
|
.descriptorCount = 1,
|
|
|
|
.pImageInfo = &image_info
|
|
|
|
};
|
|
|
|
/* *INDENT-ON* */
|
2019-06-10 16:05:32 +00:00
|
|
|
vkUpdateDescriptorSets (render->device->device, 1, &writes, 0, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VkFramebuffer
|
|
|
|
_create_framebuffer (GstVulkanImageIdentity * vk_identity, VkImageView view)
|
|
|
|
{
|
|
|
|
GstVulkanFullScreenRender *render =
|
|
|
|
GST_VULKAN_FULL_SCREEN_RENDER (vk_identity);
|
2019-05-16 09:48:24 +00:00
|
|
|
|
2019-06-10 16:05:32 +00:00
|
|
|
/* *INDENT-OFF* */
|
|
|
|
VkImageView attachments[] = {
|
|
|
|
view,
|
|
|
|
};
|
|
|
|
VkFramebufferCreateInfo framebuffer_info = {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
|
|
|
|
.pNext = NULL,
|
|
|
|
.renderPass = render->render_pass,
|
|
|
|
.attachmentCount = 1,
|
|
|
|
.pAttachments = attachments,
|
|
|
|
.width = GST_VIDEO_INFO_WIDTH (&render->in_info),
|
|
|
|
.height = GST_VIDEO_INFO_HEIGHT (&render->in_info),
|
|
|
|
.layers = 1
|
|
|
|
};
|
|
|
|
/* *INDENT-ON* */
|
|
|
|
VkFramebuffer framebuffer;
|
|
|
|
GError *error = NULL;
|
|
|
|
VkResult err;
|
|
|
|
|
|
|
|
err =
|
|
|
|
vkCreateFramebuffer (render->device->device, &framebuffer_info, NULL,
|
|
|
|
&framebuffer);
|
|
|
|
if (gst_vulkan_error_to_g_error (err, &error, "vkCreateFramebuffer") < 0) {
|
|
|
|
GST_ERROR_OBJECT (render, "Failed to create framebuffer: %s",
|
|
|
|
error->message);
|
|
|
|
g_clear_error (&error);
|
2019-10-16 06:42:33 +00:00
|
|
|
return VK_NULL_HANDLE;
|
2019-06-10 16:05:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return framebuffer;
|
2019-05-16 09:48:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_vulkan_image_identity_transform (GstBaseTransform * bt, GstBuffer * inbuf,
|
|
|
|
GstBuffer * outbuf)
|
|
|
|
{
|
2019-06-10 16:05:32 +00:00
|
|
|
GstVulkanFullScreenRender *render = GST_VULKAN_FULL_SCREEN_RENDER (bt);
|
2019-05-16 09:48:24 +00:00
|
|
|
GstVulkanImageIdentity *vk_identity = GST_VULKAN_IMAGE_IDENTITY (bt);
|
|
|
|
GstVulkanImageMemory *in_img_mem, *out_img_mem;
|
2019-09-24 07:24:38 +00:00
|
|
|
GstVulkanImageView *in_img_view, *out_img_view;
|
2019-05-16 09:48:24 +00:00
|
|
|
GstVulkanFence *fence = NULL;
|
2019-11-06 11:19:42 +00:00
|
|
|
GstVulkanDescriptorSet *set;
|
2019-05-16 09:48:24 +00:00
|
|
|
GstMemory *in_mem, *out_mem;
|
|
|
|
VkFramebuffer framebuffer;
|
2019-09-17 12:24:04 +00:00
|
|
|
GstVulkanCommandBuffer *cmd_buf;
|
2019-05-16 09:48:24 +00:00
|
|
|
GError *error = NULL;
|
|
|
|
VkResult err;
|
|
|
|
|
2019-10-27 15:27:04 +00:00
|
|
|
fence = gst_vulkan_fence_new (render->device, 0, &error);
|
|
|
|
if (!fence)
|
|
|
|
goto error;
|
|
|
|
|
2019-05-16 09:48:24 +00:00
|
|
|
in_mem = gst_buffer_peek_memory (inbuf, 0);
|
|
|
|
if (!gst_is_vulkan_image_memory (in_mem)) {
|
|
|
|
g_set_error_literal (&error, GST_VULKAN_ERROR, GST_VULKAN_FAILED,
|
|
|
|
"Input memory must be a GstVulkanImageMemory");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
in_img_mem = (GstVulkanImageMemory *) in_mem;
|
2019-09-24 07:24:38 +00:00
|
|
|
in_img_view = get_or_create_image_view (in_img_mem);
|
|
|
|
gst_vulkan_trash_list_add (render->trash_list,
|
|
|
|
gst_vulkan_trash_new_mini_object_unref (gst_vulkan_fence_ref (fence),
|
|
|
|
GST_MINI_OBJECT_CAST (in_img_view)));
|
2019-05-16 09:48:24 +00:00
|
|
|
|
|
|
|
out_mem = gst_buffer_peek_memory (outbuf, 0);
|
|
|
|
if (!gst_is_vulkan_image_memory (out_mem)) {
|
|
|
|
g_set_error_literal (&error, GST_VULKAN_ERROR, GST_VULKAN_FAILED,
|
|
|
|
"Input memory must be a GstVulkanImageMemory");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
out_img_mem = (GstVulkanImageMemory *) out_mem;
|
2019-09-24 07:24:38 +00:00
|
|
|
out_img_view = get_or_create_image_view (out_img_mem);
|
|
|
|
gst_vulkan_trash_list_add (render->trash_list,
|
|
|
|
gst_vulkan_trash_new_mini_object_unref (gst_vulkan_fence_ref (fence),
|
|
|
|
GST_MINI_OBJECT_CAST (out_img_view)));
|
2019-05-16 09:48:24 +00:00
|
|
|
|
|
|
|
if (!vk_identity->cmd_pool) {
|
|
|
|
if (!(vk_identity->cmd_pool =
|
2019-06-10 16:05:32 +00:00
|
|
|
gst_vulkan_queue_create_command_pool (render->queue, &error)))
|
2019-05-16 09:48:24 +00:00
|
|
|
goto error;
|
|
|
|
}
|
2019-11-06 11:19:42 +00:00
|
|
|
if (!(set =
|
|
|
|
gst_vulkan_descriptor_cache_acquire (vk_identity->descriptor_pool,
|
|
|
|
&error)))
|
|
|
|
goto error;
|
|
|
|
update_descriptor_set (vk_identity, set->set, in_img_view->view);
|
2019-05-16 09:48:24 +00:00
|
|
|
|
2019-09-17 12:24:04 +00:00
|
|
|
if (!(cmd_buf =
|
|
|
|
gst_vulkan_command_pool_create (vk_identity->cmd_pool, &error)))
|
2019-05-16 09:48:24 +00:00
|
|
|
goto error;
|
|
|
|
|
2019-09-24 07:24:38 +00:00
|
|
|
if (!(framebuffer = _create_framebuffer (vk_identity, out_img_view->view))) {
|
2019-05-16 09:48:24 +00:00
|
|
|
g_set_error_literal (&error, GST_VULKAN_ERROR, GST_VULKAN_FAILED,
|
|
|
|
"Failed to create framebuffer");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2019-06-10 16:05:32 +00:00
|
|
|
|
2019-05-16 09:48:24 +00:00
|
|
|
{
|
|
|
|
VkCommandBufferBeginInfo cmd_buf_info = { 0, };
|
|
|
|
|
|
|
|
/* *INDENT-OFF* */
|
|
|
|
cmd_buf_info = (VkCommandBufferBeginInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
|
|
|
|
.pNext = NULL,
|
|
|
|
.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,
|
|
|
|
.pInheritanceInfo = NULL
|
|
|
|
};
|
|
|
|
/* *INDENT-ON* */
|
|
|
|
|
2019-09-17 12:24:04 +00:00
|
|
|
gst_vulkan_command_buffer_lock (cmd_buf);
|
|
|
|
err = vkBeginCommandBuffer (cmd_buf->cmd, &cmd_buf_info);
|
2019-05-16 09:48:24 +00:00
|
|
|
if (gst_vulkan_error_to_g_error (err, &error, "vkBeginCommandBuffer") < 0)
|
2019-09-17 12:24:04 +00:00
|
|
|
goto unlock_error;
|
2019-05-16 09:48:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
/* *INDENT-OFF* */
|
2019-05-20 03:46:56 +00:00
|
|
|
VkImageMemoryBarrier in_image_memory_barrier = {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
|
|
|
|
.pNext = NULL,
|
|
|
|
.srcAccessMask = in_img_mem->barrier.parent.access_flags,
|
|
|
|
.dstAccessMask = VK_ACCESS_INPUT_ATTACHMENT_READ_BIT,
|
|
|
|
.oldLayout = in_img_mem->barrier.image_layout,
|
|
|
|
.newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
|
|
|
/* FIXME: implement exclusive transfers */
|
|
|
|
.srcQueueFamilyIndex = 0,
|
|
|
|
.dstQueueFamilyIndex = 0,
|
|
|
|
.image = in_img_mem->image,
|
|
|
|
.subresourceRange = in_img_mem->barrier.subresource_range
|
|
|
|
};
|
|
|
|
|
|
|
|
VkImageMemoryBarrier out_image_memory_barrier = {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
|
|
|
|
.pNext = NULL,
|
|
|
|
.srcAccessMask = out_img_mem->barrier.parent.access_flags,
|
|
|
|
.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
|
|
|
|
.oldLayout = out_img_mem->barrier.image_layout,
|
|
|
|
.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
|
|
|
|
/* FIXME: implement exclusive transfers */
|
|
|
|
.srcQueueFamilyIndex = 0,
|
|
|
|
.dstQueueFamilyIndex = 0,
|
|
|
|
.image = out_img_mem->image,
|
|
|
|
.subresourceRange = out_img_mem->barrier.subresource_range
|
|
|
|
};
|
2019-05-16 09:48:24 +00:00
|
|
|
/* *INDENT-ON* */
|
|
|
|
|
2019-09-17 12:24:04 +00:00
|
|
|
vkCmdPipelineBarrier (cmd_buf->cmd,
|
|
|
|
in_img_mem->barrier.parent.pipeline_stages,
|
2019-05-20 03:46:56 +00:00
|
|
|
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0, 0, NULL, 0, NULL, 1,
|
|
|
|
&in_image_memory_barrier);
|
|
|
|
|
|
|
|
in_img_mem->barrier.parent.pipeline_stages =
|
|
|
|
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
|
|
|
|
in_img_mem->barrier.parent.access_flags =
|
|
|
|
in_image_memory_barrier.dstAccessMask;
|
|
|
|
in_img_mem->barrier.image_layout = in_image_memory_barrier.newLayout;
|
|
|
|
|
2019-09-17 12:24:04 +00:00
|
|
|
vkCmdPipelineBarrier (cmd_buf->cmd,
|
|
|
|
out_img_mem->barrier.parent.pipeline_stages,
|
2019-05-20 03:46:56 +00:00
|
|
|
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, 0, 0, NULL, 0, NULL, 1,
|
|
|
|
&out_image_memory_barrier);
|
|
|
|
|
|
|
|
out_img_mem->barrier.parent.pipeline_stages =
|
|
|
|
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
|
|
|
out_img_mem->barrier.parent.access_flags =
|
|
|
|
out_image_memory_barrier.dstAccessMask;
|
|
|
|
out_img_mem->barrier.image_layout = out_image_memory_barrier.newLayout;
|
2019-05-16 09:48:24 +00:00
|
|
|
}
|
|
|
|
|
2019-09-17 12:24:04 +00:00
|
|
|
vkCmdBindDescriptorSets (cmd_buf->cmd, VK_PIPELINE_BIND_POINT_GRAPHICS,
|
2019-11-06 11:19:42 +00:00
|
|
|
render->pipeline_layout, 0, 1, &set->set, 0, NULL);
|
2019-09-17 12:24:04 +00:00
|
|
|
if (!gst_vulkan_full_screen_render_fill_command_buffer (render, cmd_buf->cmd,
|
2019-06-10 16:05:32 +00:00
|
|
|
framebuffer))
|
2019-09-17 12:24:04 +00:00
|
|
|
goto unlock_error;
|
2019-06-10 16:05:32 +00:00
|
|
|
|
2019-09-17 12:24:04 +00:00
|
|
|
err = vkEndCommandBuffer (cmd_buf->cmd);
|
|
|
|
gst_vulkan_command_buffer_unlock (cmd_buf);
|
2019-05-16 09:48:24 +00:00
|
|
|
if (gst_vulkan_error_to_g_error (err, &error, "vkEndCommandBuffer") < 0)
|
|
|
|
goto error;
|
|
|
|
|
2019-11-06 11:19:42 +00:00
|
|
|
gst_vulkan_trash_list_add (render->trash_list,
|
|
|
|
gst_vulkan_trash_new_mini_object_unref (gst_vulkan_fence_ref (fence),
|
|
|
|
GST_MINI_OBJECT_CAST (set)));
|
2019-07-04 04:03:51 +00:00
|
|
|
gst_vulkan_trash_list_add (render->trash_list,
|
2019-05-16 09:48:24 +00:00
|
|
|
gst_vulkan_trash_new_free_framebuffer (gst_vulkan_fence_ref (fence),
|
|
|
|
framebuffer));
|
2019-07-04 04:03:51 +00:00
|
|
|
gst_vulkan_trash_list_add (render->trash_list,
|
2019-09-17 12:24:04 +00:00
|
|
|
gst_vulkan_trash_new_mini_object_unref (gst_vulkan_fence_ref (fence),
|
|
|
|
GST_MINI_OBJECT_CAST (cmd_buf)));
|
2019-05-16 09:48:24 +00:00
|
|
|
|
2019-09-17 12:24:04 +00:00
|
|
|
if (!gst_vulkan_full_screen_render_submit (render, cmd_buf->cmd, fence))
|
2019-06-10 16:05:32 +00:00
|
|
|
return GST_FLOW_ERROR;
|
2019-05-16 09:48:24 +00:00
|
|
|
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
|
2019-09-17 12:24:04 +00:00
|
|
|
unlock_error:
|
|
|
|
if (cmd_buf) {
|
|
|
|
gst_vulkan_command_buffer_unlock (cmd_buf);
|
|
|
|
gst_vulkan_command_buffer_unref (cmd_buf);
|
|
|
|
}
|
2019-05-16 09:48:24 +00:00
|
|
|
error:
|
|
|
|
GST_ELEMENT_ERROR (bt, LIBRARY, FAILED, ("%s", error->message), (NULL));
|
|
|
|
g_clear_error (&error);
|
|
|
|
return GST_FLOW_ERROR;
|
|
|
|
}
|