Bug 81103 - [Texmap] Implement BGRA swizzling detection
Summary: [Texmap] Implement BGRA swizzling detection
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Platform (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-03-14 07:25 PDT by Simon Hausmann
Modified: 2013-02-04 13:50 PST (History)
5 users (show)

See Also:


Attachments
Patch (5.29 KB, patch)
2013-02-01 15:36 PST, Igor Trindade Oliveira
no flags Details | Formatted Diff | Diff
Patch V2 (5.37 KB, patch)
2013-02-01 15:55 PST, Igor Trindade Oliveira
no flags Details | Formatted Diff | Diff
Patch v3 (5.15 KB, patch)
2013-02-01 15:59 PST, Igor Trindade Oliveira
noam: review+
noam: commit-queue-
Details | Formatted Diff | Diff
Patch (5.24 KB, patch)
2013-02-04 11:55 PST, Igor Trindade Oliveira
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Hausmann 2012-03-14 07:25:55 PDT
We used to check if GL_EXT_texture_format_BGRA8888 is listed in the extensions to assume that the driver supports swizzling from GL_BGRA to the GL_RGBA texture format. Unfortunately this does not work reliably with all chipsets.
Comment 1 Simon Hausmann 2012-03-15 02:34:04 PDT
r110703 removed the swizzling for GLES.
Comment 2 Simon Hausmann 2012-03-15 02:42:46 PDT
From http://www.khronos.org/opengles/sdk/docs/man/xhtml/glTexSubImage2D.xml it appears that the format passed to glTexSubImage2D is supposed to be the same:

"GL_INVALID_OPERATION is generated if the texture array has not been defined by a previous glTexImage2D or glCopyTexImage2D operation whose internalformat matches the format of glTexSubImage2D."
Comment 3 Simon Hausmann 2012-03-15 02:48:28 PDT
Another interesting point:

<k5kangas> You might also want to quote OpenGLES2 spec, v2.0.25, page 72, "Each of the TexSubImage commands
<k5kangas> interprets and processes pixel groups in exactly the manner of its TexImage coun-
<k5kangas> terpart, except that the assignment of R, G, B, and A pixel group values to the
<k5kangas> texture components is controlled by the internalformat of the texture array, not
<k5kangas> by an argument to the command.
Comment 4 Noam Rosenthal 2012-03-15 02:55:24 PDT
(In reply to comment #3)
> Another interesting point:
> 
> <k5kangas> You might also want to quote OpenGLES2 spec, v2.0.25, page 72, "Each of the TexSubImage commands
> <k5kangas> interprets and processes pixel groups in exactly the manner of its TexImage coun-
> <k5kangas> terpart, except that the assignment of R, G, B, and A pixel group values to the
> <k5kangas> texture components is controlled by the internalformat of the texture array, not
> <k5kangas> by an argument to the command.

Interesting. I wonder why this is the only thing that had worked for desktop and Harmattan then :)
Comment 5 Igor Trindade Oliveira 2013-02-01 15:36:23 PST
Created attachment 186167 [details]
Patch

Proposed patch
Comment 6 Viatcheslav Ostapenko 2013-02-01 15:46:40 PST
Comment on attachment 186167 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=186167&action=review

> Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp:589
> +    return context->getExtensions()->supports("GL_EXT_texture_format_BGRA8888");

It is called so many times. I doubt that swizzling support can change during app execution and would cache result here.
Something like this:

static bool canSwizzle = context->getExtensions()->supports("GL_EXT_texture_format_BGRA8888");
return canSwizzle;
Comment 7 Igor Trindade Oliveira 2013-02-01 15:55:08 PST
Created attachment 186175 [details]
Patch V2

Proposed patch.
Comment 8 Igor Trindade Oliveira 2013-02-01 15:59:32 PST
Created attachment 186178 [details]
Patch v3

Fix left over from other patch.
Comment 9 Noam Rosenthal 2013-02-01 22:57:20 PST
Comment on attachment 186178 [details]
Patch v3

View in context: https://bugs.webkit.org/attachment.cgi?id=186178&action=review

I remember this kind of patch had a tendency to break stuff :)
Can someone validate it on more than one GLES2 hardware?

> Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp:591
>  #if defined(TEXMAP_OPENGL_ES_2)
> -    // FIXME: Implement reliable detection. See also https://bugs.webkit.org/show_bug.cgi?id=81103.
> -    return false;
> +    static bool supportsExternalTextureBGRA = context->getExtensions()->supports("GL_EXT_texture_format_BGRA8888");
> +    return supportsExternalTextureBGRA;
>  #else

I think we shoul switch here to isGLES2Compliant() instead of an #ifdef
Comment 10 Igor Trindade Oliveira 2013-02-02 00:16:28 PST
(In reply to comment #9)
> (From update of attachment 186178 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=186178&action=review
> 
> I remember this kind of patch had a tendency to break stuff :)
> Can someone validate it on more than one GLES2 hardware?

I tested in mesa3d llvmpipe, intel and mali t400.
The reverted implementation(changeset r110703) was slightly different. Basically it was just using BGRA in the external format, however in the GLESv2 case, when BGRA is used it also needs to be used in the internal texture format. 

> 
> > Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp:591
> >  #if defined(TEXMAP_OPENGL_ES_2)
> > -    // FIXME: Implement reliable detection. See also https://bugs.webkit.org/show_bug.cgi?id=81103.
> > -    return false;
> > +    static bool supportsExternalTextureBGRA = context->getExtensions()->supports("GL_EXT_texture_format_BGRA8888");
> > +    return supportsExternalTextureBGRA;
> >  #else
> 
> I think we shoul switch here to isGLES2Compliant() instead of an #ifdef
Comment 11 Noam Rosenthal 2013-02-02 01:45:26 PST
(In reply to comment #10)
> (In reply to comment #9)
> > (From update of attachment 186178 [details] [details])
> > View in context: https://bugs.webkit.org/attachment.cgi?id=186178&action=review
> > 
> > I remember this kind of patch had a tendency to break stuff :)
> > Can someone validate it on more than one GLES2 hardware?
> 
> I tested in mesa3d llvmpipe, intel and mali t400.
> The reverted implementation(changeset r110703) was slightly different. Basically it was just using BGRA in the external format, however in the GLESv2 case, when BGRA is used it also needs to be used in the internal texture format. 
Yes, in the N9 case that's the only thing that worked (and N9 was the only GLESv2 device running TextureMapper at the time).
But I think this should be ok, if you can address the other comment :)
Comment 12 Noam Rosenthal 2013-02-03 01:14:56 PST
Comment on attachment 186178 [details]
Patch v3

See previous comment.
Comment 13 Igor Trindade Oliveira 2013-02-04 11:55:20 PST
Created attachment 186427 [details]
Patch

Patch for landing.
Comment 14 WebKit Review Bot 2013-02-04 13:50:53 PST
Comment on attachment 186427 [details]
Patch

Clearing flags on attachment: 186427

Committed r141807: <http://trac.webkit.org/changeset/141807>
Comment 15 WebKit Review Bot 2013-02-04 13:50:57 PST
All reviewed patches have been landed.  Closing bug.