[igt-dev] [PATCH i-g-t v27 26/30] tests/gem_render_tiled_blits: remove libdrm dependency

Zbigniew Kempczyński
2020-08-10T09:48:40Z

Use intel_bb / intel_buf to remove libdrm dependency.

Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
Cc: Dominik Grzegorzek <dominik.grzegorzek@intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
---
tests/i915/gem_render_tiled_blits.c | 93 +++++++++++++++--------------
1 file changed, 47 insertions(+), 46 deletions(-)

diff --git a/tests/i915/gem_render_tiled_blits.c b/tests/i915/gem_render_tiled_blits.c
index bd76066a..0d83a43e 100644
--- a/tests/i915/gem_render_tiled_blits.c
+++ b/tests/i915/gem_render_tiled_blits.c
@@ -42,12 +42,12 @@
#include <errno.h>
#include <sys/stat.h>
#include <sys/time.h>
+#include <sys/mman.h>

#include <drm.h>

#include "i915/gem.h"
#include "igt.h"
-#include "intel_bufmgr.h"

#define WIDTH 512
#define STRIDE (WIDTH*4)
@@ -55,29 +55,26 @@
#define SIZE (HEIGHT*STRIDE)

static igt_render_copyfunc_t render_copy;
-static drm_intel_bo *linear;
+static struct intel_buf linear;
static uint32_t data[WIDTH*HEIGHT];
static int snoop;

static void
-check_bo(struct intel_batchbuffer *batch, struct igt_buf *buf, uint32_t val)
+check_buf(struct intel_bb *ibb, struct intel_buf *buf, uint32_t val)
{
- struct igt_buf tmp = {};
+ int i915 = buf_ops_get_fd(linear.bops);
uint32_t *ptr;
int i;

- tmp.bo = linear;
- tmp.surface[0].stride = STRIDE;
- tmp.tiling = I915_TILING_NONE;
- tmp.surface[0].size = SIZE;
- tmp.bpp = 32;
+ render_copy(ibb, 0, buf, 0, 0, WIDTH, HEIGHT, &linear, 0, 0);
+ intel_bb_sync(ibb);

- render_copy(batch, NULL, buf, 0, 0, WIDTH, HEIGHT, &tmp, 0, 0);
if (snoop) {
- do_or_die(drm_intel_bo_map(linear, 0));
- ptr = linear->virtual;
+ ptr = gem_mmap__cpu_coherent(i915, linear.handle, 0,
+ linear.surface[0].size, PROT_READ);
+ gem_set_domain(i915, linear.handle, I915_GEM_DOMAIN_CPU, 0);
} else {
- do_or_die(drm_intel_bo_get_subdata(linear, 0, sizeof(data), data));
+ gem_read(i915, linear.handle, 0, data, sizeof(data));
ptr = data;
}
for (i = 0; i < WIDTH*HEIGHT; i++) {
@@ -88,15 +85,15 @@ check_bo(struct intel_batchbuffer *batch, struct igt_buf *buf, uint32_t val)
val++;
}
if (ptr != data)
- drm_intel_bo_unmap(linear);
+ munmap(ptr, linear.surface[0].size);
}

