Oh Radeon..to patch or not to patch


As it has been well documented if you are using a radeon video card while running Linux on your PowerPC then you are in for a few hurdles. Things now are a lot more complicated with the changes from Wheezy to Jessie. In the past you really did not need KMS or accelerated hardware graphics to have a good, working, stable machine. Now with Jessie you at the least need KMS enabled if you want to have a usable desktop. If you are running a G4 following the boot parameters I laid out previously should get you going. However if you running a G3, Dan has a great walk through over here. Now that you have KMS enabled the next question is do you want accelerated graphics. It may not be important to most but there are some open source games in repositories that you can still play as long as you have 3D graphics enabled. You could set your default depth to 16 in xorg.conf, or you can install an already patched mesa package, or you could be more adventurous and try to patch the source and recompile yourself. I chose to patch and recompile the source. I wanted to see if I could do it and also I did not want to wait on others to produce a new patch version every time there is a new version on mesa. There are no plans to produce a final fix for this on PowerPC anytime soon. The current patch available is not suitable for final inclusion into upstream but it does get 3D working. So here is what you do.

First there are two resources you should read closely to understand patching and compiling deb build in Debian. The first is a great walk though on building packages which can be found in the Debian Forums. The second is a tutorial on apply patches in Linux, which can be found here. The next thing to obtain the patch files. These files can be found here. Jessie uses mesa version 10.3.2, which requires an additional patch to prevent the build from crashing during compile time. Now you will need to install the following packages that will allow you to compile into .deb packages:

sudo apt-get install build-essential fakeroot devscripts

The next step is to install the dependencies needed to build mesa and the source code of mesa itself. This is done by running the following commands (note from the install of the build dependencies till the time the .deb file are to be installed all the commands need to be done as regular user and not root):

sudo apt-get build-dep mesa
apt-get source mesa

Now to proceed to applying the patches. The patch file 08_packed_RGB_formats.diff patches the following, dri_drawable.c and dri2.c. You will need to be in the directory where the files to be patch are located. See below:

cd mesa-10.4.2/src/gallium/state_trackers/dri/
patch -p6 --dry-run < ~/Public/08_packed_RGB_formats.diff
checking file dri_drawable.c
checking file dri2.c
Hunk #1 succeeded at 163 (offset 34 lines).
Hunk #2 succeeded at 289 (offset -114 lines).
Hunk #3 succeeded at 699 (offset 150 lines).
Hunk #4 succeeded at 820 (offset 150 lines).


patch -p6 < ~/Public/08_packed_RGB_formats.diff
patching file dri_drawable.c
patching file dri2.c
Hunk #1 succeeded at 163 (offset 34 lines).
Hunk #2 succeeded at 289 (offset -114 lines).
Hunk #3 succeeded at 699 (offset 150 lines).
Hunk #4 succeeded at 820 (offset 150 lines).

The first time I ran the patch command I used the --dry-run option. This verifies the patch is good before actually applying it. This is a good habit to get into since messing up patch means deleting the source code and starting over. If you do not get the output shown above and instead are asked for the location of the file needing then patch, then this usually means you have the incorrect -p option. Please read the tutorial linked about for more detail on how to properly use it. The next patch file 09_r300g_big_endian_fixes.diff patches the following, r300_blit.c, r300_texture,c, r300_texture.h, r300_transfer.c, r300_context.h, r300_state.c, r300_state_dervied.c. This is how I applied this patch:

patch -p5 --dry-run < ~/Public/09_r300g_big_endian_fixes.diff
checking file r300_blit.c
checking file r300_context.h
checking file r300_state.c
Hunk #4 succeeded at 1659 (offset -7 lines).
Hunk #5 succeeded at 1675 (offset -7 lines).
checking file r300_state_derived.c
checking file r300_texture.c
checking file r300_texture.h
checking file r300_transfer.c


patch -p5 < ~/Public/09_r300g_big_endian_fixes.diff
patching file r300_blit.c
patching file r300_context.h
patching file r300_state.c
Hunk #4 succeeded at 1659 (offset -7 lines).
Hunk #5 succeeded at 1675 (offset -7 lines).
patching file r300_state_derived.c
patching file r300_texture.c
patching file r300_texture.h
patching file r300_transfer.c

If you are running Jessie then you are using mesa 10.3.2 with requires an additional patch to keep the compiler from crashing during build. Below are the commands:

cd mesa-10.3.2/src/mesa/main
patch -p4 --dry-run < ~/Public/dbc2d81d2ba12354876eb67c79e8a71e57e97f3c..cfeb394224f2daeb2139cf4ec489a4dd8297a44d.patch
patch -p4 < ~/Public/dbc2d81d2ba12354876eb67c79e8a71e57e97f3c..cfeb394224f2daeb2139cf4ec489a4dd8297a44d.patch

