[Mesa-dev] [PATCH 04/14] i965/scalar_visitor: Add init function

Kenneth Graunke kenneth at whitecape.org
Tue Sep 2 11:49:29 PDT 2014


On Monday, September 01, 2014 09:44:28 AM Jordan Justen wrote:
> This common init routine can be used by constructors for multiple program
> types.
> 
> Signed-off-by: Jordan Justen <jordan.l.justen at intel.com>
> ---
>  src/mesa/drivers/dri/i965/brw_scalar.h           | 1 +
>  src/mesa/drivers/dri/i965/brw_scalar_visitor.cpp | 6 ++++++
>  2 files changed, 7 insertions(+)
> 
> diff --git a/src/mesa/drivers/dri/i965/brw_scalar.h b/src/mesa/drivers/dri/i965/brw_scalar.h
> index b60c6d2..7d3ebdb 100644
> --- a/src/mesa/drivers/dri/i965/brw_scalar.h
> +++ b/src/mesa/drivers/dri/i965/brw_scalar.h
> @@ -215,6 +215,7 @@ public:
>                    struct gl_fragment_program *fp,
>                    unsigned dispatch_width);
>     ~scalar_visitor();
> +   void init();
>  
>     fs_reg *variable_storage(ir_variable *var);
>     int virtual_grf_alloc(int size);
> diff --git a/src/mesa/drivers/dri/i965/brw_scalar_visitor.cpp b/src/mesa/drivers/dri/i965/brw_scalar_visitor.cpp
> index 5eadb1e..9616b2a 100644
> --- a/src/mesa/drivers/dri/i965/brw_scalar_visitor.cpp
> +++ b/src/mesa/drivers/dri/i965/brw_scalar_visitor.cpp
> @@ -3262,6 +3262,12 @@ scalar_visitor::scalar_visitor(struct brw_context *brw,
>  {
>     this->fp = fp;
>     this->mem_ctx = mem_ctx;
> +   init();
> +}
> +
> +void
> +scalar_visitor::init()
> +{
>     this->failed = false;
>     this->simd16_unsupported = false;
>     this->no16_msg = NULL;
> 

I don't see why this is necessary.  If you're planning to go the subclass route, where you have:

  scalar_visitor
     |--> fs_visitor
     |--> compute_visitor
     |--> scalar_vs_visitor

Then the constructors for compute_visitor etc. can just call the constructor for scalar_visitor using an initialization list.

The reason we use this approach in fs_reg is because we wanted to share code between multiple constructors for a single class; IIRC constructors can't call sibling constructors.  But you can definitely call parent constructors.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20140902/b81a7061/attachment.sig>


More information about the mesa-dev mailing list