From: Ian Romanick Date: Fri, 26 Mar 2010 18:43:36 +0000 (-0700) Subject: Slightly change the representation of numeric types X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=738c183cc918dd613582010e54ad3a5b5336854c;p=mesa.git Slightly change the representation of numeric types For numeric types, vector_elements and matrix_columns must be at least 1. Previously matrix_columns was 0 for vectors, and both were 0 for scalars. This change simplifies things in some places. --- diff --git a/builtin_types.sh b/builtin_types.sh index 6658ada41a6..609073c9e4d 100755 --- a/builtin_types.sh +++ b/builtin_types.sh @@ -138,21 +138,21 @@ gen_header "core" index=0; bool_index=$index -gen_integral_type "bool" "GLSL_TYPE_BOOL" 0 0 +gen_integral_type "bool" "GLSL_TYPE_BOOL" 1 1 for i in 2 3 4; do - gen_integral_type "bvec$i" "GLSL_TYPE_BOOL" $i 0 + gen_integral_type "bvec$i" "GLSL_TYPE_BOOL" $i 1 done int_index=$index -gen_integral_type "int" "GLSL_TYPE_INT" 0 0 +gen_integral_type "int" "GLSL_TYPE_INT" 1 1 for i in 2 3 4; do - gen_integral_type "ivec$i" "GLSL_TYPE_INT" $i 0 + gen_integral_type "ivec$i" "GLSL_TYPE_INT" $i 1 done float_index=$index -gen_integral_type "float" "GLSL_TYPE_FLOAT" 0 0 +gen_integral_type "float" "GLSL_TYPE_FLOAT" 1 1 for i in 2 3 4; do - gen_integral_type "vec$i" "GLSL_TYPE_FLOAT" $i 0 + gen_integral_type "vec$i" "GLSL_TYPE_FLOAT" $i 1 done matX_index=$index @@ -295,9 +295,9 @@ echo '/*@{*/' gen_header "130" index=0; uint_index=$index -gen_integral_type "uint" "GLSL_TYPE_UINT" 0 0 +gen_integral_type "uint" "GLSL_TYPE_UINT" 1 1 for i in 2 3 4; do - gen_integral_type "uvec$i" "GLSL_TYPE_UINT" $i 0 + gen_integral_type "uvec$i" "GLSL_TYPE_UINT" $i 1 done echo diff --git a/glsl_types.h b/glsl_types.h index 720b05bcda3..68a32efde66 100644 --- a/glsl_types.h +++ b/glsl_types.h @@ -27,6 +27,7 @@ #define GLSL_TYPES_H #include +#include #define GLSL_TYPE_UINT 0 #define GLSL_TYPE_INT 1 @@ -60,8 +61,16 @@ struct glsl_type { * and \c GLSL_TYPE_UINT are valid. */ - unsigned vector_elements:3; /**< 0, 2, 3, or 4 vector elements. */ - unsigned matrix_columns:3; /**< 0, 2, 3, or 4 matrix columns. */ + /** + * \name Vector and matrix element counts + * + * For scalars, each of these values will be 1. For non-numeric types + * these will be 0. + */ + /*@{*/ + unsigned vector_elements:3; /**< 1, 2, 3, or 4 vector elements. */ + unsigned matrix_columns:3; /**< 1, 2, 3, or 4 matrix columns. */ + /*@}*/ /** * Name of the data type @@ -114,6 +123,9 @@ struct glsl_type { name(name), length(0) { + /* Neither dimension is zero or both dimensions are zero. + */ + assert((vector_elements == 0) == (matrix_columns == 0)); memset(& fields, 0, sizeof(fields)); } @@ -162,9 +174,7 @@ struct glsl_type { */ unsigned components() const { - return ((vector_elements == 0) ? 1 : vector_elements) - * ((matrix_columns == 0) ? 1 : matrix_columns); - + return vector_elements * matrix_columns; } /** @@ -172,7 +182,7 @@ struct glsl_type { */ bool is_scalar() const { - return (vector_elements == 0) + return (vector_elements == 1) && (base_type >= GLSL_TYPE_UINT) && (base_type <= GLSL_TYPE_BOOL); } @@ -182,8 +192,8 @@ struct glsl_type { */ bool is_vector() const { - return (vector_elements > 0) - && (matrix_columns == 0) + return (vector_elements > 1) + && (matrix_columns == 1) && (base_type >= GLSL_TYPE_UINT) && (base_type <= GLSL_TYPE_BOOL); } @@ -194,7 +204,7 @@ struct glsl_type { bool is_matrix() const { /* GLSL only has float matrices. */ - return (matrix_columns > 0) && (base_type == GLSL_TYPE_FLOAT); + return (matrix_columns > 1) && (base_type == GLSL_TYPE_FLOAT); } /**