[Mesa-dev] [PATCH] compiler/glsl: Fix uniform location counting.

Ilia Mirkin imirkin at alum.mit.edu
Thu Feb 11 17:13:06 UTC 2016


On Thu, Feb 11, 2016 at 11:31 AM, Plamena Manolova
<plamena.manolova at intel.com> wrote:
> +   struct empty_uniform_block *current_block = NULL;
> +   unsigned prev_location = -1;
> +
> +   for (unsigned i = 0; i < prog->NumUniformRemapTable; i++) {
> +      /* We found empty space in UniformRemapTable. */
> +      if (prog->UniformRemapTable[i] == NULL) {
> +         /* We've found the beginning of new continous block of empty slots */
> +         if ((i == 0) || !current_block || (i != prev_location + 1)) {

You could delete prev_location entirely and transform this into

if (!current_block || current_block->start + current_block->slots != i)

> +            current_block = ralloc(NULL, struct empty_uniform_block);
> +            current_block->start = i;
> +            current_block->slots = 1;

And depending on how clever you want to get, you could change the
above to rzalloc, not touch slots here, and drop the continue. Then
the slots++ will magically increment it to 1. Up to you if you find
this more or less readable though, I don't have a strong preference
either way.

> +            list_addtail(&current_block->link, &prog->EmptyUniformLocations);
> +            prev_location = i;
> +            continue;
> +         }
> +
> +         /* The current block continues, so we simply increment its slots */
> +         current_block->slots++;
> +         prev_location = i;
> +      }
>     }


More information about the mesa-dev mailing list