From 3e63cf893f096a7263eb1856d58417dd2d170d4b Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Sat, 28 Oct 2017 08:57:23 -0700 Subject: intel/nir: Break the linking code into a helper in brw_nir.c Reviewed-by: Timothy Arceri Cc: mesa-stable@lists.freedesktop.org --- src/intel/compiler/brw_nir.c | 32 ++++++++++++++++++++++++++++++++ src/intel/compiler/brw_nir.h | 4 ++++ 2 files changed, 36 insertions(+) (limited to 'src/intel/compiler') diff --git a/src/intel/compiler/brw_nir.c b/src/intel/compiler/brw_nir.c index 821c38a8669..3f11fb77554 100644 --- a/src/intel/compiler/brw_nir.c +++ b/src/intel/compiler/brw_nir.c @@ -675,6 +675,38 @@ brw_preprocess_nir(const struct brw_compiler *compiler, nir_shader *nir) return nir; } +void +brw_nir_link_shaders(const struct brw_compiler *compiler, + nir_shader **producer, nir_shader **consumer) +{ + NIR_PASS_V(*producer, nir_remove_dead_variables, nir_var_shader_out); + NIR_PASS_V(*consumer, nir_remove_dead_variables, nir_var_shader_in); + + if (nir_remove_unused_varyings(*producer, *consumer)) { + NIR_PASS_V(*producer, nir_lower_global_vars_to_local); + NIR_PASS_V(*consumer, nir_lower_global_vars_to_local); + + nir_variable_mode indirect_mask = (nir_variable_mode) 0; + if (compiler->glsl_compiler_options[(*producer)->info.stage].EmitNoIndirectTemp) + indirect_mask = nir_var_local; + + /* The backend might not be able to handle indirects on + * temporaries so we need to lower indirects on any of the + * varyings we have demoted here. + */ + NIR_PASS_V(*producer, nir_lower_indirect_derefs, indirect_mask); + NIR_PASS_V(*consumer, nir_lower_indirect_derefs, indirect_mask); + + const bool p_is_scalar = + compiler->scalar_stage[(*producer)->info.stage]; + *producer = brw_nir_optimize(*producer, compiler, p_is_scalar); + + const bool c_is_scalar = + compiler->scalar_stage[(*producer)->info.stage]; + *consumer = brw_nir_optimize(*consumer, compiler, c_is_scalar); + } +} + /* Prepare the given shader for codegen * * This function is intended to be called right before going into the actual diff --git a/src/intel/compiler/brw_nir.h b/src/intel/compiler/brw_nir.h index 0118cfadc1f..e9cb6f89948 100644 --- a/src/intel/compiler/brw_nir.h +++ b/src/intel/compiler/brw_nir.h @@ -95,6 +95,10 @@ void brw_nir_analyze_boolean_resolves(nir_shader *nir); nir_shader *brw_preprocess_nir(const struct brw_compiler *compiler, nir_shader *nir); +void +brw_nir_link_shaders(const struct brw_compiler *compiler, + nir_shader **producer, nir_shader **consumer); + bool brw_nir_lower_cs_intrinsics(nir_shader *nir, unsigned dispatch_width); void brw_nir_lower_vs_inputs(nir_shader *nir, -- cgit v1.2.3