Bug 68760 - BlitFramebufferEXT incorrectly performs sRGB decode on 1:1 blit to system framebuffer
Summary: BlitFramebufferEXT incorrectly performs sRGB decode on 1:1 blit to system fra...
Status: RESOLVED FIXED
Alias: None
Product: Mesa
Classification: Unclassified
Component: Drivers/DRI/i965 (show other bugs)
Version: unspecified
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: Ian Romanick
QA Contact: Intel 3D Bugs Mailing List
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-08-30 16:52 UTC by David Gow
Modified: 2016-11-02 06:10 UTC (History)
4 users (show)

See Also:
i915 platform:
i915 features:


Attachments

Description David Gow 2013-08-30 16:52:53 UTC
I've been having a strange issue where I'm getting a 'dark' image out of a basic glBlitFramebufferEXT() call when blitting from an FBO backed by a GL_RGB texture to the window system framebuffer (0). A stretched blit works fine, though I get the debug message "Medium severity API performance issue 3, glBlitFramebuffer(): non-1:1 blit. Falling back to software rendering." when using this. Similarly, just rendering a fullscreen quad works fine.

I can reproduce this in apitrace's "replay", but qapitrace's surface viewer shows the correct image. Similarly, I've observed no such problem on nVidia's proprietary driver.

I'm running this on Ivybridge, with the version of Mesa used by ubuntu's xorg-edgers repository (which is slightly old git): 9.2.0~git20130729+9.2.9b8ad643-0ubuntu0sarvatt~raring

I tried running piglit (I'm not 100% sure I got everything right) and spec/EXT_framebuffer_blit/fbo-sys-blit and spec/EXT_framebuffer_blit/fbo-sys-sub-blit failed, but it looks to be unrelated: all of the pixels checked were (0,0,0).

Screenshot of the bug: http://davidgow.net/stuff/mesa-omnispeak-srgb-bad.png
Screenshot of a 'stretched blit': http://davidgow.net/stuff/mesa-omnispeak-srgb-stretch.png

Quick apitrace log (bug is visible from the start, stretched blit starts at frame 246): http://davidgow.net/stuff/mesa-omnispeak-srgb-untrimmed.trace.gz

Source code for the program: https://github.com/sulix/omnispeak/blob/master/src/id_vl_sdl2gl.c#L187

Thanks, and apologies if I got anything wrong.

-- David
Comment 1 David Gow 2013-08-31 08:42:49 UTC
Just to clear this up a bit: I tried this using OpenGL 3.0's framebuffer entry points: same problem. Same problem also appears using a renderbuffer to back the FBO, rather than a texture.

What does fix the problem is using GL_RGBA as the internalformat for the colour attachment rather than GL_RGB. The sized GL_RGB8 also triggers the issue, but GL_RGBA8 doesn't.

Using GL_RGBA is good enough for my purposes, but I'll leave this open as it does seem to actually be a bug.

-- David
Comment 2 Eric Anholt 2013-09-30 23:14:35 UTC
Right now, you're just getting lucky.  In current Mesa, with the scaled blit support, one of your workarounds fails.  I suspect once we do format conversions, the new workaround will fail.

Here's the problem I see:

The window system framebuffer is srgb-capable, internally "SARGB8".  You don't have GL_FRAMEBUFFER_SRGB set, so you're not expecting srgb encoding, but we only look at the framebuffer's format when blitting, so you get encoding.

The source is not srgb (internally XRGB8888 or ARGB8888), so you're not expecting srgb decoding.  We don't do srgb decoding.

Thus, a conversion is happening on your data when you didn't expect it.

The GL 3.2 spec seems to indicate that we shouldn't ever do srgb encode or decode.  This seems pretty weird -- it means you can't blit from an actually-linear texture to an actually-srgb window correctly, which is an undesirable property.

The 4.3 spec says we should pay attention to GL_FRAMEBUFFER_SRGB on the destination, but only ever look at the format (aka GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING) on the source.  This seems pretty crazy, since it means that a GL_EXT_framebuffer_blit-using application that doesn't know about srgb would get their stuff srgb-encoded when copying from one part of a framebuffer object to another!

I'm not sure what the right resolution is here.  Hey CC list, what do you think?
Comment 3 Eric Anholt 2013-10-11 06:09:03 UTC
We talked about things the other day, and I'd missed this code:

   src.brw_surfaceformat = dst.brw_surfaceformat;

So there shouldn't be any mismatched encode/decode happening in blorp, ever.

Mesa master just got a big overhaul of format handling in the blit path -- you should be getting the same byte values showing up in your window system framebuffer (test using xmag) as you have in your palette.  Is that what you are seeing?
Comment 4 David Gow 2013-10-11 14:59:08 UTC
Okay, I just grabbed latest Mesa git [9.3.0-devel (git-396c69b)] and sat down with xmag. The behaviour is a bit more consistent, though it's not perfect.

Long story short, the colours I see (and register with xmag) are correct (i.e. no sRGB encode/decode happens) when I create the texture backing the FBO with the GL_RGBA format, and incorrect with the GL_RGB format.

What has changed is that the behaviour is now the same (always correct or always incorrect) with both scaled and 1:1 blits.

One thing that I noticed is that glxinfo is not showing up any FBConfigs or Visuals with sRGB enabled — should it be? I still get a "1" from glGetIntegerv(GL_FRAMEBUFFER_SRGB_CAPABLE_EXT, ...), and sRGB encode seems to work fine.

-- David
Comment 5 David Gow 2013-10-21 15:47:26 UTC
I see that the recent OpenGL spec update clarifies that BlitFramebuffer should only do sRGB encode/decode when GL_FRAMEBUFFER_SRGB is enabled.

This inspired me to do a bit more spelunking (with git 50370e483ba). I'm only getting issues when using the blorp blit engine — both the BLT engine path and _mesa_meta_BlitFramebuffer work fine. I poked around a bit in the blorp blit code, but don't really understand what's going wrong. It does work fine if you don't linearize the render target format in brw_blorp_surface_info::set(), though I'm sure it'll break other things.

I've uploaded the output from INTEL_DEBUG=blorp debug here: http://davidgow.net/stuff/omnispeak_blorp_debug.txt

Hope it helps!

-- David
Comment 6 Eero Tamminen 2014-12-29 15:42:49 UTC
Blit path got large overhaul in summer, is this now fixed/same/worse?
Comment 7 Antia Puentes 2015-03-09 14:58:24 UTC
Related with some dEQP tests failures, I looked recently at the sRGB conversions while blitting. The current status is that no color space conversions are done: neither sRGB decoding when reading, nor sRGB encoding when writting.

However, OpenGL specifications since 4.4 and OpenGL ES 3.0
say otherwise, and indicate that color space conversions should be applied when needed.

Before proceeding with this bug, we would need to take a decission regarding what it is the expected behaviour in this case. I've recently sent an e-mail to mesa's mailing list: http://lists.freedesktop.org/archives/mesa-dev/2015-February/077681.html but I haven't received an answer so far.

Notice that this also affects some dEQP tests for GLES3 that are failing because they expect the sRGB encoding/decoding to be done.
Comment 8 Matt Turner 2016-11-02 06:10:53 UTC
I think Ken fixed this with his series ending in commit 3190c7ee97 which was commited on August 8th and is in mesa-13.0.0. I have replayed your trace and it looks like http://davidgow.net/stuff/mesa-omnispeak-srgb-stretch.png (which I think is what you were saying is what you thought was the correct behavior.)

Marking fixed. Please reopen if I've made an error or mesa-13.0.0 does not fix the issue.


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.