mesa/main: fix inverted condition
[mesa.git] / src / mesa / main / performance_query.c
index aa103516a58ec8e5c93e4a41613c84b24777b808..c5825a7da3a533548288efcd3ac8cc1b4aa668d7 100644 (file)
@@ -48,6 +48,12 @@ free_performance_query(GLuint key, void *data, void *user)
    struct gl_perf_query_object *m = data;
    struct gl_context *ctx = user;
 
+   /* Don't confuse the implementation by deleting an active query. We can
+    * toggle Active/Used to false because we're tearing down the GL context
+    * and it's already idle (see _mesa_free_context_data).
+    */
+   m->Active = false;
+   m->Used = false;
    ctx->Driver.DeletePerfQuery(ctx, m);
 }
 
@@ -90,8 +96,12 @@ index_to_queryid(unsigned index)
 static inline bool
 queryid_valid(const struct gl_context *ctx, unsigned numQueries, GLuint queryid)
 {
-   GLuint index = queryid_to_index(queryid);
-   return index >= 0 && index < numQueries;
+   /* The GL_INTEL_performance_query spec says:
+    *
+    *  "Performance counter ids values start with 1. Performance counter id 0
+    *  is reserved as an invalid counter."
+    */
+   return queryid != 0 && queryid_to_index(queryid) < numQueries;
 }
 
 static inline GLuint
@@ -345,7 +355,7 @@ _mesa_GetPerfCounterInfoINTEL(GLuint queryId, GLuint counterId,
 
    counterIndex = counterid_to_index(counterId);
 
-   if (counterIndex < 0 || counterIndex >= queryNumCounters) {
+   if (counterIndex >= queryNumCounters) {
       _mesa_error(ctx, GL_INVALID_VALUE,
                   "glGetPerfCounterInfoINTEL(invalid counterId)");
       return;
@@ -607,6 +617,15 @@ _mesa_GetPerfQueryDataINTEL(GLuint queryHandle, GLuint flags,
     */
    *bytesWritten = 0;
 
+   /* Not explicitly covered in the spec but a query that was never started
+    * cannot return any data.
+    */
+   if (!obj->Used) {
+      _mesa_error(ctx, GL_INVALID_OPERATION,
+                  "glGetPerfQueryDataINTEL(query never began)");
+      return;
+   }
+
    /* Not explicitly covered in the spec but to be consistent with
     * EndPerfQuery which validates that an application only ends an
     * active query we also validate that an application doesn't try