st/mesa: don't store non-fragment sampler states and views in st_context
authorMarek Olšák <marek.olsak@amd.com>
Wed, 15 Nov 2017 23:32:22 +0000 (00:32 +0100)
committerMarek Olšák <marek.olsak@amd.com>
Thu, 8 Feb 2018 15:14:11 +0000 (16:14 +0100)
those are unused.

st_context: 10120 -> 3704 bytes

Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
src/mesa/state_tracker/st_atom_sampler.c
src/mesa/state_tracker/st_atom_texture.c
src/mesa/state_tracker/st_cb_bitmap.c
src/mesa/state_tracker/st_cb_drawpixels.c
src/mesa/state_tracker/st_context.c
src/mesa/state_tracker/st_context.h

index 6d83f963f0aab52d792afb8063b43cecef579bf4..289856cd72dead995bc2543a879454d6e3e92ea2 100644 (file)
@@ -258,13 +258,18 @@ update_shader_samplers(struct st_context *st,
    GLbitfield free_slots = ~prog->SamplersUsed;
    GLbitfield external_samplers_used = prog->ExternalSamplersUsed;
    unsigned unit, num_samplers;
+   struct pipe_sampler_state local_samplers[PIPE_MAX_SAMPLERS];
    const struct pipe_sampler_state *states[PIPE_MAX_SAMPLERS];
 
    if (samplers_used == 0x0) {
-      *out_num_samplers = 0;
+      if (out_num_samplers)
+         *out_num_samplers = 0;
       return;
    }
 
+   if (!samplers)
+      samplers = local_samplers;
+
    num_samplers = util_last_bit(samplers_used);
 
    /* loop over sampler units (aka tex image units) */
@@ -320,7 +325,9 @@ update_shader_samplers(struct st_context *st,
    }
 
    cso_set_samplers(st->cso_context, shader_stage, num_samplers, states);
-   *out_num_samplers = num_samplers;
+
+   if (out_num_samplers)
+      *out_num_samplers = num_samplers;
 }
 
 
@@ -331,9 +338,7 @@ st_update_vertex_samplers(struct st_context *st)
 
    update_shader_samplers(st,
                           PIPE_SHADER_VERTEX,
-                          ctx->VertexProgram._Current,
-                          st->state.samplers[PIPE_SHADER_VERTEX],
-                          &st->state.num_samplers[PIPE_SHADER_VERTEX]);
+                          ctx->VertexProgram._Current, NULL, NULL);
 }
 
 
@@ -345,9 +350,7 @@ st_update_tessctrl_samplers(struct st_context *st)
    if (ctx->TessCtrlProgram._Current) {
       update_shader_samplers(st,
                              PIPE_SHADER_TESS_CTRL,
-                             ctx->TessCtrlProgram._Current,
-                             st->state.samplers[PIPE_SHADER_TESS_CTRL],
-                             &st->state.num_samplers[PIPE_SHADER_TESS_CTRL]);
+                             ctx->TessCtrlProgram._Current, NULL, NULL);
    }
 }
 
@@ -360,9 +363,7 @@ st_update_tesseval_samplers(struct st_context *st)
    if (ctx->TessEvalProgram._Current) {
       update_shader_samplers(st,
                              PIPE_SHADER_TESS_EVAL,
-                             ctx->TessEvalProgram._Current,
-                             st->state.samplers[PIPE_SHADER_TESS_EVAL],
-                             &st->state.num_samplers[PIPE_SHADER_TESS_EVAL]);
+                             ctx->TessEvalProgram._Current, NULL, NULL);
    }
 }
 
@@ -375,9 +376,7 @@ st_update_geometry_samplers(struct st_context *st)
    if (ctx->GeometryProgram._Current) {
       update_shader_samplers(st,
                              PIPE_SHADER_GEOMETRY,
-                             ctx->GeometryProgram._Current,
-                             st->state.samplers[PIPE_SHADER_GEOMETRY],
-                             &st->state.num_samplers[PIPE_SHADER_GEOMETRY]);
+                             ctx->GeometryProgram._Current, NULL, NULL);
    }
 }
 
@@ -390,8 +389,8 @@ st_update_fragment_samplers(struct st_context *st)
    update_shader_samplers(st,
                           PIPE_SHADER_FRAGMENT,
                           ctx->FragmentProgram._Current,
-                          st->state.samplers[PIPE_SHADER_FRAGMENT],
-                          &st->state.num_samplers[PIPE_SHADER_FRAGMENT]);
+                          st->state.frag_samplers,
+                          &st->state.num_frag_samplers);
 }
 
 
@@ -403,8 +402,6 @@ st_update_compute_samplers(struct st_context *st)
    if (ctx->ComputeProgram._Current) {
       update_shader_samplers(st,
                              PIPE_SHADER_COMPUTE,
-                             ctx->ComputeProgram._Current,
-                             st->state.samplers[PIPE_SHADER_COMPUTE],
-                             &st->state.num_samplers[PIPE_SHADER_COMPUTE]);
+                             ctx->ComputeProgram._Current, NULL, NULL);
    }
 }
