2016-12-05 01:50:06 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gskvulkanpipelineprivate.h"
|
|
|
|
|
2016-12-14 06:21:21 +00:00
|
|
|
#include "gskvulkanpushconstantsprivate.h"
|
2016-12-05 01:50:06 +00:00
|
|
|
#include "gskvulkanshaderprivate.h"
|
|
|
|
|
2016-12-07 00:48:31 +00:00
|
|
|
#include <graphene.h>
|
|
|
|
|
2016-12-17 23:33:53 +00:00
|
|
|
typedef struct _GskVulkanPipelinePrivate GskVulkanPipelinePrivate;
|
|
|
|
|
2016-12-14 07:00:58 +00:00
|
|
|
struct _GskVulkanPipelineLayout
|
|
|
|
{
|
|
|
|
volatile gint ref_count;
|
|
|
|
GdkVulkanContext *vulkan;
|
|
|
|
|
|
|
|
VkPipelineLayout pipeline_layout;
|
|
|
|
VkDescriptorSetLayout descriptor_set_layout;
|
|
|
|
};
|
|
|
|
|
2016-12-17 23:33:53 +00:00
|
|
|
struct _GskVulkanPipelinePrivate
|
2016-12-05 01:50:06 +00:00
|
|
|
{
|
|
|
|
GObject parent_instance;
|
|
|
|
|
2016-12-14 07:00:58 +00:00
|
|
|
GskVulkanPipelineLayout *layout;
|
2016-12-05 01:50:06 +00:00
|
|
|
|
|
|
|
VkPipeline pipeline;
|
|
|
|
|
|
|
|
GskVulkanShader *vertex_shader;
|
|
|
|
GskVulkanShader *fragment_shader;
|
|
|
|
};
|
|
|
|
|
2016-12-17 23:33:53 +00:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GskVulkanPipeline, gsk_vulkan_pipeline, G_TYPE_OBJECT)
|
2016-12-05 01:50:06 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_vulkan_pipeline_finalize (GObject *gobject)
|
|
|
|
{
|
2016-12-17 23:33:53 +00:00
|
|
|
GskVulkanPipelinePrivate *priv = gsk_vulkan_pipeline_get_instance_private (GSK_VULKAN_PIPELINE (gobject));
|
|
|
|
|
|
|
|
VkDevice device = gdk_vulkan_context_get_device (priv->layout->vulkan);
|
2016-12-05 01:50:06 +00:00
|
|
|
|
|
|
|
vkDestroyPipeline (device,
|
2016-12-17 23:33:53 +00:00
|
|
|
priv->pipeline,
|
2016-12-05 01:50:06 +00:00
|
|
|
NULL);
|
|
|
|
|
2016-12-17 23:33:53 +00:00
|
|
|
g_clear_pointer (&priv->fragment_shader, gsk_vulkan_shader_free);
|
|
|
|
g_clear_pointer (&priv->vertex_shader, gsk_vulkan_shader_free);
|
2016-12-05 01:50:06 +00:00
|
|
|
|
2016-12-17 23:33:53 +00:00
|
|
|
g_clear_pointer (&priv->layout, gsk_vulkan_pipeline_layout_unref);
|
2016-12-05 01:50:06 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (gsk_vulkan_pipeline_parent_class)->finalize (gobject);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_vulkan_pipeline_class_init (GskVulkanPipelineClass *klass)
|
|
|
|
{
|
|
|
|
G_OBJECT_CLASS (klass)->finalize = gsk_vulkan_pipeline_finalize;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_vulkan_pipeline_init (GskVulkanPipeline *self)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
GskVulkanPipeline *
|
2016-12-17 23:57:37 +00:00
|
|
|
gsk_vulkan_pipeline_new (GType pipeline_type,
|
|
|
|
GskVulkanPipelineLayout *layout,
|
2016-12-14 07:00:58 +00:00
|
|
|
const char *shader_name,
|
|
|
|
VkRenderPass render_pass)
|
2016-12-05 01:50:06 +00:00
|
|
|
{
|
2016-12-17 23:33:53 +00:00
|
|
|
GskVulkanPipelinePrivate *priv;
|
2016-12-05 01:50:06 +00:00
|
|
|
GskVulkanPipeline *self;
|
2016-12-17 23:33:53 +00:00
|
|
|
|
2016-12-05 01:50:06 +00:00
|
|
|
VkDevice device;
|
|
|
|
|
2016-12-18 00:45:07 +00:00
|
|
|
g_return_val_if_fail (g_type_is_a (pipeline_type, GSK_TYPE_VULKAN_PIPELINE), NULL);
|
2016-12-14 07:00:58 +00:00
|
|
|
g_return_val_if_fail (layout != NULL, NULL);
|
|
|
|
g_return_val_if_fail (shader_name != NULL, NULL);
|
2016-12-05 01:50:06 +00:00
|
|
|
g_return_val_if_fail (render_pass != VK_NULL_HANDLE, NULL);
|
|
|
|
|
2016-12-17 23:57:37 +00:00
|
|
|
self = g_object_new (pipeline_type, NULL);
|
2016-12-05 01:50:06 +00:00
|
|
|
|
2016-12-17 23:33:53 +00:00
|
|
|
priv = gsk_vulkan_pipeline_get_instance_private (self);
|
|
|
|
|
|
|
|
priv->layout = gsk_vulkan_pipeline_layout_ref (layout);
|
2016-12-06 13:42:46 +00:00
|
|
|
|
2016-12-14 07:00:58 +00:00
|
|
|
device = gdk_vulkan_context_get_device (layout->vulkan);
|
2016-12-05 01:50:06 +00:00
|
|
|
|
2016-12-17 23:33:53 +00:00
|
|
|
priv->vertex_shader = gsk_vulkan_shader_new_from_resource (layout->vulkan, GSK_VULKAN_SHADER_VERTEX, shader_name, NULL);
|
|
|
|
priv->fragment_shader = gsk_vulkan_shader_new_from_resource (layout->vulkan, GSK_VULKAN_SHADER_FRAGMENT, shader_name, NULL);
|
2016-12-05 01:50:06 +00:00
|
|
|
|
|
|
|
GSK_VK_CHECK (vkCreateGraphicsPipelines, device,
|
|
|
|
VK_NULL_HANDLE,
|
|
|
|
1,
|
|
|
|
&(VkGraphicsPipelineCreateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
|
|
|
|
.stageCount = 2,
|
|
|
|
.pStages = (VkPipelineShaderStageCreateInfo[2]) {
|
2016-12-17 23:33:53 +00:00
|
|
|
GST_VULKAN_SHADER_STAGE_CREATE_INFO (priv->vertex_shader),
|
|
|
|
GST_VULKAN_SHADER_STAGE_CREATE_INFO (priv->fragment_shader)
|
2016-12-05 01:50:06 +00:00
|
|
|
},
|
2016-12-18 04:33:16 +00:00
|
|
|
.pVertexInputState = GSK_VULKAN_PIPELINE_GET_CLASS (self)->get_input_state_create_info (self),
|
2016-12-05 01:50:06 +00:00
|
|
|
.pInputAssemblyState = &(VkPipelineInputAssemblyStateCreateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
|
|
|
|
.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,
|
|
|
|
.primitiveRestartEnable = VK_FALSE,
|
|
|
|
},
|
|
|
|
.pTessellationState = NULL,
|
|
|
|
.pViewportState = &(VkPipelineViewportStateCreateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,
|
|
|
|
.viewportCount = 1,
|
|
|
|
.scissorCount = 1
|
|
|
|
},
|
|
|
|
.pRasterizationState = &(VkPipelineRasterizationStateCreateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,
|
|
|
|
.depthClampEnable = VK_FALSE,
|
|
|
|
.rasterizerDiscardEnable = VK_FALSE,
|
|
|
|
.polygonMode = VK_POLYGON_MODE_FILL,
|
|
|
|
.cullMode = VK_CULL_MODE_BACK_BIT,
|
|
|
|
.frontFace = VK_FRONT_FACE_CLOCKWISE,
|
|
|
|
.lineWidth = 1.0f,
|
|
|
|
},
|
|
|
|
.pMultisampleState = &(VkPipelineMultisampleStateCreateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,
|
|
|
|
.rasterizationSamples = 1,
|
|
|
|
},
|
|
|
|
.pDepthStencilState = &(VkPipelineDepthStencilStateCreateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO
|
|
|
|
},
|
|
|
|
.pColorBlendState = &(VkPipelineColorBlendStateCreateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,
|
|
|
|
.attachmentCount = 1,
|
|
|
|
.pAttachments = (VkPipelineColorBlendAttachmentState []) {
|
2016-12-09 04:51:51 +00:00
|
|
|
{
|
|
|
|
.blendEnable = VK_TRUE,
|
|
|
|
.colorBlendOp = VK_BLEND_OP_ADD,
|
|
|
|
.srcColorBlendFactor = VK_BLEND_FACTOR_ONE,
|
|
|
|
.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
|
|
|
|
.alphaBlendOp = VK_BLEND_OP_ADD,
|
|
|
|
.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE,
|
|
|
|
.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
|
|
|
|
.colorWriteMask = VK_COLOR_COMPONENT_A_BIT
|
|
|
|
| VK_COLOR_COMPONENT_R_BIT
|
|
|
|
| VK_COLOR_COMPONENT_G_BIT
|
|
|
|
| VK_COLOR_COMPONENT_B_BIT
|
|
|
|
},
|
2016-12-05 01:50:06 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
.pDynamicState = &(VkPipelineDynamicStateCreateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,
|
|
|
|
.dynamicStateCount = 2,
|
|
|
|
.pDynamicStates = (VkDynamicState[2]) {
|
|
|
|
VK_DYNAMIC_STATE_VIEWPORT,
|
|
|
|
VK_DYNAMIC_STATE_SCISSOR
|
|
|
|
},
|
|
|
|
},
|
2016-12-17 23:33:53 +00:00
|
|
|
.layout = gsk_vulkan_pipeline_layout_get_pipeline_layout (priv->layout),
|
2016-12-05 01:50:06 +00:00
|
|
|
.renderPass = render_pass,
|
|
|
|
.subpass = 0,
|
|
|
|
.basePipelineHandle = VK_NULL_HANDLE,
|
|
|
|
.basePipelineIndex = -1,
|
|
|
|
},
|
|
|
|
NULL,
|
2016-12-17 23:33:53 +00:00
|
|
|
&priv->pipeline);
|
2016-12-05 01:50:06 +00:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
VkPipeline
|
|
|
|
gsk_vulkan_pipeline_get_pipeline (GskVulkanPipeline *self)
|
|
|
|
{
|
2016-12-17 23:33:53 +00:00
|
|
|
GskVulkanPipelinePrivate *priv = gsk_vulkan_pipeline_get_instance_private (self);
|
|
|
|
|
|
|
|
return priv->pipeline;
|
2016-12-05 01:50:06 +00:00
|
|
|
}
|
|
|
|
|
2016-12-14 07:00:58 +00:00
|
|
|
/*** GskVulkanPipelineLayout ***/
|
|
|
|
|
|
|
|
GskVulkanPipelineLayout *
|
|
|
|
gsk_vulkan_pipeline_layout_new (GdkVulkanContext *context)
|
|
|
|
{
|
|
|
|
GskVulkanPipelineLayout *self;
|
|
|
|
VkDevice device;
|
|
|
|
|
|
|
|
self = g_slice_new0 (GskVulkanPipelineLayout);
|
|
|
|
self->ref_count = 1;
|
|
|
|
self->vulkan = g_object_ref (context);
|
|
|
|
|
|
|
|
device = gdk_vulkan_context_get_device (context);
|
|
|
|
|
|
|
|
GSK_VK_CHECK (vkCreateDescriptorSetLayout, device,
|
|
|
|
&(VkDescriptorSetLayoutCreateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
|
|
|
|
.bindingCount = 1,
|
|
|
|
.pBindings = (VkDescriptorSetLayoutBinding[1]) {
|
|
|
|
{
|
|
|
|
.binding = 0,
|
|
|
|
.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
|
|
|
|
.descriptorCount = 1,
|
|
|
|
.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
NULL,
|
|
|
|
&self->descriptor_set_layout);
|
|
|
|
|
|
|
|
GSK_VK_CHECK (vkCreatePipelineLayout, device,
|
|
|
|
&(VkPipelineLayoutCreateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
|
|
|
|
.setLayoutCount = 1,
|
|
|
|
.pSetLayouts = &self->descriptor_set_layout,
|
|
|
|
.pushConstantRangeCount = gst_vulkan_push_constants_get_range_count (),
|
|
|
|
.pPushConstantRanges = gst_vulkan_push_constants_get_ranges ()
|
|
|
|
},
|
|
|
|
NULL,
|
|
|
|
&self->pipeline_layout);
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
GskVulkanPipelineLayout *
|
|
|
|
gsk_vulkan_pipeline_layout_ref (GskVulkanPipelineLayout *self)
|
|
|
|
{
|
|
|
|
self->ref_count++;
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gsk_vulkan_pipeline_layout_unref (GskVulkanPipelineLayout *self)
|
|
|
|
{
|
|
|
|
VkDevice device;
|
|
|
|
|
|
|
|
self->ref_count--;
|
|
|
|
|
|
|
|
if (self->ref_count > 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
device = gdk_vulkan_context_get_device (self->vulkan);
|
|
|
|
|
|
|
|
vkDestroyPipelineLayout (device,
|
|
|
|
self->pipeline_layout,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
vkDestroyDescriptorSetLayout (device,
|
|
|
|
self->descriptor_set_layout,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
g_slice_free (GskVulkanPipelineLayout, self);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-06 13:42:46 +00:00
|
|
|
VkPipelineLayout
|
2016-12-14 07:00:58 +00:00
|
|
|
gsk_vulkan_pipeline_layout_get_pipeline_layout (GskVulkanPipelineLayout *self)
|
2016-12-06 13:42:46 +00:00
|
|
|
{
|
|
|
|
return self->pipeline_layout;
|
|
|
|
}
|
|
|
|
|
|
|
|
VkDescriptorSetLayout
|
2016-12-14 07:00:58 +00:00
|
|
|
gsk_vulkan_pipeline_layout_get_descriptor_set_layout (GskVulkanPipelineLayout *self)
|
2016-12-06 13:42:46 +00:00
|
|
|
{
|
|
|
|
return self->descriptor_set_layout;
|
|
|
|
}
|
2016-12-05 01:50:06 +00:00
|
|
|
|