This will allow mesa to determine if it needs to create a context, or can reuse the default context. Reusing the default context saves memory, and startup time. To keep the libdrm interface as dumb as possible, we simply expose a getter for the default context (which is only a real context when thereis full PPGTT and per fd contexts). As such, callers can expect NULL when this is not the case. See the usage in mesa for details. Cc: Kenneth Graunke <kenneth.w.graunke@xxxxxxxxx> Signed-off-by: Ben Widawsky <ben@xxxxxxxxxxxx> --- include/drm/i915_drm.h | 1 + intel/intel_bufmgr.h | 1 + intel/intel_bufmgr_gem.c | 30 ++++++++++++++++++++++++++++++ intel/intel_bufmgr_priv.h | 1 + 4 files changed, 33 insertions(+) diff --git a/include/drm/i915_drm.h b/include/drm/i915_drm.h index 2f4eb8c..50b080e 100644 --- a/include/drm/i915_drm.h +++ b/include/drm/i915_drm.h @@ -337,6 +337,7 @@ typedef struct drm_i915_irq_wait { #define I915_PARAM_HAS_EXEC_NO_RELOC 25 #define I915_PARAM_HAS_EXEC_HANDLE_LUT 26 #define I915_PARAM_HAS_WT 27 +#define I915_PARAM_HAS_FULL_PPGTT 28 typedef struct drm_i915_getparam { int param; diff --git a/intel/intel_bufmgr.h b/intel/intel_bufmgr.h index 2eb9742..7f08093 100644 --- a/intel/intel_bufmgr.h +++ b/intel/intel_bufmgr.h @@ -191,6 +191,7 @@ int drm_intel_bufmgr_gem_get_devid(drm_intel_bufmgr *bufmgr); int drm_intel_gem_bo_wait(drm_intel_bo *bo, int64_t timeout_ns); drm_intel_context *drm_intel_gem_context_create(drm_intel_bufmgr *bufmgr); +drm_intel_context * drm_intel_gem_default_context_get(drm_intel_bufmgr *bufmgr); void drm_intel_gem_context_destroy(drm_intel_context *ctx); int drm_intel_gem_bo_context_exec(drm_intel_bo *bo, drm_intel_context *ctx, int used, unsigned int flags); diff --git a/intel/intel_bufmgr_gem.c b/intel/intel_bufmgr_gem.c index ad722dd..dbd333a 100644 --- a/intel/intel_bufmgr_gem.c +++ b/intel/intel_bufmgr_gem.c @@ -126,6 +126,7 @@ typedef struct _drm_intel_bufmgr_gem { unsigned int bo_reuse : 1; unsigned int no_exec : 1; unsigned int has_vebox : 1; + unsigned int has_full_ppgtt : 1; bool fenced_relocs; char *aub_filename; @@ -3039,6 +3040,26 @@ drm_intel_gem_context_create(drm_intel_bufmgr *bufmgr) return context; } +drm_intel_context * +drm_intel_gem_default_context_get(drm_intel_bufmgr *bufmgr) +{ + drm_intel_bufmgr_gem *bufmgr_gem = (drm_intel_bufmgr_gem *)bufmgr; + drm_intel_context *context = NULL; + + if (!bufmgr_gem->has_full_ppgtt) + return NULL; + + context = calloc(1, sizeof(*context)); + if (!context) + return NULL; + + context->ctx_id = 0; + context->bufmgr = bufmgr; + context->is_default = 1; + + return context; +} + void drm_intel_gem_context_destroy(drm_intel_context *ctx) { @@ -3049,6 +3070,11 @@ drm_intel_gem_context_destroy(drm_intel_context *ctx) if (ctx == NULL) return; + if (ctx->is_default) { + free(ctx); + return; + } + VG_CLEAR(destroy); bufmgr_gem = (drm_intel_bufmgr_gem *)ctx->bufmgr; @@ -3267,6 +3293,10 @@ drm_intel_bufmgr_gem_init(int fd, int batch_size) ret = drmIoctl(bufmgr_gem->fd, DRM_IOCTL_I915_GETPARAM, &gp); bufmgr_gem->has_vebox = (ret == 0) & (*gp.value > 0); + gp.param = I915_PARAM_HAS_FULL_PPGTT; + ret = drmIoctl(bufmgr_gem->fd, DRM_IOCTL_I915_GETPARAM, &gp); + bufmgr_gem->has_full_ppgtt = (ret == 0) & (*gp.value > 0); + if (bufmgr_gem->gen < 4) { gp.param = I915_PARAM_NUM_FENCES_AVAIL; gp.value = &bufmgr_gem->available_fences; diff --git a/intel/intel_bufmgr_priv.h b/intel/intel_bufmgr_priv.h index 2592d42..e622746 100644 --- a/intel/intel_bufmgr_priv.h +++ b/intel/intel_bufmgr_priv.h @@ -283,6 +283,7 @@ struct _drm_intel_bufmgr { struct _drm_intel_context { unsigned int ctx_id; struct _drm_intel_bufmgr *bufmgr; + int is_default; }; #define ALIGN(value, alignment) ((value + alignment - 1) & ~(alignment - 1)) -- 1.8.5.2 _______________________________________________ Intel-gfx mailing list Intel-gfx@xxxxxxxxxxxxxxxxxxxxx http://lists.freedesktop.org/mailman/listinfo/intel-gfx