On 4 October 2011 10:32, Chad Versace <span dir="ltr">&lt;<a href="mailto:chad@chad-versace.us">chad@chad-versace.us</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;">
-----BEGIN PGP SIGNED MESSAGE-----<br>
Hash: SHA1<br>
<br>
Overall, the patch looks good, but I&#39;m going to take the bikeshed bait.<br>
<br>
Symbols of form GLxxx and constants of form GL_XXX should be reserved for<br>
those defined in the GL headers. If I encountered the symbol GLclipplane<br>
in Mesa, I would confidently, yet incorrectly, assume the symbol was<br>
defined in some GL extension of which I was unaware.<br>
<br>
Typically, when we wish a symbol name to be closely related to it GL analogue,<br>
we use one of the following naming schemes:<br>
        fuctions: _mesa_CamelCaps, intel_no_caps<br>
        struct: gl_no_caps<br>
        enums: gl_no_caps<br>
        constants: MESA_XXX<br>
<br>
For examples:<br>
        _mesa_BindFramebufferEXT(), intel_bind_framebuffer()<br>
        struct gl_framebuffer<br>
        enum gl_format<br>
        MESA_FORMAT_RGBA8888<br></blockquote><div><br>Ok, I&#39;m fine with this.  Unless someone has a better suggestion, I propose renaming &quot;GLclipplane&quot; to &quot;gl_clip_plane&quot;.  Would that address your concerns, Chad?<br>
 </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br>
