trace: Put shaders on a list in the context
authorJakob Bornecrantz <jakob@vmware.com>
Fri, 15 May 2009 03:30:43 +0000 (05:30 +0200)
committerJakob Bornecrantz <jakob@vmware.com>
Sat, 16 May 2009 00:50:53 +0000 (01:50 +0100)
src/gallium/drivers/trace/Makefile
src/gallium/drivers/trace/SConscript
src/gallium/drivers/trace/tr_context.c
src/gallium/drivers/trace/tr_context.h
src/gallium/drivers/trace/tr_state.c [new file with mode: 0644]
src/gallium/drivers/trace/tr_state.h [new file with mode: 0644]

index 188998d5793bb3664d3c851519c75c7a0bb82c35..94be0bfd5a5a0f2fbef9b1a831f2bcb637839a44 100644 (file)
@@ -8,6 +8,7 @@ C_SOURCES = \
        tr_context.c \
        tr_dump.c \
        tr_dump_state.c \
+       tr_state.c \
        tr_screen.c \
        tr_texture.c
 
index 4ab829a3a8e07782d33d28751405cf6428fd0873..9b5af0d86fb423b14090111ddbc08d2587d55b7f 100644 (file)
@@ -10,6 +10,7 @@ trace = env.ConvenienceLibrary(
         'tr_dump.c',
         'tr_dump_state.c',
         'tr_screen.c',
+        'tr_state.c',
         'tr_texture.c',
     ])
 
index 6a19233a9ae3caf9e9af7a686061011b49ad43bb..dee9ac57b4993cd1991a34a86709a25d71a9fb27 100644 (file)
 
 #include "tr_dump.h"
 #include "tr_dump_state.h"
+#include "tr_state.h"
 #include "tr_buffer.h"
 #include "tr_screen.h"
 #include "tr_texture.h"
-#include "tr_context.h"
 
 
 static INLINE struct pipe_buffer *
@@ -573,23 +573,30 @@ trace_context_create_fs_state(struct pipe_context *_pipe,
 
    trace_dump_call_end();
 
+   result = trace_shader_create(tr_ctx, state, result);
+
    return result;
 }
 
 
 static INLINE void
 trace_context_bind_fs_state(struct pipe_context *_pipe,
-                            void *state)
+                            void *_state)
 {
    struct trace_context *tr_ctx = trace_context(_pipe);
+   struct trace_shader *tr_shdr = trace_shader(_state);
    struct pipe_context *pipe = tr_ctx->pipe;
+   void *state = tr_shdr ? tr_shdr->state : NULL;
 
    trace_dump_call_begin("pipe_context", "bind_fs_state");
 
    trace_dump_arg(ptr, pipe);
    trace_dump_arg(ptr, state);
 
-   pipe->bind_fs_state(pipe, state);;
+   if (tr_shdr && tr_shdr->replaced)
+      state = tr_shdr->replaced;
+
+   pipe->bind_fs_state(pipe, state);
 
    trace_dump_call_end();
 }
@@ -597,19 +604,23 @@ trace_context_bind_fs_state(struct pipe_context *_pipe,
 
 static INLINE void
 trace_context_delete_fs_state(struct pipe_context *_pipe,
-                              void *state)
+                              void *_state)
 {
    struct trace_context *tr_ctx = trace_context(_pipe);
+   struct trace_shader *tr_shdr = trace_shader(_state);
    struct pipe_context *pipe = tr_ctx->pipe;
+   void *state = tr_shdr->state;
 
    trace_dump_call_begin("pipe_context", "delete_fs_state");
 
    trace_dump_arg(ptr, pipe);
    trace_dump_arg(ptr, state);
 
-   pipe->delete_fs_state(pipe, state);;
+   pipe->delete_fs_state(pipe, state);
 
    trace_dump_call_end();
+
+   trace_shader_destroy(tr_ctx, tr_shdr);
 }
 
 
