glsl: Document and enforce restriction on type values
authorIan Romanick <ian.d.romanick@intel.com>
Wed, 29 Jun 2016 22:17:16 +0000 (15:17 -0700)
committerIan Romanick <ian.d.romanick@intel.com>
Wed, 6 Jul 2016 00:55:29 +0000 (17:55 -0700)
Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
src/compiler/glsl_types.cpp
src/compiler/glsl_types.h

index 884f3118e8341214c9adcaa03747a7426ac1c31f..066a74e5283f0930bfbd424df5219224d1c5121e 100644 (file)
@@ -55,6 +55,13 @@ glsl_type::glsl_type(GLenum gl_type,
    vector_elements(vector_elements), matrix_columns(matrix_columns),
    length(0)
 {
+   /* Values of these types must fit in the two bits of
+    * glsl_type::sampled_type.
+    */
+   STATIC_ASSERT((unsigned(GLSL_TYPE_UINT)  & 3) == unsigned(GLSL_TYPE_UINT));
+   STATIC_ASSERT((unsigned(GLSL_TYPE_INT)   & 3) == unsigned(GLSL_TYPE_INT));
+   STATIC_ASSERT((unsigned(GLSL_TYPE_FLOAT) & 3) == unsigned(GLSL_TYPE_FLOAT));
+
    mtx_lock(&glsl_type::mutex);
 
    init_ralloc_type_ctx();
index c3a01854fc2cad7d3bfbff1619a00561883bc315..7c4827d8f831b11914faff4e7a84da55a89dbc47 100644 (file)
@@ -47,6 +47,9 @@ _mesa_glsl_release_types(void);
 #endif
 
 enum glsl_base_type {
+   /* Note: GLSL_TYPE_UINT, GLSL_TYPE_INT, and GLSL_TYPE_FLOAT must be 0, 1,
+    * and 2 so that they will fit in the 2 bits of glsl_type::sampled_type.
+    */
    GLSL_TYPE_UINT = 0,
    GLSL_TYPE_INT,
    GLSL_TYPE_FLOAT,