From patchwork Tue Dec 5 14:45:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuo Mi X-Patchwork-Id: 44927 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:9153:b0:181:818d:5e7f with SMTP id x19csp378876pzc; Tue, 5 Dec 2023 06:47:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IGFU+vjr6KQFaxLvO6OAJi+wTBd7RQqw32EwGMHoN2XtFS9XRAdqLZD3vpcDouYxuuDgfx5 X-Received: by 2002:a50:8acf:0:b0:54c:5ebf:b9d5 with SMTP id k15-20020a508acf000000b0054c5ebfb9d5mr2047364edk.92.1701787672515; Tue, 05 Dec 2023 06:47:52 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id e18-20020a50a692000000b0054cdb037c54si904064edc.104.2023.12.05.06.47.51; Tue, 05 Dec 2023 06:47:52 -0800 (PST) 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=@outlook.com header.s=selector1 header.b=fzkvmDdM; arc=fail (body hash mismatch); 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0CAAD68CF53; Tue, 5 Dec 2023 16:46:17 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from APC01-PSA-obe.outbound.protection.outlook.com (mail-psaapc01olkn2037.outbound.protection.outlook.com [40.92.52.37]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DFAA868CEE9 for ; Tue, 5 Dec 2023 16:46:09 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PKWmeSJY/ABwORMjlhrTVZdyWtbgD7+JmSC738//yRPK7uJt3HaPO2lrzZdSJKzIQs4Nn6lP9vvB3vkJp4sqkblNyCgchy0rvVOIu7pPinWyeHMehGje45UB3KcYrgY/CcVw7EH+fvhds/V3BTLImFnmgWbpzIyWyX8uN6HSWEPEbNUmQHr2rxnK8lw6/LF5/RGcboF1Dfz33EEPvOUhqmQmaOYbltF78nOotfUOacz9wf0cDmSYENQzX6G1g/2zDjKqmZKEPXUsOE4gO6Vb6718LRWHt+q2H/TPhYnKW1e4RJMYTP/bODMCen2cbSO9QHCiTkHW7x+VHlQWUEeqYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=VMcL0jtMx/VN4yEWr5RvYa01yy3SYVyzgWvoReByyaU=; b=KYQIbsE15/i8NrU9maKc/8vWmkq7goY6F0LuxhbSSGppscPx2/BXZ28T5bcJPVVlEKbqdMsiy2C5dyWu2ISe447omAiXc5ypwYJ7zWeEUZs10h3aczvB0c8Gvf5ET+m0RZFnOaiWwDgRHdWFrCppi0BZZsiDgHv0cetVEGH2iRDqQLT4du09H7fd/G1YZrxWnfbCPu8n+hSPCMRGORGw/ceJOp00VJ/+8QW0fKZrCdps+JeimwxGJrrLc46nJYjuHQ+XFOgY09J1XnNlNoyhYUXkwp4y9DrXYQglDlFaMaENsh2kZRjcHPHxCZgmFFQH5PqZe0Vp6iFtvbi+3LRdwg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VMcL0jtMx/VN4yEWr5RvYa01yy3SYVyzgWvoReByyaU=; b=fzkvmDdMu/f91N6lXDuxMi20mFn8YDye4qaMX2CdYgCd8kNxmgbX5272gbRxrXlSev+OMdzTrHFPC9pawt9QS2Qfj53VUY4IHERYKF+NwcNHOUX9XtgU+zWC672x2OfA9CfVpa1PaXBqYL2I9d9Z6J25RCrOiVU48QeeTxMSADkYtoDPZYmfIeT8Zo3Gy46ajuQOH9ZAue2Ce4RWPzqt4fRHfOWtbI9q4xGMMNBJsAsPt/xAMTSKJswgjOuho/3ENwHW88qKzQRexTFds8a6YAI3TTsws9a1pltD9v36Gp5Ml2TUn2CgPgsNWk1izrhQ7BAeFCykzh+Cet5T9PiWjg== Received: from TYSPR06MB6433.apcprd06.prod.outlook.com (2603:1096:400:47a::6) by JH0PR06MB6294.apcprd06.prod.outlook.com (2603:1096:990:14::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.33; Tue, 5 Dec 2023 14:45:56 +0000 Received: from TYSPR06MB6433.apcprd06.prod.outlook.com ([fe80::80b3:be24:949c:e49f]) by TYSPR06MB6433.apcprd06.prod.outlook.com ([fe80::80b3:be24:949c:e49f%4]) with mapi id 15.20.7046.034; Tue, 5 Dec 2023 14:45:56 +0000 From: Nuo Mi To: ffmpeg-devel@ffmpeg.org Date: Tue, 5 Dec 2023 22:45:16 +0800 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231205144519.7334-1-nuomi2021@gmail.com> References: <20231205144519.7334-1-nuomi2021@gmail.com> X-TMN: [nuwWLFSRKCMISEyp+b6QK92rcRmRaKE5] X-ClientProxiedBy: SG3P274CA0015.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:be::27) To TYSPR06MB6433.apcprd06.prod.outlook.com (2603:1096:400:47a::6) X-Microsoft-Original-Message-ID: <20231205144519.7334-11-nuomi2021@gmail.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 2 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYSPR06MB6433:EE_|JH0PR06MB6294:EE_ X-MS-Office365-Filtering-Correlation-Id: b18099d1-88c0-4c7d-3f80-08dbf5a0e326 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QiLCq9+CN6fIBIyl7epTQ0VRfanDH+Fso3bsQsmH4Aw65RQQ4F9iCyfEcJsIPb6qAAc16d/KJPj8zYS7x5RiF4VVlZyTkxQXmImFRS1F9ZHT5bUHfXY9G1io59k46c+Qfu3yPpe86DQTiSvjOMq/1aDMipecyUz4PuMJ28XIIlDhDpcgxMI671po6eILLKukircJNYKflG2Xa6+Dx+AXKBRR1LOOuh3rkErhN6y5PeQBwatOqWVnSQBA2PXP5mll8fNnZNxZL4k6daiaOUyIO0ye9ojHaLA5kZWSbY+Q5dEYPtWmjFm/7uoDlTW827N/KCu5bMbgK9uBzUGiUhU7ilCLoT6TTEqBjZeEDJE3FMdBLKzIEutKXOAfLNGDep5lgThT+U8+iuIYJHaKoyXvr/p13bOMur4uyEIyjMfgResUrTPsNdjp5dBiTazE8avEKiQGOKeAkKMTMcfUDtdBJM7xSZkzEHkdF5RK5IvzzDDGzuHfMdur0CX2u263OKlA2tRvKCrDQci5R6/jxThdeeK6a+fsyCYEdeDGuSHPVYGVq3Kkfc9k+HvSzxCnsqZKJcFgSwcFPRPOTE3KrqOe8vLnvofaa6yl+6wK+QvYeVDClMsEMfOFDDlyjjeLeeY3 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: t7rNgjrNNHrI+s0Y5Krp8yRtkk0HaKfWBsezXeGhsS57f97vm+7Su3ws2vFOKDFKpZ5KgP3Mbxt9+O4uPCPUeazhr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5DigtEXK0IWHc9SUIp/T+Nz7qhzKantFuQ6TC2i7pTF2sA01Bi9rvQa0mpLLnIBiwxtZ7t4t8T2WMFuhWIlMfLeexYBiP96EqtwxoUQ8Y0YCaNDBcCP9a X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: b18099d1-88c0-4c7d-3f80-08dbf5a0e326 X-MS-Exchange-CrossTenant-AuthSource: TYSPR06MB6433.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Dec 2023 14:45:55.9682 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: JH0PR06MB6294 Subject: [FFmpeg-devel] [PATCH v6 11/14] vvcdec: add dsp init and inv transform 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: Nuo Mi Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: r0tdteu/XZ2o --- libavcodec/vvc/Makefile | 1 + libavcodec/vvc/vvcdsp.c | 141 +++++++++++++++++++++++++++++++ libavcodec/vvc/vvcdsp_template.c | 120 ++++++++++++++++++++++++++ 3 files changed, 262 insertions(+) create mode 100644 libavcodec/vvc/vvcdsp.c create mode 100644 libavcodec/vvc/vvcdsp_template.c diff --git a/libavcodec/vvc/Makefile b/libavcodec/vvc/Makefile index 9e7fef7d38..bc663a5b50 100644 --- a/libavcodec/vvc/Makefile +++ b/libavcodec/vvc/Makefile @@ -2,6 +2,7 @@ clean:: $(RM) $(CLEANSUFFIXES:%=libavcodec/vvc/%) OBJS-$(CONFIG_VVC_DECODER) += vvc/vvcdec.o \ + vvc/vvcdsp.o \ vvc/vvc_cabac.o \ vvc/vvc_ctu.o \ vvc/vvc_data.o \ diff --git a/libavcodec/vvc/vvcdsp.c b/libavcodec/vvc/vvcdsp.c new file mode 100644 index 0000000000..fa14614397 --- /dev/null +++ b/libavcodec/vvc/vvcdsp.c @@ -0,0 +1,141 @@ +/* + * VVC DSP + * + * Copyright (C) 2021 Nuo Mi + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser 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 "vvcdsp.h" +#include "vvc_ctu.h" +#include "vvc_itx_1d.h" + +#define VVC_SIGN(v) (v < 0 ? -1 : !!v) + +static void av_always_inline pad_int16(int16_t *_dst, const ptrdiff_t dst_stride, const int width, const int height) +{ + const int padded_width = width + 2; + int16_t *dst; + for (int y = 0; y < height; y++) { + dst = _dst + y * dst_stride; + for (int x = 0; x < width; x++) { + dst[-1] = dst[0]; + dst[width] = dst[width - 1]; + } + } + + _dst--; + //top + memcpy(_dst - dst_stride, _dst, padded_width * sizeof(int16_t)); + //bottom + _dst += dst_stride * height; + memcpy(_dst, _dst - dst_stride, padded_width * sizeof(int16_t)); +} + +static int vvc_sad(const int16_t *src0, const int16_t *src1, int dx, int dy, + const int block_w, const int block_h) +{ + int sad = 0; + dx -= 2; + dy -= 2; + src0 += (2 + dy) * MAX_PB_SIZE + 2 + dx; + src1 += (2 - dy) * MAX_PB_SIZE + 2 - dx; + for (int y = 0; y < block_h; y += 2) { + for (int x = 0; x < block_w; x++) { + sad += FFABS(src0[x] - src1[x]); + } + src0 += 2 * MAX_PB_SIZE; + src1 += 2 * MAX_PB_SIZE; + } + return sad; +} + +#define itx_fn(type, s) \ +static void itx_##type##_##s(int *out, ptrdiff_t out_step, const int *in, ptrdiff_t in_step) \ +{ \ + ff_vvc_inv_##type##_##s(out, out_step, in, in_step); \ +} + +#define itx_fn_common(type) \ + itx_fn(type, 4); \ + itx_fn(type, 8); \ + itx_fn(type, 16); \ + itx_fn(type, 32); \ + +itx_fn_common(dct2); +itx_fn_common(dst7); +itx_fn_common(dct8); +itx_fn(dct2, 2); +itx_fn(dct2, 64); + +typedef struct IntraEdgeParams { + uint8_t* top; + uint8_t* left; + int filter_flag; + + uint16_t left_array[3 * MAX_TB_SIZE + 3]; + uint16_t filtered_left_array[3 * MAX_TB_SIZE + 3]; + uint16_t top_array[3 * MAX_TB_SIZE + 3]; + uint16_t filtered_top_array[3 * MAX_TB_SIZE + 3]; +} IntraEdgeParams; + +#define PROF_BORDER_EXT 1 +#define PROF_BLOCK_SIZE (AFFINE_MIN_BLOCK_SIZE + PROF_BORDER_EXT * 2) +#define BDOF_BORDER_EXT 1 + +#define BDOF_PADDED_SIZE (16 + BDOF_BORDER_EXT * 2) +#define BDOF_BLOCK_SIZE 4 +#define BDOF_GRADIENT_SIZE (BDOF_BLOCK_SIZE + BDOF_BORDER_EXT * 2) + +#define BIT_DEPTH 8 +#include "vvcdsp_template.c" +#undef BIT_DEPTH + +#define BIT_DEPTH 10 +#include "vvcdsp_template.c" +#undef BIT_DEPTH + +#define BIT_DEPTH 12 +#include "vvcdsp_template.c" +#undef BIT_DEPTH + +void ff_vvc_dsp_init(VVCDSPContext *vvcdsp, int bit_depth) +{ +#undef FUNC +#define FUNC(a, depth) a ## _ ## depth + +#define VVC_DSP(depth) \ + FUNC(ff_vvc_inter_dsp_init, depth)(&vvcdsp->inter); \ + FUNC(ff_vvc_intra_dsp_init, depth)(&vvcdsp->intra); \ + FUNC(ff_vvc_itx_dsp_init, depth)(&vvcdsp->itx); \ + FUNC(ff_vvc_lmcs_dsp_init, depth)(&vvcdsp->lmcs); \ + FUNC(ff_vvc_lf_dsp_init, depth)(&vvcdsp->lf); \ + FUNC(ff_vvc_sao_dsp_init, depth)(&vvcdsp->sao); \ + FUNC(ff_vvc_alf_dsp_init, depth)(&vvcdsp->alf); \ + + switch (bit_depth) { + case 12: + VVC_DSP(12); + break; + case 10: + VVC_DSP(10); + break; + default: + VVC_DSP(8); + break; + } +} diff --git a/libavcodec/vvc/vvcdsp_template.c b/libavcodec/vvc/vvcdsp_template.c new file mode 100644 index 0000000000..f92c266478 --- /dev/null +++ b/libavcodec/vvc/vvcdsp_template.c @@ -0,0 +1,120 @@ +/* + * VVC transform and residual DSP + * + * Copyright (C) 2021 Nuo Mi + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser 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 "libavutil/frame.h" +#include "libavcodec/bit_depth_template.c" + +#include "vvcdec.h" +#include "vvc_data.h" + +#include "vvc_inter_template.c" +#include "vvc_intra_template.c" +#include "vvc_filter_template.c" + +static void FUNC(add_residual)(uint8_t *_dst, const int *res, + const int w, const int h, const ptrdiff_t _stride) +{ + pixel *dst = (pixel *)_dst; + + const int stride = _stride / sizeof(pixel); + + for (int y = 0; y < h; y++) { + for (int x = 0; x < w; x++) { + dst[x] = av_clip_pixel(dst[x] + *res); + res++; + } + dst += stride; + } +} + +static void FUNC(add_residual_joint)(uint8_t *_dst, const int *res, + const int w, const int h, const ptrdiff_t _stride, const int c_sign, const int shift) +{ + pixel *dst = (pixel *)_dst; + + const int stride = _stride / sizeof(pixel); + + for (int y = 0; y < h; y++) { + for (int x = 0; x < w; x++) { + const int r = ((*res) * c_sign) >> shift; + dst[x] = av_clip_pixel(dst[x] + r); + res++; + } + dst += stride; + } +} + +static void FUNC(pred_residual_joint)(int *buf, const int w, const int h, + const int c_sign, const int shift) +{ + for (int y = 0; y < h; y++) { + for (int x = 0; x < w; x++) { + *buf = ((*buf) * c_sign) >> shift; + buf++; + } + } +} + +static void FUNC(transform_bdpcm)(int *coeffs, const int width, const int height, + const int vertical, const int log2_transform_range) +{ + int x, y; + + if (vertical) { + coeffs += width; + for (y = 0; y < height - 1; y++) { + for (x = 0; x < width; x++) + coeffs[x] = av_clip_intp2(coeffs[x] + coeffs[x - width], log2_transform_range); + coeffs += width; + } + } else { + for (y = 0; y < height; y++) { + for (x = 1; x < width; x++) + coeffs[x] = av_clip_intp2(coeffs[x] + coeffs[x - 1], log2_transform_range); + coeffs += width; + } + } +} + +static void FUNC(ff_vvc_itx_dsp_init)(VVCItxDSPContext *const itx) +{ +#define VVC_ITX(TYPE, type, s) \ + itx->itx[TYPE][TX_SIZE_##s] = itx_##type##_##s; \ + +#define VVC_ITX_COMMON(TYPE, type) \ + VVC_ITX(TYPE, type, 4); \ + VVC_ITX(TYPE, type, 8); \ + VVC_ITX(TYPE, type, 16); \ + VVC_ITX(TYPE, type, 32); + + itx->add_residual = FUNC(add_residual); + itx->add_residual_joint = FUNC(add_residual_joint); + itx->pred_residual_joint = FUNC(pred_residual_joint); + itx->transform_bdpcm = FUNC(transform_bdpcm); + VVC_ITX(DCT2, dct2, 2) + VVC_ITX(DCT2, dct2, 64) + VVC_ITX_COMMON(DCT2, dct2) + VVC_ITX_COMMON(DCT8, dct8) + VVC_ITX_COMMON(DST7, dst7) + +#undef VVC_ITX +#undef VVC_ITX_COMMON +}