All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Zbigniew Kempczyński" <zbigniew.kempczynski@intel.com>
To: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [PATCH i-g-t v7 3/5] lib/rendercopy_bufmgr: Add rendercopy buffer manager
Date: Mon, 13 Jan 2020 10:19:06 +0100	[thread overview]
Message-ID: <20200113091908.11983-4-zbigniew.kempczynski@intel.com> (raw)
In-Reply-To: <20200113091908.11983-1-zbigniew.kempczynski@intel.com>

This is middle layer between render copy tests and buffer operations
(buf_ops). Render copy tests uses libdrm so adding wrapper to independent
buf_ops was necessary.

Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Katarzyna Dec <katarzyna.dec@intel.com>
---
 lib/Makefile.sources    |   2 +
 lib/meson.build         |   1 +
 lib/rendercopy_bufmgr.c | 175 ++++++++++++++++++++++++++++++++++++++++
 lib/rendercopy_bufmgr.h |  28 +++++++
 4 files changed, 206 insertions(+)
 create mode 100644 lib/rendercopy_bufmgr.c
 create mode 100644 lib/rendercopy_bufmgr.h

diff --git a/lib/Makefile.sources b/lib/Makefile.sources
index da34eae7..feb8c20d 100644
--- a/lib/Makefile.sources
+++ b/lib/Makefile.sources
@@ -95,6 +95,8 @@ lib_source_list =	 	\
 	gen7_render.h		\
 	gen8_render.h		\
 	gen9_render.h		\
+	rendercopy_bufmgr.c	\
+	rendercopy_bufmgr.h	\
 	rendercopy_gen4.c	\
 	rendercopy_gen6.c	\
 	rendercopy_gen7.c	\
diff --git a/lib/meson.build b/lib/meson.build
index cf3e35da..3bf39915 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -39,6 +39,7 @@ lib_sources = [
 	'gpu_cmds.c',
 	'rendercopy_i915.c',
 	'rendercopy_i830.c',
+	'rendercopy_bufmgr.c',
 	'rendercopy_gen4.c',
 	'rendercopy_gen6.c',
 	'rendercopy_gen7.c',
diff --git a/lib/rendercopy_bufmgr.c b/lib/rendercopy_bufmgr.c
new file mode 100644
index 00000000..19d3a03e
--- /dev/null
+++ b/lib/rendercopy_bufmgr.c
@@ -0,0 +1,175 @@
+/*
+ * Copyright © 2020 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ */
+
+#include <sys/ioctl.h>
+#include "igt.h"
+#include "igt_x86.h"
+#include "rendercopy_bufmgr.h"
+
+/**
+ * SECTION:rendercopy_bufmgr
+ * @short_description: Render copy buffer manager
+ * @title: Render copy bufmgr
+ * @include: igt.h
+ *
+ * # Rendercopy buffer manager
+ *
+ * Rendercopy depends on libdrm and igt_buf, so some middle layer to intel_buf
+ * and buf_ops is required.
+ *
+ * |[<!-- language="c" -->
+ * struct rendercopy_bufmgr *bmgr;
+ * ...
+ * bmgr = rendercopy_bufmgr_create(fd, bufmgr);
+ * ...
+ * igt_buf_init(bmgr, &buf, 512, 512, 32, I915_TILING_X, false);
+ * ...
+ * linear_to_igt_buf(bmgr, &buf, linear);
+ * ...
+ * igt_buf_to_linear(bmgr, &buf, linear);
+ * ...
+ * rendercopy_bufmgr_destroy(bmgr);
+ * ]|
+ */
+
+struct rendercopy_bufmgr {
+	int fd;
+	drm_intel_bufmgr *bufmgr;
+	struct buf_ops *bops;
+};
+
+static void __igt_buf_to_intel_buf(struct igt_buf *buf, struct intel_buf *ibuf)
+{
+	ibuf->handle = buf->bo->handle;
+	ibuf->stride = buf->surface[0].stride;
+	ibuf->tiling = buf->tiling;
+	ibuf->bpp = buf->bpp;
+	ibuf->size = buf->surface[0].size;
+	ibuf->compression = buf->compression;
+	ibuf->aux.offset = buf->ccs[0].offset;
+	ibuf->aux.stride = buf->ccs[0].stride;
+}
+
+void igt_buf_to_linear(struct rendercopy_bufmgr *bmgr, struct igt_buf *buf,
+		       uint32_t *linear)
+{
+	struct intel_buf ibuf;
+
+	__igt_buf_to_intel_buf(buf, &ibuf);
+
+	intel_buf_to_linear(bmgr->bops, &ibuf, linear);
+}
+
+void linear_to_igt_buf(struct rendercopy_bufmgr *bmgr, struct igt_buf *buf,
+		       uint32_t *linear)
+{
+	struct intel_buf ibuf;
+
+	__igt_buf_to_intel_buf(buf, &ibuf);
+
+	linear_to_intel_buf(bmgr->bops, &ibuf, linear);
+}
+
+struct rendercopy_bufmgr *rendercopy_bufmgr_create(int fd,
+						   drm_intel_bufmgr *bufmgr)
+{
+	struct buf_ops *bops;
+	struct rendercopy_bufmgr *bmgr;
+
+	igt_assert(bufmgr);
+
+	bops = buf_ops_create(fd);
+	igt_assert(bops);
+
+	bmgr = calloc(1, sizeof(*bmgr));
+	igt_assert(bmgr);
+
+	bmgr->fd = fd;
+	bmgr->bufmgr = bufmgr;
+	bmgr->bops = bops;
+
+	return bmgr;
+}
+
+void rendercopy_bufmgr_destroy(struct rendercopy_bufmgr *bmgr)
+{
+	igt_assert(bmgr);
+	igt_assert(bmgr->bops);
+
+	buf_ops_destroy(bmgr->bops);
+	free(bmgr);
+}
+
+bool rendercopy_bufmgr_set_software_tiling(struct rendercopy_bufmgr *bmgr,
+					   uint32_t tiling,
+					   bool use_software_tiling)
+{
+	return buf_ops_set_software_tiling(bmgr->bops, tiling,
+					   use_software_tiling);
+}
+
+void igt_buf_init(struct rendercopy_bufmgr *bmgr, struct igt_buf *buf,
+		  int width, int height, int bpp,
+		  uint32_t tiling, uint32_t compression)
+{
+	struct intel_buf ibuf;
+	int size;
+	int ccs_width, ccs_height;
+	uint32_t devid;
+	int generation;
+
+	devid = intel_get_drm_devid(bmgr->fd);
+	generation = intel_gen(devid);
+
+	igt_assert(buf);
+	memset(buf, 0, sizeof(*buf));
+
+	buf->surface[0].stride = ALIGN(width * (bpp / 8), 128);
+	buf->surface[0].size = buf->surface[0].stride * height;
+	buf->tiling = tiling;
+	buf->bpp = bpp;
+	buf->compression = compression;
+
+	ccs_width = igt_buf_intel_ccs_width(generation, buf);
+	ccs_height = igt_buf_intel_ccs_height(generation, buf);
+
+	size = buf->surface[0].stride * ALIGN(height, 32);
+
+	if (compression) {
+		buf->ccs[0].offset = buf->surface[0].stride * ALIGN(height, 32);
+		buf->ccs[0].stride = ccs_width;
+		size = buf->ccs[0].offset + ccs_width * ccs_height;
+	}
+
+	buf->bo = drm_intel_bo_alloc(bmgr->bufmgr, "", size, 4096);
+
+	intel_buf_init_using_handle(bmgr->bops,
+				    buf->bo->handle,
+				    &ibuf,
+				    width, height, bpp, tiling,
+				    compression);
+
+	buf->ccs[0].offset = ibuf.aux.offset;
+	buf->ccs[0].stride = ibuf.aux.stride;
+}
diff --git a/lib/rendercopy_bufmgr.h b/lib/rendercopy_bufmgr.h
new file mode 100644
index 00000000..f4e5118c
--- /dev/null
+++ b/lib/rendercopy_bufmgr.h
@@ -0,0 +1,28 @@
+#ifndef __RENDERCOPY_BUFMGR_H__
+#define __RENDERCOPY_BUFMGR_H__
+
+#include <stdint.h>
+#include "intel_bufops.h"
+#include "intel_batchbuffer.h"
+
+struct rendercopy_bufmgr;
+
+struct rendercopy_bufmgr *rendercopy_bufmgr_create(int fd,
+						   drm_intel_bufmgr *bufmgr);
+void rendercopy_bufmgr_destroy(struct rendercopy_bufmgr *bmgr);
+
+bool rendercopy_bufmgr_set_software_tiling(struct rendercopy_bufmgr *bmgr,
+					   uint32_t tiling,
+					   bool use_software_tiling);
+
+void igt_buf_to_linear(struct rendercopy_bufmgr *bmgr, struct igt_buf *buf,
+		       uint32_t *linear);
+
+void linear_to_igt_buf(struct rendercopy_bufmgr *bmgr, struct igt_buf *buf,
+		       uint32_t *linear);
+
+void igt_buf_init(struct rendercopy_bufmgr *bmgr, struct igt_buf *buf,
+		  int width, int height, int bpp,
+		  uint32_t tiling, uint32_t compression);
+
+#endif
-- 
2.23.0

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

  parent reply	other threads:[~2020-01-13  9:19 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-13  9:19 [igt-dev] [PATCH i-g-t v7 0/5] Simplify working on tiled surfaces over GenX Zbigniew Kempczyński
2020-01-13  9:19 ` [igt-dev] [PATCH i-g-t v7 1/5] lib/intel_bufops: Introduce buffer operations Zbigniew Kempczyński
2020-01-13 15:59   ` Chris Wilson
2020-01-13  9:19 ` [igt-dev] [PATCH i-g-t v7 2/5] lib/intel_batchbuffer: Add CCS width/height functions for Intel igt_buf Zbigniew Kempczyński
2020-01-13  9:19 ` Zbigniew Kempczyński [this message]
2020-01-13  9:19 ` [igt-dev] [PATCH i-g-t v7 4/5] i915/gem_render_copy.c: Simplify code by switch to rendercopy bufmgr Zbigniew Kempczyński
2020-01-13 16:07   ` Chris Wilson
2020-01-13  9:19 ` [igt-dev] [PATCH i-g-t v7 5/5] HAX: run gem_render_copy tests in BAT Zbigniew Kempczyński
2020-01-13  9:46 ` [igt-dev] ✗ Fi.CI.BAT: failure for Simplify working on tiled surfaces over GenX (rev3) Patchwork
2020-01-13 16:09   ` Chris Wilson
2020-01-13 14:28 ` [igt-dev] ✗ GitLab.Pipeline: warning " 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=20200113091908.11983-4-zbigniew.kempczynski@intel.com \
    --to=zbigniew.kempczynski@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    /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.