Commit Graph

40 Commits

Author SHA1 Message Date
Alan Coopersmith 7cc0695cf7 modesetting: avoid memory leak when ms_present_check_unflip() returns FALSE
Found by Oracle Parfait 13.3 static analyzer:
   Memory leak [memory-leak]:
      Memory leak of pointer event allocated with calloc(1, 16)
        at line 470 of hw/xfree86/drivers/modesetting/present.c in
	function 'ms_present_unflip'.
          event allocated at line 431 with calloc(1, 16)
          event leaks when ms_present_check_unflip(...) == 0 at line 438
              and i >= config->num_crtc at line 445

Fixes: 13c7d53df ("modesetting: Implement page flipping support for Present.")
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1730>
2024-10-31 16:24:41 +01:00
Enrico Weigelt, metux IT consult 31c8867db4 (submit/drop-obsolete-have-dix-config.h) drop obsolete HAVE_DIX_CONFIG_H
The symbol controls whether to include dix-config.h, and it's always set,
thus we don't need it (and dozens of ifdef's) anymore.

This commit only removes them from our own source files, where we can
guarantee that dix-config.h is present - leaving the (potentially exported)
headers untouched.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2024-09-18 17:23:11 +02:00
Alan Coopersmith 522f469fe9 Move sizeof to second argument in calloc calls
Clears -Wcalloc-transposed-args warnings from gcc 14.1, such as:

../dix/main.c:165:42: warning: ‘calloc’ sizes specified with ‘sizeof’ in the
 earlier argument and not in the later argument [-Wcalloc-transposed-args]
  165 |             serverClient = calloc(sizeof(ClientRec), 1);
      |                                          ^~~~~~~~~
../dix/main.c:165:42: note: earlier argument should specify number of
 elements, later size of each element

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1606>
2024-07-19 23:45:21 +00:00
Ville Syrjälä 899c87af1f modesetting: unflip before any setcrtc() calls
Make sure we're not scanning out any fbs with fancy modifiers when
we try to light up new displays. This is already the case in cases
where the screen gets resized, but in cases where that doesn't happen
it might be possible for the modeset(s) to fail due to watermark/etc.
constraints imposed by the fancy modifiers. We can avoid that by
making sure everything gets unflipped before the modeset.

v2: make poll timeout infinite
    s/in_modeset/pending_modeset/
    deal with tearfree fallout (goto no_flip)

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
2023-12-16 04:36:39 +00:00
Sultan Alsawaf 53b02054f3 modesetting: Support accurate DRI presentation timing with TearFree
When using TearFree, DRI clients have no way of accurately knowing when
their copied pixmaps appear on the display without utilizing the kernel
driver's notification indicating that the TearFree flip containing their
pixmap is complete. This is because the target CRTC's MSC can change while
the predicted completion MSC is calculated and even while the page flip
IOCTL is sent to the kernel due to scheduling delays and/or unfortunate
timing. Even worse, a page flip isn't actually guaranteed to be finished
after one vblank; it may be several MSCs until a flip actually finishes
depending on delays and load in hardware.

As a result, DRI clients may be off by one or more MSCs when they naively
expect their pixmaps to be visible at MSC+1 with TearFree enabled. This,
for example, makes it impossible for DRI clients to achieve precise A/V
synchronization when TearFree is enabled.

This change therefore adds a way for DRI clients to receive a notification
straight from the TearFree flip-done handler to know exactly when their
pixmaps appear on the display. This is done by checking for a NULL pixmap
pointer to modesetting's DRI flip routine, which indicates that the DRI
client has copied its pixmap and wants TearFree to send a notification when
the copied pixmap appears on the display as part of a TearFree flip. The
existing PageFlip scaffolding is reused to achieve this with minimal churn.

The Present extension will be updated in an upcoming change to utilize this
new mechanism for DRI clients' presentations.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
Acked-by: Martin Roukala <martin.roukala@mupuf.org>
2023-02-28 22:43:37 -08:00
Sultan Alsawaf 18b14ea1f6 modesetting: Introduce ms_tearfree_is_active_on_crtc helper
There is more than one place with the confusing TearFree state check for a
CRTC. Instead of open-coding the TearFree check everywhere, introduce a
helper, ms_tearfree_is_active_on_crtc, to cover the TearFree state checks.