index 6c26b7751b2a6a070651d3eee543916480406d11..105fa79de0242ce2aa628fb7996f8b6c2c7f9b06 100644 (file)
@@ -216,7 +216,21 @@ update_textures(struct st_context *st,
    *out_num_textures = num_textures;
 }
 
+/* Same as update_textures, but don't store the views in st_context. */
+static void
+update_textures_local(struct st_context *st,
+                      enum pipe_shader_type shader_stage,
+                      const struct gl_program *prog,
+                      unsigned *out_num_textures)
+{
+   struct pipe_sampler_view *local_views[PIPE_MAX_SAMPLERS] = {0};
 
+   update_textures(st, shader_stage, prog, local_views, out_num_textures);
+
+   unsigned num = *out_num_textures;
+   for (unsigned i = 0; i < num; i++)
+      pipe_sampler_view_reference(&local_views[i], NULL);
+}
 
 void
 st_update_vertex_textures(struct st_context *st)
@@ -224,11 +238,9 @@ st_update_vertex_textures(struct st_context *st)
    const struct gl_context *ctx = st->ctx;
 
    if (ctx->Const.Program[MESA_SHADER_VERTEX].MaxTextureImageUnits > 0) {
-      update_textures(st,
-                      PIPE_SHADER_VERTEX,
-                      ctx->VertexProgram._Current,
-                      st->state.sampler_views[PIPE_SHADER_VERTEX],
-                      &st->state.num_sampler_views[PIPE_SHADER_VERTEX]);
+      update_textures_local(st, PIPE_SHADER_VERTEX,
+                            ctx->VertexProgram._Current,
+                            &st->state.num_sampler_views[PIPE_SHADER_VERTEX]);
    }
 }
 
@@ -241,7 +253,7 @@ st_update_fragment_textures(struct st_context *st)
    update_textures(st,
                    PIPE_SHADER_FRAGMENT,
                    ctx->FragmentProgram._Current,
-                   st->state.sampler_views[PIPE_SHADER_FRAGMENT],
+                   st->state.frag_sampler_views,
                    &st->state.num_sampler_views[PIPE_SHADER_FRAGMENT]);
 }
 
@@ -252,11 +264,9 @@ st_update_geometry_textures(struct st_context *st)
    const struct gl_context *ctx = st->ctx;
 
    if (ctx->GeometryProgram._Current) {
-      update_textures(st,
-                      PIPE_SHADER_GEOMETRY,
-                      ctx->GeometryProgram._Current,
-                      st->state.sampler_views[PIPE_SHADER_GEOMETRY],
-                      &st->state.num_sampler_views[PIPE_SHADER_GEOMETRY]);
+      update_textures_local(st, PIPE_SHADER_GEOMETRY,
+                            ctx->GeometryProgram._Current,
+                            &st->state.num_sampler_views[PIPE_SHADER_GEOMETRY]);
    }
 }
 
@@ -267,11 +277,9 @@ st_update_tessctrl_textures(struct st_context *st)
    const struct gl_context *ctx = st->ctx;
 
    if (ctx->TessCtrlProgram._Current) {
-      update_textures(st,
-                      PIPE_SHADER_TESS_CTRL,
-                      ctx->TessCtrlProgram._Current,
-                      st->state.sampler_views[PIPE_SHADER_TESS_CTRL],
-                      &st->state.num_sampler_views[PIPE_SHADER_TESS_CTRL]);
+      update_textures_local(st, PIPE_SHADER_TESS_CTRL,
+                            ctx->TessCtrlProgram._Current,
+                            &st->state.num_sampler_views[PIPE_SHADER_TESS_CTRL]);
    }
 }
 
@@ -282,11 +290,9 @@ st_update_tesseval_textures(struct st_context *st)
    const struct gl_context *ctx = st->ctx;
 
    if (ctx->TessEvalProgram._Current) {
-      update_textures(st,
-                      PIPE_SHADER_TESS_EVAL,
-                      ctx->TessEvalProgram._Current,
-                      st->state.sampler_views[PIPE_SHADER_TESS_EVAL],
-                      &st->state.num_sampler_views[PIPE_SHADER_TESS_EVAL]);
+      update_textures_local(st, PIPE_SHADER_TESS_EVAL,
+                            ctx->TessEvalProgram._Current,
+                            &st->state.num_sampler_views[PIPE_SHADER_TESS_EVAL]);
    }
 }
 
@@ -297,10 +303,8 @@ st_update_compute_textures(struct st_context *st)
    const struct gl_context *ctx = st->ctx;
 
    if (ctx->ComputeProgram._Current) {
-      update_textures(st,
-                      PIPE_SHADER_COMPUTE,
-                      ctx->ComputeProgram._Current,
-                      st->state.sampler_views[PIPE_SHADER_COMPUTE],
-                      &st->state.num_sampler_views[PIPE_SHADER_COMPUTE]);
+      update_textures_local(st, PIPE_SHADER_COMPUTE,
+                            ctx->ComputeProgram._Current,
+                            &st->state.num_sampler_views[PIPE_SHADER_COMPUTE]);
    }
 }
