[Mesa-dev] [PATCH v3 02/12] gallium/tgsi/ureg: Lift the restriction on releasing temporaries over UREG_MAX_TEMP.

Jose Fonseca jfonseca at vmware.com
Tue Mar 27 07:30:15 PDT 2012



----- Original Message -----
> ---
> v3: Handle memory allocation failure.
> 
>  src/gallium/auxiliary/tgsi/tgsi_ureg.c |   49
>  ++++++++++++++------------------
>  1 file changed, 22 insertions(+), 27 deletions(-)
> 
> diff --git a/src/gallium/auxiliary/tgsi/tgsi_ureg.c
> b/src/gallium/auxiliary/tgsi/tgsi_ureg.c
> index 75be6cf..ed613ce 100644
> --- a/src/gallium/auxiliary/tgsi/tgsi_ureg.c
> +++ b/src/gallium/auxiliary/tgsi/tgsi_ureg.c
> @@ -36,6 +36,7 @@
>  #include "util/u_debug.h"
>  #include "util/u_memory.h"
>  #include "util/u_math.h"
> +#include "util/u_bitmask.h"
>  
>  union tgsi_any_token {
>     struct tgsi_header header;
> @@ -75,7 +76,6 @@ struct ureg_tokens {
>  #define UREG_MAX_OUTPUT PIPE_MAX_ATTRIBS
>  #define UREG_MAX_CONSTANT_RANGE 32
>  #define UREG_MAX_IMMEDIATE 256
> -#define UREG_MAX_TEMP 256
>  #define UREG_MAX_ADDR 2
>  #define UREG_MAX_PRED 1
>  
> @@ -151,7 +151,7 @@ struct ureg_program
>     } resource[PIPE_MAX_SHADER_RESOURCES];
>     unsigned nr_resources;
>  
> -   unsigned temps_active[UREG_MAX_TEMP / 32];
> +   struct util_bitmask *free_temps;
>     unsigned nr_temps;
>  
>     struct const_decl const_decls;
> @@ -530,43 +530,27 @@ out:
>     return ureg_src_register(TGSI_FILE_CONSTANT, index);
>  }
>  
> -
> -/* Allocate a new temporary.  Temporaries greater than UREG_MAX_TEMP
> - * are legal, but will not be released.
> - */
>  struct ureg_dst ureg_DECL_temporary( struct ureg_program *ureg )
>  {
> -   unsigned i;
> -
> -   for (i = 0; i < UREG_MAX_TEMP; i += 32) {
> -      int bit = ffs(~ureg->temps_active[i/32]);
> -      if (bit != 0) {
> -         i += bit - 1;
> -         goto out;
> -      }
> -   }
> -
> -   /* No reusable temps, so allocate a new one:
> +   /* Look for a released temporary.
>      */
> -   i = ureg->nr_temps++;
> +   unsigned i = util_bitmask_get_first_index(ureg->free_temps);
>  
> -out:
> -   if (i < UREG_MAX_TEMP)
> -      ureg->temps_active[i/32] |= 1 << (i % 32);
> +   /* Or allocate a new one.
> +    */
> +   if (i == UTIL_BITMASK_INVALID_INDEX)
> +      i = ureg->nr_temps++;
>  
> -   if (i >= ureg->nr_temps)
> -      ureg->nr_temps = i + 1;

> +   util_bitmask_clear(ureg->free_temps, i);

bits are cleared by default. So you only need to call this when i != i == UTIL_BITMASK_INVALID_INDEX.

Anyway, looks good. Thanks for the update.

Jose


More information about the mesa-dev mailing list