[libcamera-devel,v2,09/11] libcamera: ipu3: Map buffers in IPA
diff mbox series

Message ID 20201229160318.77536-10-niklas.soderlund@ragnatech.se
State Superseded
Delegated to: Niklas Söderlund
Headers show
Series
  • libcamera: ipu3: Attach to an skeleton IPA
Related show

Commit Message

Niklas Söderlund Dec. 29, 2020, 4:03 p.m. UTC
Map and unmap the parameters and statistic buffers in the IPA when the
pipeline handler allocates and frees the buffers.

Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
---
 src/libcamera/pipeline/ipu3/ipu3.cpp | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

Comments

Jacopo Mondi Jan. 7, 2021, 4:37 p.m. UTC | #1
Hi Niklas,

On Tue, Dec 29, 2020 at 05:03:16PM +0100, Niklas Söderlund wrote:
> Map and unmap the parameters and statistic buffers in the IPA when the
> pipeline handler allocates and frees the buffers.
>
> Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
> ---
>  src/libcamera/pipeline/ipu3/ipu3.cpp | 26 ++++++++++++++++++++++++++
>  1 file changed, 26 insertions(+)
>
> diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp
> index 95f1b75dc8be5d40..141066c528890c8e 100644
> --- a/src/libcamera/pipeline/ipu3/ipu3.cpp
> +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp
> @@ -138,6 +138,8 @@ private:
>  	ImgUDevice imgu1_;
>  	MediaDevice *cio2MediaDev_;
>  	MediaDevice *imguMediaDev_;
> +
> +	std::vector<IPABuffer> ipaBuffers_;
>  };
>
>  IPU3CameraConfiguration::IPU3CameraConfiguration(IPU3CameraData *data)
> @@ -583,6 +585,23 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera)
>  	if (ret < 0)
>  		return ret;
>
> +	/* Map buffers to the IPA. */
> +	unsigned int ipaBufferId = 1;
> +
> +	for (const std::unique_ptr<FrameBuffer> &buffer : imgu->paramBuffers_) {
> +		buffer->setCookie(ipaBufferId++);
> +		ipaBuffers_.push_back({ .id = buffer->cookie(),

You can reserve space in ipaBuffers_

> +					.planes = buffer->planes() });
> +	}
> +
> +	for (const std::unique_ptr<FrameBuffer> &buffer : imgu->statBuffers_) {
> +		buffer->setCookie(ipaBufferId++);
> +		ipaBuffers_.push_back({ .id = buffer->cookie(),
> +					.planes = buffer->planes() });
> +	}
> +
> +	data->ipa_->mapBuffers(ipaBuffers_);
> +
>  	return 0;
>  }
>
> @@ -590,6 +609,13 @@ int PipelineHandlerIPU3::freeBuffers(Camera *camera)
>  {
>  	IPU3CameraData *data = cameraData(camera);
>
> +	std::vector<unsigned int> ids;

You can reserve(ipaBuffers_.size())

> +	for (IPABuffer &ipabuf : ipaBuffers_)
> +		ids.push_back(ipabuf.id);
> +
> +	data->ipa_->unmapBuffers(ids);
> +	ipaBuffers_.clear();
> +

Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>

Thanks
  j

>  	data->imgu_->freeBuffers();
>
>  	return 0;
> --
> 2.29.2
>
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel
Laurent Pinchart Jan. 10, 2021, 7:25 p.m. UTC | #2
Hi Niklas,

Thank you for the patch.

On Thu, Jan 07, 2021 at 05:37:01PM +0100, Jacopo Mondi wrote:
> On Tue, Dec 29, 2020 at 05:03:16PM +0100, Niklas Söderlund wrote:
> > Map and unmap the parameters and statistic buffers in the IPA when the
> > pipeline handler allocates and frees the buffers.
> >
> > Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
> > ---
> >  src/libcamera/pipeline/ipu3/ipu3.cpp | 26 ++++++++++++++++++++++++++
> >  1 file changed, 26 insertions(+)
> >
> > diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp
> > index 95f1b75dc8be5d40..141066c528890c8e 100644
> > --- a/src/libcamera/pipeline/ipu3/ipu3.cpp
> > +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp
> > @@ -138,6 +138,8 @@ private:
> >  	ImgUDevice imgu1_;
> >  	MediaDevice *cio2MediaDev_;
> >  	MediaDevice *imguMediaDev_;
> > +
> > +	std::vector<IPABuffer> ipaBuffers_;
> >  };
> >
> >  IPU3CameraConfiguration::IPU3CameraConfiguration(IPU3CameraData *data)
> > @@ -583,6 +585,23 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera)
> >  	if (ret < 0)
> >  		return ret;
> >
> > +	/* Map buffers to the IPA. */
> > +	unsigned int ipaBufferId = 1;
> > +
> > +	for (const std::unique_ptr<FrameBuffer> &buffer : imgu->paramBuffers_) {
> > +		buffer->setCookie(ipaBufferId++);
> > +		ipaBuffers_.push_back({ .id = buffer->cookie(),
> 
> You can reserve space in ipaBuffers_
> 
> > +					.planes = buffer->planes() });
> > +	}
> > +
> > +	for (const std::unique_ptr<FrameBuffer> &buffer : imgu->statBuffers_) {
> > +		buffer->setCookie(ipaBufferId++);
> > +		ipaBuffers_.push_back({ .id = buffer->cookie(),
> > +					.planes = buffer->planes() });

		ipaBuffers_.push_back({
			.id = buffer->cookie(),
			.planes = buffer->planes()
		});

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> > +	}
> > +
> > +	data->ipa_->mapBuffers(ipaBuffers_);
> > +
> >  	return 0;
> >  }
> >
> > @@ -590,6 +609,13 @@ int PipelineHandlerIPU3::freeBuffers(Camera *camera)
> >  {
> >  	IPU3CameraData *data = cameraData(camera);
> >
> > +	std::vector<unsigned int> ids;
> 
> You can reserve(ipaBuffers_.size())
> 
> > +	for (IPABuffer &ipabuf : ipaBuffers_)
> > +		ids.push_back(ipabuf.id);
> > +
> > +	data->ipa_->unmapBuffers(ids);
> > +	ipaBuffers_.clear();
> > +
> 
> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
> 
> >  	data->imgu_->freeBuffers();
> >
> >  	return 0;
Niklas Söderlund Feb. 3, 2021, 10:29 a.m. UTC | #3
Hi Jacopo,

Thanks for your comments.

On 2021-01-07 17:37:01 +0100, Jacopo Mondi wrote:
> Hi Niklas,
> 
> On Tue, Dec 29, 2020 at 05:03:16PM +0100, Niklas Söderlund wrote:
> > Map and unmap the parameters and statistic buffers in the IPA when the
> > pipeline handler allocates and frees the buffers.
> >
> > Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
> > ---
> >  src/libcamera/pipeline/ipu3/ipu3.cpp | 26 ++++++++++++++++++++++++++
> >  1 file changed, 26 insertions(+)
> >
> > diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp
> > index 95f1b75dc8be5d40..141066c528890c8e 100644
> > --- a/src/libcamera/pipeline/ipu3/ipu3.cpp
> > +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp
> > @@ -138,6 +138,8 @@ private:
> >  	ImgUDevice imgu1_;
> >  	MediaDevice *cio2MediaDev_;
> >  	MediaDevice *imguMediaDev_;
> > +
> > +	std::vector<IPABuffer> ipaBuffers_;
> >  };
> >
> >  IPU3CameraConfiguration::IPU3CameraConfiguration(IPU3CameraData *data)
> > @@ -583,6 +585,23 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera)
> >  	if (ret < 0)
> >  		return ret;
> >
> > +	/* Map buffers to the IPA. */
> > +	unsigned int ipaBufferId = 1;
> > +
> > +	for (const std::unique_ptr<FrameBuffer> &buffer : imgu->paramBuffers_) {
> > +		buffer->setCookie(ipaBufferId++);
> > +		ipaBuffers_.push_back({ .id = buffer->cookie(),
> 
> You can reserve space in ipaBuffers_

I could but I think it is a case of premature optimization as it makes 
the code harder to understand and as we know this will be redone with 
the new IPC framework I would like to have it as simple as possible 
until then.

> 
> > +					.planes = buffer->planes() });
> > +	}
> > +
> > +	for (const std::unique_ptr<FrameBuffer> &buffer : imgu->statBuffers_) {
> > +		buffer->setCookie(ipaBufferId++);
> > +		ipaBuffers_.push_back({ .id = buffer->cookie(),
> > +					.planes = buffer->planes() });
> > +	}
> > +
> > +	data->ipa_->mapBuffers(ipaBuffers_);
> > +
> >  	return 0;
> >  }
> >
> > @@ -590,6 +609,13 @@ int PipelineHandlerIPU3::freeBuffers(Camera *camera)
> >  {
> >  	IPU3CameraData *data = cameraData(camera);
> >
> > +	std::vector<unsigned int> ids;
> 
> You can reserve(ipaBuffers_.size())
> 
> > +	for (IPABuffer &ipabuf : ipaBuffers_)
> > +		ids.push_back(ipabuf.id);
> > +
> > +	data->ipa_->unmapBuffers(ids);
> > +	ipaBuffers_.clear();
> > +
> 
> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
> 
> Thanks
>   j
> 
> >  	data->imgu_->freeBuffers();
> >
> >  	return 0;
> > --
> > 2.29.2
> >
> > _______________________________________________
> > libcamera-devel mailing list
> > libcamera-devel@lists.libcamera.org
> > https://lists.libcamera.org/listinfo/libcamera-devel
Jacopo Mondi Feb. 3, 2021, 11:26 a.m. UTC | #4
Hi Niklas,

On Wed, Feb 03, 2021 at 11:29:52AM +0100, Niklas Söderlund wrote:
> Hi Jacopo,
>
> Thanks for your comments.
>
> On 2021-01-07 17:37:01 +0100, Jacopo Mondi wrote:
> > Hi Niklas,
> >
> > On Tue, Dec 29, 2020 at 05:03:16PM +0100, Niklas Söderlund wrote:
> > > Map and unmap the parameters and statistic buffers in the IPA when the
> > > pipeline handler allocates and frees the buffers.
> > >
> > > Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
> > > ---
> > >  src/libcamera/pipeline/ipu3/ipu3.cpp | 26 ++++++++++++++++++++++++++
> > >  1 file changed, 26 insertions(+)
> > >
> > > diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp
> > > index 95f1b75dc8be5d40..141066c528890c8e 100644
> > > --- a/src/libcamera/pipeline/ipu3/ipu3.cpp
> > > +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp
> > > @@ -138,6 +138,8 @@ private:
> > >  	ImgUDevice imgu1_;
> > >  	MediaDevice *cio2MediaDev_;
> > >  	MediaDevice *imguMediaDev_;
> > > +
> > > +	std::vector<IPABuffer> ipaBuffers_;
> > >  };
> > >
> > >  IPU3CameraConfiguration::IPU3CameraConfiguration(IPU3CameraData *data)
> > > @@ -583,6 +585,23 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera)
> > >  	if (ret < 0)
> > >  		return ret;
> > >
> > > +	/* Map buffers to the IPA. */
> > > +	unsigned int ipaBufferId = 1;
> > > +
> > > +	for (const std::unique_ptr<FrameBuffer> &buffer : imgu->paramBuffers_) {
> > > +		buffer->setCookie(ipaBufferId++);
> > > +		ipaBuffers_.push_back({ .id = buffer->cookie(),
> >
> > You can reserve space in ipaBuffers_
>
> I could but I think it is a case of premature optimization as it makes
> the code harder to understand and as we know this will be redone with
> the new IPC framework I would like to have it as simple as possible
> until then.
>

My understanding is that all it takes is a:

        ipaBuffers_.reserve(imgu->paramBuffers_.size());

before the for loop. I might be mistaken as from your words I get it's
more complex than what I think it might be.

> >
> > > +					.planes = buffer->planes() });
> > > +	}
> > > +
> > > +	for (const std::unique_ptr<FrameBuffer> &buffer : imgu->statBuffers_) {
> > > +		buffer->setCookie(ipaBufferId++);
> > > +		ipaBuffers_.push_back({ .id = buffer->cookie(),
> > > +					.planes = buffer->planes() });
> > > +	}
> > > +
> > > +	data->ipa_->mapBuffers(ipaBuffers_);
> > > +
> > >  	return 0;
> > >  }
> > >
> > > @@ -590,6 +609,13 @@ int PipelineHandlerIPU3::freeBuffers(Camera *camera)
> > >  {
> > >  	IPU3CameraData *data = cameraData(camera);
> > >
> > > +	std::vector<unsigned int> ids;
> >
> > You can reserve(ipaBuffers_.size())
> >
> > > +	for (IPABuffer &ipabuf : ipaBuffers_)
> > > +		ids.push_back(ipabuf.id);
> > > +
> > > +	data->ipa_->unmapBuffers(ids);
> > > +	ipaBuffers_.clear();
> > > +
> >
> > Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
> >
> > Thanks
> >   j
> >
> > >  	data->imgu_->freeBuffers();
> > >
> > >  	return 0;
> > > --
> > > 2.29.2
> > >
> > > _______________________________________________
> > > libcamera-devel mailing list
> > > libcamera-devel@lists.libcamera.org
> > > https://lists.libcamera.org/listinfo/libcamera-devel
>
> --
> Regards,
> Niklas Söderlund
Niklas Söderlund Feb. 3, 2021, 12:16 p.m. UTC | #5
Hi Jacopo,

On 2021-02-03 12:26:02 +0100, Jacopo Mondi wrote:
> Hi Niklas,
> 
> On Wed, Feb 03, 2021 at 11:29:52AM +0100, Niklas Söderlund wrote:
> > Hi Jacopo,
> >
> > Thanks for your comments.
> >
> > On 2021-01-07 17:37:01 +0100, Jacopo Mondi wrote:
> > > Hi Niklas,
> > >
> > > On Tue, Dec 29, 2020 at 05:03:16PM +0100, Niklas Söderlund wrote:
> > > > Map and unmap the parameters and statistic buffers in the IPA when the
> > > > pipeline handler allocates and frees the buffers.
> > > >
> > > > Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
> > > > ---
> > > >  src/libcamera/pipeline/ipu3/ipu3.cpp | 26 ++++++++++++++++++++++++++
> > > >  1 file changed, 26 insertions(+)
> > > >
> > > > diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp
> > > > index 95f1b75dc8be5d40..141066c528890c8e 100644
> > > > --- a/src/libcamera/pipeline/ipu3/ipu3.cpp
> > > > +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp
> > > > @@ -138,6 +138,8 @@ private:
> > > >  	ImgUDevice imgu1_;
> > > >  	MediaDevice *cio2MediaDev_;
> > > >  	MediaDevice *imguMediaDev_;
> > > > +
> > > > +	std::vector<IPABuffer> ipaBuffers_;
> > > >  };
> > > >
> > > >  IPU3CameraConfiguration::IPU3CameraConfiguration(IPU3CameraData *data)
> > > > @@ -583,6 +585,23 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera)
> > > >  	if (ret < 0)
> > > >  		return ret;
> > > >
> > > > +	/* Map buffers to the IPA. */
> > > > +	unsigned int ipaBufferId = 1;
> > > > +
> > > > +	for (const std::unique_ptr<FrameBuffer> &buffer : imgu->paramBuffers_) {
> > > > +		buffer->setCookie(ipaBufferId++);
> > > > +		ipaBuffers_.push_back({ .id = buffer->cookie(),
> > >
> > > You can reserve space in ipaBuffers_
> >
> > I could but I think it is a case of premature optimization as it makes
> > the code harder to understand and as we know this will be redone with
> > the new IPC framework I would like to have it as simple as possible
> > until then.
> >
> 
> My understanding is that all it takes is a:
> 
>         ipaBuffers_.reserve(imgu->paramBuffers_.size());
> 
> before the for loop. I might be mistaken as from your words I get it's
> more complex than what I think it might be.

I think you are correct, the line you suggest is all that is needed. But 
whenever I read code that calls reserve() my internal red warning light 
turns on as I think the reserved() is invoked as one wish to directly 
access the continues memory of the object and not as a minor 
optimization. So to keep the re-workability of this code high I'm not 
keen to optimize it as-is. I do not feel strongly about it tho and will 
bow to public opinion.

> 
> > >
> > > > +					.planes = buffer->planes() });
> > > > +	}
> > > > +
> > > > +	for (const std::unique_ptr<FrameBuffer> &buffer : imgu->statBuffers_) {
> > > > +		buffer->setCookie(ipaBufferId++);
> > > > +		ipaBuffers_.push_back({ .id = buffer->cookie(),
> > > > +					.planes = buffer->planes() });
> > > > +	}
> > > > +
> > > > +	data->ipa_->mapBuffers(ipaBuffers_);
> > > > +
> > > >  	return 0;
> > > >  }
> > > >
> > > > @@ -590,6 +609,13 @@ int PipelineHandlerIPU3::freeBuffers(Camera *camera)
> > > >  {
> > > >  	IPU3CameraData *data = cameraData(camera);
> > > >
> > > > +	std::vector<unsigned int> ids;
> > >
> > > You can reserve(ipaBuffers_.size())
> > >
> > > > +	for (IPABuffer &ipabuf : ipaBuffers_)
> > > > +		ids.push_back(ipabuf.id);
> > > > +
> > > > +	data->ipa_->unmapBuffers(ids);
> > > > +	ipaBuffers_.clear();
> > > > +
> > >
> > > Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
> > >
> > > Thanks
> > >   j
> > >
> > > >  	data->imgu_->freeBuffers();
> > > >
> > > >  	return 0;
> > > > --
> > > > 2.29.2
> > > >
> > > > _______________________________________________
> > > > libcamera-devel mailing list
> > > > libcamera-devel@lists.libcamera.org
> > > > https://lists.libcamera.org/listinfo/libcamera-devel
> >
> > --
> > Regards,
> > Niklas Söderlund
Jacopo Mondi Feb. 3, 2021, 1:09 p.m. UTC | #6
Hi Niklas,

On Wed, Feb 03, 2021 at 01:16:36PM +0100, Niklas Söderlund wrote:
> Hi Jacopo,
>
> On 2021-02-03 12:26:02 +0100, Jacopo Mondi wrote:
> > Hi Niklas,
> >
> > On Wed, Feb 03, 2021 at 11:29:52AM +0100, Niklas Söderlund wrote:
> > > Hi Jacopo,
> > >
> > > Thanks for your comments.
> > >
> > > On 2021-01-07 17:37:01 +0100, Jacopo Mondi wrote:
> > > > Hi Niklas,
> > > >
> > > > On Tue, Dec 29, 2020 at 05:03:16PM +0100, Niklas Söderlund wrote:
> > > > > Map and unmap the parameters and statistic buffers in the IPA when the
> > > > > pipeline handler allocates and frees the buffers.
> > > > >
> > > > > Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
> > > > > ---
> > > > >  src/libcamera/pipeline/ipu3/ipu3.cpp | 26 ++++++++++++++++++++++++++
> > > > >  1 file changed, 26 insertions(+)
> > > > >
> > > > > diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp
> > > > > index 95f1b75dc8be5d40..141066c528890c8e 100644
> > > > > --- a/src/libcamera/pipeline/ipu3/ipu3.cpp
> > > > > +++ b/src/libcamera/pipeline/ipu3/ipu3.cpp
> > > > > @@ -138,6 +138,8 @@ private:
> > > > >  	ImgUDevice imgu1_;
> > > > >  	MediaDevice *cio2MediaDev_;
> > > > >  	MediaDevice *imguMediaDev_;
> > > > > +
> > > > > +	std::vector<IPABuffer> ipaBuffers_;
> > > > >  };
> > > > >
> > > > >  IPU3CameraConfiguration::IPU3CameraConfiguration(IPU3CameraData *data)
> > > > > @@ -583,6 +585,23 @@ int PipelineHandlerIPU3::allocateBuffers(Camera *camera)
> > > > >  	if (ret < 0)
> > > > >  		return ret;
> > > > >
> > > > > +	/* Map buffers to the IPA. */
> > > > > +	unsigned int ipaBufferId = 1;
> > > > > +
> > > > > +	for (const std::unique_ptr<FrameBuffer> &buffer : imgu->paramBuffers_) {
> > > > > +		buffer->setCookie(ipaBufferId++);
> > > > > +		ipaBuffers_.push_back({ .id = buffer->cookie(),
> > > >
> > > > You can reserve space in ipaBuffers_
> > >
> > > I could but I think it is a case of premature optimization as it makes
> > > the code harder to understand and as we know this will be redone with
> > > the new IPC framework I would like to have it as simple as possible
> > > until then.
> > >
> >
> > My understanding is that all it takes is a:
> >
> >         ipaBuffers_.reserve(imgu->paramBuffers_.size());
> >
> > before the for loop. I might be mistaken as from your words I get it's
> > more complex than what I think it might be.
>
> I think you are correct, the line you suggest is all that is needed. But
> whenever I read code that calls reserve() my internal red warning light
> turns on as I think the reserved() is invoked as one wish to directly
> access the continues memory of the object and not as a minor
> optimization. So to keep the re-workability of this code high I'm not
> keen to optimize it as-is. I do not feel strongly about it tho and will
> bow to public opinion.
>

Not sure I got entirely what you mean, but reserve() it's there mainly
to avoid relocations while adding elements to a vector of a known
size.

Up to you

> >
> > > >
> > > > > +					.planes = buffer->planes() });
> > > > > +	}
> > > > > +
> > > > > +	for (const std::unique_ptr<FrameBuffer> &buffer : imgu->statBuffers_) {
> > > > > +		buffer->setCookie(ipaBufferId++);
> > > > > +		ipaBuffers_.push_back({ .id = buffer->cookie(),
> > > > > +					.planes = buffer->planes() });
> > > > > +	}
> > > > > +
> > > > > +	data->ipa_->mapBuffers(ipaBuffers_);
> > > > > +
> > > > >  	return 0;
> > > > >  }
> > > > >
> > > > > @@ -590,6 +609,13 @@ int PipelineHandlerIPU3::freeBuffers(Camera *camera)
> > > > >  {
> > > > >  	IPU3CameraData *data = cameraData(camera);
> > > > >
> > > > > +	std::vector<unsigned int> ids;
> > > >
> > > > You can reserve(ipaBuffers_.size())
> > > >
> > > > > +	for (IPABuffer &ipabuf : ipaBuffers_)
> > > > > +		ids.push_back(ipabuf.id);
> > > > > +
> > > > > +	data->ipa_->unmapBuffers(ids);
> > > > > +	ipaBuffers_.clear();
> > > > > +
> > > >
> > > > Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
> > > >
> > > > Thanks
> > > >   j
> > > >
> > > > >  	data->imgu_->freeBuffers();
> > > > >
> > > > >  	return 0;
> > > > > --
> > > > > 2.29.2
> > > > >
> > > > > _______________________________________________
> > > > > libcamera-devel mailing list
> > > > > libcamera-devel@lists.libcamera.org
> > > > > https://lists.libcamera.org/listinfo/libcamera-devel
> > >
> > > --
> > > Regards,
> > > Niklas Söderlund
>
> --
> Regards,
> Niklas Söderlund

Patch
diff mbox series

diff --git a/src/libcamera/pipeline/ipu3/ipu3.cpp b/src/libcamera/pipeline/ipu3/ipu3.cpp
index 95f1b75dc8be5d40..141066c528890c8e 100644
--- a/src/libcamera/pipeline/ipu3/ipu3.cpp
+++ b/src/libcamera/pipeline/ipu3/ipu3.cpp
@@ -138,6 +138,8 @@  private:
 	ImgUDevice imgu1_;
 	MediaDevice *cio2MediaDev_;
 	MediaDevice *imguMediaDev_;
+
+	std::vector<IPABuffer> ipaBuffers_;
 };
 
 IPU3CameraConfiguration::IPU3CameraConfiguration(IPU3CameraData *data)
