diff options
author | Kacper Michajłow <kasper93@gmail.com> | 2023-11-08 00:05:40 +0100 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2023-11-22 11:43:20 +0100 |
commit | 67deebc5b5cf9f00f43e0126213fcae05335dd48 (patch) | |
tree | e2f9e72df377735465c3ac12314485316efa0d50 /video | |
parent | 73eecdb415f2a7499b0ae41a7af5e924319068ae (diff) | |
download | mpv-67deebc5b5cf9f00f43e0126213fcae05335dd48.tar.bz2 mpv-67deebc5b5cf9f00f43e0126213fcae05335dd48.tar.xz |
vaapi: add support for vaapi-win32
Only vaapi-copy variant as nothing can map D3D12 resources currently.
And even if we would add resource sharing to D3D11 it would invoke copy
at some point, so there is no point really. Maybe in the future when
libplacebo get smarter about resource sharing on Windows, but practical
advantages are really small. I've tested it with Vulkan <-> D3D11
sharing and GPU <-> GPU copy is still invoked. Better than CPU memcpy,
something for the future.
Diffstat (limited to 'video')
-rw-r--r-- | video/vaapi.c | 53 |
1 files changed, 51 insertions, 2 deletions
diff --git a/video/vaapi.c b/video/vaapi.c index ac0f8c48a0..2af1be4981 100644 --- a/video/vaapi.c +++ b/video/vaapi.c @@ -29,9 +29,30 @@ #include "mp_image_pool.h" #include "options/m_config.h" +#ifdef _WIN32 +#include "osdep/windows_utils.h" +#include "out/d3d11/context.h" +#include "out/gpu/d3d11_helpers.h" +#endif + #include <libavutil/hwcontext.h> #include <libavutil/hwcontext_vaapi.h> +#ifdef _WIN32 +#define DEV_PATH_DEFAULT NULL +#define DEV_PATH_VALIDATE mp_dxgi_validate_adapter +#else +#define DEV_PATH_DEFAULT "/dev/dri/renderD128" +#define DEV_PATH_VALIDATE validate_path + +static int validate_path(struct mp_log *log, + const struct m_option *opt, + struct bstr name, const char **value) +{ + return (*value && **value) ? 0 : M_OPT_INVALID; +} +#endif + struct vaapi_opts { char *path; }; @@ -39,11 +60,11 @@ struct vaapi_opts { #define OPT_BASE_STRUCT struct vaapi_opts const struct m_sub_options vaapi_conf = { .opts = (const struct m_option[]) { - {"device", OPT_STRING(path)}, + {"device", OPT_STRING_VALIDATE(path, DEV_PATH_VALIDATE)}, {0}, }, .defaults = &(const struct vaapi_opts) { - .path = "/dev/dri/renderD128", + .path = DEV_PATH_DEFAULT, }, .size = sizeof(struct vaapi_opts), }; @@ -201,6 +222,31 @@ static const struct va_native_display disp_x11 = { }; #endif +#if HAVE_VAAPI_WIN32 +#include <va/va_win32.h> + +static void win32_create(struct mp_log *log, VADisplay **out_display, + void **out_native_ctx, const char *path) +{ + LUID *luid = NULL; + DXGI_ADAPTER_DESC1 desc = {0}; + if (path && path[0]) { + IDXGIAdapter1 *adapter = mp_get_dxgi_adapter(log, bstr0(path), NULL); + if (!adapter || FAILED(IDXGIAdapter1_GetDesc1(adapter, &desc))) { + mp_err(log, "Failed to get adapter LUID for name: %s\n", path); + } else { + luid = &desc.AdapterLuid; + } + SAFE_RELEASE(adapter); + } + *out_display = vaGetDisplayWin32(luid); +} + +static const struct va_native_display disp_win32 = { + .create = win32_create, +}; +#endif + #if HAVE_VAAPI_DRM #include <unistd.h> #include <fcntl.h> @@ -246,6 +292,9 @@ static const struct va_native_display *const native_displays[] = { #if HAVE_VAAPI_DRM &disp_drm, #endif +#if HAVE_VAAPI_WIN32 + &disp_win32, +#endif #if HAVE_VAAPI_X11 &disp_x11, #endif |