On Wed, 2016-07-20 at 15:28 -0700, Jason Ekstrand wrote:
> It's only ever called on single-function shaders.  At this point,
> there are
> a lot of helpers that can make it all much simpler.

This is a nice clean-up.

I wonder if for passes like this that have the implicit requirement
that all function calls had been inlined previously, we should add an
assert to make that condition more explicit, or at least add that
requirement in the documentation of the pass itself.

> Signed-off-by: Jason Ekstrand <ja...@jlekstrand.net>
> ---
>  src/compiler/nir/nir_lower_gs_intrinsics.c | 37 +++++++++++++-------
> ----------
>  1 file changed, 16 insertions(+), 21 deletions(-)
> 
> diff --git a/src/compiler/nir/nir_lower_gs_intrinsics.c
> b/src/compiler/nir/nir_lower_gs_intrinsics.c
> index 9bbaf83..13a4399 100644
> --- a/src/compiler/nir/nir_lower_gs_intrinsics.c
> +++ b/src/compiler/nir/nir_lower_gs_intrinsics.c
> @@ -188,32 +188,27 @@ nir_lower_gs_intrinsics(nir_shader *shader)
>     struct state state;
>     state.progress = false;
>  
> -   /* Create the counter variable */
> -   nir_variable *var = rzalloc(shader, nir_variable);
> -   var->data.mode = nir_var_global;
> -   var->type = glsl_uint_type();
> -   var->name = "vertex_count";
> -   var->constant_initializer = rzalloc(shader, nir_constant); /*
> initialize to 0 */
> +   nir_function_impl *impl = nir_shader_get_entrypoint(shader)-
> >impl;
> +   assert(impl);
>  
> -   exec_list_push_tail(&shader->globals, &var->node);
> -   state.vertex_count_var = var;
> +   nir_builder b;
> +   nir_builder_init(&b, impl);
> +   state.builder = &b;
>  
> -   nir_foreach_function(function, shader) {
> -      if (function->impl) {
> -         nir_builder b;
> -         nir_builder_init(&b, function->impl);
> -         state.builder = &b;
> +   /* Create the counter variable */
> +   state.vertex_count_var =
> +      nir_local_variable_create(impl, glsl_uint_type(),
> "vertex_count");
> +   /* initialize to 0 */
> +   b.cursor = nir_before_cf_list(&impl->body);
> +   nir_store_var(&b, state.vertex_count_var, nir_imm_int(&b, 0),
> 0x1);
>  
> -         nir_foreach_block_safe(block, function->impl) {
> -            rewrite_intrinsics(block, &state);
> -         }
> +   nir_foreach_block_safe(block, impl)
> +      rewrite_intrinsics(block, &state);
>  
> -         /* This only works because we have a single main()
> function. */
> -         append_set_vertex_count(function->impl->end_block, &state);
> +   /* This only works because we have a single main() function. */
> +   append_set_vertex_count(impl->end_block, &state);
>  
> -         nir_metadata_preserve(function->impl, 0);
> -      }
> -   }
> +   nir_metadata_preserve(impl, 0);
>  
>     return state.progress;
>  }
_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to