radeonsi: don't re-upload the sample position constant buffer repeatedly
authorMarek Olšák <marek.olsak@amd.com>
Sat, 29 Sep 2018 00:38:26 +0000 (20:38 -0400)
committerMarek Olšák <marek.olsak@amd.com>
Tue, 16 Oct 2018 19:28:22 +0000 (15:28 -0400)
src/gallium/drivers/radeonsi/si_pipe.c
src/gallium/drivers/radeonsi/si_pipe.h
src/gallium/drivers/radeonsi/si_state.c
src/gallium/drivers/radeonsi/si_state_msaa.c

index 14b075c7b76cd3b38a87189db9a3b4b13d75924d..4b481b47af340734c41f594801c0b9cecf6314a8 100644 (file)
@@ -160,6 +160,7 @@ static void si_destroy_context(struct pipe_context *context)
        pipe_resource_reference(&sctx->gsvs_ring, NULL);
        pipe_resource_reference(&sctx->tess_rings, NULL);
        pipe_resource_reference(&sctx->null_const_buf.buffer, NULL);
+       pipe_resource_reference(&sctx->sample_pos_buffer, NULL);
        r600_resource_reference(&sctx->border_color_buffer, NULL);
        free(sctx->border_color_table);
        r600_resource_reference(&sctx->scratch_buffer, NULL);
@@ -599,6 +600,12 @@ static struct pipe_context *si_create_context(struct pipe_screen *screen,
        util_dynarray_init(&sctx->resident_img_needs_color_decompress, NULL);
        util_dynarray_init(&sctx->resident_tex_needs_depth_decompress, NULL);
 
+       sctx->sample_pos_buffer =
+               pipe_buffer_create(sctx->b.screen, 0, PIPE_USAGE_DEFAULT,
+                                  sizeof(sctx->sample_positions));
+       pipe_buffer_write(&sctx->b, sctx->sample_pos_buffer, 0,
+                         sizeof(sctx->sample_positions), &sctx->sample_positions);
+
        /* this must be last */
        si_begin_new_gfx_cs(sctx);
        return &sctx->b;
index ff11eab022405ba358bff1ecb54d9867770358d0..93082e262d6afd1ea3510d2d6ab4eaa92f9b0e44 100644 (file)
@@ -965,11 +965,14 @@ struct si_context {
        /* MSAA sample locations.
         * The first index is the sample index.
         * The second index is the coordinate: X, Y. */
-       float                   sample_locations_1x[1][2];
-       float                   sample_locations_2x[2][2];
-       float                   sample_locations_4x[4][2];
-       float                   sample_locations_8x[8][2];
-       float                   sample_locations_16x[16][2];
+       struct {
+               float                   x1[1][2];
+               float                   x2[2][2];
+               float                   x4[4][2];
+               float                   x8[8][2];
+               float                   x16[16][2];
+       } sample_positions;
+       struct pipe_resource *sample_pos_buffer;
 
        /* Misc stats. */
        unsigned                        num_draw_calls;
index 132085a40c43041b97eb9392d277e6430eb3a6f4..b1e2fc30e2a2f9abaac3cf62ca1d484afa77e1b0 100644 (file)
@@ -2717,7 +2717,6 @@ static void si_set_framebuffer_state(struct pipe_context *ctx,
                                     const struct pipe_framebuffer_state *state)
 {
        struct si_context *sctx = (struct si_context *)ctx;
-       struct pipe_constant_buffer constbuf = {0};
        struct si_surface *surf = NULL;
        struct si_texture *tex;
        bool old_any_dst_linear = sctx->framebuffer.any_dst_linear;
@@ -2941,25 +2940,33 @@ static void si_set_framebuffer_state(struct pipe_context *ctx,
                si_mark_atom_dirty(sctx, &sctx->atoms.s.msaa_config);
 
        if (sctx->framebuffer.nr_samples != old_nr_samples) {
+               struct pipe_constant_buffer constbuf = {0};
+
                si_mark_atom_dirty(sctx, &sctx->atoms.s.msaa_config);
                si_mark_atom_dirty(sctx, &sctx->atoms.s.db_render_state);
 
+               constbuf.buffer = sctx->sample_pos_buffer;
+
                /* Set sample locations as fragment shader constants. */
                switch (sctx->framebuffer.nr_samples) {
                case 1:
-                       constbuf.user_buffer = sctx->sample_locations_1x;
+                       constbuf.buffer_offset = 0;
                        break;
                case 2:
-                       constbuf.user_buffer = sctx->sample_locations_2x;
+                       constbuf.buffer_offset = (ubyte*)sctx->sample_positions.x2 -
+                                                (ubyte*)sctx->sample_positions.x1;
                        break;
                case 4:
-                       constbuf.user_buffer = sctx->sample_locations_4x;
+                       constbuf.buffer_offset = (ubyte*)sctx->sample_positions.x4 -
+                                                (ubyte*)sctx->sample_positions.x1;
                        break;
                case 8:
-                       constbuf.user_buffer = sctx->sample_locations_8x;
+                       constbuf.buffer_offset = (ubyte*)sctx->sample_positions.x8 -
+                                                (ubyte*)sctx->sample_positions.x1;
                        break;
                case 16:
-                       constbuf.user_buffer = sctx->sample_locations_16x;
+                       constbuf.buffer_offset = (ubyte*)sctx->sample_positions.x16 -
+                                                (ubyte*)sctx->sample_positions.x1;
                        break;
                default:
                        PRINT_ERR("Requested an invalid number of samples %i.\n",
index f9387e75ed1e5ab47911091b9b4ead7ee7749217..b741bcadec866dbdf632e6be57384b14896b48b0 100644 (file)
@@ -198,14 +198,14 @@ void si_init_msaa_functions(struct si_context *sctx)
 
        sctx->b.get_sample_position = si_get_sample_position;
 
-       si_get_sample_position(&sctx->b, 1, 0, sctx->sample_locations_1x[0]);
+       si_get_sample_position(&sctx->b, 1, 0, sctx->sample_positions.x1[0]);
 
        for (i = 0; i < 2; i++)
-               si_get_sample_position(&sctx->b, 2, i, sctx->sample_locations_2x[i]);
+               si_get_sample_position(&sctx->b, 2, i, sctx->sample_positions.x2[i]);
        for (i = 0; i < 4; i++)
-               si_get_sample_position(&sctx->b, 4, i, sctx->sample_locations_4x[i]);
+               si_get_sample_position(&sctx->b, 4, i, sctx->sample_positions.x4[i]);
        for (i = 0; i < 8; i++)
-               si_get_sample_position(&sctx->b, 8, i, sctx->sample_locations_8x[i]);
+               si_get_sample_position(&sctx->b, 8, i, sctx->sample_positions.x8[i]);
        for (i = 0; i < 16; i++)
-               si_get_sample_position(&sctx->b, 16, i, sctx->sample_locations_16x[i]);
+               si_get_sample_position(&sctx->b, 16, i, sctx->sample_positions.x16[i]);
 }