r600g: put sampler states and views into an array indexed by shader type
authorMarek Olšák <maraeo@gmail.com>
Mon, 10 Sep 2012 02:53:33 +0000 (04:53 +0200)
committerMarek Olšák <maraeo@gmail.com>
Thu, 13 Sep 2012 18:18:44 +0000 (20:18 +0200)
Reviewed-by: Jerome Glisse <jglisse@redhat.com>
src/gallium/drivers/r600/evergreen_state.c
src/gallium/drivers/r600/r600_blit.c
src/gallium/drivers/r600/r600_hw_context.c
src/gallium/drivers/r600/r600_pipe.h
src/gallium/drivers/r600/r600_state.c
src/gallium/drivers/r600/r600_state_common.c

index fda0790548733f292b5c6406c0a0f0a368eb2e4a..a29b0b4a4729cbfce5dbef2535b4743945b939a7 100644 (file)
@@ -2066,12 +2066,12 @@ static void evergreen_emit_sampler_views(struct r600_context *rctx,
 
 static void evergreen_emit_vs_sampler_views(struct r600_context *rctx, struct r600_atom *atom)
 {
-       evergreen_emit_sampler_views(rctx, &rctx->vs_samplers.views, 176 + R600_MAX_CONST_BUFFERS);
+       evergreen_emit_sampler_views(rctx, &rctx->samplers[PIPE_SHADER_VERTEX].views, 176 + R600_MAX_CONST_BUFFERS);
 }
 
 static void evergreen_emit_ps_sampler_views(struct r600_context *rctx, struct r600_atom *atom)
 {
-       evergreen_emit_sampler_views(rctx, &rctx->ps_samplers.views, R600_MAX_CONST_BUFFERS);
+       evergreen_emit_sampler_views(rctx, &rctx->samplers[PIPE_SHADER_FRAGMENT].views, R600_MAX_CONST_BUFFERS);
 }
 
 static void evergreen_emit_sampler_states(struct r600_context *rctx,
@@ -2104,12 +2104,12 @@ static void evergreen_emit_sampler_states(struct r600_context *rctx,
 
 static void evergreen_emit_vs_sampler_states(struct r600_context *rctx, struct r600_atom *atom)
 {
-       evergreen_emit_sampler_states(rctx, &rctx->vs_samplers, 18, R_00A414_TD_VS_SAMPLER0_BORDER_INDEX);
+       evergreen_emit_sampler_states(rctx, &rctx->samplers[PIPE_SHADER_VERTEX], 18, R_00A414_TD_VS_SAMPLER0_BORDER_INDEX);
 }
 
 static void evergreen_emit_ps_sampler_states(struct r600_context *rctx, struct r600_atom *atom)
 {
-       evergreen_emit_sampler_states(rctx, &rctx->ps_samplers, 0, R_00A400_TD_PS_SAMPLER0_BORDER_INDEX);
+       evergreen_emit_sampler_states(rctx, &rctx->samplers[PIPE_SHADER_FRAGMENT], 0, R_00A400_TD_PS_SAMPLER0_BORDER_INDEX);
 }
 
 static void evergreen_emit_sample_mask(struct r600_context *rctx, struct r600_atom *a)
@@ -2152,13 +2152,13 @@ void evergreen_init_state_functions(struct r600_context *rctx)
        /* shader program */
        r600_init_atom(rctx, &rctx->cs_shader_state.atom, id++, evergreen_emit_cs_shader, 0);
        /* sampler */
-       r600_init_atom(rctx, &rctx->vs_samplers.states.atom, id++, evergreen_emit_vs_sampler_states, 0);
-       r600_init_atom(rctx, &rctx->ps_samplers.states.atom, id++, evergreen_emit_ps_sampler_states, 0);
+       r600_init_atom(rctx, &rctx->samplers[PIPE_SHADER_VERTEX].states.atom, id++, evergreen_emit_vs_sampler_states, 0);
+       r600_init_atom(rctx, &rctx->samplers[PIPE_SHADER_FRAGMENT].states.atom, id++, evergreen_emit_ps_sampler_states, 0);
        /* resources */
        r600_init_atom(rctx, &rctx->vertex_buffer_state.atom, id++, evergreen_fs_emit_vertex_buffers, 0);
        r600_init_atom(rctx, &rctx->cs_vertex_buffer_state.atom, id++, evergreen_cs_emit_vertex_buffers, 0);
-       r600_init_atom(rctx, &rctx->vs_samplers.views.atom, id++, evergreen_emit_vs_sampler_views, 0);
-       r600_init_atom(rctx, &rctx->ps_samplers.views.atom, id++, evergreen_emit_ps_sampler_views, 0);
+       r600_init_atom(rctx, &rctx->samplers[PIPE_SHADER_VERTEX].views.atom, id++, evergreen_emit_vs_sampler_views, 0);
+       r600_init_atom(rctx, &rctx->samplers[PIPE_SHADER_FRAGMENT].views.atom, id++, evergreen_emit_ps_sampler_views, 0);
 
        if (rctx->chip_class == EVERGREEN) {
                r600_init_atom(rctx, &rctx->sample_mask.atom, id++, evergreen_emit_sample_mask, 3);
index 584b7fc1806f12da46d8e0e7b4ca7b009c792832..a49b4530078fc69ec7725d6263fa921837d3b3bf 100644 (file)
@@ -79,12 +79,12 @@ static void r600_blitter_begin(struct pipe_context *ctx, enum r600_blitter_op op
 
        if (op & R600_SAVE_TEXTURES) {
                util_blitter_save_fragment_sampler_states(
-                       rctx->blitter, util_last_bit(rctx->ps_samplers.states.enabled_mask),
-                       (void**)rctx->ps_samplers.states.states);
+                       rctx->blitter, util_last_bit(rctx->samplers[PIPE_SHADER_FRAGMENT].states.enabled_mask),
+                       (void**)rctx->samplers[PIPE_SHADER_FRAGMENT].states.states);
 
                util_blitter_save_fragment_sampler_views(
-                       rctx->blitter, util_last_bit(rctx->ps_samplers.views.enabled_mask),
-                       (struct pipe_sampler_view**)rctx->ps_samplers.views.views);
+                       rctx->blitter, util_last_bit(rctx->samplers[PIPE_SHADER_FRAGMENT].views.enabled_mask),
+                       (struct pipe_sampler_view**)rctx->samplers[PIPE_SHADER_FRAGMENT].views.views);
        }
 
        if ((op & R600_DISABLE_RENDER_COND) && rctx->current_render_cond) {
index 020f626cde950883271d06a2a09f7b381e96e36b..f183b33c09e28c1e7dc6ddd193225fe79c5e5486 100644 (file)
@@ -1044,11 +1044,6 @@ void r600_context_flush(struct r600_context *ctx, unsigned flags)
        r600_atom_dirty(ctx, &ctx->cb_misc_state.atom);
        r600_atom_dirty(ctx, &ctx->db_misc_state.atom);
 
-       ctx->vs_samplers.states.dirty_mask = ctx->vs_samplers.states.enabled_mask;
-       ctx->ps_samplers.states.dirty_mask = ctx->ps_samplers.states.enabled_mask;
-       r600_sampler_states_dirty(ctx, &ctx->vs_samplers.states);
-       r600_sampler_states_dirty(ctx, &ctx->ps_samplers.states);
-
        if (ctx->chip_class <= R700) {
                r600_atom_dirty(ctx, &ctx->seamless_cube_map.atom);
        }
@@ -1057,16 +1052,19 @@ void r600_context_flush(struct r600_context *ctx, unsigned flags)
        ctx->vertex_buffer_state.dirty_mask = ctx->vertex_buffer_state.enabled_mask;
        r600_vertex_buffers_dirty(ctx);
 
+       /* Re-emit shader resources. */
        for (shader = 0; shader < PIPE_SHADER_TYPES; shader++) {
-               struct r600_constbuf_state *state = &ctx->constbuf_state[shader];
-               state->dirty_mask = state->enabled_mask;
-               r600_constant_buffers_dirty(ctx, state);
-       }
+               struct r600_constbuf_state *constbuf = &ctx->constbuf_state[shader];
+               struct r600_textures_info *samplers = &ctx->samplers[shader];
 
-       ctx->vs_samplers.views.dirty_mask = ctx->vs_samplers.views.enabled_mask;
-       ctx->ps_samplers.views.dirty_mask = ctx->ps_samplers.views.enabled_mask;
-       r600_sampler_views_dirty(ctx, &ctx->vs_samplers.views);
-       r600_sampler_views_dirty(ctx, &ctx->ps_samplers.views);
+               constbuf->dirty_mask = constbuf->enabled_mask;
+               samplers->views.dirty_mask = samplers->views.enabled_mask;
+               samplers->states.dirty_mask = samplers->states.enabled_mask;
+
+               r600_constant_buffers_dirty(ctx, constbuf);
+               r600_sampler_views_dirty(ctx, &samplers->views);
+               r600_sampler_states_dirty(ctx, &samplers->states);
+       }
 
        if (streamout_suspended) {
                ctx->streamout_start = TRUE;
index 8d1acd265045bcab69d6e2698967e83465e9b130..b101db637b9933ace3dc84671ce6c844f44407c5 100644 (file)
@@ -379,8 +379,7 @@ struct r600_context {
        /** Vertex buffers for compute shaders */
        struct r600_vertexbuf_state     cs_vertex_buffer_state;
        struct r600_constbuf_state      constbuf_state[PIPE_SHADER_TYPES];
-       struct r600_textures_info       vs_samplers;
-       struct r600_textures_info       ps_samplers;
+       struct r600_textures_info       samplers[PIPE_SHADER_TYPES];
        struct r600_seamless_cube_map   seamless_cube_map;
        struct r600_cs_shader_state     cs_shader_state;
        struct r600_sample_mask         sample_mask;
index 1e2e43e3081a29ac7026531df1c6c4d2b5368839..05271e20132d450500bba6e3f075b5802ecd44bc 100644 (file)
@@ -1918,12 +1918,12 @@ static void r600_emit_sampler_views(struct r600_context *rctx,
 
 static void r600_emit_vs_sampler_views(struct r600_context *rctx, struct r600_atom *atom)
 {
-       r600_emit_sampler_views(rctx, &rctx->vs_samplers.views, 160 + R600_MAX_CONST_BUFFERS);
+       r600_emit_sampler_views(rctx, &rctx->samplers[PIPE_SHADER_VERTEX].views, 160 + R600_MAX_CONST_BUFFERS);
 }
 
 static void r600_emit_ps_sampler_views(struct r600_context *rctx, struct r600_atom *atom)
 {
-       r600_emit_sampler_views(rctx, &rctx->ps_samplers.views, R600_MAX_CONST_BUFFERS);
+       r600_emit_sampler_views(rctx, &rctx->samplers[PIPE_SHADER_FRAGMENT].views, R600_MAX_CONST_BUFFERS);
 }
 
 static void r600_emit_sampler_states(struct r600_context *rctx,
@@ -1977,12 +1977,12 @@ static void r600_emit_sampler_states(struct r600_context *rctx,
 
 static void r600_emit_vs_sampler_states(struct r600_context *rctx, struct r600_atom *atom)
 {
-       r600_emit_sampler_states(rctx, &rctx->vs_samplers, 18, R_00A600_TD_VS_SAMPLER0_BORDER_RED);
+       r600_emit_sampler_states(rctx, &rctx->samplers[PIPE_SHADER_VERTEX], 18, R_00A600_TD_VS_SAMPLER0_BORDER_RED);
 }
 
 static void r600_emit_ps_sampler_states(struct r600_context *rctx, struct r600_atom *atom)
 {
-       r600_emit_sampler_states(rctx, &rctx->ps_samplers, 0, R_00A400_TD_PS_SAMPLER0_BORDER_RED);
+       r600_emit_sampler_states(rctx, &rctx->samplers[PIPE_SHADER_FRAGMENT], 0, R_00A400_TD_PS_SAMPLER0_BORDER_RED);
 }
 
 static void r600_emit_seamless_cube_map(struct r600_context *rctx, struct r600_atom *atom)
@@ -2030,11 +2030,11 @@ void r600_init_state_functions(struct r600_context *rctx)
        /* sampler must be emited before TA_CNTL_AUX otherwise DISABLE_CUBE_WRAP change
         * does not take effect (TA_CNTL_AUX emited by r600_emit_seamless_cube_map)
         */
-       r600_init_atom(rctx, &rctx->vs_samplers.states.atom, id++, r600_emit_vs_sampler_states, 0);
-       r600_init_atom(rctx, &rctx->ps_samplers.states.atom, id++, r600_emit_ps_sampler_states, 0);
+       r600_init_atom(rctx, &rctx->samplers[PIPE_SHADER_VERTEX].states.atom, id++, r600_emit_vs_sampler_states, 0);
+       r600_init_atom(rctx, &rctx->samplers[PIPE_SHADER_FRAGMENT].states.atom, id++, r600_emit_ps_sampler_states, 0);
        /* resource */
-       r600_init_atom(rctx, &rctx->vs_samplers.views.atom, id++, r600_emit_vs_sampler_views, 0);
-       r600_init_atom(rctx, &rctx->ps_samplers.views.atom, id++, r600_emit_ps_sampler_views, 0);
+       r600_init_atom(rctx, &rctx->samplers[PIPE_SHADER_VERTEX].views.atom, id++, r600_emit_vs_sampler_views, 0);
+       r600_init_atom(rctx, &rctx->samplers[PIPE_SHADER_FRAGMENT].views.atom, id++, r600_emit_ps_sampler_views, 0);
        r600_init_atom(rctx, &rctx->vertex_buffer_state.atom, id++, r600_emit_vertex_buffers, 0);
 
        r600_init_atom(rctx, &rctx->seamless_cube_map.atom, id++, r600_emit_seamless_cube_map, 3);
index 87183169a2a371eec461d3f4472473dd150a32ff..7899e6cce8edd57100c857481748954a24610b17 100644 (file)
@@ -366,7 +366,7 @@ static void r600_bind_sampler_states(struct pipe_context *pipe,
                               unsigned count, void **states)
 {
        struct r600_context *rctx = (struct r600_context *)pipe;
-       struct r600_textures_info *dst;
+       struct r600_textures_info *dst = &rctx->samplers[shader];
        struct r600_pipe_sampler_state **rstates = (struct r600_pipe_sampler_state**)states;
        int seamless_cube_map = -1;
        unsigned i;
@@ -377,18 +377,6 @@ static void r600_bind_sampler_states(struct pipe_context *pipe,
 
        assert(start == 0); /* XXX fix below */
 
-       switch (shader) {
-       case PIPE_SHADER_VERTEX:
-               dst = &rctx->vs_samplers;
-               break;
-       case PIPE_SHADER_FRAGMENT:
-               dst = &rctx->ps_samplers;
-               break;
-       default:
-               debug_error("bad shader in r600_bind_samplers()");
-               return;
-       }
-
        for (i = 0; i < count; i++) {
                struct r600_pipe_sampler_state *rstate = rstates[i];
 
@@ -571,7 +559,7 @@ static void r600_set_sampler_views(struct pipe_context *pipe, unsigned shader,
                                   struct pipe_sampler_view **views)
 {
        struct r600_context *rctx = (struct r600_context *) pipe;
-       struct r600_textures_info *dst;
+       struct r600_textures_info *dst = &rctx->samplers[shader];
        struct r600_pipe_sampler_view **rviews = (struct r600_pipe_sampler_view **)views;
        uint32_t dirty_sampler_states_mask = 0;
        unsigned i;
@@ -585,18 +573,6 @@ static void r600_set_sampler_views(struct pipe_context *pipe, unsigned shader,
 
        assert(start == 0); /* XXX fix below */
 
-       switch (shader) {
-       case PIPE_SHADER_VERTEX:
-               dst = &rctx->vs_samplers;
-               break;
-       case PIPE_SHADER_FRAGMENT:
-               dst = &rctx->ps_samplers;
-               break;
-       default:
-               debug_error("bad shader in r600_set_sampler_views()");
-               return;
-       }
-
        remaining_mask = dst->views.enabled_mask & disable_mask;
 
        while (remaining_mask) {
@@ -1069,18 +1045,17 @@ static void r600_update_derived_state(struct r600_context *rctx)
        unsigned ps_dirty = 0, blend_override;
 
        if (!rctx->blitter->running) {
+               unsigned i;
+
                /* Decompress textures if needed. */
-               if (rctx->vs_samplers.views.compressed_depthtex_mask) {
-                       r600_decompress_depth_textures(rctx, &rctx->vs_samplers.views);
-               }
-               if (rctx->ps_samplers.views.compressed_depthtex_mask) {
-                       r600_decompress_depth_textures(rctx, &rctx->ps_samplers.views);
-               }
-               if (rctx->vs_samplers.views.compressed_colortex_mask) {
-                       r600_decompress_color_textures(rctx, &rctx->vs_samplers.views);
-               }
-               if (rctx->ps_samplers.views.compressed_colortex_mask) {
-                       r600_decompress_color_textures(rctx, &rctx->ps_samplers.views);
+               for (i = 0; i < PIPE_SHADER_TYPES; i++) {
+                       struct r600_samplerview_state *views = &rctx->samplers[i].views;
+                       if (views->compressed_depthtex_mask) {
+                               r600_decompress_depth_textures(rctx, views);
+                       }
+                       if (views->compressed_colortex_mask) {
+                               r600_decompress_color_textures(rctx, views);
+                       }
                }
        }