[Mesa-dev] [PATCH 07/11] radeonsi: use a bitmask-based loop in si_decompress_textures

Marek Olšák maraeo at gmail.com
Tue Jan 17 22:47:57 UTC 2017


From: Marek Olšák <marek.olsak at amd.com>

---
 src/gallium/drivers/radeonsi/si_blit.c        | 16 +++++++++-------
 src/gallium/drivers/radeonsi/si_descriptors.c | 21 +++++++++++++++++++++
 src/gallium/drivers/radeonsi/si_pipe.h        |  1 +
 3 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/src/gallium/drivers/radeonsi/si_blit.c b/src/gallium/drivers/radeonsi/si_blit.c
index 5b53373..da6c0cd 100644
--- a/src/gallium/drivers/radeonsi/si_blit.c
+++ b/src/gallium/drivers/radeonsi/si_blit.c
@@ -611,59 +611,61 @@ static void si_check_render_feedback(struct si_context *sctx)
 	if (!sctx->need_check_render_feedback)
 		return;
 
 	for (int i = 0; i < SI_NUM_SHADERS; ++i) {
 		si_check_render_feedback_images(sctx, &sctx->images[i]);
 		si_check_render_feedback_textures(sctx, &sctx->samplers[i]);
 	}
 	sctx->need_check_render_feedback = false;
 }
 
-static void si_decompress_textures(struct si_context *sctx, int shader_start,
-                                   int shader_end)
+static void si_decompress_textures(struct si_context *sctx, unsigned shader_mask)
 {
-	unsigned compressed_colortex_counter;
+	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) {
 		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 = shader_start; i < shader_end; i++) {
+	/* Decompress color & depth textures if needed. */
+	mask = sctx->compressed_tex_shader_mask & shader_mask;
+	while (mask) {
+		unsigned i = u_bit_scan(&mask);
+
 		if (sctx->samplers[i].depth_texture_mask) {
 			si_flush_depth_textures(sctx, &sctx->samplers[i]);
 		}
 		if (sctx->samplers[i].compressed_colortex_mask) {
 			si_decompress_sampler_color_textures(sctx, &sctx->samplers[i]);
 		}
 		if (sctx->images[i].compressed_colortex_mask) {
 			si_decompress_image_color_textures(sctx, &sctx->images[i]);
 		}
 	}
 
 	si_check_render_feedback(sctx);
 }
 
 void si_decompress_graphics_textures(struct si_context *sctx)
 {
-	si_decompress_textures(sctx, 0, SI_NUM_GRAPHICS_SHADERS);
+	si_decompress_textures(sctx, u_bit_consecutive(0, SI_NUM_GRAPHICS_SHADERS));
 }
 
 void si_decompress_compute_textures(struct si_context *sctx)
 {
-	si_decompress_textures(sctx, SI_NUM_GRAPHICS_SHADERS, SI_NUM_SHADERS);
+	si_decompress_textures(sctx, 1 << PIPE_SHADER_COMPUTE);
 }
 
 static void si_clear(struct pipe_context *ctx, unsigned buffers,
 		     const union pipe_color_union *color,
 		     double depth, unsigned stencil)
 {
 	struct si_context *sctx = (struct si_context *)ctx;
 	struct pipe_framebuffer_state *fb = &sctx->framebuffer.state;
 	struct pipe_surface *zsbuf = fb->zsbuf;
 	struct r600_texture *zstex =
diff --git a/src/gallium/drivers/radeonsi/si_descriptors.c b/src/gallium/drivers/radeonsi/si_descriptors.c
index 0472d23..a535fa0 100644
--- a/src/gallium/drivers/radeonsi/si_descriptors.c
+++ b/src/gallium/drivers/radeonsi/si_descriptors.c
@@ -483,20 +483,34 @@ static void si_set_sampler_view(struct si_context *sctx,
 	descs->dirty_mask |= 1u << slot;
 	sctx->descriptors_dirty |= 1u << si_sampler_descriptors_idx(shader);
 }
 
 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_update_compressed_tex_shader_mask(struct si_context *sctx,
+						 unsigned shader)
+{
+	struct si_textures_info *samplers = &sctx->samplers[shader];
+	unsigned shader_bit = 1 << shader;
+
+	if (samplers->depth_texture_mask ||
+	    samplers->compressed_colortex_mask ||
+	    sctx->images[shader].compressed_colortex_mask)
+		sctx->compressed_tex_shader_mask |= shader_bit;
+	else
+		sctx->compressed_tex_shader_mask &= ~shader_bit;
+}
+
 static void si_set_sampler_views(struct pipe_context *ctx,
 				 enum pipe_shader_type shader, unsigned start,
                                  unsigned count,
 				 struct pipe_sampler_view **views)
 {
 	struct si_context *sctx = (struct si_context *)ctx;
 	struct si_textures_info *samplers = &sctx->samplers[shader];
 	int i;
 
 	if (!count || shader >= SI_NUM_SHADERS)
@@ -532,20 +546,22 @@ static void si_set_sampler_views(struct pipe_context *ctx,
 			}
 
 			if (rtex->dcc_offset &&
 			    p_atomic_read(&rtex->framebuffers_bound))
 				sctx->need_check_render_feedback = true;
 		} else {
 			samplers->depth_texture_mask &= ~(1u << slot);
 			samplers->compressed_colortex_mask &= ~(1u << slot);
 		}
 	}
