freedreno/ir3: add ctx->mem_to_mem()
[mesa.git] / src / gallium / drivers / trace / tr_dump.c
index 7111e0d174dea5ef68bbdcf6b3ededf43c70104e..49349496ac6cbac3b2ba0b94659c71c1b0da7fe1 100644 (file)
@@ -1,6 +1,6 @@
 /**************************************************************************
  *
- * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * Copyright 2008 VMware, Inc.
  * All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
@@ -18,7 +18,7 @@
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -35,7 +35,7 @@
  * is abstracted out of this file, so that we can switch to a binary
  * representation if/when it becomes justified.
  *
- * @author Jose Fonseca <jrfonseca@tungstengraphics.com>
+ * @author Jose Fonseca <jfonseca@vmware.com>
  */
 
 #include "pipe/p_config.h"
@@ -45,7 +45,7 @@
 
 #include "pipe/p_compiler.h"
 #include "os/os_thread.h"
-#include "os/os_time.h"
+#include "util/os_time.h"
 #include "util/u_debug.h"
 #include "util/u_memory.h"
 #include "util/u_string.h"
 
 static boolean close_stream = FALSE;
 static FILE *stream = NULL;
-pipe_static_mutex(call_mutex);
+static mtx_t call_mutex = _MTX_INITIALIZER_NP;
 static long unsigned call_no = 0;
 static boolean dumping = FALSE;
 
 
