From patchwork Thu Aug 8 18:33:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitrii Ovchinnikov X-Patchwork-Id: 14319 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 5A9CE44A450 for ; Thu, 8 Aug 2019 21:40:28 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 380B468A89E; Thu, 8 Aug 2019 21:40:28 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5302968A101 for ; Thu, 8 Aug 2019 21:40:22 +0300 (EEST) Received: by mail-lf1-f41.google.com with SMTP id z15so63325687lfh.13 for ; Thu, 08 Aug 2019 11:40:22 -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=fKnCaZKbVuMfj1MyknVlFodxPjclgGrf7HhfHKZ0himlYPkOEa8QotlRaBEqFUNbOm k0TKAWgtBpXJ3BwUnQCmSegH3JhPvt5fmtbx4Kt7IzCDQVOf7z6j1CWvBj98UpBqsxxF /52NJwl121Lo9ox0IXxQX9TvvVqbx0nB/C3fnTdaQ2xKXmGy3/ioSkzNLV6cS8X2lWVl w1Je+JzYW6w/zt1JEyxxayqbSwTlzS5e1Xnpm2aWmfRGcezv362Ai+aODN3auhrEKym2 SF5kwMkt0oGkemN5OJ25cSB3+IYVUaoMLnsvp/CIoRb3Ma+/x5MCJJRwfTzoBwof3u1K C+1Q== 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=Qhk5we9Ew3hbRKmLIivEh9KyezlRzAMsam3apLmqQqW/JTvczHef3MjseoiR4isqGF /jm8af+I42a/fJh0cdm7fJT1+kDtZIPm+5Y5FCMtTOKblgDL/IFbt2iFmdbdXoGDWYAD nTqYidGSNuUcOrcOdQkZCNyhbrgytCce9mx4zJI9lpVLm5R4iJiyN1KL8VmhcLZJKID8 R5h+WKbVmjtMCmO8XSNj68upovYe5En9kKHVz2/GdKWe33yZJQHIGwZaXhLjYx6nQUyk xXRZpVYvw+UH6ysmRNKucGoSrtdQEm8ehDq8RMG6pX9ncmnZq3zLCoyOIo5YAWc7L8dc 0iaA== X-Gm-Message-State: APjAAAVYfgrkKNTmXEZ6uc+85H/z33ARi1cBBvQXlbCD8V+DHpGoYSII lW1YaoTjC1dl7Ejkc1Ahnk0DkfUXdr8= X-Google-Smtp-Source: APXvYqy2sHq4V2MR8kfNn3qHkOylijs4LX5tCN5gdiCMcYApOfjGHSrg9Azzg+wjgRVO/1JEQGe3/w== X-Received: by 2002:ac2:4824:: with SMTP id 4mr1712090lft.161.1565289220062; Thu, 08 Aug 2019 11:33:40 -0700 (PDT) Received: from localhost.localdomain (ppp78-37-142-132.pppoe.avangarddsl.ru. [78.37.142.132]) by smtp.googlemail.com with ESMTPSA id p12sm19048813lja.23.2019.08.08.11.33.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Aug 2019 11:33:39 -0700 (PDT) From: OvchinnikovDmitrii To: ffmpeg-devel@ffmpeg.org Date: Thu, 8 Aug 2019 21:33:25 +0300 Message-Id: <20190808183325.22116-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"); } } }