Bug 27222 - Gamma not working in 3D on xserver >=
Summary: Gamma not working in 3D on xserver >=
Alias: None
Product: xorg
Classification: Unclassified
Component: Server/General (show other bugs)
Version: 7.5 (2009.10)
Hardware: All All
: high normal
Assignee: Xorg Project Team
QA Contact: Xorg Project Team
: 44332 44848 89452 (view as bug list)
Depends on:
Blocks: 64475
  Show dependency treegraph
Reported: 2010-03-21 07:38 UTC by Ondrej Zary
Modified: 2018-02-04 18:34 UTC (History)
6 users (show)

See Also:
i915 platform:
i915 features:

Urban Terror with bad gamma (51.08 KB, image/jpeg)
2010-03-21 07:38 UTC, Ondrej Zary
no flags Details
X log (35.96 KB, text/plain)
2010-03-21 07:39 UTC, Ondrej Zary
no flags Details
dmesg (15.07 KB, text/plain)
2010-03-21 07:39 UTC, Ondrej Zary
no flags Details
WIP: Hook up colormaps to RandR 1.2 gamma code (11.19 KB, patch)
2016-01-06 09:47 UTC, Michel Dänzer
no flags Details | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Ondrej Zary 2010-03-21 07:38:22 UTC
Created attachment 34287 [details]
Urban Terror with bad gamma

With xf86-video-radeon 6.12, gamma correction does not work anymore in 3D (tested with Urban Terror) - everything is dark and in-game gamma adjustment does not change anything.
Comment 1 Ondrej Zary 2010-03-21 07:39:25 UTC
Created attachment 34288 [details]
X log
Comment 2 Ondrej Zary 2010-03-21 07:39:52 UTC
Created attachment 34289 [details]
Comment 3 Alex Deucher 2010-03-21 08:20:59 UTC
Was there a previous version of the driver where gamma worked and if so which version?
Comment 4 Ondrej Zary 2010-03-21 14:49:53 UTC
Sorry, the 6.12 in the first post was not correct.
Gamma does not work since at least 6.12.4 (still does not work in 6.12.192 - as seen in X log).
It worked fine in 6.12.2 (that was with xserver 1.6.3 - slackware 13.0).
Comment 5 Ondrej Zary 2010-04-03 05:32:38 UTC
xgamma from commandline works. So when I do "xgamma -gamma 1.8" and start the game, it looks good. Only the in-game gamma setting does nothing.
Comment 6 Michel Dänzer 2010-04-03 05:53:41 UTC
I think this is actually an SDL issue then.
Comment 7 Ondrej Zary 2010-04-03 06:21:51 UTC
Yes, it uses SDL, namely this function:

