[Glamor] glamor: Changes to 'master'

Zhigang Gong zhigang.gong at linux.intel.com
Thu Jul 12 00:51:58 PDT 2012


On Wed, Jul 11, 2012 at 01:00:12PM +0200, Michel Dänzer wrote:
> On Mit, 2012-07-11 at 00:59 -0700, Zhigang Gong wrote: 
> > 
> > commit 593bd206bf2794dc1450e8e7d20142b8d0ca074b
> > Author: Zhigang Gong <zhigang.gong at linux.intel.com>
> > Date:   Tue Jun 26 15:39:24 2012 +0800
> > 
> >     glamor_render: Don't allocate buffer for vbo each time.
> >     
> >     We can reuse the last one if the last one is big enough
> >     to contain current vertext data. In the meantime, Use
> >     MapBufferRange instead of MapBuffer.
> >     
> >     Testing shows, this patch brings some benefit for
> >     aa10text/rgb10text. Not too much, but indeed faster.
> >     
> >     Signed-off-by: Zhigang Gong <zhigang.gong at linux.intel.com>
> 
> This commit decreases glyph throughput by about a factor of 4 with the
> r600g driver on an RS880 laptop.
> 
> AFAICT the new code always maps the VBO from offset 0, which I'm not
> sure can be expected to perform well. However, I've tried sliding the
> mapping range over a larger VBO, and it doesn't seem to help. Maybe the
> r600g driver doesn't handle this kind of usage very well yet.

Without this commit, each time we start to flush the compositing, we
need to call glBufferData(GL_ARRAY_BUFFER,..) to allocate resources
on GPU each time. With this commit, we will allocate new buffer only
if current required buffer if larger than the allocated buffer. If current
required buffer can be fit into the allocated buffer, we only need to map
the needed range to vma.

> 
> Still, how would you feel about reverting this change for now?
You can see that this commit does save the time to create new vertex
buffers on GPU side each time. And on Intel's platform, this commit
can get about 3% gain on the x11perf -aa10text. So IMO, it's not a
good idea to revert it.

I found an alternative way for yor, I added a new patch to disable the vbo
usage at all. And we allocated vb array in system memory directly. Please
check the below patch out and test on your platform. You just need to
change the use_vbo to 0 at glamor_priv.h. Does that work for you?

The patch is as below:

>From 38436c95700f74f1744b9c791b70247c098b522e Mon Sep 17 00:00:00 2001
From: Zhigang Gong <zhigang.gong at linux.intel.com>
Date: Thu, 12 Jul 2012 15:41:26 +0800
Subject: [PATCH] glamor_render: Add one macro to enable/disable vbo usage.

Some platforms may not handle vbo glMapBufferRange
efficiently, we add this option to disable the usage
of vbo but use system memory directly. To disable the vbo
usage, we need to modify the glamor_priv.h's corresponding
line to as below.

Signed-off-by: Zhigang Gong <zhigang.gong at linux.intel.com>
---
 src/glamor.c        |    2 ++
 src/glamor_priv.h   |    6 ++++++
 src/glamor_render.c |   15 ++++++++++-----
 3 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/src/glamor.c b/src/glamor.c
index 8b7dc93..a6e6a3f 100644
--- a/src/glamor.c
+++ b/src/glamor.c
@@ -308,11 +308,13 @@ glamor_init(ScreenPtr screen, unsigned int flags)
 		ErrorF("Require OpenGL version 1.3 or latter.\n");
 		goto fail;
 	}
+	glamor_priv->options.use_vbo = GLAMOR_USE_VBO;
 #else
 	if (gl_version < GLAMOR_GL_VERSION_ENCODE(2, 0)) {
 		ErrorF("Require Open GLES2.0 or latter.\n");
 		goto fail;
 	}
+	glamor_priv->options.use_vbo = FALSE;
 #endif
 
 	glamor_gl_dispatch_init(screen, &glamor_priv->_dispatch, gl_version);
