u_blitter: add support for saving vertex buffers
authorLuca Barbieri <luca@luca-barbieri.com>
Sun, 18 Apr 2010 12:50:14 +0000 (14:50 +0200)
committerLuca Barbieri <luca@luca-barbieri.com>
Sun, 18 Apr 2010 13:29:23 +0000 (15:29 +0200)
Currently r300g does not save vertex buffer on blitter calls.

It gets away with it because the current Mesa state tracker usually
resets vertex buffers on every draw calls.

However, this is wrong.

nvfx won't be lucky because it needs to use the blitter inside draw
calls.

src/gallium/auxiliary/util/u_blitter.c
src/gallium/auxiliary/util/u_blitter.h

index f3b42f7bf9cf4f1806c1f13353e2dee6b24021fb..956aedc8a15a66af726912450a9a894d80d6e9c3 100644 (file)
@@ -132,6 +132,7 @@ struct blitter_context *util_blitter_create(struct pipe_context *pipe)
    ctx->blitter.saved_fb_state.nr_cbufs = ~0;
    ctx->blitter.saved_num_sampler_views = ~0;
    ctx->blitter.saved_num_sampler_states = ~0;
+   ctx->blitter.saved_num_vertex_buffers = ~0;
 
    /* blend state objects */
    memset(&blend, 0, sizeof(blend));
@@ -318,6 +319,13 @@ static void blitter_restore_CSOs(struct blitter_context_priv *ctx)
                                        ctx->blitter.saved_sampler_views);
       ctx->blitter.saved_num_sampler_views = ~0;
    }
+
+   if (ctx->blitter.saved_num_vertex_buffers != ~0) {
+      pipe->set_vertex_buffers(pipe,
+                                       ctx->blitter.saved_num_vertex_buffers,
+                                       ctx->blitter.saved_vertex_buffers);
+      ctx->blitter.saved_num_vertex_buffers = ~0;
+   }
 }
 
 static void blitter_set_rectangle(struct blitter_context_priv *ctx,
index 2ad7201a29d96a5abdd010999bd1a3d066b3df30..f6e3ce4874ecb2e655045317433e966e667e4961 100644 (file)
@@ -57,6 +57,9 @@ struct blitter_context
 
    int saved_num_sampler_views;
    struct pipe_sampler_view *saved_sampler_views[PIPE_MAX_SAMPLERS];
+
+   int saved_num_vertex_buffers;
+   struct pipe_vertex_buffer saved_vertex_buffers[PIPE_MAX_ATTRIBS];
 };
 
 /**
@@ -255,6 +258,19 @@ util_blitter_save_fragment_sampler_views(struct blitter_context *blitter,
           num_views * sizeof(struct pipe_sampler_view *));
 }
 
+static INLINE void
+util_blitter_save_vertex_buffers(struct blitter_context *blitter,
+                                         int num_vertex_buffers,
+                                         struct pipe_vertex_buffer *vertex_buffers)
+{
+   assert(num_vertex_buffers <= Elements(blitter->saved_vertex_buffers));
+
+   blitter->saved_num_vertex_buffers = num_vertex_buffers;
+   memcpy(blitter->saved_vertex_buffers,
+          vertex_buffers,
+          num_vertex_buffers * sizeof(struct pipe_vertex_buffer));
+}
+
 #ifdef __cplusplus
 }
 #endif