[Mesa-dev] [PATCH 02/74] glsl: Add ir_var_buffer

Jordan Justen jordan.l.justen at intel.com
Tue May 19 15:14:11 PDT 2015


On 2015-05-14 07:06:05, Iago Toral Quiroga wrote:
> From: Kristian Høgsberg <krh at bitplanet.net>
> 
> This will be used to identify buffer variables inside shader storage
> buffer objects, which are very similar to uniforms except for a few
> differences, most important of which is that they are writable.
> 
> Since buffer variables are so similar to uniforms, we will almost always
> want them to go through the same paths as uniforms.
> ---
>  src/glsl/builtin_variables.cpp                   |  5 +++--
>  src/glsl/glsl_symbol_table.cpp                   | 16 +++++++++++-----
>  src/glsl/ir.cpp                                  |  3 +++
>  src/glsl/ir.h                                    |  4 +++-
>  src/glsl/ir_function.cpp                         |  1 +
>  src/glsl/ir_print_visitor.cpp                    |  3 ++-
>  src/glsl/ir_reader.cpp                           |  2 ++
>  src/glsl/loop_unroll.cpp                         |  1 +
>  src/glsl/lower_named_interface_blocks.cpp        |  5 +++--
>  src/glsl/lower_variable_index_to_cond_assign.cpp |  1 +
>  src/glsl/opt_structure_splitting.cpp             |  5 +++--
>  11 files changed, 33 insertions(+), 13 deletions(-)
> 
> diff --git a/src/glsl/builtin_variables.cpp b/src/glsl/builtin_variables.cpp
> index 6806aa1..a3ed79d 100644
> --- a/src/glsl/builtin_variables.cpp
> +++ b/src/glsl/builtin_variables.cpp
> @@ -436,11 +436,12 @@ builtin_variable_generator::add_variable(const char *name,
>        var->data.read_only = true;
>        break;
>     case ir_var_shader_out:
> +   case ir_var_buffer:

I think ir_var_shader_storage or ir_var_ssbo is better.

-Jordan

>        break;
>     default:
>        /* The only variables that are added using this function should be
> -       * uniforms, shader inputs, and shader outputs, constants (which use
> -       * ir_var_auto), and system values.
> +       * uniforms, buffers, shader inputs, and shader outputs, constants
> +       * (which use ir_var_auto), and system values.
>         */
>        assert(0);
>        break;
> diff --git a/src/glsl/glsl_symbol_table.cpp b/src/glsl/glsl_symbol_table.cpp
> index 2294dda..e557689 100644
> --- a/src/glsl/glsl_symbol_table.cpp
> +++ b/src/glsl/glsl_symbol_table.cpp
> @@ -36,6 +36,9 @@ public:
>        case ir_var_uniform:
>           dest = &ibu;
>           break;
> +      case ir_var_buffer:
> +         dest = &ibb;
> +         break;
>        case ir_var_shader_in:
>           dest = &ibi;
>           break;
> @@ -60,6 +63,8 @@ public:
>        switch (mode) {
>        case ir_var_uniform:
>           return ibu;
> +      case ir_var_buffer:
> +         return ibb;
>        case ir_var_shader_in:
>           return ibi;
>        case ir_var_shader_out:
> @@ -71,24 +76,25 @@ public:
>     }
>  
>     symbol_table_entry(ir_variable *v)               :
> -      v(v), f(0), t(0), ibu(0), ibi(0), ibo(0), a(0) {}
> +      v(v), f(0), t(0), ibu(0), ibb(0), ibi(0), ibo(0), a(0) {}
>     symbol_table_entry(ir_function *f)               :
> -      v(0), f(f), t(0), ibu(0), ibi(0), ibo(0), a(0) {}
> +      v(0), f(f), t(0), ibu(0), ibb(0), ibi(0), ibo(0), a(0) {}
>     symbol_table_entry(const glsl_type *t)           :
> -      v(0), f(0), t(t), ibu(0), ibi(0), ibo(0), a(0) {}
> +      v(0), f(0), t(t), ibu(0), ibb(0), ibi(0), ibo(0), a(0) {}
>     symbol_table_entry(const glsl_type *t, enum ir_variable_mode mode) :
> -      v(0), f(0), t(0), ibu(0), ibi(0), ibo(0), a(0)
> +      v(0), f(0), t(0), ibu(0), ibb(0), ibi(0), ibo(0), a(0)
>     {
>        assert(t->is_interface());
>        add_interface(t, mode);
>     }
>     symbol_table_entry(const class ast_type_specifier *a):
> -      v(0), f(0), t(0), ibu(0), ibi(0), ibo(0), a(a) {}
> +      v(0), f(0), t(0), ibu(0), ibb(0), ibi(0), ibo(0), a(a) {}
>  
>     ir_variable *v;
>     ir_function *f;
>     const glsl_type *t;
>     const glsl_type *ibu;
> +   const glsl_type *ibb;
>     const glsl_type *ibi;
>     const glsl_type *ibo;
>     const class ast_type_specifier *a;
> diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp
> index 9e32385..b86a868 100644
> --- a/src/glsl/ir.cpp
> +++ b/src/glsl/ir.cpp
> @@ -1975,6 +1975,9 @@ mode_string(const ir_variable *var)
>     case ir_var_uniform:
>        return "uniform";
>  
> +   case ir_var_buffer:
> +      return "buffer";
> +
>     case ir_var_shader_in:
>        return "shader input";
>  
> diff --git a/src/glsl/ir.h b/src/glsl/ir.h
> index fab1cd2..88eb002 100644
> --- a/src/glsl/ir.h
> +++ b/src/glsl/ir.h
> @@ -323,6 +323,7 @@ protected:
>  enum ir_variable_mode {
>     ir_var_auto = 0,     /**< Function local variables and globals. */
>     ir_var_uniform,      /**< Variable declared as a uniform. */
> +   ir_var_buffer,       /**< Variable declared as an ssbo. */
>     ir_var_shader_in,
>     ir_var_shader_out,
>     ir_var_function_in,
> @@ -444,7 +445,8 @@ public:
>      */
>     inline bool is_in_uniform_block() const
>     {
> -      return this->data.mode == ir_var_uniform && this->interface_type != NULL;
> +      return (this->data.mode == ir_var_uniform ||
> +              this->data.mode == ir_var_buffer) && this->interface_type != NULL;
>     }
>  
>     /**
> diff --git a/src/glsl/ir_function.cpp b/src/glsl/ir_function.cpp
> index 2b2643c..d6f2167 100644
> --- a/src/glsl/ir_function.cpp
> +++ b/src/glsl/ir_function.cpp
> @@ -72,6 +72,7 @@ parameter_lists_match(_mesa_glsl_parse_state *state,
>        switch ((enum ir_variable_mode)(param->data.mode)) {
>        case ir_var_auto:
>        case ir_var_uniform:
> +      case ir_var_buffer:
>        case ir_var_temporary:
>          /* These are all error conditions.  It is invalid for a parameter to
>           * a function to be declared as auto (not in, out, or inout) or
> diff --git a/src/glsl/ir_print_visitor.cpp b/src/glsl/ir_print_visitor.cpp
> index 01f52e8..ce411f2 100644
> --- a/src/glsl/ir_print_visitor.cpp
> +++ b/src/glsl/ir_print_visitor.cpp
> @@ -164,7 +164,8 @@ void ir_print_visitor::visit(ir_variable *ir)
>     const char *const cent = (ir->data.centroid) ? "centroid " : "";
>     const char *const samp = (ir->data.sample) ? "sample " : "";
>     const char *const inv = (ir->data.invariant) ? "invariant " : "";
> -   const char *const mode[] = { "", "uniform ", "shader_in ", "shader_out ",
> +   const char *const mode[] = { "", "uniform ", "buffer",
> +                                "shader_in ", "shader_out ",
>                                  "in ", "out ", "inout ",
>                                 "const_in ", "sys ", "temporary " };
>     STATIC_ASSERT(ARRAY_SIZE(mode) == ir_var_mode_count);
> diff --git a/src/glsl/ir_reader.cpp b/src/glsl/ir_reader.cpp
> index fd318c0..ff62130 100644
> --- a/src/glsl/ir_reader.cpp
> +++ b/src/glsl/ir_reader.cpp
> @@ -418,6 +418,8 @@ ir_reader::read_declaration(s_expression *expr)
>          var->data.invariant = 1;
>        } else if (strcmp(qualifier->value(), "uniform") == 0) {
>          var->data.mode = ir_var_uniform;
> +      } else if (strcmp(qualifier->value(), "buffer") == 0) {
> +        var->data.mode = ir_var_buffer;
>        } else if (strcmp(qualifier->value(), "auto") == 0) {
>          var->data.mode = ir_var_auto;
>        } else if (strcmp(qualifier->value(), "in") == 0) {
> diff --git a/src/glsl/loop_unroll.cpp b/src/glsl/loop_unroll.cpp
> index 635e1dd..de70deb 100644
> --- a/src/glsl/loop_unroll.cpp
> +++ b/src/glsl/loop_unroll.cpp
> @@ -133,6 +133,7 @@ public:
>                    unsupported_variable_indexing = true;
>                 break;
>              case ir_var_uniform:
> +            case ir_var_buffer:
>                 if (options->EmitNoIndirectUniform)
>                    unsupported_variable_indexing = true;
>                 break;
> diff --git a/src/glsl/lower_named_interface_blocks.cpp b/src/glsl/lower_named_interface_blocks.cpp
> index 7304c51..72b4f4a 100644
> --- a/src/glsl/lower_named_interface_blocks.cpp
> +++ b/src/glsl/lower_named_interface_blocks.cpp
> @@ -108,7 +108,8 @@ flatten_named_interface_blocks_declarations::run(exec_list *instructions)
>         * but, this will require changes to the other uniform block
>         * support code.
>         */
> -      if (var->data.mode == ir_var_uniform)
> +      if (var->data.mode == ir_var_uniform ||
> +          var->data.mode == ir_var_buffer)
>           continue;
>  
>        const glsl_type * iface_t = var->type;
> @@ -212,7 +213,7 @@ flatten_named_interface_blocks_declarations::handle_rvalue(ir_rvalue **rvalue)
>      * but, this will require changes to the other uniform block
>      * support code.
>      */
> -   if (var->data.mode == ir_var_uniform)
> +   if (var->data.mode == ir_var_uniform || var->data.mode == ir_var_buffer)
>        return;
>  
>     if (var->get_interface_type() != NULL) {
> diff --git a/src/glsl/lower_variable_index_to_cond_assign.cpp b/src/glsl/lower_variable_index_to_cond_assign.cpp
> index d878cb0..80706a7 100644
> --- a/src/glsl/lower_variable_index_to_cond_assign.cpp
> +++ b/src/glsl/lower_variable_index_to_cond_assign.cpp
> @@ -370,6 +370,7 @@ public:
>        case ir_var_temporary:
>          return this->lower_temps;
>        case ir_var_uniform:
> +      case ir_var_buffer:
>          return this->lower_uniforms;
>        case ir_var_function_in:
>        case ir_var_const_in:
> diff --git a/src/glsl/opt_structure_splitting.cpp b/src/glsl/opt_structure_splitting.cpp
> index 5e82fe9..f85ab50 100644
> --- a/src/glsl/opt_structure_splitting.cpp
> +++ b/src/glsl/opt_structure_splitting.cpp
> @@ -103,8 +103,9 @@ ir_structure_reference_visitor::get_variable_entry(ir_variable *var)
>  {
>     assert(var);
>  
> -   if (!var->type->is_record() || var->data.mode == ir_var_uniform
> -       || var->data.mode == ir_var_shader_in || var->data.mode == ir_var_shader_out)
> +   if (!var->type->is_record() ||
> +       var->data.mode == ir_var_uniform || var->data.mode == ir_var_buffer ||
> +       var->data.mode == ir_var_shader_in || var->data.mode == ir_var_shader_out)
>        return NULL;
>  
>     foreach_in_list(variable_entry, entry, &this->variable_list) {
> -- 
> 1.9.1
> 
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list