From patchwork Wed Mar 6 23:55:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Araz Iusubov X-Patchwork-Id: 46861 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:d90e:b0:19e:cdac:8cce with SMTP id jd14csp716803pzb; Wed, 6 Mar 2024 15:55:39 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUmBGenOm/LNOAWgnH4O7kf17olCdWcrfi5pfXH+X68OOshgk4wO4uobkOm/76///J+Kv09deHJE09KPEs9wJm4d/WRgSiTuWpDPQ== X-Google-Smtp-Source: AGHT+IEvsu2L2WBUNZJboJZ1t4G8z10Nkxf0YQGyK3OtbLXQWpx02wPW7bkG6Po3u+T7H3+t+fQ3 X-Received: by 2002:a50:cd12:0:b0:565:76b6:9206 with SMTP id z18-20020a50cd12000000b0056576b69206mr11296439edi.10.1709769338974; Wed, 06 Mar 2024 15:55:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1709769338; cv=none; d=google.com; s=arc-20160816; b=erDC8KVfm9MtiJcnI9fA+p8JOocWucH+5Kp/OO2wVuDuSnPpiSNV1HCe8g3uYKCp+N 7WbDi/hzayiQtXsxJt9qUAprctJQNi5LkbUv3HlIv0Pe5OlG4mqFuC7lvl9DZcLSlKdz IJZOCz8XpeQ5cph1sEMVw04zjYtjsZ62G6oYzFqxHtVepOiYyI0/NNF6N1PsYgZ/8viX zBfV4t5/kA8u/fgM37JsvQxXVbLw8s53JMRxxS2977J5L3xonhlnexCF7rh10lQJd2uv CAknQKq8oMgd+2pJZmkV0+z69sbhj4S0yorfNRaOarZLTLx0XzpXEuDlC0wbm9N18drw c3jg== 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=dGuddcFa4fMu+1GT9uucemUJdESt3REse/hW31naCCI=; fh=OWLPUf18s9dlUQuxhl6xLimy4NybloePU6lVbhxT1Ck=; b=A7b2ieP4ioC5wytywMdz5QUr0RlwhG1UgaAee9Eh8xs28in3VhhucPDFgapnV+V+G+ hf+n+E8akHPglVe1KnaDSHAQBzmGlaxgg1bTmW/IFd3QVaNSAP+xM3lB8fd9VN9J0SvB lxZA7nta6u3Opdqil1a6aRNnYXIrvPeKl3Ye4yEGz0St45qZRYgNlRYCGBEiw5h0resI yuCoVZN9J17CbcTM2MTLc8i4vkOjswKc/sxufNCTALhnjWykKNHb1PGu1p8YCNP+2V6u tYCThtF0qq1QgSDH0r4nbySXgSioDx+KkTkK31zOjoybiwhh14JrJ5hng/htOTDkrkxR WzWg==; 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=WrG7QUCc; 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 z22-20020a50cd16000000b00563ea13eaf1si6277710edi.400.2024.03.06.15.55.38; Wed, 06 Mar 2024 15:55:38 -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=@gmail.com header.s=20230601 header.b=WrG7QUCc; 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 9C99668CCFC; Thu, 7 Mar 2024 01:55:35 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DBFBB68CC9F for ; Thu, 7 Mar 2024 01:55:28 +0200 (EET) Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-567fbbd7658so264100a12.2 for ; Wed, 06 Mar 2024 15:55:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709769328; x=1710374128; 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=mZevvpJmo1d7wEil50wkusAriHft7o0dk7tExzBp2Q8=; b=WrG7QUCckDrj7IkJhlDsY3GwpdTVOKQOkvzl5sXK4LpUUCPWrICTzzO0LxsGwXzfES I6eadCeL2woYS6dS/+tPgJG8NwGU0wD9KV0uYK9Cu0amQoDiEVlSMlrWHmRXu240lT+1 RHBS+DN+ZQm0m8gAO2O4js7gEJSZ+oyLYZg199DJWlkzEAaNxEBtQ+qB9pgsFETWzSx2 Ve1GCRgAx845oMgHsjTadSGAqQsrhtM1g6F9ld1uV39/Gn7Z6xmtAskbReEcEOH5KSnF k/OO1VDQgB3metseg3InBOH/O67Kv+vnwXB8rCM942/5fTP+iSi6xH+BZgOkELHsgUfB Zn9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709769328; x=1710374128; 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=mZevvpJmo1d7wEil50wkusAriHft7o0dk7tExzBp2Q8=; b=qTv5YN0KBYMqdQb3twxkqsq674xd7u29rpZmcMNZEtCUdSMp8hhSL3c5lo7p3JTecc KktygpPaFutqy+D2UpmSQswlatXMFOvW+Hm9tjNmXnQVU0Y9vcKocSUxVyKw8ToHYvs9 UrEbtA0CirRaoWR2XDCM0VlRPeXI6iKD4DDCqZ7aE0DkO2duJ02FzVADa10HJVPRSa6l dgx+cjRwNhty3vVBXI8P3+YObaMMn3fzss96NouiwpF9/Sb37qHdkpN32LdJs4miZgDE n+upKVioK8cSk96BTRgSEXCOx11n+4KycjGF11KKMhmzVrXyDmxZ9Zoa6nc1nW5r8159 ajlQ== X-Gm-Message-State: AOJu0Yz4I9/w+nVilUozO0Kin/0IvAVT5mvhsfvW7yys0Kl04sAOKLnh 0YmVvW55DvBe5wEZNL3m3sGh17t9B5cKs1hcK8HB5LYMeSexzZXrOJv4C6c8m7V8tA== X-Received: by 2002:a05:6402:2151:b0:566:6a0e:7625 with SMTP id bq17-20020a056402215100b005666a0e7625mr11095237edb.7.1709769327830; Wed, 06 Mar 2024 15:55:27 -0800 (PST) Received: from aiusubov.amd.com ([87.116.135.17]) by smtp.gmail.com with ESMTPSA id q22-20020a50aa96000000b00564e489ce9asm7788139edc.12.2024.03.06.15.55.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 15:55:27 -0800 (PST) From: Araz Iusubov X-Google-Original-From: Araz Iusubov To: ffmpeg-devel@ffmpeg.org Date: Thu, 7 Mar 2024 00:55:22 +0100 Message-ID: <20240306235522.2669-1-Primeadvice@gmail.com> X-Mailer: git-send-email 2.43.0.windows.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] 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: Kl/Ugm+L9AGn 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 customzied surface size from VASurfaceAttribAlignmentSize in VAAPI version 1.21.0. To: Primeadvice@gmail.com 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 808b79c0c7..dc1b7465b7 100644 --- a/libavcodec/vaapi_encode.c +++ b/libavcodec/vaapi_encode.c @@ -2700,6 +2700,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 df7733fe5e..5725245be4 100644 --- a/libavutil/hwcontext.h +++ b/libavutil/hwcontext.h @@ -481,6 +481,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 2c75f5f5b1..161623bc27 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) {