diff options
author | Brian Smith <brian@dbsoft.org> | 2022-04-26 11:24:42 -0500 |
---|---|---|
committer | Brian Smith <brian@dbsoft.org> | 2022-04-26 11:24:42 -0500 |
commit | c82b759d56454bcd3eac54c484569e1239f7d1cc (patch) | |
tree | 14b786bac9fd295d1fca6bd32683652b7ac9ef7e /dom/canvas | |
parent | 9e2a89c71ddf67975da35eb100673f6b5546f292 (diff) | |
download | uxp-c82b759d56454bcd3eac54c484569e1239f7d1cc.tar.gz |
Issue #1829 - Revert "Issue #1751 -- Remove XP_MACOSX conditionals from /dom"
This reverts commit 0dd3424f774954627d6f53df9fb47379d9b5c871.
Diffstat (limited to 'dom/canvas')
-rw-r--r-- | dom/canvas/WebGL2Context.cpp | 7 | ||||
-rw-r--r-- | dom/canvas/WebGLBuffer.cpp | 2 | ||||
-rw-r--r-- | dom/canvas/WebGLContext.h | 13 | ||||
-rw-r--r-- | dom/canvas/WebGLContextBuffers.cpp | 16 | ||||
-rw-r--r-- | dom/canvas/WebGLContextDraw.cpp | 7 | ||||
-rw-r--r-- | dom/canvas/WebGLContextValidate.cpp | 12 | ||||
-rw-r--r-- | dom/canvas/WebGLProgram.cpp | 34 | ||||
-rw-r--r-- | dom/canvas/WebGLShaderValidator.cpp | 37 |
8 files changed, 126 insertions, 2 deletions
diff --git a/dom/canvas/WebGL2Context.cpp b/dom/canvas/WebGL2Context.cpp index 09891e7b6e..8c472384e5 100644 --- a/dom/canvas/WebGL2Context.cpp +++ b/dom/canvas/WebGL2Context.cpp @@ -125,6 +125,13 @@ WebGLContext::InitWebGL2(FailureReason* const out_failReason) fnGatherMissing2(gl::GLFeature::occlusion_query_boolean, gl::GLFeature::occlusion_query); +#ifdef XP_MACOSX + // On OSX, GL core profile is used. This requires texture swizzle + // support to emulate legacy texture formats: ALPHA, LUMINANCE, + // and LUMINANCE_ALPHA. + fnGatherMissing(gl::GLFeature::texture_swizzle); +#endif + fnGatherMissing2(gl::GLFeature::prim_restart_fixed, gl::GLFeature::prim_restart); diff --git a/dom/canvas/WebGLBuffer.cpp b/dom/canvas/WebGLBuffer.cpp index 11d956c8a4..02a8f649fe 100644 --- a/dom/canvas/WebGLBuffer.cpp +++ b/dom/canvas/WebGLBuffer.cpp @@ -115,7 +115,7 @@ WebGLBuffer::BufferData(GLenum target, size_t size, const void* data, GLenum usa const ScopedLazyBind lazyBind(gl, target, this); mContext->InvalidateBufferFetching(); -#if defined(MOZ_WIDGET_GTK) +#if defined(XP_MACOSX) || defined(MOZ_WIDGET_GTK) // bug 790879 if (gl->WorkAroundDriverBugs() && size > INT32_MAX) diff --git a/dom/canvas/WebGLContext.h b/dom/canvas/WebGLContext.h index 628d4713ca..0510e6898a 100644 --- a/dom/canvas/WebGLContext.h +++ b/dom/canvas/WebGLContext.h @@ -30,6 +30,10 @@ #include "ScopedGLHelpers.h" #include "TexUnpackBlob.h" +#ifdef XP_MACOSX +#include "ForceDiscreteGPUHelperCGL.h" +#endif + // Local #include "WebGLContextLossHandler.h" #include "WebGLContextUnchecked.h" @@ -2011,6 +2015,15 @@ protected: JSObject* WebGLObjectAsJSObject(JSContext* cx, const WebGLObjectType*, ErrorResult& rv) const; +#ifdef XP_MACOSX + // see bug 713305. This RAII helper guarantees that we're on the discrete GPU, during its lifetime + // Debouncing note: we don't want to switch GPUs too frequently, so try to not create and destroy + // these objects at high frequency. Having WebGLContext's hold one such object seems fine, + // because WebGLContext objects only go away during GC, which shouldn't happen too frequently. + // If in the future GC becomes much more frequent, we may have to revisit then (maybe use a timer). + ForceDiscreteGPUHelperCGL mForceDiscreteGPUHelper; +#endif + public: // console logging helpers void GenerateWarning(const char* fmt, ...); diff --git a/dom/canvas/WebGLContextBuffers.cpp b/dom/canvas/WebGLContextBuffers.cpp index 6f583c10c6..e787b99143 100644 --- a/dom/canvas/WebGLContextBuffers.cpp +++ b/dom/canvas/WebGLContextBuffers.cpp @@ -295,6 +295,16 @@ WebGLContext::BindBufferRange(GLenum target, GLuint index, WebGLBuffer* buffer, //// +#ifdef XP_MACOSX + if (buffer && buffer->Content() == WebGLBuffer::Kind::Undefined && + gl->WorkAroundDriverBugs()) + { + // BindBufferRange will fail if the buffer's contents is undefined. + // Bind so driver initializes the buffer. + gl->fBindBuffer(target, buffer->mGLName); + } +#endif + gl->fBindBufferRange(target, index, buffer ? buffer->mGLName : 0, offset, size); //// @@ -342,6 +352,12 @@ WebGLContext::BufferData(GLenum target, WebGLsizeiptr size, GLenum usage) if (!checkedSize.isValid()) return ErrorOutOfMemory("%s: Size too large for platform.", funcName); +#if defined(XP_MACOSX) + if (gl->WorkAroundDriverBugs() && size > 1200000000) { + return ErrorOutOfMemory("Allocations larger than 1200000000 fail on MacOS."); + } +#endif + const UniqueBuffer zeroBuffer(calloc(size, 1)); if (!zeroBuffer) return ErrorOutOfMemory("%s: Failed to allocate zeros.", funcName); diff --git a/dom/canvas/WebGLContextDraw.cpp b/dom/canvas/WebGLContextDraw.cpp index c0ba20301a..6c684b2ff8 100644 --- a/dom/canvas/WebGLContextDraw.cpp +++ b/dom/canvas/WebGLContextDraw.cpp @@ -1045,6 +1045,13 @@ WebGLContext::WhatDoesVertexAttrib0Need() const const auto& isAttribArray0Enabled = mBoundVertexArray->mAttribs[0].mEnabled; bool legacyAttrib0 = gl->IsCompatibilityProfile(); +#ifdef XP_MACOSX + if (gl->WorkAroundDriverBugs()) { + // Failures in conformance/attribs/gl-disabled-vertex-attrib. + // Even in Core profiles on NV. Sigh. + legacyAttrib0 |= (gl->Vendor() == gl::GLVendor::NVIDIA); + } +#endif if (!legacyAttrib0) return WebGLVertexAttrib0Status::Default; diff --git a/dom/canvas/WebGLContextValidate.cpp b/dom/canvas/WebGLContextValidate.cpp index 60bb3a32cc..30d4c65221 100644 --- a/dom/canvas/WebGLContextValidate.cpp +++ b/dom/canvas/WebGLContextValidate.cpp @@ -695,6 +695,18 @@ WebGLContext::InitAndValidateGL(FailureReason* const out_failReason) gl->fEnable(LOCAL_GL_PROGRAM_POINT_SIZE); } +#ifdef XP_MACOSX + if (gl->WorkAroundDriverBugs() && + gl->Vendor() == gl::GLVendor::ATI && + !nsCocoaFeatures::IsAtLeastVersion(10,9)) + { + // The Mac ATI driver, in all known OSX version up to and including + // 10.8, renders points sprites upside-down. (Apple bug 11778921) + gl->fPointParameterf(LOCAL_GL_POINT_SPRITE_COORD_ORIGIN, + LOCAL_GL_LOWER_LEFT); + } +#endif + if (gl->IsSupported(gl::GLFeature::seamless_cube_map_opt_in)) { gl->fEnable(LOCAL_GL_TEXTURE_CUBE_MAP_SEAMLESS); } diff --git a/dom/canvas/WebGLProgram.cpp b/dom/canvas/WebGLProgram.cpp index 1ff27e1d2f..9b204358bb 100644 --- a/dom/canvas/WebGLProgram.cpp +++ b/dom/canvas/WebGLProgram.cpp @@ -689,6 +689,24 @@ WebGLProgram::GetFragDataLocation(const nsAString& userName_wide) const gl->MakeCurrent(); const NS_LossyConvertUTF16toASCII userName(userName_wide); +#ifdef XP_MACOSX + if (gl->WorkAroundDriverBugs()) { + // OSX doesn't return locs for indexed names, just the base names. + // Indicated by failure in: conformance2/programs/gl-get-frag-data-location.html + bool isArray; + size_t arrayIndex; + nsCString baseUserName; + if (!ParseName(userName, &baseUserName, &isArray, &arrayIndex)) + return -1; + + if (arrayIndex >= mContext->mImplMaxDrawBuffers) + return -1; + + const auto baseLoc = GetFragDataByUserName(this, baseUserName); + const auto loc = baseLoc + GLint(arrayIndex); + return loc; + } +#endif return GetFragDataByUserName(this, userName); } @@ -752,6 +770,11 @@ WebGLProgram::GetProgramParameter(GLenum pname) const return JS::BooleanValue(IsLinked()); case LOCAL_GL_VALIDATE_STATUS: +#ifdef XP_MACOSX + // See comment in ValidateProgram. + if (gl->WorkAroundDriverBugs()) + return JS::BooleanValue(true); +#endif // Todo: Implement this in our code. return JS::BooleanValue(bool(GetProgramiv(gl, mGLName, pname))); @@ -1354,6 +1377,17 @@ WebGLProgram::ValidateProgram() const { mContext->MakeContextCurrent(); gl::GLContext* gl = mContext->gl; + +#ifdef XP_MACOSX + // See bug 593867 for NVIDIA and bug 657201 for ATI. The latter is confirmed + // with Mac OS 10.6.7. + if (gl->WorkAroundDriverBugs()) { + mContext->GenerateWarning("validateProgram: Implemented as a no-op on" + " Mac to work around crashes."); + return; + } +#endif + gl->fValidateProgram(mGLName); } diff --git a/dom/canvas/WebGLShaderValidator.cpp b/dom/canvas/WebGLShaderValidator.cpp index eadeeb56b0..bf2df82f71 100644 --- a/dom/canvas/WebGLShaderValidator.cpp +++ b/dom/canvas/WebGLShaderValidator.cpp @@ -63,8 +63,34 @@ ChooseValidatorCompileOptions(const ShBuiltInResources& resources, SH_REGENERATE_STRUCT_NAMES; } - // We want to do this everywhere. +#ifndef XP_MACOSX + // We want to do this everywhere, but to do this on Mac, we need + // to do it only on Mac OSX > 10.6 as this causes the shader + // compiler in 10.6 to crash options |= SH_CLAMP_INDIRECT_ARRAY_BOUNDS; +#endif + +#ifdef XP_MACOSX + if (gl->WorkAroundDriverBugs()) { + // Work around https://bugs.webkit.org/show_bug.cgi?id=124684, + // https://chromium.googlesource.com/angle/angle/+/5e70cf9d0b1bb + options |= SH_UNFOLD_SHORT_CIRCUIT; + + // OS X 10.7/10.8 specific: + + // Work around bug 665578 and bug 769810 + if (gl->Vendor() == gl::GLVendor::ATI) { + options |= SH_EMULATE_BUILT_IN_FUNCTIONS; + } + // Work around bug 735560 + if (gl->Vendor() == gl::GLVendor::Intel) { + options |= SH_EMULATE_BUILT_IN_FUNCTIONS; + } + + // Work around that Mac drivers handle struct scopes incorrectly. + options |= SH_REGENERATE_STRUCT_NAMES; + } +#endif if (resources.MaxExpressionComplexity > 0) { options |= SH_LIMIT_EXPRESSION_COMPLEXITY; @@ -161,6 +187,15 @@ WebGLContext::CreateShaderValidator(GLenum shaderType) const // If underlying GLES doesn't have highp in frag shaders, it should complain anyways. resources.FragmentPrecisionHigh = mDisableFragHighP ? 0 : 1; + if (gl->WorkAroundDriverBugs()) { +#ifdef XP_MACOSX + if (gl->Vendor() == gl::GLVendor::NVIDIA) { + // Work around bug 890432 + resources.MaxExpressionComplexity = 1000; + } +#endif + } + int compileOptions = webgl::ChooseValidatorCompileOptions(resources, gl); return webgl::ShaderValidator::Create(shaderType, spec, outputLanguage, resources, compileOptions); |