mesa: don't double incr/decr ActiveCounters
authorRob Clark <robdclark@gmail.com>
Mon, 2 Jul 2018 14:40:36 +0000 (10:40 -0400)
committerRob Clark <robdclark@gmail.com>
Wed, 18 Jul 2018 14:10:44 +0000 (10:10 -0400)
Frameretrace ends up w/ excess calls to SelectPerfMonitorCountersAMD()
which ends up re-enabling already enabled counters.  Which causes
ActiveCounters[group] to be double incremented for the same counter.
This causes BeginPerfMonitorAMD() to fail.

The AMD_performance_monitor spec doesn't say that an error should be
generated in this case.  So I think the safe thing to do is just safe-
guard against excess increments/decrements.

Signed-off-by: Rob Clark <robdclark@gmail.com>
src/mesa/main/performance_monitor.c

index 359727777ff5e1efc75ad51961abd079c50c19ad..253d42d989c507ba7aeff35a52c4611c73e83bbc 100644 (file)
@@ -480,14 +480,18 @@ _mesa_SelectPerfMonitorCountersAMD(GLuint monitor, GLboolean enable,
    if (enable) {
       /* Enable the counters */
       for (i = 0; i < numCounters; i++) {
-         ++m->ActiveGroups[group];
-         BITSET_SET(m->ActiveCounters[group], counterList[i]);
+         if (!BITSET_TEST(m->ActiveCounters[group], counterList[i])) {
+            ++m->ActiveGroups[group];
+            BITSET_SET(m->ActiveCounters[group], counterList[i]);
+         }
       }
    } else {
       /* Disable the counters */
       for (i = 0; i < numCounters; i++) {
-         --m->ActiveGroups[group];
-         BITSET_CLEAR(m->ActiveCounters[group], counterList[i]);
+         if (BITSET_TEST(m->ActiveCounters[group], counterList[i])) {
+            --m->ActiveGroups[group];
+            BITSET_CLEAR(m->ActiveCounters[group], counterList[i]);
+         }
       }
    }
 }