[Mesa-dev] [RFC PATCH 57/65] radeonsi: decompress resident textures/images before graphics/compute

Samuel Pitoiset samuel.pitoiset at gmail.com
Fri May 19 16:53:02 UTC 2017


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

Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
---
 src/gallium/drivers/radeonsi/si_blit.c        | 67 +++++++++++++++++++++++++--
 src/gallium/drivers/radeonsi/si_descriptors.c | 44 ++++++++++++++++++
 src/gallium/drivers/radeonsi/si_pipe.h        |  3 ++
 3 files changed, 111 insertions(+), 3 deletions(-)

diff --git a/src/gallium/drivers/radeonsi/si_blit.c b/src/gallium/drivers/radeonsi/si_blit.c
index 4078f2498b..32041695e2 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"
 
@@ -680,9 +681,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) {
@@ -709,14 +707,77 @@ 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 i;
+
+	for (i = 0; i < sctx->num_resident_tex_handles; i++) {
+		struct si_texture_handle *tex_handle =
+			sctx->resident_tex_handles[i];
+		struct si_sampler_view *sview = tex_handle->view;
+		struct pipe_sampler_view *view = &sview->base;
+		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 i;
+
+	for (i = 0; i < sctx->num_resident_img_handles; i++) {
+		struct si_image_handle *img_handle =
+			sctx->resident_img_handles[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 e459f19d66..05559d90d7 100644
--- a/src/gallium/drivers/radeonsi/si_descriptors.c
+++ b/src/gallium/drivers/radeonsi/si_descriptors.c
@@ -1624,6 +1624,40 @@ 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 i;
+
+	for (i = 0; i < sctx->num_resident_tex_handles; i++) {
+		struct si_texture_handle *tex_handle =
+			sctx->resident_tex_handles[i];
+		struct si_sampler_view *sview = tex_handle->view;
+		struct pipe_resource *res = sview->base.texture;
+
+		if (res && res->target != PIPE_BUFFER) {
+			struct r600_texture *rtex = (struct r600_texture *)res;
+
+			tex_handle->compressed_colortex =
+				is_compressed_colortex(rtex);
+		}
+	}
+
+	for (i = 0; i < sctx->num_resident_img_handles; i++) {
+		struct si_image_handle *img_handle =
+			sctx->resident_img_handles[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 +1669,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 */
@@ -2420,6 +2456,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);
 		}
 
@@ -2524,6 +2565,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 3a2487bff0..7dafa77c37 100644
--- a/src/gallium/drivers/radeonsi/si_pipe.h
+++ b/src/gallium/drivers/radeonsi/si_pipe.h
@@ -235,12 +235,15 @@ struct si_texture_handle
 {
 	struct si_resident_descriptor	*desc;
 	struct si_sampler_view		*view;
+	bool				compressed_colortex;
+	bool				depth_texture;
 };
 
 struct si_image_handle
 {
 	struct si_resident_descriptor	*desc;
 	struct pipe_image_view		view;
+	bool				compressed_colortex;
 };
 
 struct si_context {
-- 
2.13.0



More information about the mesa-dev mailing list