nir: Simplify nir_lower_gs_intrinsics

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.

Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
This commit is contained in:
Jason Ekstrand
2016-07-15 17:15:21 -07:00
parent 257aa5a1c4
commit 2f19c19b5d

View File

@@ -189,32 +189,27 @@ nir_lower_gs_intrinsics(nir_shader *shader)
struct state state; struct state state;
state.progress = false; state.progress = false;
nir_function_impl *impl = nir_shader_get_entrypoint(shader);
assert(impl);
nir_builder b;
nir_builder_init(&b, impl);
state.builder = &b;
/* Create the counter variable */ /* Create the counter variable */
nir_variable *var = rzalloc(shader, nir_variable); state.vertex_count_var =
var->data.mode = nir_var_global; nir_local_variable_create(impl, glsl_uint_type(), "vertex_count");
var->type = glsl_uint_type(); /* initialize to 0 */
var->name = "vertex_count"; b.cursor = nir_before_cf_list(&impl->body);
var->constant_initializer = rzalloc(shader, nir_constant); /* initialize to 0 */ nir_store_var(&b, state.vertex_count_var, nir_imm_int(&b, 0), 0x1);
exec_list_push_tail(&shader->globals, &var->node); nir_foreach_block_safe(block, impl)
state.vertex_count_var = var; rewrite_intrinsics(block, &state);
nir_foreach_function(function, shader) { /* This only works because we have a single main() function. */
if (function->impl) { append_set_vertex_count(impl->end_block, &state);
nir_builder b;
nir_builder_init(&b, function->impl);
state.builder = &b;
nir_foreach_block_safe(block, function->impl) { nir_metadata_preserve(impl, 0);
rewrite_intrinsics(block, &state);
}
/* This only works because we have a single main() function. */
append_set_vertex_count(function->impl->end_block, &state);
nir_metadata_preserve(function->impl, 0);
}
}
return state.progress; return state.progress;
} }