[Mesa-dev] [PATCH 22/46] glsl: add the patch in/out qualifier

Kenneth Graunke kenneth at whitecape.org
Fri Jun 19 03:40:24 PDT 2015


On Wednesday, June 17, 2015 01:01:18 AM Marek Olšák wrote:
> From: Fabian Bieler <fabianbieler at fastmail.fm>
> 
> ---
>  src/glsl/ast.h                            |  1 +
>  src/glsl/ast_to_hir.cpp                   | 45 ++++++++++++++++++++
>  src/glsl/ast_type.cpp                     |  3 +-
>  src/glsl/builtin_variables.cpp            |  8 ++--
>  src/glsl/glsl_lexer.ll                    |  2 +-
>  src/glsl/glsl_parser.yy                   | 15 ++++---
>  src/glsl/glsl_parser_extras.cpp           |  2 +
>  src/glsl/glsl_types.cpp                   |  5 +++
>  src/glsl/glsl_types.h                     |  6 +++
>  src/glsl/ir.cpp                           |  2 +
>  src/glsl/ir.h                             |  1 +
>  src/glsl/ir_print_visitor.cpp             |  5 ++-
>  src/glsl/ir_reader.cpp                    |  2 +
>  src/glsl/ir_set_program_inouts.cpp        | 69 +++++++++++++++++++++++++++----
>  src/glsl/link_varyings.cpp                | 15 ++++++-
>  src/glsl/lower_named_interface_blocks.cpp |  1 +
>  src/glsl/lower_packed_varyings.cpp        |  1 +
>  17 files changed, 161 insertions(+), 22 deletions(-)
> 
> diff --git a/src/glsl/ast.h b/src/glsl/ast.h
> index 26ad3bf..87e1354 100644
> --- a/src/glsl/ast.h
> +++ b/src/glsl/ast.h
> @@ -434,6 +434,7 @@ struct ast_type_qualifier {
>  	 unsigned out:1;
>  	 unsigned centroid:1;
>           unsigned sample:1;
> +	 unsigned patch:1;
>  	 unsigned uniform:1;
>  	 unsigned smooth:1;
>  	 unsigned flat:1;
> diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
> index 53daf13..837bac7 100644
> --- a/src/glsl/ast_to_hir.cpp
> +++ b/src/glsl/ast_to_hir.cpp
> @@ -2461,6 +2461,9 @@ apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual,
>        var->data.stream = qual->stream;
>     }
>  
> +   if (qual->flags.q.patch)
> +      var->data.patch = 1;
> +
>     if (qual->flags.q.attribute && state->stage != MESA_SHADER_VERTEX) {
>        var->type = glsl_type::error_type;
>        _mesa_glsl_error(loc, state,
> @@ -3119,6 +3122,17 @@ handle_tess_ctrl_shader_output_decl(struct _mesa_glsl_parse_state *state,
>        num_vertices = state->out_qualifier->vertices;
>     }
>  
> +   if (!var->type->is_array() && !var->data.patch) {
> +      _mesa_glsl_error(&loc, state,
> +                       "tessellation control shader outputs must be arrays");
> +
> +      /* To avoid cascading failures, short circuit the checks below. */
> +      return;
> +   }

Seems like this block should have gone in patch 20 and just the
!var->data.patch part added here.  But it's already a huge patch, so I
suppose it doesn't matter so much...

> +
> +   if (var->data.patch)
> +      return;
> +
>     if (var->type->is_unsized_array()) {
>        if (num_vertices != 0)
>           var->type = glsl_type::get_array_instance(var->type->fields.array,
> @@ -3940,6 +3954,33 @@ ast_declarator_list::hir(exec_list *instructions,
>        }
>  
>  
> +      /* From section 4.3.4 of the GLSL 4.00 spec:
> +       *    "Input variables may not be declared using the patch in qualifier
> +       *    in tessellation control or geometry shaders."
> +       *
> +       * From section 4.3.6 of the GLSL 4.00 spec:
> +       *    "It is an error to use patch out in a vertex, tessellation
> +       *    evaluation, or geometry shader."
> +       *
> +       * This doesn't explicitly forbid using them in a fragment shader, but
> +       * that's probably just an oversight.
> +       */
> +      if (state->stage != MESA_SHADER_TESS_EVAL
> +          && this->type->qualifier.flags.q.patch
> +          && this->type->qualifier.flags.q.in) {
> +
> +         _mesa_glsl_error(&loc, state, "'patch in' can only be used in a "
> +                          "tessellation evaluation shader");
> +      }
> +
> +      if (state->stage != MESA_SHADER_TESS_CTRL
> +          && this->type->qualifier.flags.q.patch
> +          && this->type->qualifier.flags.q.out) {
> +
> +         _mesa_glsl_error(&loc, state, "'patch out' can only be used in a "
> +                          "tessellation control shader");
> +      }
> +
>        /* Precision qualifiers exists only in GLSL versions 1.00 and >= 1.30.
>         */
>        if (this->type->qualifier.precision != ast_precision_none) {
> @@ -5463,6 +5504,7 @@ ast_process_structure_or_interface_block(exec_list *instructions,
>              interpret_interpolation_qualifier(qual, var_mode, state, &loc);
>           fields[i].centroid = qual->flags.q.centroid ? 1 : 0;
>           fields[i].sample = qual->flags.q.sample ? 1 : 0;
> +         fields[i].patch = qual->flags.q.patch ? 1 : 0;
>  
>           /* Only save explicitly defined streams in block's field */
>           fields[i].stream = qual->flags.q.explicit_stream ? qual->stream : -1;
> @@ -5794,6 +5836,8 @@ ast_interface_block::hir(exec_list *instructions,
>                 earlier_per_vertex->fields.structure[j].centroid;
>              fields[i].sample =
>                 earlier_per_vertex->fields.structure[j].sample;
> +            fields[i].patch =
> +               earlier_per_vertex->fields.structure[j].patch;
>           }
>        }
>  
> @@ -5973,6 +6017,7 @@ ast_interface_block::hir(exec_list *instructions,
>           var->data.interpolation = fields[i].interpolation;
>           var->data.centroid = fields[i].centroid;
>           var->data.sample = fields[i].sample;
> +         var->data.patch = fields[i].patch;
>           var->init_interface_type(block_type);
>  
>           if (var_mode == ir_var_shader_in || var_mode == ir_var_uniform)
> diff --git a/src/glsl/ast_type.cpp b/src/glsl/ast_type.cpp
> index 5bebaab..0d3651d 100644
> --- a/src/glsl/ast_type.cpp
> +++ b/src/glsl/ast_type.cpp
> @@ -85,7 +85,8 @@ bool
>  ast_type_qualifier::has_auxiliary_storage() const
>  {
>     return this->flags.q.centroid
> -          || this->flags.q.sample;
> +          || this->flags.q.sample
> +          || this->flags.q.patch;
>  }
>  
>  const char*
> diff --git a/src/glsl/builtin_variables.cpp b/src/glsl/builtin_variables.cpp
> index bb947a8..874cb10 100644
> --- a/src/glsl/builtin_variables.cpp
> +++ b/src/glsl/builtin_variables.cpp
> @@ -881,10 +881,10 @@ builtin_variable_generator::generate_tcs_special_vars()
>     add_system_value(SYSTEM_VALUE_VERTICES_IN, int_t, "gl_PatchVerticesIn");
>     add_system_value(SYSTEM_VALUE_INVOCATION_ID, int_t, "gl_InvocationID");
>  
> -   add_output(VARYING_SLOT_TESS_LEVEL_OUTER,
> -                    array(float_t, 4), "gl_TessLevelOuter");
> -   add_output(VARYING_SLOT_TESS_LEVEL_INNER,
> -                    array(float_t, 2), "gl_TessLevelInner");
> +   add_output(VARYING_SLOT_TESS_LEVEL_OUTER, array(float_t, 4),
> +              "gl_TessLevelOuter")->data.patch = 1;
> +   add_output(VARYING_SLOT_TESS_LEVEL_INNER, array(float_t, 2),
> +              "gl_TessLevelInner")->data.patch = 1;
>  }
>  
>  
> diff --git a/src/glsl/glsl_lexer.ll b/src/glsl/glsl_lexer.ll
> index 10db5b8..68f1989 100644
> --- a/src/glsl/glsl_lexer.ll
> +++ b/src/glsl/glsl_lexer.ll
> @@ -314,6 +314,7 @@ invariant	KEYWORD(120, 100, 120, 100, INVARIANT);
>  flat		KEYWORD(130, 100, 130, 300, FLAT);
>  smooth		KEYWORD(130, 300, 130, 300, SMOOTH);
>  noperspective	KEYWORD(130, 300, 130, 0, NOPERSPECTIVE);
> +patch		KEYWORD_WITH_ALT(0, 300, 400, 0, yyextra->ARB_tessellation_shader_enable, PATCH);
>  
>  sampler1D	DEPRECATED_ES_KEYWORD(SAMPLER1D);
>  sampler2D	return SAMPLER2D;
> @@ -575,7 +576,6 @@ usamplerBuffer	KEYWORD(140, 300, 140, 0, USAMPLERBUFFER);
>  
>      /* Additional reserved words in GLSL ES 3.00 */
>  resource	KEYWORD(0, 300, 0, 0, RESOURCE);
> -patch		KEYWORD(0, 300, 0, 0, PATCH);
>  sample		KEYWORD_WITH_ALT(400, 300, 400, 0, yyextra->ARB_gpu_shader5_enable, SAMPLE);
>  subroutine	KEYWORD(0, 300, 0, 0, SUBROUTINE);
>  
> diff --git a/src/glsl/glsl_parser.yy b/src/glsl/glsl_parser.yy
> index eaf0dd6..716d43b 100644
> --- a/src/glsl/glsl_parser.yy
> +++ b/src/glsl/glsl_parser.yy
> @@ -136,8 +136,9 @@ static bool match_layout_qualifier(const char *s1, const char *s2,
>  %token ATTRIBUTE CONST_TOK BOOL_TOK FLOAT_TOK INT_TOK UINT_TOK DOUBLE_TOK
>  %token BREAK CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT
>  %token BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 UVEC2 UVEC3 UVEC4 VEC2 VEC3 VEC4 DVEC2 DVEC3 DVEC4
> -%token CENTROID IN_TOK OUT_TOK INOUT_TOK UNIFORM VARYING SAMPLE
> +%token CENTROID IN_TOK OUT_TOK INOUT_TOK UNIFORM VARYING PATCH SAMPLE
>  %token NOPERSPECTIVE FLAT SMOOTH
> +%token ROW_MAJOR PACKED_TOK

A couple of the changes here look like unrelated reordering...this line

>  %token MAT2X2 MAT2X3 MAT2X4
>  %token MAT3X2 MAT3X3 MAT3X4
>  %token MAT4X2 MAT4X3 MAT4X4
> @@ -189,18 +190,18 @@ static bool match_layout_qualifier(const char *s1, const char *s2,
>  
>     /* Reserved words that are not actually used in the grammar.
>      */
> -%token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS PACKED_TOK GOTO
> +%token ASM CLASS UNION ENUM TYPEDEF TEMPLATE THIS GOTO

and this line

>  %token INLINE_TOK NOINLINE PUBLIC_TOK STATIC EXTERN EXTERNAL
>  %token LONG_TOK SHORT_TOK HALF FIXED_TOK UNSIGNED INPUT_TOK
>  %token HVEC2 HVEC3 HVEC4 FVEC2 FVEC3 FVEC4
>  %token SAMPLER3DRECT
>  %token SIZEOF CAST NAMESPACE USING
> -%token RESOURCE PATCH
> +%token RESOURCE
>  %token SUBROUTINE
>  
>  %token ERROR_TOK
>  
> -%token COMMON PARTITION ACTIVE FILTER ROW_MAJOR
> +%token COMMON PARTITION ACTIVE FILTER

and this line...could probably all be dropped.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20150619/a2a26c8e/attachment.sig>


More information about the mesa-dev mailing list