trace: Trace surface contents.
authorJosé Fonseca <jrfonseca@tungstengraphics.com>
Thu, 14 Aug 2008 13:34:33 +0000 (14:34 +0100)
committerJosé Fonseca <jrfonseca@tungstengraphics.com>
Fri, 15 Aug 2008 09:35:18 +0000 (10:35 +0100)
src/gallium/drivers/trace/README
src/gallium/drivers/trace/tr_screen.c
src/gallium/drivers/trace/tr_screen.h

index 5752448b934185eb42338df737c51e0c41f01963..5f0ae2c6419b3ed9178541df466b6ceeb6344003 100644 (file)
@@ -22,9 +22,5 @@ which should create a gallium.*.trace file, which is an XML file. You can view
 copying trace.xsl and trace.css to the same directory, and opening with a 
 XSLT capable browser like Firefox or Internet Explorer.
 
-This is still work in progress, namely:
-- surface writes are not traced
-- no way to know the start/end of a frame
-
 --
 Jose Fonseca <jrfonseca@tungstengraphics.com>
index 68165a4553b3b4e2d023b4ee47e2ea8a02e53b2e..2eecfdc1875ccccc4e54dfa613f4c73fe3cd3426 100644 (file)
@@ -26,6 +26,7 @@
  **************************************************************************/
 
 #include "pipe/p_util.h"
+#include "util/u_hash_table.h"
 
 #include "tr_dump.h"
 #include "tr_state.h"
 #include "tr_screen.h"
 
 
+static unsigned trace_surface_hash(void *surface)
+{
+   return (unsigned)(uintptr_t)surface;
+}
+
+
+static int trace_surface_compare(void *surface1, void *surface2)
+{
+   return (char *)surface2 - (char *)surface1;
+}
+
+                  
 static const char *
 trace_screen_get_name(struct pipe_screen *_screen)
 {
@@ -275,21 +288,17 @@ trace_screen_surface_map(struct pipe_screen *_screen,
 {
    struct trace_screen *tr_scr = trace_screen(_screen);
    struct pipe_screen *screen = tr_scr->screen;
-   struct pipe_surface *result;
-   
-   trace_dump_call_begin("pipe_screen", "surface_map");
+   void *map;
    
-   trace_dump_arg(ptr, screen);
-   trace_dump_arg(ptr, surface);
-   trace_dump_arg(uint, flags);
-
-   result = screen->surface_map(screen, surface, flags);
+   map = screen->surface_map(screen, surface, flags);
+   if(map) {
+      if(flags & PIPE_BUFFER_USAGE_CPU_WRITE) {
+         assert(!hash_table_get(tr_scr->surface_maps, surface));
+         hash_table_set(tr_scr->surface_maps, surface, map);
+      }
+   }
    
-   trace_dump_ret(ptr, result);
-   
-   trace_dump_call_end();
-   
-   return result;
+   return map;
 }
 
 
@@ -299,15 +308,36 @@ trace_screen_surface_unmap(struct pipe_screen *_screen,
 {
    struct trace_screen *tr_scr = trace_screen(_screen);
    struct pipe_screen *screen = tr_scr->screen;
-   
-   trace_dump_call_begin("pipe_screen", "surface_unmap");
-   
-   trace_dump_arg(ptr, screen);
-   trace_dump_arg(ptr, surface);
+   const void *map;
+   
+   map = hash_table_get(tr_scr->surface_maps, surface);
+   if(map) {
+      size_t size = surface->nblocksy * surface->stride;
+      
+      trace_dump_call_begin("pipe_winsys", "surface_write");
+      
+      trace_dump_arg(ptr, screen);
+      
+      trace_dump_arg(ptr, surface);
+      
+      trace_dump_arg_begin("data");
+      trace_dump_bytes(map, size);
+      trace_dump_arg_end();
+
+      trace_dump_arg_begin("stride");
+      trace_dump_uint(surface->stride);
+      trace_dump_arg_end();
+
+      trace_dump_arg_begin("size");
+      trace_dump_uint(size);
+      trace_dump_arg_end();
+   
+      trace_dump_call_end();
+
+      hash_table_remove(tr_scr->surface_maps, surface);
+   }
 
    screen->surface_unmap(screen, surface);
-   
-   trace_dump_call_end();
 }
 
 
@@ -368,6 +398,11 @@ trace_screen_create(struct pipe_screen *screen)
    
    tr_scr->screen = screen;
 
+   tr_scr->surface_maps = hash_table_create(trace_surface_hash, 
+                                            trace_surface_compare);
+   if(!tr_scr->surface_maps)
+      goto error3;
+   
    trace_dump_call_begin("", "pipe_screen_create");
    trace_dump_arg_begin("winsys");
    trace_dump_ptr(screen->winsys);
index 446c4af6a6bcf664c85f501e61a007fe076a7767..90103aa922d1d613e6f1db4a69fcf7d92e2ea853 100644 (file)
 #include "pipe/p_screen.h"
 
 
+struct hash_table;
+
+
 struct trace_screen
 {
    struct pipe_screen base;
    
    struct pipe_screen *screen;
+
+   struct hash_table *surface_maps;
 };