int X11_SetGammaRamp(_THIS, Uint16 *ramp)
        int i, ncolors;
        XColor xcmap[256];

        /* See if actually setting the gamma is supported */
        if ( SDL_Visual->class != DirectColor ) {
            SDL_SetError("Gamma correction not supported on this visual");

        /* Calculate the appropriate palette for the given gamma ramp */
        ncolors = SDL_Visual->map_entries;
        for ( i=0; i<ncolors; ++i ) {
                Uint8 c = (256 * i / ncolors);
                xcmap[i].pixel = SDL_MapRGB(this->screen->format, c, c, c);
                xcmap[i].red   = ramp[0*256+c];
                xcmap[i].green = ramp[1*256+c];
                xcmap[i].blue  = ramp[2*256+c];
                xcmap[i].flags = (DoRed|DoGreen|DoBlue);
        XStoreColors(GFX_Display, SDL_XColorMap, xcmap, ncolors);
        XSync(GFX_Display, False);

ncolors is 256, xcmap is:
xcmap[0] .pixel=0, .red=0, .green=0, .blue=0
xcmap[1] .pixel=65793, .red=9509, .green=9509, .blue=9509
xcmap[2] .pixel=131586, .red=12079, .green=12079, .blue=12079
xcmap[3] .pixel=197379, .red=13878, .green=13878, .blue=13878
xcmap[4] .pixel=263172, .red=15163, .green=15163, .blue=15163
xcmap[5] .pixel=328965, .red=16448, .green=16448, .blue=16448
xcmap[6] .pixel=394758, .red=17733, .green=17733, .blue=17733
xcmap[7] .pixel=460551, .red=18504, .green=18504, .blue=18504
xcmap[8] .pixel=526344, .red=19532, .green=19532, .blue=19532
xcmap[9] .pixel=592137, .red=20303, .green=20303, .blue=20303
xcmap[10] .pixel=657930, .red=21074, .green=21074, .blue=21074
xcmap[11] .pixel=723723, .red=21845, .green=21845, .blue=21845
xcmap[12] .pixel=789516, .red=22359, .green=22359, .blue=22359
xcmap[13] .pixel=855309, .red=23130, .green=23130, .blue=23130
xcmap[14] .pixel=921102, .red=23644, .green=23644, .blue=23644
xcmap[15] .pixel=986895, .red=24415, .green=24415, .blue=24415
xcmap[16] .pixel=1052688, .red=24929, .green=24929, .blue=24929
xcmap[17] .pixel=1118481, .red=25443, .green=25443, .blue=25443
xcmap[18] .pixel=1184274, .red=25957, .green=25957, .blue=25957
xcmap[19] .pixel=1250067, .red=26471, .green=26471, .blue=26471
xcmap[20] .pixel=1315860, .red=26985, .green=26985, .blue=26985
xcmap[21] .pixel=1381653, .red=27242, .green=27242, .blue=27242
xcmap[22] .pixel=1447446, .red=27756, .green=27756, .blue=27756
xcmap[23] .pixel=1513239, .red=28270, .green=28270, .blue=28270
xcmap[24] .pixel=1579032, .red=28527, .green=28527, .blue=28527
xcmap[25] .pixel=1644825, .red=29041, .green=29041, .blue=29041
xcmap[26] .pixel=1710618, .red=29555, .green=29555, .blue=29555
xcmap[27] .pixel=1776411, .red=29812, .green=29812, .blue=29812
xcmap[28] .pixel=1842204, .red=30326, .green=30326, .blue=30326
xcmap[29] .pixel=1907997, .red=30583, .green=30583, .blue=30583
xcmap[30] .pixel=1973790, .red=30840, .green=30840, .blue=30840
xcmap[31] .pixel=2039583, .red=31354, .green=31354, .blue=31354
xcmap[32] .pixel=2105376, .red=31611, .green=31611, .blue=31611
xcmap[33] .pixel=2171169, .red=32125, .green=32125, .blue=32125
xcmap[34] .pixel=2236962, .red=32382, .green=32382, .blue=32382
xcmap[35] .pixel=2302755, .red=32639, .green=32639, .blue=32639
xcmap[36] .pixel=2368548, .red=32896, .green=32896, .blue=32896
xcmap[37] .pixel=2434341, .red=33410, .green=33410, .blue=33410
xcmap[38] .pixel=2500134, .red=33667, .green=33667, .blue=33667
xcmap[39] .pixel=2565927, .red=33924, .green=33924, .blue=33924
xcmap[40] .pixel=2631720, .red=34181, .green=34181, .blue=34181
xcmap[41] .pixel=2697513, .red=34438, .green=34438, .blue=34438
xcmap[42] .pixel=2763306, .red=34952, .green=34952, .blue=34952
xcmap[43] .pixel=2829099, .red=35209, .green=35209, .blue=35209
xcmap[44] .pixel=2894892, .red=35466, .green=35466, .blue=35466
xcmap[45] .pixel=2960685, .red=35723, .green=35723, .blue=35723
xcmap[46] .pixel=3026478, .red=35980, .green=35980, .blue=35980
xcmap[47] .pixel=3092271, .red=36237, .green=36237, .blue=36237
xcmap[48] .pixel=3158064, .red=36494, .green=36494, .blue=36494
xcmap[49] .pixel=3223857, .red=36751, .green=36751, .blue=36751
xcmap[50] .pixel=3289650, .red=37008, .green=37008, .blue=37008
xcmap[51] .pixel=3355443, .red=37265, .green=37265, .blue=37265
xcmap[52] .pixel=3421236, .red=37522, .green=37522, .blue=37522
xcmap[53] .pixel=3487029, .red=37779, .green=37779, .blue=37779
xcmap[54] .pixel=3552822, .red=38036, .green=38036, .blue=38036
xcmap[55] .pixel=3618615, .red=38293, .green=38293, .blue=38293
xcmap[56] .pixel=3684408, .red=38550, .green=38550, .blue=38550
xcmap[57] .pixel=3750201, .red=38807, .green=38807, .blue=38807
xcmap[58] .pixel=3815994, .red=39064, .green=39064, .blue=39064
xcmap[59] .pixel=3881787, .red=39321, .green=39321, .blue=39321
xcmap[60] .pixel=3947580, .red=39578, .green=39578, .blue=39578
xcmap[61] .pixel=4013373, .red=39578, .green=39578, .blue=39578
xcmap[62] .pixel=4079166, .red=39835, .green=39835, .blue=39835
xcmap[63] .pixel=4144959, .red=40092, .green=40092, .blue=40092
xcmap[64] .pixel=4210752, .red=40349, .green=40349, .blue=40349
xcmap[65] .pixel=4276545, .red=40606, .green=40606, .blue=40606
xcmap[66] .pixel=4342338, .red=40863, .green=40863, .blue=40863
xcmap[67] .pixel=4408131, .red=41120, .green=41120, .blue=41120
xcmap[68] .pixel=4473924, .red=41120, .green=41120, .blue=41120
xcmap[69] .pixel=4539717, .red=41377, .green=41377, .blue=41377
xcmap[70] .pixel=4605510, .red=41634, .green=41634, .blue=41634
xcmap[71] .pixel=4671303, .red=41891, .green=41891, .blue=41891
xcmap[72] .pixel=4737096, .red=42148, .green=42148, .blue=42148
xcmap[73] .pixel=4802889, .red=42405, .green=42405, .blue=42405
xcmap[74] .pixel=4868682, .red=42405, .green=42405, .blue=42405
xcmap[75] .pixel=4934475, .red=42662, .green=42662, .blue=42662
xcmap[76] .pixel=5000268, .red=42919, .green=42919, .blue=42919
xcmap[77] .pixel=5066061, .red=43176, .green=43176, .blue=43176
xcmap[78] .pixel=5131854, .red=43176, .green=43176, .blue=43176
xcmap[79] .pixel=5197647, .red=43433, .green=43433, .blue=43433
xcmap[80] .pixel=5263440, .red=43690, .green=43690, .blue=43690
xcmap[81] .pixel=5329233, .red=43947, .green=43947, .blue=43947
xcmap[82] .pixel=5395026, .red=43947, .green=43947, .blue=43947
xcmap[83] .pixel=5460819, .red=44204, .green=44204, .blue=44204
xcmap[84] .pixel=5526612, .red=44461, .green=44461, .blue=44461
xcmap[85] .pixel=5592405, .red=44718, .green=44718, .blue=44718
xcmap[86] .pixel=5658198, .red=44718, .green=44718, .blue=44718
xcmap[87] .pixel=5723991, .red=44975, .green=44975, .blue=44975
xcmap[88] .pixel=5789784, .red=45232, .green=45232, .blue=45232
xcmap[89] .pixel=5855577, .red=45232, .green=45232, .blue=45232
xcmap[90] .pixel=5921370, .red=45489, .green=45489, .blue=45489
xcmap[91] .pixel=5987163, .red=45746, .green=45746, .blue=45746
xcmap[92] .pixel=6052956, .red=45746, .green=45746, .blue=45746
xcmap[93] .pixel=6118749, .red=46003, .green=46003, .blue=46003
xcmap[94] .pixel=6184542, .red=46260, .green=46260, .blue=46260
... not sure why the output got truncated

Both XStoreColors() and XSync() calls return 1.
Comment 8 Ondrej Zary 2010-04-03 08:05:18 UTC
Now tried compiling newer drivers with X server 1.6.3. Gamma works fine in Urban Terror with xf86-video-ati-6.12.4 and also with xf86-video-ati-6.12.6.

So this is X server bug, not ATI driver bug.
Comment 9 Ondrej Zary 2010-04-03 12:06:58 UTC
It works fine up to xorg-server-1.6.5 and it's broken in xorg-server- I tried to bisect it but the compilation fails.
Comment 10 Michel Dänzer 2012-01-03 09:28:10 UTC
*** Bug 44332 has been marked as a duplicate of this bug. ***
Comment 11 Michel Dänzer 2012-01-03 09:47:52 UTC
See http://lists.x.org/archives/xorg-devel/2011-February/019152.html for the underlying issues.
Comment 12 Michel Dänzer 2012-01-17 01:06:45 UTC
*** Bug 44848 has been marked as a duplicate of this bug. ***
Comment 13 commiethebeastie 2014-03-01 09:21:48 UTC
In 2014, this bug is present in most games :(

Just tested with Radeon HD6850, Intel HD4000, Radeon HD8730 in Source based games, euro truck simulator, europe universalis.
Comment 14 Michel Dänzer 2015-03-06 01:22:49 UTC
*** Bug 89452 has been marked as a duplicate of this bug. ***
Comment 15 Michel Dänzer 2015-03-06 01:23:21 UTC
See the "Fix colormaps with RandR 1.2 capable Xorg drivers" item on http://www.x.org/wiki/SummerOfCodeIdeas/ .
Comment 16 dimman 2016-01-04 10:15:16 UTC
Since the item has been removed from the SummerOfCodeIdeas with the comment that "Fixing colormaps requires less effort than I thought", I wonder if _a fix_ actually made it to the code base or if one is still required?

I'm hoping to be able to avoid workaround with native API's and #ifdefs when SDL2 should do.

Comment 17 Michel Dänzer 2016-01-06 09:47:43 UTC
Created attachment 120828 [details] [review]
WIP: Hook up colormaps to RandR 1.2 gamma code

Here's what I have so far attempting to fix this.

It'll need to be fleshed out / split up / cleaned up before it can be applied, and it probably doesn't work correctly yet in all cases (e.g. if running Xorg at colour depths other than 24).

That said, it does fix the problem for me with SDL based games, and since I don't know when I can do more work on this next, I'm attaching this WIP patch. YMMV.
Comment 18 dimman 2016-01-07 09:48:21 UTC
Thanks Michel. I unfortunately don't have the necessary knowledge myself to fix this properly the way you mention, I just hope it doesn't get "forgotten" for years again and that you will find time to finish it up. It would be much appreciated across the board of SDL users and developers (it mostly affects users though, I feel it might be a bit hefty to require them to recompile Xorg.)

Thanks for working on this.
Comment 19 Michel Dänzer 2016-03-01 03:52:53 UTC
Comment on attachment 120828 [details] [review]
WIP: Hook up colormaps to RandR 1.2 gamma code

Current WIP patches available on the randr12-colormaps branch of https://cgit.freedesktop.org/~daenzer/xserver/ . These work fine for me at depths 24, 16, 15 and 8.
Comment 20 Luke 2016-05-13 02:32:36 UTC
Is there a PPA or easy way for us to test this code out?
Comment 21 Michel Dänzer 2016-07-29 00:59:09 UTC
commit b4e46c0444bb09f4af59d9d13acc939a0fbbc6d6
Author: Michel Dänzer <michel.daenzer@amd.com>
Date:   Sat Nov 28 16:50:47 2015 +0900

    xfree86: Hook up colormaps and RandR 1.2 gamma code v6
Comment 22 Luke 2016-12-09 22:43:48 UTC
Verified fixed in Fedora 25 with the xorg session. 

Do these changes need to be ported over to xwayland?
Comment 23 Michel Dänzer 2016-12-12 06:42:20 UTC
These changes cannot be ported to Xwayland directly. AFAIK there is no Wayland protocol support for gamma correction yet.
Comment 24 Petr Pisar 2017-01-08 15:11:13 UTC
Fix verified with xorg-server-1.19.0.
Comment 25 Luke 2017-01-15 18:51:35 UTC
Seems to be broken again on xorg-server-1.19.1. It was working find on Fedora 25 with my Intel HD 5500 (Broadwell GT2) . After I upgraded from 1.19.0 to 1.19.1, the gamma controls stopped working and everything is dark again.
Comment 26 Michel Dänzer 2017-01-17 06:13:56 UTC
(In reply to Luke from comment #25)
> Seems to be broken again on xorg-server-1.19.1. It was working find on
> Fedora 25 with my Intel HD 5500 (Broadwell GT2) . After I upgraded from
> 1.19.0 to 1.19.1, the gamma controls stopped working and everything is dark
> again.

Make sure you're not using the modesetting driver, that one doesn't support gamma control yet.
Comment 27 Luke 2017-01-17 09:18:06 UTC
Michel Dänzer,
Thank you! That was the problem. Fedora and Arch both made the switch to modesetting the same time as upgrading to xorg-server-1.19.1. 

Should I file a bug report for this issue? I couldn't find it in the bug tracker. 

Anyone else having this issue, 

To fix this with Arch:
$ sudo pacman -S xf86-video-intel

To fix this in Fedora:

$ sudo nano /etc/X11/xorg.conf.d/20-intel.conf 
Section "Device"
    Identifier  "Intel Graphics"
    Driver      "intel"
    Option      "AccelMethod"  "sna"

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.