#include "program/prog_to_nir.h"
static void
-nir_optimize(nir_shader *nir)
+nir_optimize(nir_shader *nir, bool is_scalar)
{
bool progress;
do {
progress = false;
nir_lower_vars_to_ssa(nir);
nir_validate_shader(nir);
- nir_lower_alu_to_scalar(nir);
- nir_validate_shader(nir);
+
+ if (is_scalar) {
+ nir_lower_alu_to_scalar(nir);
+ nir_validate_shader(nir);
+ }
+
progress |= nir_copy_prop(nir);
nir_validate_shader(nir);
- nir_lower_phis_to_scalar(nir);
- nir_validate_shader(nir);
+
+ if (is_scalar) {
+ nir_lower_phis_to_scalar(nir);
+ nir_validate_shader(nir);
+ }
+
progress |= nir_copy_prop(nir);
nir_validate_shader(nir);
progress |= nir_opt_dce(nir);
nir_split_var_copies(nir);
nir_validate_shader(nir);
- nir_optimize(nir);
+ nir_optimize(nir, is_scalar);
/* Lower a bunch of stuff */
nir_lower_var_copies(nir);
nir_validate_shader(nir);
/* Get rid of split copies */
- nir_optimize(nir);
+ nir_optimize(nir, is_scalar);
+
+ if (is_scalar) {
+ nir_assign_var_locations_direct_first(nir, &nir->uniforms,
+ &nir->num_direct_uniforms,
+ &nir->num_uniforms,
+ is_scalar);
+ nir_assign_var_locations(&nir->outputs, &nir->num_outputs, is_scalar);
+ } else {
+ nir_assign_var_locations(&nir->uniforms,
+ &nir->num_uniforms,
+ is_scalar);
- nir_assign_var_locations_direct_first(nir, &nir->uniforms,
- &nir->num_direct_uniforms,
- &nir->num_uniforms,
- is_scalar);
+ foreach_list_typed(nir_variable, var, node, &nir->outputs)
+ var->data.driver_location = var->data.location;
+ }
nir_assign_var_locations(&nir->inputs, &nir->num_inputs, is_scalar);
- nir_assign_var_locations(&nir->outputs, &nir->num_outputs, is_scalar);
nir_lower_io(nir, is_scalar);
nir_lower_atomics(nir);
nir_validate_shader(nir);
- nir_optimize(nir);
+ nir_optimize(nir, is_scalar);
if (brw->gen >= 6) {
/* Try and fuse multiply-adds */
nir_print_shader(nir, stderr);
}
- nir_convert_from_ssa(nir, true);
+ nir_convert_from_ssa(nir, is_scalar);
nir_validate_shader(nir);
+ if (!is_scalar) {
+ nir_lower_vec_to_movs(nir);
+ nir_validate_shader(nir);
+ }
+
/* This is the last pass we run before we start emitting stuff. It
* determines when we need to insert boolean resolves on Gen <= 5. We
* run it last because it stashes data in instr->pass_flags and we don't
return nir;
}
+
+enum brw_reg_type
+brw_type_for_nir_type(nir_alu_type type)
+{
+ switch (type) {
+ case nir_type_unsigned:
+ return BRW_REGISTER_TYPE_UD;
+ case nir_type_bool:
+ case nir_type_int:
+ return BRW_REGISTER_TYPE_D;
+ case nir_type_float:
+ return BRW_REGISTER_TYPE_F;
+ default:
+ unreachable("unknown type");
+ }
+
+ return BRW_REGISTER_TYPE_F;
+}
+
+/* Returns the glsl_base_type corresponding to a nir_alu_type.
+ * This is used by both brw_vec4_nir and brw_fs_nir.
+ */
+enum glsl_base_type
+brw_glsl_base_type_for_nir_type(nir_alu_type type)
+{
+ switch (type) {
+ case nir_type_float:
+ return GLSL_TYPE_FLOAT;
+
+ case nir_type_int:
+ return GLSL_TYPE_INT;
+
+ case nir_type_unsigned:
+ return GLSL_TYPE_UINT;
+
+ default:
+ unreachable("bad type");
+ }
+}