glsl: add half float support to the parser

Acked-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18540>
This commit is contained in:
Timothy Arceri
2022-06-24 16:26:11 +10:00
committed by Marge Bot
parent 72fb49516e
commit edbe1b5bb4
4 changed files with 43 additions and 1 deletions

View File

@@ -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;

View File

@@ -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:

View File

@@ -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) {

View File

@@ -151,7 +151,7 @@ static bool match_layout_qualifier(const char *s1, const char *s2,
%token <identifier> IDENTIFIER TYPE_IDENTIFIER NEW_IDENTIFIER
%type <identifier> any_identifier
%type <interface_block> instance_name_opt
%token <real> FLOATCONSTANT
%token <real> FLOATCONSTANT FLOAT16CONSTANT
%token <dreal> DOUBLECONSTANT
%token <n> INTCONSTANT UINTCONSTANT BOOLCONSTANT
%token <n64> 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;