vulkan: Convert color op to new method

This is a straightforward and simple port.
This commit is contained in:
Benjamin Otte
2023-06-29 06:58:55 +02:00
parent 9da1055575
commit 99085605a8
8 changed files with 147 additions and 158 deletions

View File

@@ -113,8 +113,8 @@ if have_vulkan
'vulkan/gskvulkanboxshadowpipeline.c',
'vulkan/gskvulkanbuffer.c',
'vulkan/gskvulkanclip.c',
'vulkan/gskvulkancolorpipeline.c',
'vulkan/gskvulkancolormatrixop.c',
'vulkan/gskvulkancolorop.c',
'vulkan/gskvulkancolortextpipeline.c',
'vulkan/gskvulkancommandpool.c',
'vulkan/gskvulkancrossfadepipeline.c',

View File

@@ -0,0 +1,125 @@
#include "config.h"
#include "gskvulkancoloropprivate.h"
#include "vulkan/resources/color.vert.h"
typedef struct _GskVulkanColorOp GskVulkanColorOp;
struct _GskVulkanColorOp
{
GskVulkanOp op;
graphene_rect_t rect;
GdkRGBA color;
gsize vertex_offset;
};
static void
gsk_vulkan_color_op_finish (GskVulkanOp *op)
{
}
static void
gsk_vulkan_color_op_upload (GskVulkanOp *op,
GskVulkanRenderPass *pass,
GskVulkanRender *render,
GskVulkanUploader *uploader,
const graphene_rect_t *clip,
const graphene_vec2_t *scale)
{
}
static inline gsize
round_up (gsize number, gsize divisor)
{
return (number + divisor - 1) / divisor * divisor;
}
static gsize
gsk_vulkan_color_op_count_vertex_data (GskVulkanOp *op,
gsize n_bytes)
{
GskVulkanColorOp *self = (GskVulkanColorOp *) op;
gsize vertex_stride;
vertex_stride = gsk_vulkan_color_info.pVertexBindingDescriptions[0].stride;
n_bytes = round_up (n_bytes, vertex_stride);
self->vertex_offset = n_bytes;
n_bytes += vertex_stride;
return n_bytes;
}
static void
gsk_vulkan_color_op_collect_vertex_data (GskVulkanOp *op,
GskVulkanRenderPass *pass,
GskVulkanRender *render,
guchar *data)
{
GskVulkanColorOp *self = (GskVulkanColorOp *) op;
GskVulkanColorInstance *instance = (GskVulkanColorInstance *) (data + self->vertex_offset);
instance->rect[0] = self->rect.origin.x;
instance->rect[1] = self->rect.origin.y;
instance->rect[2] = self->rect.size.width;
instance->rect[3] = self->rect.size.height;
instance->color[0] = self->color.red;
instance->color[1] = self->color.green;
instance->color[2] = self->color.blue;
instance->color[3] = self->color.alpha;
}
static void
gsk_vulkan_color_op_reserve_descriptor_sets (GskVulkanOp *op,
GskVulkanRender *render)
{
}
static VkPipeline
gsk_vulkan_color_op_get_pipeline (GskVulkanOp *op)
{
return VK_NULL_HANDLE;
}
static void
gsk_vulkan_color_op_command (GskVulkanOp *op,
GskVulkanRender *render,
VkPipelineLayout pipeline_layout,
VkCommandBuffer command_buffer)
{
GskVulkanColorOp *self = (GskVulkanColorOp *) op;
vkCmdDraw (command_buffer,
6, 1,
0, self->vertex_offset / gsk_vulkan_color_info.pVertexBindingDescriptions[0].stride);
}
static const GskVulkanOpClass GSK_VULKAN_COLOR_OP_CLASS = {
GSK_VULKAN_OP_SIZE (GskVulkanColorOp),
"color",
&gsk_vulkan_color_info,
gsk_vulkan_color_op_finish,
gsk_vulkan_color_op_upload,
gsk_vulkan_color_op_count_vertex_data,
gsk_vulkan_color_op_collect_vertex_data,
gsk_vulkan_color_op_reserve_descriptor_sets,
gsk_vulkan_color_op_get_pipeline,
gsk_vulkan_color_op_command
};
void
gsk_vulkan_color_op (GskVulkanRenderPass *render_pass,
const char *clip_type,
const graphene_rect_t *rect,
const graphene_point_t *offset,
const GdkRGBA *color)
{
GskVulkanColorOp *self;
self = (GskVulkanColorOp *) gsk_vulkan_op_alloc (render_pass, &GSK_VULKAN_COLOR_OP_CLASS);
((GskVulkanOp *) self)->clip_type = g_intern_string (clip_type);
graphene_rect_offset_r (rect, offset->x, offset->y, &self->rect);
self->color = *color;
}

View File

@@ -0,0 +1,15 @@
#pragma once
#include "gskvulkanopprivate.h"
G_BEGIN_DECLS
void gsk_vulkan_color_op (GskVulkanRenderPass *render_pass,
const char *clip_type,
const graphene_rect_t *rect,
const graphene_point_t *offset,
const GdkRGBA *color);
G_END_DECLS

View File

@@ -1,82 +0,0 @@
#include "config.h"
#include "gskvulkancolorpipelineprivate.h"
#include "vulkan/resources/color.vert.h"
struct _GskVulkanColorPipeline
{
GObject parent_instance;
};
G_DEFINE_TYPE (GskVulkanColorPipeline, gsk_vulkan_color_pipeline, GSK_TYPE_VULKAN_PIPELINE)
static const VkPipelineVertexInputStateCreateInfo *
gsk_vulkan_color_pipeline_get_input_state_create_info (GskVulkanPipeline *self)
{
return &gsk_vulkan_color_info;
}
static void
gsk_vulkan_color_pipeline_finalize (GObject *gobject)
{
//GskVulkanColorPipeline *self = GSK_VULKAN_COLOR_PIPELINE (gobject);
G_OBJECT_CLASS (gsk_vulkan_color_pipeline_parent_class)->finalize (gobject);
}
static void
gsk_vulkan_color_pipeline_class_init (GskVulkanColorPipelineClass *klass)
{
GskVulkanPipelineClass *pipeline_class = GSK_VULKAN_PIPELINE_CLASS (klass);
G_OBJECT_CLASS (klass)->finalize = gsk_vulkan_color_pipeline_finalize;
pipeline_class->get_input_state_create_info = gsk_vulkan_color_pipeline_get_input_state_create_info;
}
static void
gsk_vulkan_color_pipeline_init (GskVulkanColorPipeline *self)
{
}
GskVulkanPipeline *
gsk_vulkan_color_pipeline_new (GdkVulkanContext *context,
VkPipelineLayout layout,
const char *shader_name,
VkRenderPass render_pass)
{
return gsk_vulkan_pipeline_new (GSK_TYPE_VULKAN_COLOR_PIPELINE, context, layout, shader_name, render_pass);
}
void
gsk_vulkan_color_pipeline_collect_vertex_data (GskVulkanColorPipeline *pipeline,
guchar *data,
const graphene_point_t *offset,
const graphene_rect_t *rect,
const GdkRGBA *color)
{
GskVulkanColorInstance *instance = (GskVulkanColorInstance *) data;
instance->rect[0] = rect->origin.x + offset->x;
instance->rect[1] = rect->origin.y + offset->y;
instance->rect[2] = rect->size.width;
instance->rect[3] = rect->size.height;
instance->color[0] = color->red;
instance->color[1] = color->green;
instance->color[2] = color->blue;
instance->color[3] = color->alpha;
}
gsize
gsk_vulkan_color_pipeline_draw (GskVulkanColorPipeline *pipeline,
VkCommandBuffer command_buffer,
gsize offset,
gsize n_commands)
{
vkCmdDraw (command_buffer,
6, n_commands,
0, offset);
return n_commands;
}

View File

