[Mesa-dev] [PATCH 08/17] tgsi/ureg: add shared variables support for compute shaders

Samuel Pitoiset samuel.pitoiset at gmail.com
Sun Jan 24 13:09:43 PST 2016


This adds a new SHARED attribute to TGSI_FILE_BUFFER. Only
one shared buffer can be declared and its size is defined by
MAX_COMPUTE_SHARED_SIZE. Note that an atomic buffer can also
be shared.

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     |  2 ++
 src/gallium/auxiliary/tgsi/tgsi_text.c     |  3 +++
 src/gallium/auxiliary/tgsi/tgsi_ureg.c     | 11 ++++++++---
 src/gallium/auxiliary/tgsi/tgsi_ureg.h     |  3 ++-
 src/gallium/include/pipe/p_shader_tokens.h |  3 ++-
 src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 15 ++++++++-------
 7 files changed, 26 insertions(+), 12 deletions(-)

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..5305d90 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_dump.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_dump.c
@@ -362,6 +362,8 @@ iter_declaration(
    if (decl->Declaration.File == TGSI_FILE_BUFFER) {
       if (decl->Declaration.Atomic)
          TXT(", ATOMIC");
+      if (decl->Declaration.Shared)
+         TXT(", SHARED");
    }
 
    if (decl->Declaration.File == TGSI_FILE_SAMPLER_VIEW) {
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 d681150..52e3c66 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_ureg.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_ureg.c
@@ -168,6 +168,7 @@ struct ureg_program
    struct {
       unsigned index;
       bool atomic;
+      bool shared;
    } buffer[PIPE_MAX_SHADER_BUFFERS];
    unsigned nr_buffers;
 
@@ -707,7 +708,7 @@ ureg_DECL_image(struct ureg_program *ureg,
 /* Allocate a new buffer.
  */
 struct ureg_src ureg_DECL_buffer(struct ureg_program *ureg, unsigned nr,
-                                 bool atomic)
+                                 bool atomic, bool shared)
 {
    struct ureg_src reg = ureg_src_register(TGSI_FILE_BUFFER, nr);
    unsigned i;
@@ -719,6 +720,7 @@ struct ureg_src ureg_DECL_buffer(struct ureg_program *ureg, unsigned nr,
    if (i < PIPE_MAX_SHADER_BUFFERS) {
       ureg->buffer[i].index = nr;
       ureg->buffer[i].atomic = atomic;
+      ureg->buffer[i].shared = shared;
       ureg->nr_buffers++;
       return reg;
    }
@@ -1637,7 +1639,8 @@ emit_decl_image(struct ureg_program *ureg,
 static void
 emit_decl_buffer(struct ureg_program *ureg,
                  unsigned index,
-                 bool atomic)
+                 bool atomic,
+                 bool shared)
 {
    union tgsi_any_token *out = get_tokens(ureg, DOMAIN_DECL, 2);
 
@@ -1647,6 +1650,7 @@ emit_decl_buffer(struct ureg_program *ureg,
    out[0].decl.File = TGSI_FILE_BUFFER;
    out[0].decl.UsageMask = 0xf;
    out[0].decl.Atomic = atomic;
+   out[0].decl.Shared = shared;
 
    out[1].value = 0;
    out[1].decl_range.First = index;
@@ -1822,7 +1826,8 @@ static void emit_decls( struct ureg_program *ureg )
    }
 
    for (i = 0; i < ureg->nr_buffers; i++) {
-      emit_decl_buffer(ureg, ureg->buffer[i].index, ureg->buffer[i].atomic);
+      emit_decl_buffer(ureg, ureg->buffer[i].index, ureg->buffer[i].atomic,
+                       ureg->buffer[i].shared);
    }
 
    if (ureg->const_decls.nr_constant_ranges) {
diff --git a/src/gallium/auxiliary/tgsi/tgsi_ureg.h b/src/gallium/auxiliary/tgsi/tgsi_ureg.h
index 86e58a9..c4f184f 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_ureg.h
+++ b/src/gallium/auxiliary/tgsi/tgsi_ureg.h
@@ -335,7 +335,8 @@ ureg_DECL_image(struct ureg_program *ureg,
                 boolean raw);
 
 struct ureg_src
-ureg_DECL_buffer(struct ureg_program *ureg, unsigned nr, bool atomic);
+ureg_DECL_buffer(struct ureg_program *ureg, unsigned nr, bool atomic,
+                 bool shared);
 
 static inline struct ureg_src
 ureg_imm4f( struct ureg_program *ureg,
diff --git a/src/gallium/include/pipe/p_shader_tokens.h b/src/gallium/include/pipe/p_shader_tokens.h
index 6539017..cb1995e 100644
--- a/src/gallium/include/pipe/p_shader_tokens.h
+++ b/src/gallium/include/pipe/p_shader_tokens.h
@@ -129,7 +129,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_BUFFER */
+   unsigned Padding     : 4;
 };
 
 struct tgsi_declaration_range
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index 870991d..ed8778f 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -395,7 +395,7 @@ public:
    int samplers_used;
    glsl_base_type sampler_types[PIPE_MAX_SAMPLERS];
    int sampler_targets[PIPE_MAX_SAMPLERS];   /**< One of TGSI_TEXTURE_* */
-   int buffers_used;
+   uint64_t buffers_used;
    bool indirect_addr_consts;
    int wpos_transform_const;
 
@@ -3937,7 +3937,7 @@ count_resources(glsl_to_tgsi_visitor *v, gl_program *prog)
                 is_resource_instruction(inst->op) ||
                 inst->op == TGSI_OPCODE_STORE)) {
          if (inst->buffer.file == PROGRAM_BUFFER)
-            v->buffers_used |= 1 << inst->buffer.index;
+            v->buffers_used |= 1ULL << inst->buffer.index;
       }
    }
    prog->SamplersUsed = v->samplers_used;
@@ -5855,19 +5855,20 @@ st_translate_program(
    }
 
    for (i = 0; i < frag_const->MaxAtomicBuffers; i++) {
-      if (program->buffers_used & (1 << i)) {
-         t->buffers[i] = ureg_DECL_buffer(ureg, i, true);
+      if (program->buffers_used & (1ULL << i)) {
+         t->buffers[i] = ureg_DECL_buffer(ureg, i, true, false);
       }
    }
 
    for (; i < frag_const->MaxAtomicBuffers + frag_const->MaxShaderStorageBlocks;
         i++) {
-      if (program->buffers_used & (1 << i)) {
-         t->buffers[i] = ureg_DECL_buffer(ureg, i, false);
+      if (program->buffers_used & (1ULL << i)) {
+         t->buffers[i] = ureg_DECL_buffer(ureg, i, false, false);
       }
    }
 
-
+   if (program->buffers_used & (1ULL << i))
+      t->buffers[i] = ureg_DECL_buffer(ureg, i, false, true);
 
    /* Emit each instruction in turn:
     */
-- 
2.6.4



More information about the mesa-dev mailing list