Closed Bug 996266 Opened 6 years ago Closed 5 years ago

Do context creation attrib fallback

Categories

(Core :: Canvas: WebGL, defect)

defect
Not set

Tracking

()

RESOLVED FIXED
mozilla34

People

(Reporter: jgilbert, Assigned: jgilbert)

References

Details

Attachments

(5 files, 5 obsolete files)

Right now, we don't really fall back when context creation fails with a given set of attribs. We detect that, for example, MSAA is disabled, and force antialias:false, but we don't actually 'fall back' programmatically.

We should do this properly.
Attached patch depth-fallback (obsolete) — Splinter Review
:kamidphish for the WebGL, :bjacob for the GLContext. (and WebGL too, if he wants!)
Attachment #8406463 - Flags: review?(dglastonbury)
Attachment #8406463 - Flags: review?(bjacob)
Please share some more background:
 - is this fixing a concrete bug or rather a general sanity improvement?
 - what is the line of thinking leading to adding a new GLContextProvider::Create* function, a rather rare event (even if as a coincidence we're getting another one added on bug 994856 !)
Comment on attachment 8406463 [details] [diff] [review]
depth-fallback

Review of attachment 8406463 [details] [diff] [review]:
-----------------------------------------------------------------

::: content/canvas/src/WebGLContext.cpp
@@ +412,5 @@
> +CreateHeadlessNativeGL(bool forceEnabled, const nsCOMPtr<nsIGfxInfo>& gfxInfo, WebGLContext& webgl)
> +{
> +    if (!forceEnabled) {
> +        if (IsFeatureInBlacklist(gfxInfo, nsIGfxInfo::FEATURE_WEBGL_OPENGL)) {
> +            webgl.GenerateWarning("Refused to create native OpenGL context because of blacklisting.");

if (!forceEnable && IsFeatureInBlacklist(...

@@ +437,5 @@
> +    nsRefPtr<GLContext> gl;
> +
> +#ifdef XP_WIN
> +    if (!forceEnabled) {
> +        if (IsFeatureInBlacklist(gfxInfo, nsIGfxInfo::FEATURE_WEBGL_ANGLE)) {

Ditto

@@ +555,5 @@
> +
> +    // we should really have this behind a
> +    // |gfxPlatform::GetPlatform()->GetScreenDepth() == 16| check, but
> +    // for now it's just behind a pref for testing/evaluation.
> +    baseCaps.bpp16 = Preferences::GetBool("webgl.prefer-16bpp", false);

Should we just do it then? How much work is it?

@@ +574,5 @@
> +    // Done with baseCaps construction.
> +
> +    bool forceAllowAA = Preferences::GetBool("webgl.msaa-force", false);
> +    if (!forceAllowAA) {
> +        if (IsFeatureInBlacklist(gfxInfo, nsIGfxInfo::FEATURE_WEBGL_MSAA)) {

Ditto

@@ +615,5 @@
> +        if (!InitAndValidateGL())
> +            break;
> +
> +        return true;
> +    } while (false);

Why the do/while(false)?
Attachment #8406463 - Flags: review?(dglastonbury) → review+
(In reply to Dan Glastonbury :djg :kamidphish from comment #3)
> Comment on attachment 8406463 [details] [diff] [review]
> depth-fallback
> 
> Review of attachment 8406463 [details] [diff] [review]:
> -----------------------------------------------------------------
> 
> ::: content/canvas/src/WebGLContext.cpp
> @@ +412,5 @@
> > +CreateHeadlessNativeGL(bool forceEnabled, const nsCOMPtr<nsIGfxInfo>& gfxInfo, WebGLContext& webgl)
> > +{
> > +    if (!forceEnabled) {
> > +        if (IsFeatureInBlacklist(gfxInfo, nsIGfxInfo::FEATURE_WEBGL_OPENGL)) {
> > +            webgl.GenerateWarning("Refused to create native OpenGL context because of blacklisting.");
> 
> if (!forceEnable && IsFeatureInBlacklist(...
Ok.
> 
> @@ +437,5 @@
> > +    nsRefPtr<GLContext> gl;
> > +
> > +#ifdef XP_WIN
> > +    if (!forceEnabled) {
> > +        if (IsFeatureInBlacklist(gfxInfo, nsIGfxInfo::FEATURE_WEBGL_ANGLE)) {
> 
> Ditto
Ok.
> 
> @@ +555,5 @@
> > +
> > +    // we should really have this behind a
> > +    // |gfxPlatform::GetPlatform()->GetScreenDepth() == 16| check, but
> > +    // for now it's just behind a pref for testing/evaluation.
> > +    baseCaps.bpp16 = Preferences::GetBool("webgl.prefer-16bpp", false);
> 
> Should we just do it then? How much work is it?
If we want to do it, we should do it in another bug.
> 
> @@ +574,5 @@
> > +    // Done with baseCaps construction.
> > +
> > +    bool forceAllowAA = Preferences::GetBool("webgl.msaa-force", false);
> > +    if (!forceAllowAA) {
> > +        if (IsFeatureInBlacklist(gfxInfo, nsIGfxInfo::FEATURE_WEBGL_MSAA)) {
> 
> Ditto
Ok.
> 
> @@ +615,5 @@
> > +        if (!InitAndValidateGL())
> > +            break;
> > +
> > +        return true;
> > +    } while (false);
> 
> Why the do/while(false)?
It makes cleanup easy, instead of having to cleanup in each if, or using real gotos.
(In reply to Jeff Gilbert [:jgilbert] from comment #4)
> > @@ +615,5 @@
> > > +        if (!InitAndValidateGL())
> > > +            break;
> > > +
> > > +        return true;
> > > +    } while (false);
> > 
> > Why the do/while(false)?
> It makes cleanup easy, instead of having to cleanup in each if, or using
> real gotos.

Oh right. I was having a stupid moment.
Depends on: 997374
Jeff, did you see my questions in comment 2?
Flags: needinfo?(jgilbert)
(In reply to Benoit Jacob [:bjacob] from comment #2)
> Please share some more background:
>  - is this fixing a concrete bug or rather a general sanity improvement?
>  - what is the line of thinking leading to adding a new
> GLContextProvider::Create* function, a rather rare event (even if as a
> coincidence we're getting another one added on bug 994856 !)

1. Both. Right now, if creating a stencil-only context fails, we'll completely fail to create the context, instead of falling back to trying without stencil.

2. This is one step closer to moving all the Offscreen stuff to WebGLContext, which removes a ton of mostly webgl-only code from GLContext. It also reflects how we want to create things. Really, we either want a context for a widget, or a headless context, which we'll do all our own stuff for.
Flags: needinfo?(jgilbert)
Attachment #8406463 - Flags: review?(bjacob) → review+
See Also: → 745912, 833779
Unfortunately, I didn't keep the old patch free of changes, so we have to review it again. :(
Attachment #8406463 - Attachment is obsolete: true
Attachment #8468985 - Flags: review?(dglastonbury)
Attached patch patch 2: More fixes (obsolete) — Splinter Review
Attachment #8468986 - Flags: review?(dglastonbury)
Attached patch patch 3: Fix ANGLE (obsolete) — Splinter Review
I'm actually not sure how we want to handle ANGLE bugs at this point.
I'll figure this out.
Attachment #8468988 - Flags: review?(dglastonbury)
Flags: needinfo?(jgilbert)
Attachment #8468988 - Attachment description: angle-allow-invalidcall → patch 3: Fix ANGLE
Flags: needinfo?(jgilbert)
Duplicate of this bug: 847714
Comment on attachment 8468985 [details] [diff] [review]
patch 1: Fallback from context creation failure.

Review of attachment 8468985 [details] [diff] [review]:
-----------------------------------------------------------------

::: dom/canvas/WebGLContext.cpp
@@ +512,5 @@
> +                       const nsCOMPtr<nsIGfxInfo>& gfxInfo,
> +                       WebGLContext* webgl)
> +{
> +    if (!forceEnabled) {
> +        if (IsFeatureInBlacklist(gfxInfo, nsIGfxInfo::FEATURE_WEBGL_OPENGL)) {

if (!forceEnabled && IsFeatureInBlacklist(...)) {
}

@@ +540,5 @@
> +    nsRefPtr<GLContext> gl;
> +
> +#ifdef XP_WIN
> +    if (!forceEnabled) {
> +        if (IsFeatureInBlacklist(gfxInfo, nsIGfxInfo::FEATURE_WEBGL_ANGLE)) {

Ditto

@@ +671,5 @@
> +    // Done with baseCaps construction.
> +
> +    bool forceAllowAA = Preferences::GetBool("webgl.msaa-force", false);
> +    if (!forceAllowAA) {
> +        if (IsFeatureInBlacklist(gfxInfo, nsIGfxInfo::FEATURE_WEBGL_MSAA)) {

if (!forceAllowAA && IsFeatureInBlacklist(...)) {
}

::: gfx/gl/GLContext.cpp
@@ +1090,5 @@
>          raw_fGetIntegerv(LOCAL_GL_SCISSOR_BOX, mScissorRect);
>          raw_fGetIntegerv(LOCAL_GL_MAX_TEXTURE_SIZE, &mMaxTextureSize);
>          raw_fGetIntegerv(LOCAL_GL_MAX_CUBE_MAP_TEXTURE_SIZE, &mMaxCubeMapTextureSize);
>          raw_fGetIntegerv(LOCAL_GL_MAX_RENDERBUFFER_SIZE, &mMaxRenderbufferSize);
>  

Drop the blank line?
Attachment #8468985 - Flags: review?(dglastonbury) → review+
Comment on attachment 8468986 [details] [diff] [review]
patch 2: More fixes

Review of attachment 8468986 [details] [diff] [review]:
-----------------------------------------------------------------

::: gfx/angle/src/libGLESv2/renderer/d3d9/RenderTarget9.cpp
@@ +14,5 @@
>  #include "libGLESv2/renderer/d3d9/renderer9_utils.h"
>  #include "libGLESv2/renderer/d3d9/formatutils9.h"
>  #include "libGLESv2/main.h"
>  
> +#include <cstdio>

o_O

::: gfx/gl/GLBlitHelper.cpp
@@ +43,5 @@
>                GLenum aType, const gfx::IntSize& aSize, bool linear)
>  {
>      GLuint tex = 0;
>      aGL->fGenTextures(1, &tex);
> +        ScopedBindTexture autoTex(aGL, tex);

Indent

::: gfx/gl/GLContext.cpp
@@ +1116,5 @@
>          raw_fGetIntegerv(LOCAL_GL_MAX_VIEWPORT_DIMS, mMaxViewportDims);
>  
> +        printf_stderr("mMaxTextureSize: %d\n", mMaxTextureSize);
> +        printf_stderr("mMaxRenderbufferSize: %d\n", mMaxRenderbufferSize);
> +        printf_stderr("mMaxViewportDims: %dx%d\n", mMaxViewportDims[0],

Should this be disabled? (I'm not sure what the rules are about printing at runtime)

@@ +1160,5 @@
>          mMaxSamples = 0;
>          if (IsSupported(GLFeature::framebuffer_multisample)) {
>              fGetIntegerv(LOCAL_GL_MAX_SAMPLES, (GLint*)&mMaxSamples);
>          }
> +        printf_stderr("mMaxSamples: %d\n", mMaxSamples);

Ditto

::: gfx/gl/GLContext.h
@@ +522,4 @@
>  // -----------------------------------------------------------------------------
>  // Error handling
>  public:
> +    static const char* GLErrorToString(GLenum aError) {

I can never tell whether we put { on the same line for functions or on the next.
Attachment #8468986 - Flags: review?(dglastonbury) → review-
Comment on attachment 8468988 [details] [diff] [review]
patch 3: Fix ANGLE

Review of attachment 8468988 [details] [diff] [review]:
-----------------------------------------------------------------

Do you need to contribute this to Vlad's mozilla patches to ANGLE on github?
Attachment #8468988 - Flags: review?(dglastonbury) → review+
(In reply to Dan Glastonbury :djg :kamidphish from comment #17)
> Comment on attachment 8468985 [details] [diff] [review]
> patch 1: Fallback from context creation failure.
> 
> Review of attachment 8468985 [details] [diff] [review]:
> -----------------------------------------------------------------
> 
> ::: dom/canvas/WebGLContext.cpp
> @@ +512,5 @@
> > +                       const nsCOMPtr<nsIGfxInfo>& gfxInfo,
> > +                       WebGLContext* webgl)
> > +{
> > +    if (!forceEnabled) {
> > +        if (IsFeatureInBlacklist(gfxInfo, nsIGfxInfo::FEATURE_WEBGL_OPENGL)) {
> 
> if (!forceEnabled && IsFeatureInBlacklist(...)) {
> }
Fixed.
> 
> @@ +540,5 @@
> > +    nsRefPtr<GLContext> gl;
> > +
> > +#ifdef XP_WIN
> > +    if (!forceEnabled) {
> > +        if (IsFeatureInBlacklist(gfxInfo, nsIGfxInfo::FEATURE_WEBGL_ANGLE)) {
> 
> Ditto
Fixed.
> 
> @@ +671,5 @@
> > +    // Done with baseCaps construction.
> > +
> > +    bool forceAllowAA = Preferences::GetBool("webgl.msaa-force", false);
> > +    if (!forceAllowAA) {
> > +        if (IsFeatureInBlacklist(gfxInfo, nsIGfxInfo::FEATURE_WEBGL_MSAA)) {
> 
> if (!forceAllowAA && IsFeatureInBlacklist(...)) {
> }
Fixed.
> 
> ::: gfx/gl/GLContext.cpp
> @@ +1090,5 @@
> >          raw_fGetIntegerv(LOCAL_GL_SCISSOR_BOX, mScissorRect);
> >          raw_fGetIntegerv(LOCAL_GL_MAX_TEXTURE_SIZE, &mMaxTextureSize);
> >          raw_fGetIntegerv(LOCAL_GL_MAX_CUBE_MAP_TEXTURE_SIZE, &mMaxCubeMapTextureSize);
> >          raw_fGetIntegerv(LOCAL_GL_MAX_RENDERBUFFER_SIZE, &mMaxRenderbufferSize);
> >  
> 
> Drop the blank line?
Fixed.
(In reply to Dan Glastonbury :djg :kamidphish from comment #18)
> Comment on attachment 8468986 [details] [diff] [review]
> patch 2: More fixes
> 
> Review of attachment 8468986 [details] [diff] [review]:
> -----------------------------------------------------------------
> 
> ::: gfx/angle/src/libGLESv2/renderer/d3d9/RenderTarget9.cpp
> @@ +14,5 @@
> >  #include "libGLESv2/renderer/d3d9/renderer9_utils.h"
> >  #include "libGLESv2/renderer/d3d9/formatutils9.h"
> >  #include "libGLESv2/main.h"
> >  
> > +#include <cstdio>
> 
> o_O
Hahaha, sorry. I was calling std::fprintf(stderr,...) here, as I needed to debug via logging on Try. ><
> 
> ::: gfx/gl/GLBlitHelper.cpp
> @@ +43,5 @@
> >                GLenum aType, const gfx::IntSize& aSize, bool linear)
> >  {
> >      GLuint tex = 0;
> >      aGL->fGenTextures(1, &tex);
> > +        ScopedBindTexture autoTex(aGL, tex);
> 
> Indent
Fixed.
> 
> ::: gfx/gl/GLContext.cpp
> @@ +1116,5 @@
> >          raw_fGetIntegerv(LOCAL_GL_MAX_VIEWPORT_DIMS, mMaxViewportDims);
> >  
> > +        printf_stderr("mMaxTextureSize: %d\n", mMaxTextureSize);
> > +        printf_stderr("mMaxRenderbufferSize: %d\n", mMaxRenderbufferSize);
> > +        printf_stderr("mMaxViewportDims: %dx%d\n", mMaxViewportDims[0],
> 
> Should this be disabled? (I'm not sure what the rules are about printing at
> runtime)
Removed.
> 
> @@ +1160,5 @@
> >          mMaxSamples = 0;
> >          if (IsSupported(GLFeature::framebuffer_multisample)) {
> >              fGetIntegerv(LOCAL_GL_MAX_SAMPLES, (GLint*)&mMaxSamples);
> >          }
> > +        printf_stderr("mMaxSamples: %d\n", mMaxSamples);
> 
> Ditto
Removed.
> 
> ::: gfx/gl/GLContext.h
> @@ +522,4 @@
> >  // -----------------------------------------------------------------------------
> >  // Error handling
> >  public:
> > +    static const char* GLErrorToString(GLenum aError) {
> 
> I can never tell whether we put { on the same line for functions or on the
> next.
We put it on the same line if the function decl is indented at all, and fits on one line.
Therefore it's on the same line in inline member function definitions, but CPP file definitions of member functions have it on the next line.
r=kamidphish
Attachment #8468985 - Attachment is obsolete: true
Attachment #8469512 - Flags: review+
Attached patch patch 2: More fixes (obsolete) — Splinter Review
Attachment #8468986 - Attachment is obsolete: true
Attachment #8469513 - Flags: review?(dglastonbury)
(In reply to Dan Glastonbury :djg :kamidphish from comment #19)
> Comment on attachment 8468988 [details] [diff] [review]
> patch 3: Fix ANGLE
> 
> Review of attachment 8468988 [details] [diff] [review]:
> -----------------------------------------------------------------
> 
> Do you need to contribute this to Vlad's mozilla patches to ANGLE on github?

I think so.
Attachment #8469513 - Flags: review?(dglastonbury) → review+
Comment on attachment 8469513 [details] [diff] [review]
patch 2: More fixes

Review of attachment 8469513 [details] [diff] [review]:
-----------------------------------------------------------------

::: gfx/gl/GLContext.cpp
@@ +281,1 @@
>      mHasRobustness(false),

Try is complaining about this:

/builds/slave/try-lx-d-000000000000000000000/build/gfx/gl/GLContext.h:618:10: error: 'mozilla::gl::GLContext::mIsInLocalErrorCheck' will be initialized after [-Werror=reorder]
/builds/slave/try-lx-d-000000000000000000000/build/gfx/gl/GLContext.h:520:10: error: 'bool mozilla::gl::GLContext::mHasRobustness' [-Werror=reorder]
/builds/slave/try-lx-d-000000000000000000000/build/gfx/gl/GLContext.cpp:268:1: error: when initialized here [-Werror=reorder]
Attachment #8469513 - Flags: review+ → review-
(In reply to Dan Glastonbury :djg :kamidphish from comment #26)
> Comment on attachment 8469513 [details] [diff] [review]
> patch 2: More fixes
> 
> Review of attachment 8469513 [details] [diff] [review]:
> -----------------------------------------------------------------
> 
> ::: gfx/gl/GLContext.cpp
> @@ +281,1 @@
> >      mHasRobustness(false),
> 
> Try is complaining about this:
> 
> /builds/slave/try-lx-d-000000000000000000000/build/gfx/gl/GLContext.h:618:10:
> error: 'mozilla::gl::GLContext::mIsInLocalErrorCheck' will be initialized
> after [-Werror=reorder]
> /builds/slave/try-lx-d-000000000000000000000/build/gfx/gl/GLContext.h:520:10:
> error: 'bool mozilla::gl::GLContext::mHasRobustness' [-Werror=reorder]
> /builds/slave/try-lx-d-000000000000000000000/build/gfx/gl/GLContext.cpp:268:
> 1: error: when initialized here [-Werror=reorder]

Fixed in:
https://tbpl.mozilla.org/?tree=Try&rev=ae72b8551f1f
Comment on attachment 8469513 [details] [diff] [review]
patch 2: More fixes

Is this r+ with the fully-passing Try run?
Attachment #8469513 - Flags: review- → review?(dglastonbury)
Blocks: 981338
(In reply to Jeff Gilbert [:jgilbert] from comment #28)
> Comment on attachment 8469513 [details] [diff] [review]
> patch 2: More fixes
> 
> Is this r+ with the fully-passing Try run?

Yes. Don't you just need to switch order of 

    #ifdef DEBUG
        mIsInLocalErrorCheck(false),
    #endif
    mHasRobustness(false),

to what it was?
(In reply to Dan Glastonbury :djg :kamidphish from comment #29)
> (In reply to Jeff Gilbert [:jgilbert] from comment #28)
> > Comment on attachment 8469513 [details] [diff] [review]
> > patch 2: More fixes
> > 
> > Is this r+ with the fully-passing Try run?
> 
> Yes. Don't you just need to switch order of 
> 
>     #ifdef DEBUG
>         mIsInLocalErrorCheck(false),
>     #endif
>     mHasRobustness(false),
> 
> to what it was?

Yes. My local patch has this. It's in the TBPL link. I'll find it and upload it.
Attachment #8469513 - Attachment is obsolete: true
Attachment #8469513 - Flags: review?(dglastonbury)
Attachment #8475664 - Flags: review?(dglastonbury)
Attachment #8468988 - Attachment is obsolete: true
Attachment #8475665 - Flags: review?(dglastonbury)
Attached patch patch 0: Kill WSSplinter Review
Attachment #8475667 - Flags: review?(dglastonbury)
Using E_INVALIDARG instead of D3DERR_INVALIDCALL gives us green Win8 Debug:
https://tbpl.mozilla.org/?tree=Try&rev=4b8d623acc1a
Comment on attachment 8475664 [details] [diff] [review]
patch 2: Support checking for errors at the GLContext level

Review of attachment 8475664 [details] [diff] [review]:
-----------------------------------------------------------------

::: gfx/gl/SharedSurfaceANGLE.cpp
@@ +151,5 @@
>                       EGLConfig config,
>                       const gfx::IntSize& size)
>  {
> +    auto width = size.width;
> +    auto height = size.height;

Why?
Attachment #8475664 - Flags: review?(dglastonbury) → review+
Comment on attachment 8475665 [details] [diff] [review]
patch 3: E_INVALIDARG sometimes is an OOM/refusal to allocate

Review of attachment 8475665 [details] [diff] [review]:
-----------------------------------------------------------------

I wonder if there's a cap in DX9 for the maximum memory size a texture can have?
Attachment #8475665 - Flags: review?(dglastonbury) → review+
Comment on attachment 8475667 [details] [diff] [review]
patch 0: Kill WS

Review of attachment 8475667 [details] [diff] [review]:
-----------------------------------------------------------------

::: modules/libpref/init/all.js
@@ +2106,5 @@
>  // but provides more time for other operations when the browser is
>  // heavily loaded.
>  pref("layout.frame_rate.precise", false);
>  
> +// pref to control whether layout warnings that are hit quite often are enabled

To the god of WS we say "not today!"
Attachment #8475667 - Flags: review?(dglastonbury) → review+
(In reply to Dan Glastonbury :djg :kamidphish from comment #35)
> Comment on attachment 8475664 [details] [diff] [review]
> patch 2: Support checking for errors at the GLContext level
> 
> Review of attachment 8475664 [details] [diff] [review]:
> -----------------------------------------------------------------
> 
> ::: gfx/gl/SharedSurfaceANGLE.cpp
> @@ +151,5 @@
> >                       EGLConfig config,
> >                       const gfx::IntSize& size)
> >  {
> > +    auto width = size.width;
> > +    auto height = size.height;
> 
> Why?

I think I only had this pulled out to allow printfs. It's not really hurting, even if it's a little more verbose. I'll remove it.
Angle patch merged here:
https://github.com/mozilla/angle/pull/6
sorry had to backout the above 3 csets (except the Kill WS change) for bustage on B2g like https://tbpl.mozilla.org/php/getParsedLog.php?id=46841680&tree=Mozilla-Inbound
*shakes fist at b2g's GCC*
Comment on attachment 8475667 [details] [diff] [review]
patch 0: Kill WS

This stuck, and so is checked in.
Attachment #8475667 - Flags: checkin+
https://hg.mozilla.org/mozilla-central/rev/fdd2bb040eb6
Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla34
My bad, I should have made this keep-open.
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Blocks: 1060948
No longer blocks: 1060948
You need to log in before you can comment on or make changes to this bug.