Bug 48629

Summary: [bisected i965]Oglc shad-compiler(advanced.TestLessThani) regressed
Product: Mesa Reporter: lu hua <huax.lu>
Component: Drivers/DRI/i965Assignee: Eric Anholt <eric>
Status: VERIFIED FIXED QA Contact:
Severity: major    
Priority: high CC: eric, idr, kenneth, xunx.fang
Version: git   
Hardware: All   
OS: Linux (All)   
Whiteboard:
i915 platform: i915 features:

Description lu hua 2012-04-12 20:13:11 UTC
System Environment:
--------------------------
Arch:             X86_64
Platform:         Ironlake
Libdrm:        (master)2.4.33-10-gf00efc7ab442f106d3ac7699e80f1f7aee8451f4
Mesa:        (master)249fc7056104113633215106ac085b505d8dc161
Libva_intel_driver:(vaapi-ext)82fa52510a37ab645daaa3bb7091ff5096a20d0b
Kernel_unstable:(drm-intel-next-queued)0156f0046bb709a8d7c7d48e3e055b3ecf6699c9

Bug detailed description:
-----------------------------
It fails on Ironlake,Sandybridge and Ivybridge with mesa master branch.It doesn't happen on mesa 8.0 branch.
Following oglc cases also fail with the same commit:
shad-compiler(advanced.TestLessThanEquali)
shad-compiler(advanced.TestGreaterThan)
shad-compiler(advanced.TestGreaterThani)
shad-compiler(advanced.TestGreaterThanEqual)
shad-compiler(advanced.TestGreaterThanEquali)
shad-compiler(advanced.TestEqualb)
shad-compiler(advanced.TestNotEqual)
shad-compiler(advanced.TestNotEquali)
shad-compiler(advanced.TestNotEqualb)

Bisect shows:80ecb8f15b9ad7d6edcc85bd19f1867c368b09b6 is the first bad commit.
commit 80ecb8f15b9ad7d6edcc85bd19f1867c368b09b6
Author: Eric Anholt <eric@anholt.net>
Date:   Tue Mar 13 14:19:31 2012 -0700

    i965/fs: Avoid generating extra AND instructions on bool logic ops.
    
    By making a bool fs_reg only have a defined low bit (matching CMP
    output), instead of being a full 0 or 1 value, we reduce the ANDs
    generated in logic chains like:
    
       if (v_texcoord.x < 0.0 || v_texcoord.x > texwidth ||
           v_texcoord.y < 0.0 || v_texcoord.y > 1.0)
          discard;
    
    My concern originally when writing this code was that we would end up
    generating unnecessary ANDs on bool uniforms, so I put the ANDs right
    at the point of doing the CMPs that otherwise set only the low bit.
    However, in order to use a bool, we're generating some instruction
    anyway (e.g. moving it so as to produce a condition code update), and
    those instructions can often be turned into an AND at that point.  It
    turns out in the shaders I have on hand, none of them regress in
    instruction count:
    
    Total instructions: 262649 -> 262545
    39/2148 programs affected (1.8%)
    14253 -> 14149 instructions in affected programs (0.7% reduction)

Reproduce steps:
----------------------------
1. start X
2. ./oglconform -z -suite all -v 2 -D 115 -test shad-compiler advanced.TestLessThani
Comment 1 lu hua 2012-04-13 01:38:07 UTC
Following cases fail on Ivybridge with mesa master branch, and fail with the same commit.
Oglc cases:
glsl-type-cast(basic.explicit.intToBool)
glsl-type-cast(basic.explicit.uIntToBool)
glsl-type-cast(basic.explicit.floatToBool)
shad-compiler(advanced.TestLessThan)
shad-compiler(advanced.TestLessThanEqual)

Bisect shows 80ecb8f15b9ad7d6edcc85bd19f1867c368b09b6 is the first bad commit.
Comment 2 lu hua 2012-04-15 22:46:06 UTC
Following cases fail on Ivybridge and Sandybridge with mesa master branch, and fail with the same commit.
Oglc cases:
glsl-type-cast(basic.explicit.intToBool)
glsl-type-cast(basic.explicit.uIntToBool)
glsl-type-cast(basic.explicit.floatToBool)
shad-compiler(advanced.TestLessThan)
shad-compiler(advanced.TestLessThanEqual)

Bisect shows 80ecb8f15b9ad7d6edcc85bd19f1867c368b09b6 is the first bad commit.
Comment 3 Eric Anholt 2012-05-04 14:53:14 UTC
commit dc42910e98dc00760255cc4579da458de09175b9
Author: Eric Anholt <eric@anholt.net>
Date:   Mon Apr 23 16:48:09 2012 -0700

    i965/fs: Fix regression in comparison handling from ANDs change.
    
    I had fixed up the logic ops for delayed ANDing, but not equality
    comparisons on bools.  Fixes new piglit fs-bool-less-compare-true.
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=48629
Comment 4 lu hua 2012-05-08 00:40:03 UTC
Following cases still fail on IVB and SNB.
shad-compiler(advanced.TestLessThanEquali)
shad-compiler(advanced.TestGreaterThan)
shad-compiler(advanced.TestGreaterThani)
shad-compiler(advanced.TestGreaterThanEqual)
shad-compiler(advanced.TestGreaterThanEquali)
shad-compiler(advanced.TestEqualb)
shad-compiler(advanced.TestNotEqual)
shad-compiler(advanced.TestNotEquali)
shad-compiler(advanced.TestNotEqualb)

