From patchwork Thu May 14 22:58:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Dekker X-Patchwork-Id: 19693 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 828E44497DA for ; Fri, 15 May 2020 01:58:32 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 602CC68A6EB; Fri, 15 May 2020 01:58:32 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EFED06807D3 for ; Fri, 15 May 2020 01:58:25 +0300 (EEST) Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 2A8015C0032 for ; Thu, 14 May 2020 18:58:24 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Thu, 14 May 2020 18:58:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=itanimul.li; h= from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm2; bh=4/YtlqmDu3Vsz g/IiVGC7qaRBrBK9FhThDVj2HqqoPk=; b=fvz6NzUrjWTy/eIRd2aS5CDu+mXaU EoU8YWOga1wjuL7ndFRd7e2sDkVpY3r5R/7LU/ktUERbnrA9vmz6g7OWWThauE7P JeI8UM1G9J089Lp5aDc2sdn0nUiyEP5EKVxjQh85FXCAXiYr+Mt25ygf2uw/OYCK 0bviyjKJ9gX85W20s8iDroXBFiahUT5yF5usEjNFXj4DFs6pkh4TeJJacbtj0q3l rO0V21dg2RWltMO2PlrRQ5YsCFa3fAxKJw36KmzxWhri9mrlrr+Qrv+A+hAOTCTP 9TKCj7y3Eq1GSkJdZLYM8UuZWEfUEfW7veiLFzLpGQpsQZ3WTuzDRx6pg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=4/YtlqmDu3Vszg/IiVGC7qaRBrBK9FhThDVj2HqqoPk=; b=ift8PDgd KcJeY23d9sG0FRp3j+xA1il39Oxgll7kPcM9i2+ipF1vp0BwtrmKf3WYStwP+1bK 3o2Vzs+vGevapLg+eL22LIPFogWm/3jeVkgWjm08HCwtkVoJo1+ZYqVKQ5KT3TZW fcdLycgjTyKm9gGrMFvg50VrUl7XmWQTdoykBlizKGZCOIM6vsmVB9wuT6zCwxgf GsJO5oyR82iU5fNnw5wkGh6W8MvzTcmFnDEUBFcs45rtWMz9w9esklZnXQqcNIOh oQZ+tHx2akGOVdC/dCFAMUOsqDYfBVy10Mkj4i7NzqZax8UoakAACEimyGV29cWb n5xAU4IfsuDROQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedrleejgddtlecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhephffvufffkffojghfggfgsedtkeertd ertddtnecuhfhrohhmpeflohhshhcuuggvucfmohgtkhcuoehjohhshhesihhtrghnihhm uhhlrdhliheqnecuggftrfgrthhtvghrnheptdffjeelhfegkeeikeffgefhgeeihfeife dvjeegtddvffehtdfghedtkeefteejnecukfhppeekuddruddtgedrjeekrdduhedunecu vehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepjhhoshhhse hithgrnhhimhhulhdrlhhi X-ME-Proxy: Received: from localhost.localdomain (cpc107625-sotn16-2-0-cust150.15-1.cable.virginm.net [81.104.78.151]) by mail.messagingengine.com (Postfix) with ESMTPA id 39B2F3280059 for ; Thu, 14 May 2020 18:58:23 -0400 (EDT) From: Josh de Kock To: ffmpeg-devel@ffmpeg.org Date: Thu, 14 May 2020 23:58:21 +0100 Message-Id: <20200514225821.37585-1-josh@itanimul.li> X-Mailer: git-send-email 2.26.0 In-Reply-To: References: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3] checkasm: add hscale test X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" This tests the hscale 8bpp to 14bpp functions with different filter sizes. Signed-off-by: Josh de Kock --- Adds support for checking corner cases for signed and large coefficients. Also makes the padded coefficients random data. Tested on x86_64 and aarch64. tests/checkasm/Makefile | 2 +- tests/checkasm/checkasm.c | 1 + tests/checkasm/checkasm.h | 1 + tests/checkasm/sw_scale.c | 134 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 tests/checkasm/sw_scale.c diff --git a/tests/checkasm/Makefile b/tests/checkasm/Makefile index de850c016e..9e9569777b 100644 --- a/tests/checkasm/Makefile +++ b/tests/checkasm/Makefile @@ -45,7 +45,7 @@ AVFILTEROBJS-$(CONFIG_NLMEANS_FILTER) += vf_nlmeans.o CHECKASMOBJS-$(CONFIG_AVFILTER) += $(AVFILTEROBJS-yes) # swscale tests -SWSCALEOBJS += sw_rgb.o +SWSCALEOBJS += sw_rgb.o sw_scale.o CHECKASMOBJS-$(CONFIG_SWSCALE) += $(SWSCALEOBJS) diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c index 5c9013d922..120052a816 100644 --- a/tests/checkasm/checkasm.c +++ b/tests/checkasm/checkasm.c @@ -183,6 +183,7 @@ static const struct { #endif #if CONFIG_SWSCALE { "sw_rgb", checkasm_check_sw_rgb }, + { "sw_scale", checkasm_check_sw_scale }, #endif #if CONFIG_AVUTIL { "fixed_dsp", checkasm_check_fixed_dsp }, diff --git a/tests/checkasm/checkasm.h b/tests/checkasm/checkasm.h index 5807d32e14..e98a800c50 100644 --- a/tests/checkasm/checkasm.h +++ b/tests/checkasm/checkasm.h @@ -69,6 +69,7 @@ void checkasm_check_pixblockdsp(void); void checkasm_check_sbrdsp(void); void checkasm_check_synth_filter(void); void checkasm_check_sw_rgb(void); +void checkasm_check_sw_scale(void); void checkasm_check_utvideodsp(void); void checkasm_check_v210dec(void); void checkasm_check_v210enc(void); diff --git a/tests/checkasm/sw_scale.c b/tests/checkasm/sw_scale.c new file mode 100644 index 0000000000..06c8a93103 --- /dev/null +++ b/tests/checkasm/sw_scale.c @@ -0,0 +1,134 @@ +/* + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with FFmpeg; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include + +#include "libavutil/common.h" +#include "libavutil/intreadwrite.h" +#include "libavutil/mem.h" + +#include "libswscale/swscale.h" +#include "libswscale/swscale_internal.h" + +#include "checkasm.h" + +#define randomize_buffers(buf, size) \ + do { \ + int j; \ + for (j = 0; j < size; j+=4) \ + AV_WN32(buf + j, rnd()); \ + } while (0) + +#define SRC_PIXELS 128 + +static void check_hscale(void) +{ +#define MAX_FILTER_WIDTH 40 +#define FILTER_SIZES 5 + static const int filter_sizes[FILTER_SIZES] = { 4, 8, 16, 32, 40 }; + +#define HSCALE_PAIRS 2 + static const int hscale_pairs[HSCALE_PAIRS][2] = { + { 8, 14 }, + { 8, 18 }, + }; + + int i, j, fsi, hpi, width; + struct SwsContext *ctx; + + // padded + LOCAL_ALIGNED_32(uint8_t, src, [SRC_PIXELS + MAX_FILTER_WIDTH - 1]); + LOCAL_ALIGNED_32(uint32_t, dst0, [SRC_PIXELS]); + LOCAL_ALIGNED_32(uint32_t, dst1, [SRC_PIXELS]); + + // padded + LOCAL_ALIGNED_32(int16_t, filter, [SRC_PIXELS * MAX_FILTER_WIDTH + MAX_FILTER_WIDTH]); + LOCAL_ALIGNED_32(int32_t, filterPos, [SRC_PIXELS]); + + // The dst parameter here is either int16_t or int32_t but we use void* to + // just cover both cases. + declare_func(void, void *c, void *dst, int dstW, + const uint8_t *src, const int16_t *filter, + const int32_t *filterPos, int filterSize); + + ctx = sws_alloc_context(); + if (sws_init_context(ctx, NULL, NULL) < 0) + fail(); + + randomize_buffers(src, SRC_PIXELS + MAX_FILTER_WIDTH - 1); + + for (hpi = 0; hpi < HSCALE_PAIRS; hpi++) { + for (fsi = 0; fsi < FILTER_SIZES; fsi++) { + width = filter_sizes[fsi]; + + ctx->srcBpc = hscale_pairs[hpi][0]; + ctx->dstBpc = hscale_pairs[hpi][1]; + ctx->hLumFilterSize = ctx->hChrFilterSize = width; + + for (i = 0; i < SRC_PIXELS; i++) { + filterPos[i] = i; + + // These filter cofficients are chosen to try break two corner + // cases, namely: + // + // - Negative filter coefficients. The filters output signed + // values, and it should be possible to end up with negative + // output values. + // + // - Positive clipping. The hscale filter function has clipping + // at (1<<15) - 1 + // + // The coefficients sum to the 1.0 point for the hscale + // functions (1 << 14). + + for (j = 0; j < width; j++) { + filter[i * width + j] = -((1 << 14) / (width - 1)); + } + filter[i * width + (rnd() % (width - 1))] = ((1 << 15) - 1); + } + + for (i = 0; i < MAX_FILTER_WIDTH; i++) { + // These values should be unused in SIMD implementations but + // may still be read, random coefficients here should help show + // issues where they are used in error. + + filter[SRC_PIXELS * width + i] = rnd(); + } + ff_getSwsFunc(ctx); + + if (check_func(ctx->hcScale, "hscale_%d_to_%d_width%d", ctx->srcBpc, ctx->dstBpc + 1, width)) { + memset(dst0, 0, SRC_PIXELS * sizeof(dst0[0])); + memset(dst1, 0, SRC_PIXELS * sizeof(dst1[0])); + + call_ref(NULL, dst0, SRC_PIXELS, src, filter, filterPos, width); + call_new(NULL, dst1, SRC_PIXELS, src, filter, filterPos, width); + if (memcmp(dst0, dst1, SRC_PIXELS * sizeof(dst0[0]))) + fail(); + bench_new(NULL, dst0, SRC_PIXELS, src, filter, filterPos, width); + } + } + } + sws_freeContext(ctx); +} + +void checkasm_check_sw_scale(void) +{ + check_hscale(); + report("hscale"); +}