-static INLINE void
+static inline void
 trace_dump_write(const char *buf, size_t size)
 {
    if (stream) {
@@ -73,14 +73,14 @@ trace_dump_write(const char *buf, size_t size)
 }
 
 
-static INLINE void
+static inline void
 trace_dump_writes(const char *s)
 {
    trace_dump_write(s, strlen(s));
 }
 
 
-static INLINE void
+static inline void
 trace_dump_writef(const char *format, ...)
 {
    static char buf[1024];
@@ -93,7 +93,7 @@ trace_dump_writef(const char *format, ...)
 }
 
 
-static INLINE void
+static inline void
 trace_dump_escape(const char *str)
 {
    const unsigned char *p = (const unsigned char *)str;
@@ -117,7 +117,7 @@ trace_dump_escape(const char *str)
 }
 
 
-static INLINE void
+static inline void
 trace_dump_indent(unsigned level)
 {
    unsigned i;
@@ -126,23 +126,14 @@ trace_dump_indent(unsigned level)
 }
 
 
-static INLINE void
+static inline void
 trace_dump_newline(void)
 {
    trace_dump_writes("\n");
 }
 
 
-static INLINE void
-trace_dump_tag(const char *name)
-{
-   trace_dump_writes("<");
-   trace_dump_writes(name);
-   trace_dump_writes("/>");
-}
-
-
-static INLINE void
+static inline void
 trace_dump_tag_begin(const char *name)
 {
    trace_dump_writes("<");
@@ -150,7 +141,7 @@ trace_dump_tag_begin(const char *name)
    trace_dump_writes(">");
 }
 
-static INLINE void
+static inline void
 trace_dump_tag_begin1(const char *name,
                       const char *attr1, const char *value1)
 {
@@ -164,50 +155,7 @@ trace_dump_tag_begin1(const char *name,
 }
 
 
-static INLINE void
-trace_dump_tag_begin2(const char *name,
-                      const char *attr1, const char *value1,
-                      const char *attr2, const char *value2)
-{
-   trace_dump_writes("<");
-   trace_dump_writes(name);
-   trace_dump_writes(" ");
-   trace_dump_writes(attr1);
-   trace_dump_writes("=\'");
-   trace_dump_escape(value1);
-   trace_dump_writes("\' ");
-   trace_dump_writes(attr2);
-   trace_dump_writes("=\'");
-   trace_dump_escape(value2);
-   trace_dump_writes("\'>");
-}
-
-
-static INLINE void
-trace_dump_tag_begin3(const char *name,
-                      const char *attr1, const char *value1,
-                      const char *attr2, const char *value2,
-                      const char *attr3, const char *value3)
-{
-   trace_dump_writes("<");
-   trace_dump_writes(name);
-   trace_dump_writes(" ");
-   trace_dump_writes(attr1);
-   trace_dump_writes("=\'");
-   trace_dump_escape(value1);
-   trace_dump_writes("\' ");
-   trace_dump_writes(attr2);
-   trace_dump_writes("=\'");
-   trace_dump_escape(value2);
-   trace_dump_writes("\' ");
-   trace_dump_writes(attr3);
-   trace_dump_writes("=\'");
-   trace_dump_escape(value3);
-   trace_dump_writes("\'>");
-}
-
-
-static INLINE void
+static inline void
 trace_dump_tag_end(const char *name)
 {
    trace_dump_writes("</");
@@ -218,7 +166,7 @@ trace_dump_tag_end(const char *name)
 void
 trace_dump_trace_flush(void)
 {
-   if(stream) {
+   if (stream) {
       fflush(stream);
    }
 }
@@ -226,7 +174,7 @@ trace_dump_trace_flush(void)
 static void
 trace_dump_trace_close(void)
 {
-   if(stream) {
+   if (stream) {
       trace_dump_writes("</trace>\n");
       if (close_stream) {
          fclose(stream);
@@ -257,10 +205,10 @@ trace_dump_trace_begin(void)
    const char *filename;
 
    filename = debug_get_option("GALLIUM_TRACE", NULL);
-   if(!filename)
+   if (!filename)
       return FALSE;
 
-   if(!stream) {
+   if (!stream) {
 
       if (strcmp(filename, "stderr") == 0) {
          close_stream = FALSE;
@@ -302,12 +250,12 @@ boolean trace_dump_trace_enabled(void)
 
 void trace_dump_call_lock(void)
 {
-   pipe_mutex_lock(call_mutex);
+   mtx_lock(&call_mutex);
 }
 
 void trace_dump_call_unlock(void)
 {
-   pipe_mutex_unlock(call_mutex);
+   mtx_unlock(&call_mutex);
 }
 
 /*
@@ -331,24 +279,24 @@ boolean trace_dumping_enabled_locked(void)
 
 void trace_dumping_start(void)
 {
-   pipe_mutex_lock(call_mutex);
+   mtx_lock(&call_mutex);
    trace_dumping_start_locked();
-   pipe_mutex_unlock(call_mutex);
+   mtx_unlock(&call_mutex);
 }
 
 void trace_dumping_stop(void)
 {
-   pipe_mutex_lock(call_mutex);
+   mtx_lock(&call_mutex);
    trace_dumping_stop_locked();
-   pipe_mutex_unlock(call_mutex);
+   mtx_unlock(&call_mutex);
 }
 
 boolean trace_dumping_enabled(void)
 {
    boolean ret;
-   pipe_mutex_lock(call_mutex);
+   mtx_lock(&call_mutex);
    ret = trace_dumping_enabled_locked();
-   pipe_mutex_unlock(call_mutex);
+   mtx_unlock(&call_mutex);
    return ret;
 }
 
@@ -395,14 +343,14 @@ void trace_dump_call_end_locked(void)
 
 void trace_dump_call_begin(const char *klass, const char *method)
 {
-   pipe_mutex_lock(call_mutex);
+   mtx_lock(&call_mutex);
    trace_dump_call_begin_locked(klass, method);
 }
 
 void trace_dump_call_end(void)
 {
    trace_dump_call_end_locked();
-   pipe_mutex_unlock(call_mutex);
+   mtx_unlock(&call_mutex);
 }
 
 void trace_dump_arg_begin(const char *name)
@@ -495,19 +443,27 @@ void trace_dump_bytes(const void *data,
 }
 
 void trace_dump_box_bytes(const void *data,
-                         enum pipe_format format,
+                          struct pipe_resource *resource,
                          const struct pipe_box *box,
                          unsigned stride,
                          unsigned slice_stride)
 {
+   enum pipe_format format = resource->format;
    size_t size;
 
-   if (slice_stride)
-      size = box->depth * slice_stride;
-   else if (stride)
-      size = util_format_get_nblocksy(format, box->height) * stride;
-   else {
-      size = util_format_get_nblocksx(format, box->width) * util_format_get_blocksize(format);
+   assert(box->height > 0);
+   assert(box->depth > 0);
+
+   size =  util_format_get_nblocksx(format, box->width )      * util_format_get_blocksize(format)
+        + (util_format_get_nblocksy(format, box->height) - 1) * stride
+        +                                  (box->depth   - 1) * slice_stride;
+
+   /*
+    * Only dump buffer transfers to avoid huge files.
+    * TODO: Make this run-time configurable
+    */
+   if (resource->target != PIPE_BUFFER) {
+      size = 0;
    }
 
    trace_dump_bytes(data, size);
@@ -616,20 +572,6 @@ void trace_dump_ptr(const void *value)
       trace_dump_null();
 }
 
-
-void trace_dump_resource_ptr(struct pipe_resource *_resource)
-{
-   if (!dumping)
-      return;
-
-   if (_resource) {
-      struct trace_resource *tr_resource = trace_resource(_resource);
-      trace_dump_ptr(tr_resource->resource);
-   } else {
-      trace_dump_null();
-   }
-}
-
 void trace_dump_surface_ptr(struct pipe_surface *_surface)
 {
    if (!dumping)