Bug 28461

Summary: screen rotation results in corrupted output. [bisected]
Product: xorg Reporter: Till Matthiesen <entropy>
Component: Driver/intelAssignee: Chris Wilson <chris>
Status: RESOLVED FIXED QA Contact: Xorg Project Team <xorg-team>
Severity: major    
Priority: high CC: chris, eric
Version: git   
Hardware: x86-64 (AMD64)   
OS: Linux (All)   
Whiteboard:
i915 platform: i915 features:
Attachments:
Description Flags
xrandr output
none
intel_reg_dump (screen orientation set to normal)
none
intel_reg_dump (screen orientation set to left) *corrupted display output*
none
screen corruption at 1680x1050 (--orientation left)
none
screen corruption at 800x600 (--orientation left)
none
Xorg.0.log none

Description Till Matthiesen 2010-06-09 03:33:11 UTC
Hi all,

libdrm, xf86-video-intel from git results in a corrupted screen when rotation is set to left (no others checked). Behaviour was introduced in commit 

 commit d41684d54592cf93554a4d6534e7ea74562b1798
 Author: Eric Anholt <eric@anholt.net>
 Date:   Mon Jun 7 11:18:09 2010 -0700

     Allocate rotate shadow buffers using the usual framebuffer allocator.
     
     This means we can get tiling on them, which should significantly boost
     performance, and also allow for FBC.

Corruption looks "somehow" tiled. 
Screen shots don't show this behaviour.

---

System information:

Linux 2.6.34 x86_64 
intel i965
xorg-server-1.8.1
Comment 1 Chris Wilson 2010-06-11 00:37:38 UTC
Sounds like yet another tiling bug - with a twist that the kernel/userspace view of tiling is consistent, i.e. the readback is correct. The only other place that springs to mind for a potential cause of tiling corruption on the display is incorrect settings applied to the pipe.

Till, can you upload the output of xrandr so that we can see the size of the pixmaps involved and intel_reg_dump so that we can see what settings we've applied to the display?

Jesse, "in-memory fine, on-screen corrupted, ergo display regs are wrong" does that sound plausible or can you think of another cause for this bug?
Comment 2 Till Matthiesen 2010-06-11 02:52:16 UTC
Hi Chris,

thanks for looking into this.
I just upgraded to latest libdrm and ddx.
Comment 3 Till Matthiesen 2010-06-11 02:52:55 UTC
Created attachment 36211 [details]
xrandr output
Comment 4 Till Matthiesen 2010-06-11 02:54:09 UTC
Created attachment 36212 [details]
intel_reg_dump (screen orientation set to normal)
Comment 5 Till Matthiesen 2010-06-11 02:54:55 UTC
Created attachment 36213 [details]
intel_reg_dump (screen orientation set to left) *corrupted display output*
Comment 6 Till Matthiesen 2010-06-11 03:42:39 UTC
For testing purpose I changed connection from DVI1 to VGA1,
but then I could not use '--orientation left/normal' at all.

While this might be a different bug, this is the xrandr output:

>xrandr --orientation {left,normal}
X  Error  of  failed request:  BadValue (integer parameter out of
range for operation)
  Major opcode of failed request:  149 (RANDR)
  Minor opcode of failed request:  2 (RRSetScreenConfig)
  Value in failed request:  0x0
  Serial number of failed request:  14
  Current serial number in output stream:  14
