From 3439956377f903ed7e673f020cd9e7dc0a980128 Mon Sep 17 00:00:00 2001 From: Caio Marcelo de Oliveira Filho Date: Fri, 20 Sep 2019 09:34:19 -0700 Subject: [PATCH] glsl: Parse `demote` statement When the EXT_demote_to_helper_invocation extension is enabled, `demote` is treated as a keyword, and produces an ir_demote. Reviewed-by: Kenneth Graunke --- src/compiler/glsl/ast.h | 10 ++++++++++ src/compiler/glsl/ast_to_hir.cpp | 19 +++++++++++++++++++ src/compiler/glsl/glsl_lexer.ll | 1 + src/compiler/glsl/glsl_parser.yy | 13 ++++++++++++- src/compiler/glsl/glsl_parser_extras.cpp | 7 +++++++ 5 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/compiler/glsl/ast.h b/src/compiler/glsl/ast.h index 90a3565..f07a14b 100644 --- a/src/compiler/glsl/ast.h +++ b/src/compiler/glsl/ast.h @@ -1213,6 +1213,16 @@ public: }; +class ast_demote_statement : public ast_node { +public: + ast_demote_statement(void) {} + virtual void print(void) const; + + virtual ir_rvalue *hir(exec_list *instructions, + struct _mesa_glsl_parse_state *state); +}; + + class ast_function_definition : public ast_node { public: ast_function_definition() : prototype(NULL), body(NULL) diff --git a/src/compiler/glsl/ast_to_hir.cpp b/src/compiler/glsl/ast_to_hir.cpp index 194d309..214412b 100644 --- a/src/compiler/glsl/ast_to_hir.cpp +++ b/src/compiler/glsl/ast_to_hir.cpp @@ -6465,6 +6465,25 @@ ast_jump_statement::hir(exec_list *instructions, ir_rvalue * +ast_demote_statement::hir(exec_list *instructions, + struct _mesa_glsl_parse_state *state) +{ + void *ctx = state; + + if (state->stage != MESA_SHADER_FRAGMENT) { + YYLTYPE loc = this->get_location(); + + _mesa_glsl_error(& loc, state, + "`demote' may only appear in a fragment shader"); + } + + instructions->push_tail(new(ctx) ir_demote); + + return NULL; +} + + +ir_rvalue * ast_selection_statement::hir(exec_list *instructions, struct _mesa_glsl_parse_state *state) { diff --git a/src/compiler/glsl/glsl_lexer.ll b/src/compiler/glsl/glsl_lexer.ll index b17f9c0..43bd2b2 100644 --- a/src/compiler/glsl/glsl_lexer.ll +++ b/src/compiler/glsl/glsl_lexer.ll @@ -356,6 +356,7 @@ for return FOR; if return IF; discard return DISCARD; return return RETURN; +demote KEYWORD_WITH_ALT(0, 0, 0, 0, yyextra->EXT_demote_to_helper_invocation_enable, DEMOTE); bvec2 { yylval->type = glsl_type::bvec2_type; return BASIC_TYPE_TOK; } bvec3 { yylval->type = glsl_type::bvec3_type; return BASIC_TYPE_TOK; } diff --git a/src/compiler/glsl/glsl_parser.yy b/src/compiler/glsl/glsl_parser.yy index d2d8716..edf421d 100644 --- a/src/compiler/glsl/glsl_parser.yy +++ b/src/compiler/glsl/glsl_parser.yy @@ -139,7 +139,7 @@ static bool match_layout_qualifier(const char *s1, const char *s2, %token ATTRIBUTE CONST_TOK %token BASIC_TYPE_TOK -%token BREAK BUFFER CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT +%token BREAK BUFFER CONTINUE DO ELSE FOR IF DEMOTE DISCARD RETURN SWITCH CASE DEFAULT %token CENTROID IN_TOK OUT_TOK INOUT_TOK UNIFORM VARYING SAMPLE %token NOPERSPECTIVE FLAT SMOOTH %token IMAGE1DSHADOW IMAGE2DSHADOW IMAGE1DARRAYSHADOW IMAGE2DARRAYSHADOW @@ -256,6 +256,7 @@ static bool match_layout_qualifier(const char *s1, const char *s2, %type declaration %type declaration_statement %type jump_statement +%type demote_statement %type interface_block %type basic_interface_block %type struct_specifier @@ -2510,6 +2511,7 @@ simple_statement: | switch_statement | iteration_statement | jump_statement + | demote_statement ; compound_statement: @@ -2808,6 +2810,15 @@ jump_statement: } ; +demote_statement: + DEMOTE ';' + { + void *ctx = state->linalloc; + $$ = new(ctx) ast_demote_statement(); + $$->set_location(@1); + } + ; + external_declaration: function_definition { $$ = $1; } | declaration { $$ = $1; } diff --git a/src/compiler/glsl/glsl_parser_extras.cpp b/src/compiler/glsl/glsl_parser_extras.cpp index d16f96f..3d1a31e 100644 --- a/src/compiler/glsl/glsl_parser_extras.cpp +++ b/src/compiler/glsl/glsl_parser_extras.cpp @@ -1513,6 +1513,13 @@ ast_jump_statement::ast_jump_statement(int mode, ast_expression *return_value) void +ast_demote_statement::print(void) const +{ + printf("demote; "); +} + + +void ast_selection_statement::print(void) const { printf("if ( "); -- 2.7.4