On Thu, Apr 7, 2016 at 1:35 PM, Nicolai Hähnle <nhaeh...@gmail.com> wrote:
> From: Nicolai Hähnle <nicolai.haeh...@amd.com>
>
> When hasFixedUnit is false, polygon stippling will fail when there is no free
> sampler available. Make the corresponding guard more robust in preparation
> of raising PIPE_MAX_SAMPLERS to 32.
>
> The literal 1 is a (signed) int, and shifting into the sign bit is undefined
> in C, so change occurences of 1 to 1u.
>
> v2: add an assert for bitfield size and use 1u << idx
>
> Reviewed-by: Brian Paul <bri...@vmware.com> (v1)
> Reviewed-by: Roland Scheidegger <srol...@vmware.com> (v1)
> Reviewed-by: Bas Nieuwenhuizen <b...@basnieuwenhuizen.nl> (v1)
> Reviewed-by: Marek Olšák <marek.ol...@amd.com> (v1)
> ---
>  src/gallium/auxiliary/util/u_pstipple.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/src/gallium/auxiliary/util/u_pstipple.c 
> b/src/gallium/auxiliary/util/u_pstipple.c
> index bcbe2a2..eb725d8 100644
> --- a/src/gallium/auxiliary/util/u_pstipple.c
> +++ b/src/gallium/auxiliary/util/u_pstipple.c
> @@ -204,7 +204,7 @@ pstip_transform_decl(struct tgsi_transform_context *ctx,
>     if (decl->Declaration.File == TGSI_FILE_SAMPLER) {
>        uint i;
>        for (i = decl->Range.First; i <= decl->Range.Last; i++) {
> -         pctx->samplersUsed |= 1 << i;
> +         pctx->samplersUsed |= 1u << i;
>        }
>     }
>     else if (decl->Declaration.File == pctx->wincoordFile) {
> @@ -266,9 +266,11 @@ pstip_transform_prolog(struct tgsi_transform_context 
> *ctx)
>     int texTemp;
>     int sampIdx;
>
> +   assert(sizeof(pctx->samplersUsed) * 8 >= PIPE_MAX_SAMPLERS);

My personal preference would be for these to be STATIC_ASSERT() so
that we get compiler failures (and in your other patches too). This is
optional, however, and definitely no need to resend if you choose to
make the change.

  -ilia

> +
>     /* find free texture sampler */
>     pctx->freeSampler = free_bit(pctx->samplersUsed);
> -   if (pctx->freeSampler >= PIPE_MAX_SAMPLERS)
> +   if (pctx->freeSampler < 0 || pctx->freeSampler >= PIPE_MAX_SAMPLERS)
>        pctx->freeSampler = PIPE_MAX_SAMPLERS - 1;
>
>     if (pctx->wincoordInput < 0)
> --
> 2.5.0
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to