Re-land: Don't expose non-conformant multisampling modes on GL

Re-landing with a fallback for failed internal format queries to work
around issue seen on Shield TV. Also fixed wrong handling of integer
RG formats in isRequiredRenderbufferFormat.

Some NVIDIA GL drivers expose non-conformant multisampling modes. The
conformance of multisampling modes can be queried using the extension
NV_internalformat_sample_query. Use it to filter out the
non-conformant modes from the modes that are exposed by ANGLE.

The MAX_SAMPLES value and other similar values stored in caps also
need to be lowered to match the maximum number of samples exposed
for required formats.

There seems to be an NVIDIA driver bug related to querying
STENCIL_INDEX8 multisample format. Work around this by querying
DEPTH24_STENCIL8 instead.

There's also some confusion around whether RGB9_E5 should be
renderable. Once the floating point texture extensions got rolled
into the core GL spec, it was eventually made clear that RGB9_E5
is intended not to be renderable. The extension specs that predate
float textures in the core spec do suggest that it would be
renderable, but in practice drivers that advertise the extension
strings don't reliably implement RGB9_E5 as renderable. Solve this
by disabling it as a renderable format and adding an explanatory
comment.

BUG=chromium:682815
TEST=angle_end2end_tests,
     dEQP-GLES31.functional.state_query.internal_format.renderbuffer.*

Change-Id: I727f03045a1534d6764b571e6d839243705d25b3
Reviewed-on: https://chromium-review.googlesource.com/551957
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Commit-Queue: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libANGLE/renderer/gl/FunctionsGL.cpp b/src/libANGLE/renderer/gl/FunctionsGL.cpp
index 2cf269d..21ea375 100644
--- a/src/libANGLE/renderer/gl/FunctionsGL.cpp
+++ b/src/libANGLE/renderer/gl/FunctionsGL.cpp
@@ -789,7 +789,8 @@
       primitiveBoundingBox(nullptr),
       eglImageTargetRenderbufferStorageOES(nullptr),
       eglImageTargetTexture2DOES(nullptr),
-      discardFramebuffer(nullptr)
+      discardFramebuffer(nullptr),
+      getInternalformatSampleivNV(nullptr)
 {
 }
 
@@ -848,6 +849,9 @@
     // Even though extensions are written against specific versions of GL, many drivers expose the extensions
     // in even older versions.  Always try loading the extensions regardless of GL version.
 
+    // GL_NV_internalformat_sample_query
+    ASSIGN_WITH_EXT("GL_NV_internalformat_sample_query", "glGetInternalformatSampleivNV", getInternalformatSampleivNV);
+
     // GL_ARB_program_interface_query (loading only functions relevant to GL_NV_path_rendering here)
     ASSIGN_WITH_EXT("GL_ARB_program_interface_query", "glGetProgramInterfaceiv", getProgramInterfaceiv);
     ASSIGN_WITH_EXT("GL_ARB_program_interface_query", "glGetProgramResourceName", getProgramResourceName);
@@ -1799,6 +1803,9 @@
 
     // clang-format off
 
+    // GL_NV_internalformat_sample_query
+    ASSIGN_WITH_EXT("GL_NV_internalformat_sample_query", "glGetInternalformatSampleivNV", getInternalformatSampleivNV);
+
     // GL_NV_path_rendering
     ASSIGN_WITH_EXT("GL_NV_path_rendering", "glMatrixLoadfEXT", matrixLoadEXT);
     ASSIGN_WITH_EXT("GL_NV_path_rendering", "glGenPathsNV", genPathsNV);