nir: Allow nir_lower_io() to only lower one type of variable.
We may want to use different type_size functions for (e.g.) inputs vs. uniforms. Passing in -1 for mode ignores this, handling all modes as before. Signed-off-by: Kenneth Graunke <kenneth@whitecape.org> Reviewed-by: Matt Turner <mattst88@gmail.com>
This commit is contained in:
@@ -1822,6 +1822,7 @@ void nir_assign_var_locations(struct exec_list *var_list,
|
|||||||
int (*type_size)(const struct glsl_type *));
|
int (*type_size)(const struct glsl_type *));
|
||||||
|
|
||||||
void nir_lower_io(nir_shader *shader,
|
void nir_lower_io(nir_shader *shader,
|
||||||
|
nir_variable_mode mode,
|
||||||
int (*type_size)(const struct glsl_type *));
|
int (*type_size)(const struct glsl_type *));
|
||||||
void nir_lower_vars_to_ssa(nir_shader *shader);
|
void nir_lower_vars_to_ssa(nir_shader *shader);
|
||||||
|
|
||||||
|
@@ -38,6 +38,7 @@ struct lower_io_state {
|
|||||||
nir_builder builder;
|
nir_builder builder;
|
||||||
void *mem_ctx;
|
void *mem_ctx;
|
||||||
int (*type_size)(const struct glsl_type *type);
|
int (*type_size)(const struct glsl_type *type);
|
||||||
|
nir_variable_mode mode;
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -154,9 +155,17 @@ nir_lower_io_block(nir_block *block, void *void_state)
|
|||||||
|
|
||||||
nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
|
nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
|
||||||
|
|
||||||
|
if (intrin->intrinsic != nir_intrinsic_load_var &&
|
||||||
|
intrin->intrinsic != nir_intrinsic_store_var)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
nir_variable_mode mode = intrin->variables[0]->var->data.mode;
|
||||||
|
|
||||||
|
if (state->mode != -1 && state->mode != mode)
|
||||||
|
continue;
|
||||||
|
|
||||||
switch (intrin->intrinsic) {
|
switch (intrin->intrinsic) {
|
||||||
case nir_intrinsic_load_var: {
|
case nir_intrinsic_load_var: {
|
||||||
nir_variable_mode mode = intrin->variables[0]->var->data.mode;
|
|
||||||
if (mode != nir_var_shader_in && mode != nir_var_uniform)
|
if (mode != nir_var_shader_in && mode != nir_var_uniform)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -239,12 +248,15 @@ nir_lower_io_block(nir_block *block, void *void_state)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
nir_lower_io_impl(nir_function_impl *impl, int(*type_size)(const struct glsl_type *))
|
nir_lower_io_impl(nir_function_impl *impl,
|
||||||
|
nir_variable_mode mode,
|
||||||
|
int (*type_size)(const struct glsl_type *))
|
||||||
{
|
{
|
||||||
struct lower_io_state state;
|
struct lower_io_state state;
|
||||||
|
|
||||||
nir_builder_init(&state.builder, impl);
|
nir_builder_init(&state.builder, impl);
|
||||||
state.mem_ctx = ralloc_parent(impl);
|
state.mem_ctx = ralloc_parent(impl);
|
||||||
|
state.mode = mode;
|
||||||
state.type_size = type_size;
|
state.type_size = type_size;
|
||||||
|
|
||||||
nir_foreach_block(impl, nir_lower_io_block, &state);
|
nir_foreach_block(impl, nir_lower_io_block, &state);
|
||||||
@@ -254,10 +266,11 @@ nir_lower_io_impl(nir_function_impl *impl, int(*type_size)(const struct glsl_typ
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
nir_lower_io(nir_shader *shader, int(*type_size)(const struct glsl_type *))
|
nir_lower_io(nir_shader *shader, nir_variable_mode mode,
|
||||||
|
int (*type_size)(const struct glsl_type *))
|
||||||
{
|
{
|
||||||
nir_foreach_overload(shader, overload) {
|
nir_foreach_overload(shader, overload) {
|
||||||
if (overload->impl)
|
if (overload->impl)
|
||||||
nir_lower_io_impl(overload->impl, type_size);
|
nir_lower_io_impl(overload->impl, mode, type_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -128,7 +128,7 @@ brw_create_nir(struct brw_context *brw,
|
|||||||
type_size_scalar);
|
type_size_scalar);
|
||||||
nir_assign_var_locations(&nir->inputs, &nir->num_inputs, type_size_scalar);
|
nir_assign_var_locations(&nir->inputs, &nir->num_inputs, type_size_scalar);
|
||||||
nir_assign_var_locations(&nir->outputs, &nir->num_outputs, type_size_scalar);
|
nir_assign_var_locations(&nir->outputs, &nir->num_outputs, type_size_scalar);
|
||||||
nir_lower_io(nir, type_size_scalar);
|
nir_lower_io(nir, -1, type_size_scalar);
|
||||||
} else {
|
} else {
|
||||||
nir_assign_var_locations(&nir->uniforms,
|
nir_assign_var_locations(&nir->uniforms,
|
||||||
&nir->num_uniforms,
|
&nir->num_uniforms,
|
||||||
@@ -139,7 +139,7 @@ brw_create_nir(struct brw_context *brw,
|
|||||||
foreach_list_typed(nir_variable, var, node, &nir->outputs)
|
foreach_list_typed(nir_variable, var, node, &nir->outputs)
|
||||||
var->data.driver_location = var->data.location;
|
var->data.driver_location = var->data.location;
|
||||||
|
|
||||||
nir_lower_io(nir, type_size_vec4);
|
nir_lower_io(nir, -1, type_size_vec4);
|
||||||
}
|
}
|
||||||
|
|
||||||
nir_validate_shader(nir);
|
nir_validate_shader(nir);
|
||||||
|
Reference in New Issue
Block a user