<p dir="ltr"><br>
On Nov 27, 2015 3:55 AM, "Juan A. Suarez Romero" <<a href="mailto:jasuarez@igalia.com">jasuarez@igalia.com</a>> wrote:<br>
><br>
> When using INTEL_DEBUG=optimizer, each optimizing step is dump to disk,<br>
> in a separate file.<br>
><br>
> But as fs_visitor::optimize() and vec4_visitor::run() are called more<br>
> than once, it ends up overwriting the files already on disk, loosing<br>
> then previous optimizer steps.<br>
><br>
> To avoid this, add a new static variable that tracks the global<br>
> iteration across the entire life of the program running.<br>
><br>
> v2: use atomic_inc() for the static variable (Jason).<br>
><br>
> v3: define local variable as const (Jason).<br>
><br>
> Signed-off-by: Juan A. Suarez Romero <<a href="mailto:jasuarez@igalia.com">jasuarez@igalia.com</a>><br>
> ---<br>
>  src/mesa/drivers/dri/i965/brw_fs.cpp   | 13 +++++++++----<br>
>  src/mesa/drivers/dri/i965/brw_vec4.cpp | 13 ++++++++-----<br>
>  2 files changed, 17 insertions(+), 9 deletions(-)<br>
><br>
> diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp<br>
> index 7904f4d..eee9e1d 100644<br>
> --- a/src/mesa/drivers/dri/i965/brw_fs.cpp<br>
> +++ b/src/mesa/drivers/dri/i965/brw_fs.cpp<br>
> @@ -39,6 +39,7 @@<br>
>  #include "brw_program.h"<br>
>  #include "brw_dead_control_flow.h"<br>
>  #include "glsl/nir/glsl_types.h"<br>
> +#include "util/u_atomic.h"<br>
><br>
>  using namespace brw;<br>
><br>
> @@ -4948,6 +4949,9 @@ fs_visitor::calculate_register_pressure()<br>
>  void<br>
>  fs_visitor::optimize()<br>
>  {<br>
> +   static int global_iteration_atomic = 0;<br>
> +   const int global_iteration = p_atomic_inc_return(&global_iteration_atomic);<br>
> +<br>
>     /* Start by validating the shader we currently have. */<br>
>     validate();<br>
><br>
> @@ -4978,8 +4982,9 @@ fs_visitor::optimize()<br>
>                                                                          \<br>
>        if (unlikely(INTEL_DEBUG & DEBUG_OPTIMIZER) && this_progress) {   \<br>
>           char filename[64];                                             \<br>
> -         snprintf(filename, 64, "%s%d-%s-%02d-%02d-" #pass,              \<br>
> -                  stage_abbrev, dispatch_width, nir-><a href="http://info.name">info.name</a>, iteration, pass_num); \<br>
> +         snprintf(filename, 64, "%s%d-%s-%02d-%02d-%02d-" #pass,        \<br>
> +                  stage_abbrev, dispatch_width, nir-><a href="http://info.name">info.name</a>,         \<br>
> +                  global_iteration, iteration, pass_num);               \<br>
>                                                                          \<br>
>           backend_shader::dump_instructions(filename);                   \<br>
>        }                                                                 \<br>
> @@ -4992,8 +4997,8 @@ fs_visitor::optimize()<br>
><br>
>     if (unlikely(INTEL_DEBUG & DEBUG_OPTIMIZER)) {<br>
>        char filename[64];<br>
> -      snprintf(filename, 64, "%s%d-%s-00-start",<br>
> -               stage_abbrev, dispatch_width, nir-><a href="http://info.name">info.name</a>);<br>
> +      snprintf(filename, 64, "%s%d-%s-%02d-00-00-start",<br>
> +               stage_abbrev, dispatch_width, nir-><a href="http://info.name">info.name</a>, global_iteration);<br>
><br>
>        backend_shader::dump_instructions(filename);<br>
>     }<br>
> diff --git a/src/mesa/drivers/dri/i965/brw_vec4.cpp b/src/mesa/drivers/dri/i965/brw_vec4.cpp<br>
> index 9a79d67..7909f1d 100644<br>
> --- a/src/mesa/drivers/dri/i965/brw_vec4.cpp<br>
> +++ b/src/mesa/drivers/dri/i965/brw_vec4.cpp<br>
> @@ -29,6 +29,7 @@<br>
>  #include "brw_vec4_live_variables.h"<br>
>  #include "brw_dead_control_flow.h"<br>
>  #include "program/prog_parameter.h"<br>
> +#include "util/u_atomic.h"<br>
><br>
>  #define MAX_INSTRUCTION (1 << 30)<br>
><br>
> @@ -1779,6 +1780,9 @@ vec4_visitor::convert_to_hw_regs()<br>
>  bool<br>
>  vec4_visitor::run()<br>
>  {<br>
> +   static int global_iteration_atomic = 0;<br>
> +   const int global_iteration = p_atomic_inc_return(&global_iteration_atomic);<br>
> +<br>
>     if (shader_time_index >= 0)<br>
>        emit_shader_time_begin();<br>
><br>
> @@ -1812,8 +1816,8 @@ vec4_visitor::run()<br>
>                                                                         \<br>
>        if (unlikely(INTEL_DEBUG & DEBUG_OPTIMIZER) && this_progress) {  \<br>
>           char filename[64];                                            \<br>
> -         snprintf(filename, 64, "%s-%s-%02d-%02d-" #pass,              \<br>
> -                  stage_abbrev, nir-><a href="http://info.name">info.name</a>, iteration, pass_num);  \<br>
> +         snprintf(filename, 64, "%s-%s-%02d-%02d-%02d-" #pass,         \<br>
> +                  stage_abbrev, nir-><a href="http://info.name">info.name</a>, global_iteration, iteration, pass_num); \<br>
>                                                                         \<br>
>           backend_shader::dump_instructions(filename);                  \<br>
>        }                                                                \<br>
> @@ -1822,11 +1826,10 @@ vec4_visitor::run()<br>
>        this_progress;                                                   \<br>
>     })<br>
><br>
> -</p>
<p dir="ltr">Unneeded white space change.</p>
<p dir="ltr">Other than that, this looks much better.</p>
<p dir="ltr">Reviewed-by: Jason Ekstrand <<a href="mailto:jason.ekstrand@intel.com">jason.ekstrand@intel.com</a>></p>
<p dir="ltr">I'd like to get Matt's OK before pushing anything though.  He may yet have a better idea about how to make things properly unique.</p>
<p dir="ltr">>     if (unlikely(INTEL_DEBUG & DEBUG_OPTIMIZER)) {<br>
>        char filename[64];<br>
> -      snprintf(filename, 64, "%s-%s-00-start",<br>
> -               stage_abbrev, nir-><a href="http://info.name">info.name</a>);<br>
> +      snprintf(filename, 64, "%s-%s-%02d-00-00-start",<br>
> +               stage_abbrev, nir-><a href="http://info.name">info.name</a>, global_iteration);<br>
><br>
>        backend_shader::dump_instructions(filename);<br>
>     }<br>
> --<br>
> 2.5.0<br>
><br>
> _______________________________________________<br>
> mesa-dev mailing list<br>
> <a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
> <a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</p>