vulkan: Add GskVulkanRender object

This is refactoring work.

GskVulkanRender is supposed to be the global object for a render
operation, ie GskVulkanRenderer.render() will create this object for
what it does.

The object will be split into stages that perform the operations
necessary to create a drawing.
This commit is contained in:
Benjamin Otte 2016-12-07 14:50:52 +01:00
parent 583956266e
commit 681554787b
4 changed files with 108 additions and 47 deletions

View File

@ -28,6 +28,7 @@ gsk_private_vulan_source_h = \
gskvulkanimageprivate.h \
gskvulkanmemoryprivate.h \
gskvulkanpipelineprivate.h \
gskvulkanrenderprivate.h \
gskvulkanrendererprivate.h \
gskvulkanshaderprivate.h
gsk_private_vulkan_source_c = \
@ -35,6 +36,7 @@ gsk_private_vulkan_source_c = \
gskvulkanimage.c \
gskvulkanmemory.c \
gskvulkanpipeline.c \
gskvulkanrender.c \
gskvulkanrenderer.c \
gskvulkanshader.c
endif

69
gsk/gskvulkanrender.c Normal file
View File

@ -0,0 +1,69 @@
#include "config.h"
#include "gskvulkanrenderprivate.h"
#include "gskvulkanpipelineprivate.h"
void
gsk_vulkan_render_init (GskVulkanRender *self,
GdkVulkanContext *context,
VkCommandPool command_pool)
{
self->vulkan = context;
self->command_pool = command_pool;
GSK_VK_CHECK (vkAllocateCommandBuffers, gdk_vulkan_context_get_device (self->vulkan),
&(VkCommandBufferAllocateInfo) {
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
.commandPool = self->command_pool,
.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY,
.commandBufferCount = 1,
},
&self->command_buffer);
GSK_VK_CHECK (vkBeginCommandBuffer, self->command_buffer,
&(VkCommandBufferBeginInfo) {
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
.flags = 0
});
}
void
gsk_vulkan_render_submit (GskVulkanRender *self,
VkFence fence)
{
GSK_VK_CHECK (vkEndCommandBuffer, self->command_buffer);
GSK_VK_CHECK (vkQueueSubmit, gdk_vulkan_context_get_queue (self->vulkan),
1,
&(VkSubmitInfo) {
.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
.waitSemaphoreCount = 1,
.pWaitSemaphores = (VkSemaphore[1]) {
gdk_vulkan_context_get_draw_semaphore (self->vulkan),
},
.pWaitDstStageMask = (VkPipelineStageFlags []) {
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
},
.commandBufferCount = 1,
.pCommandBuffers = &self->command_buffer,
},
fence);
GSK_VK_CHECK (vkWaitForFences, gdk_vulkan_context_get_device (self->vulkan),
1,
&fence,
VK_TRUE,
INT64_MAX);
GSK_VK_CHECK (vkResetFences, gdk_vulkan_context_get_device (self->vulkan),
1,
&fence);
}
void
gsk_vulkan_render_finish (GskVulkanRender *self)
{
GSK_VK_CHECK (vkResetCommandPool, gdk_vulkan_context_get_device (self->vulkan),
self->command_pool,
0);
}

View File

@ -11,6 +11,7 @@
#include "gskvulkanbufferprivate.h"
#include "gskvulkanimageprivate.h"
#include "gskvulkanpipelineprivate.h"
#include "gskvulkanrenderprivate.h"
#include <graphene.h>
@ -524,7 +525,7 @@ gsk_vulkan_renderer_render (GskRenderer *renderer,
GskRenderNode *root)
{
GskVulkanRenderer *self = GSK_VULKAN_RENDERER (renderer);
VkCommandBuffer command_buffer;
GskVulkanRender render;
GskVulkanImage *image;
#ifdef G_ENABLE_DEBUG
GskProfiler *profiler;
@ -536,58 +537,18 @@ gsk_vulkan_renderer_render (GskRenderer *renderer,
gsk_profiler_timer_begin (profiler, self->profile_timers.cpu_time);
#endif
GSK_VK_CHECK (vkAllocateCommandBuffers, gdk_vulkan_context_get_device (self->vulkan),
&(VkCommandBufferAllocateInfo) {
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
.commandPool = self->command_pool,
.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY,
.commandBufferCount = 1,
},
&command_buffer);
gsk_vulkan_render_init (&render, self->vulkan, self->command_pool);
GSK_VK_CHECK (vkBeginCommandBuffer, command_buffer,
&(VkCommandBufferBeginInfo) {
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
.flags = 0
});
image = gsk_vulkan_renderer_prepare_render (self, render.command_buffer, root);
image = gsk_vulkan_renderer_prepare_render (self, command_buffer, root);
gsk_vulkan_renderer_do_render_pass (self, render.command_buffer, image);
gsk_vulkan_renderer_do_render_pass (self, command_buffer, image);
gsk_vulkan_render_submit (&render, self->command_pool_fence);
GSK_VK_CHECK (vkEndCommandBuffer, command_buffer);
GSK_VK_CHECK (vkQueueSubmit, gdk_vulkan_context_get_queue (self->vulkan),
1,
&(VkSubmitInfo) {
.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
.waitSemaphoreCount = 1,
.pWaitSemaphores = (VkSemaphore[1]) {
gdk_vulkan_context_get_draw_semaphore (self->vulkan),
},
.pWaitDstStageMask = (VkPipelineStageFlags []) {
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
},
.commandBufferCount = 1,
.pCommandBuffers = &command_buffer,
},
self->command_pool_fence);
GSK_VK_CHECK (vkWaitForFences, gdk_vulkan_context_get_device (self->vulkan),
1,
&self->command_pool_fence,
true,
INT64_MAX);
GSK_VK_CHECK (vkResetFences, gdk_vulkan_context_get_device (self->vulkan),
1,
&self->command_pool_fence);
GSK_VK_CHECK (vkResetCommandPool, gdk_vulkan_context_get_device (self->vulkan),
self->command_pool,
0);
gsk_vulkan_image_free (image);
gsk_vulkan_render_finish (&render);
#ifdef G_ENABLE_DEBUG
cpu_time = gsk_profiler_timer_end (profiler, self->profile_timers.cpu_time);
gsk_profiler_timer_set (profiler, self->profile_timers.cpu_time, cpu_time);

View File

@ -0,0 +1,29 @@
#ifndef __GSK_VULKAN_RENDER_PRIVATE_H__
#define __GSK_VULKAN_RENDER_PRIVATE_H__
#include <gdk/gdk.h>
G_BEGIN_DECLS
typedef struct _GskVulkanRender GskVulkanRender;
struct _GskVulkanRender
{
GdkVulkanContext *vulkan;
VkCommandPool command_pool;
VkCommandBuffer command_buffer;
};
void gsk_vulkan_render_init (GskVulkanRender *self,
GdkVulkanContext *context,
VkCommandPool command_pool);
void gsk_vulkan_render_submit (GskVulkanRender *self,
VkFence fence);
void gsk_vulkan_render_finish (GskVulkanRender *self);
G_END_DECLS
#endif /* __GSK_VULKAN_RENDER_PRIVATE_H__ */