[Mesa-dev] [PATCH 3/8] nir: add a helper for getting the bitmask for a variable's location

Kenneth Graunke kenneth at whitecape.org
Fri Sep 22 18:33:53 UTC 2017


On Tuesday, September 12, 2017 4:37:30 PM PDT Timothy Arceri wrote:
> ---
>  src/compiler/nir/nir.h | 31 +++++++++++++++++++++++++++++++
>  1 file changed, 31 insertions(+)
> 
> diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
> index fab2110f619..e52a1006896 100644
> --- a/src/compiler/nir/nir.h
> +++ b/src/compiler/nir/nir.h
> @@ -351,6 +351,37 @@ typedef struct nir_variable {
>  #define nir_foreach_variable_safe(var, var_list) \
>     foreach_list_typed_safe(nir_variable, var, node, var_list)
>  
> +/**
> + * Returns the bits in the inputs_read, outputs_written, or
> + * system_values_read bitfield corresponding to this variable.
> + */
> +static inline uint64_t
> +nir_variable_get_io_mask(nir_variable *var, gl_shader_stage stage)
> +{
> +   /* TODO: add support for tess patches */
> +   if (var->data.patch || var->data.location < 0)
> +      return 0;
> +
> +   assert(var->data.mode == nir_var_shader_in ||
> +          var->data.mode == nir_var_shader_out ||
> +          var->data.mode == nir_var_system_value);
> +   assert(var->data.location >= 0);
> +
> +   const struct glsl_type *var_type = var->type;
> +   if ((var->data.mode == nir_var_shader_in &&
> +        (stage == MESA_SHADER_GEOMETRY ||
> +         stage == MESA_SHADER_TESS_CTRL ||
> +         stage == MESA_SHADER_TESS_EVAL)) ||
> +       (var->data.mode == nir_var_shader_out &&
> +        stage == MESA_SHADER_TESS_CTRL)) {
> +      if (glsl_type_is_array(var_type))
> +         var_type = glsl_get_array_element(var_type);

You can just do

   if (nir_is_per_vertex_io(var, stage)) {
      assert(glsl_type_is_array(type));
      type = glsl_get_array_element(type);
   }

> +   }
> +
> +   unsigned slots = glsl_count_attribute_slots(var_type, false);
> +   return ((1ull << slots) - 1) << var->data.location;
> +}
> +
>  static inline bool
>  nir_variable_is_global(const nir_variable *var)
>  {
> 

This is duplicating the code in nir_gather_info.c pretty hard, but it
doesn't handle patch variables, or scalar arrays with var->data.compact
set (i.e. gl_ClipDistance as float[8] packed as if it were vec4[2]).

Would it make sense to wrap or refactor set_io_mask()?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part.
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20170922/7729bdff/attachment.sig>


More information about the mesa-dev mailing list