Suggested-by: Martin Roukala <martin.roukala@mupuf.org>
Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
Reviewed-by: Martin Roukala <martin.roukala@mupuf.org>
2023-02-28 22:43:37 -08:00
Sultan Alsawaf 8b5fd55658 modesetting: Improve TearFree state check in ms_present_check_flip
Check that the VT is owned and that the CRTC is on before exporting info to
Present stating that TearFree is available. Also, since `trf->buf[0].px` is
checked, the `ms->drmmode.tearfree_enable` check is redundant and can
therefore be removed.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
Reviewed-by: Martin Roukala <martin.roukala@mupuf.org>
2023-02-28 22:43:37 -08:00
Sultan Alsawaf 1fd9d79ae0 modesetting: Pass reference CRTC pointer to ms_do_pageflip
Rather than passing the reference CRTC's vblank pipe to ms_do_pageflip,
just pass the pointer to the reference CRTC directly instead. This is
clearer and more useful than the vblank pipe, since the vblank pipe is only
used to identify whether or not a given CRTC is the reference CRTC.

No functional change.

Signed-off-by: Sultan Alsawaf <sultan@kerneltoast.com>
Reviewed-by: Martin Roukala <martin.roukala@mupuf.org>
2023-02-28 22:43:37 -08:00
Sultan Alsawaf a94dd95369 modesetting: add support for TearFree page flips
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: Sultan Alsawaf <sultan@kerneltoast.com>
2022-12-19 23:56:27 -08:00
Mario Kleiner 68f01c0f02 modesetting: Add option for non-vsynced flips for "secondary" outputs.
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: Mario Kleiner <mario.kleiner.de@gmail.com>
2021-09-09 09:53:21 +00:00
Mario Kleiner 8f8ebf870b modesetting: Allow Present flips with mismatched stride on atomic drivers.
When using DRI3+Present with PRIME render offload, sometimes there is
a mismatch between the stride of the to-be-presented Pixmap and the
frontbuffer. The current code would reject a pageflip present in this
case if atomic modesetting is not enabled, ie. always, as atomic
modesetting is disabled by default due to brokeness in the current
modesetting-ddx.

Fullscreen presents without page flipping however trigger the copy
path as fallback, which causes not only unreliable presentation timing
and degraded performance, but also massive tearing artifacts due to
rendering to the framebuffer without any hardware sync to vblank.
Tearing is extra awful on modesetting-ddx because glamor afaics seems
to use drawing of a textured triangle strip for the copy implementation,
not a dedicated blitter engine. The rasterization pattern creates extra
awful tearing artifacts.

We can do better: According to a tip from Michel Daenzer (thanks!),
at least atomic modesetting capable kms drivers should be able to
reliably change scanout stride during a pageflip, even if atomic
modesetting is not actually enabled for the modesetting client.

This commit adds detection logic to find out if the underlying kms
driver is atomic_modeset_capable, and if so, it no longer rejects
page flip presents on mismatched stride between new Pixmap and
frontbuffer.

We (ab)use a call to drmSetClientCap(ms->fd, DRM_CLIENT_CAP_ATOMIC, 0);
for this purpose. The call itself has no practical effect, as it
requests disabling atomic mode, although atomic mode is disabled by
default. However, the return value of drmSetClientCap() tells us if the
underlying kms driver is atomic modesetting capable: An atomic driver
will return 0 for success. A legacy non-atomic driver will return a
non-zero error code, either -EINVAL for early atomic Linux versions
4.0 - 4.19 (or for non-atomic Linux 3.x and earlier), or -EOPNOTSUPP
for Linux 4.20 and later.

Testing on a MacBookPro 2017 with Intel Kabylake display server gpu +
AMD Polaris11 as prime renderoffload gpu, X-Server master + Mesa 21.0.3
show improvement from unbearable tearing to perfect, despite a stride
mismatch between display gpu and Pixmap of 11776 Bytes vs. 11520
Bytes. That this is correct behaviour was also confirmed by comparing the
behaviour and .check_flip implementation of the patched modesetting-ddx
against the current intel-ddx SNA Present implementation.

Please consider merging this patch before the server-1.21 branch point.
This patch could also be cherry-picked into the server 1.20 branch to
fix the same limitation.

Signed-off-by: Mario Kleiner <mario.kleiner.de@gmail.com>
2021-09-07 09:21:39 +00:00
Łukasz Spintzyk 8836b9d243 modesetting: unflip not possible when glamor is not set
This is fixing crashes of xfce when running under qemu
2021-07-22 13:24:21 +02:00
Łukasz Spintzyk 5be3b80b8d modesetting: Remove few common functions from ms namespace
A lot of that code is the same as in xf86-amdgpu and xf86-nouveau drivers. By removing that functions from
ms namespace we can move that code to common implementation.

