Skip to content
Snippets Groups Projects
  1. Dec 20, 2022
    • Sultan Alsawaf's avatar
      modesetting: add support for TearFree page flips · a94dd953
      Sultan Alsawaf authored
      
      This adds support for TearFree page flips to eliminate tearing without the
      use of a compositor. It allocates two shadow buffers for each CRTC, a back
      buffer and a front buffer, and uses damage tracking to minimize excessive
      copying between buffers and skip unnecessary flips when the screen's
      contents remain unchanged. It works on transformed screens too, such as
      rotated and scaled CRTCs.
      
      When PageFlip is enabled, TearFree won't force fullscreen DRI clients to
      synchronize their page flips to the vblank interval.
      
      TearFree is disabled by default.
      
      Signed-off-by: default avatarSultan Alsawaf <sultan@kerneltoast.com>
      a94dd953
    • Sultan Alsawaf's avatar
      modesetting: coalesce vblank events to avoid DRM event queue exhaustion · 2d272b70
      Sultan Alsawaf authored
      
      The DRM event queue in the kernel is quite small and can be easily
      exhausted by DRI clients. When the event queue is full, that means nothing
      can be queued onto it anymore, which can lead to incorrect presentation
      times for DRI clients and failure when attempting to queue a page flip.
      
      To make matters worse, once an event is placed onto the kernel's event
      queue, there's no straightforward way to prematurely remove it from the
      kernel's event queue in userspace, which means that aborting a sequence
      number doesn't free up space in the event queue.
      
      Since vblank events from DRI clients are the largest consumers of the
      event queue, and since it's often easy to know the desired target MSC of
      their vblank events without querying the kernel for a CRTC's current MSC,
      we can coalesce vblank events occurring at the same MSC such that only one
      of them is placed onto the kernel's event queue, instead of allowing
      duplicate vblank events to pollute the event queue.
      
      This is achieved by tracking the next kernel-queued event's MSC on a
      per-CRTC basis and then running all of that CRTC's vblank event handlers
      which have reached their target MSC when the queued MSC is signaled.
      
      Signed-off-by: default avatarSultan Alsawaf <sultan@kerneltoast.com>
      2d272b70
    • Sultan Alsawaf's avatar
      modesetting: make do_queue_flip_on_crtc generic · 5f5690b8
      Sultan Alsawaf authored
      
      do_queue_flip_on_crtc() is about to be used to flip buffers other than the
      primary scanout (`ms->drmmode.fb_id`), so make it generic to accept any
      frame buffer ID, as well as x and y coordinates in the frame buffer, to
      flip on a given CRTC. Move the retry logic from queue_flip_on_crtc() into
      it as well, so that it's robust for all callers.
      
      Signed-off-by: default avatarSultan Alsawaf <sultan@kerneltoast.com>
      5f5690b8
  2. Sep 15, 2021
    • Patrik Jakobsson's avatar
      modesetting: Fix dirty updates for sw rotation · db9e9d45
      Patrik Jakobsson authored and Povilas Kanapickas's avatar Povilas Kanapickas committed
      
      Rotation is broken for all drm drivers not providing hardware rotation
      support. Drivers that give direct access to vram and not needing dirty
      updates still work but only by accident. The problem is caused by
      modesetting not sending the correct fb_id to drmModeDirtyFB() and
      passing the damage rects in the rotated state and not as the crtc
      expects them. This patch takes care of both problems.
      
      Signed-off-by: default avatarPatrik Jakobsson <pjakobsson@suse.de>
      db9e9d45
  3. Sep 09, 2021
    • Mario Kleiner's avatar
      modesetting: Add option for non-vsynced flips for "secondary" outputs. · 68f01c0f
      Mario Kleiner authored and Povilas Kanapickas's avatar Povilas Kanapickas committed
      
      Whenever an unredirected fullscreen window uses pageflipping for a
      DRI3/Present PresentPixmap() operation and the X-Screen has more than
      one active output, multiple crtc's need to execute pageflips. Only
      after the last flip has completed can the PresentPixmap operation
      as a whole complete.
      
      If a sync_flip is requested for the present, then the current
      implementation will synchronize each pageflip to the vblank of
      its associated crtc. This provides tear-free image presentation
      across all outputs, but introduces a different artifact, if not
      all outputs run at the same refresh rate with perfect synchrony:
      The slowest output throttles the presentation rate, and present
      completion is delayed to flip completion of the "latest" output
      to complete. This means degraded performance, e.g., a dual-display
      setup with a 144 Hz monitor and a 60 Hz monitor will always be
      throttled to at most 60 fps. It also means non-constant present
      rate if refresh cycles drift against each other, creating complex
      "beat patterns", tremors, stutters and periodic slowdowns - quite
      irritating!
      
      Such a scenario will be especially annoying if one uses multiple
      outputs in "mirror mode" aka "clone mode". One output will usually
      be the "production output" with the highest quality and fastest
      display attached, whereas a secondary mirror output just has a
      cheaper display for monitoring attached. Users care about perfect
      and perfectly timed tear-free presentation on the "production output",
      but cares less about quality on the secondary "mirror output". They
      are willing to trade quality on secondary outputs away in exchange
      for better presentation timing on the "production output".
      
      One example use case for such production + monitoring displays are
      neuroscience / medical science applications where one high quality
      display device is used to present visual animations to test subjects
      or patients in a fMRI scanner room (production display), whereas
      an operator monitors the same visual animations from a control room
      on a lower quality display. Presentation timing needs to be perfect,
      and animations high-speed and tear-free for the production display,
      whereas quality and timing don't matter for the monitoring display.
      
      This commit gives users the option to choose such a trade-off as
      opt-in:
      
      It adds a new boolean option "AsyncFlipSecondaries" to the device section
      of xorg.conf. If this option is specified as true, then DRI3 pageflip
      behaviour changes as follows:
      
      1. The "reference crtc" for a windows PresentPixmap operation does a
         vblank synced flip, or a DRM_MODE_PAGE_FLIP_ASYNC non-synchronized
         flip, as requested by the caller, just as in the past. Typically
         flips will be requested to be vblank synchronized for tear-free
         presentation. The "reference crtc" is the one chosen by the caller
         to drive presentation timing (as specified by PresentPixmap()'s
         "target_msc", "divisor", "remainder" parameters and implemented by
         vblank events) and to deliver Present completion timestamps (msc
         and ust) extracted from its pageflip completion event.
      
      2. All other crtc's, which also page-flip in a multi-display configuration,
         will try to flip with DRM_MODE_PAGE_FLIP_ASYNC, ie. immediately and
         not synchronized to vblank. This allows the PresentPixmap operation
         to complete with little delay compared to a single-display present,
         especially if the different crtc's run at different video refresh
         rates or their refresh cycles are not perfectly synchronized, but
         drift against each other. The downside is potential tearing artifacts
         on all outputs apart from the one of the "reference crtc".
      
      Successfully tested on a AMD gpu with single-display, dual-display and
      triple-display setups, and with single-X-Screen as well as dual-X-Screen
      "ZaphodHeads" configurations.
      
      Please consider merging this commit for the upcoming server 1.21 branch.
      
      Signed-off-by: default avatarMario Kleiner <mario.kleiner.de@gmail.com>
      68f01c0f
  4. Nov 25, 2020
  5. Oct 29, 2020
  6. Sep 25, 2020
    • Kishore409's avatar
      modesetting: keep going if a modeset fails on EnterVT · efb3abdd
      Kishore409 authored and Martin Roukala's avatar Martin Roukala committed
      
      There was a time when setting a mode on a CRTC would not depend on the
      associated connector's state. If a mode had been set successfully once,
      it would mean it would work later on.
      
      This changed with the introduction of new connectors type that now
      require a link training sequence (DP, HDMI 2.0), and that means that
      some events may have happened while the X server was not master that
      would then prevent the mode from successfully be restored to its
      previous state.
      
      This patch relaxes the requirement that all modes should be restored on
      EnterVT, or the entire X-Server would go down by allowing modesets to
      fail (with some warnings). If a modeset fails, the CRTC will be
      disabled, and a RandR event will be sent for the desktop environment to
      fix the situation as well as possible.
      
      Additional patches might be needed to make sure that the user would
      never be left with all screens black in some scenarios.
      
      v2 (Martin Peres):
       - whitespace fixes
       - remove the uevent handling (it is done in a previous patch)
       - improve the commit message
       - reduce the size of the patch by not changing lines needlessly
       - return FALSE if one modeset fails in ignore mode
       - add comments/todos to explain why we do things
       - disable the CRTCs that failed the modeset
      
      Signed-off-by: default avatarKishore Kadiyala <kishore.kadiyala@intel.com>
      Signed-off-by: default avatarMartin Peres <martin.peres@linux.intel.com>
      Reviewed-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
      Tested-by: default avatarKishore Kadiyala <kishore.kadiyala@intel.com>
      Closes: #1010
      efb3abdd
    • Martin Roukala's avatar
      modesetting: check the kms state on EnterVT · 293cf660
      Martin Roukala authored
      
      Normally, we would receive a uevent coming from Linux's DRM subsystem,
      which would trigger the check for disappearing/appearing resources.
      However, this event is not received when X is not master (another VT
      is selected), and so the userspace / desktop environment would not be
      notified about the changes that happened while X wasn't master.
      
      To fix the issue, this patch forces a refresh on EnterVT by splitting
      the kms-checking code from the uevent handling into its own (exported)
      function called drmmode_update_kms_state. This function is then called
      from both the uevent-handling function, and on EnterVT right before
      restoring the modes.
      
      Signed-off-by: default avatarMartin Peres <martin.peres@linux.intel.com>
      Reviewed-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
      Acked-by: default avatarKishore Kadiyala <kishore.kadiyala@intel.com>
      Tested-by: default avatarKishore Kadiyala <kishore.kadiyala@intel.com>
      293cf660
  7. Sep 08, 2020
    • Uday Kiran Pichika's avatar
      modesetting: Lay the foundation for enabling VRR · 9823ea4e
      Uday Kiran Pichika authored and Martin Roukala's avatar Martin Roukala committed
      
      These changes have been ported from AMD GPU DDX driver.
      
      This patch adds support for setting the CRTC variable refresh property
      for suitable windows flipping via the Present extension.
      
      In order for a window to be suitable for variable refresh it must have
      the _VARIABLE_REFRESH property set by the MESA and inform Modesetting
      DDX driver with window property updates.
      
      Then the window must pass the checks required to be suitable for
      Present extension flips - it must cover the entire X screen and no
      other window may already be flipping. And also DRM connector should
      be VRR capable.
      
      With these conditions met every CRTC for the X screen will have their
      variable refresh property set to true.
      
      Kernel Changes to support this feature in I915 driver is under development.
      
      Tested with DOTA2, Xonotic and custom GLX apps.
      
      Signed-off-by: default avatarUday Kiran Pichika <pichika.uday.kiran@intel.com>
      9823ea4e
  8. Jul 09, 2020
  9. Aug 09, 2019
  10. Aug 06, 2019
  11. Aug 02, 2018
  12. May 07, 2018
    • Mario Kleiner's avatar
      modesetting: Remove ms_crtc_msc_to_kernel_msc(). · 73f0ed2d
      Mario Kleiner authored and Adam Jackson's avatar Adam Jackson committed
      
      The function is ported from intel-ddx uxa backend around 2013, where its
      stated purpose was to apply a vblank_offset to msc values to correct for
      problems with those kernel provided msc values. Some (somewhat magic and
      puzzling to myself) heuristic tried to guess if provided values were
      unreasonable and tried to adapt the corrective vblank_offset to account
      for that.
      
      Except: It wasn't applied to kernel provided msc values, but the values
      delivered by clients via DRI2 or Present, so valid client targetmsc
      values, e.g., requesting a vblank event > 1000 vblanks in the future,
      triggered the offset correction in arbitrarily wrong ways, leading to
      wrong msc values being returned and thereby vblank events queued to the
      kernel for the wrong time. This causes glXSwapBuffersMscOML and
      glXWaitForMscOML to swap / return immediately whenever a swap/wait in >
      1000 vblanks is requested.
      
      The original code was also written to only deal with 32 bit mscs, but
      server 1.20 modesetting ddx can now use new Linux 4.15+ kernel vblank
      api to process true 64 bit msc's, which may confuse the heuristic even
      more due to 32 bit integer truncation/wrapping.
      
      This code caused various problems in the intel-ddx in the past since
      year 2013, and was removed there in 2015 by Chris Wilson in commit
      42ebe2ef9646be5c4586868cf332b4cd79bb4618:
      
      "    uxa: Remove the filtering of bogus Present MSC values
      
          If the intention was to filter the return values from the kernel, the
          filtering would have been applied to the kernel values and not to the
          incoming values from Present. This filtering introduces crazy integer
          promotion and truncation bugs all because Present feeds garbage into its
          vblank requests.
      
      "
      
      Indeed, i found a Mesa bug yesterday which can cause Mesa's
      PresentPixmap request to spuriously feed garbage targetMSC's into the
      driver under some conditions. However, while other video drivers seem to
      cope relatively well with that, modesetting ddx causes KDE-5's
      plasmashell to lock up badly quite frequently, and my suspicion is that
      the code removed in this commit is one major source of the extra
      fragility.
      
      Also my own tests fail for any swap scheduled more than 1000 vblanks
      into the future, which is not uncommon for some scientific applications.
      
      Iow. modesetting's swap scheduling seems to be more robust without this
      function afaics.
      
      Signed-off-by: default avatarMario Kleiner <mario.kleiner.de@gmail.com>
      Reviewed-by: Adam Jackson's avatarAdam Jackson <ajax@redhat.com>
      Cc: Chris Wilson <chris@chris-wilson.co.uk>
      Cc: Keith Packard <keithp@keithp.com>
      Tested-by: default avatarMike Lothian <mike@fireburn.co.uk>
      73f0ed2d
  13. Apr 04, 2018
  14. Mar 21, 2018
  15. Mar 05, 2018
  16. Feb 27, 2018
    • Keith Packard's avatar
      Add RandR leases with modesetting driver support [v6] · e4e34476
      Keith Packard authored and Adam Jackson's avatar Adam Jackson committed
      
      This adds support for RandR CRTC/Output leases through the modesetting
      driver, creating a lease using new kernel infrastructure and returning
      that to a client through an fd which will have access to only those
      resources.
      
      v2:	Restore CRTC mode when leases terminate
      
      	When a lease terminates for a crtc we have saved data for, go
      	ahead and restore the saved mode.
      
      v3:	Report RR_Rotate_0 rotations for leased crtcs.
      
      	Ignore leased CRTCs when selecting screen size.
      
      	Stop leasing encoders, the kernel doesn't do that anymore.
      
      	Turn off crtc->enabled while leased so that modesetting
      	ignores them.
      
      	Check lease status before calling any driver mode functions
      
      	When starting a lease, mark leased CRTCs as disabled and hide
      	their cursors. Also, check to see if there are other
      	non-leased CRTCs which are driving leased Outputs and mark
      	them as disabled as well. Sometimes an application will lease
      	an idle crtc instead of the one already associated with the
      	leased output.
      
      	When terminating a lease, reset any CRTCs which are driving
      	outputs that are no longer leased so that they start working
      	again.
      
      	This required splitting the DIX level lease termination code
      	into two pieces, one to remove the lease from the system
      	(RRLeaseTerminated) and a new function that frees the lease
      	data structure (RRLeaseFree).
      
      v4:	Report RR_Rotate_0 rotation for leased crtcs.
      
      v5: Terminate all leases on server reset.
      
      	Leases hang around after the associated client exits so that
      	the client doesn't need to occupy an X server client slot and
      	consume a file descriptor once it has gotten the output
      	resources necessary.
      
      	Any leases still hanging around when the X server resets or
      	shuts down need to be cleaned up by calling the kernel to
      	terminate the lease and freeing any DIX structures.
      
      	Note that we cannot simply use the existing
      	drmmode_terminate_lease function on each lease as that wants
      	to also reset the video mode, and during server shut down that
      
         modesetting: Validate leases on VT enter
      
      	The kernel doesn't allow any master ioctls to run when another
      	VT is active, including simple things like listing the active
      	leases. To deal with that, we check the list of leases
      	whenever the X server VT is activated.
      
         xfree86: hide disabled cursors when resetting after lease termination
      
      	The lessee may well have played with cursors and left one
      	active on our screen. Just tell the kernel to turn it off.
      
      v6:	Add meson build infrastructure
      
      [Also bumped libdrm requirement - ajax]
      
      Signed-off-by: default avatarKeith Packard <keithp@keithp.com>
      Reviewed-by: Adam Jackson's avatarAdam Jackson <ajax@redhat.com>
      e4e34476
  17. Feb 26, 2018
  18. Oct 30, 2017
  19. Aug 15, 2017
    • Michel Dänzer's avatar
      Make PixmapDirtyUpdateRec::src a DrawablePtr · 8e3b26ce
      Michel Dänzer authored
      
      This allows making the master screen's pixmap_dirty_list entries
      explicitly reflect that we're now tracking the root window instead of
      the screen pixmap, in order to allow Present page flipping on master
      outputs while there are active slave outputs.
      
      Define HAS_DIRTYTRACKING_DRAWABLE_SRC for drivers to check, but leave
      HAS_DIRTYTRACKING_ROTATION defined as well to make things slightly
      easier for drivers.
      
      Reviewed-by: Adam Jackson's avatarAdam Jackson <ajax@redhat.com>
      8e3b26ce
  20. Feb 08, 2017
    • Michael Thayer's avatar
      modesetting: allow switching from software to hardware cursors (v5). · eb04b201
      Michael Thayer authored and Adam Jackson's avatar Adam Jackson committed
      
      Currently if modesetting ever fails to set a hardware cursor it will switch
      to using a software cursor and never go back.  Change this to only
      permanently switch to a software cursor if -ENXIO is returned (which means
      hardware cursors not supported), and to otherwise still try a hardware
      cursor first every time a new one is set.  This is needed because hardware
      may be able to handle some cursors in hardware and others not, or virtual
      hardware may be able to handle hardware cursors at some times and not
      others.
      
      Changes since v1, v2 and v3:
       * take into account the switch to load_cursor_argb_check
       * keep the permanent software cursor fall-back if -ENXIO is returned
       * move parts of v3 into separate patches
      
      Reviewed-by: Adam Jackson's avatarAdam Jackson <ajax@redhat.com>
      Signed-off-by: default avatarMichael Thayer <michael.thayer@oracle.com>
      eb04b201
    • Michael Thayer's avatar
      modesetting: Immediately handle failure to set HW cursor, v5 · ecd0a623
      Michael Thayer authored and Adam Jackson's avatar Adam Jackson committed
      
      Based on v4 by Alexandre Courbot <acourbot@nvidia.com>
      
      There is currently no reliable way to report failure to set a HW
      cursor. Still such failures can happen if e.g. the MODE_CURSOR DRM
      ioctl fails (which currently happens at least with modesetting on Tegra
      for format incompatibility reasons).
      
      As failures are currently handled by setting the HW cursor size to
      (0,0), the fallback to SW cursor will not happen until the next time the
      cursor changes and xf86CursorSetCursor() is called again. In the
      meantime, the cursor will be invisible to the user.
      
      This patch addresses that by adding _xf86CrtcFuncs::set_cursor_check and
      _xf86CursorInfoRec::ShowCursorCheck hook variants that return booleans.
      This allows to propagate errors up to xf86CursorSetCursor(), which can
      then fall back to using the SW cursor immediately.
      
      v5:
       - Removed parts of patch already committed as part of 14c21ea1.
       - Adjusted code slightly to match surrounding code.
       - Effectively reverted af916477 which is made unnecessary by this patch.
      
      Reviewed-by: Adam Jackson's avatarAdam Jackson <ajax@redhat.com>
      Signed-off-by: default avatarMichael Thayer <michael.thayer@oracle.com>
      ecd0a623
  21. Sep 02, 2016
  22. Aug 09, 2016
  23. Jul 02, 2016
Loading