[Mesa-dev] [PATCH v2 09/20] tgsi/ureg: add shared variables support for compute shaders

Ilia Mirkin imirkin at alum.mit.edu
Sat Feb 6 23:51:45 UTC 2016


On Sat, Feb 6, 2016 at 5:04 PM, Samuel Pitoiset
<samuel.pitoiset at gmail.com> wrote:
> This introduces TGSI_FILE_MEMORY for shared, global and local memory.
> Only shared memory is currently supported.
>
> Changes from v2:
>  - introduce TGSI_FILE_MEMORY
>
> Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
> ---
>  src/gallium/auxiliary/tgsi/tgsi_build.c    |  1 +
>  src/gallium/auxiliary/tgsi/tgsi_dump.c     |  5 +++++
>  src/gallium/auxiliary/tgsi/tgsi_strings.c  |  1 +
>  src/gallium/auxiliary/tgsi/tgsi_text.c     |  3 +++
>  src/gallium/auxiliary/tgsi/tgsi_ureg.c     | 32 ++++++++++++++++++++++++++++++
>  src/gallium/auxiliary/tgsi/tgsi_ureg.h     |  3 +++
>  src/gallium/include/pipe/p_shader_tokens.h |  4 +++-
>  7 files changed, 48 insertions(+), 1 deletion(-)
>
> diff --git a/src/gallium/auxiliary/tgsi/tgsi_build.c b/src/gallium/auxiliary/tgsi/tgsi_build.c
> index 83f5062..cfe9b92 100644
> --- a/src/gallium/auxiliary/tgsi/tgsi_build.c
> +++ b/src/gallium/auxiliary/tgsi/tgsi_build.c
> @@ -111,6 +111,7 @@ tgsi_default_declaration( void )
>     declaration.Local = 0;
>     declaration.Array = 0;
>     declaration.Atomic = 0;
> +   declaration.Shared = 0;
>     declaration.Padding = 0;
>
>     return declaration;
> diff --git a/src/gallium/auxiliary/tgsi/tgsi_dump.c b/src/gallium/auxiliary/tgsi/tgsi_dump.c
> index 2ad29b9..36f0cc5 100644
> --- a/src/gallium/auxiliary/tgsi/tgsi_dump.c
> +++ b/src/gallium/auxiliary/tgsi/tgsi_dump.c
> @@ -364,6 +364,11 @@ iter_declaration(
>           TXT(", ATOMIC");
>     }
>
> +   if (decl->Declaration.File == TGSI_FILE_MEMORY) {
> +      if (decl->Declaration.Shared)
> +         TXT(", SHARED");
> +   }
> +
>     if (decl->Declaration.File == TGSI_FILE_SAMPLER_VIEW) {
>        TXT(", ");
>        ENM(decl->SamplerView.Resource, tgsi_texture_names);
> diff --git a/src/gallium/auxiliary/tgsi/tgsi_strings.c b/src/gallium/auxiliary/tgsi/tgsi_strings.c
> index f2d70d4..b15ae69 100644
> --- a/src/gallium/auxiliary/tgsi/tgsi_strings.c
> +++ b/src/gallium/auxiliary/tgsi/tgsi_strings.c
> @@ -57,6 +57,7 @@ static const char *tgsi_file_names[] =
>     "IMAGE",
>     "SVIEW",
>     "BUFFER",
> +   "MEMORY",
>  };
>
>  const char *tgsi_semantic_names[TGSI_SEMANTIC_COUNT] =
> diff --git a/src/gallium/auxiliary/tgsi/tgsi_text.c b/src/gallium/auxiliary/tgsi/tgsi_text.c
> index 97b1869..ef43ebc 100644
> --- a/src/gallium/auxiliary/tgsi/tgsi_text.c
> +++ b/src/gallium/auxiliary/tgsi/tgsi_text.c
> @@ -1381,6 +1381,9 @@ static boolean parse_declaration( struct translate_ctx *ctx )
>           if (str_match_nocase_whole(&cur, "ATOMIC")) {
>              decl.Declaration.Atomic = 1;
>              ctx->cur = cur;
> +         } else if (str_match_nocase_whole(&cur, "SHARED")) {
> +            decl.Declaration.Shared = 1;
> +            ctx->cur = cur;
>           }
>        } else {
>           if (str_match_nocase_whole(&cur, "LOCAL")) {
> diff --git a/src/gallium/auxiliary/tgsi/tgsi_ureg.c b/src/gallium/auxiliary/tgsi/tgsi_ureg.c
> index 9654ac5..e1a7278 100644
> --- a/src/gallium/auxiliary/tgsi/tgsi_ureg.c
> +++ b/src/gallium/auxiliary/tgsi/tgsi_ureg.c
> @@ -189,6 +189,8 @@ struct ureg_program
>     unsigned nr_instructions;
>
>     struct ureg_tokens domain[2];
> +
> +   bool use_shared_memory;
>  };
>
>  static union tgsi_any_token error_tokens[32];
> @@ -727,6 +729,16 @@ struct ureg_src ureg_DECL_buffer(struct ureg_program *ureg, unsigned nr,
>     return reg;
>  }
>
> +/* Allocate a shared memory area.
> + */
> +struct ureg_src ureg_DECL_shared_memory(struct ureg_program *ureg)
> +{
> +   struct ureg_src reg = ureg_src_register(TGSI_FILE_MEMORY, 0);
> +
> +   ureg->use_shared_memory = true;
> +   return reg;
> +}
> +
>  static int
>  match_or_expand_immediate64( const unsigned *v,
>                               int type,
> @@ -1654,6 +1666,23 @@ emit_decl_buffer(struct ureg_program *ureg,
>  }
>
>  static void
> +emit_decl_shared_memory(struct ureg_program *ureg)
> +{
> +   union tgsi_any_token *out = get_tokens(ureg, DOMAIN_DECL, 2);
> +
> +   out[0].value = 0;
> +   out[0].decl.Type = TGSI_TOKEN_TYPE_DECLARATION;
> +   out[0].decl.NrTokens = 2;
> +   out[0].decl.File = TGSI_FILE_MEMORY;
> +   out[0].decl.UsageMask = TGSI_WRITEMASK_XYZW;
> +   out[0].decl.Shared = true;
> +
> +   out[1].value = 0;
> +   out[1].decl_range.First = 0;
> +   out[1].decl_range.Last = 0;
> +}
> +
> +static void
>  emit_immediate( struct ureg_program *ureg,
>                  const unsigned *v,
>                  unsigned type )
> @@ -1825,6 +1854,9 @@ static void emit_decls( struct ureg_program *ureg )
>        emit_decl_buffer(ureg, ureg->buffer[i].index, ureg->buffer[i].atomic);
>     }
>
> +   if (ureg->use_shared_memory)
> +      emit_decl_shared_memory(ureg);
> +
>     if (ureg->const_decls.nr_constant_ranges) {
>        for (i = 0; i < ureg->const_decls.nr_constant_ranges; i++) {
>           emit_decl_range(ureg,
> diff --git a/src/gallium/auxiliary/tgsi/tgsi_ureg.h b/src/gallium/auxiliary/tgsi/tgsi_ureg.h
> index 86e58a9..6a3b5dd 100644
> --- a/src/gallium/auxiliary/tgsi/tgsi_ureg.h
> +++ b/src/gallium/auxiliary/tgsi/tgsi_ureg.h
> @@ -337,6 +337,9 @@ ureg_DECL_image(struct ureg_program *ureg,
>  struct ureg_src
>  ureg_DECL_buffer(struct ureg_program *ureg, unsigned nr, bool atomic);
>
> +struct ureg_src
> +ureg_DECL_shared_memory(struct ureg_program *ureg);
> +
>  static inline struct ureg_src
>  ureg_imm4f( struct ureg_program *ureg,
>                         float a, float b,
> diff --git a/src/gallium/include/pipe/p_shader_tokens.h b/src/gallium/include/pipe/p_shader_tokens.h
> index 6539017..9d4a96a 100644
> --- a/src/gallium/include/pipe/p_shader_tokens.h
> +++ b/src/gallium/include/pipe/p_shader_tokens.h
> @@ -79,6 +79,7 @@ enum tgsi_file_type {
>     TGSI_FILE_IMAGE               =10,
>     TGSI_FILE_SAMPLER_VIEW        =11,
>     TGSI_FILE_BUFFER              =12,
> +   TGSI_FILE_MEMORY              =13,
>     TGSI_FILE_COUNT      /**< how many TGSI_FILE_ types */
>  };
>
> @@ -129,7 +130,8 @@ struct tgsi_declaration
>     unsigned Local       : 1;  /**< optimize as subroutine local variable? */
>     unsigned Array       : 1;  /**< extra array info? */
>     unsigned Atomic      : 1;  /**< atomic only? for TGSI_FILE_BUFFER */
> -   unsigned Padding     : 5;
> +   unsigned Shared      : 1;  /**< shared storage for TGSI_FILE_MEMORY */

Might as well go all out and steal 2 bits for shared/private/global?

> +   unsigned Padding     : 4;
>  };
>
>  struct tgsi_declaration_range
> --
> 2.6.4
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list