Signed-off-by: Łukasz Spintzyk <lukasz.spintzyk@synaptics.com>
2021-04-16 10:53:43 +00:00
Olivier Fourdan 3ce05a44f3 modesetting: Fix build with DebugPresent() enabled
By default, the macro DebugPresent() is a no-op but it can be enabled
at build time for debugging purpose.

However, doing so prevents the code to build because one debug statement
tries to make use of a non-existent variable:

  present.c: In function ‘ms_present_queue_vblank’:
  present.c:147:18: error: ‘vbl’ undeclared (first use in this function)
    147 |                  vbl.request.sequence));
        |                  ^~~
  present.c:49:32: note: in definition of macro ‘DebugPresent’
    49 | #define DebugPresent(x) ErrorF x
       |                                ^

Fix the build with DebugPresent() by removing the vbl variable from the
debug message.

Signed-off-by: Olivier Fourdan <ofourdan@redhat.com>
2020-11-26 22:06:56 +00:00
Uday Kiran Pichika 9823ea4ed2 modesetting: Lay the foundation for enabling VRR
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: Uday Kiran Pichika <pichika.uday.kiran@intel.com>
2020-09-08 08:00:20 +00:00
Adam Jackson cb1b1e1847 Revert "Revert "modesetting: Indirect the glamor API through LoaderSymbol""
Now that we've fixed LoaderSymbolFromModule this should work properly.

This reverts commit 5c7c6d5cff.

Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
2019-11-21 14:20:57 -05:00
Michel Dänzer 5c7c6d5cff Revert "modesetting: Indirect the glamor API through LoaderSymbol"
This reverts commit dd63f717fe.

Caused a crash at least on some systems.

Closes: https://gitlab.freedesktop.org/xorg/xserver/issues/934
2019-11-15 11:32:38 +01:00
Adam Jackson dd63f717fe modesetting: Indirect the glamor API through LoaderSymbol
Prerequisite for building all of xserver with -z now.

Gitlab: https://gitlab.freedesktop.org/xorg/xserver/issues/692
2019-11-13 19:49:18 +00:00
Alex Goins 562c7888be modesetting: Implement ms_covering_randr_crtc() for ms_present_get_crtc()
ms_present_get_crtc() returns an RRCrtcPtr, but derives it from a xf86CrtcPtr
found via ms_dri2_crtc_covering_drawable()=>ms_covering_crtc(). As a result, it
depends on all associated DIX ScreenRecs having an xf86CrtcConfigPtr DDX
private.

Some DIX ScreenRecs don't have an xf86CrtcConfigPtr DDX private, but do have an
rrScrPrivPtr DDX private. Given that we can derive all of the information we
need from RandR, we can support these screens by avoiding the use of xf86Crtc.
This change implements an RandR-based path for ms_present_get_crtc(), allowing
drawables to successfully fall back to syncing to the primary output, even if
the slave doesn't have an xf86CrtcConfigPtr DDX private.

Without this change, if a slave doesn't have an xf86CrtcConfigPtr DDX private,
drawables will fall back to 1 FPS if they overlap an output on that slave.

Signed-off-by: Alex Goins <agoins@nvidia.com>
2019-11-11 14:35:57 -08:00
Hans de Goede 12821852f0 modesetting: Avoid duplicate error messages on present-flip errors
Currently on present-flip failures we log 2 messages for each failure,
1 from ms_do_pageflip and then another one from ms_present_flip which
is the caller of ms_do_pageflip. This commit adds a log_prefix argument
to ms_do_pageflip so that its log messages can show if it is a DRI2 or
a Present flip which fails and removes the redundant error message from
ms_present_flip.

Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2019-08-09 10:50:55 +02:00
Hans de Goede 0aaac8d783 modesetting: Disable pageflipping when using a swcursor
The miPointerSpriteFunc swcursor code expects there to only be a single
framebuffer and when the cursor moves it will undo the damage of the
previous draw, potentially overwriting what ever is there in a new
framebuffer installed after a flip.

This leads to all kind of artifacts, so we need to disable pageflipping
when a swcursor is used.

The code for this has shamelessly been copied from the xf86-video-amdgpu
code.

Fixes: https://gitlab.freedesktop.org/xorg/xserver/issues/828

Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2019-08-06 17:22:02 +02:00
Louis-Francis Ratté-Boulianne 6cace4990a modesetting: Fix GBM objects leak when checking for flip
GBM objects were never destroyed after looking for format and
modifier compatibility when deciding whether flipping or copying
a presented pixmap.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=106106
Signed-off-by: Louis-Francis Ratté-Boulianne <lfrb@collabora.com>
2018-04-30 14:01:02 -04:00
Adam Jackson ba0c751772 modesetting: Fix up some XXX from removing GLAMOR_HAS_DRM_*
Signed-off-by: Adam Jackson <ajax@redhat.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
2018-03-22 15:00:06 -04:00
Emil Velikov 22b489d273 Remove always true GLAMOR_HAS_DRM_* guards
With earlier commit the required version was bumped to 2.4.89, thus the
guards always evaluate to true.

