[cairo-commit] 3 commits - src/cairo-egl-context.c src/cairo-gl-composite.c src/cairo-gl-device.c src/cairo-gl-info.c src/cairo-gl-private.h

Bryce Harrington bryce at kemper.freedesktop.org
Fri Sep 19 17:33:29 PDT 2014


 src/cairo-egl-context.c  |    6 ++++++
 src/cairo-gl-composite.c |    3 ++-
 src/cairo-gl-device.c    |    4 +++-
 src/cairo-gl-info.c      |   20 ++++++++++++++++++++
 src/cairo-gl-private.h   |    9 +++++++--
 5 files changed, 38 insertions(+), 4 deletions(-)

New commits:
commit 402b456a3229f6c7f1550e66bbd8125c253a4ff1
Author: Bryce Harrington <bryce at osg.samsung.com>
Date:   Thu Jul 31 17:58:15 2014 -0700

    gl: Increase default VBO size on GL to 1M
    
    The default VBO size was reduced from 256k to 16k because embedded
    devices had trouble with the larger memory demands of a big VBO.  My
    testing[1] indicates this incurred a 5% performance loss on at least one
    of Cairo's performance tests.  Further testing showed that with
    late-model graphics cards, further performance benefits can be seen with
    even larger VBO sizes, up to 8.3% at 1M for Intel.
    
    Now that we can set the vbo size differently for different backends, set
    it to the lower value (16k) for EGL, and higher (1M) for GL.
    
    1: http://www.bryceharrington.org/wordpress/2013/08/vbo-size/
    
    Signed-off-by: Bryce Harrington <bryce at osg.samsung.com>

diff --git a/src/cairo-egl-context.c b/src/cairo-egl-context.c
index bb0772a..bf704c6 100644
--- a/src/cairo-egl-context.c
+++ b/src/cairo-egl-context.c
@@ -244,6 +244,12 @@ cairo_egl_device_create (EGLDisplay dpy, EGLContext egl)
 	return _cairo_gl_context_create_in_error (status);
     }
 
+    /* Tune the default VBO size to reduce overhead on embedded devices.
+     * This smaller size means that flushing needs to be done more often,
+     * but it is less demanding of scarce memory on embedded devices.
+     */
+    ctx->base.vbo_size = 16*1024;
+
     eglMakeCurrent (dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
 
     return &ctx->base.base;
diff --git a/src/cairo-gl-private.h b/src/cairo-gl-private.h
index c1104b6..cb915c8 100644
--- a/src/cairo-gl-private.h
+++ b/src/cairo-gl-private.h
@@ -95,7 +95,7 @@
  * but larger means hogging more memory and can cause trouble for drivers
  * (especially on embedded devices). Use the CAIRO_GL_VBO_SIZE environment
  * variable to set this to a different size. */
-#define CAIRO_GL_VBO_SIZE_DEFAULT (16*1024)
+#define CAIRO_GL_VBO_SIZE_DEFAULT (1024*1024)
 
 typedef struct _cairo_gl_surface cairo_gl_surface_t;
 
commit aa820c13d78a4fc1c87da0da9012ee532aa2d50a
Author: Bryce Harrington <bryce at osg.samsung.com>
Date:   Thu Jul 31 17:43:03 2014 -0700

    gl: Track the VBO size as a property of the ctx
    
    Change suggested by Chris Wilson.  This will enable setting different
    vbo sizes for GL vs. EGL.
    
    Signed-off-by: Bryce Harrington <bryce at osg.samsung.com>

diff --git a/src/cairo-gl-composite.c b/src/cairo-gl-composite.c
index 65b0f26..b50f9a7 100644
--- a/src/cairo-gl-composite.c
+++ b/src/cairo-gl-composite.c
@@ -875,7 +875,8 @@ _cairo_gl_composite_prepare_buffer (cairo_gl_context_t *ctx,
 	ctx->primitive_type = primitive_type;
     }
 
-    if (ctx->vb_offset + n_vertices * ctx->vertex_size > _cairo_gl_get_vbo_size())
+    assert(ctx->vbo_size > 0);
+    if (ctx->vb_offset + n_vertices * ctx->vertex_size > ctx->vbo_size)
 	_cairo_gl_composite_flush (ctx);
 }
 
diff --git a/src/cairo-gl-device.c b/src/cairo-gl-device.c
index dc2b6d6..7235d9a 100644
--- a/src/cairo-gl-device.c
+++ b/src/cairo-gl-device.c
@@ -297,7 +297,9 @@ _cairo_gl_context_init (cairo_gl_context_t *ctx)
     if (unlikely (status))
         return status;
 
-    ctx->vb = malloc (_cairo_gl_get_vbo_size());
+    ctx->vbo_size = _cairo_gl_get_vbo_size();
+
+    ctx->vb = malloc (ctx->vbo_size);
     if (unlikely (ctx->vb == NULL)) {
 	    _cairo_cache_fini (&ctx->gradients);
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
diff --git a/src/cairo-gl-info.c b/src/cairo-gl-info.c
index c47033e..66b0b50 100644
--- a/src/cairo-gl-info.c
+++ b/src/cairo-gl-info.c
@@ -73,21 +73,19 @@ _cairo_gl_get_flavor (void)
     return flavor;
 }
 
