intel/dump_gpu: only map in GTT buffers not previously mapped
[mesa.git] / src / intel / tools / intel_dump_gpu.c
index 67f8559b9aec6b9eb71fc08106fda1552fcd6030..c3330e6cc2eba03d5ce5856727d018c1c00758e4 100644 (file)
@@ -58,7 +58,8 @@ static int drm_fd = -1;
 static char *output_filename = NULL;
 static FILE *output_file = NULL;
 static int verbose = 0;
-static bool device_override;
+static bool device_override = false;
+static bool capture_only = false;
 
 #define MAX_FD_COUNT 64
 #define MAX_BO_COUNT 64 * 1024
@@ -67,6 +68,8 @@ struct bo {
    uint32_t size;
    uint64_t offset;
    void *map;
+   /* Whether the buffer has been positionned in the GTT already. */
+   bool gtt_mapped : 1;
    /* Tracks userspace mmapping of the buffer */
    bool user_mapped : 1;
    /* Using the i915-gem mmapping ioctl & execbuffer ioctl, track whether a
@@ -277,8 +280,10 @@ dump_execbuffer2(int fd, struct drm_i915_gem_execbuffer2 *execbuffer2)
          bo->map = gem_mmap(fd, obj->handle, 0, bo->size);
       fail_if(bo->map == MAP_FAILED, "bo mmap failed\n");
 
-      if (aub_use_execlists(&aub_file))
+      if (aub_use_execlists(&aub_file) && !bo->gtt_mapped) {
          aub_map_ppgtt(&aub_file, bo->offset, bo->size);
+         bo->gtt_mapped = true;
+      }
    }
 
    batch_index = (execbuffer2->flags & I915_EXEC_BATCH_FIRST) ? 0 :
@@ -293,7 +298,9 @@ dump_execbuffer2(int fd, struct drm_i915_gem_execbuffer2 *execbuffer2)
       else
          data = bo->map;
 
-      if (bo->dirty) {
+      bool write = !capture_only || (obj->flags & EXEC_OBJECT_CAPTURE);
+
+      if (write && bo->dirty) {
          if (bo == batch_bo) {
             aub_write_trace_block(&aub_file, AUB_TRACE_TYPE_BATCH,
                                   GET_PTR(data), bo->size, bo->offset);
@@ -345,6 +352,7 @@ add_new_bo(unsigned fd, int handle, uint64_t size, void *map)
    bo->size = size;
    bo->map = map;
    bo->user_mapped = false;
+   bo->gtt_mapped = false;
 }
 
 static void
@@ -354,9 +362,7 @@ remove_bo(int fd, int handle)
 
    if (bo->map && !IS_USERPTR(bo->map))
       munmap(bo->map, bo->size);
-   bo->size = 0;
-   bo->map = NULL;
-   bo->user_mapped = false;
+   memset(bo, 0, sizeof(*bo));
 }
 
 __attribute__ ((visibility ("default"))) int
@@ -420,6 +426,8 @@ maybe_init(int fd)
          fail_if(output_file == NULL,
                  "failed to open file '%s'\n",
                  output_filename);
+      } else if (!strcmp(key, "capture_only")) {
+         capture_only = atoi(value);
       } else {
          fprintf(stderr, "unknown option '%s'\n", key);
       }