xf86-video-amdgpu: Branch 'master' - 6 commits
Michel Dänzer
daenzer at kemper.freedesktop.org
Tue Jun 14 09:30:54 UTC 2016
src/amdgpu_bo_helper.c | 48 +++++++++++++++++--------
src/amdgpu_bo_helper.h | 20 +++++++++-
src/amdgpu_dri2.c | 63 ++-------------------------------
src/amdgpu_glamor.c | 80 +++++++++++++++++++++++++++++++++++++++++--
src/amdgpu_glamor.h | 1
src/amdgpu_glamor_wrappers.c | 18 ---------
src/amdgpu_pixmap.h | 2 +
7 files changed, 134 insertions(+), 98 deletions(-)
New commits:
commit 0007c2f018ba663303d91d847e7c085269a23062
Author: Michel Dänzer <michel.daenzer at amd.com>
Date: Wed Jun 8 16:27:33 2016 +0900
glamor: Reallocate linear pixmap BO if necessary for DRI2 PRIME
Fixes corruption when using DRI2 PRIME render offloading with the master
screen using this driver.
Reported-by: Qiang Yu <qiang.yu at amd.com>
Reviewed-by: Alex Deucher <alexander.deucher at amd.com>
Tested-by: Qiang Yu <qiang.yu at amd.com>
diff --git a/src/amdgpu_glamor.c b/src/amdgpu_glamor.c
index 6fbe089..3f4b1af 100644
--- a/src/amdgpu_glamor.c
+++ b/src/amdgpu_glamor.c
@@ -327,10 +327,31 @@ amdgpu_glamor_share_pixmap_backing(PixmapPtr pixmap, ScreenPtr slave,
void **handle_p)
{
ScreenPtr screen = pixmap->drawable.pScreen;
+ uint64_t tiling_info;
CARD16 stride;
CARD32 size;
int fd;
+ tiling_info = amdgpu_pixmap_get_tiling_info(pixmap);
+ if (AMDGPU_TILING_GET(tiling_info, ARRAY_MODE) != 0) {
+ PixmapPtr linear;
+
+ /* We don't want to re-allocate the screen pixmap as
+ * linear, to avoid trouble with page flipping
+ */
+ if (screen->GetScreenPixmap(screen) == pixmap)
+ return FALSE;
+
+ linear = screen->CreatePixmap(screen, pixmap->drawable.width,
+ pixmap->drawable.height,
+ pixmap->drawable.depth,
+ CREATE_PIXMAP_USAGE_SHARED);
+ if (!linear)
+ return FALSE;
+
+ amdgpu_glamor_set_pixmap_bo(&pixmap->drawable, linear);
+ }
+
fd = glamor_fd_from_pixmap(screen, pixmap, &stride, &size);
if (fd < 0)
return FALSE;
commit 5518bf5d793439b5bab369e5fc18de9a4a3b9dd6
Author: Michel Dänzer <michel.daenzer at amd.com>
Date: Wed Jun 8 16:44:26 2016 +0900
Move DRI2's local fixup_glamor helper to amdgpu_glamor_set_pixmap_bo v2
So it can be used outside of the DRI2 code.
v2: Keep pixmap refcnt increment in amdgpu_dri2_create_buffer2 (Qiang Yu)
Reviewed-by: Alex Deucher <alexander.deucher at amd.com>
Tested-by: Qiang Yu <qiang.yu at amd.com> (v1)
diff --git a/src/amdgpu_dri2.c b/src/amdgpu_dri2.c
index 5f978c9..9cdcf28 100644
--- a/src/amdgpu_dri2.c
+++ b/src/amdgpu_dri2.c
@@ -98,54 +98,6 @@ amdgpu_get_flink_name(AMDGPUEntPtr pAMDGPUEnt, PixmapPtr pixmap, uint32_t *name)
return TRUE;
}
-static PixmapPtr fixup_glamor(DrawablePtr drawable, PixmapPtr pixmap)
-{
- PixmapPtr old = get_drawable_pixmap(drawable);
- ScreenPtr screen = drawable->pScreen;
- struct amdgpu_pixmap *priv = amdgpu_get_pixmap_private(pixmap);
- GCPtr gc;
-
- /* With a glamor pixmap, 2D pixmaps are created in texture
- * and without a static BO attached to it. To support DRI,
- * we need to create a new textured-drm pixmap and
- * need to copy the original content to this new textured-drm
- * pixmap, and then convert the old pixmap to a coherent
- * textured-drm pixmap which has a valid BO attached to it
- * and also has a valid texture, thus both glamor and DRI2
- * can access it.
- *
- */
-
- /* Copy the current contents of the pixmap to the bo. */
- gc = GetScratchGC(drawable->depth, screen);
- if (gc) {
- ValidateGC(&pixmap->drawable, gc);
- gc->ops->CopyArea(&old->drawable, &pixmap->drawable,
- gc,
- 0, 0,
- old->drawable.width,
- old->drawable.height, 0, 0);
- FreeScratchGC(gc);
- }
-
- amdgpu_set_pixmap_private(pixmap, NULL);
-
- /* And redirect the pixmap to the new bo (for 3D). */
- glamor_egl_exchange_buffers(old, pixmap);
- amdgpu_set_pixmap_private(old, priv);
- old->refcnt++;
-
- screen->ModifyPixmapHeader(old,
- old->drawable.width,
- old->drawable.height,
- 0, 0, pixmap->devKind, NULL);
- old->devPrivate.ptr = NULL;
-
- screen->DestroyPixmap(pixmap);
-
- return old;
-}
-
static BufferPtr
amdgpu_dri2_create_buffer2(ScreenPtr pScreen,
DrawablePtr drawable,
@@ -217,8 +169,10 @@ amdgpu_dri2_create_buffer2(ScreenPtr pScreen,
goto error;
if (pixmap) {
- if (is_glamor_pixmap)
- pixmap = fixup_glamor(drawable, pixmap);
+ if (is_glamor_pixmap) {
+ pixmap = amdgpu_glamor_set_pixmap_bo(drawable, pixmap);
+ pixmap->refcnt++;
+ }
if (!amdgpu_get_flink_name(pAMDGPUEnt, pixmap, &buffers->name))
goto error;
diff --git a/src/amdgpu_glamor.c b/src/amdgpu_glamor.c
index b6ec98f..6fbe089 100644
--- a/src/amdgpu_glamor.c
+++ b/src/amdgpu_glamor.c
@@ -272,6 +272,54 @@ fallback_pixmap:
return fbCreatePixmap(screen, w, h, depth, usage);
}
+PixmapPtr
+amdgpu_glamor_set_pixmap_bo(DrawablePtr drawable, PixmapPtr pixmap)
+{
+ PixmapPtr old = get_drawable_pixmap(drawable);
+ ScreenPtr screen = drawable->pScreen;
+ struct amdgpu_pixmap *priv = amdgpu_get_pixmap_private(pixmap);
+ GCPtr gc;
+
+ /* With a glamor pixmap, 2D pixmaps are created in texture
+ * and without a static BO attached to it. To support DRI,
+ * we need to create a new textured-drm pixmap and
+ * need to copy the original content to this new textured-drm
+ * pixmap, and then convert the old pixmap to a coherent
+ * textured-drm pixmap which has a valid BO attached to it
+ * and also has a valid texture, thus both glamor and DRI2
+ * can access it.
+ *
+ */
+
+ /* Copy the current contents of the pixmap to the bo. */
+ gc = GetScratchGC(drawable->depth, screen);
+ if (gc) {
+ ValidateGC(&pixmap->drawable, gc);
+ gc->ops->CopyArea(&old->drawable, &pixmap->drawable,
+ gc,
+ 0, 0,
+ old->drawable.width,
+ old->drawable.height, 0, 0);
+ FreeScratchGC(gc);
+ }
+
+ amdgpu_set_pixmap_private(pixmap, NULL);
+
+ /* And redirect the pixmap to the new bo (for 3D). */
+ glamor_egl_exchange_buffers(old, pixmap);
+ amdgpu_set_pixmap_private(old, priv);
+
+ screen->ModifyPixmapHeader(old,
+ old->drawable.width,
+ old->drawable.height,
+ 0, 0, pixmap->devKind, NULL);
+ old->devPrivate.ptr = NULL;
+
+ screen->DestroyPixmap(pixmap);
+
+ return old;
+}
+
#ifdef AMDGPU_PIXMAP_SHARING
static Bool
diff --git a/src/amdgpu_glamor.h b/src/amdgpu_glamor.h
index 77e0c21..05ca5cf 100644
--- a/src/amdgpu_glamor.h
+++ b/src/amdgpu_glamor.h
@@ -71,6 +71,7 @@ void amdgpu_glamor_finish(ScrnInfoPtr pScrn);
Bool
amdgpu_glamor_create_textured_pixmap(PixmapPtr pixmap, struct amdgpu_pixmap *priv);
void amdgpu_glamor_exchange_buffers(PixmapPtr src, PixmapPtr dst);
+PixmapPtr amdgpu_glamor_set_pixmap_bo(DrawablePtr drawable, PixmapPtr pixmap);
XF86VideoAdaptorPtr amdgpu_glamor_xv_init(ScreenPtr pScreen, int num_adapt);
commit 641f4647b7f51dfd2da330376cd10fa9702b6423
Author: Michel Dänzer <michel.daenzer at amd.com>
Date: Wed Jun 8 16:39:10 2016 +0900
Consolidate get_drawable_pixmap helper
There were two static helpers for the same purpose. Consolidate them
into a single inline helper which can be used anywhere.
Reviewed-by: Alex Deucher <alexander.deucher at amd.com>
Tested-by: Qiang Yu <qiang.yu at amd.com>
diff --git a/src/amdgpu_bo_helper.h b/src/amdgpu_bo_helper.h
index efbdcda..26fca16 100644
--- a/src/amdgpu_bo_helper.h
+++ b/src/amdgpu_bo_helper.h
@@ -104,4 +104,20 @@ struct amdgpu_buffer *amdgpu_gem_bo_open_prime(amdgpu_device_handle pDev,
int fd_handle,
uint32_t size);
+/**
+ * get_drawable_pixmap() returns the backing pixmap for a given drawable.
+ *
+ * @param drawable the drawable being requested.
+ *
+ * This function returns the backing pixmap for a drawable, whether it is a
+ * redirected window, unredirected window, or already a pixmap.
+ */
+static inline PixmapPtr get_drawable_pixmap(DrawablePtr drawable)
+{
+ if (drawable->type == DRAWABLE_PIXMAP)
+ return (PixmapPtr)drawable;
+ else
+ return drawable->pScreen->GetWindowPixmap((WindowPtr)drawable);
+}
+
#endif /* AMDGPU_BO_HELPER_H */
diff --git a/src/amdgpu_dri2.c b/src/amdgpu_dri2.c
index 27a0c1a..5f978c9 100644
--- a/src/amdgpu_dri2.c
+++ b/src/amdgpu_dri2.c
@@ -98,15 +98,6 @@ amdgpu_get_flink_name(AMDGPUEntPtr pAMDGPUEnt, PixmapPtr pixmap, uint32_t *name)
return TRUE;
}
-static PixmapPtr get_drawable_pixmap(DrawablePtr drawable)
-{
- if (drawable->type == DRAWABLE_PIXMAP)
- return (PixmapPtr) drawable;
- else
- return (*drawable->pScreen->
- GetWindowPixmap) ((WindowPtr) drawable);
-}
-
static PixmapPtr fixup_glamor(DrawablePtr drawable, PixmapPtr pixmap)
{
PixmapPtr old = get_drawable_pixmap(drawable);
diff --git a/src/amdgpu_glamor_wrappers.c b/src/amdgpu_glamor_wrappers.c
index 35b6d7e..81b212d 100644
--- a/src/amdgpu_glamor_wrappers.c
+++ b/src/amdgpu_glamor_wrappers.c
@@ -39,24 +39,6 @@
#include "amdgpu_pixmap.h"
-/**
- * get_drawable_pixmap() returns the backing pixmap for a given drawable.
- *
- * @param pDrawable the drawable being requested.
- *
- * This function returns the backing pixmap for a drawable, whether it is a
- * redirected window, unredirected window, or already a pixmap.
- */
-static PixmapPtr
-get_drawable_pixmap(DrawablePtr pDrawable)
-{
- if (pDrawable->type == DRAWABLE_WINDOW)
- return pDrawable->pScreen->
- GetWindowPixmap((WindowPtr) pDrawable);
- else
- return (PixmapPtr) pDrawable;
-}
-
/* Are there any outstanding GPU operations for this pixmap? */
static Bool
amdgpu_glamor_gpu_pending(uint_fast32_t gpu_synced, uint_fast32_t gpu_access)
commit 8e40f190e4704c2802bf0f073f17e742786d0f18
Author: Michel Dänzer <michel.daenzer at amd.com>
Date: Wed Jun 8 16:00:21 2016 +0900
Add amdgpu_pixmap_get_tiling_info
Retrieves the tiling information about a pixmap BO from the kernel
driver.
Reviewed-by: Alex Deucher <alexander.deucher at amd.com>
Tested-by: Qiang Yu <qiang.yu at amd.com>
diff --git a/src/amdgpu_bo_helper.c b/src/amdgpu_bo_helper.c
index a566920..783347b 100644
--- a/src/amdgpu_bo_helper.c
+++ b/src/amdgpu_bo_helper.c
@@ -131,6 +131,35 @@ Bool amdgpu_bo_get_handle(struct amdgpu_buffer *bo, uint32_t *handle)
handle) == 0;
}
+static void amdgpu_pixmap_do_get_tiling_info(PixmapPtr pixmap)
+{
+ struct amdgpu_pixmap *priv = amdgpu_get_pixmap_private(pixmap);
+ ScreenPtr screen = pixmap->drawable.pScreen;
+ ScrnInfoPtr scrn = xf86ScreenToScrn(screen);
+ AMDGPUEntPtr pAMDGPUEnt = AMDGPUEntPriv(scrn);
+ struct drm_amdgpu_gem_metadata gem_metadata;
+
+ gem_metadata.handle = priv->handle;
+ gem_metadata.op = AMDGPU_GEM_METADATA_OP_GET_METADATA;
+
+ if (drmCommandWriteRead(pAMDGPUEnt->fd, DRM_AMDGPU_GEM_METADATA,
+ &gem_metadata, sizeof(gem_metadata)) == 0)
+ priv->tiling_info = gem_metadata.data.tiling_info;
+}
+
+uint64_t amdgpu_pixmap_get_tiling_info(PixmapPtr pixmap)
+{
+ struct amdgpu_pixmap *priv = amdgpu_get_pixmap_private(pixmap);
+ uint32_t handle;
+
+ if (!priv || !priv->handle_valid) {
+ amdgpu_pixmap_get_handle(pixmap, &handle);
+ priv = amdgpu_get_pixmap_private(pixmap);
+ }
+
+ return priv->tiling_info;
+}
+
Bool amdgpu_pixmap_get_handle(PixmapPtr pixmap, uint32_t *handle)
{
#ifdef USE_GLAMOR
@@ -162,13 +191,15 @@ Bool amdgpu_pixmap_get_handle(PixmapPtr pixmap, uint32_t *handle)
r = drmPrimeFDToHandle(pAMDGPUEnt->fd, fd, &priv->handle);
close(fd);
if (r == 0)
- goto success;
+ goto get_tiling_info;
}
#endif
if (!priv->bo || !amdgpu_bo_get_handle(priv->bo, &priv->handle))
return FALSE;
+ get_tiling_info:
+ amdgpu_pixmap_do_get_tiling_info(pixmap);
success:
priv->handle_valid = TRUE;
*handle = priv->handle;
diff --git a/src/amdgpu_bo_helper.h b/src/amdgpu_bo_helper.h
index 3e81fca..efbdcda 100644
--- a/src/amdgpu_bo_helper.h
+++ b/src/amdgpu_bo_helper.h
@@ -31,6 +31,8 @@ extern struct amdgpu_buffer *amdgpu_alloc_pixmap_bo(ScrnInfoPtr pScrn, int width
extern Bool amdgpu_bo_get_handle(struct amdgpu_buffer *bo, uint32_t *handle);
+extern uint64_t amdgpu_pixmap_get_tiling_info(PixmapPtr pixmap);
+
extern Bool amdgpu_pixmap_get_handle(PixmapPtr pixmap, uint32_t *handle);
extern int amdgpu_bo_map(ScrnInfoPtr pScrn, struct amdgpu_buffer *bo);
diff --git a/src/amdgpu_pixmap.h b/src/amdgpu_pixmap.h
index 1fba90e..ecdd74d 100644
--- a/src/amdgpu_pixmap.h
+++ b/src/amdgpu_pixmap.h
@@ -32,6 +32,8 @@ struct amdgpu_pixmap {
uint_fast32_t gpu_read;
uint_fast32_t gpu_write;
+ uint64_t tiling_info;
+
struct amdgpu_buffer *bo;
/* GEM handle for pixmaps shared via DRI2/3 */
commit e7eeb6ad1133b6023d34b4489959ae330a8e15dd
Author: Michel Dänzer <michel.daenzer at amd.com>
Date: Wed Jun 8 15:42:01 2016 +0900
Remove amdgpu_share_pixmap_backing
Not used anymore.
Reviewed-by: Alex Deucher <alexander.deucher at amd.com>
Tested-by: Qiang Yu <qiang.yu at amd.com>
diff --git a/src/amdgpu_bo_helper.c b/src/amdgpu_bo_helper.c
index 01b0d87..a566920 100644
--- a/src/amdgpu_bo_helper.c
+++ b/src/amdgpu_bo_helper.c
@@ -345,21 +345,6 @@ struct amdgpu_buffer *amdgpu_gem_bo_open_prime(amdgpu_device_handle pDev,
#ifdef AMDGPU_PIXMAP_SHARING
-Bool amdgpu_share_pixmap_backing(struct amdgpu_buffer *bo, void **handle_p)
-{
- int handle;
-
- if (bo->flags & AMDGPU_BO_FLAGS_GBM)
- handle = gbm_bo_get_fd(bo->bo.gbm);
- else
- amdgpu_bo_export(bo->bo.amdgpu,
- amdgpu_bo_handle_type_dma_buf_fd,
- (uint32_t *)&handle);
-
- *handle_p = (void *)(long)handle;
- return TRUE;
-}
-
Bool amdgpu_set_shared_pixmap_backing(PixmapPtr ppix, void *fd_handle)
{
ScrnInfoPtr pScrn = xf86ScreenToScrn(ppix->drawable.pScreen);
diff --git a/src/amdgpu_bo_helper.h b/src/amdgpu_bo_helper.h
index 10e2db7..3e81fca 100644
--- a/src/amdgpu_bo_helper.h
+++ b/src/amdgpu_bo_helper.h
@@ -37,8 +37,6 @@ extern int amdgpu_bo_map(ScrnInfoPtr pScrn, struct amdgpu_buffer *bo);
extern void amdgpu_bo_unmap(struct amdgpu_buffer *bo);
-extern Bool amdgpu_share_pixmap_backing(struct amdgpu_buffer *bo, void **handle_p);
-
extern Bool
amdgpu_set_shared_pixmap_backing(PixmapPtr ppix, void *fd_handle);
commit b36c77695ba77b59a0ccd868454e3af4fc04d5ff
Author: Michel Dänzer <michel.daenzer at amd.com>
Date: Wed Jun 8 15:38:57 2016 +0900
glamor: Fix amdgpu_glamor_share_pixmap_backing for priv->bo == NULL
Fixes crash when running a compositor and DRI_PRIME client via DRI2.
Reported-by: Qiang Yu <qiang.yu at amd.com>
Reviewed-by: Alex Deucher <alexander.deucher at amd.com>
Tested-by: Qiang Yu <qiang.yu at amd.com>
diff --git a/src/amdgpu_glamor.c b/src/amdgpu_glamor.c
index 52aa30d..b6ec98f 100644
--- a/src/amdgpu_glamor.c
+++ b/src/amdgpu_glamor.c
@@ -278,12 +278,17 @@ static Bool
amdgpu_glamor_share_pixmap_backing(PixmapPtr pixmap, ScreenPtr slave,
void **handle_p)
{
- struct amdgpu_pixmap *priv = amdgpu_get_pixmap_private(pixmap);
+ ScreenPtr screen = pixmap->drawable.pScreen;
+ CARD16 stride;
+ CARD32 size;
+ int fd;
- if (!priv)
+ fd = glamor_fd_from_pixmap(screen, pixmap, &stride, &size);
+ if (fd < 0)
return FALSE;
- return amdgpu_share_pixmap_backing(priv->bo, handle_p);
+ *handle_p = (void *)(long)fd;
+ return TRUE;
}
static Bool
More information about the xorg-commit
mailing list