Mesa (main): iris: Track imported vs. exported status separately
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Wed Jun 2 21:37:21 UTC 2021
Module: Mesa
Branch: main
Commit: 49070038f432a7266ce99898732e0a878438774f
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=49070038f432a7266ce99898732e0a878438774f
Author: Kenneth Graunke <kenneth at whitecape.org>
Date: Thu May 20 10:55:53 2021 -0700
iris: Track imported vs. exported status separately
Not all external objects are the same. Imported buffers may be from
other devices (say a dmabuf from an AMD or NVIDIA discrete card) which
are backed by memory that we can't use with I915_GEM_MMAP. However,
exported buffers are ones that we know we allocated ourselves from our
own device. We may not know what other clients are doing with them,
but we can assume a bit more about where they came from.
Acked-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10941>
---
src/gallium/drivers/iris/iris_bufmgr.c | 26 ++++++++++++++------------
src/gallium/drivers/iris/iris_bufmgr.h | 17 ++++++++---------
src/gallium/drivers/iris/iris_resource.c | 4 ++--
3 files changed, 24 insertions(+), 23 deletions(-)
diff --git a/src/gallium/drivers/iris/iris_bufmgr.c b/src/gallium/drivers/iris/iris_bufmgr.c
index c1e0a3dc7b8..a403c8d0119 100644
--- a/src/gallium/drivers/iris/iris_bufmgr.c
+++ b/src/gallium/drivers/iris/iris_bufmgr.c
@@ -730,7 +730,7 @@ iris_bo_gem_create_from_name(struct iris_bufmgr *bufmgr,
bo->name = name;
bo->global_name = handle;
bo->reusable = false;
- bo->external = true;
+ bo->imported = true;
bo->kflags = EXEC_OBJECT_SUPPORTS_48B_ADDRESS | EXEC_OBJECT_PINNED;
bo->gtt_offset = vma_alloc(bufmgr, IRIS_MEMZONE_OTHER, bo->size, 1);
@@ -1438,7 +1438,7 @@ iris_bo_import_dmabuf(struct iris_bufmgr *bufmgr, int prime_fd,
bo->bufmgr = bufmgr;
bo->name = "prime";
bo->reusable = false;
- bo->external = true;
+ bo->imported = true;
bo->kflags = EXEC_OBJECT_SUPPORTS_48B_ADDRESS | EXEC_OBJECT_PINNED;
/* From the Bspec, Memory Compression - Gfx12:
@@ -1523,7 +1523,7 @@ iris_bo_import_dmabuf_no_mods(struct iris_bufmgr *bufmgr,
bo->bufmgr = bufmgr;
bo->name = "prime";
bo->reusable = false;
- bo->external = true;
+ bo->imported = true;
bo->kflags = EXEC_OBJECT_SUPPORTS_48B_ADDRESS | EXEC_OBJECT_PINNED;
bo->gtt_offset = vma_alloc(bufmgr, IRIS_MEMZONE_OTHER, bo->size, 1);
bo->gem_handle = handle;
@@ -1535,32 +1535,34 @@ out:
}
static void
-iris_bo_make_external_locked(struct iris_bo *bo)
+iris_bo_mark_exported_locked(struct iris_bo *bo)
{
- if (!bo->external) {
+ if (!iris_bo_is_external(bo))
_mesa_hash_table_insert(bo->bufmgr->handle_table, &bo->gem_handle, bo);
+
+ if (!bo->exported) {
/* If a BO is going to be used externally, it could be sent to the
* display HW. So make sure our CPU mappings don't assume cache
* coherency since display is outside that cache.
*/
bo->cache_coherent = false;
- bo->external = true;
+ bo->exported = true;
bo->reusable = false;
}
}
void
-iris_bo_make_external(struct iris_bo *bo)
+iris_bo_mark_exported(struct iris_bo *bo)
{
struct iris_bufmgr *bufmgr = bo->bufmgr;
- if (bo->external) {
+ if (bo->exported) {
assert(!bo->reusable);
return;
}
mtx_lock(&bufmgr->lock);
- iris_bo_make_external_locked(bo);
+ iris_bo_mark_exported_locked(bo);
mtx_unlock(&bufmgr->lock);
}
@@ -1569,7 +1571,7 @@ iris_bo_export_dmabuf(struct iris_bo *bo, int *prime_fd)
{
struct iris_bufmgr *bufmgr = bo->bufmgr;
- iris_bo_make_external(bo);
+ iris_bo_mark_exported(bo);
if (drmPrimeHandleToFD(bufmgr->fd, bo->gem_handle,
DRM_CLOEXEC | DRM_RDWR, prime_fd) != 0)
@@ -1581,7 +1583,7 @@ iris_bo_export_dmabuf(struct iris_bo *bo, int *prime_fd)
uint32_t
iris_bo_export_gem_handle(struct iris_bo *bo)
{
- iris_bo_make_external(bo);
+ iris_bo_mark_exported(bo);
return bo->gem_handle;
}
@@ -1599,7 +1601,7 @@ iris_bo_flink(struct iris_bo *bo, uint32_t *name)
mtx_lock(&bufmgr->lock);
if (!bo->global_name) {
- iris_bo_make_external_locked(bo);
+ iris_bo_mark_exported_locked(bo);
bo->global_name = flink.name;
_mesa_hash_table_insert(bufmgr->name_table, &bo->global_name, bo);
}
diff --git a/src/gallium/drivers/iris/iris_bufmgr.h b/src/gallium/drivers/iris/iris_bufmgr.h
index 057ba888501..5d825bce255 100644
--- a/src/gallium/drivers/iris/iris_bufmgr.h
+++ b/src/gallium/drivers/iris/iris_bufmgr.h
@@ -223,10 +223,11 @@ struct iris_bo {
*/
bool reusable;
- /**
- * Boolean of whether this buffer has been shared with an external client.
- */
- bool external;
+ /** Was this buffer imported from an external client? */
+ bool imported;
+
+ /** Has this buffer been exported to external clients? */
+ bool exported;
/**
* Boolean of whether this buffer is cache coherent
@@ -348,15 +349,13 @@ int iris_bo_flink(struct iris_bo *bo, uint32_t *name);
static inline bool
iris_bo_is_external(const struct iris_bo *bo)
{
- return bo->external;
+ return bo->exported || bo->imported;
}
/**
- * Make a BO externally accessible.
- *
- * \param bo Buffer to make external
+ * Mark a buffer as being shared with other external clients.
*/
-void iris_bo_make_external(struct iris_bo *bo);
+void iris_bo_mark_exported(struct iris_bo *bo);
/**
* Returns 1 if mapping the buffer for write could cause the process
diff --git a/src/gallium/drivers/iris/iris_resource.c b/src/gallium/drivers/iris/iris_resource.c
index eb92f12e927..988fcd8287c 100644
--- a/src/gallium/drivers/iris/iris_resource.c
+++ b/src/gallium/drivers/iris/iris_resource.c
@@ -971,7 +971,7 @@ iris_resource_create_for_buffer(struct pipe_screen *pscreen,
}
if (templ->bind & PIPE_BIND_SHARED) {
- iris_bo_make_external(res->bo);
+ iris_bo_mark_exported(res->bo);
res->base.is_shared = true;
}
@@ -1068,7 +1068,7 @@ iris_resource_create_with_modifiers(struct pipe_screen *pscreen,
}
if (templ->bind & PIPE_BIND_SHARED) {
- iris_bo_make_external(res->bo);
+ iris_bo_mark_exported(res->bo);
res->base.is_shared = true;
}
More information about the mesa-commit
mailing list