1. 15 Apr, 2019 1 commit
    • Philip Langdale's avatar
      xtalloc: Re-prefix all ta_* symbols to xta_* · 12aab84a
      Philip Langdale authored
      xtalloc was copied from mpv, which means that we see symbol
      collisions if libplacebo is statically linked into mpv. So
      use an `xta_` prefix for all the functions. In practice, this
      has almost no effect on the consuming code because everything
      is accessed via macros.
      12aab84a
  2. 24 Feb, 2019 5 commits
    • Niklas Haas's avatar
      shaders: compat for GLSL < 130 · bd502804
      Niklas Haas authored
      We need to use the explicitly named functions like texture2D(),
      texture3D() etc. for low GLSL versions. Add a bunch of shitty
      compatibility code to template out the function name.
      
      The specific way I solved it also opens us up to allowing e.g. rectangle
      textures in the future.
      bd502804
    • Niklas Haas's avatar
      shaders: cosmetic (code moving) · 02a2f7bd
      Niklas Haas authored
      Make this a function instead of a static inline, since it's complicated
      enough.
      02a2f7bd
    • Niklas Haas's avatar
      shaders: allow overriding shader GLSL version explicitly · 27835a8b
      Niklas Haas authored
      This can be useful for API users that don't want to go through the
      bother of setting up a dummy `pl_gpu` just to create some shaders.
      27835a8b
    • Niklas Haas's avatar
      shaders: refactor shader creation API · 729e4aee
      Niklas Haas authored
      - I wanted to add new parameters, and rather than having the function
        signature grow out of control, I decided to switch to the same
        `params`-style as the rest of libplacebo, for future forwards
        compatibility.
      
      - We need to expose the identifier, because users of raw shaders might
        want to combine multiple shaders into the same GLSL program.
      
      This kills off the hacky `_ex` functions and uses a params struct. Also
      organizes some fields around, for reasons.
      729e4aee
    • Niklas Haas's avatar
      shaders: change implicit GLSL version assumptions · 44b4f779
      Niklas Haas authored
      Instead of assuming the lowest possible, assume GLSL 130 as the
      baseline. This requires bumping the API version because it is a breaking
      change to some use cases.
      
      Also a missing GLSL version compat check to the dither code.
      44b4f779
  3. 11 Jan, 2019 1 commit
    • Niklas Haas's avatar
      shaders: hide `uint8_t ident` from `pl_shader_reset` · 21d079b8
      Niklas Haas authored
      This was accidentally left exposed from a previous version of the API.
      It makes no sense in the public-facing code, so move it to the private
      `pl_shader_reset_ex`.
      
      Also swap the order of parameters for consistency.
      21d079b8
  4. 05 Jan, 2019 1 commit
    • Niklas Haas's avatar
      shaders/colorspace: completely refactor HDR peak detection · 9b4aecb1
      Niklas Haas authored
      The previous approach of using an FIR with tunable hard threshold for
      scene changes had several problems:
      
      - the FIR involved annoying dynamic buffer sizes, high VRAM usage,
        and the FIR sum was prone to numerical overflow which limited the
        number of frames we could average over.
      
      - the hard scene change detection was prone to both false positives and
        false negatives, each with their own (annoying) issues.
      
      Scrap this entirely and switch to a dual approach of using a simple
      single-pole IIR low pass filter to smooth out noise, while using a
      softer scene change curve (with tunable low and high thresholds), based
      on `smoothstep`. The IIR filter is extremely simple in its
      implementation and has an arbitrarily user-tunable cutoff frequency,
      while the smoothstep-based scene change curve provides a good, tunable
      tradeoff between adaptation speed and stability - without exhibiting
      either of the traditional issues associated with the hard cutoff.
      
      Another way to think about the new options is that the "low threshold"
      provides a margin of error within which we don't care about small
      fluctuations in the scene (which will therefore be smoothed out by the
      IIR filter).
      
      While redesigning the algorithm, I also redesigned the API - so that
      peak detection and tone mapping are separate, discrete steps that can be
      done as part of two different shaders. (Or as part of the same shader)
      This is required for #40, and in particular, means that issue is now
      within reach.
      
      cf. https://github.com/mpv-player/mpv/pull/6415
      9b4aecb1
  5. 05 Dec, 2018 1 commit
    • Niklas Haas's avatar
      shaders: allow pl_shader_obj reuse between samplers · d130d190
      Niklas Haas authored
      Right now, pl_shader_sample_polar and pl_shader_sample_ortho had
      distinct sampler object types - but this was unclear and actually caused
      issues in e.g. the pl_renderer code. Fix it to use the same sampler
      object type instead.
      d130d190
  6. 04 Dec, 2018 1 commit
    • Niklas Haas's avatar
      3rdparty: use meson subprojects instead · 195f28ea
      Niklas Haas authored
      Major refactor of the source code structure. Now uses meson subprojects
      for "third party" dependencies (including bstr and talloc), and moves a
      lot of the meson boilerplate from src/meson.build to the top-level
      meson.build.
      
      We choose the name 'xtalloc' to make sure we don't collide with samba
      libtalloc, and to reflect the fact that our wrappers abort on OOM.
      195f28ea
  7. 17 Nov, 2018 1 commit
    • Niklas Haas's avatar
      gpu: move pl_buffer_var from gpu.h to shaders.h · 573cf43c
      Niklas Haas authored
      This makes no real sense in gpu.h, since the pl_gpu doesn't actually
      need this information in any way. It's only needed for the shader header
      generation inside dispatch.h, so having it in shaders.h is the right
      place.
      
      Makes some code arguably a bit uglier, but whatever.
      573cf43c
  8. 30 Oct, 2018 2 commits
    • Niklas Haas's avatar
      shaders: add AV1 film grain shader · 1d635def
      Niklas Haas authored
      This is can be used to apply AV1 film grain onto planes directly on the
      GPU. Eventually, the pl_renderer will be able to take this grain params
      struct and do it automatically - but for now, we need the basic shader
      implemntation first.
      
      We make some amount of effort to follow the AV1 spec exactly, even down
      to reproducing the (terrible) PRNG, awkward corner blending and rounding
      (where possible).
      
      Some things are not currently preserved: In particular, the blending of
      pixels is not correctly rounded. (We continue calculating on the
      un-rounded floating point values) In practice this does not produce any
      significant deviation (bounded by +/- 1) - especially if you don't round
      but instead continue calculating with floating point precision, in which
      case the true error is only the difference between the un-rounded value
      and its correctly rounded counterpart (bounded by +/- 0.5).
      
      The generated shader can be used as both a compute shader and a fragment
      shader, but a compute shader is preferred (slightly faster).
      
      We upload the weights and grain tables using an SSBO (which we need
      anyway to store the integer offset table). In theory we could try
      replacing these by LUTs, but the existing sh_lut mechanism does not lend
      itself well to frequent updates, and we will want to be updating this
      texture constantly (especially for parallel streaming).
      
      But more testing is warranted here. For now, this should be a working v1
      implementation.
      1d635def
    • Niklas Haas's avatar
      shaders: fix sh_lut consistency · 9942ea92
      Niklas Haas authored
      The current code treated SH_LUT_TEXTURE like SH_LUT_LINEAR for no good
      reason (which was also wrong since d178fd2). Furthermore, it claimed
      SH_LUT_LINEAR used integer addressing, which is not the case.
      
      Make this more consistent by treating *all* LUT methods as integer
      addressing except for SH_LUT_LINEAR (which is the only sane exception).
      
      Fixes the dither bugs since d178fd2, and also a hypothetical bug if
      SH_LUT_AUTO decided to use uniform variables as the LUT method.
      9942ea92
  9. 28 Oct, 2018 1 commit
    • Niklas Haas's avatar
      shaders: add a concept of "failed" shaders · 1247de7b
      Niklas Haas authored
      A shader may fail due to any number of error conditions (that previously
      resulted in just an error message and the code continuing on as if
      nothing happened, most likely producing a seriously broken shader and
      trying to compile it)
      
      Now we safe-guard against shader failure, add a way to detect it, and
      actually consider it an error state w.r.t pl_dispatch and so forth.
      1247de7b
  10. 26 Oct, 2018 1 commit
  11. 29 Sep, 2018 1 commit
    • Niklas Haas's avatar
      common: switch to explicit includes · b6104e12
      Niklas Haas authored
      Since we no longer need the GCC pragma for symbol visibility, there's
      also no more reason to have common.h import everything under the sun -
      so only have modules import what they actually use.
      
      This speeds up compilation a tiny bit.
      b6104e12
  12. 27 Sep, 2018 1 commit
    • Niklas Haas's avatar
      dispatch: rework the shader identification mechanism · 5cbcbcec
      Niklas Haas authored
      Rather than having the uint8_t be public, which makes little sense with
      no public way to merge shaders (sh_subpass is private), just add an
      internal _ex function for the (relatively few) cases where we actually
      need this merging stuff.
      
      For the most cases, we can just always use identifier 0, this also gives
      us better caching for stuff like OSD passes etc.
      5cbcbcec
  13. 28 May, 2018 1 commit
    • Niklas Haas's avatar
      shaders: add support for ICC profiles and 3DLUTs · eb14d3bd
      Niklas Haas authored
      Code taken from mpv, with some modifications. The shader stuff is from
      scratch, but lcms.c draws heavily from code I already wrote.
      
      This again uses LittleCMS 2, with which I've been very satisfied.
      Partially addresses #23.
      eb14d3bd
  14. 13 Feb, 2018 1 commit
  15. 02 Feb, 2018 1 commit
    • Niklas Haas's avatar
      ra: rename ra to pl_gpu, change ra_ to pl_ · 3e881060
      Niklas Haas authored
      This is a very major rewrite operation, but all of the actual logic is
      unaffected. The change is completely cosmetic.
      
      The idea behind this is to avoid clashing the mpv ra_ namespace when
      libplacebo eventually makes its way back into mpv, allowing it to
      coexist with vo_gpu peacefully (at least for the transition period).
      
      It's also sort of weirdly inconsistent with the rest of libplacebo
      anyway.
      3e881060
  16. 22 Jan, 2018 2 commits
  17. 25 Dec, 2017 2 commits
    • Niklas Haas's avatar
      shaders: add high quality dithering · aa04f95b
      Niklas Haas authored
      The algorithm is ported from mpv; with some minor modifications (AVLFG
      -> rand()). Blue noise is internally preferred wherever possiblle, with
      ordered LUT being an alternative - and falling back to fixed function
      ordered and finally white noise when LUTs are not available.
      
      Also contains some minor other modifications (maximum shader literal LUT
      size, maximum dither depth)
      aa04f95b
    • Niklas Haas's avatar
      shaders: rework sh_lut mechanism · e2dabec9
      Niklas Haas authored
      1. Drop the use of UBOs and SSBOs; since not only are there unaddressed
         packing concerns, but they also don't really provide an advantage.
         Instead, use regular uniform floats (i.e. input variables with
         dim_v), but only do this by default if we have global inputs.
      
      2. Implement the missing case (SH_LITERAL)
      
      3. Improve the signature for the `fill` function.
      
      On my nvidia hardware, both SH_LITERAL and SH_UNIFORM sadly explode for
      large inputs - SH_UNIFORM exhausts the UBO size limits when using
      vulkan, mainly due to the vec4/float packing inefficiency. SH_LITERAL on
      the other hand just makes the nvidia shader compiler explode. Further
      investigation is required, but for small LUTs it should work
      nonetheless.
      e2dabec9
  18. 22 Dec, 2017 1 commit
    • Niklas Haas's avatar
      shaders: refactor pl_shader_obj and add sh_lut · 456aa914
      Niklas Haas authored
      This refactors the way we store data like scaler LUTs, with the intent
      of generalizing it for other types of LUTs (e.g. dither matrix) in an
      easy-to-use but flexible way.
      
      Instead of trying to come up with sane semantics for who gets to use
      what fields inside a pl_shader_obj, we just abstract it away and let the
      caller deal with the *priv representation (as usual). Unfortunately,
      this requires "nesting" pl_shader_objs for cases like the sampler LUTs
      where we need to store information about the scaling kernel *and* the
      underlying LUT. But that's not too bad, I think.
      
      I had to rewrite the code that uses pl_shader_objs. Hopefully for the
      better.
      456aa914
  19. 10 Nov, 2017 1 commit
    • Niklas Haas's avatar
      shaders: place shader inputs dynamically · 301bf233
      Niklas Haas authored
      Instead of hard-coding the bindings and position in pl_shader_res, place
      them dynamically once we have a better idea of the overall inputs. This
      is needed to enable shader merging without conflicting bindings /
      offsets. The logic is moved to pl_dispatch instead.
      301bf233
  20. 09 Nov, 2017 1 commit
    • Niklas Haas's avatar
      shaders: add sh_subpass / shader merging · 7465c43b
      Niklas Haas authored
      This adds the secondary shader as a subpass of the first shader;
      exposing it as a function (much like pl_shader_finalize). There is
      currently still no public shader merging API, but it could easily be
      built on top of this.
      
      This switches from void *tmp to ta_ref *tmp in order to avoid breaking
      memory allocated by the attached objects.
      7465c43b
  21. 06 Nov, 2017 3 commits
    • Niklas Haas's avatar
      shaders: seed sh_prng with gl_FragCoord · df91c5d3
      Niklas Haas authored
      No need to waste a VA on this (or force the user to pass one in)
      df91c5d3
    • Niklas Haas's avatar
      shaders: generalize the PRNG · c99cd6bf
      Niklas Haas authored
      I've also found some independent resources describing this exact
      algorithm. In particular, one of them also offers a performance tip: we
      can use fract() instead of x - floor() since we don't need the exact
      modulus semantics.
      c99cd6bf
    • Niklas Haas's avatar
      shaders: refactor randomness seeding · 8f0890de
      Niklas Haas authored
      Instead of having the user pass in seed values, instead pass in a global
      `index` on pl_shader generation, and use this to internally seed the
      PRNG / perturb the dither matrix / etc.
      
      This removes the highly state-dependent garbage from the *_params
      structs, which is the right thing to do for the upcoming pl_renderer
      options.
      8f0890de
  22. 05 Nov, 2017 2 commits
    • Niklas Haas's avatar
      shaders: seed sh_prng with gl_FragCoord · efd0d9a5
      Niklas Haas authored
      No need to waste a VA on this (or force the user to pass one in)
      efd0d9a5
    • Niklas Haas's avatar
      shaders: generalize the PRNG · a6ea1100
      Niklas Haas authored
      I've also found some independent resources describing this exact
      algorithm. In particular, one of them also offers a performance tip: we
      can use fract() instead of x - floor() since we don't need the exact
      modulus semantics.
      a6ea1100
  23. 31 Oct, 2017 1 commit
    • Niklas Haas's avatar
      shaders: major refactor of tone mapping and color spaces · 7aa14ac3
      Niklas Haas authored
      This accomplishes several things:
      
      1. vec4 colors are now explicitly always normalized such that 1.0 is the
         reference white, and out-out-range values are used to communicate
         high dynamic range images. This makes a lot of processing steps
         saner, and doesn't matter much in the end. It also makes better use
         of the dynamic range of a float FBO, which is better for
         representational efficiency than linear FBOs either way.
      
      2. HDR metadata now includes the frame average light level, not just the
         signal peak. This is important because it allows us to linearly
         darken over-bright scenes, which are sadly common due to shit
         mastering.
      
      3. The tone mapping code takes into account the desired target peak and
         frame average light level. Not strictly necessary, but could be
         useful to play around with; especially for PQ output.
      
      4. The peak detection SSBO code is fundamentally fixed. This had a large
         number of issues, too many to even bother listing. Now it should
         actually work properly.
      7aa14ac3
  24. 22 Oct, 2017 1 commit
  25. 21 Oct, 2017 1 commit
  26. 20 Oct, 2017 3 commits
    • Niklas Haas's avatar
      shaders: remove the dynamic variable renaming crap · d8f63a6e
      Niklas Haas authored
      This was brittle and ugly and slow and annoying anyway. Instead, turn
      this into a user problem. Most users probably know what requirements
      they have, no need to have this annoying code in their hot paths.
      
      For the pl_dispatch system, we can just get this for free as long as you
      `reset_frame` before starting over. This should be fine for the purposes
      of pl_dispatch, which was never meant to be as flexible as pl_shader
      anyway.
      d8f63a6e
    • Niklas Haas's avatar
      shaders: cache the position of all bound textures · 8850611f
      Niklas Haas authored
      This avoids all potential headaches due to multiple evaluation of the
      compute shader position macro
      8850611f
    • Niklas Haas's avatar
      dispatch: refactor compute shader generation · 436d9865
      Niklas Haas authored
      This required making some (semi-significant) changes to shaders/ra as
      well. This provides the infrastructure to properly simulate vertices.
      
      Also clarified the lifetime/usage rules of ident_t.
      436d9865
  27. 17 Oct, 2017 2 commits
    • Niklas Haas's avatar
      shaders: implement HDR peak detection · 6c8c357c
      Niklas Haas authored
      Taken from mpv, with some modifications to fit the new system.
      
      Not entirely sure I'm happy with the buffer building code. It might be a
      good idea to add some sort of mid-level wrapper that makes this easier
      for pl_shaders, but since the peak detection SSBO is the only current
      user of this interface, doing it the ugly way is probably fine.
      6c8c357c
    • Niklas Haas's avatar
      shaders: add shader object tracking mechanism · 04bc66cb
      Niklas Haas authored
      For shaders which require access to "configured" objects, this tracks
      the object's lifetime and allows the shader to re-use the same
      configured object across frames, with the caller being responsible for
      cleanup.
      
      Not entirely sure if I want to just chuck everything in there or do
      subtyping via void *priv, but I think for now the chuck-everything
      approach is fine.
      04bc66cb