mesa/varray: split update_array() into validate_array() and update_array()
[mesa.git] / src / mesa / main / performance_monitor.c
index 597f633f6f9c42d1f847d13a3e2581e87c7622fd..65ea8437fd887e95b50e3e08395c75da6c0d8068 100644 (file)
@@ -42,8 +42,8 @@
 #include "macros.h"
 #include "mtypes.h"
 #include "performance_monitor.h"
-#include "bitset.h"
-#include "ralloc.h"
+#include "util/bitset.h"
+#include "util/ralloc.h"
 
 void
 _mesa_init_performance_monitors(struct gl_context *ctx)
@@ -53,6 +53,13 @@ _mesa_init_performance_monitors(struct gl_context *ctx)
    ctx->PerfMonitor.Groups = NULL;
 }
 
+static inline void
+init_groups(struct gl_context *ctx)
+{
+   if (unlikely(!ctx->PerfMonitor.Groups))
+      ctx->Driver.InitPerfMonitorGroups(ctx);
+}
+
 static struct gl_perf_monitor_object *
 new_performance_monitor(struct gl_context *ctx, GLuint index)
 {
@@ -144,6 +151,7 @@ _mesa_GetPerfMonitorGroupsAMD(GLint *numGroups, GLsizei groupsSize,
                               GLuint *groups)
 {
    GET_CURRENT_CONTEXT(ctx);
+   init_groups(ctx);
 
    if (numGroups != NULL)
       *numGroups = ctx->PerfMonitor.NumGroups;
@@ -164,7 +172,11 @@ _mesa_GetPerfMonitorCountersAMD(GLuint group, GLint *numCounters,
                                 GLsizei countersSize, GLuint *counters)
 {
    GET_CURRENT_CONTEXT(ctx);
-   const struct gl_perf_monitor_group *group_obj = get_group(ctx, group);
+   const struct gl_perf_monitor_group *group_obj;
+
+   init_groups(ctx);
+
+   group_obj = get_group(ctx, group);
    if (group_obj == NULL) {
       _mesa_error(ctx, GL_INVALID_VALUE,
                   "glGetPerfMonitorCountersAMD(invalid group)");
@@ -192,9 +204,11 @@ _mesa_GetPerfMonitorGroupStringAMD(GLuint group, GLsizei bufSize,
                                    GLsizei *length, GLchar *groupString)
 {
    GET_CURRENT_CONTEXT(ctx);
+   const struct gl_perf_monitor_group *group_obj;
 
-   const struct gl_perf_monitor_group *group_obj = get_group(ctx, group);
+   init_groups(ctx);
 
+   group_obj = get_group(ctx, group);
    if (group_obj == NULL) {
       _mesa_error(ctx, GL_INVALID_VALUE, "glGetPerfMonitorGroupStringAMD");
       return;
@@ -224,6 +238,8 @@ _mesa_GetPerfMonitorCounterStringAMD(GLuint group, GLuint counter,
    const struct gl_perf_monitor_group *group_obj;
    const struct gl_perf_monitor_counter *counter_obj;
 
+   init_groups(ctx);
+
    group_obj = get_group(ctx, group);
 
    if (group_obj == NULL) {
@@ -263,6 +279,8 @@ _mesa_GetPerfMonitorCounterInfoAMD(GLuint group, GLuint counter, GLenum pname,
    const struct gl_perf_monitor_group *group_obj;
    const struct gl_perf_monitor_counter *counter_obj;
 
+   init_groups(ctx);
+
    group_obj = get_group(ctx, group);
 
    if (group_obj == NULL) {
@@ -326,6 +344,8 @@ _mesa_GenPerfMonitorsAMD(GLsizei n, GLuint *monitors)
    if (MESA_VERBOSE & VERBOSE_API)
       _mesa_debug(ctx, "glGenPerfMonitorsAMD(%d)\n", n);
 
+   init_groups(ctx);
+
    if (n < 0) {
       _mesa_error(ctx, GL_INVALID_VALUE, "glGenPerfMonitorsAMD(n < 0)");
       return;
@@ -544,11 +564,10 @@ perf_monitor_result_size(const struct gl_context *ctx,
 
    for (group = 0; group < ctx->PerfMonitor.NumGroups; group++) {
       const struct gl_perf_monitor_group *g = &ctx->PerfMonitor.Groups[group];
-      for (counter = 0; counter < g->NumCounters; counter++) {
-         const struct gl_perf_monitor_counter *c = &g->Counters[counter];
+      BITSET_WORD tmp;
 
-         if (!BITSET_TEST(m->ActiveCounters[group], counter))
-            continue;
+      BITSET_FOREACH_SET(counter, tmp, m->ActiveCounters[group], g->NumCounters) {
+         const struct gl_perf_monitor_counter *c = &g->Counters[counter];
 
          size += sizeof(uint32_t); /* Group ID */
          size += sizeof(uint32_t); /* Counter ID */
@@ -639,222 +658,3 @@ _mesa_perf_monitor_counter_size(const struct gl_perf_monitor_counter *c)
       return 0;
    }
 }
-
-extern void GLAPIENTRY
-_mesa_GetFirstPerfQueryIdINTEL(GLuint *queryId)
-{
-   GET_CURRENT_CONTEXT(ctx);
-
-   /* The GL_INTEL_performance_query spec says:
-    *
-    *    "If queryId pointer is equal to 0, INVALID_VALUE error is generated."
-    */
-   if (!queryId) {
-      _mesa_error(ctx, GL_INVALID_VALUE,
-                  "glGetFirstPerfQueryIdINTEL(queryId == NULL)");
-      return;
-   }
-
-   /* The GL_INTEL_performance_query spec says:
-    *
-    *    "If the given hardware platform doesn't support any performance
-    *    queries, then the value of 0 is returned and INVALID_OPERATION error
-    *    is raised."
-    */
-
-   *queryId = 0;
-   _mesa_error(ctx, GL_INVALID_OPERATION,
-               "glGetFirstPerfQueryIdINTEL(no queries supported)");
-}
-
-extern void GLAPIENTRY
-_mesa_GetNextPerfQueryIdINTEL(GLuint queryId, GLuint *nextQueryId)
-{
-   GET_CURRENT_CONTEXT(ctx);
-
-   /* The GL_INTEL_performance_query spec says:
-    *
-    *    "If nextQueryId pointer is equal to 0, an INVALID_VALUE error is
-    *    generated."
-    */
-   if (!nextQueryId) {
-      _mesa_error(ctx, GL_INVALID_VALUE,
-                  "glGetNextPerfQueryIdINTEL(nextQueryId == NULL)");
-      return;
-   }
-
-   /* The GL_INTEL_performance_query spec says:
-    *
-    *    "If the specified performance query identifier is invalid then
-    *    INVALID_VALUE error is generated. Whenever error is generated, the
-    *    value of 0 is returned."
-    *
-    * No queries are supported, so all queries are invalid.
-    */
-   *nextQueryId = 0;
-   _mesa_error(ctx, GL_INVALID_VALUE,
-               "glGetNextPerfQueryIdINTEL(invalid query)");
-}
-
-extern void GLAPIENTRY
-_mesa_GetPerfQueryIdByNameINTEL(char *queryName, GLuint *queryId)
-{
-   GET_CURRENT_CONTEXT(ctx);
-
-   /* The GL_INTEL_performance_query spec says:
-    *
-    *    "If queryName does not reference a valid query name, an INVALID_VALUE
-    *    error is generated."
-    *
-    * No queries are supported, so all query names are invalid.
-    */
-
-   _mesa_error(ctx, GL_INVALID_VALUE,
-               "glGetPerfQueryIdByNameINTEL(invalid query name)");
-}
-
-extern void GLAPIENTRY
-_mesa_GetPerfQueryInfoINTEL(GLuint queryId,
-                            GLuint queryNameLength, char *queryName,
-                            GLuint *dataSize, GLuint *noCounters,
-                            GLuint *noActiveInstances,
-                            GLuint *capsMask)
-{
-   GET_CURRENT_CONTEXT(ctx);
-
-   /* The GL_INTEL_performance_query spec says:
-    *
-    *    "If queryId does not reference a valid query type, an INVALID_VALUE
-    *    error is generated."
-    *
-    * No queries are supported, so all queries are invalid.
-    */
-
-   _mesa_error(ctx, GL_INVALID_VALUE,
-               "glGetPerfQueryInfoINTEL(invalid query)");
-}
-
-extern void GLAPIENTRY
-_mesa_GetPerfCounterInfoINTEL(GLuint queryId, GLuint counterId,
-                              GLuint counterNameLength, char *counterName,
-                              GLuint counterDescLength, char *counterDesc,
-                              GLuint *counterOffset, GLuint *counterDataSize, GLuint *counterTypeEnum,
-                              GLuint *counterDataTypeEnum, GLuint64 *rawCounterMaxValue)
-{
-   GET_CURRENT_CONTEXT(ctx);
-
-   /* The GL_INTEL_performance_query spec says:
-    *
-    *    "If the pair of queryId and counterId does not reference a valid
-    *    counter, an INVALID_VALUE error is generated."
-    *
-    * No queries are supported, so all queries are invalid.
-    */
-
-   _mesa_error(ctx, GL_INVALID_VALUE,
-               "glGetPerfCounterInfoINTEL(invalid counterId)");
-}
-
-extern void GLAPIENTRY
-_mesa_CreatePerfQueryINTEL(GLuint queryId, GLuint *queryHandle)
-{
-   GET_CURRENT_CONTEXT(ctx);
-
-   /* The GL_INTEL_performance_query spec says:
-    *
-    *    "If queryId does not reference a valid query type, an INVALID_VALUE
-    *    error is generated."
-    *
-    * No queries are supported, so all queries are invalid.
-    */
-
-   _mesa_error(ctx, GL_INVALID_VALUE,
-               "glCreatePerfQueryINTEL(invalid queryId)");
-}
-
-extern void GLAPIENTRY
-_mesa_DeletePerfQueryINTEL(GLuint queryHandle)
-{
-   GET_CURRENT_CONTEXT(ctx);
-
-   /* The GL_INTEL_performance_query spec says:
-    *
-    *    "If a query handle doesn't reference a previously created performance
-    *    query instance, an INVALID_VALUE error is generated."
-    *
-    * No queries are supported, so all queries are invalid.
-    */
-
-   _mesa_error(ctx, GL_INVALID_VALUE,
-               "glDeletePerfQueryINTEL(invalid queryHandle)");
-}
-
-extern void GLAPIENTRY
-_mesa_BeginPerfQueryINTEL(GLuint queryHandle)
-{
-   GET_CURRENT_CONTEXT(ctx);
-
-   /* The GL_INTEL_performance_query spec says:
-    *
-    *    "If a query handle doesn't reference a previously created performance
-    *    query instance, an INVALID_VALUE error is generated."
-    *
-    * No queries are supported, so all queries are invalid.
-    */
-
-   _mesa_error(ctx, GL_INVALID_VALUE,
-               "glBeginPerfQueryINTEL(invalid queryHandle)");
-}
-
-extern void GLAPIENTRY
-_mesa_EndPerfQueryINTEL(GLuint queryHandle)
-{
-   GET_CURRENT_CONTEXT(ctx);
-
-   /* The GL_INTEL_performance_query spec says:
-    *
-    *    "If a performance query is not currently started, an
-    *    INVALID_OPERATION error will be generated."
-    *
-    * The specification doesn't state that an invalid handle would be an
-    * INVALID_VALUE error. Regardless, query for such a handle will not be
-    * started, so we generate an INVALID_OPERATION in that case.
-    *
-    * No queries are supported, so all handles are invalid.
-    */
-
-   _mesa_error(ctx, GL_INVALID_OPERATION,
-               "glEndPerfQueryINTEL(query not started)");
-}
-
-extern void GLAPIENTRY
-_mesa_GetPerfQueryDataINTEL(GLuint queryHandle, GLuint flags,
-                            GLsizei dataSize, void *data, GLuint *bytesWritten)
-{
-   GET_CURRENT_CONTEXT(ctx);
-
-   /* The GL_INTEL_performance_query spec says:
-    *
-    *    "If bytesWritten or data pointers are NULL then an INVALID_VALUE
-    *    error is generated."
-    */
-   if (!bytesWritten || !data) {
-      _mesa_error(ctx, GL_INVALID_VALUE,
-                  "glGetPerfQueryDataINTEL(bytesWritten or data is NULL)");
-      return;
-   }
-
-   /* The specification doesn't state that an invalid handle generates an
-    * error. We could interpret that to mean the case should be handled as
-    * "measurement not ready for this query", but what should be done if
-    * `flags' equals PERFQUERY_WAIT_INTEL?
-    *
-    * To resolve this, we just generate an INVALID_VALUE from an invalid query
-    * handle.
-    *
-    * No queries are supported, so all handles are invalid.
-    */
-
-   _mesa_error(ctx, GL_INVALID_VALUE,
-               "glGetPerfQueryDataINTEL(invalid queryHandle)");
-}