[libcamera-devel,v2] ipa: ipu3: af: enforce grid size restrictions
diff mbox series

Message ID 20220407231414.97058-1-kieran.bingham@ideasonboard.com
State Accepted
Commit b0c2484d6191a6225b301144a9d1781870e03c68
Headers show
Series
  • [libcamera-devel,v2] ipa: ipu3: af: enforce grid size restrictions
Related show

Commit Message

Kieran Bingham April 7, 2022, 11:14 p.m. UTC
Provide enforcement of the selection of the block_{width,height}_log2
parameters to the capabilities of the hardware.

While this selection is currently hardcoded to the minimum, providing
the restriction now allows for further dynamic sizing in the future and
documents the restrictions directly in code, making use of the already
existing constants.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
---
v2:
 - Finally actually fixed the clang compiler by also adding the
   kAfMaxGrid{Width,Height} constants too.


 src/ipa/ipu3/algorithms/af.cpp | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

Patch
diff mbox series

diff --git a/src/ipa/ipu3/algorithms/af.cpp b/src/ipa/ipu3/algorithms/af.cpp
index 0170a3728892..a33c229aabea 100644
--- a/src/ipa/ipu3/algorithms/af.cpp
+++ b/src/ipa/ipu3/algorithms/af.cpp
@@ -168,6 +168,25 @@  int Af::configure(IPAContext &context, const IPAConfigInfo &configInfo)
 	grid.height = kAfMinGridHeight;
 	grid.block_width_log2 = kAfMinGridBlockWidth;
 	grid.block_height_log2 = kAfMinGridBlockHeight;
+
+	/*
+	 * \todo - while this clamping code is effectively a no-op, it satisfies
+	 * the compiler that the constant definitions of the hardware limits
+	 * are used, and paves the way to support dynamic grid sizing in the
+	 * future. While the block_{width,height}_log2 remain assigned to the
+	 * minimum, this code should be optimized out by the compiler.
+	 */
+	grid.width = std::clamp(grid.width, kAfMinGridWidth, kAfMaxGridWidth);
+	grid.height = std::clamp(grid.height, kAfMinGridHeight, kAfMaxGridHeight);
+
+	grid.block_width_log2 = std::clamp(grid.block_width_log2,
+					   kAfMinGridBlockWidth,
+					   kAfMaxGridBlockWidth);
+
+	grid.block_height_log2 = std::clamp(grid.block_height_log2,
+					    kAfMinGridBlockHeight,
+					    kAfMaxGridBlockHeight);
+
 	grid.height_per_slice = kAfDefaultHeightPerSlice;
 
 	/* x_start and y start are default to BDS center */