-long
+unsigned long
 _cairo_gl_get_vbo_size (void)
 {
-    static long vbo_size = -1;
+    unsigned long vbo_size;
 
-    if (vbo_size < 0) {
-        const char *env = getenv ("CAIRO_GL_VBO_SIZE");
-        if (env == NULL) {
-            vbo_size = CAIRO_GL_VBO_SIZE_DEFAULT;
-	} else {
-	    errno = 0;
-	    vbo_size = strtol (env, NULL, 10);
-	    assert (errno == 0);
-	    assert (vbo_size > 0);
-	}
+    const char *env = getenv ("CAIRO_GL_VBO_SIZE");
+    if (env == NULL) {
+        vbo_size = CAIRO_GL_VBO_SIZE_DEFAULT;
+    } else {
+	errno = 0;
+	vbo_size = strtol (env, NULL, 10);
+	assert (errno == 0);
+	assert (vbo_size > 0);
     }
 
     return vbo_size;
diff --git a/src/cairo-gl-private.h b/src/cairo-gl-private.h
index 79b67a5..c1104b6 100644
--- a/src/cairo-gl-private.h
+++ b/src/cairo-gl-private.h
@@ -362,6 +362,7 @@ struct _cairo_gl_context {
     cairo_gl_operand_t operands[2];
     cairo_bool_t spans;
 
+    unsigned int vbo_size;
     unsigned int vb_offset;
     unsigned int vertex_size;
     cairo_region_t *clip_region;
@@ -703,7 +704,7 @@ _cairo_gl_get_version (void);
 cairo_private cairo_gl_flavor_t
 _cairo_gl_get_flavor (void);
 
-cairo_private long
+cairo_private unsigned long
 _cairo_gl_get_vbo_size (void);
 
 cairo_private cairo_bool_t
commit 036f47c34579259fa86d0193797b6f83fe79bbeb
Author: Bryce Harrington <b.harrington at samsung.com>
Date:   Mon Aug 19 19:38:26 2013 -0700

    cairo-gl: Make VBO size run-time settable
    
    The default VBO size was reduced from 256k to 16k last year in commit
    90860241 due to problems with larger VBOs on embedded hardware.
    However, that change resulted in a 5% performance impact to the
    firefox-fishbowl benchmark when using the spans or traps compositors.
    
    This patch doesn't change the VBO size, but does permit it to be
    altered via an environment variable, to facilitate testing.
    
    Signed-off-by: Bryce Harrington <bryce at osg.samsung.com>

diff --git a/src/cairo-gl-composite.c b/src/cairo-gl-composite.c
index 30b7931..65b0f26 100644
--- a/src/cairo-gl-composite.c
+++ b/src/cairo-gl-composite.c
@@ -875,7 +875,7 @@ _cairo_gl_composite_prepare_buffer (cairo_gl_context_t *ctx,
 	ctx->primitive_type = primitive_type;
     }
 
-    if (ctx->vb_offset + n_vertices * ctx->vertex_size > CAIRO_GL_VBO_SIZE)
+    if (ctx->vb_offset + n_vertices * ctx->vertex_size > _cairo_gl_get_vbo_size())
 	_cairo_gl_composite_flush (ctx);
 }
 
diff --git a/src/cairo-gl-device.c b/src/cairo-gl-device.c
index 054f145..dc2b6d6 100644
--- a/src/cairo-gl-device.c
+++ b/src/cairo-gl-device.c
@@ -297,7 +297,7 @@ _cairo_gl_context_init (cairo_gl_context_t *ctx)
     if (unlikely (status))
         return status;
 
-    ctx->vb = malloc (CAIRO_GL_VBO_SIZE);
+    ctx->vb = malloc (_cairo_gl_get_vbo_size());
     if (unlikely (ctx->vb == NULL)) {
 	    _cairo_cache_fini (&ctx->gradients);
 	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
diff --git a/src/cairo-gl-info.c b/src/cairo-gl-info.c
index 12a618d..c47033e 100644
--- a/src/cairo-gl-info.c
+++ b/src/cairo-gl-info.c
@@ -29,6 +29,8 @@
  *      Alexandros Frantzis <alexandros.frantzis at linaro.org>
  */
 
+#include <errno.h>
+
 #include "cairoint.h"
 #include "cairo-gl-private.h"
 
@@ -71,6 +73,26 @@ _cairo_gl_get_flavor (void)
     return flavor;
 }
 
+long
+_cairo_gl_get_vbo_size (void)
+{
+    static long vbo_size = -1;
+
+    if (vbo_size < 0) {
+        const char *env = getenv ("CAIRO_GL_VBO_SIZE");
+        if (env == NULL) {
+            vbo_size = CAIRO_GL_VBO_SIZE_DEFAULT;
+	} else {
+	    errno = 0;
+	    vbo_size = strtol (env, NULL, 10);
+	    assert (errno == 0);
+	    assert (vbo_size > 0);
+	}
+    }
+
+    return vbo_size;
+}
+
 cairo_bool_t
 _cairo_gl_has_extension (const char *ext)
 {
diff --git a/src/cairo-gl-private.h b/src/cairo-gl-private.h
index 8379abc..79b67a5 100644
--- a/src/cairo-gl-private.h
+++ b/src/cairo-gl-private.h
@@ -93,8 +93,9 @@
 
 /* VBO size that we allocate, smaller size means we gotta flush more often,
  * but larger means hogging more memory and can cause trouble for drivers
- * (especially on embedded devices). */
-#define CAIRO_GL_VBO_SIZE (16*1024)
+ * (especially on embedded devices). Use the CAIRO_GL_VBO_SIZE environment
+ * variable to set this to a different size. */
+#define CAIRO_GL_VBO_SIZE_DEFAULT (16*1024)
 
 typedef struct _cairo_gl_surface cairo_gl_surface_t;
 
@@ -702,6 +703,9 @@ _cairo_gl_get_version (void);
 cairo_private cairo_gl_flavor_t
 _cairo_gl_get_flavor (void);
 
+cairo_private long
+_cairo_gl_get_vbo_size (void);
+
 cairo_private cairo_bool_t
 _cairo_gl_has_extension (const char *ext);
 


More information about the cairo-commit mailing list