vulkan: Make border shader use new ops
This commit is contained in:
@@ -109,7 +109,7 @@ if have_vulkan
|
||||
gsk_private_sources += files([
|
||||
'vulkan/gskvulkanblendmodeop.c',
|
||||
'vulkan/gskvulkanblurop.c',
|
||||
'vulkan/gskvulkanborderpipeline.c',
|
||||
'vulkan/gskvulkanborderop.c',
|
||||
'vulkan/gskvulkanbuffer.c',
|
||||
'vulkan/gskvulkanclip.c',
|
||||
'vulkan/gskvulkancolormatrixop.c',
|
||||
|
||||
135
gsk/vulkan/gskvulkanborderop.c
Normal file
135
gsk/vulkan/gskvulkanborderop.c
Normal file
@@ -0,0 +1,135 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "gskvulkanborderopprivate.h"
|
||||
|
||||
#include "vulkan/resources/border.vert.h"
|
||||
|
||||
#include "gsk/gskroundedrectprivate.h"
|
||||
|
||||
typedef struct _GskVulkanBorderOp GskVulkanBorderOp;
|
||||
|
||||
struct _GskVulkanBorderOp
|
||||
{
|
||||
GskVulkanOp op;
|
||||
|
||||
GskRoundedRect outline;
|
||||
float widths[4];
|
||||
GdkRGBA colors[4];
|
||||
|
||||
gsize vertex_offset;
|
||||
};
|
||||
|
||||
static void
|
||||
gsk_vulkan_border_op_finish (GskVulkanOp *op)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_vulkan_border_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_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,
|
||||
GskVulkanRenderPass *pass,
|
||||
GskVulkanRender *render,
|
||||
guchar *data)
|
||||
{
|
||||
GskVulkanBorderOp *self = (GskVulkanBorderOp *) op;
|
||||
GskVulkanBorderInstance *instance = (GskVulkanBorderInstance *) (data + self->vertex_offset);
|
||||
guint i;
|
||||
|
||||
gsk_rounded_rect_to_float (&self->outline, graphene_point_zero (), instance->rect);
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
instance->border_widths[i] = self->widths[i];
|
||||
gsk_vulkan_rgba_to_float (&self->colors[i], (gpointer) &instance->border_colors[4 * i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_vulkan_border_op_reserve_descriptor_sets (GskVulkanOp *op,
|
||||
GskVulkanRender *render)
|
||||
{
|
||||
}
|
||||
|
||||
static VkPipeline
|
||||
gsk_vulkan_border_op_get_pipeline (GskVulkanOp *op)
|
||||
{
|
||||
return VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_vulkan_border_op_command (GskVulkanOp *op,
|
||||
GskVulkanRender *render,
|
||||
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);
|
||||
}
|
||||
|
||||
static const GskVulkanOpClass GSK_VULKAN_BORDER_OP_CLASS = {
|
||||
GSK_VULKAN_OP_SIZE (GskVulkanBorderOp),
|
||||
"border",
|
||||
&gsk_vulkan_border_info,
|
||||
gsk_vulkan_border_op_finish,
|
||||
gsk_vulkan_border_op_upload,
|
||||
gsk_vulkan_border_op_count_vertex_data,
|
||||
gsk_vulkan_border_op_collect_vertex_data,
|
||||
gsk_vulkan_border_op_reserve_descriptor_sets,
|
||||
gsk_vulkan_border_op_get_pipeline,
|
||||
gsk_vulkan_border_op_command
|
||||
};
|
||||
|
||||
void
|
||||
gsk_vulkan_border_op (GskVulkanRenderPass *render_pass,
|
||||
const char *clip_type,
|
||||
const GskRoundedRect *outline,
|
||||
const graphene_point_t *offset,
|
||||
const float widths[4],
|
||||
const GdkRGBA colors[4])
|
||||
{
|
||||
GskVulkanBorderOp *self;
|
||||
guint i;
|
||||
|
||||
self = (GskVulkanBorderOp *) gsk_vulkan_op_alloc (render_pass, &GSK_VULKAN_BORDER_OP_CLASS);
|
||||
|
||||
((GskVulkanOp *) self)->clip_type = g_intern_string (clip_type);
|
||||
self->outline = *outline;
|
||||
gsk_rounded_rect_offset (&self->outline, offset->x, offset->y);
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
self->widths[i] = widths[i];
|
||||
self->colors[i] = colors[i];
|
||||
}
|
||||
}
|
||||
|
||||
16
gsk/vulkan/gskvulkanborderopprivate.h
Normal file
16
gsk/vulkan/gskvulkanborderopprivate.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include "gskvulkanopprivate.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
void gsk_vulkan_border_op (GskVulkanRenderPass *render_pass,
|
||||
const char *clip_type,
|
||||
const GskRoundedRect *outline,
|
||||
const graphene_point_t *offset,
|
||||
const float widths[4],
|
||||
const GdkRGBA colors[4]);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "gskvulkanborderpipelineprivate.h"
|
||||
|
||||
#include "gskroundedrectprivate.h"
|
||||
|
||||
#include "vulkan/resources/border.vert.h"
|
||||
|
||||
struct _GskVulkanBorderPipeline
|
||||
{
|
||||
GObject parent_instance;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (GskVulkanBorderPipeline, gsk_vulkan_border_pipeline, GSK_TYPE_VULKAN_PIPELINE)
|
||||
|
||||
static const VkPipelineVertexInputStateCreateInfo *
|
||||
gsk_vulkan_border_pipeline_get_input_state_create_info (GskVulkanPipeline *self)
|
||||
{
|
||||
return &gsk_vulkan_border_info;
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_vulkan_border_pipeline_finalize (GObject *gobject)
|
||||
{
|
||||
//GskVulkanBorderPipeline *self = GSK_VULKAN_BORDER_PIPELINE (gobject);
|
||||
|
||||
G_OBJECT_CLASS (gsk_vulkan_border_pipeline_parent_class)->finalize (gobject);
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_vulkan_border_pipeline_class_init (GskVulkanBorderPipelineClass *klass)
|
||||
{
|
||||
GskVulkanPipelineClass *pipeline_class = GSK_VULKAN_PIPELINE_CLASS (klass);
|
||||
|
||||
G_OBJECT_CLASS (klass)->finalize = gsk_vulkan_border_pipeline_finalize;
|
||||
|
||||
pipeline_class->get_input_state_create_info = gsk_vulkan_border_pipeline_get_input_state_create_info;
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_vulkan_border_pipeline_init (GskVulkanBorderPipeline *self)
|
||||
{
|
||||
}
|
||||
|
||||
GskVulkanPipeline *
|
||||
gsk_vulkan_border_pipeline_new (GdkVulkanContext *context,
|
||||
VkPipelineLayout layout,
|
||||
const char *shader_name,
|
||||
VkRenderPass render_pass)
|
||||
{
|
||||
return gsk_vulkan_pipeline_new (GSK_TYPE_VULKAN_BORDER_PIPELINE, context, layout, shader_name, render_pass);
|
||||
}
|
||||
|
||||
void
|
||||
gsk_vulkan_border_pipeline_collect_vertex_data (GskVulkanBorderPipeline *pipeline,
|
||||
guchar *data,
|
||||
const graphene_point_t *offset,
|
||||
const GskRoundedRect *rect,
|
||||
const float widths[4],
|
||||
const GdkRGBA colors[4])
|
||||
{
|
||||
GskVulkanBorderInstance *instance = (GskVulkanBorderInstance *) data;
|
||||
guint i;
|
||||
|
||||
gsk_rounded_rect_to_float (rect, offset, instance->rect);
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
instance->border_widths[i] = widths[i];
|
||||
instance->border_colors[4 * i + 0] = colors[i].red;
|
||||
instance->border_colors[4 * i + 1] = colors[i].green;
|
||||
instance->border_colors[4 * i + 2] = colors[i].blue;
|
||||
instance->border_colors[4 * i + 3] = colors[i].alpha;
|
||||
}
|
||||
}
|
||||
|
||||
gsize
|
||||
gsk_vulkan_border_pipeline_draw (GskVulkanBorderPipeline *pipeline,
|
||||
VkCommandBuffer command_buffer,
|
||||
gsize offset,
|
||||
gsize n_commands)
|
||||
{
|
||||
vkCmdDraw (command_buffer,
|
||||
6 * 8, n_commands,
|
||||
0, offset);
|
||||
|
||||
return n_commands;
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <graphene.h>
|
||||
|
||||
#include "gskvulkanpipelineprivate.h"
|
||||
#include "gskroundedrect.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _GskVulkanBorderPipelineLayout GskVulkanBorderPipelineLayout;
|
||||
|
||||
#define GSK_TYPE_VULKAN_BORDER_PIPELINE (gsk_vulkan_border_pipeline_get_type ())
|
||||
|
||||
G_DECLARE_FINAL_TYPE (GskVulkanBorderPipeline, gsk_vulkan_border_pipeline, GSK, VULKAN_BORDER_PIPELINE, GskVulkanPipeline)
|
||||
|
||||
GskVulkanPipeline * gsk_vulkan_border_pipeline_new (GdkVulkanContext *context,
|
||||
VkPipelineLayout layout,
|
||||
const char *shader_name,
|
||||
VkRenderPass render_pass);
|
||||
|
||||
void gsk_vulkan_border_pipeline_collect_vertex_data (GskVulkanBorderPipeline *pipeline,
|
||||
guchar *data,
|
||||
const graphene_point_t *offset,
|
||||
const GskRoundedRect *rect,
|
||||
const float widths[4],
|
||||
const GdkRGBA colors[4]);
|
||||
gsize gsk_vulkan_border_pipeline_draw (GskVulkanBorderPipeline *pipeline,
|
||||
VkCommandBuffer command_buffer,
|
||||
gsize offset,
|
||||
gsize n_commands);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#include "gskvulkanpipelineprivate.h"
|
||||
#include "gskvulkanrenderpassprivate.h"
|
||||
|
||||
#include "gskvulkanborderpipelineprivate.h"
|
||||
#include "gskvulkancolortextpipelineprivate.h"
|
||||
#include "gskvulkanlineargradientpipelineprivate.h"
|
||||
#include "gskvulkantextpipelineprivate.h"
|
||||
@@ -501,9 +500,6 @@ gsk_vulkan_render_get_pipeline (GskVulkanRender *self,
|
||||
{ "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 },
|
||||
{ "border", 0, gsk_vulkan_border_pipeline_new },
|
||||
{ "border-clip", 0, gsk_vulkan_border_pipeline_new },
|
||||
{ "border-clip-rounded", 0, gsk_vulkan_border_pipeline_new },
|
||||
{ "mask", 1, gsk_vulkan_text_pipeline_new },
|
||||
{ "mask-clip", 1, gsk_vulkan_text_pipeline_new },
|
||||
{ "mask-clip-rounded", 1, gsk_vulkan_text_pipeline_new },
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "gsktransform.h"
|
||||
#include "gskvulkanblendmodeopprivate.h"
|
||||
#include "gskvulkanbluropprivate.h"
|
||||
#include "gskvulkanborderpipelineprivate.h"
|
||||
#include "gskvulkanborderopprivate.h"
|
||||
#include "gskvulkanclipprivate.h"
|
||||
#include "gskvulkancolormatrixopprivate.h"
|
||||
#include "gskvulkancoloropprivate.h"
|
||||
@@ -54,7 +54,6 @@ typedef struct _GskVulkanOpPushConstants GskVulkanOpPushConstants;
|
||||
typedef enum {
|
||||
/* GskVulkanOpRender */
|
||||
GSK_VULKAN_OP_LINEAR_GRADIENT,
|
||||
GSK_VULKAN_OP_BORDER,
|
||||
/* GskVulkanOpText */
|
||||
GSK_VULKAN_OP_TEXT,
|
||||
GSK_VULKAN_OP_COLOR_TEXT,
|
||||
@@ -554,23 +553,12 @@ gsk_vulkan_render_pass_add_border_node (GskVulkanRenderPass *self,
|
||||
const GskVulkanParseState *state,
|
||||
GskRenderNode *node)
|
||||
{
|
||||
GskVulkanPipelineType pipeline_type;
|
||||
GskVulkanOpRender op = {
|
||||
.type = GSK_VULKAN_OP_BORDER,
|
||||
.node = node,
|
||||
.offset = state->offset,
|
||||
};
|
||||
|
||||
if (gsk_vulkan_clip_contains_rect (&state->clip, &state->offset, &node->bounds))
|
||||
pipeline_type = GSK_VULKAN_PIPELINE_BORDER;
|
||||
else if (state->clip.type == GSK_VULKAN_CLIP_RECT)
|
||||
pipeline_type = GSK_VULKAN_PIPELINE_BORDER_CLIP;
|
||||
else
|
||||
pipeline_type = GSK_VULKAN_PIPELINE_BORDER_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_border_op (self,
|
||||
gsk_vulkan_clip_get_clip_type (&state->clip, &state->offset, &node->bounds),
|
||||
gsk_border_node_get_outline (node),
|
||||
&state->offset,
|
||||
gsk_border_node_get_widths (node),
|
||||
gsk_border_node_get_colors (node));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -1504,7 +1492,6 @@ gsk_vulkan_render_op_upload (GskVulkanOp *op_,
|
||||
g_assert_not_reached ();
|
||||
case GSK_VULKAN_OP_PUSH_VERTEX_CONSTANTS:
|
||||
case GSK_VULKAN_OP_LINEAR_GRADIENT:
|
||||
case GSK_VULKAN_OP_BORDER:
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1537,7 +1524,6 @@ gsk_vulkan_render_op_count_vertex_data (GskVulkanOp *op_,
|
||||
switch (op->any.type)
|
||||
{
|
||||
case GSK_VULKAN_OP_LINEAR_GRADIENT:
|
||||
case GSK_VULKAN_OP_BORDER:
|
||||
vertex_stride = gsk_vulkan_pipeline_get_vertex_stride (op->render.pipeline);
|
||||
n_bytes = round_up (n_bytes, vertex_stride);
|
||||
op->render.vertex_offset = n_bytes;
|
||||
@@ -1637,15 +1623,6 @@ gsk_vulkan_render_op_collect_vertex_data (GskVulkanOp *op_,
|
||||
gsk_linear_gradient_node_get_n_color_stops (op->render.node));
|
||||
break;
|
||||
|
||||
case GSK_VULKAN_OP_BORDER:
|
||||
gsk_vulkan_border_pipeline_collect_vertex_data (GSK_VULKAN_BORDER_PIPELINE (op->render.pipeline),
|
||||
data + op->render.vertex_offset,
|
||||
&op->render.offset,
|
||||
gsk_border_node_get_outline (op->render.node),
|
||||
gsk_border_node_get_widths (op->render.node),
|
||||
gsk_border_node_get_colors (op->render.node));
|
||||
break;
|
||||
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
case GSK_VULKAN_OP_PUSH_VERTEX_CONSTANTS:
|
||||
@@ -1739,7 +1716,6 @@ gsk_vulkan_render_op_reserve_descriptor_sets (GskVulkanOp *op_,
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
|
||||
case GSK_VULKAN_OP_BORDER:
|
||||
case GSK_VULKAN_OP_PUSH_VERTEX_CONSTANTS:
|
||||
break;
|
||||
}
|
||||
@@ -1804,7 +1780,6 @@ gsk_vulkan_render_op_get_pipeline (GskVulkanOp *op_)
|
||||
switch (op->any.type)
|
||||
{
|
||||
case GSK_VULKAN_OP_LINEAR_GRADIENT:
|
||||
case GSK_VULKAN_OP_BORDER:
|
||||
return gsk_vulkan_pipeline_get_pipeline (op->render.pipeline);
|
||||
|
||||
case GSK_VULKAN_OP_TEXT:
|
||||
@@ -1851,13 +1826,6 @@ gsk_vulkan_render_op_command (GskVulkanOp *op_,
|
||||
1);
|
||||
break;
|
||||
|
||||
case GSK_VULKAN_OP_BORDER:
|
||||
gsk_vulkan_border_pipeline_draw (GSK_VULKAN_BORDER_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_PUSH_VERTEX_CONSTANTS:
|
||||
gsk_vulkan_push_constants_push (command_buffer,
|
||||
pipeline_layout,
|
||||
|
||||
@@ -14,9 +14,6 @@ typedef enum {
|
||||
GSK_VULKAN_PIPELINE_LINEAR_GRADIENT,
|
||||
GSK_VULKAN_PIPELINE_LINEAR_GRADIENT_CLIP,
|
||||
GSK_VULKAN_PIPELINE_LINEAR_GRADIENT_CLIP_ROUNDED,
|
||||
GSK_VULKAN_PIPELINE_BORDER,
|
||||
GSK_VULKAN_PIPELINE_BORDER_CLIP,
|
||||
GSK_VULKAN_PIPELINE_BORDER_CLIP_ROUNDED,
|
||||
GSK_VULKAN_PIPELINE_TEXT,
|
||||
GSK_VULKAN_PIPELINE_TEXT_CLIP,
|
||||
GSK_VULKAN_PIPELINE_TEXT_CLIP_ROUNDED,
|
||||
|
||||
Reference in New Issue
Block a user