Adds new INT16, UINT16 and FLOAT16 base types.
The corresponding GL types for half floats were reused from the
AMD_gpu_shader_half_float extension. The int16 and uint16 types come from
NV_gpu_shader_5 extension.
This adds the builtins and the lexer support.
To avoid a bunch of warnings due to cases not handled in switch, the
new types have been added to a few places using same behavior as
their 32-bit counterparts, except for a few trivial cases where they are
already handled properly. Subsequent patches in this set will provide
correct 16-bit implementations when needed.
v2: * Use FLOAT16 instead of HALF_FLOAT as name of the base type.
* Removed float16_t from builtin types.
* Don't copy 16-bit types as if they were 32-bit values in
copy_constant_to_storage().
* Use get_scalar_type() instead of adding a new custom switch
statement.
(Jason Ekstrand)
v3: Use GL_FLOAT16_NV instead of GL_HALF_FLOAT for consistency
(Ilia Mirkin)
v4: Add missing 16-bit base types support in glsl_to_nir (Eduardo Lima).
v5: Fix coding style (Topi Poholainen).
Signed-off-by: Jose Maria Casanova Crespo <jmcasanova@igalia.com>
Signed-off-by: Eduardo Lima <elima@igalia.com>
Signed-off-by: Alejandro Piñeiro <apinheiro@igalia.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
DECL_TYPE(mat4x2, GL_FLOAT_MAT4x2, GLSL_TYPE_FLOAT, 2, 4)
DECL_TYPE(mat4x3, GL_FLOAT_MAT4x3, GLSL_TYPE_FLOAT, 3, 4)
+DECL_TYPE(float16_t, GL_FLOAT16_NV, GLSL_TYPE_FLOAT16, 1, 1)
+DECL_TYPE(f16vec2, GL_FLOAT16_VEC2_NV, GLSL_TYPE_FLOAT16, 2, 1)
+DECL_TYPE(f16vec3, GL_FLOAT16_VEC3_NV, GLSL_TYPE_FLOAT16, 3, 1)
+DECL_TYPE(f16vec4, GL_FLOAT16_VEC4_NV, GLSL_TYPE_FLOAT16, 4, 1)
+
+DECL_TYPE(f16mat2, GL_FLOAT16_MAT2_AMD, GLSL_TYPE_FLOAT16, 2, 2)
+DECL_TYPE(f16mat3, GL_FLOAT16_MAT3_AMD, GLSL_TYPE_FLOAT16, 3, 3)
+DECL_TYPE(f16mat4, GL_FLOAT16_MAT4_AMD, GLSL_TYPE_FLOAT16, 4, 4)
+
+DECL_TYPE(f16mat2x3, GL_FLOAT16_MAT2x3_AMD, GLSL_TYPE_FLOAT16, 3, 2)
+DECL_TYPE(f16mat2x4, GL_FLOAT16_MAT2x4_AMD, GLSL_TYPE_FLOAT16, 4, 2)
+DECL_TYPE(f16mat3x2, GL_FLOAT16_MAT3x2_AMD, GLSL_TYPE_FLOAT16, 2, 3)
+DECL_TYPE(f16mat3x4, GL_FLOAT16_MAT3x4_AMD, GLSL_TYPE_FLOAT16, 4, 3)
+DECL_TYPE(f16mat4x2, GL_FLOAT16_MAT4x2_AMD, GLSL_TYPE_FLOAT16, 2, 4)
+DECL_TYPE(f16mat4x3, GL_FLOAT16_MAT4x3_AMD, GLSL_TYPE_FLOAT16, 3, 4)
+
DECL_TYPE(double, GL_DOUBLE, GLSL_TYPE_DOUBLE, 1, 1)
DECL_TYPE(dvec2, GL_DOUBLE_VEC2, GLSL_TYPE_DOUBLE, 2, 1)
DECL_TYPE(dvec3, GL_DOUBLE_VEC3, GLSL_TYPE_DOUBLE, 3, 1)
DECL_TYPE(u64vec3, GL_UNSIGNED_INT64_VEC3_ARB, GLSL_TYPE_UINT64, 3, 1)
DECL_TYPE(u64vec4, GL_UNSIGNED_INT64_VEC4_ARB, GLSL_TYPE_UINT64, 4, 1)
+DECL_TYPE(int16_t, GL_INT16_NV, GLSL_TYPE_INT16, 1, 1)
+DECL_TYPE(i16vec2, GL_INT16_VEC2_NV, GLSL_TYPE_INT16, 2, 1)
+DECL_TYPE(i16vec3, GL_INT16_VEC3_NV, GLSL_TYPE_INT16, 3, 1)
+DECL_TYPE(i16vec4, GL_INT16_VEC4_NV, GLSL_TYPE_INT16, 4, 1)
+
+DECL_TYPE(uint16_t, GL_UNSIGNED_INT16_NV, GLSL_TYPE_UINT16, 1, 1)
+DECL_TYPE(u16vec2, GL_UNSIGNED_INT16_VEC2_NV, GLSL_TYPE_UINT16, 2, 1)
+DECL_TYPE(u16vec3, GL_UNSIGNED_INT16_VEC3_NV, GLSL_TYPE_UINT16, 3, 1)
+DECL_TYPE(u16vec4, GL_UNSIGNED_INT16_VEC4_NV, GLSL_TYPE_UINT16, 4, 1)
+
DECL_TYPE(sampler, GL_SAMPLER_1D, GLSL_TYPE_SAMPLER, GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_VOID)
DECL_TYPE(sampler1D, GL_SAMPLER_1D, GLSL_TYPE_SAMPLER, GLSL_SAMPLER_DIM_1D, 0, 0, GLSL_TYPE_FLOAT)
DECL_TYPE(sampler2D, GL_SAMPLER_2D, GLSL_TYPE_SAMPLER, GLSL_SAMPLER_DIM_2D, 0, 0, GLSL_TYPE_FLOAT)
switch (op0->type->base_type) {
case GLSL_TYPE_FLOAT:
+ case GLSL_TYPE_FLOAT16:
case GLSL_TYPE_UINT:
case GLSL_TYPE_INT:
case GLSL_TYPE_BOOL:
case GLSL_TYPE_DOUBLE:
case GLSL_TYPE_UINT64:
case GLSL_TYPE_INT64:
+ case GLSL_TYPE_UINT16:
+ case GLSL_TYPE_INT16:
return new(mem_ctx) ir_expression(operation, op0, op1);
case GLSL_TYPE_ARRAY: {
static bool
type_is_float(glsl_base_type type)
{
- return type == GLSL_TYPE_FLOAT || type == GLSL_TYPE_DOUBLE;
+ return type == GLSL_TYPE_FLOAT || type == GLSL_TYPE_DOUBLE ||
+ type == GLSL_TYPE_FLOAT16;
}
static bool
type_is_signed(glsl_base_type type)
{
- return type == GLSL_TYPE_INT || type == GLSL_TYPE_INT64;
+ return type == GLSL_TYPE_INT || type == GLSL_TYPE_INT64 ||
+ type == GLSL_TYPE_INT16;
}
void
case GLSL_TYPE_UINT:
case GLSL_TYPE_INT:
case GLSL_TYPE_FLOAT:
+ case GLSL_TYPE_FLOAT16:
case GLSL_TYPE_DOUBLE:
case GLSL_TYPE_BOOL:
case GLSL_TYPE_UINT64:
case GLSL_TYPE_INT64:
+ case GLSL_TYPE_UINT16:
+ case GLSL_TYPE_INT16:
case GLSL_TYPE_SAMPLER:
case GLSL_TYPE_IMAGE:
return new(mem_ctx) ir_constant(this->type, &this->value);
case GLSL_TYPE_SUBROUTINE:
case GLSL_TYPE_FUNCTION:
case GLSL_TYPE_ERROR:
+ case GLSL_TYPE_UINT16:
+ case GLSL_TYPE_INT16:
+ case GLSL_TYPE_FLOAT16:
/* All other types should have already been filtered by other
* paths in the caller.
*/
const unsigned matrix_stride =
link_calculate_matrix_stride(matrix_type, row_major, packing);
- const glsl_type *deref_type = deref->type->is_float() ?
- glsl_type::float_type : glsl_type::double_type;
+ const glsl_type *deref_type = deref->type->get_scalar_type();
for (unsigned i = 0; i < deref->type->vector_elements; i++) {
ir_rvalue *chan_offset =
switch (base_type) {
case GLSL_TYPE_UINT:
return uint_type;
+ case GLSL_TYPE_UINT16:
+ return uint16_t_type;
case GLSL_TYPE_INT:
return int_type;
+ case GLSL_TYPE_INT16:
+ return int16_t_type;
case GLSL_TYPE_FLOAT:
return float_type;
+ case GLSL_TYPE_FLOAT16:
+ return float16_t_type;
case GLSL_TYPE_DOUBLE:
return double_type;
case GLSL_TYPE_BOOL:
switch (type->base_type) {
case GLSL_TYPE_UINT:
return uint_type;
+ case GLSL_TYPE_UINT16:
+ return uint16_t_type;
case GLSL_TYPE_INT:
return int_type;
+ case GLSL_TYPE_INT16:
+ return int16_t_type;
case GLSL_TYPE_FLOAT:
return float_type;
+ case GLSL_TYPE_FLOAT16:
+ return float16_t_type;
case GLSL_TYPE_DOUBLE:
return double_type;
case GLSL_TYPE_BOOL:
return ts[components - 1];
}
+const glsl_type *
+glsl_type::f16vec(unsigned components)
+{
+ if (components == 0 || components > 4)
+ return error_type;
+
+ static const glsl_type *const ts[] = {
+ float16_t_type, f16vec2_type, f16vec3_type, f16vec4_type
+ };
+ return ts[components - 1];
+}
+
const glsl_type *
glsl_type::dvec(unsigned components)
{
return ts[components - 1];
}
+const glsl_type *
+glsl_type::i16vec(unsigned components)
+{
+ if (components == 0 || components > 4)
+ return error_type;
+
+ static const glsl_type *const ts[] = {
+ int16_t_type, i16vec2_type, i16vec3_type, i16vec4_type
+ };
+ return ts[components - 1];
+}
+
+
+const glsl_type *
+glsl_type::u16vec(unsigned components)
+{
+ if (components == 0 || components > 4)
+ return error_type;
+
+ static const glsl_type *const ts[] = {
+ uint16_t_type, u16vec2_type, u16vec3_type, u16vec4_type
+ };
+ return ts[components - 1];
+}
+
const glsl_type *
glsl_type::get_instance(unsigned base_type, unsigned rows, unsigned columns)
{
return ivec(rows);
case GLSL_TYPE_FLOAT:
return vec(rows);
+ case GLSL_TYPE_FLOAT16:
+ return f16vec(rows);
case GLSL_TYPE_DOUBLE:
return dvec(rows);
case GLSL_TYPE_BOOL:
return u64vec(rows);
case GLSL_TYPE_INT64:
return i64vec(rows);
+ case GLSL_TYPE_UINT16:
+ return u16vec(rows);
+ case GLSL_TYPE_INT16:
+ return i16vec(rows);
default:
return error_type;
}
} else {
- if ((base_type != GLSL_TYPE_FLOAT && base_type != GLSL_TYPE_DOUBLE) || (rows == 1))
+ if ((base_type != GLSL_TYPE_FLOAT &&
+ base_type != GLSL_TYPE_DOUBLE &&
+ base_type != GLSL_TYPE_FLOAT16) || (rows == 1))
return error_type;
/* GLSL matrix types are named mat{COLUMNS}x{ROWS}. Only the following
*/
#define IDX(c,r) (((c-1)*3) + (r-1))
- if (base_type == GLSL_TYPE_DOUBLE) {
+ switch (base_type) {
+ case GLSL_TYPE_DOUBLE: {
switch (IDX(columns, rows)) {
case IDX(2,2): return dmat2_type;
case IDX(2,3): return dmat2x3_type;
case IDX(4,4): return dmat4_type;
default: return error_type;
}
- } else {
+ }
+ case GLSL_TYPE_FLOAT: {
switch (IDX(columns, rows)) {
case IDX(2,2): return mat2_type;
case IDX(2,3): return mat2x3_type;
default: return error_type;
}
}
+ case GLSL_TYPE_FLOAT16: {
+ switch (IDX(columns, rows)) {
+ case IDX(2,2): return f16mat2_type;
+ case IDX(2,3): return f16mat2x3_type;
+ case IDX(2,4): return f16mat2x4_type;
+ case IDX(3,2): return f16mat3x2_type;
+ case IDX(3,3): return f16mat3_type;
+ case IDX(3,4): return f16mat3x4_type;
+ case IDX(4,2): return f16mat4x2_type;
+ case IDX(4,3): return f16mat4x3_type;
+ case IDX(4,4): return f16mat4_type;
+ default: return error_type;
+ }
+ }
+ default: return error_type;
+ }
}
assert(!"Should not get here.");
switch (this->base_type) {
case GLSL_TYPE_UINT:
case GLSL_TYPE_INT:
+ case GLSL_TYPE_UINT16:
+ case GLSL_TYPE_INT16:
case GLSL_TYPE_FLOAT:
+ case GLSL_TYPE_FLOAT16:
case GLSL_TYPE_BOOL:
return this->components();
case GLSL_TYPE_UINT:
case GLSL_TYPE_INT:
case GLSL_TYPE_FLOAT:
+ case GLSL_TYPE_FLOAT16:
case GLSL_TYPE_DOUBLE:
+ case GLSL_TYPE_UINT16:
+ case GLSL_TYPE_INT16:
case GLSL_TYPE_UINT64:
case GLSL_TYPE_INT64:
case GLSL_TYPE_BOOL:
case GLSL_TYPE_UINT:
case GLSL_TYPE_INT:
case GLSL_TYPE_FLOAT:
+ case GLSL_TYPE_FLOAT16:
case GLSL_TYPE_DOUBLE:
case GLSL_TYPE_BOOL:
+ case GLSL_TYPE_UINT16:
+ case GLSL_TYPE_INT16:
case GLSL_TYPE_UINT64:
case GLSL_TYPE_INT64:
return 1;
switch (this->base_type) {
case GLSL_TYPE_UINT:
case GLSL_TYPE_INT:
+ case GLSL_TYPE_UINT16:
+ case GLSL_TYPE_INT16:
case GLSL_TYPE_FLOAT:
+ case GLSL_TYPE_FLOAT16:
case GLSL_TYPE_BOOL:
case GLSL_TYPE_SAMPLER:
case GLSL_TYPE_IMAGE:
GLSL_TYPE_UINT = 0,
GLSL_TYPE_INT,
GLSL_TYPE_FLOAT,
+ GLSL_TYPE_FLOAT16,
GLSL_TYPE_DOUBLE,
+ GLSL_TYPE_UINT16,
+ GLSL_TYPE_INT16,
GLSL_TYPE_UINT64,
GLSL_TYPE_INT64,
GLSL_TYPE_BOOL,
* @{
*/
static const glsl_type *vec(unsigned components);
+ static const glsl_type *f16vec(unsigned components);
static const glsl_type *dvec(unsigned components);
static const glsl_type *ivec(unsigned components);
static const glsl_type *uvec(unsigned components);
static const glsl_type *bvec(unsigned components);
static const glsl_type *i64vec(unsigned components);
static const glsl_type *u64vec(unsigned components);
+ static const glsl_type *i16vec(unsigned components);
+ static const glsl_type *u16vec(unsigned components);
/**@}*/
/**
bool is_matrix() const
{
/* GLSL only has float matrices. */
- return (matrix_columns > 1) && (base_type == GLSL_TYPE_FLOAT || base_type == GLSL_TYPE_DOUBLE);
+ return (matrix_columns > 1) && (base_type == GLSL_TYPE_FLOAT ||
+ base_type == GLSL_TYPE_DOUBLE ||
+ base_type == GLSL_TYPE_FLOAT16);
}
/**
switch (type->base_type) {
case GLSL_TYPE_UINT:
case GLSL_TYPE_INT:
+ case GLSL_TYPE_UINT16:
+ case GLSL_TYPE_INT16:
case GLSL_TYPE_FLOAT:
+ case GLSL_TYPE_FLOAT16:
case GLSL_TYPE_BOOL:
if (type->is_matrix()) {
return type->matrix_columns;
dmul *= 2;
/* fallthrough */
case GLSL_TYPE_UINT:
+ case GLSL_TYPE_UINT16:
assert(ctx->Const.NativeIntegers);
format = uniform_native;
columns = 1;
dmul *= 2;
/* fallthrough */
case GLSL_TYPE_INT:
+ case GLSL_TYPE_INT16:
format =
(ctx->Const.NativeIntegers) ? uniform_native : uniform_int_float;
columns = 1;
dmul *= 2;
/* fallthrough */
case GLSL_TYPE_FLOAT:
+ case GLSL_TYPE_FLOAT16:
format = uniform_native;
columns = storage->type->matrix_columns;
break;