[Mesa-dev] [PATCH 02/15] nir: allow builin arrays to be lowered
Nicolai Hähnle
nhaehnle at gmail.com
Wed Nov 29 11:16:09 UTC 2017
On 22.11.2017 11:29, Timothy Arceri wrote:
> Galliums nir drivers expect this to be done.
> ---
> src/compiler/nir/nir_lower_io_arrays_to_elements.c | 17 ++++++++++-------
> 1 file changed, 10 insertions(+), 7 deletions(-)
>
> diff --git a/src/compiler/nir/nir_lower_io_arrays_to_elements.c b/src/compiler/nir/nir_lower_io_arrays_to_elements.c
> index 29076bf79b..dfd8e85d96 100644
> --- a/src/compiler/nir/nir_lower_io_arrays_to_elements.c
> +++ b/src/compiler/nir/nir_lower_io_arrays_to_elements.c
> @@ -249,21 +249,22 @@ create_indirects_mask(nir_shader *shader, uint64_t *indirects,
> }
> }
> }
> }
> }
> }
>
> static void
> lower_io_arrays_to_elements(nir_shader *shader, nir_variable_mode mask,
> uint64_t *indirects, uint64_t *patch_indirects,
> - struct hash_table *varyings)
> + struct hash_table *varyings,
> + bool after_cross_stage_opts)
> {
> nir_foreach_function(function, shader) {
> if (function->impl) {
> nir_builder b;
> nir_builder_init(&b, function->impl);
>
> nir_foreach_block(block, function->impl) {
> nir_foreach_instr_safe(instr, block) {
> if (instr->type != nir_instr_type_intrinsic)
> continue;
> @@ -298,28 +299,30 @@ lower_io_arrays_to_elements(nir_shader *shader, nir_variable_mode mask,
> }
>
> /* Skip types we cannot split.
> *
> * TODO: Add support for struct splitting.
> */
> if ((!glsl_type_is_array(type) && !glsl_type_is_matrix(type))||
> glsl_type_is_struct(glsl_without_array(type)))
> continue;
>
> - if (var->data.location < VARYING_SLOT_VAR0 &&
> + /* Skip builtins */
> + if (!after_cross_stage_opts &&
> + var->data.location < VARYING_SLOT_VAR0 &&
> var->data.location >= 0)
> continue;
>
> /* Don't bother splitting if we can't opt away any unused
> * elements.
> */
> - if (var->data.always_active_io)
> + if (!after_cross_stage_opts && var->data.always_active_io)
> continue;
>
> switch (intr->intrinsic) {
> case nir_intrinsic_interp_var_at_centroid:
> case nir_intrinsic_interp_var_at_sample:
> case nir_intrinsic_interp_var_at_offset:
> case nir_intrinsic_load_var:
> case nir_intrinsic_store_var:
> if ((mask & nir_var_shader_in && mode == nir_var_shader_in) ||
> (mask & nir_var_shader_out && mode == nir_var_shader_out))
> @@ -340,24 +343,24 @@ nir_lower_io_arrays_to_elements_no_indirects(nir_shader *shader)
> struct hash_table *split_inputs =
> _mesa_hash_table_create(NULL, _mesa_hash_pointer,
> _mesa_key_pointer_equal);
> struct hash_table *split_outputs =
> _mesa_hash_table_create(NULL, _mesa_hash_pointer,
> _mesa_key_pointer_equal);
>
> uint64_t indirects[4] = {0}, patch_indirects[4] = {0};
>
> lower_io_arrays_to_elements(shader, nir_var_shader_out, indirects,
> - patch_indirects, split_outputs);
> + patch_indirects, split_outputs, true);
>
> lower_io_arrays_to_elements(shader, nir_var_shader_in, indirects,
> - patch_indirects, split_inputs);
> + patch_indirects, split_inputs, true);
The name of the function ("no indirects") doesn't really reflect the
semantic difference between the two top-level functions anymore. I don't
have a good alternative suggestion right now, though.
Cheers,
Nicolai
>
> /* Remove old input from the shaders inputs list */
> struct hash_entry *entry;
> hash_table_foreach(split_inputs, entry) {
> nir_variable *var = (nir_variable *) entry->key;
> exec_node_remove(&var->node);
>
> free(entry->data);
> }
>
> @@ -381,24 +384,24 @@ nir_lower_io_arrays_to_elements(nir_shader *producer, nir_shader *consumer)
> _mesa_key_pointer_equal);
> struct hash_table *split_outputs =
> _mesa_hash_table_create(NULL, _mesa_hash_pointer,
> _mesa_key_pointer_equal);
>
> uint64_t indirects[4] = {0}, patch_indirects[4] = {0};
> create_indirects_mask(producer, indirects, patch_indirects);
> create_indirects_mask(consumer, indirects, patch_indirects);
>
> lower_io_arrays_to_elements(producer, nir_var_shader_out, indirects,
> - patch_indirects, split_outputs);
> + patch_indirects, split_outputs, false);
>
> lower_io_arrays_to_elements(consumer, nir_var_shader_in, indirects,
> - patch_indirects, split_inputs);
> + patch_indirects, split_inputs, false);
>
> /* Remove old input from the shaders inputs list */
> struct hash_entry *entry;
> hash_table_foreach(split_inputs, entry) {
> nir_variable *var = (nir_variable *) entry->key;
> exec_node_remove(&var->node);
>
> free(entry->data);
> }
>
>
--
Lerne, wie die Welt wirklich ist,
Aber vergiss niemals, wie sie sein sollte.
More information about the mesa-dev
mailing list