[RFC,v2,06/14] libcamera: software_isp: Allocate multiple parameters buffers
diff mbox series

Message ID 20260216203034.27558-7-mzamazal@redhat.com
State New
Headers show
Series
  • Software ISP: Share params and stats buffers
Related show

Commit Message

Milan Zamazal Feb. 16, 2026, 8:30 p.m. UTC
We want to use more than one parameters buffer.  Processing statistics
(and setting the corresponding parameters) is asynchronous and may work
with a parameters buffer while the last parameters buffer may be in or
wait for use in debayering.

The question is how many buffer we need.  A starting idea might be to
use the same number as for input and output buffers.  This may not be
necessarily the best or even correct idea, but if the number of those
buffers is sufficient now then perhaps the same number of the parameters
buffers (and later statistics buffers) would work.  Unless multiple
streams are used...

Nevertheless, the number of the input and output buffers is currently
fixed, which makes it possible to use in init, before configure, where
the current single buffer is allocated.  It just requires to make the
given constant public in SimplePipelineHandler so that it can be passed
to the SoftwareIsp constructor.

Another alternative would be to determine the right number of buffers in
SoftwareIsp::configure.  This would be more complicated as it would
require some more refactoring, allocating the buffers in configure and
passing their file descriptors to the IPA and debayering on demand.

Only the first allocated buffer is actually used at the moment.  This
will be changed in the followup patches once support for multiple
buffers is added to the IPA and debayering.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
---
 .../libcamera/internal/software_isp/software_isp.h |  6 +++---
 src/libcamera/pipeline/simple/simple.cpp           |  5 +++--
 src/libcamera/software_isp/software_isp.cpp        | 14 +++++---------
 3 files changed, 11 insertions(+), 14 deletions(-)

Patch
diff mbox series

diff --git a/include/libcamera/internal/software_isp/software_isp.h b/include/libcamera/internal/software_isp/software_isp.h
index f809e6be8..65348e213 100644
--- a/include/libcamera/internal/software_isp/software_isp.h
+++ b/include/libcamera/internal/software_isp/software_isp.h
@@ -49,7 +49,8 @@  class SoftwareIsp : public Object
 {
 public:
 	SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor,
-		    ControlInfoMap *ipaControls);
+		    ControlInfoMap *ipaControls,
+		    const unsigned int bufferCount);
 	~SoftwareIsp();
 
 	int loadConfiguration([[maybe_unused]] const std::string &filename) { return 0; }
@@ -97,11 +98,10 @@  private:
 	void outputReady(FrameBuffer *output);
 	std::unique_ptr<Debayer> debayer_;
 	Thread ispWorkerThread_;
-	static constexpr unsigned int kParamStatBufferCount = 1;
 	std::map<uint32_t, SharedMemObject<DebayerParams>> sharedParams_;
 	DebayerParams debayerParams_;
 	std::queue<uint32_t> availableParams_;
-	bool allocateParamsBuffers();
+	bool allocateParamsBuffers(const unsigned int bufferCount);
 	DmaBufAllocator dmaHeap_;
 	bool ccmEnabled_;
 
diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp
index 4a0b9f58d..dc9176c29 100644
--- a/src/libcamera/pipeline/simple/simple.cpp
+++ b/src/libcamera/pipeline/simple/simple.cpp
@@ -427,13 +427,13 @@  public:
 	V4L2Subdevice *subdev(const MediaEntity *entity);
 	std::shared_ptr<MediaDevice> converter() { return converter_; }
 	bool swIspEnabled() const { return swIspEnabled_; }
+	static constexpr unsigned int kNumInternalBuffers = 4;
 
 protected:
 	int queueRequestDevice(Camera *camera, Request *request) override;
 
 private:
 	static constexpr unsigned int kMaxQueuedRequestsDevice = 4;
-	static constexpr unsigned int kNumInternalBuffers = 4;
 
 	struct EntityData {
 		std::unique_ptr<V4L2VideoDevice> video;
@@ -615,7 +615,8 @@  int SimpleCameraData::init()
 	 * Instantiate Soft ISP if this is enabled for the given driver and no converter is used.
 	 */
 	if (!converter_ && pipe->swIspEnabled()) {
-		swIsp_ = std::make_unique<SoftwareIsp>(pipe, sensor_.get(), &controlInfo_);
+		swIsp_ = std::make_unique<SoftwareIsp>(pipe, sensor_.get(), &controlInfo_,
+						       pipe->kNumInternalBuffers);
 		if (!swIsp_->isValid()) {
 			LOG(SimplePipeline, Warning)
 				<< "Failed to create software ISP, disabling software debayering";
diff --git a/src/libcamera/software_isp/software_isp.cpp b/src/libcamera/software_isp/software_isp.cpp
index 79d5dfe0e..02d1c4c12 100644
--- a/src/libcamera/software_isp/software_isp.cpp
+++ b/src/libcamera/software_isp/software_isp.cpp
@@ -70,20 +70,16 @@  LOG_DEFINE_CATEGORY(SoftwareIsp)
  * ready
  */
 
-/**
- * \var SoftwareIsp::kParamStatBufferCount
- * \brief The number of stats and params buffers (each of them)
- */
-
 /**
  * \brief Constructs SoftwareIsp object
  * \param[in] pipe The pipeline handler in use
  * \param[in] sensor Pointer to the CameraSensor instance owned by the pipeline
  * \param[out] ipaControls The IPA controls to update
+ * \param[in] bufferCount Number of parameters buffers and stats buffers to allocate
  * handler
  */
 SoftwareIsp::SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor,
-			 ControlInfoMap *ipaControls)
+			 ControlInfoMap *ipaControls, const unsigned bufferCount)
 	: ispWorkerThread_("SWIspWorker"),
 	  dmaHeap_(DmaBufAllocator::DmaBufAllocatorFlag::CmaHeap |
 		   DmaBufAllocator::DmaBufAllocatorFlag::SystemHeap |
@@ -93,7 +89,7 @@  SoftwareIsp::SoftwareIsp(PipelineHandler *pipe, const CameraSensor *sensor,
 		LOG(SoftwareIsp, Error) << "Failed to create DmaBufAllocator object";
 		return;
 	}
-	if (!allocateParamsBuffers())
+	if (!allocateParamsBuffers(bufferCount))
 		return;
 
 	const GlobalConfiguration &configuration = pipe->cameraManager()->_d()->configuration();
@@ -177,9 +173,9 @@  SoftwareIsp::~SoftwareIsp()
 	debayer_.reset();
 }
 
-bool SoftwareIsp::allocateParamsBuffers()
+bool SoftwareIsp::allocateParamsBuffers(const unsigned int bufferCount)
 {
-	for (unsigned int i = 0; i < kParamStatBufferCount; i++) {
+	for (unsigned int i = 0; i < bufferCount; i++) {
 		auto params = SharedMemObject<DebayerParams>("softIsp_params");
 		if (!params) {
 			LOG(SoftwareIsp, Error) << "Failed to create shared memory for parameters";