[gtk/wip/chergert/glproto: 489/526] remove indirect pointer to uniform info
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/chergert/glproto: 489/526] remove indirect pointer to uniform info
- Date: Tue, 16 Feb 2021 01:14:39 +0000 (UTC)
commit 5c64c19c115f6539ea820f5cebf097d1c07b1764
Author: Christian Hergert <chergert redhat com>
Date: Tue Feb 9 13:02:55 2021 -0800
remove indirect pointer to uniform info
this removes an extra pointer chase from the very hot uniform state
setting code.
gsk/next/gskgluniformstate.c | 35 +++++++++++++++++++++--------------
gsk/next/gskgluniformstateprivate.h | 33 ++++++++++++++++-----------------
2 files changed, 37 insertions(+), 31 deletions(-)
---
diff --git a/gsk/next/gskgluniformstate.c b/gsk/next/gskgluniformstate.c
index 91f110e954..6961bd36f1 100644
--- a/gsk/next/gskgluniformstate.c
+++ b/gsk/next/gskgluniformstate.c
@@ -106,7 +106,7 @@ clear_program_info (gpointer data)
{
GskGLUniformProgram *program_info = data;
- g_clear_pointer (&program_info->uniform_info, g_array_unref);
+ g_clear_pointer (&program_info->uniform_info, g_free);
g_clear_pointer (&program_info->changed, g_free);
}
@@ -179,7 +179,8 @@ gsk_gl_uniform_state_clear_program (GskGLUniformState *state,
program_info = &g_array_index (state->program_info, GskGLUniformProgram, program);
- g_clear_pointer (&program_info->uniform_info, g_array_unref);
+ g_clear_pointer (&program_info->uniform_info, g_free);
+ program_info->uniform_info_len = 0;
program_info->n_changed = 0;
program_info->changed_len = 0;
@@ -245,10 +246,9 @@ get_uniform (GskGLUniformState *state,
/* Fast path for common case (state already initialized) */
if G_LIKELY (program < state->program_info->len &&
(program_info = &g_array_index (state->program_info, GskGLUniformProgram, program)) &&
- program_info->uniform_info != NULL &&
- location < program_info->uniform_info->len)
+ location < program_info->uniform_info_len)
{
- info = &g_array_index (program_info->uniform_info, GskGLUniformInfo, location);
+ info = &program_info->uniform_info[location];
if G_LIKELY (format == info->format)
{
@@ -293,30 +293,37 @@ setup_info:
g_array_set_size (state->program_info, program + 1);
program_info = &g_array_index (state->program_info, GskGLUniformProgram, program);
- program_info->uniform_info = g_array_new (FALSE, TRUE, sizeof (GskGLUniformInfo));
+ program_info->uniform_info = g_new0 (GskGLUniformInfo, location + 1);
+ program_info->uniform_info_len = location + 1;
program_info->changed = NULL;
program_info->n_changed = 0;
program_info->changed_len = 0;
+
+ for (guint i = 0; i < program_info->uniform_info_len; i++)
+ program_info->uniform_info[i].initial = TRUE;
}
g_assert (program_info != NULL);
g_assert (program_info->uniform_info != NULL);
- if (location >= program_info->uniform_info->len)
+ if (location >= program_info->uniform_info_len)
{
- guint prev = program_info->uniform_info->len;
+ guint prev = program_info->uniform_info_len;
- g_array_set_size (program_info->uniform_info, location + 1);
+ program_info->uniform_info = g_realloc_n (program_info->uniform_info, location + 1, sizeof
(GskGLUniformInfo));
+ program_info->uniform_info_len = location + 1;
- for (guint i = prev; i < program_info->uniform_info->len; i++)
- g_array_index (program_info->uniform_info, GskGLUniformInfo, i).initial = TRUE;
+ memset (&program_info->uniform_info[prev], 0,
+ (program_info->uniform_info_len - prev) * sizeof (GskGLUniformInfo));
+ for (guint i = prev; i < program_info->uniform_info_len; i++)
+ program_info->uniform_info[i].initial = TRUE;
}
alloc_uniform_data (state,
uniform_sizes[format] * MAX (1, array_count),
&offset);
- info = &g_array_index (program_info->uniform_info, GskGLUniformInfo, location);
+ info = &program_info->uniform_info[location];
info->changed = FALSE;
info->format = format;
info->offset = offset;
@@ -833,9 +840,9 @@ gsk_gl_uniform_state_end_frame (GskGLUniformState *state)
if (program_info->uniform_info == NULL)
continue;
- for (guint j = 0; j < program_info->uniform_info->len; j++)
+ for (guint j = 0; j < program_info->uniform_info_len; j++)
{
- GskGLUniformInfo *info = &g_array_index (program_info->uniform_info, GskGLUniformInfo, j);
+ GskGLUniformInfo *info = &program_info->uniform_info[j];
guint size;
if (info->format == 0)
diff --git a/gsk/next/gskgluniformstateprivate.h b/gsk/next/gskgluniformstateprivate.h
index 731411a492..c08f568cb3 100644
--- a/gsk/next/gskgluniformstateprivate.h
+++ b/gsk/next/gskgluniformstateprivate.h
@@ -25,10 +25,24 @@
G_BEGIN_DECLS
+typedef struct _GskGLUniformInfo
+{
+ guint changed : 1;
+ guint format : 5;
+ guint array_count : 6;
+ guint initial : 1;
+ guint send_corners : 1;
+ guint unused : 2;
+ guint offset : 16;
+} GskGLUniformInfo;
+
+G_STATIC_ASSERT (sizeof (GskGLUniformInfo) == 4);
+
typedef struct _GskGLUniformProgram
{
/* Array of GskGLUniformInfo, index is GLSL location */
- GArray *uniform_info;
+ GskGLUniformInfo *uniform_info;
+ guint uniform_info_len;
/* To avoid walking unchanged locations in @uniform_info (or sparse
* elements used to map location->info), we use this to determine the
@@ -47,19 +61,6 @@ typedef struct _GskGLUniformState
guint values_len;
} GskGLUniformState;
-typedef struct _GskGLUniformInfo
-{
- guint changed : 1;
- guint format : 5;
- guint array_count : 6;
- guint initial : 1;
- guint send_corners : 1;
- guint unused : 2;
- guint offset : 16;
-} GskGLUniformInfo;
-
-G_STATIC_ASSERT (sizeof (GskGLUniformInfo) == 4);
-
/**
* GskGLUniformStateCallback:
* @info: a pointer to the information about the uniform
@@ -216,9 +217,7 @@ gsk_gl_uniform_state_get_uniform_data (const GskGLUniformState *state,
for (guint z = 0; z < program_info->n_changed; z++) \
{ \
guint location = program_info->changed[z]; \
- GskGLUniformInfo *info = &g_array_index (program_info->uniform_info, \
- GskGLUniformInfo, \
- location); \
+ GskGLUniformInfo *info = &program_info->uniform_info[location]; \
\
g_assert (info->changed); \
\
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]