public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
To: igt-dev@lists.freedesktop.org
Cc: Petri Latvala <petri.latvala@intel.com>,
	Eben Upton <eben@raspberrypi.org>,
	Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Subject: [igt-dev] [PATCH i-g-t 6/9] lib/igt_vc4: Add helpers for converting linear to T-tiled XRGB buffers
Date: Thu,  6 Dec 2018 15:11:29 +0100	[thread overview]
Message-ID: <20181206141132.23349-7-paul.kocialkowski@bootlin.com> (raw)
In-Reply-To: <20181206141132.23349-1-paul.kocialkowski@bootlin.com>

In order to integrate testing of T-tiled buffers, the easiest path is to
generate patterns (with the already-existing functions) in linear
buffers and convert them to T-tiled subsequently.

Add helpers to do that conversion, with a first helper that returns the
memory offset for a given position in a T-tiled buffer and a second
helper that uses it for converting between framebuffers.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
---
 lib/igt_vc4.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/igt_vc4.h |  4 +++
 2 files changed, 100 insertions(+)

diff --git a/lib/igt_vc4.c b/lib/igt_vc4.c
index 16dfe67a..0b5124f3 100644
--- a/lib/igt_vc4.c
+++ b/lib/igt_vc4.c
@@ -34,6 +34,7 @@
 #include "drmtest.h"
 #include "igt_aux.h"
 #include "igt_core.h"
+#include "igt_fb.h"
 #include "igt_vc4.h"
 #include "ioctl_wrappers.h"
 #include "intel_reg.h"
@@ -176,3 +177,98 @@ bool igt_vc4_purgeable_bo(int fd, int handle, bool purgeable)
 
 	return arg.retained;
 }
+
+unsigned int igt_vc4_fb_t_tiled_convert(struct igt_fb *dst, struct igt_fb *src)
+{
+	unsigned int fb_id;
+	unsigned int i, j;
+	uint32_t *src_buf;
+	uint32_t *dst_buf;
+	size_t offset;
+
+	igt_assert(src->drm_format == DRM_FORMAT_XRGB8888);
+
+	fb_id = igt_create_fb(src->fd, src->width, src->height, src->drm_format,
+			      DRM_FORMAT_MOD_BROADCOM_VC4_T_TILED, dst);
+	igt_assert(fb_id > 0);
+
+	src_buf = igt_fb_map_buffer(src->fd, src);
+	igt_assert(src_buf);
+
+	dst_buf = igt_fb_map_buffer(dst->fd, dst);
+	igt_assert(dst_buf);
+
+	for (i = 0; i < src->height; i++) {
+		for (j = 0; j < src->width; j++) {
+			offset = igt_vc4_t_tiled_offset(src->width, src->height,
+							src->drm_format, j, i) / 4;
+			*(dst_buf + offset) = *(src_buf +
+						src->strides[0] / 4 * i + j);
+		}
+	}
+
+	igt_fb_unmap_buffer(src, src_buf);
+	igt_fb_unmap_buffer(dst, dst_buf);
+
+	return fb_id;
+}
+
+size_t igt_vc4_t_tiled_offset(size_t width, size_t height, size_t format,
+			      size_t x, size_t y)
+{
+	size_t t1k_map_even[4] = { 0, 3, 1, 2 };
+	size_t t1k_map_odd[4] = { 2, 1, 3, 0 };
+	size_t offset = 0;
+	size_t t4k_w, t4k_x, t4k_y;
+	size_t t1k_x, t1k_y;
+	size_t t64b_x, t64b_y;
+	size_t pix_x, pix_y;
+	unsigned int index;
+
+	igt_assert(format == DRM_FORMAT_XRGB8888);
+
+	/* Width in number of 4K tiles. */
+	t4k_w = ALIGN(width, 32) / 32;
+
+	/* X and y coordinates in number of 4K tiles (32x32). */
+	t4k_x = x / 32;
+	t4k_y = y / 32;
+
+	/* Increase offset to the beginning of the corresponding 4K tile. */
+	offset += t4k_y * t4k_w * 32 * 32;
+
+	/* X and Y coordinates in number of 1K tiles (16x16) within the 4K tile. */
+	t1k_x = (x % 32) / 16;
+	t1k_y = (y % 32) / 16;
+
+	index = 2 * t1k_y + t1k_x;
+
+	if (t4k_y % 2) {
+		/* Odd rows start from the right. */
+		offset += (t4k_w - t4k_x - 1) * 32 * 32;
+		offset += t1k_map_odd[index] * 16 * 16;
+	} else {
+		/* Even rows start from the left. */
+		offset += t4k_x * 32 * 32;
+		offset += t1k_map_even[index] * 16 * 16;
+	}
+
+	/* X and Y coordinates in number of 64 byte tiles (4x4) within the 1K tile. */
+	t64b_x = (x % 16) / 4;
+	t64b_y = (y % 16) / 4;
+
+	/* Increase offset to the beginning of the corresponding 64 byte tile. */
+	offset += t64b_y * 4 * 4 * 4 + t64b_x * 4 * 4;
+
+	/* X and Y coordinates in number of pixels within the 64 byte tile. */
+	pix_x = x % 4;
+	pix_y = y % 4;
+
+	/* Increase offset to the correct pixel. */
+	offset += pix_y * 4 + pix_x;
+
+	/* Multiply by the number of bytes per pixel for the format. */
+	offset *= 4;
+
+	return offset;
+}
diff --git a/lib/igt_vc4.h b/lib/igt_vc4.h
index ebc8a388..ab44f771 100644
--- a/lib/igt_vc4.h
+++ b/lib/igt_vc4.h
@@ -33,4 +33,8 @@ bool igt_vc4_purgeable_bo(int fd, int handle, bool purgeable);
 void igt_vc4_set_tiling(int fd, uint32_t handle, uint64_t modifier);
 uint64_t igt_vc4_get_tiling(int fd, uint32_t handle);
 
