0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 20:03:10 +02:00
Commit Graph

2179 Commits

Author SHA1 Message Date
wm4
f72eb5b394 sub: move paletted image handling completely to sd_lavc.c
Until now, subtitle renderers could export SUBBITMAP_INDEXED, which is a
8 bit per pixel with palette format. sd_lavc.c was the only renderer
doing this, and the result was converted to RGBA in every use-case
(except maybe when the subtitles were hidden.)

Change it so that sd_lavc.c converts to RGBA on its own. This simplifies
everything a bit, and the palette handling can be removed from the
common code.

This is also preparation for making subtitle images refcounted. The
"caching" in img_convert.c is a PITA in this respect, and needs to be
redone. So getting rid of some img_convert.c code is a positive side-
effect. Also related to refcounted subtitles is packing them into a
single mp_image. Fewer objects to refcount is easier, and for the libass
format the same will be done. The plan is to remove manual packing from
the VOs which need single images entirely.
2016-06-17 23:13:14 +02:00
wm4
454fff39ad bitmap_packer: make manual use slightly more convenient
Apply the padding internally to each input bitmap, instead of requiring
this for the semi-public API.

Right now, everything still uses packer_pack_from_subbitmaps() to fill
the input bitmap sizes, but that's going to change with the following
commit. Since bitmap_packer.in is mutated during packing anyway, it's
more convenient to add the padding automatically.

Also, guarantee that every sub-bitmap has a padding border around it.
Don't let the padding overlap. Add padding even on the containing
borders.

This is simpler, doesn't cost much in memory usage, and is convenient
for one of the following commits.
2016-06-17 23:12:43 +02:00
James Ross-Gowan
5700da4a8f vo_opengl: use EXT_disjoint_timer_query for timers
This is the ES equivalent to ARB_timer_query. It enables the performance
timers on ANGLE. All the added functions should be identical in
semantics to their desktop GL equivalents.
2016-06-15 20:32:47 +10:00
wm4
43e964e2d6 vo_opengl: fix framebuffer object name
The OpenGL 3.0+ and ES specs are quite clear on what values are
accepted for the attachment object name parameter. And there's no
overlap for the default framebuffer. Sigh.

Probably fixes Mesa raising an error in this case and might fix #3251.
Regression by the previous vo_opengl change.
2016-06-15 00:55:27 +02:00
wm4
788929e4e0 vo_opengl: use standard functions to retrieve display depth
Until now, we've used system-specific API (GLX, EGL, etc.) to retrieve
the depth of the default framebuffer. (We equal this to display depth
and use the determined depth for dithering.)

We can actually retrieve this value through standard GL API, and it
works everywhere (except GLES 2 of course). This simplifies everything a
great deal.

egl_helpers.c is empty now. But I expect that some EGL boilerplate will
be moved to it, so don't remove it yet.
2016-06-14 10:35:43 +02:00
wm4
3682df2dd5 vo_opengl: hwdec_d3d11egl: remove ES2 swizzle special-case
This was somehow done under the assumption that ANGLE would somehow
always use RG in ES2 mode. But there's no basis for this. Even if ANGLE
supports NV12 textures with drivers that do not allow for texture_rg,
this cas eis too obscure to worry about. So do the robust and correct
thing instead, and disable this code if texture_rg is not available.
2016-06-13 16:15:57 +02:00
Gusar321
81ec9cf596 vo_rpi: fix destroying overlays
Commit 74e3d11 resulted in the background overlay not getting destroyed
when mpv quits. Add back a piece of code that was removed in that commit
to restore correct functionality.

Fixes issue #3100
2016-06-13 14:48:11 +02:00
Bin Jin
3d844cddf8 vo_opengl: make size of OUTPUT available to user shaders 2016-06-12 17:51:50 +02:00
James Ross-Gowan
9fcc517cee win32: use HINST_THISCOMPONENT
This is a common idiom used in MSDN docs and Raymond Chen's example
programs to get a HINSTANCE for the current module, regardless of
whether it's an .exe or a .dll. Using GetModuleHandle(NULL) for this is
technically incorrect, since it always gets a handle to the .exe, even
when the executing code (in libmpv) is running in a .dll. In this case,
using the wrong HINSTANCE could cause namespace issues with window
classes, since CreateWindowEx uses the HINSTANCE to search for the
matching window class name.

See:
https://blogs.msdn.microsoft.com/oldnewthing/20050418-59/?p=35873
https://blogs.msdn.microsoft.com/oldnewthing/20041025-00/?p=37483
2016-06-11 15:35:17 +02:00
Stefano Pigozzi
de4c74e5a4 cocoa: use displaylink without manually tracking the display id
Maybe it partially helps with #2392 (on dual display setups). Either way, it
makes the code simpler.
2016-06-11 11:58:07 +02:00
Rudolf Polzer
9cc5507079 vo_sdl: fix pixel formats.
There were two mistakes:

- SDL's RGB565 is always equivalent to ffmpeg's RGB565 (both are packed 16bit
  native-endian integers in RGB=565 form) - this was wrongly reversed on
  big endian platforms.
- SDL's RGB888 doesn't actually mean RGB24, but XRGB8888 (i.e. 32bit
  packed integer, top 8 bits unused).
- Use RGB0 not RGBA when there is no alpha.
2016-06-10 16:30:12 -04:00
wm4
bea2e39721 vo_opengl: request core profile on X11/EGL too
Avoids that some OpenGL implementation will pin it to 3.0.
2016-06-10 20:31:28 +02:00
Bin Jin
2b1656b1ac vo_opengl: increase the size limit for cached file
This is mainly for the nnedi3 user shader. With all whose NN weights
hardcoded into the shader source code, the shader file could be as
large as 300 kB.
2016-06-10 17:08:54 +02:00
wm4
d38d26057a vo_opengl: hwdec_d3d11eglrgb: remove some more unused fields
Not sure what/if I was thinking there.
2016-06-09 18:43:40 +02:00
wm4
262ceca731 vo_opengl: fix d3d11 hardware decoding probing on Windows 7
Although D3D11 video decoding is unuspported on Windows 7, the
associated APIs almost work. Where they fail is texture creation, where
we try to create D3D11_BIND_DECODER surfaces. So specifically try to
detect this situation.

One issue is that once the hwdec interop is created, the damage is done,
and it can't use another backend (because currently only 1 hwdec backend
is supported). So that's where we prevent attempts to use it.

It still can fail when trying to use d3d11va-copy (since that doesn't
require an interop backend), but at that point we don't care anymore -
dxva2(-copy) is tried before that anyway.
2016-06-09 11:18:36 +02:00
wm4
6fd7f5a111 vo_opengl: hwdec_d3d11eglrgb: remove unused fields
Leftovers.
2016-06-09 10:51:04 +02:00
wm4
4123c9642d vo_opengl: hwdec_vdpau: remove minor code duplication
Move unmap() to the top of the function, and replace some duplicated
code with a call to it.
2016-06-08 22:16:32 +02:00
Niklas Haas
54c48bd801 vo_opengl: make user hook passes optional
User hooks can now use an extra WHEN expression to specify when the
shader should be run. For example, this can be used to only run a chroma
scaling shader `WHEN CHROMA.w LUMA.w <`.

There's a slight semantics change to user shaders: When trying to bind a
texture that does not exist, a shader will now be silently skipped
(similar to when the condition is false) instead of generating an error.

This allows shader stages to depend on an optional earlier stage without
having to copy/paste the same condition everywhere.

(In other words: there's an implicit condition on all of the bound
textures existing)
2016-06-08 20:50:19 +02:00
wm4
a15181e5df vo_opengl: do not leak previous FBO when reallocating it
WTF of the day.
2016-06-08 17:49:23 +02:00
James Ross-Gowan
b906eb37ed hwdec_d3d11eglrgb: reduce log level when probing
When using --hwdec=auto, systems that don't provide
D3D11_CREATE_DEVICE_VIDEO_SUPPORT, which probably includes all Windows
Vista and 7 systems, will print an error message. Reduce the log level
to verbose when probing and skip the error message entirely if d3d11.dll
is not present.

This commit is in a similar spirit to 991af7d.
2016-06-09 00:24:49 +10:00
wm4
7373158703 vo_opengl: hwdec_d3d11egl: remove broken code on error path
If ID3D11Device_QueryInterface fails, "multithread" will be set to NULL.
The _Release would just make it crash with a null pointer deref.
2016-06-08 12:57:14 +02:00
Niklas Haas
5b5db336e9 build: silence -Wunused-result
For clang, it's enough to just put (void) around usages we are
intentionally ignoring the result of.

Since GCC does not seem to want to respect this decision, we are forced
to disable the warning globally.
2016-06-07 14:12:33 +02:00
Niklas Haas
38ac5d5e7b vo_opengl: avoid outputting ultra-wide-gamut by default
The default behavior of vo_opengl has pretty much always been 'show the
source colors as-is, without caring to adapt it to the target device'.
This decision is mostly based on the fact that if we do anything else,
lots of people will complain.

With the rise of content like BT.2020, however, it turns out more people
complain about this content being very desaturated than people complain
about this content not matching VLC - so let's just map ultra-wide gamut
content back down to standard gamut by default.
2016-06-07 12:18:39 +02:00
Niklas Haas
9bd886f449 vo_opengl: also collect upload perfdata for hwdec
Instead of measuring the actual upload time, this instead measures the
time needed to render + map the texture via vdpau. These numbers are
still useful, since they're part of the critical path.
2016-06-07 12:18:05 +02:00
Niklas Haas
393a069112 vo_opengl: expose performance timers as properties
This is plumbed through a new VOCTRL, VOCTRL_PERFORMANCE_DATA, and
exposed as properties render-time-last, render-time-avg etc.

All of these numbers are in microseconds, which gives a good precision
range when just outputting them via show-text. (Lua scripts can
obviously still do their own formatting etc.)

Signed-off-by: wm4 <wm4@nowhere>
2016-06-07 12:17:25 +02:00
Niklas Haas
8ceb935bd8 vo_opengl: add time queries
To avoid blocking the CPU, we use 8 time objects and rotate through
them, only blocking until the last possible moment (before we need
access to them on the next iteration through the ring buffer). I tested
it out on my machine and 4 query objects were enough to guarantee
block-free querying, but the extra margin shouldn't hurt.

Frame render times are just output at the end of each frame, via MP_DBG.
This might be improved in the future. (In particular, I want to expose
these numbers as properties so that users get some more visible feedback
about render times)

Currently, we measure pass_render_frame and pass_draw_to_screen
separately because the former might be called multiple times due to
interpolation. Doing it this way gives more faithful numbers. Same goes
for frame upload times.
2016-06-07 12:16:15 +02:00
James Ross-Gowan
a9150a49d7 vo_opengl: angle: prevent DXGI hooking Alt+Enter
When ANGLE is using D3D11 and not running in DirectComposition mode,
DXGI will hook the video window's message loop and override Alt+Enter to
trigger a transition to exclusive fullscreen mode (which doesn't even
work with mpv's renderer for some reason.) This behaviour can be
disabled by getting a pointer to the IDXGIFactory associated with the
D3D11 device and calling MakeWindowAssociation with the appropriate
flags.
2016-06-07 18:41:47 +10:00
wm4
c1cb04b6a3 vo_opengl: apply vo-cmdline command incrementally
Instead of implicitly resetting the options to defaults and then
applying the options, they're always applied on top of the current
options (in the same way adding new options to the CLI command line
will).

This does not apply to vo_opengl_cb, because that has an even worse mess
which I refuse to deal with.
2016-06-05 16:56:34 +02:00
wm4
ee337b47be vo_opengl_cb: icc-profile-auto does not and will not work
In theory we could probably make icc-profile-auto a vo_opengl-specific
option, but I won't bother with this. Logging an error is simpler.
2016-06-05 15:00:07 +02:00
wm4
b3a3ed00f0 vo_opengl: possibly update icc profile after changing options
Changing the options can enable icc-profile-auto, and in this case the
profile has to be reteieved again from the system.
2016-06-05 12:21:47 +02:00
wm4
65f5fbc5d4 vo_opengl: somewhat simplify suboption handling mess
Enable m_sub_options_copy() to copy nested sub-options, and also enable
it to create an option struct from defaults. We can get rid of most of
the crap in assign_options() now.

Calling handle_scaler_opt() to get a static allocation for scaler name
is still needed. It's moved to reinit_scaler(), which seems to be a
better place for it. Without it, dangling pointers could be created when
options are changed. (And in fact, this fixes possible dangling pointers
for window.name.) In theory we could create a dynamic copy, but that
seemed even more messy.

Chance of regressions.
2016-06-04 20:48:56 +02:00
wm4
352904fd03 vo_opengl: cleanup icc + runtime option changing behavior
Commit 026b75e7 actually enabled changing icc options at runtime (via
vo_cmdline), but it didn't quite work. In particular, changing the icc-
profile option just kept the old profile, because it was cached
accordingly.

As part of this, change gl_lcms.opts from a struct to a pointer to a
struct. We properly copy it, instead of allowing possibly dangling
strings, like it was done in a working but unclean way before.

Also, reinit the whole rendering chain when the auto icc profile
changes, just like it's done when icc options are changed.
2016-06-04 17:52:10 +02:00
wm4
2dfea67f3b vo_opengl: minor simplification to gl_lcms_set_memory_profile()
Passing the bstr thing as pointer makes no sense. Everywhere else bstr
structs are passed by value because they're so small. Only when it's
supposed to receive a return value they're not.
2016-06-04 14:50:32 +02:00
wm4
a9ffe38aa1 vo_opengl: remove pointless NULL-check
It's never NULL.
2016-06-04 13:44:46 +02:00
wm4
026b75e7f5 vo_opengl: move all icc handling from vo_opengl.c to video.c
Originally, video.c did not access any CMS things (other than lut3d
being set on it), but this has changed. In practice, almost all accesses
to it have moved to video.c. vo_opengl only created it, and set the auto
icc profile path.

Complete the move.

Some things wrt. option handling are a bit fishy. (But when is this not
the case.)

icc-profile-auto was not tested, but the distributed human CI will take
care of it.
2016-06-03 20:35:22 +02:00
wm4
2179879172 vo_opengl: move struct lut3d definition
This was dumb. Also, lcms.h has actually no need to include video.h
besides this and csputils.h (makes it slightly less entangled).
2016-06-03 20:06:29 +02:00
wm4
2d76c145c3 vo_opengl: fix giant memory leaks with icc profiles
Well this was dumb.
2016-06-03 20:03:49 +02:00
Rostislav Pehlivanov
e44882d792 wayland: mark existing dnd entry print as debug rather than an error
It gets printed on every alt+tab or desktop switch under mutter and
weston, and offers no useful information since it's handled by
destroying the previous entry.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2016-05-31 11:22:57 +02:00
Rostislav Pehlivanov
29ea6e5e4a wayland: correctly report display refresh rate
This commit will cause the wayland backend and vo to correctly report
the display frame rate. This didn't work as VOCTRL_GET_DISPLAY_FPS was
received way too early, before the window was created (and thus
current_output set).

The VO will now signal VO_EVENT_WIN_STATE after window initialization
and upon a resize.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2016-05-31 11:22:55 +02:00
Niklas Haas
68c77d955f vo_opengl: default hdr-tone-mapping to hable
This algorithm works really well. Setting it is a much better
"out-of-the-box" experience than just clipping, which will always look
ugly.

In other words, with this default, users of mpv will just be able to
play HDR content without even realizing it's HDR (pretty much).
2016-05-30 20:17:35 +02:00
Niklas Haas
45c3e0f0d0 vo_opengl: refactor HDR mechanism
Instead of doing HDR tone mapping on an ad-hoc basis inside
pass_colormanage, the reference peak of an image is now part of the
image params (alongside colorspace, gamma, etc.) and tone mapping is
done whenever peak_src != peak_dst.

To get sensible behavior when mixing HDR and SDR content and displays,
target-brightness is a generic filler for "the assumed brightness of SDR
content".

This gets rid of the weird display_scaled hack, sets the framework
for multiple HDR functions with difference reference peaks, and allows
us to (in a future commit) autodetect the right source peak from
the HDR metadata.

(Apart from metadata, the source peak can also be controlled via
vf_format. For HDR content this adjusts the overall image brightness,
for SDR content it's like simulating a different exposure)
2016-05-30 20:17:33 +02:00
Rostislav Pehlivanov
098ff4174c wayland: implement HIDPI support
The wayland protocol exposes scaling done by the compositor to
compensate for small window sizes on small high DPI displays. If the
program ignores the scaling done, what'll happen is the compositor is
going to ask the program to be scaled down by N times the window size and
then it'll upscale the program's surface by N times. The scaling
algorithm seems to be bilinear so the scaling is quite obvious.

This commit sets up callbacks to listen for the scaling factor of each
output and, on rescale events, notifies the compositor that the
surface's scale is what the compositor asked for and changes the
player's surface to the appropriate size, causing no scaling to be done
by the compositor.

Compositors not supporting this interface will ignore the callbacks and do
nothing, keeping program behaviour the same. For compositors supporting
and using this interface (mutter), this will fix the rendering to be pixel
precise as it should be.

Both the opengl wayland backend and the wayland vo have been fixed to support
this. Verified to not break either on weston and mutter.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
2016-05-30 20:17:26 +02:00
Niklas Haas
15bb05d2fe vo_opengl: add hable tone-mapping algorithm
Developed by John Hable for use in Uncharted 2. Also used by Frictional
Games in SOMA. Originally inspired by a filmic tone mapping algorithm
created by Kodak.

From http://frictionalgames.blogspot.de/2012/09/tech-feature-hdr-lightning.html
2016-05-30 16:58:25 +02:00
Niklas Haas
48015009b7 vo_opengl: rename tone-mapping=simple to reinhard
This is the canonical name for the algorithm. I simply didn't know it
before.
2016-05-30 16:58:22 +02:00
maniak1349
899d3e55b3 w32_common: center window on original window center on video resize
Position the window around the original window center on video size change
(when switching to the next file with different resolution, for example)
instead of keeping the position of its top-left corner fixed.
2016-05-30 16:58:07 +02:00
wm4
0348cd080f video: remove d3d11 video processor use from OpenGL interop
We now have a video filter that uses the d3d11 video processor, so it
makes no sense to have one in the VO interop code. The VO uses it for
formats not directly supported by ANGLE (so the video data is converted
to a RGB texture, which ANGLE can take in).

Change this so that the video filter is automatically inserted if
needed. Move the code that maps RGB surfaces to its own inteorp backend.
Add a bunch of new image formats, which are used to enforce the new
constraints, and to automatically insert the filter only when needed.

The added vf mechanism to auto-insert the d3d11vpp filter is very dumb
and primitive, and will work only for this specific purpose. The format
negotiation mechanism in the filter chain is generally not very pretty,
and mostly broken as well. (libavfilter has a different mechanism, and
these mechanisms don't match well, so vf_lavfi uses some sort of hack.
It only works because hwaccel and non-hwaccel formats are strictly
separated.)

The RGB interop is now only used with older ANGLE versions. The only
reason I'm keeping it is because it's relatively isolated (uses only
existing mechanisms and adds no new concepts), and because I want to be
able to compare the behavior of the old code with the new one for
testing. It will be removed eventually.

If ANGLE has NV12 interop, P010 is now handled by converting to NV12
with the video processor, instead of converting it to RGB and using the
old mechanism to import that as a texture.
2016-05-29 19:00:55 +02:00
James Ross-Gowan
9eccedf447 vo_opengl: angle: enable DirectComposition
This avoids a copy of the video image and lowers vsync jitter. Since
there are now two options to add to the window_attribs list, it has been
made dynamic.
2016-05-29 01:55:10 +10:00
Niklas Haas
f8df0528b5 vo_opengl: skip junk before first user shader pass
A lot of real-world shaders start off with comments explaining the usage
or license, generating lots of "empty" passes. This simply change allows
us to skip them, which silences the warning spam and prevents us from
having to store and copy around these empty passes.

It also adds a more useful failure check: Attempting to use a user
shader that doesn't define any passes at all.
2016-05-27 17:03:00 +02:00
James Ross-Gowan
84fba1df21 vo_opengl: enable color management on GLES
This requires the GL_EXT_texture_norm16 extension and works in ANGLE.
A default precision had to be set for sampler3Ds, otherwise the shaders
would fail to compile.
2016-05-27 23:02:26 +10:00
wm4
306c554376 vo_opengl: fix superxbr shader compilation on ES
ES shaders do not allow implicit conversion from int to float, which
is the most annoying ES anti-feature ever.
2016-05-26 08:21:10 +02:00
wm4
e5f49d9685 vo_opengl: always autoselect ANGLE as backend if available
Remove the opengl-hq option default that caused it not to autoselect
ANGLE (unlike --vo=opengl). Details see commit d5df90a2.

Back then the intention was to use ANGLE by default, since it integrates
much nicer with the Windows compositor (instead of native OpenGL, which
tends to cause crazy glitches). On the other hand, many opengl-hq
capabilities are not available with older ANGLE builds, so it didn't
make any sense to autoselect ANGLE for it.

With the GL_EXT_texture_norm16 extension recently added to ANGLE, it has
essentially reached feature parity to desktop GL for the subset we are
using. (Even the integer texture hack for high bit depth input could be
dropped now.)

It (probably) still does not support nnedi3, due to the weird way the NN
coefficients are imported. Also, it uses half-floats instead of 16 bit
fixed-point textures for technical reasons, which implies about 5 bits
of precision loss. If anyone actually manages to distinguish the two
dithering texture formats in a double-blind test, I will fix it.
2016-05-26 00:07:10 +02:00
wm4
8ff96f0216 hwdec_d3d11egl: call ID3D11DeviceContext::Flush
This must be called if a texture shared between D3D devices is updated.

Often enough, the shared devices will be the same device, but ANGLE
forces using shared surfaces. I suppose there is no guarantee the driver
will do the expected thing. Internally, the driver could for example not
insert the required barriers before the shared texture is used.
2016-05-24 14:30:15 +02:00
dequis
d941a57bd3 vo_xv: Handle incorrect size returned by Xv(Shm)CreateImage
Fixes #320 (which is closed as 'not our problem' but eh)

Relevant xorg bug: https://bugs.freedesktop.org/show_bug.cgi?id=70931

For me this happened when (accidentally) trying to play a 8460x2812 jpg
file with mpv. Like the referenced bug, xvinfo reports "maximum XvImage
size: 8192 x 8192". So the returned XvImage is 8192x2812 and memory
corruption happens.

Only after handling this BadShmSeg X11 errors are shown.
2016-05-24 10:25:39 +02:00
wm4
c4707cdee6 vo_opengl: fix other minor namespace issues
See previous commit.
2016-05-23 21:27:18 +02:00
wm4
e76aa7e8db vo_opengl: rename glUploadTex, drop unused parameter
Rename it to get out of OpenGL's namespace. The gl_ prefix is used by
other mpv functions, but no OpenGL ones.

The "slice" parameter was never actually used, and all callers passed 0
for it.
2016-05-23 21:27:18 +02:00
wm4
66079048ea vo_opengl: unify PBO and normal OSD texture upload path
The main change is actually that e first copy to a "staging" memory
frame, and then upload this at once. The old non-PBO code called
glTexsubImage2D for each OSD sub-bitmap.

The new non-PBO code path is a bit faster now if there are many small
sub-bitmaps (on Linux/nVidia). It's also a bit simpler, so this is a
win.

(Although I don't particularly appreciate the mixed normal/PBO texture
code.)
2016-05-23 21:27:18 +02:00
wm4
049e3ccb65 vo_opengl: make ES float texture format checks stricter
Some of these checks became pointless after dropping ES 2.0 support for
extended filtering.

GL_EXT_texture_rg is part of core in ES 3.0, and we already check for
this version, so testing for the extension is redundant.

GL_OES_texture_half_float_linear is also always available, at least as
far as our needs go.

The functionality we need from GL_EXT_color_buffer_half_float is always
available in ES 3.2, and we explicitly check for ES 3.2, so reject this
extension if the ES version is new enough.
2016-05-23 21:27:18 +02:00
wm4
80d702dce8 vo_opengl: make PBOs work on GLES 3.x
For some reason, GLES has no glMapBuffer, only glMapBufferRange.

GLES 2 has no buffer mapping at all, and GL 2.1 does not always have
glMapBufferRange. On those PBOs remain unsupported (there's no reason to
care about GL 2.1 without the extension).

This doesn't actually work on ANGLE, and I have no idea why. (There are
artifacts on OSD, as if parts of the OSD data weren't copied.) It works
on desktop OpenGL and at least 1 other ES 3 implementation. Don't enable
it on ANGLE, I guess.
2016-05-23 21:27:18 +02:00
wm4
75f373cc46 vo_opengl: remove unused glDrawBuffer 2016-05-23 21:27:18 +02:00
wm4
cc72a4e8c3 vo_opengl: support framebuffer invalidation
Not sure how much can be gained with this, as we can't use it properly
yet. For now, this is used only before rendering, which probably does
overwhelmingly nothing.

In the future, this should be used after temporary passes, which could
possibly reduce memory usage and even memory bandwidth usage, depending
on the drivers.
2016-05-23 21:27:18 +02:00
wm4
cc4a0571fa vo_opengl: slightly improve logging of loaded extensions
Only log when actual extensions are loaded, never log anything about
builtins.
2016-05-23 21:27:18 +02:00
maniak1349
5a3c299ca1 w32_common: make VOCTRL_SET_UNFS_WINDOW_SIZE resize the window around its center
Before that position of the window top-left corner was remaining the same
when the window was scaled.

Right now VOCTRL_SET_UNFS_WINDOW_SIZE is called only by window-scale. This
change will not affect resizes made by the user (dragging window edge).

Fixes #3164.
2016-05-22 14:31:37 +02:00
maniak1349
364af7c630 w32_common: center window on original window center on resize to fit screen
Center the window on the original window center instead of the screen center
when the window has been resized due to requested window size exceeding the
size of the screen.

If user moved the window, he probably did it for the reason and he probably
don't want it to get back to the center of the screen when he is resizing it
(with window-scale for example).
2016-05-22 14:31:37 +02:00
maniak1349
981048e041 w32_common: update stored client area size on window resize
Properly update stored client area size when the window is resized in
reinit_window_state due to window size exceeding the size of the screen.

This was causing wrong behavior with window-scale - when window size was
becoming too big the window was resized but the video was not.
2016-05-22 14:31:37 +02:00
wm4
79afa347cc vo_opengl: remove non-working rgb/rgba FBO formats
Following commit 84ccebd9, the internal helpers don't allow GL_RGB and
GL_RGBA as internal formats for FBO attachments anymore.

While OpenGL itself is perfectly fine with it, I don't see much of a
reason to bother, and mixing sized and unsized internal formats is
confusing anyway.

Just remove these formats.
2016-05-20 23:21:43 +02:00
wm4
05b3a8cd14 vo_opengl: require at least ES 3.0 for float textures
ES 2.0 has this weird rule that not the internalformat parameter
determines the internal format, but the combination of all texture
parameters. GL_OES_texture_half_float thus does not specify e.g. a
GL_RGBA16F format, but requires passing GL_RGBA as format and
GL_HALF_FLOAT_OES as type. We won't bother with this, since ES 2.0 is a
lost cause anyway.

This also removes the OpenGL error when the code is trying to create a
f16 FBO for testing whether FBOs work.
2016-05-19 17:52:09 +02:00
wm4
561630cb01 vo_opengl: change error state handling and fix hwdec crashes on errors
gl_video_upload_image() can fail in the hardware decoding case. In this
case rendering continued "normally", which meant that pass_get_img_tex()
would kill the process with an assertion failure.

Fix this by allowing gl_video_upload_image() to fail, and exit rendering
early enough to skip code which requires an image to be present. (Maybe
this is still a bit too subtle, but better than before.)

Set an error flag, and render the blue screen we introduced for shader
errors. (For this purpose also move the rendering of it to final output,
to ensure it's visible at all.) The error flag is temporary, because the
associated failure might also be temporary, unlike shader compilation
errors.
2016-05-19 12:18:48 +02:00
wm4
4e5f1ec00e vo_opengl: d3d11egl: enable "required" GLSL extensions
ANGLE doesn't handle this very strictly. But if they change this in the
future, it shouldn't brick us.

Not quite happy with this glsl_extensions fields, but it is quite
unintrusive after all.
2016-05-19 12:02:08 +02:00
wm4
b0d3c2ede7 vo_opengl: make gl_sc_enable_extension() permanent/idempotent
No reason not to, and makes the following commit slightly simpler.

In fact, this makes the shaders more correct too. Normally, "#extension"
must come before any normal shader text, including the "precision"
directive. Not sure why this worked before. (Probably didn't.)
2016-05-19 12:01:59 +02:00
wm4
b46eaa3b43 vo_opengl: d3d11egl: enable direct nv12 sampling on ES 3.x
ANGLE was missing texture() overloads in the shader compiler for
GL_TEXTURE_EXTERNAL_OES textures. Support has been added upstream,
so we can use it now.
2016-05-19 10:43:57 +02:00
wm4
5f7bd411fb vo_opengl: remove unused field 2016-05-18 18:22:27 +02:00
wm4
0b911792ca vo_opengl: fix/simplify reinitialization on dynamic reconfiguration
With the new hooks mechanism, user shaders and such are actually loaded
before rendering starts, instead of being loaded during rendering. This
is used to cache them (instead of e.g. reparsing them every frame).

The cached state wasn't cleared correctly in some situations. Namely,
resizing didn't correctly enable/disable prescale hooks.

Reorganize how these reinitializations are handled. Get rid of
reinit_rendering(), whose meaning was pretty unclear. Call the required
functions to reset or recreate state directly wherever they are needed.
2016-05-18 17:47:10 +02:00
wm4
9b56bbecdf vo_opengl: hwdec: remove build-dependency on dxva2
wscript builds hwdec_dxva2gldx.c if gl-dxinterop is enabled, while
video/dxva2.c depends on d3d-hwaccel. If d3d-hwaccel is disabled, then
hwdec_dxva2gldx.c will fail to link, because it uses
d3d9_surface_in_mp_image(), defined in dxva2.c.

Fix this by removing the use of this function. It has barely any value
at this point anyway. Just use the libavcodec documented way to get the
surface directly.

Fixes #3150.
2016-05-17 10:59:11 +02:00
wm4
a2d58d9986 vo_opengl: move UT_buffer to switch handling
No reason to make it a special case.
2016-05-17 10:48:05 +02:00
wm4
f00040b9fc vo_opengl: make number of cached shaders/uniform dynamic
Use dynamic memory allocation, as the static allocation is starting to
get annoying.

Currently, SC_MAX_ENTRIES is essentially still a static upper limit on
the number of shaders. But in future we could try a more clever cache
replacement strategy, which does not keep stale entries forever if the
maximum happens not to be reached.
2016-05-17 10:45:01 +02:00
wm4
09763bef83 vo_opengl: move cached uniforms to a separate struct 2016-05-17 10:33:45 +02:00
Niklas Haas
8262a4dd52 vo_opengl: increase shader limits
The new uniforms introduced by 362015c have exceeded the uniform limit
when using high-radius tscale. In addition, the SC limit of 32 entries
might be pushing it with user shaders.

Just make these value a bigger to delay the onset of this same failure
mode. Maybe in the future it should be reworked to grow dynamically?
Either way, we *can* always predict a static upper bound on the number
of uniforms and shader cache entries, it's just that we forgot to do so.

Fixes #3151
2016-05-17 10:09:01 +02:00
Niklas Haas
e73c83d3df
vo_opengl: skip tonemapping if the output trc is HDR
This makes it so that users with actual HDR displays can just set their
config to target-trc=st2084 and get native HDR output. This will look a
bit silly for SDR content (everything will be really bright), but for
lack of a better tone mapping situation (including reverse tone mapping)
this is the easiest thing to do for now.

Ideally the brightness metadata should be part of the colorspace struct
or something (with mpv always adapting where necessary), but it depends
on the TRC and not the primaries so it's a bit more complicated than
that.
2016-05-16 14:42:45 +02:00
Niklas Haas
e6f6ae94f3
vo_opengl: copy over HDR parameters to dumb_mode
Since dumb mode is affected by tone mapping (which I'll call a feature,
not a bug), we need to copy over the configuration - in particular, the
defaults. (To prevent a render failure)
2016-05-16 14:20:48 +02:00
Niklas Haas
3bdbf6274c
vo_opengl: fall back to gamma2.2 by default for HDR content
Since HDR content is now auto-detected as such, we should probably do
something smarter in the "no configuration" case, such as outputting
gamma 2.2 instead.

This decision will affect the majority of users of stock configurations
who just play back appropriately tagged HDR files, so having a good
default behavior is important. "Output the HDR content as-is" is
definitely not likely to give the user a good result.
2016-05-16 14:07:39 +02:00
wm4
887b2cc30f vo_opengl: remove unnecessary casts 2016-05-16 12:58:09 +02:00
wm4
1bc902336a vo_opengl: remove another unneeded allocation 2016-05-16 12:54:45 +02:00
wm4
51307e9f18 vo_opengl: remove possibly undefined behavior 2016-05-16 12:53:45 +02:00
wm4
70df6aa375 vo_opengl: free to-be-added hook on hook array overflow
Seems sensible.

Untested.
2016-05-16 12:51:36 +02:00
wm4
155857dbe6 vo_opengl: never clear file cache
Make it dynamic and never remove entries from it.

For now, this is better than possibly creating dangling pointers all
over the place in the gl_user_shader struct.

Untested.
2016-05-16 12:51:26 +02:00
wm4
0c40eee479 vo_opengl: use proper include statement 2016-05-16 12:44:12 +02:00
wm4
dd99c1e3b4 vo_opengl: remove unnecessary allocation 2016-05-16 12:42:08 +02:00
wm4
56ed5bf1c7 vo_opengl: remove unused global variable
?
2016-05-16 12:41:55 +02:00
wm4
51603e472d vo_opengl: fix bicubic_fast in ES mode
GLES shaders disallow implicit conversion from int to float.

This has been broken for quite a while.
2016-05-16 12:10:47 +02:00
Niklas Haas
e047cc0931 vo_opengl: implement more HDR tonemapping algorithms
This is now a configurable option, with tunable parameters.

I got inspiration for these algorithms off wikipedia. "simple" seems to
work pretty well, but not well enough to make it a reasonable default.

Some other notable candidates:

- Local functions (e.g. based on local contrast or gradient)
- Clamp with soft knee (linear up to a point)
- Mapping in CIE L*Ch. Map L smoothly, clamp C and h.
- Color appearance models

These will have to be implemented some other time.

Note that the parameter "peak_src" to pass_tone_map should, in
principle, be auto-detected from the SEI information of the source file
where available. This will also have to be implemented in a later
commit.
2016-05-16 02:49:49 +02:00
Niklas Haas
3cfe98c684 vo_opengl: avoid redundant double-gamma conversion
Due to the way color management in mpv worked historically, the subtitle
blending function was written to preserve the linearity of the input.
(In the past, the 3DLUT function required linear inputs)

Since the 3DLUT was refactored to accept the video color directly, the
re-linearization after blending is now virtually always redundant.
(Notably, it's also redundant when CMS is turned off, so this way of
writing the code stopped making sense a long time ago. It is a remnant
from before the pass_colormanage function was as flexible as it is now)
2016-05-16 02:45:39 +02:00
Niklas Haas
f81f486c68 vo_opengl: implement HDR (SMPTE ST2084)
Currently, this relies on the user manually entering their display
brightness (since we have no way to detect this at runtime or from ICC
metadata). The default value of 250 was picked by looking at ~10 reviews
on tftcentral.co.uk and realizing they all come with around 250 cd/m^2
out of the box. (In addition, ITU-R Rec. BT.2022 supports this)

Since there is no metadata in FFmpeg to indicate usage of this TRC, the
only way to actually play HDR content currently is to set
``--vf=format=gamma=st2084``. (It could be guessed based on SEI, but
this is not implemented yet)

Incidentally, since SEI is ignored, it's currently assumed that all
content is scaled to 10,000 cd/m^2 (and hard-clipped where out of
range). I don't see this assumption changing much, though.

As an unfortunate consequence of the fact that we don't know the display
brightness, mixed with the fact that LittleCMS' parametric tone curves
are not flexible enough to support PQ, we have to build the 3DLUT
against gamma 2.2 if it's used. This might be a good thing, though,
consdering the PQ source space is probably not fantastic for
interpolation either way.

Partially addresses #2572.
2016-05-16 02:45:39 +02:00
Niklas Haas
965031ccd5 vo_opengl: use enums for choice options internally
This is much more readable than hard-coding magic IDs all over the file,
and removes the need for all the explanatory comments that were a direct
result of this.
2016-05-16 02:45:39 +02:00
Niklas Haas
362015cd77
vo_opengl: abstract hook texture access behind macro
This macro takes care of rotation, swizzling, integer conversion and
normalization automatically. I found the performance impact to be
nonexistant for superxbr and debanding, although rotation *did* have an
impact due to the extra matrix multiplication. (So it gets skipped where
possible)

All of the internal hooks have been rewritten to use this new mechanism,
and the prescaler hooks have finally been separated from each other.
This also means the prescale FBO kludge is no longer required.

This fixes image corruption for image formats like 0bgr, and also fixes
prescaling under rotation. (As well as other user hooks that have
orientation-dependent access)

The "raw" attributes (tex, tex_pos, pixel_size) are still un-rotated, in
case something needs them, but ideally the hooks should be rewritten to
use the new API as much as possible. The hooked texture has been renamed
from just NAME to NAME_raw to make script authors notice the change (and
also deemphasize direct texture access).

This is also a step towards getting rid of the use_integer pass.
2016-05-15 20:42:08 +02:00
Niklas Haas
dfc7b59909 vo_opengl: make the screen blue on shader errors
This helps visually signify that somthing went wrong, and prevents
confusing shader compilation errors with other types of bugs.
2016-05-15 20:42:02 +02:00
Niklas Haas
034faaa9d8 vo_opengl: use RPN expressions for user hook sizes
This replaces the previous TRANSFORM by WIDTH, HEIGHT and OFFSET where
WIDTH and HEIGHT are RPN expressions. This allows for more fine-grained
control over the output size, and also makes sure that overwriting
existing textures works more cleanly.

(Also add some more useful bstr functions)
2016-05-15 20:42:02 +02:00
Niklas Haas
7c3d78fd82 vo_opengl: support external user hooks
This allows users to add their own near-arbitrary hooks to the vo_opengl
processing pipeline, greatly enhancing the flexibility of user shaders.
This enables, among other things, user shaders such as CrossBilateral,
SuperRes, LumaSharpen and many more.

To make parsing the user shaders easier, shaders are now loaded as
bstrs, and the hooks are set up during video reconfig instead of on
every single frame.
2016-05-15 20:42:02 +02:00
Niklas Haas
d53142f9ba vo_opengl: add optional hook points
These are "sequence points" where the image could be rendered out to an
FBO, hooked, and re-loaded if any such hook exists. This is perfect for
things like the current user shaders system, as well as optional effects
like unsharp masking.

Note that since we have to pick *some* FBO to store the optionally
hooked texture, we just store it in an array indexed by an increasing
counter. Since we only ever store as many as MAX_TEXTURE_HOOKS + all
internal hook points entries, this is guaranteed to be enough space.

This commit also removes some of the now unused FBOs.
2016-05-15 20:42:02 +02:00
Niklas Haas
070edd7300 vo_opengl: add hooks and rework pass_read_video
The hook mechanism allows arbitrary processing stages to get dispatched
whenever certain named textures have been "finalized" by the code.

This is mostly meant to serve as a change that opens up the internal
processing in pass_read_video to user scripts, but as a side benefit all
of the code dealing with offsets and plane alignment and other such
confusing things has been rewritten.

This hook mechanism is powerful enough to cover the needs of both
debanding and prescaling (and more), so as a result they can be removed
from pass_read_video entirely and implemented through hooks.

Some avenues for optimization:

- The prescale hook is currently somewhat distributed code-wise. It might be
  cleaner to split it into superxbr and NNEDI3 hooks which can each be
  self-contained.

- It might be possible to move a large part of the hook code out to an
  external file (including the hook definitions for debanding and
  prescaling), which would be very much desired.

- Currently, some stages (chroma merging, integer conversion) will
  *always* run even if unnecessary. I'm planning another series of
  refactors (deferred img_tex) to allow dropping unnecessary shader
  stages like these, but that's probably some ways away. In the meantime
  it would be doable to re-add some of the logic to skip these stages if
  we know we don't need them.

- More hook locations could be added (?)
2016-05-15 20:42:02 +02:00
Niklas Haas
3d4889e91e vo_opengl: minor change to scaler_resizes_only
Instead of rounding down, we round to the nearest float. This reduces
the maximum possible error introduced by this rounding operation. Also
clarify the comment.
2016-05-15 20:42:02 +02:00