xcb: Take advantage of clip-boxes

A demonstration of step 2, improves performance for selected benchmarks
on selected GPUs by up to 30%.

firefox-fishbowl on snb {i5-2520m): 42s -> 29s.
firefox-talos-gfx on snb: 7.6 -> 5.2s.
firefox-fishbowl on pnv (n450): 380 -> 360s.

Whist this looks like it is getting close to as good as we can achieve,
we are constrained by both our API and Xrender and fishbowl is about 50%
slower than peak performance (on snb).

And it fixes the older performance regression in firefox-planet-gnome.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
This commit is contained in:
Chris Wilson 2011-07-19 11:29:49 +01:00
parent b419fdcacd
commit d5d4a0f240
10 changed files with 739 additions and 315 deletions

View file

@ -186,25 +186,40 @@ static void _destroy_similar (void *closure)
free (similar);
}
struct xcb_info {
xcb_render_query_pict_formats_reply_t *formats;
xcb_render_pictforminfo_t *render_format[3];
};
static cairo_surface_t *
_cairo_boilerplate_xcb_create_similar (cairo_surface_t *other,
cairo_content_t content,
int width, int height)
{
cairo_device_t *device = cairo_surface_get_device (other);
struct xcb_info *info = cairo_device_get_user_data (device, &key);
xcb_screen_t *root;
cairo_surface_t *surface;
struct similar *similar;
xcb_render_pictforminfo_t *render_format;
int depth;
void *formats;
similar = malloc (sizeof (*similar));
switch (content) {
default:
case CAIRO_CONTENT_COLOR_ALPHA: depth = 32; break;
case CAIRO_CONTENT_COLOR: depth = 24; break;
case CAIRO_CONTENT_ALPHA: depth = 8; break;
case CAIRO_CONTENT_COLOR_ALPHA:
depth = 32;
render_format = info->render_format[0];
break;
case CAIRO_CONTENT_COLOR:
depth = 24;
render_format = info->render_format[1];
break;
case CAIRO_CONTENT_ALPHA:
depth = 8;
render_format = info->render_format[2];
break;
}
similar->connection =
@ -216,17 +231,12 @@ _cairo_boilerplate_xcb_create_similar (cairo_surface_t *other,
similar->pixmap, root->root,
width, height);
render_format = find_depth (similar->connection, depth, &formats);
if (render_format == NULL)
return NULL;
surface = cairo_xcb_surface_create_with_xrender_format (similar->connection,
root,
similar->pixmap,
render_format,
width, height);
cairo_surface_set_user_data (surface, &key, similar, _destroy_similar);
free(formats);
return surface;
}
@ -245,14 +255,17 @@ _cairo_boilerplate_xcb_create_surface (const char *name,
xcb_screen_t *root;
xcb_target_closure_t *xtc;
xcb_connection_t *c;
xcb_render_query_pict_formats_cookie_t formats_cookie;
xcb_render_pictforminfo_t *render_format;
xcb_render_pictforminfo_iterator_t i;
struct xcb_info *info;
int depth;
xcb_void_cookie_t cookie;
cairo_surface_t *surface;
cairo_status_t status;
void *formats;
*closure = xtc = xmalloc (sizeof (xcb_target_closure_t));
info = xcalloc (1, sizeof (struct xcb_info));
if (width == 0)
width = 1;
@ -266,6 +279,7 @@ _cairo_boilerplate_xcb_create_surface (const char *name,
}
root = xcb_setup_roots_iterator(xcb_get_setup(c)).data;
formats_cookie = xcb_render_query_pict_formats (c);
xtc->surface = NULL;
xtc->is_pixmap = TRUE;
@ -273,16 +287,10 @@ _cairo_boilerplate_xcb_create_surface (const char *name,
switch (content) {
case CAIRO_CONTENT_COLOR:
depth = 24;
cookie = xcb_create_pixmap_checked (c, depth,
xtc->drawable, root->root,
width, height);
break;
case CAIRO_CONTENT_COLOR_ALPHA:
depth = 32;
cookie = xcb_create_pixmap_checked (c, depth,
xtc->drawable, root->root,
width, height);
break;
case CAIRO_CONTENT_ALPHA: /* would be XCB_PICT_STANDARD_A_8 */
@ -292,6 +300,10 @@ _cairo_boilerplate_xcb_create_surface (const char *name,
return NULL;
}
cookie = xcb_create_pixmap_checked (c, depth,
xtc->drawable, root->root,
width, height);
/* slow, but sure */
if (xcb_request_check (c, cookie) != NULL) {
xcb_disconnect (c);
@ -299,19 +311,53 @@ _cairo_boilerplate_xcb_create_surface (const char *name,
return NULL;
}
render_format = find_depth (c, depth, &formats);
if (render_format == NULL) {
xcb_disconnect (c);
free (xtc);
info->formats = xcb_render_query_pict_formats_reply (c, formats_cookie, 0);
if (info->formats == NULL)
return NULL;
for (i = xcb_render_query_pict_formats_formats_iterator (info->formats);
i.rem;
xcb_render_pictforminfo_next (&i))
{
if (XCB_RENDER_PICT_TYPE_DIRECT != i.data->type)
continue;
if (i.data->depth == 32) {
if (info->render_format[0] == 0)
info->render_format[0] = i.data;
} else if (i.data->depth == 24) {
if (info->render_format[1] == 0)
info->render_format[1] = i.data;
} else if (i.data->depth == 8) {
if (info->render_format[2] == 0)
info->render_format[2] = i.data;
}
}
assert (info->render_format[0]);
assert (info->render_format[1]);
assert (info->render_format[2]);
switch (content) {
default:
case CAIRO_CONTENT_COLOR_ALPHA:
render_format = info->render_format[0];
break;
case CAIRO_CONTENT_COLOR:
render_format = info->render_format[1];
break;
case CAIRO_CONTENT_ALPHA: /* would be XCB_PICT_STANDARD_A_8 */
render_format = info->render_format[2];
break;
}
surface = cairo_xcb_surface_create_with_xrender_format (c, root,
xtc->drawable,
render_format,
width, height);
free (formats);
cairo_device_set_user_data (cairo_surface_get_device (surface), &key, info, free);
if (mode != CAIRO_BOILERPLATE_MODE_PERF)
_cairo_boilerplate_xcb_setup_test_surface(surface);
@ -566,6 +612,7 @@ _cairo_boilerplate_xcb_create_render_0_0 (const char *name,
free (xtc);
return NULL;
}
xcb_flush (c);
render_format = find_depth (c, depth, &formats);
if (render_format == NULL) {
@ -593,7 +640,6 @@ _cairo_boilerplate_xcb_create_render_0_0 (const char *name,
xtc->drawable,
render_format,
width, height);
free (formats);
cairo_surface_destroy (tmp);
assert (cairo_surface_get_device (surface) == xtc->device);

View file

@ -572,14 +572,13 @@ _cairo_boxes_intersect (const cairo_boxes_t *a,
return CAIRO_STATUS_SUCCESS;
}
if (unlikely (a->num_boxes == 1)) {
if (a->num_boxes == 1) {
cairo_box_t box = a->chunks.base[0];
return _cairo_boxes_intersect_with_box (b, &box, out);
}
if (unlikely (b->num_boxes == 1)) {
if (b->num_boxes == 1) {
cairo_box_t box = b->chunks.base[0];
return _cairo_boxes_intersect_with_box (a, &box, out);
/* XXX */
}
rectangles = stack_rectangles;

View file

@ -94,6 +94,9 @@ _cairo_clip_set_all_clipped (cairo_clip_t *clip)
cairo_private cairo_clip_t *
_cairo_clip_copy (const cairo_clip_t *clip);
cairo_private cairo_clip_t *
_cairo_clip_copy_region (const cairo_clip_t *clip);
cairo_private cairo_clip_t *
_cairo_clip_copy_with_translation (const cairo_clip_t *clip, int tx, int ty);

View file

@ -175,6 +175,38 @@ _cairo_clip_copy (const cairo_clip_t *clip)
return copy;
}
cairo_clip_t *
_cairo_clip_copy_region (const cairo_clip_t *clip)
{
cairo_clip_t *copy;
int i;
if (clip == NULL || _cairo_clip_is_all_clipped (clip))
return (cairo_clip_t *) clip;
assert (clip->num_boxes);
copy = _cairo_clip_create ();
copy->extents = clip->extents;
copy->boxes = _cairo_malloc_ab (clip->num_boxes, sizeof (cairo_box_t));
if (unlikely (copy->boxes == NULL))
return _cairo_clip_set_all_clipped (copy);
for (i = 0; i < clip->num_boxes; i++) {
copy->boxes[i].p1.x = _cairo_fixed_floor (clip->boxes[i].p1.x);
copy->boxes[i].p1.y = _cairo_fixed_floor (clip->boxes[i].p1.y);
copy->boxes[i].p2.x = _cairo_fixed_ceil (clip->boxes[i].p2.x);
copy->boxes[i].p2.y = _cairo_fixed_ceil (clip->boxes[i].p2.y);
}
copy->num_boxes = clip->num_boxes;
copy->region = cairo_region_reference (clip->region);
copy->is_region = TRUE;
return copy;
}
cairo_clip_t *
_cairo_clip_intersect_path (cairo_clip_t *clip,
const cairo_path_fixed_t *path,

View file

@ -104,6 +104,10 @@ _cairo_composite_rectangles_init_for_glyphs (cairo_composite_rectangles_t *exten
const cairo_clip_t *clip,
cairo_bool_t *overlap);
cairo_private cairo_int_status_t
_cairo_composite_rectangles_intersect_mask_extents (cairo_composite_rectangles_t *extents,
const cairo_box_t *box);
cairo_private void
_cairo_composite_rectangles_fini (cairo_composite_rectangles_t *extents);

View file

@ -112,6 +112,9 @@ _cairo_composite_rectangles_intersect (cairo_composite_rectangles_t *extents,
if (! ret && extents->is_bounded & CAIRO_OPERATOR_BOUND_BY_MASK)
return CAIRO_INT_STATUS_NOTHING_TO_DO;
if (extents->is_bounded == (CAIRO_OPERATOR_BOUND_BY_MASK | CAIRO_OPERATOR_BOUND_BY_SOURCE))
extents->unbounded = extents->bounded;
extents->clip = _cairo_clip_reduce_for_composite (clip, extents);
if (_cairo_clip_is_all_clipped (extents->clip))
return CAIRO_INT_STATUS_NOTHING_TO_DO;
@ -119,6 +122,36 @@ _cairo_composite_rectangles_intersect (cairo_composite_rectangles_t *extents,
return CAIRO_STATUS_SUCCESS;
}
cairo_int_status_t
_cairo_composite_rectangles_intersect_mask_extents (cairo_composite_rectangles_t *extents,
const cairo_box_t *box)
{
cairo_rectangle_int_t mask;
cairo_int_status_t status;
cairo_clip_t *clip;
_cairo_box_round_to_rectangle (box, &mask);
if (mask.x == extents->mask.x &&
mask.y == extents->mask.y &&
mask.width == extents->mask.width &&
mask.height == extents->mask.height)
{
return CAIRO_INT_STATUS_SUCCESS;
}
_cairo_rectangle_intersect (&extents->mask, &mask);
extents->mask = mask;
clip = extents->clip;
status = _cairo_composite_rectangles_intersect (extents, clip);
if (clip != extents->clip)
_cairo_clip_destroy (clip);
return status;
}
cairo_int_status_t
_cairo_composite_rectangles_init_for_mask (cairo_composite_rectangles_t *extents,
int surface_width, int surface_height,

View file

@ -269,6 +269,16 @@ _cairo_debug_print_polygon (FILE *stream, cairo_polygon_t *polygon)
_cairo_fixed_to_double (polygon->extents.p1.y),
_cairo_fixed_to_double (polygon->extents.p2.x),
_cairo_fixed_to_double (polygon->extents.p2.y));
if (polygon->num_limits) {
fprintf (stream,
" : limit=(%f, %f), (%f, %f) x %d\n",
_cairo_fixed_to_double (polygon->limit.p1.x),
_cairo_fixed_to_double (polygon->limit.p1.y),
_cairo_fixed_to_double (polygon->limit.p2.x),
_cairo_fixed_to_double (polygon->limit.p2.y),
polygon->num_limits);
}
for (n = 0; n < polygon->num_edges; n++) {
cairo_edge_t *edge = &polygon->edges[n];

View file

@ -90,6 +90,7 @@ struct _cairo_xcb_surface {
int use_pixmap;
cairo_bool_t deferred_clear;
cairo_color_t deferred_clear_color;
int width;
int height;

File diff suppressed because it is too large Load diff

View file

@ -927,6 +927,7 @@ _cairo_xcb_surface_create_internal (cairo_xcb_screen_t *screen,
surface->use_pixmap = 0;
surface->deferred_clear = FALSE;
surface->deferred_clear_color = *CAIRO_COLOR_TRANSPARENT;
surface->width = width;
surface->height = height;