[Glamor] [PATCH] Fallback to pixman when trapezoid mask is big.

Zhigang Gong zhigang.gong at linux.intel.com
Tue Aug 7 01:27:53 PDT 2012


Junyan,

Just as we discussed offline, I'm ok with this patch currently. We can
further optimize the shaders in next release.
Here is a quick test on my SNB platform. In general, we get performance gain
with this commit.

Speedups
========
 xlib             grads-heat-map  1234.91 (1290.04 3.04%) -> 604.95 (607.98
10.65%):  2.04x speedup
 xlib           firefox-fishbowl  35030.31 (35058.47 1.12%) -> 25650.82
(25700.15 0.73%):  1.37x speedup
 xlib          firefox-asteroids  6994.34 (7073.67 1.19%) -> 5619.71
(5891.85 3.12%):  1.24x speedup
 xlib         swfdec-giant-steps  1715.79 (1724.21 0.24%) -> 1446.59
(1455.65 0.31%):  1.19x speedup
 xlib           firefox-fishtank  31585.41 (31834.41 1.93%) -> 27333.31
(27334.93 0.03%):  1.16x speedup
 xlib       firefox-canvas-alpha  29681.81 (29762.79 0.21%) -> 26207.22
(26288.66 0.17%):  1.13x speedup
 xlib             firefox-canvas  42771.43 (42903.96 0.16%) -> 39805.82
(40106.03 0.47%):  1.07x speedup
Slowdowns
=========
 xlib          firefox-talos-svg  13510.84 (13698.29 0.66%) -> 14411.74
(14446.91 0.13%):  1.07x slowdown

CC to Michel, Would you please test the performance on your platform and
report the result? The threshold pixman
size is from testing and should be platform dependent, so they are may not
the best choice on your platform. 

Actually this is a tradeoff currently. We want to release version 0.5 soon,
and want to start development cycle for next
version shortly. Eventually, we need to optimize the shader and avoid the
complexy edge detection for each pixels in
the pixel shader. We may even need to consider different antialiasing
algorithm.

Thanks.

> -----Original Message-----
> From:
> glamor-bounces+zhigang.gong=linux.intel.com at lists.freedesktop.org
> [mailto:glamor-bounces+zhigang.gong=linux.intel.com at lists.freedesktop.o
> rg] On Behalf Of junyan.he at linux.intel.com
> Sent: Tuesday, August 07, 2012 5:02 AM
> To: zhigang.gong at linux.intel.com; glamor at lists.freedesktop.org
> Cc: Junyan He
> Subject: [Glamor] [PATCH] Fallback to pixman when trapezoid mask is big.
> 
> From: Junyan He <junyan.he at linux.intel.com>
> 
>  The trapezoid generating speed of the shader is relatively  slower when
> the trapezoid area is big. We fallback when  the trapezoid's width and
> height is bigger enough.
>  The big traps number will also slow down the render because  of the
> VBO size. We fallback if ntrap > 256
> 
> Signed-off-by: Junyan He <junyan.he at linux.intel.com>
> ---
>  src/glamor_priv.h      |   2 +-
>  src/glamor_trapezoid.c | 104
> +++++++++++++++++++++++++++++++++++--------------
>  2 files changed, 75 insertions(+), 31 deletions(-)
> 
> diff --git a/src/glamor_priv.h b/src/glamor_priv.h index 11d09c4..1830b56
> 100644
> --- a/src/glamor_priv.h
> +++ b/src/glamor_priv.h
> @@ -1016,7 +1016,7 @@ glamor_composite_rectangles(CARD8	 op,
> 
>  #define GLAMOR_PIXMAP_DYNAMIC_UPLOAD
>  #define GLAMOR_GRADIENT_SHADER
> -//#define GLAMOR_TRAPEZOID_SHADER
> +#define GLAMOR_TRAPEZOID_SHADER
>  #define GLAMOR_TEXTURED_LARGE_PIXMAP 1
>  #define WALKAROUND_LARGE_TEXTURE_MAP
>  #if 0
> diff --git a/src/glamor_trapezoid.c b/src/glamor_trapezoid.c index
> 7813d82..7bb75f5 100644
> --- a/src/glamor_trapezoid.c
> +++ b/src/glamor_trapezoid.c
> @@ -36,6 +36,28 @@
>  #include "mipict.h"
>  #include "fbpict.h"
> 
> +static xFixed
> +_glamor_linefixedX (xLineFixed *l, xFixed y, Bool ceil) {
> +	xFixed dx = l->p2.x - l->p1.x;
> +	xFixed_32_32 ex = (xFixed_32_32) (y - l->p1.y) * dx;
> +	xFixed dy = l->p2.y - l->p1.y;
> +	if (ceil)
> +		ex += (dy - 1);
> +	return l->p1.x + (xFixed) (ex / dy);
> +}
> +
> +static xFixed
> +_glamor_linefixedY (xLineFixed *l, xFixed x, Bool ceil) {
> +	xFixed dy = l->p2.y - l->p1.y;
> +	xFixed_32_32 ey = (xFixed_32_32) (x - l->p1.x) * dy;
> +	xFixed dx = l->p2.x - l->p1.x;
> +	if (ceil)
> +		ey += (dx - 1);
> +	return l->p1.y + (xFixed) (ey / dx);
> +}
> +
>  #ifdef GLAMOR_TRAPEZOID_SHADER
> 
>  #define GLAMOR_VERTEX_TOP_BOTTOM  (GLAMOR_VERTEX_SOURCE +
> 1) @@ -72,28 +94,6 @@ _glamor_lines_crossfixedY (xLineFixed *l,
> xLineFixed *r)
>  	return 0xFFFFFFFF;
>  }
> 
> -static xFixed
> -_glamor_linefixedX (xLineFixed *l, xFixed y, Bool ceil) -{
> -	xFixed dx = l->p2.x - l->p1.x;
> -	xFixed_32_32 ex = (xFixed_32_32) (y - l->p1.y) * dx;
> -	xFixed dy = l->p2.y - l->p1.y;
> -	if (ceil)
> -		ex += (dy - 1);
> -	return l->p1.x + (xFixed) (ex / dy);
> -}
> -
> -static xFixed
> -_glamor_linefixedY (xLineFixed *l, xFixed x, Bool ceil) -{
> -	xFixed dy = l->p2.y - l->p1.y;
> -	xFixed_32_32 ey = (xFixed_32_32) (x - l->p1.x) * dy;
> -	xFixed dx = l->p2.x - l->p1.x;
> -	if (ceil)
> -		ey += (dx - 1);
> -	return l->p1.y + (xFixed) (ey / dx);
> -}
> -
>  static Bool
>  point_inside_trapezoid(int point[2], xTrapezoid * trap, xFixed cut_y)
> { @@ -1601,6 +1601,45 @@ glamor_create_mask_picture(ScreenPtr
> screen,
>  	return picture;
>  }
> 
> +static int
> +_glamor_trapezoid_bounds (int ntrap, xTrapezoid *traps, BoxPtr box) {
> +	box->y1 = MAXSHORT;
> +	box->y2 = MINSHORT;
> +	box->x1 = MAXSHORT;
> +	box->x2 = MINSHORT;
> +	int has_large_trapezoid = 0;
> +
> +	for (; ntrap; ntrap--, traps++) {
> +		INT16 x1, y1, x2, y2;
> +
> +		if (!xTrapezoidValid(traps))
> +			continue;
> +		y1 = xFixedToInt (traps->top);
> +		if (y1 < box->y1)
> +			box->y1 = y1;
> +
> +		y2 = xFixedToInt (xFixedCeil (traps->bottom));
> +		if (y2 > box->y2)
> +			box->y2 = y2;
> +
> +		x1 = xFixedToInt (min (_glamor_linefixedX (&traps->left,
> traps->top, FALSE),
> +		                  _glamor_linefixedX (&traps->left,
> traps->bottom, FALSE)));
> +		if (x1 < box->x1)
> +			box->x1 = x1;
> +
> +		x2 = xFixedToInt (xFixedCeil (max (_glamor_linefixedX
> (&traps->right, traps->top, TRUE),
> +		                  _glamor_linefixedX (&traps->right,
> traps->bottom, TRUE))));
> +		if (x2 > box->x2)
> +			box->x2 = x2;
> +
> +		if (!has_large_trapezoid && (x2 - x1) > 256 && (y2 - y1) >
32)
> +			has_large_trapezoid = 1;
> +	}
> +
> +	return has_large_trapezoid;
> +}
> +
>  /**
>   * glamor_trapezoids will first try to create a trapezoid mask using
> shader,
>   * if failed, miTrapezoids will generate trapezoid mask accumulating in
> @@ -1621,6 +1660,7 @@ _glamor_trapezoids(CARD8 op,
>  	PixmapPtr pixmap;
>  	pixman_image_t *image = NULL;
>  	int ret = 0;
> +	int has_large_trapezoid;
> 
>  	/* If a mask format wasn't provided, we get to choose, but behavior
> should
>  	 * be as if there was no temporary mask the traps were accumulated
> into.
> @@ -1638,10 +1678,10 @@ _glamor_trapezoids(CARD8 op,
>  		return TRUE;
>  	}
> 
> -	miTrapezoidBounds(ntrap, traps, &bounds);
> +	has_large_trapezoid = _glamor_trapezoid_bounds(ntrap, traps,
> &bounds);
>  	DEBUGF("The bounds for all traps is: bounds.x1 = %d, bounds.x2 = %d,
> "
> -	       "bounds.y1 = %d, bounds.y2 = %d\n", bounds.x1, bounds.x2,
> -	       bounds.y1, bounds.y2);
> +	       "bounds.y1 = %d, bounds.y2 = %d, ---- ntrap = %d\n",
> bounds.x1,
> +	       bounds.x2, bounds.y1, bounds.y2, ntrap);
> 
>  	if (bounds.y1 >= bounds.y2 || bounds.x1 >= bounds.x2)
>  		return TRUE;
> @@ -1666,16 +1706,20 @@ _glamor_trapezoids(CARD8 op,
>  	   When the depth is not 1, AA is needed and we use a shader to
> generate
>  	   a temp mask pixmap.
>  	 */
> -	if(mask_format->depth == 1) {
> +	if (mask_format->depth == 1) {
>  		ret = _glamor_trapezoids_with_shader(op, src, dst,
mask_format,
>  		                                     x_src, y_src, ntrap,
> traps);
>  		if(ret)
>  			return TRUE;
>  	} else {
> -		/*  The precise mode is that we sample the trapezoid on the
> centre points of
> -		    an (2*n+1)x(2*n-1) subpixel grid. It is computationally
> expensive in shader
> -		    and we use inside area ratio to replace it if the
polymode ==
> Imprecise. */
> -		if(dst->polyMode == PolyModeImprecise) {
> +		if (has_large_trapezoid || ntrap > 256) {
> +			/* The shader speed is relative slower than pixman
when
> generating big chunk
> +			   trapezoid mask. We fallback to pixman to improve
the
> performance. */
> +			;
> +		} else if (dst->polyMode == PolyModeImprecise) {
> +			/*  The precise mode is that we sample the trapezoid
on
> the centre points of
> +			    an (2*n+1)x(2*n-1) subpixel grid. It is
computationally
> expensive in shader
> +			    and we use inside area ratio to replace it if
the
> polymode ==
> +Imprecise. */
>  			picture = glamor_create_mask_picture(screen, dst,
> mask_format,
>  			          width, height, 1);
>  			if (!picture)
> --
> 1.7.11.2
> 
> _______________________________________________
> Glamor mailing list
> Glamor at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/glamor



More information about the Glamor mailing list