index a5c7ed0ee66d27bcae6d662a25d916361e9c0349..0a30ffa0f38e4e51cef9107ef8811b1b01430a5a 100644 (file)
@@ -224,10 +224,10 @@ setup_render_state(struct gl_context *ctx,
    {
       struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS];
       uint num = MAX2(fpv->bitmap_sampler + 1,
-                      st->state.num_samplers[PIPE_SHADER_FRAGMENT]);
+                      st->state.num_frag_samplers);
       uint i;
-      for (i = 0; i < st->state.num_samplers[PIPE_SHADER_FRAGMENT]; i++) {
-         samplers[i] = &st->state.samplers[PIPE_SHADER_FRAGMENT][i];
+      for (i = 0; i < st->state.num_frag_samplers; i++) {
+         samplers[i] = &st->state.frag_samplers[i];
       }
       if (atlas)
          samplers[fpv->bitmap_sampler] = &st->bitmap.atlas_sampler;
@@ -242,7 +242,7 @@ setup_render_state(struct gl_context *ctx,
       struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS];
       uint num = MAX2(fpv->bitmap_sampler + 1,
                       st->state.num_sampler_views[PIPE_SHADER_FRAGMENT]);
-      memcpy(sampler_views, st->state.sampler_views[PIPE_SHADER_FRAGMENT],
+      memcpy(sampler_views, st->state.frag_sampler_views,
              sizeof(sampler_views));
       sampler_views[fpv->bitmap_sampler] = sv;
       cso_set_sampler_views(cso, PIPE_SHADER_FRAGMENT, num, sampler_views);
index ff3eb9b6143182e9e6caf9cad5715c5a9d629a4e..44f5b235c83ba0d786418a9b66a8cad4ca04797a 100644 (file)
@@ -736,11 +736,11 @@ draw_textured_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
          const struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS];
          uint num = MAX3(fpv->drawpix_sampler + 1,
                          fpv->pixelmap_sampler + 1,
-                         st->state.num_samplers[PIPE_SHADER_FRAGMENT]);
+                         st->state.num_frag_samplers);
          uint i;
 
-         for (i = 0; i < st->state.num_samplers[PIPE_SHADER_FRAGMENT]; i++)
-            samplers[i] = &st->state.samplers[PIPE_SHADER_FRAGMENT][i];
+         for (i = 0; i < st->state.num_frag_samplers; i++)
+            samplers[i] = &st->state.frag_samplers[i];
 
          samplers[fpv->drawpix_sampler] = &sampler;
          if (sv[1])
@@ -763,7 +763,7 @@ draw_textured_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
                       fpv->pixelmap_sampler + 1,
                       st->state.num_sampler_views[PIPE_SHADER_FRAGMENT]);
 
-      memcpy(sampler_views, st->state.sampler_views[PIPE_SHADER_FRAGMENT],
+      memcpy(sampler_views, st->state.frag_sampler_views,
              sizeof(sampler_views));
 
       sampler_views[fpv->drawpix_sampler] = sv[0];
index 8274b9e0a8b549bb896de3826b6d9fd28eb44203..7e721572e0a26b375c3103b6c8dec0c20170fbec 100644 (file)
@@ -254,7 +254,7 @@ st_invalidate_state(struct gl_context *ctx)
 static void
 st_destroy_context_priv(struct st_context *st, bool destroy_pipe)
 {
-   uint shader, i;
+   uint i;
 
    st_destroy_atoms(st);
    st_destroy_draw(st);
@@ -267,11 +267,9 @@ st_destroy_context_priv(struct st_context *st, bool destroy_pipe)
    st_destroy_bound_texture_handles(st);
    st_destroy_bound_image_handles(st);
 
-   for (shader = 0; shader < ARRAY_SIZE(st->state.sampler_views); shader++) {
-      for (i = 0; i < ARRAY_SIZE(st->state.sampler_views[0]); i++) {
-         pipe_sampler_view_release(st->pipe,
-                                   &st->state.sampler_views[shader][i]);
-      }
+   for (i = 0; i < ARRAY_SIZE(st->state.frag_sampler_views); i++) {
+      pipe_sampler_view_release(st->pipe,
+                                &st->state.frag_sampler_views[i]);
    }
 
    /* free glReadPixels cache data */
index ae2bdf596ac9a8838a16aa0823a1cb023565375d..660c993fe22a4b863b469597155de31479176c25 100644 (file)
@@ -151,9 +151,9 @@ struct st_context
       struct pipe_blend_state               blend;
       struct pipe_depth_stencil_alpha_state depth_stencil;
       struct pipe_rasterizer_state          rasterizer;
-      struct pipe_sampler_state samplers[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
-      GLuint num_samplers[PIPE_SHADER_TYPES];
-      struct pipe_sampler_view *sampler_views[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
+      struct pipe_sampler_state frag_samplers[PIPE_MAX_SAMPLERS];
+      GLuint num_frag_samplers;
+      struct pipe_sampler_view *frag_sampler_views[PIPE_MAX_SAMPLERS];
       GLuint num_sampler_views[PIPE_SHADER_TYPES];
       struct pipe_clip_state clip;
       struct {