modesetting: add DRI2 page flip support
v2 cover modesetting: add DRI2 page flip support
Hi guys,
This patch set is for adding DRI2 page flip support to modesetting driver. I mainly take reference of amdgpu DDX and reuse present page flip code in the modesetting driver.
V2:
1. fix DRI2 page flip success handler event memory leak
2. adjust patch sequence to make DRI2 use the common page flip code in pageflip.c from the beginning
3. some fix on debug output and comments
Regards,
Qiang
Qiang Yu (5):
modesetting: make ms_do_pageflip generic for share with DRI2
modesetting: move ms_do_pageflip to pageflip.c
modesetting: move common page flip handle to pageflip.c
modesetting: add DRI2 page flip support
modesetting: exclude DRI2 and prensent page flip
hw/xfree86/drivers/modesetting/Makefile.am | 1 + hw/xfree86/drivers/modesetting/dri2.c | 237 +++++++++++++++- hw/xfree86/drivers/modesetting/driver.h | 21 ++ hw/xfree86/drivers/modesetting/drmmode_display.h | 3 + hw/xfree86/drivers/modesetting/pageflip.c | 344 +++++++++++++++++++++++ hw/xfree86/drivers/modesetting/present.c | 335 ++-------------------- 6 files changed, 628 insertions(+), 313 deletions(-) create mode 100644 hw/xfree86/drivers/modesetting/pageflip.c
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 1471611050-27207-1-git-send-email-Qiang.Yu-5C7GfCeVMHo@public.gmane.org
PATCH v2 1/5 modesetting: make ms_do_pageflip generic for share with DRI2
--- hw/xfree86/drivers/modesetting/present.c | 38 ++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 14 deletions(-)
hw/xfree86/drivers/modesetting/present.c +24 -14
@@ -235,7 +235,7 @@ ms_present_flush(WindowPtr window)*/ struct ms_flipdata {ScreenPtr screen; -struct ms_present_vblank_event *event; +void *event;/* number of CRTC events referencing this */ int flip_count;uint64_t fe_msc;
@@ -254,6 +254,12 @@ struct ms_crtc_pageflip {struct ms_flipdata *flipdata; }; +typedef void (*ms_pageflip_handler_proc )(uint64_t frame, +uint64_t usec, +void *data); + +typedef void (*ms_pageflip_abort_proc )(void *data); +/** * Free an ms_crtc_pageflip. *
@@ -277,7 +283,7 @@ ms_present_flip_free(struct ms_crtc_pageflip *flip)* extension code telling it when that happened */ static void -ms_flip_handler (uint64_t msc,uint64_t ust,void *data) +ms_present_flip_handler (uint64_t msc,uint64_t ust,void *data) {struct ms_crtc_pageflip *flip = data;ScreenPtr screen = flip->flipdata->screen;
@@ -331,7 +337,9 @@ ms_present_flip_abort(void *data)static Bool queue_flip_on_crtc (ScreenPtr screen,xf86CrtcPtr crtc,struct ms_flipdata *flipdata, -int ref_crtc_vblank_pipe,uint32_t flags) +int ref_crtc_vblank_pipe,uint32_t flags, +ms_pageflip_handler_proc pageflip_handler, +ms_pageflip_abort_proc pageflip_abort) {ScrnInfoPtr scrn =xf86ScreenToScrn (screen);modesettingPtr ms =modesettingPTR (scrn);
@@ -353,17 +361,12 @@ queue_flip_on_crtc(ScreenPtr screen, xf86CrtcPtr crtc, flip->on_reference_crtc = (drmmode_crtc->vblank_pipe == ref_crtc_vblank_pipe); flip->flipdata = flipdata; - seq =ms_drm_queue_alloc (crtc, flip, ms_flip_handler, ms_present_flip_abort); + seq =ms_drm_queue_alloc (crtc, flip, pageflip_handler, pageflip_abort);if (!seq) {free (flip);return FALSE; } -DebugPresent (("\t\tms:fq %lld c %d -> %d seq %llu\n" , - (long long ) flipdata->event->event_id, - flipdata->flip_count, flipdata->flip_count +1 , - (long long ) seq)); -/* take a reference on flipdata for use in flip */ flipdata->flip_count++;
@@ -394,9 +397,11 @@ queue_flip_on_crtc(ScreenPtr screen, xf86CrtcPtr crtc,static Bool ms_do_pageflip (ScreenPtr screen,PixmapPtr new_front, -struct ms_present_vblank_event *event, +void *event,int ref_crtc_vblank_pipe, -Bool async) +Bool async, +ms_pageflip_handler_proc pageflip_handler, +ms_pageflip_abort_proc pageflip_abort) {#ifndef GLAMOR_HAS_GBM return FALSE;
@@ -470,7 +475,8 @@ ms_do_pageflip(ScreenPtr screen,if (!queue_flip_on_crtc (screen, crtc, flipdata, ref_crtc_vblank_pipe, - flags)) { + flags, pageflip_handler, + pageflip_abort)) { goto error_undo; } }
@@ -588,8 +594,11 @@ ms_present_flip(RRCrtcPtr crtc,if (!event)return FALSE; +DebugPresent (("\t\tms:fq %lld\n" , event_id)); + event->event_id = event_id; - ret =ms_do_pageflip (screen, pixmap, event, drmmode_crtc->vblank_pipe, !sync_flip); + ret =ms_do_pageflip (screen, pixmap, event, drmmode_crtc->vblank_pipe, !sync_flip, + ms_present_flip_handler, ms_present_flip_abort);if (!ret)xf86DrvMsg (scrn->scrnIndex,X_ERROR ,"present flip failed\n" );
@@ -615,7 +624,8 @@ ms_present_unflip(ScreenPtr screen, uint64_t event_id) event->event_id = event_id;if (ms_present_check_flip (NULL , screen->root, pixmap, TRUE) && -ms_do_pageflip (screen, pixmap, event,-1 , FALSE)) { +ms_do_pageflip (screen, pixmap, event,-1 , FALSE, + ms_present_flip_handler, ms_present_flip_abort)) {return ; }
Signature · 6 lines
2.7.4 _______________________________________________ [email protected]: X.Org development Archives: http://lists.x.org/archives/xorg-devel Info: https://lists.x.org/mailman/listinfo/xorg-devel
PATCH v2 2/5 modesetting: move ms_do_pageflip to pageflip.c
In reply to a message not in the archive--- hw/xfree86/drivers/modesetting/Makefile.am | 1 + hw/xfree86/drivers/modesetting/driver.h | 48 ++++++ hw/xfree86/drivers/modesetting/pageflip.c | 251 ++++++++++++++++++++++++++++ hw/xfree86/drivers/modesetting/present.c | 252 ----------------------------- 4 files changed, 300 insertions(+), 252 deletions(-) create mode 100644 hw/xfree86/drivers/modesetting/pageflip.c
hw/xfree86/drivers/modesetting/Makefile.am +1 -0
@@ -54,6 +54,7 @@ modesetting_drv_la_SOURCES = \ sh3224.c \ sh3224.h \ vblank.c \ + pageflip.c \ $(NULL) drivermandir = $(DRIVER_MAN_DIR)
hw/xfree86/drivers/modesetting/driver.h +48 -0
51 lines not on this page · raw message
hw/xfree86/drivers/modesetting/pageflip.c new file +251 -0
251 lines not on this page · raw message
hw/xfree86/drivers/modesetting/present.c +0 -252
276 lines not on this page · raw message
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH v2 3/5 modesetting: move common page flip handle to pageflip.c
In reply to a message not in the archiveThe common page flip handle framework can be shared with DRI2 page flip.
--- hw/xfree86/drivers/modesetting/driver.h | 28 -------- hw/xfree86/drivers/modesetting/pageflip.c | 102 ++++++++++++++++++++++++++++-- hw/xfree86/drivers/modesetting/present.c | 63 +++--------------- 3 files changed, 104 insertions(+), 89 deletions(-)
hw/xfree86/drivers/modesetting/driver.h +0 -28
@@ -156,34 +156,6 @@ Bool ms_present_screen_init(ScreenPtr screen);#ifdef GLAMOR -/* -* Event data for an in progress flip. -* This contains a pointer to the vblank event, -* and information about the flip in progress. -* a reference to this is stored in the per-crtc -* flips. -*/ -struct ms_flipdata { -ScreenPtr screen; -void *event; -/* number of CRTC events referencing this */ -int flip_count; -uint64_t fe_msc; -uint64_t fe_usec; -uint32_t old_fb_id; -}; - -/* -* Per crtc pageflipping infomation, -* These are submitted to the queuing code -* one of them per crtc per flip. -*/ -struct ms_crtc_pageflip { -Bool on_reference_crtc; -/* reference to the ms_flipdata */ -struct ms_flipdata *flipdata; -}; -typedef void (*ms_pageflip_handler_proc )(uint64_t frame,uint64_t usec,void *data);
hw/xfree86/drivers/modesetting/pageflip.c +96 -6
132 lines not on this page · raw message
hw/xfree86/drivers/modesetting/present.c +8 -55
85 lines not on this page · raw message
Signature · 6 lines
2.7.4 _______________________________________________ [email protected]: X.Org development Archives: http://lists.x.org/archives/xorg-devel Info: https://lists.x.org/mailman/listinfo/xorg-devel
A message that is not in the archive (sent off-list or not yet received): 1471611050-27207-4-git-send-email-Qiang.Yu-5C7GfCeVMHo@public.gmane.org
Re: [PATCH v2 xserver 3/5] modesetting: move common page flip handle to pageflip.c
In ms_pageflip_free() you cannot free the parent structure before freeing things it points to. That's undefined behaviour.
Tom
________________________________
From: amd-gfx <amd-gfx-bounces-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org> on behalf of Qiang Yu <[email protected]>
Sent: Friday, August 19, 2016 08:50
To: [email protected]
Cc: Yu, Qiang; [email protected]; [email protected]; [email protected]
Subject: [PATCH v2 xserver 3/5] modesetting: move common page flip handle to pageflip.c
The common page flip handle framework can be shared with DRI2 page flip.
--- hw/xfree86/drivers/modesetting/driver.h | 28 -------- hw/xfree86/drivers/modesetting/pageflip.c | 102 ++++++++++++++++++++++++++++-- hw/xfree86/drivers/modesetting/present.c | 63 +++--------------- 3 files changed, 104 insertions(+), 89 deletions(-)
hw/xfree86/drivers/modesetting/driver.h +0 -28
@@ -156,34 +156,6 @@ Bool ms_present_screen_init(ScreenPtr screen);#ifdef GLAMOR -/* -* Event data for an in progress flip. -* This contains a pointer to the vblank event, -* and information about the flip in progress. -* a reference to this is stored in the per-crtc -* flips. -*/ -struct ms_flipdata { -ScreenPtr screen; -void *event; -/* number of CRTC events referencing this */ -int flip_count; -uint64_t fe_msc; -uint64_t fe_usec; -uint32_t old_fb_id; -}; - -/* -* Per crtc pageflipping infomation, -* These are submitted to the queuing code -* one of them per crtc per flip. -*/ -struct ms_crtc_pageflip { -Bool on_reference_crtc; -/* reference to the ms_flipdata */ -struct ms_flipdata *flipdata; -}; -typedef void (*ms_pageflip_handler_proc )(uint64_t frame,uint64_t usec,void *data);
hw/xfree86/drivers/modesetting/pageflip.c +96 -6
132 lines not on this page · raw message
hw/xfree86/drivers/modesetting/present.c +8 -55
85 lines not on this page · raw message
--
2.7.4
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
amd-gfx Info Page - lists.freedesktop.org<https://lists.freedesktop.org/mailman/listinfo/amd-gfx>
lists.freedesktop.org
To see the collection of prior postings to the list, visit the amd-gfx Archives. Using amd-gfx: To post a message to all the list members, send email ...
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): DM5PR12MB1132187DDE5132521F18628FF7160-2J9CzHegvk+UzrhdoDeimQdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org
Re: [PATCH v2 xserver 3/5] modesetting: move common page flip handle to pageflip.c
Sorry, disregard. The pointer doesn't point inside the struct. That part of the patch is fine.
Tom
________________________________
From: amd-gfx <amd-gfx-bounces-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org> on behalf of StDenis, Tom <[email protected]>
Sent: Friday, August 19, 2016 07:30
To: Yu, Qiang; [email protected]
Cc: [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v2 xserver 3/5] modesetting: move common page flip handle to pageflip.c
In ms_pageflip_free() you cannot free the parent structure before freeing things it points to. That's undefined behaviour.
Tom
________________________________
From: amd-gfx <amd-gfx-bounces-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org> on behalf of Qiang Yu <[email protected]>
Sent: Friday, August 19, 2016 08:50
To: [email protected]
Cc: Yu, Qiang; [email protected]; [email protected]; [email protected]
Subject: [PATCH v2 xserver 3/5] modesetting: move common page flip handle to pageflip.c
The common page flip handle framework can be shared with DRI2 page flip.
--- hw/xfree86/drivers/modesetting/driver.h | 28 -------- hw/xfree86/drivers/modesetting/pageflip.c | 102 ++++++++++++++++++++++++++++-- hw/xfree86/drivers/modesetting/present.c | 63 +++--------------- 3 files changed, 104 insertions(+), 89 deletions(-)
hw/xfree86/drivers/modesetting/driver.h +0 -28
@@ -156,34 +156,6 @@ Bool ms_present_screen_init(ScreenPtr screen);#ifdef GLAMOR -/* -* Event data for an in progress flip. -* This contains a pointer to the vblank event, -* and information about the flip in progress. -* a reference to this is stored in the per-crtc -* flips. -*/ -struct ms_flipdata { -ScreenPtr screen; -void *event; -/* number of CRTC events referencing this */ -int flip_count; -uint64_t fe_msc; -uint64_t fe_usec; -uint32_t old_fb_id; -}; - -/* -* Per crtc pageflipping infomation, -* These are submitted to the queuing code -* one of them per crtc per flip. -*/ -struct ms_crtc_pageflip { -Bool on_reference_crtc; -/* reference to the ms_flipdata */ -struct ms_flipdata *flipdata; -}; -typedef void (*ms_pageflip_handler_proc )(uint64_t frame,uint64_t usec,void *data);
hw/xfree86/drivers/modesetting/pageflip.c +96 -6
132 lines not on this page · raw message
hw/xfree86/drivers/modesetting/present.c +8 -55
85 lines not on this page · raw message
--
2.7.4
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
amd-gfx Info Page - lists.freedesktop.org<https://lists.freedesktop.org/mailman/listinfo/amd-gfx>
lists.freedesktop.org
To see the collection of prior postings to the list, visit the amd-gfx Archives. Using amd-gfx: To post a message to all the list members, send email ...
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH v2 4/5 modesetting: add DRI2 page flip support
In reply to a message not in the archive--- hw/xfree86/drivers/modesetting/dri2.c | 230 ++++++++++++++++++++++++++++++++-- 1 file changed, 221 insertions(+), 9 deletions(-)
hw/xfree86/drivers/modesetting/dri2.c +221 -9
@@ -46,6 +46,7 @@enum ms_dri2_frame_event_type {MS_DRI2_QUEUE_SWAP , +MS_DRI2_QUEUE_FLIP ,MS_DRI2_WAIT_MSC , };
@@ -399,6 +400,190 @@ ms_dri2_blit_swap(DrawablePtr drawable,ms_dri2_copy_region (drawable, ®ion, dst, src); } +struct ms_dri2_vblank_event { +XID drawable_id; +ClientPtr client; +DRI2SwapEventPtr event_complete; +void *event_data; +}; + +static void +ms_dri2_flip_abort (void *data) +{ +struct ms_present_vblank_event *event = data; + +free (event); +} + +static void +ms_dri2_flip_handler (uint64_t msc,uint64_t ust,void *data) +{ +struct ms_dri2_vblank_event *event = data; +uint32_t frame = msc; +uint32_t tv_sec = ust /1000000 ; +uint32_t tv_usec = ust %1000000 ; +DrawablePtr drawable; +int status; + + status =dixLookupDrawable (&drawable, event->drawable_id, serverClient, +M_ANY , DixWriteAccess); +if (status == Success) +DRI2SwapComplete (event->client, drawable, frame, tv_sec, tv_usec, +DRI2_FLIP_COMPLETE , event->event_complete, + event->event_data); + +free (event); +} + +static Bool +ms_dri2_schedule_flip (ms_dri2_frame_event_ptr info) +{ +DrawablePtr draw = info->drawable; +ScreenPtr screen = draw->pScreen; +ms_dri2_buffer_private_ptr back_priv = info->back->driverPrivate; +struct ms_dri2_vblank_event *event; +drmmode_crtc_private_ptr drmmode_crtc = info->crtc->driver_private; + + event =calloc (1 ,sizeof (struct ms_dri2_vblank_event )); +if (!event) +return FALSE; + + event->drawable_id = draw->id; + event->client = info->client; + event->event_complete = info->event_complete; + event->event_data = info->event_data; + +if (ms_do_pageflip (screen, back_priv->pixmap, event, + drmmode_crtc->vblank_pipe, FALSE, + ms_dri2_flip_handler, + ms_dri2_flip_abort)) { +return TRUE; + } +return FALSE; +} + +static Bool +update_front (DrawablePtr draw,DRI2BufferPtr front) +{ +ScreenPtr screen = draw->pScreen; +PixmapPtr pixmap =get_drawable_pixmap (draw); +ms_dri2_buffer_private_ptr priv = front->driverPrivate; +CARD32 size; +CARD16 pitch; + + front->name =glamor_name_from_pixmap (pixmap, &pitch, &size); +if (front->name <0 ) +return FALSE; + + (*screen->DestroyPixmap) (priv->pixmap); + front->pitch = pixmap->devKind; + front->cpp = pixmap->drawable.bitsPerPixel /8 ; + priv->pixmap = pixmap; + pixmap->refcnt++; + +return TRUE; +} + +static Bool +can_exchange (ScrnInfoPtr scrn,DrawablePtr draw, +DRI2BufferPtr front,DRI2BufferPtr back) +{ +ms_dri2_buffer_private_ptr front_priv = front->driverPrivate; +ms_dri2_buffer_private_ptr back_priv = back->driverPrivate; +PixmapPtr front_pixmap; +PixmapPtr back_pixmap = back_priv->pixmap; +xf86CrtcConfigPtr config =XF86_CRTC_CONFIG_PTR (scrn); +int num_crtcs_on =0 ; +int i; + +for (i =0 ; i < config->num_crtc; i++) { +drmmode_crtc_private_ptr drmmode_crtc = config->crtc[i]->driver_private; + +/* Don't do pageflipping if CRTCs are rotated. */ +#ifdef GLAMOR_HAS_GBM +if (drmmode_crtc->rotate_bo.gbm) +return FALSE; +#endif + +if (ms_crtc_on (config->crtc[i])) + num_crtcs_on++; + } + +/* We can't do pageflipping if all the CRTCs are off. */ +if (num_crtcs_on ==0 ) +return FALSE; + +if (!update_front (draw, front)) +return FALSE; + + front_pixmap = front_priv->pixmap; + +if (front_pixmap->drawable.width != back_pixmap->drawable.width) +return FALSE; + +if (front_pixmap->drawable.height != back_pixmap->drawable.height) +return FALSE; + +if (front_pixmap->drawable.bitsPerPixel != + back_pixmap->drawable.bitsPerPixel) +return FALSE; + +if (front_pixmap->devKind != back_pixmap->devKind) +return FALSE; + +return TRUE; +} + +static Bool +can_flip (ScrnInfoPtr scrn,DrawablePtr draw, +DRI2BufferPtr front,DRI2BufferPtr back) +{ +modesettingPtr ms =modesettingPTR (scrn); + +return draw->type ==DRAWABLE_WINDOW && + ms->drmmode.pageflip && + scrn->vtSema && +DRI2CanFlip (draw) &&can_exchange (scrn, draw, front, back); +} + +static void +ms_dri2_exchange_buffers (DrawablePtr draw,DRI2BufferPtr front, +DRI2BufferPtr back) +{ +ms_dri2_buffer_private_ptr front_priv = front->driverPrivate; +ms_dri2_buffer_private_ptr back_priv = back->driverPrivate; +ScreenPtr screen = draw->pScreen; +ScrnInfoPtr scrn =xf86ScreenToScrn (screen); +modesettingPtr ms =modesettingPTR (scrn); +msPixmapPrivPtr front_pix =msGetPixmapPriv (&ms->drmmode, front_priv->pixmap); +msPixmapPrivPtr back_pix =msGetPixmapPriv (&ms->drmmode, back_priv->pixmap); +msPixmapPrivRec tmp_pix; +RegionRec region; +int tmp; + +/* Swap BO names so DRI works */ + tmp = front->name; + front->name = back->name; + back->name = tmp; + +/* Swap pixmap privates */ + tmp_pix = *front_pix; + *front_pix = *back_pix; + *back_pix = tmp_pix; + +glamor_egl_exchange_buffers (front_priv->pixmap, back_priv->pixmap); + +/* Post damage on the front buffer so that listeners, such +* as DisplayLink know take a copy and shove it over the USB. +*/ + region.extents.x1 = region.extents.y1 =0 ; + region.extents.x2 = front_priv->pixmap->drawable.width; + region.extents.y2 = front_priv->pixmap->drawable.width; + region.data =NULL ; +DamageRegionAppend (&front_priv->pixmap->drawable, ®ion); +DamageRegionProcessPending (&front_priv->pixmap->drawable); +} + static void ms_dri2_frame_event_handler(uint64_t msc, uint64_t usec,
@@ -417,6 +602,13 @@ ms_dri2_frame_event_handler(uint64_t msc, }switch (frame_info->type) { +case MS_DRI2_QUEUE_FLIP : +if (can_flip (scrn, drawable, frame_info->front, frame_info->back) && +ms_dri2_schedule_flip (frame_info)) { +ms_dri2_exchange_buffers (drawable, frame_info->front, frame_info->back); +break ; + } +/* else fall through to blit */ case MS_DRI2_QUEUE_SWAP :ms_dri2_blit_swap (drawable, frame_info->front, frame_info->back); DRI2SwapComplete(frame_info->client, drawable, msc, tv_sec, tv_usec,
@@ -607,7 +799,7 @@ ms_dri2_schedule_swap(ClientPtr client, DrawablePtr draw,ScrnInfoPtr scrn =xf86ScreenToScrn (screen);modesettingPtr ms =modesettingPTR (scrn);drmVBlank vbl; -int ret; +int ret, flip =0 ;xf86CrtcPtr crtc =ms_dri2_crtc_covering_drawable (draw);drmmode_crtc_private_ptr drmmode_crtc;ms_dri2_frame_event_ptr frame_info =NULL ;
@@ -645,20 +837,36 @@ ms_dri2_schedule_swap(ClientPtr client, DrawablePtr draw, ret =ms_get_crtc_ust_msc (crtc, ¤t_ust, ¤t_msc); +/* Flips need to be submitted one frame before */ +if (can_flip (scrn, draw, front, back)) { + frame_info->type =MS_DRI2_QUEUE_FLIP ; + flip =1 ; + } + +/* Correct target_msc by 'flip' if frame_info->type == MS_DRI2_QUEUE_FLIP. +* Do it early, so handling of different timing constraints +* for divisor, remainder and msc vs. target_msc works. +*/ +if (*target_msc >0 ) + *target_msc -= flip; +/* * If divisor is zero, or current_msc is smaller than target_msc * we just need to make sure target_msc passes before initiating * the swap. */ if (divisor ==0 || current_msc < *target_msc) { -/* We need to use DRM_VBLANK_NEXTONMISS to avoid unreliable -* timestamping later on. -*/ vbl.request.type = (DRM_VBLANK_ABSOLUTE | -DRM_VBLANK_NEXTONMISS |DRM_VBLANK_EVENT | drmmode_crtc->vblank_pipe); +/* If non-pageflipping, but blitting/exchanging, we need to use +* DRM_VBLANK_NEXTONMISS to avoid unreliable timestamping later +* on. +*/ +if (flip ==0 ) + vbl.request.type |=DRM_VBLANK_NEXTONMISS ; +/* If target_msc already reached or passed, set it to * current_msc to ensure we return a reasonable value back * to the caller. This makes swap_interval logic more robust.
@@ -683,7 +891,8 @@ ms_dri2_schedule_swap(ClientPtr client, DrawablePtr draw, goto blit_fallback; } - *target_msc =ms_kernel_msc_to_crtc_msc (crtc, vbl.reply.sequence); + *target_msc =ms_kernel_msc_to_crtc_msc (crtc, + vbl.reply.sequence + flip); frame_info->frame = *target_msc;return TRUE;
@@ -695,9 +904,10 @@ ms_dri2_schedule_swap(ClientPtr client, DrawablePtr draw,* equation. */ vbl.request.type = (DRM_VBLANK_ABSOLUTE | -DRM_VBLANK_NEXTONMISS |DRM_VBLANK_EVENT | drmmode_crtc->vblank_pipe); +if (flip ==0 ) + vbl.request.type |=DRM_VBLANK_NEXTONMISS ; request_msc = current_msc - (current_msc % divisor) + remainder;
@@ -721,7 +931,8 @@ ms_dri2_schedule_swap(ClientPtr client, DrawablePtr draw,if (!seq) goto blit_fallback; - vbl.request.sequence =ms_crtc_msc_to_kernel_msc (crtc, request_msc); +/* Account for 1 frame extra pageflip delay if flip > 0 */ + vbl.request.sequence =ms_crtc_msc_to_kernel_msc (crtc, request_msc) - flip; vbl.request.signal = (unsigned long )seq; ret =drmWaitVBlank (ms->fd, &vbl);
@@ -732,7 +943,8 @@ ms_dri2_schedule_swap(ClientPtr client, DrawablePtr draw, goto blit_fallback; } - *target_msc =ms_kernel_msc_to_crtc_msc (crtc, vbl.reply.sequence); +/* Adjust returned value for 1 fame pageflip offset of flip > 0 */ + *target_msc =ms_kernel_msc_to_crtc_msc (crtc, vbl.reply.sequence + flip); frame_info->frame = *target_msc;return TRUE;
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH v2 5/5 modesetting: exclude DRI2 and prensent page flip
In reply to a message not in the archive--- hw/xfree86/drivers/modesetting/dri2.c | 11 +++++++++-- hw/xfree86/drivers/modesetting/driver.h | 5 +++-- hw/xfree86/drivers/modesetting/drmmode_display.h | 3 +++ hw/xfree86/drivers/modesetting/pageflip.c | 7 +++++-- hw/xfree86/drivers/modesetting/present.c | 20 ++++++++++++++++++-- 5 files changed, 38 insertions(+), 8 deletions(-)
hw/xfree86/drivers/modesetting/dri2.c +9 -2
@@ -408,15 +408,17 @@ struct ms_dri2_vblank_event { };static void -ms_dri2_flip_abort (void *data) +ms_dri2_flip_abort (modesettingPtr ms,void *data) {struct ms_present_vblank_event *event = data; + ms->drmmode.dri2_flipping = FALSE;free (event); }static void -ms_dri2_flip_handler (uint64_t msc,uint64_t ust,void *data) +ms_dri2_flip_handler (modesettingPtr ms,uint64_t msc, +uint64_t ust,void *data) {struct ms_dri2_vblank_event *event = data;uint32_t frame = msc;
@@ -432,6 +434,7 @@ ms_dri2_flip_handler(uint64_t msc, uint64_t ust, void *data)DRI2_FLIP_COMPLETE , event->event_complete, event->event_data); + ms->drmmode.dri2_flipping = FALSE;free (event); }
@@ -440,6 +443,8 @@ ms_dri2_schedule_flip(ms_dri2_frame_event_ptr info) {DrawablePtr draw = info->drawable;ScreenPtr screen = draw->pScreen; +ScrnInfoPtr scrn =xf86ScreenToScrn (screen); +modesettingPtr ms =modesettingPTR (scrn);ms_dri2_buffer_private_ptr back_priv = info->back->driverPrivate;struct ms_dri2_vblank_event *event;drmmode_crtc_private_ptr drmmode_crtc = info->crtc->driver_private;
@@ -457,6 +462,7 @@ ms_dri2_schedule_flip(ms_dri2_frame_event_ptr info) drmmode_crtc->vblank_pipe, FALSE, ms_dri2_flip_handler, ms_dri2_flip_abort)) { + ms->drmmode.dri2_flipping = TRUE;return TRUE; }return FALSE;
@@ -542,6 +548,7 @@ can_flip(ScrnInfoPtr scrn, DrawablePtr draw,return draw->type ==DRAWABLE_WINDOW && ms->drmmode.pageflip && + !ms->drmmode.present_flipping && scrn->vtSema &&DRI2CanFlip (draw) &&can_exchange (scrn, draw, front, back); }
hw/xfree86/drivers/modesetting/driver.h +3 -2
@@ -156,11 +156,12 @@ Bool ms_present_screen_init(ScreenPtr screen);#ifdef GLAMOR -typedef void (*ms_pageflip_handler_proc )(uint64_t frame, +typedef void (*ms_pageflip_handler_proc )(modesettingPtr ms, +uint64_t frame,uint64_t usec,void *data); -typedef void (*ms_pageflip_abort_proc )(void *data); +typedef void (*ms_pageflip_abort_proc )(modesettingPtr ms,void *data);int ms_flush_drm_events (ScreenPtr screen);
hw/xfree86/drivers/modesetting/drmmode_display.h +3 -0
@@ -80,6 +80,9 @@ typedef struct {Bool is_secondary;PixmapPtr fbcon_pixmap; + +Bool dri2_flipping; +Bool present_flipping; } drmmode_rec, *drmmode_ptr; typedef struct {
hw/xfree86/drivers/modesetting/pageflip.c +5 -2
@@ -98,7 +98,7 @@ ms_pageflip_handler(uint64_t msc, uint64_t ust, void *data) }if (flipdata->flip_count ==1 ) { - flipdata->event_handler (flipdata->fe_msc, + flipdata->event_handler (ms, flipdata->fe_msc, flipdata->fe_usec, flipdata->event);
@@ -115,9 +115,12 @@ ms_pageflip_abort(void *data) {struct ms_crtc_pageflip *flip = data;struct ms_flipdata *flipdata = flip->flipdata; +ScreenPtr screen = flipdata->screen; +ScrnInfoPtr scrn =xf86ScreenToScrn (screen); +modesettingPtr ms =modesettingPTR (scrn);if (flipdata->flip_count ==1 ) - flipdata->abort_handler (flipdata->event); + flipdata->abort_handler (ms, flipdata->event);ms_pageflip_free (flip); }
hw/xfree86/drivers/modesetting/present.c +18 -2
@@ -53,6 +53,7 @@struct ms_present_vblank_event {uint64_t event_id; +Bool unflip; }; static RRCrtcPtr
@@ -196,7 +197,8 @@ ms_present_flush(WindowPtr window)* extension code telling it when that happened */ static void -ms_present_flip_handler (uint64_t msc,uint64_t ust,void *data) +ms_present_flip_handler (modesettingPtr ms,uint64_t msc, +uint64_t ust,void *data) {struct ms_present_vblank_event *event = data;
@@ -204,6 +206,9 @@ ms_present_flip_handler(uint64_t msc, uint64_t ust, void *data) (long long ) event->event_id, (long long) msc, (long long) ust)); +if (event->unflip) + ms->drmmode.present_flipping = FALSE; +ms_present_vblank_handler (msc, ust, event); }
@@ -211,7 +216,7 @@ ms_present_flip_handler(uint64_t msc, uint64_t ust, void *data)* Callback for the flip has been aborted. */ static void -ms_present_flip_abort (void *data) +ms_present_flip_abort (modesettingPtr ms,void *data) {struct ms_present_vblank_event *event = data;
@@ -237,6 +242,9 @@ ms_present_check_flip(RRCrtcPtr crtc,if (!ms->drmmode.pageflip)return FALSE; +if (ms->drmmode.dri2_flipping) +return FALSE; +if (!scrn->vtSema)return FALSE;
@@ -283,6 +291,7 @@ ms_present_flip(RRCrtcPtr crtc, {ScreenPtr screen = crtc->pScreen;ScrnInfoPtr scrn =xf86ScreenToScrn (screen); +modesettingPtr ms =modesettingPTR (scrn);xf86CrtcPtr xf86_crtc = crtc->devPrivate;drmmode_crtc_private_ptr drmmode_crtc = xf86_crtc->driver_private;Bool ret;
@@ -298,10 +307,14 @@ ms_present_flip(RRCrtcPtr crtc,DebugPresent (("\t\tms:fq %lld\n" , event_id)); event->event_id = event_id; + event->unflip = FALSE; + ret =ms_do_pageflip (screen, pixmap, event, drmmode_crtc->vblank_pipe, !sync_flip, ms_present_flip_handler, ms_present_flip_abort);if (!ret)xf86DrvMsg (scrn->scrnIndex,X_ERROR ,"present flip failed\n" ); +else + ms->drmmode.present_flipping = TRUE;return ret; }
@@ -313,6 +326,7 @@ static void ms_present_unflip(ScreenPtr screen, uint64_t event_id) {ScrnInfoPtr scrn =xf86ScreenToScrn (screen); +modesettingPtr ms =modesettingPTR (scrn);PixmapPtr pixmap = screen->GetScreenPixmap (screen);xf86CrtcConfigPtr config =XF86_CRTC_CONFIG_PTR (scrn);int i;
@@ -323,6 +337,7 @@ ms_present_unflip(ScreenPtr screen, uint64_t event_id)return ; event->event_id = event_id; + event->unflip = TRUE;if (ms_present_check_flip (NULL , screen->root, pixmap, TRUE) && ms_do_pageflip(screen, pixmap, event, -1, FALSE,
@@ -354,6 +369,7 @@ ms_present_unflip(ScreenPtr screen, uint64_t event_id) }present_event_notify (event_id,0 ,0 ); + ms->drmmode.present_flipping = FALSE; }#endif
Signature · 6 lines
2.7.4 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 15 lines · Qiang Yu
Hi guys,
This patch set is for adding DRI2 page flip support to modesetting driver. I mainly take reference of amdgpu DDX and reuse present page flip code in the modesetting driver.
V2:
1. fix DRI2 page flip success handler event memory leak
2. adjust patch sequence to make DRI2 use the common page flip code inpageflip.cfrom the beginning
3. some fix on debug output and commentsRegards,
Qiang
Quoted 6 lines
Qiang Yu (5):
modesetting: makems_do_pageflipgeneric for share with DRI2
modesetting: movems_do_pagefliptopageflip.c
modesetting: move common page flip handle topageflip.c
modesetting: add DRI2 page flip support
modesetting: exclude DRI2 and prensent page flip
Please squash patch 5 into patch 4.
Signature · 6 lines
Earthling Michel Dänzer | http://www.amd.com Libre software enthusiast | Mesa and X developer _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx