<div dir="ltr">On 14 July 2013 02:39, Chris Forbes <span dir="ltr"><<a href="mailto:chrisf@ijw.co.nz" target="_blank">chrisf@ijw.co.nz</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Previously we only gave special treatment to the builtin color varyings.<br>
This patch adds support for arbitrary flat-shaded varyings, which is<br>
required for GLSL 1.30.<br>
<br>
Based on Olivier Galibert's patch from last year:<br>
<a href="http://lists.freedesktop.org/archives/mesa-dev/2012-July/024340.html" target="_blank">http://lists.freedesktop.org/archives/mesa-dev/2012-July/024340.html</a><br>
<br>
[V1-2]: Signed-off-by: Olivier Galibert <galibert at <a href="http://pobox.com" target="_blank">pobox.com</a>><br>
Signed-off-by: Chris Forbes <<a href="mailto:chrisf@ijw.co.nz" target="_blank">chrisf@ijw.co.nz</a>><br>
---<br>
src/mesa/drivers/dri/i965/brw_clip.c | 13 +++++--<br>
src/mesa/drivers/dri/i965/brw_clip.h | 6 ++--<br>
src/mesa/drivers/dri/i965/brw_clip_line.c | 6 ++--<br>
src/mesa/drivers/dri/i965/brw_clip_tri.c | 18 +++++-----<br>
src/mesa/drivers/dri/i965/brw_clip_unfilled.c | 2 +-<br>
src/mesa/drivers/dri/i965/brw_clip_util.c | 51 +++++++--------------------<br>
6 files changed, 40 insertions(+), 56 deletions(-)<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/brw_clip.c b/src/mesa/drivers/dri/i965/brw_clip.c<br>
index 488e0a0..7df4b18 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_clip.c<br>
+++ b/src/mesa/drivers/dri/i965/brw_clip.c<br>
@@ -186,6 +186,7 @@ brw_upload_clip_prog(struct brw_context *brw)<br>
{<br>
struct gl_context *ctx = &brw->ctx;<br>
struct brw_clip_prog_key key;<br>
+ int i;<br>
<br>
memset(&key, 0, sizeof(key));<br>
<br>
@@ -200,8 +201,16 @@ brw_upload_clip_prog(struct brw_context *brw)<br>
key.primitive = brw->reduced_primitive;<br>
/* BRW_NEW_VUE_MAP_GEOM_OUT */<br>
key.attrs = brw->vue_map_geom_out.slots_valid;<br>
- /* _NEW_LIGHT */<br>
- key.do_flat_shading = (ctx->Light.ShadeModel == GL_FLAT);<br>
+<br>
+ /* BRW_NEW_FRAGMENT_PROGRAM, _NEW_LIGHT */<br>
+ key.has_flat_shading = 0;<br>
+ for (i = 0; i < brw->vue_map_geom_out.num_slots; i++) {<br>
+ if (key.interpolation_mode[i] == INTERP_QUALIFIER_FLAT) {<br>
+ key.has_flat_shading = 1;<br>
+ break;<br>
+ }<br>
+ }<br></blockquote><div><br></div><div>Similar to my comment on patch 2/5, I'd prefer to see this for() loop moved into compile_clip_prog() (and key.has_flat_shading moved into brw_clip_compile) so that we only do this computation when compiling the clip program.<br>
<br>In fact, since this is the same computation that patch 2/5 added to SF, we should probably move it to its own function to avoid code duplication.<br><br></div><div>With that fixed, this patch is:<br><br></div><div>Reviewed-by: Paul Berry <<a href="mailto:stereotype441@gmail.com">stereotype441@gmail.com</a>><br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
key.pv_first = (ctx->Light.ProvokingVertex == GL_FIRST_VERTEX_CONVENTION);<br>
/* _NEW_TRANSFORM (also part of VUE map)*/<br>
key.nr_userclip = _mesa_bitcount_64(ctx->Transform.ClipPlanesEnabled);<br>
diff --git a/src/mesa/drivers/dri/i965/brw_clip.h b/src/mesa/drivers/dri/i965/brw_clip.h<br>
index fcbe2a0..656254b 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_clip.h<br>
+++ b/src/mesa/drivers/dri/i965/brw_clip.h<br>
@@ -46,7 +46,7 @@ struct brw_clip_prog_key {<br>
unsigned char interpolation_mode[BRW_VARYING_SLOT_COUNT];<br>
GLuint primitive:4;<br>
GLuint nr_userclip:4;<br>
- GLuint do_flat_shading:1;<br>
+ GLuint has_flat_shading:1;<br>
GLuint pv_first:1;<br>
GLuint do_unfilled:1;<br>
GLuint fill_cw:2; /* includes cull information */<br>
@@ -173,8 +173,8 @@ void brw_clip_kill_thread(struct brw_clip_compile *c);<br>
struct brw_reg brw_clip_plane_stride( struct brw_clip_compile *c );<br>
struct brw_reg brw_clip_plane0_address( struct brw_clip_compile *c );<br>
<br>
-void brw_clip_copy_colors( struct brw_clip_compile *c,<br>
- GLuint to, GLuint from );<br>
+void brw_clip_copy_flatshaded_attributes( struct brw_clip_compile *c,<br>
+ GLuint to, GLuint from );<br>
<br>
void brw_clip_init_clipmask( struct brw_clip_compile *c );<br>
<br>
diff --git a/src/mesa/drivers/dri/i965/brw_clip_line.c b/src/mesa/drivers/dri/i965/brw_clip_line.c<br>
index 9ce80b8..8df7d0c 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_clip_line.c<br>
+++ b/src/mesa/drivers/dri/i965/brw_clip_line.c<br>
@@ -272,11 +272,11 @@ void brw_emit_line_clip( struct brw_clip_compile *c )<br>
brw_clip_line_alloc_regs(c);<br>
brw_clip_init_ff_sync(c);<br>
<br>
- if (c->key.do_flat_shading) {<br>
+ if (c->key.has_flat_shading) {<br>
if (c->key.pv_first)<br>
- brw_clip_copy_colors(c, 1, 0);<br>
+ brw_clip_copy_flatshaded_attributes(c, 1, 0);<br>
else<br>
- brw_clip_copy_colors(c, 0, 1);<br>
+ brw_clip_copy_flatshaded_attributes(c, 0, 1);<br>
}<br>
<br>
clip_and_emit_line(c);<br>
diff --git a/src/mesa/drivers/dri/i965/brw_clip_tri.c b/src/mesa/drivers/dri/i965/brw_clip_tri.c<br>
index bea0853..ac24929 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_clip_tri.c<br>
+++ b/src/mesa/drivers/dri/i965/brw_clip_tri.c<br>
@@ -190,8 +190,8 @@ void brw_clip_tri_flat_shade( struct brw_clip_compile *c )<br>
<br>
brw_IF(p, BRW_EXECUTE_1);<br>
{<br>
- brw_clip_copy_colors(c, 1, 0);<br>
- brw_clip_copy_colors(c, 2, 0);<br>
+ brw_clip_copy_flatshaded_attributes(c, 1, 0);<br>
+ brw_clip_copy_flatshaded_attributes(c, 2, 0);<br>
}<br>
brw_ELSE(p);<br>
{<br>
@@ -203,19 +203,19 @@ void brw_clip_tri_flat_shade( struct brw_clip_compile *c )<br>
brw_imm_ud(_3DPRIM_TRIFAN));<br>
brw_IF(p, BRW_EXECUTE_1);<br>
{<br>
- brw_clip_copy_colors(c, 0, 1);<br>
- brw_clip_copy_colors(c, 2, 1);<br>
+ brw_clip_copy_flatshaded_attributes(c, 0, 1);<br>
+ brw_clip_copy_flatshaded_attributes(c, 2, 1);<br>
}<br>
brw_ELSE(p);<br>
{<br>
- brw_clip_copy_colors(c, 1, 0);<br>
- brw_clip_copy_colors(c, 2, 0);<br>
+ brw_clip_copy_flatshaded_attributes(c, 1, 0);<br>
+ brw_clip_copy_flatshaded_attributes(c, 2, 0);<br>
}<br>
brw_ENDIF(p);<br>
}<br>
else {<br>
- brw_clip_copy_colors(c, 0, 2);<br>
- brw_clip_copy_colors(c, 1, 2);<br>
+ brw_clip_copy_flatshaded_attributes(c, 0, 2);<br>
+ brw_clip_copy_flatshaded_attributes(c, 1, 2);<br>
}<br>
}<br>
brw_ENDIF(p);<br>
@@ -645,7 +645,7 @@ void brw_emit_tri_clip( struct brw_clip_compile *c )<br>
* flatshading, need to apply the flatshade here because we don't<br>
* respect the PV when converting to trifan for emit:<br>
*/<br>
- if (c->key.do_flat_shading)<br>
+ if (c->key.has_flat_shading)<br>
brw_clip_tri_flat_shade(c);<br>
<br>
if ((c->key.clip_mode == BRW_CLIPMODE_NORMAL) ||<br>
diff --git a/src/mesa/drivers/dri/i965/brw_clip_unfilled.c b/src/mesa/drivers/dri/i965/brw_clip_unfilled.c<br>
index e211b95..0e645c0 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_clip_unfilled.c<br>
+++ b/src/mesa/drivers/dri/i965/brw_clip_unfilled.c<br>
@@ -501,7 +501,7 @@ void brw_emit_unfilled_clip( struct brw_clip_compile *c )<br>
<br>
/* Need to do this whether we clip or not:<br>
*/<br>
- if (c->key.do_flat_shading)<br>
+ if (c->key.has_flat_shading)<br>
brw_clip_tri_flat_shade(c);<br>
<br>
brw_clip_init_clipmask(c);<br>
diff --git a/src/mesa/drivers/dri/i965/brw_clip_util.c b/src/mesa/drivers/dri/i965/brw_clip_util.c<br>
index 37b7734..8a21c1f 100644<br>
--- a/src/mesa/drivers/dri/i965/brw_clip_util.c<br>
+++ b/src/mesa/drivers/dri/i965/brw_clip_util.c<br>
@@ -290,49 +290,24 @@ struct brw_reg brw_clip_plane_stride( struct brw_clip_compile *c )<br>
}<br>
<br>
<br>
-/* If flatshading, distribute color from provoking vertex prior to<br>
+/* Distribute flatshaded attributes from provoking vertex prior to<br>
* clipping.<br>
*/<br>
-void brw_clip_copy_colors( struct brw_clip_compile *c,<br>
+void brw_clip_copy_flatshaded_attributes( struct brw_clip_compile *c,<br>
GLuint to, GLuint from )<br>
{<br>
struct brw_compile *p = &c->func;<br>
-<br>
- if (brw_clip_have_varying(c, VARYING_SLOT_COL0))<br>
- brw_MOV(p,<br>
- byte_offset(c->reg.vertex[to],<br>
- brw_varying_to_offset(&c->vue_map,<br>
- VARYING_SLOT_COL0)),<br>
- byte_offset(c->reg.vertex[from],<br>
- brw_varying_to_offset(&c->vue_map,<br>
- VARYING_SLOT_COL0)));<br>
-<br>
- if (brw_clip_have_varying(c, VARYING_SLOT_COL1))<br>
- brw_MOV(p,<br>
- byte_offset(c->reg.vertex[to],<br>
- brw_varying_to_offset(&c->vue_map,<br>
- VARYING_SLOT_COL1)),<br>
- byte_offset(c->reg.vertex[from],<br>
- brw_varying_to_offset(&c->vue_map,<br>
- VARYING_SLOT_COL1)));<br>
-<br>
- if (brw_clip_have_varying(c, VARYING_SLOT_BFC0))<br>
- brw_MOV(p,<br>
- byte_offset(c->reg.vertex[to],<br>
- brw_varying_to_offset(&c->vue_map,<br>
- VARYING_SLOT_BFC0)),<br>
- byte_offset(c->reg.vertex[from],<br>
- brw_varying_to_offset(&c->vue_map,<br>
- VARYING_SLOT_BFC0)));<br>
-<br>
- if (brw_clip_have_varying(c, VARYING_SLOT_BFC1))<br>
- brw_MOV(p,<br>
- byte_offset(c->reg.vertex[to],<br>
- brw_varying_to_offset(&c->vue_map,<br>
- VARYING_SLOT_BFC1)),<br>
- byte_offset(c->reg.vertex[from],<br>
- brw_varying_to_offset(&c->vue_map,<br>
- VARYING_SLOT_BFC1)));<br>
+ int i;<br>
+<br>
+ for (i=0; i < c->vue_map.num_slots; i++) {<br>
+ if (c->key.interpolation_mode[i] == INTERP_QUALIFIER_FLAT) {<br>
+ printf("flatshaded: %d @ %d\n", i,<br>
+ brw_vue_slot_to_offset(i));<br>
+ brw_MOV(p,<br>
+ byte_offset(c->reg.vertex[to], brw_vue_slot_to_offset(i)),<br>
+ byte_offset(c->reg.vertex[from], brw_vue_slot_to_offset(i)));<br>
+ }<br>
+ }<br>
}<br>
<span><font color="#888888"><br>
<br>
--<br>
1.8.3.2<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>