summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2020-09-29 11:52:39 +0200
committerAlexander Larsson <alexl@redhat.com>2020-09-29 11:52:39 +0200
commit51ab56d33aa158cac0a0cc03fa2828807729cda1 (patch)
tree3e0b97a121d69f4d09098a1524f9cb154d529c8e
parent2e5caa68bc5b37fdf1b808b304c6d5499f21ab48 (diff)
downloadgtk+-51ab56d33aa158cac0a0cc03fa2828807729cda1.tar.gz
gl: Track the current uniform state for custom programs
This allows us to avoid updating uniforms if that is not necessary. This in turn allows us to sometimes reuse the same draw op by just extending the vertex array size we draw rather than doing a separate glDraw call. For example, in the fishbowl demo, all the icons added at the same time will have the same time and size, so we emit single draw calls with 100s of triangles instead of 100s of draw calls with 2 triangles.
-rw-r--r--gsk/gl/gskglrenderops.c21
-rw-r--r--gsk/gl/gskglrenderopsprivate.h6
2 files changed, 27 insertions, 0 deletions
diff --git a/gsk/gl/gskglrenderops.c b/gsk/gl/gskglrenderops.c
index 1fc9d02810..63273db93d 100644
--- a/gsk/gl/gskglrenderops.c
+++ b/gsk/gl/gskglrenderops.c
@@ -640,7 +640,28 @@ ops_set_gl_shader_args (RenderOpBuilder *builder,
float height,
const guchar *uniform_data)
{
+ ProgramState *current_program_state = get_current_program_state (builder);
OpGLShader *op;
+ gsize args_size = gsk_gl_shader_get_args_size (shader);
+
+ if (current_program_state)
+ {
+ if (current_program_state->gl_shader.width == width &&
+ current_program_state->gl_shader.height == height &&
+ current_program_state->gl_shader.uniform_data_len == args_size &&
+ memcmp (current_program_state->gl_shader.uniform_data, uniform_data, args_size) == 0)
+ return;
+
+ current_program_state->gl_shader.width = width;
+ current_program_state->gl_shader.height = height;
+ if (args_size > sizeof (current_program_state->gl_shader.uniform_data))
+ current_program_state->gl_shader.uniform_data_len = 0;
+ else
+ {
+ current_program_state->gl_shader.uniform_data_len = args_size;
+ memcpy (current_program_state->gl_shader.uniform_data, uniform_data, args_size);
+ }
+ }
op = ops_begin (builder, OP_CHANGE_GL_SHADER_ARGS);
op->shader = shader;
diff --git a/gsk/gl/gskglrenderopsprivate.h b/gsk/gl/gskglrenderopsprivate.h
index 38b5756a9c..6f90a0c212 100644
--- a/gsk/gl/gskglrenderopsprivate.h
+++ b/gsk/gl/gskglrenderopsprivate.h
@@ -79,6 +79,12 @@ typedef struct
float end;
float radius[2]; /* h/v */
} radial_gradient;
+ struct {
+ float width;
+ float height;
+ gint uniform_data_len;
+ guchar uniform_data[32];
+ } gl_shader;
};
} ProgramState;