glthread,hud: draw per-frame values and expose the number of batches per frame
authorMarek Olšák <marek.olsak@amd.com>
Tue, 23 Aug 2022 04:09:23 +0000 (00:09 -0400)
committerMarge Bot <emma+marge@anholt.net>
Mon, 26 Sep 2022 22:58:16 +0000 (22:58 +0000)
This is better because we see the statistics for 1 frame instead of 1 second.

Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18828>

src/gallium/auxiliary/hud/hud_context.c
src/gallium/auxiliary/hud/hud_cpu.c
src/gallium/auxiliary/hud/hud_private.h
src/mesa/main/glthread.c
src/util/u_queue.h

index b76981f..ea0a294 100644 (file)
@@ -1276,6 +1276,9 @@ hud_parse_env_var(struct hud_context *hud, struct pipe_screen *screen,
       else if (strcmp(name, "API-thread-num-syncs") == 0) {
          hud_thread_counter_install(pane, name, HUD_COUNTER_SYNCS);
       }
+      else if (strcmp(name, "API-thread-num-batches") == 0) {
+         hud_thread_counter_install(pane, name, HUD_COUNTER_BATCHES);
+      }
       else if (strcmp(name, "main-thread-busy") == 0) {
          hud_thread_busy_install(pane, name, true);
       }
index 767bff4..820e7d7 100644 (file)
@@ -395,24 +395,35 @@ hud_thread_busy_install(struct hud_pane *pane, const char *name, bool main)
 
 struct counter_info {
    enum hud_counter counter;
-   unsigned last_value;
    int64_t last_time;
 };
 
 static unsigned get_counter(struct hud_graph *gr, enum hud_counter counter)
 {
    struct util_queue_monitoring *mon = gr->pane->hud->monitored_queue;
+   unsigned value;
 
    if (!mon || !mon->queue)
       return 0;
 
+   /* Reset the counters to 0 to only display values for 1 frame. */
    switch (counter) {
    case HUD_COUNTER_OFFLOADED:
-      return mon->num_offloaded_items;
+      value = mon->num_offloaded_items;
+      mon->num_offloaded_items = 0;
+      return value;
    case HUD_COUNTER_DIRECT:
-      return mon->num_direct_items;
+      value = mon->num_direct_items;
+      mon->num_direct_items = 0;
+      return value;
    case HUD_COUNTER_SYNCS:
-      return mon->num_syncs;
+      value = mon->num_syncs;
+      mon->num_syncs = 0;
+      return value;
+   case HUD_COUNTER_BATCHES:
+      value = mon->num_batches;
+      mon->num_batches = 0;
+      return value;
    default:
       assert(0);
       return 0;
@@ -424,18 +435,15 @@ query_thread_counter(struct hud_graph *gr, struct pipe_context *pipe)
 {
    struct counter_info *info = gr->query_data;
    int64_t now = os_time_get_nano();
+   unsigned value = get_counter(gr, info->counter);
 
    if (info->last_time) {
       if (info->last_time + gr->pane->period*1000 <= now) {
-         unsigned current_value = get_counter(gr, info->counter);
-
-         hud_graph_add_value(gr, current_value - info->last_value);
-         info->last_value = current_value;
+         hud_graph_add_value(gr, value);
          info->last_time = now;
       }
    } else {
       /* initialize */
-      info->last_value = get_counter(gr, info->counter);
       info->last_time = now;
    }
 }
index b8ee495..3604760 100644 (file)
@@ -38,6 +38,7 @@ enum hud_counter {
    HUD_COUNTER_OFFLOADED,
    HUD_COUNTER_DIRECT,
    HUD_COUNTER_SYNCS,
+   HUD_COUNTER_BATCHES,
 };
 
 struct hud_context {
index 66436fa..b44ff9b 100644 (file)
@@ -78,6 +78,8 @@ glthread_unmarshal_batch(void *job, void *gdata, int thread_index)
    /* Atomically set this to -1 if it's equal to batch_index. */
    p_atomic_cmpxchg(&ctx->GLThread.LastProgramChangeBatch, batch_index, -1);
    p_atomic_cmpxchg(&ctx->GLThread.LastDListChangeBatchIndex, batch_index, -1);
+
+   p_atomic_inc(&ctx->GLThread.stats.num_batches);
 }
 
 static void
index 2da74c5..b46b179 100644 (file)
@@ -273,6 +273,7 @@ struct util_queue_monitoring
    unsigned num_offloaded_items;
    unsigned num_direct_items;
    unsigned num_syncs;
+   unsigned num_batches;
 };
 
 #ifdef __cplusplus