cso: add constant buffer save/restore feature for postprocessing
authorMarek Olšák <maraeo@gmail.com>
Mon, 18 Mar 2013 21:36:21 +0000 (22:36 +0100)
committerMarek Olšák <maraeo@gmail.com>
Tue, 26 Mar 2013 00:28:18 +0000 (01:28 +0100)
Postprocessing is an internal meta op and should restore the states
it changes.

src/gallium/auxiliary/cso_cache/cso_context.c
src/gallium/auxiliary/cso_cache/cso_context.h
src/gallium/auxiliary/postprocess/pp_mlaa.c
src/gallium/auxiliary/postprocess/pp_run.c
src/mesa/state_tracker/st_atom_constbuf.c

index 3f6fd8cbb76bb725f5107f5cf03c3ccfe6956d84..e46f2abf6328c476b58f50a5ce99076202a9c929 100644 (file)
@@ -90,6 +90,9 @@ struct cso_context {
    struct pipe_vertex_buffer aux_vertex_buffer_saved;
    unsigned aux_vertex_buffer_index;
 
+   struct pipe_constant_buffer aux_constbuf_current[PIPE_SHADER_TYPES];
+   struct pipe_constant_buffer aux_constbuf_saved[PIPE_SHADER_TYPES];
+
    unsigned nr_so_targets;
    struct pipe_stream_output_target *so_targets[PIPE_MAX_SO_BUFFERS];
 
@@ -329,6 +332,11 @@ void cso_release_all( struct cso_context *ctx )
    pipe_resource_reference(&ctx->aux_vertex_buffer_current.buffer, NULL);
    pipe_resource_reference(&ctx->aux_vertex_buffer_saved.buffer, NULL);
 
+   for (i = 0; i < PIPE_SHADER_TYPES; i++) {
+      pipe_resource_reference(&ctx->aux_constbuf_current[i].buffer, NULL);
+      pipe_resource_reference(&ctx->aux_constbuf_saved[i].buffer, NULL);
+   }
+
    for (i = 0; i < PIPE_MAX_SO_BUFFERS; i++) {
       pipe_so_target_reference(&ctx->so_targets[i], NULL);
       pipe_so_target_reference(&ctx->so_targets_saved[i], NULL);
@@ -1318,6 +1326,57 @@ cso_restore_stream_outputs(struct cso_context *ctx)
    ctx->nr_so_targets_saved = 0;
 }
 
+/* constant buffers */
+
+void
+cso_set_constant_buffer(struct cso_context *cso, unsigned shader_stage,
+                        unsigned index, struct pipe_constant_buffer *cb)
+{
+   struct pipe_context *pipe = cso->pipe;
+
+   pipe->set_constant_buffer(pipe, shader_stage, index, cb);
+
+   if (index == 0) {
+      util_copy_constant_buffer(&cso->aux_constbuf_current[shader_stage], cb);
+   }
+}
+
+void
+cso_set_constant_buffer_resource(struct cso_context *cso,
+                                 unsigned shader_stage,
+                                 unsigned index,
+                                 struct pipe_resource *buffer)
+{
+   if (buffer) {
+      struct pipe_constant_buffer cb;
+      cb.buffer = buffer;
+      cb.buffer_offset = 0;
+      cb.buffer_size = buffer->width0;
+      cb.user_buffer = NULL;
+      cso_set_constant_buffer(cso, shader_stage, index, &cb);
+   } else {
+      cso_set_constant_buffer(cso, shader_stage, index, NULL);
+   }
+}
+
+void
+cso_save_constant_buffer_slot0(struct cso_context *cso,
+                                  unsigned shader_stage)
+{
+   util_copy_constant_buffer(&cso->aux_constbuf_saved[shader_stage],
+                             &cso->aux_constbuf_current[shader_stage]);
+}
+
+void
+cso_restore_constant_buffer_slot0(struct cso_context *cso,
+                                     unsigned shader_stage)
+{
+   cso_set_constant_buffer(cso, shader_stage, 0,
+                           &cso->aux_constbuf_saved[shader_stage]);
+   pipe_resource_reference(&cso->aux_constbuf_saved[shader_stage].buffer,
+                           NULL);
+}
+
 /* drawing */
 
 void
index e8f5a9f77bf101b11b7da9b0a8ac69f360caae44..20ab4ef1aaa19c5751cc2f542581771d48076d65 100644 (file)
@@ -203,6 +203,19 @@ void
 cso_restore_sampler_views(struct cso_context *cso, unsigned shader_stage);
 
 
+/* constant buffers */
+
+void cso_set_constant_buffer(struct cso_context *cso, unsigned shader_stage,
+                             unsigned index, struct pipe_constant_buffer *cb);
+void cso_set_constant_buffer_resource(struct cso_context *cso,
+                                      unsigned shader_stage,
+                                      unsigned index,
+                                      struct pipe_resource *buffer);
+void cso_save_constant_buffer_slot0(struct cso_context *cso,
+                                    unsigned shader_stage);
+void cso_restore_constant_buffer_slot0(struct cso_context *cso,
+                                       unsigned shader_stage);
+
 
 /* drawing */
 
index fcbc573c70a7d7b5bdb4239d9f66c1af3d0eb86e..6d9fa9aa3ddcc89511f747a59331a9f2d5a511f6 100644 (file)
@@ -99,8 +99,8 @@ pp_jimenezmlaa_run(struct pp_queue_t *ppq, struct pipe_resource *in,
       dimensions[1] = p->framebuffer.height;
    }
 
-   pipe_set_constant_buffer(p->pipe, PIPE_SHADER_VERTEX, 0, constbuf);
-   pipe_set_constant_buffer(p->pipe, PIPE_SHADER_FRAGMENT, 0, constbuf);
+   cso_set_constant_buffer_resource(p->cso, PIPE_SHADER_VERTEX, 0, constbuf);
+   cso_set_constant_buffer_resource(p->cso, PIPE_SHADER_FRAGMENT, 0, constbuf);
 
    mstencil.stencil[0].enabled = 1;
    mstencil.stencil[0].valuemask = mstencil.stencil[0].writemask = ~0;
index 0bed547bd445ac327ce88b8b4a065197bb3875e2..54a513e16b1ba2b97dfc21f20e245a2148813c45 100644 (file)
@@ -82,6 +82,8 @@ pp_run(struct pp_queue_t *ppq, struct pipe_resource *in,
    cso_save_vertex_shader(cso);
    cso_save_viewport(cso);
    cso_save_aux_vertex_buffer_slot(cso);
+   cso_save_constant_buffer_slot0(cso, PIPE_SHADER_VERTEX);
+   cso_save_constant_buffer_slot0(cso, PIPE_SHADER_FRAGMENT);
    cso_save_render_condition(cso);
 
    /* set default state */
@@ -141,6 +143,8 @@ pp_run(struct pp_queue_t *ppq, struct pipe_resource *in,
    cso_restore_vertex_shader(cso);
    cso_restore_viewport(cso);
    cso_restore_aux_vertex_buffer_slot(cso);
+   cso_restore_constant_buffer_slot0(cso, PIPE_SHADER_VERTEX);
+   cso_restore_constant_buffer_slot0(cso, PIPE_SHADER_FRAGMENT);
    cso_restore_render_condition(cso);
 
    pipe_resource_reference(&ppq->depth, NULL);
index 961fb28a967442c0f3570d45cae9e39dfe0d9d2d..56ba96fe3628ddedf3cabf790d6253441b730e7e 100644 (file)
@@ -39,6 +39,7 @@
 #include "pipe/p_defines.h"
 #include "util/u_inlines.h"
 #include "util/u_upload_mgr.h"
+#include "cso_cache/cso_context.h"
 
 #include "st_debug.h"
 #include "st_context.h"
@@ -96,16 +97,17 @@ void st_upload_constants( struct st_context *st,
          _mesa_print_parameter_list(params);
       }
 
-      st->pipe->set_constant_buffer(st->pipe, shader_type, 0, &cb);
+      cso_set_constant_buffer(st->cso_context, shader_type, 0, &cb);
       pipe_resource_reference(&cb.buffer, NULL);
 
       st->state.constants[shader_type].ptr = params->ParameterValues;
       st->state.constants[shader_type].size = paramBytes;
    }
    else if (st->state.constants[shader_type].ptr) {
+      /* Unbind. */
       st->state.constants[shader_type].ptr = NULL;
       st->state.constants[shader_type].size = 0;
-      st->pipe->set_constant_buffer(st->pipe, shader_type, 0, NULL);
+      cso_set_constant_buffer(st->cso_context, shader_type, 0, NULL);
    }
 }
 
@@ -196,7 +198,7 @@ static void st_bind_ubos(struct st_context *st,
 
       cb.buffer_size = st_obj->buffer->width0 - binding->Offset;
 
-      st->pipe->set_constant_buffer(st->pipe, shader_type, 1 + i, &cb);
+      cso_set_constant_buffer(st->cso_context, shader_type, 1 + i, &cb);
       pipe_resource_reference(&cb.buffer, NULL);
    }
 }