Now that the patches are applied the next was to change the version number of mesa to preserve the upgrade path. Since the current version of mesa for Stretch is 10.4.2-2, this how I changed it:

debchange -b -v 10.4.2-2a~patch1

The takes you to the changelog in a nano session. There edit the log if you want then save and exit. Now you are ready to compile your .deb packages! Just run the following:

dpkg-buildpackage -rfakeroot -us -uc

This will take a few hours to complete. So go have a drink and watch a movie while the packages are building. Then when it is completed you will see in the directory above all the .deb files. The build make the install, dev, and debug packages. I normal move them to a separate directory then segregate them into separate folders. So I then just install the packages like this:

sudo dpkg -i *.deb

Finally reboot and test! You should run the command LIBGL_DEBUG=verbose glxinfo |grep render and see this output "OpenGL renderer string: Gallium 0.4 on ATI RV350". If you do then congrats you just successfully installed a patch!

UPDATE I: It looks like starting with Mesa 10.5.5 the patches above are starting to fail. I am seeing this on Stretch. This should be expected since these patches are just really 'workarounds' and were never going to implemented upstream. You could still set the DefaultDisplay to 16 in xorg.conf to get 3D if you run into this.

14 comments:

  1. I read a couple of weeks ago, I can't remember where but it was some mailing list, that a fix for the Mesa bug was being worked on and would come in a future version, so I never bothered filing a bug report.

    ReplyDelete
  2. I have heard rumors as well, not too sure how much truth there is behind them. Open a bug I will comment on it.

    ReplyDelete
  3. Good post, Rican.

    Have you tried Jessie + MATE yet? Or MATE on any Debian? I did yesterday and love it. It's not an LXDE replacer for me, but I will certainly keep it installed. I was a big GNOME user until 3 came out, and that was when I switched to LXDE.

    This comment is totally unrelated to the post here, but I just wanted to add my fondness for MATE.

    ReplyDelete
    Replies
    1. I ran Jessie + MATE and really enjoyed it. I think it is a great DE. I love the text editor Pluma.

      Delete
  4. Thanks for the help Rican! Between this and the link you shared on PPC Luddite, I am well on my way to patching and compiling kernels.

    I am also really enjoying MATE. I have yet to try Cinnamon on anything.

    ReplyDelete
    Replies
    1. Cinnamon is fork of GNOME 3 so I wonder if it may be too much for PowerPC.

      Delete
    2. Rican is correct. Stay away from Cinnamon. I tried it just to say I did, and it was slow as molasses. I would even call it slower than GNOME 3. It's almost in Unity territory, which is scary.

      MATE is really light in my experiences, and after using it for a while it trumps LXDE in a few ways, at least in raw performance. I might just be off LXDE.

      The moral of the story, Mark, is stay away from Cinomon unless you have a dual/quad G5. Even then... why lose out on all that performance you could have with something lighter. MATE might melt your eyes on a quad.

      Delete
  5. I actually listened to an interview of one of the MATE devs. He was remarking that the reason it is so lightweight was due to the ripping out old code when they were forking GNOME 2. It looks like they did a great clean up job!

    ReplyDelete
    Replies
    1. Makes sense, because it's certainly faster than I remember GNOME 2 being.

      Delete
  6. radeon 9000 Pro, G4 silver

    1. for this step, do I need to download the mesa-10.4.2 source and place in /home/user/ then run patch? because i have 10.3.2
    cd mesa-10.4.2/src/gallium/state_trackers/dri/
    patch -p6 --dry-run < ~/Public/08_packed_RGB_formats.diff

    2. for this step do i go into, 10.4.2 folder or 10.3.2 folder to run
    debchange -b -v 10.4.2-2a~patch1

    3. for this step do i go into, 10.4.2 folder or 10.3.2 folder to run
    dpkg-buildpackage -rfakeroot -us -uc

    Thanks

    ReplyDelete
    Replies
    1. If you are running Jessie then when you get the source it will be 10.3.2. The directory paths are the same.

      Delete
  7. I seem to be unable to extract those bin files containing the patches on Lubuntu 12.04 ?

    https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=746272

    What am I doing wrong ?

    ReplyDelete
  8. Things are improving for powerpc users...since mesa 12.0.0 the r300 bug was definitly fixed :
    http://www.mesa3d.org/relnotes/12.0.0.html
    So do we still need patching the mesa for 3D accel ?

    ReplyDelete
  9. how can i get mesa 12 for debian wheezy or do i need to patch this thing (powerpc7,3 , radeon xt9650, r300 bug, debian wheezy) as i don't want for several reasons upgrade to debian jessie for now?

    ReplyDelete