diff --git a/src/glamor_priv.h b/src/glamor_priv.h
index 0703c07..015d1a3 100644
--- a/src/glamor_priv.h
+++ b/src/glamor_priv.h
@@ -181,6 +181,10 @@ enum glamor_gl_flavor {
 	GLAMOR_GL_ES2		// OPENGL ES2.0 API
 };
 
+struct glamor_options {
+	int use_vbo:1;	
+};
+
 #define GLAMOR_CREATE_PIXMAP_CPU  0x100
 #define GLAMOR_CREATE_PIXMAP_FIXUP 0x101
 #define GLAMOR_CREATE_FBO_NO_FBO   0x103
@@ -244,6 +248,7 @@ typedef struct glamor_screen_private {
 	int yInverted;
 	unsigned int tick;
 	enum glamor_gl_flavor gl_flavor;
+	struct glamor_options options;
 	int has_pack_invert;
 	int has_fbo_blit;
 	int max_fbo_size;
@@ -1013,6 +1018,7 @@ glamor_composite_rectangles(CARD8	 op,
  * fallback the whole process to cpu. Most of the time,
  * this will increase performance obviously. */
 
+#define GLAMOR_USE_VBO 1
 #define GLAMOR_PIXMAP_DYNAMIC_UPLOAD
 #ifndef GLAMOR_GLES2
 #define GLAMOR_GRADIENT_SHADER
diff --git a/src/glamor_render.c b/src/glamor_render.c
index d986e9a..dd53136 100644
--- a/src/glamor_render.c
+++ b/src/glamor_render.c
@@ -404,7 +404,8 @@ glamor_init_composite_shaders(ScreenPtr screen)
 
 	eb_size = GLAMOR_COMPOSITE_VBO_VERT_CNT * sizeof(short) * 2;
 
-	if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
+	if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP
+	    && glamor_priv->options.use_vbo) {
 		dispatch->glBufferData(GL_ELEMENT_ARRAY_BUFFER,
 				       eb_size,
 				       NULL, GL_DYNAMIC_DRAW);
@@ -421,7 +422,8 @@ glamor_init_composite_shaders(ScreenPtr screen)
 		FatalError("fatal error, fail to get element buffer. GL context may be not created correctly.\n");
 	glamor_init_eb(eb, GLAMOR_COMPOSITE_VBO_VERT_CNT);
 
-	if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
+	if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP
+	    && glamor_priv->options.use_vbo) {
 		dispatch->glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER);
 		dispatch->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
 	} else {
@@ -464,7 +466,8 @@ glamor_fini_composite_shaders(ScreenPtr screen)
 				if (shader->prog)
 					dispatch->glDeleteProgram(shader->prog);
 			}
-	if (glamor_priv->gl_flavor != GLAMOR_GL_DESKTOP
+	if ((glamor_priv->gl_flavor != GLAMOR_GL_DESKTOP
+	      || (!glamor_priv->options.use_vbo))
 	    && glamor_priv->vb)
 		free(glamor_priv->vb);
 
@@ -744,7 +747,8 @@ glamor_setup_composite_vbo(ScreenPtr screen, int n_verts)
 
 	dispatch = glamor_get_dispatch(glamor_priv);
 	dispatch->glBindBuffer(GL_ARRAY_BUFFER, glamor_priv->vbo);
-	if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
+	if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP
+	    && glamor_priv->options.use_vbo) {
 		if (need_new_buffer)
 			dispatch->glBufferData(GL_ARRAY_BUFFER,
 					       vert_size,
@@ -828,7 +832,8 @@ glamor_flush_composite_rects(ScreenPtr screen)
 		return;
 
 	dispatch = glamor_get_dispatch(glamor_priv);
-	if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP)
+	if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP
+	    && glamor_priv->options.use_vbo)
 		dispatch->glUnmapBuffer(GL_ARRAY_BUFFER);
 	else {
 
-- 
1.7.4.4




More information about the Glamor mailing list