struct lower_io_state {
nir_builder builder;
- void *mem_ctx;
int (*type_size)(const struct glsl_type *type);
nir_variable_mode modes;
nir_lower_io_options options;
nir_foreach_variable(var, var_list) {
/*
- * UBO's have their own address spaces, so don't count them towards the
+ * UBOs have their own address spaces, so don't count them towards the
* number of global uniforms
*/
if ((var->data.mode == nir_var_uniform || var->data.mode == nir_var_shader_storage) &&
* (such as geometry shader inputs).
*/
bool
-nir_is_per_vertex_io(nir_variable *var, gl_shader_stage stage)
+nir_is_per_vertex_io(const nir_variable *var, gl_shader_stage stage)
{
if (var->data.patch || !glsl_type_is_array(var->type))
return false;
nir_intrinsic_op op;
switch (mode) {
case nir_var_shader_in:
- if (nir->stage == MESA_SHADER_FRAGMENT &&
+ if (nir->info.stage == MESA_SHADER_FRAGMENT &&
nir->options->use_interpolated_input_intrinsics &&
var->data.interpolation != INTERP_MODE_FLAT) {
assert(vertex_index == NULL);
unreachable("Unknown variable mode");
}
- nir_intrinsic_instr *load = nir_intrinsic_instr_create(state->mem_ctx, op);
+ nir_intrinsic_instr *load =
+ nir_intrinsic_instr_create(state->builder.shader, op);
load->num_components = intrin->num_components;
nir_intrinsic_set_base(load, var->data.driver_location);
nir_intrinsic_store_output;
}
- nir_intrinsic_instr *store = nir_intrinsic_instr_create(state->mem_ctx, op);
+ nir_intrinsic_instr *store =
+ nir_intrinsic_instr_create(state->builder.shader, op);
store->num_components = intrin->num_components;
nir_src_copy(&store->src[0], &intrin->src[0], store);
}
nir_intrinsic_instr *atomic =
- nir_intrinsic_instr_create(state->mem_ctx, op);
+ nir_intrinsic_instr_create(state->builder.shader, op);
nir_intrinsic_set_base(atomic, var->data.driver_location);
}
nir_intrinsic_instr *bary_setup =
- nir_intrinsic_instr_create(state->mem_ctx, bary_op);
+ nir_intrinsic_instr_create(state->builder.shader, bary_op);
nir_ssa_dest_init(&bary_setup->instr, &bary_setup->dest, 2, 32, NULL);
nir_intrinsic_set_interp_mode(bary_setup, var->data.interpolation);
nir_builder_instr_insert(&state->builder, &bary_setup->instr);
nir_intrinsic_instr *load =
- nir_intrinsic_instr_create(state->mem_ctx,
+ nir_intrinsic_instr_create(state->builder.shader,
nir_intrinsic_load_interpolated_input);
load->num_components = intrin->num_components;
{
nir_builder *b = &state->builder;
const nir_shader_compiler_options *options = b->shader->options;
+ bool progress = false;
nir_foreach_instr_safe(instr, block) {
if (instr->type != nir_instr_type_intrinsic)
b->cursor = nir_before_instr(instr);
- const bool per_vertex = nir_is_per_vertex_io(var, b->shader->stage);
+ const bool per_vertex = nir_is_per_vertex_io(var, b->shader->info.stage);
nir_ssa_def *offset;
nir_ssa_def *vertex_index = NULL;
nir_ssa_def_rewrite_uses(&intrin->dest.ssa,
nir_src_for_ssa(&replacement->dest.ssa));
} else {
- nir_dest_copy(&replacement->dest, &intrin->dest, state->mem_ctx);
+ nir_dest_copy(&replacement->dest, &intrin->dest, &intrin->instr);
}
}
nir_instr_insert_before(&intrin->instr, &replacement->instr);
nir_instr_remove(&intrin->instr);
+ progress = true;
}
- return true;
+ return progress;
}
-static void
+static bool
nir_lower_io_impl(nir_function_impl *impl,
nir_variable_mode modes,
int (*type_size)(const struct glsl_type *),
nir_lower_io_options options)
{
struct lower_io_state state;
+ bool progress = false;
nir_builder_init(&state.builder, impl);
- state.mem_ctx = ralloc_parent(impl);
state.modes = modes;
state.type_size = type_size;
state.options = options;
nir_foreach_block(block, impl) {
- nir_lower_io_block(block, &state);
+ progress |= nir_lower_io_block(block, &state);
}
nir_metadata_preserve(impl, nir_metadata_block_index |
nir_metadata_dominance);
+ return progress;
}
-void
+bool
nir_lower_io(nir_shader *shader, nir_variable_mode modes,
int (*type_size)(const struct glsl_type *),
nir_lower_io_options options)
{
+ bool progress = false;
+
nir_foreach_function(function, shader) {
if (function->impl) {
- nir_lower_io_impl(function->impl, modes, type_size, options);
+ progress |= nir_lower_io_impl(function->impl, modes,
+ type_size, options);
}
}
+
+ return progress;
}
/**
- * Return the offset soruce for a load/store intrinsic.
+ * Return the offset source for a load/store intrinsic.
*/
nir_src *
nir_get_io_offset_src(nir_intrinsic_instr *instr)