Not sure I want to include this in the make test suite, but it's useful
to both test the feature, and show how it can be used.

Signed-off-by: Ben Widawsky <[email protected]>
---
 tests/gem_wait_render_timeout.c |  175 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 176 insertions(+)
 create mode 100644 tests/gem_wait_render_timeout.c

diff --git a/tests/gem_wait_render_timeout.c b/tests/gem_wait_render_timeout.c
new file mode 100644
index 0000000..0cc33d7
--- /dev/null
+++ b/tests/gem_wait_render_timeout.c
@@ -0,0 +1,175 @@
+/*
+ * Copyright © 2012 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.
+ *
+ * Authors:
+ *    Ben Widawsky <[email protected]>
+ *      based on gem_ringfill.c by Eric Anholt <[email protected]>
+ *
+ */
+
+#include <stdio.h>
+#include "drm.h"
+#include "rendercopy.h"
+
+#define MSEC_PER_SEC   1000L
+#define USEC_PER_MSEC  1000L
+#define NSEC_PER_USEC  1000L
+#define NSEC_PER_MSEC  1000000L
+#define USEC_PER_SEC   1000000L
+#define NSEC_PER_SEC   1000000000L
+#define FSEC_PER_SEC   1000000000000000LL
+
+struct bo {
+       const char *ring;
+       drm_intel_bo *src, *dst, *tmp;
+} last_bo;
+
+static const int width = 512, height = 512;
+
+static void create_bo(drm_intel_bufmgr *bufmgr,
+                     struct bo *b,
+                     const char *ring)
+{
+       int size = 4 * width * height;
+
+       b->ring = ring;
+       b->src = drm_intel_bo_alloc(bufmgr, "src", size, 4096);
+       b->dst = drm_intel_bo_alloc(bufmgr, "dst", size, 4096);
+       b->tmp = drm_intel_bo_alloc(bufmgr, "tmp", size, 4096);
+}
+
+static void destroy_bo(struct bo *b)
+{
+       drm_intel_bo_unreference(b->src);
+       drm_intel_bo_unreference(b->tmp);
+       drm_intel_bo_unreference(b->dst);
+}
+
+static void make_work(drm_intel_bufmgr *bufmgr,
+                     struct intel_batchbuffer *batch,
+                     const char *ring,
+                     render_copyfunc_t copy)
+{
+       struct scratch_buf src, tmp, dst;
+       struct bo bo;
+       int i;
+
+       create_bo(bufmgr, &bo, ring);
+
+       src.stride = 4 * width;
+       src.tiling = 0;
+       src.data = src.cpu_mapping = NULL;
+       src.size = 4 * width * height;
+       src.num_tiles = 4 * width * height;
+       dst = tmp = src;
+
+       src.bo = bo.src;
+       tmp.bo = bo.tmp;
+       dst.bo = bo.dst;
+
+       for (i = 0; i < (width * height) >> 3; i++) {
+               int x = i % width;
+               int y = i / width;
+
+               assert(y < height);
+
+               copy(batch, &src, 0, 0, width, height, &tmp, 0, 0);
+               copy(batch, &src, x, y, 1, 1, &dst, x, y);
+       }
+
+       last_bo = bo;
+}
+
+static void blt_copy(struct intel_batchbuffer *batch,
+                    struct scratch_buf *src, unsigned src_x, unsigned src_y,
+                    unsigned w, unsigned h,
+                    struct scratch_buf *dst, unsigned dst_x, unsigned dst_y)
+{
+       BEGIN_BATCH(8);
+       OUT_BATCH(XY_SRC_COPY_BLT_CMD |
+                 XY_SRC_COPY_BLT_WRITE_ALPHA |
+                 XY_SRC_COPY_BLT_WRITE_RGB);
+       OUT_BATCH((3 << 24) | /* 32 bits */
+                 (0xcc << 16) | /* copy ROP */
+                 dst->stride);
+       OUT_BATCH((dst_y << 16) | dst_x); /* dst x1,y1 */
+       OUT_BATCH(((dst_y + h) << 16) | (dst_x + w)); /* dst x2,y2 */
+       OUT_RELOC(dst->bo, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, 0);
+       OUT_BATCH((src_y << 16) | src_x); /* src x1,y1 */
+       OUT_BATCH(src->stride);
+       OUT_RELOC(src->bo, I915_GEM_DOMAIN_RENDER, 0, 0);
+       ADVANCE_BATCH();
+
+       intel_batchbuffer_flush(batch);
+}
+
+int main(int argc, char **argv)
+{
+       drm_intel_bufmgr *bufmgr;
+       struct intel_batchbuffer *batch;
+       uint64_t orig_timeout, timeout;
+       int fd, ret;
+       bool do_signals = false;
+
+       if (argc > 2) {
+               do_signals = true;
+               orig_timeout = timeout = atoi(argv[1]) * NSEC_PER_MSEC;
+       } else if (argc > 1)
+               orig_timeout = timeout = atoi(argv[1]) * NSEC_PER_MSEC;
+       else
+               orig_timeout = timeout = 150 * NSEC_PER_MSEC;
+
+       fd = drm_open_any();
+
+       bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
+       drm_intel_bufmgr_gem_enable_reuse(bufmgr);
+       batch = intel_batchbuffer_alloc(bufmgr, intel_get_drm_devid(fd));
+
+       if (do_signals)
+               drmtest_fork_signal_helper();
+
+       make_work(bufmgr, batch, "blt", blt_copy);
+       ret = drm_intel_gem_bo_wait(last_bo.dst, &timeout);
+       if (ret) {
+               fprintf(stderr, "Timed wait failed %s\n", strerror(errno));
+               exit(EXIT_FAILURE);
+       }
+
+       if (timeout == 0)
+               printf("Timeout before render completed!\n");
+       else {
+               printf("Finished with %lums time remaining\n",
+                       timeout / NSEC_PER_MSEC);
+               assert(timeout <= orig_timeout);
+       }
+
+       destroy_bo(&last_bo);
+       intel_batchbuffer_free(batch);
+       drm_intel_bufmgr_destroy(bufmgr);
+
+       close(fd);
+
+       if (do_signals)
+               drmtest_stop_signal_helper();
+
+       return 0;
+}
-- 
1.7.10

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

Reply via email to