From: Marek Olšák Date: Thu, 23 Jul 2020 01:31:10 +0000 (-0400) Subject: glsl: fix constant expression evaluation for 16-bit types X-Git-Url: https://git.libre-soc.org/?p=mesa.git;a=commitdiff_plain;h=48a6255186d65d39d56b6a0d46067f70a4fdc13d glsl: fix constant expression evaluation for 16-bit types Reviewed-by: Rob Clark Part-of: --- diff --git a/src/compiler/glsl/ir_constant_expression.cpp b/src/compiler/glsl/ir_constant_expression.cpp index 855b7884fb7..47049d0202b 100644 --- a/src/compiler/glsl/ir_constant_expression.cpp +++ b/src/compiler/glsl/ir_constant_expression.cpp @@ -694,6 +694,7 @@ ir_expression::constant_expression_value(void *mem_ctx, if (this->type->is_error()) return NULL; + const glsl_type *return_type = this->type; ir_constant *op[ARRAY_SIZE(this->operands)] = { NULL, }; ir_constant_data data; @@ -760,6 +761,33 @@ ir_expression::constant_expression_value(void *mem_ctx, } } + switch (return_type->base_type) { + case GLSL_TYPE_FLOAT16: + return_type = glsl_type::get_instance(GLSL_TYPE_FLOAT, + return_type->vector_elements, + return_type->matrix_columns, + return_type->explicit_stride, + return_type->interface_row_major); + break; + case GLSL_TYPE_INT16: + return_type = glsl_type::get_instance(GLSL_TYPE_INT, + return_type->vector_elements, + return_type->matrix_columns, + return_type->explicit_stride, + return_type->interface_row_major); + break; + case GLSL_TYPE_UINT16: + return_type = glsl_type::get_instance(GLSL_TYPE_UINT, + return_type->vector_elements, + return_type->matrix_columns, + return_type->explicit_stride, + return_type->interface_row_major); + break; + default: + /* nothing to do */ + break; + } + if (op[1] != NULL) switch (this->operation) { case ir_binop_lshift: diff --git a/src/compiler/glsl/ir_expression_operation.py b/src/compiler/glsl/ir_expression_operation.py index 1c4e6b358e1..0d8d7a6f9ed 100644 --- a/src/compiler/glsl/ir_expression_operation.py +++ b/src/compiler/glsl/ir_expression_operation.py @@ -247,7 +247,7 @@ constant_template_vector_insert = mako.template.Template("""\ memcpy(&data, &op[0]->value, sizeof(data)); - switch (this->type->base_type) { + switch (return_type->base_type) { % for dst_type, src_types in op.signatures(): case ${src_types[0].glsl_type}: data.${dst_type.union_field}[idx] = op[1]->value.${src_types[0].union_field}[0]; @@ -262,8 +262,8 @@ constant_template_vector_insert = mako.template.Template("""\ # This template is for ir_quadop_vector. constant_template_vector = mako.template.Template("""\ case ${op.get_enum_name()}: - for (unsigned c = 0; c < this->type->vector_elements; c++) { - switch (this->type->base_type) { + for (unsigned c = 0; c < return_type->vector_elements; c++) { + switch (return_type->base_type) { % for dst_type, src_types in op.signatures(): case ${src_types[0].glsl_type}: data.${dst_type.union_field}[c] = op[c]->value.${src_types[0].union_field}[0]; @@ -284,7 +284,7 @@ constant_template_lrp = mako.template.Template("""\ unsigned c2_inc = op[2]->type->is_scalar() ? 0 : 1; for (unsigned c = 0, c2 = 0; c < components; c2 += c2_inc, c++) { - switch (this->type->base_type) { + switch (return_type->base_type) { % for dst_type, src_types in op.signatures(): case ${src_types[0].glsl_type}: data.${dst_type.union_field}[c] = ${op.get_c_expression(src_types, ("c", "c", "c2"))}; @@ -303,7 +303,7 @@ constant_template_lrp = mako.template.Template("""\ constant_template_csel = mako.template.Template("""\ case ${op.get_enum_name()}: for (unsigned c = 0; c < components; c++) { - switch (this->type->base_type) { + switch (return_type->base_type) { % for dst_type, src_types in op.signatures(): case ${src_types[1].glsl_type}: data.${dst_type.union_field}[c] = ${op.get_c_expression(src_types)};