vkfullscreenrender: create descriptor sets later

The desciptor sets may be dependant on the caps
This commit is contained in:
Matthew Waters 2019-06-19 15:27:11 +10:00
parent 2e34dd891d
commit b93de8b0d8
2 changed files with 117 additions and 55 deletions

View file

@ -500,6 +500,41 @@ _create_render_pass (GstVulkanFullScreenRender * render)
return render_pass; return render_pass;
} }
static VkDescriptorSetLayout
_create_descriptor_set_layout (GstVulkanFullScreenRender * render)
{
GstVulkanFullScreenRenderClass *render_class =
GST_VULKAN_FULL_SCREEN_RENDER_GET_CLASS (render);
guint n_bindings;
VkDescriptorSetLayoutBinding *bindings =
render_class->descriptor_set_layout_bindings (render, &n_bindings);
/* *INDENT-OFF* */
VkDescriptorSetLayoutCreateInfo layout_info = {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
.pNext = NULL,
.bindingCount = n_bindings,
.pBindings = bindings
};
/* *INDENT-ON* */
VkDescriptorSetLayout descriptor_set_layout;
VkResult err;
GError *error = NULL;
err =
vkCreateDescriptorSetLayout (render->device->device, &layout_info,
NULL, &descriptor_set_layout);
g_free (bindings);
if (gst_vulkan_error_to_g_error (err, &error,
"vkCreateDescriptorSetLayout") < 0) {
GST_ERROR_OBJECT (render, "Failed to create renderpass: %s",
error->message);
return NULL;
}
return descriptor_set_layout;
}
static gboolean static gboolean
gst_vulkan_full_screen_render_set_caps (GstBaseTransform * bt, gst_vulkan_full_screen_render_set_caps (GstBaseTransform * bt,
GstCaps * in_caps, GstCaps * out_caps) GstCaps * in_caps, GstCaps * out_caps)
@ -514,22 +549,58 @@ gst_vulkan_full_screen_render_set_caps (GstBaseTransform * bt,
gst_caps_replace (&render->in_caps, in_caps); gst_caps_replace (&render->in_caps, in_caps);
gst_caps_replace (&render->out_caps, out_caps); gst_caps_replace (&render->out_caps, out_caps);
if (render->last_fence) {
if (render->descriptor_set_layout) {
render->trash_list = g_list_prepend (render->trash_list,
gst_vulkan_trash_new_free_descriptor_set_layout (gst_vulkan_fence_ref
(render->last_fence), render->descriptor_set_layout));
render->descriptor_set_layout = NULL;
}
if (render->pipeline_layout) {
render->trash_list = g_list_prepend (render->trash_list,
gst_vulkan_trash_new_free_pipeline_layout (gst_vulkan_fence_ref
(render->last_fence), render->pipeline_layout));
render->pipeline_layout = NULL;
}
if (render->render_pass) { if (render->render_pass) {
render->trash_list = g_list_prepend (render->trash_list, render->trash_list = g_list_prepend (render->trash_list,
gst_vulkan_trash_new_free_render_pass (gst_vulkan_fence_ref gst_vulkan_trash_new_free_render_pass (gst_vulkan_fence_ref
(render->last_fence), render->render_pass)); (render->last_fence), render->render_pass));
render->render_pass = NULL; render->render_pass = NULL;
} }
if (!(render->render_pass = _create_render_pass (render)))
return FALSE;
if (render->graphics_pipeline) { if (render->graphics_pipeline) {
render->trash_list = g_list_prepend (render->trash_list, render->trash_list = g_list_prepend (render->trash_list,
gst_vulkan_trash_new_free_pipeline (gst_vulkan_fence_ref gst_vulkan_trash_new_free_pipeline (gst_vulkan_fence_ref
(render->last_fence), render->graphics_pipeline)); (render->last_fence), render->graphics_pipeline));
render->graphics_pipeline = NULL; render->graphics_pipeline = NULL;
} }
} else {
if (render->graphics_pipeline)
vkDestroyPipeline (render->device->device,
render->graphics_pipeline, NULL);
render->graphics_pipeline = NULL;
if (render->pipeline_layout)
vkDestroyPipelineLayout (render->device->device,
render->pipeline_layout, NULL);
render->pipeline_layout = NULL;
if (render->render_pass)
vkDestroyRenderPass (render->device->device, render->render_pass, NULL);
render->render_pass = NULL;
if (render->descriptor_set_layout)
vkDestroyDescriptorSetLayout (render->device->device,
render->descriptor_set_layout, NULL);
render->descriptor_set_layout = NULL;
}
if (!(render->descriptor_set_layout = _create_descriptor_set_layout (render)))
return FALSE;
if (!(render->pipeline_layout = _create_pipeline_layout (render)))
return FALSE;
if (!(render->render_pass = _create_render_pass (render)))
return FALSE;
if (!(render->graphics_pipeline = _create_pipeline (render))) if (!(render->graphics_pipeline = _create_pipeline (render)))
return FALSE; return FALSE;
@ -598,41 +669,6 @@ gst_vulkan_full_screen_render_decide_allocation (GstBaseTransform * bt,
return TRUE; return TRUE;
} }
static VkDescriptorSetLayout
_create_descriptor_set_layout (GstVulkanFullScreenRender * render)
{
GstVulkanFullScreenRenderClass *render_class =
GST_VULKAN_FULL_SCREEN_RENDER_GET_CLASS (render);
guint n_bindings;
VkDescriptorSetLayoutBinding *bindings =
render_class->descriptor_set_layout_bindings (render, &n_bindings);
/* *INDENT-OFF* */
VkDescriptorSetLayoutCreateInfo layout_info = {
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
.pNext = NULL,
.bindingCount = n_bindings,
.pBindings = bindings
};
/* *INDENT-ON* */
VkDescriptorSetLayout descriptor_set_layout;
VkResult err;
GError *error = NULL;
err =
vkCreateDescriptorSetLayout (render->device->device, &layout_info,
NULL, &descriptor_set_layout);
g_free (bindings);
if (gst_vulkan_error_to_g_error (err, &error,
"vkCreateDescriptorSetLayout") < 0) {
GST_ERROR_OBJECT (render, "Failed to create renderpass: %s",
error->message);
return NULL;
}
return descriptor_set_layout;
}
static gboolean static gboolean
_create_vertex_buffers (GstVulkanFullScreenRender * render) _create_vertex_buffers (GstVulkanFullScreenRender * render)
{ {
@ -705,11 +741,6 @@ gst_vulkan_full_screen_render_start (GstBaseTransform * bt)
if (!render->queue) if (!render->queue)
return FALSE; return FALSE;
if (!(render->descriptor_set_layout = _create_descriptor_set_layout (render)))
return FALSE;
if (!(render->pipeline_layout = _create_pipeline_layout (render)))
return FALSE;
if (!_create_vertex_buffers (render)) if (!_create_vertex_buffers (render))
return FALSE; return FALSE;

View file

@ -47,6 +47,8 @@ static GstCaps *gst_vulkan_image_identity_transform_caps (GstBaseTransform * bt,
GstPadDirection direction, GstCaps * caps, GstCaps * filter); GstPadDirection direction, GstCaps * caps, GstCaps * filter);
static GstFlowReturn gst_vulkan_image_identity_transform (GstBaseTransform * bt, static GstFlowReturn gst_vulkan_image_identity_transform (GstBaseTransform * bt,
GstBuffer * inbuf, GstBuffer * outbuf); GstBuffer * inbuf, GstBuffer * outbuf);
static gboolean gst_vulkan_image_identity_set_caps (GstBaseTransform * bt,
GstCaps * in_caps, GstCaps * out_caps);
static VkAttachmentReference static VkAttachmentReference
* gst_vulkan_image_identity_render_pass_attachment_references * gst_vulkan_image_identity_render_pass_attachment_references
@ -124,6 +126,7 @@ gst_vulkan_image_identity_class_init (GstVulkanImageIdentityClass * klass)
GST_DEBUG_FUNCPTR (gst_vulkan_image_identity_stop); GST_DEBUG_FUNCPTR (gst_vulkan_image_identity_stop);
gstbasetransform_class->transform_caps = gstbasetransform_class->transform_caps =
gst_vulkan_image_identity_transform_caps; gst_vulkan_image_identity_transform_caps;
gstbasetransform_class->set_caps = gst_vulkan_image_identity_set_caps;
gstbasetransform_class->transform = gst_vulkan_image_identity_transform; gstbasetransform_class->transform = gst_vulkan_image_identity_transform;
fullscreenrender_class->render_pass_attachment_references = fullscreenrender_class->render_pass_attachment_references =
@ -340,6 +343,38 @@ _create_descriptor_set (GstVulkanImageIdentity * vk_identity)
return descriptor; return descriptor;
} }
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);
if (!GST_BASE_TRANSFORM_CLASS (parent_class)->set_caps (bt, in_caps,
out_caps))
return FALSE;
if (render->last_fence) {
render->trash_list = g_list_prepend (render->trash_list,
gst_vulkan_trash_new_free_descriptor_pool (gst_vulkan_fence_ref
(render->last_fence), vk_identity->descriptor_pool));
vk_identity->descriptor_set = NULL;
vk_identity->descriptor_pool = NULL;
} else {
vkDestroyDescriptorPool (render->device->device,
vk_identity->descriptor_pool, NULL);
vk_identity->descriptor_set = NULL;
vk_identity->descriptor_pool = NULL;
}
if (!(vk_identity->descriptor_pool = _create_descriptor_pool (vk_identity)))
return FALSE;
if (!(vk_identity->descriptor_set = _create_descriptor_set (vk_identity)))
return FALSE;
return TRUE;
}
static VkSampler static VkSampler
_create_sampler (GstVulkanImageIdentity * vk_identity) _create_sampler (GstVulkanImageIdentity * vk_identity)
{ {
@ -391,10 +426,6 @@ gst_vulkan_image_identity_start (GstBaseTransform * bt)
if (!(vk_identity->sampler = _create_sampler (vk_identity))) if (!(vk_identity->sampler = _create_sampler (vk_identity)))
return FALSE; return FALSE;
if (!(vk_identity->descriptor_pool = _create_descriptor_pool (vk_identity)))
return FALSE;
if (!(vk_identity->descriptor_set = _create_descriptor_set (vk_identity)))
return FALSE;
return TRUE; return TRUE;
} }