[gtk/wip/chergert/glproto: 128/493] move autorelease semantics to driver
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/chergert/glproto: 128/493] move autorelease semantics to driver
- Date: Fri, 19 Feb 2021 02:25:07 +0000 (UTC)
commit 4093d86cc3b169fd2542fd23e0137ca4b514459f
Author: Christian Hergert <chergert redhat com>
Date: Mon Jan 4 13:07:57 2021 -0800
move autorelease semantics to driver
we want this in the driver so that we can keep texture caching at a higher
level and out of things like the command queue which are indifferent to it
gsk/next/gskglcommandqueue.c | 40 +----------------
gsk/next/gskglcommandqueueprivate.h | 86 ++++++++++++++++---------------------
gsk/next/gskgldriver.c | 36 ++++++++++++++++
gsk/next/gskgldriverprivate.h | 29 ++++++++-----
gsk/next/gskglrenderer.c | 2 +-
5 files changed, 93 insertions(+), 100 deletions(-)
---
diff --git a/gsk/next/gskglcommandqueue.c b/gsk/next/gskglcommandqueue.c
index da53fa0401..d204a3ed40 100644
--- a/gsk/next/gskglcommandqueue.c
+++ b/gsk/next/gskglcommandqueue.c
@@ -200,8 +200,6 @@ gsk_gl_command_queue_dispose (GObject *object)
g_clear_pointer (&self->batch_binds, g_array_unref);
g_clear_pointer (&self->batch_uniforms, g_array_unref);
g_clear_pointer (&self->saved_state, g_ptr_array_unref);
- g_clear_pointer (&self->autorelease_framebuffers, g_array_unref);
- g_clear_pointer (&self->autorelease_textures, g_array_unref);
G_OBJECT_CLASS (gsk_gl_command_queue_parent_class)->dispose (object);
}
@@ -227,8 +225,6 @@ gsk_gl_command_queue_init (GskGLCommandQueue *self)
self->vertices = gsk_gl_buffer_new (GL_ARRAY_BUFFER, sizeof (GskGLDrawVertex));
self->uniforms = gsk_gl_uniform_state_new ();
self->saved_state = g_ptr_array_new_with_free_func ((GDestroyNotify)gsk_gl_attachment_state_free);
- self->autorelease_textures = g_array_new (FALSE, FALSE, sizeof (GLuint));
- self->autorelease_framebuffers = g_array_new (FALSE, FALSE, sizeof (GLuint));
self->debug_groups = g_string_chunk_new (4096);
}
@@ -241,7 +237,7 @@ gsk_gl_command_queue_new (GdkGLContext *context)
self = g_object_new (GSK_TYPE_GL_COMMAND_QUEUE, NULL);
self->context = g_object_ref (context);
-
+
return g_steal_pointer (&self);
}
@@ -348,7 +344,7 @@ gsk_gl_command_queue_end_draw (GskGLCommandQueue *self)
g_return_if_fail (self->in_draw == TRUE);
batch = &g_array_index (self->batches, GskGLCommandBatch, self->batches->len - 1);
-
+
g_assert (batch->any.kind == GSK_GL_COMMAND_KIND_DRAW);
if G_UNLIKELY (batch->draw.vbo_count == 0)
@@ -790,24 +786,12 @@ gsk_gl_command_queue_end_frame (GskGLCommandQueue *self)
gsk_gl_uniform_state_end_frame (self->uniforms);
- /* Release autoreleased framebuffers */
- if (self->autorelease_framebuffers->len > 0)
- glDeleteFramebuffers (self->autorelease_framebuffers->len,
- (GLuint *)(gpointer)self->autorelease_framebuffers->data);
-
- /* Release autoreleased textures */
- if (self->autorelease_textures->len > 0)
- glDeleteTextures (self->autorelease_textures->len,
- (GLuint *)(gpointer)self->autorelease_textures->data);
-
g_string_chunk_clear (self->debug_groups);
self->batches->len = 0;
self->batch_draws->len = 0;
self->batch_uniforms->len = 0;
self->batch_binds->len = 0;
- self->autorelease_framebuffers->len = 0;
- self->autorelease_textures->len = 0;
self->tail_batch_index = -1;
}
@@ -853,26 +837,6 @@ gsk_gl_command_queue_create_render_target (GskGLCommandQueue *self,
return TRUE;
}
-void
-gsk_gl_command_queue_autorelease_framebuffer (GskGLCommandQueue *self,
- guint framebuffer_id)
-{
- g_return_if_fail (GSK_IS_GL_COMMAND_QUEUE (self));
- g_return_if_fail (framebuffer_id > 0);
-
- g_array_append_val (self->autorelease_framebuffers, framebuffer_id);
-}
-
-void
-gsk_gl_command_queue_autorelease_texture (GskGLCommandQueue *self,
- guint texture_id)
-{
- g_return_if_fail (GSK_IS_GL_COMMAND_QUEUE (self));
- g_return_if_fail (texture_id > 0);
-
- g_array_append_val (self->autorelease_textures, texture_id);
-}
-
int
gsk_gl_command_queue_create_texture (GskGLCommandQueue *self,
int width,
diff --git a/gsk/next/gskglcommandqueueprivate.h b/gsk/next/gskglcommandqueueprivate.h
index 9bc70601f0..52988fddd9 100644
--- a/gsk/next/gskglcommandqueueprivate.h
+++ b/gsk/next/gskglcommandqueueprivate.h
@@ -91,16 +91,6 @@ struct _GskGLCommandQueue
*/
GPtrArray *saved_state;
- /* Sometimes it is handy to keep a number of textures or framebuffers
- * around until the frame has finished drawing. That way some objects can
- * be used immediately even though they won't have any rendering until the
- * frame has finished.
- *
- * When end_frame is called, we remove these resources.
- */
- GArray *autorelease_framebuffers;
- GArray *autorelease_textures;
-
/* String storage for debug groups */
GStringChunk *debug_groups;
@@ -120,46 +110,42 @@ struct _GskGLCommandQueue
guint in_draw : 1;
};
-GskGLCommandQueue *gsk_gl_command_queue_new (GdkGLContext *context);
-GdkGLContext *gsk_gl_command_queue_get_context (GskGLCommandQueue *self);
-void gsk_gl_command_queue_make_current (GskGLCommandQueue *self);
-void gsk_gl_command_queue_begin_frame (GskGLCommandQueue *self);
-void gsk_gl_command_queue_end_frame (GskGLCommandQueue *self);
-void gsk_gl_command_queue_execute (GskGLCommandQueue *self);
-guint gsk_gl_command_queue_upload_texture (GskGLCommandQueue *self,
- GdkTexture *texture,
- GError **error);
-int gsk_gl_command_queue_create_texture (GskGLCommandQueue *self,
- int width,
- int height,
- int min_filter,
- int mag_filter);
-guint gsk_gl_command_queue_create_framebuffer (GskGLCommandQueue *self);
-gboolean gsk_gl_command_queue_create_render_target (GskGLCommandQueue *self,
- int width,
- int height,
- guint *out_fbo_id,
- guint *out_texture_id);
-void gsk_gl_command_queue_delete_program (GskGLCommandQueue *self,
- guint program_id);
-void gsk_gl_command_queue_bind_framebuffer (GskGLCommandQueue *self,
- guint framebuffer);
-void gsk_gl_command_queue_clear (GskGLCommandQueue *self,
- guint clear_bits,
- const graphene_rect_t *viewport);
-void gsk_gl_command_queue_push_debug_group (GskGLCommandQueue *self,
- const char *message);
-void gsk_gl_command_queue_pop_debug_group (GskGLCommandQueue *self);
-void gsk_gl_command_queue_autorelease_framebuffer (GskGLCommandQueue *self,
- guint framebuffer_id);
-void gsk_gl_command_queue_autorelease_texture (GskGLCommandQueue *self,
- guint texture_id);
-void gsk_gl_command_queue_begin_draw (GskGLCommandQueue *self,
- guint program,
- const graphene_rect_t *viewport);
-void gsk_gl_command_queue_end_draw (GskGLCommandQueue *self);
-GskGLDrawVertex *gsk_gl_command_queue_add_vertices (GskGLCommandQueue *self,
- const GskGLDrawVertex
vertices[GSK_GL_N_VERTICES]);
+GskGLCommandQueue *gsk_gl_command_queue_new (GdkGLContext *context);
+GdkGLContext *gsk_gl_command_queue_get_context (GskGLCommandQueue *self);
+void gsk_gl_command_queue_make_current (GskGLCommandQueue *self);
+void gsk_gl_command_queue_begin_frame (GskGLCommandQueue *self);
+void gsk_gl_command_queue_end_frame (GskGLCommandQueue *self);
+void gsk_gl_command_queue_execute (GskGLCommandQueue *self);
+guint gsk_gl_command_queue_upload_texture (GskGLCommandQueue *self,
+ GdkTexture *texture,
+ GError **error);
+int gsk_gl_command_queue_create_texture (GskGLCommandQueue *self,
+ int width,
+ int height,
+ int min_filter,
+ int mag_filter);
+guint gsk_gl_command_queue_create_framebuffer (GskGLCommandQueue *self);
+gboolean gsk_gl_command_queue_create_render_target (GskGLCommandQueue *self,
+ int width,
+ int height,
+ guint *out_fbo_id,
+ guint *out_texture_id);
+void gsk_gl_command_queue_delete_program (GskGLCommandQueue *self,
+ guint program_id);
+void gsk_gl_command_queue_bind_framebuffer (GskGLCommandQueue *self,
+ guint framebuffer);
+void gsk_gl_command_queue_clear (GskGLCommandQueue *self,
+ guint clear_bits,
+ const graphene_rect_t *viewport);
+void gsk_gl_command_queue_push_debug_group (GskGLCommandQueue *self,
+ const char *message);
+void gsk_gl_command_queue_pop_debug_group (GskGLCommandQueue *self);
+void gsk_gl_command_queue_begin_draw (GskGLCommandQueue *self,
+ guint program,
+ const graphene_rect_t *viewport);
+void gsk_gl_command_queue_end_draw (GskGLCommandQueue *self);
+GskGLDrawVertex *gsk_gl_command_queue_add_vertices (GskGLCommandQueue *self,
+ const GskGLDrawVertex
vertices[GSK_GL_N_VERTICES]);
static inline void
gsk_gl_command_queue_set_uniform1i (GskGLCommandQueue *self,
diff --git a/gsk/next/gskgldriver.c b/gsk/next/gskgldriver.c
index 4794730aac..ae77a16ef8 100644
--- a/gsk/next/gskgldriver.c
+++ b/gsk/next/gskgldriver.c
@@ -52,6 +52,8 @@ gsk_next_driver_dispose (GObject *object)
#undef GSK_GL_DEFINE_PROGRAM
g_clear_object (&self->command_queue);
+ g_clear_pointer (&self->autorelease_framebuffers, g_array_unref);
+ g_clear_pointer (&self->autorelease_textures, g_array_unref);
G_OBJECT_CLASS (gsk_next_driver_parent_class)->dispose (object);
}
@@ -67,6 +69,8 @@ gsk_next_driver_class_init (GskNextDriverClass *klass)
static void
gsk_next_driver_init (GskNextDriver *self)
{
+ self->autorelease_framebuffers = g_array_new (FALSE, FALSE, sizeof (guint));
+ self->autorelease_textures = g_array_new (FALSE, FALSE, sizeof (guint));
}
static gboolean
@@ -196,6 +200,20 @@ gsk_next_driver_end_frame (GskNextDriver *self)
gsk_gl_texture_library_end_frame (GSK_GL_TEXTURE_LIBRARY (self->glyphs));
gsk_gl_texture_library_end_frame (GSK_GL_TEXTURE_LIBRARY (self->shadows));
+ if (self->autorelease_textures->len > 0)
+ {
+ glDeleteTextures (self->autorelease_textures->len,
+ (GLuint *)(gpointer)self->autorelease_textures->data);
+ self->autorelease_textures->len = 0;
+ }
+
+ if (self->autorelease_framebuffers->len > 0)
+ {
+ glDeleteFramebuffers (self->autorelease_framebuffers->len,
+ (GLuint *)(gpointer)self->autorelease_framebuffers->data);
+ self->autorelease_framebuffers->len = 0;
+ }
+
self->in_frame = FALSE;
}
@@ -226,3 +244,21 @@ gsk_next_driver_create_render_target (GskNextDriver *self,
out_fbo_id,
out_texture_id);
}
+
+void
+gsk_next_driver_autorelease_texture (GskNextDriver *self,
+ guint texture_id)
+{
+ g_return_if_fail (GSK_IS_NEXT_DRIVER (self));
+
+ g_array_append_val (self->autorelease_textures, texture_id);
+}
+
+void
+gsk_next_driver_autorelease_framebuffer (GskNextDriver *self,
+ guint framebuffer_id)
+{
+ g_return_if_fail (GSK_IS_NEXT_DRIVER (self));
+
+ g_array_append_val (self->autorelease_framebuffers, framebuffer_id);
+}
diff --git a/gsk/next/gskgldriverprivate.h b/gsk/next/gskgldriverprivate.h
index b7c5a852b5..e63bc607ae 100644
--- a/gsk/next/gskgldriverprivate.h
+++ b/gsk/next/gskgldriverprivate.h
@@ -58,6 +58,9 @@ struct _GskNextDriver
GskGLIconLibrary *icons;
GskGLShadowLibrary *shadows;
+ GArray *autorelease_framebuffers;
+ GArray *autorelease_textures;
+
#define GSK_GL_NO_UNIFORMS
#define GSK_GL_ADD_UNIFORM(pos, KEY, name)
#define GSK_GL_DEFINE_PROGRAM(name, resource, uniforms) GskGLProgram *name;
@@ -70,17 +73,21 @@ struct _GskNextDriver
guint in_frame : 1;
};
-GskNextDriver *gsk_next_driver_new (GskGLCommandQueue *command_queue,
- gboolean debug,
- GError **error);
-GdkGLContext *gsk_next_driver_get_context (GskNextDriver *self);
-gboolean gsk_next_driver_create_render_target (GskNextDriver *self,
- int width,
- int height,
- guint *out_fbo_id,
- guint *out_texture_id);
-void gsk_next_driver_begin_frame (GskNextDriver *driver);
-void gsk_next_driver_end_frame (GskNextDriver *driver);
+GskNextDriver *gsk_next_driver_new (GskGLCommandQueue *command_queue,
+ gboolean debug,
+ GError **error);
+GdkGLContext *gsk_next_driver_get_context (GskNextDriver *self);
+gboolean gsk_next_driver_create_render_target (GskNextDriver *self,
+ int width,
+ int height,
+ guint *out_fbo_id,
+ guint *out_texture_id);
+void gsk_next_driver_begin_frame (GskNextDriver *self);
+void gsk_next_driver_end_frame (GskNextDriver *self);
+void gsk_next_driver_autorelease_framebuffer (GskNextDriver *self,
+ guint framebuffer_id);
+void gsk_next_driver_autorelease_texture (GskNextDriver *self,
+ guint texture_id);
G_END_DECLS
diff --git a/gsk/next/gskglrenderer.c b/gsk/next/gskglrenderer.c
index 73827d6031..202e009b30 100644
--- a/gsk/next/gskglrenderer.c
+++ b/gsk/next/gskglrenderer.c
@@ -268,7 +268,7 @@ gsk_gl_renderer_render_texture (GskRenderer *renderer,
&texture_id))
return NULL;
- gsk_gl_command_queue_autorelease_framebuffer (self->command_queue, fbo_id);
+ gsk_next_driver_autorelease_framebuffer (self->driver, fbo_id);
job = gsk_gl_render_job_new (self->driver, viewport, 1, NULL, fbo_id, TRUE);
gsk_gl_render_job_render (job, root);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]