Comment 7 Till Matthiesen 2010-06-11 06:46:42 UTC
First of(In reply to comment #6)
> For testing purpose I changed connection from DVI1 to VGA1,
> but then I could not use '--orientation left/normal' at all.
> 
> While this might be a different bug, this is the xrandr output:
> 
> >xrandr --orientation {left,normal}
> X  Error  of  failed request:  BadValue (integer parameter out of
> range for operation)
>   Major opcode of failed request:  149 (RANDR)
>   Minor opcode of failed request:  2 (RRSetScreenConfig)
>   Value in failed request:  0x0
>   Serial number of failed request:  14
>   Current serial number in output stream:  14

Seems like the xrandr error above is not reproducible straight forward and only happens when I change randr settings a few times. As if there where some remnants that cause you trouble eventually even in a previously well-known working configuration. But that is surely another thing...

Back to the corruption issue:
I only tested this with the native panel resolution of 1680x1050.
It's a DELL 2090WE, btw.

Checking all available modes for VGA1 and DVI1 I found out that all modes work fine apart from 1680x1050 and 800x600. This seems to be independent from connector type. I first thought it could be due to the aspect ratio but since 800x600 also causes trouble this seems unlikely to me.

Allow me a side question:
Why is it that the modes listed in xrandr are not listed in a descending way?
Is this a driver thing or given by the EDID?
So all auto configuration give me 1280x1024 resolution to start with, which is not the most sensible thing to do, imho.
Comment 8 Chris Wilson 2010-06-15 01:42:21 UTC
Till, hmm I don't think it's actually a simple tiling mode mismatch any more. Can you upload a screenshot?

The oddity I found in the registers exists for both...

working config:
            DSPACNTR: 0xd8000400 (enabled, pipe A)
          DSPASTRIDE: 0x00001c00 (7168 bytes)
             DSPAPOS: 0x00000000 (0, 0)
            DSPASIZE: 0x00000000 (1, 1)
            DSPABASE: 0x00000000
            DSPASURF: 0x08a7f000
         DSPATILEOFF: 0x00000000
           PIPEACONF: 0xc0000000 (enabled, active)
            PIPEASRC: 0x068f0419 (1680, 1050)
...
FENCE START 9: 0x08a7f0dd ( enabled, X tile walk, 7040 pitch, 0x08a7f000 start)
FENCE END 9: 0x0927e000 (                                   0x0927e000 end)

corrupted config:
            DSPACNTR: 0xd8000400 (enabled, pipe A)
          DSPASTRIDE: 0x00001c00 (7168 bytes)
             DSPAPOS: 0x00000000 (0, 0)
            DSPASIZE: 0x00000000 (1, 1)
            DSPABASE: 0x00000000
            DSPASURF: 0x077d3000
         DSPATILEOFF: 0x00000000
           PIPEACONF: 0xc0000000 (enabled, active)
            PIPEASRC: 0x068f0419 (1680, 1050)
...
FENCE START 5: 0x077d30dd ( enabled, X tile walk, 7040 pitch, 0x077d3000 start)
FENCE END 5: 0x07fd2000 (                                   0x07fd2000 end)

So the tiling doesn't match the scanout for either configuration! But otherwise the registers match, so it's probably userspace being confused. The only time when the fence is used would be during readback [ignoring FBC] so perhaps during modeswitch we decouple the old fb, readback the contents and blit into the new fb. When grabbing the screenshot we readback the contents using the same stride so everything appears fine... My conclusion is that the ddx feeds a different stride into the fb config than we use for the pixmap.
Comment 9 Chris Wilson 2010-06-15 01:55:22 UTC
Till can you also upload Xorg.log? The driver should be printing out the framebuffer sizes and pitches - that would seem relevant here.
Comment 10 Till Matthiesen 2010-06-15 04:12:30 UTC
Created attachment 36281 [details]
screen corruption at 1680x1050 (--orientation left)
Comment 11 Till Matthiesen 2010-06-15 04:13:00 UTC
Created attachment 36282 [details]
screen corruption at 800x600 (--orientation left)
Comment 12 Till Matthiesen 2010-06-15 04:13:32 UTC
Created attachment 36283 [details]
Xorg.0.log
Comment 13 Till Matthiesen 2010-06-15 04:19:38 UTC
Hi Chris,

thanks for looking into this!

Can you tell me something about the mode ordering given in `xrandr`?
A `xrandr --output DVI1 --auto` always defaults to the resolution of 1280x1024. While this is not really a big issue, I'm puzzled why the modes are not sorted in a descending way, so that it defaults to the native panel resolution.
Comment 14 Chris Wilson 2010-06-15 04:44:39 UTC
I am not totally conversantin intricacies of xrandr, I'll take a lot though. One snippet from Xorg.log:

[ 91895.579] (II) intel(0): Using user preference for initial modes
[ 91895.579] (II) intel(0): Output DVI1 using initial mode 1280x1024

suggests that there might be something in your /etc/x11/xorg.conf worth checking.

The staircase effect in the screenshots is a classic example of an incorrect stride, thanks! However, the driver really does believe that it is using a pitch of 7168 throughout, so how we requested a tiling with only a 7040 pitch is an interesting mystery...
Comment 15 Chris Wilson 2010-06-15 05:09:00 UTC
* finds bug in intel_reg_dump not writing out the correct value of the fence pitch.

Back to square one. So it appears that the fence register is consistent with the tiling and stride used by the pixmap. Maybe it is not the classic staircase I so brazenly pronounced. Time to rethink.
Comment 16 Till Matthiesen 2010-06-15 05:19:48 UTC
If there's anything else you want me to test, just let me know.

Btw, you were completely right.
There were some predefined modes in my xorg.conf.
Thanks, my bad. Fixed that now. 

This is not related to the tiling issue - it's still there.
(if that question may arise)
Comment 17 Chris Wilson 2010-06-15 05:32:13 UTC
I gave in and tried rotating my display. Didn't see the tiling corruption at 1920x1080, but I did see some rendering errors that for the time being I am choosing to ignore. ;-)
Comment 18 Chris Wilson 2010-06-15 05:40:24 UTC
Well that was fun. Bingo at 800x600.
Comment 19 Chris Wilson 2010-06-15 12:31:40 UTC
It was just a misuse of stride in the ddx. Trust thy instincts!

commit a25573d5c47ebea34c076075e1993233d7db2b4f
Author: Chris Wilson <chris@chris-wilson.co.uk>
Date:   Tue Jun 15 20:26:19 2010 +0100

    drmmode: Use the tiled stride for the rotated pixmap.
    
    After d41684d5459 we now allocate all framebuffers as tiled bo, and so
    we must be careful to use the appropriate stride as returned from the
    allocation, instead of assuming that it is just an aligned width.
    
    Fixes:
    
      Bug 28461 - screen rotation results in corrupted output.
      https://bugs.freedesktop.org/show_bug.cgi?id=28461
    
    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
    Reported-by: Till Matthiesen <entropy@everymail.net>
Comment 20 Till Matthiesen 2010-06-16 04:48:19 UTC
(In reply to comment #17)
> I gave in and tried rotating my display. Didn't see the tiling corruption at
> 1920x1080, but I did see some rendering errors that for the time being I am
> choosing to ignore. ;-)

Hi Chris,

thanks for fixing this bug.

Concerning the misrenderings, were you facing this?
https://bugs.freedesktop.org/show_bug.cgi?id=28572

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.