gallium/cso: allow saving the first fragment shader image slot
authorNicolai Hähnle <nicolai.haehnle@amd.com>
Wed, 27 Apr 2016 00:54:41 +0000 (19:54 -0500)
committerNicolai Hähnle <nicolai.haehnle@amd.com>
Wed, 1 Jun 2016 20:37:15 +0000 (22:37 +0200)
Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/gallium/auxiliary/cso_cache/cso_context.c
src/gallium/auxiliary/cso_cache/cso_context.h
src/mesa/state_tracker/st_atom_image.c

index 5206acae8f4a11ca8bb536efdb2c297e0be02d13..b84d5997aaa893a127d9723499d4091790d1246c 100644 (file)
@@ -91,6 +91,9 @@ struct cso_context {
    struct pipe_constant_buffer aux_constbuf_current[PIPE_SHADER_TYPES];
    struct pipe_constant_buffer aux_constbuf_saved[PIPE_SHADER_TYPES];
 
+   struct pipe_image_view fragment_image0_current;
+   struct pipe_image_view fragment_image0_saved;
+
    unsigned nr_so_targets;
    struct pipe_stream_output_target *so_targets[PIPE_MAX_SO_BUFFERS];
 
@@ -371,6 +374,9 @@ void cso_destroy_context( struct cso_context *ctx )
       pipe_resource_reference(&ctx->aux_constbuf_saved[i].buffer, NULL);
    }
 
+   pipe_resource_reference(&ctx->fragment_image0_current.resource, NULL);
+   pipe_resource_reference(&ctx->fragment_image0_saved.resource, 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);
@@ -1352,6 +1358,35 @@ cso_restore_fragment_sampler_views(struct cso_context *ctx)
 }
 
 
+void
+cso_set_shader_images(struct cso_context *ctx, unsigned shader_stage,
+                      unsigned start, unsigned count,
+                      struct pipe_image_view *images)
+{
+   if (shader_stage == PIPE_SHADER_FRAGMENT && start == 0 && count >= 1) {
+      util_copy_image_view(&ctx->fragment_image0_current, &images[0]);
+   }
+
+   ctx->pipe->set_shader_images(ctx->pipe, shader_stage, start, count, images);
+}
+
+
+static void
+cso_save_fragment_image0(struct cso_context *ctx)
+{
+   util_copy_image_view(&ctx->fragment_image0_saved,
+                        &ctx->fragment_image0_current);
+}
+
+
+static void
+cso_restore_fragment_image0(struct cso_context *ctx)
+{
+   cso_set_shader_images(ctx, PIPE_SHADER_FRAGMENT, 0, 1,
+                         &ctx->fragment_image0_saved);
+}
+
+
 void
 cso_set_stream_outputs(struct cso_context *ctx,
                        unsigned num_targets,
@@ -1541,6 +1576,8 @@ cso_save_state(struct cso_context *cso, unsigned state_mask)
       cso_save_viewport(cso);
    if (state_mask & CSO_BIT_PAUSE_QUERIES)
       cso->pipe->set_active_query_state(cso->pipe, false);
+   if (state_mask & CSO_BIT_FRAGMENT_IMAGE0)
+      cso_save_fragment_image0(cso);
 }
 
 
@@ -1594,6 +1631,8 @@ cso_restore_state(struct cso_context *cso)
       cso_restore_viewport(cso);
    if (state_mask & CSO_BIT_PAUSE_QUERIES)
       cso->pipe->set_active_query_state(cso->pipe, true);
+   if (state_mask & CSO_BIT_FRAGMENT_IMAGE0)
+      cso_restore_fragment_image0(cso);
 
    cso->saved_state = 0;
 }
index e27cbe9f7216b24be72f970f9c29c974a520a6ff..a4309c7684ca6a9d99d721ea4af9fdf4ee202acc 100644 (file)
@@ -171,6 +171,7 @@ void cso_set_render_condition(struct cso_context *cso,
 #define CSO_BIT_VERTEX_SHADER         0x20000
 #define CSO_BIT_VIEWPORT              0x40000
 #define CSO_BIT_PAUSE_QUERIES         0x80000
+#define CSO_BIT_FRAGMENT_IMAGE0      0x100000
 
 #define CSO_BITS_ALL_SHADERS (CSO_BIT_VERTEX_SHADER | \
                               CSO_BIT_FRAGMENT_SHADER | \
@@ -191,6 +192,14 @@ cso_set_sampler_views(struct cso_context *cso,
                       struct pipe_sampler_view **views);
 
 
+/* shader images */
+
+void
+cso_set_shader_images(struct cso_context *cso, unsigned shader_stage,
+                      unsigned start, unsigned count,
+                      struct pipe_image_view *views);
+
+
 /* constant buffers */
 
 void cso_set_constant_buffer(struct cso_context *cso, unsigned shader_stage,
index e96d10a196c25a4d43fd9ff5237515c3a2de7ffc..9b8f5059ac0e2ede1a2061cc221a8e0684241fe5 100644 (file)
@@ -34,6 +34,7 @@
 #include "pipe/p_defines.h"
 #include "util/u_inlines.h"
 #include "util/u_surface.h"
+#include "cso_cache/cso_context.h"
 
 #include "st_cb_texture.h"
 #include "st_debug.h"
@@ -122,12 +123,12 @@ st_bind_images(struct st_context *st, struct gl_shader *shader,
          }
       }
    }
-   st->pipe->set_shader_images(st->pipe, shader_type, 0, shader->NumImages,
-                               images);
+   cso_set_shader_images(st->cso_context, shader_type, 0, shader->NumImages,
+                         images);
    /* clear out any stale shader images */
    if (shader->NumImages < c->MaxImageUniforms)
-      st->pipe->set_shader_images(
-            st->pipe, shader_type,
+      cso_set_shader_images(
+            st->cso_context, shader_type,
             shader->NumImages,
             c->MaxImageUniforms - shader->NumImages,
             NULL);