From: Nicolai Hähnle <nicolai.haeh...@amd.com>

---
 src/gallium/drivers/radeonsi/si_blit.c        |  9 ++++++
 src/gallium/drivers/radeonsi/si_descriptors.c | 43 +++++++++++++++++++++++++--
 src/gallium/drivers/radeonsi/si_state.h       |  1 +
 3 files changed, 51 insertions(+), 2 deletions(-)

diff --git a/src/gallium/drivers/radeonsi/si_blit.c 
b/src/gallium/drivers/radeonsi/si_blit.c
index e17343f..f9a6de4 100644
--- a/src/gallium/drivers/radeonsi/si_blit.c
+++ b/src/gallium/drivers/radeonsi/si_blit.c
@@ -352,9 +352,18 @@ si_decompress_color_textures(struct si_context *sctx,
 
 void si_decompress_textures(struct si_context *sctx)
 {
+       unsigned compressed_colortex_counter;
+
        if (sctx->blitter->running)
                return;
 
+       /* Update the compressed_colortex_mask if necessary. */
+       compressed_colortex_counter = 
p_atomic_read(&sctx->screen->b.compressed_colortex_counter);
+       if (compressed_colortex_counter != 
sctx->b.last_compressed_colortex_counter) {
+               sctx->b.last_compressed_colortex_counter = 
compressed_colortex_counter;
+               si_update_compressed_colortex_masks(sctx);
+       }
+
        /* Flush depth textures which need to be flushed. */
        for (int i = 0; i < SI_NUM_SHADERS; i++) {
                if (sctx->samplers[i].depth_texture_mask) {
diff --git a/src/gallium/drivers/radeonsi/si_descriptors.c 
b/src/gallium/drivers/radeonsi/si_descriptors.c
index 37b9d68..9aa4877 100644
--- a/src/gallium/drivers/radeonsi/si_descriptors.c
+++ b/src/gallium/drivers/radeonsi/si_descriptors.c
@@ -224,6 +224,12 @@ static void si_set_sampler_view(struct si_context *sctx,
        views->desc.list_dirty = true;
 }
 
+static bool is_compressed_colortex(struct r600_texture *rtex)
+{
+       return rtex->cmask.size || rtex->fmask.size ||
+              (rtex->dcc_offset && rtex->dirty_level_mask);
+}
+
 static void si_set_sampler_views(struct pipe_context *ctx,
                                 unsigned shader, unsigned start,
                                  unsigned count,
@@ -257,8 +263,7 @@ static void si_set_sampler_views(struct pipe_context *ctx,
                        } else {
                                samplers->depth_texture_mask &= ~(1 << slot);
                        }
-                       if (rtex->cmask.size || rtex->fmask.size ||
-                           (rtex->dcc_offset && rtex->dirty_level_mask)) {
+                       if (is_compressed_colortex(rtex)) {
                                samplers->compressed_colortex_mask |= 1 << slot;
                        } else {
                                samplers->compressed_colortex_mask &= ~(1 << 
slot);
@@ -270,6 +275,27 @@ static void si_set_sampler_views(struct pipe_context *ctx,
        }
 }
 
+static void
+si_samplers_update_compressed_colortex_mask(struct si_textures_info *samplers)
+{
+       uint64_t mask = samplers->views.desc.enabled_mask;
+
+       while (mask) {
+               int i = u_bit_scan64(&mask);
+               struct pipe_resource *res = samplers->views.views[i]->texture;
+
+               if (res && res->target != PIPE_BUFFER) {
+                       struct r600_texture *rtex = (struct r600_texture *)res;
+
+                       if (is_compressed_colortex(rtex)) {
+                               samplers->compressed_colortex_mask |= 1 << i;
+                       } else {
+                               samplers->compressed_colortex_mask &= ~(1 << i);
+                       }
+               }
+       }
+}
+
 /* SAMPLER STATES */
 
 static void si_bind_sampler_states(struct pipe_context *ctx, unsigned shader,
@@ -762,6 +788,19 @@ static void si_desc_reset_buffer_offset(struct 
pipe_context *ctx,
                  S_008F04_BASE_ADDRESS_HI(va >> 32);
 }
 
+/* TEXTURE METADATA ENABLE/DISABLE */
+
+/* CMASK can be enabled (for fast clear) and disabled (for texture export)
+ * while the texture is bound, possibly by a different context. In that case,
+ * call this function to update compressed_colortex_masks.
+ */
+void si_update_compressed_colortex_masks(struct si_context *sctx)
+{
+       for (int i = 0; i < SI_NUM_SHADERS; ++i) {
+               si_samplers_update_compressed_colortex_mask(&sctx->samplers[i]);
+       }
+}
+
 /* BUFFER DISCARD/INVALIDATION */
 
 /* Reallocate a buffer a update all resource bindings where the buffer is
diff --git a/src/gallium/drivers/radeonsi/si_state.h 
b/src/gallium/drivers/radeonsi/si_state.h
index fb16d0f..60c34f1 100644
--- a/src/gallium/drivers/radeonsi/si_state.h
+++ b/src/gallium/drivers/radeonsi/si_state.h
@@ -249,6 +249,7 @@ void si_all_descriptors_begin_new_cs(struct si_context 
*sctx);
 void si_upload_const_buffer(struct si_context *sctx, struct r600_resource 
**rbuffer,
                            const uint8_t *ptr, unsigned size, uint32_t 
*const_offset);
 void si_shader_change_notify(struct si_context *sctx);
+void si_update_compressed_colortex_masks(struct si_context *sctx);
 void si_emit_shader_userdata(struct si_context *sctx, struct r600_atom *atom);
 
 /* si_state.c */
-- 
2.5.0

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to