<p dir="ltr"><br>
On Aug 19, 2015 6:45 AM, "Francisco Jerez" <<a href="mailto:currojerez@riseup.net">currojerez@riseup.net</a>> wrote:<br>
><br>
> Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>> writes:<br>
><br>
> > On Aug 19, 2015 2:56 AM, "Francisco Jerez" <<a href="mailto:currojerez@riseup.net">currojerez@riseup.net</a>> wrote:<br>
> >><br>
> >> Jason Ekstrand <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>> writes:<br>
> >><br>
> >> > Previously, setting up image uniforms relied on being called after<br>
> >> > fs_visitor::uniforms was set and with fs_visitor::uniforms not<br>
> > allocating<br>
> >> > space for it.  This made sense in an ir_visitor world because the<br>
> > visitor<br>
> >> > assigns locations and uploads data as it walks through the variables.<br>
> > In<br>
> >> > NIR it also happened to work because nir_lower_io assumed zero space for<br>
> >> > images.  In the near future, we will be able to reserve space using<br>
> >> > nir_lower_io and these invariants will be broken.<br>
> >> ><br>
> >> > This commit makes setup_image_uniforms take a pointer to the location in<br>
> >> > the prog_data params array that indicates where the image uniforms<br>
> > should<br>
> >> > be stored.  This way it can be called from anywhere in the shader setup.<br>
> >> ><br>
> >> > v2: Fix nir_setup_uniform to correctly correspond with this change<br>
> >> >     (rebase fail)<br>
> >> ><br>
> >> > Cc: Francisco Jerez <<a href="mailto:currojerez@riseup.net">currojerez@riseup.net</a>><br>
> >> > Cc: Kenneth Graunke <<a href="mailto:kenneth@whitecape.org">kenneth@whitecape.org</a>><br>
> >> > ---<br>
> >> >  src/mesa/drivers/dri/i965/brw_fs.cpp     | 12 ------------<br>
> >> >  src/mesa/drivers/dri/i965/brw_fs.h       |  3 ---<br>
> >> >  src/mesa/drivers/dri/i965/brw_fs_nir.cpp |  6 ++++--<br>
> >> >  src/mesa/drivers/dri/i965/brw_shader.cpp | 28<br>
> > +++++++++++++++++++++-------<br>
> >> >  src/mesa/drivers/dri/i965/brw_shader.h   |  5 ++---<br>
> >> >  5 files changed, 27 insertions(+), 27 deletions(-)<br>
> >> ><br>
> >> > diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp<br>
> > b/src/mesa/drivers/dri/i965/brw_fs.cpp<br>
> >> > index 82cb499..d1550e6 100644<br>
> >> > --- a/src/mesa/drivers/dri/i965/brw_fs.cpp<br>
> >> > +++ b/src/mesa/drivers/dri/i965/brw_fs.cpp<br>
> >> > @@ -942,18 +942,6 @@ fs_visitor::import_uniforms(fs_visitor *v)<br>
> >> >     this->param_size = v->param_size;<br>
> >> >  }<br>
> >> ><br>
> >> > -void<br>
> >> > -fs_visitor::setup_vector_uniform_values(const gl_constant_value<br>
> > *values, unsigned n)<br>
> >> > -{<br>
> >> > -   static const gl_constant_value zero = { 0 };<br>
> >> > -<br>
> >> > -   for (unsigned i = 0; i < n; ++i)<br>
> >> > -      stage_prog_data->param[uniforms++] = &values[i];<br>
> >> > -<br>
> >> > -   for (unsigned i = n; i < 4; ++i)<br>
> >> > -      stage_prog_data->param[uniforms++] = &zero;<br>
> >> > -}<br>
> >> > -<br>
> >> >  fs_reg *<br>
> >> >  fs_visitor::emit_fragcoord_interpolation(bool pixel_center_integer,<br>
> >> >                                           bool origin_upper_left)<br>
> >> > diff --git a/src/mesa/drivers/dri/i965/brw_fs.h<br>
> > b/src/mesa/drivers/dri/i965/brw_fs.h<br>
> >> > index 975183e..28fcfa3 100644<br>
> >> > --- a/src/mesa/drivers/dri/i965/brw_fs.h<br>
> >> > +++ b/src/mesa/drivers/dri/i965/brw_fs.h<br>
> >> > @@ -291,9 +291,6 @@ public:<br>
> >> ><br>
> >> >     struct brw_reg interp_reg(int location, int channel);<br>
> >> ><br>
> >> > -   virtual void setup_vector_uniform_values(const gl_constant_value<br>
> > *values,<br>
> >> > -                                            unsigned n);<br>
> >> > -<br>
> >> >     int implied_mrf_writes(fs_inst *inst);<br>
> >> ><br>
> >> >     virtual void dump_instructions();<br>
> >> > diff --git a/src/mesa/drivers/dri/i965/brw_fs_nir.cpp<br>
> > b/src/mesa/drivers/dri/i965/brw_fs_nir.cpp<br>
> >> > index ce4153d..c8ea649 100644<br>
> >> > --- a/src/mesa/drivers/dri/i965/brw_fs_nir.cpp<br>
> >> > +++ b/src/mesa/drivers/dri/i965/brw_fs_nir.cpp<br>
> >> > @@ -244,10 +244,12 @@ fs_visitor::nir_setup_uniform(nir_variable *var)<br>
> >> >            * space for them here at the end of the parameter array.<br>
> >> >            */<br>
> >> >           var->data.driver_location = uniforms;<br>
> >> > -         param_size[uniforms] =<br>
> >> > +         unsigned size =<br>
> >> >              BRW_IMAGE_PARAM_SIZE * MAX2(storage->array_elements, 1);<br>
> >> ><br>
> >> > -         setup_image_uniform_values(storage);<br>
> >> > +         setup_image_uniform_values(stage_prog_data->param + uniforms,<br>
> > storage);<br>
> >> > +         param_size[uniforms] = size;<br>
> >> > +         uniforms += size;<br>
> >> >        } else {<br>
> >> >           unsigned slots = storage->type->component_slots();<br>
> >> >           if (storage->array_elements)<br>
> >> > diff --git a/src/mesa/drivers/dri/i965/brw_shader.cpp<br>
> > b/src/mesa/drivers/dri/i965/brw_shader.cpp<br>
> >> > index 6b92806..b31ae9b 100644<br>
> >> > --- a/src/mesa/drivers/dri/i965/brw_shader.cpp<br>
> >> > +++ b/src/mesa/drivers/dri/i965/brw_shader.cpp<br>
> >> > @@ -1419,8 +1419,22 @@<br>
> > backend_shader::assign_common_binding_table_offsets(uint32_t<br>
> > next_binding_table_<br>
> >> >     /* prog_data->base.binding_table.size will be set by<br>
> > brw_mark_surface_used. */<br>
> >> >  }<br>
> >> ><br>
> >> > +static void<br>
> >> > +setup_vector_uniform_values(const gl_constant_value ***dst,<br>
> >> > +                            const gl_constant_value *values, unsigned<br>
> > n)<br>
> >> > +{<br>
> >> > +   static const gl_constant_value zero = { 0 };<br>
> >> > +<br>
> >> > +   for (unsigned i = 0; i < n; ++i)<br>
> >> > +      *((*dst)++) = &values[i];<br>
> >> > +<br>
> >> > +   for (unsigned i = n; i < 4; ++i)<br>
> >> > +      *((*dst)++) = &zero;<br>
> >> > +}<br>
> >> > +<br>
> >> >  void<br>
> >> > -backend_shader::setup_image_uniform_values(const gl_uniform_storage<br>
> > *storage)<br>
> >> > +backend_shader::setup_image_uniform_values(const gl_constant_value<br>
> > **prog_param,<br>
> >> > +                                           const gl_uniform_storage<br>
> > *storage)<br>
> >> >  {<br>
> >> >     const unsigned stage =<br>
> > _mesa_program_enum_to_shader_stage(prog->Target);<br>
> >> ><br>
> >> > @@ -1431,17 +1445,17 @@<br>
> > backend_shader::setup_image_uniform_values(const gl_uniform_storage<br>
> > *storage)<br>
> >> >        /* Upload the brw_image_param structure.  The order is expected<br>
> > to match<br>
> >> >         * the BRW_IMAGE_PARAM_*_OFFSET defines.<br>
> >> >         */<br>
> >> > -      setup_vector_uniform_values(<br>
> >> > +      setup_vector_uniform_values(&prog_param,<br>
> >> >           (const gl_constant_value *)&param->surface_idx, 1);<br>
> >> > -      setup_vector_uniform_values(<br>
> >> > +      setup_vector_uniform_values(&prog_param,<br>
> >> >           (const gl_constant_value *)param->offset, 2);<br>
> >> > -      setup_vector_uniform_values(<br>
> >> > +      setup_vector_uniform_values(&prog_param,<br>
> >> >           (const gl_constant_value *)param->size, 3);<br>
> >> > -      setup_vector_uniform_values(<br>
> >> > +      setup_vector_uniform_values(&prog_param,<br>
> >> >           (const gl_constant_value *)param->stride, 4);<br>
> >> > -      setup_vector_uniform_values(<br>
> >> > +      setup_vector_uniform_values(&prog_param,<br>
> >> >           (const gl_constant_value *)param->tiling, 3);<br>
> >> > -      setup_vector_uniform_values(<br>
> >> > +      setup_vector_uniform_values(&prog_param,<br>
> >> >           (const gl_constant_value *)param->swizzling, 2);<br>
> >> ><br>
> >> >        brw_mark_surface_used(<br>
> >> > diff --git a/src/mesa/drivers/dri/i965/brw_shader.h<br>
> > b/src/mesa/drivers/dri/i965/brw_shader.h<br>
> >> > index 2cc97f2..2cd0a5a 100644<br>
> >> > --- a/src/mesa/drivers/dri/i965/brw_shader.h<br>
> >> > +++ b/src/mesa/drivers/dri/i965/brw_shader.h<br>
> >> > @@ -270,9 +270,8 @@ public:<br>
> >> ><br>
> >> >     virtual void invalidate_live_intervals() = 0;<br>
> >> ><br>
> >> > -   virtual void setup_vector_uniform_values(const gl_constant_value<br>
> > *values,<br>
> >> > -                                            unsigned n) = 0;<br>
> >> > -   void setup_image_uniform_values(const gl_uniform_storage *storage);<br>
> >> > +   void setup_image_uniform_values(const gl_constant_value<br>
> > **prog_param,<br>
> >> > +                                   const gl_uniform_storage *storage);<br>
> >> >  };<br>
> >> ><br>
> >> >  uint32_t brw_texture_offset(int *offsets, unsigned num_components);<br>
> >> > --<br>
> >> > 2.4.3<br>
> >><br>
> >> Did you notice that this makes<br>
> >> backend_shader::setup_image_uniform_values() FS-specific?  I think<br>
> >> passing the base uniform index where it should be set up would do what<br>
> >> you want and at the same time could be implemented in a backend-agnostic<br>
> >> way.<br>
> ><br>
> > How is this FS-specific? setup_vector_uniform_values was exactly the same<br>
> > code in both backends and the same as this static helper. They both have an<br>
> > array of params.  Am I missing something?<br>
><br>
> The VEC4 back-end additionally keeps track of the uniform vector sizes<br>
> in the uniform_vector_size[] array.</p>
<p dir="ltr">Right... Thanks for catching that. I'll have to think about it.</p>