mesa: Move _mesa_all_buffers_are_unmapped to arrayobj.c.
[mesa.git] / src / mesa / main / performance_monitor.c
index 9d1a6b4d807e9a72524969d42944f0582f646657..43529b2b35a3c350c1b8acfb7e6402f7d4381a52 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)
 {
@@ -164,19 +171,6 @@ counterid_to_index(GLuint counterid)
    return counterid - 1;
 }
 
-static inline GLuint
-index_to_counterid(GLuint index)
-{
-   return index + 1;
-}
-
-static inline bool
-counterid_valid(const struct gl_perf_monitor_group *group_obj,
-                GLuint counterid)
-{
-   return get_counter(group_obj, counterid_to_index(counterid)) != NULL;
-}
-
 /*****************************************************************************/
 
 void GLAPIENTRY
@@ -184,6 +178,7 @@ _mesa_GetPerfMonitorGroupsAMD(GLint *numGroups, GLsizei groupsSize,
                               GLuint *groups)
 {
    GET_CURRENT_CONTEXT(ctx);
+   init_groups(ctx);
 
    if (numGroups != NULL)
       *numGroups = ctx->PerfMonitor.NumGroups;
@@ -204,7 +199,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)");
@@ -232,9 +231,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;
@@ -264,6 +265,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) {
@@ -303,6 +306,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) {
@@ -366,6 +371,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;
@@ -584,11 +591,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 */
@@ -686,6 +692,8 @@ _mesa_GetFirstPerfQueryIdINTEL(GLuint *queryId)
    GET_CURRENT_CONTEXT(ctx);
    unsigned numGroups;
 
+   init_groups(ctx);
+
    /* The GL_INTEL_performance_query spec says:
     *
     *    "If queryId pointer is equal to 0, INVALID_VALUE error is generated."
@@ -718,6 +726,7 @@ extern void GLAPIENTRY
 _mesa_GetNextPerfQueryIdINTEL(GLuint queryId, GLuint *nextQueryId)
 {
    GET_CURRENT_CONTEXT(ctx);
+   init_groups(ctx);
 
    /* The GL_INTEL_performance_query spec says:
     *
@@ -757,6 +766,8 @@ _mesa_GetPerfQueryIdByNameINTEL(char *queryName, GLuint *queryId)
    GET_CURRENT_CONTEXT(ctx);
    unsigned i;
 
+   init_groups(ctx);
+
    /* The GL_INTEL_performance_query spec says:
     *
     *    "If queryName does not reference a valid query name, an INVALID_VALUE
@@ -796,9 +807,11 @@ _mesa_GetPerfQueryInfoINTEL(GLuint queryId,
    GET_CURRENT_CONTEXT(ctx);
    unsigned i;
 
-   const struct gl_perf_monitor_group *group_obj =
-      get_group(ctx, queryid_to_index(queryId));
+   const struct gl_perf_monitor_group *group_obj;
+
+   init_groups(ctx);
 
+   group_obj = get_group(ctx, queryid_to_index(queryId));
    if (group_obj == NULL) {
       /* The GL_INTEL_performance_query spec says:
        *
@@ -873,6 +886,8 @@ _mesa_GetPerfCounterInfoINTEL(GLuint queryId, GLuint counterId,
    unsigned counterIndex;
    unsigned i;
 
+   init_groups(ctx);
+
    group_obj = get_group(ctx, queryid_to_index(queryId));
 
    /* The GL_INTEL_performance_query spec says:
@@ -992,6 +1007,8 @@ _mesa_CreatePerfQueryINTEL(GLuint queryId, GLuint *queryHandle)
    struct gl_perf_monitor_object *m;
    unsigned i;
 
+   init_groups(ctx);
+
    /* This is not specified in the extension, but is the only sane thing to
     * do.
     */