Patch Detail
Show a patch.
GET /api/1.1/patches/9641/?format=api
{ "id": 9641, "url": "https://patchwork.libcamera.org/api/1.1/patches/9641/?format=api", "web_url": "https://patchwork.libcamera.org/patch/9641/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20200916145254.1644-6-laurent.pinchart@ideasonboard.com>", "date": "2020-09-16T14:52:52", "name": "[libcamera-devel,5/7] qcam: viewfinder_gl: Support #define in shaders", "commit_ref": "0bc03960daf0d7e28d45513873e3d1feecbedbf6", "pull_url": null, "state": "accepted", "archived": false, "hash": "eaa1d75c33d2fad7932c30950f0ec891935f9702", "submitter": { "id": 2, "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api", "name": "Laurent Pinchart", "email": "laurent.pinchart@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/9641/mbox/", "series": [ { "id": 1293, "url": "https://patchwork.libcamera.org/api/1.1/series/1293/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=1293", "date": "2020-09-16T14:52:47", "name": "qcam: Accelerate packed YUV rendering with OpenGL", "version": 1, "mbox": "https://patchwork.libcamera.org/series/1293/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/9641/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/9641/checks/", "tags": {}, "headers": { "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>", "X-Original-To": "parsemail@patchwork.libcamera.org", "Delivered-To": "parsemail@patchwork.libcamera.org", "Received": [ "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id B0F26C3B5B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 16 Sep 2020 14:54:33 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7C8AB62EC5;\n\tWed, 16 Sep 2020 16:54:33 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9FCFE62E75\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 16 Sep 2020 16:54:32 +0200 (CEST)", "from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id D04BC26B;\n\tWed, 16 Sep 2020 16:54:25 +0200 (CEST)" ], "Authentication-Results": "lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"D+relIbS\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1600268066;\n\tbh=RTU1WqqU+emMau92i/LATnXRW7N34GngxDR71H03HxM=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=D+relIbSecZwguWB5k22NWAtK1ax+ACLQFhKMdPB3zpabD88kVdtFehvQF1XruDbi\n\tky2oByudM1gY01mvGlgv5NFDLT5Okn7L+q4AQNWqAk3slYiqsPo4gQzi5PM+7+VqTS\n\t+W4iGbgYK/agcAjOeMwbRLOx2w+2kwvKAb4mTJLs=", "From": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Date": "Wed, 16 Sep 2020 17:52:52 +0300", "Message-Id": "<20200916145254.1644-6-laurent.pinchart@ideasonboard.com>", "X-Mailer": "git-send-email 2.27.0", "In-Reply-To": "<20200916145254.1644-1-laurent.pinchart@ideasonboard.com>", "References": "<20200916145254.1644-1-laurent.pinchart@ideasonboard.com>", "MIME-Version": "1.0", "Subject": "[libcamera-devel] [PATCH 5/7] qcam: viewfinder_gl: Support #define\n\tin shaders", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "<libcamera-devel.lists.libcamera.org>", "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>", "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>", "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>", "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>", "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>", "Content-Type": "text/plain; charset=\"us-ascii\"", "Content-Transfer-Encoding": "7bit", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "Prepare the infrastructure to support defining preprocessor macros in\nshaders:\n\n- Rename the fragmentShaderSrc_ member to fragmentShaderFile_ to reflect\n better that it contains a file name, not shader source code\n- Add a new fragmentShaderDefines_ member to store preprocessor macros\n- Prepend the macros to the shader source before compiling it\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n---\n src/qcam/viewfinder_gl.cpp | 42 +++++++++++++++++++++++++++-----------\n src/qcam/viewfinder_gl.h | 11 +++++-----\n 2 files changed, 35 insertions(+), 18 deletions(-)", "diff": "diff --git a/src/qcam/viewfinder_gl.cpp b/src/qcam/viewfinder_gl.cpp\nindex 0fa06a290959..7cb5fb63656f 100644\n--- a/src/qcam/viewfinder_gl.cpp\n+++ b/src/qcam/viewfinder_gl.cpp\n@@ -7,6 +7,8 @@\n \n #include \"viewfinder_gl.h\"\n \n+#include <QByteArray>\n+#include <QFile>\n #include <QImage>\n \n #include <libcamera/formats.h>\n@@ -24,7 +26,7 @@ static const QList<libcamera::PixelFormat> supportedFormats{\n \n ViewFinderGL::ViewFinderGL(QWidget *parent)\n \t: QOpenGLWidget(parent), buffer_(nullptr), yuvData_(nullptr),\n-\t fragmentShader_(nullptr), vertexShader_(nullptr),\n+\t vertexShader_(nullptr), fragmentShader_(nullptr),\n \t vertexBuffer_(QOpenGLBuffer::VertexBuffer),\n \t textureU_(QOpenGLTexture::Target2D),\n \t textureV_(QOpenGLTexture::Target2D),\n@@ -97,46 +99,49 @@ void ViewFinderGL::render(libcamera::FrameBuffer *buffer, MappedBuffer *map)\n bool ViewFinderGL::selectFormat(const libcamera::PixelFormat &format)\n {\n \tbool ret = true;\n+\n+\tfragmentShaderDefines_.clear();\n+\n \tswitch (format) {\n \tcase libcamera::formats::NV12:\n \t\thorzSubSample_ = 2;\n \t\tvertSubSample_ = 2;\n-\t\tfragmentShaderSrc_ = \":YUV_2_planes_UV.frag\";\n+\t\tfragmentShaderFile_ = \":YUV_2_planes_UV.frag\";\n \t\tbreak;\n \tcase libcamera::formats::NV21:\n \t\thorzSubSample_ = 2;\n \t\tvertSubSample_ = 2;\n-\t\tfragmentShaderSrc_ = \":YUV_2_planes_VU.frag\";\n+\t\tfragmentShaderFile_ = \":YUV_2_planes_VU.frag\";\n \t\tbreak;\n \tcase libcamera::formats::NV16:\n \t\thorzSubSample_ = 2;\n \t\tvertSubSample_ = 1;\n-\t\tfragmentShaderSrc_ = \":YUV_2_planes_UV.frag\";\n+\t\tfragmentShaderFile_ = \":YUV_2_planes_UV.frag\";\n \t\tbreak;\n \tcase libcamera::formats::NV61:\n \t\thorzSubSample_ = 2;\n \t\tvertSubSample_ = 1;\n-\t\tfragmentShaderSrc_ = \":YUV_2_planes_VU.frag\";\n+\t\tfragmentShaderFile_ = \":YUV_2_planes_VU.frag\";\n \t\tbreak;\n \tcase libcamera::formats::NV24:\n \t\thorzSubSample_ = 1;\n \t\tvertSubSample_ = 1;\n-\t\tfragmentShaderSrc_ = \":YUV_2_planes_UV.frag\";\n+\t\tfragmentShaderFile_ = \":YUV_2_planes_UV.frag\";\n \t\tbreak;\n \tcase libcamera::formats::NV42:\n \t\thorzSubSample_ = 1;\n \t\tvertSubSample_ = 1;\n-\t\tfragmentShaderSrc_ = \":YUV_2_planes_VU.frag\";\n+\t\tfragmentShaderFile_ = \":YUV_2_planes_VU.frag\";\n \t\tbreak;\n \tcase libcamera::formats::YUV420:\n \t\thorzSubSample_ = 2;\n \t\tvertSubSample_ = 2;\n-\t\tfragmentShaderSrc_ = \":YUV_3_planes.frag\";\n+\t\tfragmentShaderFile_ = \":YUV_3_planes.frag\";\n \t\tbreak;\n \tcase libcamera::formats::YVU420:\n \t\thorzSubSample_ = 2;\n \t\tvertSubSample_ = 2;\n-\t\tfragmentShaderSrc_ = \":YUV_3_planes.frag\";\n+\t\tfragmentShaderFile_ = \":YUV_3_planes.frag\";\n \t\tbreak;\n \tdefault:\n \t\tret = false;\n@@ -168,11 +173,24 @@ bool ViewFinderGL::createFragmentShader()\n \tint attributeVertex;\n \tint attributeTexture;\n \n-\t/* Create Fragment Shader */\n+\t/*\n+\t * Create the fragment shader, compile it, and add it to the shader\n+\t * program. The #define macros stored in fragmentShaderDefines_, if\n+\t * any, are prepended to the source code.\n+\t */\n \tfragmentShader_ = new QOpenGLShader(QOpenGLShader::Fragment, this);\n \n-\t/* Compile the fragment shader */\n-\tif (!fragmentShader_->compileSourceFile(fragmentShaderSrc_)) {\n+\tQFile file(fragmentShaderFile_);\n+\tif (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {\n+\t\tqWarning() << \"Shader\" << fragmentShaderFile_ << \"not found\";\n+\t\treturn false;\n+\t}\n+\n+\tQString defines = fragmentShaderDefines_.join('\\n') + \"\\n\";\n+\tQByteArray src = file.readAll();\n+\tsrc.prepend(defines.toUtf8());\n+\n+\tif (!fragmentShader_->compileSourceCode(src)) {\n \t\tqWarning() << \"[ViewFinderGL]:\" << fragmentShader_->log();\n \t\treturn false;\n \t}\ndiff --git a/src/qcam/viewfinder_gl.h b/src/qcam/viewfinder_gl.h\nindex 7675d0a06351..53424dc10bc5 100644\n--- a/src/qcam/viewfinder_gl.h\n+++ b/src/qcam/viewfinder_gl.h\n@@ -65,17 +65,16 @@ private:\n \tQSize size_;\n \tunsigned char *yuvData_;\n \n-\t/* OpenGL components for rendering */\n-\tQOpenGLShader *fragmentShader_;\n-\tQOpenGLShader *vertexShader_;\n+\t/* Shaders */\n \tQOpenGLShaderProgram shaderProgram_;\n+\tQOpenGLShader *vertexShader_;\n+\tQOpenGLShader *fragmentShader_;\n+\tQString fragmentShaderFile_;\n+\tQStringList fragmentShaderDefines_;\n \n \t/* Vertex buffer */\n \tQOpenGLBuffer vertexBuffer_;\n \n-\t/* Fragment shader file name */\n-\tQString fragmentShaderSrc_;\n-\n \t/* YUV texture planars and parameters */\n \tGLuint textureUniformU_;\n \tGLuint textureUniformV_;\n", "prefixes": [ "libcamera-devel", "5/7" ] }