From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: Kevin Strasser <kevin.strasser@intel.com>
Cc: igt-dev@lists.freedesktop.org
Subject: Re: [igt-dev] [RFC v2 4/5] lib/igt_fb: Add support for fp16 formats through conversion
Date: Fri, 5 Apr 2019 22:26:42 +0300 [thread overview]
Message-ID: <20190405192642.GS3888@intel.com> (raw)
In-Reply-To: <1551838717-5283-5-git-send-email-kevin.strasser@intel.com>
On Tue, Mar 05, 2019 at 06:18:36PM -0800, Kevin Strasser wrote:
> Follow design of P01x conversion to support tests needing pixel data in fp16
> (half float 64 bpp).
>
> rfc2:
> - Convert whole rows of pixels if possible (Maarten)
> - Treat rgbx like rgba, let hardware ignore alpha (Maarten)
>
> Signed-off-by: Kevin Strasser <kevin.strasser@intel.com>
lgtm
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> ---
> lib/igt_fb.c | 148 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
> lib/igt_fb.h | 1 +
> 2 files changed, 148 insertions(+), 1 deletion(-)
>
> diff --git a/lib/igt_fb.c b/lib/igt_fb.c
> index 9dca2a4..451b2c2 100644
> --- a/lib/igt_fb.c
> +++ b/lib/igt_fb.c
> @@ -35,6 +35,7 @@
> #include "igt_aux.h"
> #include "igt_color_encoding.h"
> #include "igt_fb.h"
> +#include "igt_halffloat.h"
> #include "igt_kms.h"
> #include "igt_matrix.h"
> #include "igt_vc4.h"
> @@ -161,6 +162,22 @@ static const struct format_desc_struct {
> .num_planes = 1, .plane_bpp = { 32, },
> .hsub = 1, .vsub = 1,
> },
> + { .name = "XRGB16161616F", .depth = -1, .drm_id = DRM_FORMAT_XRGB16161616F,
> + .cairo_id = CAIRO_FORMAT_RGBA128F,
> + .num_planes = 1, .plane_bpp = { 64, },
> + },
> + { .name = "ARGB16161616F", .depth = -1, .drm_id = DRM_FORMAT_ARGB16161616F,
> + .cairo_id = CAIRO_FORMAT_RGBA128F,
> + .num_planes = 1, .plane_bpp = { 64, },
> + },
> + { .name = "XBGR16161616F", .depth = -1, .drm_id = DRM_FORMAT_XBGR16161616F,
> + .cairo_id = CAIRO_FORMAT_RGBA128F,
> + .num_planes = 1, .plane_bpp = { 64, },
> + },
> + { .name = "ABGR16161616F", .depth = -1, .drm_id = DRM_FORMAT_ABGR16161616F,
> + .cairo_id = CAIRO_FORMAT_RGBA128F,
> + .num_planes = 1, .plane_bpp = { 64, },
> + },
> { .name = "NV12", .depth = -1, .drm_id = DRM_FORMAT_NV12,
> .cairo_id = CAIRO_FORMAT_RGB24,
> .num_planes = 2, .plane_bpp = { 8, 16, },
> @@ -661,7 +678,8 @@ static int create_bo_for_fb(struct igt_fb *fb)
> * them, so we need to make sure to use a device BO then.
> */
> if (fb->tiling || fb->size || fb->strides[0] ||
> - (is_i915_device(fd) && igt_format_is_yuv(fb->drm_format)))
> + (is_i915_device(fd) && igt_format_is_yuv(fb->drm_format)) ||
> + (is_i915_device(fd) && igt_format_is_fp16(fb->drm_format)))
> device_bo = true;
>
> /* Sets offets and stride if necessary. */
> @@ -2202,6 +2220,102 @@ static void convert_float_to_yuv16(struct fb_convert *cvt)
> }
> }
>
> +/* { R, G, B, X } */
> +static const unsigned char swizzle_rgbx[] = { 0, 1, 2, 3 };
> +static const unsigned char swizzle_bgrx[] = { 2, 1, 0, 3 };
> +
> +static const unsigned char *rgbx_swizzle(uint32_t format)
> +{
> + switch (format) {
> + default:
> + case DRM_FORMAT_XRGB16161616F:
> + case DRM_FORMAT_ARGB16161616F:
> + return swizzle_bgrx;
> + case DRM_FORMAT_XBGR16161616F:
> + case DRM_FORMAT_ABGR16161616F:
> + return swizzle_rgbx;
> + }
> +}
> +
> +static void convert_fp16_to_float(struct fb_convert *cvt)
> +{
> + int i, j;
> + uint16_t *fp16;
> + float *ptr = cvt->dst.ptr;
> + unsigned int float_stride = cvt->dst.fb->strides[0] / sizeof(*ptr);
> + unsigned int fp16_stride = cvt->src.fb->strides[0] / sizeof(*fp16);
> + const unsigned char *swz = rgbx_swizzle(cvt->src.fb->drm_format);
> + bool needs_reswizzle = swz != swizzle_rgbx;
> +
> + uint16_t *buf = convert_src_get(cvt);
> + fp16 = buf + cvt->src.fb->offsets[0] / sizeof(*buf);
> +
> + for (i = 0; i < cvt->dst.fb->height; i++) {
> + if (needs_reswizzle) {
> + const uint16_t *fp16_tmp = fp16;
> + float *rgb_tmp = ptr;
> +
> + for (j = 0; j < cvt->dst.fb->width; j++) {
> + struct igt_vec4 rgb;
> +
> + igt_half_to_float(fp16_tmp, rgb.d, 4);
> +
> + rgb_tmp[0] = rgb.d[swz[0]];
> + rgb_tmp[1] = rgb.d[swz[1]];
> + rgb_tmp[2] = rgb.d[swz[2]];
> + rgb_tmp[3] = rgb.d[swz[3]];
> +
> + rgb_tmp += 4;
> + fp16_tmp += 4;
> + }
> + } else {
> + igt_half_to_float(fp16, ptr, cvt->dst.fb->width * 4);
> + }
> +
> + ptr += float_stride;
> + fp16 += fp16_stride;
> + }
> +
> + convert_src_put(cvt, buf);
> +}
> +
> +static void convert_float_to_fp16(struct fb_convert *cvt)
> +{
> + int i, j;
> + uint16_t *fp16 = cvt->dst.ptr + cvt->dst.fb->offsets[0];
> + const float *ptr = cvt->src.ptr;
> + unsigned float_stride = cvt->src.fb->strides[0] / sizeof(*ptr);
> + unsigned fp16_stride = cvt->dst.fb->strides[0] / sizeof(*fp16);
> + const unsigned char *swz = rgbx_swizzle(cvt->dst.fb->drm_format);
> + bool needs_reswizzle = swz != swizzle_rgbx;
> +
> + for (i = 0; i < cvt->dst.fb->height; i++) {
> + if (needs_reswizzle) {
> + const float *rgb_tmp = ptr;
> + uint16_t *fp16_tmp = fp16;
> +
> + for (j = 0; j < cvt->dst.fb->width; j++) {
> + struct igt_vec4 rgb;
> +
> + rgb.d[0] = rgb_tmp[swz[0]];
> + rgb.d[1] = rgb_tmp[swz[1]];
> + rgb.d[2] = rgb_tmp[swz[2]];
> + rgb.d[3] = rgb_tmp[swz[3]];
> +
> + igt_float_to_half(rgb.d, fp16_tmp, 4);
> +
> + rgb_tmp += 4;
> + fp16_tmp += 4;
> + }
> + } else {
> + igt_float_to_half(ptr, fp16, cvt->dst.fb->width * 4);
> + }
> +
> + ptr += float_stride;
> + fp16 += fp16_stride;
> + }
> +}
> +
> static void convert_pixman(struct fb_convert *cvt)
> {
> pixman_format_code_t src_pixman = drm_format_to_pixman(cvt->src.fb->drm_format);
> @@ -2290,6 +2404,12 @@ static void fb_convert(struct fb_convert *cvt)
> case DRM_FORMAT_P016:
> convert_yuv16_to_float(cvt);
> return;
> + case DRM_FORMAT_XRGB16161616F:
> + case DRM_FORMAT_XBGR16161616F:
> + case DRM_FORMAT_ARGB16161616F:
> + case DRM_FORMAT_ABGR16161616F:
> + convert_fp16_to_float(cvt);
> + return;
> }
> } else if (cvt->src.fb->drm_format == IGT_FORMAT_FLOAT) {
> switch (cvt->dst.fb->drm_format) {
> @@ -2298,6 +2418,12 @@ static void fb_convert(struct fb_convert *cvt)
> case DRM_FORMAT_P016:
> convert_float_to_yuv16(cvt);
> return;
> + case DRM_FORMAT_XRGB16161616F:
> + case DRM_FORMAT_XBGR16161616F:
> + case DRM_FORMAT_ARGB16161616F:
> + case DRM_FORMAT_ABGR16161616F:
> + convert_float_to_fp16(cvt);
> + return;
> }
> }
>
> @@ -2453,6 +2579,7 @@ cairo_surface_t *igt_get_cairo_surface(int fd, struct igt_fb *fb)
>
> if (fb->cairo_surface == NULL) {
> if (igt_format_is_yuv(fb->drm_format) ||
> + igt_format_is_fp16(fb->drm_format) ||
> ((f->cairo_id == CAIRO_FORMAT_INVALID) &&
> (f->pixman_id != PIXMAN_invalid)))
> create_cairo_surface__convert(fd, fb);
> @@ -2762,6 +2889,25 @@ bool igt_format_is_yuv(uint32_t drm_format)
> }
>
> /**
> + * igt_format_is_fp16
> + * @drm_format: drm fourcc
> + *
> + * Check if the format is fp16.
> + */
> +bool igt_format_is_fp16(uint32_t drm_format)
> +{
> + switch (drm_format) {
> + case DRM_FORMAT_XRGB16161616F:
> + case DRM_FORMAT_ARGB16161616F:
> + case DRM_FORMAT_XBGR16161616F:
> + case DRM_FORMAT_ABGR16161616F:
> + return true;
> + default:
> + return false;
> + }
> +}
> +
> +/**
> * igt_format_plane_bpp:
> * @drm_format: drm fourcc
> * @plane: format plane index
> diff --git a/lib/igt_fb.h b/lib/igt_fb.h
> index e1d885e..07b6814 100644
> --- a/lib/igt_fb.h
> +++ b/lib/igt_fb.h
> @@ -182,6 +182,7 @@ uint32_t igt_drm_format_to_bpp(uint32_t drm_format);
> const char *igt_format_str(uint32_t drm_format);
> bool igt_fb_supported_format(uint32_t drm_format);
> bool igt_format_is_yuv(uint32_t drm_format);
> +bool igt_format_is_fp16(uint32_t drm_format);
> int igt_format_plane_bpp(uint32_t drm_format, int plane);
> void igt_format_array_fill(uint32_t **formats_array, unsigned int *count,
> bool allow_yuv);
> --
> 2.7.4
--
Ville Syrjälä
Intel
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev
next prev parent reply other threads:[~2019-04-05 19:26 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-06 2:18 [igt-dev] [RFC v2 0/5] Add support for fp16 formats Kevin Strasser
2019-03-06 2:18 ` [igt-dev] [RFC v2 1/5] lib: Add halffloat implementation Kevin Strasser
2019-04-05 19:23 ` Ville Syrjälä
2019-04-05 19:29 ` Strasser, Kevin
2019-03-06 2:18 ` [igt-dev] [RFC v2 2/5] include: Add fp16 format defines Kevin Strasser
2019-03-06 2:18 ` [igt-dev] [RFC v2 3/5] tests/kms_available_modes_crc: Add cases for 64bit formats Kevin Strasser
2019-04-05 19:29 ` Ville Syrjälä
2019-04-05 19:43 ` Strasser, Kevin
2019-04-05 19:58 ` Ville Syrjälä
2019-03-06 2:18 ` [igt-dev] [RFC v2 4/5] lib/igt_fb: Add support for fp16 formats through conversion Kevin Strasser
2019-04-05 19:26 ` Ville Syrjälä [this message]
2019-03-06 2:18 ` [igt-dev] [RFC v2 5/5] tests/kms_plane_scaling: Skip testing unsupported fp16 features Kevin Strasser
2019-04-05 19:38 ` Ville Syrjälä
2019-03-06 3:19 ` [igt-dev] ✓ Fi.CI.BAT: success for Add support for fp16 formats (rev2) Patchwork
2019-03-06 9:31 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190405192642.GS3888@intel.com \
--to=ville.syrjala@linux.intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=kevin.strasser@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.