d3d11va: Check WINAPI_FAMILY instead of HAVE_LOADLIBRARY

Message ID 1499195901-18196-1-git-send-email-martin@martin.st
State Superseded
Headers show

Commit Message

Martin Storsjö July 4, 2017, 7:18 p.m.
If using the winstore compat library, a fallback LoadLibrary
function does exist, that only calls LoadPackagedLibrary though
(which doesn't work for dynamically loading d3d11 DLLs).

Therefore explicitly check the targeted API family instead.
---
 configure                     |  9 ++++++++-
 libavutil/hwcontext_d3d11va.c | 13 ++++++++++---
 2 files changed, 18 insertions(+), 4 deletions(-)

Comments

Luca Barbato July 4, 2017, 7:35 p.m. | #1
On 7/4/17 9:18 PM, Martin Storsjö wrote:
> If using the winstore compat library, a fallback LoadLibrary
> function does exist, that only calls LoadPackagedLibrary though
> (which doesn't work for dynamically loading d3d11 DLLs).
> 
> Therefore explicitly check the targeted API family instead.
> ---
>  configure                     |  9 ++++++++-
>  libavutil/hwcontext_d3d11va.c | 13 ++++++++++---
>  2 files changed, 18 insertions(+), 4 deletions(-)
> 

Seems ok.
wm4 July 4, 2017, 7:56 p.m. | #2
On Tue,  4 Jul 2017 22:18:21 +0300
Martin Storsjö <martin@martin.st> wrote:

> If using the winstore compat library, a fallback LoadLibrary
> function does exist, that only calls LoadPackagedLibrary though
> (which doesn't work for dynamically loading d3d11 DLLs).
> 
> Therefore explicitly check the targeted API family instead.
> ---
>  configure                     |  9 ++++++++-
>  libavutil/hwcontext_d3d11va.c | 13 ++++++++++---
>  2 files changed, 18 insertions(+), 4 deletions(-)
> 
> diff --git a/configure b/configure
> index 96bc5ab..ce81d3b 100755
> --- a/configure
> +++ b/configure
> @@ -4894,7 +4894,14 @@ fi
>  
>  # d3d11va requires linking directly to dxgi and d3d11 if not building for
>  # the desktop api partition
> -enabled LoadLibrary || d3d11va_extralibs="-ldxgi -ld3d11"
> +check_cpp <<EOF || d3d11va_extralibs="-ldxgi -ld3d11"
> +#ifdef WINAPI_FAMILY
> +#include <winapifamily.h>
> +#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
> +#error not desktop
> +#endif
> +#endif
> +EOF
>  
>  enabled vaapi && require vaapi va/va.h vaInitialize -lva
>  
> diff --git a/libavutil/hwcontext_d3d11va.c b/libavutil/hwcontext_d3d11va.c
> index 75f78d8..4d21b57 100644
> --- a/libavutil/hwcontext_d3d11va.c
> +++ b/libavutil/hwcontext_d3d11va.c
> @@ -47,6 +47,13 @@
>  #include "pixdesc.h"
>  #include "pixfmt.h"
>  
> +#ifdef WINAPI_FAMILY
> +#include <winapifamily.h>
> +#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
> +#define UWP
> +#endif
> +#endif
> +
>  typedef HRESULT(WINAPI *PFN_CREATE_DXGI_FACTORY)(REFIID riid, void **ppFactory);
>  
>  static AVOnce functions_loaded = AV_ONCE_INIT;
> @@ -56,7 +63,7 @@ static PFN_D3D11_CREATE_DEVICE mD3D11CreateDevice;
>  
>  static av_cold void load_functions(void)
>  {
> -#if HAVE_LOADLIBRARY
> +#ifndef UWP
>      // We let these "leak" - this is fine, as unloading has no great benefit, and
>      // Windows will mark a DLL as loaded forever if its internal refcount overflows
>      // from too many LoadLibrary calls.
> @@ -486,7 +493,7 @@ static int d3d11va_device_create(AVHWDeviceContext *ctx, const char *device,
>      int ret;
>  
>      // (On UWP we can't check this.)
> -#if HAVE_LOADLIBRARY
> +#ifndef UWP
>      if (!LoadLibrary("d3d11_1sdklayers.dll"))
>          is_debug = 0;
>  #endif
> @@ -527,7 +534,7 @@ static int d3d11va_device_create(AVHWDeviceContext *ctx, const char *device,
>          ID3D10Multithread_Release(pMultithread);
>      }
>  
> -#if HAVE_LOADLIBRARY && HAVE_DXGIDEBUG_H
> +#if !defined(UWP) && HAVE_DXGIDEBUG_H
>      if (is_debug) {
>          HANDLE dxgidebug_dll = LoadLibrary("dxgidebug.dll");
>          if (dxgidebug_dll) {

LGTM... though isn't "UWP" a bit too generic as an identifier?
Martin Storsjö July 4, 2017, 7:57 p.m. | #3
On Tue, 4 Jul 2017, wm4 wrote:

> On Tue,  4 Jul 2017 22:18:21 +0300
> Martin Storsjö <martin@martin.st> wrote:
>
>> If using the winstore compat library, a fallback LoadLibrary
>> function does exist, that only calls LoadPackagedLibrary though
>> (which doesn't work for dynamically loading d3d11 DLLs).
>> 
>> Therefore explicitly check the targeted API family instead.
>> ---
>>  configure                     |  9 ++++++++-
>>  libavutil/hwcontext_d3d11va.c | 13 ++++++++++---
>>  2 files changed, 18 insertions(+), 4 deletions(-)
>> 
>> diff --git a/configure b/configure
>> index 96bc5ab..ce81d3b 100755
>> --- a/configure
>> +++ b/configure
>> @@ -4894,7 +4894,14 @@ fi
>>
>>  # d3d11va requires linking directly to dxgi and d3d11 if not building for
>>  # the desktop api partition
>> -enabled LoadLibrary || d3d11va_extralibs="-ldxgi -ld3d11"
>> +check_cpp <<EOF || d3d11va_extralibs="-ldxgi -ld3d11"
>> +#ifdef WINAPI_FAMILY
>> +#include <winapifamily.h>
>> +#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
>> +#error not desktop
>> +#endif
>> +#endif
>> +EOF
>>
>>  enabled vaapi && require vaapi va/va.h vaInitialize -lva
>> 
>> diff --git a/libavutil/hwcontext_d3d11va.c b/libavutil/hwcontext_d3d11va.c
>> index 75f78d8..4d21b57 100644
>> --- a/libavutil/hwcontext_d3d11va.c
>> +++ b/libavutil/hwcontext_d3d11va.c
>> @@ -47,6 +47,13 @@
>>  #include "pixdesc.h"
>>  #include "pixfmt.h"
>> 
>> +#ifdef WINAPI_FAMILY
>> +#include <winapifamily.h>
>> +#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
>> +#define UWP
>> +#endif
>> +#endif
>> +
>>  typedef HRESULT(WINAPI *PFN_CREATE_DXGI_FACTORY)(REFIID riid, void **ppFactory);
>>
>>  static AVOnce functions_loaded = AV_ONCE_INIT;
>> @@ -56,7 +63,7 @@ static PFN_D3D11_CREATE_DEVICE mD3D11CreateDevice;
>>
>>  static av_cold void load_functions(void)
>>  {
>> -#if HAVE_LOADLIBRARY
>> +#ifndef UWP
>>      // We let these "leak" - this is fine, as unloading has no great benefit, and
>>      // Windows will mark a DLL as loaded forever if its internal refcount overflows
>>      // from too many LoadLibrary calls.
>> @@ -486,7 +493,7 @@ static int d3d11va_device_create(AVHWDeviceContext *ctx, const char *device,
>>      int ret;
>>
>>      // (On UWP we can't check this.)
>> -#if HAVE_LOADLIBRARY
>> +#ifndef UWP
>>      if (!LoadLibrary("d3d11_1sdklayers.dll"))
>>          is_debug = 0;
>>  #endif
>> @@ -527,7 +534,7 @@ static int d3d11va_device_create(AVHWDeviceContext *ctx, const char *device,
>>          ID3D10Multithread_Release(pMultithread);
>>      }
>> 
>> -#if HAVE_LOADLIBRARY && HAVE_DXGIDEBUG_H
>> +#if !defined(UWP) && HAVE_DXGIDEBUG_H
>>      if (is_debug) {
>>          HANDLE dxgidebug_dll = LoadLibrary("dxgidebug.dll");
>>          if (dxgidebug_dll) {
>
> LGTM... though isn't "UWP" a bit too generic as an identifier?

It's a little terse yeah, but it's at least only visible within this file 
(for now). Any better suggestions?

// Martin
wm4 July 4, 2017, 8:04 p.m. | #4
On Tue, 4 Jul 2017 22:57:41 +0300 (EEST)
Martin Storsjö <martin@martin.st> wrote:

> On Tue, 4 Jul 2017, wm4 wrote:
> 
> > On Tue,  4 Jul 2017 22:18:21 +0300
> > Martin Storsjö <martin@martin.st> wrote:
> >  
> >> If using the winstore compat library, a fallback LoadLibrary
> >> function does exist, that only calls LoadPackagedLibrary though
> >> (which doesn't work for dynamically loading d3d11 DLLs).
> >> 
> >> Therefore explicitly check the targeted API family instead.
> >> ---
> >>  configure                     |  9 ++++++++-
> >>  libavutil/hwcontext_d3d11va.c | 13 ++++++++++---
> >>  2 files changed, 18 insertions(+), 4 deletions(-)
> >> 
> >> diff --git a/configure b/configure
> >> index 96bc5ab..ce81d3b 100755
> >> --- a/configure
> >> +++ b/configure
> >> @@ -4894,7 +4894,14 @@ fi
> >>
> >>  # d3d11va requires linking directly to dxgi and d3d11 if not building for
> >>  # the desktop api partition
> >> -enabled LoadLibrary || d3d11va_extralibs="-ldxgi -ld3d11"
> >> +check_cpp <<EOF || d3d11va_extralibs="-ldxgi -ld3d11"
> >> +#ifdef WINAPI_FAMILY
> >> +#include <winapifamily.h>
> >> +#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
> >> +#error not desktop
> >> +#endif
> >> +#endif
> >> +EOF
> >>
> >>  enabled vaapi && require vaapi va/va.h vaInitialize -lva
> >> 
> >> diff --git a/libavutil/hwcontext_d3d11va.c b/libavutil/hwcontext_d3d11va.c
> >> index 75f78d8..4d21b57 100644
> >> --- a/libavutil/hwcontext_d3d11va.c
> >> +++ b/libavutil/hwcontext_d3d11va.c
> >> @@ -47,6 +47,13 @@
> >>  #include "pixdesc.h"
> >>  #include "pixfmt.h"
> >> 
> >> +#ifdef WINAPI_FAMILY
> >> +#include <winapifamily.h>
> >> +#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
> >> +#define UWP
> >> +#endif
> >> +#endif
> >> +
> >>  typedef HRESULT(WINAPI *PFN_CREATE_DXGI_FACTORY)(REFIID riid, void **ppFactory);
> >>
> >>  static AVOnce functions_loaded = AV_ONCE_INIT;
> >> @@ -56,7 +63,7 @@ static PFN_D3D11_CREATE_DEVICE mD3D11CreateDevice;
> >>
> >>  static av_cold void load_functions(void)
> >>  {
> >> -#if HAVE_LOADLIBRARY
> >> +#ifndef UWP
> >>      // We let these "leak" - this is fine, as unloading has no great benefit, and
> >>      // Windows will mark a DLL as loaded forever if its internal refcount overflows
> >>      // from too many LoadLibrary calls.
> >> @@ -486,7 +493,7 @@ static int d3d11va_device_create(AVHWDeviceContext *ctx, const char *device,
> >>      int ret;
> >>
> >>      // (On UWP we can't check this.)
> >> -#if HAVE_LOADLIBRARY
> >> +#ifndef UWP
> >>      if (!LoadLibrary("d3d11_1sdklayers.dll"))
> >>          is_debug = 0;
> >>  #endif
> >> @@ -527,7 +534,7 @@ static int d3d11va_device_create(AVHWDeviceContext *ctx, const char *device,
> >>          ID3D10Multithread_Release(pMultithread);
> >>      }
> >> 
> >> -#if HAVE_LOADLIBRARY && HAVE_DXGIDEBUG_H
> >> +#if !defined(UWP) && HAVE_DXGIDEBUG_H
> >>      if (is_debug) {
> >>          HANDLE dxgidebug_dll = LoadLibrary("dxgidebug.dll");
> >>          if (dxgidebug_dll) {  
> >
> > LGTM... though isn't "UWP" a bit too generic as an identifier?  
> 
> It's a little terse yeah, but it's at least only visible within this file 
> (for now). Any better suggestions?

Maybe FF_UWP? UWP alone is awfully generic and I'd be slightly worried
about potential collisions. Could also be that I'm overthinking this.
Diego Biurrun July 4, 2017, 9:04 p.m. | #5
On Tue, Jul 04, 2017 at 10:57:41PM +0300, Martin Storsjö wrote:
> On Tue, 4 Jul 2017, wm4 wrote:
> >On Tue,  4 Jul 2017 22:18:21 +0300 Martin Storsjö <martin@martin.st> wrote:
> >>--- a/libavutil/hwcontext_d3d11va.c
> >>+++ b/libavutil/hwcontext_d3d11va.c
> >>@@ -47,6 +47,13 @@
> >>
> >>+#ifdef WINAPI_FAMILY
> >>+#include <winapifamily.h>
> >>+#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
> >>+#define UWP
> >>+#endif
> >>+#endif
> >>+
> >>@@ -56,7 +63,7 @@ static PFN_D3D11_CREATE_DEVICE mD3D11CreateDevice;
> >>
> >> static av_cold void load_functions(void)
> >> {
> >>-#if HAVE_LOADLIBRARY
> >>+#ifndef UWP
> >>     // We let these "leak" - this is fine, as unloading has no great benefit, and
> >
> >LGTM... though isn't "UWP" a bit too generic as an identifier?
> 
> It's a little terse yeah, but it's at least only visible within this file
> (for now). Any better suggestions?

WINAPI_FAMILY_DESKTOP
WINAPI_DESKTOP

or something along those lines? Maybe with an FF_ prefix?

Diego
Diego Biurrun July 4, 2017, 9:10 p.m. | #6
On Tue, Jul 04, 2017 at 10:18:21PM +0300, Martin Storsjö wrote:
> --- a/configure
> +++ b/configure
> @@ -4894,7 +4894,14 @@ fi
>  
>  # d3d11va requires linking directly to dxgi and d3d11 if not building for
>  # the desktop api partition
> -enabled LoadLibrary || d3d11va_extralibs="-ldxgi -ld3d11"
> +check_cpp <<EOF || d3d11va_extralibs="-ldxgi -ld3d11"
> +#ifdef WINAPI_FAMILY
> +#include <winapifamily.h>
> +#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
> +#error not desktop
> +#endif
> +#endif
> +EOF

Add "uwp" or whatever to HAVE_LIST, test for and enable it here, then

> --- a/libavutil/hwcontext_d3d11va.c
> +++ b/libavutil/hwcontext_d3d11va.c
> @@ -47,6 +47,13 @@
>  #include "pixdesc.h"
>  #include "pixfmt.h"
>  
> +#ifdef WINAPI_FAMILY
> +#include <winapifamily.h>
> +#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
> +#define UWP
> +#endif
> +#endif

you don't need to do this dance here and instead

> @@ -56,7 +63,7 @@ static PFN_D3D11_CREATE_DEVICE mD3D11CreateDevice;
>  
>  static av_cold void load_functions(void)
>  {
> -#if HAVE_LOADLIBRARY
> +#ifndef UWP

check for HAVE_UWP or whatever at this point.

Diego

Patch

diff --git a/configure b/configure
index 96bc5ab..ce81d3b 100755
--- a/configure
+++ b/configure
@@ -4894,7 +4894,14 @@  fi
 
 # d3d11va requires linking directly to dxgi and d3d11 if not building for
 # the desktop api partition
-enabled LoadLibrary || d3d11va_extralibs="-ldxgi -ld3d11"
+check_cpp <<EOF || d3d11va_extralibs="-ldxgi -ld3d11"
+#ifdef WINAPI_FAMILY
+#include <winapifamily.h>
+#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
+#error not desktop
+#endif
+#endif
+EOF
 
 enabled vaapi && require vaapi va/va.h vaInitialize -lva
 
diff --git a/libavutil/hwcontext_d3d11va.c b/libavutil/hwcontext_d3d11va.c
index 75f78d8..4d21b57 100644
--- a/libavutil/hwcontext_d3d11va.c
+++ b/libavutil/hwcontext_d3d11va.c
@@ -47,6 +47,13 @@ 
 #include "pixdesc.h"
 #include "pixfmt.h"
 
+#ifdef WINAPI_FAMILY
+#include <winapifamily.h>
+#if !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
+#define UWP
+#endif
+#endif
+
 typedef HRESULT(WINAPI *PFN_CREATE_DXGI_FACTORY)(REFIID riid, void **ppFactory);
 
 static AVOnce functions_loaded = AV_ONCE_INIT;
@@ -56,7 +63,7 @@  static PFN_D3D11_CREATE_DEVICE mD3D11CreateDevice;
 
 static av_cold void load_functions(void)
 {
-#if HAVE_LOADLIBRARY
+#ifndef UWP
     // We let these "leak" - this is fine, as unloading has no great benefit, and
     // Windows will mark a DLL as loaded forever if its internal refcount overflows
     // from too many LoadLibrary calls.
@@ -486,7 +493,7 @@  static int d3d11va_device_create(AVHWDeviceContext *ctx, const char *device,
     int ret;
 
     // (On UWP we can't check this.)
-#if HAVE_LOADLIBRARY
+#ifndef UWP
     if (!LoadLibrary("d3d11_1sdklayers.dll"))
         is_debug = 0;
 #endif
@@ -527,7 +534,7 @@  static int d3d11va_device_create(AVHWDeviceContext *ctx, const char *device,
         ID3D10Multithread_Release(pMultithread);
     }
 
-#if HAVE_LOADLIBRARY && HAVE_DXGIDEBUG_H
+#if !defined(UWP) && HAVE_DXGIDEBUG_H
     if (is_debug) {
         HANDLE dxgidebug_dll = LoadLibrary("dxgidebug.dll");
         if (dxgidebug_dll) {