summaryrefslogtreecommitdiffstats
path: root/video/out/opengl/video.c
Commit message (Collapse)AuthorAgeFilesLines
* vo_opengl: refactor into vo_gpuNiklas Haas2017-09-211-3813/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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_swchain_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 8. move ra->fns->flush to ra_gl_ctx instead 9. some other minor changes that I've probably already forgotten Note: This is one half of a major refactor, the other half of which is provided by rossy's following commit. This commit enables support for all linux platforms, while his version enables support for all non-linux platforms. Note 2: vo_opengl_cb.c also re-uses ra_gl_ctx so it benefits from the --opengl- options like --opengl-early-flush, --opengl-finish etc. Should be a strict superset of the old functionality. Disclaimer: Since I have no way of compiling mpv on all platforms, some of these ports were done blindly. Specifically, the blind ports included context_mali_fbdev.c and context_rpi.c. Since they're both based on egl_helpers, the port should have gone smoothly without any major changes required. But if somebody complains about a compile error on those platforms (assuming anybody actually uses them), you know where to complain.
* vo_opengl: add a gamut warning featureNiklas Haas2017-09-101-1/+2
| | | | | | | | This clearly highlights all out-of-gamut/clipped pixels. (Either too bright or too saturated) Has some (documented) caveats. Also make TONE_MAPPING_CLIP stop actually clamping the value range (it's unnecessary and breaks this feature).
* vo_opengl: add support for vulkan GLSL dialectNiklas Haas2017-09-041-1/+1
| | | | | | | | | | Redefining texture1D / texture3D seems to be illegal, they are already built-in macros or something. So just use tex1D and tex3D instead. Additionally, GL_KHR_vulkan_glsl requires using explicit vertex locations and bindings, so make some changes to facilitate this. (It also requires explicitly setting location=0 for the color attachment output)
* vo_opengl: use rgba16 for 3DLUTs instead of rgb16Niklas Haas2017-09-041-2/+2
| | | | | | | Vulkan compat. rgb16 doesn't exist on hardware anyway, might as well just generate the 3DLUT against rgba16 as well. We've decided this is the simplest way to do vulkan compatibility: just make sure we never actually need 3-component textures.
* vo_opengl: refactor scaler LUT weight packing/loadingNiklas Haas2017-09-041-13/+8
| | | | | | | | This is mostly done so we can support using textures with more components than the scaler LUTs have entries. But while we're at it, also change the way the weights are packed so that they're always sequential with no gaps. This allows us to simplify pass_sample_separated_get_weights as well.
* vo_opengl: scale deband-grain to the signal rangeNiklas Haas2017-09-031-1/+2
| | | | | This prevents blowing up for high dynamic range sources, where a noise level of 48 can suddenly mean 4800.
* vo_opengl: fix overlay mode (again)wm42017-08-301-7/+8
| | | | Did I mention yet that I regret this overlay mode thing?
* vo_opengl: don't discard buffered video on redundant resize callswm42017-08-291-0/+5
| | | | | | | | | | If a VO-area option changes, gl_video_resize() is called unconditionally. This function does something even if the size does not change (at least it discards buffered frames for interpolation), which can lead to stutter when you keep firing option change events during playback. Check for an actual resize, and if nothing changes, exit early.
* video: redo video equalizer option handlingwm42017-08-221-20/+3
| | | | | | | | | | | | | | | | | | | | | | | I really wouldn't care much about this, but some parts of the core code are under HAVE_GPL, so there's some need to get rid of it. Simply turn the video equalizer from its current fine-grained handling with vf/vo fallbacks into global options. This makes updating them much simpler. This removes any possibility of applying video equalizers in filters, which affects vf_scale, and the previously removed vf_eq. Not a big loss, since the preferred VOs have this builtin. Remove video equalizer handling from vo_direct3d, vo_sdl, vo_vaapi, and vo_xv. I'm not going to waste my time on these legacy VOs. vo.eq_opts_cache exists _only_ to send a VOCTRL_SET_EQUALIZER, which exists _only_ to trigger a redraw. This seems silly, but for now I feel like this is less of a pain. The rest of the equalizer using code is self-updating. See commit 96b906a51d5 for how some video equalizer code was GPL only. Some command line option names and ranges can probably be traced back to a GPL only committer, but we don't consider these copyrightable.
* options: add a thread-safe way to notify option updateswm42017-08-221-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | So far, we had a thread-safe way to read options, but no option update notification mechanism. Everything was funneled though the main thread's central mp_option_change_callback() function. For example, if the panscan options were changed, the function called vo_control() with VOCTRL_SET_PANSCAN to manually notify the VO thread of updates. This worked, but's pretty inconvenient. Most of these problems come from the fact that MPlayer was written as a single-threaded program. This commit works towards a more flexible mechanism. It adds an update callback to m_config_cache (the thing that is already used for thread-safe access of global options). This alone would still be rather inconvenient, at least in context of VOs. Add another mechanism on top of it that uses mp_dispatch_queue, and takes care of some annoying synchronization issues. We extend mp_dispatch_queue itself to make this easier and slightly more efficient. As a first application, use this to reimplement certain VO scaling and renderer options. The update_opts() function translates these to the "old" VOCTRLs, though. An annoyingly subtle issue is that m_config_cache's destructor now releases pending notifications, and must be released before the associated dispatch queue. Otherwise, it could happen that option updates during e.g. VO destruction queue or run stale entries, which is not expected. Rather untested. The singly-linked list code in dispatch.c is probably buggy, and I bet some aspects about synchronization are not entirely sane.
* vo_opengl: refactor tex_upload to ra_buf_poolNiklas Haas2017-08-221-5/+6
| | | | | | | | | | Also refactors the usage of tex_upload to make ra_tex_upload_pbo a RA-internal thing again. ra_buf_pool has the main advantage of being dynamically sized depending on buf_poll, so for OpenGL we'll end up only using one buffer (when not persistently mapping) - while for vulkan we'll use as many as necessary, which depends on the swapchain depth anyway.
* vo_opengl: refactor RA texture and buffer updatesNiklas Haas2017-08-181-16/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - tex_uploads args are moved to a struct - the ability to directly upload texture data without going through a buffer is made explicit - the concept of buffer updates and buffer polling is made more explicit and generalized to buf_update as well (not just mapped buffers) - the ability to call tex_upload/buf_update on a tex/buf is made explicit during tex/buf creation - uploading from buffers now uses an explicit offset instead of implicitly comparing *src against buf->data, because not all buffers may actually be persistently mapped - the initial_data = immutable requirement is dropped. (May be re-added later for D3D11 if that ever becomes a thing) This change helps the vulkan abstraction immensely and also helps move common code (like the PBO pooling) out of ra_gl and into the opengl/utils.c This also technically has the side-benefit / side-constraint of using PBOs for OSD texture uploads as well, which actually seems to help performance on machines where --opengl-pbo is faster than the naive code path. Because of this, I decided to hook up the OSD code to the opengl-pbo option as well. One drawback of this refactor is that the GL_STREAM_COPY hack for texture uploads "got lost", but I think I'm happy with that going away anyway since DR almost fully deprecates it, and it's not the "right thing" anyway - but instead an nvidia-only hack to make this stuff work somewhat better on NUMA systems with discrete GPUs. Another change is that due to the way fencing works with ra_buf (we get one fence per ra_buf per upload) we have to use multiple ra_bufs instead of offsets into a shared buffer. But for OpenGL this is probably better anyway. It's possible that in future, we could support having independent “buffer slices” (each with their own fence/sync object), but this would be an optimization more than anything. I also think that we could address the underlying problem (memory closeness) differently by making the ra_vk memory allocator smart enough to chunk together allocations under the hood.
* vo_opengl: remove redundant #defines in unsharp_hookNiklas Haas2017-08-171-3/+0
| | | | These are no longer valid anyway, and the code doesn't use them.
* vo_rpi: fix operationwm42017-08-151-0/+5
| | | | Commit 697c4389a9e6 worked "almost". I couldn't test it at the time.
* vo_opengl: remove DR image layouting code to rendererwm42017-08-141-3/+27
| | | | No reason to have it in a higher level.
* rpi: fix buildwm42017-08-111-1/+19
| | | | | | | | | | | Runtime untested, because I get this: [vo/rpi] Could not get DISPMANX objects. This happened even when building older git versions, and on a RPI image that hasn't changed in the recent years. I don't know how to make this POS work again, so I guess if there's a bug in the new code, it will remain broken.
* vo_opengl: remove some indirect GL header inclusions from core rendererwm42017-08-101-3/+0
|
* vo_opengl: separate hwdec context and mapping, port it to use rawm42017-08-101-40/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This does two separate rather intrusive things: 1. Make the hwdec context (which does initialization, provides the device to the decoder, and other basic state) and frame mapping (getting textures from a mp_image) separate. This is more flexible, and you could map multiple images at once. It will help removing some hwdec special-casing from video.c. 2. Switch all hwdec API use to ra. Of course all code is still GL specific, but in theory it would be possible to support other backends. The most important change is that the hwdec interop returns ra objects, instead of anything GL specific. This removes the last dependency on GL-specific header files from video.c. I'm mixing these separate changes because both requires essentially rewriting all the glue code, so better do them at once. For the same reason, this change isn't done incrementally. hwdec_ios.m is untested, since I can't test it. Apart from superficial mistakes, this also requires dealing with Apple's texture format fuckups: they force you to use GL_LUMINANCE[_ALPHA] instead of GL_RED and GL_RG. We also need to report the correct format via ra_tex to the renderer, which is done by find_la_variant(). It's unknown whether this works correctly. hwdec_rpi.c as well as vo_rpi.c are still broken. (I need to pull my RPI out of a dusty pile of devices and cables, so, later.)
* vo_opengl: shrink the hwdec overlay APIwm42017-08-091-6/+4
| | | | | Just remove one callback, and fold the functionality into the other one. RPI will still not compile, so the hwdec_rpi.c changes are untested.
* vo_opengl: call ra_free() in the correct contextwm42017-08-071-1/+0
| | | | This also fixes a double free in vo_opengl_cb.c.
* vo_opengl: further GL API use separationwm42017-08-071-87/+36
| | | | | | | | | | | | | | | Move multiple GL-specific things from the renderer to other places like vo_opengl.c, vo_opengl_cb.c, and ra_gl.c. The vp_w/vp_h parameters to gl_video_resize() make no sense anymore, and are implicitly part of struct fbodst. Checking the main framebuffer depth is moved to vo_opengl.c. For vo_opengl_cb.c it always assumes 8. The API user now has to override this manually. The previous heuristic didn't make much sense anyway. The only remaining dependency on GL is the hwdec stuff, which is harder to change.
* vo_opengl: simplify mirroring and fix it if glBlitFramebuffer is usedwm42017-08-071-36/+35
| | | | | | | | | | | | | | | | | | The vp_w/vp_h variables and parameters were not really used anymore (they were redundant with ra_tex w/h) - but vp_h was still used to identify whether rendering should be done mirrored. Simplify this by adding a fbodst struct (some bad naming), which contains the render target texture, and some parameters how it should be rendered to (for now only flipping). It would not be appropriate to make this a member of ra_tex, so it's a separate struct. Introduces a weird regression for the first frame rendered after interpolation is toggled at runtime, but seems to work otherwise. This is possibly due to the change that blit() now mirrors, instead of just copying. (This is also why ra_fns.blit is changed.) Fixes #4719.
* vo_opengl: drop pointless fbotex_init() functionwm42017-08-071-1/+1
|
* vo_opengl: generalize ra_buf to support other buffer objectsNiklas Haas2017-08-071-47/+47
| | | | | This allows us to integrate PBOs and SSBOs into the same abstraction, with the potential to easily add UBOs if the need arises.
* vo_opengl: only mark frames as fresh if they contain a new imageNiklas Haas2017-08-061-1/+1
| | | | | | | When using dumb mode, we can actually redraw a frame without uploading it. Marking this as fresh as well results in unpredictable pass behavior, which is confusing and makes debugging harder. So mark it as a redraw instead, in that case.
* vo_opengl: measure pass_draw_osd as a wholeNiklas Haas2017-08-061-1/+8
| | | | | | | | | | | | | | In the past, this always measured the per-shader execution times of the individual OSD parts, which was thrown off because the shader was reused anyway. (And apparently recording the OSD shader execution times was removed completely, probably because of them being so unrealiably anyway) Since ra_timer no longer has the restriction of not allowing timers to run concurrently, we can just wrap the entire OSD block inside a single osd_timer now, and record that. (Technically, this can still be off when using --blend-subtitles=video/yes and showing a full-screen OSD at the same time. Maybe this can be done better?)
* vo_opengl: move timers to struct raNiklas Haas2017-08-061-18/+16
| | | | | | | In order to prevent code duplication and keep the ra abstraction as small as possible, `ra` only implements the actual timer queries, it does not do pooling/averaging of the results. This is instead moved to a ra-neutral struct timer_pool in utils.c.
* vo_opengl: move GL state resetting to vo_opengl_cbwm42017-08-051-18/+0
| | | | | | | | | This code is pretty much for the sake of vo_opengl_cb API users. It resets certain state that either the user or our code doesn't reset correctly. This is somewhat outdated. With GL implicit state being so awfully large, it seems more reasonable require that any code restores the default state when returning to the caller. Some exceptions are defined in opengl_cb.h.
* vo_opengl: move shader handling to rawm42017-08-051-52/+31
| | | | | | | | | | | | | Now all GL-specifics of shader compilation are abstracted through ra. Of course we still have everything hardcoded to GLSL - that isn't going to change. Some things will probably change later - in particular, the way we pass uniforms and textures to the shader. Currently, there is a confusing mismatch between "primitive" uniforms like floats, and others like textures. Also, SSBOs are not abstracted yet.
* vo_opengl: organize ra PBO flag slightly differentlywm42017-08-051-6/+2
| | | | | | | | Instead of having a mutable ra_tex field (and the only one), move the flag to struct ra, since we have only 2 tex_upload user calls anyway, and both want the same PBO behavior. (At first I considered making it a RA_TEX_UPLOAD_ flag, but why bother. PBOs are a terribly GL-specific thing, so we can't expect a reasonable abstraction of it anyway.)
* vo_opengl: make OSD code use ra for textureswm42017-08-051-2/+3
| | | | | | | | | | | | This requires a silly extension to ra_fns.tex_upload: since the OSD texture can be much larger than the actual OSD image data to upload, a mechanism for uploading only to a small part of the texture is needed. Otherwise, we'd have to realloc/copy the data, just to pad it, and then pay for uploading the padding too. The RA_TEX_UPLOAD_DISCARD flag is not interpreted by GL (not sure how you'd tell GL about this), but it clarifies the API and might be helpful if we support other backend APIs in the future.
* vo_opengl: always use GL_TRIANGLES for all primitiveswm42017-08-051-2/+5
| | | | Will make the ra layer _slightly_ simpler.
* vo_opengl: pass ra objects during rendering instead of GL objectswm42017-08-051-139/+91
| | | | | | | | | Another "small" step towards removing GL dependencies from the renderer. This commit generally passes ra_tex objects instead of GL FBO integer IDs to various rendering functions. video.c still manually binds the FBOs when calling shaders. This also happens to fix a memory leak with output_fbo.
* vo_opengl: make fbotex helper use rawm42017-08-051-47/+52
| | | | | | | | Further work removing GL dependencies from the actual video renderer, and moving them into ra backends. Use of glInvalidateFramebuffer() falls away. I'd like to keep this, but it's better to readd it once shader runs are in ra.
* vo_opengl: support embedded ICC profilesNiklas Haas2017-08-031-2/+6
| | | | | | | | | | | | | | | | This currently only works when using lcms-based color management (--icc-profile-*). In principle, we could also support using lcms even when the user has not specified an ICC profile, by generating the profile against a fixed reference (--target-prim/--target-trc) instead. I still might do that some day, simply because 3dlut provides a higher quality conversion than our simple gamut mapping does for stuff like BT.2020, and also because it's now needed to enable embedded ICC profiles. But that would be a separate change, so preserve the status quo for now. (Besides, my opinion is still that you should be using an ICC profile if you care about colors being accurate _at all_)
* vo_opengl: don't precompute texcoord in global scopeNiklas Haas2017-08-031-1/+1
| | | | | | | | | | | Breaks on mesa for whatever reason... even though it doesn't generate a GLSL shader compiler error Shouldn't make a performance difference for us because we cache `pos` anyway, and most compute shaders will probably cache all of their samples to shmem. Might have to re-visit this when we have an actual use case for repeated sampling inside CS though. (RAVU + anti-ringing is a possible candidate for that)
* vo_opengl: make compute shaders more flexibleNiklas Haas2017-08-031-25/+32
| | | | | | This allows users to do their own custom sample writing, mainly meant to address use cases such as RAVU. Also clean up the compute shader code a bit.
* vo_opengl: simplify/fix user shader textureswm42017-08-031-24/+4
| | | | | | | | | | | | | | | | | | | | This broke float textures, which were actually used by some shaders. There were probably some other bugs as well. Lots of code can be avoided by using ra_tex_params directly, so do that. The main change is that COMPONENT/FORMAT are replaced by a single FORMAT directive, which takes different parameters now. Due to the mess with 16/32 bit float textures, and because we want to support other APIs than just GL in the future, it's not really clear how this should be handled, and the nice component/type separation makes things actually harder. So just jump the gun and use the ra_format.name names, which were originally meant mostly for debugging. (This is probably something that will be regretted later.) Still only superficially tested, but seems to work. Fixes #4708.
* vo_opengl: generalize HDR tone mapping to gamut mappingNiklas Haas2017-08-031-4/+5
| | | | | | | | | | | | | | | | | | | | | | Since this code was already written for HDR, and is now per-channel (because it works better for HDR as well), we can actually reuse this to get very high quality gamut mapping without clipping. The only required change is to move the tone mapping from before the gamut map to after the gamut map. Additonally, we need to also account for changes in the signal range as a result of applying the CMS when we compute ref_peak, which is fortunately pretty easy because we only need to consider the case of primaries mapping to themselves. Since `HDR` no longer really makes sense as a label, rename it to `--tone-mapping` in general. Also fits better with `--tone-mapping-desat` etc. Arguably we could also rename `--hdr-compute-peak`, but that option is basically only useful for HDR content anyway because we don't need information about the signal range for gamut mapping. This (finally!) gives us reasonably high quality gamut mapping even in the absence of an ICC profile / 3DLUT.
* vo_opengl: manage user shader textures with rawm42017-07-301-31/+16
| | | | | Drops some features I guess, no idea if those were needed. Untested due to lack of test cases.
* vo_opengl: fix dither texture filterwm42017-07-301-1/+0
| | | | Should be GL_NEAREST, not GL_LINEAR.
* vo_opengl: manage ICC LUT texture via rawm42017-07-291-28/+25
| | | | | Also move the capability check to gl_video_get_lut3d(), because it seems more convenient (ra won't have a _CAP_EXT16).
* vo_opengl: manage scaler LUT textures via rawm42017-07-291-33/+16
| | | | Also fix the RA_CAP_ bitmask nonsense.
* vo_opengl: manage dither texture via rawm42017-07-291-30/+23
| | | | | | | | | Also add some more helpers. Fix the broken math.h include statement. utils.c uses ra_gl.h internals, which it shouldn't, and which will be removed again as soon as this code gets converted to ra fully.
* vo_opengl: do not use GL format conversion on texture uploadwm42017-07-291-16/+16
| | | | | | | | | | | | | | | | | | The dither texture data is created as a float array, but uploaded to a texture with GL_R16 as internal format. We relied on GL to do the conversion from float to uint16_t. Not all GL variants even support this: GLES does not provide this conversion (one of the reasons why this code has a float16 code path). Also, ra is not going to do this. So just convert on the fly. Still keep the float16 texture format fallback, because not all GLES implementations provide GL_R16. There is some possibility that we'll need to provide some kind of upload conversion anyway for float->float16. We still rely on GL doing this implicitly, and all GL variants support it, but with RA there might be the need for explicit conversion. Even then, it might be best to reduce the number of conversion cases. I'll worry about this later.
* vo_opengl: use ra_* for format negotiation toowm42017-07-291-23/+4
| | | | | | | | | | | | | Format handling via ra_* was added earlier, but the format negotiation part was forgotten. Actually move some aspects of it to ra_get_imgfmt_desc(). Also make sure the unorm and float formats selected by the common format lookup functions are linear filterable. (For OpenGL, this is implicitly guaranteed, so it wasn't done before.) Whether these assumptions should be checked/enforced in the ra code at all is a bit fuzzy, but with ra being helper code only for the actual video renderer, it's probably justified.
* vo_opengl: support loading custom user texturesNiklas Haas2017-07-271-58/+145
| | | | | | | | | | | Parsing the texture data as raw strings makes the textures the most portable and self-contained. In order to facilitate different types of shaders, the parse_user_shader interaction has been changed to instead have it loop through blocks and call the passed functions for ea