<div dir="ltr">On 27 August 2013 15:21, Eric Anholt <span dir="ltr"><<a href="mailto:eric@anholt.net" target="_blank">eric@anholt.net</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
This brings over the batch-wrap-prevention and aperture space checking<br>
code from the normal brw_draw.c path, so that we don't need to flush the<br>
batch every time.<br>
<br>
There's a risk here if the intel_emit_post_sync_nonzero_flush() call isn't<br>
high enough up in the state emit sequences -- before, we implicitly had<br>
one at the batch flush before any state was emitted, so Mesa's workaround<br>
emits didn't really matter.<br>
<br>
Improves cairo-gl performance by 13.7733% +/- 1.74876% (n=30/32)<br>
Improves minecraft apitrace performance by 1.03183% +/- 0.482297% (n=90).<br>
Reduces low-resolution GLB 2.7 performance by 1.17553% +/- 0.432263% (n=88)<br>
Reduces Lightsmark performance by 3.70246% +/- 0.322432% (n=126)<br>
No statistically significant performance difference on unigine tropics<br>
(n=10)<br>
No statistically significant performance difference on openarena (n=755)<br>
<br>
The two apps that are hurt happen to include stalls on busy buffer<br>
objects, so I think this is an effect of missing out on an opportune<br>
flush.<br>
---<br>
src/mesa/drivers/dri/i965/brw_blorp.cpp | 50 ++++++++++++++++++++++++++++++++<br>
src/mesa/drivers/dri/i965/brw_blorp.h | 4 ---<br>
src/mesa/drivers/dri/i965/gen6_blorp.cpp | 12 --------<br>
src/mesa/drivers/dri/i965/gen7_blorp.cpp | 1 -<br>
4 files changed, 50 insertions(+), 17 deletions(-)<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/brw_blorp.cpp b/src/mesa/drivers/dri/i965/brw_blorp.cpp<br>
index 1576ff2..c566d1d 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_blorp.cpp<br>
+++ b/src/mesa/drivers/dri/i965/brw_blorp.cpp<br>
@@ -21,6 +21,7 @@<br>
* IN THE SOFTWARE.<br>
*/<br>
<br>
+#include <errno.h><br>
#include "intel_batchbuffer.h"<br>
#include "intel_fbo.h"<br>
<br>
@@ -191,6 +192,26 @@ intel_hiz_exec(struct brw_context *brw, struct intel_mipmap_tree *mt,<br>
void<br>
brw_blorp_exec(struct brw_context *brw, const brw_blorp_params *params)<br>
{<br>
+ struct gl_context *ctx = &brw->ctx;<br>
+ uint32_t estimated_max_batch_usage = 1500;<br>
+ bool check_aperture_failed_once = false;<br>
+<br>
+ /* Flush the sampler and render caches. We definitely need to flush the<br>
+ * sampler cache so that we get updated contents from the render cache for<br>
+ * the glBlitFramebuffer() source. Also, we are sometimes warned in the<br>
+ * docs to flush the cache between reinterpretations of the same surface<br>
+ * data with different formats, which blorp does for stencil and depth<br>
+ * data.<br>
+ */<br>
+ intel_batchbuffer_emit_mi_flush(brw);<br>
+<br>
+retry:<br>
+ intel_batchbuffer_require_space(brw, estimated_max_batch_usage, false);<br>
+ intel_batchbuffer_save_state(brw);<br>
+ drm_intel_bo *saved_bo = brw-><a href="http://batch.bo" target="_blank">batch.bo</a>;<br>
+ uint32_t saved_used = brw->batch.used;<br>
+ uint32_t saved_state_batch_offset = brw->batch.state_batch_offset;<br>
+<br>
switch (brw->gen) {<br>
case 6:<br>
gen6_blorp_exec(brw, params);<br>
@@ -204,6 +225,35 @@ brw_blorp_exec(struct brw_context *brw, const brw_blorp_params *params)<br>
break;<br>
}<br>
<br></blockquote><div><br></div><div>Would it be feasible to add an assertion here to verify that the amount of batch space actually used by this blorp call is less than or equal to estimated_max_batch_usage? That would give me a lot of increased confidence that the magic number 1500 is correct.<br>
<br></div><div>With the added assertion, the series is:<br><br>Reviewed-by: Paul Berry <<a href="mailto:stereotype441@gmail.com">stereotype441@gmail.com</a>><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+ /* Make sure we didn't wrap the batch unintentionally, and make sure we<br>
+ * reserved enough space that a wrap will never happen.<br>
+ */<br>
+ assert(brw-><a href="http://batch.bo" target="_blank">batch.bo</a> == saved_bo);<br>
+ assert((brw->batch.used - saved_used) * 4 +<br>
+ (saved_state_batch_offset - brw->batch.state_batch_offset) <<br>
+ estimated_max_batch_usage);<br>
+ /* Shut up compiler warnings on release build */<br>
+ (void)saved_bo;<br>
+ (void)saved_used;<br>
+ (void)saved_state_batch_offset;<br>
+<br>
+ /* Check if the blorp op we just did would make our batch likely to fail to<br>
+ * map all the BOs into the GPU at batch exec time later. If so, flush the<br>
+ * batch and try again with nothing else in the batch.<br>
+ */<br>
+ if (dri_bufmgr_check_aperture_space(&brw-><a href="http://batch.bo" target="_blank">batch.bo</a>, 1)) {<br>
+ if (!check_aperture_failed_once) {<br>
+ check_aperture_failed_once = true;<br>
+ intel_batchbuffer_reset_to_saved(brw);<br>
+ intel_batchbuffer_flush(brw);<br>
+ goto retry;<br>
+ } else {<br>
+ int ret = intel_batchbuffer_flush(brw);<br>
+ WARN_ONCE(ret == -ENOSPC,<br>
+ "i965: blorp emit exceeded available aperture space\n");<br>
+ }<br>
+ }<br>
+<br>
if (unlikely(brw->always_flush_batch))<br>
intel_batchbuffer_flush(brw);<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/brw_blorp.h b/src/mesa/drivers/dri/i965/brw_blorp.h<br>
index dceb4fc..e03e27f 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_blorp.h<br>
+++ b/src/mesa/drivers/dri/i965/brw_blorp.h<br>
@@ -370,10 +370,6 @@ void<br>
gen6_blorp_init(struct brw_context *brw);<br>
<br>
void<br>
-gen6_blorp_emit_batch_head(struct brw_context *brw,<br>
- const brw_blorp_params *params);<br>
-<br>
-void<br>
gen6_blorp_emit_state_base_address(struct brw_context *brw,<br>
const brw_blorp_params *params);<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/gen6_blorp.cpp b/src/mesa/drivers/dri/i965/gen6_blorp.cpp<br>
index da523e5..87b1d2b 100644<br>
--- a/src/mesa/drivers/dri/i965/gen6_blorp.cpp<br>
+++ b/src/mesa/drivers/dri/i965/gen6_blorp.cpp<br>
@@ -45,17 +45,6 @@<br>
* sizeof(float))<br>
/** \} */<br>
<br>
-void<br>
-gen6_blorp_emit_batch_head(struct brw_context *brw,<br>
- const brw_blorp_params *params)<br>
-{<br>
- /* To ensure that the batch contains only the resolve, flush the batch<br>
- * before beginning and after finishing emitting the resolve packets.<br>
- */<br>
- intel_batchbuffer_flush(brw);<br>
-}<br>
-<br>
-<br>
/**<br>
* CMD_STATE_BASE_ADDRESS<br>
*<br>
@@ -1030,7 +1019,6 @@ gen6_blorp_exec(struct brw_context *brw,<br>
uint32_t wm_bind_bo_offset = 0;<br>
<br>
uint32_t prog_offset = params->get_wm_prog(brw, &prog_data);<br>
- gen6_blorp_emit_batch_head(brw, params);<br>
gen6_emit_3dstate_multisample(brw, params->num_samples);<br>
gen6_emit_3dstate_sample_mask(brw, params->num_samples, 1.0, false, ~0u);<br>
gen6_blorp_emit_state_base_address(brw, params);<br>
diff --git a/src/mesa/drivers/dri/i965/gen7_blorp.cpp b/src/mesa/drivers/dri/i965/gen7_blorp.cpp<br>
index a387836..120f535 100644<br>
--- a/src/mesa/drivers/dri/i965/gen7_blorp.cpp<br>
+++ b/src/mesa/drivers/dri/i965/gen7_blorp.cpp<br>
@@ -824,7 +824,6 @@ gen7_blorp_exec(struct brw_context *brw,<br>
uint32_t sampler_offset = 0;<br>
<br>
uint32_t prog_offset = params->get_wm_prog(brw, &prog_data);<br>
- gen6_blorp_emit_batch_head(brw, params);<br>
gen6_emit_3dstate_multisample(brw, params->num_samples);<br>
gen6_emit_3dstate_sample_mask(brw, params->num_samples, 1.0, false, ~0u);<br>
gen6_blorp_emit_state_base_address(brw, params);<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.8.4.rc3<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>