dri3: Flush if necessary in dri3_fd_from_pixmap
PATCH 1/7 dri3: Flush if necessary in dri3_fd_from_pixmap
From: Michel Dänzer <[email protected]>
To make sure the client can't use the shared pixmap storage for direct rendering first, which could produce garbage.
Bugzilla: https://bugs.freedesktop.org/109235
(Ported from amdgpu commit d168532ee739f7e33a2798051e64ba445dd3859f)
--- src/radeon_dri3.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-)
src/radeon_dri3.c +29 -2
@@ -37,6 +37,7 @@#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> +#include <gbm.h> #include <errno.h> #include <libgen.h>
@@ -218,8 +219,34 @@ static int radeon_dri3_fd_from_pixmap(ScreenPtr screen,ScrnInfoPtr scrn =xf86ScreenToScrn (screen);RADEONInfoPtr info =RADEONPTR (scrn); -if (info->use_glamor) -return glamor_fd_from_pixmap (screen, pixmap, stride, size); +if (info->use_glamor) { +Bool need_flush = TRUE; +int ret =-1 ; +#if XORG_VERSION_CURRENT >=XORG_VERSION_NUMERIC (1 ,19 ,99 ,904 ,0 ) +struct gbm_bo *gbm_bo =glamor_gbm_bo_from_pixmap (screen, pixmap); + +if (gbm_bo) { + ret =gbm_bo_get_fd (gbm_bo); +gbm_bo_destroy (gbm_bo); + +if (ret >=0 ) + need_flush = FALSE; + } +#endif + +if (ret <0 ) + ret =glamor_fd_from_pixmap (screen, pixmap, stride, size); + +/* glamor might have needed to reallocate the pixmap storage and +* copy the pixmap contents to the new storage. The copy +* operation needs to be flushed to the kernel driver before the +* client starts using the pixmap storage for direct rendering. +*/ +if (ret >=0 && need_flush) +radeon_cs_flush_indirect (scrn); + +return ret; + }#endif bo =radeon_get_pixmap_bo (pixmap);
Signature · 6 lines
2.20.1 _______________________________________________ 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): 20190128173420.8920-1-michel-otUistvHUpPR7s880joybQ@public.gmane.org
PATCH 2/7 dri2: Flush in dri2_create_buffer2 after calling glamor_set_pixmap_bo
From: Michel Dänzer <[email protected]>
To make sure the client can't use the shared pixmap storage for direct rendering first, which could produce garbage.
Bugzilla: https://bugs.freedesktop.org/109235
(Ported from amdgpu commit ebd32b1c07208f8dbe853e089f5e4b7c6a7a658a)
--- src/radeon_dri2.c | 6 ++++++ 1 file changed, 6 insertions(+)
src/radeon_dri2.c +6 -0
@@ -252,6 +252,12 @@ radeon_dri2_create_buffer2(ScreenPtr pScreen, }else if (is_glamor_pixmap) { pixmap =radeon_glamor_set_pixmap_bo (drawable, pixmap); pixmap->refcnt++; + +/* The copy operation from radeon_glamor_set_pixmap_bo needs to +* be flushed to the kernel driver before the client starts +* using the pixmap storage for direct rendering. +*/ +radeon_cs_flush_indirect (pScrn); }if (!radeon_get_flink_name (pRADEONEnt, pixmap, &buffers->name))
Signature · 6 lines
2.20.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 3/7 glamor: Avoid glamor_create_pixmap for pixmaps backing windows
In reply to a message not in the archiveFrom: Michel Dänzer <[email protected]>
If the compositing manager uses direct rendering (as is usually the case these days), the storage of a pixmap allocated by glamor_create_pixmap needs to be reallocated for sharing it with the compositing manager. Instead, allocate pixmap storage which can be shared directly.
(Ported from amdgpu commit bf326f2ea19daa6c8da23d6788ff301ae70b8e69)
--- src/radeon_glamor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/radeon_glamor.c +1 -1
@@ -238,7 +238,7 @@ radeon_glamor_create_pixmap(ScreenPtr screen, int w, int h, int depth,if (info->shadow_primary) {if (usage !=CREATE_PIXMAP_USAGE_BACKING_PIXMAP )return fbCreatePixmap (screen, w, h, depth, usage); - }else { + }else if (usage !=CREATE_PIXMAP_USAGE_BACKING_PIXMAP ) { pixmap =glamor_create_pixmap (screen, w, h, depth, usage);if (pixmap)return pixmap;
Signature · 6 lines
2.20.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 4/7 Don't allow TearFree scanout flips to complete in the same vblank period
In reply to a message not in the archiveFrom: Michel Dänzer <[email protected]>
We were using a relative target of 0, meaning "complete the flip ASAP". This could result in the flip sometimes, but not always completing in the same vertical blank period where the corresponding drawing occurred, potentially causing judder artifacts with applications updating their window contents synchronized to the display refresh. A good way to test this is the vsynctester.com site in a windowed browser, where the judder results in the large "VSYNC" text intermittently appearing red or cyan instead of the expected gray.
To avoid this, use a relative target MSC of 1, meaning that if a vertical blank period is in progress, the flip will only complete in the next one.
Reported by Julian Tempel and Brandon Wright in
https://bugs.freedesktop.org/106175 .
(Ported from amdgpu commit a1b479c7d0066c481af920f297d6af9009dda11e)
--- src/radeon_kms.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
src/radeon_kms.c +2 -2
@@ -858,7 +858,7 @@ radeon_prime_scanout_flip(PixmapDirtyUpdatePtr ent)if (drmmode_page_flip_target_relative (pRADEONEnt, drmmode_crtc, drmmode_crtc->flip_pending->handle, -0 , drm_queue_seq,0 ) !=0 ) { +0 , drm_queue_seq,1 ) !=0 ) {if (!(drmmode_crtc->scanout_status &DRMMODE_SCANOUT_FLIP_FAILED )) { xf86DrvMsg(scrn->scrnIndex, X_WARNING, "flip queue failed in %s: %s, TearFree inactive\n",
@@ -1175,7 +1175,7 @@ radeon_scanout_flip(ScreenPtr pScreen, RADEONInfoPtr info,if (drmmode_page_flip_target_relative (pRADEONEnt, drmmode_crtc, drmmode_crtc->flip_pending->handle, -0 , drm_queue_seq,0 ) !=0 ) { +0 , drm_queue_seq,1 ) !=0 ) {if (!(drmmode_crtc->scanout_status &DRMMODE_SCANOUT_FLIP_FAILED )) { xf86DrvMsg(scrn->scrnIndex, X_WARNING, "flip queue failed in %s: %s, TearFree inactive\n",
Signature · 6 lines
2.20.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 5/7 Only update drmmode_crtc->flip_pending after actually submitting a flip
In reply to a message not in the archiveFrom: Michel Dänzer <[email protected]>
And only clear it if it matches the framebuffer of the completed flip being processed.
Fixes
(WW) RADEON(0): flip queue failed: Device or resource busy (WW) RADEON(0): Page flip failed: Device or resource busy (EE) RADEON(0): present flip failed
due to clobbering drmmode_crtc->flip_pending.
Reproducer: Enable TearFree, run warzone2100 fullscreen, toggle Vertical sync on/off under Video Options. Discovered while investigating
https://bugs.freedesktop.org/109364 .
(Ported from amdgpu commit e72a02ba1d35743fefd939458b9d8cddce86e7f5)
--- src/drmmode_display.c | 15 ++++++---- src/radeon_kms.c | 66 ++++++++++++++++++++++--------------------- 2 files changed, 43 insertions(+), 38 deletions(-)
src/drmmode_display.c +9 -6
@@ -2651,12 +2651,14 @@ drmmode_flip_handler(xf86CrtcPtr crtc, uint32_t frame, uint64_t usec, void *even flipdata->fe_usec = usec; } -if (drmmode_crtc->flip_pending == *fb) { -drmmode_fb_reference (pRADEONEnt->fd, - &drmmode_crtc->flip_pending,NULL ); +if (*fb) { +if (drmmode_crtc->flip_pending == *fb) { +drmmode_fb_reference (pRADEONEnt->fd, + &drmmode_crtc->flip_pending,NULL ); + } +drmmode_fb_reference (pRADEONEnt->fd, &drmmode_crtc->fb, *fb); +drmmode_fb_reference (pRADEONEnt->fd, fb,NULL ); } -drmmode_fb_reference (pRADEONEnt->fd, &drmmode_crtc->fb, *fb); -drmmode_fb_reference (pRADEONEnt->fd, fb,NULL );if (--flipdata->flip_count ==0 ) {/* Deliver MSC & UST from reference/current CRTC to flip event
@@ -3492,9 +3494,10 @@ Bool radeon_do_pageflip(ScrnInfoPtr scrn, ClientPtr client, drmmode_crtc->ignore_damage = TRUE; } - next:drmmode_fb_reference (pRADEONEnt->fd, &drmmode_crtc->flip_pending, flipdata->fb[crtc_id]); + + next: drm_queue_seq =0 ; }
src/radeon_kms.c +34 -32
141 lines not on this page · raw message
Signature · 6 lines
2.20.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 6/7 Call drmHandleEvent again if it was interrupted by a signal
In reply to a message not in the archiveFrom: Michel Dänzer <[email protected]>
drmHandleEvent can be interrupted by a signal in read(), in which case it doesn't process any events but returns -1, which drm_handle_event propagated to its callers. This could cause the following failure cascade:
1. drm_wait_pending_flip stopped waiting for a pending flip.
2. Its caller cleared drmmode_crtc->flip_pending before the flip completed.
3. Another flip was attempted but got an unexpected EBUSY error because the previous flip was still pending.
4. TearFree was disabled due to the error.
The solution is to call drmHandleEvent if it was interrupted by a signal. We can do that in drm_handle_event, because when that is called, either it is known that there are events ready to be processed, or the caller has to wait for events to arrive anyway.
v2:
* Use ErrorF instead of xf86DrvMsg with hard-coded screen 0.
Bugzilla: https://bugs.freedesktop.org/109364
(Ported from amdgpu commit 3ff2cc225f6bc08364ee007fa54e9d0150adaf11)
--- src/radeon_drm_queue.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
src/radeon_drm_queue.c +16 -1
@@ -30,6 +30,8 @@#include "config.h" #endif +#include <errno.h> +#include <xorg-server.h> #include <X11/Xdefs.h> #include <list.h>
@@ -277,7 +279,20 @@ radeon_drm_handle_event(int fd, drmEventContext *event_context)struct radeon_drm_queue_entry *e;int r; - r =drmHandleEvent (fd, event_context); +/* Retry drmHandleEvent if it was interrupted by a signal in read() */ +do { + r =drmHandleEvent (fd, event_context); + }while (r <0 && (errno ==EINTR || errno ==EAGAIN )); + +if (r <0 ) { +static Bool printed; + +if (!printed) { +ErrorF ("%s: drmHandleEvent returned %d, errno=%d (%s)\n" , + __func__, r, errno,strerror (errno)); + printed = TRUE; + } + }while (!xorg_list_is_empty (&radeon_drm_flip_signalled)) { e = xorg_list_first_entry(&radeon_drm_flip_signalled,
Signature · 6 lines
2.20.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH 7/7 Keep waiting for a pending flip if drm_handle_event returns 0
In reply to a message not in the archiveFrom: Michel Dänzer <[email protected]>
drm_wait_pending_flip stopped waiting if drm_handle_event returned 0, but that might have processed only some unrelated DRM events. As long as the flip is pending, we have to keep waiting for its completion event.
Noticed while working on the previous fix.
(Ported from amdgpu commit 9045fb310f88780e250e60b80431ca153330e61b)
--- src/radeon_drm_queue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
src/radeon_drm_queue.c +1 -1
@@ -325,7 +325,7 @@ void radeon_drm_wait_pending_flip(xf86CrtcPtr crtc)while (drmmode_crtc->flip_pending &&radeon_drm_handle_event (pRADEONEnt->fd, - &drmmode_crtc->drmmode->event_context) >0 ); + &drmmode_crtc->drmmode->event_context) >=0 ); }/*
Signature · 6 lines
2.20.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx