r600g: put constant buffer state into an array indexed by shader type
authorMarek Olšák <maraeo@gmail.com>
Sun, 9 Sep 2012 22:56:45 +0000 (00:56 +0200)
committerMarek Olšák <maraeo@gmail.com>
Thu, 13 Sep 2012 18:18:44 +0000 (20:18 +0200)
to easily and robustly handle multiple shader stages

Reviewed-by: Jerome Glisse <jglisse@redhat.com>
src/gallium/drivers/r600/evergreen_state.c
src/gallium/drivers/r600/r600_buffer.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 4d88e83c5e4cdacf9f29c1be21555f4b9d536db2..baeedaeeed70e43a4bff818f2a9e825dbd016791 100644 (file)
@@ -2057,14 +2057,14 @@ static void evergreen_emit_constant_buffers(struct r600_context *rctx,
 
 static void evergreen_emit_vs_constant_buffers(struct r600_context *rctx, struct r600_atom *atom)
 {
-       evergreen_emit_constant_buffers(rctx, &rctx->vs_constbuf_state, 176,
+       evergreen_emit_constant_buffers(rctx, &rctx->constbuf_state[PIPE_SHADER_VERTEX], 176,
                                        R_028180_ALU_CONST_BUFFER_SIZE_VS_0,
                                        R_028980_ALU_CONST_CACHE_VS_0);
 }
 
 static void evergreen_emit_ps_constant_buffers(struct r600_context *rctx, struct r600_atom *atom)
 {
-       evergreen_emit_constant_buffers(rctx, &rctx->ps_constbuf_state, 0,
+       evergreen_emit_constant_buffers(rctx, &rctx->constbuf_state[PIPE_SHADER_FRAGMENT], 0,
                                       R_028140_ALU_CONST_BUFFER_SIZE_PS_0,
                                       R_028940_ALU_CONST_CACHE_PS_0);
 }
@@ -2179,8 +2179,8 @@ void evergreen_init_state_functions(struct r600_context *rctx)
         */
 
        /* shader const */
-       r600_init_atom(rctx, &rctx->vs_constbuf_state.atom, id++, evergreen_emit_vs_constant_buffers, 0);
-       r600_init_atom(rctx, &rctx->ps_constbuf_state.atom, id++, evergreen_emit_ps_constant_buffers, 0);
+       r600_init_atom(rctx, &rctx->constbuf_state[PIPE_SHADER_VERTEX].atom, id++, evergreen_emit_vs_constant_buffers, 0);
+       r600_init_atom(rctx, &rctx->constbuf_state[PIPE_SHADER_FRAGMENT].atom, id++, evergreen_emit_ps_constant_buffers, 0);
        /* shader program */
        r600_init_atom(rctx, &rctx->cs_shader_state.atom, id++, evergreen_emit_cs_shader, 0);
        /* sampler */
index 88d67dfaf49d3faecbdd8f500b19e1e21b8c23d2..0b0ac3460e1bfb3fec66028a2fa3d7ea9e2fe5d9 100644 (file)
@@ -65,21 +65,25 @@ static struct pipe_transfer *r600_get_transfer(struct pipe_context *ctx,
 }
 
 static void r600_set_constants_dirty_if_bound(struct r600_context *rctx,
-                                             struct r600_constbuf_state *state,
                                              struct r600_resource *rbuffer)
 {
-       bool found = false;
-       uint32_t mask = state->enabled_mask;
-
-       while (mask) {
-               unsigned i = u_bit_scan(&mask);
-               if (state->cb[i].buffer == &rbuffer->b.b) {
-                       found = true;
-                       state->dirty_mask |= 1 << i;
+       unsigned shader;
+
+       for (shader = 0; shader < PIPE_SHADER_TYPES; shader++) {
+               struct r600_constbuf_state *state = &rctx->constbuf_state[shader];
+               bool found = false;
+               uint32_t mask = state->enabled_mask;
+
+               while (mask) {
+                       unsigned i = u_bit_scan(&mask);
+                       if (state->cb[i].buffer == &rbuffer->b.b) {
+                               found = true;
+                               state->dirty_mask |= 1 << i;
+                       }
+               }
+               if (found) {
+                       r600_constant_buffers_dirty(rctx, state);
                }
-       }
-       if (found) {
-               r600_constant_buffers_dirty(rctx, state);
        }
 }
 
@@ -126,8 +130,7 @@ static void *r600_buffer_transfer_map(struct pipe_context *pipe,
                                }
                        }
                        /* Constant buffers. */
-                       r600_set_constants_dirty_if_bound(rctx, &rctx->vs_constbuf_state, rbuffer);
-                       r600_set_constants_dirty_if_bound(rctx, &rctx->ps_constbuf_state, rbuffer);
+                       r600_set_constants_dirty_if_bound(rctx, rbuffer);
                }
        }
 #if 0 /* this is broken (see Bug 53130) */
index d40f6b60933cf30e7c518de00835564fa6fd727c..1db5f0d645cdfa96663b684d3f43498646b9d53b 100644 (file)
@@ -989,6 +989,7 @@ void r600_context_flush(struct r600_context *ctx, unsigned flags)
        bool timer_queries_suspended = false;
        bool nontimer_queries_suspended = false;
        bool streamout_suspended = false;
+       unsigned shader;
 
        if (cs->cdw == ctx->start_cs_cmd.atom.num_dw)
                return;
@@ -1053,10 +1054,11 @@ 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);
 
-       ctx->vs_constbuf_state.dirty_mask = ctx->vs_constbuf_state.enabled_mask;
-       ctx->ps_constbuf_state.dirty_mask = ctx->ps_constbuf_state.enabled_mask;
-       r600_constant_buffers_dirty(ctx, &ctx->vs_constbuf_state);
-       r600_constant_buffers_dirty(ctx, &ctx->ps_constbuf_state);
+       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);
+       }
 
        ctx->vs_samplers.views.dirty_mask = ctx->vs_samplers.views.enabled_mask;
        ctx->ps_samplers.views.dirty_mask = ctx->ps_samplers.views.enabled_mask;
index 8fb0972bfd0d327a7b34647dde3d5f37f1b5f92b..57861358b3557a6e7ed43452c403639b4912c16d 100644 (file)
@@ -372,8 +372,7 @@ struct r600_context {
        struct r600_vertexbuf_state     vertex_buffer_state;
        /** Vertex buffers for compute shaders */
        struct r600_vertexbuf_state     cs_vertex_buffer_state;
-       struct r600_constbuf_state      vs_constbuf_state;
-       struct r600_constbuf_state      ps_constbuf_state;
+       struct r600_constbuf_state      constbuf_state[PIPE_SHADER_TYPES];
        struct r600_textures_info       vs_samplers;
        struct r600_textures_info       ps_samplers;
        struct r600_seamless_cube_map   seamless_cube_map;
index aca5e3cb8e50c3f9b2492de3035cd822a1f6cdf1..9a9d8276102e2e69959a01c8beefb3f2c3765447 100644 (file)
@@ -1909,14 +1909,14 @@ static void r600_emit_constant_buffers(struct r600_context *rctx,
 
 static void r600_emit_vs_constant_buffers(struct r600_context *rctx, struct r600_atom *atom)
 {
-       r600_emit_constant_buffers(rctx, &rctx->vs_constbuf_state, 160,
+       r600_emit_constant_buffers(rctx, &rctx->constbuf_state[PIPE_SHADER_VERTEX], 160,
                                   R_028180_ALU_CONST_BUFFER_SIZE_VS_0,
                                   R_028980_ALU_CONST_CACHE_VS_0);
 }
 
 static void r600_emit_ps_constant_buffers(struct r600_context *rctx, struct r600_atom *atom)
 {
-       r600_emit_constant_buffers(rctx, &rctx->ps_constbuf_state, 0,
+       r600_emit_constant_buffers(rctx, &rctx->constbuf_state[PIPE_SHADER_FRAGMENT], 0,
                                   R_028140_ALU_CONST_BUFFER_SIZE_PS_0,
                                   R_028940_ALU_CONST_CACHE_PS_0);
 }
@@ -2054,8 +2054,8 @@ void r600_init_state_functions(struct r600_context *rctx)
         */
 
        /* shader const */
-       r600_init_atom(rctx, &rctx->vs_constbuf_state.atom, id++, r600_emit_vs_constant_buffers, 0);
-       r600_init_atom(rctx, &rctx->ps_constbuf_state.atom, id++, r600_emit_ps_constant_buffers, 0);
+       r600_init_atom(rctx, &rctx->constbuf_state[PIPE_SHADER_VERTEX].atom, id++, r600_emit_vs_constant_buffers, 0);
+       r600_init_atom(rctx, &rctx->constbuf_state[PIPE_SHADER_FRAGMENT].atom, id++, r600_emit_ps_constant_buffers, 0);
 
        /* 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)
index 4df3c78e1635ccc60def73f9a810a3bab76c535a..28972274b0cd7df78b59d5fd67072c15ff8420cb 100644 (file)
@@ -864,21 +864,10 @@ static void r600_set_constant_buffer(struct pipe_context *ctx, uint shader, uint
                                     struct pipe_constant_buffer *input)
 {
        struct r600_context *rctx = (struct r600_context *)ctx;
-       struct r600_constbuf_state *state;
+       struct r600_constbuf_state *state = &rctx->constbuf_state[shader];
        struct pipe_constant_buffer *cb;
        const uint8_t *ptr;
 
-       switch (shader) {
-       case PIPE_SHADER_VERTEX:
-               state = &rctx->vs_constbuf_state;
-               break;
-       case PIPE_SHADER_FRAGMENT:
-               state = &rctx->ps_constbuf_state;
-               break;
-       default:
-               return;
-       }
-
        /* Note that the state tracker can unbind constant buffers by
         * passing NULL here.
         */