summaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary/cso_cache/cso_context.c
diff options
context:
space:
mode:
authorMarek Olšák <[email protected]>2013-03-18 22:36:21 +0100
committerMarek Olšák <[email protected]>2013-03-26 01:28:18 +0100
commitd1b91e309be2467829aa71ebdcb5a8f78e30e781 (patch)
tree6103f83763ae7aadbb01c027b49683f63b3dd92f /src/gallium/auxiliary/cso_cache/cso_context.c
parent35c522dce461a7d18a471e681413781da702d4b0 (diff)
cso: add constant buffer save/restore feature for postprocessing
Postprocessing is an internal meta op and should restore the states it changes.
Diffstat (limited to 'src/gallium/auxiliary/cso_cache/cso_context.c')
-rw-r--r--src/gallium/auxiliary/cso_cache/cso_context.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c b/src/gallium/auxiliary/cso_cache/cso_context.c
index 3f6fd8cbb76..e46f2abf632 100644
--- a/src/gallium/auxiliary/cso_cache/cso_context.c
+++ b/src/gallium/auxiliary/cso_cache/cso_context.c
@@ -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