i965: Fix fractional viewport coordinates handling on gen8+

Submitted by Danylo Piliaiev on June 4, 2018, 10:41 a.m.

Details

Message ID 1528108899-23777-1-git-send-email-danylo.piliaiev@gmail.com
State New
Headers show
Series "i965: Fix fractional viewport coordinates handling on gen8+" ( rev: 1 ) in Mesa

Not browsing as part of any series.

Commit Message

Danylo Piliaiev June 4, 2018, 10:41 a.m.
On gen8+ fractional translation of viewport moved it by a whole integer.
The behaviour in this case isn't defined anywhere but some apps like
Wine may depend on viewport's width and height being ceiled.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=106526
Signed-off-by: Danylo Piliaiev <danylo.piliaiev@gmail.com>
---
 src/mesa/drivers/dri/i965/genX_state_upload.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/mesa/drivers/dri/i965/genX_state_upload.c b/src/mesa/drivers/dri/i965/genX_state_upload.c
index 88fde9d..886290f 100644
--- a/src/mesa/drivers/dri/i965/genX_state_upload.c
+++ b/src/mesa/drivers/dri/i965/genX_state_upload.c
@@ -2586,12 +2586,11 @@  genX(upload_sf_clip_viewport)(struct brw_context *brw)
        * pipeline stall so we're better off just being a little more clever
        * with our viewport so we can emit it once at context creation time.
        */
-      const float viewport_Xmin = MAX2(ctx->ViewportArray[i].X, 0);
-      const float viewport_Ymin = MAX2(ctx->ViewportArray[i].Y, 0);
-      const float viewport_Xmax =
-         MIN2(ctx->ViewportArray[i].X + ctx->ViewportArray[i].Width, fb_width);
-      const float viewport_Ymax =
-         MIN2(ctx->ViewportArray[i].Y + ctx->ViewportArray[i].Height, fb_height);
+      const struct gl_viewport_attrib *vp = &ctx->ViewportArray[i];
+      const float viewport_Xmin = MAX2(vp->X, 0);
+      const float viewport_Ymin = MAX2(vp->Y, 0);
+      const float viewport_Xmax = MIN2(ceilf(vp->X + vp->Width), fb_width);
+      const float viewport_Ymax = MIN2(ceilf(vp->Y + vp->Height), fb_height);
 
       if (render_to_fbo) {
          sfv.XMinViewPort = viewport_Xmin;

Comments

Could anyone review this patch?

Here is a Wine dev reporting similar bug to Nvidia 
<https://devtalk.nvidia.com/default/topic/971005/linux/glviewportindexedf-wrongly-rounding-down-x-and-y-parameters/>.
Test in Wine source to enable a workaround for this issue 
<https://source.winehq.org/git/wine.git/blob/HEAD:/dlls/wined3d/utils.c#l3568>.
Similar patch for gallium/radeon 
<https://patchwork.freedesktop.org/patch/81255/>.

Hope this will help.

-Danil

On 04.06.18 13:41, Danylo Piliaiev wrote:
> On gen8+ fractional translation of viewport moved it by a whole integer.
> The behaviour in this case isn't defined anywhere but some apps like
> Wine may depend on viewport's width and height being ceiled.
>
> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=106526
> Signed-off-by: Danylo Piliaiev <danylo.piliaiev@gmail.com>
> ---
>   src/mesa/drivers/dri/i965/genX_state_upload.c | 11 +++++------
>   1 file changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/src/mesa/drivers/dri/i965/genX_state_upload.c b/src/mesa/drivers/dri/i965/genX_state_upload.c
> index 88fde9d..886290f 100644
> --- a/src/mesa/drivers/dri/i965/genX_state_upload.c
> +++ b/src/mesa/drivers/dri/i965/genX_state_upload.c
> @@ -2586,12 +2586,11 @@ genX(upload_sf_clip_viewport)(struct brw_context *brw)
>          * pipeline stall so we're better off just being a little more clever
>          * with our viewport so we can emit it once at context creation time.
>          */
> -      const float viewport_Xmin = MAX2(ctx->ViewportArray[i].X, 0);
> -      const float viewport_Ymin = MAX2(ctx->ViewportArray[i].Y, 0);
> -      const float viewport_Xmax =
> -         MIN2(ctx->ViewportArray[i].X + ctx->ViewportArray[i].Width, fb_width);
> -      const float viewport_Ymax =
> -         MIN2(ctx->ViewportArray[i].Y + ctx->ViewportArray[i].Height, fb_height);
> +      const struct gl_viewport_attrib *vp = &ctx->ViewportArray[i];
> +      const float viewport_Xmin = MAX2(vp->X, 0);
> +      const float viewport_Ymin = MAX2(vp->Y, 0);
> +      const float viewport_Xmax = MIN2(ceilf(vp->X + vp->Width), fb_width);
> +      const float viewport_Ymax = MIN2(ceilf(vp->Y + vp->Height), fb_height);
>   
>         if (render_to_fbo) {
>            sfv.XMinViewPort = viewport_Xmin;