All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mario Kleiner <mario.kleiner.de@gmail.com>
To: dri-devel@lists.freedesktop.org
Cc: michel.daenzer@amd.com, jglisse@redhat.com, bskeggs@redhat.com,
	alexander.deucher@amd.com, airlied@redhat.com
Subject: [PATCH 2/2] drm/radeon: Fix pageflipping of PRIME imported scanout bo's.
Date: Wed, 17 Aug 2016 18:12:57 +0200	[thread overview]
Message-ID: <1471450377-12274-3-git-send-email-mario.kleiner.de@gmail.com> (raw)
In-Reply-To: <1471450377-12274-1-git-send-email-mario.kleiner.de@gmail.com>

Scanout bo's which are dmabuf backed in RAM and
imported via prime will not update their content
with new rendering from the renderoffload gpu
once they've been flipped onto the scanout once.
The reason is that at preparation of first flip
they get pinned into VRAM, then unpinned at some
later point, but they stay in the VRAM memory domain,
so updates to the system RAM dmabuf object by the
exporting render offload gpu don't lead to updates
of the content in VRAM - it becomes stale.

For prime imported dmabufs we solve this by first
pinning the bo into GTT, which will reset the bos
domain back to GTT, then unpinning again, so the
followup pinning into VRAM will actually upload an up
to date display buffer from dmabuf GTT backing store.

During the pinning into GTT, we skip the actual data move
from VRAM to GTT to avoid a needless bo copy of stale
image data.

Signed-off-by: Mario Kleiner <mario.kleiner.de@gmail.com>
---
 drivers/gpu/drm/radeon/radeon.h         |  1 +
 drivers/gpu/drm/radeon/radeon_display.c | 28 ++++++++++++++++++++++++++++
 drivers/gpu/drm/radeon/radeon_prime.c   |  1 +
 drivers/gpu/drm/radeon/radeon_ttm.c     | 14 ++++++++++++++
 4 files changed, 44 insertions(+)

diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
index 5633ee3..c200e8a 100644
--- a/drivers/gpu/drm/radeon/radeon.h
+++ b/drivers/gpu/drm/radeon/radeon.h
@@ -508,6 +508,7 @@ struct radeon_bo {
 	struct drm_gem_object		gem_base;
 
 	struct ttm_bo_kmap_obj		dma_buf_vmap;
+	bool				prime_imported;
 	pid_t				pid;
 
 	struct radeon_mn		*mn;
diff --git a/drivers/gpu/drm/radeon/radeon_display.c b/drivers/gpu/drm/radeon/radeon_display.c
index c3206fb..1082267 100644
--- a/drivers/gpu/drm/radeon/radeon_display.c
+++ b/drivers/gpu/drm/radeon/radeon_display.c
@@ -550,6 +550,34 @@ static int radeon_crtc_page_flip(struct drm_crtc *crtc,
 		DRM_ERROR("failed to reserve new rbo buffer before flip\n");
 		goto cleanup;
 	}
+
+	/*
+	 * Repin into GTT in case of imported prime dmabuf,
+	 * then unpin again. Restores source dmabuf location
+	 * to GTT, where the actual dmabuf backing store gets
+	 * updated by the exporting render offload gpu at swap.
+	 */
+	if (new_rbo->prime_imported) {
+		DRM_DEBUG_PRIME("Flip to prime imported dmabuf %p\n", new_rbo);
+
+		r = radeon_bo_pin(new_rbo, RADEON_GEM_DOMAIN_GTT, NULL);
+		if (unlikely(r != 0)) {
+			DRM_ERROR("failed to gtt pin buffer %p before flip\n",
+				  new_rbo);
+		}
+		else {
+			r = radeon_bo_unpin(new_rbo);
+		}
+
+		if (unlikely(r != 0)) {
+			radeon_bo_unreserve(new_rbo);
+			r = -EINVAL;
+			DRM_ERROR("failed to gtt unpin buffer %p before flip\n",
+				  new_rbo);
+			goto cleanup;
+		}
+	}
+
 	/* Only 27 bit offset for legacy CRTC */
 	r = radeon_bo_pin_restricted(new_rbo, RADEON_GEM_DOMAIN_VRAM,
 				     ASIC_IS_AVIVO(rdev) ? 0 : 1 << 27, &base);
diff --git a/drivers/gpu/drm/radeon/radeon_prime.c b/drivers/gpu/drm/radeon/radeon_prime.c
index f3609c9..693c362 100644
--- a/drivers/gpu/drm/radeon/radeon_prime.c
+++ b/drivers/gpu/drm/radeon/radeon_prime.c
@@ -69,6 +69,7 @@ struct drm_gem_object *radeon_gem_prime_import_sg_table(struct drm_device *dev,
 	ww_mutex_lock(&resv->lock, NULL);
 	ret = radeon_bo_create(rdev, attach->dmabuf->size, PAGE_SIZE, false,
 			       RADEON_GEM_DOMAIN_GTT, 0, sg, resv, &bo);
+	bo->prime_imported = true;
 	ww_mutex_unlock(&resv->lock);
 	if (ret)
 		return ERR_PTR(ret);
diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
index 0c00e19..87b3f59 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -256,6 +256,7 @@ static int radeon_move_blit(struct ttm_buffer_object *bo,
 			struct ttm_mem_reg *old_mem)
 {
 	struct radeon_device *rdev;
+	struct radeon_bo *rbo;
 	uint64_t old_start, new_start;
 	struct radeon_fence *fence;
 	unsigned num_pages;
@@ -296,6 +297,19 @@ static int radeon_move_blit(struct ttm_buffer_object *bo,
 	BUILD_BUG_ON((PAGE_SIZE % RADEON_GPU_PAGE_SIZE) != 0);
 
 	num_pages = new_mem->num_pages * (PAGE_SIZE / RADEON_GPU_PAGE_SIZE);
+
+	/*
+	 * Prime imported dmabuf, previously used as scanout buffer in a page
+	 * flip? If so, skip actual data move back from VRAM into GTT, as this
+	 * would only copy back stale image data.
+	 */
+	rbo = container_of(bo, struct radeon_bo, tbo);
+	if (rbo->prime_imported && old_mem->mem_type == TTM_PL_VRAM &&
+	    new_mem->mem_type == TTM_PL_TT) {
+		DRM_DEBUG_PRIME("Skip for dmabuf back-move %p.\n", rbo);
+		num_pages = 0;
+	}
+
 	fence = radeon_copy(rdev, old_start, new_start, num_pages, bo->resv);
 	if (IS_ERR(fence))
 		return PTR_ERR(fence);
-- 
2.7.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  parent reply	other threads:[~2016-08-17 16:13 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-17 16:12 "Fixes" for page flipping under PRIME on AMD & nouveau Mario Kleiner
2016-08-17 16:12 ` [PATCH 1/2] drm/nouveau: Fix pageflipping of PRIME imported scanout bo's Mario Kleiner
2016-08-17 16:12 ` Mario Kleiner [this message]
2016-08-17 16:27 ` "Fixes" for page flipping under PRIME on AMD & nouveau Christian König
2016-08-17 16:35   ` Mario Kleiner
2016-08-17 17:02     ` Christian König
2016-08-17 23:29       ` Mario Kleiner
2016-08-18  7:41         ` Christian König
2016-08-18  7:52           ` Michel Dänzer
2016-08-18  8:20             ` Christian König
2016-08-18  8:26               ` Michel Dänzer
2016-08-17 17:43     ` Alex Deucher
2016-08-17 23:51       ` Mario Kleiner
2016-08-18  2:32         ` Michel Dänzer
2016-08-18  7:49           ` Christian König
2016-08-26 20:07           ` Mario Kleiner
2016-08-29  3:06             ` Michel Dänzer
2016-08-18  2:23 ` Michel Dänzer
2016-08-18 19:21   ` Marek Olšák
2016-08-26 20:10     ` Mario Kleiner
2016-08-26 20:33       ` Alex Deucher
2016-08-26 19:57   ` Mario Kleiner
2016-08-29  3:16     ` Michel Dänzer
2016-08-29 13:20       ` Deucher, Alexander

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1471450377-12274-3-git-send-email-mario.kleiner.de@gmail.com \
    --to=mario.kleiner.de@gmail.com \
    --cc=airlied@redhat.com \
    --cc=alexander.deucher@amd.com \
    --cc=bskeggs@redhat.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jglisse@redhat.com \
    --cc=michel.daenzer@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.