@@ -1,31 +0,0 @@
#pragma once
#include <graphene.h>
#include "gskvulkanpipelineprivate.h"
G_BEGIN_DECLS
typedef struct _GskVulkanColorPipelineLayout GskVulkanColorPipelineLayout;
#define GSK_TYPE_VULKAN_COLOR_PIPELINE (gsk_vulkan_color_pipeline_get_type ())
G_DECLARE_FINAL_TYPE (GskVulkanColorPipeline, gsk_vulkan_color_pipeline, GSK, VULKAN_COLOR_PIPELINE, GskVulkanPipeline)
GskVulkanPipeline * gsk_vulkan_color_pipeline_new (GdkVulkanContext *context,
VkPipelineLayout layout,
const char *shader_name,
VkRenderPass render_pass);
void gsk_vulkan_color_pipeline_collect_vertex_data (GskVulkanColorPipeline *pipeline,
guchar *data,
const graphene_point_t *offset,
const graphene_rect_t *rect,
const GdkRGBA *color);
gsize gsk_vulkan_color_pipeline_draw (GskVulkanColorPipeline *pipeline,
VkCommandBuffer command_buffer,
gsize offset,
gsize n_commands);
G_END_DECLS

View File

@@ -14,7 +14,6 @@
#include "gskvulkanblurpipelineprivate.h"
#include "gskvulkanborderpipelineprivate.h"
#include "gskvulkanboxshadowpipelineprivate.h"
#include "gskvulkancolorpipelineprivate.h"
#include "gskvulkancolortextpipelineprivate.h"
#include "gskvulkancrossfadepipelineprivate.h"
#include "gskvulkanlineargradientpipelineprivate.h"
@@ -503,9 +502,6 @@ gsk_vulkan_render_get_pipeline (GskVulkanRender *self,
guint num_textures;
GskVulkanPipeline * (* create_func) (GdkVulkanContext *context, VkPipelineLayout layout, const char *name, VkRenderPass render_pass);
} pipeline_info[GSK_VULKAN_N_PIPELINES] = {
{ "color", 0, gsk_vulkan_color_pipeline_new },
{ "color-clip", 0, gsk_vulkan_color_pipeline_new },
{ "color-clip-rounded", 0, gsk_vulkan_color_pipeline_new },
{ "linear", 0, gsk_vulkan_linear_gradient_pipeline_new },
{ "linear-clip", 0, gsk_vulkan_linear_gradient_pipeline_new },
{ "linear-clip-rounded", 0, gsk_vulkan_linear_gradient_pipeline_new },

View File

@@ -15,7 +15,7 @@
#include "gskvulkanboxshadowpipelineprivate.h"
#include "gskvulkanclipprivate.h"
#include "gskvulkancolormatrixopprivate.h"
#include "gskvulkancolorpipelineprivate.h"
#include "gskvulkancoloropprivate.h"
#include "gskvulkancolortextpipelineprivate.h"
#include "gskvulkancrossfadepipelineprivate.h"
#include "gskvulkanlineargradientpipelineprivate.h"
@@ -52,7 +52,6 @@ typedef struct _GskVulkanOpPushConstants GskVulkanOpPushConstants;
typedef enum {
/* GskVulkanOpRender */
GSK_VULKAN_OP_COLOR,
GSK_VULKAN_OP_LINEAR_GRADIENT,
GSK_VULKAN_OP_BLUR,
GSK_VULKAN_OP_BORDER,
@@ -524,22 +523,11 @@ gsk_vulkan_render_pass_add_color_node (GskVulkanRenderPass *self,
const GskVulkanParseState *state,
GskRenderNode *node)
{
GskVulkanOpRender op = {
.type = GSK_VULKAN_OP_COLOR,
.node = node,
.offset = state->offset,
};
GskVulkanPipelineType pipeline_type;
if (gsk_vulkan_clip_contains_rect (&state->clip, &state->offset, &node->bounds))
pipeline_type = GSK_VULKAN_PIPELINE_COLOR;
else if (state->clip.type == GSK_VULKAN_CLIP_RECT)
pipeline_type = GSK_VULKAN_PIPELINE_COLOR_CLIP;
else
pipeline_type = GSK_VULKAN_PIPELINE_COLOR_CLIP_ROUNDED;
op.pipeline = gsk_vulkan_render_pass_get_pipeline (self, render, pipeline_type);
gsk_vulkan_render_pass_add_op (self, (GskVulkanOp *) &op);
gsk_vulkan_color_op (self,
gsk_vulkan_clip_get_clip_type (&state->clip, &state->offset, &node->bounds),
&node->bounds,
&state->offset,
gsk_color_node_get_color (node));
return TRUE;
}
@@ -1738,7 +1726,6 @@ gsk_vulkan_render_op_upload (GskVulkanOp *op_,
default:
g_assert_not_reached ();
case GSK_VULKAN_OP_PUSH_VERTEX_CONSTANTS:
case GSK_VULKAN_OP_COLOR:
case GSK_VULKAN_OP_LINEAR_GRADIENT:
case GSK_VULKAN_OP_BORDER:
case GSK_VULKAN_OP_INSET_SHADOW:
@@ -1774,7 +1761,6 @@ gsk_vulkan_render_op_count_vertex_data (GskVulkanOp *op_,
switch (op->any.type)
{
case GSK_VULKAN_OP_COLOR:
case GSK_VULKAN_OP_LINEAR_GRADIENT:
case GSK_VULKAN_OP_BLUR:
case GSK_VULKAN_OP_BORDER:
@@ -1869,14 +1855,6 @@ gsk_vulkan_render_op_collect_vertex_data (GskVulkanOp *op_,
op->text.scale);
break;
case GSK_VULKAN_OP_COLOR:
gsk_vulkan_color_pipeline_collect_vertex_data (GSK_VULKAN_COLOR_PIPELINE (op->render.pipeline),
data + op->render.vertex_offset,
&op->render.offset,
&op->render.node->bounds,
gsk_color_node_get_color (op->render.node));
break;
case GSK_VULKAN_OP_LINEAR_GRADIENT:
gsk_vulkan_linear_gradient_pipeline_collect_vertex_data (GSK_VULKAN_LINEAR_GRADIENT_PIPELINE (op->render.pipeline),
data + op->render.vertex_offset,
@@ -2075,7 +2053,6 @@ gsk_vulkan_render_op_reserve_descriptor_sets (GskVulkanOp *op_,
default:
g_assert_not_reached ();
case GSK_VULKAN_OP_COLOR:
case GSK_VULKAN_OP_BORDER:
case GSK_VULKAN_OP_INSET_SHADOW:
case GSK_VULKAN_OP_OUTSET_SHADOW:
@@ -2142,7 +2119,6 @@ gsk_vulkan_render_op_get_pipeline (GskVulkanOp *op_)
switch (op->any.type)
{
case GSK_VULKAN_OP_COLOR:
case GSK_VULKAN_OP_LINEAR_GRADIENT:
case GSK_VULKAN_OP_BLUR:
case GSK_VULKAN_OP_BORDER:
@@ -2198,13 +2174,6 @@ gsk_vulkan_render_op_command (GskVulkanOp *op_,
1);
break;
case GSK_VULKAN_OP_COLOR:
gsk_vulkan_color_pipeline_draw (GSK_VULKAN_COLOR_PIPELINE (op->render.pipeline),
command_buffer,
op->render.vertex_offset / gsk_vulkan_pipeline_get_vertex_stride (op->render.pipeline),
1);
break;
case GSK_VULKAN_OP_LINEAR_GRADIENT:
gsk_vulkan_linear_gradient_pipeline_draw (GSK_VULKAN_LINEAR_GRADIENT_PIPELINE (op->render.pipeline),
command_buffer,

View File

@@ -11,9 +11,6 @@
G_BEGIN_DECLS
typedef enum {
GSK_VULKAN_PIPELINE_COLOR,
GSK_VULKAN_PIPELINE_COLOR_CLIP,
GSK_VULKAN_PIPELINE_COLOR_CLIP_ROUNDED,
GSK_VULKAN_PIPELINE_LINEAR_GRADIENT,
GSK_VULKAN_PIPELINE_LINEAR_GRADIENT_CLIP,
GSK_VULKAN_PIPELINE_LINEAR_GRADIENT_CLIP_ROUNDED,