Bug 1207288. Ask ANGLE for the correct output version. r=jgilbert

This commit is contained in:
Jeff Muizelaar 2015-11-27 15:54:50 -05:00
parent e8278c18c7
commit b30c9f6295
4 changed files with 135 additions and 8 deletions

View File

@ -93,11 +93,9 @@ TranslateWithoutValidation(const nsACString& sourceNS, bool isWebGL2,
switch (glesslVersion) {
case 100:
if (!versionStrLen) {
/* According to ARB_ES2_compatibility extension glsl
* should accept #version 100 for ES 2 shaders. */
reversionedSource.insert(versionStrStart, "#version 100\n");
}
/* According to ARB_ES2_compatibility extension glsl
* should accept #version 100 for ES 2 shaders. */
reversionedSource.insert(versionStrStart, "#version 100\n");
break;
case 300:
reversionedSource.insert(versionStrStart, "#version 330\n");

View File

@ -93,6 +93,34 @@ ChooseValidatorCompileOptions(const ShBuiltInResources& resources,
////////////////////////////////////////
static ShShaderOutput
ShaderOutput(gl::GLContext* gl)
{
if (gl->IsGLES()) {
return SH_ESSL_OUTPUT;
} else {
uint32_t version = gl->ShadingLanguageVersion();
switch (version) {
case 100: return SH_GLSL_COMPATIBILITY_OUTPUT;
case 120: return SH_GLSL_COMPATIBILITY_OUTPUT;
case 130: return SH_GLSL_130_OUTPUT;
case 140: return SH_GLSL_140_OUTPUT;
case 150: return SH_GLSL_150_CORE_OUTPUT;
case 330: return SH_GLSL_330_CORE_OUTPUT;
case 400: return SH_GLSL_400_CORE_OUTPUT;
case 410: return SH_GLSL_410_CORE_OUTPUT;
case 420: return SH_GLSL_420_CORE_OUTPUT;
case 430: return SH_GLSL_430_CORE_OUTPUT;
case 440: return SH_GLSL_440_CORE_OUTPUT;
case 450: return SH_GLSL_450_CORE_OUTPUT;
default:
MOZ_CRASH("Unexpected GLSL version.");
}
}
return SH_GLSL_OUTPUT;
}
webgl::ShaderValidator*
WebGLContext::CreateShaderValidator(GLenum shaderType) const
{
@ -100,9 +128,7 @@ WebGLContext::CreateShaderValidator(GLenum shaderType) const
return nullptr;
ShShaderSpec spec = IsWebGL2() ? SH_WEBGL2_SPEC : SH_WEBGL_SPEC;
ShShaderOutput outputLanguage = gl->IsGLES() ? SH_ESSL_OUTPUT
: SH_GLSL_OUTPUT;
ShShaderOutput outputLanguage = ShaderOutput(gl);
ShBuiltInResources resources;
memset(&resources, 0, sizeof(resources));
ShInitBuiltInResources(&resources);

View File

@ -179,6 +179,97 @@ static const char *sExtensionNames[] = {
"GL_OES_vertex_array_object"
};
static bool
ParseGLSLVersion(GLContext* gl, uint32_t* out_version)
{
if (gl->fGetError() != LOCAL_GL_NO_ERROR) {
MOZ_ASSERT(false, "An OpenGL error has been triggered before.");
return false;
}
/**
* OpenGL 2.x, 3.x, 4.x specifications:
* The VERSION and SHADING_LANGUAGE_VERSION strings are laid out as follows:
*
* <version number><space><vendor-specific information>
*
* The version number is either of the form major_number.minor_number or
* major_number.minor_number.release_number, where the numbers all have
* one or more digits.
*
* SHADING_LANGUAGE_VERSION is *almost* identical to VERSION. The
* difference is that the minor version always has two digits and the
* prefix has an additional 'GLSL ES'
*
*
* OpenGL ES 2.0, 3.0 specifications:
* The VERSION string is laid out as follows:
*
* "OpenGL ES N.M vendor-specific information"
*
* The version number is either of the form major_number.minor_number or
* major_number.minor_number.release_number, where the numbers all have
* one or more digits.
*
*
* Note:
* We don't care about release_number.
*/
const char* versionString = (const char*) gl->fGetString(LOCAL_GL_SHADING_LANGUAGE_VERSION);
if (gl->fGetError() != LOCAL_GL_NO_ERROR) {
MOZ_ASSERT(false, "glGetString(GL_SHADING_LANGUAGE_VERSION) has generated an error");
return false;
}
if (!versionString) {
// This happens on the Android emulators. We'll just return 100
*out_version = 100;
return true;
}
const char kGLESVersionPrefix[] = "OpenGL ES GLSL ES";
if (strncmp(versionString, kGLESVersionPrefix, strlen(kGLESVersionPrefix)) == 0)
versionString += strlen(kGLESVersionPrefix);
const char* itr = versionString;
char* end = nullptr;
auto majorVersion = strtol(itr, &end, 10);
if (!end) {
MOZ_ASSERT(false, "Failed to parse the GL major version number.");
return false;
}
if (*end != '.') {
MOZ_ASSERT(false, "Failed to parse GL's major-minor version number separator.");
return false;
}
// we skip the '.' between the major and the minor version
itr = end + 1;
end = nullptr;
auto minorVersion = strtol(itr, &end, 10);
if (!end) {
MOZ_ASSERT(false, "Failed to parse GL's minor version number.");
return false;
}
if (majorVersion <= 0 || majorVersion >= 100) {
MOZ_ASSERT(false, "Invalid major version.");
return false;
}
if (minorVersion < 0 || minorVersion >= 100) {
MOZ_ASSERT(false, "Invalid minor version.");
return false;
}
*out_version = (uint32_t) majorVersion * 100 + (uint32_t) minorVersion;
return true;
}
static bool
ParseGLVersion(GLContext* gl, uint32_t* out_version)
{
@ -303,6 +394,7 @@ GLContext::GLContext(const SurfaceCaps& caps,
mContextLost(false),
mVersion(0),
mProfile(ContextProfile::Unknown),
mShadingLanguageVersion(0),
mVendor(GLVendor::Other),
mRenderer(GLRenderer::Other),
mHasRobustness(false),
@ -515,8 +607,12 @@ GLContext::InitWithPrefix(const char *prefix, bool trygl)
uint32_t version = 0;
ParseGLVersion(this, &version);
uint32_t shadingLangVersion = 100;
ParseGLSLVersion(this, &shadingLangVersion);
if (ShouldSpew()) {
printf_stderr("OpenGL version detected: %u\n", version);
printf_stderr("OpenGL shading language version detected: %u\n", shadingLangVersion);
printf_stderr("OpenGL vendor: %s\n", fGetString(LOCAL_GL_VENDOR));
printf_stderr("OpenGL renderer: %s\n", fGetString(LOCAL_GL_RENDERER));
}
@ -524,6 +620,7 @@ GLContext::InitWithPrefix(const char *prefix, bool trygl)
if (version >= mVersion) {
mVersion = version;
}
// Don't fail if version < mVersion, see bug 999445,
// Mac OSX 10.6/10.7 machines with Intel GPUs claim only OpenGL 1.4 but
// have all the GL2+ extensions that we need.

View File

@ -302,6 +302,10 @@ public:
return mVersionString.get();
}
inline uint32_t ShadingLanguageVersion() const {
return mShadingLanguageVersion;
}
GLVendor Vendor() const {
return mVendor;
}
@ -346,6 +350,8 @@ protected:
nsCString mVersionString;
ContextProfile mProfile;
uint32_t mShadingLanguageVersion;
GLVendor mVendor;
GLRenderer mRenderer;