[igt-dev] [PATCH i-g-t 7/7] tests/gem_render_copy: Add a subtest for AUX_CCS_E
Ville Syrjala
ville.syrjala at linux.intel.com
Wed Jul 4 16:16:46 UTC 2018
From: Ville Syrjälä <ville.syrjala at linux.intel.com>
Add a new subtest that does renders the test pattern into a
compressed buffer. And we'll follow it up with another copy
back to an uncompressed buffer so that we also test the
capability to sampled from compressed buffers, and also so
that we can actually compare the results against the reference
image.
We'll also do a quick check of the aux surface to check that
it actually indicates that at least some parts of the buffer
were in fact compressed. Further visual verification can be
done via the dumped png.
Signed-off-by: Ville Syrjälä <ville.syrjala at linux.intel.com>
---
tests/gem_render_copy.c | 197 +++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 186 insertions(+), 11 deletions(-)
diff --git a/tests/gem_render_copy.c b/tests/gem_render_copy.c
index 13198dfcb3fd..a2e9d32bfed7 100644
--- a/tests/gem_render_copy.c
+++ b/tests/gem_render_copy.c
@@ -113,6 +113,61 @@ static void scratch_buf_write_to_png(data_t *data, struct igt_buf *buf,
free(linear);
}
+#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
+
+static int scratch_buf_aux_width(const struct igt_buf *buf)
+{
+ return DIV_ROUND_UP(igt_buf_width(buf), 1024) * 128;
+}
+
+static int scratch_buf_aux_height(const struct igt_buf *buf)
+{
+ return DIV_ROUND_UP(igt_buf_height(buf), 512) * 32;
+}
+
+static void *linear_copy_aux(data_t *data, struct igt_buf *buf)
+{
+ void *map, *linear;
+ int aux_size = scratch_buf_aux_width(buf) *
+ scratch_buf_aux_height(buf);
+
+ igt_assert_eq(posix_memalign(&linear, 16, aux_size), 0);
+
+ gem_set_domain(data->drm_fd, buf->bo->handle,
+ I915_GEM_DOMAIN_GTT, 0);
+
+ map = gem_mmap__gtt(data->drm_fd, buf->bo->handle,
+ buf->bo->size, PROT_READ);
+
+ igt_memcpy_from_wc(linear, map + buf->aux.offset, aux_size);
+
+ munmap(map, buf->bo->size);
+
+ return linear;
+}
+
+static void scratch_buf_aux_write_to_png(data_t *data,
+ struct igt_buf *buf,
+ const char *filename)
+{
+ cairo_surface_t *surface;
+ cairo_status_t ret;
+ void *linear;
+
+ linear = linear_copy_aux(data, buf);
+
+ surface = cairo_image_surface_create_for_data(linear,
+ CAIRO_FORMAT_A8,
+ scratch_buf_aux_width(buf),
+ scratch_buf_aux_height(buf),
+ buf->aux.stride);
+ ret = cairo_surface_write_to_png(surface, make_filename(filename));
+ igt_assert(ret == CAIRO_STATUS_SUCCESS);
+ cairo_surface_destroy(surface);
+
+ free(linear);
+}
+
static void scratch_buf_draw_pattern(data_t *data, struct igt_buf *buf,
int x, int y, int w, int h,
int cx, int cy, int cw, int ch,
@@ -215,19 +270,37 @@ scratch_buf_copy(data_t *data,
static void scratch_buf_init(data_t *data, struct igt_buf *buf,
int width, int height, int stride,
- uint32_t tiling)
+ uint32_t tiling, bool ccs)
{
- drm_intel_bo *bo;
int size = height * stride;
- bo = drm_intel_bo_alloc(data->bufmgr, "", size, 4096);
-
memset(buf, 0, sizeof(*buf));
- buf->bo = bo;
- buf->stride = stride;
- buf->tiling = tiling;
- buf->size = size;
+ if (ccs) {
+ int aux_width, aux_height;
+
+ igt_require(intel_gen(data->drm_fd) >= 9);
+
+ igt_assert_eq(tiling, I915_TILING_Y);
+
+ buf->size = size;
+ buf->stride = stride;
+ buf->tiling = tiling;
+
+ aux_width = scratch_buf_aux_width(buf);
+ aux_height = scratch_buf_aux_height(buf);
+
+ buf->aux.offset = ALIGN(size, 4096);
+ buf->aux.stride = aux_width;
+
+ size = buf->aux.offset + aux_width * aux_height;
+ } else {
+ buf->size = size;
+ buf->stride = stride;
+ buf->tiling = tiling;
+ }
+
+ buf->bo = drm_intel_bo_alloc(data->bufmgr, "", size, 4096);
drm_intel_bo_set_tiling(buf->bo, &tiling, buf->stride);
igt_assert_eq(tiling, buf->tiling);
@@ -294,14 +367,35 @@ scratch_buf_check_all(data_t *data,
free(linear_buf);
}
+static void scratch_buf_aux_check(data_t *data,
+ struct igt_buf *buf)
+{
+ int aux_size = scratch_buf_aux_width(buf) *
+ scratch_buf_aux_height(buf);
+ uint8_t *linear;
+ int i;
+
+ linear = linear_copy_aux(data, buf);
+
+ for (i = 0; i < aux_size; i++) {
+ if (linear[i])
+ break;
+ }
+
+ free(linear);
+
+ igt_assert_f(i < aux_size,
+ "Aux surface indicates that nothing was compressed\n");
+}
+
static void test_basic(data_t *data, uint32_t tiling)
{
struct igt_buf src, dst, ref;
int opt_dump_aub = igt_aub_dump_enabled();
- scratch_buf_init(data, &src, WIDTH, HEIGHT, STRIDE, tiling);
- scratch_buf_init(data, &dst, WIDTH, HEIGHT, STRIDE, tiling);
- scratch_buf_init(data, &ref, WIDTH, HEIGHT, STRIDE, I915_TILING_NONE);
+ scratch_buf_init(data, &src, WIDTH, HEIGHT, STRIDE, tiling, false);
+ scratch_buf_init(data, &dst, WIDTH, HEIGHT, STRIDE, tiling, false);
+ scratch_buf_init(data, &ref, WIDTH, HEIGHT, STRIDE, I915_TILING_NONE, false);
scratch_buf_draw_pattern(data, &src,
0, 0, WIDTH, HEIGHT,
@@ -358,6 +452,84 @@ static void test_basic(data_t *data, uint32_t tiling)
}
}
+static void test_ccs(data_t *data, uint32_t tiling)
+{
+ struct intel_batchbuffer *batch = data->batch;
+ struct igt_buf src, dst, ccs, ref;
+ int opt_dump_aub = igt_aub_dump_enabled();
+
+ scratch_buf_init(data, &src, WIDTH, HEIGHT, STRIDE, I915_TILING_NONE, false);
+ scratch_buf_init(data, &dst, WIDTH, HEIGHT, STRIDE, I915_TILING_NONE, false);
+ scratch_buf_init(data, &ccs, WIDTH, HEIGHT, STRIDE, tiling, true);
+ scratch_buf_init(data, &ref, WIDTH, HEIGHT, STRIDE, I915_TILING_NONE, false);
+
+ scratch_buf_draw_pattern(data, &src,
+ 0, 0, WIDTH, HEIGHT,
+ 0, 0, WIDTH, HEIGHT, true);
+ scratch_buf_draw_pattern(data, &dst,
+ 0, 0, WIDTH, HEIGHT,
+ 0, 0, WIDTH, HEIGHT, false);
+
+ scratch_buf_copy(data,
+ &dst, 0, 0, WIDTH, HEIGHT,
+ &ref, 0, 0);
+ scratch_buf_copy(data,
+ &src, WIDTH/4, WIDTH/4, WIDTH/2, HEIGHT/2,
+ &ref, WIDTH/2-1, WIDTH/2-1);
+
+ if (opt_dump_png) {
+ scratch_buf_write_to_png(data, &src, "source.png");
+ scratch_buf_write_to_png(data, &dst, "destination.png");
+ scratch_buf_write_to_png(data, &ref, "reference.png");
+ }
+
+ if (opt_dump_aub) {
+ drm_intel_bufmgr_gem_set_aub_filename(data->bufmgr,
+ "rendercopy.aub");
+ drm_intel_bufmgr_gem_set_aub_dump(data->bufmgr, true);
+ }
+
+ /* This will copy the src to the mid point of the dst buffer. Presumably
+ * the out of bounds accesses will get clipped.
+ * Resulting buffer should look like:
+ * _______
+ * |dst|dst|
+ * |dst|src|
+ * -------
+ */
+ data->render_copy(batch, NULL,
+ &dst, 0, 0, WIDTH, HEIGHT,
+ &ccs, 0, 0);
+ data->render_copy(batch, NULL,
+ &src, WIDTH/4, HEIGHT/4, WIDTH/2, HEIGHT/2,
+ &ccs, WIDTH/2-1, HEIGHT/2-1);
+
+ data->render_copy(batch, NULL,
+ &ccs, 0, 0, WIDTH, HEIGHT,
+ &dst, 0, 0);
+
+ if (opt_dump_png) {
+ scratch_buf_write_to_png(data, &dst, "result.png");
+ scratch_buf_write_to_png(data, &ccs, "compressed.png");
+ scratch_buf_aux_write_to_png(data, &ccs, "compressed-aux.png");
+ }
+
+ if (opt_dump_aub) {
+ drm_intel_gem_bo_aub_dump_bmp(dst.bo,
+ 0, 0, WIDTH, HEIGHT,
+ AUB_DUMP_BMP_FORMAT_ARGB_8888,
+ STRIDE, 0);
+ drm_intel_bufmgr_gem_set_aub_dump(data->bufmgr, false);
+ } else if (check_all_pixels) {
+ scratch_buf_check_all(data, &dst, &ref);
+ } else {
+ scratch_buf_check(data, &dst, &ref, 10, 10);
+ scratch_buf_check(data, &dst, &ref, WIDTH - 10, HEIGHT - 10);
+ }
+
+ scratch_buf_aux_check(data, &ccs);
+}
+
static int opt_handler(int opt, int opt_index, void *data)
{
if (opt == 'd') {
@@ -402,6 +574,9 @@ int main(int argc, char **argv)
igt_subtest("y-tiled")
test_basic(&data, I915_TILING_Y);
+ igt_subtest("y-tiled-ccs")
+ test_ccs(&data, I915_TILING_Y);
+
igt_fixture {
intel_batchbuffer_free(data.batch);
drm_intel_bufmgr_destroy(data.bufmgr);
--
2.16.4
More information about the igt-dev
mailing list