From patchwork Thu Mar 21 17:02:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Araz Iusubov X-Patchwork-Id: 47294 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:3a4a:b0:1a3:31a3:7958 with SMTP id zu10csp684759pzb; Thu, 21 Mar 2024 10:03:09 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCX9uscFvP1eHtVMtaEJwAFtUb2XVjJBdRebN98DxVraTJz2ti1RT3onr5oLFRl4VI5kMVZOKsCkEt6gv31yJylCpT+S5w0hbap7nA== X-Google-Smtp-Source: AGHT+IEjXmMkwkuVXeag92rCTP5Rzf5ilm9SHZY3r+B2mq1Sg8l9EQhp49QLTQCnTZ6xuA9OD9Aa X-Received: by 2002:ac2:5f9c:0:b0:512:b0a7:2943 with SMTP id r28-20020ac25f9c000000b00512b0a72943mr6175716lfe.5.1711040589015; Thu, 21 Mar 2024 10:03:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1711040588; cv=none; d=google.com; s=arc-20160816; b=WIkZUP0eIUCpQb+DroUFpLaDVUxJRX3qV2EUKZDuBLQrvLBUhrQJ5qkYA6WGHa0HWQ kPECtKNI0UTk+UjSLk5gDUHoFZhYjq5IlOMHTTtx6rOMQWWpFBiD2HMmaXkrgZYqdzEm WQ1szuqUnduAcSLaKdpKeKqDvXZFouAVolGxMm98L7KI+GMMcJdiyVDjUfliYletxIYN i3W718BKO69ouks+VMlCNkQa1Lb7GVhCS6VB7S4L1ndca4aYAv2hdpOpbrAnhg9NyWWs zkn4Wu6XQ6vsUFkWn2/7To8A6vFQfoUaBbKqRKIV1ubwNOV+cgIjhVlAnUY6u62q/EoB NA5w== 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=MAKnyskxorhDx5FJTBEncYOzofowOeoh4+5emQPdBBgLdzizSdkEJTWQ3RDfF2uVUu UdWr5qjtLldMRr64o6V3qYyVQ3Qn9Fuggeg7uH02j5DHD096b31AOjrEogjj/pEHHkNs JR6uTQl2UVSu9E6A20NNLeAV9mJxtvB0jdiC8urxLWolNlArMA92JWFyblCECsI91rfz EvzQnDQ5yfwFs/6FmEERrjXHcSMg0dMprI+j5tIdBST1ihhkXxf7yG2uUpaaaKWz+vq4 2tfPIJiW04tK/0VxsAKgshmoceFgqHA+61nGS6uxck8uuHQXrRrmPXWt6fJfCUhQOR7q +3ig==; 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=aaotH54r; 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 d26-20020a0565123d1a00b005158b2d7a42si16699lfv.84.2024.03.21.10.03.08; Thu, 21 Mar 2024 10:03:08 -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=aaotH54r; 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 E3F7068D565; Thu, 21 Mar 2024 19:03:02 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1C4A668D4CF for ; Thu, 21 Mar 2024 19:02:56 +0200 (EET) Received: by mail-ed1-f45.google.com with SMTP id 4fb4d7f45d1cf-56845954ffeso1554099a12.2 for ; Thu, 21 Mar 2024 10:02:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711040575; x=1711645375; 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=aaotH54rPBAFmQvCUXRK/wG0IsvfYdCgy4hYglIMYvbTdE6UY4rRd2PErGH5ebOHV2 ezUElFN/Cki/fCkCd5EIZRkqt3Vdu82ddzSsVsK9wE2waIkOSnyIlUfv7DtVsDf+sIBl V6IhWp6+R8PWdntLupGBvq6PZ1Ok98XIYENwrrnrRx5gM+jFa0/z49IDG5hvEOV0dmfG AHKPyT7Uc++hr1HpttHykfpLC9JIj4yVygAB4RjOyXyuAUqhCC4hAxaYmNvkE9M4lHpS qHWJlEvi7j1g3vmjprSLx3YEAM4/IhQafoUYCEV2SYt97ZNnDlUCTLnl1vOCYy10iBws y4jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711040575; x=1711645375; 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=XwXnDDnhwnQMsGcP9+9i+JWoFBzWwwA6PqqPDFMNBRMSm/lJAItwkKoZio23RJnOpM h4G0pvEjUVeY8IfgLsYmpNS4KX+LPLy1tb9AmCU2W3yjNhI8JUIBoWF+B2RLzHBxhaxl YXmqbO9jlz/WEfjKUBCWrJmrV6/LoE29GGYzvbhdVF8vhF1bjGZeIveXb5/95mQYAbTc oAqsTuj9acynjVgusd0fHjWWdXwWmbA1efiRGkiZr3MiMDzqIr6oMuTeJwALugM8hS9u p534l1YBer5J+xgjhAu+oxHeElX3ke6+k7l5XQkZA0rVTpCP7v/vu82RQuVl33PD/Bbd WSSw== X-Gm-Message-State: AOJu0YxZfh8gE9ek/ejfqU5WYUS/zuCcUZecQxI4/K6vpWZPGIcgUPgx WqElzwSdNYrNhzxjFrPWYiR48c0DL6jYtj3g9oB0MAoneSSViE017+Egb83C5VwW2w== X-Received: by 2002:a17:906:6958:b0:a46:a662:e567 with SMTP id c24-20020a170906695800b00a46a662e567mr15643ejs.3.1711040575091; Thu, 21 Mar 2024 10:02:55 -0700 (PDT) Received: from aiusubov.amd.com ([87.116.135.17]) by smtp.gmail.com with ESMTPSA id q4-20020a1709060e4400b00a46d001a259sm113524eji.52.2024.03.21.10.02.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 10:02:54 -0700 (PDT) From: Araz Iusubov X-Google-Original-From: Araz Iusubov To: ffmpeg-devel@ffmpeg.org Date: Thu, 21 Mar 2024 18:02:19 +0100 Message-ID: <20240321170219.1487-1-Primeadvice@gmail.com> X-Mailer: git-send-email 2.43.0.windows.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] [v4] 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: Hqo1CgwQzvgJ 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) {