[gtk/wip/chergert/glproto: 356/493] remove swap buffers
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/chergert/glproto: 356/493] remove swap buffers
- Date: Fri, 19 Feb 2021 02:25:16 +0000 (UTC)
commit 7ec34f2b26f94e7c57142fd6dec7eb30175c9908
Author: Christian Hergert <chergert redhat com>
Date: Tue Feb 2 20:00:20 2021 -0800
remove swap buffers
this is no longer really gaining us anything, so we can just drop it. even if it
still is, its negligible
gsk/next/gskglbuffer.c | 100 +++++++-----------------------------------
gsk/next/gskglbufferprivate.h | 42 ++++++++++--------
gsk/next/gskglcommandqueue.c | 4 +-
3 files changed, 43 insertions(+), 103 deletions(-)
---
diff --git a/gsk/next/gskglbuffer.c b/gsk/next/gskglbuffer.c
index fd3896be5f..f7494da987 100644
--- a/gsk/next/gskglbuffer.c
+++ b/gsk/next/gskglbuffer.c
@@ -24,69 +24,6 @@
#include "gskglbufferprivate.h"
-#define RESERVED_SIZE 1024
-
-static void
-gsk_gl_buffer_shadow_init (GskGLBufferShadow *shadow,
- GLenum target,
- guint element_size,
- guint reserved_size)
-{
- GLuint id;
-
- glGenBuffers (1, &id);
- glBindBuffer (target, id);
- glBufferData (target, element_size * reserved_size, NULL, GL_STATIC_DRAW);
- glBindBuffer (target, 0);
-
- shadow->id = id;
- shadow->size_on_gpu = element_size * reserved_size;
-}
-
-static void
-gsk_gl_buffer_shadow_destroy (GskGLBufferShadow *shadow)
-{
- shadow->size_on_gpu = 0;
-
- if (shadow->id > 0)
- {
- glDeleteBuffers (1, &shadow->id);
- shadow->id = 0;
- }
-}
-
-static void
-gsk_gl_buffer_shadow_submit (GskGLBufferShadow *shadow,
- GLenum target,
- GArray *buffer)
-{
- guint to_upload = buffer->len * g_array_get_element_size (buffer);
-
- /* If what we generated is larger than our size on the GPU, then we need
- * to release our previous buffer and create a new one of the appropriate
- * size. We add some padding to make it more likely the next frame with this
- * buffer does not need to do the same thing again. We also try to keep
- * things aligned to the size of a whole (4096 byte) page.
- */
- if G_UNLIKELY (to_upload > shadow->size_on_gpu)
- {
- guint size_on_gpu = (to_upload & ~0xFFF) + (4 * 4096L);
-
- glBindBuffer (target, 0);
- glDeleteBuffers (1, &shadow->id);
- glGenBuffers (1, &shadow->id);
- glBindBuffer (target, shadow->id);
- glBufferData (target, size_on_gpu, NULL, GL_STATIC_DRAW);
- glBufferSubData (target, 0, to_upload, buffer->data);
- shadow->size_on_gpu = size_on_gpu;
- }
- else
- {
- glBindBuffer (target, shadow->id);
- glBufferSubData (target, 0, to_upload, buffer->data);
- }
-}
-
/**
* gsk_gl_buffer_new:
* @target: the target buffer such as %GL_ARRAY_BUFFER or %GL_UNIFORM_BUFFER
@@ -106,41 +43,36 @@ gsk_gl_buffer_new (GLenum target,
guint element_size)
{
GskGLBuffer *buffer;
- GLuint id = 0;
-
- glGenBuffers (1, &id);
buffer = g_new0 (GskGLBuffer, 1);
- buffer->buffer = g_array_sized_new (FALSE, FALSE, element_size, RESERVED_SIZE);
+ buffer->buffer = g_malloc (8092);
+ buffer->buffer_len = 8092;
+ buffer->buffer_pos = 0;
buffer->target = target;
- buffer->current = 0;
buffer->element_size = element_size;
-
- for (guint i = 0; i < GSK_GL_BUFFER_N_BUFFERS; i++)
- gsk_gl_buffer_shadow_init (&buffer->shadows[i],
- target,
- element_size,
- RESERVED_SIZE);
+ buffer->count = 0;
return g_steal_pointer (&buffer);
}
-void
+GLuint
gsk_gl_buffer_submit (GskGLBuffer *buffer)
{
- gsk_gl_buffer_shadow_submit (&buffer->shadows[buffer->current],
- buffer->target,
- buffer->buffer);
- buffer->current = (buffer->current + 1) % GSK_GL_BUFFER_N_BUFFERS;
- buffer->buffer->len = 0;
+ GLuint id;
+
+ glGenBuffers (1, &id);
+ glBindBuffer (buffer->target, id);
+ glBufferData (buffer->target, buffer->buffer_pos, buffer->buffer, GL_STATIC_DRAW);
+
+ buffer->buffer_pos = 0;
+ buffer->count = 0;
+
+ return id;
}
void
gsk_gl_buffer_free (GskGLBuffer *buffer)
{
- buffer->target = 0;
- buffer->current = 0;
- for (guint i = 0; i < GSK_GL_BUFFER_N_BUFFERS; i++)
- gsk_gl_buffer_shadow_destroy (&buffer->shadows[i]);
+ g_free (buffer->buffer);
g_free (buffer);
}
diff --git a/gsk/next/gskglbufferprivate.h b/gsk/next/gskglbufferprivate.h
index 43c80108d7..6c7e15924f 100644
--- a/gsk/next/gskglbufferprivate.h
+++ b/gsk/next/gskglbufferprivate.h
@@ -26,42 +26,48 @@
G_BEGIN_DECLS
-#define GSK_GL_BUFFER_N_BUFFERS 2
-
-typedef struct _GskGLBufferShadow
-{
- GLuint id;
- guint size_on_gpu;
-} GskGLBufferShadow;
-
typedef struct _GskGLBuffer
{
- GArray *buffer;
- GskGLBufferShadow shadows[GSK_GL_BUFFER_N_BUFFERS];
- GLenum target;
- guint current;
- guint element_size;
+ guint8 *buffer;
+ guint buffer_pos;
+ guint buffer_len;
+ guint count;
+ GLenum target;
+ guint element_size;
} GskGLBuffer;
GskGLBuffer *gsk_gl_buffer_new (GLenum target,
guint element_size);
void gsk_gl_buffer_free (GskGLBuffer *buffer);
-void gsk_gl_buffer_submit (GskGLBuffer *buffer);
+GLuint gsk_gl_buffer_submit (GskGLBuffer *buffer);
static inline gpointer
gsk_gl_buffer_advance (GskGLBuffer *buffer,
guint count,
guint *offset)
{
- *offset = buffer->buffer->len;
- g_array_set_size (buffer->buffer, buffer->buffer->len + count);
- return (guint8 *)buffer->buffer->data + (*offset * buffer->element_size);
+ gpointer ret;
+ gsize to_alloc = count * buffer->element_size;
+
+ if G_UNLIKELY (buffer->buffer_pos + to_alloc > buffer->buffer_len)
+ {
+ buffer->buffer_len *= 2;
+ buffer->buffer = g_realloc (buffer->buffer, buffer->buffer_len);
+ }
+
+ *offset = buffer->count;
+ ret = buffer->buffer + buffer->buffer_pos;
+
+ buffer->buffer_pos += to_alloc;
+ buffer->count += count;
+
+ return ret;
}
static inline guint
gsk_gl_buffer_get_offset (GskGLBuffer *buffer)
{
- return buffer->buffer->len;
+ return buffer->count;
}
G_END_DECLS
diff --git a/gsk/next/gskglcommandqueue.c b/gsk/next/gskglcommandqueue.c
index 2d37b7e14d..d89da4e33d 100644
--- a/gsk/next/gskglcommandqueue.c
+++ b/gsk/next/gskglcommandqueue.c
@@ -936,6 +936,7 @@ gsk_gl_command_queue_execute (GskGLCommandQueue *self,
guint n_binds = 0;
guint n_fbos = 0;
guint n_uniforms = 0;
+ guint vbo_id;
g_return_if_fail (GSK_IS_GL_COMMAND_QUEUE (self));
g_return_if_fail (self->in_draw == FALSE);
@@ -961,7 +962,7 @@ gsk_gl_command_queue_execute (GskGLCommandQueue *self,
glGenVertexArrays (1, &vao_id);
glBindVertexArray (vao_id);
- gsk_gl_buffer_submit (self->vertices);
+ vbo_id = gsk_gl_buffer_submit (self->vertices);
/* 0 = position location */
glEnableVertexAttribArray (0);
@@ -1110,6 +1111,7 @@ gsk_gl_command_queue_execute (GskGLCommandQueue *self,
next_batch_index = batch->any.next_batch_index;
}
+ glDeleteBuffers (1, &vbo_id);
glDeleteVertexArrays (1, &vao_id);
gdk_profiler_set_int_counter (self->metrics.n_binds, n_binds);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]