* inline functions. That way they get properly initialized at the top
* of the function and not at the top of its caller.
*/
- NIR_PASS_V(nir, nir_lower_constant_initializers, nir_var_function_temp);
+ NIR_PASS_V(nir, nir_lower_variable_initializers, nir_var_function_temp);
NIR_PASS_V(nir, nir_lower_returns);
NIR_PASS_V(nir, nir_inline_functions);
NIR_PASS_V(nir, nir_opt_deref);
/* Make sure we lower constant initializers on output variables so that
* nir_remove_dead_variables below sees the corresponding stores
*/
- NIR_PASS_V(nir, nir_lower_constant_initializers, nir_var_shader_out);
+ NIR_PASS_V(nir, nir_lower_variable_initializers, nir_var_shader_out);
/* Now that we've deleted all but the main function, we can go ahead and
* lower the rest of the constant initializers.
*/
- NIR_PASS_V(nir, nir_lower_constant_initializers, ~0);
+ NIR_PASS_V(nir, nir_lower_variable_initializers, ~0);
/* Split member structs. We do this before lower_io_to_temporaries so that
* it doesn't lower system values to temporaries by accident.
nir/nir_lower_clip.c \
nir/nir_lower_clip_cull_distance_arrays.c \
nir/nir_lower_clip_halfz.c \
- nir/nir_lower_constant_initializers.c \
+ nir/nir_lower_variable_initializers.c \
nir/nir_lower_double_ops.c \
nir/nir_lower_drawpixels.c \
nir/nir_lower_fb_read.c \
* inline functions. That way they get properly initialized at the top
* of the function and not at the top of its caller.
*/
- nir_lower_constant_initializers(shader, (nir_variable_mode)~0);
+ nir_lower_variable_initializers(shader, (nir_variable_mode)~0);
nir_lower_returns(shader);
nir_inline_functions(shader);
nir_opt_deref(shader);
nir_validate_shader(nir, "float64_funcs_to_nir");
- NIR_PASS_V(nir, nir_lower_constant_initializers, nir_var_function_temp);
+ NIR_PASS_V(nir, nir_lower_variable_initializers, nir_var_function_temp);
NIR_PASS_V(nir, nir_lower_returns);
NIR_PASS_V(nir, nir_inline_functions);
NIR_PASS_V(nir, nir_opt_deref);
'nir_lower_clip.c',
'nir_lower_clip_cull_distance_arrays.c',
'nir_lower_clip_halfz.c',
- 'nir_lower_constant_initializers.c',
+ 'nir_lower_variable_initializers.c',
'nir_lower_double_ops.c',
'nir_lower_drawpixels.c',
'nir_lower_fb_read.c',
bool nir_remove_dead_derefs(nir_shader *shader);
bool nir_remove_dead_derefs_impl(nir_function_impl *impl);
bool nir_remove_dead_variables(nir_shader *shader, nir_variable_mode modes);
-bool nir_lower_constant_initializers(nir_shader *shader,
+bool nir_lower_variable_initializers(nir_shader *shader,
nir_variable_mode modes);
bool nir_move_vec_src_uses_to_dest(nir_shader *shader);
* For most use-cases, function inlining is a multi-step process. The general
* pattern employed by SPIR-V consumers and others is as follows:
*
- * 1. nir_lower_constant_initializers(shader, nir_var_function_temp)
+ * 1. nir_lower_variable_initializers(shader, nir_var_function_temp)
*
* This is needed because local variables from the callee are simply added
* to the locals list for the caller and the information about where the
* spirv_to_nir returns the root function and so we can just use == whereas
* with GL, you may have to look for a function named "main".
*
- * 6. nir_lower_constant_initializers(shader, ~nir_var_function_temp)
+ * 6. nir_lower_variable_initializers(shader, ~nir_var_function_temp)
*
* Lowering constant initializers on inputs, outputs, global variables,
* etc. requires that we know the main entrypoint so that we know where to
+++ /dev/null
-/*
- * Copyright © 2016 Intel Corporation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- */
-
-#include "nir.h"
-#include "nir_builder.h"
-
-static void
-build_constant_load(nir_builder *b, nir_deref_instr *deref, nir_constant *c)
-{
- if (glsl_type_is_vector_or_scalar(deref->type)) {
- nir_load_const_instr *load =
- nir_load_const_instr_create(b->shader,
- glsl_get_vector_elements(deref->type),
- glsl_get_bit_size(deref->type));
- memcpy(load->value, c->values, sizeof(*load->value) * load->def.num_components);
- nir_builder_instr_insert(b, &load->instr);
- nir_store_deref(b, deref, &load->def, ~0);
- } else if (glsl_type_is_struct_or_ifc(deref->type)) {
- unsigned len = glsl_get_length(deref->type);
- for (unsigned i = 0; i < len; i++) {
- build_constant_load(b, nir_build_deref_struct(b, deref, i),
- c->elements[i]);
- }
- } else {
- assert(glsl_type_is_array(deref->type) ||
- glsl_type_is_matrix(deref->type));
- unsigned len = glsl_get_length(deref->type);
- for (unsigned i = 0; i < len; i++) {
- build_constant_load(b,
- nir_build_deref_array_imm(b, deref, i),
- c->elements[i]);
- }
- }
-}
-
-static bool
-lower_const_initializer(struct nir_builder *b, struct exec_list *var_list)
-{
- bool progress = false;
-
- b->cursor = nir_before_cf_list(&b->impl->body);
-
- nir_foreach_variable(var, var_list) {
- if (var->constant_initializer) {
- build_constant_load(b, nir_build_deref_var(b, var),
- var->constant_initializer);
-
- progress = true;
- var->constant_initializer = NULL;
- } else if (var->pointer_initializer) {
- nir_deref_instr *src_deref = nir_build_deref_var(b, var->pointer_initializer);
- nir_deref_instr *dst_deref = nir_build_deref_var(b, var);
-
- /* Note that this stores a pointer to src into dst */
- nir_store_deref(b, dst_deref, &src_deref->dest.ssa, ~0);
-
- progress = true;
- var->pointer_initializer = NULL;
- }
-
- }
-
- return progress;
-}
-
-bool
-nir_lower_constant_initializers(nir_shader *shader, nir_variable_mode modes)
-{
- bool progress = false;
-
- nir_foreach_function(function, shader) {
- if (!function->impl)
- continue;
-
- bool impl_progress = false;
-
- nir_builder builder;
- nir_builder_init(&builder, function->impl);
-
- if ((modes & nir_var_shader_out) && function->is_entrypoint)
- impl_progress |= lower_const_initializer(&builder, &shader->outputs);
-
- if ((modes & nir_var_shader_temp) && function->is_entrypoint)
- impl_progress |= lower_const_initializer(&builder, &shader->globals);
-
- if ((modes & nir_var_system_value) && function->is_entrypoint)
- impl_progress |= lower_const_initializer(&builder, &shader->system_values);
-
- if (modes & nir_var_function_temp)
- impl_progress |= lower_const_initializer(&builder, &function->impl->locals);
-
- if (impl_progress) {
- progress = true;
- nir_metadata_preserve(function->impl, nir_metadata_block_index |
- nir_metadata_dominance |
- nir_metadata_live_ssa_defs);
- } else {
-#ifndef NDEBUG
- function->impl->valid_metadata &= ~nir_metadata_not_properly_reset;
-#endif
- }
- }
-
- return progress;
-}
--- /dev/null
+/*
+ * Copyright © 2016 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "nir.h"
+#include "nir_builder.h"
+
+static void
+build_constant_load(nir_builder *b, nir_deref_instr *deref, nir_constant *c)
+{
+ if (glsl_type_is_vector_or_scalar(deref->type)) {
+ nir_load_const_instr *load =
+ nir_load_const_instr_create(b->shader,
+ glsl_get_vector_elements(deref->type),
+ glsl_get_bit_size(deref->type));
+ memcpy(load->value, c->values, sizeof(*load->value) * load->def.num_components);
+ nir_builder_instr_insert(b, &load->instr);
+ nir_store_deref(b, deref, &load->def, ~0);
+ } else if (glsl_type_is_struct_or_ifc(deref->type)) {
+ unsigned len = glsl_get_length(deref->type);
+ for (unsigned i = 0; i < len; i++) {
+ build_constant_load(b, nir_build_deref_struct(b, deref, i),
+ c->elements[i]);
+ }
+ } else {
+ assert(glsl_type_is_array(deref->type) ||
+ glsl_type_is_matrix(deref->type));
+ unsigned len = glsl_get_length(deref->type);
+ for (unsigned i = 0; i < len; i++) {
+ build_constant_load(b,
+ nir_build_deref_array_imm(b, deref, i),
+ c->elements[i]);
+ }
+ }
+}
+
+static bool
+lower_const_initializer(struct nir_builder *b, struct exec_list *var_list)
+{
+ bool progress = false;
+
+ b->cursor = nir_before_cf_list(&b->impl->body);
+
+ nir_foreach_variable(var, var_list) {
+ if (var->constant_initializer) {
+ build_constant_load(b, nir_build_deref_var(b, var),
+ var->constant_initializer);
+
+ progress = true;
+ var->constant_initializer = NULL;
+ } else if (var->pointer_initializer) {
+ nir_deref_instr *src_deref = nir_build_deref_var(b, var->pointer_initializer);
+ nir_deref_instr *dst_deref = nir_build_deref_var(b, var);
+
+ /* Note that this stores a pointer to src into dst */
+ nir_store_deref(b, dst_deref, &src_deref->dest.ssa, ~0);
+
+ progress = true;
+ var->pointer_initializer = NULL;
+ }
+
+ }
+
+ return progress;
+}
+
+bool
+nir_lower_variable_initializers(nir_shader *shader, nir_variable_mode modes)
+{
+ bool progress = false;
+
+ nir_foreach_function(function, shader) {
+ if (!function->impl)
+ continue;
+
+ bool impl_progress = false;
+
+ nir_builder builder;
+ nir_builder_init(&builder, function->impl);
+
+ if ((modes & nir_var_shader_out) && function->is_entrypoint)
+ impl_progress |= lower_const_initializer(&builder, &shader->outputs);
+
+ if ((modes & nir_var_shader_temp) && function->is_entrypoint)
+ impl_progress |= lower_const_initializer(&builder, &shader->globals);
+
+ if ((modes & nir_var_system_value) && function->is_entrypoint)
+ impl_progress |= lower_const_initializer(&builder, &shader->system_values);
+
+ if (modes & nir_var_function_temp)
+ impl_progress |= lower_const_initializer(&builder, &function->impl->locals);
+
+ if (impl_progress) {
+ progress = true;
+ nir_metadata_preserve(function->impl, nir_metadata_block_index |
+ nir_metadata_dominance |
+ nir_metadata_live_ssa_defs);
+ } else {
+#ifndef NDEBUG
+ function->impl->valid_metadata &= ~nir_metadata_not_properly_reset;
+#endif
+ }
+ }
+
+ return progress;
+}
* right away. In order to do so, we must lower any constant initializers
* on outputs so nir_remove_dead_variables sees that they're written to.
*/
- nir_lower_constant_initializers(b->shader, nir_var_shader_out);
+ nir_lower_variable_initializers(b->shader, nir_var_shader_out);
nir_remove_dead_variables(b->shader,
nir_var_shader_in | nir_var_shader_out);
}
/* multi step inlining procedure */
- NIR_PASS_V(nir, nir_lower_constant_initializers, nir_var_function_temp);
+ NIR_PASS_V(nir, nir_lower_variable_initializers, nir_var_function_temp);
NIR_PASS_V(nir, nir_lower_returns);
NIR_PASS_V(nir, nir_inline_functions);
NIR_PASS_V(nir, nir_opt_deref);
exec_node_remove(&func->node);
}
assert(exec_list_length(&nir->functions) == 1);
- NIR_PASS_V(nir, nir_lower_constant_initializers, ~nir_var_function_temp);
+ NIR_PASS_V(nir, nir_lower_variable_initializers, ~nir_var_function_temp);
/* Split member structs. We do this before lower_io_to_temporaries so that
* it doesn't lower system values to temporaries by accident.
// Inline all functions first.
// according to the comment on nir_inline_functions
- NIR_PASS_V(nir, nir_lower_constant_initializers, nir_var_function_temp);
+ NIR_PASS_V(nir, nir_lower_variable_initializers, nir_var_function_temp);
NIR_PASS_V(nir, nir_lower_returns);
NIR_PASS_V(nir, nir_inline_functions);
NIR_PASS_V(nir, nir_opt_deref);
nir_validate_shader(nir, "clover after function inlining");
- NIR_PASS_V(nir, nir_lower_constant_initializers,
+ NIR_PASS_V(nir, nir_lower_variable_initializers,
static_cast<nir_variable_mode>(~nir_var_function_temp));
// copy propagate to prepare for lower_explicit_io
* inline functions. That way they get properly initialized at the top
* of the function and not at the top of its caller.
*/
- NIR_PASS_V(nir, nir_lower_constant_initializers, nir_var_function_temp);
+ NIR_PASS_V(nir, nir_lower_variable_initializers, nir_var_function_temp);
NIR_PASS_V(nir, nir_lower_returns);
NIR_PASS_V(nir, nir_inline_functions);
NIR_PASS_V(nir, nir_opt_deref);
* nir_remove_dead_variables and split_per_member_structs below see the
* corresponding stores.
*/
- NIR_PASS_V(nir, nir_lower_constant_initializers, ~0);
+ NIR_PASS_V(nir, nir_lower_variable_initializers, ~0);
/* Split member structs. We do this before lower_io_to_temporaries so that
* it doesn't lower system values to temporaries by accident.
* inline functions. That way they get properly initialized at the top
* of the function and not at the top of its caller.
*/
- NIR_PASS_V(nir, nir_lower_constant_initializers, nir_var_function_temp);
+ NIR_PASS_V(nir, nir_lower_variable_initializers, nir_var_function_temp);
NIR_PASS_V(nir, nir_lower_returns);
NIR_PASS_V(nir, nir_inline_functions);
NIR_PASS_V(nir, nir_opt_deref);