public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Ben Widawsky <benjamin.widawsky@intel.com>
To: Intel GFX <intel-gfx@lists.freedesktop.org>
Cc: Ben Widawsky <ben@bwidawsk.net>,
	Kenneth Graunke <kenneth.w.graunke@intel.com>,
	DRI Development <dri-devel@lists.freedesktop.org>,
	Ben Widawsky <benjamin.widawsky@intel.com>
Subject: [PATCH 4/5] intel: Intel full PPGTT param
Date: Thu,  2 Jan 2014 19:50:33 -1000	[thread overview]
Message-ID: <1388728235-20410-7-git-send-email-benjamin.widawsky@intel.com> (raw)
In-Reply-To: <1388728235-20410-1-git-send-email-benjamin.widawsky@intel.com>

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@intel.com>
Signed-off-by: Ben Widawsky <ben@bwidawsk.net>
---
 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

  parent reply	other threads:[~2014-01-03  5:50 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <to=1388555170-19936-1-git-send-email-benjamin.widawsky@intel.com>
2014-01-03  5:50 ` [PATCH] [v2] drm/i915/ppgtt: Never return a NULL context Ben Widawsky
2014-01-03  5:50   ` [PATCH 2/3] drm/i915: set ctx->initialized only after RCS Ben Widawsky
2014-01-03  5:50   ` [PATCH 3/3] drm/i915: Make file default context persistent Ben Widawsky
2014-01-03  5:50   ` [PATCH 1/5] intel: squash unused variable 'bo_gem' Ben Widawsky
2014-01-03  5:50   ` [PATCH 2/5] intel: Handle malloc fails in context create Ben Widawsky
2014-01-03  5:50   ` [PATCH 3/5] intel: Merge latest i915_drm.h Ben Widawsky
2014-01-03  5:50   ` Ben Widawsky [this message]
2014-01-07  7:53     ` [PATCH 4/5] intel: Intel full PPGTT param Daniel Vetter
2014-01-09 23:20       ` Ben Widawsky
2014-01-03  5:50   ` [PATCH 5/5] configure.ac: bump version to 2.4.51 for release Ben Widawsky
2014-01-03  5:50   ` [PATCH] i965: Use default contexts when possible Ben Widawsky
2014-02-23 20:32     ` [Intel-gfx] " Ben Widawsky
2014-01-03 12:07   ` [PATCH] [v2] drm/i915/ppgtt: Never return a NULL context Mika Kuoppala
2014-01-07  7:51     ` Daniel Vetter
     [not found]       ` <CALNAZXq8EZ4Wmq2ONz08gNFcEv4Bi-JzBasEvnAKWEfEWyf_xw@mail.gmail.com>
     [not found]         ` <CAKMK7uE9aai27U7jwGe0jK5AzjxKx40z8VyS1D4mr__a5x-Qeg@mail.gmail.com>
2014-01-10 23:20           ` Daniel Vetter

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=1388728235-20410-7-git-send-email-benjamin.widawsky@intel.com \
    --to=benjamin.widawsky@intel.com \
    --cc=ben@bwidawsk.net \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=kenneth.w.graunke@intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox