From 053f10003ca0e2df354d959cecd7e83809b678b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Ekstr=C3=B6m?= Date: Mon, 6 Dec 2021 21:59:26 +0200 Subject: vo_gpu_next: initial attempt at adding d3d11 support --- DOCS/man/vo.rst | 2 +- video/out/gpu_next/context.c | 94 ++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 88 insertions(+), 8 deletions(-) diff --git a/DOCS/man/vo.rst b/DOCS/man/vo.rst index 1428c632c2..d1abe1088d 100644 --- a/DOCS/man/vo.rst +++ b/DOCS/man/vo.rst @@ -262,7 +262,7 @@ Available video output drivers are: the same set of features as ``--vo=gpu``. See `GPU renderer options`_ for a list. - Currently, this only supports Vulkan, OpenGL and no hardware + Currently, this only supports Vulkan, OpenGL, D3D11 and no hardware decoding. Unlike ``--vo=gpu``, the FBO formats are not tunable, but you can still set ``--gpu-dumb-mode=yes`` to forcibly disable their use. diff --git a/video/out/gpu_next/context.c b/video/out/gpu_next/context.c index f89927e008..7315355b59 100644 --- a/video/out/gpu_next/context.c +++ b/video/out/gpu_next/context.c @@ -17,6 +17,10 @@ #include +#ifdef PL_HAVE_D3D11 +#include +#endif + #ifdef PL_HAVE_OPENGL #include #endif @@ -28,6 +32,12 @@ #include "video/out/placebo/utils.h" #include "video/out/gpu/video.h" +#if HAVE_D3D11 +#include "osdep/windows_utils.h" +#include "video/out/d3d11/ra_d3d11.h" +#include "video/out/d3d11/context.h" +#endif + #if HAVE_GL #include "video/out/opengl/context.h" #include "video/out/opengl/ra_gl.h" @@ -38,6 +48,9 @@ #endif struct priv { +#ifdef PL_HAVE_D3D11 + pl_d3d11 d3d11; +#endif #ifdef PL_HAVE_OPENGL pl_opengl opengl; #else @@ -45,6 +58,60 @@ struct priv { #endif }; +#if HAVE_D3D11 +static bool d3d11_pl_init(struct vo *vo, struct gpu_ctx *ctx, struct priv *p, + struct ra_ctx_opts *ctx_opts) +{ +#if !defined(PL_HAVE_D3D11) + MP_MSG(ctx, vo->probing ? MSGL_V : MSGL_ERR, + "libplacebo was built without D3D11 support.\n"); + return false; +#else // defined(PL_HAVE_D3D11) + bool success = false; + + ID3D11Device *device = ra_d3d11_get_device(ctx->ra_ctx->ra); + IDXGISwapChain *swapchain = ra_d3d11_ctx_get_swapchain(ctx->ra_ctx); + if (!device || !swapchain) { + mp_err(ctx->log, + "Failed to receive required components from the mpv d3d11 " + "context! (device: %s, swap chain: %s)\n", + device ? "OK" : "failed", + swapchain ? "OK" : "failed"); + goto err_out; + } + + p->d3d11 = pl_d3d11_create(ctx->pllog, pl_d3d11_params( + .device = device, + )); + if (!p->d3d11) { + mp_err(ctx->log, "Failed to acquire a d3d11 libplacebo context!\n"); + goto err_out; + } + ctx->gpu = p->d3d11->gpu; + + mppl_ctx_set_log(ctx->pllog, ctx->log, false); // disable probing + + ctx->swapchain = pl_d3d11_create_swapchain(p->d3d11, + pl_d3d11_swapchain_params( + .swapchain = swapchain, + ) + ); + if (!ctx->swapchain) { + mp_err(ctx->log, "Failed to acquire a d3d11 libplacebo swap chain!\n"); + goto err_out; + } + + success = true; + +err_out: + SAFE_RELEASE(swapchain); + SAFE_RELEASE(device); + + return success; +#endif // defined(PL_HAVE_D3D11) +} +#endif // HAVE_D3D11 + struct gpu_ctx *gpu_ctx_create(struct vo *vo, struct gl_video_opts *gl_opts) { struct gpu_ctx *ctx = talloc_zero(NULL, struct gpu_ctx); @@ -76,6 +143,15 @@ struct gpu_ctx *gpu_ctx_create(struct vo *vo, struct gl_video_opts *gl_opts) mp_verbose(ctx->log, "Initialized libplacebo %s (API v%d)\n", PL_VERSION, PL_API_VER); +#if HAVE_D3D11 + if (ra_is_d3d11(ctx->ra_ctx->ra)) { + if (!d3d11_pl_init(vo, ctx, p, ctx_opts)) + goto err_out; + + return ctx; + } +#endif + #if HAVE_GL && defined(PL_HAVE_OPENGL) if (ra_is_gl(ctx->ra_ctx->ra)) { p->opengl = pl_opengl_create(ctx->pllog, pl_opengl_params( @@ -110,15 +186,13 @@ err_out: bool gpu_ctx_resize(struct gpu_ctx *ctx, int w, int h) { - struct priv *p = ctx->priv; - -#ifdef PL_HAVE_OPENGL - // The vulkan context handles this on its own, so only for OpenGL here - if (p->opengl) - return pl_swapchain_resize(ctx->swapchain, &w, &h); +#if HAVE_VULKAN + if (ra_vk_ctx_get(ctx->ra_ctx)) + // vulkan RA handles this by itself + return true; #endif - return true; + return pl_swapchain_resize(ctx->swapchain, &w, &h); } void gpu_ctx_destroy(struct gpu_ctx **ctxp) @@ -147,6 +221,12 @@ void gpu_ctx_destroy(struct gpu_ctx **ctxp) } #endif +#if HAVE_D3D11 && defined(PL_HAVE_D3D11) + if (ra_is_d3d11(ctx->ra_ctx->ra)) { + pl_d3d11_destroy(&p->d3d11); + } +#endif + if (ctx->pllog) pl_log_destroy(&ctx->pllog); -- cgit v1.2.3