On 2 September 2011 12:59, 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;">
<div class="im">On Fri,  2 Sep 2011 09:06:44 -0700, Paul Berry &lt;<a href="mailto:stereotype441@gmail.com">stereotype441@gmail.com</a>&gt; wrote:<br>
&gt; Previously, the old VS backend computed the URB entry size by adding<br>
&gt; the number of vertex shader outputs to the size of the URB header.<br>
&gt; This often produced a larger result than necessary, because some<br>
&gt; vertex shader outputs are stored in the header, so they were being<br>
&gt; double counted.  This patch changes the old VS backend to compute the<br>
&gt; URB entry size directly from the number of slots in the VUE map.<br>
<br>
</div>This kind of scares me, if the later stages with similar failure at<br>
computing the size might be trying to read too much data from a<br>
now-smaller VUE.  I&#39;m not sure what happens in that case.  (hopefully<br>
the answer is &quot;read garbage&quot;, but what if our vertex happens to be at<br>
the end of URB space?<br></blockquote><div><br>Yeah, good point.  I don&#39;t know what the GPU would do if the vertex were at the end of URB space and a later stage tried to read beyond the end.  Hopefully, as you say, the answer is &quot;read garbage&quot;.  Fortunately, later patches in the series adjust the later pipeline stages to compute their URB read sizes based on the VUE map.  So by the time the whole patch series is applied, we should be fine.  (In fact, we should be in far lower danger of this kind of problem, because after the whole patch series, all URB sizes are computed in the same way from the VUE map).<br>
<br>So, depending on how the hardware behaves when reading beyond the end of a URB entry, there is a minor danger that this patch will introduce a temporary regression that gets fixed by later patches in the series.  I&#39;m on the fence as to what to do about it.  On one hand, I could move this patch to the end of the series and that would close the window for temporary regressions.  On the other hand, that would mean that the VS-related changes aren&#39;t grouped together anymore.  Advice?<br>
 </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="im"><br>
&gt; ---<br>
&gt;  src/mesa/drivers/dri/i965/brw_vs.h      |    1 -<br>
&gt;  src/mesa/drivers/dri/i965/brw_vs_emit.c |   31 +++++++------------------------<br>
&gt;  2 files changed, 7 insertions(+), 25 deletions(-)<br>
&gt;<br>
&gt; diff --git a/src/mesa/drivers/dri/i965/brw_vs.h b/src/mesa/drivers/dri/i965/brw_vs.h<br>
&gt; index a02c06d..c31869c 100644<br>
&gt; --- a/src/mesa/drivers/dri/i965/brw_vs.h<br>
&gt; +++ b/src/mesa/drivers/dri/i965/brw_vs.h<br>
&gt; @@ -65,7 +65,6 @@ struct brw_vs_compile {<br>
&gt;<br>
&gt;     struct brw_vue_map vue_map;<br>
&gt;     GLuint first_output;<br>
&gt; -   GLuint nr_outputs;<br>
&gt;     GLuint last_scratch;<br>
&gt;<br>
&gt;     GLuint first_tmp;<br>
&gt; diff --git a/src/mesa/drivers/dri/i965/brw_vs_emit.c b/src/mesa/drivers/dri/i965/brw_vs_emit.c<br>
&gt; index e7667c8..7c430ce 100644<br>
&gt; --- a/src/mesa/drivers/dri/i965/brw_vs_emit.c<br>
&gt; +++ b/src/mesa/drivers/dri/i965/brw_vs_emit.c<br>
&gt; @@ -402,36 +402,19 @@ static void brw_vs_alloc_regs( struct brw_vs_compile *c )<br>
&gt;     /* The VS VUEs are shared by VF (outputting our inputs) and VS, so size<br>
&gt;      * them to fit the biggest thing they need to.<br>
&gt;      */<br>
&gt; -   attributes_in_vue = MAX2(c-&gt;nr_outputs, c-&gt;nr_inputs);<br>
&gt; +   attributes_in_vue = MAX2(c-&gt;vue_map.num_slots, c-&gt;nr_inputs);<br>
<br>
</div>There&#39;s a subtle change here, that we&#39;re no longer counting header regs<br>
towards the size of the VF input.  Is that appropriate?  I think it is,<br>
because brw_vs_state.c has vs-&gt;thread3.urb_entry_read_offset = 0.<br>
<br>
This probably deserves mention in the commit message.<br></blockquote><div><br>Good point.  I will make mention of this in the commit message.<br><br>BTW I don&#39;t think the *new* VS backend accounts for the number of inputs at all when computing the URB entry size.  That&#39;s probably a bug (I believe it would manifest itself for cases where there are a lot of vertex attributes but not many varyings).  I kind of glazed over this detail when making the patch series because I don&#39;t understand how VS inputs work yet.  Do you have an opinion on this?<br>
 </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div class="im"><br>
&gt; -   /* See emit_vertex_write() for where the VUE&#39;s overhead on top of the<br>
&gt; -    * attributes comes from.<br>
&gt; -    */<br>
&gt; -   if (intel-&gt;gen &gt;= 7) {<br>
&gt; -      int header_regs = 2;<br>
&gt; -      if (c-&gt;key.nr_userclip)<br>
&gt; -      header_regs += 2;<br>
&gt; -<br>
&gt; -      /* Each attribute is 16 bytes (1 vec4), so dividing by 4 gives us the<br>
&gt; -       * number of 64-byte (512-bit) units.<br>
&gt; -       */<br>
&gt; -      c-&gt;prog_data.urb_entry_size = (attributes_in_vue + header_regs + 3) / 4;<br>
&gt; -   } else if (intel-&gt;gen == 6) {<br>
&gt; -      int header_regs = 2;<br>
&gt; -      if (c-&gt;key.nr_userclip)<br>
&gt; -      header_regs += 2;<br>
&gt; -<br>
&gt; -      /* Each attribute is 16 bytes (1 vec4), so dividing by 8 gives us the<br>
&gt; +   if (intel-&gt;gen == 6) {<br>
&gt; +      /* Each attribute is 32 bytes (2 vec4s), so dividing by 8 gives us the<br>
&gt;         * number of 128-byte (1024-bit) units.<br>
&gt;         */<br>
<br>
</div>This comment change here looks wrong to me.  32 bytes * 8 = 256 bytes.<br>
Same below.  An attribute is 1 vec4, and the urb_entry_size is for one<br>
vertex&#39;s URB entry, even though a register contains 2 vec4s which get<br>
output to two separate URB entries.<br></blockquote><div><br>Oops, you&#39;re right.  This was a total brain failure; the comment was correct as is.  Good catch.<br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

<div><div></div><div class="h5"><br>
&gt; -      c-&gt;prog_data.urb_entry_size = (attributes_in_vue + header_regs + 7) / 8;<br>
&gt; -   } else if (intel-&gt;gen == 5)<br>
&gt; +      c-&gt;prog_data.urb_entry_size = (attributes_in_vue + 7) / 8;<br>
&gt; +   } else {<br>
&gt;        /* Each attribute is 16 bytes (1 vec4), so dividing by 4 gives us the<br>
&gt;         * number of 64-byte (512-bit) units.<br>
&gt;         */<br>
&gt; -      c-&gt;prog_data.urb_entry_size = (attributes_in_vue + 6 + 3) / 4;<br>
&gt; -   else<br>
&gt; -      c-&gt;prog_data.urb_entry_size = (attributes_in_vue + 2 + 3) / 4;<br>
&gt; +      c-&gt;prog_data.urb_entry_size = (attributes_in_vue + 3) / 4;<br>
&gt; +   }<br>
</div></div></blockquote></div><br>