[igt-dev] [PATCH i-g-t] tests/gem_render_copy: Use a more elaborate pattern of pixels

Chris Wilson chris at chris-wilson.co.uk
Fri Jun 29 20:12:38 UTC 2018


Quoting Ville Syrjala (2018-06-29 17:23:57)
> +static void scratch_buf_draw_pattern(data_t *data, struct igt_buf *buf,
> +                                    int x, int y, int w, int h,
> +                                    int cx, int cy, int cw, int ch,
> +                                    bool use_alternate_colors)
> +{
> +       cairo_surface_t *surface;
> +       cairo_pattern_t *pat;
> +       cairo_t *cr;
> +       void *map;
> +
> +       gem_set_domain(data->drm_fd, buf->bo->handle,
> +                      I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU);
> +
> +       map = gem_mmap__cpu(data->drm_fd, buf->bo->handle, 0,
> +                           buf->bo->size, PROT_READ | PROT_WRITE);
> +
> +       surface = cairo_image_surface_create_for_data(map,
> +                                                     CAIRO_FORMAT_RGB24,
> +                                                     igt_buf_width(buf),
> +                                                     igt_buf_height(buf),
> +                                                     buf->stride);
> +
> +       cr = cairo_create(surface);
> +
> +       cairo_rectangle(cr, cx, cy, cw, ch);
> +       cairo_clip(cr);
> +
> +       pat = cairo_pattern_create_mesh();
> +       cairo_mesh_pattern_begin_patch(pat);
> +       cairo_mesh_pattern_move_to(pat, x,   y);
> +       cairo_mesh_pattern_line_to(pat, x+w, y);
> +       cairo_mesh_pattern_line_to(pat, x+w, y+h);
> +       cairo_mesh_pattern_line_to(pat, x,   y+h);
> +       if (use_alternate_colors) {
> +               cairo_mesh_pattern_set_corner_color_rgb(pat, 0, 0.0, 1.0, 1.0);
> +               cairo_mesh_pattern_set_corner_color_rgb(pat, 1, 1.0, 0.0, 1.0);
> +               cairo_mesh_pattern_set_corner_color_rgb(pat, 2, 1.0, 1.0, 0.0);
> +               cairo_mesh_pattern_set_corner_color_rgb(pat, 3, 0.0, 0.0, 0.0);
> +       } else {
> +               cairo_mesh_pattern_set_corner_color_rgb(pat, 0, 1.0, 0.0, 0.0);
> +               cairo_mesh_pattern_set_corner_color_rgb(pat, 1, 0.0, 1.0, 0.0);
> +               cairo_mesh_pattern_set_corner_color_rgb(pat, 2, 0.0, 0.0, 1.0);
> +               cairo_mesh_pattern_set_corner_color_rgb(pat, 3, 1.0, 1.0, 1.0);
> +       }
> +       cairo_mesh_pattern_end_patch(pat);

I was expecting to see some new EU shaders. Disappoint! ;)

> +static void
> +scratch_buf_copy(data_t *data,
> +                struct igt_buf *src, int sx, int sy, int w, int h,
> +                struct igt_buf *dst, int dx, int dy)
> +{
> +       int width = igt_buf_width(dst);
> +       int height  = igt_buf_height(dst);
> +       uint32_t *linear_dst, *linear_src;
> +
> +       igt_assert_eq(igt_buf_width(dst), igt_buf_width(src));
> +       igt_assert_eq(igt_buf_height(dst), igt_buf_height(src));
> +       igt_assert_eq(dst->bo->size, src->bo->size);
> +
> +       linear_dst = malloc(dst->bo->size);
> +       linear_src = malloc(src->bo->size);
> +
> +       gem_read(data->drm_fd, dst->bo->handle, 0,
> +                linear_dst, dst->bo->size);
> +       gem_read(data->drm_fd, src->bo->handle, 0,
> +                linear_src, src->bo->size);

The danger here is for non-constant/unknown swizzling (L-shaped memory
layouts may end up with mixed swizzle modes). Safest to use GTT, and
memcpy_from_wc if available. What to do when no GTT? Then assume linear
is good enough?
-Chris


More information about the igt-dev mailing list