On 4 June 2012 14:43, Ben Widawsky <span dir="ltr"><<a href="mailto:ben@bwidawsk.net" target="_blank">ben@bwidawsk.net</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Based off of a patch from Ken Graunke. I just modified it for a more<br>
modern mesa (also don't allow contexts on blit ring).<br>
<br>
Signed-off-by: Ben Widawsky <<a href="mailto:ben@bwidawsk.net">ben@bwidawsk.net</a>><br>
---<br>
src/mesa/drivers/dri/i965/brw_context.c | 1 +<br>
src/mesa/drivers/dri/i965/brw_vtbl.c | 5 ++++-<br>
src/mesa/drivers/dri/intel/intel_batchbuffer.c | 9 +++++++--<br>
src/mesa/drivers/dri/intel/intel_context.c | 2 ++<br>
src/mesa/drivers/dri/intel/intel_context.h | 2 +-<br>
5 files changed, 15 insertions(+), 4 deletions(-)<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/brw_context.c b/src/mesa/drivers/dri/i965/brw_context.c<br>
index f7073cd..d4159c7 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_context.c<br>
+++ b/src/mesa/drivers/dri/i965/brw_context.c<br>
@@ -298,6 +298,7 @@ brwCreateContext(int api,<br>
<br>
brw->prim_restart.in_progress = false;<br>
brw->prim_restart.enable_cut_index = false;<br>
+ intel->hw_ctx = drm_intel_gem_context_create(intel->bufmgr);<br>
<br>
brw_init_state( brw );<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/brw_vtbl.c b/src/mesa/drivers/dri/i965/brw_vtbl.c<br>
index 5699749..d9fd2cb 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_vtbl.c<br>
+++ b/src/mesa/drivers/dri/i965/brw_vtbl.c<br>
@@ -170,7 +170,10 @@ static void brw_new_batch( struct intel_context *intel )<br>
* This is probably not as severe as on 915, since almost all of our state<br>
* is just in referenced buffers.<br>
*/<br>
- brw->state.dirty.brw |= BRW_NEW_CONTEXT | BRW_NEW_BATCH;<br>
+ if (intel->hw_ctx == NULL)<br>
+ brw->state.dirty.brw |= BRW_NEW_CONTEXT;<br>
+<br>
+ brw->state.dirty.brw |= BRW_NEW_BATCH;<br></blockquote><div><br>The comment above this change ("Mark all context state as needing to be re-emitted.") is no longer accurate. Perhaps change it to something like this?<br>
<br>"If the kernel supports hardware contexts, then most hardware state is preserved between batches; we only need to re-emit state that is required to be in every batch. Otherwise we need to re-emit all the state that would otherwise be stored in the context (which for all intents and purposes means everything)."<br>
<br>Also, I think it would be ok to delete the comment "This is probably not as severe as on 915 ... referenced buffers"--that comment is mostly just a rationalization for not having implemented hardware context support earlier, and not a very convincing one at that :)<br>
</div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
/* Assume that the last command before the start of our batch was a<br>
* primitive, for safety.<br>
diff --git a/src/mesa/drivers/dri/intel/intel_batchbuffer.c b/src/mesa/drivers/dri/intel/intel_batchbuffer.c<br>
index 76a69f7..7ba141d 100644<br>
--- a/src/mesa/drivers/dri/intel/intel_batchbuffer.c<br>
+++ b/src/mesa/drivers/dri/intel/intel_batchbuffer.c<br>
@@ -188,8 +188,13 @@ do_flush_locked(struct intel_context *intel)<br>
if (ret == 0) {<br>
if (unlikely(INTEL_DEBUG & DEBUG_AUB) && intel->vtbl.annotate_aub)<br>
intel->vtbl.annotate_aub(intel);<br>
- ret = drm_intel_bo_mrb_exec(batch->bo, 4*batch->used, NULL, 0, 0,<br>
- flags);<br>
+ if (intel->hw_ctx == NULL || batch->is_blit) {<br>
+ ret = drm_intel_bo_mrb_exec(batch->bo, 4*batch->used, NULL, 0, 0,<br>
+ flags);<br>
+ } else {<br>
+ ret = drm_intel_gem_bo_context_exec(batch->bo, intel->hw_ctx,<br>
+ 4 * batch->used, flags);<br>
+ }<br>
}<br>
}<br>
<br>
diff --git a/src/mesa/drivers/dri/intel/intel_context.c b/src/mesa/drivers/dri/intel/intel_context.c<br>
index 9deb4ca..46c2492 100644<br>
--- a/src/mesa/drivers/dri/intel/intel_context.c<br>
+++ b/src/mesa/drivers/dri/intel/intel_context.c<br>
@@ -593,6 +593,8 @@ intelInitContext(struct intel_context *intel,<br>
if (intelScreen->bufmgr == NULL)<br>
return false;<br>
<br>
+ intel->hw_ctx = NULL;<br>
+<br>
/* Can't rely on invalidate events, fall back to glViewport hack */<br>
if (!driContextPriv->driScreenPriv->dri2.useInvalidate) {<br>
intel->saved_viewport = functions->Viewport;<br>
diff --git a/src/mesa/drivers/dri/intel/intel_context.h b/src/mesa/drivers/dri/intel/intel_context.h<br>
index cc3ee0d..c026fea 100644<br>
--- a/src/mesa/drivers/dri/intel/intel_context.h<br>
+++ b/src/mesa/drivers/dri/intel/intel_context.h<br>
@@ -226,7 +226,7 @@ struct intel_context<br>
int urb_size;<br>
<br>
struct intel_batchbuffer batch;<br>
-<br>
+ drm_intel_context *hw_ctx;<br>
drm_intel_bo *first_post_swapbuffers_batch;<br>
bool need_throttle;<br>
bool no_batch_wrap;<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.7.10.2<br>
<br>
_______________________________________________<br>
Intel-gfx mailing list<br>
<a href="mailto:Intel-gfx@lists.freedesktop.org">Intel-gfx@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/intel-gfx" target="_blank">http://lists.freedesktop.org/mailman/listinfo/intel-gfx</a><br>
</font></span></blockquote></div><br>I'm kind of surprised to see a call to drm_intel_gem_context_create(), but no call anywhere to a clean-up function that destroys the context. Was that an oversight, or is there a reason why it's unnecessary? If it's the latter, a comment in brw_destroy_context() would be helpful.<br>