gpu: Make cache keep track of time

If GskGpuCache has an idea of what time it is, cached items can use that
time to update their last-use time instead of having to carry it around
throught function calls everywhere.
This commit is contained in:
Benjamin Otte
2024-07-22 16:54:37 +02:00
parent 821eb92dfb
commit 4639b3bc4c
5 changed files with 40 additions and 38 deletions

View File

@@ -39,6 +39,7 @@ struct _GskGpuCache
GObject parent_instance;
GskGpuDevice *device;
gint64 timestamp;
GskGpuCached *first_cached;
GskGpuCached *last_cached;
@@ -152,10 +153,9 @@ gsk_gpu_cached_new (GskGpuCache *cache,
static void
gsk_gpu_cached_use (GskGpuCache *self,
GskGpuCached *cached,
gint64 timestamp)
GskGpuCached *cached)
{
cached->timestamp = timestamp;
cached->timestamp = self->timestamp;
mark_as_stale (cached, FALSE);
}
@@ -355,7 +355,6 @@ gsk_gpu_cache_get_atlas_image (GskGpuCache *self)
static GskGpuImage *
gsk_gpu_cache_add_atlas_image (GskGpuCache *self,
gint64 timestamp,
gsize width,
gsize height,
gsize *out_x,
@@ -368,7 +367,7 @@ gsk_gpu_cache_add_atlas_image (GskGpuCache *self,
if (gsk_gpu_cached_atlas_allocate (self->current_atlas, width, height, out_x, out_y))
{
gsk_gpu_cached_use (self, (GskGpuCached *) self->current_atlas, timestamp);
gsk_gpu_cached_use (self, (GskGpuCached *) self->current_atlas);
return self->current_atlas->image;
}
@@ -376,7 +375,7 @@ gsk_gpu_cache_add_atlas_image (GskGpuCache *self,
if (gsk_gpu_cached_atlas_allocate (self->current_atlas, width, height, out_x, out_y))
{
gsk_gpu_cached_use (self, (GskGpuCached *) self->current_atlas, timestamp);
gsk_gpu_cached_use (self, (GskGpuCached *) self->current_atlas);
return self->current_atlas->image;
}
@@ -688,7 +687,6 @@ GskGpuImage *
gsk_gpu_cache_lookup_tile (GskGpuCache *self,
GdkTexture *texture,
gsize tile_id,
gint64 timestamp,
GdkColorState **out_color_state)
{
GskGpuCachedTile *tile;
@@ -704,7 +702,7 @@ gsk_gpu_cache_lookup_tile (GskGpuCache *self,
if (tile == NULL)
return NULL;
gsk_gpu_cached_use (self, (GskGpuCached *) tile, timestamp);
gsk_gpu_cached_use (self, (GskGpuCached *) tile);
*out_color_state = tile->color_state;
@@ -713,7 +711,6 @@ gsk_gpu_cache_lookup_tile (GskGpuCache *self,
void
gsk_gpu_cache_cache_tile (GskGpuCache *self,
gint64 timestamp,
GdkTexture *texture,
guint tile_id,
GskGpuImage *image,
@@ -723,7 +720,7 @@ gsk_gpu_cache_cache_tile (GskGpuCache *self,
tile = gsk_gpu_cached_tile_new (self, texture, tile_id, image, color_state);
gsk_gpu_cached_use (self, (GskGpuCached *) tile, timestamp);
gsk_gpu_cached_use (self, (GskGpuCached *) tile);
}
/* }}} */
@@ -810,6 +807,21 @@ static const GskGpuCachedClass GSK_GPU_CACHED_GLYPH_CLASS =
/* }}} */
/* {{{ GskGpuCache */
/*
* gsk_gpu_cache_set_time:
* @self: a `GskGpuCache`
* @timestamp: time in whatever the frameclock uses
*
* Sets the timestamp to use for all following operations.
* Frames should set this when they start drawing.
**/
void
gsk_gpu_cache_set_time (GskGpuCache *self,
gint64 timestamp)
{
self->timestamp = timestamp;
}
typedef struct
{
guint n_items;
@@ -980,7 +992,6 @@ gsk_gpu_cache_init (GskGpuCache *self)
GskGpuImage *
gsk_gpu_cache_lookup_texture_image (GskGpuCache *self,
GdkTexture *texture,
gint64 timestamp,
GdkColorState *color_state)
{
GskGpuCachedTexture *cache;
@@ -999,7 +1010,7 @@ gsk_gpu_cache_lookup_texture_image (GskGpuCache *self,
if (!cache || !cache->image || gsk_gpu_cached_texture_is_invalid (cache))
return NULL;
gsk_gpu_cached_use (self, (GskGpuCached *) cache, timestamp);
gsk_gpu_cached_use (self, (GskGpuCached *) cache);
return g_object_ref (cache->image);
}
@@ -1007,7 +1018,6 @@ gsk_gpu_cache_lookup_texture_image (GskGpuCache *self,
void
gsk_gpu_cache_cache_texture_image (GskGpuCache *self,
GdkTexture *texture,
gint64 timestamp,
GskGpuImage *image,
GdkColorState *color_state)
{
@@ -1016,7 +1026,7 @@ gsk_gpu_cache_cache_texture_image (GskGpuCache *self,
cache = gsk_gpu_cached_texture_new (self, texture, image, color_state);
g_return_if_fail (cache != NULL);
gsk_gpu_cached_use (self, (GskGpuCached *) cache, timestamp);
gsk_gpu_cached_use (self, (GskGpuCached *) cache);
}
GskGpuImage *
@@ -1048,7 +1058,7 @@ gsk_gpu_cache_lookup_glyph_image (GskGpuCache *self,
cache = g_hash_table_lookup (self->glyph_cache, &lookup);
if (cache)
{
gsk_gpu_cached_use (self, (GskGpuCached *) cache, gsk_gpu_frame_get_timestamp (frame));
gsk_gpu_cached_use (self, (GskGpuCached *) cache);
*out_bounds = cache->bounds;
*out_origin = cache->origin;
@@ -1075,7 +1085,6 @@ gsk_gpu_cache_lookup_glyph_image (GskGpuCache *self,
padding = 1;
image = gsk_gpu_cache_add_atlas_image (self,
gsk_gpu_frame_get_timestamp (frame),
rect.size.width + 2 * padding, rect.size.height + 2 * padding,
&atlas_x, &atlas_y);
if (image)
@@ -1118,7 +1127,7 @@ gsk_gpu_cache_lookup_glyph_image (GskGpuCache *self,
cache->origin.y + padding));
g_hash_table_insert (self->glyph_cache, cache, cache);
gsk_gpu_cached_use (self, (GskGpuCached *) cache, gsk_gpu_frame_get_timestamp (frame));
gsk_gpu_cached_use (self, (GskGpuCached *) cache);
*out_bounds = cache->bounds;
*out_origin = cache->origin;

View File

@@ -24,6 +24,8 @@ GType gsk_gpu_cache_get_type (void) G
GskGpuCache * gsk_gpu_cache_new (GskGpuDevice *device);
void gsk_gpu_cache_set_time (GskGpuCache *self,
gint64 timestamp);
gboolean gsk_gpu_cache_gc (GskGpuCache *self,
gint64 cache_timeout,
gint64 timestamp);
@@ -32,20 +34,16 @@ GskGpuImage * gsk_gpu_cache_get_atlas_image (GskGpuC
GskGpuImage * gsk_gpu_cache_lookup_texture_image (GskGpuCache *self,
GdkTexture *texture,
gint64 timestamp,
GdkColorState *color_state);
void gsk_gpu_cache_cache_texture_image (GskGpuCache *self,
GdkTexture *texture,
gint64 timestamp,
GskGpuImage *image,
GdkColorState *color_state);
GskGpuImage * gsk_gpu_cache_lookup_tile (GskGpuCache *self,
GdkTexture *texture,
gsize tile_id,
gint64 timestamp,
GdkColorState **out_color_state);
void gsk_gpu_cache_cache_tile (GskGpuCache *self,
gint64 timestamp,
GdkTexture *texture,
guint tile_id,
GskGpuImage *image,

View File

@@ -150,7 +150,7 @@ gsk_gpu_download_op_vk_command (GskGpuOp *op,
GskGpuCache *cache = gsk_gpu_device_get_cache (device);
VkDevice vk_device = gsk_vulkan_device_get_vk_device (GSK_VULKAN_DEVICE (device));
gsk_gpu_cache_cache_texture_image (cache, self->texture, gsk_gpu_frame_get_timestamp (frame), self->image, NULL);
gsk_gpu_cache_cache_texture_image (cache, self->texture, self->image, NULL);
if (gsk_vulkan_device_has_feature (GSK_VULKAN_DEVICE (device), GDK_VULKAN_FEATURE_SEMAPHORE_EXPORT))
{

View File

@@ -445,7 +445,7 @@ gsk_gpu_frame_upload_texture (GskGpuFrame *self,
image = GSK_GPU_FRAME_GET_CLASS (self)->upload_texture (self, with_mipmap, texture);
if (image)
gsk_gpu_cache_cache_texture_image (gsk_gpu_device_get_cache (priv->device), texture, priv->timestamp, image, NULL);
gsk_gpu_cache_cache_texture_image (gsk_gpu_device_get_cache (priv->device), texture, image, NULL);
return image;
}
@@ -605,6 +605,7 @@ gsk_gpu_frame_record (GskGpuFrame *self,
GskRenderPassType pass_type = texture ? GSK_RENDER_PASS_EXPORT : GSK_RENDER_PASS_PRESENT;
priv->timestamp = timestamp;
gsk_gpu_cache_set_time (gsk_gpu_device_get_cache (priv->device), timestamp);
if (clip)
{
@@ -725,7 +726,10 @@ gsk_gpu_frame_download_texture (GskGpuFrame *self,
GskGpuFramePrivate *priv = gsk_gpu_frame_get_instance_private (self);
GskGpuImage *image;
image = gsk_gpu_cache_lookup_texture_image (gsk_gpu_device_get_cache (priv->device), texture, timestamp, NULL);
priv->timestamp = timestamp;
gsk_gpu_cache_set_time (gsk_gpu_device_get_cache (priv->device), timestamp);
image = gsk_gpu_cache_lookup_texture_image (gsk_gpu_device_get_cache (priv->device), texture, NULL);
if (image == NULL)
image = gsk_gpu_frame_upload_texture (self, FALSE, texture);
if (image == NULL)
@@ -736,8 +740,6 @@ gsk_gpu_frame_download_texture (GskGpuFrame *self,
gsk_gpu_frame_cleanup (self);
priv->timestamp = timestamp;
gsk_gpu_download_op (self,
image,
FALSE,

View File

@@ -1684,20 +1684,18 @@ gsk_gpu_lookup_texture (GskGpuFrame *frame,
{
GskGpuCache *cache;
GdkColorState *image_cs;
gint64 timestamp;
GskGpuImage *image;
cache = gsk_gpu_device_get_cache (gsk_gpu_frame_get_device (frame));
timestamp = gsk_gpu_frame_get_timestamp (frame);
image = gsk_gpu_cache_lookup_texture_image (cache, texture, timestamp, ccs);
image = gsk_gpu_cache_lookup_texture_image (cache, texture, ccs);
if (image)
{
*out_image_cs = ccs;
return image;
}
image = gsk_gpu_cache_lookup_texture_image (cache, texture, timestamp, NULL);
image = gsk_gpu_cache_lookup_texture_image (cache, texture, NULL);
if (image == NULL)
image = gsk_gpu_frame_upload_texture (frame, try_mipmap, texture);
@@ -1746,7 +1744,6 @@ gsk_gpu_node_processor_draw_texture_tiles (GskGpuNodeProcessor *self,
{
GskGpuCache *cache;
GskGpuDevice *device;
gint64 timestamp;
GskGpuImage *tile;
GdkColorState *tile_cs;
GskGpuSampler sampler;
@@ -1759,7 +1756,6 @@ gsk_gpu_node_processor_draw_texture_tiles (GskGpuNodeProcessor *self,
device = gsk_gpu_frame_get_device (self->frame);
cache = gsk_gpu_device_get_cache (device);
timestamp = gsk_gpu_frame_get_timestamp (self->frame);
sampler = gsk_gpu_sampler_for_scaling_filter (scaling_filter);
need_mipmap = scaling_filter == GSK_SCALING_FILTER_TRILINEAR;
gsk_gpu_node_processor_get_clip_bounds (self, &clip_bounds);
@@ -1784,7 +1780,7 @@ gsk_gpu_node_processor_draw_texture_tiles (GskGpuNodeProcessor *self,
!gsk_rect_intersects (&clip_bounds, &tile_rect))
continue;
tile = gsk_gpu_cache_lookup_tile (cache, texture, y * n_width + x, timestamp, &tile_cs);
tile = gsk_gpu_cache_lookup_tile (cache, texture, y * n_width + x, &tile_cs);
if (tile == NULL)
{
@@ -1811,7 +1807,7 @@ gsk_gpu_node_processor_draw_texture_tiles (GskGpuNodeProcessor *self,
g_assert (tile_cs);
}
gsk_gpu_cache_cache_tile (cache, timestamp, texture, y * n_width + x, tile, tile_cs);
gsk_gpu_cache_cache_tile (cache, texture, y * n_width + x, tile, tile_cs);
}
if (need_mipmap &&
@@ -1819,7 +1815,7 @@ gsk_gpu_node_processor_draw_texture_tiles (GskGpuNodeProcessor *self,
{
tile = gsk_gpu_copy_image (self->frame, self->ccs, tile, tile_cs, TRUE);
tile_cs = self->ccs;
gsk_gpu_cache_cache_tile (cache, timestamp, texture, y * n_width + x, tile, tile_cs);
gsk_gpu_cache_cache_tile (cache, texture, y * n_width + x, tile, tile_cs);
}
if (need_mipmap && !(gsk_gpu_image_get_flags (tile) & GSK_GPU_IMAGE_MIPMAP))
gsk_gpu_mipmap_op (self->frame, tile);
@@ -1922,7 +1918,6 @@ gsk_gpu_node_processor_add_texture_node (GskGpuNodeProcessor *self,
image_cs = self->ccs;
gsk_gpu_cache_cache_texture_image (gsk_gpu_device_get_cache (gsk_gpu_frame_get_device (self->frame)),
texture,
gsk_gpu_frame_get_timestamp (self->frame),
image,
image_cs);
}
@@ -1988,7 +1983,6 @@ gsk_gpu_get_texture_node_as_image (GskGpuFrame *frame,
image = gsk_gpu_copy_image (frame, ccs, image, image_cs, FALSE);
gsk_gpu_cache_cache_texture_image (gsk_gpu_device_get_cache (gsk_gpu_frame_get_device (frame)),
texture,
gsk_gpu_frame_get_timestamp (frame),
image,
ccs);
}
@@ -2077,7 +2071,6 @@ gsk_gpu_node_processor_add_texture_scale_node (GskGpuNodeProcessor *self,
image_cs = self->ccs;
gsk_gpu_cache_cache_texture_image (gsk_gpu_device_get_cache (gsk_gpu_frame_get_device (self->frame)),
texture,
gsk_gpu_frame_get_timestamp (self->frame),
image,
image_cs);
}