Skip to contentSkip to conversation

xf86-video-intel DRI3 and Present patch series

PATCH In review Keith Packard 3 participants 7 messages Nov 20, 2013 – Nov 26, 2013 2 messages not in the archive

lore
Share & tools
lore
#0 lore raw

cover xf86-video-intel DRI3 and Present patch series

Here's a series of patches which provide DRI3 and Present support in the Intel 2D driver. The first two patches pave the way by synthesizing 64-bit vblank counters and extending the DRM event handling to allow for both DRI2 and DRI3 events. Then there's a patch to add DRI2 and miSyncShm support followed by a patch to add Present support.

[PATCH 1/4] Support 64-bit MSC values. Handle kernel vageries about [PATCH 2/4] Restructure DRM event handling.
[PATCH 3/4] Add DRI3 and miSyncShm support
[PATCH 4/4] Add Present extension support

-keith
_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

#1 lore raw

PATCH 1/4 Support 64-bit MSC values. Handle kernel vageries about MSC reporting

The kernel sometimes reports bogus MSC values, especially when suspending and resuming the machine. Deal with this by tracking an offset to ensure that the MSC seen by applications increases monotonically, and at a reasonable pace.

Also, provide a full 64 bits of MSC value by noticing wrapping and tracking the high 32-bits of MSC separately.

---
 src/uxa/intel.h         |   9 ++++
 src/uxa/intel_display.c | 118 ++++++++++++++++++++++++++++++++++++++++-----
 src/uxa/intel_dri.c     | 125 ++++++++++++++++--------------------------------
 3 files changed, 156 insertions(+), 96 deletions(-)
src/uxa/intel.h +9 -0
index 131f18c..f05b160 100644
@@ -401,6 +401,15 @@ extern int intel_crtc_id(xf86CrtcPtr crtc);
 extern int intel_output_dpms_status(xf86OutputPtr output);
 extern void intel_copy_fb(ScrnInfoPtr scrn);
 
