ureg: add buffer support to ureg
authorIlia Mirkin <imirkin@alum.mit.edu>
Sat, 19 Sep 2015 22:19:13 +0000 (18:19 -0400)
committerIlia Mirkin <imirkin@alum.mit.edu>
Fri, 8 Jan 2016 20:10:32 +0000 (15:10 -0500)
Signed-off-by: Ilia Mirkin <imirkin@alum.mit.edu>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/gallium/auxiliary/tgsi/tgsi_dump.c
src/gallium/auxiliary/tgsi/tgsi_strings.c
src/gallium/auxiliary/tgsi/tgsi_text.c
src/gallium/auxiliary/tgsi/tgsi_ureg.c
src/gallium/auxiliary/tgsi/tgsi_ureg.h
src/gallium/include/pipe/p_shader_tokens.h

index dad3839d89736c8cc37dab49ad887a67b48e1bec..de3aae5337c0af8889c937152a4438f3e27fa189 100644 (file)
@@ -359,6 +359,11 @@ iter_declaration(
          TXT(", RAW");
    }
 
+   if (decl->Declaration.File == TGSI_FILE_BUFFER) {
+      if (decl->Declaration.Atomic)
+         TXT(", ATOMIC");
+   }
+
    if (decl->Declaration.File == TGSI_FILE_SAMPLER_VIEW) {
       TXT(", ");
       ENM(decl->SamplerView.Resource, tgsi_texture_names);
index ae30399376ffa3ff9dc26dd4a7c43295a90202dc..c0dd04497f7bdb09638f6142c7871f062ac1c702 100644 (file)
@@ -56,6 +56,7 @@ static const char *tgsi_file_names[] =
    "SV",
    "IMAGE",
    "SVIEW",
+   "BUFFER",
 };
 
 const char *tgsi_semantic_names[TGSI_SEMANTIC_COUNT] =
index a45ab908ee032342d94ef8c321de240b8d597fd7..d72d843951a052a093c3f94511267d20a7b46361 100644 (file)
@@ -1350,6 +1350,11 @@ static boolean parse_declaration( struct translate_ctx *ctx )
                decl.SamplerView.ReturnTypeX;
          }
          ctx->cur = cur;
+      } else if (file == TGSI_FILE_BUFFER) {
+         if (str_match_nocase_whole(&cur, "ATOMIC")) {
+            decl.Declaration.Atomic = 1;
+            ctx->cur = cur;
+         }
       } else {
          if (str_match_nocase_whole(&cur, "LOCAL")) {
             decl.Declaration.Local = 1;
index 59a4d3642a69a78583b5889af9a22e5a30f421be..0ad23dd5e5628a085ebeaf4db25c7c553d4ceb3d 100644 (file)
@@ -164,6 +164,12 @@ struct ureg_program
    } image[PIPE_MAX_SHADER_IMAGES];
    unsigned nr_images;
 
+   struct {
+      unsigned index;
+      bool atomic;
+   } buffer[PIPE_MAX_SHADER_BUFFERS];
+   unsigned nr_buffers;
+
    struct util_bitmask *free_temps;
    struct util_bitmask *local_temps;
    struct util_bitmask *decl_temps;
@@ -697,6 +703,29 @@ ureg_DECL_image(struct ureg_program *ureg,
    return reg;
 }
 
+/* Allocate a new buffer.
+ */
+struct ureg_src ureg_DECL_buffer(struct ureg_program *ureg, unsigned nr,
+                                 bool atomic)
+{
+   struct ureg_src reg = ureg_src_register(TGSI_FILE_BUFFER, nr);
+   unsigned i;
+
+   for (i = 0; i < ureg->nr_buffers; i++)
+      if (ureg->buffer[i].index == nr)
+         return reg;
+
+   if (i < PIPE_MAX_SHADER_BUFFERS) {
+      ureg->buffer[i].index = nr;
+      ureg->buffer[i].atomic = atomic;
+      ureg->nr_buffers++;
+      return reg;
+   }
+
+   assert(0);
+   return reg;
+}
+
 static int
 match_or_expand_immediate64( const unsigned *v,
                              int type,
@@ -1553,6 +1582,25 @@ emit_decl_image(struct ureg_program *ureg,
    out[2].decl_image.Format   = format;
 }
 
+static void
+emit_decl_buffer(struct ureg_program *ureg,
+                 unsigned index,
+                 bool atomic)
+{
+   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_BUFFER;
+   out[0].decl.UsageMask = 0xf;
+   out[0].decl.Atomic = atomic;
+
+   out[1].value = 0;
+   out[1].decl_range.First = index;
+   out[1].decl_range.Last = index;
+}
+
 static void
 emit_immediate( struct ureg_program *ureg,
                 const unsigned *v,
@@ -1721,6 +1769,10 @@ static void emit_decls( struct ureg_program *ureg )
                       ureg->image[i].raw);
    }
 
+   for (i = 0; i < ureg->nr_buffers; i++) {
+      emit_decl_buffer(ureg, ureg->buffer[i].index, ureg->buffer[i].atomic);
+   }
+
    if (ureg->const_decls.nr_constant_ranges) {
       for (i = 0; i < ureg->const_decls.nr_constant_ranges; i++) {
          emit_decl_range(ureg,
index 39b0a0f0ba108de13eeaca43abc07f465ea63229..4a411c66491c4d1260989a9ca7e27ee1364bf8b5 100644 (file)
@@ -334,6 +334,9 @@ ureg_DECL_image(struct ureg_program *ureg,
                 boolean wr,
                 boolean raw);
 
+struct ureg_src
+ureg_DECL_buffer(struct ureg_program *ureg, unsigned nr, bool atomic);
+
 static inline struct ureg_src
 ureg_imm4f( struct ureg_program *ureg,
                        float a, float b,
index d18296276f768daef80ee600be7e9754a773c42e..815aff1dab362bbc58006c7716811ab48c6ce396 100644 (file)
@@ -78,6 +78,7 @@ enum tgsi_file_type {
    TGSI_FILE_SYSTEM_VALUE        =9,
    TGSI_FILE_IMAGE               =10,
    TGSI_FILE_SAMPLER_VIEW        =11,
+   TGSI_FILE_BUFFER              =12,
    TGSI_FILE_COUNT      /**< how many TGSI_FILE_ types */
 };
 
@@ -127,7 +128,8 @@ struct tgsi_declaration
    unsigned Invariant   : 1;  /**< invariant optimization? */
    unsigned Local       : 1;  /**< optimize as subroutine local variable? */
    unsigned Array       : 1;  /**< extra array info? */
-   unsigned Padding     : 6;
+   unsigned Atomic      : 1;  /**< atomic only? for TGSI_FILE_BUFFER */
+   unsigned Padding     : 5;
 };
 
 struct tgsi_declaration_range