st/mesa: combine vertex/fragment sampler state in arrays
authorBrian Paul <brianp@vmware.com>
Fri, 10 Aug 2012 02:59:44 +0000 (20:59 -0600)
committerBrian Paul <brianp@vmware.com>
Thu, 16 Aug 2012 15:01:31 +0000 (09:01 -0600)
As with other recent changes, put the vertex and fragment sampler state
into arrays indexed by the shader type.  This will let us easily add
support for other types of shaders in the future.

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_context.c
src/mesa/state_tracker/st_context.h

index f39fd7551c2718a6efa2257b8b14c735db1ca0db..70ae55fd2eba33b7d0a1b8828fd79079bec3f754 100644 (file)
@@ -253,23 +253,23 @@ update_samplers(struct st_context *st)
                           PIPE_SHADER_FRAGMENT,
                           &ctx->FragmentProgram._Current->Base,
                           ctx->Const.MaxTextureImageUnits,
-                          st->state.fragment_samplers,
-                          &st->state.num_fragment_samplers);
+                          st->state.samplers[PIPE_SHADER_FRAGMENT],
+                          &st->state.num_samplers[PIPE_SHADER_FRAGMENT]);
 
    update_shader_samplers(st,
                           PIPE_SHADER_VERTEX,
                           &ctx->VertexProgram._Current->Base,
                           ctx->Const.MaxVertexTextureImageUnits,
-                          st->state.vertex_samplers,
-                          &st->state.num_vertex_samplers);
+                          st->state.samplers[PIPE_SHADER_VERTEX],
+                          &st->state.num_samplers[PIPE_SHADER_VERTEX]);
 
 /*
    update_shader_samplers(st,
                           PIPE_SHADER_GEOMETRY,
                           &ctx->GeometryProgram._Current->Base,
                           ctx->Const.MaxGeometryTextureImageUnits,
-                          st->state.geometry_samplers,
-                          &st->state.num_geometry_samplers);
+                          st->state.samplers[PIPE_SHADER_GEOMETRY],
+                          &st->state.num_samplers[PIPE_SHADER_GEOMETRY]);
 */
 }
 
index e88675d4e6b52e02b129b741e4ff13ce964e2ff8..5604b8762b218a3ad12c2145a41f167d7becd5c8 100644 (file)
@@ -312,8 +312,8 @@ update_vertex_textures(struct st_context *st)
                       PIPE_SHADER_VERTEX,
                       &ctx->VertexProgram._Current->Base,
                       ctx->Const.MaxVertexTextureImageUnits,
-                      st->state.vertex_sampler_views,
-                      &st->state.num_vertex_textures);
+                      st->state.sampler_views[PIPE_SHADER_VERTEX],
+                      &st->state.num_sampler_views[PIPE_SHADER_VERTEX]);
    }
 }
 
@@ -327,8 +327,8 @@ update_fragment_textures(struct st_context *st)
                    PIPE_SHADER_FRAGMENT,
                    &ctx->FragmentProgram._Current->Base,
                    ctx->Const.MaxTextureImageUnits,
-                   st->state.fragment_sampler_views,
-                   &st->state.num_fragment_textures);
+                   st->state.sampler_views[PIPE_SHADER_FRAGMENT],
+                   &st->state.num_sampler_views[PIPE_SHADER_FRAGMENT]);
 }
 
 
index 7d9ccc1e5a05964b77a12025d655a0c6c307dc43..dbd778b4fc74204115fe01303d9b148034f3db39 100644 (file)
@@ -481,10 +481,11 @@ draw_bitmap_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
    /* user samplers, plus our bitmap sampler */
    {
       struct pipe_sampler_state *samplers[PIPE_MAX_SAMPLERS];
-      uint num = MAX2(fpv->bitmap_sampler + 1, st->state.num_fragment_samplers);
+      uint num = MAX2(fpv->bitmap_sampler + 1,
+                      st->state.num_samplers[PIPE_SHADER_FRAGMENT]);
       uint i;
-      for (i = 0; i < st->state.num_fragment_samplers; i++) {
-         samplers[i] = &st->state.fragment_samplers[i];
+      for (i = 0; i < st->state.num_samplers[PIPE_SHADER_FRAGMENT]; i++) {
+         samplers[i] = &st->state.samplers[PIPE_SHADER_FRAGMENT][i];
       }
       samplers[fpv->bitmap_sampler] =
          &st->bitmap.samplers[sv->texture->target != PIPE_TEXTURE_RECT];
@@ -496,8 +497,8 @@ draw_bitmap_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
    {
       struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS];
       uint num = MAX2(fpv->bitmap_sampler + 1,
-                      st->state.num_fragment_textures);
-      memcpy(sampler_views, st->state.fragment_sampler_views,
+                      st->state.num_sampler_views[PIPE_SHADER_FRAGMENT]);
+      memcpy(sampler_views, st->state.sampler_views[PIPE_SHADER_FRAGMENT],
              sizeof(sampler_views));
       sampler_views[fpv->bitmap_sampler] = sv;
       cso_set_sampler_views(cso, PIPE_SHADER_FRAGMENT, num, sampler_views);
index 2f951617829bc8d759b54414abae3d96545caa34..7735eee4f3d34f16acdb27b5bce3ae7491288024 100644 (file)
@@ -237,7 +237,7 @@ struct st_context *st_create_context(gl_api api, struct pipe_context *pipe,
 
 static void st_destroy_context_priv( struct st_context *st )
 {
-   uint i;
+   uint shader, i;
 
    st_destroy_atoms( st );
    st_destroy_draw( st );
@@ -248,14 +248,11 @@ static void st_destroy_context_priv( struct st_context *st )
    st_destroy_drawpix(st);
    st_destroy_drawtex(st);
 
-   for (i = 0; i < Elements(st->state.fragment_sampler_views); i++) {
-      pipe_sampler_view_release(st->pipe,
-                                &st->state.fragment_sampler_views[i]);
-   }
-
-   for (i = 0; i < Elements(st->state.vertex_sampler_views); i++) {
-      pipe_sampler_view_release(st->pipe,
-                                &st->state.vertex_sampler_views[i]);
+   for (shader = 0; shader < Elements(st->state.sampler_views); shader++) {
+      for (i = 0; i < Elements(st->state.sampler_views[0]); i++) {
+         pipe_sampler_view_release(st->pipe,
+                                   &st->state.sampler_views[shader][i]);
+      }
    }
 
    if (st->default_texture) {
index 8afd7766362d5f8d0d84cedb2b6df48013e73ce7..47d3af5205108993d6a3851388556838331a73ad 100644 (file)
@@ -98,25 +98,20 @@ 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    fragment_samplers[PIPE_MAX_SAMPLERS];
-      struct pipe_sampler_state    vertex_samplers[PIPE_MAX_SAMPLERS];
+      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];
+      GLuint num_sampler_views[PIPE_SHADER_TYPES];
       struct pipe_clip_state clip;
       struct {
          void *ptr;
          unsigned size;
       } constants[PIPE_SHADER_TYPES];
       struct pipe_framebuffer_state framebuffer;
-      struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS];
-      struct pipe_sampler_view *vertex_sampler_views[PIPE_MAX_SAMPLERS];
       struct pipe_scissor_state scissor;
       struct pipe_viewport_state viewport;
       unsigned sample_mask;
 
-      GLuint num_fragment_samplers;
-      GLuint num_vertex_samplers;
-      GLuint num_fragment_textures;
-      GLuint num_vertex_textures;
-
       GLuint poly_stipple[32];  /**< In OpenGL's bottom-to-top order */
 
       GLuint fb_orientation;