+unsigned int igt_vc4_fb_t_tiled_convert(struct igt_fb *dst, struct igt_fb *src);
+size_t igt_vc4_t_tiled_offset(size_t width, size_t height, size_t format,
+			      size_t x, size_t y);
+
 #endif /* IGT_VC4_H */
-- 
2.19.2

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

  parent reply	other threads:[~2018-12-06 14:13 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-06 14:11 [igt-dev] [PATCH i-g-t 0/9] Chamelium VC4 plane testing, with T-tiled mode Paul Kocialkowski
2018-12-06 14:11 ` [igt-dev] [PATCH i-g-t 1/9] chamelium: Pass dimensions instead of mode to pattern generation helper Paul Kocialkowski
2018-12-06 21:43   ` Lyude Paul
2018-12-07  7:37     ` Paul Kocialkowski
2018-12-07 22:41       ` Lyude Paul
2018-12-06 14:11 ` [igt-dev] [PATCH i-g-t 2/9] chamelium: Pass the pattern block size as argument to helpers Paul Kocialkowski
2018-12-06 22:54   ` Lyude Paul
2018-12-06 14:11 ` [igt-dev] [PATCH i-g-t 3/9] lib: drmtest: Add helpers to check and require the VC4 driver Paul Kocialkowski
2018-12-06 22:55   ` Lyude Paul
2018-12-06 14:11 ` [igt-dev] [PATCH i-g-t 4/9] lib/igt_fb: Add checks on i915 for i915-specific tiled buffer allocation Paul Kocialkowski
2018-12-06 14:30   ` Maxime Ripard
2018-12-10 16:30   ` Ville Syrjälä
2018-12-13 13:29     ` Paul Kocialkowski
2018-12-06 14:11 ` [igt-dev] [PATCH i-g-t 5/9] lib/igt_fb: Add support for allocating T-tiled VC4 buffers Paul Kocialkowski
2018-12-06 14:11 ` Paul Kocialkowski [this message]
2018-12-06 21:51   ` [igt-dev] [PATCH i-g-t 6/9] lib/igt_vc4: Add helpers for converting linear to T-tiled XRGB buffers Lyude Paul
2018-12-07  7:38     ` Paul Kocialkowski
2018-12-06 14:11 ` [igt-dev] [PATCH i-g-t 7/9] lib/igt_fb: Add a stride-provisioned fashion of igt_fb_convert Paul Kocialkowski
2018-12-06 14:32   ` Maxime Ripard
2018-12-06 22:57   ` Lyude Paul
2018-12-06 14:11 ` [igt-dev] [PATCH i-g-t 8/9] lib/igt_fb: Add a helper to retreive the plane bpp for a given format Paul Kocialkowski
2018-12-06 22:58   ` Lyude Paul
2018-12-06 14:11 ` [igt-dev] [PATCH i-g-t 9/9] chamelium: Add a CRC-based display test for randomized planes Paul Kocialkowski
2018-12-06 14:49   ` Maxime Ripard
2018-12-06 22:52   ` Lyude Paul
2018-12-13 14:39     ` Paul Kocialkowski
2018-12-06 14:19 ` [igt-dev] ✗ Fi.CI.BAT: failure for Chamelium VC4 plane testing, with T-tiled mode 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=20181206141132.23349-7-paul.kocialkowski@bootlin.com \
    --to=paul.kocialkowski@bootlin.com \
    --cc=eben@raspberrypi.org \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=petri.latvala@intel.com \
    --cc=thomas.petazzoni@bootlin.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox