+
+ /* From the OpenGL 4.5 specification, section 11.3.1:
+ *
+ * The error INVALID_OPERATION is generated if Begin, or any command that
+ * implicitly calls Begin, is called when a geometry shader is active and:
+ *
+ * * the input primitive type of the current geometry shader is
+ * POINTS and <mode> is not POINTS,
+ *
+ * * the input primitive type of the current geometry shader is
+ * LINES and <mode> is not LINES, LINE_STRIP, or LINE_LOOP,
+ *
+ * * the input primitive type of the current geometry shader is
+ * TRIANGLES and <mode> is not TRIANGLES, TRIANGLE_STRIP or
+ * TRIANGLE_FAN,
+ *
+ * * the input primitive type of the current geometry shader is
+ * LINES_ADJACENCY_ARB and <mode> is not LINES_ADJACENCY_ARB or
+ * LINE_STRIP_ADJACENCY_ARB, or
+ *
+ * * the input primitive type of the current geometry shader is
+ * TRIANGLES_ADJACENCY_ARB and <mode> is not
+ * TRIANGLES_ADJACENCY_ARB or TRIANGLE_STRIP_ADJACENCY_ARB.
+ *
+ * The GL spec doesn't mention any interaction with tessellation, which
+ * is clearly a spec bug. The same rule should apply, but instead of
+ * the draw primitive mode, the tessellation evaluation shader primitive
+ * mode should be used for the checking.
+ */
+ if (ctx->_Shader->CurrentProgram[MESA_SHADER_GEOMETRY]) {
+ const GLenum geom_mode =
+ ctx->_Shader->CurrentProgram[MESA_SHADER_GEOMETRY]->
+ _LinkedShaders[MESA_SHADER_GEOMETRY]->info.Geom.InputType;
+ struct gl_shader_program *tes =
+ ctx->_Shader->CurrentProgram[MESA_SHADER_TESS_EVAL];
+ GLenum mode_before_gs = mode;
+
+ if (tes) {
+ struct gl_linked_shader *tes_sh =
+ tes->_LinkedShaders[MESA_SHADER_TESS_EVAL];
+ if (tes_sh->info.TessEval.PointMode)
+ mode_before_gs = GL_POINTS;
+ else if (tes_sh->info.TessEval.PrimitiveMode == GL_ISOLINES)
+ mode_before_gs = GL_LINES;
+ else
+ /* the GL_QUADS mode generates triangles too */
+ mode_before_gs = GL_TRIANGLES;
+ }
+
+ switch (mode_before_gs) {
+ case GL_POINTS:
+ valid_enum = (geom_mode == GL_POINTS);
+ break;
+ case GL_LINES:
+ case GL_LINE_LOOP:
+ case GL_LINE_STRIP:
+ valid_enum = (geom_mode == GL_LINES);
+ break;
+ case GL_TRIANGLES:
+ case GL_TRIANGLE_STRIP:
+ case GL_TRIANGLE_FAN:
+ valid_enum = (geom_mode == GL_TRIANGLES);
+ break;
+ case GL_QUADS:
+ case GL_QUAD_STRIP:
+ case GL_POLYGON:
+ valid_enum = false;
+ break;
+ case GL_LINES_ADJACENCY:
+ case GL_LINE_STRIP_ADJACENCY:
+ valid_enum = (geom_mode == GL_LINES_ADJACENCY);
+ break;
+ case GL_TRIANGLES_ADJACENCY:
+ case GL_TRIANGLE_STRIP_ADJACENCY:
+ valid_enum = (geom_mode == GL_TRIANGLES_ADJACENCY);
+ break;
+ default:
+ valid_enum = false;
+ break;
+ }
+ if (!valid_enum) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "%s(mode=%s vs geometry shader input %s)",
+ name,
+ _mesa_lookup_prim_by_nr(mode_before_gs),
+ _mesa_lookup_prim_by_nr(geom_mode));
+ return GL_FALSE;
+ }
+ }
+
+ /* From the OpenGL 4.0 (Core Profile) spec (section 2.12):
+ *
+ * "Tessellation operates only on patch primitives. If tessellation is
+ * active, any command that transfers vertices to the GL will
+ * generate an INVALID_OPERATION error if the primitive mode is not
+ * PATCHES.
+ * Patch primitives are not supported by pipeline stages below the
+ * tessellation evaluation shader. If there is no active program
+ * object or the active program object does not contain a tessellation
+ * evaluation shader, the error INVALID_OPERATION is generated by any
+ * command that transfers vertices to the GL if the primitive mode is
+ * PATCHES."
+ *
+ */
+ if (ctx->_Shader->CurrentProgram[MESA_SHADER_TESS_EVAL] ||
+ ctx->_Shader->CurrentProgram[MESA_SHADER_TESS_CTRL]) {
+ if (mode != GL_PATCHES) {
+ _mesa_error(ctx, GL_INVALID_OPERATION,
+ "only GL_PATCHES valid with tessellation");
+ return GL_FALSE;
+ }