From 32a7438bf79573100862ad91c5722d12623a8bf9 Mon Sep 17 00:00:00 2001 From: Zhigang Gong Date: Tue, 3 Jul 2012 18:24:07 +0800 Subject: [PATCH] glamor_copyarea: Use blitcopy if current state is not render. Practically, for pure 2D blit, the blit copy is much faster than textured copy. For the x11perf copywinwin100, it's about 3x faster. But if we have heavy rendering/compositing, then use textured copy will get much better (>30%)performance for most of the cases. So we simply add a data element to track current state. For rendering state we use textured copy, otherwise, we use blit copy. Signed-off-by: Zhigang Gong --- glamor/glamor.c | 5 +++++ glamor/glamor_copyarea.c | 5 ++++- glamor/glamor_fill.c | 43 ++-------------------------------------- glamor/glamor_priv.h | 8 +++++++- glamor/glamor_render.c | 4 +++- glamor/glamor_tile.c | 3 +++ 6 files changed, 24 insertions(+), 44 deletions(-) diff --git a/glamor/glamor.c b/glamor/glamor.c index 01f6a9a8ff..8b7dc930d1 100644 --- a/glamor/glamor.c +++ b/glamor/glamor.c @@ -225,6 +225,11 @@ glamor_block_handler(ScreenPtr screen) dispatch->glFlush(); glamor_fbo_expire(glamor_priv); glamor_put_dispatch(glamor_priv); + if (glamor_priv->state == RENDER_STATE + && glamor_priv->render_idle_cnt++ > RENDER_IDEL_MAX) { + glamor_priv->state = IDLE_STATE; + glamor_priv->render_idle_cnt = 0; + } } static void diff --git a/glamor/glamor_copyarea.c b/glamor/glamor_copyarea.c index ee6f8120ff..299417927d 100644 --- a/glamor/glamor_copyarea.c +++ b/glamor/glamor_copyarea.c @@ -137,6 +137,7 @@ glamor_copy_n_to_n_fbo_blit(DrawablePtr src, } } glamor_put_dispatch(glamor_priv); + glamor_priv->state = BLIT_STATE; return TRUE; } #endif @@ -257,6 +258,8 @@ glamor_copy_n_to_n_textured(DrawablePtr src, dispatch->glUseProgram(0); /* The source texture is bound to a fbo, we have to flush it here. */ glamor_put_dispatch(glamor_priv); + glamor_priv->state = RENDER_STATE; + glamor_priv->render_idle_cnt = 0; return TRUE; } @@ -315,7 +318,7 @@ __glamor_copy_n_to_n(DrawablePtr src, dx, dy, src_pixmap, dst_pixmap); #ifndef GLAMOR_GLES2 - if ((overlaped + if ((overlaped || glamor_priv->state != RENDER_STATE || !src_pixmap_priv->base.gl_tex || !dst_pixmap_priv->base.gl_tex) && glamor_copy_n_to_n_fbo_blit(src, dst, gc, box, nbox, dx, dy)) { diff --git a/glamor/glamor_fill.c b/glamor/glamor_fill.c index 2163c9461b..1d81aea520 100644 --- a/glamor/glamor_fill.c +++ b/glamor/glamor_fill.c @@ -259,47 +259,8 @@ _glamor_solid_boxes(PixmapPtr pixmap, BoxPtr box, int nbox, float *color) dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_POS); dispatch->glUseProgram(0); glamor_put_dispatch(glamor_priv); -} - -static void -_glamor_solid(PixmapPtr pixmap, int x, int y, int width, int height, - float *color) -{ - ScreenPtr screen = pixmap->drawable.pScreen; - glamor_screen_private *glamor_priv = - glamor_get_screen_private(screen); - glamor_pixmap_private *pixmap_priv = - glamor_get_pixmap_private(pixmap); - glamor_gl_dispatch *dispatch; - int x1 = x; - int x2 = x + width; - int y1 = y; - int y2 = y + height; - float vertices[8]; - GLfloat xscale, yscale; - - glamor_set_destination_pixmap_priv_nc(pixmap_priv); - - dispatch = glamor_get_dispatch(glamor_priv); - dispatch->glUseProgram(glamor_priv->solid_prog); - - dispatch->glUniform4fv(glamor_priv->solid_color_uniform_location, - 1, color); - - dispatch->glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT, - GL_FALSE, 2 * sizeof(float), - vertices); - dispatch->glEnableVertexAttribArray(GLAMOR_VERTEX_POS); - pixmap_priv_get_dest_scale(pixmap_priv, &xscale, &yscale); - - glamor_set_normalize_vcoords(pixmap_priv, xscale, yscale, - x1, y1, - x2, y2, - glamor_priv->yInverted, vertices); - dispatch->glDrawArrays(GL_TRIANGLE_FAN, 0, 4); - dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_POS); - dispatch->glUseProgram(0); - glamor_put_dispatch(glamor_priv); + glamor_priv->state = RENDER_STATE; + glamor_priv->render_idle_cnt = 0; } Bool diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h index a7d4fe7838..0703c076d6 100644 --- a/glamor/glamor_priv.h +++ b/glamor/glamor_priv.h @@ -199,7 +199,6 @@ typedef struct { uint16_t evict; } glamor_glyph_cache_t; - #include "glamor_gl_dispatch.h" struct glamor_saved_procs { @@ -235,6 +234,11 @@ struct glamor_saved_procs { #define GLAMOR_TICK_AFTER(t0, t1) \ (((int)(t1) - (int)(t0)) < 0) +#define IDLE_STATE 0 +#define RENDER_STATE 1 +#define BLIT_STATE 2 +#define RENDER_IDEL_MAX 32 + typedef struct glamor_screen_private { struct glamor_gl_dispatch _dispatch; int yInverted; @@ -296,6 +300,8 @@ typedef struct glamor_screen_private { char delayed_fallback_string[GLAMOR_DELAYED_STRING_MAX + 1]; int delayed_fallback_pending; int flags; + int state; + unsigned int render_idle_cnt; ScreenPtr screen; } glamor_screen_private; diff --git a/glamor/glamor_render.c b/glamor/glamor_render.c index b82c7c3275..60fc2f658c 100644 --- a/glamor/glamor_render.c +++ b/glamor/glamor_render.c @@ -1444,6 +1444,8 @@ glamor_composite_with_shader(CARD8 op, #endif DEBUGF("finish rendering.\n"); dispatch->glUseProgram(0); + glamor_priv->state = RENDER_STATE; + glamor_priv->render_idle_cnt = 0; if (saved_source_format) source->format = saved_source_format; glamor_put_dispatch(glamor_priv); @@ -1665,6 +1667,7 @@ glamor_composite_clipped_region(CARD8 op, prect[i].y_dst = box[i].y1; prect[i].width = box[i].x2 - box[i].x1; prect[i].height = box[i].y2 - box[i].y1; + DEBUGF("dest %d %d \n", prect[i].x_dst, prect[i].y_dst); } ok = glamor_composite_with_shader(op, temp_src, temp_mask, dest, temp_src_priv, temp_mask_priv, @@ -1722,7 +1725,6 @@ _glamor_composite(CARD8 op, DrawablePtr saved_source_drawable; DrawablePtr saved_mask_drawable; int force_clip = 0; - dest_pixmap_priv = glamor_get_pixmap_private(dest_pixmap); if (source->pDrawable) { diff --git a/glamor/glamor_tile.c b/glamor/glamor_tile.c index 7809e8bf83..60486cfc09 100644 --- a/glamor/glamor_tile.c +++ b/glamor/glamor_tile.c @@ -185,6 +185,9 @@ _glamor_tile(PixmapPtr pixmap, PixmapPtr tile, dispatch->glDisableVertexAttribArray(GLAMOR_VERTEX_POS); dispatch->glUseProgram(0); glamor_put_dispatch(glamor_priv); + + glamor_priv->state = RENDER_STATE; + glamor_priv->render_idle_cnt = 0; } Bool