On 2 September 2011 11: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><div></div><div class="h5">On Fri,  2 Sep 2011 09:06:40 -0700, Paul Berry &lt;<a href="mailto:stereotype441@gmail.com">stereotype441@gmail.com</a>&gt; wrote:<br>
&gt; Previously, this conversion was duplicated in several places in the<br>
&gt; i965 driver.  This patch moves it to a common location in mtypes.h,<br>
&gt; near the declaration of gl_vert_result and gl_frag_attrib.<br>
&gt;<br>
&gt; I&#39;ve also added comments to remind us that we may need to revisit the<br>
&gt; conversion code when adding elements to gl_vert_result and<br>
&gt; gl_frag_attrib.<br>
&gt; ---<br>
&gt;  src/gallium/drivers/i965/brw_wm_glsl.c      |    9 +-----<br>
&gt;  src/mesa/drivers/dri/i965/brw_fs.cpp        |   16 +--------<br>
&gt;  src/mesa/drivers/dri/i965/brw_vs_constval.c |    8 +---<br>
&gt;  src/mesa/drivers/dri/i965/brw_wm_pass2.c    |    9 +-----<br>
&gt;  src/mesa/drivers/dri/i965/gen6_sf_state.c   |   15 ++------<br>
&gt;  src/mesa/main/mtypes.h                      |   45 +++++++++++++++++++++++++-<br>
&gt;  6 files changed, 53 insertions(+), 49 deletions(-)<br>
&gt;<br>
&gt; diff --git a/src/gallium/drivers/i965/brw_wm_glsl.c b/src/gallium/drivers/i965/brw_wm_glsl.c<br>
&gt; index fb8e40d..9efb003 100644<br>
&gt; --- a/src/gallium/drivers/i965/brw_wm_glsl.c<br>
&gt; +++ b/src/gallium/drivers/i965/brw_wm_glsl.c<br>
&gt; @@ -388,14 +388,7 @@ static void prealloc_reg(struct brw_wm_compile *c)<br>
&gt;<br>
&gt;      /* fragment shader inputs */<br>
&gt;      for (i = 0; i &lt; VERT_RESULT_MAX; i++) {<br>
&gt; -       int fp_input;<br>
&gt; -<br>
&gt; -       if (i &gt;= VERT_RESULT_VAR0)<br>
&gt; -       fp_input = i - VERT_RESULT_VAR0 + FRAG_ATTRIB_VAR0;<br>
&gt; -       else if (i &lt;= VERT_RESULT_TEX7)<br>
&gt; -       fp_input = i;<br>
&gt; -       else<br>
&gt; -       fp_input = -1;<br>
&gt; +       int fp_input = vert_result_to_frag_attrib(i);<br>
&gt;<br>
&gt;         if (fp_input &gt;= 0 &amp;&amp; inputs &amp; (1 &lt;&lt; fp_input)) {<br>
&gt;         urb_read_length = reg_index;<br>
<br>
</div></div>Probably don&#39;t want to be touching this code.<br>
<div><div></div><div class="h5"><br>
&gt; diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h<br>
&gt; index 44ebf0a..776872c 100644<br>
&gt; --- a/src/mesa/main/mtypes.h<br>
&gt; +++ b/src/mesa/main/mtypes.h<br>
&gt; @@ -215,7 +215,9 @@ typedef enum<br>
&gt;<br>
&gt;<br>
&gt;  /**<br>
&gt; - * Indexes for vertex program result attributes<br>
&gt; + * Indexes for vertex program result attributes.  Note that<br>
&gt; + * vert_result_to_frag_attrib() and frag_attrib_to_vert_result() make<br>
&gt; + * assumptions about the layout of this enum.<br>
&gt;   */<br>
&gt;  typedef enum<br>
&gt;  {<br>
&gt; @@ -313,7 +315,9 @@ typedef enum<br>
&gt;<br>
&gt;<br>
&gt;  /**<br>
&gt; - * Indexes for fragment program input attributes.<br>
&gt; + * Indexes for fragment program input attributes.  Note that<br>
&gt; + * vert_result_to_frag_attrib() and frag_attrib_to_vert_result() make<br>
&gt; + * assumptions about the layout of this enum.<br>
&gt;   */<br>
&gt;  typedef enum<br>
&gt;  {<br>
&gt; @@ -336,6 +340,43 @@ typedef enum<br>
&gt;  } gl_frag_attrib;<br>
&gt;<br>
&gt;  /**<br>
&gt; + * Convert from a gl_vert_result value to the corresponding gl_frag_attrib.<br>
&gt; + *<br>
&gt; + * VERT_RESULT_HPOS is converted to FRAG_ATTRIB_WPOS.<br>
&gt; + *<br>
&gt; + * gl_vert_result values which have no corresponding gl_frag_attrib<br>
&gt; + * (VERT_RESULT_PSIZ, VERT_RESULT_BFC0, VERT_RESULT_BFC1, and<br>
&gt; + * VERT_RESULT_EDGE) are converted to a value of -1.<br>
&gt; + */<br>
&gt; +static inline int vert_result_to_frag_attrib(int vert_result)<br>
&gt; +{<br>
&gt; +   if (vert_result &gt;= VERT_RESULT_VAR0)<br>
&gt; +      return vert_result - VERT_RESULT_VAR0 + FRAG_ATTRIB_VAR0;<br>
&gt; +   else if (vert_result &lt;= VERT_RESULT_TEX7)<br>
&gt; +      return vert_result;<br>
&gt; +   else<br>
&gt; +      return -1;<br>
&gt; +}<br>
&gt; +<br>
&gt; +/**<br>
&gt; + * Convert from a gl_frag_attrib value to the corresponding gl_vert_result.<br>
&gt; + *<br>
&gt; + * FRAG_ATTRIB_WPOS is converted to VERT_RESULT_HPOS.<br>
&gt; + *<br>
&gt; + * gl_frag_attrib values which have no corresponding gl_vert_result<br>
&gt; + * (FRAG_ATTRIB_FACE and FRAG_ATTRIB_PNTC) are converted to a value of -1.<br>
&gt; + */<br>
&gt; +static inline int frag_attrib_to_vert_result(int frag_attrib)<br>
&gt; +{<br>
&gt; +   if (frag_attrib &lt;= FRAG_ATTRIB_TEX7)<br>
&gt; +      return frag_attrib;<br>
&gt; +   else if (frag_attrib &gt;= FRAG_ATTRIB_VAR0)<br>
&gt; +      return frag_attrib - FRAG_ATTRIB_VAR0 + VERT_RESULT_VAR0;<br>
&gt; +   else<br>
&gt; +      return -1;<br>
&gt; +}<br>
&gt; +<br>
&gt; +/**<br>
&gt;   * Bitflags for fragment program input attributes.<br>
&gt;   */<br>
&gt;  /*@{*/<br>
<br>
</div></div>This looks to be the first inline functions in mtypes.h.  I suspect the<br>
code should go somewhere else, but I don&#39;t know where.<br>
</blockquote></div><br>My reasoning for putting these functions in mtypes.h was that I wanted to put them as near as possible to the enums they were related to, especially since they will likely need updating when we modify those enums.  I&#39;m open to other suggestions about where to put them if anyone cares strongly.<br>