Following cases pass on IVB and SNB.
glsl-type-cast(basic.explicit.intToBool)
glsl-type-cast(basic.explicit.uIntToBool)
glsl-type-cast(basic.explicit.floatToBool)

This issue fixed on Ironlake with commit dc42910e98dc0.
Comment 5 Ian Romanick 2012-07-20 16:14:22 UTC
I suspect this may have been fixed by the commit below.  Lu, can you verify?

commit 5b83bdc154ec8d607a4c4d96171d0128e51abaec
Author: Kenneth Graunke <kenneth@whitecape.org>
Date:   Sat Jun 16 02:08:13 2012 -0700

    i965: Fix brw_swap_cmod() for LE/GE comparisons.
    
    The idea here is to rewrite comparisons like 2 >= x with x <= 2; we want
    to simply exchange arguments, not negate the condition.  If equality was
    part of the original comparison, it should remain part of the swapped
    version.
    
    This is the true cause of bug #50298.  It didn't manifest itself on
    Sandybridge because we embed the conditional modifier in the IF
    instruction rather than emitting a CMP.  All other platforms use CMP.
    
    It also didn't manifest itself on the master branch because commit
    be5f27a84d ("glsl: Refine the loop instruction counting.") papered over
    the problem.
    
    NOTE: This is a candidate for stable release branches.
    
    Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=50298
    Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
    Reviewed-by: Eric Anholt <eric@anholt.net>
Comment 6 Kenneth Graunke 2012-07-20 18:32:15 UTC
Still seems broken to me.
Comment 7 lu hua 2012-07-23 06:51:28 UTC
Issue still exist.

Following cases still fail on IVB and SNB.
shad-compiler(advanced.TestLessThanEquali)
shad-compiler(advanced.TestGreaterThan)
shad-compiler(advanced.TestGreaterThani)
shad-compiler(advanced.TestGreaterThanEqual)
shad-compiler(advanced.TestGreaterThanEquali)
shad-compiler(advanced.TestEqualb)
shad-compiler(advanced.TestNotEqual)
shad-compiler(advanced.TestNotEquali)
shad-compiler(advanced.TestNotEqualb)
Comment 8 Kenneth Graunke 2012-09-16 04:27:09 UTC
I can't reproduce this on Ivybridge...it seems to be working there.

On Sandybridge, this is fixed by the following patch on the mailing list:
http://lists.freedesktop.org/archives/mesa-dev/2012-September/027519.html
Comment 9 lu hua 2012-10-12 03:02:10 UTC
(In reply to comment #7)
> Issue still exist.
> 
> Following cases still fail on IVB and SNB.
> shad-compiler(advanced.TestLessThanEquali)
> shad-compiler(advanced.TestGreaterThan)
> shad-compiler(advanced.TestGreaterThani)
> shad-compiler(advanced.TestGreaterThanEqual)
> shad-compiler(advanced.TestGreaterThanEquali)
> shad-compiler(advanced.TestEqualb)
> shad-compiler(advanced.TestNotEqual)
> shad-compiler(advanced.TestNotEquali)
> shad-compiler(advanced.TestNotEqualb)

Fixed on ivybridge. Still fails on sandybridge.
Comment 10 Kenneth Graunke 2012-11-12 21:26:40 UTC
Eric has NAK'd my fix and is writing a better one.  Reassigning.
Comment 11 Eric Anholt 2012-11-21 18:48:02 UTC
commit 0482998ccc205a9d29953c7a8b33f41ae3584935
Author: Eric Anholt <eric@anholt.net>
Date:   Mon Nov 12 13:13:55 2012 -0800

    i965/fs: Fix the gen6-specific if handling for 80ecb8f15b9ad7d6edc
Comment 12 lu hua 2012-11-26 02:40:30 UTC
(In reply to comment #11)
> commit 0482998ccc205a9d29953c7a8b33f41ae3584935
> Author: Eric Anholt <eric@anholt.net>
> Date:   Mon Nov 12 13:13:55 2012 -0800
> 
>     i965/fs: Fix the gen6-specific if handling for 80ecb8f15b9ad7d6edc

Fixed on master branch. It still fails on sandybridge with 9.0 branch.
Comment 13 Gordon Jin 2012-12-06 03:24:57 UTC
Eric/Ian, do we have plan to put the fix to 9.0 branch? If so we should keep this bug open, otherwise we can close it.
Comment 14 Andreas Boll 2013-02-21 15:28:15 UTC
Cherry-picked to the 9.0 branch: 457eab5a9bf563b54d46fa57cba513837224b120

It will be available in Mesa 9.0.3.
Comment 15 lu hua 2013-02-26 03:12:26 UTC
Verified.Fixed on the latest 9.1 branch(commit:5b19631f7cffc0fb48).

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.