Similar to the existing decompression code path except that it
loops over the list of resident textures/images.

v2: - store pipe_sampler_view instead of si_sampler_view

Signed-off-by: Samuel Pitoiset <samuel.pitoi...@gmail.com>
---
 src/gallium/drivers/radeonsi/si_blit.c        | 77 +++++++++++++++++++++++++--
 src/gallium/drivers/radeonsi/si_descriptors.c | 52 ++++++++++++++++++
 src/gallium/drivers/radeonsi/si_pipe.h        |  3 ++
 3 files changed, 129 insertions(+), 3 deletions(-)

diff --git a/src/gallium/drivers/radeonsi/si_blit.c 
b/src/gallium/drivers/radeonsi/si_blit.c
index 343ca35736..a47f43958c 100644
--- a/src/gallium/drivers/radeonsi/si_blit.c
+++ b/src/gallium/drivers/radeonsi/si_blit.c
@@ -22,6 +22,7 @@
  */
 
 #include "si_pipe.h"
+#include "si_compute.h"
 #include "util/u_format.h"
 #include "util/u_surface.h"
 
@@ -690,9 +691,6 @@ static void si_decompress_textures(struct si_context *sctx, 
unsigned shader_mask
 {
        unsigned compressed_colortex_counter, mask;
 
-       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) {
@@ -719,14 +717,87 @@ static void si_decompress_textures(struct si_context 
*sctx, unsigned shader_mask
        si_check_render_feedback(sctx);
 }
 
+static void si_decompress_resident_textures(struct si_context *sctx)
+{
+       unsigned num_resident_tex_handles;
+       unsigned i;
+
+       num_resident_tex_handles = sctx->resident_tex_handles.size /
+                                  sizeof(struct si_texture_handle *);
+
+       for (i = 0; i < num_resident_tex_handles; i++) {
+               struct si_texture_handle *tex_handle =
+                       *util_dynarray_element(&sctx->resident_tex_handles,
+                                              struct si_texture_handle *, i);
+               struct pipe_sampler_view *view = tex_handle->view;
+               struct si_sampler_view *sview = (struct si_sampler_view *)view;
+               struct r600_texture *tex;
+
+               assert(view);
+               tex = (struct r600_texture *)view->texture;
+
+               if (view->texture->target == PIPE_BUFFER)
+                       continue;
+
+               if (tex_handle->compressed_colortex)
+                       si_decompress_color_texture(sctx, tex, 
view->u.tex.first_level,
+                                                   view->u.tex.last_level);
+
+               if (tex_handle->depth_texture)
+                       si_flush_depth_texture(sctx, tex,
+                               sview->is_stencil_sampler ? PIPE_MASK_S : 
PIPE_MASK_Z,
+                               view->u.tex.first_level, view->u.tex.last_level,
+                               0, util_max_layer(&tex->resource.b.b, 
view->u.tex.first_level));
+       }
+}
+
+static void si_decompress_resident_images(struct si_context *sctx)
+{
+       unsigned num_resident_img_handles;
+       unsigned i;
+
+       num_resident_img_handles = sctx->resident_img_handles.size /
+                                  sizeof(struct si_image_handle *);
+
+       for (i = 0; i < num_resident_img_handles; i++) {
+               struct si_image_handle *img_handle =
+                       *util_dynarray_element(&sctx->resident_img_handles,
+                                              struct si_image_handle *, i);
+               struct pipe_image_view *view = &img_handle->view;
+               struct r600_texture *tex;
+
+               assert(view);
+               tex = (struct r600_texture *)view->resource;
+
+               if (view->resource->target == PIPE_BUFFER)
+                       continue;
+
+               if (img_handle->compressed_colortex)
+                       si_decompress_color_texture(sctx, tex, 
view->u.tex.level,
+                                                   view->u.tex.level);
+       }
+}
+
 void si_decompress_graphics_textures(struct si_context *sctx)
 {
+       if (sctx->blitter->running)
+               return;
+
        si_decompress_textures(sctx, u_bit_consecutive(0, 
SI_NUM_GRAPHICS_SHADERS));
+
+       si_decompress_resident_textures(sctx);
+       si_decompress_resident_images(sctx);
 }
 
 void si_decompress_compute_textures(struct si_context *sctx)
 {
+       if (sctx->blitter->running)
+               return;
+
        si_decompress_textures(sctx, 1 << PIPE_SHADER_COMPUTE);
+
+       si_decompress_resident_textures(sctx);
+       si_decompress_resident_images(sctx);
 }
 
 static void si_clear(struct pipe_context *ctx, unsigned buffers,
diff --git a/src/gallium/drivers/radeonsi/si_descriptors.c 
b/src/gallium/drivers/radeonsi/si_descriptors.c
index 195ec4ef99..357039a78a 100644
--- a/src/gallium/drivers/radeonsi/si_descriptors.c
+++ b/src/gallium/drivers/radeonsi/si_descriptors.c
@@ -1624,6 +1624,48 @@ static void si_set_polygon_stipple(struct pipe_context 
*ctx,
 
 /* TEXTURE METADATA ENABLE/DISABLE */
 
+static void
+si_resident_handles_update_compressed_colortex(struct si_context *sctx)
+{
+       unsigned num_resident_tex_handles, num_resident_img_handles;
+       unsigned i;
+
+       num_resident_tex_handles = sctx->resident_tex_handles.size /
+                                  sizeof(struct si_texture_handle *);
+
+       for (i = 0; i < num_resident_tex_handles; i++) {
+               struct si_texture_handle *tex_handle =
+                       *util_dynarray_element(&sctx->resident_tex_handles,
+                                              struct si_texture_handle *, i);
+               struct pipe_resource *res = tex_handle->view->texture;
+
+               if (res && res->target != PIPE_BUFFER) {
+                       struct r600_texture *rtex = (struct r600_texture *)res;
+
+                       tex_handle->compressed_colortex =
+                               is_compressed_colortex(rtex);
+               }
+       }
+
+       num_resident_img_handles = sctx->resident_img_handles.size /
+                                  sizeof(struct si_image_handle *);
+
+       for (i = 0; i < num_resident_img_handles; i++) {
+               struct si_image_handle *img_handle =
+                       *util_dynarray_element(&sctx->resident_img_handles,
+                                              struct si_image_handle *, i);
+               struct pipe_image_view *view = &img_handle->view;
+               struct pipe_resource *res = view->resource;
+
+               if (res && res->target != PIPE_BUFFER) {
+                       struct r600_texture *rtex = (struct r600_texture *)res;
+
+                       img_handle->compressed_colortex =
+                               is_compressed_colortex(rtex);
+               }
+       }
+}
+
 /* 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.
@@ -1635,6 +1677,8 @@ void si_update_compressed_colortex_masks(struct 
si_context *sctx)
                si_images_update_compressed_colortex_mask(&sctx->images[i]);
                si_update_compressed_tex_shader_mask(sctx, i);
        }
+
+       si_resident_handles_update_compressed_colortex(sctx);
 }
 
 /* BUFFER DISCARD/INVALIDATION */
@@ -2252,6 +2296,11 @@ static void si_make_texture_handle_resident(struct 
pipe_context *ctx,
                        struct r600_texture *rtex =
                                (struct r600_texture *)sview->base.texture;
 
+                       tex_handle->depth_texture =
+                               depth_needs_decompression(rtex, sview);
+                       tex_handle->compressed_colortex =
+                               is_compressed_colortex(rtex);
+
                        si_update_check_render_feedback(sctx, rtex);
                }
 
@@ -2363,6 +2412,9 @@ static void si_make_image_handle_resident(struct 
pipe_context *ctx,
                if (res->b.b.target != PIPE_BUFFER) {
                        struct r600_texture *rtex = (struct r600_texture *)res;
 
+                       img_handle->compressed_colortex =
+                               is_compressed_colortex(rtex);
+
                        si_update_check_render_feedback(sctx, rtex);
                }
 
diff --git a/src/gallium/drivers/radeonsi/si_pipe.h 
b/src/gallium/drivers/radeonsi/si_pipe.h
index 8b7ff26a69..04470e65cf 100644
--- a/src/gallium/drivers/radeonsi/si_pipe.h
+++ b/src/gallium/drivers/radeonsi/si_pipe.h
@@ -237,12 +237,15 @@ struct si_texture_handle
 {
        struct si_bindless_descriptor   *desc;
        struct pipe_sampler_view        *view;
+       bool                            compressed_colortex;
+       bool                            depth_texture;
 };
 
 struct si_image_handle
 {
        struct si_bindless_descriptor   *desc;
        struct pipe_image_view          view;
+       bool                            compressed_colortex;
 };
 
 struct si_context {
-- 
2.13.0

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

Reply via email to