summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakob Bornecrantz <[email protected]>2009-03-12 13:20:37 +0100
committerJakob Bornecrantz <[email protected]>2009-03-12 16:35:43 +0100
commite8ee34e7f34c51121dcfa6c763fc5eb900b562df (patch)
tree0d90f99b560147adf17dbd67376c5e56f624f3fe
parent53e5248b0a71b1e72b1a613046a1b3e5d145d072 (diff)
trace: Wrap pipe_buffers
-rw-r--r--src/gallium/drivers/trace/Makefile1
-rw-r--r--src/gallium/drivers/trace/SConscript1
-rw-r--r--src/gallium/drivers/trace/tr_buffer.c68
-rw-r--r--src/gallium/drivers/trace/tr_buffer.h69
-rw-r--r--src/gallium/drivers/trace/tr_context.c50
-rw-r--r--src/gallium/drivers/trace/tr_screen.c42
-rw-r--r--src/gallium/drivers/trace/tr_state.c4
7 files changed, 215 insertions, 20 deletions
diff --git a/src/gallium/drivers/trace/Makefile b/src/gallium/drivers/trace/Makefile
index 7c570bf7a58..e087db169aa 100644
--- a/src/gallium/drivers/trace/Makefile
+++ b/src/gallium/drivers/trace/Makefile
@@ -4,6 +4,7 @@ include $(TOP)/configs/current
LIBNAME = trace
C_SOURCES = \
+ tr_buffer.c \
tr_context.c \
tr_dump.c \
tr_screen.c \
diff --git a/src/gallium/drivers/trace/SConscript b/src/gallium/drivers/trace/SConscript
index 45e5ef6868d..4215215d1a1 100644
--- a/src/gallium/drivers/trace/SConscript
+++ b/src/gallium/drivers/trace/SConscript
@@ -5,6 +5,7 @@ env = env.Clone()
trace = env.ConvenienceLibrary(
target = 'trace',
source = [
+ 'tr_buffer.c',
'tr_context.c',
'tr_dump.c',
'tr_screen.c',
diff --git a/src/gallium/drivers/trace/tr_buffer.c b/src/gallium/drivers/trace/tr_buffer.c
new file mode 100644
index 00000000000..12c491c571d
--- /dev/null
+++ b/src/gallium/drivers/trace/tr_buffer.c
@@ -0,0 +1,68 @@
+/**************************************************************************
+ *
+ * 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 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 TUNGSTEN GRAPHICS 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.
+ *
+ **************************************************************************/
+
+
+#include "util/u_memory.h"
+
+#include "tr_buffer.h"
+
+
+struct pipe_buffer *
+trace_buffer_create(struct trace_screen *tr_scr,
+ struct pipe_buffer *buffer)
+{
+ struct trace_buffer *tr_buf;
+
+ if(!buffer)
+ goto error;
+
+ assert(buffer->screen == tr_scr->screen);
+
+ tr_buf = CALLOC_STRUCT(trace_buffer);
+ if(!tr_buf)
+ goto error;
+
+ memcpy(&tr_buf->base, buffer, sizeof(struct pipe_buffer));
+ tr_buf->base.screen = &tr_scr->base;
+ tr_buf->buffer = buffer;
+
+ return &tr_buf->base;
+
+error:
+ pipe_buffer_reference(&buffer, NULL);
+ return NULL;
+}
+
+
+void
+trace_buffer_destroy(struct trace_screen *tr_scr,
+ struct pipe_buffer *buffer)
+{
+ struct trace_buffer *tr_buf = trace_buffer(tr_scr, buffer);
+ pipe_buffer_reference(&tr_buf->buffer, NULL);
+ FREE(tr_buf);
+}
diff --git a/src/gallium/drivers/trace/tr_buffer.h b/src/gallium/drivers/trace/tr_buffer.h
new file mode 100644
index 00000000000..e9daeb77028
--- /dev/null
+++ b/src/gallium/drivers/trace/tr_buffer.h
@@ -0,0 +1,69 @@
+/**************************************************************************
+ *
+ * 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 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 TUNGSTEN GRAPHICS 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.
+ *
+ **************************************************************************/
+
+#ifndef TR_BUFFER_H_
+#define TR_BUFFER_H_
+
+
+#include "pipe/p_compiler.h"
+#include "pipe/p_state.h"
+
+#include "tr_screen.h"
+
+
+struct trace_buffer
+{
+ struct pipe_buffer base;
+
+ struct pipe_buffer *buffer;
+
+ void *map;
+};
+
+
+static INLINE struct trace_buffer *
+trace_buffer(struct trace_screen *tr_scr,
+ struct pipe_buffer *buffer)
+{
+ if(!buffer)
+ return NULL;
+ assert(tr_scr);
+ assert(buffer->screen == &tr_scr->base);
+ return (struct trace_buffer *)buffer;
+}
+
+
+struct pipe_buffer *
+trace_buffer_create(struct trace_screen *tr_scr,
+ struct pipe_buffer *buffer);
+
+void
+trace_buffer_destroy(struct trace_screen *tr_scr,
+ struct pipe_buffer *buffer);
+
+
+#endif
diff --git a/src/gallium/drivers/trace/tr_context.c b/src/gallium/drivers/trace/tr_context.c
index 6e367af57ae..9dcd13f114d 100644
--- a/src/gallium/drivers/trace/tr_context.c
+++ b/src/gallium/drivers/trace/tr_context.c
@@ -30,11 +30,30 @@
#include "tr_dump.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 *
+trace_buffer_unwrap(struct trace_context *tr_ctx,
+ struct pipe_buffer *buffer)
+{
+ struct trace_screen *tr_scr = trace_screen(tr_ctx->base.screen);
+ struct trace_buffer *tr_buf;
+
+ if(!buffer)
+ return NULL;
+
+ tr_buf = trace_buffer(tr_scr, buffer);
+
+ assert(tr_buf->buffer);
+ assert(tr_buf->buffer->screen == tr_scr->screen);
+ return tr_buf->buffer;
+}
+
+
static INLINE struct pipe_texture *
trace_texture_unwrap(struct trace_context *tr_ctx,
struct pipe_texture *texture)
@@ -123,12 +142,15 @@ trace_context_draw_arrays(struct pipe_context *_pipe,
static INLINE boolean
trace_context_draw_elements(struct pipe_context *_pipe,
- struct pipe_buffer *indexBuffer,
+ struct pipe_buffer *_indexBuffer,
unsigned indexSize,
unsigned mode, unsigned start, unsigned count)
{
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_buffer *tr_buf = trace_buffer(tr_scr, _indexBuffer);
struct pipe_context *pipe = tr_ctx->pipe;
+ struct pipe_buffer *indexBuffer = tr_buf->buffer;
boolean result;
trace_screen_user_buffer_update(_pipe->screen, indexBuffer);
@@ -154,7 +176,7 @@ trace_context_draw_elements(struct pipe_context *_pipe,
static INLINE boolean
trace_context_draw_range_elements(struct pipe_context *_pipe,
- struct pipe_buffer *indexBuffer,
+ struct pipe_buffer *_indexBuffer,
unsigned indexSize,
unsigned minIndex,
unsigned maxIndex,
@@ -162,8 +184,11 @@ trace_context_draw_range_elements(struct pipe_context *_pipe,
unsigned start,
unsigned count)
{
+ struct trace_screen *tr_scr = trace_screen(_pipe->screen);
struct trace_context *tr_ctx = trace_context(_pipe);
+ struct trace_buffer *tr_buf = trace_buffer(tr_scr, _indexBuffer);
struct pipe_context *pipe = tr_ctx->pipe;
+ struct pipe_buffer *indexBuffer = tr_buf->buffer;
boolean result;
trace_screen_user_buffer_update(_pipe->screen, indexBuffer);
@@ -695,7 +720,8 @@ trace_context_set_constant_buffer(struct pipe_context *_pipe,
struct trace_context *tr_ctx = trace_context(_pipe);
struct pipe_context *pipe = tr_ctx->pipe;
- trace_screen_user_buffer_update(_pipe->screen, (struct pipe_buffer *)buffer);
+ if (buffer)
+ trace_screen_user_buffer_update(_pipe->screen, buffer->buffer);
trace_dump_call_begin("pipe_context", "set_constant_buffer");
@@ -704,7 +730,13 @@ trace_context_set_constant_buffer(struct pipe_context *_pipe,
trace_dump_arg(uint, index);
trace_dump_arg(constant_buffer, buffer);
- pipe->set_constant_buffer(pipe, shader, index, buffer);;
+ if (buffer) {
+ struct pipe_constant_buffer _buffer;
+ _buffer.buffer = trace_buffer_unwrap(tr_ctx, buffer->buffer);
+ pipe->set_constant_buffer(pipe, shader, index, &_buffer);
+ } else {
+ pipe->set_constant_buffer(pipe, shader, index, buffer);
+ }
trace_dump_call_end();
}
@@ -840,7 +872,15 @@ trace_context_set_vertex_buffers(struct pipe_context *_pipe,
trace_dump_struct_array(vertex_buffer, buffers, num_buffers);
trace_dump_arg_end();
- pipe->set_vertex_buffers(pipe, num_buffers, buffers);;
+ if (num_buffers) {
+ struct pipe_vertex_buffer *_buffers = malloc(num_buffers * sizeof(*_buffers));
+ memcpy(_buffers, buffers, num_buffers * sizeof(*_buffers));
+ for (i = 0; i < num_buffers; i++)
+ _buffers[i].buffer = trace_buffer_unwrap(tr_ctx, buffers[i].buffer);
+ pipe->set_vertex_buffers(pipe, num_buffers, _buffers);
+ } else {
+ pipe->set_vertex_buffers(pipe, num_buffers, buffers);
+ }
trace_dump_call_end();
}
diff --git a/src/gallium/drivers/trace/tr_screen.c b/src/gallium/drivers/trace/tr_screen.c
index 8e7e033d514..5ad4cccf0a1 100644
--- a/src/gallium/drivers/trace/tr_screen.c
+++ b/src/gallium/drivers/trace/tr_screen.c
@@ -27,6 +27,7 @@
#include "util/u_memory.h"
+#include "tr_buffer.h"
#include "tr_dump.h"
#include "tr_state.h"
#include "tr_texture.h"
@@ -34,6 +35,7 @@
#include "pipe/p_inlines.h"
+
static const char *
trace_screen_get_name(struct pipe_screen *_screen)
{
@@ -488,7 +490,7 @@ trace_screen_surface_buffer_create(struct pipe_screen *_screen,
trace_dump_call_end();
- return result;
+ return trace_buffer_create(tr_scr, result);
}
@@ -525,7 +527,7 @@ trace_screen_buffer_create(struct pipe_screen *_screen,
}
}
- return result;
+ return trace_buffer_create(tr_scr, result);
}
@@ -559,7 +561,7 @@ trace_screen_user_buffer_create(struct pipe_screen *_screen,
result->usage |= TRACE_BUFFER_USAGE_USER;
}
- return result;
+ return trace_buffer_create(tr_scr, result);
}
@@ -569,7 +571,7 @@ trace_screen_user_buffer_create(struct pipe_screen *_screen,
*/
void
trace_screen_user_buffer_update(struct pipe_screen *_screen,
- struct pipe_buffer *buffer)
+ struct pipe_buffer *_buffer)
{
#if 0
struct trace_screen *tr_scr = trace_screen(_screen);
@@ -604,11 +606,13 @@ trace_screen_user_buffer_update(struct pipe_screen *_screen,
static void *
trace_screen_buffer_map(struct pipe_screen *_screen,
- struct pipe_buffer *buffer,
+ struct pipe_buffer *_buffer,
unsigned usage)
{
struct trace_screen *tr_scr = trace_screen(_screen);
+ struct trace_buffer *tr_buf = trace_buffer(tr_scr, _buffer);
struct pipe_screen *screen = tr_scr->screen;
+ struct pipe_buffer *buffer = tr_buf->buffer;
void *map;
trace_dump_call_begin("pipe_screen", "buffer_map");
@@ -636,13 +640,15 @@ trace_screen_buffer_map(struct pipe_screen *_screen,
static void *
trace_screen_buffer_map_range(struct pipe_screen *_screen,
- struct pipe_buffer *buffer,
+ struct pipe_buffer *_buffer,
unsigned offset,
unsigned length,
unsigned usage)
{
struct trace_screen *tr_scr = trace_screen(_screen);
+ struct trace_buffer *tr_buf = trace_buffer(tr_scr, _buffer);
struct pipe_screen *screen = tr_scr->screen;
+ struct pipe_buffer *buffer = tr_buf->buffer;
void *map;
trace_dump_call_begin("pipe_screen", "buffer_map_range");
@@ -666,12 +672,14 @@ trace_screen_buffer_map_range(struct pipe_screen *_screen,
static void
trace_screen_buffer_flush_mapped_range(struct pipe_screen *_screen,
- struct pipe_buffer *buffer,
+ struct pipe_buffer *_buffer,
unsigned offset,
unsigned length)
{
struct trace_screen *tr_scr = trace_screen(_screen);
+ struct trace_buffer *tr_buf = trace_buffer(tr_scr, _buffer);
struct pipe_screen *screen = tr_scr->screen;
+ struct pipe_buffer *buffer = tr_buf->buffer;
trace_dump_call_begin("pipe_screen", "buffer_flush_mapped_range");
@@ -689,10 +697,12 @@ trace_screen_buffer_flush_mapped_range(struct pipe_screen *_screen,
static void
trace_screen_buffer_unmap(struct pipe_screen *_screen,
- struct pipe_buffer *buffer)
+ struct pipe_buffer *_buffer)
{
struct trace_screen *tr_scr = trace_screen(_screen);
+ struct trace_buffer *tr_buf = trace_buffer(tr_scr, _buffer);
struct pipe_screen *screen = tr_scr->screen;
+ struct pipe_buffer *buffer = tr_buf->buffer;
#if 0
const void *map;
@@ -731,23 +741,29 @@ trace_screen_buffer_unmap(struct pipe_screen *_screen,
static void
-trace_screen_buffer_destroy(struct pipe_buffer *buffer)
+trace_screen_buffer_destroy(struct pipe_buffer *_buffer)
{
- struct trace_screen *tr_scr = trace_screen(buffer->screen);
+ struct trace_screen *tr_scr = trace_screen(_buffer->screen);
+ struct trace_buffer *tr_buf = trace_buffer(tr_scr, _buffer);
struct pipe_screen *screen = tr_scr->screen;
+ struct pipe_buffer *buffer = tr_buf->buffer;
trace_dump_call_begin("pipe_screen", "buffer_destroy");
trace_dump_arg(ptr, screen);
trace_dump_arg(ptr, buffer);
- assert(screen->buffer_destroy);
- screen->buffer_destroy(buffer);
-
trace_dump_call_end();
+
+ trace_buffer_destroy(tr_scr, _buffer);
}
+/********************************************************************
+ * fence
+ */
+
+
static void
trace_screen_fence_reference(struct pipe_screen *_screen,
struct pipe_fence_handle **dst,
diff --git a/src/gallium/drivers/trace/tr_state.c b/src/gallium/drivers/trace/tr_state.c
index 6c02826d9e2..11384b9892b 100644
--- a/src/gallium/drivers/trace/tr_state.c
+++ b/src/gallium/drivers/trace/tr_state.c
@@ -230,7 +230,7 @@ void trace_dump_constant_buffer(const struct pipe_constant_buffer *state)
trace_dump_struct_begin("pipe_constant_buffer");
- trace_dump_member(ptr, state, buffer);
+ trace_dump_member(buffer_ptr, state, buffer);
trace_dump_struct_end();
}
@@ -469,7 +469,7 @@ void trace_dump_vertex_buffer(const struct pipe_vertex_buffer *state)
trace_dump_member(uint, state, stride);
trace_dump_member(uint, state, max_index);
trace_dump_member(uint, state, buffer_offset);
- trace_dump_member(ptr, state, buffer);
+ trace_dump_member(buffer_ptr, state, buffer);
trace_dump_struct_end();
}