[Mesa-dev] [PATCH 02/19] st_glsl_types: add st_glsl_type_usagemask

Nicolai Hähnle nhaehnle at gmail.com
Tue Aug 9 10:36:31 UTC 2016


From: Nicolai Hähnle <nicolai.haehnle at amd.com>

Determine which components of the underlying vec4 storage will be used.
---
 src/mesa/state_tracker/st_glsl_types.cpp | 33 ++++++++++++++++++++++++++++++++
 src/mesa/state_tracker/st_glsl_types.h   |  1 +
 2 files changed, 34 insertions(+)

diff --git a/src/mesa/state_tracker/st_glsl_types.cpp b/src/mesa/state_tracker/st_glsl_types.cpp
index 857e143..89ec2cf 100644
--- a/src/mesa/state_tracker/st_glsl_types.cpp
+++ b/src/mesa/state_tracker/st_glsl_types.cpp
@@ -87,15 +87,48 @@ st_glsl_attrib_type_size(const struct glsl_type *type, bool is_vs_input)
    case GLSL_TYPE_INTERFACE:
    case GLSL_TYPE_VOID:
    case GLSL_TYPE_ERROR:
    case GLSL_TYPE_FUNCTION:
       assert(!"Invalid type in type_size");
       break;
    }
    return 0;
 }
 
+/**
+ * Returns a mask of which channels of a vec4 are used for this type.
+ */
+unsigned
+st_glsl_type_usagemask(const struct glsl_type* type)
+{
+   switch (type->base_type) {
+   case GLSL_TYPE_UINT:
+   case GLSL_TYPE_INT:
+   case GLSL_TYPE_FLOAT:
+   case GLSL_TYPE_BOOL:
+      return (1u << type->vector_elements) - 1;
+   case GLSL_TYPE_DOUBLE:
+      if (type->vector_elements <= 1)
+         return 3;
+      else
+         return 0xf;
+   case GLSL_TYPE_ARRAY:
+      return st_glsl_type_usagemask(type->fields.array);
+   case GLSL_TYPE_STRUCT: {
+      unsigned mask = 0;
+      unsigned i;
+      for (i = 0; i < type->length && mask != 0xf; i++) {
+         mask |= st_glsl_type_usagemask(type->fields.structure[i].type);
+      }
+      return mask;
+   }
+   default:
+      assert(!"Invalid type in st_glsl_type_usagemask");
+      return 0xf;
+   }
+}
+
 int
 st_glsl_type_size(const struct glsl_type *type)
 {
    return st_glsl_attrib_type_size(type, false);
 }
diff --git a/src/mesa/state_tracker/st_glsl_types.h b/src/mesa/state_tracker/st_glsl_types.h
index 3a39cee..a144bc0 100644
--- a/src/mesa/state_tracker/st_glsl_types.h
+++ b/src/mesa/state_tracker/st_glsl_types.h
@@ -27,18 +27,19 @@
 #ifndef __ST_GLSL_TYPES_H__
 #define __ST_GLSL_TYPES_H__
 
 #include "compiler/glsl_types.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 int st_glsl_attrib_type_size(const struct glsl_type *type, bool is_vs_input);
+unsigned st_glsl_type_usagemask(const struct glsl_type* type);
 int st_glsl_type_size(const struct glsl_type *type);
 
 
 #ifdef __cplusplus
 }
 #endif
 
 #endif /* __ST_GLSL_TYPES_H__ */
-- 
2.7.4



More information about the mesa-dev mailing list