svga: add new num-failed-allocations HUD query
authorBrian Paul <brianp@vmware.com>
Fri, 16 Jun 2017 22:36:43 +0000 (16:36 -0600)
committerBrian Paul <brianp@vmware.com>
Fri, 16 Jun 2017 23:04:08 +0000 (17:04 -0600)
This counter is incremented if we fail to allocate memory for
vertex/index/const buffers, textures, etc.

Reviewed-by: Neha Bhende <bhenden@vmware.com>
src/gallium/drivers/svga/svga_context.h
src/gallium/drivers/svga/svga_pipe_query.c
src/gallium/drivers/svga/svga_resource.c
src/gallium/drivers/svga/svga_screen.c
src/gallium/drivers/svga/svga_screen.h

index 2987c709ac974755daae392a47ab079e1d58105a..b1ccfc8775d36aebd8a95636d9ef1eaf50b8ae97 100644 (file)
@@ -72,6 +72,7 @@ enum svga_hud {
    SVGA_QUERY_NUM_STATE_OBJECTS,
    SVGA_QUERY_NUM_SURFACE_VIEWS,
    SVGA_QUERY_NUM_GENERATE_MIPMAP,
+   SVGA_QUERY_NUM_FAILED_ALLOCATIONS,
 
 /*SVGA_QUERY_MAX has to be last because it is size of an array*/
    SVGA_QUERY_MAX
index 76360fdd4d0dc6524f4311935dd6d80b9e15a75e..6703b729c6e65e0ea4fa6d706ba5cafc20639bb1 100644 (file)
@@ -747,6 +747,7 @@ svga_create_query(struct pipe_context *pipe,
    case SVGA_QUERY_NUM_BUFFER_UPLOADS:
    case SVGA_QUERY_NUM_CONST_BUF_UPDATES:
    case SVGA_QUERY_NUM_CONST_UPDATES:
+   case SVGA_QUERY_NUM_FAILED_ALLOCATIONS:
       break;
    case SVGA_QUERY_FLUSH_TIME:
    case SVGA_QUERY_MAP_BUFFER_TIME:
@@ -826,6 +827,7 @@ svga_destroy_query(struct pipe_context *pipe, struct pipe_query *q)
    case SVGA_QUERY_NUM_BUFFER_UPLOADS:
    case SVGA_QUERY_NUM_CONST_BUF_UPDATES:
    case SVGA_QUERY_NUM_CONST_UPDATES:
+   case SVGA_QUERY_NUM_FAILED_ALLOCATIONS:
       /* nothing */
       break;
    default:
@@ -937,6 +939,7 @@ svga_begin_query(struct pipe_context *pipe, struct pipe_query *q)
    case SVGA_QUERY_NUM_STATE_OBJECTS:
    case SVGA_QUERY_NUM_SURFACE_VIEWS:
    case SVGA_QUERY_NUM_GENERATE_MIPMAP:
+   case SVGA_QUERY_NUM_FAILED_ALLOCATIONS:
       /* nothing */
       break;
    default:
@@ -1049,6 +1052,7 @@ svga_end_query(struct pipe_context *pipe, struct pipe_query *q)
    case SVGA_QUERY_NUM_STATE_OBJECTS:
    case SVGA_QUERY_NUM_SURFACE_VIEWS:
    case SVGA_QUERY_NUM_GENERATE_MIPMAP:
+   case SVGA_QUERY_NUM_FAILED_ALLOCATIONS:
       /* nothing */
       break;
    default:
@@ -1182,6 +1186,9 @@ svga_get_query_result(struct pipe_context *pipe,
    case SVGA_QUERY_NUM_GENERATE_MIPMAP:
       vresult->u64 = svga->hud.num_generate_mipmap;
       break;
+   case SVGA_QUERY_NUM_FAILED_ALLOCATIONS:
+      vresult->u64 = svgascreen->hud.num_failed_allocations;
+      break;
    default:
       assert(!"unexpected query type in svga_get_query_result");
    }
index 6a297a2ae024b529ccce861129beb5e754eca7e8..874cfa072235448daab64822f16360263a4d011e 100644 (file)
 #include "svga_format.h"
 
 
+/**
+ * This is the primary driver entrypoint for allocating graphics memory
+ * (vertex/index/constant buffers, textures, etc)
+ */
 static struct pipe_resource *
 svga_resource_create(struct pipe_screen *screen,
                      const struct pipe_resource *template)
 {
+   struct pipe_resource *r;
+
    if (template->target == PIPE_BUFFER)
-      return svga_buffer_create(screen, template);
+      r = svga_buffer_create(screen, template);
    else
-      return svga_texture_create(screen, template);
+      r = svga_texture_create(screen, template);
+
+   if (!r) {
+      struct svga_screen *svgascreen = svga_screen(screen);
+      svgascreen->hud.num_failed_allocations++;
+   }
+
+   return r;
 }
 
 
index 3aa99452a8c048b1a47439e7d2faf23de0fc306c..0b63525aaf2698b1606dc42f293326ed241533e5 100644 (file)
@@ -916,6 +916,8 @@ svga_get_driver_query_info(struct pipe_screen *screen,
             PIPE_DRIVER_QUERY_TYPE_UINT64),
       QUERY("num-generate-mipmap", SVGA_QUERY_NUM_GENERATE_MIPMAP,
             PIPE_DRIVER_QUERY_TYPE_UINT64),
+      QUERY("num-failed-allocations", SVGA_QUERY_NUM_FAILED_ALLOCATIONS,
+            PIPE_DRIVER_QUERY_TYPE_UINT64),
    };
 #undef QUERY
 
index 68834a69e2e59a0d46723e0ee8f09636cbe77920..12b93468da2eea73f0a6a2bb9541a9c0d5612abb 100644 (file)
@@ -86,6 +86,7 @@ struct svga_screen
       /** Memory used by all resources (buffers and surfaces) */
       uint64_t total_resource_bytes;
       uint64_t num_resources;
+      uint64_t num_failed_allocations;
    } hud;
 };