[Mesa-dev] [PATCH 2/2] RFC i965: Share the GTT between non-robust contexts

Jason Ekstrand jason at jlekstrand.net
Fri Dec 15 15:40:51 UTC 2017


What does this actually gain us?  Multiple contexts aren't common.


On December 15, 2017 05:43:09 Chris Wilson <chris at chris-wilson.co.uk> wrote:

> Every client (everyone instance that opens /dev/dri/card0 or the render
> nodes), receives a unique per-process GTT (where supported by the
> hardware, unfortunately that means only Broadwell and later). Every
> context created by each client, in turns receives its own unique ppGTT.
> This is overkill in terms of allocations and tracking, both in the
> kernel and in the hardware, as we could be sharing the per-client GTT
> amongst all of its contexts. The downside is that context segregation is
> reduced, a stray write from one context may affect another, and so we
> must honour any client requests that require robust segregation (e.g.
> ARB_robustness).
>
> Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
> ---
>  src/mesa/drivers/dri/i965/brw_bufmgr.c  | 23 +++++++++++++++++------
>  src/mesa/drivers/dri/i965/brw_bufmgr.h  |  2 +-
>  src/mesa/drivers/dri/i965/brw_context.c |  2 +-
>  3 files changed, 19 insertions(+), 8 deletions(-)
>
> diff --git a/src/mesa/drivers/dri/i965/brw_bufmgr.c 
> b/src/mesa/drivers/dri/i965/brw_bufmgr.c
> index 52b5bf97a1..d8a9635f5d 100644
> --- a/src/mesa/drivers/dri/i965/brw_bufmgr.c
> +++ b/src/mesa/drivers/dri/i965/brw_bufmgr.c
> @@ -1297,13 +1297,24 @@ init_cache_buckets(struct brw_bufmgr *bufmgr)
>  }
>
>  uint32_t
> -brw_create_hw_context(struct brw_bufmgr *bufmgr)
> +brw_create_hw_context(struct brw_bufmgr *bufmgr, unsigned int flags)
>  {
> -   struct drm_i915_gem_context_create create = { };
> -   int ret = drmIoctl(bufmgr->fd, DRM_IOCTL_I915_GEM_CONTEXT_CREATE, &create);
> -   if (ret != 0) {
> -      DBG("DRM_IOCTL_I915_GEM_CONTEXT_CREATE failed: %s\n", strerror(errno));
> -      return 0;
> +   struct local_i915_gem_context_create_v2 {
> +      uint32_t ctx_id; /* out */
> +      uint32_t flags;
> +#define I915_GEM_CONTEXT_SHARE_GTT 0x1
> +      uint32_t share_ctx;
> +      uint32_t pad;
> +   } create =  { };
> +#define LOCAL_IOCTL_I915_GEM_CONTEXT_CREATE      DRM_IOWR 
> (DRM_COMMAND_BASE + DRM_I915_GEM_CONTEXT_CREATE, struct 
> local_i915_gem_context_create_v2)
> +
> +   if (!(flags & __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS))
> +      create.flags |= I915_GEM_CONTEXT_SHARE_GTT;
> +
> +   if (drmIoctl(bufmgr->fd, LOCAL_IOCTL_I915_GEM_CONTEXT_CREATE, &create)) {
> +      create.flags = 0;
> +      if (drmIoctl(bufmgr->fd, LOCAL_IOCTL_I915_GEM_CONTEXT_CREATE, &create))
> +         return 0;
>     }
>
>     return create.ctx_id;
> diff --git a/src/mesa/drivers/dri/i965/brw_bufmgr.h 
> b/src/mesa/drivers/dri/i965/brw_bufmgr.h
> index 0ae541cda0..f5191aff76 100644
> --- a/src/mesa/drivers/dri/i965/brw_bufmgr.h
> +++ b/src/mesa/drivers/dri/i965/brw_bufmgr.h
> @@ -321,7 +321,7 @@ void brw_bufmgr_enable_reuse(struct brw_bufmgr *bufmgr);
>
>  int brw_bo_wait(struct brw_bo *bo, int64_t timeout_ns);
>
> -uint32_t brw_create_hw_context(struct brw_bufmgr *bufmgr);
> +uint32_t brw_create_hw_context(struct brw_bufmgr *bufmgr, unsigned int flags);
>
>  #define BRW_CONTEXT_LOW_PRIORITY ((I915_CONTEXT_MIN_USER_PRIORITY-1)/2)
>  #define BRW_CONTEXT_MEDIUM_PRIORITY (I915_CONTEXT_DEFAULT_PRIORITY)
> diff --git a/src/mesa/drivers/dri/i965/brw_context.c 
> b/src/mesa/drivers/dri/i965/brw_context.c
> index 9e0f875b27..e374236b6b 100644
> --- a/src/mesa/drivers/dri/i965/brw_context.c
> +++ b/src/mesa/drivers/dri/i965/brw_context.c
> @@ -986,7 +986,7 @@ brwCreateContext(gl_api api,
>      * This is required for transform feedback buffer offsets, query objects,
>      * and also allows us to reduce how much state we have to emit.
>      */
> -   brw->hw_ctx = brw_create_hw_context(brw->bufmgr);
> +   brw->hw_ctx = brw_create_hw_context(brw->bufmgr, ctx_config->flags);
>     if (!brw->hw_ctx && devinfo->gen >= 6) {
>        fprintf(stderr, "Failed to create hardware context.\n");
>        intelDestroyContext(driContextPriv);
> --
> 2.15.1
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev




More information about the mesa-dev mailing list