glsl: Add ir_constant constructor for fp16
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3929>
This commit is contained in:

committed by
Marge Bot

parent
b75a166e68
commit
4068d6baff
@@ -682,6 +682,19 @@ ir_constant::ir_constant(const struct glsl_type *type,
|
|||||||
memcpy(& this->value, data, sizeof(this->value));
|
memcpy(& this->value, data, sizeof(this->value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ir_constant::ir_constant(float16_t f16, unsigned vector_elements)
|
||||||
|
: ir_rvalue(ir_type_constant)
|
||||||
|
{
|
||||||
|
assert(vector_elements <= 4);
|
||||||
|
this->type = glsl_type::get_instance(GLSL_TYPE_FLOAT16, vector_elements, 1);
|
||||||
|
for (unsigned i = 0; i < vector_elements; i++) {
|
||||||
|
this->value.f16[i] = f16.bits;
|
||||||
|
}
|
||||||
|
for (unsigned i = vector_elements; i < 16; i++) {
|
||||||
|
this->value.f[i] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ir_constant::ir_constant(float f, unsigned vector_elements)
|
ir_constant::ir_constant(float f, unsigned vector_elements)
|
||||||
: ir_rvalue(ir_type_constant)
|
: ir_rvalue(ir_type_constant)
|
||||||
{
|
{
|
||||||
|
@@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
#include "util/ralloc.h"
|
#include "util/ralloc.h"
|
||||||
#include "util/format/u_format.h"
|
#include "util/format/u_format.h"
|
||||||
|
#include "util/half_float.h"
|
||||||
#include "compiler/glsl_types.h"
|
#include "compiler/glsl_types.h"
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "ir_visitor.h"
|
#include "ir_visitor.h"
|
||||||
@@ -2190,6 +2191,7 @@ public:
|
|||||||
ir_constant(bool b, unsigned vector_elements=1);
|
ir_constant(bool b, unsigned vector_elements=1);
|
||||||
ir_constant(unsigned int u, unsigned vector_elements=1);
|
ir_constant(unsigned int u, unsigned vector_elements=1);
|
||||||
ir_constant(int i, unsigned vector_elements=1);
|
ir_constant(int i, unsigned vector_elements=1);
|
||||||
|
ir_constant(float16_t f16, unsigned vector_elements=1);
|
||||||
ir_constant(float f, unsigned vector_elements=1);
|
ir_constant(float f, unsigned vector_elements=1);
|
||||||
ir_constant(double d, unsigned vector_elements=1);
|
ir_constant(double d, unsigned vector_elements=1);
|
||||||
ir_constant(uint64_t u64, unsigned vector_elements=1);
|
ir_constant(uint64_t u64, unsigned vector_elements=1);
|
||||||
|
@@ -33,8 +33,8 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define FP16_ONE 0x3C00
|
#define FP16_ONE ((uint16_t) 0x3c00)
|
||||||
#define FP16_ZERO 0
|
#define FP16_ZERO ((uint16_t) 0)
|
||||||
|
|
||||||
uint16_t _mesa_float_to_half(float val);
|
uint16_t _mesa_float_to_half(float val);
|
||||||
float _mesa_half_to_float(uint16_t val);
|
float _mesa_half_to_float(uint16_t val);
|
||||||
@@ -62,6 +62,22 @@ _mesa_half_is_negative(uint16_t h)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
|
||||||
|
/* Helper class for disambiguating fp16 from uint16_t in C++ overloads */
|
||||||
|
|
||||||
|
struct float16_t {
|
||||||
|
uint16_t bits;
|
||||||
|
float16_t(float f) : bits(_mesa_float_to_half(f)) {}
|
||||||
|
float16_t(double d) : bits(_mesa_float_to_half(d)) {}
|
||||||
|
float16_t(uint16_t bits) : bits(bits) {}
|
||||||
|
static float16_t one() { return float16_t(FP16_ONE); }
|
||||||
|
static float16_t zero() { return float16_t(FP16_ZERO); }
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} /* extern C */
|
} /* extern C */
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user