mesa/es3: Allow transpose matrix uniforms in GLES3

Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
mesa/es3: Add support for GL_ANY_SAMPLES_PASSED_CONSERVATIVE query target

Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
mesa/es3: Add support for GL_PRIMITIVE_RESTART_FIXED_INDEX

This requires some derived state.  The cut vertex used is either the
value specified by glPrimitiveRestartIndex or it's hard-coded to ~0.
The derived state gl_array_attrib::_RestartIndex captures this value.
In addition, the derived state gl_array_attrib::_PrimitiveRestart is set
whenever either gl_array_attrib::PrimitiveRestart or
gl_array_attrib::PrimitiveRestartFixedIndex is set.

v2: Use _mesa_is_gles3.

Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
mesa: Rework crazy error code rules in glDrawBuffers().

Perhaps most importantly, this patch adds comments quoting the relevant
spec paragraphs above each error condition.

It also makes three changes:
- For FBOs, GL_COLOR_ATTACHMENTm where m >= MaxDrawBuffers is supposed
  to generate INVALID_OPERATION (not INVALID_ENUM).
- Constants that refer to multiple buffers (such as FRONT, BACK, LEFT,
  RIGHT, and FRONT_AND_BACK) are supposed to generate INVALID_OPERATION,
  not INVALID_ENUM.
- In ES 3.0, for FBOs, buffers[i] must be NONE or GL_COLOR_ATTACHMENTi
  or else INVALID_OPERATION occurs.  (This is a new restriction.)

Fixes es3conform's draw-buffers-api test.
mesa: Fix default value of BUFFER_ACCESS_FLAGS.

According to both the GL 3.0 and ES 3.0 specifications (table 2.7 for GL
and table 2.8 for ES), the default value of BUFFER_ACCESS_FLAGS is
supposed to be zero.

Note that there are two related quantities: the obsolete BUFFER_ACCESS
enum and the new BUFFER_ACCESS_FLAGS bitfield.

BUFFER_ACCESS can only be GL_READ_ONLY, GL_WRITE_ONLY, or GL_READ_WRITE;
BUFFER_ACCESS_FLAGS can easily represent all three via GL_MAP_WRITE_BIT,
GL_MAP_READ_BIT, and their logical or.  It also supports more flags.

Thus, Mesa only stores the bitfield, and simply computes the old enum
when queried, via simplified_access_mode(bufObj->AccessFlags).

The tricky part is that, while BUFFER_ACCESS_FLAGS defaults to 0,
BUFFER_ACCESS defaults to GL_READ_WRITE for desktop [GL 3.0, table 2.8]
and GL_WRITE_ONLY_OES for ES [the GL_EXT_map_buffer_range extension].

Mesa tried to implement this by setting the default AccessFlags to
GL_MAP_READ_BIT | GL_MAP_WRITE_BIT on desktop, and GL_MAP_WRITE_BIT on
ES.  But in all specifications, it needs to be 0.

This patch moves that logic into simplified_access_mode(): when
AccessFlags == 0, it now returns GL_READ_WRITE for desktop and
GL_WRITE_ONLY for ES 1/2.  (BUFFER_ACCESS doesn't exist on ES 3.0,
so it's irrelevant there.)

With that in place, it changes the AccessFlags default to 0.

Fixes three es3conform tsets:
- copy_buffer_defaults
- map_buffer_range_modify_indices
- pixel_buffer_object_default_parameters
mesa: Reject texture-only formats as renderbuffer formats in ES 3

ES 3 specifies some formats as texture-only (i.e., not available for
renderbuffers).

See the "Required Texture Formats" section (pg 126) of the ES 3 spec.

Fixes es3conform's color_buffer_unsupported_format test.
Acked-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Anuj Phogat <anuj.phogat@gmail.com>
mesa: Allow HALF_FLOAT in glVertexAttribPointer

Fixes es3conform's half_float_max_vertex_dimensions and
half_float_textures tests.
mesa: Use _mesa_lookup_enum_by_nr in tex*_error_check

Reviewed-by: Brian Paul <brianp@vmware.com>
mesa: Return INVALID_OPERATION when type is known but not allowed

INVALID_ENUM is for when the type is simply not known.

Fixes part of es3conform's packed_depth_stencil_error test.
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
mesa: Return INVALID_ENUM for glReadPixels(..., GL_DEPTH_*, ...) on ES 3

I'm not sure if this is the correct fix. The
_mesa_es_error_check_format_and_type function (used above in the ES 1
and 2 cases) was originally added for glTexImage checking and allows
GL_DEPTH_STENCIL/GL_UNSIGNED_INT_24_8 combinations. Using it in ES 3
causes other tests to regress.

Fixes es3conform's packed_depth_stencil_error test.
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> (v1)
Reviewed-by: Anuj Phogat <anuj.phogat@gmail.com>
glcpp: Add a flag to the parser state to indicate GLES.

This can be triggered either by creation of a GLES context (with
api == API_OPENGLES2) or else by a #version directive with version
value 100 or with a string of "es" following the version value.

There's no behavioral change with this commit—just preparation for ES-specific
behavior in the preprocessor in the future.

Reviewed-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
glcpp: Make undefined macros illegal in #if and #elif for GLES3

Simply emitting a nicely-formatted error message if any undefined macro is
encountered in a parser context expecting an expression.

With this commit, the following piglit test now passes:

	spec/glsl-es-3.00/compiler/undefined-macro.vert

Reviewed-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
glcpp: Reject token pasting operator in GLES

The GLSL ES 3.0 spec (Section 12.17) says:
"GLSL ES 1.00 removed token pasting and other functionality."

NOTE: This is a candidate for the stable branches.
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Carl Worth <cworth@cworth.org>
mesa/es3: Enable ES 3.0 API and shading language version

Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
i965: Add support for GL_ANY_SAMPLES_PASSED_CONSERVATIVE

We just treat this as an alias for GL_ANY_SAMPLES_PASSED.

Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
i965/Gen6+: Enable ARB_ES3_compatibility extension

IMPORTANT: this patch should not be pushed to master until ES3 support
is fully implemented on i965/Gen6+.
i965: Bump maximum supported ES2 context version to 3.0

Since patch "i965: Validate requested GLES context version in
brwCreateContext", we have been able to create ES 3.0 contexts due to the
max version check.  So...bump the max version.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
intel: Set screen's api mask according to hw capabilities (v3)

Before this patch, intelInitScreen2 set DRIScreen::api_mask with the hacky
heuristic below:

    if (gen >= 3)
        api_mask = GL | GLES1 | GLES2;
    else
        api_mask = 0;

This hack was likely broken on gen2 (i830), but I don't care enough to
properly investigate. It appears that every EGLConfig on i830 has
EGL_RENDERABLE_TYPE=0, and thus eglCreateContext will never succeed.
Anyway, moving on to living drivers...

With the arrival of EGL_OPENGL_ES3_BIT_KHR, this heuristic is now
insufficient. We must enable the GLES3 bit if and only if the driver is
capable of creating a GLES3 context. This requires us to determine the
maximum supported context version supported by the hardware/driver for
each api *during initialization of intel_screen*.

Therefore, this patch adds four new fields to intel_screen which indicate
the maximum supported context version for each api:
  max_gl_core_version
  max_gl_compat_version
  max_gl_es1_version
  max_gl_es2_version

The api mask is now correctly set as:

    api_mask = GL;
    if (max_gl_es1_version > 0)
        api_mask |= GLES1;
    if (max_gl_es2_version > 0)
        api_mask |= GLES2;

Tested against gen6 with piglit egl-create-context-verify-gl-flavor.
Verified that this patch does not change the set of exposed EGL context
flavors.

v2:
  - Replace the if-tree on gen with a switch, for Ian.
  - Unconditionally enable the DRI_API_OPENGL bit, for Ian.

v3:
  - Drop max gl version to 1.4 on gen3 if !has_occlusion_query,
    because occlusion queries entered core in 1.5. For Ian.

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
Reviewed-by: Ian Romanick <ian.d.romanick.intel.com>
intel: Move validation of context version into intelInitContext

Each driver (i830, i915, i965) used independent but similar code to
validate the requested context version. With the rececnt arrival of GLES3,
that logic has needed an update. Rather than apply identical updates to
each drivers validation code, let's just move the validation into the
shared routine intelInitContext.

This refactor required some incidental changes to functions
i830CreateContext and intelInitContext. For each function, this patch:
    - Adds context version parameters to the signature.
    - Adds a DRI_CTX_ERROR out param to the signature.
    - Sets the DRI_CTX_ERROR at each early return.

Tested against gen6 with piglit egl-create-context-verify-gl-flavor.
Verified that this patch does not change the set of exposed EGL context
flavors.

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
dri: Define enum __DRI_API_GLES3

This enum corresponds to EGL_OPENGL_ES3_BIT_KHR.
Neither the GLX nor EGL layer use the enum yet.

I don't like the GLES bits. I'd prefer that all GLES APIs be exposed
through a single API bit, as is done in GLX_EXT_create_context_es_profile.
But, we need this GLES3 enum in order to do the plumbing necessary to
correctly support EGL_OPENGL_ES3_BIT_KHR as required by the
EGL_KHR_create_context spec.

Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>