<p dir="ltr"><br>
On Nov 13, 2015 5:53 AM, "Iago Toral" <<a href="mailto:itoral@igalia.com">itoral@igalia.com</a>> wrote:<br>
><br>
> On Wed, 2015-11-11 at 17:26 -0800, Jason Ekstrand wrote:<br>
> > ---<br>
> > src/mesa/drivers/dri/i965/brw_fs.cpp | 11 +++++++++--<br>
> > src/mesa/drivers/dri/i965/brw_nir.c | 1 -<br>
> > src/mesa/drivers/dri/i965/brw_vec4.cpp | 5 ++++-<br>
> > src/mesa/drivers/dri/i965/brw_vec4_gs_visitor.cpp | 6 +++++-<br>
> > 4 files changed, 18 insertions(+), 5 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 ad94fa4..b8713ab 100644<br>
> > --- a/src/mesa/drivers/dri/i965/brw_fs.cpp<br>
> > +++ b/src/mesa/drivers/dri/i965/brw_fs.cpp<br>
> > @@ -43,6 +43,7 @@<br>
> > #include "brw_wm.h"<br>
> > #include "brw_fs.h"<br>
> > #include "brw_cs.h"<br>
> > +#include "brw_nir.h"<br>
> > #include "brw_vec4_gs_visitor.h"<br>
> > #include "brw_cfg.h"<br>
> > #include "brw_dead_control_flow.h"<br>
> > @@ -5459,13 +5460,16 @@ brw_compile_fs(const struct brw_compiler *compiler, void *log_data,<br>
> > void *mem_ctx,<br>
> > const struct brw_wm_prog_key *key,<br>
> > struct brw_wm_prog_data *prog_data,<br>
> > - const nir_shader *shader,<br>
> > + const nir_shader *src_shader,<br>
> > struct gl_program *prog,<br>
> > int shader_time_index8, int shader_time_index16,<br>
> > bool use_rep_send,<br>
> > unsigned *final_assembly_size,<br>
> > char **error_str)<br>
> > {<br>
> > + nir_shader *shader = nir_shader_clone(mem_ctx, src_shader);<br>
> > + brw_postprocess_nir(shader, compiler->devinfo, true);<br>
> > +<br>
><br>
> Maybe it is a silly question, but why do we need to clone the shader to<br>
> do this?</p>
<p dir="ltr">Because brw_compile_foo may be called multiple times on the same shader source. Since brw_postprocess_nir alters the shader source, we need to make a copy.</p>
<p dir="ltr">> > /* key->alpha_test_func means simulating alpha testing via discards,<br>
> > * so the shader definitely kills pixels.<br>
> > */<br>
> > @@ -5618,11 +5622,14 @@ brw_compile_cs(const struct brw_compiler *compiler, void *log_data,<br>
> > void *mem_ctx,<br>
> > const struct brw_cs_prog_key *key,<br>
> > struct brw_cs_prog_data *prog_data,<br>
> > - const nir_shader *shader,<br>
> > + const nir_shader *src_shader,<br>
> > int shader_time_index,<br>
> > unsigned *final_assembly_size,<br>
> > char **error_str)<br>
> > {<br>
> > + nir_shader *shader = nir_shader_clone(mem_ctx, src_shader);<br>
> > + brw_postprocess_nir(shader, compiler->devinfo, true);<br>
> > +<br>
> > prog_data->local_size[0] = shader->info.cs.local_size[0];<br>
> > prog_data->local_size[1] = shader->info.cs.local_size[1];<br>
> > prog_data->local_size[2] = shader->info.cs.local_size[2];<br>
> > diff --git a/src/mesa/drivers/dri/i965/brw_nir.c b/src/mesa/drivers/dri/i965/brw_nir.c<br>
> > index 21c2648..693b9cd 100644<br>
> > --- a/src/mesa/drivers/dri/i965/brw_nir.c<br>
> > +++ b/src/mesa/drivers/dri/i965/brw_nir.c<br>
> > @@ -391,7 +391,6 @@ brw_create_nir(struct brw_context *brw,<br>
> ><br>
> > brw_preprocess_nir(nir, is_scalar);<br>
> > brw_lower_nir(nir, devinfo, shader_prog, is_scalar);<br>
> > - brw_postprocess_nir(nir, devinfo, is_scalar);<br>
> ><br>
> > return nir;<br>
> > }<br>
> > diff --git a/src/mesa/drivers/dri/i965/brw_vec4.cpp b/src/mesa/drivers/dri/i965/brw_vec4.cpp<br>
> > index 8350a02..9f75bb6 100644<br>
> > --- a/src/mesa/drivers/dri/i965/brw_vec4.cpp<br>
> > +++ b/src/mesa/drivers/dri/i965/brw_vec4.cpp<br>
> > @@ -2028,13 +2028,16 @@ brw_compile_vs(const struct brw_compiler *compiler, void *log_data,<br>
> > void *mem_ctx,<br>
> > const struct brw_vs_prog_key *key,<br>
> > struct brw_vs_prog_data *prog_data,<br>
> > - const nir_shader *shader,<br>
> > + const nir_shader *src_shader,<br>
> > gl_clip_plane *clip_planes,<br>
> > bool use_legacy_snorm_formula,<br>
> > int shader_time_index,<br>
> > unsigned *final_assembly_size,<br>
> > char **error_str)<br>
> > {<br>
> > + nir_shader *shader = nir_shader_clone(mem_ctx, src_shader);<br>
> > + brw_postprocess_nir(shader, compiler->devinfo, compiler->scalar_vs);<br>
> > +<br>
> > const unsigned *assembly = NULL;<br>
> ><br>
> > unsigned nr_attributes = _mesa_bitcount_64(prog_data->inputs_read);<br>
> > diff --git a/src/mesa/drivers/dri/i965/brw_vec4_gs_visitor.cpp b/src/mesa/drivers/dri/i965/brw_vec4_gs_visitor.cpp<br>
> > index 49c1083..92b15d9 100644<br>
> > --- a/src/mesa/drivers/dri/i965/brw_vec4_gs_visitor.cpp<br>
> > +++ b/src/mesa/drivers/dri/i965/brw_vec4_gs_visitor.cpp<br>
> > @@ -30,6 +30,7 @@<br>
> > #include "brw_vec4_gs_visitor.h"<br>
> > #include "gen6_gs_visitor.h"<br>
> > #include "brw_fs.h"<br>
> > +#include "brw_nir.h"<br>
> ><br>
> > namespace brw {<br>
> ><br>
> > @@ -604,7 +605,7 @@ brw_compile_gs(const struct brw_compiler *compiler, void *log_data,<br>
> > void *mem_ctx,<br>
> > const struct brw_gs_prog_key *key,<br>
> > struct brw_gs_prog_data *prog_data,<br>
> > - const nir_shader *shader,<br>
> > + const nir_shader *src_shader,<br>
> > struct gl_shader_program *shader_prog,<br>
> > int shader_time_index,<br>
> > unsigned *final_assembly_size,<br>
> > @@ -614,6 +615,9 @@ brw_compile_gs(const struct brw_compiler *compiler, void *log_data,<br>
> > memset(&c, 0, sizeof(c));<br>
> > c.key = *key;<br>
> ><br>
> > + nir_shader *shader = nir_shader_clone(mem_ctx, src_shader);<br>
> > + brw_postprocess_nir(shader, compiler->devinfo, compiler->scalar_gs);<br>
> > +<br>
> > prog_data->include_primitive_id =<br>
> > (shader->info.inputs_read & VARYING_BIT_PRIMITIVE_ID) != 0;<br>
> ><br>
><br>
><br>
</p>