Commit adff3995 authored by Benjamin Otte's avatar Benjamin Otte

vulkan: Move command pool and fence into render object

parent 96355981
......@@ -21,6 +21,8 @@ struct _GskVulkanRender
VkRect2D scissor;
VkCommandPool command_pool;
VkFence fence;
VkCommandBuffer command_buffer;
GSList *render_passes;
......@@ -56,20 +58,38 @@ gsk_vulkan_render_compute_mvp (GskVulkanRender *self)
GskVulkanRender *
gsk_vulkan_render_new (GskRenderer *renderer,
GdkVulkanContext *context,
VkCommandPool command_pool)
GdkVulkanContext *context)
{
GskVulkanRender *self;
VkDevice device;
self = g_slice_new0 (GskVulkanRender);
self->vulkan = context;
self->renderer = renderer;
self->command_pool = command_pool;
gsk_vulkan_render_compute_mvp (self);
GSK_VK_CHECK (vkAllocateCommandBuffers, gdk_vulkan_context_get_device (self->vulkan),
device = gdk_vulkan_context_get_device (self->vulkan);
GSK_VK_CHECK (vkCreateCommandPool, device,
&(const VkCommandPoolCreateInfo) {
.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
.queueFamilyIndex = gdk_vulkan_context_get_queue_family_index (self->vulkan),
.flags = 0
},
NULL,
&self->command_pool);
GSK_VK_CHECK (vkCreateFence, device,
&(VkFenceCreateInfo) {
.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
.flags = 0
},
NULL,
&self->fence);
GSK_VK_CHECK (vkAllocateCommandBuffers, device,
&(VkCommandBufferAllocateInfo) {
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
.commandPool = self->command_pool,
......@@ -245,8 +265,7 @@ gsk_vulkan_render_draw (GskVulkanRender *self,
}
void
gsk_vulkan_render_submit (GskVulkanRender *self,
VkFence fence)
gsk_vulkan_render_submit (GskVulkanRender *self)
{
GSK_VK_CHECK (vkEndCommandBuffer, self->command_buffer);
......@@ -268,28 +287,37 @@ gsk_vulkan_render_submit (GskVulkanRender *self,
gdk_vulkan_context_get_draw_semaphore (self->vulkan)
}
},
fence);
self->fence);
GSK_VK_CHECK (vkWaitForFences, gdk_vulkan_context_get_device (self->vulkan),
1,
&fence,
&self->fence,
VK_TRUE,
INT64_MAX);
GSK_VK_CHECK (vkResetFences, gdk_vulkan_context_get_device (self->vulkan),
1,
&fence);
&self->fence);
}
void
gsk_vulkan_render_free (GskVulkanRender *self)
{
GSK_VK_CHECK (vkResetCommandPool, gdk_vulkan_context_get_device (self->vulkan),
VkDevice device = gdk_vulkan_context_get_device (self->vulkan);
GSK_VK_CHECK (vkResetCommandPool, device,
self->command_pool,
0);
g_slist_free_full (self->render_passes, (GDestroyNotify) gsk_vulkan_render_pass_free);
g_slist_free_full (self->cleanup_images, (GDestroyNotify) gsk_vulkan_image_free);
vkDestroyFence (device,
self->fence,
NULL);
vkDestroyCommandPool (device,
self->command_pool,
NULL);
g_slice_free (GskVulkanRender, self);
}
......
......@@ -34,8 +34,6 @@ struct _GskVulkanRenderer
GskVulkanTarget **targets;
VkRenderPass render_pass;
VkCommandPool command_pool;
VkFence command_pool_fence;
VkDescriptorPool descriptor_pool;
VkDescriptorSet descriptor_set;
......@@ -220,22 +218,6 @@ gsk_vulkan_renderer_realize (GskRenderer *renderer,
},
NULL,
&self->render_pass);
GSK_VK_CHECK (vkCreateCommandPool, device,
&(const VkCommandPoolCreateInfo) {
.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
.queueFamilyIndex = gdk_vulkan_context_get_queue_family_index (self->vulkan),
.flags = 0
},
NULL,
&self->command_pool);
GSK_VK_CHECK (vkCreateFence, device,
&(VkFenceCreateInfo) {
.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
.flags = 0
},
NULL,
&self->command_pool_fence);
self->pipeline = gsk_vulkan_pipeline_new (self->vulkan, self->render_pass);
......@@ -314,16 +296,6 @@ gsk_vulkan_renderer_unrealize (GskRenderer *renderer)
g_clear_object (&self->pipeline);
vkDestroyFence (device,
self->command_pool_fence,
NULL);
self->command_pool_fence = VK_NULL_HANDLE;
vkDestroyCommandPool (device,
self->command_pool,
NULL);
self->command_pool = VK_NULL_HANDLE;
vkDestroyRenderPass (device,
self->render_pass,
NULL);
......@@ -348,7 +320,7 @@ gsk_vulkan_renderer_render (GskRenderer *renderer,
gsk_profiler_timer_begin (profiler, self->profile_timers.cpu_time);
#endif
render = gsk_vulkan_render_new (renderer, self->vulkan, self->command_pool);
render = gsk_vulkan_render_new (renderer, self->vulkan);
gsk_vulkan_render_add_node (render, root);
......@@ -359,7 +331,7 @@ gsk_vulkan_renderer_render (GskRenderer *renderer,
self->targets[gdk_vulkan_context_get_draw_index (self->vulkan)]->framebuffer,
self->descriptor_set, self->sampler);
gsk_vulkan_render_submit (render, self->command_pool_fence);
gsk_vulkan_render_submit (render);
gsk_vulkan_render_free (render);
......
......@@ -21,8 +21,7 @@ struct _GskVulkanVertex
};
GskVulkanRender * gsk_vulkan_render_new (GskRenderer *renderer,
GdkVulkanContext *context,
VkCommandPool command_pool);
GdkVulkanContext *context);
void gsk_vulkan_render_free (GskVulkanRender *self);
GskRenderer * gsk_vulkan_render_get_renderer (GskVulkanRender *self);
......@@ -42,8 +41,7 @@ void gsk_vulkan_render_draw (GskVulk
VkDescriptorSet descriptor_set,
VkSampler sampler);
void gsk_vulkan_render_submit (GskVulkanRender *self,
VkFence fence);
void gsk_vulkan_render_submit (GskVulkanRender *self);
G_END_DECLS
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment