Created
February 18, 2017 22:41
-
-
Save jmorrill/af856d0aa3cdcc6f6264b0e4fa089fd9 to your computer and use it in GitHub Desktop.
Patch for ffmpeg 3.2.4 for higher perf dxva (in things like wpf)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From e0eb0152371327a54bf6cf209a600bb21896e34e Mon Sep 17 00:00:00 2001 | |
From: Jeremiah Morrill <[email protected]> | |
Date: Wed, 25 Jan 2017 22:04:15 -0800 | |
Subject: [PATCH 107/107] Chose to create IDirect3DDevice9Ex if available | |
--- | |
libavutil/hwcontext_dxva2.c | 46 ++++++++++++++++++++++++++++++++++++--------- | |
1 file changed, 37 insertions(+), 9 deletions(-) | |
diff --git a/libavutil/hwcontext_dxva2.c b/libavutil/hwcontext_dxva2.c | |
index e79254b..3d85cc6 100644 | |
--- a/libavutil/hwcontext_dxva2.c | |
+++ b/libavutil/hwcontext_dxva2.c | |
@@ -39,6 +39,7 @@ | |
#include "pixfmt.h" | |
typedef IDirect3D9* WINAPI pDirect3DCreate9(UINT); | |
+typedef HRESULT WINAPI pDirect3DCreate9Ex(UINT, IDirect3D9Ex **); | |
typedef HRESULT WINAPI pCreateDeviceManager9(UINT *, IDirect3DDeviceManager9 **); | |
typedef struct DXVA2FramesContext { | |
@@ -333,6 +334,7 @@ static int dxva2_device_create(AVHWDeviceContext *ctx, const char *device, | |
DXVA2DevicePriv *priv; | |
pDirect3DCreate9 *createD3D = NULL; | |
+ pDirect3DCreate9Ex *createD3DEx = NULL; | |
pCreateDeviceManager9 *createDeviceManager = NULL; | |
D3DPRESENT_PARAMETERS d3dpp = {0}; | |
D3DDISPLAYMODE d3ddm; | |
@@ -364,8 +366,9 @@ static int dxva2_device_create(AVHWDeviceContext *ctx, const char *device, | |
} | |
createD3D = (pDirect3DCreate9 *)GetProcAddress(priv->d3dlib, "Direct3DCreate9"); | |
- if (!createD3D) { | |
- av_log(ctx, AV_LOG_ERROR, "Failed to locate Direct3DCreate9\n"); | |
+ createD3DEx = (pDirect3DCreate9Ex *)GetProcAddress(priv->d3dlib, "Direct3DCreate9Ex"); | |
+ if (!createD3D && !createD3DEx) { | |
+ av_log(ctx, AV_LOG_ERROR, "Failed to locate Direct3DCreate9 or Direct3DCreate9Ex\n"); | |
return AVERROR_UNKNOWN; | |
} | |
createDeviceManager = (pCreateDeviceManager9 *)GetProcAddress(priv->dxva2lib, | |
@@ -375,10 +378,23 @@ static int dxva2_device_create(AVHWDeviceContext *ctx, const char *device, | |
return AVERROR_UNKNOWN; | |
} | |
- priv->d3d9 = createD3D(D3D_SDK_VERSION); | |
- if (!priv->d3d9) { | |
- av_log(ctx, AV_LOG_ERROR, "Failed to create IDirect3D object\n"); | |
- return AVERROR_UNKNOWN; | |
+ if (createD3DEx) { | |
+ IDirect3D9Ex* d3d9Ex = NULL; | |
+ | |
+ hr = createD3DEx(D3D_SDK_VERSION, &d3d9Ex); | |
+ if (FAILED(hr)) { | |
+ av_log(ctx, AV_LOG_ERROR, "Failed to create IDirect3D9Ex object\n"); | |
+ return AVERROR_UNKNOWN; | |
+ } | |
+ | |
+ priv->d3d9 = d3d9Ex; | |
+ } else { | |
+ priv->d3d9 = createD3D(D3D_SDK_VERSION); | |
+ | |
+ if (!priv->d3d9) { | |
+ av_log(ctx, AV_LOG_ERROR, "Failed to create IDirect3D9 object\n"); | |
+ return AVERROR_UNKNOWN; | |
+ } | |
} | |
IDirect3D9_GetAdapterDisplayMode(priv->d3d9, adapter, &d3ddm); | |
@@ -390,9 +406,21 @@ static int dxva2_device_create(AVHWDeviceContext *ctx, const char *device, | |
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; | |
d3dpp.Flags = D3DPRESENTFLAG_VIDEO; | |
- hr = IDirect3D9_CreateDevice(priv->d3d9, adapter, D3DDEVTYPE_HAL, GetDesktopWindow(), | |
- D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED | D3DCREATE_FPU_PRESERVE, | |
- &d3dpp, &priv->d3d9device); | |
+ if (createD3DEx) | |
+ { | |
+ IDirect3D9Ex *d3d9Ex = priv->d3d9; | |
+ IDirect3DDevice9Ex *d3d9deviceEx = NULL; | |
+ | |
+ hr = IDirect3D9Ex_CreateDeviceEx(d3d9Ex, adapter, D3DDEVTYPE_HAL, GetDesktopWindow(), | |
+ D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED | D3DCREATE_FPU_PRESERVE, | |
+ &d3dpp, NULL, &d3d9deviceEx); | |
+ priv->d3d9device = d3d9deviceEx; | |
+ } else { | |
+ hr = IDirect3D9_CreateDevice(priv->d3d9, adapter, D3DDEVTYPE_HAL, GetDesktopWindow(), | |
+ D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED | D3DCREATE_FPU_PRESERVE, | |
+ &d3dpp, &priv->d3d9device); | |
+ } | |
+ | |
if (FAILED(hr)) { | |
av_log(ctx, AV_LOG_ERROR, "Failed to create Direct3D device\n"); | |
return AVERROR_UNKNOWN; | |
-- | |
2.10.1.windows.1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment