*/
#include <string.h>
#include "ir.h"
+#include "util/half_float.h"
#include "compiler/glsl_types.h"
#include "glsl_parser_extras.h"
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;
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 */
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];
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;
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:
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:
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
{
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:
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:
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:
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:
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:
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:
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;
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;
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;
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;
#include "main/macros.h"
#include "util/hash_table.h"
#include "util/u_string.h"
+#include "util/half_float.h"
static void print_type(FILE *f, const glsl_type *t);
fprintf(f, ") ");
}
+static void
+print_float_constant(FILE *f, float val)
+{
+ if (val == 0.0f)
+ /* 0.0 == -0.0, so print with %f to get the proper sign. */
+ fprintf(f, "%f", val);
+ else if (fabs(val) < 0.000001f)
+ fprintf(f, "%a", val);
+ else if (fabs(val) > 1000000.0f)
+ fprintf(f, "%e", val);
+ else
+ fprintf(f, "%f", val);
+}
void ir_print_visitor::visit(ir_constant *ir)
{
case GLSL_TYPE_UINT: fprintf(f, "%u", ir->value.u[i]); break;
case GLSL_TYPE_INT: fprintf(f, "%d", ir->value.i[i]); break;
case GLSL_TYPE_FLOAT:
- if (ir->value.f[i] == 0.0f)
- /* 0.0 == -0.0, so print with %f to get the proper sign. */
- fprintf(f, "%f", ir->value.f[i]);
- else if (fabs(ir->value.f[i]) < 0.000001f)
- fprintf(f, "%a", ir->value.f[i]);
- else if (fabs(ir->value.f[i]) > 1000000.0f)
- fprintf(f, "%e", ir->value.f[i]);
- else
- fprintf(f, "%f", ir->value.f[i]);
+ print_float_constant(f, ir->value.f[i]);
+ break;
+ case GLSL_TYPE_FLOAT16:
+ print_float_constant(f, _mesa_half_to_float(ir->value.f16[i]));
break;
case GLSL_TYPE_SAMPLER:
case GLSL_TYPE_IMAGE: