On 3 September 2011 11:38, Kenneth Graunke <span dir="ltr"><<a href="mailto:kenneth@whitecape.org">kenneth@whitecape.org</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;">
<div><div></div><div class="h5">On 09/02/2011 09:06 AM, Paul Berry wrote:<br>
> Previously, the old VS backend computed the URB entry size by adding<br>
> the number of vertex shader outputs to the size of the URB header.<br>
> This often produced a larger result than necessary, because some<br>
> vertex shader outputs are stored in the header, so they were being<br>
> double counted. This patch changes the old VS backend to compute the<br>
> URB entry size directly from the number of slots in the VUE map.<br>
> ---<br>
> src/mesa/drivers/dri/i965/brw_vs.h | 1 -<br>
> src/mesa/drivers/dri/i965/brw_vs_emit.c | 31 +++++++------------------------<br>
> 2 files changed, 7 insertions(+), 25 deletions(-)<br>
><br>
> diff --git a/src/mesa/drivers/dri/i965/brw_vs.h b/src/mesa/drivers/dri/i965/brw_vs.h<br>
> index a02c06d..c31869c 100644<br>
> --- a/src/mesa/drivers/dri/i965/brw_vs.h<br>
> +++ b/src/mesa/drivers/dri/i965/brw_vs.h<br>
> @@ -65,7 +65,6 @@ struct brw_vs_compile {<br>
><br>
> struct brw_vue_map vue_map;<br>
> GLuint first_output;<br>
> - GLuint nr_outputs;<br>
> GLuint last_scratch;<br>
><br>
> GLuint first_tmp;<br>
> diff --git a/src/mesa/drivers/dri/i965/brw_vs_emit.c b/src/mesa/drivers/dri/i965/brw_vs_emit.c<br>
> index e7667c8..7c430ce 100644<br>
> --- a/src/mesa/drivers/dri/i965/brw_vs_emit.c<br>
> +++ b/src/mesa/drivers/dri/i965/brw_vs_emit.c<br>
> @@ -402,36 +402,19 @@ static void brw_vs_alloc_regs( struct brw_vs_compile *c )<br>
> /* The VS VUEs are shared by VF (outputting our inputs) and VS, so size<br>
> * them to fit the biggest thing they need to.<br>
> */<br>
> - attributes_in_vue = MAX2(c->nr_outputs, c->nr_inputs);<br>
> + attributes_in_vue = MAX2(c->vue_map.num_slots, c->nr_inputs);<br>
><br>
> - /* See emit_vertex_write() for where the VUE's overhead on top of the<br>
> - * attributes comes from.<br>
> - */<br>
> - if (intel->gen >= 7) {<br>
> - int header_regs = 2;<br>
> - if (c->key.nr_userclip)<br>
> - header_regs += 2;<br>
> -<br>
> - /* Each attribute is 16 bytes (1 vec4), so dividing by 4 gives us the<br>
> - * number of 64-byte (512-bit) units.<br>
> - */<br>
> - c->prog_data.urb_entry_size = (attributes_in_vue + header_regs + 3) / 4;<br>
> - } else if (intel->gen == 6) {<br>
> - int header_regs = 2;<br>
> - if (c->key.nr_userclip)<br>
> - header_regs += 2;<br>
> -<br>
> - /* Each attribute is 16 bytes (1 vec4), so dividing by 8 gives us the<br>
> + if (intel->gen == 6) {<br>
> + /* Each attribute is 32 bytes (2 vec4s), so dividing by 8 gives us the<br>
> * number of 128-byte (1024-bit) units.<br>
> */<br>
> - c->prog_data.urb_entry_size = (attributes_in_vue + header_regs + 7) / 8;<br>
> - } else if (intel->gen == 5)<br>
> + c->prog_data.urb_entry_size = (attributes_in_vue + 7) / 8;<br>
> + } else {<br>
> /* Each attribute is 16 bytes (1 vec4), so dividing by 4 gives us the<br>
> * number of 64-byte (512-bit) units.<br>
> */<br>
> - c->prog_data.urb_entry_size = (attributes_in_vue + 6 + 3) / 4;<br>
> - else<br>
> - c->prog_data.urb_entry_size = (attributes_in_vue + 2 + 3) / 4;<br>
> + c->prog_data.urb_entry_size = (attributes_in_vue + 3) / 4;<br>
> + }<br>
><br>
> c->prog_data.total_grf = reg;<br>
<br>
</div></div>Totally non-obvious, but seems correct and is _much_ cleaner.<br>
<br>
While we're at it, it might be nicer to do:<br>
<br>
if (intel->gen == 6)<br>
c->prog_data.urb_entry_size = ALIGN(attributes_in_vue, 8) / 8;<br>
else<br>
c->prog_data.urb_entry_size = ALIGN(attributes_in_vue, 4) / 4;<br>
<br>
Otherwise, I get confused, thinking there are +7 or +3 registers<br>
dedicated to something or other. Most likely because in the original<br>
code, (attributes_in_vue + 6 + 3) / 4, the +6 _is_ adding some header<br>
registers, while the +3 is purely a "round up!" factor.<br>
<br>
We can always do that in a follow-up patch if you prefer (or just not,<br>
because this is all going away soon enough.)<br>
</blockquote></div><br>Yeah, I like your rewrite, Ken--it's clearer, and it's a simple enough change. I'll go ahead and update the patch.<br>