On 4 October 2011 10:32, Chad Versace <span dir="ltr"><<a href="mailto:chad@chad-versace.us">chad@chad-versace.us</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;">
-----BEGIN PGP SIGNED MESSAGE-----<br>
Hash: SHA1<br>
<br>
Overall, the patch looks good, but I'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'm fine with this. Unless someone has a better suggestion, I propose renaming "GLclipplane" to "gl_clip_plane". 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>
> This patch implements proper support for gl_ClipVertex by causing the<br>
> new VS backend to populate the clip distance VUE slots using<br>
> VERT_RESULT_CLIP_VERTEX when appropriate, and by using the<br>
> untransformed clip planes in ctx->Transform.EyeUserPlane rather than<br>
> the transformed clip planes in ctx->Transform._ClipUserPlane when a<br>
> GLSL-based vertex shader is in use.<br>
><br>
> When not using a GLSL-based vertex shader, we use<br>
> ctx->Transform._ClipUserPlane (which is what we used prior to this<br>
> patch). This ensures that clipping is still performed correctly for<br>
> fixed function and ARB vertex programs. A new function,<br>
> brw_select_clip_planes() is used to determine whether to use<br>
> _ClipUserPlane or EyeUserPlane, so that the logic for making this<br>
> decision is shared between the new and old vertex shaders.<br>
><br>
> Fixes the following Piglit tests on i965 Gen6:<br>
> - vs-clip-vertex-const-accept<br>
> - vs-clip-vertex-const-reject<br>
> - vs-clip-vertex-different-from-position<br>
> - vs-clip-vertex-equal-to-position<br>
> - vs-clip-vertex-homogeneity<br>
> - vs-clip-based-on-position<br>
> - vs-clip-based-on-position-homogeneity<br>
> - clip-plane-transformation clipvert_pos<br>
> - clip-plane-transformation pos_clipvert<br>
> - clip-plane-transformation pos<br>
> ---<br>
> src/mesa/drivers/dri/i965/brw_context.h | 3 ++<br>
> src/mesa/drivers/dri/i965/brw_curbe.c | 10 ++++---<br>
> src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp | 24 +++++++++++++++-<br>
> src/mesa/drivers/dri/i965/brw_vs.c | 34 +++++++++++++++++++++++-<br>
> src/mesa/drivers/dri/i965/gen6_vs_state.c | 3 +-<br>
> src/mesa/main/mtypes.h | 11 ++++++-<br>
> 6 files changed, 75 insertions(+), 10 deletions(-)<br>
><br>
> diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h<br>
> index d32eded..7c5bfd0 100644<br>
> --- a/src/mesa/drivers/dri/i965/brw_context.h<br>
> +++ b/src/mesa/drivers/dri/i965/brw_context.h<br>
> @@ -899,6 +899,7 @@ struct brw_context<br>
> };<br>
><br>
><br>
> +<br>
> #define BRW_PACKCOLOR8888(r,g,b,a) ((r<<24) | (g<<16) | (b<<8) | a)<br>
><br>
> struct brw_instruction_info {<br>
<br>
<br>
</div></div>The above hunk is spurious.<br></blockquote><div><br>Oops. I'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>
> @@ -966,6 +967,8 @@ int brw_disasm (FILE *file, struct brw_instruction *inst, int gen);<br>
> void brw_compute_vue_map(struct brw_vue_map *vue_map,<br>
> const struct intel_context *intel, int nr_userclip,<br>
> GLbitfield64 outputs_written);<br>
> +GLclipplane *brw_select_clip_planes(struct gl_context *ctx);<br>
> +<br>
><br>
> /*======================================================================<br>
> * Inline conversion functions. These are better-typed than the<br>
> diff --git a/src/mesa/drivers/dri/i965/brw_curbe.c b/src/mesa/drivers/dri/i965/brw_curbe.c<br>
> index e1676de..5d2a024 100644<br>
> --- a/src/mesa/drivers/dri/i965/brw_curbe.c<br>
> +++ b/src/mesa/drivers/dri/i965/brw_curbe.c<br>
> @@ -188,6 +188,7 @@ static void prepare_constant_buffer(struct brw_context *brw)<br>
> const GLuint bufsz = sz * 16 * sizeof(GLfloat);<br>
> GLfloat *buf;<br>
> GLuint i;<br>
> + GLclipplane *clip_planes;<br>
><br>
> if (sz == 0) {<br>
> brw->curbe.last_bufsz = 0;<br>
> @@ -232,12 +233,13 @@ static void prepare_constant_buffer(struct brw_context *brw)<br>
> /* Clip planes: _NEW_TRANSFORM plus _NEW_PROJECTION to get to<br>
> * clip-space:<br>
> */<br>
> + clip_planes = brw_select_clip_planes(ctx);<br>
> for (j = 0; j < MAX_CLIP_PLANES; j++) {<br>
> if (ctx->Transform.ClipPlanesEnabled & (1<<j)) {<br>
> - buf[offset + i * 4 + 0] = ctx->Transform._ClipUserPlane[j][0];<br>
> - buf[offset + i * 4 + 1] = ctx->Transform._ClipUserPlane[j][1];<br>
> - buf[offset + i * 4 + 2] = ctx->Transform._ClipUserPlane[j][2];<br>
> - buf[offset + i * 4 + 3] = ctx->Transform._ClipUserPlane[j][3];<br>
> + buf[offset + i * 4 + 0] = clip_planes[j][0];<br>
> + buf[offset + i * 4 + 1] = clip_planes[j][1];<br>
> + buf[offset + i * 4 + 2] = clip_planes[j][2];<br>
> + buf[offset + i * 4 + 3] = clip_planes[j][3];<br>
> i++;<br>
> }<br>
> }<br>
> diff --git a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp<br>
> index ad8b433..0f16342 100644<br>
> --- a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp<br>
> +++ b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp<br>
> @@ -557,6 +557,8 @@ vec4_visitor::setup_uniform_values(int loc, const glsl_type *type)<br>
> void<br>
> vec4_visitor::setup_uniform_clipplane_values()<br>
> {<br>
> + GLclipplane *clip_planes = brw_select_clip_planes(ctx);<br>
> +<br>
> int compacted_clipplane_index = 0;<br>
> for (int i = 0; i < MAX_CLIP_PLANES; ++i) {<br>
> if (ctx->Transform.ClipPlanesEnabled & (1 << i)) {<br>
> @@ -564,7 +566,7 @@ vec4_visitor::setup_uniform_clipplane_values()<br>
> this->userplane[compacted_clipplane_index] = dst_reg(UNIFORM, this->uniforms);<br>
> this->userplane[compacted_clipplane_index].type = BRW_REGISTER_TYPE_F;<br>
> for (int j = 0; j < 4; ++j) {<br>
> - c->prog_data.param[this->uniforms * 4 + j] = &ctx->Transform._ClipUserPlane[i][j];<br>
> + c->prog_data.param[this->uniforms * 4 + j] = &clip_planes[i][j];<br>
> }<br>
> ++compacted_clipplane_index;<br>
> ++this->uniforms;<br>
> @@ -1863,9 +1865,27 @@ vec4_visitor::emit_clip_distances(struct brw_reg reg, int offset)<br>
> return;<br>
> }<br>
><br>
> + /* From the GLSL 1.30 spec, section 7.1 (Vertex Shader Special Variables):<br>
> + *<br>
> + * "If a linked set of shaders forming the vertex stage contains no<br>
> + * static write to gl_ClipVertex or gl_ClipDistance, but the<br>
> + * application has requested clipping against user clip planes through<br>
> + * the API, then the coordinate written to gl_Position is used for<br>
> + * comparison against the user clip planes."<br>
> + *<br>
> + * This function is only called if the shader didn't write to<br>
> + * gl_ClipDistance. Accordingly, we use gl_ClipVertex to perform clipping<br>
> + * if the user wrote to it; otherwise we use gl_Position.<br>
> + */<br>
> + gl_vert_result clip_vertex = VERT_RESULT_CLIP_VERTEX;<br>
> + if (!(c->prog_data.outputs_written<br>
> + & BITFIELD64_BIT(VERT_RESULT_CLIP_VERTEX))) {<br>
> + clip_vertex = VERT_RESULT_HPOS;<br>
> + }<br>
> +<br>
> for (int i = 0; i + offset < c->key.nr_userclip && i < 4; ++i) {<br>
> emit(DP4(dst_reg(brw_writemask(reg, 1 << i)),<br>
> - src_reg(output_reg[VERT_RESULT_HPOS]),<br>
> + src_reg(output_reg[clip_vertex]),<br>
> src_reg(this->userplane[i + offset])));<br>
> }<br>
> }<br>
> diff --git a/src/mesa/drivers/dri/i965/brw_vs.c b/src/mesa/drivers/dri/i965/brw_vs.c<br>
> index 93c6838..360deed 100644<br>
> --- a/src/mesa/drivers/dri/i965/brw_vs.c<br>
> +++ b/src/mesa/drivers/dri/i965/brw_vs.c<br>
> @@ -137,15 +137,47 @@ brw_compute_vue_map(struct brw_vue_map *vue_map,<br>
> /* The hardware doesn't care about the rest of the vertex outputs, so just<br>
> * assign them contiguously. Don't reassign outputs that already have a<br>
> * slot.<br>
> + *<br>
> + * Also, don't assign a slot for VERT_RESULT_CLIP_VERTEX, since it is<br>
> + * unsupported in pre-GEN6, and in GEN6+ the vertex shader converts it into<br>
> + * clip distances.<br>
> */<br>
> for (int i = 0; i < VERT_RESULT_MAX; ++i) {<br>
> if ((outputs_written & BITFIELD64_BIT(i)) &&<br>
> - vue_map->vert_result_to_slot[i] == -1) {<br>
> + vue_map->vert_result_to_slot[i] == -1 &&<br>
> + i != VERT_RESULT_CLIP_VERTEX) {<br>
> assign_vue_slot(vue_map, i);<br>
> }<br>
> }<br>
> }<br>
><br>
> +<br>
> +/**<br>
> + * Decide which set of clip planes should be used when clipping via<br>
> + * gl_Position or gl_ClipVertex.<br>
> + */<br>
> +GLclipplane *brw_select_clip_planes(struct gl_context *ctx)<br>
> +{<br>
> + if (ctx->Shader.CurrentVertexProgram) {<br>
> + /* There is currently a GLSL vertex shader, so clip according to GLSL<br>
> + * rules, which means compare gl_ClipVertex (or gl_Position, if<br>
> + * gl_ClipVertex wasn't assigned) against the eye-coordinate clip planes<br>
> + * that were stored in EyeUserPlane at the time the clip planes were<br>
> + * specified.<br>
> + */<br>
> + return ctx->Transform.EyeUserPlane;<br>
> + } else {<br>
> + /* Either we are using fixed function or an ARB vertex program. In<br>
> + * either case the clip planes are going to be compared against<br>
> + * gl_Position (which is in clip coordinates) so we have to clip using<br>
> + * _ClipUserPlane, which was transformed into clip coordinates by Mesa<br>
> + * core.<br>
> + */<br>
> + return ctx->Transform._ClipUserPlane;<br>
> + }<br>
> +}<br>
> +<br>
> +<br>
> static bool<br>
> do_vs_prog(struct brw_context *brw,<br>
> struct gl_shader_program *prog,<br>
> diff --git a/src/mesa/drivers/dri/i965/gen6_vs_state.c b/src/mesa/drivers/dri/i965/gen6_vs_state.c<br>
> index 0f6f6a7..d827ee0 100644<br>
> --- a/src/mesa/drivers/dri/i965/gen6_vs_state.c<br>
> +++ b/src/mesa/drivers/dri/i965/gen6_vs_state.c<br>
> @@ -77,9 +77,10 @@ gen6_prepare_vs_push_constants(struct brw_context *brw)<br>
> * until we redo the VS backend.<br>
> */<br>
> if (!uses_clip_distance) {<br>
> + GLclipplane *clip_planes = brw_select_clip_planes(ctx);<br>
> for (i = 0; i < MAX_CLIP_PLANES; i++) {<br>
> if (ctx->Transform.ClipPlanesEnabled & (1 << i)) {<br>
> - memcpy(param, ctx->Transform._ClipUserPlane[i], 4 * sizeof(float));<br>
> + memcpy(param, clip_planes[i], 4 * sizeof(float));<br>
> param += 4;<br>
> params_uploaded++;<br>
> }<br>
> diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h<br>
> index ab03d9a..265559b 100644<br>
> --- a/src/mesa/main/mtypes.h<br>
> +++ b/src/mesa/main/mtypes.h<br>
> @@ -1493,13 +1493,20 @@ struct gl_texture_attrib<br>
><br>
><br>
> /**<br>
> + * Data structure representing a single clip plane (e.g. one of the elements<br>
> + * of the ctx->Transform.EyeUserPlane or ctx->Transform._ClipUserPlane array).<br>
> + */<br>
> +typedef GLfloat GLclipplane[4];<br>
> +<br>
> +<br>
> +/**<br>
> * Transformation attribute group (GL_TRANSFORM_BIT).<br>
> */<br>
> struct gl_transform_attrib<br>
> {<br>
> GLenum MatrixMode; /**< Matrix mode */<br>
> - GLfloat EyeUserPlane[MAX_CLIP_PLANES][4]; /**< User clip planes */<br>
> - GLfloat _ClipUserPlane[MAX_CLIP_PLANES][4]; /**< derived */<br>
> + GLclipplane EyeUserPlane[MAX_CLIP_PLANES]; /**< User clip planes */<br>
> + GLclipplane _ClipUserPlane[MAX_CLIP_PLANES]; /**< derived */<br>
> GLbitfield ClipPlanesEnabled; /**< on/off bitmask */<br>
> GLboolean Normalize; /**< Normalize all normals? */<br>
> GLboolean RescaleNormals; /**< 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>