[Mesa-dev] [PATCH 27/70] i965: Move HW context into brw_batch
Chris Wilson
chris at chris-wilson.co.uk
Fri Aug 7 13:13:31 PDT 2015
To reduce churn later, move the HW context variable from brw_context to
brw_batch.
Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
---
src/mesa/drivers/dri/i965/brw_batch.h | 2 ++
src/mesa/drivers/dri/i965/brw_context.c | 22 +++---------------
src/mesa/drivers/dri/i965/brw_context.h | 2 --
src/mesa/drivers/dri/i965/brw_queryobj.c | 4 ++--
src/mesa/drivers/dri/i965/brw_reset.c | 6 ++---
src/mesa/drivers/dri/i965/brw_state_upload.c | 2 +-
src/mesa/drivers/dri/i965/gen7_misc_state.c | 2 +-
src/mesa/drivers/dri/i965/gen8_depth_state.c | 2 +-
src/mesa/drivers/dri/i965/intel_batchbuffer.c | 32 ++++++++++++++++++++++-----
src/mesa/drivers/dri/i965/intel_batchbuffer.h | 2 +-
10 files changed, 40 insertions(+), 36 deletions(-)
diff --git a/src/mesa/drivers/dri/i965/brw_batch.h b/src/mesa/drivers/dri/i965/brw_batch.h
index e3a83ea..849a442 100644
--- a/src/mesa/drivers/dri/i965/brw_batch.h
+++ b/src/mesa/drivers/dri/i965/brw_batch.h
@@ -89,6 +89,8 @@ typedef struct brw_batch {
bool always_flush : 1;
bool disable_throttling : 1;
+ drm_intel_context *hw_ctx;
+
/**
* Set of brw_bo* that have been rendered to within this batchbuffer
* and would need flushing before being used from another cache domain that
diff --git a/src/mesa/drivers/dri/i965/brw_context.c b/src/mesa/drivers/dri/i965/brw_context.c
index 12313ec..ffc3b1f 100644
--- a/src/mesa/drivers/dri/i965/brw_context.c
+++ b/src/mesa/drivers/dri/i965/brw_context.c
@@ -802,23 +802,9 @@ brwCreateContext(gl_api api,
intel_fbo_init(brw);
- intel_batchbuffer_init(brw);
-
- if (brw->gen >= 6) {
- /* Create a new hardware context. Using a hardware context means that
- * our GPU state will be saved/restored on context switch, allowing us
- * to assume that the GPU is in the same state we left it in.
- *
- * 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 = drm_intel_gem_context_create(brw->batch.bufmgr);
-
- if (!brw->hw_ctx) {
- fprintf(stderr, "Gen6+ requires Kernel 3.6 or later.\n");
- intelDestroyContext(driContextPriv);
- return false;
- }
+ if (!intel_batchbuffer_init(brw)) {
+ intelDestroyContext(driContextPriv);
+ return false;
}
brw_init_pipe_control(brw, devinfo);
@@ -936,8 +922,6 @@ intelDestroyContext(__DRIcontext * driContextPriv)
brw_bo_put(brw->wm.base.scratch_bo);
brw_bo_put(brw->hw_bt_pool.bo);
- drm_intel_gem_context_destroy(brw->hw_ctx);
-
if (ctx->swrast_context) {
_swsetup_DestroyContext(&brw->ctx);
_tnl_DestroyContext(&brw->ctx);
diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h
index a4169f4..f1fcbd8 100644
--- a/src/mesa/drivers/dri/i965/brw_context.h
+++ b/src/mesa/drivers/dri/i965/brw_context.h
@@ -1003,8 +1003,6 @@ struct brw_context
brw_batch batch;
bool no_batch_wrap;
- drm_intel_context *hw_ctx;
-
/** BO for post-sync nonzero writes for gen6 workaround. */
brw_bo *workaround_bo;
uint8_t pipe_controls_since_last_cs_stall;
diff --git a/src/mesa/drivers/dri/i965/brw_queryobj.c b/src/mesa/drivers/dri/i965/brw_queryobj.c
index 6f29d04..cb0c210 100644
--- a/src/mesa/drivers/dri/i965/brw_queryobj.c
+++ b/src/mesa/drivers/dri/i965/brw_queryobj.c
@@ -425,7 +425,7 @@ brw_emit_query_begin(struct brw_context *brw)
struct gl_context *ctx = &brw->ctx;
struct brw_query_object *query = brw->query.obj;
- if (brw->hw_ctx)
+ if (brw->batch.hw_ctx)
return;
/* Skip if we're not doing any queries, or we've already recorded the
@@ -452,7 +452,7 @@ brw_emit_query_end(struct brw_context *brw)
{
struct brw_query_object *query = brw->query.obj;
- if (brw->hw_ctx)
+ if (brw->batch.hw_ctx)
return;
if (!brw->query.begin_emitted)
diff --git a/src/mesa/drivers/dri/i965/brw_reset.c b/src/mesa/drivers/dri/i965/brw_reset.c
index e3182b1..f84df22 100644
--- a/src/mesa/drivers/dri/i965/brw_reset.c
+++ b/src/mesa/drivers/dri/i965/brw_reset.c
@@ -40,7 +40,7 @@ brw_get_graphics_reset_status(struct gl_context *ctx)
* DRM_IOCTL_I915_GET_RESET_STATS is not supported), this function should
* not be accessible.
*/
- assert(brw->hw_ctx != NULL);
+ assert(brw->batch.hw_ctx);
/* A reset status other than NO_ERROR was returned last time. I915 returns
* nonzero active/pending only if reset has been encountered and completed.
@@ -49,8 +49,8 @@ brw_get_graphics_reset_status(struct gl_context *ctx)
if (brw->reset_count != 0)
return GL_NO_ERROR;
- err = drm_intel_get_reset_stats(brw->hw_ctx, &reset_count, &active,
- &pending);
+ err = drm_intel_get_reset_stats(brw->batch.hw_ctx,
+ &reset_count, &active, &pending);
if (err)
return GL_NO_ERROR;
diff --git a/src/mesa/drivers/dri/i965/brw_state_upload.c b/src/mesa/drivers/dri/i965/brw_state_upload.c
index c2af48c..1d94172 100644
--- a/src/mesa/drivers/dri/i965/brw_state_upload.c
+++ b/src/mesa/drivers/dri/i965/brw_state_upload.c
@@ -350,7 +350,7 @@ brw_upload_initial_gpu_state(struct brw_context *brw)
* right away rather than doing it via state atoms. This saves a small
* amount of overhead on every draw call.
*/
- if (!brw->hw_ctx)
+ if (!brw->batch.hw_ctx)
return;
if (brw->gen == 6)
diff --git a/src/mesa/drivers/dri/i965/gen7_misc_state.c b/src/mesa/drivers/dri/i965/gen7_misc_state.c
index f792cc6..fb20b22 100644
--- a/src/mesa/drivers/dri/i965/gen7_misc_state.c
+++ b/src/mesa/drivers/dri/i965/gen7_misc_state.c
@@ -52,7 +52,7 @@ gen7_emit_depth_stencil_hiz(struct brw_context *brw,
/* Skip repeated NULL depth/stencil emits (think 2D rendering). */
if (!mt && brw->no_depth_or_stencil) {
- assert(brw->hw_ctx);
+ assert(brw->batch.hw_ctx);
return;
}
diff --git a/src/mesa/drivers/dri/i965/gen8_depth_state.c b/src/mesa/drivers/dri/i965/gen8_depth_state.c
index 3a6a763..82c033d 100644
--- a/src/mesa/drivers/dri/i965/gen8_depth_state.c
+++ b/src/mesa/drivers/dri/i965/gen8_depth_state.c
@@ -53,7 +53,7 @@ emit_depth_packets(struct brw_context *brw,
/* Skip repeated NULL depth/stencil emits (think 2D rendering). */
if (!depth_mt && !stencil_mt && brw->no_depth_or_stencil) {
- assert(brw->hw_ctx);
+ assert(brw->batch.hw_ctx);
return;
}
diff --git a/src/mesa/drivers/dri/i965/intel_batchbuffer.c b/src/mesa/drivers/dri/i965/intel_batchbuffer.c
index e57463d..1f11036 100644
--- a/src/mesa/drivers/dri/i965/intel_batchbuffer.c
+++ b/src/mesa/drivers/dri/i965/intel_batchbuffer.c
@@ -41,7 +41,7 @@
static void
intel_batchbuffer_reset(struct brw_context *brw);
-void
+int
intel_batchbuffer_init(struct brw_context *brw)
{
intel_batchbuffer_reset(brw);
@@ -51,6 +51,24 @@ intel_batchbuffer_init(struct brw_context *brw)
brw->batch.map = brw->batch.cpu_map;
brw->batch.map_next = brw->batch.cpu_map;
}
+
+ if (brw->gen >= 6) {
+ /* Create a new hardware context. Using a hardware context means that
+ * our GPU state will be saved/restored on context switch, allowing us
+ * to assume that the GPU is in the same state we left it in.
+ *
+ * This is required for transform feedback buffer offsets, query objects,
+ * and also allows us to reduce how much state we have to emit.
+ */
+ brw->batch.hw_ctx = drm_intel_gem_context_create(brw->batch.bufmgr);
+
+ if (!brw->batch.hw_ctx) {
+ fprintf(stderr, "Gen6+ requires Kernel 3.6 or later.\n");
+ return false;
+ }
+ }
+
+ return true;
}
static void
@@ -106,6 +124,8 @@ intel_batchbuffer_free(struct brw_context *brw)
brw_bo_put(brw->batch.throttle_batch[1]);
brw_bo_put(brw->batch.throttle_batch[0]);
+
+ drm_intel_gem_context_destroy(brw->batch.hw_ctx);
}
static void
@@ -171,7 +191,7 @@ brw_new_batch(struct brw_context *brw)
* would otherwise be stored in the context (which for all intents and
* purposes means everything).
*/
- if (brw->hw_ctx == NULL)
+ if (!brw->batch.hw_ctx)
brw->ctx.NewDriverState |= BRW_NEW_CONTEXT;
brw->ctx.NewDriverState |= BRW_NEW_BATCH;
@@ -321,13 +341,13 @@ do_flush_locked(struct brw_context *brw)
if (unlikely(INTEL_DEBUG & DEBUG_AUB))
brw_annotate_aub(brw);
- if (brw->hw_ctx == NULL || batch->ring != RENDER_RING) {
+ if (batch->hw_ctx == NULL || batch->ring != RENDER_RING) {
ret = drm_intel_bo_mrb_exec(batch->bo, 4 * USED_BATCH(*batch),
NULL, 0, 0, flags);
- } else {
- ret = drm_intel_gem_bo_context_exec(batch->bo, brw->hw_ctx,
+ } else {
+ ret = drm_intel_gem_bo_context_exec(batch->bo, batch->hw_ctx,
4 * USED_BATCH(*batch), flags);
- }
+ }
}
throttle(brw);
diff --git a/src/mesa/drivers/dri/i965/intel_batchbuffer.h b/src/mesa/drivers/dri/i965/intel_batchbuffer.h
index 5ca3bf3..9e32aea 100644
--- a/src/mesa/drivers/dri/i965/intel_batchbuffer.h
+++ b/src/mesa/drivers/dri/i965/intel_batchbuffer.h
@@ -37,7 +37,7 @@ struct brw_context;
enum brw_gpu_ring;
void intel_batchbuffer_emit_render_ring_prelude(struct brw_context *brw);
-void intel_batchbuffer_init(struct brw_context *brw);
+int intel_batchbuffer_init(struct brw_context *brw);
void intel_batchbuffer_free(struct brw_context *brw);
void intel_batchbuffer_save_state(struct brw_context *brw);
void intel_batchbuffer_reset_to_saved(struct brw_context *brw);
--
2.5.0
More information about the mesa-dev
mailing list