[igt-dev] [Intel-gfx] [PATCH i-g-t v5 3/6] lib: Add function to hash a framebuffer

Chris Wilson chris at chris-wilson.co.uk
Tue Jan 15 18:47:47 UTC 2019


Quoting Liviu Dudau (2019-01-15 17:47:44)
> +int igt_fb_get_crc(struct igt_fb *fb, igt_crc_t *crc)
> +{
> +#define FNV1a_OFFSET_BIAS 2166136261
> +#define FNV1a_PRIME 16777619
> +       uint32_t hash;
> +       void *map;
> +       char *ptr, *line = NULL;
> +       int x, y, cpp = igt_drm_format_to_bpp(fb->drm_format) / 8;
> +       uint32_t stride = calc_plane_stride(fb, 0);
> +
> +       if (fb->is_dumb)
> +               map = kmstest_dumb_map_buffer(fb->fd, fb->gem_handle, fb->size,
> +                                             PROT_READ);
> +       else
> +               map = gem_mmap__gtt(fb->fd, fb->gem_handle, fb->size,
> +                                   PROT_READ);
> +       ptr = map;
> +
> +       /*
> +        * Framebuffers are often uncached, which can make byte-wise accesses
> +        * very slow. We copy each line of the FB into a local buffer to speed
> +        * up the hashing.
> +        */
> +       line = malloc(stride);
> +       if (!line) {
> +               munmap(map, fb->size);
> +               return -ENOMEM;
> +       }
> +
> +       hash = FNV1a_OFFSET_BIAS;
> +
> +       for (y = 0; y < fb->height; y++, ptr += stride) {
> +
> +               memcpy(line, ptr, stride);

igt_memcpy_from_wc() for the reasons cited above.
-Chris


More information about the igt-dev mailing list