[Mesa-dev] [PATCH 3/6] mesa: Clamp GetUniformui64v values to be >= 0

Nicolai Hähnle nhaehnle at gmail.com
Fri May 12 08:40:06 UTC 2017


On 11.05.2017 13:10, Iago Toral Quiroga wrote:
> Like we do for the 32-bit case.
> ---
>  src/mesa/main/uniform_query.cpp | 45 ++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 44 insertions(+), 1 deletion(-)
>
> diff --git a/src/mesa/main/uniform_query.cpp b/src/mesa/main/uniform_query.cpp
> index 315973a..42abd18 100644
> --- a/src/mesa/main/uniform_query.cpp
> +++ b/src/mesa/main/uniform_query.cpp
> @@ -549,7 +549,6 @@ _mesa_get_uniform(struct gl_context *ctx, GLuint program, GLint location,
>                 break;
>
>              case GLSL_TYPE_INT64:
> -            case GLSL_TYPE_UINT64:
>                 switch (uni->type->base_type) {
>                 case GLSL_TYPE_UINT: {
>                    uint64_t tmp = src[sidx].u;
> @@ -568,6 +567,13 @@ _mesa_get_uniform(struct gl_context *ctx, GLuint program, GLint location,
>                    memcpy(&dst[didx].u, &tmp, sizeof(tmp));
>                    break;
>                 }
> +               case GLSL_TYPE_UINT64: {
> +                  uint64_t u64;
> +                  memcpy(&u64, &src[sidx].u, sizeof(u64));
> +                  int64_t tmp = MIN2(u64, INT_MAX);
> +                  memcpy(&dst[didx].u, &tmp, sizeof(tmp));
> +                  break;
> +               }
>                 case GLSL_TYPE_FLOAT: {
>                    int64_t tmp = src[sidx].f;
>                    memcpy(&dst[didx].u, &tmp, sizeof(tmp));
> @@ -579,6 +585,43 @@ _mesa_get_uniform(struct gl_context *ctx, GLuint program, GLint location,
>                 }
>                 break;
>
> +            case GLSL_TYPE_UINT64:
> +               switch (uni->type->base_type) {
> +               case GLSL_TYPE_UINT: {
> +                  uint64_t tmp = src[sidx].u;
> +                  memcpy(&dst[didx].u, &tmp, sizeof(tmp));
> +                  break;
> +               }
> +               case GLSL_TYPE_INT:
> +               case GLSL_TYPE_SAMPLER:
> +               case GLSL_TYPE_IMAGE: {
> +                  int64_t tmp = MAX2(src[sidx].i, 0);
> +                  memcpy(&dst[didx].u, &tmp, sizeof(tmp));
> +                  break;
> +               }
> +               case GLSL_TYPE_BOOL: {
> +                  int64_t tmp = src[sidx].i ? 1.0f : 0.0f;
> +                  memcpy(&dst[didx].u, &tmp, sizeof(tmp));
> +                  break;
> +               }
> +               case GLSL_TYPE_INT64: {
> +                  uint64_t i64;
> +                  memcpy(&i64, &src[sidx].i, sizeof(i64));
> +                  uint64_t tmp = MAX2(i64, 0);
> +                  memcpy(&dst[didx].u, &tmp, sizeof(tmp));
> +                  break;
> +               }
> +               case GLSL_TYPE_FLOAT: {
> +                  int64_t tmp = src[sidx].f < 0.0f ? 0 : IROUND64(src[sidx].f);

Unsigned rounding.

Cheers,
Nicolai


> +                  memcpy(&dst[didx].u, &tmp, sizeof(tmp));
> +                  break;
> +               }
> +               default:
> +                  assert(!"Should not get here.");
> +                  break;
> +               }
> +               break;
> +
>              default:
>                 assert(!"Should not get here.");
>                 break;
>


-- 
Lerne, wie die Welt wirklich ist,
Aber vergiss niemals, wie sie sein sollte.


More information about the mesa-dev mailing list