[Mesa-dev] [PATCH 2/2] anv: pipeline: reorder NIR passes closer to the i965 driver

Lionel Landwerlin llandwerlin at gmail.com
Tue Aug 30 17:24:30 UTC 2016


While comparing similar programs on both the vulkan driver and i965 GL, like :

varying vec4 tex_coord;
varying vec4 color_in;

uniform sampler2D sampler;

vec4 temp;

void func()
{
  temp = texture2D(sampler, tex_coord) * color_in;
}

void main()
{
  func();
  temp = vec4(gl_PointCoord.x, gl_PointCoord.y, 0.0, 1.0);
  gl_FragColor = temp;
}

I noticed that 2 varyings were programmed on the Vulkan driver where the GL
driver only programs one. The difference between the GL driver and the
vulkan one seems to be that other optimization passes are applied before the
glsl_to_nir() transformation.

It seems that dead variables removal passes should be applied after inlining
functions and applying dead code elimination, otherwise variables might
still be used by code that isn't useful.

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
Cc: Jason Ekstrand <jason at jlekstrand.net>
---
 src/intel/vulkan/anv_pipeline.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/intel/vulkan/anv_pipeline.c b/src/intel/vulkan/anv_pipeline.c
index 451166e..bc7aa6e 100644
--- a/src/intel/vulkan/anv_pipeline.c
+++ b/src/intel/vulkan/anv_pipeline.c
@@ -157,10 +157,6 @@ anv_shader_compile_to_nir(struct anv_device *device,
       assert(exec_list_length(&nir->functions) == 1);
       entry_point->name = ralloc_strdup(entry_point, "main");
 
-      NIR_PASS_V(nir, nir_remove_dead_variables, nir_var_shader_in);
-      NIR_PASS_V(nir, nir_remove_dead_variables, nir_var_shader_out);
-      NIR_PASS_V(nir, nir_remove_dead_variables, nir_var_system_value);
-
       NIR_PASS_V(nir, nir_propagate_invariant);
 
       NIR_PASS_V(nir, nir_lower_io_to_temporaries, entry_point->impl,
@@ -174,6 +170,12 @@ anv_shader_compile_to_nir(struct anv_device *device,
 
    nir = brw_preprocess_nir(compiler, nir);
 
+   if (!module->nir) {
+      NIR_PASS_V(nir, nir_remove_dead_variables, nir_var_shader_in);
+      NIR_PASS_V(nir, nir_remove_dead_variables, nir_var_shader_out);
+      NIR_PASS_V(nir, nir_remove_dead_variables, nir_var_system_value);
+   }
+
    NIR_PASS_V(nir, nir_shader_gather_info, entry_point->impl);
 
    nir_variable_mode indirect_mask = 0;
-- 
2.9.3



More information about the mesa-dev mailing list