summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/failover
diff options
context:
space:
mode:
authorChia-I Wu <[email protected]>2010-07-16 04:35:58 +0800
committerChia-I Wu <[email protected]>2010-07-29 13:45:30 +0800
commit6d28bf917fb1d741d90fd3f05c22769376021fca (patch)
tree9b8724b30658d61426297113136c2d23c0c62f14 /src/gallium/drivers/failover
parentc5e9d3114a80d6d35a2f4e65783cdc75fcc2deac (diff)
gallium: Implement draw_vbo and set_index_buffer for all drivers.
Some drivers define a generic function that is called by all drawing functions. To implement draw_vbo for such drivers, either draw_vbo calls the generic function or the prototype of the generic function is changed to match draw_vbo. Other drivers have no such generic function. draw_vbo is implemented by calling either draw_arrays and draw_elements. For most drivers, set_index_buffer does not mark the state dirty for tracking. Instead, the index buffer state is emitted whenever draw_vbo is called, just like the case with draw_elements. It surely can be improved.
Diffstat (limited to 'src/gallium/drivers/failover')
-rw-r--r--src/gallium/drivers/failover/fo_context.c61
-rw-r--r--src/gallium/drivers/failover/fo_context.h2
-rw-r--r--src/gallium/drivers/failover/fo_state.c18
-rw-r--r--src/gallium/drivers/failover/fo_state_emit.c5
4 files changed, 65 insertions, 21 deletions
diff --git a/src/gallium/drivers/failover/fo_context.c b/src/gallium/drivers/failover/fo_context.c
index 9c9c1bdc452..1048d58313d 100644
--- a/src/gallium/drivers/failover/fo_context.c
+++ b/src/gallium/drivers/failover/fo_context.c
@@ -28,6 +28,7 @@
#include "pipe/p_defines.h"
#include "util/u_memory.h"
+#include "util/u_draw_quad.h"
#include "pipe/p_context.h"
#include "fo_context.h"
@@ -50,13 +51,8 @@ void failover_fail_over( struct failover_context *failover )
}
-static void failover_draw_elements( struct pipe_context *pipe,
- struct pipe_resource *indexResource,
- unsigned indexSize,
- int indexBias,
- unsigned prim,
- unsigned start,
- unsigned count)
+static void failover_draw_vbo( struct pipe_context *pipe,
+ const struct pipe_draw_info *info)
{
struct failover_context *failover = failover_context( pipe );
@@ -70,13 +66,7 @@ static void failover_draw_elements( struct pipe_context *pipe,
/* Try hardware:
*/
if (failover->mode == FO_HW) {
- failover->hw->draw_elements( failover->hw,
- indexResource,
- indexSize,
- indexBias,
- prim,
- start,
- count );
+ failover->hw->draw_vbo( failover->hw, info );
}
/* Possibly try software:
@@ -88,13 +78,7 @@ static void failover_draw_elements( struct pipe_context *pipe,
failover_state_emit( failover );
}
- failover->sw->draw_elements( failover->sw,
- indexResource,
- indexSize,
- indexBias,
- prim,
- start,
- count );
+ failover->sw->draw_vbo( failover->sw, info );
/* Be ready to switch back to hardware rendering without an
* intervening flush. Unlikely to be much performance impact to
@@ -105,6 +89,40 @@ static void failover_draw_elements( struct pipe_context *pipe,
}
+static void failover_draw_elements( struct pipe_context *pipe,
+ struct pipe_resource *indexResource,
+ unsigned indexSize,
+ int indexBias,
+ unsigned prim,
+ unsigned start,
+ unsigned count)
+{
+ struct failover_context *failover = failover_context( pipe );
+ struct pipe_draw_info info;
+ struct pipe_index_buffer saved_ib, ib;
+
+ util_draw_init_info(&info);
+ info.mode = prim;
+ info.start = start;
+ info.count = count;
+
+ if (indexResource) {
+ info.indexed = TRUE;
+ saved_ib = failover->index_buffer;
+
+ ib.buffer = indexResource;
+ ib.offset = 0;
+ ib.index_size = indexSize;
+ pipe->set_index_buffer(pipe, &ib);
+ }
+
+ failover_draw_vbo(pipe, &info);
+
+ if (indexResource)
+ pipe->set_index_buffer(pipe, &saved_ib);
+}
+
+
static void failover_draw_arrays( struct pipe_context *pipe,
unsigned prim, unsigned start, unsigned count)
{
@@ -145,6 +163,7 @@ struct pipe_context *failover_create( struct pipe_context *hw,
failover->pipe.draw_arrays = failover_draw_arrays;
failover->pipe.draw_elements = failover_draw_elements;
+ failover->pipe.draw_vbo = failover_draw_vbo;
failover->pipe.clear = hw->clear;
failover->pipe.clear_render_target = hw->clear_render_target;
failover->pipe.clear_depth_stencil = hw->clear_depth_stencil;
diff --git a/src/gallium/drivers/failover/fo_context.h b/src/gallium/drivers/failover/fo_context.h
index 9d3e0d0dba0..1afa6c9ceed 100644
--- a/src/gallium/drivers/failover/fo_context.h
+++ b/src/gallium/drivers/failover/fo_context.h
@@ -56,6 +56,7 @@
#define FO_NEW_VERTEX_BUFFER 0x40000
#define FO_NEW_VERTEX_ELEMENT 0x80000
#define FO_NEW_SAMPLE_MASK 0x100000
+#define FO_NEW_INDEX_BUFFER 0x200000
@@ -97,6 +98,7 @@ struct failover_context {
struct pipe_scissor_state scissor;
struct pipe_viewport_state viewport;
struct pipe_vertex_buffer vertex_buffers[PIPE_MAX_ATTRIBS];
+ struct pipe_index_buffer index_buffer;
uint num_vertex_buffers;
diff --git a/src/gallium/drivers/failover/fo_state.c b/src/gallium/drivers/failover/fo_state.c
index 12e42379f98..c265f381b67 100644
--- a/src/gallium/drivers/failover/fo_state.c
+++ b/src/gallium/drivers/failover/fo_state.c
@@ -583,6 +583,23 @@ failover_set_vertex_buffers(struct pipe_context *pipe,
}
+static void
+failover_set_index_buffer(struct pipe_context *pipe,
+ const struct pipe_index_buffer *ib)
+{
+ struct failover_context *failover = failover_context(pipe);
+
+ if (ib)
+ memcpy(&failover->index_buffer, ib, sizeof(failover->index_buffer));
+ else
+ memset(&failover->index_buffer, 0, sizeof(failover->index_buffer));
+
+ failover->dirty |= FO_NEW_INDEX_BUFFER;
+ failover->sw->set_index_buffer( failover->sw, ib );
+ failover->hw->set_index_buffer( failover->hw, ib );
+}
+
+
void
failover_set_constant_buffer(struct pipe_context *pipe,
uint shader, uint index,
@@ -635,6 +652,7 @@ failover_init_state_functions( struct failover_context *failover )
failover->pipe.set_vertex_sampler_views = failover_set_vertex_sampler_views;
failover->pipe.set_viewport_state = failover_set_viewport_state;
failover->pipe.set_vertex_buffers = failover_set_vertex_buffers;
+ failover->pipe.set_index_buffer = failover_set_index_buffer;
failover->pipe.set_constant_buffer = failover_set_constant_buffer;
failover->pipe.create_sampler_view = failover_create_sampler_view;
failover->pipe.sampler_view_destroy = failover_sampler_view_destroy;
diff --git a/src/gallium/drivers/failover/fo_state_emit.c b/src/gallium/drivers/failover/fo_state_emit.c
index 147f23269ca..7f434ff9d68 100644
--- a/src/gallium/drivers/failover/fo_state_emit.c
+++ b/src/gallium/drivers/failover/fo_state_emit.c
@@ -135,5 +135,10 @@ failover_state_emit( struct failover_context *failover )
failover->vertex_buffers );
}
+ if (failover->dirty & FO_NEW_INDEX_BUFFER) {
+ failover->sw->set_index_buffer( failover->sw,
+ &failover->index_buffer );
+ }
+
failover->dirty = 0;
}