From patchwork Tue Jul 16 17:03:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitrii Ovchinnikov X-Patchwork-Id: 13972 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 14C16449BF6 for ; Tue, 16 Jul 2019 20:11:00 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DD64368AE4A; Tue, 16 Jul 2019 20:10:59 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CD05768ADEE for ; Tue, 16 Jul 2019 20:10:53 +0300 (EEST) Received: by mail-lf1-f52.google.com with SMTP id 62so9403430lfa.8 for ; Tue, 16 Jul 2019 10:10:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=51bdyOkeYb/6ZZJlflQX7xG6AtwLuhLHxmK7mey0C5E=; b=cw5kETieed6L0gTBJhWlXjoXQSHPAtjdSPvWkgYxZuYQOSq8T+ynC3muQIsCoBWUbw Affe8qYcZcPB7E+gHn+VvJEJTSpRK2JOCkvOq9/iUVd3u8SvFqqtxDc4bIIZ7eCcRnYI 5eBsNoofVQGzrSIGqQhttcHix9Xgh+yigwn/pG5cvn1xZ0ou98OoBFigV/wRKDctSfyY v0cD0GFpjTypZDjG3pC/StNXQp2hDrZFn1VZNfRn9MViY3LjyDOZkyUiEpK3xMweBSrd J0RLPUuXcPhSd40fjCk3ppr4aM+8yLb9GXI+3CgMoYm4VEWDW8gyMh4jsMTbLTNtlXst k5kQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=51bdyOkeYb/6ZZJlflQX7xG6AtwLuhLHxmK7mey0C5E=; b=r5SJfWlRA8vMfx3565nKPiXN8rnfayZ0Y53KCYthBTg1lMQbGp6IMXzrIy8NuwIspp VQL0Q/dxbnvS7ecFvTSAEAOZ3Td2i5OmVMlA+/2F/q0lM8GbrFo/Mbi8xFol7xwD7Uu1 BytovPgiKIM/iei/NQUYBtKQxYfqBCPgiVKGY/tAeYkZi5nhTytySdyxWXWmQhbMBgTX I5twIdtpQYsXBH1trDO5VBZ5HmMi85yZf3DtM5OcQGfYPx4XGbT9XJkaxcJpB95ZcaC8 yddQEquPCpWisJ8doVj3Z/5pVpHN4yEogsudTpCZNfgWIU3NLjWu5eHxTknKrf9iEC08 M67Q== X-Gm-Message-State: APjAAAXWVlMMvdaM7APnDCzqu3YbfA1X4LZdJJvYv9lfr0biaMlNg/qH TArnjG+oeQL8EGAkeGn9X+1pXPHBnqY= X-Google-Smtp-Source: APXvYqwAQJsYmWlyiCDj/zD3wsIZWjFWltMQ/+6Ghu8VAfQA+vh2THpxhEq44xBW75oQCr5bMcnQgg== X-Received: by 2002:a19:5d53:: with SMTP id p19mr12808596lfj.109.1563296602421; Tue, 16 Jul 2019 10:03:22 -0700 (PDT) Received: from localhost.localdomain (ppp78-37-151-45.pppoe.avangarddsl.ru. [78.37.151.45]) by smtp.googlemail.com with ESMTPSA id o187sm2885736lfa.88.2019.07.16.10.03.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Jul 2019 10:03:21 -0700 (PDT) From: OvchinnikovDmitrii To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Jul 2019 20:03:11 +0300 Message-Id: <20190716170311.18704-1-ovchinnikov.dmitrii@gmail.com> X-Mailer: git-send-email 2.19.1.windows.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2] libavcodec/amfenc: Vulkan initialization support for encoder. X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: OvchinnikovDmitrii Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Added linux support for amf encoder through vulkan. To use h.264(AMD VCE) encoder on linux amdgru-pro version 19.20+ and amf-amdgpu-pro package(amdgru-pro contains, but does not install automatically) are required. This driver can be installed using amdgpu-pro-install script in official amd driver archive. Initialization of amf encoder occurs in this order: 1) trying to initialize through dx11(only windows) 2) trying to initialize through dx9(only windows) 3) trying to initialize through vulkan Only Vulkan initialization available on linux. --- doc/general.texi | 16 +++++++++++++--- libavcodec/amfenc.c | 17 +++++++++++++++-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/doc/general.texi b/doc/general.texi index 3c0c803449..056f88fba3 100644 --- a/doc/general.texi +++ b/doc/general.texi @@ -27,16 +27,26 @@ enable it. @section AMD AMF/VCE -FFmpeg can use the AMD Advanced Media Framework library under Windows -for accelerated H.264 and HEVC encoding on hardware with Video Coding Engine (VCE). +FFmpeg can use the AMD Advanced Media Framework library +for accelerated H.264 and HEVC(only windows) encoding on hardware with Video Coding Engine (VCE). -To enable support you must obtain the AMF framework header files from +To enable support you must obtain the AMF framework header files(version 1.4.9+) from @url{https://github.com/GPUOpen-LibrariesAndSDKs/AMF.git}. Create an @code{AMF/} directory in the system include path. Copy the contents of @code{AMF/amf/public/include/} into that directory. Then configure FFmpeg with @code{--enable-amf}. +Initialization of amf encoder occurs in this order: +1) trying to initialize through dx11(only windows) +2) trying to initialize through dx9(only windows) +3) trying to initialize through vulkan + +To use h.264(AMD VCE) encoder on linux amdgru-pro version 19.20+ and amf-amdgpu-pro +package(amdgru-pro contains, but does not install automatically) are required. + +This driver can be installed using amdgpu-pro-install script in official amd driver archive. + @section AviSynth FFmpeg can read AviSynth scripts as input. To enable support, pass diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c index 384d8efc92..f66b95645e 100644 --- a/libavcodec/amfenc.c +++ b/libavcodec/amfenc.c @@ -213,6 +213,7 @@ static int amf_init_from_dxva2_device(AVCodecContext *avctx, AVDXVA2DeviceContex static int amf_init_context(AVCodecContext *avctx) { AmfContext *ctx = avctx->priv_data; + AMFContext1 *context1 = NULL; AMF_RESULT res; av_unused int ret; @@ -311,8 +312,20 @@ static int amf_init_context(AVCodecContext *avctx) if (res == AMF_OK) { av_log(avctx, AV_LOG_VERBOSE, "AMF initialisation succeeded via D3D9.\n"); } else { - av_log(avctx, AV_LOG_ERROR, "AMF initialisation failed via D3D9: error %d.\n", res); - return AVERROR(ENOSYS); + AMFGuid guid = IID_AMFContext1(); + res = ctx->context->pVtbl->QueryInterface(ctx->context, &guid, (void**)&context1); + AMF_RETURN_IF_FALSE(ctx, res == AMF_OK, AVERROR_UNKNOWN, "CreateContext1() failed with error %d\n", res); + + res = context1->pVtbl->InitVulkan(context1, NULL); + context1->pVtbl->Release(context1); + if (res != AMF_OK) { + if (res == AMF_NOT_SUPPORTED) + av_log(avctx, AV_LOG_ERROR, "AMF via Vulkan is not supported on the given device.\n"); + else + av_log(avctx, AV_LOG_ERROR, "AMF failed to initialise on the given Vulkan device: %d.\n", res); + return AVERROR(ENOSYS); + } + av_log(avctx, AV_LOG_VERBOSE, "AMF initialisation succeeded via Vulkan.\n"); } } }