[Mesa-dev] [PATCH 01/24] tgsi/scan: record load/store/atomic image usage

Marek Olšák maraeo at gmail.com
Sat Feb 25 23:57:59 UTC 2017


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

---
 src/gallium/auxiliary/tgsi/tgsi_scan.c   | 15 ++++++++++-----
 src/gallium/auxiliary/tgsi/tgsi_scan.h   |  8 +++-----
 src/gallium/drivers/radeonsi/si_shader.c |  4 +++-
 3 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/src/gallium/auxiliary/tgsi/tgsi_scan.c b/src/gallium/auxiliary/tgsi/tgsi_scan.c
index 7d5496c..99799fa 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_scan.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_scan.c
@@ -276,31 +276,36 @@ scan_src_operand(struct tgsi_shader_info *info,
 
    if (is_memory_file(src->Register.File) &&
        !is_mem_query_inst(fullinst->Instruction.Opcode)) {
       *is_mem_inst = true;
 
       if (tgsi_get_opcode_info(fullinst->Instruction.Opcode)->is_store) {
          info->writes_memory = TRUE;
 
          if (src->Register.File == TGSI_FILE_IMAGE) {
             if (src->Register.Indirect)
-               info->images_writemask = info->images_declared;
+               info->images_atomic = info->images_declared;
             else
-               info->images_writemask |= 1 << src->Register.Index;
+               info->images_atomic |= 1 << src->Register.Index;
          } else if (src->Register.File == TGSI_FILE_BUFFER) {
             if (src->Register.Indirect)
                info->shader_buffers_atomic = info->shader_buffers_declared;
             else
                info->shader_buffers_atomic |= 1 << src->Register.Index;
          }
       } else {
-         if (src->Register.File == TGSI_FILE_BUFFER) {
+         if (src->Register.File == TGSI_FILE_IMAGE) {
+            if (src->Register.Indirect)
+               info->images_load = info->images_declared;
+            else
+               info->images_load |= 1 << src->Register.Index;
+         } else if (src->Register.File == TGSI_FILE_BUFFER) {
             if (src->Register.Indirect)
                info->shader_buffers_load = info->shader_buffers_declared;
             else
                info->shader_buffers_load |= 1 << src->Register.Index;
          }
       }
    }
 }
 
 
@@ -418,23 +423,23 @@ scan_instruction(struct tgsi_shader_info *info,
          info->dim_indirect_files |= 1u << dst->Register.File;
 
       if (is_memory_file(dst->Register.File)) {
          assert(fullinst->Instruction.Opcode == TGSI_OPCODE_STORE);
 
          is_mem_inst = true;
          info->writes_memory = TRUE;
 
          if (dst->Register.File == TGSI_FILE_IMAGE) {
             if (dst->Register.Indirect)
-               info->images_writemask = info->images_declared;
+               info->images_store = info->images_declared;
             else
-               info->images_writemask |= 1 << dst->Register.Index;
+               info->images_store |= 1 << dst->Register.Index;
          } else if (dst->Register.File == TGSI_FILE_BUFFER) {
             if (dst->Register.Indirect)
                info->shader_buffers_store = info->shader_buffers_declared;
             else
                info->shader_buffers_store |= 1 << dst->Register.Index;
          }
       }
    }
 
    if (is_mem_inst)
diff --git a/src/gallium/auxiliary/tgsi/tgsi_scan.h b/src/gallium/auxiliary/tgsi/tgsi_scan.h
index e3c24e9..3854827 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_scan.h
+++ b/src/gallium/auxiliary/tgsi/tgsi_scan.h
@@ -131,28 +131,26 @@ struct tgsi_shader_info
    boolean is_msaa_sampler[PIPE_MAX_SAMPLERS];
    boolean uses_doubles; /**< uses any of the double instructions */
    boolean uses_derivatives;
    unsigned clipdist_writemask;
    unsigned culldist_writemask;
    unsigned num_written_culldistance;
    unsigned num_written_clipdistance;
 
    unsigned images_declared; /**< bitmask of declared images */
    /**
-    * Bitmask indicating which images are written to (STORE / ATOM*).
-    * Indirect image accesses are not reflected in this mask.
-    */
-   unsigned images_writemask;
-   /**
     * Bitmask indicating which declared image is a buffer.
     */
    unsigned images_buffers;
+   unsigned images_load; /**< bitmask of images using loads */
+   unsigned images_store; /**< bitmask of images using stores */
+   unsigned images_atomic; /**< bitmask of images using atomics */
    unsigned shader_buffers_declared; /**< bitmask of declared shader buffers */
    unsigned shader_buffers_load; /**< bitmask of shader buffers using loads */
    unsigned shader_buffers_store; /**< bitmask of shader buffers using stores */
    unsigned shader_buffers_atomic; /**< bitmask of shader buffers using atomics */
    /**
     * Bitmask indicating which register files are accessed with
     * indirect addressing.  The bits are (1 << TGSI_FILE_x), etc.
     */
    unsigned indirect_files;
    /**
diff --git a/src/gallium/drivers/radeonsi/si_shader.c b/src/gallium/drivers/radeonsi/si_shader.c
index ea3f4fd..0299298 100644
--- a/src/gallium/drivers/radeonsi/si_shader.c
+++ b/src/gallium/drivers/radeonsi/si_shader.c
@@ -3321,24 +3321,26 @@ image_fetch_rsrc(
 	struct si_shader_context *ctx = si_shader_context(bld_base);
 	LLVMValueRef rsrc_ptr = LLVMGetParam(ctx->main_fn,
 					     SI_PARAM_IMAGES);
 	LLVMValueRef index, tmp;
 	bool dcc_off = target != TGSI_TEXTURE_BUFFER && is_store;
 
 	assert(image->Register.File == TGSI_FILE_IMAGE);
 
 	if (!image->Register.Indirect) {
 		const struct tgsi_shader_info *info = bld_base->info;
+		unsigned images_writemask = info->images_store |
+					    info->images_atomic;
 
 		index = LLVMConstInt(ctx->i32, image->Register.Index, 0);
 
-		if (info->images_writemask & (1 << image->Register.Index) &&
+		if (images_writemask & (1 << image->Register.Index) &&
 		    target != TGSI_TEXTURE_BUFFER)
 			dcc_off = true;
 	} else {
 		/* From the GL_ARB_shader_image_load_store extension spec:
 		 *
 		 *    If a shader performs an image load, store, or atomic
 		 *    operation using an image variable declared as an array,
 		 *    and if the index used to select an individual element is
 		 *    negative or greater than or equal to the size of the
 		 *    array, the results of the operation are undefined but may
-- 
2.7.4



More information about the mesa-dev mailing list