summaryrefslogtreecommitdiff
path: root/src/compiler/glsl_types.cpp
diff options
context:
space:
mode:
authorEduardo Lima Mitev <elima@igalia.com>2017-07-01 07:46:41 +0200
committerJose Maria Casanova Crespo <jmcasanova@igalia.com>2017-12-06 08:57:18 +0100
commit59f458cd8703b97b31b826499f01fcc9a30cd606 (patch)
tree73319583582ec9d3830da2c32f554816a7c86e67 /src/compiler/glsl_types.cpp
parent8761a04d0d9332d9c0c99164faf855fc3c741f7c (diff)
glsl: Add 16-bit types
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>
Diffstat (limited to 'src/compiler/glsl_types.cpp')
-rw-r--r--src/compiler/glsl_types.cpp93
1 files changed, 90 insertions, 3 deletions
diff --git a/src/compiler/glsl_types.cpp b/src/compiler/glsl_types.cpp
index 107a81f5e79..3cc5eb0495c 100644
--- a/src/compiler/glsl_types.cpp
+++ b/src/compiler/glsl_types.cpp
@@ -355,10 +355,16 @@ const glsl_type *glsl_type::get_base_type() const
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:
@@ -385,10 +391,16 @@ const glsl_type *glsl_type::get_scalar_type() const
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:
@@ -499,6 +511,18 @@ glsl_type::vec(unsigned components)
}
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)
{
if (components == 0 || components > 4)
@@ -575,6 +599,31 @@ glsl_type::u64vec(unsigned components)
}
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)
{
if (base_type == GLSL_TYPE_VOID)
@@ -593,6 +642,8 @@ 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:
@@ -601,11 +652,17 @@ glsl_type::get_instance(unsigned base_type, unsigned rows, unsigned columns)
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
@@ -619,7 +676,8 @@ glsl_type::get_instance(unsigned base_type, unsigned rows, unsigned columns)
*/
#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;
@@ -632,7 +690,8 @@ glsl_type::get_instance(unsigned base_type, unsigned rows, unsigned columns)
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;
@@ -646,6 +705,22 @@ glsl_type::get_instance(unsigned base_type, unsigned rows, unsigned columns)
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.");
@@ -1282,7 +1357,10 @@ glsl_type::component_slots() const
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();
@@ -1371,7 +1449,10 @@ glsl_type::uniform_locations() const
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:
@@ -1401,8 +1482,11 @@ glsl_type::varying_count() const
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;
@@ -1974,7 +2058,10 @@ glsl_type::count_attribute_slots(bool is_vertex_input) const
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: