On 24 October 2011 14:17, Eric Anholt <span dir="ltr">&lt;<a href="mailto:eric@anholt.net">eric@anholt.net</a>&gt;</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;">
This rearranges the code a bit, and makes the upload of the binding<br>
table take only as many surfaces as there are in use.<br>
---<br>
 src/mesa/drivers/dri/i965/brw_vs_surface_state.c |   62 +++++++++-------------<br>
 1 files changed, 25 insertions(+), 37 deletions(-)<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/brw_vs_surface_state.c b/src/mesa/drivers/dri/i965/brw_vs_surface_state.c<br>
index bfc4f5d..0237b58 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_vs_surface_state.c<br>
+++ b/src/mesa/drivers/dri/i965/brw_vs_surface_state.c<br>
@@ -138,22 +138,6 @@ brw_update_vs_constant_surface( struct gl_context *ctx,<br>
    }<br>
 }<br>
<br>
-<br>
-static void<br>
-prepare_vs_surfaces(struct brw_context *brw)<br>
-{<br>
-   int nr_surfaces = 0;<br>
-<br>
-   if (brw-&gt;vs.const_bo) {<br>
-      nr_surfaces = 1;<br>
-   }<br>
-<br>
-   if (brw-&gt;vs.nr_surfaces != nr_surfaces) {<br>
-      brw-&gt;state.dirty.brw |= BRW_NEW_NR_VS_SURFACES;<br>
-      brw-&gt;vs.nr_surfaces = nr_surfaces;<br>
-   }<br>
-}<br>
-<br>
 /**<br>
  * Vertex shader surfaces (constant buffer).<br>
  *<br>
@@ -161,36 +145,41 @@ prepare_vs_surfaces(struct brw_context *brw)<br>
  * to be updated, and produces BRW_NEW_NR_VS_SURFACES for the VS unit and<br>
  * CACHE_NEW_SURF_BIND for the binding table upload.<br>
  */<br>
-static void upload_vs_surfaces(struct brw_context *brw)<br>
+static void<br>
+brw_upload_vs_surfaces(struct brw_context *brw)<br>
 {<br>
    struct gl_context *ctx = &amp;brw-&gt;intel.ctx;<br>
    uint32_t *bind;<br>
    int i;<br>
+   int nr_surfaces = 0;<br>
+<br>
+   /* BRW_NEW_VS_CONSTBUF */<br>
+   if (brw-&gt;vs.const_bo) {<br>
+      nr_surfaces = 1;<br>
+      brw_update_vs_constant_surface(ctx, SURF_INDEX_VERT_CONST_BUFFER);<br>
+   }<br>
+<br>
+   if (nr_surfaces != 0) {<br></blockquote><div><br>This reads a little strange to me.  The only way nr_surfaces can be nonzero is if the previous if test succeeded, so why not just merge the two if statements?<br> </div>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
+      bind = brw_state_batch(brw, AUB_TRACE_SURFACE_STATE,<br>
+                            sizeof(uint32_t) * nr_surfaces,<br>
+                            32, &amp;brw-&gt;vs.bind_bo_offset);<br>
<br>
-   /* BRW_NEW_NR_VS_SURFACES */<br>
-   if (brw-&gt;vs.nr_surfaces == 0) {<br>
+      for (i = 0; i &lt; nr_surfaces; i++) {<br>
+        /* BRW_NEW_VS_CONSTBUF */<br>
+        bind[i] = brw-&gt;vs.surf_offset[i];<br>
+      }<br></blockquote><div><br>This for loop also seems weird, since at this point in the code nr_surfaces is known to be equal to 1.  Why not just do &quot;bind[0] = brw-&gt;vs.surf_offset[0];&quot;?<br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

+      brw-&gt;state.dirty.brw |= BRW_NEW_VS_BINDING_TABLE;<br>
+   } else {<br>
       if (brw-&gt;vs.bind_bo_offset) {<br>
         brw-&gt;state.dirty.brw |= BRW_NEW_VS_BINDING_TABLE;<br>
+        brw-&gt;vs.bind_bo_offset = 0;<br>
       }<br>
-      brw-&gt;vs.bind_bo_offset = 0;<br>
-      return;<br>
    }<br>
<br>
-   brw_update_vs_constant_surface(ctx, SURF_INDEX_VERT_CONST_BUFFER);<br>
-<br>
-   /* Might want to calculate nr_surfaces first, to avoid taking up so much<br>
-    * space for the binding table. (once we have vs samplers)<br>
-    */<br>
-   bind = brw_state_batch(brw, AUB_TRACE_SURFACE_STATE,<br>
-                         sizeof(uint32_t) * BRW_VS_MAX_SURF,<br>
-                         32, &amp;brw-&gt;vs.bind_bo_offset);<br>
-<br>
-   for (i = 0; i &lt; BRW_VS_MAX_SURF; i++) {<br>
-      /* BRW_NEW_VS_CONSTBUF */<br>
-      bind[i] = brw-&gt;vs.surf_offset[i];<br>
+   if (brw-&gt;vs.nr_surfaces != nr_surfaces) {<br>
+      brw-&gt;state.dirty.brw |= BRW_NEW_NR_VS_SURFACES;<br>
+      brw-&gt;vs.nr_surfaces = nr_surfaces;<br>
    }<br>
-<br>
-   brw-&gt;state.dirty.brw |= BRW_NEW_VS_BINDING_TABLE;<br>
 }<br>
<br>
 const struct brw_tracked_state brw_vs_surfaces = {<br>
@@ -201,6 +190,5 @@ const struct brw_tracked_state brw_vs_surfaces = {<br>
              BRW_NEW_BATCH),<br>
       .cache = 0<br>
    },<br>
-   .prepare = prepare_vs_surfaces,<br>
-   .emit = upload_vs_surfaces,<br>
+   .emit = brw_upload_vs_surfaces,<br>
 };<br>
<font color="#888888">--<br>
1.7.7<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></blockquote></div><br>