aboutsummaryrefslogtreecommitdiffstats
path: root/src/compiler/glsl/ir.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/compiler/glsl/ir.cpp')
-rw-r--r--src/compiler/glsl/ir.cpp57
1 files changed, 54 insertions, 3 deletions
diff --git a/src/compiler/glsl/ir.cpp b/src/compiler/glsl/ir.cpp
index 57551850757..d9bc83501cd 100644
--- a/src/compiler/glsl/ir.cpp
+++ b/src/compiler/glsl/ir.cpp
@@ -22,6 +22,7 @@
*/
#include <string.h>
#include "ir.h"
+#include "util/half_float.h"
#include "compiler/glsl_types.h"
#include "glsl_parser_extras.h"
@@ -796,6 +797,7 @@ ir_constant::ir_constant(const ir_constant *c, unsigned i)
case GLSL_TYPE_UINT: this->value.u[0] = c->value.u[i]; break;
case GLSL_TYPE_INT: this->value.i[0] = c->value.i[i]; break;
case GLSL_TYPE_FLOAT: this->value.f[0] = c->value.f[i]; break;
+ case GLSL_TYPE_FLOAT16: this->value.f16[0] = c->value.f16[i]; break;
case GLSL_TYPE_BOOL: this->value.b[0] = c->value.b[i]; break;
case GLSL_TYPE_DOUBLE: this->value.d[0] = c->value.d[i]; break;
default: assert(!"Should not get here."); break;
@@ -841,14 +843,23 @@ ir_constant::ir_constant(const struct glsl_type *type, exec_list *value_list)
if (value->type->is_scalar() && value->next->is_tail_sentinel()) {
if (type->is_matrix()) {
/* Matrix - fill diagonal (rest is already set to 0) */
- assert(type->is_float() || type->is_double());
for (unsigned i = 0; i < type->matrix_columns; i++) {
- if (type->is_float())
+ switch (type->base_type) {
+ case GLSL_TYPE_FLOAT:
this->value.f[i * type->vector_elements + i] =
value->value.f[0];
- else
+ break;
+ case GLSL_TYPE_DOUBLE:
this->value.d[i * type->vector_elements + i] =
value->value.d[0];
+ break;
+ case GLSL_TYPE_FLOAT16:
+ this->value.f16[i * type->vector_elements + i] =
+ value->value.f16[0];
+ break;
+ default:
+ assert(!"unexpected matrix base type");
+ }
}
} else {
/* Vector or scalar - fill all components */
@@ -862,6 +873,10 @@ ir_constant::ir_constant(const struct glsl_type *type, exec_list *value_list)
for (unsigned i = 0; i < type->components(); i++)
this->value.f[i] = value->value.f[0];
break;
+ case GLSL_TYPE_FLOAT16:
+ for (unsigned i = 0; i < type->components(); i++)
+ this->value.f16[i] = value->value.f16[0];
+ break;
case GLSL_TYPE_DOUBLE:
for (unsigned i = 0; i < type->components(); i++)
this->value.d[i] = value->value.d[0];
@@ -931,6 +946,9 @@ ir_constant::ir_constant(const struct glsl_type *type, exec_list *value_list)
case GLSL_TYPE_FLOAT:
this->value.f[i] = value->get_float_component(j);
break;
+ case GLSL_TYPE_FLOAT16:
+ this->value.f16[i] = value->get_float16_component(j);
+ break;
case GLSL_TYPE_BOOL:
this->value.b[i] = value->get_bool_component(j);
break;
@@ -996,6 +1014,7 @@ ir_constant::get_bool_component(unsigned i) const
case GLSL_TYPE_UINT: return this->value.u[i] != 0;
case GLSL_TYPE_INT: return this->value.i[i] != 0;
case GLSL_TYPE_FLOAT: return ((int)this->value.f[i]) != 0;
+ case GLSL_TYPE_FLOAT16: return ((int)_mesa_half_to_float(this->value.f16[i])) != 0;
case GLSL_TYPE_BOOL: return this->value.b[i];
case GLSL_TYPE_DOUBLE: return this->value.d[i] != 0.0;
case GLSL_TYPE_SAMPLER:
@@ -1018,6 +1037,7 @@ ir_constant::get_float_component(unsigned i) const
case GLSL_TYPE_UINT: return (float) this->value.u[i];
case GLSL_TYPE_INT: return (float) this->value.i[i];
case GLSL_TYPE_FLOAT: return this->value.f[i];
+ case GLSL_TYPE_FLOAT16: return _mesa_half_to_float(this->value.f16[i]);
case GLSL_TYPE_BOOL: return this->value.b[i] ? 1.0f : 0.0f;
case GLSL_TYPE_DOUBLE: return (float) this->value.d[i];
case GLSL_TYPE_SAMPLER:
@@ -1033,6 +1053,15 @@ ir_constant::get_float_component(unsigned i) const
return 0.0;
}
+uint16_t
+ir_constant::get_float16_component(unsigned i) const
+{
+ if (this->type->base_type == GLSL_TYPE_FLOAT16)
+ return this->value.f16[i];
+ else
+ return _mesa_float_to_half(get_float_component(i));
+}
+
double
ir_constant::get_double_component(unsigned i) const
{
@@ -1040,6 +1069,7 @@ ir_constant::get_double_component(unsigned i) const
case GLSL_TYPE_UINT: return (double) this->value.u[i];
case GLSL_TYPE_INT: return (double) this->value.i[i];
case GLSL_TYPE_FLOAT: return (double) this->value.f[i];
+ case GLSL_TYPE_FLOAT16: return (double) _mesa_half_to_float(this->value.f16[i]);
case GLSL_TYPE_BOOL: return this->value.b[i] ? 1.0 : 0.0;
case GLSL_TYPE_DOUBLE: return this->value.d[i];
case GLSL_TYPE_SAMPLER:
@@ -1062,6 +1092,7 @@ ir_constant::get_int_component(unsigned i) const
case GLSL_TYPE_UINT: return this->value.u[i];
case GLSL_TYPE_INT: return this->value.i[i];
case GLSL_TYPE_FLOAT: return (int) this->value.f[i];
+ case GLSL_TYPE_FLOAT16: return (int) _mesa_half_to_float(this->value.f16[i]);
case GLSL_TYPE_BOOL: return this->value.b[i] ? 1 : 0;
case GLSL_TYPE_DOUBLE: return (int) this->value.d[i];
case GLSL_TYPE_SAMPLER:
@@ -1084,6 +1115,7 @@ ir_constant::get_uint_component(unsigned i) const
case GLSL_TYPE_UINT: return this->value.u[i];
case GLSL_TYPE_INT: return this->value.i[i];
case GLSL_TYPE_FLOAT: return (unsigned) this->value.f[i];
+ case GLSL_TYPE_FLOAT16: return (unsigned) _mesa_half_to_float(this->value.f16[i]);
case GLSL_TYPE_BOOL: return this->value.b[i] ? 1 : 0;
case GLSL_TYPE_DOUBLE: return (unsigned) this->value.d[i];
case GLSL_TYPE_SAMPLER:
@@ -1106,6 +1138,7 @@ ir_constant::get_int64_component(unsigned i) const
case GLSL_TYPE_UINT: return this->value.u[i];
case GLSL_TYPE_INT: return this->value.i[i];
case GLSL_TYPE_FLOAT: return (int64_t) this->value.f[i];
+ case GLSL_TYPE_FLOAT16: return (int64_t) _mesa_half_to_float(this->value.f16[i]);
case GLSL_TYPE_BOOL: return this->value.b[i] ? 1 : 0;
case GLSL_TYPE_DOUBLE: return (int64_t) this->value.d[i];
case GLSL_TYPE_SAMPLER:
@@ -1128,6 +1161,7 @@ ir_constant::get_uint64_component(unsigned i) const
case GLSL_TYPE_UINT: return this->value.u[i];
case GLSL_TYPE_INT: return this->value.i[i];
case GLSL_TYPE_FLOAT: return (uint64_t) this->value.f[i];
+ case GLSL_TYPE_FLOAT16: return (uint64_t) _mesa_half_to_float(this->value.f16[i]);
case GLSL_TYPE_BOOL: return this->value.b[i] ? 1 : 0;
case GLSL_TYPE_DOUBLE: return (uint64_t) this->value.d[i];
case GLSL_TYPE_SAMPLER:
@@ -1182,6 +1216,7 @@ ir_constant::copy_offset(ir_constant *src, int offset)
case GLSL_TYPE_UINT:
case GLSL_TYPE_INT:
case GLSL_TYPE_FLOAT:
+ case GLSL_TYPE_FLOAT16:
case GLSL_TYPE_DOUBLE:
case GLSL_TYPE_SAMPLER:
case GLSL_TYPE_IMAGE:
@@ -1201,6 +1236,9 @@ ir_constant::copy_offset(ir_constant *src, int offset)
case GLSL_TYPE_FLOAT:
value.f[i+offset] = src->get_float_component(i);
break;
+ case GLSL_TYPE_FLOAT16:
+ value.f16[i+offset] = src->get_float16_component(i);
+ break;
case GLSL_TYPE_BOOL:
value.b[i+offset] = src->get_bool_component(i);
break;
@@ -1260,6 +1298,9 @@ ir_constant::copy_masked_offset(ir_constant *src, int offset, unsigned int mask)
case GLSL_TYPE_FLOAT:
value.f[i+offset] = src->get_float_component(id++);
break;
+ case GLSL_TYPE_FLOAT16:
+ value.f16[i+offset] = src->get_float16_component(id++);
+ break;
case GLSL_TYPE_BOOL:
value.b[i+offset] = src->get_bool_component(id++);
break;
@@ -1310,6 +1351,12 @@ ir_constant::has_value(const ir_constant *c) const
if (this->value.f[i] != c->value.f[i])
return false;
break;
+ case GLSL_TYPE_FLOAT16:
+ /* Convert to float to make sure NaN and ±0.0 compares correctly */
+ if (_mesa_half_to_float(this->value.f16[i]) !=
+ _mesa_half_to_float(c->value.f16[i]))
+ return false;
+ break;
case GLSL_TYPE_BOOL:
if (this->value.b[i] != c->value.b[i])
return false;
@@ -1353,6 +1400,10 @@ ir_constant::is_value(float f, int i) const
if (this->value.f[c] != f)
return false;
break;
+ case GLSL_TYPE_FLOAT16:
+ if (_mesa_half_to_float(this->value.f16[c]) != f)
+ return false;
+ break;
case GLSL_TYPE_INT:
if (this->value.i[c] != i)
return false;