From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 70345479CD for ; Tue, 28 Nov 2023 04:42:52 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0574C68CF94; Tue, 28 Nov 2023 06:42:49 +0200 (EET) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E83DB68CA50 for ; Tue, 28 Nov 2023 06:42:41 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701146567; x=1732682567; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=sd1Zf5/G5bz23BqJ+UiEFE6vqHh1OYRQel3W+9/6eM8=; b=Rt9H3h3UlYwGuu2w2JX8pf2ePI/FP/GUMS71e20e351vegPeZFV5MydP c91Gb8xus/6FscQ7qh3yMWQrDrYpcVvsyvxc5X0V8lnAXv4FKYUGNkZlx 13LWfMSgav4EssJhdfyAYMhcK0PGikX/pHblS0Aaij9cJ7J1lG1uIuocu UZGS+6k7ETZMAUOfV6lXmCgsjfEkl/+8RHlt46iVPltAy2YVCgsVOjOTE cmLzNnweYL3rNHriM+0GZcTRj1R4HBBppLsWfZ0cne/GTVY3x7GRSxHF9 e6gNz7E5hUSV7jkJ52eMGfok2TNtmv+3y4L+TFefDaGpZMrOgMOrdzh9l w==; X-IronPort-AV: E=McAfee;i="6600,9927,10907"; a="6103472" X-IronPort-AV: E=Sophos;i="6.04,232,1695711600"; d="scan'208";a="6103472" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Nov 2023 20:42:39 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10907"; a="1015797401" X-IronPort-AV: E=Sophos;i="6.04,232,1695711600"; d="scan'208";a="1015797401" Received: from xhh-dg264.sh.intel.com ([10.238.2.76]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Nov 2023 20:42:36 -0800 From: "Xiang, Haihao" To: ffmpeg-devel@ffmpeg.org Date: Tue, 28 Nov 2023 12:42:25 +0800 Message-Id: <20231128044227.2440476-1-haihao.xiang@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 1/3] lavu/hwcontext_d3d11va: Add option vendor_id 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: Haihao Xiang , Artem Galin Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: From: Artem Galin User may choose the hardware via option vendor_id when multiple hardwares are available. Signed-off-by: Artem Galin Signed-off-by: Haihao Xiang --- libavutil/hwcontext_d3d11va.c | 59 ++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/libavutil/hwcontext_d3d11va.c b/libavutil/hwcontext_d3d11va.c index cc8c97d2b6..2fd3561c88 100644 --- a/libavutil/hwcontext_d3d11va.c +++ b/libavutil/hwcontext_d3d11va.c @@ -552,6 +552,47 @@ static void d3d11va_device_uninit(AVHWDeviceContext *hwdev) } } +static int d3d11va_device_find_adapter_by_vendor_id(AVHWDeviceContext *ctx, uint32_t flags, const char *vendor_id) +{ + HRESULT hr; + IDXGIAdapter *adapter = NULL; + IDXGIFactory2 *factory; + int adapter_id = 0; + long int id = strtol(vendor_id, NULL, 0); + + hr = mCreateDXGIFactory(&IID_IDXGIFactory2, (void **)&factory); + if (FAILED(hr)) { + av_log(ctx, AV_LOG_ERROR, "CreateDXGIFactory returned error\n"); + return -1; + } + + while (IDXGIFactory2_EnumAdapters(factory, adapter_id++, &adapter) != DXGI_ERROR_NOT_FOUND) { + ID3D11Device* device = NULL; + DXGI_ADAPTER_DESC adapter_desc; + + hr = mD3D11CreateDevice(adapter, D3D_DRIVER_TYPE_UNKNOWN, NULL, flags, NULL, 0, D3D11_SDK_VERSION, &device, NULL, NULL); + if (FAILED(hr)) { + av_log(ctx, AV_LOG_DEBUG, "D3D11CreateDevice returned error, try next adapter\n"); + IDXGIAdapter_Release(adapter); + continue; + } + + hr = IDXGIAdapter2_GetDesc(adapter, &adapter_desc); + ID3D11Device_Release(device); + IDXGIAdapter_Release(adapter); + if (FAILED(hr)) { + av_log(ctx, AV_LOG_DEBUG, "IDXGIAdapter2_GetDesc returned error, try next adapter\n"); + continue; + } else if (adapter_desc.VendorId == id) { + IDXGIFactory2_Release(factory); + return adapter_id - 1; + } + } + + IDXGIFactory2_Release(factory); + return -1; +} + static int d3d11va_device_create(AVHWDeviceContext *ctx, const char *device, AVDictionary *opts, int flags) { @@ -563,6 +604,7 @@ static int d3d11va_device_create(AVHWDeviceContext *ctx, const char *device, UINT creationFlags = D3D11_CREATE_DEVICE_VIDEO_SUPPORT; int is_debug = !!av_dict_get(opts, "debug", NULL, 0); int ret; + int adapter = -1; // (On UWP we can't check this.) #if !HAVE_UWP @@ -581,10 +623,25 @@ static int d3d11va_device_create(AVHWDeviceContext *ctx, const char *device, } if (device) { + adapter = atoi(device); + } else { + AVDictionaryEntry *e = av_dict_get(opts, "vendor_id", NULL, 0); + if (e && e->value) { + adapter = d3d11va_device_find_adapter_by_vendor_id(ctx, creationFlags, e->value); + if (adapter < 0) { + av_log(ctx, AV_LOG_ERROR, "Failed to find d3d11va adapter by " + "vendor id %s\n", e->value); + return AVERROR_UNKNOWN; + } + } + } + + if (adapter >= 0) { IDXGIFactory2 *pDXGIFactory; + + av_log(ctx, AV_LOG_VERBOSE, "Selecting d3d11va adapter %d\n", adapter); hr = mCreateDXGIFactory(&IID_IDXGIFactory2, (void **)&pDXGIFactory); if (SUCCEEDED(hr)) { - int adapter = atoi(device); if (FAILED(IDXGIFactory2_EnumAdapters(pDXGIFactory, adapter, &pAdapter))) pAdapter = NULL; IDXGIFactory2_Release(pDXGIFactory); -- 2.34.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".