glsl: fix constant expression evaluation for 16-bit types
Reviewed-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6073>
diff --git a/src/compiler/glsl/ir_constant_expression.cpp b/src/compiler/glsl/ir_constant_expression.cpp
index 855b788..47049d0 100644
--- a/src/compiler/glsl/ir_constant_expression.cpp
+++ b/src/compiler/glsl/ir_constant_expression.cpp
@@ -694,6 +694,7 @@
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 @@
}
}
+ 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 1c4e6b3..0d8d7a6 100644
--- a/src/compiler/glsl/ir_expression_operation.py
+++ b/src/compiler/glsl/ir_expression_operation.py
@@ -247,7 +247,7 @@
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 @@
# 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 @@
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_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)};