[Mesa-dev] [PATCH] glsl: Document and enforce restriction on type values

Dave Airlie airlied at gmail.com
Sat Jul 2 06:04:28 UTC 2016


On 30 June 2016 at 08:26, Ian Romanick <idr at freedesktop.org> wrote:
> From: Ian Romanick <ian.d.romanick at intel.com>

Probably a good idea,

Reviewed-by: Dave Airlie <airlied at redhat.com>

>
> Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
> Cc: Dave Airlie <airlied at redhat.com>
> ---
>  src/compiler/glsl_types.cpp | 7 +++++++
>  src/compiler/glsl_types.h   | 3 +++
>  2 files changed, 10 insertions(+)
>
> diff --git a/src/compiler/glsl_types.cpp b/src/compiler/glsl_types.cpp
> index 6e107a7..1539f5a 100644
> --- a/src/compiler/glsl_types.cpp
> +++ b/src/compiler/glsl_types.cpp
> @@ -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();
> diff --git a/src/compiler/glsl_types.h b/src/compiler/glsl_types.h
> index c3a0185..7c4827d 100644
> --- a/src/compiler/glsl_types.h
> +++ b/src/compiler/glsl_types.h
> @@ -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,
> --
> 2.5.5
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list