diff --git a/src/compiler/glsl/ast.h b/src/compiler/glsl/ast.h index 7be83da9ada..6450fed9ff6 100644 --- a/src/compiler/glsl/ast.h +++ b/src/compiler/glsl/ast.h @@ -197,6 +197,7 @@ enum ast_operators { ast_identifier, ast_int_constant, ast_uint_constant, + ast_float16_constant, ast_float_constant, ast_bool_constant, ast_double_constant, @@ -258,6 +259,7 @@ public: union { const char *identifier; int int_constant; + float float16_constant; float float_constant; unsigned uint_constant; int bool_constant; diff --git a/src/compiler/glsl/ast_to_hir.cpp b/src/compiler/glsl/ast_to_hir.cpp index 8b5cdd5cb35..0c59c2b6710 100644 --- a/src/compiler/glsl/ast_to_hir.cpp +++ b/src/compiler/glsl/ast_to_hir.cpp @@ -2113,6 +2113,10 @@ ast_expression::do_hir(exec_list *instructions, result = new(ctx) ir_constant(this->primary_expression.uint_constant); break; + case ast_float16_constant: + result = new(ctx) ir_constant(float16_t(this->primary_expression.float16_constant)); + break; + case ast_float_constant: result = new(ctx) ir_constant(this->primary_expression.float_constant); break; @@ -2256,6 +2260,7 @@ ast_expression::has_sequence_subexpression() const case ast_identifier: case ast_int_constant: case ast_uint_constant: + case ast_float16_constant: case ast_float_constant: case ast_bool_constant: case ast_double_constant: diff --git a/src/compiler/glsl/glsl_lexer.ll b/src/compiler/glsl/glsl_lexer.ll index b8d6b4bb1ba..611b3643a53 100644 --- a/src/compiler/glsl/glsl_lexer.ll +++ b/src/compiler/glsl/glsl_lexer.ll @@ -609,6 +609,16 @@ layout { return LITERAL_INTEGER(8); } +[0-9]+\.[0-9]+([eE][+-]?[0-9]+)?(hf|HF) | +\.[0-9]+([eE][+-]?[0-9]+)?(hf|HF) | +[0-9]+\.([eE][+-]?[0-9]+)?(hf|HF) | +[0-9]+[eE][+-]?[0-9]+(hf|HF) { + if (!yyextra->AMD_gpu_shader_half_float_enable) + return ERROR_TOK; + yylval->dreal = _mesa_strtod(yytext, NULL); + return FLOAT16CONSTANT; + } + [0-9]+\.[0-9]+([eE][+-]?[0-9]+)?[fF]? | \.[0-9]+([eE][+-]?[0-9]+)?[fF]? | [0-9]+\.([eE][+-]?[0-9]+)?[fF]? | @@ -739,6 +749,24 @@ u64vec2 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable || yyext u64vec3 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable || yyextra->AMD_gpu_shader_int64_enable, &glsl_type_builtin_u64vec3); u64vec4 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->ARB_gpu_shader_int64_enable || yyextra->AMD_gpu_shader_int64_enable, &glsl_type_builtin_u64vec4); + /* Additional words for AMD_gpu_shader_half_float */ +float16_t TYPE_WITH_ALT(0, 0, 0, 0, yyextra->AMD_gpu_shader_half_float_enable, &glsl_type_builtin_float16_t); +f16vec2 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->AMD_gpu_shader_half_float_enable, &glsl_type_builtin_f16vec2); +f16vec3 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->AMD_gpu_shader_half_float_enable, &glsl_type_builtin_f16vec3); +f16vec4 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->AMD_gpu_shader_half_float_enable, &glsl_type_builtin_f16vec4); +f16mat2 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->AMD_gpu_shader_half_float_enable, &glsl_type_builtin_f16mat2); +f16mat3 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->AMD_gpu_shader_half_float_enable, &glsl_type_builtin_f16mat3); +f16mat4 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->AMD_gpu_shader_half_float_enable, &glsl_type_builtin_f16mat4); +f16mat2x2 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->AMD_gpu_shader_half_float_enable, &glsl_type_builtin_f16mat2); +f16mat2x3 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->AMD_gpu_shader_half_float_enable, &glsl_type_builtin_f16mat2x3); +f16mat2x4 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->AMD_gpu_shader_half_float_enable, &glsl_type_builtin_f16mat2x4); +f16mat3x2 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->AMD_gpu_shader_half_float_enable, &glsl_type_builtin_f16mat3x2); +f16mat3x3 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->AMD_gpu_shader_half_float_enable, &glsl_type_builtin_f16mat3); +f16mat3x4 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->AMD_gpu_shader_half_float_enable, &glsl_type_builtin_f16mat3x4); +f16mat4x2 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->AMD_gpu_shader_half_float_enable, &glsl_type_builtin_f16mat4x2); +f16mat4x3 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->AMD_gpu_shader_half_float_enable, &glsl_type_builtin_f16mat4x3); +f16mat4x4 TYPE_WITH_ALT(0, 0, 0, 0, yyextra->AMD_gpu_shader_half_float_enable, &glsl_type_builtin_f16mat4); + [_a-zA-Z][_a-zA-Z0-9]* { struct _mesa_glsl_parse_state *state = yyextra; if (state->es_shader && yyleng > 1024) { diff --git a/src/compiler/glsl/glsl_parser.yy b/src/compiler/glsl/glsl_parser.yy index 8c0535f4a9d..aae60ef50bd 100644 --- a/src/compiler/glsl/glsl_parser.yy +++ b/src/compiler/glsl/glsl_parser.yy @@ -151,7 +151,7 @@ static bool match_layout_qualifier(const char *s1, const char *s2, %token IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER %type any_identifier %type instance_name_opt -%token FLOATCONSTANT +%token FLOATCONSTANT FLOAT16CONSTANT %token DOUBLECONSTANT %token INTCONSTANT UINTCONSTANT BOOLCONSTANT %token INT64CONSTANT UINT64CONSTANT @@ -462,6 +462,13 @@ primary_expression: $$->set_location(@1); $$->primary_expression.uint64_constant = $1; } + | FLOAT16CONSTANT + { + linear_ctx *ctx = state->linalloc; + $$ = new(ctx) ast_expression(ast_float16_constant, NULL, NULL, NULL); + $$->set_location(@1); + $$->primary_expression.float16_constant = $1; + } | FLOATCONSTANT { linear_ctx *ctx = state->linalloc;