From patchwork Wed Jun 5 17:34:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zhao Zhili X-Patchwork-Id: 49588 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:d792:0:b0:460:55fa:d5ed with SMTP id db18csp551895vqb; Wed, 5 Jun 2024 10:35:23 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXmobfJB961mVOcQ0sX21RU+62CGtfEdIlBUdgyC+KfjgL8Br1q/eU4xEoDlNHSmORHI6RxMBgLIUSYLKoNlLJDsYvY1UJtunEwnA== X-Google-Smtp-Source: AGHT+IF4Heikm6qo9OiT3JVFN5pQfkGKZkZnVUo0vkhVcTh9NlBLW1qnGdgVsuA00HpGanqE3ElE X-Received: by 2002:a05:6512:124f:b0:520:df8f:9997 with SMTP id 2adb3069b0e04-52bab4b1232mr2175005e87.9.1717608923225; Wed, 05 Jun 2024 10:35:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1717608923; cv=none; d=google.com; s=arc-20160816; b=VirEZwCYn1wNeM58KKLunCWA3eGSaVYpziToa8jcSTp8qe1+7I+4pomRAhvGMnjadd AAQZM5u5tPeKQm8vvrdLq/nxZ9lMDrkeBatYTCkWsWj6wAifJSd8eHNajxr97mi27QUC D1PEcSJ/NqXgIqPr8+Tu+HG3kCT4z5y/iDAmIXEdVvVz99dXJgDxhfTb7g1hdVUUZi0q PDRaGvT8M6yAu6n2qHUXhM9aBIYzsqwv1iZIcQmQqcBNGgbdNfIxhpikum3ptalulvXw VC9m4MGnVEFmJFYM3+e1N8Bo8byZVUPN0cOfzOSFvp2Wdt9ddsHuUWcVDAaPSMLPJLZ/ ou4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:date:to:from:message-id :dkim-signature:delivered-to; bh=4Ta/07U5Uo6EmTgO02b47GWL3zoB6DiJa3g3hL+7pFU=; fh=HnHYuZ9XgUo86ZRXTLWWmQxhslYEI9B9taZ5X1DLFfc=; b=Wa3w0dwV/Bw3PsSdRInfV7EC+vBpiw6q0RxWCmj7sxYiVfMlVs6gN7ExLsV/lvpp9S 2VoJUtBnoD3uuPGanfFKvS+D/fJOauH5AbWRpfh85rGo5TUY3zoo038Tm9EzG2v+ybll sDz5gEQ4SfnRp9FwyLpHI6uqu9vibOJ9IzEQqsU+DeLpi8MXAI70VW1rGwExNhC/Wc9G Dbva3mAvedkN40WKfBsnOPDyXf/NjprjcpksQnjVQjSXEyFvOedjtnTbk/xh3LbU5tfy UbTpecK61nfvXBB3ns43LvUQy8ObaUZTpByicNfbDPpRMzz0SZuE51HtF2DiZ+nZuBl1 onkw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@foxmail.com header.s=s201512 header.b=bh2YL5Pi; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 4fb4d7f45d1cf-57a31ca62ccsi6283479a12.563.2024.06.05.10.35.22; Wed, 05 Jun 2024 10:35:23 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@foxmail.com header.s=s201512 header.b=bh2YL5Pi; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8DA4368D6DB; Wed, 5 Jun 2024 20:35:18 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from out162-62-57-252.mail.qq.com (out162-62-57-252.mail.qq.com [162.62.57.252]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4207E68D586 for ; Wed, 5 Jun 2024 20:35:09 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1717608899; bh=H0je/i2WosoBQIBE8AVougdSnIrQcByzq6o37o6cvDE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=bh2YL5PicSVqopopFgDqpzY6ed8PstW932DAK96OVLRsSHDiGRIHrnZeoKu4lE3NX I1qi/oiBq0ky8S7Ww0ukFSUIflVGK2GTHPFmjtbqGpgsXqaka6QiPPDcA6IjQwHs48 gr9isc3WNV0PH9tG6Z83HxLjosdnK53NQtVgwtuA= Received: from ZHILIZHAO-MB1.tencent.com ([121.34.203.204]) by newxmesmtplogicsvrszc5-2.qq.com (NewEsmtp) with SMTP id 8BA1E83B; Thu, 06 Jun 2024 01:34:58 +0800 X-QQ-mid: xmsmtpt1717608898tyb82polc Message-ID: X-QQ-XMAILINFO: Nd/Exl7W9DK5spwOYGA6GbbzhNLOJWU+pdJp2svaI6nZ44A5jw3H1L+CepAbnR U+UQdrpw3x+Rl/uminKRA7Wwpz8BggexZVn3h41zGJetikC6KQp1uT8BeovYtxFHYkT+EpYtCt9Z rPHKwHcIjlHtkGaB5TgofvF2g7ryYozKpggQ4yYKBmBcoIIRwJxBJuU7IyEHq9z6EdjX9+fpNhQt OFmLUvqm0nMRTuAHv3PZBlGqIM7eV1HjdnN/pUMSmCFPhZAE0cxGBLDDUbMnEsCV0/VNSKALEo7G 6xIWhNWnz0PSTlXin5y3Pj7Nt22AwacQ3CqMTrlbZPBCidirsDfL7z7KPzu1XlqL62HKKqekVkos UX4NdWrZ33WIfnOzsjNkONuHdHCBsI02ByD4g7coSFYeMjbWQPp3qPK5Tvt7D33RTtY54/JJ1NQY hRsy5a1UXUPunSqA8qrj9dwUVWvvv10g3NdypgG83/YVWLpzat31YLLlUnMDf0tOgjqnpXAhIREp AE6BrxniEEG7kAFQbop8gGhZN9+vhIFjq8gor5U1qQwsDSkfXj2AUQ4MPL3CNLbZc7pr7cfsRDja bQfD+JjKO63RMetlMZ6RtGB181OuK/phP2uQLhr42Ghh1KVtUOKtw0uzWNE4/KA829kflF+Frj5x CHYRXQCyTYCO5YgckBBmSBtqWYm7Y8obm+o+NnkDj2pSqD7pdWu+m4RqZzwKhWs83Q/AsLFZGyfp CR5qzvOMTTV09GJk3i/geoQdDrCbP5rxKSNOO7AS8laGEu0N6sB+hLViJdA3R/Dr0A4dBYqDYnGR g6wmwigTEDjWkoKcm0thf+UTSJgDHURg6SAtKCmzgzI7AWWZXo7RMv2ctwlP8FC2vhDiDBxkwz9v saFJeF1PrLnPp1Ur3Bgn6UVPZQ+kXrb7LTQH7Ksu3Zo0ZL7la0aVU2gEZ6VDuddAdMdrr3UhQGof HUfn78liDlN3xgGeadyzwp/w94ucisymelQY8iI2I= X-QQ-XMRINFO: NS+P29fieYNw95Bth2bWPxk= From: Zhao Zhili To: ffmpeg-devel@ffmpeg.org Date: Thu, 6 Jun 2024 01:34:45 +0800 X-OQ-MSGID: <20240605173455.88233-1-quinkblack@foxmail.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <2732152.mvXUDI8C0e@basile.remlab.net> References: <2732152.mvXUDI8C0e@basile.remlab.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 1/5] checkasm/sw_rgb: test rgb24/bgr24 to yuv X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Cc: Zhao Zhili Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: ZZo7eyyw4tcc From: Zhao Zhili The line width 8 is supposed to test corner case, while the performance doesn't matter. Width 1080 is also a case of unaligned to 16. Width 1920 meant for benchmark (together with --runs options). --- v2: add bgr24 support Feel free to remove 128 and/or 1280 from input_sizes if you think it's redundant. I'm still working on patch 2-5. Send patch 1/5 because James and RĂ©mi' patches depend on this. tests/checkasm/sw_rgb.c | 113 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/tests/checkasm/sw_rgb.c b/tests/checkasm/sw_rgb.c index 7cd815e5be..06d27f9235 100644 --- a/tests/checkasm/sw_rgb.c +++ b/tests/checkasm/sw_rgb.c @@ -22,8 +22,11 @@ #include "libavutil/common.h" #include "libavutil/intreadwrite.h" #include "libavutil/mem_internal.h" +#include "libavutil/pixdesc.h" #include "libswscale/rgb2rgb.h" +#include "libswscale/swscale.h" +#include "libswscale/swscale_internal.h" #include "checkasm.h" @@ -179,8 +182,104 @@ static void check_interleave_bytes(void) } } +#define MAX_LINE_SIZE 1920 +static const int input_sizes[] = {8, 128, 1280, 1080, MAX_LINE_SIZE}; +static const enum AVPixelFormat rgb_formats[] = { + AV_PIX_FMT_RGB24, + AV_PIX_FMT_BGR24, +}; + +static void check_rgb_to_y(struct SwsContext *ctx) +{ + LOCAL_ALIGNED_32(uint8_t, src, [MAX_LINE_SIZE * 3]); + LOCAL_ALIGNED_32(uint8_t, dst0_y, [MAX_LINE_SIZE * 2]); + LOCAL_ALIGNED_32(uint8_t, dst1_y, [MAX_LINE_SIZE * 2]); + + declare_func(void, uint8_t *dst, const uint8_t *src, + const uint8_t *unused1, const uint8_t *unused2, int width, + uint32_t *rgb2yuv, void *opq); + + randomize_buffers(src, MAX_LINE_SIZE * 3); + + for (int i = 0; i < FF_ARRAY_ELEMS(rgb_formats); i++) { + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(rgb_formats[i]); + + ctx->srcFormat = rgb_formats[i]; + ctx->dstFormat = AV_PIX_FMT_YUV420P; + ff_sws_init_scale(ctx); + + for (int j = 0; j < FF_ARRAY_ELEMS(input_sizes); j++) { + int w = input_sizes[j]; + + if (check_func(ctx->lumToYV12, "%s_to_y_%d", desc->name, w)) { + memset(dst0_y, 0xFA, MAX_LINE_SIZE * 2); + memset(dst1_y, 0xFA, MAX_LINE_SIZE * 2); + + call_ref(dst0_y, src, NULL, NULL, w, ctx->input_rgb2yuv_table, + NULL); + call_new(dst1_y, src, NULL, NULL, w, ctx->input_rgb2yuv_table, + NULL); + + if (memcmp(dst0_y, dst1_y, w * 2)) + fail(); + + bench_new(dst1_y, src, NULL, NULL, w, ctx->input_rgb2yuv_table, + NULL); + } + } + } +} + +static void check_rgb_to_uv(struct SwsContext *ctx) +{ + LOCAL_ALIGNED_32(uint8_t, src, [MAX_LINE_SIZE * 3]); + LOCAL_ALIGNED_32(uint8_t, dst0_u, [MAX_LINE_SIZE * 2]); + LOCAL_ALIGNED_32(uint8_t, dst0_v, [MAX_LINE_SIZE * 2]); + LOCAL_ALIGNED_32(uint8_t, dst1_u, [MAX_LINE_SIZE * 2]); + LOCAL_ALIGNED_32(uint8_t, dst1_v, [MAX_LINE_SIZE * 2]); + + declare_func(void, uint8_t *dstU, uint8_t *dstV, + const uint8_t *src1, const uint8_t *src2, const uint8_t *src3, + int width, uint32_t *pal, void *opq); + + randomize_buffers(src, MAX_LINE_SIZE * 3); + + for (int i = 0; i < 2 * FF_ARRAY_ELEMS(rgb_formats); i++) { + enum AVPixelFormat src_fmt = rgb_formats[i / 2]; + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(src_fmt); + + ctx->chrSrcHSubSample = (i % 2) ? 0 : 1; + ctx->srcFormat = src_fmt; + ctx->dstFormat = ctx->chrSrcHSubSample ? AV_PIX_FMT_YUV420P : AV_PIX_FMT_YUV444P; + ff_sws_init_scale(ctx); + + for (int j = 0; j < FF_ARRAY_ELEMS(input_sizes); j++) { + int w = input_sizes[j] >> ctx->chrSrcHSubSample; + + if (check_func(ctx->chrToYV12, "%s_to_uv%s_%d", desc->name, + ctx->chrSrcHSubSample ? "_half" : "", + input_sizes[j])) { + memset(dst0_u, 0xFF, MAX_LINE_SIZE * 2); + memset(dst0_v, 0xFF, MAX_LINE_SIZE * 2); + memset(dst1_u, 0xFF, MAX_LINE_SIZE * 2); + memset(dst1_v, 0xFF, MAX_LINE_SIZE * 2); + + call_ref(dst0_u, dst0_v, NULL, src, src, w, ctx->input_rgb2yuv_table, NULL); + call_new(dst1_u, dst1_v, NULL, src, src, w, ctx->input_rgb2yuv_table, NULL); + + if (memcmp(dst0_u, dst1_u, w * 2) || memcmp(dst0_v, dst1_v, w * 2)) + fail(); + + bench_new(dst1_u, dst1_v, NULL, src, src, w, ctx->input_rgb2yuv_table, NULL); + } + } + } +} + void checkasm_check_sw_rgb(void) { + struct SwsContext *ctx; + ff_sws_rgb2rgb_init(); check_shuffle_bytes(shuffle_bytes_2103, "shuffle_bytes_2103"); @@ -203,4 +302,18 @@ void checkasm_check_sw_rgb(void) check_interleave_bytes(); report("interleave_bytes"); + + ctx = sws_getContext(MAX_LINE_SIZE, MAX_LINE_SIZE, AV_PIX_FMT_RGB24, + MAX_LINE_SIZE, MAX_LINE_SIZE, AV_PIX_FMT_YUV420P, + SWS_ACCURATE_RND | SWS_BITEXACT, NULL, NULL, NULL); + if (!ctx) + fail(); + + check_rgb_to_y(ctx); + report("rgb_to_y"); + + check_rgb_to_uv(ctx); + report("rgb_to_uv"); + + sws_freeContext(ctx); }