<div dir="ltr">On 28 August 2013 16:49, Kenneth Graunke <span dir="ltr"><<a href="mailto:kenneth@whitecape.org" target="_blank">kenneth@whitecape.org</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">These functions have almost identical code; the only difference is that<br>
a few of the bits moved around. Adding a few trivial conditionals<br>
allows the same function to work on all generations, and the resulting<br>
code is still quite readable.<br>
<br>
Signed-off-by: Kenneth Graunke <<a href="mailto:kenneth@whitecape.org">kenneth@whitecape.org</a>><br></blockquote><div><br></div><div>Thanks for doing this! One minor comment below.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
---<br>
src/mesa/drivers/dri/i965/brw_draw.c | 80 ++++++++----------------------------<br>
1 file changed, 17 insertions(+), 63 deletions(-)<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/brw_draw.c b/src/mesa/drivers/dri/i965/brw_draw.c<br>
index c7164ac..df9b750 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_draw.c<br>
+++ b/src/mesa/drivers/dri/i965/brw_draw.c<br>
@@ -171,11 +171,15 @@ static void brw_emit_prim(struct brw_context *brw,<br>
start_vertex_location = prim->start;<br>
base_vertex_location = prim->basevertex;<br>
if (prim->indexed) {<br>
- vertex_access_type = GEN4_3DPRIM_VERTEXBUFFER_ACCESS_RANDOM;<br>
+ vertex_access_type = brw->gen >= 7 ?<br>
+ GEN7_3DPRIM_VERTEXBUFFER_ACCESS_RANDOM :<br>
+ GEN4_3DPRIM_VERTEXBUFFER_ACCESS_RANDOM;<br>
start_vertex_location += brw->ib.start_vertex_offset;<br>
base_vertex_location += brw->vb.start_vertex_bias;<br>
} else {<br>
- vertex_access_type = GEN4_3DPRIM_VERTEXBUFFER_ACCESS_SEQUENTIAL;<br>
+ vertex_access_type = brw->gen >= 7 ?<br>
+ GEN7_3DPRIM_VERTEXBUFFER_ACCESS_SEQUENTIAL :<br>
+ GEN4_3DPRIM_VERTEXBUFFER_ACCESS_SEQUENTIAL;<br>
start_vertex_location += brw->vb.start_vertex_bias;<br>
}<br>
<br>
@@ -198,65 +202,16 @@ static void brw_emit_prim(struct brw_context *brw,<br>
intel_batchbuffer_emit_mi_flush(brw);<br>
}<br>
<br>
- BEGIN_BATCH(6);<br>
- OUT_BATCH(CMD_3D_PRIM << 16 | (6 - 2) |<br>
- hw_prim << GEN4_3DPRIM_TOPOLOGY_TYPE_SHIFT |<br>
- vertex_access_type);<br>
- OUT_BATCH(verts_per_instance);<br>
- OUT_BATCH(start_vertex_location);<br>
- OUT_BATCH(prim->num_instances);<br>
- OUT_BATCH(prim->base_instance);<br>
- OUT_BATCH(base_vertex_location);<br>
- ADVANCE_BATCH();<br>
-<br>
- brw->batch.need_workaround_flush = true;<br>
-<br>
- if (brw->always_flush_cache) {<br>
- intel_batchbuffer_emit_mi_flush(brw);<br>
- }<br>
-}<br>
-<br>
-static void gen7_emit_prim(struct brw_context *brw,<br>
- const struct _mesa_prim *prim,<br>
- uint32_t hw_prim)<br>
-{<br>
- int verts_per_instance;<br>
- int vertex_access_type;<br>
- int start_vertex_location;<br>
- int base_vertex_location;<br>
-<br>
- DBG("PRIM: %s %d %d\n", _mesa_lookup_enum_by_nr(prim->mode),<br>
- prim->start, prim->count);<br>
-<br>
- start_vertex_location = prim->start;<br>
- base_vertex_location = prim->basevertex;<br>
- if (prim->indexed) {<br>
- vertex_access_type = GEN7_3DPRIM_VERTEXBUFFER_ACCESS_RANDOM;<br>
- start_vertex_location += brw->ib.start_vertex_offset;<br>
- base_vertex_location += brw->vb.start_vertex_bias;<br>
+ if (brw->gen >= 7) {<br>
+ BEGIN_BATCH(7);<br>
+ OUT_BATCH(CMD_3D_PRIM << 16 | (7 - 2));<br>
+ OUT_BATCH(hw_prim | vertex_access_type);<br>
} else {<br>
- vertex_access_type = GEN7_3DPRIM_VERTEXBUFFER_ACCESS_SEQUENTIAL;<br>
- start_vertex_location += brw->vb.start_vertex_bias;<br>
+ BEGIN_BATCH(6);<br>
+ OUT_BATCH(CMD_3D_PRIM << 16 | (6 - 2) |<br>
+ hw_prim << GEN4_3DPRIM_TOPOLOGY_TYPE_SHIFT |<br>
+ vertex_access_type);<br>
}<br>
-<br>
- verts_per_instance = prim->count;<br>
-<br>
- /* If nothing to emit, just return. */<br>
- if (verts_per_instance == 0)<br>
- return;<br>
-<br>
- /* If we're set to always flush, do it before and after the primitive emit.<br>
- * We want to catch both missed flushes that hurt instruction/state cache<br>
- * and missed flushes of the render cache as it heads to other parts of<br>
- * the besides the draw code.<br>
- */<br>
- if (brw->always_flush_cache) {<br>
- intel_batchbuffer_emit_mi_flush(brw);<br>
- }<br>
-<br>
- BEGIN_BATCH(7);<br>
- OUT_BATCH(CMD_3D_PRIM << 16 | (7 - 2));<br>
- OUT_BATCH(hw_prim | vertex_access_type);<br>
OUT_BATCH(verts_per_instance);<br>
OUT_BATCH(start_vertex_location);<br>
OUT_BATCH(prim->num_instances);<br>
@@ -264,6 +219,8 @@ static void gen7_emit_prim(struct brw_context *brw,<br>
OUT_BATCH(base_vertex_location);<br>
ADVANCE_BATCH();<br>
<br>
+ brw->batch.need_workaround_flush = true;<br>
+<br></blockquote><div><br></div><div>It took a while for to me to figure out why this wasn't inside a conditional (prior to this patch it only existed in brw_emit_prim).<br><br></div><div>It might be nice to add a comment either here or in the commit message explaining that it is safe to set brw->batch.need_workaround_flush unconditionally, since the boolean is only used on Gen6.<br>
<br></div><div>In any case, this patch 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">
if (brw->always_flush_cache) {<br>
intel_batchbuffer_emit_mi_flush(brw);<br>
}<br>
@@ -453,10 +410,7 @@ retry:<br>
brw_upload_state(brw);<br>
}<br>
<br>
- if (brw->gen >= 7)<br>
- gen7_emit_prim(brw, &prim[i], brw->primitive);<br>
- else<br>
- brw_emit_prim(brw, &prim[i], brw->primitive);<br>
+ brw_emit_prim(brw, &prim[i], brw->primitive);<br>
<br>
brw->no_batch_wrap = false;<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
1.8.3.4<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>