- --<br>
Chad Versace<br>
<a href="mailto:chad@chad-versace.us">chad@chad-versace.us</a><br>
<div><div></div><div class="h5"><br>
On 10/03/2011 02:17 PM, Paul Berry wrote:<br>
&gt; This patch implements proper support for gl_ClipVertex by causing the<br>
&gt; new VS backend to populate the clip distance VUE slots using<br>
&gt; VERT_RESULT_CLIP_VERTEX when appropriate, and by using the<br>
&gt; untransformed clip planes in ctx-&gt;Transform.EyeUserPlane rather than<br>
&gt; the transformed clip planes in ctx-&gt;Transform._ClipUserPlane when a<br>
&gt; GLSL-based vertex shader is in use.<br>
&gt;<br>
&gt; When not using a GLSL-based vertex shader, we use<br>
&gt; ctx-&gt;Transform._ClipUserPlane (which is what we used prior to this<br>
&gt; patch).  This ensures that clipping is still performed correctly for<br>
&gt; fixed function and ARB vertex programs.  A new function,<br>
&gt; brw_select_clip_planes() is used to determine whether to use<br>
&gt; _ClipUserPlane or EyeUserPlane, so that the logic for making this<br>
&gt; decision is shared between the new and old vertex shaders.<br>
&gt;<br>
&gt; Fixes the following Piglit tests on i965 Gen6:<br>
&gt; - vs-clip-vertex-const-accept<br>
&gt; - vs-clip-vertex-const-reject<br>
&gt; - vs-clip-vertex-different-from-position<br>
&gt; - vs-clip-vertex-equal-to-position<br>
&gt; - vs-clip-vertex-homogeneity<br>
&gt; - vs-clip-based-on-position<br>
&gt; - vs-clip-based-on-position-homogeneity<br>
&gt; - clip-plane-transformation clipvert_pos<br>
&gt; - clip-plane-transformation pos_clipvert<br>
&gt; - clip-plane-transformation pos<br>
&gt; ---<br>
&gt;  src/mesa/drivers/dri/i965/brw_context.h        |    3 ++<br>
&gt;  src/mesa/drivers/dri/i965/brw_curbe.c          |   10 ++++---<br>
&gt;  src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp |   24 +++++++++++++++-<br>
&gt;  src/mesa/drivers/dri/i965/brw_vs.c             |   34 +++++++++++++++++++++++-<br>
&gt;  src/mesa/drivers/dri/i965/gen6_vs_state.c      |    3 +-<br>
&gt;  src/mesa/main/mtypes.h                         |   11 ++++++-<br>
&gt;  6 files changed, 75 insertions(+), 10 deletions(-)<br>
&gt;<br>
&gt; diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h<br>
&gt; index d32eded..7c5bfd0 100644<br>
&gt; --- a/src/mesa/drivers/dri/i965/brw_context.h<br>
&gt; +++ b/src/mesa/drivers/dri/i965/brw_context.h<br>
&gt; @@ -899,6 +899,7 @@ struct brw_context<br>
&gt;  };<br>
&gt;<br>
&gt;<br>
&gt; +<br>
&gt;  #define BRW_PACKCOLOR8888(r,g,b,a)  ((r&lt;&lt;24) | (g&lt;&lt;16) | (b&lt;&lt;8) | a)<br>
&gt;<br>
&gt;  struct brw_instruction_info {<br>
<br>
<br>
</div></div>The above hunk is spurious.<br></blockquote><div><br>Oops.  I&#39;ll remove 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><div></div><div class="h5"><br>
<br>
&gt; @@ -966,6 +967,8 @@ int brw_disasm (FILE *file, struct brw_instruction *inst, int gen);<br>
&gt;  void brw_compute_vue_map(struct brw_vue_map *vue_map,<br>
&gt;                           const struct intel_context *intel, int nr_userclip,<br>
&gt;                           GLbitfield64 outputs_written);<br>
&gt; +GLclipplane *brw_select_clip_planes(struct gl_context *ctx);<br>
&gt; +<br>
&gt;<br>
&gt;  /*======================================================================<br>
&gt;   * Inline conversion functions.  These are better-typed than the<br>
&gt; diff --git a/src/mesa/drivers/dri/i965/brw_curbe.c b/src/mesa/drivers/dri/i965/brw_curbe.c<br>
&gt; index e1676de..5d2a024 100644<br>
&gt; --- a/src/mesa/drivers/dri/i965/brw_curbe.c<br>
&gt; +++ b/src/mesa/drivers/dri/i965/brw_curbe.c<br>
&gt; @@ -188,6 +188,7 @@ static void prepare_constant_buffer(struct brw_context *brw)<br>
&gt;     const GLuint bufsz = sz * 16 * sizeof(GLfloat);<br>
&gt;     GLfloat *buf;<br>
&gt;     GLuint i;<br>
&gt; +   GLclipplane *clip_planes;<br>
&gt;<br>
&gt;     if (sz == 0) {<br>
&gt;        brw-&gt;curbe.last_bufsz  = 0;<br>
&gt; @@ -232,12 +233,13 @@ static void prepare_constant_buffer(struct brw_context *brw)<br>
&gt;        /* Clip planes: _NEW_TRANSFORM plus _NEW_PROJECTION to get to<br>
&gt;         * clip-space:<br>
&gt;         */<br>
&gt; +      clip_planes = brw_select_clip_planes(ctx);<br>
&gt;        for (j = 0; j &lt; MAX_CLIP_PLANES; j++) {<br>
&gt;        if (ctx-&gt;Transform.ClipPlanesEnabled &amp; (1&lt;&lt;j)) {<br>
&gt; -         buf[offset + i * 4 + 0] = ctx-&gt;Transform._ClipUserPlane[j][0];<br>
&gt; -         buf[offset + i * 4 + 1] = ctx-&gt;Transform._ClipUserPlane[j][1];<br>
&gt; -         buf[offset + i * 4 + 2] = ctx-&gt;Transform._ClipUserPlane[j][2];<br>
&gt; -         buf[offset + i * 4 + 3] = ctx-&gt;Transform._ClipUserPlane[j][3];<br>
&gt; +         buf[offset + i * 4 + 0] = clip_planes[j][0];<br>
&gt; +         buf[offset + i * 4 + 1] = clip_planes[j][1];<br>
&gt; +         buf[offset + i * 4 + 2] = clip_planes[j][2];<br>
&gt; +         buf[offset + i * 4 + 3] = clip_planes[j][3];<br>
&gt;           i++;<br>
&gt;        }<br>
&gt;        }<br>
&gt; diff --git a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp<br>
&gt; index ad8b433..0f16342 100644<br>
&gt; --- a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp<br>
&gt; +++ b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp<br>
&gt; @@ -557,6 +557,8 @@ vec4_visitor::setup_uniform_values(int loc, const glsl_type *type)<br>
&gt;  void<br>
&gt;  vec4_visitor::setup_uniform_clipplane_values()<br>
&gt;  {<br>
&gt; +   GLclipplane *clip_planes = brw_select_clip_planes(ctx);<br>
&gt; +<br>
&gt;     int compacted_clipplane_index = 0;<br>
&gt;     for (int i = 0; i &lt; MAX_CLIP_PLANES; ++i) {<br>
&gt;        if (ctx-&gt;Transform.ClipPlanesEnabled &amp; (1 &lt;&lt; i)) {<br>
&gt; @@ -564,7 +566,7 @@ vec4_visitor::setup_uniform_clipplane_values()<br>
&gt;           this-&gt;userplane[compacted_clipplane_index] = dst_reg(UNIFORM, this-&gt;uniforms);<br>
&gt;           this-&gt;userplane[compacted_clipplane_index].type = BRW_REGISTER_TYPE_F;<br>
&gt;           for (int j = 0; j &lt; 4; ++j) {<br>
&gt; -            c-&gt;prog_data.param[this-&gt;uniforms * 4 + j] = &amp;ctx-&gt;Transform._ClipUserPlane[i][j];<br>
&gt; +            c-&gt;prog_data.param[this-&gt;uniforms * 4 + j] = &amp;clip_planes[i][j];<br>
&gt;           }<br>
&gt;           ++compacted_clipplane_index;<br>
&gt;           ++this-&gt;uniforms;<br>
&gt; @@ -1863,9 +1865,27 @@ vec4_visitor::emit_clip_distances(struct brw_reg reg, int offset)<br>
&gt;        return;<br>
&gt;     }<br>
&gt;<br>
&gt; +   /* From the GLSL 1.30 spec, section 7.1 (Vertex Shader Special Variables):<br>
&gt; +    *<br>
&gt; +    *     &quot;If a linked set of shaders forming the vertex stage contains no<br>
&gt; +    *     static write to gl_ClipVertex or gl_ClipDistance, but the<br>
&gt; +    *     application has requested clipping against user clip planes through<br>
&gt; +    *     the API, then the coordinate written to gl_Position is used for<br>
&gt; +    *     comparison against the user clip planes.&quot;<br>
&gt; +    *<br>
&gt; +    * This function is only called if the shader didn&#39;t write to<br>
&gt; +    * gl_ClipDistance.  Accordingly, we use gl_ClipVertex to perform clipping<br>
&gt; +    * if the user wrote to it; otherwise we use gl_Position.<br>
&gt; +    */<br>
&gt; +   gl_vert_result clip_vertex = VERT_RESULT_CLIP_VERTEX;<br>
&gt; +   if (!(c-&gt;prog_data.outputs_written<br>
&gt; +         &amp; BITFIELD64_BIT(VERT_RESULT_CLIP_VERTEX))) {<br>
&gt; +      clip_vertex = VERT_RESULT_HPOS;<br>
&gt; +   }<br>
&gt; +<br>
&gt;     for (int i = 0; i + offset &lt; c-&gt;key.nr_userclip &amp;&amp; i &lt; 4; ++i) {<br>
&gt;        emit(DP4(dst_reg(brw_writemask(reg, 1 &lt;&lt; i)),<br>
&gt; -               src_reg(output_reg[VERT_RESULT_HPOS]),<br>
&gt; +               src_reg(output_reg[clip_vertex]),<br>
&gt;                 src_reg(this-&gt;userplane[i + offset])));<br>
&gt;     }<br>
&gt;  }<br>
&gt; diff --git a/src/mesa/drivers/dri/i965/brw_vs.c b/src/mesa/drivers/dri/i965/brw_vs.c<br>
&gt; index 93c6838..360deed 100644<br>
&gt; --- a/src/mesa/drivers/dri/i965/brw_vs.c<br>
&gt; +++ b/src/mesa/drivers/dri/i965/brw_vs.c<br>
&gt; @@ -137,15 +137,47 @@ brw_compute_vue_map(struct brw_vue_map *vue_map,<br>
&gt;     /* The hardware doesn&#39;t care about the rest of the vertex outputs, so just<br>
&gt;      * assign them contiguously.  Don&#39;t reassign outputs that already have a<br>
&gt;      * slot.<br>
&gt; +    *<br>
&gt; +    * Also, don&#39;t assign a slot for VERT_RESULT_CLIP_VERTEX, since it is<br>
&gt; +    * unsupported in pre-GEN6, and in GEN6+ the vertex shader converts it into<br>
&gt; +    * clip distances.<br>
&gt;      */<br>
&gt;     for (int i = 0; i &lt; VERT_RESULT_MAX; ++i) {<br>
&gt;        if ((outputs_written &amp; BITFIELD64_BIT(i)) &amp;&amp;<br>
&gt; -          vue_map-&gt;vert_result_to_slot[i] == -1) {<br>
&gt; +          vue_map-&gt;vert_result_to_slot[i] == -1 &amp;&amp;<br>
&gt; +          i != VERT_RESULT_CLIP_VERTEX) {<br>
&gt;           assign_vue_slot(vue_map, i);<br>
&gt;        }<br>
&gt;     }<br>
&gt;  }<br>
&gt;<br>
&gt; +<br>
&gt; +/**<br>
&gt; + * Decide which set of clip planes should be used when clipping via<br>
&gt; + * gl_Position or gl_ClipVertex.<br>
&gt; + */<br>
&gt; +GLclipplane *brw_select_clip_planes(struct gl_context *ctx)<br>
&gt; +{<br>
&gt; +   if (ctx-&gt;Shader.CurrentVertexProgram) {<br>
&gt; +      /* There is currently a GLSL vertex shader, so clip according to GLSL<br>
&gt; +       * rules, which means compare gl_ClipVertex (or gl_Position, if<br>
&gt; +       * gl_ClipVertex wasn&#39;t assigned) against the eye-coordinate clip planes<br>
&gt; +       * that were stored in EyeUserPlane at the time the clip planes were<br>
&gt; +       * specified.<br>
&gt; +       */<br>
&gt; +      return ctx-&gt;Transform.EyeUserPlane;<br>
&gt; +   } else {<br>
&gt; +      /* Either we are using fixed function or an ARB vertex program.  In<br>
&gt; +       * either case the clip planes are going to be compared against<br>
&gt; +       * gl_Position (which is in clip coordinates) so we have to clip using<br>
&gt; +       * _ClipUserPlane, which was transformed into clip coordinates by Mesa<br>
&gt; +       * core.<br>
&gt; +       */<br>
&gt; +      return ctx-&gt;Transform._ClipUserPlane;<br>
&gt; +   }<br>
&gt; +}<br>
&gt; +<br>
&gt; +<br>
&gt;  static bool<br>
&gt;  do_vs_prog(struct brw_context *brw,<br>
&gt;          struct gl_shader_program *prog,<br>
&gt; diff --git a/src/mesa/drivers/dri/i965/gen6_vs_state.c b/src/mesa/drivers/dri/i965/gen6_vs_state.c<br>
&gt; index 0f6f6a7..d827ee0 100644<br>
&gt; --- a/src/mesa/drivers/dri/i965/gen6_vs_state.c<br>
&gt; +++ b/src/mesa/drivers/dri/i965/gen6_vs_state.c<br>
&gt; @@ -77,9 +77,10 @@ gen6_prepare_vs_push_constants(struct brw_context *brw)<br>
&gt;            * until we redo the VS backend.<br>
&gt;            */<br>
&gt;           if (!uses_clip_distance) {<br>
&gt; +            GLclipplane *clip_planes = brw_select_clip_planes(ctx);<br>
&gt;              for (i = 0; i &lt; MAX_CLIP_PLANES; i++) {<br>
&gt;                 if (ctx-&gt;Transform.ClipPlanesEnabled &amp; (1 &lt;&lt; i)) {<br>
&gt; -                  memcpy(param, ctx-&gt;Transform._ClipUserPlane[i], 4 * sizeof(float));<br>
&gt; +                  memcpy(param, clip_planes[i], 4 * sizeof(float));<br>
&gt;                    param += 4;<br>
&gt;                    params_uploaded++;<br>
&gt;                 }<br>
&gt; diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h<br>
&gt; index ab03d9a..265559b 100644<br>
&gt; --- a/src/mesa/main/mtypes.h<br>
&gt; +++ b/src/mesa/main/mtypes.h<br>
&gt; @@ -1493,13 +1493,20 @@ struct gl_texture_attrib<br>
&gt;<br>
&gt;<br>
&gt;  /**<br>
&gt; + * Data structure representing a single clip plane (e.g. one of the elements<br>
&gt; + * of the ctx-&gt;Transform.EyeUserPlane or ctx-&gt;Transform._ClipUserPlane array).<br>
&gt; + */<br>
&gt; +typedef GLfloat GLclipplane[4];<br>
&gt; +<br>
&gt; +<br>
&gt; +/**<br>
&gt;   * Transformation attribute group (GL_TRANSFORM_BIT).<br>
&gt;   */<br>
&gt;  struct gl_transform_attrib<br>
&gt;  {<br>
&gt;     GLenum MatrixMode;                                /**&lt; Matrix mode */<br>
&gt; -   GLfloat EyeUserPlane[MAX_CLIP_PLANES][4]; /**&lt; User clip planes */<br>
&gt; -   GLfloat _ClipUserPlane[MAX_CLIP_PLANES][4];       /**&lt; derived */<br>
&gt; +   GLclipplane EyeUserPlane[MAX_CLIP_PLANES];        /**&lt; User clip planes */<br>
&gt; +   GLclipplane _ClipUserPlane[MAX_CLIP_PLANES];      /**&lt; derived */<br>
&gt;     GLbitfield ClipPlanesEnabled;                /**&lt; on/off bitmask */<br>
&gt;     GLboolean Normalize;                              /**&lt; Normalize all normals? */<br>
&gt;     GLboolean RescaleNormals;                 /**&lt; GL_EXT_rescale_normal */<br>
</div></div>-----BEGIN PGP SIGNATURE-----<br>
Version: GnuPG v1.4.11 (GNU/Linux)<br>
Comment: Using GnuPG with Mozilla - <a href="http://enigmail.mozdev.org/" target="_blank">http://enigmail.mozdev.org/</a><br>
<br>
iQIcBAEBAgAGBQJOi0MpAAoJEAIvNt057x8iiWIP/1WrKCQhfrU6u3fc5fNiZYlU<br>
MULaamE5N8PxdrXXEoBA4Yrmi5RyNo+ilPzDolLzVyaihykJ+pFUuRzb3pV48NSb<br>
RDnPvuq1AHb1gCSmr1VuNX5WbZJI9ElwzwmK5V/YiIr5hp9vbYsTfiIoxKYNIhdn<br>
aGkjhQ8zEhxD84r0PODg0nSEmS/KDYSm8kusDAhDIEmGyH2gYPbqUkBkSdMAMJqp<br>
XvZNtO/Odxf20/81KKsTGrLorhvxbyKblpaNG/WQ0vrlJ2PvK8gUuxNjQV/lW5u/<br>
DQ+PEp3l1t4jPylE8li5oMDBRfSwGv0fIH9JNH1yxKLT7dbEzGxw7PfW17kSEdf5<br>
fFVe0iyfXNFyZG+CYQjfQDOCH/w7rRpX7gev4gOVV+jXluaazG+V/4AMCYgg8JpG<br>
cSDZ+zK0UxQb1z6WWDwfIrMemcdYBV60ZqQBNJyoIa1GuanPGp66mrf1pmaWbkwY<br>
ADF/4NYtuabR3Ta5YMehHWt7eBiiEcfMGyJHqUnNcoYlvk56GxUB021DQaAWEYMn<br>
7rLEPp1tPXgwTDr1Z3XdwGyYyFWg06MuYMhFhv/vUdEieJMbYYx6HmaMAPsmgnkO<br>
9f1uwcEJ5ZMO59hDL/8y4/s3tXKIwdjmAko/pfsg+Cn0XNhaXSTPcmD15sCoNT0Y<br>
cXOcwHrdS9DfsWl+TH1r<br>
=tUpM<br>
-----END PGP SIGNATURE-----<br>
</blockquote></div><br>