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;
|
|
|
|
|
|
|
|
struct _GskVulkanPipelinePrivate
|
2016-12-05 01:50:06 +00:00
|
|
|
{
|
|
|
|
GObject parent_instance;
|
|
|
|
|
2017-09-22 17:30:26 +00:00
|
|
|
GdkVulkanContext *context;
|
2016-12-05 01:50:06 +00:00
|
|
|
|
|
|
|
VkPipeline pipeline;
|
2017-09-22 17:30:26 +00:00
|
|
|
VkPipelineLayout layout;
|
2016-12-05 01:50:06 +00:00
|
|
|
|
|
|
|
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));
|
2017-09-22 17:30:26 +00:00
|
|
|
VkDevice device;
|
2016-12-17 23:33:53 +00:00
|
|
|
|
2017-09-22 17:30:26 +00:00
|
|
|
device = gdk_vulkan_context_get_device (priv->context);
|
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);
|
2017-09-22 17:30:26 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
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,
|
2017-09-22 17:30:26 +00:00
|
|
|
GdkVulkanContext *context,
|
|
|
|
VkPipelineLayout layout,
|
2016-12-14 07:00:58 +00:00
|
|
|
const char *shader_name,
|
|
|
|
VkRenderPass render_pass)
|
2017-09-01 20:58:42 +00:00
|
|
|
{
|
2017-09-22 17:30:26 +00:00
|
|
|
return gsk_vulkan_pipeline_new_full (pipeline_type, context, layout, shader_name, render_pass,
|
2017-09-01 20:58:42 +00:00
|
|
|
VK_BLEND_FACTOR_ONE,
|
|
|
|
VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA);
|
|
|
|
}
|
|
|
|
|
|
|
|
GskVulkanPipeline *
|
|
|
|
gsk_vulkan_pipeline_new_full (GType pipeline_type,
|
2017-09-22 17:30:26 +00:00
|
|
|
GdkVulkanContext *context,
|
|
|
|
VkPipelineLayout layout,
|
2017-09-01 20:58:42 +00:00
|
|
|
const char *shader_name,
|
|
|
|
VkRenderPass render_pass,
|
|
|
|
VkBlendFactor srcBlendFactor,
|
|
|
|
VkBlendFactor dstBlendFactor)
|
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;
|
|
|
|
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);
|
2017-09-22 17:30:26 +00:00
|
|
|
g_return_val_if_fail (layout != VK_NULL_HANDLE, NULL);
|
2016-12-14 07:00:58 +00:00
|
|
|
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);
|
|
|
|
|
2017-09-22 17:30:26 +00:00
|
|
|
device = gdk_vulkan_context_get_device (context);
|
2016-12-06 13:42:46 +00:00
|
|
|
|
2017-09-22 17:30:26 +00:00
|
|
|
priv->context = context;
|
|
|
|
priv->layout = layout;
|
2016-12-05 01:50:06 +00:00
|
|
|
|
2017-09-22 17:30:26 +00:00
|
|
|
priv->vertex_shader = gsk_vulkan_shader_new_from_resource (context, GSK_VULKAN_SHADER_VERTEX, shader_name, NULL);
|
|
|
|
priv->fragment_shader = gsk_vulkan_shader_new_from_resource (context, 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,
|
2017-09-01 20:58:42 +00:00
|
|
|
.srcColorBlendFactor = srcBlendFactor,
|
|
|
|
.dstColorBlendFactor = dstBlendFactor,
|
2016-12-09 04:51:51 +00:00
|
|
|
.alphaBlendOp = VK_BLEND_OP_ADD,
|
2017-09-01 20:58:42 +00:00
|
|
|
.srcAlphaBlendFactor = srcBlendFactor,
|
|
|
|
.dstAlphaBlendFactor = dstBlendFactor,
|
2016-12-09 04:51:51 +00:00
|
|
|
.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
|
|
|
|
},
|
|
|
|
},
|
2017-09-22 17:30:26 +00:00
|
|
|
.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
|
|
|
}
|
|
|
|
|
2017-09-22 14:13:25 +00:00
|
|
|
VkPipelineLayout
|
|
|
|
gsk_vulkan_pipeline_get_pipeline_layout (GskVulkanPipeline *self)
|
|
|
|
{
|
|
|
|
GskVulkanPipelinePrivate *priv = gsk_vulkan_pipeline_get_instance_private (self);
|
|
|
|
|
2017-09-22 17:30:26 +00:00
|
|
|
return priv->layout;
|
2016-12-06 13:42:46 +00:00
|
|
|
}
|