[igt-dev] [PATCH i-g-t v2 1/3] lib: Separated emit part of gpgpu_fill.

Tomasz Lis tomasz.lis at intel.com
Fri Oct 5 18:04:34 UTC 2018


From: "Lis, Tomasz" <tomasz.lis at intel.com>

Having emitting and sumbission in one function was restricting
possible use cases of the code. Now it is possible to emit
the gpgpu_fill to a batchbuffer with something already there,
or add more commands after.

Cc: Joonas Lahtinen <joonas.lahtinen at linux.intel.com>
Cc: Chris Wilson <chris at chris-wilson.co.uk>
Cc: Michal Winiarski <michal.winiarski at intel.com>

Signed-off-by: Tomasz Lis <tomasz.lis at intel.com>
---
 lib/gpgpu_fill.c        | 59 ++++++++++++++++---------------------------------
 lib/gpgpu_fill.h        |  8 +++----
 lib/intel_batchbuffer.c | 12 +++++-----
 lib/intel_batchbuffer.h |  2 +-
 tests/gem_gpgpu_fill.c  | 19 ++++++++++++----
 5 files changed, 45 insertions(+), 55 deletions(-)

diff --git a/lib/gpgpu_fill.c b/lib/gpgpu_fill.c
index 003f461..654b791 100644
--- a/lib/gpgpu_fill.c
+++ b/lib/gpgpu_fill.c
@@ -117,18 +117,17 @@ static const uint32_t gen11_gpgpu_kernel[][4] = {
 #define GEN7_VFE_STATE_GPGPU_MODE 1
 
 void
-gen7_gpgpu_fillfunc(struct intel_batchbuffer *batch,
+gen7_emit_gpgpu_fillfunc(struct intel_batchbuffer *batch,
 		    const struct igt_buf *dst,
 		    unsigned int x, unsigned int y,
 		    unsigned int width, unsigned int height,
 		    uint8_t color)
 {
 	uint32_t curbe_buffer, interface_descriptor;
-	uint32_t batch_end;
-
-	intel_batchbuffer_flush(batch);
+	uint8_t *prev_ptr;
 
 	/* setup states */
+	prev_ptr = batch->ptr;
 	batch->ptr = &batch->buffer[BATCH_STATE_SPLIT];
 
 	/*
@@ -143,7 +142,7 @@ gen7_gpgpu_fillfunc(struct intel_batchbuffer *batch,
 
 	igt_assert(batch->ptr < &batch->buffer[4095]);
 
-	batch->ptr = batch->buffer;
+	batch->ptr = prev_ptr;
 
 	/* GPGPU pipeline */
 	OUT_BATCH(GEN7_PIPELINE_SELECT | PIPELINE_SELECT_GPGPU);
@@ -156,28 +155,21 @@ gen7_gpgpu_fillfunc(struct intel_batchbuffer *batch,
 	gen7_emit_interface_descriptor_load(batch, interface_descriptor);
 	gen7_emit_gpgpu_walk(batch, x, y, width, height);
 
-	OUT_BATCH(MI_BATCH_BUFFER_END);
-
-	batch_end = intel_batchbuffer_align(batch, 8);
-	igt_assert(batch_end < BATCH_STATE_SPLIT);
-
-	gen7_render_flush(batch, batch_end);
-	intel_batchbuffer_reset(batch);
+	igt_assert(batch->ptr + 8 < batch->buffer + BATCH_STATE_SPLIT);
 }
 
 void
-gen8_gpgpu_fillfunc(struct intel_batchbuffer *batch,
+gen8_emit_gpgpu_fillfunc(struct intel_batchbuffer *batch,
 		    const struct igt_buf *dst,
 		    unsigned int x, unsigned int y,
 		    unsigned int width, unsigned int height,
 		    uint8_t color)
 {
 	uint32_t curbe_buffer, interface_descriptor;
-	uint32_t batch_end;
-
-	intel_batchbuffer_flush(batch);
+	uint8_t *prev_ptr;
 
 	/* setup states */
+	prev_ptr = batch->ptr;
 	batch->ptr = &batch->buffer[BATCH_STATE_SPLIT];
 
 	/*
@@ -192,7 +184,7 @@ gen8_gpgpu_fillfunc(struct intel_batchbuffer *batch,
 
 	igt_assert(batch->ptr < &batch->buffer[4095]);
 
-	batch->ptr = batch->buffer;
+	batch->ptr = prev_ptr;
 
 	/* GPGPU pipeline */
 	OUT_BATCH(GEN7_PIPELINE_SELECT | PIPELINE_SELECT_GPGPU);
@@ -204,17 +196,11 @@ gen8_gpgpu_fillfunc(struct intel_batchbuffer *batch,
 	gen7_emit_interface_descriptor_load(batch, interface_descriptor);
 	gen8_emit_gpgpu_walk(batch, x, y, width, height);
 
-	OUT_BATCH(MI_BATCH_BUFFER_END);
-
-	batch_end = intel_batchbuffer_align(batch, 8);
-	igt_assert(batch_end < BATCH_STATE_SPLIT);
-
-	gen7_render_flush(batch, batch_end);
-	intel_batchbuffer_reset(batch);
+	igt_assert(batch->ptr + 8 < batch->buffer + BATCH_STATE_SPLIT);
 }
 
 static void
-__gen9_gpgpu_fillfunc(struct intel_batchbuffer *batch,
+__gen9_emit_gpgpu_fill(struct intel_batchbuffer *batch,
 		      const struct igt_buf *dst,
 		      unsigned int x, unsigned int y,
 		      unsigned int width, unsigned int height,
@@ -222,11 +208,10 @@ __gen9_gpgpu_fillfunc(struct intel_batchbuffer *batch,
 		      size_t kernel_size)
 {
 	uint32_t curbe_buffer, interface_descriptor;
-	uint32_t batch_end;
-
-	intel_batchbuffer_flush(batch);
+	uint8_t *prev_ptr;
 
 	/* setup states */
+	prev_ptr = batch->ptr;
 	batch->ptr = &batch->buffer[BATCH_STATE_SPLIT];
 
 	/*
@@ -241,7 +226,7 @@ __gen9_gpgpu_fillfunc(struct intel_batchbuffer *batch,
 
 	igt_assert(batch->ptr < &batch->buffer[4095]);
 
-	batch->ptr = batch->buffer;
+	batch->ptr = prev_ptr;
 
 	/* GPGPU pipeline */
 	OUT_BATCH(GEN7_PIPELINE_SELECT | GEN9_PIPELINE_SELECTION_MASK |
@@ -254,31 +239,25 @@ __gen9_gpgpu_fillfunc(struct intel_batchbuffer *batch,
 	gen7_emit_interface_descriptor_load(batch, interface_descriptor);
 	gen8_emit_gpgpu_walk(batch, x, y, width, height);
 
-	OUT_BATCH(MI_BATCH_BUFFER_END);
-
-	batch_end = intel_batchbuffer_align(batch, 8);
-	igt_assert(batch_end < BATCH_STATE_SPLIT);
-
-	gen7_render_flush(batch, batch_end);
-	intel_batchbuffer_reset(batch);
+	igt_assert(batch->ptr + 8 < batch->buffer + BATCH_STATE_SPLIT);
 }
 
-void gen9_gpgpu_fillfunc(struct intel_batchbuffer *batch,
+void gen9_emit_gpgpu_fillfunc(struct intel_batchbuffer *batch,
 			 const struct igt_buf *dst,
 			 unsigned int x, unsigned int y,
 			 unsigned int width, unsigned int height,
 			 uint8_t color)
 {
-	__gen9_gpgpu_fillfunc(batch, dst, x, y, width, height, color,
+	__gen9_emit_gpgpu_fill(batch, dst, x, y, width, height, color,
 			      gen9_gpgpu_kernel, sizeof(gen9_gpgpu_kernel));
 }
 
-void gen11_gpgpu_fillfunc(struct intel_batchbuffer *batch,
+void gen11_emit_gpgpu_fillfunc(struct intel_batchbuffer *batch,
 			  const struct igt_buf *dst,
 			  unsigned int x, unsigned int y,
 			  unsigned int width, unsigned int height,
 			  uint8_t color)
 {
-	__gen9_gpgpu_fillfunc(batch, dst, x, y, width, height, color,
+	__gen9_emit_gpgpu_fill(batch, dst, x, y, width, height, color,
 			      gen11_gpgpu_kernel, sizeof(gen11_gpgpu_kernel));
 }
diff --git a/lib/gpgpu_fill.h b/lib/gpgpu_fill.h
index e405df3..1901b1e 100644
--- a/lib/gpgpu_fill.h
+++ b/lib/gpgpu_fill.h
@@ -30,28 +30,28 @@
 #include "intel_batchbuffer.h"
 
 void
-gen7_gpgpu_fillfunc(struct intel_batchbuffer *batch,
+gen7_emit_gpgpu_fillfunc(struct intel_batchbuffer *batch,
 		    const struct igt_buf *dst,
 		    unsigned int x, unsigned int y,
 		    unsigned int width, unsigned int height,
 		    uint8_t color);
 
 void
-gen8_gpgpu_fillfunc(struct intel_batchbuffer *batch,
+gen8_emit_gpgpu_fillfunc(struct intel_batchbuffer *batch,
 		    const struct igt_buf *dst,
 		    unsigned int x, unsigned int y,
 		    unsigned int width, unsigned int height,
 		    uint8_t color);
 
 void
-gen9_gpgpu_fillfunc(struct intel_batchbuffer *batch,
+gen9_emit_gpgpu_fillfunc(struct intel_batchbuffer *batch,
 		    const struct igt_buf *dst,
 		    unsigned int x, unsigned int y,
 		    unsigned int width, unsigned int height,
 		    uint8_t color);
 
 void
-gen11_gpgpu_fillfunc(struct intel_batchbuffer *batch,
+gen11_emit_gpgpu_fillfunc(struct intel_batchbuffer *batch,
 		     const struct igt_buf *dst,
 		     unsigned int x, unsigned int y,
 		     unsigned int width, unsigned int height,
diff --git a/lib/intel_batchbuffer.c b/lib/intel_batchbuffer.c
index 387404f..dc1e6f2 100644
--- a/lib/intel_batchbuffer.c
+++ b/lib/intel_batchbuffer.c
@@ -871,7 +871,7 @@ igt_fillfunc_t igt_get_media_fillfunc(int devid)
 }
 
 /**
- * igt_get_gpgpu_fillfunc:
+ * igt_get_emit_gpgpu_fill:
  * @devid: pci device id
  *
  * Returns:
@@ -879,18 +879,18 @@ igt_fillfunc_t igt_get_media_fillfunc(int devid)
  * The platform-specific gpgpu fill function pointer for the device specified
  * with @devid. Will return NULL when no gpgpu fill function is implemented.
  */
-igt_fillfunc_t igt_get_gpgpu_fillfunc(int devid)
+igt_fillfunc_t igt_get_emit_gpgpu_fillfunc(int devid)
 {
 	igt_fillfunc_t fill = NULL;
 
 	if (IS_GEN7(devid))
-		fill = gen7_gpgpu_fillfunc;
+		fill = gen7_emit_gpgpu_fillfunc;
 	else if (IS_BROADWELL(devid))
-		fill = gen8_gpgpu_fillfunc;
+		fill = gen8_emit_gpgpu_fillfunc;
 	else if (IS_GEN9(devid) || IS_GEN10(devid))
-		fill = gen9_gpgpu_fillfunc;
+		fill = gen9_emit_gpgpu_fillfunc;
 	else if (IS_GEN11(devid))
-		fill = gen11_gpgpu_fillfunc;
+		fill = gen11_emit_gpgpu_fillfunc;
 
 	return fill;
 }
diff --git a/lib/intel_batchbuffer.h b/lib/intel_batchbuffer.h
index 2dcb09c..21babff 100644
--- a/lib/intel_batchbuffer.h
+++ b/lib/intel_batchbuffer.h
@@ -321,7 +321,7 @@ typedef void (*igt_fillfunc_t)(struct intel_batchbuffer *batch,
 			       uint8_t color);
 
 igt_fillfunc_t igt_get_media_fillfunc(int devid);
-igt_fillfunc_t igt_get_gpgpu_fillfunc(int devid);
+igt_fillfunc_t igt_get_emit_gpgpu_fillfunc(int devid);
 
 /**
  * igt_media_spinfunc_t:
diff --git a/tests/gem_gpgpu_fill.c b/tests/gem_gpgpu_fill.c
index dfb5816..d79f747 100644
--- a/tests/gem_gpgpu_fill.c
+++ b/tests/gem_gpgpu_fill.c
@@ -44,6 +44,7 @@
 #include <sys/time.h>
 #include "drm.h"
 #include "intel_bufmgr.h"
+#include "gpu_cmds.h"
 
 #define WIDTH 64
 #define HEIGHT 64
@@ -99,7 +100,8 @@ igt_simple_main
 	data_t data = {0, };
 	struct intel_batchbuffer *batch = NULL;
 	struct igt_buf dst;
-	igt_fillfunc_t gpgpu_fill = NULL;
+	igt_fillfunc_t emit_gpgpu_fill = NULL;
+        uint32_t batch_end;
 	int i, j;
 
 	data.drm_fd = drm_open_driver_render(DRIVER_INTEL);
@@ -109,9 +111,9 @@ igt_simple_main
 	data.bufmgr = drm_intel_bufmgr_gem_init(data.drm_fd, 4096);
 	igt_assert(data.bufmgr);
 
-	gpgpu_fill = igt_get_gpgpu_fillfunc(data.devid);
+	emit_gpgpu_fill = igt_get_emit_gpgpu_fillfunc(data.devid);
 
-	igt_require_f(gpgpu_fill,
+	igt_require_f(emit_gpgpu_fill,
 		      "no gpgpu-fill function\n");
 
 	batch = intel_batchbuffer_alloc(data.bufmgr, data.devid);
@@ -125,10 +127,19 @@ igt_simple_main
 		}
 	}
 
-	gpgpu_fill(batch,
+        intel_batchbuffer_flush(batch);
+
+	emit_gpgpu_fill(batch,
 		   &dst, 0, 0, WIDTH / 2, HEIGHT / 2,
 		   COLOR_4C);
 
+        OUT_BATCH(MI_BATCH_BUFFER_END);
+
+        batch_end = intel_batchbuffer_align(batch, 8);
+
+        gen7_render_flush(batch, batch_end);
+        intel_batchbuffer_reset(batch);
+
 	for (i = 0; i < WIDTH; i++) {
 		for (j = 0; j < HEIGHT; j++) {
 			if (i < WIDTH / 2 && j < HEIGHT / 2)
-- 
2.7.4



More information about the igt-dev mailing list