[PATCH i-g-t 5/6] lib/i915_blt: Extract init functions for blt_copy_object

Karolina Stolarek karolina.stolarek at intel.com
Fri Dec 16 15:04:38 UTC 2022


gem_ccs and gem_lmem_swapping share a couple of functions. Extract them
to i915_blt so they are accessible for both tests. Delete local
definitions. Extract structs that can be used in blit multicopy test cases.

Signed-off-by: Karolina Stolarek <karolina.stolarek at intel.com>
---
 lib/i915/i915_blt.c            |  80 ++++++++++++++++++++++++
 lib/i915/i915_blt.h            |  50 +++++++++++++++
 tests/i915/gem_ccs.c           | 108 ---------------------------------
 tests/i915/gem_lmem_swapping.c |  36 -----------
 4 files changed, 130 insertions(+), 144 deletions(-)

diff --git a/lib/i915/i915_blt.c b/lib/i915/i915_blt.c
index cfc7558e..01abcc7d 100644
--- a/lib/i915/i915_blt.c
+++ b/lib/i915/i915_blt.c
@@ -1053,6 +1053,86 @@ int blt_fast_copy(int i915,
 	return ret;
 }
 
+void set_geom(struct blt_copy_object *obj, uint32_t pitch,
+	      int16_t x1, int16_t y1, int16_t x2, int16_t y2,
+	      uint16_t x_offset, uint16_t y_offset)
+{
+	obj->pitch = pitch;
+	obj->x1 = x1;
+	obj->y1 = y1;
+	obj->x2 = x2;
+	obj->y2 = y2;
+	obj->x_offset = x_offset;
+	obj->y_offset = y_offset;
+}
+
+void set_batch(struct blt_copy_batch *batch,
+	       uint32_t handle, uint64_t size, uint32_t region)
+{
+	batch->handle = handle;
+	batch->size = size;
+	batch->region = region;
+}
+
+struct blt_copy_object *
+create_object(int i915, uint32_t region,
+	      uint32_t width, uint32_t height, uint32_t bpp, uint8_t mocs,
+	      enum tiling_type tiling,
+	      enum blt_compression compression,
+	      enum blt_compression_type compression_type,
+	      bool create_mapping)
+{
+	struct blt_copy_object *obj;
+	uint64_t size = width * height * bpp / 8;
+	uint32_t stride = tiling == T_LINEAR ? width * 4 : width;
+	uint32_t handle;
+
+	obj = calloc(1, sizeof(*obj));
+
+	obj->size = size;
+	igt_assert(__gem_create_in_memory_regions(i915, &handle,
+						  &size, region) == 0);
+
+	set_object(obj, handle, size, region, mocs, tiling,
+		   compression, compression_type);
+	set_geom(obj, stride, 0, 0, width, height, 0, 0);
+
+	if (create_mapping)
+		obj->ptr = gem_mmap__device_coherent(i915, handle, 0, size,
+						     PROT_READ | PROT_WRITE);
+
+	return obj;
+}
+
+void destroy_object(int i915, struct blt_copy_object *obj)
+{
+	if (obj->ptr)
+		munmap(obj->ptr, obj->size);
+
+	gem_close(i915, obj->handle);
+}
+
+void set_object(struct blt_copy_object *obj,
+		uint32_t handle, uint64_t size, uint32_t region,
+		uint8_t mocs, enum tiling_type tiling,
+		enum blt_compression compression,
+		enum blt_compression_type compression_type)
+{
+	obj->handle = handle;
+	obj->size = size;
+	obj->region = region;
+	obj->mocs = mocs;
+	obj->tiling = tiling;
+	obj->compression = compression;
+	obj->compression_type = compression_type;
+}
+
+void set_blt_object(struct blt_copy_object *obj,
+		    const struct blt_copy_object *orig)
+{
+	memcpy(obj, orig, sizeof(*obj));
+}
+
 /**
  * blt_surface_fill_rect:
  * @i915: drm fd
diff --git a/lib/i915/i915_blt.h b/lib/i915/i915_blt.h
index f1cf5408..d3844d2a 100644
--- a/lib/i915/i915_blt.h
+++ b/lib/i915/i915_blt.h
@@ -51,6 +51,14 @@
 
 #define CCS_RATIO 256
 
+#define PRINT_SURFACE_INFO(name, obj) do { \
+	if (param.print_surface_info) \
+		blt_surface_info((name), (obj)); } while (0)
+
+#define WRITE_PNG(fd, id, name, obj, w, h) do { \
+	if (param.write_png) \
+		blt_surface_to_png((fd), (id), (name), (obj), (w), (h)); } while (0)
+
 enum blt_color_depth {
 	CD_8bit,
 	CD_16bit,
@@ -134,6 +142,26 @@ struct blt_block_copy_data_ext {
 	struct blt_block_copy_object_ext dst;
 };
 
+struct blt_copy3_data {
+	int i915;
+	struct blt_copy_object src;
+	struct blt_copy_object mid;
+	struct blt_copy_object dst;
+	struct blt_copy_object final;
+	struct blt_copy_batch bb;
+	enum blt_color_depth color_depth;
+
+	/* debug stuff */
+	bool print_bb;
+};
+
+struct blt_block_copy3_data_ext {
+	struct blt_block_copy_object_ext src;
+	struct blt_block_copy_object_ext mid;
+	struct blt_block_copy_object_ext dst;
+	struct blt_block_copy_object_ext final;
+};
+
 enum blt_access_type {
 	INDIRECT_ACCESS,
 	DIRECT_ACCESS,
@@ -198,6 +226,28 @@ int blt_fast_copy(int i915,
 		  uint64_t ahnd,
 		  const struct blt_copy_data *blt);
 
+void set_geom(struct blt_copy_object *obj, uint32_t pitch,
+	      int16_t x1, int16_t y1, int16_t x2, int16_t y2,
+	      uint16_t x_offset, uint16_t y_offset);
+void set_batch(struct blt_copy_batch *batch,
+	       uint32_t handle, uint64_t size, uint32_t region);
+
+struct blt_copy_object *
+create_object(int i915, uint32_t region,
+	      uint32_t width, uint32_t height, uint32_t bpp, uint8_t mocs,
+	      enum tiling_type tiling,
+	      enum blt_compression compression,
+	      enum blt_compression_type compression_type,
+	      bool create_mapping);
+void destroy_object(int i915, struct blt_copy_object *obj);
+void set_object(struct blt_copy_object *obj,
+		uint32_t handle, uint64_t size, uint32_t region,
+		uint8_t mocs, enum tiling_type tiling,
+		enum blt_compression compression,
+		enum blt_compression_type compression_type);
+void set_blt_object(struct blt_copy_object *obj,
+		    const struct blt_copy_object *orig);
+
 void blt_surface_info(const char *info,
 		      const struct blt_copy_object *obj);
 void blt_surface_fill_rect(int i915, const struct blt_copy_object *obj,
diff --git a/tests/i915/gem_ccs.c b/tests/i915/gem_ccs.c
index 5f3115e7..d8be5a23 100644
--- a/tests/i915/gem_ccs.c
+++ b/tests/i915/gem_ccs.c
@@ -44,42 +44,6 @@ struct test_config {
 	bool suspend_resume;
 };
 
-static void set_object(struct blt_copy_object *obj,
-		       uint32_t handle, uint64_t size, uint32_t region,
-		       uint8_t mocs, enum tiling_type tiling,
-		       enum blt_compression compression,
-		       enum blt_compression_type compression_type)
-{
-	obj->handle = handle;
-	obj->size = size;
-	obj->region = region;
-	obj->mocs = mocs;
-	obj->tiling = tiling;
-	obj->compression = compression;
-	obj->compression_type = compression_type;
-}
-
-static void set_geom(struct blt_copy_object *obj, uint32_t pitch,
-		     int16_t x1, int16_t y1, int16_t x2, int16_t y2,
-		     uint16_t x_offset, uint16_t y_offset)
-{
-	obj->pitch = pitch;
-	obj->x1 = x1;
-	obj->y1 = y1;
-	obj->x2 = x2;
-	obj->y2 = y2;
-	obj->x_offset = x_offset;
-	obj->y_offset = y_offset;
-}
-
-static void set_batch(struct blt_copy_batch *batch,
-		      uint32_t handle, uint64_t size, uint32_t region)
-{
-	batch->handle = handle;
-	batch->size = size;
-	batch->region = region;
-}
-
 static void set_object_ext(struct blt_block_copy_object_ext *obj,
 			   uint8_t compression_format,
 			   uint16_t surface_width, uint16_t surface_height,
@@ -105,58 +69,6 @@ static void set_surf_object(struct blt_ctrl_surf_copy_object *obj,
 	obj->access_type = access_type;
 }
 
-static struct blt_copy_object *
-create_object(int i915, uint32_t region,
-	      uint32_t width, uint32_t height, uint32_t bpp, uint8_t mocs,
-	      enum tiling_type tiling,
-	      enum blt_compression compression,
-	      enum blt_compression_type compression_type,
-	      bool create_mapping)
-{
-	struct blt_copy_object *obj;
-	uint64_t size = width * height * bpp / 8;
-	uint32_t stride = tiling == T_LINEAR ? width * 4 : width;
-	uint32_t handle;
-
-	obj = calloc(1, sizeof(*obj));
-
-	obj->size = size;
-	igt_assert(__gem_create_in_memory_regions(i915, &handle,
-						  &size, region) == 0);
-
-	set_object(obj, handle, size, region, mocs, tiling,
-		   compression, compression_type);
-	set_geom(obj, stride, 0, 0, width, height, 0, 0);
-
-	if (create_mapping)
-		obj->ptr = gem_mmap__device_coherent(i915, handle, 0, size,
-						     PROT_READ | PROT_WRITE);
-
-	return obj;
-}
-
-static void destroy_object(int i915, struct blt_copy_object *obj)
-{
-	if (obj->ptr)
-		munmap(obj->ptr, obj->size);
-
-	gem_close(i915, obj->handle);
-}
-
-static void set_blt_object(struct blt_copy_object *obj,
-			   const struct blt_copy_object *orig)
-{
-	memcpy(obj, orig, sizeof(*obj));
-}
-
-#define PRINT_SURFACE_INFO(name, obj) do { \
-	if (param.print_surface_info) \
-		blt_surface_info((name), (obj)); } while (0)
-
-#define WRITE_PNG(fd, id, name, obj, w, h) do { \
-	if (param.write_png) \
-		blt_surface_to_png((fd), (id), (name), (obj), (w), (h)); } while (0)
-
 static void surf_copy(int i915,
 		      const intel_ctx_t *ctx,
 		      const struct intel_execution_engine2 *e,
@@ -262,26 +174,6 @@ static void surf_copy(int i915,
 	gem_close(i915, ccs);
 }
 
-struct blt_copy3_data {
-	int i915;
-	struct blt_copy_object src;
-	struct blt_copy_object mid;
-	struct blt_copy_object dst;
-	struct blt_copy_object final;
-	struct blt_copy_batch bb;
-	enum blt_color_depth color_depth;
-
-	/* debug stuff */
-	bool print_bb;
-};
-
-struct blt_block_copy3_data_ext {
-	struct blt_block_copy_object_ext src;
-	struct blt_block_copy_object_ext mid;
-	struct blt_block_copy_object_ext dst;
-	struct blt_block_copy_object_ext final;
-};
-
 #define FILL_OBJ(_idx, _handle, _offset, _flags) do { \
 	obj[(_idx)].handle = (_handle); \
 	obj[(_idx)].offset = (_offset); \
diff --git a/tests/i915/gem_lmem_swapping.c b/tests/i915/gem_lmem_swapping.c
index 8cff35d5..746fbf80 100644
--- a/tests/i915/gem_lmem_swapping.c
+++ b/tests/i915/gem_lmem_swapping.c
@@ -76,42 +76,6 @@ struct object {
 	struct blt_copy_object *blt_obj;
 };
 
-static void set_object(struct blt_copy_object *obj,
-		       uint32_t handle, uint64_t size, uint32_t region,
-		       uint8_t mocs, enum tiling_type tiling,
-		       enum blt_compression compression,
-		       enum blt_compression_type compression_type)
-{
-	obj->handle = handle;
-	obj->size = size;
-	obj->region = region;
-	obj->mocs = mocs;
-	obj->tiling = tiling;
-	obj->compression = compression;
-	obj->compression_type = compression_type;
-}
-
-static void set_geom(struct blt_copy_object *obj, uint32_t pitch,
-		     int16_t x1, int16_t y1, int16_t x2, int16_t y2,
-		     uint16_t x_offset, uint16_t y_offset)
-{
-	obj->pitch = pitch;
-	obj->x1 = x1;
-	obj->y1 = y1;
-	obj->x2 = x2;
-	obj->y2 = y2;
-	obj->x_offset = x_offset;
-	obj->y_offset = y_offset;
-}
-
-static void set_batch(struct blt_copy_batch *batch,
-		      uint32_t handle, uint64_t size, uint32_t region)
-{
-	batch->handle = handle;
-	batch->size = size;
-	batch->region = region;
-}
-
 static void set_object_ext(struct blt_block_copy_object_ext *obj,
 			   uint8_t compression_format,
 			   uint16_t surface_width, uint16_t surface_height,
-- 
2.25.1



More information about the Intel-gfx-trybot mailing list