Commit 069a6d17 authored by Zhigang Gong's avatar Zhigang Gong Committed by Eric Anholt

glamor_composite: Allocate VBO on demand.

Use a fixed VBO is not efficient. Some times we may only has less than
100 verts, and some times we may have larger than 4K verts. We change
it to allocate VBO buffer dynamically, and this can bring about 10%
performance gain for both aa10text/rgb10text and some cairo benchmarks.
Signed-off-by: default avatarZhigang Gong <zhigang.gong@linux.intel.com>
parent 42a0261c
...@@ -290,16 +290,6 @@ glamor_lookup_composite_shader(ScreenPtr screen, struct ...@@ -290,16 +290,6 @@ glamor_lookup_composite_shader(ScreenPtr screen, struct
#define GLAMOR_COMPOSITE_VBO_VERT_CNT 1024 #define GLAMOR_COMPOSITE_VBO_VERT_CNT 1024
static void
glamor_reset_composite_vbo(ScreenPtr screen)
{
glamor_screen_private *glamor_priv =
glamor_get_screen_private(screen);
glamor_priv->vbo_offset = 0;
glamor_priv->vbo_size = GLAMOR_COMPOSITE_VBO_VERT_CNT * sizeof(float) * 2;
glamor_priv->render_nr_verts = 0;
}
static void static void
glamor_init_eb(unsigned short *eb, int vert_cnt) glamor_init_eb(unsigned short *eb, int vert_cnt)
{ {
...@@ -334,7 +324,6 @@ glamor_init_composite_shaders(ScreenPtr screen) ...@@ -334,7 +324,6 @@ glamor_init_composite_shaders(ScreenPtr screen)
glamor_init_eb(eb, GLAMOR_COMPOSITE_VBO_VERT_CNT); glamor_init_eb(eb, GLAMOR_COMPOSITE_VBO_VERT_CNT);
dispatch->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); dispatch->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
dispatch->glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER); dispatch->glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER);
glamor_reset_composite_vbo(screen);
} }
static Bool static Bool
...@@ -395,7 +384,6 @@ glamor_set_composite_texture(ScreenPtr screen, int unit, ...@@ -395,7 +384,6 @@ glamor_set_composite_texture(ScreenPtr screen, int unit,
PicturePtr picture, PicturePtr picture,
glamor_pixmap_private * pixmap_priv) glamor_pixmap_private * pixmap_priv)
{ {
unsigned int no_alpha, no_revert, format, type;
glamor_screen_private *glamor_priv = glamor_screen_private *glamor_priv =
glamor_get_screen_private(screen); glamor_get_screen_private(screen);
glamor_gl_dispatch *dispatch = &glamor_priv->dispatch; glamor_gl_dispatch *dispatch = &glamor_priv->dispatch;
...@@ -555,12 +543,17 @@ glamor_composite_with_copy(CARD8 op, ...@@ -555,12 +543,17 @@ glamor_composite_with_copy(CARD8 op,
} }
static void static void
glamor_setup_composite_vbo(ScreenPtr screen) glamor_setup_composite_vbo(ScreenPtr screen, int n_verts)
{ {
glamor_screen_private *glamor_priv = glamor_screen_private *glamor_priv =
glamor_get_screen_private(screen); glamor_get_screen_private(screen);
glamor_gl_dispatch *dispatch = &glamor_priv->dispatch; glamor_gl_dispatch *dispatch = &glamor_priv->dispatch;
glamor_priv->vbo_offset = 0;
glamor_priv->vbo_offset = 0;
glamor_priv->render_nr_verts = 0;
glamor_priv->vbo_size = n_verts * sizeof(float) * 2;
glamor_priv->vb_stride = 2 * sizeof(float); glamor_priv->vb_stride = 2 * sizeof(float);
if (glamor_priv->has_source_coords) if (glamor_priv->has_source_coords)
glamor_priv->vb_stride += 2 * sizeof(float); glamor_priv->vb_stride += 2 * sizeof(float);
...@@ -569,7 +562,7 @@ glamor_setup_composite_vbo(ScreenPtr screen) ...@@ -569,7 +562,7 @@ glamor_setup_composite_vbo(ScreenPtr screen)
dispatch->glBindBuffer(GL_ARRAY_BUFFER, glamor_priv->vbo); dispatch->glBindBuffer(GL_ARRAY_BUFFER, glamor_priv->vbo);
dispatch->glBufferData(GL_ARRAY_BUFFER, dispatch->glBufferData(GL_ARRAY_BUFFER,
GLAMOR_COMPOSITE_VBO_VERT_CNT * sizeof(float) * 2, n_verts * sizeof(float) * 2,
NULL, GL_DYNAMIC_DRAW); NULL, GL_DYNAMIC_DRAW);
glamor_priv->vb = dispatch->glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); glamor_priv->vb = dispatch->glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
...@@ -644,7 +637,6 @@ glamor_flush_composite_rects(ScreenPtr screen) ...@@ -644,7 +637,6 @@ glamor_flush_composite_rects(ScreenPtr screen)
dispatch->glUnmapBuffer(GL_ARRAY_BUFFER); dispatch->glUnmapBuffer(GL_ARRAY_BUFFER);
dispatch->glDrawElements(GL_TRIANGLES, (glamor_priv->render_nr_verts * 3) / 2, dispatch->glDrawElements(GL_TRIANGLES, (glamor_priv->render_nr_verts * 3) / 2,
GL_UNSIGNED_SHORT, NULL); GL_UNSIGNED_SHORT, NULL);
glamor_reset_composite_vbo(screen);
} }
static void static void
...@@ -653,19 +645,6 @@ glamor_emit_composite_rect(ScreenPtr screen, ...@@ -653,19 +645,6 @@ glamor_emit_composite_rect(ScreenPtr screen,
const float *mask_coords, const float *mask_coords,
const float *dst_coords) const float *dst_coords)
{ {
glamor_screen_private *glamor_priv =
glamor_get_screen_private(screen);
glamor_gl_dispatch *dispatch = &glamor_priv->dispatch;
if (glamor_priv->vbo_offset + 4 * glamor_priv->vb_stride >
glamor_priv->vbo_size) {
glamor_flush_composite_rects(screen);
}
if (glamor_priv->vbo_offset == 0) {
glamor_setup_composite_vbo(screen);
}
glamor_emit_composite_vert(screen, src_coords, mask_coords, glamor_emit_composite_vert(screen, src_coords, mask_coords,
dst_coords, 0); dst_coords, 0);
glamor_emit_composite_vert(screen, src_coords, mask_coords, glamor_emit_composite_vert(screen, src_coords, mask_coords,
...@@ -676,7 +655,6 @@ glamor_emit_composite_rect(ScreenPtr screen, ...@@ -676,7 +655,6 @@ glamor_emit_composite_rect(ScreenPtr screen,
dst_coords, 3); dst_coords, 3);
} }
int pict_format_combine_tab[][3] = { int pict_format_combine_tab[][3] = {
{PICT_TYPE_ARGB, PICT_TYPE_A, PICT_TYPE_ARGB}, {PICT_TYPE_ARGB, PICT_TYPE_A, PICT_TYPE_ARGB},
{PICT_TYPE_ABGR, PICT_TYPE_A, PICT_TYPE_ABGR}, {PICT_TYPE_ABGR, PICT_TYPE_A, PICT_TYPE_ABGR},
...@@ -763,10 +741,7 @@ glamor_composite_with_shader(CARD8 op, ...@@ -763,10 +741,7 @@ glamor_composite_with_shader(CARD8 op,
1, src_yscale = 1; 1, src_yscale = 1;
struct shader_key key; struct shader_key key;
glamor_composite_shader *shader; glamor_composite_shader *shader;
RegionRec region;
float vertices[8], source_texcoords[8], mask_texcoords[8]; float vertices[8], source_texcoords[8], mask_texcoords[8];
int i;
BoxPtr box;
int dest_x_off, dest_y_off; int dest_x_off, dest_y_off;
int source_x_off, source_y_off; int source_x_off, source_y_off;
int mask_x_off, mask_y_off; int mask_x_off, mask_y_off;
...@@ -776,6 +751,8 @@ glamor_composite_with_shader(CARD8 op, ...@@ -776,6 +751,8 @@ glamor_composite_with_shader(CARD8 op,
float src_matrix[9], mask_matrix[9]; float src_matrix[9], mask_matrix[9];
GLfloat source_solid_color[4], mask_solid_color[4]; GLfloat source_solid_color[4], mask_solid_color[4];
dest_pixmap_priv = glamor_get_pixmap_private(dest_pixmap); dest_pixmap_priv = glamor_get_pixmap_private(dest_pixmap);
int vert_stride = 4;
int nrect_max;
if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(dest_pixmap_priv)) { if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(dest_pixmap_priv)) {
glamor_fallback("dest has no fbo.\n"); glamor_fallback("dest has no fbo.\n");
...@@ -1025,6 +1002,7 @@ glamor_composite_with_shader(CARD8 op, ...@@ -1025,6 +1002,7 @@ glamor_composite_with_shader(CARD8 op,
pixmap_priv_get_scale(source_pixmap_priv, &src_xscale, pixmap_priv_get_scale(source_pixmap_priv, &src_xscale,
&src_yscale); &src_yscale);
glamor_picture_get_matrixf(source, src_matrix); glamor_picture_get_matrixf(source, src_matrix);
vert_stride += 4;
} }
if (glamor_priv->has_mask_coords) { if (glamor_priv->has_mask_coords) {
...@@ -1033,72 +1011,89 @@ glamor_composite_with_shader(CARD8 op, ...@@ -1033,72 +1011,89 @@ glamor_composite_with_shader(CARD8 op,
pixmap_priv_get_scale(mask_pixmap_priv, &mask_xscale, pixmap_priv_get_scale(mask_pixmap_priv, &mask_xscale,
&mask_yscale); &mask_yscale);
glamor_picture_get_matrixf(mask, mask_matrix); glamor_picture_get_matrixf(mask, mask_matrix);
vert_stride += 4;
} }
while (nrect--) { nrect_max = (vert_stride * nrect) > GLAMOR_COMPOSITE_VBO_VERT_CNT ?
INT16 x_source; (GLAMOR_COMPOSITE_VBO_VERT_CNT / 6) : nrect;
INT16 y_source;
INT16 x_mask; while(nrect) {
INT16 y_mask; int mrect, rect_processed;
INT16 x_dest;
INT16 y_dest; mrect = nrect > nrect_max ? nrect_max : nrect ;
CARD16 width; glamor_setup_composite_vbo(screen, mrect * vert_stride);
CARD16 height; rect_processed = mrect;
x_dest = rects->x_dst + dest_x_off; while (mrect--) {
y_dest = rects->y_dst + dest_y_off; INT16 x_source;
x_source = rects->x_src + source_x_off;; INT16 y_source;
y_source = rects->y_src + source_y_off; INT16 x_mask;
x_mask = rects->x_mask + mask_x_off; INT16 y_mask;
y_mask = rects->y_mask + mask_y_off; INT16 x_dest;
width = rects->width; INT16 y_dest;
height = rects->height; CARD16 width;
CARD16 height;
glamor_set_normalize_vcoords(dst_xscale,
dst_yscale, x_dest = rects->x_dst + dest_x_off;
x_dest, y_dest, y_dest = rects->y_dst + dest_y_off;
x_dest + width, y_dest + height, x_source = rects->x_src + source_x_off;;
glamor_priv->yInverted, y_source = rects->y_src + source_y_off;
vertices); x_mask = rects->x_mask + mask_x_off;
y_mask = rects->y_mask + mask_y_off;
if (key.source != SHADER_SOURCE_SOLID) { width = rects->width;
if (source->transform) height = rects->height;
glamor_set_transformed_normalize_tcoords(src_matrix, src_xscale,
src_yscale, x_source, y_source, glamor_set_normalize_vcoords(dst_xscale,
x_source + width, y_source + height, dst_yscale,
glamor_priv->yInverted, x_dest, y_dest,
source_texcoords); x_dest + width, y_dest + height,
else glamor_priv->yInverted,
glamor_set_normalize_tcoords(src_xscale, src_yscale, vertices);
x_source, y_source,
x_source + width, y_source + height, if (key.source != SHADER_SOURCE_SOLID) {
glamor_priv->yInverted, if (source->transform)
source_texcoords); glamor_set_transformed_normalize_tcoords
} (src_matrix, src_xscale,
src_yscale, x_source, y_source,
x_source + width, y_source + height,
glamor_priv->yInverted,
source_texcoords);
else
glamor_set_normalize_tcoords
(src_xscale, src_yscale,
x_source, y_source,
x_source + width, y_source + height,
glamor_priv->yInverted,
source_texcoords);
}
if (key.mask != SHADER_MASK_NONE if (key.mask != SHADER_MASK_NONE
&& key.mask != SHADER_MASK_SOLID) { && key.mask != SHADER_MASK_SOLID) {
if (mask->transform) if (mask->transform)
glamor_set_transformed_normalize_tcoords(mask_matrix, glamor_set_transformed_normalize_tcoords
mask_xscale, (mask_matrix,
mask_yscale, x_mask, y_mask, mask_xscale,
x_mask + width, y_mask + height, mask_yscale, x_mask, y_mask,
glamor_priv->yInverted, x_mask + width, y_mask + height,
mask_texcoords); glamor_priv->yInverted,
else mask_texcoords);
glamor_set_normalize_tcoords(mask_xscale, else
mask_yscale, x_mask, y_mask, glamor_set_normalize_tcoords
x_mask + width, y_mask + height, (mask_xscale,
glamor_priv->yInverted, mask_yscale, x_mask, y_mask,
mask_texcoords); x_mask + width, y_mask + height,
glamor_priv->yInverted,
mask_texcoords);
}
glamor_emit_composite_rect(screen,
source_texcoords,
mask_texcoords,
vertices);
rects++;
} }
glamor_emit_composite_rect(screen, glamor_flush_composite_rects(screen);
source_texcoords, nrect -= rect_processed;
mask_texcoords,
vertices);
rects++;
} }
glamor_flush_composite_rects(screen);
dispatch->glBindBuffer(GL_ARRAY_BUFFER, 0); dispatch->glBindBuffer(GL_ARRAY_BUFFER, 0);
dispatch->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); dispatch->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
...@@ -1380,7 +1375,6 @@ _glamor_composite(CARD8 op, ...@@ -1380,7 +1375,6 @@ _glamor_composite(CARD8 op,
goto done; goto done;
} }
fallback:
glamor_fallback glamor_fallback
("from picts %p:%p %dx%d / %p:%p %d x %d (%c,%c) to pict %p:%p %dx%d (%c)\n", ("from picts %p:%p %dx%d / %p:%p %d x %d (%c,%c) to pict %p:%p %dx%d (%c)\n",
source, source->pDrawable, source, source->pDrawable,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment