[07/10] libcamera: egl: Add activateBindTexture
diff mbox series

Message ID 20260624085849.873784-8-bryan.odonoghue@linaro.org
State New
Headers show
Series
  • libcamera: software_isp: gpu: Add go faster stripes
Related show

Commit Message

Bryan O'Donoghue June 24, 2026, 8:58 a.m. UTC
When operating from a texture cache on dma-buf inputs we will no longer
create new textures nor attach those textures for dma-buf handles we have
already encountered.

This means we will use the texture id associated with a given texture unit
to switch between one texture and another. The pages associated with the
texture will have been populated with new data by the CSI2 receiver. All we
will do is say to the GPU "reuse this texture id" aka zero-copy.

However we must also activate and bind that texture for each loop. This
cost is small but necessary for zero-copy.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
---
 include/libcamera/internal/egl.h |  1 +
 src/libcamera/egl.cpp            | 14 +++++++++-----
 2 files changed, 10 insertions(+), 5 deletions(-)

Comments

Robert Mader June 24, 2026, 12:15 p.m. UTC | #1
On 24.06.26 10:58, Bryan O'Donoghue wrote:
> When operating from a texture cache on dma-buf inputs we will no longer
> create new textures nor attach those textures for dma-buf handles we have
> already encountered.
>
> This means we will use the texture id associated with a given texture unit
> to switch between one texture and another. The pages associated with the
> texture will have been populated with new data by the CSI2 receiver. All we
> will do is say to the GPU "reuse this texture id" aka zero-copy.
>
> However we must also activate and bind that texture for each loop. This
> cost is small but necessary for zero-copy.
>
> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
> ---
>   include/libcamera/internal/egl.h |  1 +
>   src/libcamera/egl.cpp            | 14 +++++++++-----
>   2 files changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h
> index f1fa75d96..59fd52749 100644
> --- a/include/libcamera/internal/egl.h
> +++ b/include/libcamera/internal/egl.h
> @@ -112,6 +112,7 @@ public:
>   	void createOutputTexture2D(eGLImage &eglImage);
>   
>   	int attachTextureToFBO(eGLImage &eglImage);
> +	void activateBindTexture(eGLImage &eglImage);
>   
>   	void pushEnv(std::vector<std::string> &shaderEnv, const char *str);
>   	void makeCurrent();
> diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp
> index 6134b05f9..f26fe2e53 100644
> --- a/src/libcamera/egl.cpp
> +++ b/src/libcamera/egl.cpp
> @@ -138,6 +138,13 @@ int eGL::attachTextureToFBO(eGLImage &eglImage)
>   	return ret;
>   }
>   
> +void eGL::activateBindTexture(eGLImage &eglImage)
> +{
> +	// Bind texture unit and texture
> +	glActiveTexture(eglImage.texture_unit_);
> +	glBindTexture(GL_TEXTURE_2D, eglImage.texture_);
> +}
> +
>   /**
>    * \brief Create a DMA-BUF backed 2D texture
>    * \param[in,out] eglImage EGL image to associate with the DMA-BUF
> @@ -197,9 +204,7 @@ int eGL::createDMABufTexture2D(eGLImage &eglImage, int fd, bool output)
>   		return -ENODEV;
>   	}
>   
> -	// Bind texture unit and texture
> -	glActiveTexture(eglImage.texture_unit_);
> -	glBindTexture(GL_TEXTURE_2D, eglImage.texture_);
> +	activateBindTexture(eglImage);
>   
>   	// Generate texture with filter semantics
>   	glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image);
> @@ -273,8 +278,7 @@ void eGL::createInputTexture2D(eGLImage &eglImage, void *data)
>   
>   	ASSERT(tid_ == Thread::currentId());
>   
> -	glActiveTexture(eglImage.texture_unit_);
> -	glBindTexture(GL_TEXTURE_2D, eglImage.texture_);
> +	activateBindTexture(eglImage);
>   
>   	switch (eglImage.format_) {
>   	case GL_R16F:

As noted on the previous commit, this is missing updateInputTexture2D(). 
I suggest to switch those commits around.

Apart from that:

Reviewed-by: Robert Mader <robert.mader@collabora.com>

Patch
diff mbox series

diff --git a/include/libcamera/internal/egl.h b/include/libcamera/internal/egl.h
index f1fa75d96..59fd52749 100644
--- a/include/libcamera/internal/egl.h
+++ b/include/libcamera/internal/egl.h
@@ -112,6 +112,7 @@  public:
 	void createOutputTexture2D(eGLImage &eglImage);
 
 	int attachTextureToFBO(eGLImage &eglImage);
+	void activateBindTexture(eGLImage &eglImage);
 
 	void pushEnv(std::vector<std::string> &shaderEnv, const char *str);
 	void makeCurrent();
diff --git a/src/libcamera/egl.cpp b/src/libcamera/egl.cpp
index 6134b05f9..f26fe2e53 100644
--- a/src/libcamera/egl.cpp
+++ b/src/libcamera/egl.cpp
@@ -138,6 +138,13 @@  int eGL::attachTextureToFBO(eGLImage &eglImage)
 	return ret;
 }
 
+void eGL::activateBindTexture(eGLImage &eglImage)
+{
+	// Bind texture unit and texture
+	glActiveTexture(eglImage.texture_unit_);
+	glBindTexture(GL_TEXTURE_2D, eglImage.texture_);
+}
+
 /**
  * \brief Create a DMA-BUF backed 2D texture
  * \param[in,out] eglImage EGL image to associate with the DMA-BUF
@@ -197,9 +204,7 @@  int eGL::createDMABufTexture2D(eGLImage &eglImage, int fd, bool output)
 		return -ENODEV;
 	}
 
-	// Bind texture unit and texture
-	glActiveTexture(eglImage.texture_unit_);
-	glBindTexture(GL_TEXTURE_2D, eglImage.texture_);
+	activateBindTexture(eglImage);
 
 	// Generate texture with filter semantics
 	glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image);
@@ -273,8 +278,7 @@  void eGL::createInputTexture2D(eGLImage &eglImage, void *data)
 
 	ASSERT(tid_ == Thread::currentId());
 
-	glActiveTexture(eglImage.texture_unit_);
-	glBindTexture(GL_TEXTURE_2D, eglImage.texture_);
+	activateBindTexture(eglImage);
 
 	switch (eglImage.format_) {
 	case GL_R16F: