radeonsi: Add counter to check if a texture is bound to a framebuffer.
authorBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Tue, 31 May 2016 11:44:03 +0000 (13:44 +0200)
committerBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Tue, 31 May 2016 19:43:00 +0000 (21:43 +0200)
Signed-off-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/gallium/drivers/radeon/r600_pipe_common.h
src/gallium/drivers/radeonsi/si_pipe.c
src/gallium/drivers/radeonsi/si_state.c
src/gallium/drivers/radeonsi/si_state.h

index 3e54534e79e3a2f1705276b62274aea24d4c336c..084e3fb1240f04a75672a9c12d8e8e30e2462114 100644 (file)
@@ -260,6 +260,11 @@ struct r600_texture {
        uint8_t                         stencil_clear_value;
 
        bool                            non_disp_tiling; /* R600-Cayman only */
+
+       /* Counter that should be non-zero if the texture is bound to a
+        * framebuffer. Implemented in radeonsi only.
+        */
+       uint32_t                        framebuffers_bound;
 };
 
 struct r600_surface {
index 88f4f2083e37505e15ed89c2ee077178b2d58447..0987baf86c54695ab077b28145f81bb85fe5f1b9 100644 (file)
@@ -40,6 +40,8 @@ static void si_destroy_context(struct pipe_context *context)
        struct si_context *sctx = (struct si_context *)context;
        int i;
 
+       si_dec_framebuffer_counters(&sctx->framebuffer.state);
+
        si_release_all_descriptors(sctx);
 
        if (sctx->ce_suballocator)
index ab321ef0b8fe869bff1c9d76432aa9fe0a04be9f..ed62710611f096d821c62bb6d82c54d8556a62fb 100644 (file)
@@ -2268,6 +2268,21 @@ static void si_init_depth_surface(struct si_context *sctx,
        surf->depth_initialized = true;
 }
 
+void si_dec_framebuffer_counters(const struct pipe_framebuffer_state *state)
+{
+       for (int i = 0; i < state->nr_cbufs; ++i) {
+               struct r600_surface *surf = NULL;
+               struct r600_texture *rtex;
+
+               if (!state->cbufs[i])
+                       continue;
+               surf = (struct r600_surface*)state->cbufs[i];
+               rtex = (struct r600_texture*)surf->base.texture;
+
+               p_atomic_dec(&rtex->framebuffers_bound);
+       }
+}
+
 static void si_set_framebuffer_state(struct pipe_context *ctx,
                                     const struct pipe_framebuffer_state *state)
 {
@@ -2298,6 +2313,7 @@ static void si_set_framebuffer_state(struct pipe_context *ctx,
                (1 << MAX2(sctx->framebuffer.state.nr_cbufs, state->nr_cbufs)) - 1;
        sctx->framebuffer.dirty_zsbuf |= sctx->framebuffer.state.zsbuf != state->zsbuf;
 
+       si_dec_framebuffer_counters(&sctx->framebuffer.state);
        util_copy_framebuffer_state(&sctx->framebuffer.state, state);
 
        sctx->framebuffer.spi_shader_col_format = 0;
@@ -2342,6 +2358,8 @@ static void si_set_framebuffer_state(struct pipe_context *ctx,
                        sctx->framebuffer.compressed_cb_mask |= 1 << i;
                }
                r600_context_add_resource_size(ctx, surf->base.texture);
+
+               p_atomic_inc(&rtex->framebuffers_bound);
        }
        /* Set the second SPI format for possible dual-src blending. */
        if (i == 1 && surf) {
index a3589d4611d0b35ca39f6583159c104f0d2282d8..01b73f607bab2ad8d1b1982d831b57ab14117985 100644 (file)
@@ -308,6 +308,7 @@ si_create_sampler_view_custom(struct pipe_context *ctx,
                              const struct pipe_sampler_view *state,
                              unsigned width0, unsigned height0,
                              unsigned force_level);
+void si_dec_framebuffer_counters(const struct pipe_framebuffer_state *state);
 
 /* si_state_shader.c */
 bool si_update_shaders(struct si_context *sctx);