@@ -583,6 +585,23 @@  int PipelineHandlerIPU3::allocateBuffers(Camera *camera)
 	if (ret < 0)
 		return ret;
 
+	/* Map buffers to the IPA. */
+	unsigned int ipaBufferId = 1;
+
+	for (const std::unique_ptr<FrameBuffer> &buffer : imgu->paramBuffers_) {
+		buffer->setCookie(ipaBufferId++);
+		ipaBuffers_.push_back({ .id = buffer->cookie(),
+					.planes = buffer->planes() });
+	}
+
+	for (const std::unique_ptr<FrameBuffer> &buffer : imgu->statBuffers_) {
+		buffer->setCookie(ipaBufferId++);
+		ipaBuffers_.push_back({ .id = buffer->cookie(),
+					.planes = buffer->planes() });
+	}
+
+	data->ipa_->mapBuffers(ipaBuffers_);
+
 	return 0;
 }
 
@@ -590,6 +609,13 @@  int PipelineHandlerIPU3::freeBuffers(Camera *camera)
 {
 	IPU3CameraData *data = cameraData(camera);
 
+	std::vector<unsigned int> ids;
+	for (IPABuffer &ipabuf : ipaBuffers_)
+		ids.push_back(ipabuf.id);
+
+	data->ipa_->unmapBuffers(ids);
+	ipaBuffers_.clear();
+
 	data->imgu_->freeBuffers();
 
 	return 0;