+
+	si_update_compressed_tex_shader_mask(sctx, shader);
 }
 
 static void
 si_samplers_update_compressed_colortex_mask(struct si_textures_info *samplers)
 {
 	unsigned mask = samplers->views.enabled_mask;
 
 	while (mask) {
 		int i = u_bit_scan(&mask);
 		struct pipe_resource *res = samplers->views.views[i]->texture;
@@ -752,20 +768,22 @@ si_set_shader_images(struct pipe_context *pipe,
 
 	assert(start_slot + count <= SI_NUM_IMAGES);
 
 	if (views) {
 		for (i = 0, slot = start_slot; i < count; ++i, ++slot)
 			si_set_shader_image(ctx, shader, slot, &views[i]);
 	} else {
 		for (i = 0, slot = start_slot; i < count; ++i, ++slot)
 			si_set_shader_image(ctx, shader, slot, NULL);
 	}
+
+	si_update_compressed_tex_shader_mask(ctx, shader);
 }
 
 static void
 si_images_update_compressed_colortex_mask(struct si_images_info *images)
 {
 	unsigned mask = images->enabled_mask;
 
 	while (mask) {
 		int i = u_bit_scan(&mask);
 		struct pipe_resource *res = images->views[i].resource;
@@ -1484,20 +1502,21 @@ static void si_set_polygon_stipple(struct pipe_context *ctx,
 
 /* 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]);
 		si_images_update_compressed_colortex_mask(&sctx->images[i]);
+		si_update_compressed_tex_shader_mask(sctx, i);
 	}
 }
 
 /* BUFFER DISCARD/INVALIDATION */
 
 /** Reset descriptors of buffer resources after \p buf has been invalidated. */
 static void si_reset_buffer_resources(struct si_context *sctx,
 				      struct si_buffer_resources *buffers,
 				      unsigned descriptors_idx,
 				      struct pipe_resource *buf,
@@ -1699,20 +1718,22 @@ void si_update_all_texture_descriptors(struct si_context *sctx)
 			struct pipe_sampler_view *view = samplers->views[i];
 
 			if (!view ||
 			    !view->texture ||
 			    view->texture->target == PIPE_BUFFER)
 				continue;
 
 			si_set_sampler_view(sctx, shader, i,
 					    samplers->views[i], true);
 		}
+
+		si_update_compressed_tex_shader_mask(sctx, shader);
 	}
 }
 
 /* SHADER USER DATA */
 
 static void si_mark_shader_pointers_dirty(struct si_context *sctx,
 					  unsigned shader)
 {
 	struct si_descriptors *descs =
 		&sctx->descriptors[SI_DESCS_FIRST_SHADER + shader * SI_NUM_SHADER_DESCS];
diff --git a/src/gallium/drivers/radeonsi/si_pipe.h b/src/gallium/drivers/radeonsi/si_pipe.h
index c9ae27e..e7d071d 100644
--- a/src/gallium/drivers/radeonsi/si_pipe.h
+++ b/src/gallium/drivers/radeonsi/si_pipe.h
@@ -261,20 +261,21 @@ struct si_context {
 	/* shader information */
 	struct si_vertex_element	*vertex_elements;
 	unsigned			sprite_coord_enable;
 	bool				flatshade;
 	bool				do_update_shaders;
 
 	/* shader descriptors */
 	struct si_descriptors		vertex_buffers;
 	struct si_descriptors		descriptors[SI_NUM_DESCS];
 	unsigned			descriptors_dirty;
+	unsigned			compressed_tex_shader_mask;
 	struct si_buffer_resources	rw_buffers;
 	struct si_buffer_resources	const_buffers[SI_NUM_SHADERS];
 	struct si_buffer_resources	shader_buffers[SI_NUM_SHADERS];
 	struct si_textures_info		samplers[SI_NUM_SHADERS];
 	struct si_images_info		images[SI_NUM_SHADERS];
 
 	/* other shader resources */
 	struct pipe_constant_buffer	null_const_buf; /* used for set_constant_buffer(NULL) on CIK */
 	struct pipe_resource		*esgs_ring;
 	struct pipe_resource		*gsvs_ring;
-- 
2.7.4



More information about the mesa-dev mailing list