static void run_test (int fd, int count)
{
- drm_intel_bufmgr *bufmgr;
- struct intel_batchbuffer *batch;
+ struct buf_ops *bops;
+ struct intel_bb *ibb;
uint32_t *start_val;
- struct igt_buf *buf;
+ struct intel_buf *bufs;
uint32_t start = 0;
int i, j;
uint32_t devid;
@@ -112,66 +109,67 @@ static void run_test (int fd, int count)
if (IS_BROADWATER(devid) || IS_CRESTLINE(devid)) /* snafu */
snoop = 0;

- bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
- drm_intel_bufmgr_gem_set_vma_cache_size(bufmgr, 32);
- batch = intel_batchbuffer_alloc(bufmgr, devid);
+ bops = buf_ops_create(fd);
+ ibb = intel_bb_create(fd, 4096);

- linear = drm_intel_bo_alloc(bufmgr, "linear", WIDTH*HEIGHT*4, 0);
+ intel_buf_init(bops, &linear, WIDTH, HEIGHT, 32, 0,
+ I915_TILING_NONE, I915_COMPRESSION_NONE);
if (snoop) {
- gem_set_caching(fd, linear->handle, 1);
+ gem_set_caching(fd, linear.handle, 1);
igt_info("Using a snoop linear buffer for comparisons\n");
}

- buf = calloc(sizeof(*buf), count);
+ bufs = calloc(sizeof(*bufs), count);
start_val = malloc(sizeof(*start_val)*count);

for (i = 0; i < count; i++) {
uint32_t tiling = I915_TILING_X + (random() & 1);
- unsigned long pitch = STRIDE;
uint32_t *ptr;

- buf[i].bo = drm_intel_bo_alloc_tiled(bufmgr, "",
- WIDTH, HEIGHT, 4,
- &tiling, &pitch, 0);
- buf[i].surface[0].stride = pitch;
- buf[i].tiling = tiling;
- buf[i].surface[0].size = SIZE;
- buf[i].bpp = 32;
-
+ intel_buf_init(bops, &bufs[i], WIDTH, HEIGHT, 32, 0,
+ tiling, I915_COMPRESSION_NONE);
start_val[i] = start;

- do_or_die(drm_intel_gem_bo_map_gtt(buf[i].bo));
- ptr = buf[i].bo->virtual;
+ ptr = gem_mmap__gtt(fd, bufs[i].handle,
+ bufs[i].surface[0].size, PROT_WRITE);
+ gem_set_domain(fd, bufs[i].handle,
+ I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT);
for (j = 0; j < WIDTH*HEIGHT; j++)
ptr[j] = start++;
- drm_intel_gem_bo_unmap_gtt(buf[i].bo);
+
+ munmap(ptr, bufs[i].surface[0].size);
}

igt_info("Verifying initialisation...\n");
for (i = 0; i < count; i++)
- check_bo(batch, &buf[i], start_val[i]);
+ check_buf(ibb, &bufs[i], start_val[i]);

igt_info("Cyclic blits, forward...\n");
for (i = 0; i < count * 4; i++) {
int src = i % count;
int dst = (i + 1) % count;

- render_copy(batch, NULL, buf+src, 0, 0, WIDTH, HEIGHT, buf+dst, 0, 0);
+ render_copy(ibb, 0, &bufs[src], 0, 0, WIDTH, HEIGHT,
+ &bufs[dst], 0, 0);
start_val[dst] = start_val[src];
}
+ intel_bb_sync(ibb);
+
for (i = 0; i < count; i++)
- check_bo(batch, &buf[i], start_val[i]);
+ check_buf(ibb, &bufs[i], start_val[i]);

igt_info("Cyclic blits, backward...\n");
for (i = 0; i < count * 4; i++) {
int src = (i + 1) % count;
int dst = i % count;

- render_copy(batch, NULL, buf+src, 0, 0, WIDTH, HEIGHT, buf+dst, 0, 0);
+ render_copy(ibb, 0, &bufs[src], 0, 0, WIDTH, HEIGHT,
+ &bufs[dst], 0, 0);
start_val[dst] = start_val[src];
}
+ intel_bb_sync(ibb);
for (i = 0; i < count; i++)
- check_bo(batch, &buf[i], start_val[i]);
+ check_buf(ibb, &bufs[i], start_val[i]);

igt_info("Random blits...\n");
for (i = 0; i < count * 4; i++) {
@@ -181,19 +179,22 @@ static void run_test (int fd, int count)
if (src == dst)
continue;

- render_copy(batch, NULL, buf+src, 0, 0, WIDTH, HEIGHT, buf+dst, 0, 0);
+ render_copy(ibb, 0, &bufs[src], 0, 0, WIDTH, HEIGHT,
+ &bufs[dst], 0, 0);
start_val[dst] = start_val[src];
}
+ intel_bb_sync(ibb);
+
for (i = 0; i < count; i++)
- check_bo(batch, &buf[i], start_val[i]);
+ check_buf(ibb, &bufs[i], start_val[i]);

/* release resources */
- drm_intel_bo_unreference(linear);
+ intel_buf_close(bops, &linear);
for (i = 0; i < count; i++) {
- drm_intel_bo_unreference(buf[i].bo);
+ intel_buf_close(bops, &bufs[i]);
}
- intel_batchbuffer_free(batch);
- drm_intel_bufmgr_destroy(bufmgr);
+ intel_bb_destroy(ibb);
+ buf_ops_destroy(bops);