cso: Store pointers to struct cso_sampler in struct sampler_info
authorMichel Dänzer <michel.daenzer@amd.com>
Fri, 16 Dec 2016 02:13:26 +0000 (11:13 +0900)
committerMichel Dänzer <michel@daenzer.net>
Mon, 19 Dec 2016 08:50:17 +0000 (17:50 +0900)
Preparation for following changes, no functional change intended.

Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
src/gallium/auxiliary/cso_cache/cso_context.c

index 2ee87f91848e9ed8efbe582dbe59cfea9f96c638..f52969d3668ca3ba4d0fda58ae09fea0fbbcaa73 100644 (file)
@@ -55,6 +55,7 @@
  */
 struct sampler_info
 {
+   struct cso_sampler *cso_samplers[PIPE_MAX_SAMPLERS];
    void *samplers[PIPE_MAX_SAMPLERS];
    unsigned nr_samplers;
 };
@@ -79,9 +80,7 @@ struct cso_context {
    struct pipe_sampler_view *fragment_views_saved[PIPE_MAX_SHADER_SAMPLER_VIEWS];
    unsigned nr_fragment_views_saved;
 
-   void *fragment_samplers_saved[PIPE_MAX_SAMPLERS];
-   unsigned nr_fragment_samplers_saved;
-
+   struct sampler_info fragment_samplers_saved;
    struct sampler_info samplers[PIPE_SHADER_TYPES];
 
    struct pipe_vertex_buffer aux_vertex_buffer_current;
@@ -1164,18 +1163,17 @@ enum pipe_error
 cso_single_sampler(struct cso_context *ctx, unsigned shader_stage,
                    unsigned idx, const struct pipe_sampler_state *templ)
 {
-   void *handle = NULL;
-
    if (templ) {
       unsigned key_size = sizeof(struct pipe_sampler_state);
       unsigned hash_key = cso_construct_key((void*)templ, key_size);
+      struct cso_sampler *cso;
       struct cso_hash_iter iter =
          cso_find_state_template(ctx->cache,
                                  hash_key, CSO_SAMPLER,
                                  (void *) templ, key_size);
 
       if (cso_hash_iter_is_null(iter)) {
-         struct cso_sampler *cso = MALLOC(sizeof(struct cso_sampler));
+         cso = MALLOC(sizeof(struct cso_sampler));
          if (!cso)
             return PIPE_ERROR_OUT_OF_MEMORY;
 
@@ -1190,15 +1188,18 @@ cso_single_sampler(struct cso_context *ctx, unsigned shader_stage,
             FREE(cso);
             return PIPE_ERROR_OUT_OF_MEMORY;
          }
-
-         handle = cso->data;
       }
       else {
-         handle = ((struct cso_sampler *)cso_hash_iter_data(iter))->data;
+         cso = cso_hash_iter_data(iter);
       }
+
+      ctx->samplers[shader_stage].cso_samplers[idx] = cso;
+      ctx->samplers[shader_stage].samplers[idx] = cso->data;
+   } else {
+      ctx->samplers[shader_stage].cso_samplers[idx] = NULL;
+      ctx->samplers[shader_stage].samplers[idx] = NULL;
    }
 
-   ctx->samplers[shader_stage].samplers[idx] = handle;
    return PIPE_OK;
 }
 
@@ -1263,10 +1264,11 @@ static void
 cso_save_fragment_samplers(struct cso_context *ctx)
 {
    struct sampler_info *info = &ctx->samplers[PIPE_SHADER_FRAGMENT];
+   struct sampler_info *saved = &ctx->fragment_samplers_saved;
 
-   ctx->nr_fragment_samplers_saved = info->nr_samplers;
-   memcpy(ctx->fragment_samplers_saved, info->samplers,
-          sizeof(info->samplers));
+   saved->nr_samplers = info->nr_samplers;
+   memcpy(saved->cso_samplers, info->cso_samplers, sizeof(info->cso_samplers));
+   memcpy(saved->samplers, info->samplers, sizeof(info->samplers));
 }
 
 
@@ -1274,9 +1276,10 @@ static void
 cso_restore_fragment_samplers(struct cso_context *ctx)
 {
    struct sampler_info *info = &ctx->samplers[PIPE_SHADER_FRAGMENT];
+   struct sampler_info *saved = &ctx->fragment_samplers_saved;
 
-   memcpy(info->samplers, ctx->fragment_samplers_saved,
-          sizeof(info->samplers));
+   memcpy(info->cso_samplers, saved->cso_samplers, sizeof(info->cso_samplers));
+   memcpy(info->samplers, saved->samplers, sizeof(info->samplers));
    cso_single_sampler_done(ctx, PIPE_SHADER_FRAGMENT);
 }