[Intel-gfx] [PATCH 1/2] tests: Add a helper to generate raw batches
Damien Lespiau
damien.lespiau at intel.com
Fri Dec 13 19:15:46 CET 2013
These batches can be used to test the CS parser in libdrm. Let's start
by generating a MI_FLUSH_DW command that flushes a DWord (as opposed to
a QWord).
Signed-off-by: Damien Lespiau <damien.lespiau at intel.com>
---
tests/.gitignore | 1 +
tests/Makefile.sources | 1 +
tests/generate_test_batches.c | 109 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 111 insertions(+)
create mode 100644 tests/generate_test_batches.c
diff --git a/tests/.gitignore b/tests/.gitignore
index 8a00364..f6e2cf8 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -97,6 +97,7 @@ gen3_render_linear_blits
gen3_render_mixed_blits
gen3_render_tiledx_blits
gen3_render_tiledy_blits
+generate_test_batches
igt_fork_helper
igt_list_only
igt_no_exit
diff --git a/tests/Makefile.sources b/tests/Makefile.sources
index e286a7c..493fa4e 100644
--- a/tests/Makefile.sources
+++ b/tests/Makefile.sources
@@ -1,6 +1,7 @@
noinst_PROGRAMS = \
gem_stress \
ddi_compute_wrpll \
+ generate_test_batches \
$(TESTS_progs) \
$(TESTS_progs_M) \
$(HANG) \
diff --git a/tests/generate_test_batches.c b/tests/generate_test_batches.c
new file mode 100644
index 0000000..997ce37
--- /dev/null
+++ b/tests/generate_test_batches.c
@@ -0,0 +1,109 @@
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <assert.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "drmtest.h"
+#include "intel_batchbuffer.h"
+#include "gen8_render.h"
+#include "intel_reg.h"
+#include "i830_reg.h"
+
+#define ALIGN(x, y) (((x) + (y)-1) & ~((y)-1))
+
+static uint32_t
+batch_used(struct intel_batchbuffer *batch)
+{
+ return batch->ptr - batch->buffer;
+}
+
+static void dump_batch(struct intel_batchbuffer *batch,
+ const char *filename)
+{
+ int fd;
+
+ fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
+ if (fd == -1) {
+ fprintf(stderr, "Couldn't open %s: %s", filename,
+ strerror(errno));
+ return;
+ }
+
+ write(fd, batch->buffer, batch_used(batch));
+ close(fd);
+}
+
+static uint32_t
+batch_align(struct intel_batchbuffer *batch, uint32_t align)
+{
+ uint32_t offset;
+
+ offset = batch_used(batch);
+ offset = ALIGN(offset, align);
+ batch->ptr = batch->buffer + offset;
+ return offset;
+}
+
+static void batch_start(struct intel_batchbuffer *batch)
+{
+ batch_align(batch, 8);
+}
+
+static void batch_finish(struct intel_batchbuffer *batch, const char *filename)
+{
+ uint32_t batch_end;
+
+ batch_end = batch_align(batch, 8);
+ assert(batch_end < 4095);
+
+ dump_batch(batch, filename);
+
+ intel_batchbuffer_reset(batch);
+}
+
+static void emit_mi_flush_dw(struct intel_batchbuffer *batch)
+{
+ batch_start(batch);
+
+ OUT_BATCH(MI_FLUSH_DW | (4-2));
+ OUT_BATCH(0xdead0000 | 1 << 2);
+ OUT_BATCH(0);
+ OUT_BATCH(0);
+
+ /*
+ * Add a random command after MI_FLUSH_DW to make sure we continue
+ * decoding correctly
+ */
+
+ OUT_BATCH(MI_STORE_DWORD_IMM);
+ OUT_RELOC(batch->bo, I915_GEM_DOMAIN_INSTRUCTION,
+ I915_GEM_DOMAIN_INSTRUCTION, 0xbeef00);
+ OUT_BATCH(0);
+ OUT_BATCH(0xf00);
+
+ batch_finish(batch, "gen8-2d-mi-flush-dw-len-4.batch");
+}
+
+static struct gen_batches {
+ int drm_fd;
+ uint32_t devid;
+ drm_intel_bufmgr *bufmgr;
+} data;
+
+int main(int argc, char **argv)
+{
+ struct intel_batchbuffer *batch = NULL;
+
+ data.drm_fd = drm_open_any_render();
+ data.devid = intel_get_drm_devid(data.drm_fd);
+ data.bufmgr = drm_intel_bufmgr_gem_init(data.drm_fd, 4096);
+ igt_assert(data.bufmgr);
+
+ batch = intel_batchbuffer_alloc(data.bufmgr, data.devid);
+ igt_assert(batch);
+
+ emit_mi_flush_dw(batch);
+}
--
1.8.3.1
More information about the Intel-gfx
mailing list