[{"id":36453,"web_url":"https://patchwork.libcamera.org/comment/36453/","msgid":"<857bwk81ov.fsf@mzamazal-thinkpadp1gen7.tpbc.csb>","date":"2025-10-24T20:49:52","subject":"Re: [PATCH v3 31/39] libcamera: shaders: Fix neighbouring positions\n\tin 8-bit debayering","submitter":{"id":177,"url":"https://patchwork.libcamera.org/api/people/177/","name":"Milan Zamazal","email":"mzamazal@redhat.com"},"content":"Bryan O'Donoghue <bryan.odonoghue@linaro.org> writes:\n\n> From: Milan Zamazal <mzamazal@redhat.com>\n>\n> When accessing a texture position in a shader, the pixel with the\n> nearest centre to the specified texture coordinates (as mandated by\n> specifying GL_NEAREST parameter) is taken.  The current vertex shader\n> determines the positions of the neighbouring pixels by adding the\n> provided texture steps to the exact centre pixel coordinates.  But this\n> places the computed coordinates, from the point of view of GL_NEAREST,\n> exactly between the pixels and is thus prone to floating point\n> inaccuracies.  Wrong neighbouring pixel coordinates may be used,\n> resulting in artefacts in the output image.\n\nI cannot reproduce this any more.  Quite opposite, artefacts are not\npresent iff the corrective step multiplication step is inside -0.5..0.5\nrange.  So the coordinates are apparently placed on pixel centres rather\nthan borders now.  And if I attempt to use a second set of shaders, the\ncoordinates shift introduced by this patch causes another trouble with\nartefacts (still no idea why).\n\nHonestly, I don't understand how it is supposed to work and what has\nchanged that it works differently now than long time before (pre-v1, I\nthink).  But based on my recent empiric observations, I'd say we should\ndrop this patch (unless independent testing tells otherwise).\n\n> Let's fix the problem by shifting the initial coordinates a bit from the\n> pixel border.\n>\n> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>\n> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>\n> ---\n>  include/libcamera/internal/shaders/bayer_unpacked.vert | 8 ++++----\n>  1 file changed, 4 insertions(+), 4 deletions(-)\n>\n> diff --git a/include/libcamera/internal/shaders/bayer_unpacked.vert b/include/libcamera/internal/shaders/bayer_unpacked.vert\n> index fb5109ee..fc1cf89f 100644\n> --- a/include/libcamera/internal/shaders/bayer_unpacked.vert\n> +++ b/include/libcamera/internal/shaders/bayer_unpacked.vert\n> @@ -44,10 +44,10 @@ void main(void) {\n>      center.xy = textureIn;\n>      center.zw = textureIn * tex_size + tex_bayer_first_red;\n>  \n> -    xCoord = center.x + vec4(-2.0 * tex_step.x,\n> -                             -tex_step.x, tex_step.x, 2.0 * tex_step.x);\n> -    yCoord = center.y + vec4(-2.0 * tex_step.y,\n> -                              -tex_step.y, tex_step.y, 2.0 * tex_step.y);\n> +    xCoord = center.x + 0.1 * tex_step.x +\n> +      vec4(-2.0 * tex_step.x, -tex_step.x, tex_step.x, 2.0 * tex_step.x);\n> +    yCoord = center.y + 0.1 * tex_step.y +\n> +      vec4(-2.0 * tex_step.y, -tex_step.y, tex_step.y, 2.0 * tex_step.y);\n>  \n>      gl_Position = proj_matrix * vertexIn;\n>  }","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 45436BE080\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 24 Oct 2025 20:50:03 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 82461609E7;\n\tFri, 24 Oct 2025 22:50:02 +0200 (CEST)","from us-smtp-delivery-124.mimecast.com\n\t(us-smtp-delivery-124.mimecast.com [170.10.129.124])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1C67660990\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 24 Oct 2025 22:50:00 +0200 (CEST)","from mail-ej1-f70.google.com (mail-ej1-f70.google.com\n\t[209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS\n\t(version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n\tus-mta-467-77SI4DS7ODKwjMmbjaDvFA-1; Fri, 24 Oct 2025 16:49:57 -0400","by mail-ej1-f70.google.com with SMTP id\n\ta640c23a62f3a-b6d52387ebeso287951666b.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 24 Oct 2025 13:49:57 -0700 (PDT)","from mzamazal-thinkpadp1gen7.tpbc.csb\n\t(ip-77-48-47-2.net.vodafone.cz. [77.48.47.2])\n\tby smtp.gmail.com with ESMTPSA id\n\t4fb4d7f45d1cf-63e7ef829dasm121895a12.13.2025.10.24.13.49.52\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 24 Oct 2025 13:49:53 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=redhat.com header.i=@redhat.com\n\theader.b=\"W5Ldrb6q\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n\ts=mimecast20190719; t=1761338998;\n\th=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n\tto:to:cc:cc:mime-version:mime-version:content-type:content-type:\n\tin-reply-to:in-reply-to:references:references;\n\tbh=L1YEkjqfvHmKx0DuQiZG9LTE1ytWVx0K/LbFSOGJ9Ao=;\n\tb=W5Ldrb6qP1IKw6maeqDCGnyaacVUMpsPkEqAbcRD8XF97UBl4om2ZD1rDCIz55t2yFIMOS\n\tlfI8Y5dDNnCMQs8tVYYhHf+MWsaS4QW7wR/x20hMPeh5yzAfYE+MaHybejkk4AczBYc24R\n\tvGqvD5qjNBRfY7nahzPxUaaVRAEM3jI=","X-MC-Unique":"77SI4DS7ODKwjMmbjaDvFA-1","X-Mimecast-MFC-AGG-ID":"77SI4DS7ODKwjMmbjaDvFA_1761338996","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1761338996; x=1761943796;\n\th=mime-version:user-agent:message-id:date:references:in-reply-to\n\t:sub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leI1a220fzGhX7Sgf2S7kOTuLjE\n\t31UoZmXyZKhPHjo6+z9tQmCEzirikIiMqsVW4xSzNeYNYKYZK0uoz","X-Received":["by 2002:a17:906:6a19:b0:ad5:d597:561e with SMTP id\n\ta640c23a62f3a-b6d6ffb5395mr416874066b.56.1761338996004; \n\tFri, 24 Oct 2025 13:49:56 -0700 (PDT)","by 2002:a17:906:6a19:b0:ad5:d597:561e with SMTP id\n\ta640c23a62f3a-b6d6ffb5395mr416871966b.56.1761338995551; \n\tFri, 24 Oct 2025 13:49:55 -0700 (PDT)"],"X-Google-Smtp-Source":"AGHT+IHtMqR/gwwJGcZcvy3ubK8Jx2ObWhY5u+j7fs84z7iwl+NAPimiOzBFzO0R9oFSFVgZ/sxwmw==","From":"Milan Zamazal <mzamazal@redhat.com>","To":"Bryan O'Donoghue <bryan.odonoghue@linaro.org>","Cc":"libcamera-devel@lists.libcamera.org,  hdegoede@redhat.com,\n\tbod.linux@nxsw.ie","Subject":"Re: [PATCH v3 31/39] libcamera: shaders: Fix neighbouring positions\n\tin 8-bit debayering","In-Reply-To":"<20251015012251.17508-32-bryan.odonoghue@linaro.org> (Bryan\n\tO'Donoghue's message of \"Wed, 15 Oct 2025 02:22:43 +0100\")","References":"<20251015012251.17508-1-bryan.odonoghue@linaro.org>\n\t<20251015012251.17508-32-bryan.odonoghue@linaro.org>","Date":"Fri, 24 Oct 2025 22:49:52 +0200","Message-ID":"<857bwk81ov.fsf@mzamazal-thinkpadp1gen7.tpbc.csb>","User-Agent":"Gnus/5.13 (Gnus v5.13)","MIME-Version":"1.0","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"u-IAz8IQhmGxO0jVZQ6m9e5aTTdh6o2HrJKY_vCqPqU_1761338996","X-Mimecast-Originator":"redhat.com","Content-Type":"text/plain","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":36458,"web_url":"https://patchwork.libcamera.org/comment/36458/","msgid":"<461cb3b0-1cb0-4ef8-b396-d8b8954167ab@linaro.org>","date":"2025-10-25T00:27:22","subject":"Re: [PATCH v3 31/39] libcamera: shaders: Fix neighbouring positions\n\tin 8-bit debayering","submitter":{"id":175,"url":"https://patchwork.libcamera.org/api/people/175/","name":"Bryan O'Donoghue","email":"bryan.odonoghue@linaro.org"},"content":"On 24/10/2025 21:49, Milan Zamazal wrote:\n> Bryan O'Donoghue<bryan.odonoghue@linaro.org> writes:\n> \n>> From: Milan Zamazal<mzamazal@redhat.com>\n>>\n>> When accessing a texture position in a shader, the pixel with the\n>> nearest centre to the specified texture coordinates (as mandated by\n>> specifying GL_NEAREST parameter) is taken.  The current vertex shader\n>> determines the positions of the neighbouring pixels by adding the\n>> provided texture steps to the exact centre pixel coordinates.  But this\n>> places the computed coordinates, from the point of view of GL_NEAREST,\n>> exactly between the pixels and is thus prone to floating point\n>> inaccuracies.  Wrong neighbouring pixel coordinates may be used,\n>> resulting in artefacts in the output image.\n> I cannot reproduce this any more.  Quite opposite, artefacts are not\n> present iff the corrective step multiplication step is inside -0.5..0.5\n> range.  So the coordinates are apparently placed on pixel centres rather\n> than borders now.  And if I attempt to use a second set of shaders, the\n> coordinates shift introduced by this patch causes another trouble with\n> artefacts (still no idea why).\n> \n> Honestly, I don't understand how it is supposed to work and what has\n> changed that it works differently now than long time before (pre-v1, I\n> think).  But based on my recent empiric observations, I'd say we should\n> drop this patch (unless independent testing tells otherwise).\n\nOK.\n\nI trust your debug here and rely on your input for this setup anyway.\n\nDropped.\n\n---\nbod","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 22C8BC3259\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSat, 25 Oct 2025 00:27:27 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 6682E609E0;\n\tSat, 25 Oct 2025 02:27:26 +0200 (CEST)","from mail-ed1-x531.google.com (mail-ed1-x531.google.com\n\t[IPv6:2a00:1450:4864:20::531])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 429AC607ED\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat, 25 Oct 2025 02:27:25 +0200 (CEST)","by mail-ed1-x531.google.com with SMTP id\n\t4fb4d7f45d1cf-63c12ff0c5eso5341059a12.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 24 Oct 2025 17:27:25 -0700 (PDT)","from [192.168.0.163] (188-141-3-146.dynamic.upc.ie.\n\t[188.141.3.146]) by smtp.gmail.com with ESMTPSA id\n\t4fb4d7f45d1cf-63e7efb9fa6sm426428a12.31.2025.10.24.17.27.23\n\t(version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);\n\tFri, 24 Oct 2025 17:27:23 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=linaro.org header.i=@linaro.org\n\theader.b=\"hqlie9GM\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=linaro.org; s=google; t=1761352045; x=1761956845;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:in-reply-to:content-language:from\n\t:references:cc:to:subject:user-agent:mime-version:date:message-id\n\t:from:to:cc:subject:date:message-id:reply-to;\n\tbh=gu5byN8G0oj58wwLahw3lu7pSxN2g8uWa4skDYCerU8=;\n\tb=hqlie9GMmN3K6UESiF7cpiECFeIJCTsPqgmqTGC3F/fp414j4Y7HxYFNC/n0PIz+d5\n\tyyScel7onB/8bKM9+jX51o6xV4orEWwwVGEXs9vxJGG0ULj5LuJEitKiDHQeIPukD8bk\n\tPl2qEA3DSxyCGJjXYO2KJ8kLPmRPp/l+1XBrzWz1GZ49i2HgcJcq+qC/Yx4TUG+MugDI\n\t5E+/9o6yR+gGD0RElX0uh7sxtT/d2gLMZKbcoKR0yCOFIU8BLQIGl6uWHw1HrXDWv86u\n\tWmQWroL9ABStbO5P//nNXs0HjyYcLobs5+/uA3GK4OFlnUCTT5iZA6lPgSCEzmTTolvd\n\tVUDg==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1761352045; x=1761956845;\n\th=content-transfer-encoding:in-reply-to:content-language:from\n\t:references:cc:to:subject:user-agent:mime-version:date:message-id\n\t:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;\n\tbh=gu5byN8G0oj58wwLahw3lu7pSxN2g8uWa4skDYCerU8=;\n\tb=riYlv8RgNdcWWXzsIW8mfOy7vo1ro/bo+8EwcoDTntmZBMhfGJ4aiPSL3+4Izhl9bz\n\t7nokSpbh8EpDWOCN+e2eYhI1j8WR2BYsj45sADgBN27ozPdPYEqXYLm1FuiFZrztwUoH\n\tX3kQWLZj5LYoLwfG8HfU8MbE3eSVEo2halPQnL2M8OH3eNHQPWdYMPxPtkPhcle3XOR9\n\tzpH/2ktnM1fpTIAMg3KsoEnkdbiQToRQIjq/r3HTae5oDxhc7MU5pQjpQn3rGmF5Yc4d\n\ta596rYE23AWz6m8wOauRuaYoU099NB2TlY4aXJEXjo8HUA9NrFhP0L452NpUjkTYu+kd\n\t1Zdg==","X-Gm-Message-State":"AOJu0YxzCtN9UTQep0UpPZJp54+omM3YRjMEsCg3sXB9eiwec0mrdCsv\n\tRh2MmQ75q7kHITfndesW+c+te/wDVXIyLi4bXMhgieSf7xQJCpuc1AKcmmZrcPIuPtw=","X-Gm-Gg":"ASbGncujkg/GnHaH8YTtzOAKNyS2TxgRmIlItgAIecohWLIBZENTB4PA3xXRRPrOS7+\n\t+J/k5xyCd1LL1FOcvsNT9vl4VdAfjTmKSlYgpaKx4vyiq3PdxO4vq3R5kliGIqo+yu2CgJLXMKG\n\tnwOvUJOM5CX0XjLTfcw7vdTvT5iUL5cwM9yh8uF6dHyQJasYU4158lYGPuZmqJrE7G4w7vkRgIz\n\tl8i9aD8F4KVk6VPnJN14hRrURryHn5MooajM51Dnichr3UYDqqyn3WXJdf9LrRRP/cbvD7u7TTG\n\tVJrHElcF9/iimukG4IpIueL/kmg0d7VkgORcXffKx9C/PA/4JE3l4LcTea/9ILZo0oZ8bj/HM+j\n\taIlcrRJmGIGtSZDH3CDBCZ+1js9mTjo+lkoLr5YymTuMmhuz9P/6+5o5a0WC0kN/bB1TFGUj68e\n\t1mbmT2yKKRylIQyw0DcIyHs/YtFRcOGcC3mxQiNcQ+tJ8=","X-Google-Smtp-Source":"AGHT+IEAUL13SwZ+XALwaaJDtosngYnpJUCIURrPWbx2KQIVftWxEyF3UH/0oArnuURgY61uOgug5Q==","X-Received":"by 2002:a05:6402:2355:b0:63c:5892:3c3a with SMTP id\n\t4fb4d7f45d1cf-63e5eb28aa6mr4131095a12.13.1761352044675; \n\tFri, 24 Oct 2025 17:27:24 -0700 (PDT)","Message-ID":"<461cb3b0-1cb0-4ef8-b396-d8b8954167ab@linaro.org>","Date":"Sat, 25 Oct 2025 01:27:22 +0100","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v3 31/39] libcamera: shaders: Fix neighbouring positions\n\tin 8-bit debayering","To":"Milan Zamazal <mzamazal@redhat.com>","Cc":"libcamera-devel@lists.libcamera.org, hdegoede@redhat.com,\n\tbod.linux@nxsw.ie","References":"<20251015012251.17508-1-bryan.odonoghue@linaro.org>\n\t<20251015012251.17508-32-bryan.odonoghue@linaro.org>\n\t<857bwk81ov.fsf@mzamazal-thinkpadp1gen7.tpbc.csb>","From":"Bryan O'Donoghue <bryan.odonoghue@linaro.org>","Content-Language":"en-US","In-Reply-To":"<857bwk81ov.fsf@mzamazal-thinkpadp1gen7.tpbc.csb>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"7bit","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>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]