[Mesa-dev] [RFC 02/16] glsl: Add half float type
Topi Pohjolainen
topi.pohjolainen at intel.com
Fri May 15 02:39:29 PDT 2015
Signed-off-by: Topi Pohjolainen <topi.pohjolainen at intel.com>
---
src/glsl/ast_to_hir.cpp | 1 +
src/glsl/glsl_types.cpp | 2 ++
src/glsl/glsl_types.h | 9 +++++++++
src/glsl/ir_clone.cpp | 1 +
src/glsl/link_uniform_initializers.cpp | 2 ++
src/glsl/nir/nir_lower_io.c | 1 +
src/mesa/drivers/dri/i965/brw_fs.cpp | 1 +
src/mesa/drivers/dri/i965/brw_fs_visitor.cpp | 1 +
src/mesa/drivers/dri/i965/brw_shader.cpp | 1 +
src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp | 1 +
src/mesa/program/ir_to_mesa.cpp | 3 +++
11 files changed, 23 insertions(+)
diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp
index 7d5bb1d..332de5b 100644
--- a/src/glsl/ast_to_hir.cpp
+++ b/src/glsl/ast_to_hir.cpp
@@ -916,6 +916,7 @@ do_comparison(void *mem_ctx, int operation, ir_rvalue *op0, ir_rvalue *op1)
join_op = ir_binop_logic_or;
switch (op0->type->base_type) {
+ case GLSL_TYPE_HALF:
case GLSL_TYPE_FLOAT:
case GLSL_TYPE_UINT:
case GLSL_TYPE_INT:
diff --git a/src/glsl/glsl_types.cpp b/src/glsl/glsl_types.cpp
index 46c8bf1..51bc19c 100644
--- a/src/glsl/glsl_types.cpp
+++ b/src/glsl/glsl_types.cpp
@@ -936,6 +936,7 @@ glsl_type::component_slots() const
switch (this->base_type) {
case GLSL_TYPE_UINT:
case GLSL_TYPE_INT:
+ case GLSL_TYPE_HALF:
case GLSL_TYPE_FLOAT:
case GLSL_TYPE_BOOL:
return this->components();
@@ -1312,6 +1313,7 @@ glsl_type::count_attribute_slots() const
switch (this->base_type) {
case GLSL_TYPE_UINT:
case GLSL_TYPE_INT:
+ case GLSL_TYPE_HALF:
case GLSL_TYPE_FLOAT:
case GLSL_TYPE_BOOL:
case GLSL_TYPE_DOUBLE:
diff --git a/src/glsl/glsl_types.h b/src/glsl/glsl_types.h
index 25c4d30..86686e3 100644
--- a/src/glsl/glsl_types.h
+++ b/src/glsl/glsl_types.h
@@ -49,6 +49,7 @@ _mesa_glsl_release_types(void);
enum glsl_base_type {
GLSL_TYPE_UINT = 0,
GLSL_TYPE_INT,
+ GLSL_TYPE_HALF,
GLSL_TYPE_FLOAT,
GLSL_TYPE_DOUBLE,
GLSL_TYPE_BOOL,
@@ -450,6 +451,14 @@ struct glsl_type {
}
/**
+ * Query whether or not a type is a double type
+ */
+ bool is_half() const
+ {
+ return base_type == GLSL_TYPE_HALF;
+ }
+
+ /**
* Query whether or not a type is a non-array boolean type
*/
bool is_boolean() const
diff --git a/src/glsl/ir_clone.cpp b/src/glsl/ir_clone.cpp
index 914e0e4..f1ef351 100644
--- a/src/glsl/ir_clone.cpp
+++ b/src/glsl/ir_clone.cpp
@@ -326,6 +326,7 @@ ir_constant::clone(void *mem_ctx, struct hash_table *ht) const
switch (this->type->base_type) {
case GLSL_TYPE_UINT:
case GLSL_TYPE_INT:
+ case GLSL_TYPE_HALF:
case GLSL_TYPE_FLOAT:
case GLSL_TYPE_DOUBLE:
case GLSL_TYPE_BOOL:
diff --git a/src/glsl/link_uniform_initializers.cpp b/src/glsl/link_uniform_initializers.cpp
index 6907384..fbdefa1 100644
--- a/src/glsl/link_uniform_initializers.cpp
+++ b/src/glsl/link_uniform_initializers.cpp
@@ -72,6 +72,8 @@ copy_constant_to_storage(union gl_constant_value *storage,
case GLSL_TYPE_SAMPLER:
storage[i].i = val->value.i[i];
break;
+ case GLSL_TYPE_HALF:
+ /* Half float constants are treated in the compiler as floats. */
case GLSL_TYPE_FLOAT:
storage[i].f = val->value.f[i];
break;
diff --git a/src/glsl/nir/nir_lower_io.c b/src/glsl/nir/nir_lower_io.c
index 03eed04..28ba7d2 100644
--- a/src/glsl/nir/nir_lower_io.c
+++ b/src/glsl/nir/nir_lower_io.c
@@ -48,6 +48,7 @@ type_size(const struct glsl_type *type)
switch (glsl_get_base_type(type)) {
case GLSL_TYPE_UINT:
case GLSL_TYPE_INT:
+ case GLSL_TYPE_HALF:
case GLSL_TYPE_FLOAT:
case GLSL_TYPE_BOOL:
return glsl_get_components(type);
diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp
index 3414d92..1385673 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs.cpp
@@ -670,6 +670,7 @@ fs_visitor::type_size(const struct glsl_type *type)
case GLSL_TYPE_VOID:
case GLSL_TYPE_ERROR:
case GLSL_TYPE_INTERFACE:
+ case GLSL_TYPE_HALF:
case GLSL_TYPE_DOUBLE:
unreachable("not reached");
}
diff --git a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
index 78f269e..4b29b56 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
@@ -1344,6 +1344,7 @@ fs_visitor::emit_assignment_writes(fs_reg &l, fs_reg &r,
case GLSL_TYPE_ATOMIC_UINT:
break;
+ case GLSL_TYPE_HALF:
case GLSL_TYPE_DOUBLE:
case GLSL_TYPE_VOID:
case GLSL_TYPE_ERROR:
diff --git a/src/mesa/drivers/dri/i965/brw_shader.cpp b/src/mesa/drivers/dri/i965/brw_shader.cpp
index c1fd859..f3c115f 100644
--- a/src/mesa/drivers/dri/i965/brw_shader.cpp
+++ b/src/mesa/drivers/dri/i965/brw_shader.cpp
@@ -350,6 +350,7 @@ brw_type_for_base_type(const struct glsl_type *type)
case GLSL_TYPE_VOID:
case GLSL_TYPE_ERROR:
case GLSL_TYPE_INTERFACE:
+ case GLSL_TYPE_HALF:
case GLSL_TYPE_DOUBLE:
unreachable("not reached");
}
diff --git a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
index 5a60fe4..949bac9 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4_visitor.cpp
@@ -612,6 +612,7 @@ type_size(const struct glsl_type *type)
return 0;
case GLSL_TYPE_IMAGE:
case GLSL_TYPE_VOID:
+ case GLSL_TYPE_HALF:
case GLSL_TYPE_DOUBLE:
case GLSL_TYPE_ERROR:
case GLSL_TYPE_INTERFACE:
diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
index 3dcb537..f97437f 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -496,6 +496,7 @@ type_size(const struct glsl_type *type)
switch (type->base_type) {
case GLSL_TYPE_UINT:
case GLSL_TYPE_INT:
+ case GLSL_TYPE_HALF:
case GLSL_TYPE_FLOAT:
case GLSL_TYPE_BOOL:
if (type->is_matrix()) {
@@ -2429,6 +2430,8 @@ _mesa_associate_uniform_storage(struct gl_context *ctx,
if (storage->type->vector_elements > 2)
dmul *= 2;
/* fallthrough */
+ case GLSL_TYPE_HALF:
+ /* Half float constants are treated as floats in the front-end. */
case GLSL_TYPE_FLOAT:
format = uniform_native;
columns = storage->type->matrix_columns;
--
1.9.3
More information about the mesa-dev
mailing list