xf86-video-intel: 2 commits - src/sna/kgem.c test/.gitignore test/lowlevel-blt-bench.c test/Makefile.am test/test_display.c test/test.h
Chris Wilson
ickle at kemper.freedesktop.org
Tue Feb 5 14:08:31 PST 2013
src/sna/kgem.c | 17 ++---
test/.gitignore | 1
test/Makefile.am | 2
test/lowlevel-blt-bench.c | 135 ++++++++++++++++++++++++++++++++++++++++++++++
test/test.h | 5 +
test/test_display.c | 17 +++++
6 files changed, 166 insertions(+), 11 deletions(-)
New commits:
commit a8cfddd280b5220f23565b21c91f3f7dd10bbe91
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Tue Feb 5 22:06:03 2013 +0000
sna: Tidy buffer allocation size assertions
Rather than perilously update a local variable with the allocated size,
just use the size of the bo in the assertion that is large enough to
satisfy the allocation request.
Reported-by: Jiri Slaby <jirislaby at gmail.com>
Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
diff --git a/src/sna/kgem.c b/src/sna/kgem.c
index 36b245d..1086c3f 100644
--- a/src/sna/kgem.c
+++ b/src/sna/kgem.c
@@ -5117,8 +5117,6 @@ struct kgem_bo *kgem_create_buffer(struct kgem *kgem,
if (bo->mem) {
if (flags & KGEM_BUFFER_WRITE)
kgem_bo_sync__cpu(kgem, &bo->base);
-
- alloc = num_pages(&bo->base);
goto init;
} else {
bo->base.refcnt = 0; /* for valgrind */
@@ -5190,7 +5188,6 @@ struct kgem_bo *kgem_create_buffer(struct kgem *kgem,
bo->mem = kgem_bo_map(kgem, &bo->base);
if (bo->mem) {
- alloc = num_pages(&bo->base);
if (IS_CPU_MAP(bo->base.map))
flags &= ~KGEM_BUFFER_INPLACE;
goto init;
@@ -5213,7 +5210,6 @@ struct kgem_bo *kgem_create_buffer(struct kgem *kgem,
if (flags & KGEM_BUFFER_WRITE)
kgem_bo_sync__cpu(kgem, &bo->base);
flags &= ~KGEM_BUFFER_INPLACE;
- alloc = num_pages(&bo->base);
goto init;
}
@@ -5236,8 +5232,7 @@ struct kgem_bo *kgem_create_buffer(struct kgem *kgem,
if (old) {
DBG(("%s: reusing ordinary handle %d for io\n",
__FUNCTION__, old->handle));
- alloc = num_pages(old);
- bo = buffer_alloc_with_data(alloc);
+ bo = buffer_alloc_with_data(num_pages(old));
if (bo == NULL)
return NULL;
@@ -5264,7 +5259,6 @@ struct kgem_bo *kgem_create_buffer(struct kgem *kgem,
DBG(("%s: reusing handle=%d for buffer\n",
__FUNCTION__, old->handle));
- alloc = num_pages(old);
init_buffer_from_bo(bo, old);
} else {
uint32_t handle = gem_create(kgem->fd, alloc);
@@ -5293,7 +5287,7 @@ struct kgem_bo *kgem_create_buffer(struct kgem *kgem,
DBG(("%s: failing back to new pwrite buffer\n", __FUNCTION__));
old = &bo->base;
- bo = buffer_alloc_with_data(alloc);
+ bo = buffer_alloc_with_data(num_pages(old));
if (bo == NULL) {
free(old);
return NULL;
@@ -5310,7 +5304,8 @@ struct kgem_bo *kgem_create_buffer(struct kgem *kgem,
init:
bo->base.io = true;
assert(bo->base.refcnt == 1);
- assert(num_pages(&bo->base) == alloc);
+ assert(num_pages(&bo->base) >= alloc);
+ assert(num_pages(&bo->base) >= NUM_PAGES(size));
assert(!bo->need_io || !bo->base.needs_flush);
assert(!bo->need_io || bo->base.domain != DOMAIN_GPU);
assert(bo->mem);
@@ -5323,8 +5318,8 @@ init:
assert(list_is_empty(&bo->base.list));
list_add(&bo->base.list, &kgem->batch_buffers);
- DBG(("%s(pages=%d) new handle=%d, used=%d, write=%d\n",
- __FUNCTION__, alloc, bo->base.handle, bo->used, bo->write));
+ DBG(("%s(pages=%d [%d]) new handle=%d, used=%d, write=%d\n",
+ __FUNCTION__, num_pages(&bo->base), alloc, bo->base.handle, bo->used, bo->write));
done:
bo->used = ALIGN(bo->used, UPLOAD_ALIGNMENT);
commit 82dc91e8c24a1fbbf03dcf89a3955319b3399ea0
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Tue Feb 5 21:50:43 2013 +0000
test: Add a very basic blt benchmark
Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
diff --git a/test/.gitignore b/test/.gitignore
index e24e3fd..d3e59c5 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -13,3 +13,4 @@ render-copyarea
render-copyarea-size
render-copy-alphaless
mixed-stress
+lowlevel-blt-bench
diff --git a/test/Makefile.am b/test/Makefile.am
index c1dd0e9..0f9bd7d 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -21,6 +21,8 @@ stress_TESTS = \
check_PROGRAMS = $(stress_TESTS)
+noinst_PROGRAMS = lowlevel-blt-bench
+
AM_CFLAGS = @CWARNFLAGS@ @X11_CFLAGS@ @DRM_CFLAGS@
LDADD = libtest.la @X11_LIBS@ -lXfixes @DRM_LIBS@ -lrt
diff --git a/test/lowlevel-blt-bench.c b/test/lowlevel-blt-bench.c
new file mode 100644
index 0000000..0cea0a8
--- /dev/null
+++ b/test/lowlevel-blt-bench.c
@@ -0,0 +1,135 @@
+/*
+ * Copyright © 2009 Nokia Corporation
+ * Copyright © 2010 Movial Creative Technologies Oy
+ * Copyright © 2013 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.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdint.h>
+#include <stdbool.h>
+
+#include <X11/X.h>
+#include <X11/Xutil.h> /* for XDestroyImage */
+#include <pixman.h> /* for pixman blt functions */
+
+#include "test.h"
+
+static const struct format {
+ const char *name;
+ pixman_format_code_t pixman_format;
+} formats[] = {
+ { "a8r8g8b8", PIXMAN_a8r8g8b8 },
+ { "x8r8g8b8", PIXMAN_x8r8g8b8 },
+ { "a8", PIXMAN_a8 },
+ { "a4", PIXMAN_a4 },
+ { "a1", PIXMAN_a1 },
+};
+
+static const struct op {
+ const char *name;
+} ops[] = {
+ [PictOpClear] = { "Clear" },
+ [PictOpSrc] = { "Src" },
+ [PictOpDst] = { "Dst" },
+ [PictOpOver] = { "Over" },
+ [PictOpOverReverse] = { "OverReverse" },
+ [PictOpIn] = { "In" },
+ [PictOpInReverse] = { "InReverse" },
+ [PictOpOut] = { "Out" },
+ [PictOpOutReverse] = { "OutReverse" },
+ [PictOpAtop] = { "Atop" },
+ [PictOpAtopReverse] = { "AtopReverse" },
+ [PictOpXor] = { "Xor" },
+ [PictOpAdd] = { "Add" },
+ [PictOpSaturate] = { "Saturate" },
+};
+
+static double _bench(struct test_display *t, enum target target_type,
+ int op, int src_format,
+ int loops)
+{
+ XRenderColor render_color = { 0x8000, 0x8000, 0x8000, 0x8000 };
+ struct test_target target;
+ Pixmap pixmap;
+ Picture picture;
+ struct timespec tv;
+ double elapsed;
+
+ test_target_create_render(t, target_type, &target);
+ XRenderFillRectangle(t->dpy, PictOpClear, target.picture, &render_color,
+ 0, 0, target.width, target.height);
+
+ pixmap = XCreatePixmap(t->dpy, t->root,
+ target.width, target.height,
+ PIXMAN_FORMAT_DEPTH(formats[src_format].pixman_format));
+
+ picture = XRenderCreatePicture(t->dpy, pixmap,
+ XRenderFindStandardFormat(t->dpy, src_format),
+ 0, NULL);
+ XRenderFillRectangle(t->dpy, PictOpSrc, picture, &render_color,
+ 0, 0, target.width, target.height);
+
+ test_timer_start(t, &tv);
+ while (loops--)
+ XRenderComposite(t->dpy, op,
+ picture, 0, target.picture,
+ 0, 0,
+ 0, 0,
+ 0, 0,
+ target.width, target.height);
+ elapsed = test_timer_stop(t, &tv);
+
+ XRenderFreePicture(t->dpy, picture);
+ XFreePixmap(t->dpy, pixmap);
+ test_target_destroy_render(t, &target);
+
+ return elapsed;
+}
+
+static void bench(struct test *t, enum target target, int op, int sf)
+{
+ double real, ref;
+
+ ref = _bench(&t->ref, target, op, sf, 1000);
+ real = _bench(&t->real, target, op, sf, 1000);
+
+ fprintf (stdout, "Testing %s with %s: ref=%f, real=%f\n",
+ formats[sf].name, ops[op].name, ref, real);
+}
+
+int main(int argc, char **argv)
+{
+ struct test test;
+ int op, sf;
+
+ test_init(&test, argc, argv);
+
+ for (op = 0; op < sizeof(ops)/sizeof(ops[0]); op++) {
+ for (sf = 0; sf < sizeof(formats)/sizeof(formats[0]); sf++)
+ bench(&test, ROOT, op, sf);
+ fprintf (stdout, "\n");
+ }
+
+ return 0;
+}
diff --git a/test/test.h b/test/test.h
index 1e3995b..7ef4dca 100644
--- a/test/test.h
+++ b/test/test.h
@@ -2,6 +2,8 @@
#define TEST_H
#include <stdint.h>
+#include <time.h>
+
#include <X11/Xlib.h>
#include <X11/extensions/XShm.h>
#include <X11/extensions/Xrender.h>
@@ -107,6 +109,9 @@ static inline uint32_t color(uint8_t red, uint8_t green, uint8_t blue, uint8_t a
return alpha << 24 | ra >> 8 << 16 | ga >> 8 << 8 | ba >> 8;
}
+void test_timer_start(struct test_display *t, struct timespec *tv);
+double test_timer_stop(struct test_display *t, struct timespec *tv);
+
#ifndef MAX
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#endif
diff --git a/test/test_display.c b/test/test_display.c
index ad3e40b..b5e7e06 100644
--- a/test/test_display.c
+++ b/test/test_display.c
@@ -148,3 +148,20 @@ void test_init(struct test *test, int argc, char **argv)
memset(test, 0, sizeof(*test));
test_get_displays(argc, argv, &test->real, &test->ref);
}
+
+void test_timer_start(struct test_display *t, struct timespec *tv)
+{
+ clock_gettime(CLOCK_MONOTONIC, tv);
+}
+
+double test_timer_stop(struct test_display *t, struct timespec *tv)
+{
+ XImage *image;
+ struct timespec now;
+
+ image = XGetImage(t->dpy, t->root, 0, 0, 1, 1, AllPlanes, ZPixmap);
+ clock_gettime(CLOCK_MONOTONIC, &now);
+ XDestroyImage(image);
+
+ return (now.tv_sec - tv->tv_sec) + 1e-9*(now.tv_nsec - tv->tv_nsec);
+}
More information about the xorg-commit
mailing list