Fixes: e4e3447603 ("Add RandR leases with modesetting driver support
[v6]")
Cc: Keith Packard <keithp@keithp.com>
Cc: Daniel Stone <daniels@collabora.com>
Cc: Louis-Francis Ratté-Boulianne <lfrb@collabora.com>
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2018-03-21 10:06:12 -04:00
Louis-Francis Ratté-Boulianne 9d147305b4 modesetting: Check if buffer format is supported when flipping
Add support for 'check_flip2' so that the present core can know
why it is impossible to flip in that scenario. The core can then
let know the client that the buffer format/modifier is suboptimal.

v2: No longer need to implement 'check_flip'

Signed-off-by: Louis-Francis Ratté-Boulianne <lfrb@collabora.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
Acked-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2018-03-05 13:27:47 -05:00
Louis-Francis Ratté-Boulianne 9817c14f6a modesetting: Use atomic modesetting to configure output/CRTCs
To make sure we also use the same primary plane and to avoid
mixing uses of two APIs, it is better to always use the atomic
modesetting API when possible.

v2: Don't use mode_output->connector_id

Signed-off-by: Louis-Francis Ratté-Boulianne <lfrb@collabora.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
Acked-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2018-03-05 13:27:40 -05:00
Keith Packard 677c32bcda xf86-video-modesetting: Add ms_queue_vblank helper [v3]
This provides an API wrapper around the kernel interface for queueing
a vblank event, simplifying all of the callers.

v2: Fix missing '|' in computing vbl.request.type

v3: Remove spurious bit of next patch (thanks, Michel Dänzer)

Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2017-10-04 15:17:41 -04:00
Eric Anholt 32957d9fae modesetting: Drop code for GLAMOR && !GLAMOR_HAS_GBM.
The glamor_egl module that the GLAMOR paths are using is only built if
GLAMOR_HAS_GBM is true, and there's no plan for implementing the
module without GBM.  Simplify modesetting's code as a result.

Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Eric Anholt <eric@anholt.net>
2017-05-18 11:33:05 -04:00
Qiang Yu f06aef31c0 modesetting: add DRI2 page flip support
Signed-off-by: Qiang Yu <Qiang.Yu@amd.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
2016-09-02 13:58:09 -04:00
Qiang Yu 4a839da627 modesetting: move common page flip handle to pageflip.c
The common page flip handle framework can be shared with DRI2
page flip.

Signed-off-by: Qiang Yu <Qiang.Yu@amd.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
2016-09-02 13:57:42 -04:00
Qiang Yu 4f1eb7864b modesetting: move ms_do_pageflip to pageflip.c
Signed-off-by: Qiang Yu <Qiang.Yu@amd.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
2016-09-02 13:56:10 -04:00
Qiang Yu a586bf9ccf modesetting: make ms_do_pageflip generic for share with DRI2
Signed-off-by: Qiang Yu <Qiang.Yu@amd.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
2016-09-02 13:46:42 -04:00
Keith Packard d403aca70a Switch poll() users to xserver_poll()
This uses the wrapper in case we need to emulate poll with select
as we do on Windows.

Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Keith Packard <keithp@keithp.com>
2016-07-21 15:04:36 -04:00
Lyude Paul 848089e0dd modesetting: Clear drmmode->fb_id before unflipping
[fix copied from 40191d82370e in xf86-video-ati]

Without this, we end up setting rotated CRTCs back to their previous
framebuffer right after we perform a rotation. Reproducer:

- Have two monitors connected at the same resolution
- Rotate one monitor from normal straight to inverted
- Watch as the monitor you didn't rotate either freezes or shows intense
  flickering

Signed-off-by: Lyude <cpaul@redhat.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2016-06-17 11:38:13 +02:00
Alan Coopersmith fe8562f531 modesetting should not reference gbm when it's not defined
Fixes build errors of:
present.c: In function 'ms_do_pageflip':
present.c:410:17: error: 'drmmode_bo' has no member named 'gbm'
     new_front_bo.gbm = glamor_gbm_bo_from_pixmap(screen, new_front);
                 ^
present.c:412:22: error: 'drmmode_bo' has no member named 'gbm'
     if (!new_front_bo.gbm) {
                      ^
present.c: In function 'ms_present_check_flip':
present.c:536:36: error: 'drmmode_bo' has no member named 'gbm'
         if (drmmode_crtc->rotate_bo.gbm)
                                    ^
Introduced by commit 13c7d53d

Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2016-01-05 13:23:56 -05:00
Dave Airlie e3624aa5fd xserver: fix build with glamor disabled.
This fixes modesetting when glamor is disabled.

Signed-off-by: Dave Airlie <airlied@redhat.com>
Signed-off-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2015-07-06 12:01:33 -07:00
Kenneth Graunke 13c7d53df8 modesetting: Implement page flipping support for Present.
Based on code by Keith Packard, Eric Anholt, and Jason Ekstrand.

v2:
- Fix double free and flip_count underrun (caught by Mario Kleiner).
- Don't leak flip_vblank_event on the error_out path (Mario).
- Use the updated ms_flush_drm_events API (Mario, Ken).

v3: Hack around DPMS shenanigans.  If all monitors are DPMS off, then
    there is no active framebuffer; attempting to pageflip will hit the
    error_undo paths, causing us to drmModeRmFB with no framebuffer,
    which confuses the kernel into doing full modesets and generally
    breaks things.  To avoid this, make ms_present_check_flip check that
    some CRTCs are enabled and DPMS on.  This is an ugly hack that would
    get better with atomic modesetting, or some core Present work.

v4:
- Don't do pageflipping if CRTCs are rotated (caught by Jason Ekstrand).
- Make pageflipping optional (Option "PageFlip" in xorg.conf.d), but
  enabled by default.

v5: Initialize num_crtcs_on to 0 (caught by Michel Dänzer).

[airlied: took over]
v6: merge async flip support from Mario Kleiner
free sequence after failed vblank queue
handle unflip while DPMS'ed off (Michel)
move flip tracking into its own structure, and
fix up reference counting issues, and add comments.

Signed-off-by: Dave Airlie <airlied@redhat.com>
Acked-by: Eric Anholt <eric@anholt.net>
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
2015-06-30 13:44:09 +10:00
Kenneth Graunke f6853baeba modesetting: Improve the ms_flush_drm_events() API.
Previously, ms_flush_drm_events() returned a boolean value, and it was
very easy to interpret the meaning incorrectly.  Now, we return an
integer value.

The possible outcomes of this call are:
- poll() raised an error (formerly TRUE, now -1 - poll's return value)
- poll() said there are no events (formerly TRUE, now 0).
- drmHandleEvent() raised an error (formerly FALSE, now the negative
  value returned by drmHandleEvent).
- An event was successfully handled (formerly TRUE, now 1).

The nice part is that this allows you to distinguish errors (< 0),
nothing to do (= 0), and success (1).  We no longer conflate errors
with success.

v2: Change ms_present_queue_vblank to < 0 instead of <= 0, fixing an
    unintentional behavior change.  libdrm may return EBUSY if it's
    received EINTR for more than a second straight; just keep retrying
    in that case.  Suggested by Jasper St. Pierre.

Reviewed-by: Dave Airlie <airlied@redhat.com>
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
2015-06-30 13:44:09 +10:00
Kenneth Graunke 6672606420 modesetting: Fix build with --disable-glamor.
present.c: In function 'ms_present_flush':
present.c:204:9: error: implicit declaration of function
'glamor_block_handler'

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=87858
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Jasper St. Pierre <jstpierre@mecheye.net>
Reviewed-by: Rob Clark <robdclark@gmail.com>
Signed-off-by: Keith Packard <keithp@keithp.com>
2015-01-01 10:52:30 -08:00
Kenneth Graunke 09230a2d43 modesetting: Add vblank synchronization support when using Present.
modesetting hooked up vblank support for DRI2, but was missing support
for vblanks in Present.

This is mostly copy and pasted from Keith's code in the intel driver.

v2: Use ms_crtc_msc_to_kernel_msc in ms_present_queue_vblank to hook
    up the vblank_offset workaround for bogus MSC values (which the
    DRI2 code already did).

    Also simplify the ms_present_get_crtc function.  vblank.c already
    implements the functionality; we just need to convert types.

v3: Fix ms_flush_drm_events return code.  I'd copied code where 0 meant
    success into a function that returned a boolean, so the return code
    was always backwards.

    Also add DebugPresent calls in ms_present_vblank_{handler,abort}.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Keith Packard <keithp@keithp.com>
Tested-by: Jason Ekstrand <jason.ekstrand@intel.com>
Signed-off-by: Keith Packard <keithp@keithp.com>
2014-12-25 13:39:19 -08:00