Skip to content

Commit

Permalink
(WIP) vo_opengl: refactor into vo_gpu
Browse files Browse the repository at this point in the history
This is done in several steps:

1. refactor MPGLContext -> struct ra_ctx
2. move GL-specific stuff in vo_opengl into opengl/context.c
3. generalize context creation to support other APIs, and add --gpu-api
4. rename all of the --opengl- options that are no longer opengl-specific
5. move all of the stuff from opengl/* that isn't GL-specific into gpu/
   (note: opengl/gl_utils.h became opengl/utils.h)
6. rename vo_opengl to vo_gpu
7. to handle window screenshots, the short-term approach was to just add
   it to ra_ctx_fns. Long term (and for vulkan) this has to be moved to
   ra itself (and vo_gpu altered to compensate), but this was a stop-gap
   measure to prevent this commit from getting too big

Note: This is an in-progress commit. For a list of files that need to be
ported to the new API, see the commented out build steps in
wscript_build.py as well as the commented out backends in
video/out/gpu/context.c
  • Loading branch information
haasn committed Sep 15, 2017
1 parent 2f41b83 commit 48afb0b
Show file tree
Hide file tree
Showing 52 changed files with 1,842 additions and 1,722 deletions.
14 changes: 14 additions & 0 deletions DOCS/interface-changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ Interface changes

::

--- mpv 0.28.0 ---
- rename --vo=opengl to --vo=gpu
- rename --opengl-backend to --gpu-context
- rename --opengl-shaders to --glsl-shaders
- rename --opengl-shader-cache-dir to --gpu-shader-cache-dir
- rename --opengl-tex-pad-x/y to --gpu-tex-pad-x/y
- rename --opengl-fbo-format to --fbo-format
- rename --opengl-gamma to --gpu-gamma
- rename --opengl-debug to --gpu-debug
- rename --opengl-sw to --gpu-sw
- rename --opengl-vsync-fences to --swapchain-depth
- rename the built-in profile `opengl-hq` to `gpu-hq`
- the semantics of --opengl-es=yes are slightly changed -> now requires GLES
- remove the (deprecated) alias --gpu-context=drm-egl
--- mpv 0.27.0 ---
- drop previously deprecated --field-dominance option
- drop previously deprecated "osd" command
Expand Down
6 changes: 3 additions & 3 deletions DOCS/man/mpv.rst
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,8 @@ setting them to *no*. Even suboptions can be specified in this way.

::

# Use opengl video output by default.
vo=opengl
# Use GPU-accelerated video output by default.
vo=gpu
# Use quotes for text that can contain spaces:
status-msg="Time: ${time-pos}"

Expand Down Expand Up @@ -582,7 +582,7 @@ profile name ``default`` to continue with normal options.
[slow]
profile-desc="some profile name"
# reference a builtin profile
profile=opengl-hq
profile=gpu-hq

[fast]
vo=vdpau
Expand Down
149 changes: 77 additions & 72 deletions DOCS/man/options.rst

Large diffs are not rendered by default.

33 changes: 15 additions & 18 deletions DOCS/man/vo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ in the list.

See ``--vo=help`` for a list of compiled-in video output drivers.

The recommended output driver is ``--vo=opengl``, which is the default. All
The recommended output driver is ``--vo=gpu``, which is the default. All
other drivers are for compatibility or special purposes. If the default
does not work, it will fallback to other drivers (in the same order as
listed by ``--vo=help``).
Expand Down Expand Up @@ -273,37 +273,34 @@ Available video output drivers are:
``--vo-direct3d-exact-backbuffer``
Always resize the backbuffer to window size.

``opengl``
OpenGL video output driver. It supports extended scaling methods, dithering
and color management.
``gpu``
General purpose, customizable, GPU-accelerated video output driver. It
supports extended scaling methods, dithering, color management, custom
shaders, HDR, and more.

See `OpenGL renderer options`_ for options specific to this VO.
See `GPU renderer options`_ for options specific to this VO.

By default, it tries to use fast and fail-safe settings. Use the
``opengl-hq`` profile to use this driver with defaults set to high
quality rendering. (This profile is also the replacement for
``--vo=opengl-hq``.) The profile can be applied with ``--profile=opengl-hq``
and its contents can be viewed with ``--show-profile=opengl-hq``.
``gpu-hq`` profile to use this driver with defaults set to high quality
rendering. The profile can be applied with ``--profile=gpu-hq`` and its
contents can be viewed with ``--show-profile=gpu-hq``.

Requires at least OpenGL 2.1.

Some features are available with OpenGL 3 capable graphics drivers only
(or if the necessary extensions are available).

OpenGL ES 2.0 and 3.0 are supported as well.
This VO abstracts over several possible graphics APIs and windowing
contexts, which can be influenced using the ``--gpu-api`` and
``--gpu-context`` options.

Hardware decoding over OpenGL-interop is supported to some degree. Note
that in this mode, some corner case might not be gracefully handled, and
color space conversion and chroma upsampling is generally in the hand of
the hardware decoder APIs.

``opengl`` makes use of FBOs by default. Sometimes you can achieve better
quality or performance by changing the ``--opengl-fbo-format`` option to
``gpu`` makes use of FBOs by default. Sometimes you can achieve better
quality or performance by changing the ``--gpu-fbo-format`` option to
``rgb16f``, ``rgb32f`` or ``rgb``. Known problems include Mesa/Intel not
accepting ``rgb16``, Mesa sometimes not being compiled with float texture
support, and some OS X setups being very slow with ``rgb16`` but fast
with ``rgb32f``. If you have problems, you can also try enabling the
``--opengl-dumb-mode=yes`` option.
``--gpu-dumb-mode=yes`` option.

``sdl``
SDL 2.0+ Render video output driver, depending on system with or without
Expand Down
6 changes: 3 additions & 3 deletions DOCS/mplayer-changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,16 @@ Video

* Wayland support.
* Native support for VAAPI and VDA. Improved VDPAU video output.
* Improved OpenGL output (see the ``opengl-hq`` video output).
* Make hardware decoding work with the ``opengl`` video output.
* Improved GPU-accelerated video output (see the ``gpu-hq`` preset).
* Make hardware decoding work with the ``gpu`` video output.
* Support for libavfilter (for video->video and audio->audio). This allows
using most of FFmpeg's filters, which improve greatly on the old MPlayer
filters in features, performance, and correctness.
* More correct color reproduction (color matrix generation), including support
for BT.2020 (Ultra HD). linear XYZ (Digital Cinema) and SMPTE ST2084 (HDR)
inputs.
* Support for color managed displays, via ICC profiles.
* High-quality image resamplers (see the ``opengl`` ``scale`` suboption).
* High-quality image resamplers (see the ``--scale`` suboption).
* Support for scaling in (sigmoidized) linear light.
* Better subtitle rendering using libass by default.
* Improvements when playing multiple files (``-fixed-vo`` is default, do not
Expand Down
6 changes: 5 additions & 1 deletion etc/builtin.conf
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,15 @@ load-scripts=no
osc=no
framedrop=no

[opengl-hq]
[gpu-hq]
scale=spline36
cscale=spline36
dscale=mitchell
dither-depth=auto
correct-downscaling=yes
sigmoid-upscaling=yes
deband=yes

# Compatibility alias (deprecated)
[opengl-hq]
profile=gpu-hq
4 changes: 2 additions & 2 deletions etc/mpv.conf
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
# Keep the player window on top of all other windows.
#ontop=yes

# Specify high quality video rendering preset (for OpenGL VO only)
# Specify high quality video rendering preset (for --vo=gpu only)
# Can cause performance problems with some drivers and GPUs.
#profile=opengl-hq
#profile=gpu-hq

# Force video to lock on the display's refresh rate, and change video and audio
# speed to some degree to ensure synchronous playback - can cause problems
Expand Down
11 changes: 8 additions & 3 deletions options/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
#include "video/out/drm_common.h"
#endif

#if HAVE_GL
#include "video/out/opengl/hwdec.h"
#if HAVE_GPU
#include "video/out/gpu/hwdec.h"
#endif

static void print_version(struct mp_log *log)
Expand Down Expand Up @@ -87,6 +87,7 @@ extern const struct m_obj_list af_obj_list;
extern const struct m_obj_list vo_obj_list;
extern const struct m_obj_list ao_obj_list;

extern const struct m_sub_options opengl_conf;
extern const struct m_sub_options angle_conf;
extern const struct m_sub_options cocoa_conf;

Expand Down Expand Up @@ -686,10 +687,14 @@ const m_option_t mp_opts[] = {
OPT_SUBSTRUCT("", vo, vo_sub_opts, 0),
OPT_SUBSTRUCT("", demux_opts, demux_conf, 0),

#if HAVE_GL
#if HAVE_GPU
OPT_SUBSTRUCT("", gl_video_opts, gl_video_conf, 0),
#endif

#if HAVE_GL
OPT_SUBSTRUCT("", opengl_opts, opengl_conf, 0),
#endif

#if HAVE_EGL_ANGLE_WIN32
OPT_SUBSTRUCT("", angle_opts, angle_conf, 0),
#endif
Expand Down
1 change: 1 addition & 0 deletions options/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ typedef struct MPOpts {

struct gl_video_opts *gl_video_opts;
struct angle_opts *angle_opts;
struct opengl_opts *opengl_opts;
struct cocoa_opts *cocoa_opts;
struct dvd_opts *dvd_opts;

Expand Down
17 changes: 0 additions & 17 deletions player/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,21 +297,6 @@ static bool handle_help_options(struct MPContext *mpctx)
return false;
}

static void handle_deprecated_options(struct MPContext *mpctx)
{
struct MPOpts *opts = mpctx->opts;
struct m_obj_settings *vo = opts->vo->video_driver_list;
if (vo && vo->name && strcmp(vo->name, "opengl-hq") == 0) {
MP_WARN(mpctx,
"--vo=opengl-hq is deprecated! Use --profile=opengl-hq instead.\n");
// Fudge it. This will replace the --vo option too, which is why we
// unset/safe it, and later restore it.
talloc_free(vo->name);
vo->name = talloc_strdup(NULL, "opengl");
m_config_set_profile(mpctx->mconfig, "opengl-hq", 0);
}
}

static int cfg_include(void *ctx, char *filename, int flags)
{
struct MPContext *mpctx = ctx;
Expand Down Expand Up @@ -445,8 +430,6 @@ int mp_initialize(struct MPContext *mpctx, char **options)
if (handle_help_options(mpctx))
return -2;

handle_deprecated_options(mpctx);

if (!print_libav_versions(mp_null_log, 0)) {
// Using mismatched libraries can be legitimate, but even then it's
// a bad idea. We don't acknowledge its usefulness and stability.
Expand Down
163 changes: 163 additions & 0 deletions video/out/gpu/context.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
/*
* This file is part of mpv.
*
* mpv is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* mpv is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
*/

#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <assert.h>

#include "config.h"
#include "common/common.h"
#include "common/msg.h"
#include "options/options.h"
#include "options/m_option.h"
#include "video/out/vo.h"

#include "context.h"

extern const struct ra_ctx_fns ra_ctx_glx;
extern const struct ra_ctx_fns ra_ctx_glx_probe;
extern const struct ra_ctx_fns ra_ctx_x11_egl;
extern const struct ra_ctx_fns ra_ctx_drm_egl;
extern const struct ra_ctx_fns ra_ctx_cocoa;
extern const struct ra_ctx_fns ra_ctx_wayland_egl;
extern const struct ra_ctx_fns ra_ctx_wgl;
extern const struct ra_ctx_fns ra_ctx_angle;
extern const struct ra_ctx_fns ra_ctx_dxinterop;
extern const struct ra_ctx_fns ra_ctx_rpi;
extern const struct ra_ctx_fns ra_ctx_mali;
extern const struct ra_ctx_fns ra_ctx_vdpauglx;

static const struct ra_ctx_fns *contexts[] = {
// OpenGL contexts:
/*
#if HAVE_RPI
&ra_ctx_rpi,
#endif
#if HAVE_GL_COCOA
&ra_ctx_cocoa,
#endif
#if HAVE_EGL_ANGLE_WIN32
&ra_ctx_angle,
#endif
#if HAVE_GL_WIN32
&ra_ctx_wgl,
#endif
#if HAVE_GL_DXINTEROP
&ra_ctx_dxinterop,
#endif
*/
#if HAVE_GL_X11
&ra_ctx_glx_probe,
#endif
#if HAVE_EGL_X11
&ra_ctx_x11_egl,
#endif
#if HAVE_GL_X11
&ra_ctx_glx,
#endif
#if HAVE_GL_WAYLAND
&ra_ctx_wayland_egl,
#endif
#if HAVE_EGL_DRM
&ra_ctx_drm_egl,
#endif
/*
#if HAVE_MALI_FBDEV
&ra_ctx_mali,
#endif
#if HAVE_VDPAU_GL_X11
&ra_ctx_vdpauglx,
#endif
*/
};

static const char *type_names[] = {
[RA_API_OPENGL] = "opengl",
};

int ra_ctx_validate_context(struct mp_log *log, const struct m_option *opt,
struct bstr name, struct bstr param)
{
if (bstr_equals0(param, "help")) {
mp_info(log, "GPU contexts:\n");
mp_info(log, " auto (autodetect)\n");
for (int n = 0; n < MP_ARRAY_SIZE(contexts); n++) {
mp_info(log, " %s (%s)\n", contexts[n]->name,
type_names[contexts[n]->type]);
}
return M_OPT_EXIT;
}

if (bstr_equals0(param, "auto"))
return 1;
for (int i = 0; i < MP_ARRAY_SIZE(contexts); i++) {
if (bstr_equals0(param, contexts[i]->name))
return 1;
}

return M_OPT_INVALID;
}

// Create a VO window and create a RA context on it.
// vo_flags: passed to the backend's create window function
struct ra_ctx *ra_ctx_create(struct vo *vo, enum ra_api_type type,
const char *context_name, struct ra_ctx_opts opts)
{
if (!context_name || strcmp(context_name, "auto") == 0) {
MP_VERBOSE(vo, "Probing for best GPU context.\n");
opts.probing = true;
}

for (int i = 0; i < MP_ARRAY_SIZE(contexts); i++) {
if (!opts.probing && strcmp(contexts[i]->name, context_name) != 0)
continue;
if (type && type != contexts[i]->type)
continue;

struct ra_ctx *ctx = talloc_ptrtype(NULL, ctx);
*ctx = (struct ra_ctx) {
.vo = vo,
.global = vo->global,
.log = vo->log,
.opts = opts,
.fns = contexts[i],
};

MP_VERBOSE(ctx, "Initializing GPU context '%s'\n", ctx->fns->name);
if (contexts[i]->init(ctx))
return ctx;

talloc_free(ctx);
}

// If we've reached this point, then none of the contexts matched the name
// requested, or the backend creation failed for all of them.
MP_ERR(vo, "Failed initializing any suitable GPU context!\n");
return NULL;
}

void ra_ctx_destroy(struct ra_ctx **ctx)
{
if (*ctx)
(*ctx)->fns->uninit(*ctx);
talloc_free(*ctx);
*ctx = NULL;
}
Loading

0 comments on commit 48afb0b

Please sign in to comment.