From patchwork Thu Mar 21 15:27:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Araz Iusubov X-Patchwork-Id: 47292 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:3a4a:b0:1a3:31a3:7958 with SMTP id zu10csp624421pzb; Thu, 21 Mar 2024 08:27:20 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVYnBx79MUoGRu/c62Whjmx1Z1MJMwTM7g2Y4LOExHZpkd/bX5TpIyAzopR7GSEFDpN18b5BoWw9+QlznhvxqQtMztPi/6QYWQkNA== X-Google-Smtp-Source: AGHT+IGYxVvzeBLH47sw5jLZT1qVVEY/yMEqkpdTwOUSjkIsDxSZ8rb6ZD5C64UB+0BEuZAaGL9O X-Received: by 2002:a17:907:9612:b0:a46:aed5:2552 with SMTP id gb18-20020a170907961200b00a46aed52552mr5026364ejc.45.1711034839677; Thu, 21 Mar 2024 08:27:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1711034839; cv=none; d=google.com; s=arc-20160816; b=0qHfqWqg4VdHa+stgvwKhwkW5UokVFelakorNSJOQQXCY4C9oq5ObbupluhPLUkhRj aCQaX0idxGM2LVVW/Xj5ZaVdQ0JCeNiGEghbI4df+kgPGNfsTVZVmWTMOMwGxeSw1wrH ScB/XmgTntWxK8MSy2xNx052srEeDizphGL9pdSNkxy72zn12hhUrZsf8u9H9hnH1+3B jb1iImjQwoAXkAbG2uYNquIlb+68b8aQR0L5ZBe1JtlHh0QrjTE/BJgvDJ0FM50AJ/Bx aUR1aiZbjFcaYZ6OzOGL/xvMBfP+WrFhZT5Q/fsH8kace6BPrYjBzbdxx039O3ZZkaiB M5Gg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=ZKSamEzExkjTb1bgKg8mH6LbJIvXKRydG16FDBtt8rs=; fh=OWLPUf18s9dlUQuxhl6xLimy4NybloePU6lVbhxT1Ck=; b=G0YuSDtBm99lugvIJ/6xNxpj6O/Q2gwdu/i7u8WJW5PdI+s7NtZbZIYVAwNnq/jrxI nkRodGq9w0cTNLHWAmIW/66b165RIZMBh8DbmG6sqKYRXTgeQx/xN2eLzOT+v4LO8CZn yLcz0fl/fo4woJ7ZC8hZvxkjWyylf0KApoXItcR5gEFVqmDTNFZ9dYJMyZNC3RyOTifl c3VwZYosTSTq6g376KRrgWLPph7J6bAebOXJPjJ3x8pVZuxkl7f96Dp3Vlna5EcR0MNK 4x2nI0J40LQaif9NuQSPkfrHdWqB+hjv0ikfODpjK8Y578I99VLdlx35dOJ7FFxjo13r ZEBw==; 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=BnTUordE; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id v5-20020a1709063bc500b00a46a8ba60b9si27538ejf.223.2024.03.21.08.27.19; Thu, 21 Mar 2024 08:27:19 -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=BnTUordE; 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 7787668D55B; Thu, 21 Mar 2024 17:27:16 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4416068D4E2 for ; Thu, 21 Mar 2024 17:27:10 +0200 (EET) Received: by mail-ed1-f44.google.com with SMTP id 4fb4d7f45d1cf-55a179f5fa1so1589907a12.0 for ; Thu, 21 Mar 2024 08:27:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711034829; x=1711639629; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=XKiHX4bneKsSfGYaKcI7/XL45aBBtGdA9hB4uvh/Lbw=; b=BnTUordEEOLMBt9uyyo1shL1VgTJzjZfiGYB+/m6knHi3Ew05hemzCb5KosXFqDrkf 2WeB8myWZYoeRsDUi7aWz2lUh5tGCeJSrArSypRf/jQH3m9tPWAJ9yBru6CH3GQ6bDh6 SW+qsIgnoKxU7T+CWpexnCGPqh4CPjD5NWEH8SKa42xNLfcsJJ7ayZAJcdKdUZNd7uHc 1xOwQm+OZeY8NvEGhGbkNHdZXcW11t/CMdSji7CxBG0XIQuGDmXjyPtZzfVqHFoqGoLA U0slWsMFLrhHqK5PS7Vhe3ytE0jZxdhVS5xuJkRdnBkpk4h/PURxGXSMB+fkvjwRbqWu J2Fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711034829; x=1711639629; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=XKiHX4bneKsSfGYaKcI7/XL45aBBtGdA9hB4uvh/Lbw=; b=NmdKVhLg5iEXVKqvBEy29Gb+ZAGD3aCNxWo1F8Oy6gzdxFMbt3VD9iu7Vf00irDP47 bFfcSbdxHBSZTQW/aXV5IB2+efLBd8cmdQPxzDMJet9Af7+JEKy9+629rC+GjydI1FED hNep7GfcGvd9LiXYKbfI9qcCM89zV6p4x8s2w3kdjBaD8v12UdH8hHVQZ/2sCi5w4THM P7H3BobF4tBk+YEdC/TPcBjOqSgRNdZxw5RojMsDWQ3DQAhgKFN6FvnAGQfvgmzhpd+l iVeBtTJRArVPSQ/5AVq4O4JyMzjekc/Lpe4xybvYzC1Y2DMgxJXF89NGpfgkIOat1gwH 0GSA== X-Gm-Message-State: AOJu0YzUtGK+19cO0wkAW0xmQ1TvmlLIEYr6dcNIbqT5cHvu3QNPnEn0 B82jwwsbc3yw/dWMyxo3zM2Y9EkFdPhrWFsKPC9LARNoTh3RijUvrCe4A+4q9NyJGg== X-Received: by 2002:a17:907:9612:b0:a46:aed5:2552 with SMTP id gb18-20020a170907961200b00a46aed52552mr5025901ejc.45.1711034829161; Thu, 21 Mar 2024 08:27:09 -0700 (PDT) Received: from aiusubov.amd.com ([87.116.135.17]) by smtp.gmail.com with ESMTPSA id f22-20020a17090631d600b00a465fd3977esm26191ejf.143.2024.03.21.08.27.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 08:27:08 -0700 (PDT) From: Araz Iusubov X-Google-Original-From: Araz Iusubov To: ffmpeg-devel@ffmpeg.org Date: Thu, 21 Mar 2024 16:27:03 +0100 Message-ID: <20240321152703.1350-1-Primeadvice@gmail.com> X-Mailer: git-send-email 2.43.0.windows.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] [FFmpeg-devel, v3] avcodec/vaapi_encode: add customized surface alignment 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: Araz Iusubov Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: jHsTF/THTZ2s This commit fixes issues with AMD HEVC encoding. By default AMD hevc encoder asks for the alignment 64x16, while FFMPEG VAAPI has 16x16. Adding support for customized surface size from VASurfaceAttribAlignmentSize in VAAPI version 1.21.0 Signed-off-by: Araz Iusubov --- libavcodec/vaapi_encode.c | 11 +++++++++++ libavutil/hwcontext.h | 7 +++++++ libavutil/hwcontext_vaapi.c | 5 +++++ 3 files changed, 23 insertions(+) diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c index 940f0678a5..2a74db23b1 100644 --- a/libavcodec/vaapi_encode.c +++ b/libavcodec/vaapi_encode.c @@ -2711,6 +2711,17 @@ static av_cold int vaapi_encode_create_recon_frames(AVCodecContext *avctx) av_log(avctx, AV_LOG_DEBUG, "Using %s as format of " "reconstructed frames.\n", av_get_pix_fmt_name(recon_format)); + if (constraints->log2_alignment) { + ctx->surface_width = FFALIGN(avctx->width, + 1 << (constraints->log2_alignment & 0xf)); + ctx->surface_height = FFALIGN(avctx->height, + 1 << ((constraints->log2_alignment & 0xf0) >> 4)); + av_log(avctx, AV_LOG_VERBOSE, "Using customized alignment size " + "[%dx%d].\n", + (1 << (constraints->log2_alignment & 0xf)), + (1 << ((constraints->log2_alignment & 0xf0) >> 4))); + } + if (ctx->surface_width < constraints->min_width || ctx->surface_height < constraints->min_height || ctx->surface_width > constraints->max_width || diff --git a/libavutil/hwcontext.h b/libavutil/hwcontext.h index bac30debae..1eb56aff78 100644 --- a/libavutil/hwcontext.h +++ b/libavutil/hwcontext.h @@ -465,6 +465,13 @@ typedef struct AVHWFramesConstraints { */ int max_width; int max_height; + + /** + * The frame width/height log2 alignment when available + * the lower 4 bits, width; another 4 bits, height + * (Zero is not applied, use the default value) + */ + int log2_alignment; } AVHWFramesConstraints; /** diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c index 56d03aa4cd..6cda0fd811 100644 --- a/libavutil/hwcontext_vaapi.c +++ b/libavutil/hwcontext_vaapi.c @@ -294,6 +294,11 @@ static int vaapi_frames_get_constraints(AVHWDeviceContext *hwdev, case VASurfaceAttribMaxHeight: constraints->max_height = attr_list[i].value.value.i; break; +#if VA_CHECK_VERSION(1, 21, 0) + case VASurfaceAttribAlignmentSize: + constraints->log2_alignment = attr_list[i].value.value.i; + break; +#endif } } if (pix_fmt_count == 0) {