1
0
mirror of https://github.com/mpv-player/mpv synced 2025-01-10 00:49:32 +00:00

vo_gpu_next: initial attempt at adding d3d11 support

This commit is contained in:
Jan Ekström 2021-12-06 21:59:26 +02:00
parent 723a2ba762
commit 053f10003c
2 changed files with 88 additions and 8 deletions

View File

@ -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.

View File

@ -17,6 +17,10 @@
#include <libplacebo/config.h>
#ifdef PL_HAVE_D3D11
#include <libplacebo/d3d11.h>
#endif
#ifdef PL_HAVE_OPENGL
#include <libplacebo/opengl.h>
#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);