From 0732f81a2c67354ddfa7a495bee6b0997c6ef244 Mon Sep 17 00:00:00 2001 From: Michel Dänzer Date: Tue, 21 Apr 2020 10:54:47 +0200 Subject: glamor: Make pixmap scanout compatible if its dimensions are Namely, if its dimensions match those of the screen pixmap (enough that it could stand in for it). When that's the case, the pixmap may end up being scanned out directly due to page flipping via the Present extension, e.g. with xfwm4 --vblank=xpresent . v2: * Use AMDGPU_CREATE_PIXMAP_SCANOUT instead of second-guessing in amdgpu_alloc_pixmap_bo, fixes corruption when resizing from smaller to larger virtual size via RandR. Closes: https://gitlab.freedesktop.org/xorg/driver/xf86-video-amdgpu/-/issues/10 --- src/amdgpu_bo_helper.c | 2 +- src/amdgpu_glamor.c | 15 +++++++++++---- src/amdgpu_kms.c | 7 ++++--- src/drmmode_display.c | 10 +++++----- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/amdgpu_bo_helper.c b/src/amdgpu_bo_helper.c index 3f62214..df32f5d 100644 --- a/src/amdgpu_bo_helper.c +++ b/src/amdgpu_bo_helper.c @@ -79,7 +79,7 @@ struct amdgpu_buffer *amdgpu_alloc_pixmap_bo(ScrnInfoPtr pScrn, int width, } pixmap_buffer->ref_count = 1; - if ( bitsPerPixel == pScrn->bitsPerPixel) + if (usage_hint & AMDGPU_CREATE_PIXMAP_SCANOUT) bo_use |= GBM_BO_USE_SCANOUT; #ifdef HAVE_GBM_BO_USE_LINEAR diff --git a/src/amdgpu_glamor.c b/src/amdgpu_glamor.c index 5b8d560..174bbdf 100644 --- a/src/amdgpu_glamor.c +++ b/src/amdgpu_glamor.c @@ -201,11 +201,12 @@ amdgpu_glamor_create_pixmap(ScreenPtr screen, int w, int h, int depth, unsigned usage) { ScrnInfoPtr scrn = xf86ScreenToScrn(screen); + PixmapFormatPtr format = xf86GetPixFormat(scrn, depth); AMDGPUInfoPtr info = AMDGPUPTR(scrn); struct amdgpu_pixmap *priv; PixmapPtr pixmap, new_pixmap = NULL; - if (!xf86GetPixFormat(scrn, depth)) + if (!format) return NULL; if (!AMDGPU_CREATE_PIXMAP_SHARED(usage)) { @@ -216,9 +217,15 @@ amdgpu_glamor_create_pixmap(ScreenPtr screen, int w, int h, int depth, usage |= AMDGPU_CREATE_PIXMAP_LINEAR | AMDGPU_CREATE_PIXMAP_GTT; } else if (usage != CREATE_PIXMAP_USAGE_BACKING_PIXMAP) { - pixmap = glamor_create_pixmap(screen, w, h, depth, usage); - if (pixmap) - return pixmap; + if (w < scrn->virtualX || w > scrn->displayWidth || + h != scrn->virtualY || + format->bitsPerPixel != scrn->bitsPerPixel) { + pixmap = glamor_create_pixmap(screen, w, h, depth, usage); + if (pixmap) + return pixmap; + } else { + usage |= AMDGPU_CREATE_PIXMAP_SCANOUT; + } } } diff --git a/src/amdgpu_kms.c b/src/amdgpu_kms.c index f0831d2..54238c4 100644 --- a/src/amdgpu_kms.c +++ b/src/amdgpu_kms.c @@ -2207,6 +2207,7 @@ Bool AMDGPUEnterVT_KMS(ScrnInfoPtr pScrn) struct amdgpu_buffer *front_buffer = amdgpu_alloc_pixmap_bo(pScrn, pScrn->virtualX, pScrn->virtualY, pScrn->depth, + AMDGPU_CREATE_PIXMAP_SCANOUT | AMDGPU_CREATE_PIXMAP_LINEAR, pScrn->bitsPerPixel, &pitch); @@ -2413,12 +2414,12 @@ static Bool amdgpu_setup_kernel_mem(ScreenPtr pScreen) if (!info->front_buffer) { int pitch; - int hint = 0; + int hint = AMDGPU_CREATE_PIXMAP_SCANOUT; if (info->shadow_primary) - hint = AMDGPU_CREATE_PIXMAP_LINEAR | AMDGPU_CREATE_PIXMAP_GTT; + hint |= AMDGPU_CREATE_PIXMAP_LINEAR | AMDGPU_CREATE_PIXMAP_GTT; else if (!info->use_glamor) - hint = AMDGPU_CREATE_PIXMAP_LINEAR; + hint |= AMDGPU_CREATE_PIXMAP_LINEAR; info->front_buffer = amdgpu_alloc_pixmap_bo(pScrn, pScrn->virtualX, diff --git a/src/drmmode_display.c b/src/drmmode_display.c index 2c0b96c..1fcc252 100644 --- a/src/drmmode_display.c +++ b/src/drmmode_display.c @@ -557,8 +557,8 @@ drmmode_crtc_scanout_create(xf86CrtcPtr crtc, struct drmmode_scanout *scanout, drmmode_crtc_scanout_destroy(drmmode, scanout); } - scanout->bo = amdgpu_alloc_pixmap_bo(pScrn, width, height, - pScrn->depth, 0, + scanout->bo = amdgpu_alloc_pixmap_bo(pScrn, width, height, pScrn->depth, + AMDGPU_CREATE_PIXMAP_SCANOUT, pScrn->bitsPerPixel, &pitch); if (!scanout->bo) { xf86DrvMsg(pScrn->scrnIndex, X_ERROR, @@ -2975,8 +2975,8 @@ static Bool drmmode_xf86crtc_resize(ScrnInfoPtr scrn, int width, int height) int i, pitch, old_width, old_height, old_pitch; int cpp = info->pixel_bytes; PixmapPtr ppix = screen->GetScreenPixmap(screen); + int hint = AMDGPU_CREATE_PIXMAP_SCANOUT; void *fb_shadow; - int hint = 0; if (scrn->virtualX == width && scrn->virtualY == height) return TRUE; @@ -2990,9 +2990,9 @@ static Bool drmmode_xf86crtc_resize(ScrnInfoPtr scrn, int width, int height) } if (info->shadow_primary) - hint = AMDGPU_CREATE_PIXMAP_LINEAR | AMDGPU_CREATE_PIXMAP_GTT; + hint |= AMDGPU_CREATE_PIXMAP_LINEAR | AMDGPU_CREATE_PIXMAP_GTT; else if (!info->use_glamor) - hint = AMDGPU_CREATE_PIXMAP_LINEAR; + hint |= AMDGPU_CREATE_PIXMAP_LINEAR; xf86DrvMsg(scrn->scrnIndex, X_INFO, "Allocate new frame buffer %dx%d\n", width, height); -- cgit v1.2.3