From patchwork Mon Sep 23 12:40:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ramiro Polla X-Patchwork-Id: 51750 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:d154:0:b0:48e:c0f8:d0de with SMTP id bt20csp2472968vqb; Mon, 23 Sep 2024 06:59:21 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWHLj56LMIBG3cZizwAYD1xDJ+eG3JzSLyFZvzP5Op7QmvQD3qCzhNEr/EbnoJC82PSH57IfikGI3n6uMAFJmgm@gmail.com X-Google-Smtp-Source: AGHT+IESbibkPZSEVpF5YYSrf1cLYmkGxjyC9HF+yTcoFeVUTMgu+zohL8kW+Yyx816cS/QT0gk5 X-Received: by 2002:a05:6512:4009:b0:52e:f77b:bb58 with SMTP id 2adb3069b0e04-536ac2fec5dmr5637789e87.36.1727099960681; Mon, 23 Sep 2024 06:59:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1727099960; cv=none; d=google.com; s=arc-20240605; b=DwAwuz/4SRF7ptCCKZDbnnjuI0vIbFNucdOta9JCFBXss0tE70gNmcOF524NNGSViU 2YEQfMY6qNORyvaibny6vaPyMbhdfu11AkfwPKDSk69D8Gy/8yL8NlOno4uBTUp/OVAo 6/CVnD//tgy19jtebNxhjU85r5z0Aji4zypeGF1g7TQ0CeqjoIFAd9XXtg1hEnNK9GEl +nnimQQYnUTkmMr8nd6bCK5RZ93cQnnP+2Dg3RvGxrTXuZvWztUqMccFTscw81YjqbzC Ac3g0RxjmdAPUTDJbOd+/tDNApGu67ZZJEXFss4YHFEsYSS16CzlqMB4fev7y52fkgFS gcIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=guZkA0sDthRbqRou9bVdgCkcLkzUTHCnMZbJgPNyRi8=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=j6FZY2fFKXyWmcYx1lywBVMfphMmC2lEYb/EQ1XU6pryiS08ljubVdMLmPvkSkLb+G FvQec0ubmYs5KQK2OIAaOBygjQbfpm6N9MrlWGNdxla2a5DDfVwY4NWKU6zZOT7GCPA9 +g41rPBwC2lb1v6F02cmU4oFbmupKFFpY9fPXmj855q2pxBKUv2U92CsFbG58YRrcZsD CmHlsuuCtzpdGlX30vAQB+SYKzCBly9bg+u/YV7MALiFvEqRoxjEiV4BujKkD5/gAjQH 8sxo3g59CH8baUfX8vwnoQkBpFYm10dgKWIHtebD8tR6LEPcA3pnR2P3N00tbRsGOzIr Y0fg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=ClQA3YOx; 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=QUARANTINE dis=NONE) header.from=gmail.com; dara=fail header.i=@gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 2adb3069b0e04-536870a0b5bsi6556475e87.376.2024.09.23.06.59.19; Mon, 23 Sep 2024 06:59:20 -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=@gmail.com header.s=20230601 header.b=ClQA3YOx; 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=QUARANTINE dis=NONE) header.from=gmail.com; dara=fail header.i=@gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7FC2368D9D9; Mon, 23 Sep 2024 15:40:39 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 435A368DAD7 for ; Mon, 23 Sep 2024 15:40:30 +0300 (EEST) Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-42cc43454d5so33826125e9.3 for ; Mon, 23 Sep 2024 05:40:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727095230; x=1727700030; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Tfde/GWmOUeBcrkZSBAg0DdLoPm9H7USjTJRe77tISU=; b=ClQA3YOxpJdTxHRzAak2ryZuCNkd4YcEwr2Qj3FnXoGpaY3ZQgwUFq0Sv5/ymWDTua rLx/+3F3nQNp7iH/yxw0/OTvCsKO/IUgf94vqGd2EZOfCi61/Reuk3YOpDG9qk2OmVZT TFlKWcHwv6F89MUaqbcxjAKuWLi3/IBEZzOVmxUO1+l/sKz4qzQSF90OjA+Jvs4fckDz H99ORIk7fIMJ2w/z76tCqMxBvMUfMIP2qI3PUMZ8bqjoEhnXoZRnWbzIw+z1XsyjL8zY vqybdGEgrOzrHGPIU57aR+qbQQr/rMEk7rvPtjAX8E2b6qqC0hLWc6FQpOsAWyTM26BG Q0pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727095230; x=1727700030; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Tfde/GWmOUeBcrkZSBAg0DdLoPm9H7USjTJRe77tISU=; b=QYB5salRtHUOL1lFOXldEa2TDl8bSw9nzsjnymEm7aJmaycK1tV/LnZeb6AmgYeEyM rd5Zm/Nvhesj5JQCk9+mweb3jWjj4kG7iLiEnGR2hs818WoXOhtEh8Kmj83q3oqEa3ta Y0tEOVdWiYjINg/odfjWGscMU/wlYkNAlS56hj6q5Qw4I8jQjXLdRYm7VSS6XKLZ1b92 Z841TBMgpMJXX0W7+WbvrMCFmmwkH4eGXeQJ4bgREPfSE0eh0sHPZnHD2lDU+rdWgyVa szveL5zu32/80Bk497W+RUNCr4Oz3LAF2GkH+n0gm7V0kt8fYYC3x6qJt52lgLQy5x6l e8sw== X-Gm-Message-State: AOJu0YyfKNyUCD+aMtQxFey0qVRyLYghPbl8kmy/6WcTBqas0ahNiDEC VEoCSDvV8vO3eTI8vjzWkK1dJt4blWhlOnlD3Z86L4WZN8p381C+G5foZw== X-Received: by 2002:a05:600c:1d1e:b0:426:6379:3b4f with SMTP id 5b1f17b1804b1-42e7adda199mr68813335e9.31.1727095229376; Mon, 23 Sep 2024 05:40:29 -0700 (PDT) Received: from localhost.localdomain (213.95-240-81.adsl-dyn.isp.belgacom.be. [81.240.95.213]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-378e71f0683sm24424345f8f.13.2024.09.23.05.40.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Sep 2024 05:40:28 -0700 (PDT) From: Ramiro Polla To: ffmpeg-devel@ffmpeg.org Date: Mon, 23 Sep 2024 14:40:11 +0200 Message-Id: <20240923124017.33659-9-ramiro.polla@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240923124017.33659-1-ramiro.polla@gmail.com> References: <20240923124017.33659-1-ramiro.polla@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 08/14] checkasm/sw_range_convert: test all supported bit depths 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 8IyHZZywKA+/ This commit also reduces the number of times ff_sws_init_scale() gets called (only once per bit depth), and the number of times randomize_buffers() gets called (only if the function must be checked). Benchmarks are only performed on bit depths 8 and 16 (since they are different functions, and not only different constants). --- tests/checkasm/sw_range_convert.c | 94 +++++++++++++++++++++---------- 1 file changed, 63 insertions(+), 31 deletions(-) diff --git a/tests/checkasm/sw_range_convert.c b/tests/checkasm/sw_range_convert.c index e97388d14a..e3e5096729 100644 --- a/tests/checkasm/sw_range_convert.c +++ b/tests/checkasm/sw_range_convert.c @@ -28,6 +28,33 @@ #include "checkasm.h" +static const enum AVPixelFormat pixel_formats[] = { + AV_PIX_FMT_YUV444P, + AV_PIX_FMT_YUV444P9, + AV_PIX_FMT_YUV444P10, + AV_PIX_FMT_YUV444P12, + AV_PIX_FMT_YUV444P14, + AV_PIX_FMT_YUV444P16, +}; + +static void randomize_buffers(int16_t *buf0, int16_t *buf1, int bit_depth, int width) +{ + int32_t *buf0_32 = (int32_t *) buf0; + int32_t *buf1_32 = (int32_t *) buf1; + int mask = (1 << bit_depth) - 1; + int src_shift = bit_depth <= 14 ? 15 - bit_depth : 19 - bit_depth; + for (int i = 0; i < width; i++) { + int32_t r = rnd() & mask; + if (bit_depth == 16) { + buf0_32[i] = r << src_shift; + buf1_32[i] = r << src_shift; + } else { + buf0[i] = r << src_shift; + buf1[i] = r << src_shift; + } + } +} + static void check_lumConvertRange(int from) { const char *func_str = from ? "lumRangeFromJpeg" : "lumRangeToJpeg"; @@ -35,8 +62,8 @@ static void check_lumConvertRange(int from) static const int input_sizes[] = {8, LARGEST_INPUT_SIZE}; struct SwsContext *ctx; - LOCAL_ALIGNED_32(int16_t, dst0, [LARGEST_INPUT_SIZE]); - LOCAL_ALIGNED_32(int16_t, dst1, [LARGEST_INPUT_SIZE]); + LOCAL_ALIGNED_32(int16_t, dst0, [LARGEST_INPUT_SIZE * 2]); + LOCAL_ALIGNED_32(int16_t, dst1, [LARGEST_INPUT_SIZE * 2]); declare_func(void, int16_t *dst, int width); @@ -44,28 +71,31 @@ static void check_lumConvertRange(int from) if (sws_init_context(ctx, NULL, NULL) < 0) fail(); - ctx->srcFormat = AV_PIX_FMT_YUV444P; - ctx->dstFormat = AV_PIX_FMT_YUV444P; ctx->srcRange = from; ctx->dstRange = !from; + for (int pfi = 0; pfi < FF_ARRAY_ELEMS(pixel_formats); pfi++) { + enum AVPixelFormat pix_fmt = pixel_formats[pfi]; + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); + int bit_depth = desc->comp[0].depth; + int sample_size = bit_depth == 16 ? sizeof(int32_t) : sizeof(int16_t); + ctx->srcFormat = pix_fmt; + ctx->dstFormat = pix_fmt; + ctx->dstBpc = bit_depth; + ff_sws_init_scale(ctx); for (int dstWi = 0; dstWi < FF_ARRAY_ELEMS(input_sizes); dstWi++) { int width = input_sizes[dstWi]; - for (int i = 0; i < width; i++) { - uint8_t r = rnd(); - dst0[i] = (int16_t) r << 7; - dst1[i] = (int16_t) r << 7; - } - ff_sws_init_scale(ctx); - if (check_func(ctx->lumConvertRange, "%s_%d", func_str, width)) { + if (check_func(ctx->lumConvertRange, "%s%d_%d", func_str, bit_depth, width)) { + randomize_buffers(dst0, dst1, bit_depth, width); call_ref(dst0, width); call_new(dst1, width); - if (memcmp(dst0, dst1, width * sizeof(int16_t))) + if (memcmp(dst0, dst1, width * sample_size)) fail(); - if (width == LARGEST_INPUT_SIZE) + if (width == LARGEST_INPUT_SIZE && (bit_depth == 8 || bit_depth == 16)) bench_new(dst1, width); } } + } sws_freeContext(ctx); } @@ -78,10 +108,10 @@ static void check_chrConvertRange(int from) static const int input_sizes[] = {8, LARGEST_INPUT_SIZE}; struct SwsContext *ctx; - LOCAL_ALIGNED_32(int16_t, dstU0, [LARGEST_INPUT_SIZE]); - LOCAL_ALIGNED_32(int16_t, dstV0, [LARGEST_INPUT_SIZE]); - LOCAL_ALIGNED_32(int16_t, dstU1, [LARGEST_INPUT_SIZE]); - LOCAL_ALIGNED_32(int16_t, dstV1, [LARGEST_INPUT_SIZE]); + LOCAL_ALIGNED_32(int16_t, dstU0, [LARGEST_INPUT_SIZE * 2]); + LOCAL_ALIGNED_32(int16_t, dstV0, [LARGEST_INPUT_SIZE * 2]); + LOCAL_ALIGNED_32(int16_t, dstU1, [LARGEST_INPUT_SIZE * 2]); + LOCAL_ALIGNED_32(int16_t, dstV1, [LARGEST_INPUT_SIZE * 2]); declare_func(void, int16_t *dstU, int16_t *dstV, int width); @@ -89,31 +119,33 @@ static void check_chrConvertRange(int from) if (sws_init_context(ctx, NULL, NULL) < 0) fail(); - ctx->srcFormat = AV_PIX_FMT_YUV444P; - ctx->dstFormat = AV_PIX_FMT_YUV444P; ctx->srcRange = from; ctx->dstRange = !from; + for (int pfi = 0; pfi < FF_ARRAY_ELEMS(pixel_formats); pfi++) { + enum AVPixelFormat pix_fmt = pixel_formats[pfi]; + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(pix_fmt); + int bit_depth = desc->comp[0].depth; + int sample_size = bit_depth == 16 ? sizeof(int32_t) : sizeof(int16_t); + ctx->srcFormat = pix_fmt; + ctx->dstFormat = pix_fmt; + ctx->dstBpc = bit_depth; + ff_sws_init_scale(ctx); for (int dstWi = 0; dstWi < FF_ARRAY_ELEMS(input_sizes); dstWi++) { int width = input_sizes[dstWi]; - for (int i = 0; i < width; i++) { - uint8_t r = rnd(); - dstU0[i] = (int16_t) r << 7; - dstV0[i] = (int16_t) r << 7; - dstU1[i] = (int16_t) r << 7; - dstV1[i] = (int16_t) r << 7; - } - ff_sws_init_scale(ctx); - if (check_func(ctx->chrConvertRange, "%s_%d", func_str, width)) { + if (check_func(ctx->chrConvertRange, "%s%d_%d", func_str, bit_depth, width)) { + randomize_buffers(dstU0, dstU1, bit_depth, width); + randomize_buffers(dstV0, dstV1, bit_depth, width); call_ref(dstU0, dstV0, width); call_new(dstU1, dstV1, width); - if (memcmp(dstU0, dstU1, width * sizeof(int16_t)) || - memcmp(dstV0, dstV1, width * sizeof(int16_t))) + if (memcmp(dstU0, dstU1, width * sample_size) || + memcmp(dstV0, dstV1, width * sample_size)) fail(); - if (width == LARGEST_INPUT_SIZE) + if (width == LARGEST_INPUT_SIZE && (bit_depth == 8 || bit_depth == 16)) bench_new(dstU1, dstV1, width); } } + } sws_freeContext(ctx); }