vulkan: Unify some functions

All the ops that just execute a shader do pretty much the same stuff, so
put it all in a single function that they all call.

It's basically faking a base class for them.
This commit is contained in:
Benjamin Otte 2023-07-09 16:27:02 +02:00
parent c0b185bee9
commit 21d2372396
14 changed files with 114 additions and 532 deletions

View File

@ -21,8 +21,6 @@ struct _GskVulkanBlendModeOp
graphene_rect_t tex_rect;
guint32 image_descriptor;
} top, bottom;
gsize vertex_offset;
};
static void
@ -47,38 +45,12 @@ gsk_vulkan_blend_mode_op_print (GskVulkanOp *op,
print_newline (string);
}
static void
gsk_vulkan_blend_mode_op_upload (GskVulkanOp *op,
GskVulkanUploader *uploader)
{
}
static inline gsize
round_up (gsize number, gsize divisor)
{
return (number + divisor - 1) / divisor * divisor;
}
static gsize
gsk_vulkan_blend_mode_op_count_vertex_data (GskVulkanOp *op,
gsize n_bytes)
{
GskVulkanBlendModeOp *self = (GskVulkanBlendModeOp *) op;
gsize vertex_stride;
vertex_stride = gsk_vulkan_blend_mode_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_blend_mode_op_collect_vertex_data (GskVulkanOp *op,
guchar *data)
{
GskVulkanBlendModeOp *self = (GskVulkanBlendModeOp *) op;
GskVulkanBlendModeInstance *instance = (GskVulkanBlendModeInstance *) (data + self->vertex_offset);
GskVulkanBlendModeInstance *instance = (GskVulkanBlendModeInstance *) (data + op->vertex_offset);
gsk_vulkan_rect_to_float (&self->bounds, instance->rect);
gsk_vulkan_rect_to_float (&self->top.rect, instance->top_rect);
@ -127,11 +99,11 @@ static const GskVulkanShaderOpClass GSK_VULKAN_BLEND_MODE_OP_CLASS = {
&gsk_vulkan_blend_mode_info,
gsk_vulkan_blend_mode_op_finish,
gsk_vulkan_blend_mode_op_print,
gsk_vulkan_blend_mode_op_upload,
gsk_vulkan_blend_mode_op_count_vertex_data,
gsk_vulkan_op_draw_upload,
gsk_vulkan_op_draw_count_vertex_data,
gsk_vulkan_blend_mode_op_collect_vertex_data,
gsk_vulkan_blend_mode_op_reserve_descriptor_sets,
gsk_vulkan_blend_mode_op_command
gsk_vulkan_op_draw_command
};
void

View File

@ -18,7 +18,6 @@ struct _GskVulkanBlurOp
float radius;
guint32 image_descriptor;
gsize vertex_offset;
};
static void
@ -44,37 +43,11 @@ gsk_vulkan_blur_op_print (GskVulkanOp *op,
}
static void
gsk_vulkan_blur_op_upload (GskVulkanOp *op,
GskVulkanUploader *uploader)
{
}
static inline gsize
round_up (gsize number, gsize divisor)
{
return (number + divisor - 1) / divisor * divisor;
}
static gsize
gsk_vulkan_blur_op_count_vertex_data (GskVulkanOp *op,
gsize n_bytes)
gsk_vulkan_blur_op_collect_vertex_data (GskVulkanOp *op,
guchar *data)
{
GskVulkanBlurOp *self = (GskVulkanBlurOp *) op;
gsize vertex_stride;
vertex_stride = gsk_vulkan_blur_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_blur_op_collect_vertex_data (GskVulkanOp *op,
guchar *data)
{
GskVulkanBlurOp *self = (GskVulkanBlurOp *) op;
GskVulkanBlurInstance *instance = (GskVulkanBlurInstance *) (data + self->vertex_offset);
GskVulkanBlurInstance *instance = (GskVulkanBlurInstance *) (data + op->vertex_offset);
gsk_vulkan_rect_to_float (&self->rect, instance->rect);
gsk_vulkan_rect_to_float (&self->tex_rect, instance->tex_rect);
@ -93,21 +66,6 @@ gsk_vulkan_blur_op_reserve_descriptor_sets (GskVulkanOp *op,
GSK_VULKAN_SAMPLER_DEFAULT);
}
static GskVulkanOp *
gsk_vulkan_blur_op_command (GskVulkanOp *op,
GskVulkanRender *render,
VkPipelineLayout pipeline_layout,
VkCommandBuffer command_buffer)
{
GskVulkanBlurOp *self = (GskVulkanBlurOp *) op;
vkCmdDraw (command_buffer,
6, 1,
0, self->vertex_offset / gsk_vulkan_blur_info.pVertexBindingDescriptions[0].stride);
return op->next;
}
static const GskVulkanOpClass GSK_VULKAN_BLUR_OP_CLASS = {
GSK_VULKAN_OP_SIZE (GskVulkanBlurOp),
GSK_VULKAN_STAGE_COMMAND,
@ -115,11 +73,11 @@ static const GskVulkanOpClass GSK_VULKAN_BLUR_OP_CLASS = {
&gsk_vulkan_blur_info,
gsk_vulkan_blur_op_finish,
gsk_vulkan_blur_op_print,
gsk_vulkan_blur_op_upload,
gsk_vulkan_blur_op_count_vertex_data,
gsk_vulkan_op_draw_upload,
gsk_vulkan_op_draw_count_vertex_data,
gsk_vulkan_blur_op_collect_vertex_data,
gsk_vulkan_blur_op_reserve_descriptor_sets,
gsk_vulkan_blur_op_command
gsk_vulkan_op_draw_command
};
void

View File

@ -16,8 +16,6 @@ struct _GskVulkanBorderOp
GskRoundedRect outline;
float widths[4];
GdkRGBA colors[4];
gsize vertex_offset;
};
static void
@ -53,38 +51,12 @@ gsk_vulkan_border_op_print (GskVulkanOp *op,
print_newline (string);
}
static void
gsk_vulkan_border_op_upload (GskVulkanOp *op,
GskVulkanUploader *uploader)
{
}
static inline gsize
round_up (gsize number, gsize divisor)
{
return (number + divisor - 1) / divisor * divisor;
}
static gsize
gsk_vulkan_border_op_count_vertex_data (GskVulkanOp *op,
gsize n_bytes)
{
GskVulkanBorderOp *self = (GskVulkanBorderOp *) op;
gsize vertex_stride;
vertex_stride = gsk_vulkan_border_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_border_op_collect_vertex_data (GskVulkanOp *op,
guchar *data)
{
GskVulkanBorderOp *self = (GskVulkanBorderOp *) op;
GskVulkanBorderInstance *instance = (GskVulkanBorderInstance *) (data + self->vertex_offset);
GskVulkanBorderInstance *instance = (GskVulkanBorderInstance *) (data + op->vertex_offset);
guint i;
gsk_rounded_rect_to_float (&self->outline, graphene_point_zero (), instance->rect);
@ -107,13 +79,7 @@ gsk_vulkan_border_op_command (GskVulkanOp *op,
VkPipelineLayout pipeline_layout,
VkCommandBuffer command_buffer)
{
GskVulkanBorderOp *self = (GskVulkanBorderOp *) op;
vkCmdDraw (command_buffer,
6 * 8, 1,
0, self->vertex_offset / gsk_vulkan_border_info.pVertexBindingDescriptions[0].stride);
return op->next;
return gsk_vulkan_op_draw_command_n (op, render, pipeline_layout, command_buffer, 8);
}
static const GskVulkanOpClass GSK_VULKAN_BORDER_OP_CLASS = {
@ -123,8 +89,8 @@ static const GskVulkanOpClass GSK_VULKAN_BORDER_OP_CLASS = {
&gsk_vulkan_border_info,
gsk_vulkan_border_op_finish,
gsk_vulkan_border_op_print,
gsk_vulkan_border_op_upload,
gsk_vulkan_border_op_count_vertex_data,
gsk_vulkan_op_draw_upload,
gsk_vulkan_op_draw_count_vertex_data,
gsk_vulkan_border_op_collect_vertex_data,
gsk_vulkan_border_op_reserve_descriptor_sets,
gsk_vulkan_border_op_command

View File

@ -19,7 +19,6 @@ struct _GskVulkanColorMatrixOp
graphene_rect_t tex_rect;
guint32 image_descriptor;
gsize vertex_offset;
};
static void
@ -43,38 +42,12 @@ gsk_vulkan_color_matrix_op_print (GskVulkanOp *op,
print_newline (string);
}
static void
gsk_vulkan_color_matrix_op_upload (GskVulkanOp *op,
GskVulkanUploader *uploader)
{
}
static inline gsize
round_up (gsize number, gsize divisor)
{
return (number + divisor - 1) / divisor * divisor;
}
static gsize
gsk_vulkan_color_matrix_op_count_vertex_data (GskVulkanOp *op,
gsize n_bytes)
{
GskVulkanColorMatrixOp *self = (GskVulkanColorMatrixOp *) op;
gsize vertex_stride;
vertex_stride = gsk_vulkan_color_matrix_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_matrix_op_collect_vertex_data (GskVulkanOp *op,
guchar *data)
{
GskVulkanColorMatrixOp *self = (GskVulkanColorMatrixOp *) op;
GskVulkanColorMatrixInstance *instance = (GskVulkanColorMatrixInstance *) (data + self->vertex_offset);
GskVulkanColorMatrixInstance *instance = (GskVulkanColorMatrixInstance *) (data + op->vertex_offset);
instance->rect[0] = self->rect.origin.x;
instance->rect[1] = self->rect.origin.y;
@ -100,21 +73,6 @@ gsk_vulkan_color_matrix_op_reserve_descriptor_sets (GskVulkanOp *op,
GSK_VULKAN_SAMPLER_DEFAULT);
}
static GskVulkanOp *
gsk_vulkan_color_matrix_op_command (GskVulkanOp *op,
GskVulkanRender *render,
VkPipelineLayout pipeline_layout,
VkCommandBuffer command_buffer)
{
GskVulkanColorMatrixOp *self = (GskVulkanColorMatrixOp *) op;
vkCmdDraw (command_buffer,
6, 1,
0, self->vertex_offset / gsk_vulkan_color_matrix_info.pVertexBindingDescriptions[0].stride);
return op->next;
}
static const GskVulkanOpClass GSK_VULKAN_COLOR_MATRIX_OP_CLASS = {
GSK_VULKAN_OP_SIZE (GskVulkanColorMatrixOp),
GSK_VULKAN_STAGE_COMMAND,
@ -122,11 +80,11 @@ static const GskVulkanOpClass GSK_VULKAN_COLOR_MATRIX_OP_CLASS = {
&gsk_vulkan_color_matrix_info,
gsk_vulkan_color_matrix_op_finish,
gsk_vulkan_color_matrix_op_print,
gsk_vulkan_color_matrix_op_upload,
gsk_vulkan_color_matrix_op_count_vertex_data,
gsk_vulkan_op_draw_upload,
gsk_vulkan_op_draw_count_vertex_data,
gsk_vulkan_color_matrix_op_collect_vertex_data,
gsk_vulkan_color_matrix_op_reserve_descriptor_sets,
gsk_vulkan_color_matrix_op_command
gsk_vulkan_op_draw_command
};
void

View File

@ -14,8 +14,6 @@ struct _GskVulkanColorOp
graphene_rect_t rect;
GdkRGBA color;
gsize vertex_offset;
};
static void
@ -29,26 +27,6 @@ gsk_vulkan_color_op_upload (GskVulkanOp *op,
{
}
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_print (GskVulkanOp *op,
GString *string,
@ -68,7 +46,7 @@ gsk_vulkan_color_op_collect_vertex_data (GskVulkanOp *op,
guchar *data)
{
GskVulkanColorOp *self = (GskVulkanColorOp *) op;
GskVulkanColorInstance *instance = (GskVulkanColorInstance *) (data + self->vertex_offset);
GskVulkanColorInstance *instance = (GskVulkanColorInstance *) (data + op->vertex_offset);
instance->rect[0] = self->rect.origin.x;
instance->rect[1] = self->rect.origin.y;
@ -86,21 +64,6 @@ gsk_vulkan_color_op_reserve_descriptor_sets (GskVulkanOp *op,
{
}
static GskVulkanOp *
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);
return op->next;
}
static const GskVulkanOpClass GSK_VULKAN_COLOR_OP_CLASS = {
GSK_VULKAN_OP_SIZE (GskVulkanColorOp),
GSK_VULKAN_STAGE_COMMAND,
@ -109,10 +72,10 @@ static const GskVulkanOpClass GSK_VULKAN_COLOR_OP_CLASS = {
gsk_vulkan_color_op_finish,
gsk_vulkan_color_op_print,
gsk_vulkan_color_op_upload,
gsk_vulkan_color_op_count_vertex_data,
gsk_vulkan_op_draw_count_vertex_data,
gsk_vulkan_color_op_collect_vertex_data,
gsk_vulkan_color_op_reserve_descriptor_sets,
gsk_vulkan_color_op_command
gsk_vulkan_op_draw_command
};
void

View File

@ -21,8 +21,6 @@ struct _GskVulkanCrossFadeOp
graphene_rect_t tex_rect;
guint32 image_descriptor;
} start, end;
gsize vertex_offset;
};
static void
@ -47,38 +45,12 @@ gsk_vulkan_cross_fade_op_print (GskVulkanOp *op,
print_newline (string);
}
static void
gsk_vulkan_cross_fade_op_upload (GskVulkanOp *op,
GskVulkanUploader *uploader)
{
}
static inline gsize
round_up (gsize number, gsize divisor)
{
return (number + divisor - 1) / divisor * divisor;
}
static gsize
gsk_vulkan_cross_fade_op_count_vertex_data (GskVulkanOp *op,
gsize n_bytes)
{
GskVulkanCrossFadeOp *self = (GskVulkanCrossFadeOp *) op;
gsize vertex_stride;
vertex_stride = gsk_vulkan_cross_fade_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_cross_fade_op_collect_vertex_data (GskVulkanOp *op,
guchar *data)
{
GskVulkanCrossFadeOp *self = (GskVulkanCrossFadeOp *) op;
GskVulkanCrossFadeInstance *instance = (GskVulkanCrossFadeInstance *) (data + self->vertex_offset);
GskVulkanCrossFadeInstance *instance = (GskVulkanCrossFadeInstance *) (data + op->vertex_offset);
gsk_vulkan_rect_to_float (&self->bounds, instance->rect);
gsk_vulkan_rect_to_float (&self->start.rect, instance->start_rect);
@ -105,21 +77,6 @@ gsk_vulkan_cross_fade_op_reserve_descriptor_sets (GskVulkanOp *op,
GSK_VULKAN_SAMPLER_DEFAULT);
}
static GskVulkanOp *
gsk_vulkan_cross_fade_op_command (GskVulkanOp *op,
GskVulkanRender *render,
VkPipelineLayout pipeline_layout,
VkCommandBuffer command_buffer)
{
GskVulkanCrossFadeOp *self = (GskVulkanCrossFadeOp *) op;
vkCmdDraw (command_buffer,
6, 1,
0, self->vertex_offset / gsk_vulkan_cross_fade_info.pVertexBindingDescriptions[0].stride);
return op->next;
}
static const GskVulkanOpClass GSK_VULKAN_CROSS_FADE_OP_CLASS = {
GSK_VULKAN_OP_SIZE (GskVulkanCrossFadeOp),
GSK_VULKAN_STAGE_COMMAND,
@ -127,11 +84,11 @@ static const GskVulkanOpClass GSK_VULKAN_CROSS_FADE_OP_CLASS = {
&gsk_vulkan_cross_fade_info,
gsk_vulkan_cross_fade_op_finish,
gsk_vulkan_cross_fade_op_print,
gsk_vulkan_cross_fade_op_upload,
gsk_vulkan_cross_fade_op_count_vertex_data,
gsk_vulkan_op_draw_upload,
gsk_vulkan_op_draw_count_vertex_data,
gsk_vulkan_cross_fade_op_collect_vertex_data,
gsk_vulkan_cross_fade_op_reserve_descriptor_sets,
gsk_vulkan_cross_fade_op_command
gsk_vulkan_op_draw_command
};
void

View File

@ -18,7 +18,6 @@ struct _GskVulkanGlyphOp
GdkRGBA color;
guint32 image_descriptor;
gsize vertex_offset;
};
static void
@ -29,12 +28,6 @@ gsk_vulkan_glyph_op_finish (GskVulkanOp *op)
g_object_unref (self->image);
}
static void
gsk_vulkan_glyph_op_upload (GskVulkanOp *op,
GskVulkanUploader *uploader)
{
}
static void
gsk_vulkan_glyph_op_print (GskVulkanOp *op,
GString *string,
@ -49,32 +42,12 @@ gsk_vulkan_glyph_op_print (GskVulkanOp *op,
print_newline (string);
}
static inline gsize
round_up (gsize number, gsize divisor)
{
return (number + divisor - 1) / divisor * divisor;
}
static gsize
gsk_vulkan_glyph_op_count_vertex_data (GskVulkanOp *op,
gsize n_bytes)
{
GskVulkanGlyphOp *self = (GskVulkanGlyphOp *) op;
gsize vertex_stride;
vertex_stride = gsk_vulkan_glyph_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_glyph_op_collect_vertex_data (GskVulkanOp *op,
guchar *data)
{
GskVulkanGlyphOp *self = (GskVulkanGlyphOp *) op;
GskVulkanGlyphInstance *instance = (GskVulkanGlyphInstance *) (data + self->vertex_offset);
GskVulkanGlyphInstance *instance = (GskVulkanGlyphInstance *) (data + op->vertex_offset);
gsk_vulkan_rect_to_float (&self->rect, instance->rect);
gsk_vulkan_rect_to_float (&self->tex_rect, instance->tex_rect);
@ -91,21 +64,6 @@ gsk_vulkan_glyph_op_reserve_descriptor_sets (GskVulkanOp *op,
self->image_descriptor = gsk_vulkan_render_get_image_descriptor (render, self->image, GSK_VULKAN_SAMPLER_DEFAULT);
}
static GskVulkanOp *
gsk_vulkan_glyph_op_command (GskVulkanOp *op,
GskVulkanRender *render,
VkPipelineLayout pipeline_layout,
VkCommandBuffer command_buffer)
{
GskVulkanGlyphOp *self = (GskVulkanGlyphOp *) op;
vkCmdDraw (command_buffer,
6, 1,
0, self->vertex_offset / gsk_vulkan_glyph_info.pVertexBindingDescriptions[0].stride);
return op->next;
}
static const GskVulkanOpClass GSK_VULKAN_GLYPH_OP_CLASS = {
GSK_VULKAN_OP_SIZE (GskVulkanGlyphOp),
GSK_VULKAN_STAGE_COMMAND,
@ -113,11 +71,11 @@ static const GskVulkanOpClass GSK_VULKAN_GLYPH_OP_CLASS = {
&gsk_vulkan_glyph_info,
gsk_vulkan_glyph_op_finish,
gsk_vulkan_glyph_op_print,
gsk_vulkan_glyph_op_upload,
gsk_vulkan_glyph_op_count_vertex_data,
gsk_vulkan_op_draw_upload,
gsk_vulkan_op_draw_count_vertex_data,
gsk_vulkan_glyph_op_collect_vertex_data,
gsk_vulkan_glyph_op_reserve_descriptor_sets,
gsk_vulkan_glyph_op_command
gsk_vulkan_op_draw_command
};
void

View File

@ -18,8 +18,6 @@ struct _GskVulkanInsetShadowOp
graphene_point_t offset;
float spread;
float blur_radius;
gsize vertex_offset;
};
static void
@ -42,38 +40,12 @@ gsk_vulkan_inset_shadow_op_print (GskVulkanOp *op,
print_newline (string);
}
static void
gsk_vulkan_inset_shadow_op_upload (GskVulkanOp *op,
GskVulkanUploader *uploader)
{
}
static inline gsize
round_up (gsize number, gsize divisor)
{
return (number + divisor - 1) / divisor * divisor;
}
static gsize
gsk_vulkan_inset_shadow_op_count_vertex_data (GskVulkanOp *op,
gsize n_bytes)
{
GskVulkanInsetShadowOp *self = (GskVulkanInsetShadowOp *) op;
gsize vertex_stride;
vertex_stride = gsk_vulkan_inset_shadow_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_inset_shadow_op_collect_vertex_data (GskVulkanOp *op,
guchar *data)
{
GskVulkanInsetShadowOp *self = (GskVulkanInsetShadowOp *) op;
GskVulkanInsetShadowInstance *instance = (GskVulkanInsetShadowInstance *) (data + self->vertex_offset);
GskVulkanInsetShadowInstance *instance = (GskVulkanInsetShadowInstance *) (data + op->vertex_offset);
gsk_rounded_rect_to_float (&self->outline, graphene_point_zero (), instance->outline);
gsk_vulkan_rgba_to_float (&self->color, instance->color);
@ -88,21 +60,6 @@ gsk_vulkan_inset_shadow_op_reserve_descriptor_sets (GskVulkanOp *op,
{
}
static GskVulkanOp *
gsk_vulkan_inset_shadow_op_command (GskVulkanOp *op,
GskVulkanRender *render,
VkPipelineLayout pipeline_layout,
VkCommandBuffer command_buffer)
{
GskVulkanInsetShadowOp *self = (GskVulkanInsetShadowOp *) op;
vkCmdDraw (command_buffer,
6, 1,
0, self->vertex_offset / gsk_vulkan_inset_shadow_info.pVertexBindingDescriptions[0].stride);
return op->next;
}
static const GskVulkanOpClass GSK_VULKAN_INSET_SHADOW_OP_CLASS = {
GSK_VULKAN_OP_SIZE (GskVulkanInsetShadowOp),
GSK_VULKAN_STAGE_COMMAND,
@ -110,11 +67,11 @@ static const GskVulkanOpClass GSK_VULKAN_INSET_SHADOW_OP_CLASS = {
&gsk_vulkan_inset_shadow_info,
gsk_vulkan_inset_shadow_op_finish,
gsk_vulkan_inset_shadow_op_print,
gsk_vulkan_inset_shadow_op_upload,
gsk_vulkan_inset_shadow_op_count_vertex_data,
gsk_vulkan_op_draw_upload,
gsk_vulkan_op_draw_count_vertex_data,
gsk_vulkan_inset_shadow_op_collect_vertex_data,
gsk_vulkan_inset_shadow_op_reserve_descriptor_sets,
gsk_vulkan_inset_shadow_op_command
gsk_vulkan_op_draw_command
};
void

View File

@ -20,7 +20,6 @@ struct _GskVulkanLinearGradientOp
gsize n_stops;
gsize buffer_offset;
gsize vertex_offset;
};
static void
@ -45,37 +44,11 @@ gsk_vulkan_linear_gradient_op_print (GskVulkanOp *op,
}
static void
gsk_vulkan_linear_gradient_op_upload (GskVulkanOp *op,
GskVulkanUploader *uploader)
{
}
static inline gsize
round_up (gsize number, gsize divisor)
{
return (number + divisor - 1) / divisor * divisor;
}
static gsize
gsk_vulkan_linear_gradient_op_count_vertex_data (GskVulkanOp *op,
gsize n_bytes)
gsk_vulkan_linear_gradient_op_collect_vertex_data (GskVulkanOp *op,
guchar *data)
{
GskVulkanLinearGradientOp *self = (GskVulkanLinearGradientOp *) op;
gsize vertex_stride;
vertex_stride = gsk_vulkan_linear_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_linear_gradient_op_collect_vertex_data (GskVulkanOp *op,
guchar *data)
{
GskVulkanLinearGradientOp *self = (GskVulkanLinearGradientOp *) op;
GskVulkanLinearInstance *instance = (GskVulkanLinearInstance *) (data + self->vertex_offset);
GskVulkanLinearInstance *instance = (GskVulkanLinearInstance *) (data + op->vertex_offset);
gsk_vulkan_rect_to_float (&self->rect, instance->rect);
gsk_vulkan_point_to_float (&self->start, instance->start);
@ -99,21 +72,6 @@ gsk_vulkan_linear_gradient_op_reserve_descriptor_sets (GskVulkanOp *op,
memcpy (mem, self->stops, self->n_stops * sizeof (GskColorStop));
}
static GskVulkanOp *
gsk_vulkan_linear_gradient_op_command (GskVulkanOp *op,
GskVulkanRender *render,
VkPipelineLayout pipeline_layout,
VkCommandBuffer command_buffer)
{
GskVulkanLinearGradientOp *self = (GskVulkanLinearGradientOp *) op;
vkCmdDraw (command_buffer,
6, 1,
0, self->vertex_offset / gsk_vulkan_linear_info.pVertexBindingDescriptions[0].stride);
return op->next;
}
static const GskVulkanOpClass GSK_VULKAN_LINEAR_GRADIENT_OP_CLASS = {
GSK_VULKAN_OP_SIZE (GskVulkanLinearGradientOp),
GSK_VULKAN_STAGE_COMMAND,
@ -121,11 +79,11 @@ static const GskVulkanOpClass GSK_VULKAN_LINEAR_GRADIENT_OP_CLASS = {
&gsk_vulkan_linear_info,
gsk_vulkan_linear_gradient_op_finish,
gsk_vulkan_linear_gradient_op_print,
gsk_vulkan_linear_gradient_op_upload,
gsk_vulkan_linear_gradient_op_count_vertex_data,
gsk_vulkan_op_draw_upload,
gsk_vulkan_op_draw_count_vertex_data,
gsk_vulkan_linear_gradient_op_collect_vertex_data,
gsk_vulkan_linear_gradient_op_reserve_descriptor_sets,
gsk_vulkan_linear_gradient_op_command
gsk_vulkan_op_draw_command
};
void

View File

@ -19,8 +19,6 @@ struct _GskVulkanMaskOp
guint32 image_descriptor;
} source, mask;
GskMaskMode mask_mode;
gsize vertex_offset;
};
static void
@ -64,38 +62,12 @@ gsk_vulkan_mask_op_print (GskVulkanOp *op,
print_newline (string);
}
static void
gsk_vulkan_mask_op_upload (GskVulkanOp *op,
GskVulkanUploader *uploader)
{
}
static inline gsize
round_up (gsize number, gsize divisor)
{
return (number + divisor - 1) / divisor * divisor;
}
static gsize
gsk_vulkan_mask_op_count_vertex_data (GskVulkanOp *op,
gsize n_bytes)
{
GskVulkanMaskOp *self = (GskVulkanMaskOp *) op;
gsize vertex_stride;
vertex_stride = gsk_vulkan_mask_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_mask_op_collect_vertex_data (GskVulkanOp *op,
guchar *data)
{
GskVulkanMaskOp *self = (GskVulkanMaskOp *) op;
GskVulkanMaskInstance *instance = (GskVulkanMaskInstance *) (data + self->vertex_offset);
GskVulkanMaskInstance *instance = (GskVulkanMaskInstance *) (data + op->vertex_offset);
gsk_vulkan_rect_to_float (&self->source.rect, instance->source_rect);
gsk_vulkan_rect_to_float (&self->source.tex_rect, instance->source_tex_rect);
@ -116,21 +88,6 @@ gsk_vulkan_mask_op_reserve_descriptor_sets (GskVulkanOp *op,
self->mask.image_descriptor = gsk_vulkan_render_get_image_descriptor (render, self->mask.image, GSK_VULKAN_SAMPLER_DEFAULT);
}
static GskVulkanOp *
gsk_vulkan_mask_op_command (GskVulkanOp *op,
GskVulkanRender *render,
VkPipelineLayout pipeline_layout,
VkCommandBuffer command_buffer)
{
GskVulkanMaskOp *self = (GskVulkanMaskOp *) op;
vkCmdDraw (command_buffer,
6, 1,
0, self->vertex_offset / gsk_vulkan_mask_info.pVertexBindingDescriptions[0].stride);
return op->next;
}
static const GskVulkanOpClass GSK_VULKAN_COLOR_MASK_OP_CLASS = {
GSK_VULKAN_OP_SIZE (GskVulkanMaskOp),
GSK_VULKAN_STAGE_COMMAND,
@ -138,11 +95,11 @@ static const GskVulkanOpClass GSK_VULKAN_COLOR_MASK_OP_CLASS = {
&gsk_vulkan_mask_info,
gsk_vulkan_mask_op_finish,
gsk_vulkan_mask_op_print,
gsk_vulkan_mask_op_upload,
gsk_vulkan_mask_op_count_vertex_data,
gsk_vulkan_op_draw_upload,
gsk_vulkan_op_draw_count_vertex_data,
gsk_vulkan_mask_op_collect_vertex_data,
gsk_vulkan_mask_op_reserve_descriptor_sets,
gsk_vulkan_mask_op_command
gsk_vulkan_op_draw_command
};
void

View File

@ -66,3 +66,51 @@ gsk_vulkan_op_command (GskVulkanOp *op,
return op->op_class->command (op, render, pipeline_layout, command_buffer);
}
void
gsk_vulkan_op_draw_upload (GskVulkanOp *op,
GskVulkanUploader *uploader)
{
}
static inline gsize
round_up (gsize number, gsize divisor)
{
return (number + divisor - 1) / divisor * divisor;
}
gsize
gsk_vulkan_op_draw_count_vertex_data (GskVulkanOp *op,
gsize n_bytes)
{
gsize vertex_stride;
vertex_stride = op->op_class->vertex_input_state->pVertexBindingDescriptions[0].stride;
n_bytes = round_up (n_bytes, vertex_stride);
op->vertex_offset = n_bytes;
n_bytes += vertex_stride;
return n_bytes;
}
GskVulkanOp *
gsk_vulkan_op_draw_command_n (GskVulkanOp *op,
GskVulkanRender *render,
VkPipelineLayout pipeline_layout,
VkCommandBuffer command_buffer,
gsize instance_scale)
{
vkCmdDraw (command_buffer,
6 * instance_scale, 1,
0, op->vertex_offset / op->op_class->vertex_input_state->pVertexBindingDescriptions[0].stride);
return op->next;
}
GskVulkanOp *
gsk_vulkan_op_draw_command (GskVulkanOp *op,
GskVulkanRender *render,
VkPipelineLayout pipeline_layout,
VkCommandBuffer command_buffer)
{
return gsk_vulkan_op_draw_command_n (op, render, pipeline_layout, command_buffer, 1);
}

View File

@ -23,6 +23,7 @@ struct _GskVulkanOp
const /* interned */ char *clip_type;
GskVulkanOp *next;
gsize vertex_offset;
};
struct _GskVulkanOpClass
@ -77,5 +78,19 @@ GskVulkanOp * gsk_vulkan_op_command (GskVulk
VkPipelineLayout pipeline_layout,
VkCommandBuffer command_buffer);
void gsk_vulkan_op_draw_upload (GskVulkanOp *op,
GskVulkanUploader *uploader);
gsize gsk_vulkan_op_draw_count_vertex_data (GskVulkanOp *op,
gsize n_bytes);
GskVulkanOp * gsk_vulkan_op_draw_command_n (GskVulkanOp *op,
GskVulkanRender *render,
VkPipelineLayout pipeline_layout,
VkCommandBuffer command_buffer,
gsize instance_scale);
GskVulkanOp * gsk_vulkan_op_draw_command (GskVulkanOp *op,
GskVulkanRender *render,
VkPipelineLayout pipeline_layout,
VkCommandBuffer command_buffer);
G_END_DECLS

View File

@ -18,8 +18,6 @@ struct _GskVulkanOutsetShadowOp
graphene_point_t offset;
float spread;
float blur_radius;
gsize vertex_offset;
};
static void
@ -42,38 +40,12 @@ gsk_vulkan_outset_shadow_op_print (GskVulkanOp *op,
print_newline (string);
}
static void
gsk_vulkan_outset_shadow_op_upload (GskVulkanOp *op,
GskVulkanUploader *uploader)
{
}
static inline gsize
round_up (gsize number, gsize divisor)
{
return (number + divisor - 1) / divisor * divisor;
}
static gsize
gsk_vulkan_outset_shadow_op_count_vertex_data (GskVulkanOp *op,
gsize n_bytes)
{
GskVulkanOutsetShadowOp *self = (GskVulkanOutsetShadowOp *) op;
gsize vertex_stride;
vertex_stride = gsk_vulkan_outset_shadow_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_outset_shadow_op_collect_vertex_data (GskVulkanOp *op,
guchar *data)
{
GskVulkanOutsetShadowOp *self = (GskVulkanOutsetShadowOp *) op;
GskVulkanOutsetShadowInstance *instance = (GskVulkanOutsetShadowInstance *) (data + self->vertex_offset);
GskVulkanOutsetShadowInstance *instance = (GskVulkanOutsetShadowInstance *) (data + op->vertex_offset);
gsk_rounded_rect_to_float (&self->outline, graphene_point_zero (), instance->outline);
gsk_vulkan_rgba_to_float (&self->color, instance->color);
@ -88,21 +60,6 @@ gsk_vulkan_outset_shadow_op_reserve_descriptor_sets (GskVulkanOp *op,
{
}
static GskVulkanOp *
gsk_vulkan_outset_shadow_op_command (GskVulkanOp *op,
GskVulkanRender *render,
VkPipelineLayout pipeline_layout,
VkCommandBuffer command_buffer)
{
GskVulkanOutsetShadowOp *self = (GskVulkanOutsetShadowOp *) op;
vkCmdDraw (command_buffer,
6, 1,
0, self->vertex_offset / gsk_vulkan_outset_shadow_info.pVertexBindingDescriptions[0].stride);
return op->next;
}
static const GskVulkanOpClass GSK_VULKAN_OUTSET_SHADOW_OP_CLASS = {
GSK_VULKAN_OP_SIZE (GskVulkanOutsetShadowOp),
GSK_VULKAN_STAGE_COMMAND,
@ -110,11 +67,11 @@ static const GskVulkanOpClass GSK_VULKAN_OUTSET_SHADOW_OP_CLASS = {
&gsk_vulkan_outset_shadow_info,
gsk_vulkan_outset_shadow_op_finish,
gsk_vulkan_outset_shadow_op_print,
gsk_vulkan_outset_shadow_op_upload,
gsk_vulkan_outset_shadow_op_count_vertex_data,
gsk_vulkan_op_draw_upload,
gsk_vulkan_op_draw_count_vertex_data,
gsk_vulkan_outset_shadow_op_collect_vertex_data,
gsk_vulkan_outset_shadow_op_reserve_descriptor_sets,
gsk_vulkan_outset_shadow_op_command
gsk_vulkan_op_draw_command
};
void

View File

@ -18,7 +18,6 @@ struct _GskVulkanTextureOp
graphene_rect_t tex_rect;
guint32 image_descriptor;
gsize vertex_offset;
};
static void
@ -43,38 +42,12 @@ gsk_vulkan_texture_op_print (GskVulkanOp *op,
print_newline (string);
}
static void
gsk_vulkan_texture_op_upload (GskVulkanOp *op,
GskVulkanUploader *uploader)
{
}
static inline gsize
round_up (gsize number, gsize divisor)
{
return (number + divisor - 1) / divisor * divisor;
}
static gsize
gsk_vulkan_texture_op_count_vertex_data (GskVulkanOp *op,
gsize n_bytes)
{
GskVulkanTextureOp *self = (GskVulkanTextureOp *) op;
gsize vertex_stride;
vertex_stride = gsk_vulkan_texture_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_texture_op_collect_vertex_data (GskVulkanOp *op,
guchar *data)
{
GskVulkanTextureOp *self = (GskVulkanTextureOp *) op;
GskVulkanTextureInstance *instance = (GskVulkanTextureInstance *) (data + self->vertex_offset);
GskVulkanTextureInstance *instance = (GskVulkanTextureInstance *) (data + op->vertex_offset);
instance->rect[0] = self->rect.origin.x;
instance->rect[1] = self->rect.origin.y;
@ -96,21 +69,6 @@ gsk_vulkan_texture_op_reserve_descriptor_sets (GskVulkanOp *op,
self->image_descriptor = gsk_vulkan_render_get_image_descriptor (render, self->image, self->sampler);
}
static GskVulkanOp *
gsk_vulkan_texture_op_command (GskVulkanOp *op,
GskVulkanRender *render,
VkPipelineLayout pipeline_layout,
VkCommandBuffer command_buffer)
{
GskVulkanTextureOp *self = (GskVulkanTextureOp *) op;
vkCmdDraw (command_buffer,
6, 1,
0, self->vertex_offset / gsk_vulkan_texture_info.pVertexBindingDescriptions[0].stride);
return op->next;
}
static const GskVulkanOpClass GSK_VULKAN_TEXTURE_OP_CLASS = {
GSK_VULKAN_OP_SIZE (GskVulkanTextureOp),
GSK_VULKAN_STAGE_COMMAND,
@ -118,11 +76,11 @@ static const GskVulkanOpClass GSK_VULKAN_TEXTURE_OP_CLASS = {
&gsk_vulkan_texture_info,
gsk_vulkan_texture_op_finish,
gsk_vulkan_texture_op_print,
gsk_vulkan_texture_op_upload,
gsk_vulkan_texture_op_count_vertex_data,
gsk_vulkan_op_draw_upload,
gsk_vulkan_op_draw_count_vertex_data,
gsk_vulkan_texture_op_collect_vertex_data,
gsk_vulkan_texture_op_reserve_descriptor_sets,
gsk_vulkan_texture_op_command
gsk_vulkan_op_draw_command
};
void