+int
+intel_get_crtc_msc_ust(ScrnInfoPtr scrn, xf86CrtcPtr crtc, uint64_t *msc, uint64_t *ust);
+
+uint32_t
+intel_crtc_msc_to_sequence(ScrnInfoPtr scrn, xf86CrtcPtr crtc, uint64_t expect);
+
+uint64_t
+intel_sequence_to_crtc_msc(xf86CrtcPtr crtc, uint32_t sequence);
+
 enum DRI2FrameEventType {
 	DRI2_SWAP,
 	DRI2_SWAP_CHAIN,
src/uxa/intel_display.c +107 -11

154 lines not on this page · raw message

src/uxa/intel_dri.c +40 -85

254 lines not on this page · raw message

Signature · 1 line
1.8.4.2

A message that is not in the archive (sent off-list or not yet received): 1384980817-20535-1-git-send-email-keithp-aN4HjG94KOLQT0dZR+AlfA@public.gmane.org

#3 lore raw

PATCH 2/4 Restructure DRM event handling.

This refactors the drm interrupt handling logic quite a bit, both to allow for either DRI2 or Present handlers, but also to eliminate passing pointers through the kernel. Passing pointers left the kernel holding the only reference to some internal X server data structures.

After a server reset, the X server would end up using stale pointers stored in those structures. Using simple integers makes it possible to empty the queue of pending interrupt data and then ignore the stale kernel data.

---
 src/uxa/intel.h         |  31 ++++-
 src/uxa/intel_display.c | 316 ++++++++++++++++++++++++++++++++++++++++++------
 src/uxa/intel_dri.c     |  99 ++++++++++++---
 3 files changed, 390 insertions(+), 56 deletions(-)
src/uxa/intel.h +30 -1
index f05b160..922b208 100644
@@ -395,6 +395,25 @@ extern void intel_mode_disable_unused_functions(ScrnInfoPtr scrn);
 extern void intel_mode_remove_fb(intel_screen_private *intel);
 extern void intel_mode_close(intel_screen_private *intel);
 extern void intel_mode_fini(intel_screen_private *intel);
+extern int intel_mode_read_drm_events(intel_screen_private *intel);
+
+typedef void (*intel_drm_handler_proc)(ScrnInfoPtr scrn,
+                                       xf86CrtcPtr crtc,
+                                       uint64_t seq,
+                                       uint64_t usec,
+                                       void *data);
+
+typedef void (*intel_drm_abort_proc)(ScrnInfoPtr scrn,
+                                     xf86CrtcPtr crtc,
+                                     void *data);
+
+extern uint32_t intel_drm_queue_alloc(ScrnInfoPtr scrn, xf86CrtcPtr crtc, void *data, intel_drm_handler_proc handler, intel_drm_abort_proc abort);
+extern void intel_drm_abort(ScrnInfoPtr scrn, Bool (*match)(void *data, void *match_data), void *match_data);
+
+/* struct intel_mode *
+   intel_page_flip_handler(void *event_data); */
+
+
 
 extern int intel_get_pipe_from_crtc_id(drm_intel_bufmgr *bufmgr, xf86CrtcPtr crtc);
 extern int intel_crtc_id(xf86CrtcPtr crtc);
@@ -422,6 +441,12 @@ typedef void (*DRI2SwapEventPtr)(ClientPtr client, void *data, int type,
 				 CARD64 ust, CARD64 msc, CARD64 sbc);
 #endif
 
+typedef void (*intel_pageflip_handler_proc) (uint64_t frame,
+                                             uint64_t usec,
+                                             void *data);
+
+typedef void (*intel_pageflip_abort_proc) (void *data);
+
 typedef struct _DRI2FrameEvent {
 	struct intel_screen_private *intel;
 
@@ -444,7 +469,11 @@ typedef struct _DRI2FrameEvent {
 
 extern Bool intel_do_pageflip(intel_screen_private *intel,
 			      dri_bo *new_front,
-			      DRI2FrameEventPtr flip_info, int ref_crtc_hw_id);
+                              int ref_crtc_hw_id,
+                              Bool async,
+                              void *pageflip_data,
+                              intel_pageflip_handler_proc pageflip_handler,
+                              intel_pageflip_abort_proc pageflip_abort);
 
 static inline intel_screen_private *
 intel_get_screen_private(ScrnInfoPtr scrn)
src/uxa/intel_display.c +280 -36

469 lines not on this page · raw message

src/uxa/intel_dri.c +80 -19

230 lines not on this page · raw message

Signature · 6 lines
1.8.4.2

_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel
#4 lore raw

PATCH 3/4 Add DRI3 and miSyncShm support

In reply to a message not in the archive
---
 configure.ac           |  14 ++++
 src/uxa/Makefile.am    |   7 ++
 src/uxa/intel.h        |  17 +++++
 src/uxa/intel_dri3.c   | 184 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/uxa/intel_driver.c |  13 ++++
 src/uxa/intel_sync.c   | 109 +++++++++++++++++++++++++++++
 src/uxa/intel_uxa.c    |   1 +
 7 files changed, 345 insertions(+)
 create mode 100644 src/uxa/intel_dri3.c
 create mode 100644 src/uxa/intel_sync.c
configure.ac +14 -0
index 0783d61..13b9970 100644
@@ -276,6 +276,7 @@ XORG_DRIVER_CHECK_EXT(RANDR, randrproto)
 XORG_DRIVER_CHECK_EXT(RENDER, renderproto)
 XORG_DRIVER_CHECK_EXT(XF86DRI, xextproto x11)
 XORG_DRIVER_CHECK_EXT(DPMSExtension, xextproto)
+XORG_DRIVER_CHECK_EXT(DRI3, dri3proto)
 
 # Obtain compiler/linker options for the driver dependencies
 PKG_CHECK_MODULES(DRM, [libdrm >= 2.4.20]) # libdrm_intel is checked separately
@@ -463,6 +464,19 @@ else
 	UXA=no
 fi
 
+if test "x$DRI3" != "xno"; then
+	save_CFLAGS=$CFLAGS
+	CFLAGS="$XORG_CFLAGS $DRM_CFLAGS $DRI_CFLAGS $DRI3_CFLAGS"
+	AC_CHECK_DECL(DRI3,
+		      [DRI3=yes], [DRI3=no],
+		      [#include <xorg-server.h>])
+	CFLAGS=$save_CFLAGS
+	dri_msg="$dri_msg DRI3"
+fi
+AC_MSG_CHECKING([whether to include DRI3 support])
+AM_CONDITIONAL(DRI3, test "x$DRI3" = xyes)
+AC_MSG_RESULT([$DRI3])
+
 AC_CHECK_HEADERS([X11/extensions/dpmsconst.h])
 
 AC_MSG_CHECKING([whether to include UXA support])
src/uxa/Makefile.am +7 -0
index 971ac21..3c9e693 100644
@@ -80,6 +80,13 @@ libuxa_la_LIBADD += \
 	$(NULL)
 endif
 
+if DRI3
+libuxa_la_SOURCES += \
+	intel_dri3.c \
+	intel_sync.c \
+	$(NULL)
+endif
+
 if XVMC
 AM_CFLAGS += -I$(top_srcdir)/xvmc
 libuxa_la_SOURCES += \
src/uxa/intel.h +17 -0
index 922b208..c3d00f4 100644
@@ -59,6 +59,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "xf86xv.h"
 #include "xf86Crtc.h"
 #include "xf86RandR12.h"
+#include "misync.h"
 
 #include "xorg-server.h"
 #include <pciaccess.h>
@@ -352,6 +353,11 @@ typedef struct intel_screen_private {
 	InputHandlerProc uevent_handler;
 #endif
 	Bool has_prime_vmap_flush;
+
+        SyncScreenFuncsRec save_sync_screen_funcs;
+
+        void (*flush_rendering)(struct intel_screen_private *intel);
+
 } intel_screen_private;
 
 #define INTEL_INFO(intel) ((intel)->info)
@@ -519,6 +525,9 @@ void I830DRI2FrameEventHandler(unsigned int frame, unsigned int tv_sec,
 void I830DRI2FlipEventHandler(unsigned int frame, unsigned int tv_sec,
 			      unsigned int tv_usec, DRI2FrameEventPtr flip_info);
 
+/* intel_dri3.c */
+Bool intel_dri3_screen_init(ScreenPtr screen);
+
 extern Bool intel_crtc_on(xf86CrtcPtr crtc);
 int intel_crtc_to_pipe(xf86CrtcPtr crtc);
 
@@ -725,4 +734,12 @@ static inline Bool intel_pixmap_is_offscreen(PixmapPtr pixmap)
 	return priv && priv->offscreen;
 }
 
+#if DRI3
+Bool
+intel_sync_init(ScreenPtr screen);
+#endif
+
+void
+intel_sync_close(ScreenPtr screen);
+
 #endif /* _I830_H_ */
src/uxa/intel_dri3.c new file +184 -0

184 lines not on this page · raw message

src/uxa/intel_driver.c +13 -0
index 431c34b..12c7b34 100644
@@ -1050,6 +1050,10 @@ I830ScreenInit(SCREEN_INIT_ARGS_DECL)
 	if (intel->XvEnabled)
 		I830InitVideo(screen);
 
+#if DRI3
+        intel_dri3_screen_init(screen);
+#endif
+
 #if defined(DRI2)
 	switch (intel->directRenderingType) {
 	case DRI_DRI2:
@@ -1076,6 +1080,11 @@ I830ScreenInit(SCREEN_INIT_ARGS_DECL)
 
 	intel_mode_init(intel);
 
+
+#if DRI3
+        (void) intel_sync_init(screen);
+#endif
+
 	intel->suspended = FALSE;
 
 #if HAVE_UDEV
@@ -1163,6 +1172,10 @@ static Bool I830CloseScreen(CLOSE_SCREEN_ARGS_DECL)
 	I830UeventFini(scrn);
 #endif
 
+#if DRI3
+        intel_sync_close(screen);
+#endif
+
 	intel_mode_close(intel);
 
 	DeleteCallback(&FlushCallback, intel_flush_callback, scrn);
src/uxa/intel_sync.c new file +109 -0

109 lines not on this page · raw message

src/uxa/intel_uxa.c +1 -0
index 6fb1333..a31d196 100644
@@ -1420,5 +1420,6 @@ Bool intel_uxa_init(ScreenPtr screen)
 	uxa_set_fallback_debug(screen, intel->fallback_debug);
 	uxa_set_force_fallback(screen, intel->force_fallback);
 
+        intel->flush_rendering = intel_flush_rendering;
 	return TRUE;
 }
Signature · 6 lines
1.8.4.2

_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel
#5 lore raw
In reply to a message not in the archive
Quoted 8 lines · Keith Packard

Here's a series of patches which provide DRI3 and Present support in the Intel 2D driver. The first two patches pave the way by synthesizing 64-bit vblank counters and extending the DRM event handling to allow for both DRI2 and DRI3 events. Then there's a patch to add DRI2 and miSyncShm support followed by a patch to add Present support.

[PATCH 1/4] Support 64-bit MSC values. Handle kernel vageries about

Some spurious assignments that appear to intentially drop the error code could be clarified, and intel_crtc_msc_to_sequence() is always called with a derived current_msc already to hand. The latter present path obfuscates its derived current_msc.

Quoted 1 line

[PATCH 2/4] Restructure DRM event handling.

This won't compile against older Xorg due to xorg_list in the common code.

Quoted 1 line

[PATCH 3/4] Add DRI3 and miSyncShm support

O_CLOEXEC needs protecting, also would appear to be candidate for a render-node. The imported and exported DRI3 pixmaps need to be pinned to prevent the driver using BO exchanges on that pixmap. DRI3 doesn't respect the xorg.conf Option for disabling. A fence is only tied to a screen and no XID or Client in particular? So it is a global operation akin to intel_flush_callback() which would be called before the Sync reply was sent.

Quoted 1 line

[PATCH 4/4] Add Present extension support

Yikes. The patch is itself fairly innoculous, but only because the Present extension in the server appears to be repeating the worst of DRI2, including its original bugs. The fallback/non-fullscreen case is not synchronised to screen refresh (if the Client so desired), and should be passed through to the driver. The whole driver interface seems to be too low a level, baking in many assumptions, rather the usual approach of providing a set of mi routines that the driver can plug into or not as the case may be. That the WindowPixmap no longer points to the actual bo leads to a few problems, such as the CRTC misconfiguration and GetImage being broken after a PresentFlip. After a vblank_event, Present must check that the flip is still valid before execution. In the backend it is not clear whether the RRCrtc should be the primary CRTC or the only CRTC to flip. Damage is processed after the fallback but not the Flip path, the lack of Damage notification would upset Prime amongst others. -Chris

Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

A message that is not in the archive (sent off-list or not yet received): 20131125134951.GE21316-aII6DKEyn0pWYbfKqPwjAkR8Iwp7RQ6xAL8bYrjMMd8@public.gmane.org

#7 lore raw
Quoted 4 lines · Chris Wilson
Quoted 1 line

[PATCH 1/4] Support 64-bit MSC values. Handle kernel vageries about

Some spurious assignments that appear to intentially drop the error code could be clarified,

I can't find any dropped error codes in this patch to add comments to, please provide patch excerpts for this review.

Quoted 3 lines

and intel_crtc_msc_to_sequence() is always called
with a derived current_msc already to hand. The latter present path obfuscates its derived current_msc.

Present always computes absolute MSC values and provides those to the driver, instead of expecting every driver to duplicate that logic.

Quoted 4 lines
Quoted 1 line

[PATCH 2/4] Restructure DRM event handling.

This won't compile against older Xorg due to xorg_list in the common code.

Can switch to intel_list, but that would need list_for_each_entry_safe added. How many versions back is this supposed to compile against?

Quoted 4 lines
Quoted 1 line

[PATCH 3/4] Add DRI3 and miSyncShm support

O_CLOEXEC needs protecting, also would appear to be candidate for a render-node.

Yes, obviously this wants to use render-node. I haven't had complaints about O_CLOEXEC from BSD or Solaris developers for libxshmfence; what systems do not have support for this?

Quoted 2 lines

The imported and exported DRI3 pixmaps need to be pinned to prevent the driver using BO exchanges on that pixmap.

I don't understand this comment.

Quoted 1 line

DRI3 doesn't respect the xorg.conf Option for disabling.

Ok, it should check intel->directRenderingType == DRI_DISABLED.

Quoted 2 lines

A fence is only tied to a
screen and no XID or Client in particular?

DRI3 fences are screen-specific (otherwise you'd have no way of hooking the fence to a specific driver).

Quoted 3 lines

So it is a global operation
akin to intel_flush_callback() which would be called before the Sync reply was sent.

Yes, the hardware queue is to be flushed before the Sync event is sent (and before the xshmfence object is triggered, of course). Note that this is just the mi version of sync fences, which use libxshmfence; the driver is free to use different code there. If we find that the code for handling these xshmfence objects is common across drivers, we can move that into the X server to share.

Quoted 5 lines
Quoted 1 line

[PATCH 4/4] Add Present extension support

Yikes. The patch is itself fairly innoculous, but only because the Present extension in the server appears to be repeating the worst of DRI2, including its original bugs.

Please provide more specific comments here.

Quoted 3 lines

The fallback/non-fullscreen case is not
synchronised to screen refresh (if the Client so desired), and should be passed through to the driver.

The fallback case is synchronized as the Present code triggers the CopyArea call from the vblank hook. In practice, this has proven sufficient to get images onto the screen without tearing and without requiring a huge amount of driver and kernel infrastructure.

Quoted 3 lines

The whole driver interface seems to be too low a level, baking in many assumptions, rather the usual approach of providing a set of mi routines that the driver can plug into or not as the case may be.

Patches to the X server to change the API for better hardware support are welcome, of course.

Quoted 3 lines

That the WindowPixmap no longer points to the actual bo leads to a few problems, such as the CRTC misconfiguration and GetImage being broken after a PresentFlip.

A patch for the X server to fix that has been posted.

Quoted 2 lines

After a vblank_event, Present must check that
the flip is still valid before execution.

The flip proc may return FALSE to indicate failure of any kind. Present will then fall-back to a simple blt.

Quoted 2 lines

In the backend it is not clear whether the RRCrtc should be the primary CRTC or the only CRTC to flip.

There is only one screen pixmap, so of course every CRTC must flip together. The CRTC provided indicates which one the MSC is from.

Quoted 2 lines

Damage is processed after the fallback but not the Flip path, the lack of Damage notification would upset Prime amongst others.

Sounds easy to fix in the X server.

Thanks for your review!

Signature · 1 line
[email protected]

_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

#8 lore raw

PATCH 4/4 Add Present extension support

In reply to Keith Packard
---
 configure.ac            |  15 ++
 src/uxa/Makefile.am     |   6 +
 src/uxa/intel.h         |  15 ++
 src/uxa/intel_driver.c  |   4 +
 src/uxa/intel_present.c | 406 ++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 446 insertions(+)
 create mode 100644 src/uxa/intel_present.c
configure.ac +15 -0
index 13b9970..8d881a8 100644
@@ -277,6 +277,7 @@ XORG_DRIVER_CHECK_EXT(RENDER, renderproto)
 XORG_DRIVER_CHECK_EXT(XF86DRI, xextproto x11)
 XORG_DRIVER_CHECK_EXT(DPMSExtension, xextproto)
 XORG_DRIVER_CHECK_EXT(DRI3, dri3proto)
+XORG_DRIVER_CHECK_EXT(PRESENT, presentproto)
 
 # Obtain compiler/linker options for the driver dependencies
 PKG_CHECK_MODULES(DRM, [libdrm >= 2.4.20]) # libdrm_intel is checked separately
@@ -477,6 +478,19 @@ AC_MSG_CHECKING([whether to include DRI3 support])
 AM_CONDITIONAL(DRI3, test "x$DRI3" = xyes)
 AC_MSG_RESULT([$DRI3])
 
+if test "x$PRESENT" != "xno"; then
+	save_CFLAGS=$CFLAGS
+	CFLAGS="$XORG_CFLAGS $PRESENT_CFLAGS"
+	AC_CHECK_DECL(PRESENT,
+		      [PRESENT=yes], [PRESENT=no],
+		      [#include <xorg-server.h>])
+	CFLAGS=$save_CFLAGS
+fi
+echo 'PRESENT is now ' $PRESENT
+AC_MSG_CHECKING([whether to include Present support])
+AM_CONDITIONAL(PRESENT, test "x$PRESENT" = xyes)
+AC_MSG_RESULT([$PRESENT])
+
 AC_CHECK_HEADERS([X11/extensions/dpmsconst.h])
 
 AC_MSG_CHECKING([whether to include UXA support])
@@ -731,6 +745,7 @@ echo "  Additional debugging support?$debug_msg"
 echo "  Support for Kernel Mode Setting? $KMS"
 echo "  Support for legacy User Mode Setting (for i810)? $UMS"
 echo "  Support for Direct Rendering Infrastructure:$dri_msg"
+echo "  Support for Present extension? $PRESENT"
 echo "  Support for Xv motion compensation (XvMC and libXvMC):$xvmc_msg"
 echo "  Build additional tools and utilities?$tools_msg"
 if test -n "$xp_msg"; then
src/uxa/Makefile.am +6 -0
index 3c9e693..1f6f942 100644
@@ -87,6 +87,12 @@ libuxa_la_SOURCES += \
 	$(NULL)
 endif
 
+if PRESENT
+libuxa_la_SOURCES += \
+	intel_present.c \
+	$(NULL)
+endif
+
 if XVMC
 AM_CFLAGS += -I$(top_srcdir)/xvmc
 libuxa_la_SOURCES += \
src/uxa/intel.h +15 -0
index c3d00f4..48711e4 100644
@@ -742,4 +742,19 @@ intel_sync_init(ScreenPtr screen);
 void
 intel_sync_close(ScreenPtr screen);
 
+/*
+ * intel_present.c
+ */
+
+#if 0
+#define DebugPresent(x) ErrorF x
+#else
+#define DebugPresent(x)
+#endif
+
+#if PRESENT
+Bool
+intel_present_screen_init(ScreenPtr screen);
+#endif
+
 #endif /* _I830_H_ */
src/uxa/intel_driver.c +4 -0
index 12c7b34..c760ff6 100644
@@ -1050,6 +1050,10 @@ I830ScreenInit(SCREEN_INIT_ARGS_DECL)
 	if (intel->XvEnabled)
 		I830InitVideo(screen);
 
+#if PRESENT
+        intel_present_screen_init(screen);
+#endif
+
 #if DRI3
         intel_dri3_screen_init(screen);
 #endif
src/uxa/intel_present.c new file +406 -0

406 lines not on this page · raw message

Signature · 6 lines
1.8.4.2

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx