glsl: fix constant expression evaluation for 16-bit types
authorMarek Olšák <marek.olsak@amd.com>
Thu, 23 Jul 2020 01:31:10 +0000 (21:31 -0400)
committerMarge Bot <eric+marge@anholt.net>
Wed, 5 Aug 2020 22:04:47 +0000 (22:04 +0000)
Reviewed-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6073>

src/compiler/glsl/ir_constant_expression.cpp
src/compiler/glsl/ir_expression_operation.py

index 855b7884fb76754bbe21eefbefd010297c644afc..47049d0202b5e4ffa8e6275a62b6e30fb28b60ce 100644 (file)
@@ -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:
index 1c4e6b358e161cd7238e0ab47b7ebf1c573f52a8..0d8d7a6f9eddfddb61ed4a2da6d29ca3cba8b434 100644 (file)
@@ -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)};