2016-11-29 15:33:14 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gskvulkanrendererprivate.h"
|
|
|
|
|
|
|
|
#include "gskdebugprivate.h"
|
2016-12-05 01:50:06 +00:00
|
|
|
#include "gskprivate.h"
|
2016-11-29 15:33:14 +00:00
|
|
|
#include "gskrendererprivate.h"
|
|
|
|
#include "gskrendernodeprivate.h"
|
2016-12-05 01:50:06 +00:00
|
|
|
#include "gskvulkanbufferprivate.h"
|
2016-12-06 13:42:46 +00:00
|
|
|
#include "gskvulkanimageprivate.h"
|
2023-07-03 13:57:30 +00:00
|
|
|
#include "gskvulkanprivate.h"
|
2016-12-07 13:50:52 +00:00
|
|
|
#include "gskvulkanrenderprivate.h"
|
2017-09-19 23:32:04 +00:00
|
|
|
#include "gskvulkanglyphcacheprivate.h"
|
2016-11-29 15:33:14 +00:00
|
|
|
|
2023-06-14 08:18:47 +00:00
|
|
|
#include "gdk/gdkdisplayprivate.h"
|
2023-06-18 12:00:39 +00:00
|
|
|
#include "gdk/gdkdrawcontextprivate.h"
|
2018-05-19 19:35:02 +00:00
|
|
|
#include "gdk/gdkprofilerprivate.h"
|
2023-06-20 14:35:55 +00:00
|
|
|
#include "gdk/gdktextureprivate.h"
|
|
|
|
#include "gdk/gdkvulkancontextprivate.h"
|
2017-11-02 20:39:00 +00:00
|
|
|
|
2016-12-07 00:48:31 +00:00
|
|
|
#include <graphene.h>
|
|
|
|
|
2023-05-24 14:55:18 +00:00
|
|
|
#define GSK_VULKAN_MAX_RENDERS 4
|
|
|
|
|
2016-12-09 06:23:04 +00:00
|
|
|
typedef struct _GskVulkanTextureData GskVulkanTextureData;
|
|
|
|
|
|
|
|
struct _GskVulkanTextureData {
|
2017-11-02 20:39:00 +00:00
|
|
|
GdkTexture *texture;
|
2016-12-09 06:23:04 +00:00
|
|
|
GskVulkanImage *image;
|
|
|
|
GskVulkanRenderer *renderer;
|
|
|
|
};
|
|
|
|
|
2016-11-29 15:33:14 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
2017-09-25 22:37:22 +00:00
|
|
|
typedef struct {
|
|
|
|
GQuark frames;
|
2017-09-28 12:29:14 +00:00
|
|
|
GQuark render_passes;
|
2017-09-26 01:02:21 +00:00
|
|
|
GQuark fallback_pixels;
|
2017-09-30 14:39:04 +00:00
|
|
|
GQuark texture_pixels;
|
2017-09-25 22:37:22 +00:00
|
|
|
} ProfileCounters;
|
|
|
|
|
2016-11-29 15:33:14 +00:00
|
|
|
typedef struct {
|
|
|
|
GQuark cpu_time;
|
|
|
|
GQuark gpu_time;
|
|
|
|
} ProfileTimers;
|
|
|
|
|
2018-05-19 19:35:02 +00:00
|
|
|
static guint texture_pixels_counter;
|
|
|
|
static guint fallback_pixels_counter;
|
2020-01-29 13:03:56 +00:00
|
|
|
#endif
|
2018-05-19 19:35:02 +00:00
|
|
|
|
2016-11-29 15:33:14 +00:00
|
|
|
struct _GskVulkanRenderer
|
|
|
|
{
|
|
|
|
GskRenderer parent_instance;
|
|
|
|
|
|
|
|
GdkVulkanContext *vulkan;
|
2016-11-30 01:08:17 +00:00
|
|
|
|
|
|
|
guint n_targets;
|
2016-12-08 21:35:16 +00:00
|
|
|
GskVulkanImage **targets;
|
2016-11-30 02:59:28 +00:00
|
|
|
|
2023-05-24 14:55:18 +00:00
|
|
|
GskVulkanRender *renders[GSK_VULKAN_MAX_RENDERS];
|
2016-12-08 17:40:35 +00:00
|
|
|
|
2016-12-09 06:23:04 +00:00
|
|
|
GSList *textures;
|
|
|
|
|
2017-09-19 23:32:04 +00:00
|
|
|
GskVulkanGlyphCache *glyph_cache;
|
2017-09-01 20:58:42 +00:00
|
|
|
|
2016-11-29 15:33:14 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
2017-09-25 22:37:22 +00:00
|
|
|
ProfileCounters profile_counters;
|
2016-11-29 15:33:14 +00:00
|
|
|
ProfileTimers profile_timers;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _GskVulkanRendererClass
|
|
|
|
{
|
|
|
|
GskRendererClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GskVulkanRenderer, gsk_vulkan_renderer, GSK_TYPE_RENDERER)
|
|
|
|
|
2023-04-02 22:18:24 +00:00
|
|
|
static cairo_region_t *
|
|
|
|
get_render_region (GskVulkanRenderer *self)
|
|
|
|
{
|
|
|
|
const cairo_region_t *damage;
|
|
|
|
cairo_region_t *render_region;
|
|
|
|
cairo_region_t *scaled_damage;
|
|
|
|
GdkRectangle whole_surface;
|
|
|
|
GdkRectangle extents;
|
|
|
|
GdkSurface *surface;
|
2023-04-03 13:39:25 +00:00
|
|
|
double scale;
|
2023-04-02 22:18:24 +00:00
|
|
|
|
|
|
|
render_region = NULL;
|
|
|
|
surface = gdk_draw_context_get_surface (GDK_DRAW_CONTEXT (self->vulkan));
|
2023-04-03 13:39:25 +00:00
|
|
|
scale = gdk_surface_get_scale (surface);
|
2023-04-02 22:18:24 +00:00
|
|
|
|
|
|
|
whole_surface.x = 0;
|
|
|
|
whole_surface.y = 0;
|
|
|
|
whole_surface.width = gdk_surface_get_width (surface);
|
|
|
|
whole_surface.height = gdk_surface_get_height (surface);
|
|
|
|
|
|
|
|
damage = gdk_draw_context_get_frame_region (GDK_DRAW_CONTEXT (self->vulkan));
|
|
|
|
scaled_damage = cairo_region_create ();
|
|
|
|
for (int i = 0; i < cairo_region_num_rectangles (damage); i++)
|
|
|
|
{
|
|
|
|
cairo_rectangle_int_t rect;
|
|
|
|
cairo_region_get_rectangle (damage, i, &rect);
|
|
|
|
cairo_region_union_rectangle (scaled_damage, &(cairo_rectangle_int_t) {
|
2023-04-03 13:39:25 +00:00
|
|
|
.x = (int) floor (rect.x * scale),
|
|
|
|
.y = (int) floor (rect.y * scale),
|
|
|
|
.width = (int) ceil ((rect.x + rect.width) * scale) - floor (rect.x * scale),
|
|
|
|
.height = (int) ceil ((rect.y + rect.height) * scale) - floor (rect.y * scale),
|
2023-04-02 22:18:24 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cairo_region_contains_rectangle (scaled_damage, &whole_surface) == CAIRO_REGION_OVERLAP_IN)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
cairo_region_get_extents (scaled_damage, &extents);
|
|
|
|
if (gdk_rectangle_equal (&extents, &whole_surface))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
render_region = cairo_region_create_rectangle (&extents);
|
|
|
|
|
|
|
|
out:
|
|
|
|
g_clear_pointer (&scaled_damage, cairo_region_destroy);
|
|
|
|
|
|
|
|
return g_steal_pointer (&render_region);
|
|
|
|
}
|
|
|
|
|
2016-11-30 01:08:17 +00:00
|
|
|
static void
|
|
|
|
gsk_vulkan_renderer_free_targets (GskVulkanRenderer *self)
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < self->n_targets; i++)
|
|
|
|
{
|
2016-12-08 21:35:16 +00:00
|
|
|
g_object_unref (self->targets[i]);
|
2016-11-30 01:08:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_clear_pointer (&self->targets, g_free);
|
|
|
|
self->n_targets = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_vulkan_renderer_update_images_cb (GdkVulkanContext *context,
|
|
|
|
GskVulkanRenderer *self)
|
|
|
|
{
|
2023-06-14 08:18:47 +00:00
|
|
|
GdkSurface *surface;
|
2023-04-03 13:39:25 +00:00
|
|
|
double scale;
|
2016-12-08 20:14:41 +00:00
|
|
|
gsize width, height;
|
2016-11-30 01:08:17 +00:00
|
|
|
guint i;
|
|
|
|
|
2023-06-14 08:18:47 +00:00
|
|
|
surface = gsk_renderer_get_surface (GSK_RENDERER (self));
|
|
|
|
if (surface == NULL)
|
|
|
|
return;
|
|
|
|
|
2016-11-30 01:08:17 +00:00
|
|
|
gsk_vulkan_renderer_free_targets (self);
|
|
|
|
|
|
|
|
self->n_targets = gdk_vulkan_context_get_n_images (context);
|
2016-12-08 21:35:16 +00:00
|
|
|
self->targets = g_new (GskVulkanImage *, self->n_targets);
|
2016-11-30 01:08:17 +00:00
|
|
|
|
2023-06-14 08:18:47 +00:00
|
|
|
scale = gdk_surface_get_scale (surface);
|
|
|
|
width = (int) ceil (gdk_surface_get_width (surface) * scale);
|
|
|
|
height = (int) ceil (gdk_surface_get_height (surface) * scale);
|
2016-12-08 20:14:41 +00:00
|
|
|
|
2016-11-30 01:08:17 +00:00
|
|
|
for (i = 0; i < self->n_targets; i++)
|
|
|
|
{
|
2016-12-08 21:35:16 +00:00
|
|
|
self->targets[i] = gsk_vulkan_image_new_for_swapchain (self->vulkan,
|
|
|
|
gdk_vulkan_context_get_image (context, i),
|
|
|
|
gdk_vulkan_context_get_image_format (self->vulkan),
|
|
|
|
width, height);
|
2016-11-30 01:08:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-24 14:55:18 +00:00
|
|
|
static GskVulkanRender *
|
|
|
|
gsk_vulkan_renderer_get_render (GskVulkanRenderer *self)
|
|
|
|
{
|
|
|
|
VkFence fences[G_N_ELEMENTS (self->renders)];
|
|
|
|
VkDevice device;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
device = gdk_vulkan_context_get_device (self->vulkan);
|
|
|
|
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (self->renders); i++)
|
|
|
|
{
|
|
|
|
if (self->renders[i] == NULL)
|
|
|
|
{
|
|
|
|
self->renders[i] = gsk_vulkan_render_new (GSK_RENDERER (self), self->vulkan);
|
|
|
|
return self->renders[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
fences[i] = gsk_vulkan_render_get_fence (self->renders[i]);
|
|
|
|
if (vkGetFenceStatus (device, fences[i]) == VK_SUCCESS)
|
|
|
|
return self->renders[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
GSK_VK_CHECK (vkWaitForFences, device,
|
|
|
|
G_N_ELEMENTS (fences),
|
|
|
|
fences,
|
|
|
|
VK_FALSE,
|
|
|
|
INT64_MAX);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-29 15:33:14 +00:00
|
|
|
static gboolean
|
|
|
|
gsk_vulkan_renderer_realize (GskRenderer *renderer,
|
2021-10-20 18:30:08 +00:00
|
|
|
GdkSurface *surface,
|
2016-11-30 01:08:17 +00:00
|
|
|
GError **error)
|
2016-11-29 15:33:14 +00:00
|
|
|
{
|
|
|
|
GskVulkanRenderer *self = GSK_VULKAN_RENDERER (renderer);
|
|
|
|
|
2021-10-20 18:30:08 +00:00
|
|
|
if (surface == NULL)
|
2023-06-14 08:18:47 +00:00
|
|
|
self->vulkan = gdk_display_create_vulkan_context (gdk_display_get_default (), error);
|
|
|
|
else
|
|
|
|
self->vulkan = gdk_surface_create_vulkan_context (surface, error);
|
2021-10-20 18:30:08 +00:00
|
|
|
|
2016-11-29 15:33:14 +00:00
|
|
|
if (self->vulkan == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
2016-11-30 01:08:17 +00:00
|
|
|
g_signal_connect (self->vulkan,
|
|
|
|
"images-updated",
|
|
|
|
G_CALLBACK (gsk_vulkan_renderer_update_images_cb),
|
|
|
|
self);
|
|
|
|
gsk_vulkan_renderer_update_images_cb (self->vulkan, self);
|
|
|
|
|
2023-07-03 07:15:04 +00:00
|
|
|
self->glyph_cache = gsk_vulkan_glyph_cache_new (self->vulkan);
|
2017-09-11 01:55:22 +00:00
|
|
|
|
2016-11-29 15:33:14 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_vulkan_renderer_unrealize (GskRenderer *renderer)
|
|
|
|
{
|
|
|
|
GskVulkanRenderer *self = GSK_VULKAN_RENDERER (renderer);
|
2016-12-09 06:23:04 +00:00
|
|
|
GSList *l;
|
2023-05-24 14:55:18 +00:00
|
|
|
guint i;
|
2016-12-09 06:23:04 +00:00
|
|
|
|
2017-09-19 23:32:04 +00:00
|
|
|
g_clear_object (&self->glyph_cache);
|
2017-09-11 01:55:22 +00:00
|
|
|
|
2016-12-09 06:23:04 +00:00
|
|
|
for (l = self->textures; l; l = l->next)
|
|
|
|
{
|
|
|
|
GskVulkanTextureData *data = l->data;
|
|
|
|
|
|
|
|
data->renderer = NULL;
|
2017-11-02 20:39:00 +00:00
|
|
|
gdk_texture_clear_render_data (data->texture);
|
2016-12-09 06:23:04 +00:00
|
|
|
}
|
2018-07-28 17:53:48 +00:00
|
|
|
g_clear_pointer (&self->textures, g_slist_free);
|
2016-11-30 02:59:28 +00:00
|
|
|
|
2023-05-24 14:55:18 +00:00
|
|
|
for (i = 0; i < G_N_ELEMENTS (self->renders); i++)
|
|
|
|
g_clear_pointer (&self->renders[i], gsk_vulkan_render_free);
|
2016-12-08 17:40:35 +00:00
|
|
|
|
2016-11-30 01:08:17 +00:00
|
|
|
gsk_vulkan_renderer_free_targets (self);
|
|
|
|
g_signal_handlers_disconnect_by_func(self->vulkan,
|
|
|
|
gsk_vulkan_renderer_update_images_cb,
|
|
|
|
self);
|
2016-11-30 02:59:28 +00:00
|
|
|
|
2016-11-29 15:33:14 +00:00
|
|
|
g_clear_object (&self->vulkan);
|
|
|
|
}
|
|
|
|
|
2023-07-14 21:22:35 +00:00
|
|
|
static void
|
|
|
|
gsk_vulkan_renderer_download_texture_cb (gpointer user_data,
|
|
|
|
GdkMemoryFormat format,
|
|
|
|
const guchar *data,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
gsize stride)
|
|
|
|
{
|
|
|
|
GdkTexture **texture = (GdkTexture **) user_data;
|
|
|
|
GBytes *bytes;
|
|
|
|
|
|
|
|
bytes = g_bytes_new (data, stride * height);
|
|
|
|
*texture = gdk_memory_texture_new (width, height,
|
|
|
|
format,
|
|
|
|
bytes,
|
|
|
|
stride);
|
|
|
|
g_bytes_unref (bytes);
|
|
|
|
}
|
|
|
|
|
2017-11-02 20:39:00 +00:00
|
|
|
static GdkTexture *
|
2016-12-22 18:01:07 +00:00
|
|
|
gsk_vulkan_renderer_render_texture (GskRenderer *renderer,
|
|
|
|
GskRenderNode *root,
|
|
|
|
const graphene_rect_t *viewport)
|
|
|
|
{
|
|
|
|
GskVulkanRenderer *self = GSK_VULKAN_RENDERER (renderer);
|
|
|
|
GskVulkanRender *render;
|
|
|
|
GskVulkanImage *image;
|
2017-11-02 20:39:00 +00:00
|
|
|
GdkTexture *texture;
|
2023-05-05 07:29:47 +00:00
|
|
|
graphene_rect_t rounded_viewport;
|
2016-12-22 18:01:07 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
GskProfiler *profiler;
|
2020-08-19 22:49:34 +00:00
|
|
|
gint64 cpu_time;
|
|
|
|
gint64 start_time G_GNUC_UNUSED;
|
2016-12-22 18:01:07 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
profiler = gsk_renderer_get_profiler (renderer);
|
2017-09-26 01:02:21 +00:00
|
|
|
gsk_profiler_counter_set (profiler, self->profile_counters.fallback_pixels, 0);
|
2017-09-30 14:39:04 +00:00
|
|
|
gsk_profiler_counter_set (profiler, self->profile_counters.texture_pixels, 0);
|
2017-09-28 12:29:14 +00:00
|
|
|
gsk_profiler_counter_set (profiler, self->profile_counters.render_passes, 0);
|
2016-12-22 18:01:07 +00:00
|
|
|
gsk_profiler_timer_begin (profiler, self->profile_timers.cpu_time);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
render = gsk_vulkan_render_new (renderer, self->vulkan);
|
|
|
|
|
2023-05-05 07:29:47 +00:00
|
|
|
rounded_viewport = GRAPHENE_RECT_INIT (viewport->origin.x,
|
|
|
|
viewport->origin.y,
|
|
|
|
ceil (viewport->size.width),
|
|
|
|
ceil (viewport->size.height));
|
2023-06-14 19:20:56 +00:00
|
|
|
image = gsk_vulkan_image_new_for_offscreen (self->vulkan,
|
2023-06-20 14:35:55 +00:00
|
|
|
gdk_vulkan_context_get_offscreen_format (self->vulkan,
|
|
|
|
gsk_render_node_get_preferred_depth (root)),
|
2023-06-14 19:20:56 +00:00
|
|
|
rounded_viewport.size.width,
|
|
|
|
rounded_viewport.size.height);
|
2016-12-22 18:01:07 +00:00
|
|
|
|
2023-07-14 21:22:35 +00:00
|
|
|
texture = NULL;
|
|
|
|
gsk_vulkan_render_render (render,
|
|
|
|
image,
|
|
|
|
&rounded_viewport,
|
|
|
|
NULL,
|
|
|
|
root,
|
|
|
|
gsk_vulkan_renderer_download_texture_cb,
|
|
|
|
&texture);
|
2016-12-22 18:01:07 +00:00
|
|
|
|
|
|
|
gsk_vulkan_render_free (render);
|
2023-07-14 21:22:35 +00:00
|
|
|
g_object_unref (image);
|
|
|
|
|
|
|
|
/* check that callback setting texture was actually called, as its technically async */
|
|
|
|
g_assert (texture);
|
2016-12-22 18:01:07 +00:00
|
|
|
|
|
|
|
#ifdef G_ENABLE_DEBUG
|
2018-05-19 19:35:02 +00:00
|
|
|
start_time = gsk_profiler_timer_get_start (profiler, self->profile_timers.cpu_time);
|
2016-12-22 18:01:07 +00:00
|
|
|
cpu_time = gsk_profiler_timer_end (profiler, self->profile_timers.cpu_time);
|
|
|
|
gsk_profiler_timer_set (profiler, self->profile_timers.cpu_time, cpu_time);
|
|
|
|
|
|
|
|
gsk_profiler_push_samples (profiler);
|
2018-05-19 19:35:02 +00:00
|
|
|
|
2020-02-12 10:05:01 +00:00
|
|
|
if (GDK_PROFILER_IS_RUNNING)
|
2018-05-19 19:35:02 +00:00
|
|
|
{
|
2020-08-19 22:49:34 +00:00
|
|
|
gdk_profiler_add_mark (start_time * 1000, cpu_time * 1000, "render", "");
|
2018-05-19 19:35:02 +00:00
|
|
|
gdk_profiler_set_int_counter (texture_pixels_counter,
|
|
|
|
gsk_profiler_counter_get (profiler, self->profile_counters.texture_pixels));
|
|
|
|
gdk_profiler_set_int_counter (fallback_pixels_counter,
|
|
|
|
gsk_profiler_counter_get (profiler, self->profile_counters.fallback_pixels));
|
|
|
|
}
|
2016-12-22 18:01:07 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
|
2016-11-29 15:33:14 +00:00
|
|
|
static void
|
2018-03-28 13:01:34 +00:00
|
|
|
gsk_vulkan_renderer_render (GskRenderer *renderer,
|
|
|
|
GskRenderNode *root,
|
|
|
|
const cairo_region_t *region)
|
2016-11-29 15:33:14 +00:00
|
|
|
{
|
|
|
|
GskVulkanRenderer *self = GSK_VULKAN_RENDERER (renderer);
|
2016-12-08 16:46:08 +00:00
|
|
|
GskVulkanRender *render;
|
2023-04-02 22:18:24 +00:00
|
|
|
cairo_region_t *render_region;
|
2016-11-29 15:33:14 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
GskProfiler *profiler;
|
|
|
|
gint64 cpu_time;
|
|
|
|
#endif
|
2023-04-02 22:18:24 +00:00
|
|
|
uint32_t draw_index;
|
2016-11-29 15:33:14 +00:00
|
|
|
|
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
profiler = gsk_renderer_get_profiler (renderer);
|
2017-09-28 00:56:01 +00:00
|
|
|
gsk_profiler_counter_set (profiler, self->profile_counters.fallback_pixels, 0);
|
2017-09-30 14:39:04 +00:00
|
|
|
gsk_profiler_counter_set (profiler, self->profile_counters.texture_pixels, 0);
|
2017-09-28 12:29:14 +00:00
|
|
|
gsk_profiler_counter_set (profiler, self->profile_counters.render_passes, 0);
|
2016-11-29 15:33:14 +00:00
|
|
|
gsk_profiler_timer_begin (profiler, self->profile_timers.cpu_time);
|
|
|
|
#endif
|
|
|
|
|
2023-06-18 12:00:39 +00:00
|
|
|
gdk_draw_context_begin_frame_full (GDK_DRAW_CONTEXT (self->vulkan),
|
|
|
|
gsk_render_node_get_preferred_depth (root),
|
|
|
|
region);
|
2023-05-24 14:55:18 +00:00
|
|
|
render = gsk_vulkan_renderer_get_render (self);
|
2016-12-08 17:40:35 +00:00
|
|
|
|
2023-04-02 22:18:24 +00:00
|
|
|
render_region = get_render_region (self);
|
|
|
|
draw_index = gdk_vulkan_context_get_draw_index (self->vulkan);
|
2016-12-07 13:50:52 +00:00
|
|
|
|
2023-07-14 21:22:35 +00:00
|
|
|
gsk_vulkan_render_render (render,
|
|
|
|
self->targets[draw_index],
|
|
|
|
NULL,
|
|
|
|
render_region,
|
|
|
|
root,
|
|
|
|
NULL, NULL);
|
2016-12-05 01:50:06 +00:00
|
|
|
|
2016-11-29 15:33:14 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
2017-09-25 22:37:22 +00:00
|
|
|
gsk_profiler_counter_inc (profiler, self->profile_counters.frames);
|
|
|
|
|
2016-11-29 15:33:14 +00:00
|
|
|
cpu_time = gsk_profiler_timer_end (profiler, self->profile_timers.cpu_time);
|
|
|
|
gsk_profiler_timer_set (profiler, self->profile_timers.cpu_time, cpu_time);
|
|
|
|
|
|
|
|
gsk_profiler_push_samples (profiler);
|
|
|
|
#endif
|
2016-12-01 03:07:20 +00:00
|
|
|
|
2018-04-23 15:28:55 +00:00
|
|
|
gdk_draw_context_end_frame (GDK_DRAW_CONTEXT (self->vulkan));
|
2023-04-02 22:18:24 +00:00
|
|
|
|
|
|
|
g_clear_pointer (&render_region, cairo_region_destroy);
|
2016-12-01 03:07:20 +00:00
|
|
|
}
|
|
|
|
|
2016-11-29 15:33:14 +00:00
|
|
|
static void
|
|
|
|
gsk_vulkan_renderer_class_init (GskVulkanRendererClass *klass)
|
|
|
|
{
|
|
|
|
GskRendererClass *renderer_class = GSK_RENDERER_CLASS (klass);
|
|
|
|
|
|
|
|
renderer_class->realize = gsk_vulkan_renderer_realize;
|
|
|
|
renderer_class->unrealize = gsk_vulkan_renderer_unrealize;
|
|
|
|
renderer_class->render = gsk_vulkan_renderer_render;
|
2016-12-22 18:01:07 +00:00
|
|
|
renderer_class->render_texture = gsk_vulkan_renderer_render_texture;
|
2016-11-29 15:33:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_vulkan_renderer_init (GskVulkanRenderer *self)
|
|
|
|
{
|
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
GskProfiler *profiler = gsk_renderer_get_profiler (GSK_RENDERER (self));
|
2016-12-05 01:50:06 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
gsk_ensure_resources ();
|
2016-11-29 15:33:14 +00:00
|
|
|
|
2016-12-05 01:50:06 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
2017-09-25 22:37:22 +00:00
|
|
|
self->profile_counters.frames = gsk_profiler_add_counter (profiler, "frames", "Frames", FALSE);
|
2017-09-28 12:29:14 +00:00
|
|
|
self->profile_counters.render_passes = gsk_profiler_add_counter (profiler, "render-passes", "Render passes", FALSE);
|
2017-09-26 01:02:21 +00:00
|
|
|
self->profile_counters.fallback_pixels = gsk_profiler_add_counter (profiler, "fallback-pixels", "Fallback pixels", TRUE);
|
2017-09-30 14:39:04 +00:00
|
|
|
self->profile_counters.texture_pixels = gsk_profiler_add_counter (profiler, "texture-pixels", "Texture pixels", TRUE);
|
2017-09-26 01:02:21 +00:00
|
|
|
|
2016-11-29 15:33:14 +00:00
|
|
|
self->profile_timers.cpu_time = gsk_profiler_add_timer (profiler, "cpu-time", "CPU time", FALSE, TRUE);
|
2018-01-14 20:11:33 +00:00
|
|
|
if (GSK_RENDERER_DEBUG_CHECK (GSK_RENDERER (self), SYNC))
|
2017-09-28 14:27:58 +00:00
|
|
|
self->profile_timers.gpu_time = gsk_profiler_add_timer (profiler, "gpu-time", "GPU time", FALSE, TRUE);
|
2018-05-19 19:35:02 +00:00
|
|
|
|
|
|
|
if (texture_pixels_counter == 0)
|
|
|
|
{
|
|
|
|
texture_pixels_counter = gdk_profiler_define_int_counter ("texture-pixels", "Texture Pixels");
|
|
|
|
fallback_pixels_counter = gdk_profiler_define_int_counter ("fallback-pixels", "Fallback Pixels");
|
|
|
|
}
|
|
|
|
|
2016-11-29 15:33:14 +00:00
|
|
|
#endif
|
|
|
|
}
|
2016-12-09 06:23:04 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_vulkan_renderer_clear_texture (gpointer p)
|
|
|
|
{
|
|
|
|
GskVulkanTextureData *data = p;
|
|
|
|
|
|
|
|
if (data->renderer != NULL)
|
|
|
|
data->renderer->textures = g_slist_remove (data->renderer->textures, data);
|
|
|
|
|
|
|
|
g_object_unref (data->image);
|
|
|
|
|
2023-03-03 11:48:49 +00:00
|
|
|
g_free (data);
|
2016-12-09 06:23:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GskVulkanImage *
|
2023-06-24 22:54:10 +00:00
|
|
|
gsk_vulkan_renderer_get_texture_image (GskVulkanRenderer *self,
|
|
|
|
GdkTexture *texture)
|
2016-12-09 06:23:04 +00:00
|
|
|
{
|
|
|
|
GskVulkanTextureData *data;
|
|
|
|
|
2017-11-02 20:39:00 +00:00
|
|
|
data = gdk_texture_get_render_data (texture, self);
|
2016-12-09 06:23:04 +00:00
|
|
|
if (data)
|
2023-06-24 22:54:10 +00:00
|
|
|
return data->image;
|
2016-12-09 06:23:04 +00:00
|
|
|
|
2023-06-24 22:54:10 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gsk_vulkan_renderer_add_texture_image (GskVulkanRenderer *self,
|
|
|
|
GdkTexture *texture,
|
|
|
|
GskVulkanImage *image)
|
|
|
|
{
|
|
|
|
GskVulkanTextureData *data;
|
2016-12-09 06:23:04 +00:00
|
|
|
|
2023-03-03 11:48:49 +00:00
|
|
|
data = g_new0 (GskVulkanTextureData, 1);
|
2016-12-09 06:23:04 +00:00
|
|
|
data->image = image;
|
|
|
|
data->texture = texture;
|
|
|
|
data->renderer = self;
|
|
|
|
|
2017-11-02 20:39:00 +00:00
|
|
|
if (gdk_texture_set_render_data (texture, self, data, gsk_vulkan_renderer_clear_texture))
|
2016-12-09 06:23:04 +00:00
|
|
|
{
|
|
|
|
g_object_ref (data->image);
|
|
|
|
self->textures = g_slist_prepend (self->textures, data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-03-03 11:48:49 +00:00
|
|
|
g_free (data);
|
2016-12-09 06:23:04 +00:00
|
|
|
}
|
2023-06-24 22:54:10 +00:00
|
|
|
}
|
|
|
|
|
2023-07-03 07:15:04 +00:00
|
|
|
GskVulkanGlyphCache *
|
|
|
|
gsk_vulkan_renderer_get_glyph_cache (GskVulkanRenderer *self)
|
2017-09-11 01:55:22 +00:00
|
|
|
{
|
2023-07-03 07:15:04 +00:00
|
|
|
return self->glyph_cache;
|
2017-09-11 01:55:22 +00:00
|
|
|
}
|
2017-09-01 20:58:42 +00:00
|
|
|
|
2019-05-02 00:57:23 +00:00
|
|
|
/**
|
|
|
|
* gsk_vulkan_renderer_new:
|
|
|
|
*
|
|
|
|
* Creates a new Vulkan renderer.
|
|
|
|
*
|
|
|
|
* The Vulkan renderer is a renderer that uses the Vulkan library for
|
|
|
|
* rendering.
|
|
|
|
*
|
|
|
|
* This function is only available when GTK was compiled with Vulkan
|
|
|
|
* support.
|
|
|
|
*
|
|
|
|
* Returns: a new Vulkan renderer
|
|
|
|
**/
|
|
|
|
GskRenderer *
|
|
|
|
gsk_vulkan_renderer_new (void)
|
|
|
|
{
|
|
|
|
return g_object_new (GSK_TYPE_VULKAN_RENDERER, NULL);
|
|
|
|
}
|