From patchwork Tue Dec 6 15:06:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tomeu Vizoso X-Patchwork-Id: 9462739 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C00FA60231 for ; Tue, 6 Dec 2016 15:07:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B249928424 for ; Tue, 6 Dec 2016 15:07:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A50EA28426; Tue, 6 Dec 2016 15:07:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1223A28424 for ; Tue, 6 Dec 2016 15:07:07 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6403B6E0E5; Tue, 6 Dec 2016 15:07:06 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wm0-x241.google.com (mail-wm0-x241.google.com [IPv6:2a00:1450:400c:c09::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id A15716E0E5 for ; Tue, 6 Dec 2016 15:07:04 +0000 (UTC) Received: by mail-wm0-x241.google.com with SMTP id m203so22017646wma.3 for ; Tue, 06 Dec 2016 07:07:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=eCuv9EypHXXta7W3ToNW/VSuIaGEVJ5qhXsUlhSV2Yw=; b=bxNnEsILgkbiH1/e7CYIXKPKJGPwzGxgMmmnFQCRqJiDFPyUZuIhEuhmgBBi3vt1M1 S+VyQqh69JZSFn7GOdsXjNiUBEycGAKL6P/PIDI5cXDy35Uk3gJHMYlD0snR11OI78mg 2nWXFBM9vPeLH7YHKA2e4oHfRERickk8fGWlt01WRk5KSruCjbVYafGbt+eKwMD5bl9J ygFv/4D5h7kPsel/sgR7RvKDjD6t/vaO87Br/ODXk4Q73MNQCIJ31qE1XAc/UWXsYvqS l3xVNcBbf0S7RoASMlKO+AQNOVEZrbkCSLzztAMQXok971PvKv4iwGyEQf/cTaRLYJ5G 5qVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=eCuv9EypHXXta7W3ToNW/VSuIaGEVJ5qhXsUlhSV2Yw=; b=ZRTknDlJTyssIcWTJp7l3hKAxACZ2Hjf28ygngLde7WsVNgNcKFAUXvDXZEEQ+ZDY+ jJV+FCjhCoJ5SzOvwN0wdc03re6+p1PJ2S/nv1PEKKesbyi1DcGT82hZuTgKHmqlik+m 74qnyXj/pLZmb0PAo6i+GA7dQJa0BWPUtfRGoF2UtJp7HQRk1pKT66o++Ywp0pLlKq51 rUf4P2g76xm8Ra2BmsKvsVXKu5phtPCJdInuKRhSAm317lzzK9MzTpBeAghVn8CRSkuV jTGeu8R4JVFeB1y7RpWrRA8eKIXdrVRrJUMbQXyvcKNTgGz8lFI3NYerQEoxDzAHgoH6 LAFQ== X-Gm-Message-State: AKaTC00lq+O+CCN2hjSJ8+ulWSaX14puDHxzrvwgeHkHe7AZW8qko1U0w/WYWRGr35tfvg== X-Received: by 10.28.187.11 with SMTP id l11mr3019458wmf.72.1481036822935; Tue, 06 Dec 2016 07:07:02 -0800 (PST) Received: from cizrna.lan ([109.72.12.105]) by smtp.gmail.com with ESMTPSA id t82sm4439554wmd.17.2016.12.06.07.07.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Dec 2016 07:07:02 -0800 (PST) From: Tomeu Vizoso To: Intel GFX discussion Date: Tue, 6 Dec 2016 16:06:50 +0100 Message-Id: <1481036810-32726-1-git-send-email-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Cc: Ben Widawsky , Tomeu Vizoso Subject: [Intel-gfx] [PATCH i-g-t v1] tests/kms_ccs: Add test for render compression X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP Add a few subtests that check that lossless compressed render targets are properly displayed. Also test a few error conditions. Cc: Ville Syrjälä Cc: Ben Widawsky Signed-off-by: Tomeu Vizoso Acked-by: Ben Widawsky --- Hi, this has been tested with Ville's branch at: https://github.com/vsyrjala/linux/tree/fb_format_dedup_2_ccs The test was based on Ville's one at: https://github.com/vsyrjala/intel-gpu-tools/tree/ccs_test_3 Regards, Tomeu --- lib/ioctl_wrappers.h | 2 + tests/Makefile.sources | 1 + tests/kms_ccs.c | 306 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 309 insertions(+) create mode 100644 tests/kms_ccs.c diff --git a/lib/ioctl_wrappers.h b/lib/ioctl_wrappers.h index 26270975b6c2..71e2a5fe4fd1 100644 --- a/lib/ioctl_wrappers.h +++ b/lib/ioctl_wrappers.h @@ -222,6 +222,8 @@ struct local_drm_mode_fb_cmd2 { #define LOCAL_I915_FORMAT_MOD_X_TILED local_fourcc_mod_code(INTEL, 1) #define LOCAL_I915_FORMAT_MOD_Y_TILED local_fourcc_mod_code(INTEL, 2) #define LOCAL_I915_FORMAT_MOD_Yf_TILED local_fourcc_mod_code(INTEL, 3) +#define LOCAL_I915_FORMAT_MOD_Y_TILED_CCS local_fourcc_mod_code(INTEL, 4) +#define LOCAL_I915_FORMAT_MOD_Yf_TILED_CCS local_fourcc_mod_code(INTEL, 5) #define LOCAL_DRM_IOCTL_MODE_ADDFB2 DRM_IOWR(0xB8, \ struct local_drm_mode_fb_cmd2) diff --git a/tests/Makefile.sources b/tests/Makefile.sources index 65e079220d97..95c570a86675 100644 --- a/tests/Makefile.sources +++ b/tests/Makefile.sources @@ -91,6 +91,7 @@ TESTS_progs_M = \ kms_atomic \ kms_atomic_transition \ kms_busy \ + kms_ccs \ kms_chv_cursor_fail \ kms_cursor_crc \ kms_cursor_legacy \ diff --git a/tests/kms_ccs.c b/tests/kms_ccs.c new file mode 100644 index 000000000000..7e7255c374a4 --- /dev/null +++ b/tests/kms_ccs.c @@ -0,0 +1,306 @@ +/* + * Copyright © 2016 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 "igt.h" + +IGT_TEST_DESCRIPTION("Test render compression (RC), in which the main surface " + "is complemented by a color control surface (CCS) that " + "the display uses to interpret the compressed data."); + +enum test_flags { + TEST_CRC = 1 << 1, + TEST_ROTATE_180 = 1 << 2, + TEST_BAD_PIXEL_FORMAT = 1 << 3, + TEST_BAD_ROTATION_90 = 1 << 4, +}; + +typedef struct { + int drm_fd; + igt_display_t display; + struct igt_fb fb; + igt_output_t *output; + enum pipe pipe; + enum test_flags flags; +} data_t; + +#define COMPRESSED_RED 0x0ff0000f +#define COMPRESSED_GREEN 0x000ff00f +#define COMPRESSED_BLUE 0x00000fff + +#define RED 0x00ff0000 + +static void render_fb(data_t *data, bool compressed) +{ + struct igt_fb *fb = &data->fb; + uint32_t *ptr; + int i; + + igt_assert(fb->fb_id); + + ptr = gem_mmap__cpu(data->drm_fd, fb->gem_handle, + 0, fb->size, + PROT_READ | PROT_WRITE); + + for (i = 0; i < fb->size / 4; i++) { + /* Fill upper half as compressed */ + if (compressed && i < fb->size / 4 / 2) + ptr[i] = COMPRESSED_RED; + else + ptr[i] = RED; + } + + munmap(ptr, fb->size); +} + +static uint8_t *ccs_ptr(uint8_t *ptr, + unsigned int x, unsigned int y, + unsigned int stride) +{ + return ptr + + ((y & ~0x3f) * stride) + + ((x & ~0x7) * 64) + + ((y & 0x3f) * 8) + + (x & 7); +} + +static void render_ccs(data_t *data, uint32_t gem_handle, + uint32_t offset, uint32_t size, + int w, int h, unsigned int stride) +{ + uint8_t *ptr; + int x, y; + + ptr = gem_mmap__cpu(data->drm_fd, gem_handle, + offset, size, + PROT_READ | PROT_WRITE); + + /* Mark upper half as compressed */ + for (x = 0 ; x < w; x++) + for (y = 0 ; y <= h / 2; y++) + *ccs_ptr(ptr, x, y, stride) = 0x55; + + munmap(ptr, size); +} + +static void display_fb(data_t *data, int compressed) +{ + struct local_drm_mode_fb_cmd2 f = {}; + struct igt_fb *fb = &data->fb; + igt_display_t *display = &data->display; + igt_plane_t *primary; + drmModeModeInfo *mode; + unsigned int width, height; + unsigned int size[2]; + uint64_t modifier; + enum igt_commit_style commit = COMMIT_UNIVERSAL; + int ret; + + if (data->display.is_atomic) + commit = COMMIT_ATOMIC; + + mode = igt_output_get_mode(data->output); + + if (compressed) + modifier = LOCAL_I915_FORMAT_MOD_Y_TILED_CCS; + else + modifier = LOCAL_I915_FORMAT_MOD_Y_TILED; + + f.flags = LOCAL_DRM_MODE_FB_MODIFIERS; + f.width = ALIGN(mode->hdisplay, 16); + f.height = ALIGN(mode->vdisplay, 8); + + if (data->flags & TEST_BAD_PIXEL_FORMAT) + f.pixel_format = DRM_FORMAT_RGB565; + else + f.pixel_format = DRM_FORMAT_XRGB8888; + + width = f.width; + height = f.height; + f.pitches[0] = ALIGN(width * 4, 128); + f.modifier[0] = modifier; + f.offsets[0] = 0; + size[0] = f.pitches[0] * ALIGN(height, 32); + + if (compressed) { + width = ALIGN(f.width, 16) / 16; + height = ALIGN(f.height, 8) / 8; + f.pitches[1] = ALIGN(width * 1, 64); + f.modifier[1] = modifier; + f.offsets[1] = size[0]; + size[1] = f.pitches[1] * ALIGN(height, 64); + + f.handles[0] = gem_create(data->drm_fd, size[0] + size[1]); + f.handles[1] = f.handles[0]; + } else + f.handles[0] = gem_create(data->drm_fd, size[0]); + + ret = drmIoctl(data->drm_fd, LOCAL_DRM_IOCTL_MODE_ADDFB2, &f); + if (data->flags & TEST_BAD_PIXEL_FORMAT) { + igt_assert_eq(ret, -1); + igt_assert_eq(errno, EINVAL); + return; + } else + igt_assert_eq(ret, 0); + + fb->fb_id = f.fb_id; + fb->fd = data->drm_fd; + fb->gem_handle = f.handles[0]; + fb->is_dumb = false; + fb->drm_format = f.pixel_format; + fb->width = f.width; + fb->height = f.height; + fb->stride = f.pitches[0]; + fb->tiling = f.modifier[0]; + fb->size = size[0]; + fb->cairo_surface = NULL; + fb->domain = 0; + + render_fb(data, compressed); + + if (compressed) + render_ccs(data, f.handles[0], f.offsets[1], size[1], + f.width/16, f.height/8, f.pitches[1]); + + primary = igt_output_get_plane(data->output, IGT_PLANE_PRIMARY); + igt_plane_set_fb(primary, fb); + + if (data->flags & TEST_ROTATE_180) + igt_plane_set_rotation(primary, IGT_ROTATION_180); + if (data->flags & TEST_BAD_ROTATION_90) + igt_plane_set_rotation(primary, IGT_ROTATION_90); + + ret = igt_display_try_commit2(display, commit); + if (data->flags & TEST_BAD_ROTATION_90) + igt_assert_eq(ret, -EINVAL); + else + igt_assert_eq(ret, 0); + + igt_debug_wait_for_keypress("ccs"); +} + +#define TEST_UNCOMPRESSED 0 +#define TEST_COMPRESSED 1 + +static bool test_output(data_t *data) +{ + igt_display_t *display = &data->display; + igt_plane_t *primary; + igt_crc_t crc, ref_crc; + igt_pipe_crc_t *pipe_crc; + + igt_output_set_pipe(data->output, data->pipe); + + if (data->flags & TEST_CRC) { + pipe_crc = igt_pipe_crc_new(data->pipe, INTEL_PIPE_CRC_SOURCE_AUTO); + + display_fb(data, TEST_COMPRESSED); + igt_pipe_crc_collect_crc(pipe_crc, &ref_crc); + + display_fb(data, TEST_UNCOMPRESSED); + igt_pipe_crc_collect_crc(pipe_crc, &crc); + + igt_assert_crc_equal(&crc, &ref_crc); + + igt_pipe_crc_free(pipe_crc); + pipe_crc = NULL; + } + + if (data->flags & TEST_BAD_PIXEL_FORMAT || + data->flags & TEST_BAD_ROTATION_90) { + display_fb(data, TEST_COMPRESSED); + } + + primary = igt_output_get_plane(data->output, IGT_PLANE_PRIMARY); + igt_plane_set_fb(primary, NULL); + igt_plane_set_rotation(primary, IGT_ROTATION_0); + igt_output_set_pipe(data->output, PIPE_ANY); + igt_display_commit2(display, COMMIT_UNIVERSAL); + + if (data->flags & TEST_CRC) + igt_remove_fb(data->drm_fd, &data->fb); + + return true; +} + +static void test(data_t *data) +{ + igt_display_t *display = &data->display; + int valid_tests = 0; + + for_each_connected_output(display, data->output) { + if (!test_output(data)) + continue; + + valid_tests++; + + igt_info("\n%s on pipe %s, connector %s: PASSED\n\n", + igt_subtest_name(), + kmstest_pipe_name(data->pipe), + igt_output_name(data->output)); + } + + igt_require_f(valid_tests, "no valid crtc/connector combinations found\n"); +} + +static data_t data; + +igt_main +{ + igt_fixture { + data.drm_fd = drm_open_driver_master(DRIVER_INTEL); + + igt_require(intel_gen(intel_get_drm_devid(data.drm_fd)) >= 9); + kmstest_set_vt_graphics_mode(); + igt_require_pipe_crc(); + + igt_display_init(&data.display, data.drm_fd); + } + + igt_subtest_f("bad-pixel-format") { + data.flags = TEST_BAD_PIXEL_FORMAT; + data.pipe = PIPE_A; + test(&data); + } + + igt_subtest_f("bad-rotation-90") { + data.flags = TEST_BAD_ROTATION_90; + data.pipe = PIPE_A; + test(&data); + } + + for_each_pipe(&data.display, data.pipe) { + data.flags = TEST_CRC; + igt_subtest_f("pipe-%s-crc-basic", kmstest_pipe_name(data.pipe)) + test(&data); + } + + for_each_pipe(&data.display, data.pipe) { + data.flags = TEST_CRC | TEST_ROTATE_180; + igt_subtest_f("pipe-%s-crc-rotation-180", kmstest_pipe_name(data.pipe)) + test(&data); + } + + igt_fixture + igt_display_fini(&data.display); +}