<p dir="ltr"><br>
On Apr 12, 2016 8:46 AM, "Marek Olšák" <<a href="mailto:maraeo@gmail.com">maraeo@gmail.com</a>> wrote:<br>
><br>
> On Tue, Apr 12, 2016 at 1:53 AM, Marek Olšák <<a href="mailto:maraeo@gmail.com">maraeo@gmail.com</a>> wrote:<br>
> > On Mon, Apr 11, 2016 at 7:37 PM, Nicolai Hähnle <<a href="mailto:nhaehnle@gmail.com">nhaehnle@gmail.com</a>> wrote:<br>
> >> On 10.04.2016 17:34, Marek Olšák wrote:<br>
> >>><br>
> >>> From: Marek Olšák <<a href="mailto:marek.olsak@amd.com">marek.olsak@amd.com</a>><br>
> >>><br>
> >>> Guard band clipping speeds up rasterization for primitives that are<br>
> >>> partially off-screen. This change in particular results in small<br>
> >>> framerate improvements in a wide range of games.<br>
> >>><br>
> >>> Started by Grigori Goronzy <<a href="mailto:greg@chown.ath.cx">greg@chown.ath.cx</a>>.<br>
> >>> ---<br>
> >>> src/gallium/drivers/radeonsi/si_state.c | 73<br>
> >>> +++++++++++++++++++++++++++++++--<br>
> >>> 1 file changed, 69 insertions(+), 4 deletions(-)<br>
> >>><br>
> >>> diff --git a/src/gallium/drivers/radeonsi/si_state.c<br>
> >>> b/src/gallium/drivers/radeonsi/si_state.c<br>
> >>> index b5db456..bc04b46 100644<br>
> >>> --- a/src/gallium/drivers/radeonsi/si_state.c<br>
> >>> +++ b/src/gallium/drivers/radeonsi/si_state.c<br>
> >>> @@ -887,6 +887,15 @@ static void si_clip_scissor(struct pipe_scissor_state<br>
> >>> *out,<br>
> >>> out->maxy = MIN2(out->maxy, clip->maxy);<br>
> >>> }<br>
> >>><br>
> >>> +static void si_scissor_make_union(struct si_signed_scissor *out,<br>
> >>> + struct si_signed_scissor *in)<br>
> >>> +{<br>
> >>> + out->minx = MIN2(out->minx, in->minx);<br>
> >>> + out->miny = MIN2(out->miny, in->miny);<br>
> >>> + out->maxx = MAX2(out->maxx, in->maxx);<br>
> >>> + out->maxy = MAX2(out->maxy, in->maxy);<br>
> >>> +}<br>
> >>> +<br>
> >>> static void si_emit_one_scissor(struct radeon_winsys_cs *cs,<br>
> >>> struct si_signed_scissor *vp_scissor,<br>
> >>> struct pipe_scissor_state *scissor)<br>
> >>> @@ -908,12 +917,64 @@ static void si_emit_one_scissor(struct<br>
> >>> radeon_winsys_cs *cs,<br>
> >>> S_028254_BR_Y(final.maxy));<br>
> >>> }<br>
> >>><br>
> >>> +/* the range is [-MAX, MAX] */<br>
> >>> +#define SI_MAX_VIEWPORT_RANGE 32768<br>
> >>> +<br>
> >>> +static void si_emit_guardband(struct si_context *sctx,<br>
> >>> + struct si_signed_scissor *vp_as_scissor)<br>
> >>> +{<br>
> >>> + struct radeon_winsys_cs *cs = sctx->b.gfx.cs;<br>
> >>> + struct pipe_viewport_state vp;<br>
> >>> + float left, top, right, bottom, max_range, guardband_x,<br>
> >>> guardband_y;<br>
> >>> +<br>
> >>> + /* Reconstruct the viewport transformation from the scissor. */<br>
> >>> + vp.translate[0] = (vp_as_scissor->minx + vp_as_scissor->maxx) /<br>
> >>> 2.0;<br>
> >>> + vp.translate[1] = (vp_as_scissor->miny + vp_as_scissor->maxy) /<br>
> >>> 2.0;<br>
> >>> + vp.scale[0] = vp_as_scissor->maxx - vp.translate[0];<br>
> >>> + vp.scale[1] = vp_as_scissor->maxy - vp.translate[1];<br>
> >>> +<br>
> >>> + /* Treat a 0x0 viewport as 1x1 to prevent division by zero. */<br>
> >>> + if (vp_as_scissor->minx == vp_as_scissor->maxx)<br>
> >>> + vp.scale[0] = 0.5;<br>
> >>> + if (vp_as_scissor->miny == vp_as_scissor->maxy)<br>
> >>> + vp.scale[1] = 0.5;<br>
> >>> +<br>
> >>> + /* Find the biggest guard band that is inside the supported<br>
> >>> viewport<br>
> >>> + * range. The guard band is specified as a horizontal and vertical<br>
> >>> + * distance from (0,0) in clip space.<br>
> >>> + *<br>
> >>> + * This is done by applying the inverse viewport transformation<br>
> >>> + * on the viewport limits to get those limits in clip space.<br>
> >>> + *<br>
> >>> + * Use a limit one pixel smaller to allow for some precision<br>
> >>> error.<br>
> >>> + */<br>
> >>> + max_range = SI_MAX_VIEWPORT_RANGE - 1;<br>
> >>> + left = (-max_range - vp.translate[0]) / vp.scale[0];<br>
> >>> + right = ( max_range - vp.translate[0]) / vp.scale[0];<br>
> >>> + top = (-max_range - vp.translate[1]) / vp.scale[1];<br>
> >>> + bottom = ( max_range - vp.translate[1]) / vp.scale[1];<br>
> >>> +<br>
> >>> + assert(left < 0 && top < 0 && right > 0 && bottom > 0);<br>
> >><br>
> >><br>
> >> The viewport transform is supplied directly by the user, isn't it? So if<br>
> >> they provide a crazy transform, this assert might trigger. On the other<br>
> >> hand, for reasonable viewport transforms, it should even be the case that<br>
> >> left <= -1.0, right >= 1.0, and so on, right? I guess what I'm saying is<br>
> >> that the spirit of the assert is good and could probably be even<br>
> >> strengthened, but in reality it probably needs to go away.<br>
> >><br>
> >> In a similar spirit, perhaps guardband_x/y should be bounded to be at least<br>
> >> 1.0?<br>
> ><br>
> > glViewport is clamped to ctx->Const.ViewportBounds.Min/Max. This<br>
> > assures that all guard bands are >= 1. However, if we get invalid<br>
> > coordinates from other sources, the guard band must prevent generating<br>
><br>
> That should be "if we get invalid viewport transform from other sources".<br>
><br>
> I think the assertion should stay and be strengthened to "x >= 1", because:<br>
> - we don't know how the discard guard band interacts with the clip guard band<br>
> - we should keep the assertion to prevent and detect possible<br>
> corruption caused by invalid viewport transformation<br>
><br>
> Does this sound good?<br>
><br>
> Marek<br>
></p>
<p dir="ltr">You might also consider using pipe_debug_message to report such invalid usage. That way you avoid the abort but still let the user know what's going on.</p>
<p dir="ltr"> -ilia</p>