<p><br>
On Jan 20, 2012 9:07 PM, "Jonathan Coome" <<a href="mailto:jcoome@fastmail.co.uk">jcoome@fastmail.co.uk</a>> wrote:<br>
><br>
> On 19/01/2012 23:48, Yuanhan Liu wrote:<br>
> > When rendering to FBO, rendering is inverted. At the same time, we would<br>
> > also make sure the point sprite origin is inverted. Or, we will get an<br>
> > inverted result correspoinding to rendering to the default winsys FBO.<br>
> ><br>
> > Bugzilla: <a href="https://bugs.freedesktop.org/show_bug.cgi?id=44613">https://bugs.freedesktop.org/show_bug.cgi?id=44613</a><br>
> ><br>
> > NOTE: This is a candidate for stable release branches.<br>
> ><br>
> > v2: add the simliar logic to ivb, too (comments from Ian)<br>
> > simplify the logic operation (comments from Brian)<br>
> ><br>
> > v3: pick a better comment from Eric<br>
> > use != for the logic instead of ^ (comments from Ian)<br>
> ><br>
> > Signed-off-by: Yuanhan Liu <<a href="mailto:yuanhan.liu@linux.intel.com">yuanhan.liu@linux.intel.com</a>><br>
> > ---<br>
> > src/mesa/drivers/dri/i965/brw_defines.h | 1 +<br>
> > src/mesa/drivers/dri/i965/gen6_sf_state.c | 13 +++++++++++--<br>
> > src/mesa/drivers/dri/i965/gen7_sf_state.c | 18 +++++++++++++++---<br>
> > 3 files changed, 27 insertions(+), 5 deletions(-)<br>
> ><br>
> > diff --git a/src/mesa/drivers/dri/i965/brw_defines.h b/src/mesa/drivers/dri/i965/brw_defines.h<br>
> > index 4d90a99..029be87 100644<br>
> > --- a/src/mesa/drivers/dri/i965/brw_defines.h<br>
> > +++ b/src/mesa/drivers/dri/i965/brw_defines.h<br>
> > @@ -1128,6 +1128,7 @@ enum brw_message_target {<br>
> > /* DW1 (for gen6) */<br>
> > # define GEN6_SF_NUM_OUTPUTS_SHIFT 22<br>
> > # define GEN6_SF_SWIZZLE_ENABLE (1 << 21)<br>
> > +# define GEN6_SF_POINT_SPRITE_UPPERLEFT (0 << 20)<br>
> > # define GEN6_SF_POINT_SPRITE_LOWERLEFT (1 << 20)<br>
> > # define GEN6_SF_URB_ENTRY_READ_LENGTH_SHIFT 11<br>
> > # define GEN6_SF_URB_ENTRY_READ_OFFSET_SHIFT 4<br>
> > diff --git a/src/mesa/drivers/dri/i965/gen6_sf_state.c b/src/mesa/drivers/dri/i965/gen6_sf_state.c<br>
> > index 548c5a3..163b54c 100644<br>
> > --- a/src/mesa/drivers/dri/i965/gen6_sf_state.c<br>
> > +++ b/src/mesa/drivers/dri/i965/gen6_sf_state.c<br>
> > @@ -129,6 +129,7 @@ upload_sf_state(struct brw_context *brw)<br>
> > float point_size;<br>
> > uint16_t attr_overrides[FRAG_ATTRIB_MAX];<br>
> > bool userclip_active;<br>
> > + uint32_t point_sprite_origin;<br>
> ><br>
> > /* _NEW_TRANSFORM */<br>
> > userclip_active = (ctx->Transform.ClipPlanesEnabled != 0);<br>
> > @@ -258,8 +259,16 @@ upload_sf_state(struct brw_context *brw)<br>
> > /* Clamp to the hardware limits and convert to fixed point */<br>
> > dw4 |= U_FIXED(CLAMP(point_size, 0.125, 255.875), 3);<br>
> ><br>
> > - if (ctx->Point.SpriteOrigin == GL_LOWER_LEFT)<br>
> > - dw1 |= GEN6_SF_POINT_SPRITE_LOWERLEFT;<br>
> > + /*<br>
> > + * Window coordinates in an FBO are inverted, which means point<br>
> > + * sprite origin must be inverted, too.<br>
> > + */<br>
> > + if ((ctx->Point.SpriteOrigin == GL_LOWER_LEFT) != render_to_fbo) {<br>
> > + point_sprite_origin = GEN6_SF_POINT_SPRITE_LOWERLEFT;<br>
> > + } else {<br>
> > + point_sprite_origin = GEN6_SF_POINT_SPRITE_UPPERLEFT;<br>
> > + }<br>
> > + dw1 |= point_sprite_origin;<br>
> ><br>
> > /* _NEW_LIGHT */<br>
> > if (ctx->Light.ProvokingVertex != GL_FIRST_VERTEX_CONVENTION) {<br>
> > diff --git a/src/mesa/drivers/dri/i965/gen7_sf_state.c b/src/mesa/drivers/dri/i965/gen7_sf_state.c<br>
> > index 7691cb2..da7ef81 100644<br>
> > --- a/src/mesa/drivers/dri/i965/gen7_sf_state.c<br>
> > +++ b/src/mesa/drivers/dri/i965/gen7_sf_state.c<br>
> > @@ -48,6 +48,9 @@ upload_sbe_state(struct brw_context *brw)<br>
> > int urb_entry_read_offset = 1;<br>
> > bool userclip_active = (ctx->Transform.ClipPlanesEnabled != 0);<br>
> > uint16_t attr_overrides[FRAG_ATTRIB_MAX];<br>
> > + /* _NEW_BUFFERS */<br>
> > + bool render_to_fbo = ctx->DrawBuffer->Name != 0;<br>
> > + uint32_t point_sprite_origin;<br>
> ><br>
> > brw_compute_vue_map(&vue_map, intel, userclip_active, vs_outputs_written);<br>
> > urb_entry_read_length = (vue_map.num_slots + 1)/2 - urb_entry_read_offset;<br>
> > @@ -65,9 +68,18 @@ upload_sbe_state(struct brw_context *brw)<br>
> > urb_entry_read_length << GEN7_SBE_URB_ENTRY_READ_LENGTH_SHIFT |<br>
> > urb_entry_read_offset << GEN7_SBE_URB_ENTRY_READ_OFFSET_SHIFT;<br>
> ><br>
> > - /* _NEW_POINT */<br>
> > - if (ctx->Point.SpriteOrigin == GL_LOWER_LEFT)<br>
> > - dw1 |= GEN6_SF_POINT_SPRITE_LOWERLEFT;<br>
> > + /* _NEW_POINT<br>
> > + *<br>
> > + * Window coordinates in an FBO are inverted, which means point<br>
> > + * sprite origin must be inverted.<br>
> > + */<br>
> > + if ((ctx->Point.SpriteOrigin == GL_LOWER_LEFT) != render_to_fbo) {<br>
> > + point_sprite_origin = GEN6_SF_POINT_SPRITE_LOWERLEFT;<br>
> > + } else {<br>
> > + point_sprite_origin = GEN6_SF_POINT_SPRITE_UPPERLEFT;<br>
> > + }<br>
> > + dw1 |= point_sprite_origin;<br>
> > +<br>
> ><br>
> > dw10 = 0;<br>
> > dw11 = 0;<br>
><br>
> Is there any need for GEN6_SF_POINT_SPRITE_UPPERLEFT?</p>
<p>For making the code clear and easy reading, I'd like to add it.</p>
<p>> It's basically 0,<br>
> so the | operation with dw1 won't have any effect, and you could remove<br>
> the else clauses.<br>
> And if you wanted to clear the bit, </p>
<p>No, its not supposed to be a clear operation, but an _or_ operation. And the operand happens to be zero. Just image we want to set a bit, but not set 0. So, the logic of your following code doesn't make sense to me.</p>
<p>Thanks.</p>
<p>--<br>
Yuanhan Liu<br>
(Sent by my phone, please forgive for the poor format)</p>
<p>>I think you'd need<br>
> to do something like this instead:<br>
><br>
> if ((ctx->Point.SpriteOrigin == GL_LOWER_LEFT) != render_to_fbo) {<br>
> dw1 |= GEN6_SF_POINT_SPRITE_LOWERLEFT;<br>
> } else {<br>
> dw1 &= ~GEN6_SF_POINT_SPRITE_LOWERLEFT;<br>
> }<br>
><br>
> -Jonathan<br>
> _______________________________________________<br>
> mesa-dev mailing list<br>
> <a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
> <a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</p>