aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKristian H. Kristensen <[email protected]>2020-02-25 13:43:39 -0800
committerMarge Bot <[email protected]>2020-03-09 16:31:08 +0000
commit878a35db9dafa0cd8da19149d6f5c34e652a1459 (patch)
treec6400519be2d9e581acb6c45d2c4c12bf376477c /src
parent505428f20b082f04787630e6d0e5f4dfbce5efb7 (diff)
glsl: Expand fp16 to float before constant expression evaluation
This way the generated constant folding code doesn't need to understand fp16. All operations have to be expanded to full float for evaulation on the CPU, so we might as well do it up front. As far as GLSL is concerned, fp16 isn't a separate type from float, so everything we're supposed to support for float we need to do for fp16. Reviewed-by: Ian Romanick <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3929>
Diffstat (limited to 'src')
-rw-r--r--src/compiler/glsl/ir_constant_expression.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/compiler/glsl/ir_constant_expression.cpp b/src/compiler/glsl/ir_constant_expression.cpp
index 4b80282c266..cdb634bd328 100644
--- a/src/compiler/glsl/ir_constant_expression.cpp
+++ b/src/compiler/glsl/ir_constant_expression.cpp
@@ -692,6 +692,23 @@ ir_expression::constant_expression_value(void *mem_ctx,
return NULL;
}
+ for (unsigned operand = 0; operand < this->num_operands; operand++) {
+ if (op[operand]->type->base_type == GLSL_TYPE_FLOAT16) {
+ const struct glsl_type *float_type =
+ glsl_type::get_instance(GLSL_TYPE_FLOAT,
+ op[operand]->type->vector_elements,
+ op[operand]->type->matrix_columns,
+ op[operand]->type->explicit_stride,
+ op[operand]->type->interface_row_major);
+
+ ir_constant_data f;
+ for (unsigned i = 0; i < ARRAY_SIZE(f.f); i++)
+ f.f[i] = _mesa_half_to_float(op[operand]->value.f16[i]);
+
+ op[operand] = new(mem_ctx) ir_constant(float_type, &f);
+ }
+ }
+
if (op[1] != NULL)
switch (this->operation) {
case ir_binop_lshift:
@@ -740,6 +757,15 @@ ir_expression::constant_expression_value(void *mem_ctx,
#include "ir_expression_operation_constant.h"
+ if (this->type->base_type == GLSL_TYPE_FLOAT16) {
+ ir_constant_data f;
+ for (unsigned i = 0; i < ARRAY_SIZE(f.f16); i++)
+ f.f16[i] = _mesa_float_to_half(data.f[i]);
+
+ return new(mem_ctx) ir_constant(this->type, &f);
+ }
+
+
return new(mem_ctx) ir_constant(this->type, &data);
}