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

Jose Fonseca jfonseca at vmware.com
Mon Mar 26 05:28:27 PDT 2012



----- Original Message -----
> ---
>  src/gallium/auxiliary/tgsi/tgsi_ureg.c |   43
>  ++++++++++++--------------------
>  1 file changed, 16 insertions(+), 27 deletions(-)
> 
> diff --git a/src/gallium/auxiliary/tgsi/tgsi_ureg.c
> b/src/gallium/auxiliary/tgsi/tgsi_ureg.c
> index 75be6cf..082fec3 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);
>  
>     return ureg_dst_register( TGSI_FILE_TEMPORARY, i );
>  }
>  
> -
>  void ureg_release_temporary( struct ureg_program *ureg,
>                               struct ureg_dst tmp )
>  {
>     if(tmp.File == TGSI_FILE_TEMPORARY)
> -      if (tmp.Index < UREG_MAX_TEMP)
> -         ureg->temps_active[tmp.Index/32] &= ~(1 << (tmp.Index %
> 32));
> +      util_bitmask_set(ureg->free_temps, tmp.Index);
>  }
>  
>  
> @@ -1669,6 +1653,9 @@ struct ureg_program *ureg_create( unsigned
> processor )
>     ureg->property_gs_input_prim = ~0;
>     ureg->property_gs_output_prim = ~0;
>     ureg->property_gs_max_vertices = ~0;
> +
> +   ureg->free_temps = util_bitmask_create();

Please handle creation failure.

Jose

> +
>     return ureg;
>  }
>  
> @@ -1682,6 +1669,8 @@ void ureg_destroy( struct ureg_program *ureg )
>            ureg->domain[i].tokens != error_tokens)
>           FREE(ureg->domain[i].tokens);
>     }
> -
> +
> +   util_bitmask_destroy(ureg->free_temps);
> +
>     FREE(ureg);
>  }
> --
> 1.7.9.2
> 
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
> 


More information about the mesa-dev mailing list