From: Benjamin Otte Date: Mon, 3 Jul 2023 07:15:04 +0000 (+0200) Subject: vulkan: Make glyphs use new node ops X-Git-Tag: archive/raspbian/4.12.3+ds-1+rpi1~1^2^2^2~22^2~1^2~60^2~56 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=6e6fa3daedafde12436b9ed3517ef1d2094f7e65;p=gtk4.git vulkan: Make glyphs use new node ops This is a rudimentary - but working - port. Glyph uploads are still using the old machinery, a bunch of functions still exist that probably aren't necessary anymore and each glyph emits its own node. This will need to be improved in further commits. --- diff --git a/gsk/meson.build b/gsk/meson.build index bfb09d7d0b..c468ff0a15 100644 --- a/gsk/meson.build +++ b/gsk/meson.build @@ -114,7 +114,6 @@ if have_vulkan 'vulkan/gskvulkanclip.c', 'vulkan/gskvulkancolormatrixop.c', 'vulkan/gskvulkancolorop.c', - 'vulkan/gskvulkancolortextpipeline.c', 'vulkan/gskvulkancommandpool.c', 'vulkan/gskvulkancrossfadeop.c', 'vulkan/gskvulkanglyphcache.c', @@ -132,7 +131,6 @@ if have_vulkan 'vulkan/gskvulkanrenderer.c', 'vulkan/gskvulkanrenderpass.c', 'vulkan/gskvulkanscissorop.c', - 'vulkan/gskvulkantextpipeline.c', 'vulkan/gskvulkantextureop.c', 'vulkan/gskvulkanuploadcairoop.c', 'vulkan/gskvulkanuploadop.c', diff --git a/gsk/vulkan/gskvulkancolortextpipeline.c b/gsk/vulkan/gskvulkancolortextpipeline.c deleted file mode 100644 index 26b102f9d5..0000000000 --- a/gsk/vulkan/gskvulkancolortextpipeline.c +++ /dev/null @@ -1,121 +0,0 @@ -#include "config.h" - -#include "gskvulkancolortextpipelineprivate.h" - -#include "vulkan/resources/texture.vert.h" - -struct _GskVulkanColorTextPipeline -{ - GObject parent_instance; -}; - -G_DEFINE_TYPE (GskVulkanColorTextPipeline, gsk_vulkan_color_text_pipeline, GSK_TYPE_VULKAN_PIPELINE) - -static const VkPipelineVertexInputStateCreateInfo * -gsk_vulkan_color_text_pipeline_get_input_state_create_info (GskVulkanPipeline *self) -{ - return &gsk_vulkan_texture_info; -} - -static void -gsk_vulkan_color_text_pipeline_finalize (GObject *gobject) -{ - //GskVulkanColorTextPipeline *self = GSK_VULKAN_COLOR_TEXT_PIPELINE (gobject); - - G_OBJECT_CLASS (gsk_vulkan_color_text_pipeline_parent_class)->finalize (gobject); -} - -static void -gsk_vulkan_color_text_pipeline_class_init (GskVulkanColorTextPipelineClass *klass) -{ - GskVulkanPipelineClass *pipeline_class = GSK_VULKAN_PIPELINE_CLASS (klass); - - G_OBJECT_CLASS (klass)->finalize = gsk_vulkan_color_text_pipeline_finalize; - - pipeline_class->get_input_state_create_info = gsk_vulkan_color_text_pipeline_get_input_state_create_info; -} - -static void -gsk_vulkan_color_text_pipeline_init (GskVulkanColorTextPipeline *self) -{ -} - -GskVulkanPipeline * -gsk_vulkan_color_text_pipeline_new (GdkVulkanContext *context, - VkPipelineLayout layout, - const char *shader_name, - VkRenderPass render_pass) -{ - return gsk_vulkan_pipeline_new (GSK_TYPE_VULKAN_COLOR_TEXT_PIPELINE, context, layout, shader_name, render_pass); -} - -void -gsk_vulkan_color_text_pipeline_collect_vertex_data (GskVulkanColorTextPipeline *pipeline, - guchar *data, - GskVulkanRenderer *renderer, - const graphene_rect_t *rect, - guint tex_id, - PangoFont *font, - guint total_glyphs, - const PangoGlyphInfo *glyphs, - const graphene_point_t *offset, - guint start_glyph, - guint num_glyphs, - float scale) -{ - GskVulkanTextureInstance *instances = (GskVulkanTextureInstance *) data; - int i; - int count = 0; - int x_position = 0; - - for (i = 0; i < start_glyph; i++) - x_position += glyphs[i].geometry.width; - - for (; i < total_glyphs && count < num_glyphs; i++) - { - const PangoGlyphInfo *gi = &glyphs[i]; - - if (gi->glyph != PANGO_GLYPH_EMPTY) - { - double cx = (x_position + gi->geometry.x_offset) / PANGO_SCALE; - double cy = gi->geometry.y_offset / PANGO_SCALE; - GskVulkanTextureInstance *instance = &instances[count]; - GskVulkanCachedGlyph *glyph; - - glyph = gsk_vulkan_renderer_get_cached_glyph (renderer, - font, - gi->glyph, - x_position + gi->geometry.x_offset, - gi->geometry.y_offset, - scale); - - instance->rect[0] = offset->x + cx + glyph->draw_x; - instance->rect[1] = offset->y + cy + glyph->draw_y; - instance->rect[2] = glyph->draw_width; - instance->rect[3] = glyph->draw_height; - - instance->tex_rect[0] = glyph->tx; - instance->tex_rect[1] = glyph->ty; - instance->tex_rect[2] = glyph->tw; - instance->tex_rect[3] = glyph->th; - - instance->tex_id = tex_id; - - count++; - } - x_position += gi->geometry.width; - } -} - -gsize -gsk_vulkan_color_text_pipeline_draw (GskVulkanColorTextPipeline *pipeline, - VkCommandBuffer command_buffer, - gsize offset, - gsize n_commands) -{ - vkCmdDraw (command_buffer, - 6, n_commands, - 0, offset); - - return n_commands; -} diff --git a/gsk/vulkan/gskvulkancolortextpipelineprivate.h b/gsk/vulkan/gskvulkancolortextpipelineprivate.h deleted file mode 100644 index 0094398785..0000000000 --- a/gsk/vulkan/gskvulkancolortextpipelineprivate.h +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -#include - -#include "gskvulkanpipelineprivate.h" -#include "gskvulkanrendererprivate.h" - -G_BEGIN_DECLS - -typedef struct _GskVulkanColorTextPipelineLayout GskVulkanColorTextPipelineLayout; - -#define GSK_TYPE_VULKAN_COLOR_TEXT_PIPELINE (gsk_vulkan_color_text_pipeline_get_type ()) - -G_DECLARE_FINAL_TYPE (GskVulkanColorTextPipeline, gsk_vulkan_color_text_pipeline, GSK, VULKAN_COLOR_TEXT_PIPELINE, GskVulkanPipeline) - -GskVulkanPipeline * gsk_vulkan_color_text_pipeline_new (GdkVulkanContext *context, - VkPipelineLayout layout, - const char *shader_name, - VkRenderPass render_pass); - -void gsk_vulkan_color_text_pipeline_collect_vertex_data (GskVulkanColorTextPipeline *pipeline, - guchar *data, - GskVulkanRenderer *renderer, - const graphene_rect_t *rect, - guint tex_id, - PangoFont *font, - guint total_glyphs, - const PangoGlyphInfo *glyphs, - const graphene_point_t *offset, - guint start_glyph, - guint num_glyphs, - float scale); -gsize gsk_vulkan_color_text_pipeline_draw (GskVulkanColorTextPipeline *pipeline, - VkCommandBuffer command_buffer, - gsize offset, - gsize n_commands); - -G_END_DECLS - diff --git a/gsk/vulkan/gskvulkanglyphcache.c b/gsk/vulkan/gskvulkanglyphcache.c index e2e00912b2..1b5b916f11 100644 --- a/gsk/vulkan/gskvulkanglyphcache.c +++ b/gsk/vulkan/gskvulkanglyphcache.c @@ -73,6 +73,8 @@ create_atlas (GskVulkanGlyphCache *cache) atlas->num_glyphs = 0; atlas->dirty_glyphs = NULL; + atlas->image = gsk_vulkan_image_new_for_atlas (cache->vulkan, atlas->width, atlas->height); + return atlas; } @@ -217,6 +219,7 @@ add_to_cache (GskVulkanGlyphCache *cache, g_ptr_array_add (cache->atlases, atlas); } + value->atlas_image = atlas->image; value->atlas_x = atlas->x; value->atlas_y = atlas->y0; @@ -225,8 +228,6 @@ add_to_cache (GskVulkanGlyphCache *cache, value->tw = (float)width / atlas->width; value->th = (float)height / atlas->height; - value->texture_index = i; - dirty = g_new (DirtyGlyph, 1); dirty->key = key; dirty->value = value; @@ -238,7 +239,7 @@ add_to_cache (GskVulkanGlyphCache *cache, atlas->num_glyphs++; #ifdef G_ENABLE_DEBUG - if (GSK_RENDERER_DEBUG_CHECK (cache->renderer, GLYPH_CACHE)) + if (GSK_DEBUG_CHECK (GLYPH_CACHE)) { g_print ("Glyph cache:\n"); for (i = 0; i < cache->atlases->len; i++) @@ -322,8 +323,7 @@ upload_dirty_glyphs (GskVulkanGlyphCache *cache, for (l = atlas->dirty_glyphs, i = 0; l; l = l->next, i++) render_glyph (atlas, (DirtyGlyph *)l->data, ®ions[i]); - GSK_RENDERER_DEBUG (cache->renderer, GLYPH_CACHE, - "uploading %d glyphs to cache", num_regions); + GSK_DEBUG (GLYPH_CACHE, "uploading %d glyphs to cache", num_regions); gsk_vulkan_image_upload_regions (atlas->image, uploader, num_regions, regions); @@ -332,13 +332,11 @@ upload_dirty_glyphs (GskVulkanGlyphCache *cache, } GskVulkanGlyphCache * -gsk_vulkan_glyph_cache_new (GskRenderer *renderer, - GdkVulkanContext *vulkan) +gsk_vulkan_glyph_cache_new (GdkVulkanContext *vulkan) { GskVulkanGlyphCache *cache; cache = GSK_VULKAN_GLYPH_CACHE (g_object_new (GSK_TYPE_VULKAN_GLYPH_CACHE, NULL)); - cache->renderer = renderer; cache->vulkan = vulkan; g_ptr_array_add (cache->atlases, create_atlas (cache)); @@ -420,24 +418,20 @@ gsk_vulkan_glyph_cache_lookup (GskVulkanGlyphCache *cache, return value; } -GskVulkanImage * -gsk_vulkan_glyph_cache_get_glyph_image (GskVulkanGlyphCache *cache, - GskVulkanUploader *uploader, - guint index) +void +gsk_vulkan_glyph_cache_upload (GskVulkanGlyphCache *cache, + GskVulkanUploader *uploader) { Atlas *atlas; + guint i; - g_return_val_if_fail (index < cache->atlases->len, NULL); - - atlas = g_ptr_array_index (cache->atlases, index); - - if (atlas->image == NULL) - atlas->image = gsk_vulkan_image_new_for_atlas (cache->vulkan, atlas->width, atlas->height); - - if (atlas->dirty_glyphs) - upload_dirty_glyphs (cache, atlas, uploader); + for (i = 0; i < cache->atlases->len; i++) + { + atlas = g_ptr_array_index (cache->atlases, i); - return atlas->image; + if (atlas->dirty_glyphs) + upload_dirty_glyphs (cache, atlas, uploader); + } } void @@ -489,9 +483,9 @@ gsk_vulkan_glyph_cache_begin_frame (GskVulkanGlyphCache *cache) if (atlas->old_pixels > MAX_OLD * atlas->width * atlas->height) { - GSK_RENDERER_DEBUG (cache->renderer, GLYPH_CACHE, - "Dropping atlas %d (%g.2%% old)", - i, 100.0 * (double)atlas->old_pixels / (double)(atlas->width * atlas->height)); + GSK_DEBUG (GLYPH_CACHE, + "Dropping atlas %d (%g.2%% old)", + i, 100.0 * (double)atlas->old_pixels / (double)(atlas->width * atlas->height)); g_ptr_array_remove_index (cache->atlases, i); drops[i] = 1; @@ -520,5 +514,5 @@ gsk_vulkan_glyph_cache_begin_frame (GskVulkanGlyphCache *cache) } } - GSK_RENDERER_DEBUG (cache->renderer, GLYPH_CACHE, "Dropped %d glyphs", dropped); + GSK_DEBUG (GLYPH_CACHE, "Dropped %d glyphs", dropped); } diff --git a/gsk/vulkan/gskvulkanglyphcacheprivate.h b/gsk/vulkan/gskvulkanglyphcacheprivate.h index e7520937b7..4d845a6295 100644 --- a/gsk/vulkan/gskvulkanglyphcacheprivate.h +++ b/gsk/vulkan/gskvulkanglyphcacheprivate.h @@ -1,7 +1,6 @@ #pragma once #include -#include "gskvulkanrendererprivate.h" #include "gskvulkanimageprivate.h" G_BEGIN_DECLS @@ -10,12 +9,31 @@ G_BEGIN_DECLS G_DECLARE_FINAL_TYPE(GskVulkanGlyphCache, gsk_vulkan_glyph_cache, GSK, VULKAN_GLYPH_CACHE, GObject) -GskVulkanGlyphCache *gsk_vulkan_glyph_cache_new (GskRenderer *renderer, - GdkVulkanContext *vulkan); +typedef struct +{ + guint texture_index; -GskVulkanImage * gsk_vulkan_glyph_cache_get_glyph_image (GskVulkanGlyphCache *cache, - GskVulkanUploader *uploader, - guint index); + float tx; + float ty; + float tw; + float th; + + int draw_x; + int draw_y; + int draw_width; + int draw_height; + + GskVulkanImage *atlas_image; + int atlas_x; + int atlas_y; + + guint64 timestamp; +} GskVulkanCachedGlyph; + +GskVulkanGlyphCache *gsk_vulkan_glyph_cache_new (GdkVulkanContext *vulkan); + +void gsk_vulkan_glyph_cache_upload (GskVulkanGlyphCache *cache, + GskVulkanUploader *uploader); GskVulkanCachedGlyph *gsk_vulkan_glyph_cache_lookup (GskVulkanGlyphCache *cache, gboolean create, diff --git a/gsk/vulkan/gskvulkanrender.c b/gsk/vulkan/gskvulkanrender.c index e39d0122bd..9c414db029 100644 --- a/gsk/vulkan/gskvulkanrender.c +++ b/gsk/vulkan/gskvulkanrender.c @@ -7,11 +7,11 @@ #include "gskrendererprivate.h" #include "gskvulkanbufferprivate.h" #include "gskvulkancommandpoolprivate.h" +#include "gskvulkanglyphcacheprivate.h" #include "gskvulkanpipelineprivate.h" +#include "gskvulkanrendererprivate.h" #include "gskvulkanrenderpassprivate.h" -#include "gskvulkancolortextpipelineprivate.h" -#include "gskvulkantextpipelineprivate.h" #include "gskvulkanpushconstantsprivate.h" #include "gdk/gdkvulkancontextprivate.h" @@ -55,7 +55,6 @@ struct _GskVulkanRender GskDescriptorBufferInfos descriptor_buffers; VkDescriptorPool descriptor_pool; VkDescriptorSet descriptor_sets[N_DESCRIPTOR_SETS]; - GskVulkanPipeline *pipelines[GSK_VULKAN_N_PIPELINES]; GHashTable *pipeline_cache; GskVulkanImage *target; @@ -354,6 +353,9 @@ gsk_vulkan_render_upload (GskVulkanRender *self) { GList *l; + gsk_vulkan_glyph_cache_upload (gsk_vulkan_renderer_get_glyph_cache (GSK_VULKAN_RENDERER (self->renderer)), + self->uploader); + /* gsk_vulkan_render_pass_upload may call gsk_vulkan_render_add_node_for_texture, * prepending new render passes to the list. Therefore, we walk the list from * the end. @@ -486,35 +488,6 @@ gsk_vulkan_render_create_pipeline (GskVulkanRender *s return pipeline; } -GskVulkanPipeline * -gsk_vulkan_render_get_pipeline (GskVulkanRender *self, - GskVulkanPipelineType type, - VkRenderPass render_pass) -{ - static const struct { - const char *name; - guint num_textures; - GskVulkanPipeline * (* create_func) (GdkVulkanContext *context, VkPipelineLayout layout, const char *name, VkRenderPass render_pass); - } pipeline_info[GSK_VULKAN_N_PIPELINES] = { - { "mask", 1, gsk_vulkan_text_pipeline_new }, - { "mask-clip", 1, gsk_vulkan_text_pipeline_new }, - { "mask-clip-rounded", 1, gsk_vulkan_text_pipeline_new }, - { "texture", 1, gsk_vulkan_color_text_pipeline_new }, - { "texture-clip", 1, gsk_vulkan_color_text_pipeline_new }, - { "texture-clip-rounded", 1, gsk_vulkan_color_text_pipeline_new }, - }; - - g_return_val_if_fail (type < GSK_VULKAN_N_PIPELINES, NULL); - - if (self->pipelines[type] == NULL) - self->pipelines[type] = pipeline_info[type].create_func (self->vulkan, - self->pipeline_layout, - pipeline_info[type].name, - render_pass); - - return self->pipelines[type]; -} - void gsk_vulkan_render_bind_descriptor_sets (GskVulkanRender *self, VkCommandBuffer command_buffer) @@ -821,9 +794,6 @@ gsk_vulkan_render_free (GskVulkanRender *self) } g_hash_table_unref (self->pipeline_cache); - for (i = 0; i < GSK_VULKAN_N_PIPELINES; i++) - g_clear_object (&self->pipelines[i]); - g_clear_pointer (&self->uploader, gsk_vulkan_uploader_free); diff --git a/gsk/vulkan/gskvulkanrenderer.c b/gsk/vulkan/gskvulkanrenderer.c index 1de96bbfad..e7dac98bb5 100644 --- a/gsk/vulkan/gskvulkanrenderer.c +++ b/gsk/vulkan/gskvulkanrenderer.c @@ -222,7 +222,7 @@ gsk_vulkan_renderer_realize (GskRenderer *renderer, self); gsk_vulkan_renderer_update_images_cb (self->vulkan, self); - self->glyph_cache = gsk_vulkan_glyph_cache_new (renderer, self->vulkan); + self->glyph_cache = gsk_vulkan_glyph_cache_new (self->vulkan); return TRUE; } @@ -477,15 +477,13 @@ gsk_vulkan_renderer_ref_texture_image (GskVulkanRenderer *self, return image; } -GskVulkanImage * -gsk_vulkan_renderer_ref_glyph_image (GskVulkanRenderer *self, - GskVulkanUploader *uploader, - guint index) +GskVulkanGlyphCache * +gsk_vulkan_renderer_get_glyph_cache (GskVulkanRenderer *self) { - return g_object_ref (gsk_vulkan_glyph_cache_get_glyph_image (self->glyph_cache, uploader, index)); + return self->glyph_cache; } -guint +GskVulkanCachedGlyph * gsk_vulkan_renderer_cache_glyph (GskVulkanRenderer *self, PangoFont *font, PangoGlyph glyph, @@ -493,18 +491,7 @@ gsk_vulkan_renderer_cache_glyph (GskVulkanRenderer *self, int y, float scale) { - return gsk_vulkan_glyph_cache_lookup (self->glyph_cache, TRUE, font, glyph, x, y, scale)->texture_index; -} - -GskVulkanCachedGlyph * -gsk_vulkan_renderer_get_cached_glyph (GskVulkanRenderer *self, - PangoFont *font, - PangoGlyph glyph, - int x, - int y, - float scale) -{ - return gsk_vulkan_glyph_cache_lookup (self->glyph_cache, FALSE, font, glyph, x, y, scale); + return gsk_vulkan_glyph_cache_lookup (self->glyph_cache, TRUE, font, glyph, x, y, scale); } /** diff --git a/gsk/vulkan/gskvulkanrendererprivate.h b/gsk/vulkan/gskvulkanrendererprivate.h index fdebb49235..dc17f14e8a 100644 --- a/gsk/vulkan/gskvulkanrendererprivate.h +++ b/gsk/vulkan/gskvulkanrendererprivate.h @@ -1,6 +1,7 @@ #pragma once #include "gskvulkanrenderer.h" +#include "gskvulkanglyphcacheprivate.h" #include "gskvulkanimageprivate.h" G_BEGIN_DECLS @@ -14,43 +15,14 @@ GskVulkanImage * gsk_vulkan_renderer_ref_texture_image (GskVulk GdkTexture *texture, GskVulkanUploader *uploader); -typedef struct -{ - guint texture_index; - - float tx; - float ty; - float tw; - float th; - - int draw_x; - int draw_y; - int draw_width; - int draw_height; - - int atlas_x; - int atlas_y; - - guint64 timestamp; -} GskVulkanCachedGlyph; - -guint gsk_vulkan_renderer_cache_glyph (GskVulkanRenderer *renderer, +GskVulkanCachedGlyph *gsk_vulkan_renderer_cache_glyph (GskVulkanRenderer *renderer, PangoFont *font, PangoGlyph glyph, int x, int y, float scale); -GskVulkanImage * gsk_vulkan_renderer_ref_glyph_image (GskVulkanRenderer *self, - GskVulkanUploader *uploader, - guint index); - -GskVulkanCachedGlyph * gsk_vulkan_renderer_get_cached_glyph (GskVulkanRenderer *self, - PangoFont *font, - PangoGlyph glyph, - int x, - int y, - float scale); +GskVulkanGlyphCache * gsk_vulkan_renderer_get_glyph_cache (GskVulkanRenderer *self); G_END_DECLS diff --git a/gsk/vulkan/gskvulkanrenderpass.c b/gsk/vulkan/gskvulkanrenderpass.c index 4a33d21fd2..74437c1363 100644 --- a/gsk/vulkan/gskvulkanrenderpass.c +++ b/gsk/vulkan/gskvulkanrenderpass.c @@ -15,14 +15,12 @@ #include "gskvulkanclipprivate.h" #include "gskvulkancolormatrixopprivate.h" #include "gskvulkancoloropprivate.h" -#include "gskvulkancolortextpipelineprivate.h" #include "gskvulkancrossfadeopprivate.h" #include "gskvulkanglyphopprivate.h" #include "gskvulkaninsetshadowopprivate.h" #include "gskvulkanlineargradientopprivate.h" #include "gskvulkanopprivate.h" #include "gskvulkanrendererprivate.h" -#include "gskvulkantextpipelineprivate.h" #include "gskvulkanimageprivate.h" #include "gskvulkanoffscreenopprivate.h" #include "gskvulkanoutsetshadowopprivate.h" @@ -48,33 +46,13 @@ typedef struct _GskVulkanParseState GskVulkanParseState; typedef struct _GskVulkanOpAny GskVulkanOpAny; typedef union _GskVulkanOpAll GskVulkanOpAll; -typedef struct _GskVulkanOpText GskVulkanOpText; typedef struct _GskVulkanOpPushConstants GskVulkanOpPushConstants; typedef enum { - /* GskVulkanOpText */ - GSK_VULKAN_OP_TEXT, - GSK_VULKAN_OP_COLOR_TEXT, /* GskVulkanOpPushConstants */ GSK_VULKAN_OP_PUSH_VERTEX_CONSTANTS, } GskVulkanOpType; -struct _GskVulkanOpText -{ - GskVulkanOp base; - GskVulkanOpType type; - GskRenderNode *node; /* node that's the source of this op */ - graphene_point_t offset; /* offset of the node */ - GskVulkanPipeline *pipeline; /* pipeline to use */ - GskVulkanImage *source; /* source image to render */ - gsize vertex_offset; /* offset into vertex buffer */ - guint32 image_descriptor; /* index into descriptor for the (image, sampler) */ - guint texture_index; /* index of the texture in the glyph cache */ - guint start_glyph; /* the first glyph in nodes glyphstring that we render */ - guint num_glyphs; /* number of *non-empty* glyphs (== instances) we render */ - float scale; -}; - struct _GskVulkanOpPushConstants { GskVulkanOp base; @@ -95,7 +73,6 @@ struct _GskVulkanOpAny union _GskVulkanOpAll { GskVulkanOpAny any; - GskVulkanOpText text; GskVulkanOpPushConstants constants; }; @@ -320,16 +297,6 @@ gsk_vulkan_render_pass_append_push_constants (GskVulkanRenderPass *self, return FALSE; \ }G_STMT_END -static GskVulkanPipeline * -gsk_vulkan_render_pass_get_pipeline (GskVulkanRenderPass *self, - GskVulkanRender *render, - GskVulkanPipelineType pipeline_type) -{ - return gsk_vulkan_render_get_pipeline (render, - pipeline_type, - self->render_pass); -} - static GskVulkanImage * gsk_vulkan_render_pass_get_node_as_image (GskVulkanRenderPass *self, GskVulkanRender *render, @@ -1179,86 +1146,67 @@ gsk_vulkan_render_pass_add_text_node (GskVulkanRenderPass *self, const GskVulkanParseState *state, GskRenderNode *node) { - GskVulkanOpText op = { - .node = node, - .offset = state->offset, - }; - GskVulkanPipelineType pipeline_type; const PangoGlyphInfo *glyphs; GskVulkanRenderer *renderer; + const graphene_point_t *node_offset; const PangoFont *font; - guint texture_index; guint num_glyphs; - guint count; int x_position; int i; + float scale; renderer = GSK_VULKAN_RENDERER (gsk_vulkan_render_get_renderer (render)); num_glyphs = gsk_text_node_get_num_glyphs (node); glyphs = gsk_text_node_get_glyphs (node, NULL); font = gsk_text_node_get_font (node); - if (gsk_text_node_has_color_glyphs (node)) - { - if (gsk_vulkan_clip_contains_rect (&state->clip, &state->offset, &node->bounds)) - pipeline_type = GSK_VULKAN_PIPELINE_COLOR_TEXT; - else if (state->clip.type == GSK_VULKAN_CLIP_RECT) - pipeline_type = GSK_VULKAN_PIPELINE_COLOR_TEXT_CLIP; - else - pipeline_type = GSK_VULKAN_PIPELINE_COLOR_TEXT_CLIP_ROUNDED; - op.type = GSK_VULKAN_OP_COLOR_TEXT; - } - else - { - if (gsk_vulkan_clip_contains_rect (&state->clip, &state->offset, &node->bounds)) - pipeline_type = GSK_VULKAN_PIPELINE_TEXT; - else if (state->clip.type == GSK_VULKAN_CLIP_RECT) - pipeline_type = GSK_VULKAN_PIPELINE_TEXT_CLIP; - else - pipeline_type = GSK_VULKAN_PIPELINE_TEXT_CLIP_ROUNDED; - op.type = GSK_VULKAN_OP_TEXT; - } - op.pipeline = gsk_vulkan_render_pass_get_pipeline (self, render, pipeline_type); - op.start_glyph = 0; - op.texture_index = G_MAXUINT; - op.scale = MAX (graphene_vec2_get_x (&state->scale), graphene_vec2_get_y (&state->scale)); + scale = MAX (graphene_vec2_get_x (&state->scale), graphene_vec2_get_y (&state->scale)); + node_offset = gsk_text_node_get_offset (node); x_position = 0; - for (i = 0, count = 0; i < num_glyphs; i++) + for (i = 0; i < num_glyphs; i++) { + GskVulkanCachedGlyph *glyph; const PangoGlyphInfo *gi = &glyphs[i]; - - texture_index = gsk_vulkan_renderer_cache_glyph (renderer, - (PangoFont *)font, - gi->glyph, - x_position + gi->geometry.x_offset, - gi->geometry.y_offset, - op.scale); - if (op.texture_index == G_MAXUINT) - op.texture_index = texture_index; - if (texture_index != op.texture_index) - { - op.num_glyphs = count; - - gsk_vulkan_render_pass_add_op (self, (GskVulkanOp *) &op); - - count = 1; - op.start_glyph = i; - op.texture_index = texture_index; - } + graphene_rect_t glyph_bounds, glyph_tex_rect; + + glyph = gsk_vulkan_renderer_cache_glyph (renderer, + (PangoFont *)font, + gi->glyph, + x_position + gi->geometry.x_offset, + gi->geometry.y_offset, + scale); + + glyph_bounds = GRAPHENE_RECT_INIT (glyph->draw_x + node_offset->x + (float) (x_position + gi->geometry.x_offset) / PANGO_SCALE, + glyph->draw_y + node_offset->y + (float) (gi->geometry.y_offset) / PANGO_SCALE, + glyph->draw_width, + glyph->draw_height); + graphene_rect_init (&glyph_tex_rect, + glyph_bounds.origin.x - glyph->draw_width * glyph->tx / glyph->tw, + glyph_bounds.origin.y - glyph->draw_height * glyph->ty / glyph->th, + glyph->draw_width / glyph->tw, + glyph->draw_height / glyph->th); + if (gsk_text_node_has_color_glyphs (node)) + gsk_vulkan_texture_op (self, + gsk_vulkan_clip_get_clip_type (&state->clip, &state->offset, &glyph_bounds), + glyph->atlas_image, + GSK_VULKAN_SAMPLER_DEFAULT, + &glyph_bounds, + &state->offset, + &glyph_tex_rect); else - count++; + gsk_vulkan_glyph_op (self, + gsk_vulkan_clip_get_clip_type (&state->clip, &state->offset, &glyph_bounds), + glyph->atlas_image, + &glyph_bounds, + &state->offset, + &glyph_tex_rect, + gsk_text_node_get_color (node)); x_position += gi->geometry.width; } - if (op.texture_index != G_MAXUINT && count != 0) - { - op.num_glyphs = count; - gsk_vulkan_render_pass_add_op (self, (GskVulkanOp *) &op); - } - return TRUE; } @@ -1490,16 +1438,6 @@ gsk_vulkan_render_op_upload (GskVulkanOp *op_, switch (op->any.type) { - case GSK_VULKAN_OP_TEXT: - case GSK_VULKAN_OP_COLOR_TEXT: - { - op->text.source = gsk_vulkan_renderer_ref_glyph_image (GSK_VULKAN_RENDERER (gsk_vulkan_render_get_renderer (render)), - uploader, - op->text.texture_index); - gsk_vulkan_render_add_cleanup_image (render, op->text.source); - } - break; - default: g_assert_not_reached (); case GSK_VULKAN_OP_PUSH_VERTEX_CONSTANTS: @@ -1530,18 +1468,9 @@ gsk_vulkan_render_op_count_vertex_data (GskVulkanOp *op_, gsize n_bytes) { GskVulkanOpAll *op = (GskVulkanOpAll *) op_; - gsize vertex_stride; switch (op->any.type) { - case GSK_VULKAN_OP_TEXT: - case GSK_VULKAN_OP_COLOR_TEXT: - vertex_stride = gsk_vulkan_pipeline_get_vertex_stride (op->text.pipeline); - n_bytes = round_up (n_bytes, vertex_stride); - op->text.vertex_offset = n_bytes; - n_bytes += vertex_stride * op->text.num_glyphs; - break; - default: g_assert_not_reached (); @@ -1578,43 +1507,6 @@ gsk_vulkan_render_op_collect_vertex_data (GskVulkanOp *op_, switch (op->any.type) { - case GSK_VULKAN_OP_TEXT: - gsk_vulkan_text_pipeline_collect_vertex_data (GSK_VULKAN_TEXT_PIPELINE (op->text.pipeline), - data + op->text.vertex_offset, - GSK_VULKAN_RENDERER (gsk_vulkan_render_get_renderer (render)), - &op->text.node->bounds, - op->text.image_descriptor, - (PangoFont *)gsk_text_node_get_font (op->text.node), - gsk_text_node_get_num_glyphs (op->text.node), - gsk_text_node_get_glyphs (op->text.node, NULL), - gsk_text_node_get_color (op->text.node), - &GRAPHENE_POINT_INIT ( - gsk_text_node_get_offset (op->text.node)->x + op->text.offset.x, - gsk_text_node_get_offset (op->text.node)->y + op->text.offset.y - ), - op->text.start_glyph, - op->text.num_glyphs, - op->text.scale); - break; - - case GSK_VULKAN_OP_COLOR_TEXT: - gsk_vulkan_color_text_pipeline_collect_vertex_data (GSK_VULKAN_COLOR_TEXT_PIPELINE (op->text.pipeline), - data + op->text.vertex_offset, - GSK_VULKAN_RENDERER (gsk_vulkan_render_get_renderer (render)), - &op->text.node->bounds, - op->text.image_descriptor, - (PangoFont *)gsk_text_node_get_font (op->text.node), - gsk_text_node_get_num_glyphs (op->text.node), - gsk_text_node_get_glyphs (op->text.node, NULL), - &GRAPHENE_POINT_INIT ( - gsk_text_node_get_offset (op->text.node)->x + op->text.offset.x, - gsk_text_node_get_offset (op->text.node)->y + op->text.offset.y - ), - op->text.start_glyph, - op->text.num_glyphs, - op->text.scale); - break; - default: g_assert_not_reached (); case GSK_VULKAN_OP_PUSH_VERTEX_CONSTANTS: @@ -1683,13 +1575,6 @@ gsk_vulkan_render_op_reserve_descriptor_sets (GskVulkanOp *op_, switch (op->any.type) { - case GSK_VULKAN_OP_TEXT: - case GSK_VULKAN_OP_COLOR_TEXT: - op->text.image_descriptor = gsk_vulkan_render_get_image_descriptor (render, - op->text.source, - GSK_VULKAN_SAMPLER_DEFAULT); - break; - default: g_assert_not_reached (); @@ -1756,10 +1641,6 @@ gsk_vulkan_render_op_get_pipeline (GskVulkanOp *op_) switch (op->any.type) { - case GSK_VULKAN_OP_TEXT: - case GSK_VULKAN_OP_COLOR_TEXT: - return gsk_vulkan_pipeline_get_pipeline (op->text.pipeline); - case GSK_VULKAN_OP_PUSH_VERTEX_CONSTANTS: return NULL; @@ -1779,20 +1660,6 @@ gsk_vulkan_render_op_command (GskVulkanOp *op_, switch (op->any.type) { - case GSK_VULKAN_OP_TEXT: - gsk_vulkan_text_pipeline_draw (GSK_VULKAN_TEXT_PIPELINE (op->text.pipeline), - command_buffer, - op->text.vertex_offset / gsk_vulkan_pipeline_get_vertex_stride (op->text.pipeline), - op->text.num_glyphs); - break; - - case GSK_VULKAN_OP_COLOR_TEXT: - gsk_vulkan_color_text_pipeline_draw (GSK_VULKAN_COLOR_TEXT_PIPELINE (op->text.pipeline), - command_buffer, - op->text.vertex_offset / gsk_vulkan_pipeline_get_vertex_stride (op->text.pipeline), - op->text.num_glyphs); - break; - case GSK_VULKAN_OP_PUSH_VERTEX_CONSTANTS: gsk_vulkan_push_constants_push (command_buffer, pipeline_layout, diff --git a/gsk/vulkan/gskvulkanrenderprivate.h b/gsk/vulkan/gskvulkanrenderprivate.h index 7e605a1933..41023d5ad8 100644 --- a/gsk/vulkan/gskvulkanrenderprivate.h +++ b/gsk/vulkan/gskvulkanrenderprivate.h @@ -10,17 +10,6 @@ G_BEGIN_DECLS -typedef enum { - GSK_VULKAN_PIPELINE_TEXT, - GSK_VULKAN_PIPELINE_TEXT_CLIP, - GSK_VULKAN_PIPELINE_TEXT_CLIP_ROUNDED, - GSK_VULKAN_PIPELINE_COLOR_TEXT, - GSK_VULKAN_PIPELINE_COLOR_TEXT_CLIP, - GSK_VULKAN_PIPELINE_COLOR_TEXT_CLIP_ROUNDED, - /* add more */ - GSK_VULKAN_N_PIPELINES -} GskVulkanPipelineType; - typedef enum { GSK_VULKAN_SAMPLER_DEFAULT, GSK_VULKAN_SAMPLER_REPEAT, @@ -56,9 +45,6 @@ VkPipeline gsk_vulkan_render_create_pipeline (GskVulk const VkPipelineVertexInputStateCreateInfo *vertex_input_state, VkFormat format, VkRenderPass render_pass); -GskVulkanPipeline * gsk_vulkan_render_get_pipeline (GskVulkanRender *self, - GskVulkanPipelineType pipeline_type, - VkRenderPass render_pass); gsize gsk_vulkan_render_get_image_descriptor (GskVulkanRender *self, GskVulkanImage *source, GskVulkanRenderSampler render_sampler); diff --git a/gsk/vulkan/gskvulkantextpipeline.c b/gsk/vulkan/gskvulkantextpipeline.c deleted file mode 100644 index 80b9200341..0000000000 --- a/gsk/vulkan/gskvulkantextpipeline.c +++ /dev/null @@ -1,127 +0,0 @@ -#include "config.h" - -#include "gskvulkantextpipelineprivate.h" - -#include "vulkan/resources/mask.vert.h" - -struct _GskVulkanTextPipeline -{ - GObject parent_instance; -}; - -G_DEFINE_TYPE (GskVulkanTextPipeline, gsk_vulkan_text_pipeline, GSK_TYPE_VULKAN_PIPELINE) - -static const VkPipelineVertexInputStateCreateInfo * -gsk_vulkan_text_pipeline_get_input_state_create_info (GskVulkanPipeline *self) -{ - return &gsk_vulkan_mask_info; -} - -static void -gsk_vulkan_text_pipeline_finalize (GObject *gobject) -{ - //GskVulkanTextPipeline *self = GSK_VULKAN_TEXT_PIPELINE (gobject); - - G_OBJECT_CLASS (gsk_vulkan_text_pipeline_parent_class)->finalize (gobject); -} - -static void -gsk_vulkan_text_pipeline_class_init (GskVulkanTextPipelineClass *klass) -{ - GskVulkanPipelineClass *pipeline_class = GSK_VULKAN_PIPELINE_CLASS (klass); - - G_OBJECT_CLASS (klass)->finalize = gsk_vulkan_text_pipeline_finalize; - - pipeline_class->get_input_state_create_info = gsk_vulkan_text_pipeline_get_input_state_create_info; -} - -static void -gsk_vulkan_text_pipeline_init (GskVulkanTextPipeline *self) -{ -} - -GskVulkanPipeline * -gsk_vulkan_text_pipeline_new (GdkVulkanContext *context, - VkPipelineLayout layout, - const char *shader_name, - VkRenderPass render_pass) -{ - return gsk_vulkan_pipeline_new (GSK_TYPE_VULKAN_TEXT_PIPELINE, context, layout, shader_name, render_pass); -} - -void -gsk_vulkan_text_pipeline_collect_vertex_data (GskVulkanTextPipeline *pipeline, - guchar *data, - GskVulkanRenderer *renderer, - const graphene_rect_t *rect, - guint tex_id, - PangoFont *font, - guint total_glyphs, - const PangoGlyphInfo *glyphs, - const GdkRGBA *color, - const graphene_point_t *offset, - guint start_glyph, - guint num_glyphs, - float scale) -{ - GskVulkanMaskInstance *instances = (GskVulkanMaskInstance *) data; - int i; - int count = 0; - int x_position = 0; - - for (i = 0; i < start_glyph; i++) - x_position += glyphs[i].geometry.width; - - for (; i < total_glyphs && count < num_glyphs; i++) - { - const PangoGlyphInfo *gi = &glyphs[i]; - - if (gi->glyph != PANGO_GLYPH_EMPTY) - { - double cx = (x_position + gi->geometry.x_offset) / PANGO_SCALE; - double cy = gi->geometry.y_offset / PANGO_SCALE; - GskVulkanMaskInstance *instance = &instances[count]; - GskVulkanCachedGlyph *glyph; - - glyph = gsk_vulkan_renderer_get_cached_glyph (renderer, - font, - gi->glyph, - x_position + gi->geometry.x_offset, - gi->geometry.y_offset, - scale); - - instance->rect[0] = offset->x + cx + glyph->draw_x; - instance->rect[1] = offset->y + cy + glyph->draw_y; - instance->rect[2] = glyph->draw_width; - instance->rect[3] = glyph->draw_height; - - instance->tex_rect[0] = glyph->tx; - instance->tex_rect[1] = glyph->ty; - instance->tex_rect[2] = glyph->tw; - instance->tex_rect[3] = glyph->th; - - instance->color[0] = color->red; - instance->color[1] = color->green; - instance->color[2] = color->blue; - instance->color[3] = color->alpha; - - instance->tex_id = tex_id; - - count++; - } - x_position += gi->geometry.width; - } -} - -gsize -gsk_vulkan_text_pipeline_draw (GskVulkanTextPipeline *pipeline, - VkCommandBuffer command_buffer, - gsize offset, - gsize n_commands) -{ - vkCmdDraw (command_buffer, - 6, n_commands, - 0, offset); - - return n_commands; -} diff --git a/gsk/vulkan/gskvulkantextpipelineprivate.h b/gsk/vulkan/gskvulkantextpipelineprivate.h deleted file mode 100644 index 8f05e43500..0000000000 --- a/gsk/vulkan/gskvulkantextpipelineprivate.h +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once - -#include - -#include "gskvulkanpipelineprivate.h" -#include "gskvulkanrendererprivate.h" - -G_BEGIN_DECLS - -typedef struct _GskVulkanTextPipelineLayout GskVulkanTextPipelineLayout; - -#define GSK_TYPE_VULKAN_TEXT_PIPELINE (gsk_vulkan_text_pipeline_get_type ()) - -G_DECLARE_FINAL_TYPE (GskVulkanTextPipeline, gsk_vulkan_text_pipeline, GSK, VULKAN_TEXT_PIPELINE, GskVulkanPipeline) - -GskVulkanPipeline * gsk_vulkan_text_pipeline_new (GdkVulkanContext *context, - VkPipelineLayout layout, - const char *shader_name, - VkRenderPass render_pass); - -void gsk_vulkan_text_pipeline_collect_vertex_data (GskVulkanTextPipeline *pipeline, - guchar *data, - GskVulkanRenderer *renderer, - const graphene_rect_t *rect, - guint32 tex_id, - PangoFont *font, - guint total_glyphs, - const PangoGlyphInfo *glyphs, - const GdkRGBA *color, - const graphene_point_t *offset, - guint start_glyph, - guint num_glyphs, - float scale); -gsize gsk_vulkan_text_pipeline_draw (GskVulkanTextPipeline *pipeline, - VkCommandBuffer command_buffer, - gsize offset, - gsize n_commands); - -G_END_DECLS -