@@ -626,28 +637,35 @@ trace_context_create_vs_state(struct pipe_context *_pipe,
    trace_dump_arg(ptr, pipe);
    trace_dump_arg(shader_state, state);
 
-   result = pipe->create_vs_state(pipe, state);;
+   result = pipe->create_vs_state(pipe, state);
 
    trace_dump_ret(ptr, result);
 
    trace_dump_call_end();
 
+   result = trace_shader_create(tr_ctx, state, result);
+
    return result;
 }
 
 
 static INLINE void
 trace_context_bind_vs_state(struct pipe_context *_pipe,
-                            void *state)
+                            void *_state)
 {
    struct trace_context *tr_ctx = trace_context(_pipe);
+   struct trace_shader *tr_shdr = trace_shader(_state);
    struct pipe_context *pipe = tr_ctx->pipe;
+   void *state = tr_shdr ? tr_shdr->state : NULL;
 
    trace_dump_call_begin("pipe_context", "bind_vs_state");
 
    trace_dump_arg(ptr, pipe);
    trace_dump_arg(ptr, state);
 
+   if (tr_shdr && tr_shdr->replaced)
+      state = tr_shdr->replaced;
+
    pipe->bind_vs_state(pipe, state);;
 
    trace_dump_call_end();
@@ -656,10 +674,12 @@ trace_context_bind_vs_state(struct pipe_context *_pipe,
 
 static INLINE void
 trace_context_delete_vs_state(struct pipe_context *_pipe,
-                              void *state)
+                              void *_state)
 {
    struct trace_context *tr_ctx = trace_context(_pipe);
+   struct trace_shader *tr_shdr = trace_shader(_state);
    struct pipe_context *pipe = tr_ctx->pipe;
+   void *state = tr_shdr->state;
 
    trace_dump_call_begin("pipe_context", "delete_vs_state");
 
@@ -669,6 +689,8 @@ trace_context_delete_vs_state(struct pipe_context *_pipe,
    pipe->delete_vs_state(pipe, state);;
 
    trace_dump_call_end();
+
+   trace_shader_destroy(tr_ctx, tr_shdr);
 }
 
 
@@ -1099,6 +1121,9 @@ trace_context_create(struct pipe_screen *_screen,
    if(!tr_ctx)
       goto error1;
 
+   pipe_mutex_init(tr_ctx->list_mutex);
+   make_empty_list(&tr_ctx->shaders);
+
    tr_ctx->base.winsys = _screen->winsys;
    tr_ctx->base.screen = _screen;
    tr_ctx->base.destroy = trace_context_destroy;
index 2512a0a2328221f0eb61ef93f4255da859984a2f..a7da7b9526936f2eabfad9c5a19222c88921d43b 100644 (file)
@@ -33,6 +33,7 @@
 #include "util/u_debug.h"
 #include "pipe/p_context.h"
 
+#include "tr_screen.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -45,7 +46,13 @@ struct trace_context
 
    struct pipe_context *pipe;
 
+   /* for list on screen */
    struct tr_list list;
+
+   /* list of state objects */
+   pipe_mutex list_mutex;
+   unsigned num_shaders;
+   struct tr_list shaders;
 };
 
 
diff --git a/src/gallium/drivers/trace/tr_state.c b/src/gallium/drivers/trace/tr_state.c
new file mode 100644 (file)
index 0000000..c9ce63a
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2009 VMware, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * on the rights to use, copy, modify, merge, publish, distribute, sub
+ * license, and/or sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * 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
+ * VMWARE AND/OR THEIR 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.
+ */
+
+#include "tr_state.h"
+
+#include "util/u_memory.h"
+#include "util/u_simple_list.h"
+
+struct trace_shader * trace_shader_create(struct trace_context *tr_ctx,
+                                          const struct pipe_shader_state *state,
+                                          void *result)
+{
+   struct trace_shader *tr_shdr = CALLOC_STRUCT(trace_shader);
+
+   tr_shdr->state = result;
+
+   /* works on context as well */
+   trace_screen_add_to_list(tr_ctx, shaders, tr_shdr);
+
+   return tr_shdr;
+}
+
+void trace_shader_destroy(struct trace_context *tr_ctx,
+                          struct trace_shader *tr_shdr)
+{
+   trace_screen_remove_from_list(tr_ctx, shaders, tr_shdr);
+
+   FREE(tr_shdr);
+}
diff --git a/src/gallium/drivers/trace/tr_state.h b/src/gallium/drivers/trace/tr_state.h
new file mode 100644 (file)
index 0000000..bca615c
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2009 VMware, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * on the rights to use, copy, modify, merge, publish, distribute, sub
+ * license, and/or sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * 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
+ * VMWARE AND/OR THEIR 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.
+ */
+
+#ifndef TR_STATE_H_
+#define TR_STATE_H_
+
+#include "tr_context.h"
+
+struct tgsi_token;
+
+struct trace_shader
+{
+   struct tr_list list;
+
+   void *state;
+   void *replaced;
+
+   struct tgsi_token *tokens;
+   struct tgsi_token *replaced_tokens;
+
+   boolean disabled;
+};
+
+
+static INLINE struct trace_shader *
+trace_shader(void *state)
+{
+   return (struct trace_shader *)state;
+}
+
+struct trace_shader * trace_shader_create(struct trace_context *tr_ctx,
+                                          const struct pipe_shader_state *state,
+                                          void *result);
+
+void trace_shader_destroy(struct trace_context *tr_ctx,
+                          struct trace_shader *tr_shdr);
+
+#endif