From: Damien Lespiau Subject: [PATCH 2/5] tests/gem_render_copy: Add a simple render copy test Date: Wed, 23 Oct 2013 16:05:13 +0100 Message-ID: <1382540716-32711-3-git-send-email-damien.lespiau@intel.com> References: <1382540716-32711-1-git-send-email-damien.lespiau@intel.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1460517721==" Return-path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by gabe.freedesktop.org (Postfix) with ESMTP id 7708EE6EBC for ; Wed, 23 Oct 2013 08:05:23 -0700 (PDT) In-Reply-To: <1382540716-32711-1-git-send-email-damien.lespiau@intel.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: intel-gfx-bounces+gcfxdi-intel-gfx=m.gmane.org@lists.freedesktop.org Errors-To: intel-gfx-bounces+gcfxdi-intel-gfx=m.gmane.org@lists.freedesktop.org To: intel-gfx@lists.freedesktop.org List-Id: intel-gfx@lists.freedesktop.org --===============1460517721== Content-Type: text/plain; charset=y Content-Transfer-Encoding: quoted-printable The goal is here to both: demonstrate a simple usage of render copy with the possibility to write pngs to visualize what it's doing and to provide a test bed to port the render copy function to new architectures. Signed-off-by: Damien Lespiau --- tests/.gitignore | 1 + tests/Makefile.am | 1 + tests/gem_render_copy.c | 127 ++++++++++++++++++++++++++++++++++++++++++= ++++++ 3 files changed, 129 insertions(+) create mode 100644 tests/gem_render_copy.c diff --git a/tests/.gitignore b/tests/.gitignore index 1c97a04..eded4a7 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -58,6 +58,7 @@ gem_readwrite gem_reg_read gem_reloc_overflow gem_reloc_vs_gpu +gem_render_copy gem_render_linear_blits gem_render_tiled_blits gem_ringfill diff --git a/tests/Makefile.am b/tests/Makefile.am index 843c7d2..7be2bc2 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -87,6 +87,7 @@ TESTS_progs =3D \ gem_pin \ gem_pipe_control_store_loop \ gem_reg_read \ + gem_render_copy \ gem_render_linear_blits \ gem_render_tiled_blits \ gem_ring_sync_loop \ diff --git a/tests/gem_render_copy.c b/tests/gem_render_copy.c new file mode 100644 index 0000000..a693cee --- /dev/null +++ b/tests/gem_render_copy.c @@ -0,0 +1,127 @@ +/* + * Copyright =C2=A9 2013 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining= a + * copy of this software and associated documentation files (the "Softwa= re"), + * to deal in the Software without restriction, including without limita= tion + * the rights to use, copy, modify, merge, publish, distribute, sublicen= se, + * 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, EXPRE= SS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILI= TY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SH= ALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR = OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISI= NG + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER D= EALINGS + * IN THE SOFTWARE. + * + * Authors: + * Damien Lespiau + */ + +/* + * This file is a basic test for the render_copy() function, a very simp= le + * workload for the 3D engine. + */ + +#include + +#include "rendercopy.h" + +#define WIDTH 512 +#define STRIDE (WIDTH*4) +#define HEIGHT 512 +#define SIZE (HEIGHT*STRIDE) + +#define SRC_COLOR 0xffff00ff +#define DST_COLOR 0xfff0ff00 + +typedef struct { + int drm_fd; + uint32_t devid; + drm_intel_bufmgr *bufmgr; + uint32_t linear[WIDTH * HEIGHT]; +} data_t; + +static void scratch_buf_init(data_t *data, struct scratch_buf *buf, + int width, int height, int stride, uint32_t color) +{ + drm_intel_bo *bo; + int i; + + bo =3D drm_intel_bo_alloc(data->bufmgr, "", SIZE, 4096); + for (i =3D 0; i < width * height; i++) + data->linear[i] =3D color; + gem_write(data->drm_fd, bo->handle, 0, data->linear, + sizeof(data->linear)); + + buf->bo =3D bo; + buf->stride =3D stride; + buf->tiling =3D I915_TILING_NONE; + buf->size =3D SIZE; +} + +static void +scratch_buf_check(data_t *data, struct scratch_buf *buf, int x, int y, + uint32_t color) +{ + uint32_t val; + + gem_read(data->drm_fd, buf->bo->handle, 0, + data->linear, sizeof(data->linear)); + val =3D data->linear[y * WIDTH + x]; + if (val !=3D color) { + fprintf(stderr, "Expected 0x%08x, found 0x%08x at (%d,%d)\n", + color, val, x, y); + abort(); + } +} + +int main(int argc, char **argv) +{ + data_t data =3D {0, }; + struct intel_batchbuffer *batch =3D NULL; + struct scratch_buf src, dst; + render_copyfunc_t render_copy =3D NULL; + int opt_dump_png =3D false; + + igt_fixture { + data.drm_fd =3D drm_open_any(); + data.devid =3D intel_get_drm_devid(data.drm_fd); + + data.bufmgr =3D drm_intel_bufmgr_gem_init(data.drm_fd, 4096); + igt_assert(data.bufmgr); + + render_copy =3D get_render_copyfunc(data.devid); + igt_require_f(render_copy, + "no render-copy function\n"); + + batch =3D intel_batchbuffer_alloc(data.bufmgr, data.devid); + igt_assert(batch); + } + + scratch_buf_init(&data, &src, WIDTH, HEIGHT, STRIDE, SRC_COLOR); + scratch_buf_init(&data, &dst, WIDTH, HEIGHT, STRIDE, DST_COLOR); + + scratch_buf_check(&data, &src, WIDTH / 2, HEIGHT / 2, SRC_COLOR); + scratch_buf_check(&data, &dst, WIDTH / 2, HEIGHT / 2, DST_COLOR); + + scratch_buf_write_to_png(&src, "source.png"); + scratch_buf_write_to_png(&dst, "destination.png"); + + render_copy(batch, + &src, 0, 0, WIDTH, HEIGHT, + &dst, WIDTH / 2, HEIGHT / 2); + + scratch_buf_check(&data, &dst, 10, 10, DST_COLOR); + scratch_buf_check(&data, &dst, WIDTH - 10, HEIGHT - 10, SRC_COLOR); + + scratch_buf_write_to_png(&dst, "result.png"); + + return 0; +} --=20 1.8.3.1 --===============1460517721== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Intel-gfx mailing list Intel-gfx@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/intel-gfx --===============1460517721==--